feat(libkernel): implement sceKernelFdatasync #2129

Merged
sktharunbalaji13-cmd merged 3 commits from upstream-pr/2129 into main 2026-10-10 18:19:46 +00:00
sktharunbalaji13-cmd commented 2026-10-09 09:41:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by sktharunbalaji13-cmd on 2026-10-09T09:41:14Z.


What

Implement the missing sceKernelFdatasync libkernel export (NID 30Rh4ixbKy4), which is imported by Dying Light 2 (PPSA02262). The implementation uses _commit on Windows and fdatasync on POSIX, following the existing sceKernelFsync implementation pattern.

Add regression coverage for successful synchronization and invalid POSIX file descriptors. The related open PR #1620 implements a distinct fdatasync_nid_postfix export with a different NID, so it does not overlap with this change.

Tested

Windows/MinGW Release:

  • cmake --build build --target guest_filesystem_tests — passed.
  • ctest --test-dir build -R "^guest_filesystem$" --output-on-failure — 1/1 passed.
  • Verified sceKernelFdatasync is exported and the repository NID helper returns 30Rh4ixbKy4.

WSL/Linux Release:

  • cmake --build build-libs --target guest_filesystem_tests — passed.

  • ctest --test-dir build-libs -R '^guest_filesystem$' --output-on-failure — 1/1 passed.

  • Verified the exported symbol; both valid-descriptor and invalid-descriptor assertions passed.

  • Confirmed the regression before the fix via a link failure for the missing export.

  • git diff --check — passed.

  • The full test suite and Dying Light 2 runtime were not tested.

Checklist

  • Based on current upstream main; no duplicate PR implements this export/NID.
  • One topic per PR; implementation and regression tests only.
  • No code comments or silent stubs added.
  • No notes, reports, images, or third-party code added.
  • Generic behavior; not title-specific.
  • Depends on: none.
  • AI-assisted: yes (OpenCode).
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4798718929 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2129). Originally posted by [sktharunbalaji13-cmd](https://github.com/sktharunbalaji13-cmd) on 2026-10-09T09:41:14Z. --- ### What Implement the missing `sceKernelFdatasync` libkernel export (NID `30Rh4ixbKy4`), which is imported by Dying Light 2 (PPSA02262). The implementation uses `_commit` on Windows and `fdatasync` on POSIX, following the existing `sceKernelFsync` implementation pattern. Add regression coverage for successful synchronization and invalid POSIX file descriptors. The related open PR #1620 implements a distinct `fdatasync_nid_postfix` export with a different NID, so it does not overlap with this change. ### Tested **Windows/MinGW Release:** - `cmake --build build --target guest_filesystem_tests` — passed. - `ctest --test-dir build -R "^guest_filesystem$" --output-on-failure` — 1/1 passed. - Verified `sceKernelFdatasync` is exported and the repository NID helper returns `30Rh4ixbKy4`. **WSL/Linux Release:** - `cmake --build build-libs --target guest_filesystem_tests` — passed. - `ctest --test-dir build-libs -R '^guest_filesystem$' --output-on-failure` — 1/1 passed. - Verified the exported symbol; both valid-descriptor and invalid-descriptor assertions passed. - Confirmed the regression before the fix via a link failure for the missing export. - `git diff --check` — passed. - The full test suite and Dying Light 2 runtime were not tested. ### Checklist - [x] Based on current upstream `main`; no duplicate PR implements this export/NID. - [x] One topic per PR; implementation and regression tests only. - [x] No code comments or silent stubs added. - [x] No notes, reports, images, or third-party code added. - [x] Generic behavior; not title-specific. - [x] Depends on: none. - [x] AI-assisted: yes (OpenCode).
oneandonlydean commented 2026-10-09 20:15:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T20:15:04Z.


Does Dying Light 2 (PPSA02262) stop at sceKernelFdatasync on main? Please add the log line where it stops; an import alone isn't enough for a new export. Also, sceKernel* functions return SCE error codes, so a bad descriptor should give 0x80020009, not -1 (the test at GuestFilesystem.cpp:158 should check that).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088515290 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2129#issuecomment-6088515290). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T20:15:04Z. --- Does Dying Light 2 (PPSA02262) stop at `sceKernelFdatasync` on main? Please add the log line where it stops; an import alone isn't enough for a new export. Also, `sceKernel*` functions return SCE error codes, so a bad descriptor should give `0x80020009`, not -1 (the test at `GuestFilesystem.cpp:158` should check that).
github-actions[bot] commented 2026-10-10 07:54:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T07:54:27Z.


Progress report (de5e541 → 57be03a)

➖ System libraries: 84.52% (+0.0%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel sceKernelFdatasync
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6095328585 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2129#issuecomment-6095328585). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T07:54:27Z. --- <!-- progress-report --> ### Progress report (de5e541 → 57be03a) ➖ **System libraries**: 84.52% (+0.0%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel | `sceKernelFdatasync` | </details>
klosixgaming-arch commented 2026-10-10 11:16:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-10T11:16:12Z.


Independent validation on Windows

Built and ran the PR head 8734b923 on my own box:

  • Windows 11 Pro (26200), WinLibs MinGW-w64 GCC 15.2.0 (r7), Release, BUILD_TESTING=ON.

Results:

  • guest_filesystem_tests PASSES (exit 0). libkernel.prx exports sceKernelFdatasync (verified with nm: T sceKernelFdatasync).
  • The bundled GuestFont.cpp change: guest_font_tests PASSES (exit 0) after the font .prx DLLs are present in the tests dir.

Rigor check (is the test real?): I removed the sceKernelFdatasync implementation from Stdio.cpp, rebuilt, and confirmed guest_filesystem_tests fails to link — undefined reference to 'sceKernelFdatasync' — then restored it → PASS. So the new test genuinely requires the new export rather than passing unconditionally. This matches the "link failure for the missing export" base regression noted in the PR.

One concern — scope / "one topic per PR": this PR bundles two unrelated changes:

  1. the sceKernelFdatasync feature + its GuestFilesystem.cpp test, and
  2. an unrelated font-test isolation change in GuestFont.cpp (the PR's head commit is even titled "test(font): isolate system font failure case").

The author checked "One topic per PR", but these are two distinct topics. I'd suggest splitting the font-test change into its own PR so review/rollback stay clean.

Honest limits of what I verified:

  • On Windows I verified the valid-fd == 0 path and the export. The invalid-fd == -1 assertion is inside #ifndef _WIN32, so it does not run on Windows — I could not verify that path here.
  • I did not test the Linux/POSIX fdatasync path (no Linux here) or the Dying Light 2 title (no game/ROM).

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6096919720 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2129#issuecomment-6096919720). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-10-10T11:16:12Z. --- **Independent validation on Windows** Built and ran the PR head `8734b923` on my own box: - **Windows 11 Pro (26200)**, WinLibs MinGW-w64 **GCC 15.2.0 (r7)**, `Release`, `BUILD_TESTING=ON`. **Results:** - `guest_filesystem_tests` **PASSES (exit 0)**. `libkernel.prx` **exports** `sceKernelFdatasync` (verified with `nm`: `T sceKernelFdatasync`). - The bundled `GuestFont.cpp` change: `guest_font_tests` **PASSES (exit 0)** after the font `.prx` DLLs are present in the tests dir. **Rigor check (is the test real?):** I removed the `sceKernelFdatasync` implementation from `Stdio.cpp`, rebuilt, and confirmed `guest_filesystem_tests` **fails to link** — `undefined reference to 'sceKernelFdatasync'` — then restored it → PASS. So the new test genuinely requires the new export rather than passing unconditionally. This matches the "link failure for the missing export" base regression noted in the PR. **One concern — scope / "one topic per PR":** this PR bundles **two** unrelated changes: 1. the `sceKernelFdatasync` feature + its `GuestFilesystem.cpp` test, and 2. an **unrelated** font-test isolation change in `GuestFont.cpp` (the PR's head commit is even titled *"test(font): isolate system font failure case"*). The author checked *"One topic per PR"*, but these are two distinct topics. I'd suggest **splitting** the font-test change into its own PR so review/rollback stay clean. **Honest limits of what I verified:** - On Windows I verified the **valid-fd `== 0`** path and the export. The **invalid-fd `== -1`** assertion is inside `#ifndef _WIN32`, so it does **not** run on Windows — I could not verify that path here. - I did **not** test the Linux/POSIX `fdatasync` path (no Linux here) or the Dying Light 2 title (no game/ROM). Written with AI assistance.
sktharunbalaji13-cmd commented 2026-10-10 11:40:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by sktharunbalaji13-cmd on 2026-10-10T11:40:19Z.


Status update after the rebase and scope cleanup.

Title evidence (Dying Light 2, PPSA02262) — reported by @tv7 in #1794 (comment):

  • Clean main: the loader stops at FAIL: unresolved ELF import 30Rh4ixbKy4 from libkernel.prx.
  • With this change: that import resolves, and execution advances to FAIL: unresolved ELF import -q-vbO859Tw from libSceVideoOut.prx.

This is evidence the import blocker advances past 30Rh4ixbKy4; it is not a claim that the title becomes playable (12 further imports remain unresolved).

Scope — the PR now contains only core/libs/prx/libkernel/File/src/Stdio.cpp and core/libs/tests/GuestFilesystem.cpp. The bundled test(font) change was dropped, since main now carries that fix (SetFontDirectory in GuestFont.cpp), which had caused a redefinition build error.

Behavior — sceKernelFdatasync maps native failures through SceErrorFromErrno(errno) and returns 0 on success, matching the neighbouring sceKernel* file calls; the closed-descriptor assertion expects 0x80020009.

Tests — guest_filesystem passes on Windows (MinGW-w64 GCC 15.2.0) and on Linux.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6097113474 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2129#issuecomment-6097113474). Originally posted by [sktharunbalaji13-cmd](https://github.com/sktharunbalaji13-cmd) on 2026-10-10T11:40:19Z. --- Status update after the rebase and scope cleanup. **Title evidence (Dying Light 2, PPSA02262)** — reported by @tv7 in #1794 ([comment](https://github.com/boykopovar/AnyPS5/issues/1794#issuecomment-6096904742)): - Clean `main`: the loader stops at `FAIL: unresolved ELF import 30Rh4ixbKy4 from libkernel.prx`. - With this change: that import resolves, and execution advances to `FAIL: unresolved ELF import -q-vbO859Tw from libSceVideoOut.prx`. This is evidence the import blocker advances past `30Rh4ixbKy4`; it is not a claim that the title becomes playable (12 further imports remain unresolved). **Scope** — the PR now contains only `core/libs/prx/libkernel/File/src/Stdio.cpp` and `core/libs/tests/GuestFilesystem.cpp`. The bundled `test(font)` change was dropped, since `main` now carries that fix (`SetFontDirectory` in `GuestFont.cpp`), which had caused a redefinition build error. **Behavior** — `sceKernelFdatasync` maps native failures through `SceErrorFromErrno(errno)` and returns `0` on success, matching the neighbouring `sceKernel*` file calls; the closed-descriptor assertion expects `0x80020009`. **Tests** — `guest_filesystem` passes on Windows (MinGW-w64 GCC 15.2.0) and on Linux.
orishamir commented 2026-10-10 12:29:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orishamir on 2026-10-10T12:29:14Z.


Built the PR (head 36bc9214) merged with current main and probed the new export against a guest socket: sceKernelFdatasync(socket) returns 0x80020009, while fdatasync_nid_postfix(socket) on the same descriptor returns -1 with errno 22, because the POSIX export checks GuestSockets::FirstDescriptor first and this one does not. The EBADF comes from the host rejecting 0x10000000 as an fd, so it is accidental; on Windows the same call reaches _commit and the UCRT invalid-parameter handler in CrashReport.cpp before returning.

Suggest moving the guard and the host call into sceKernelFdatasync and having fdatasync_nid_postfix wrap it, the way fsync_nid_postfix wraps sceKernelFsync.

Probe (linked like guest_filesystem_tests, Linux):

const int s = socket_nid_postfix(2, 1, 0);        // 0x10000000
sceKernelFdatasync(s);                             // -> 0x80020009
fdatasync_nid_postfix(s);                          // -> -1, guest errno 22
sceKernelFdatasync(0x7fffffff);                    // -> 0x80020009

Not run on Windows. AI-assisted.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6097501428 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2129#issuecomment-6097501428). Originally posted by [orishamir](https://github.com/orishamir) on 2026-10-10T12:29:14Z. --- Built the PR (head 36bc9214) merged with current main and probed the new export against a guest socket: `sceKernelFdatasync(socket)` returns `0x80020009`, while `fdatasync_nid_postfix(socket)` on the same descriptor returns -1 with errno 22, because the POSIX export checks `GuestSockets::FirstDescriptor` first and this one does not. The EBADF comes from the host rejecting `0x10000000` as an fd, so it is accidental; on Windows the same call reaches `_commit` and the UCRT invalid-parameter handler in CrashReport.cpp before returning. Suggest moving the guard and the host call into `sceKernelFdatasync` and having `fdatasync_nid_postfix` wrap it, the way `fsync_nid_postfix` wraps `sceKernelFsync`. Probe (linked like `guest_filesystem_tests`, Linux): ```cpp const int s = socket_nid_postfix(2, 1, 0); // 0x10000000 sceKernelFdatasync(s); // -> 0x80020009 fdatasync_nid_postfix(s); // -> -1, guest errno 22 sceKernelFdatasync(0x7fffffff); // -> 0x80020009 ``` Not run on Windows. AI-assisted.
sktharunbalaji13-cmd commented 2026-10-10 15:22:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by sktharunbalaji13-cmd on 2026-10-10T15:22:19Z.


Thanks @orishamir for catching the guest-socket descriptor issue — that was a real bug.

The fix is in 57be03a4:

  • sceKernelFdatasync now checks GuestSockets::FirstDescriptor before any native syscall. An open guest socket returns SCE EINVAL (0x80020016); a closed or invalid guest socket returns SCE EBADF (0x80020009). This prevents high guest descriptors from reaching _commit on Windows (which would trigger the UCRT invalid-parameter handler).
  • fdatasync_nid_postfix now delegates to sceKernelFdatasync through PosixResult, so the socket guard and error mapping live in one place — no duplicated logic.

The targeted guest_filesystem_tests passed on Windows/MinGW and Linux/WSL, including the new assertions for a valid socket (EINVAL), a closed socket (EBADF), and a high invalid descriptor like 0x7fffffff (EBADF). The full test suite and Dying Light 2 were not tested.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6099041624 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2129#issuecomment-6099041624). Originally posted by [sktharunbalaji13-cmd](https://github.com/sktharunbalaji13-cmd) on 2026-10-10T15:22:19Z. --- Thanks @orishamir for catching the guest-socket descriptor issue — that was a real bug. The fix is in `57be03a4`: - **`sceKernelFdatasync`** now checks `GuestSockets::FirstDescriptor` before any native syscall. An open guest socket returns SCE EINVAL (`0x80020016`); a closed or invalid guest socket returns SCE EBADF (`0x80020009`). This prevents high guest descriptors from reaching `_commit` on Windows (which would trigger the UCRT invalid-parameter handler). - **`fdatasync_nid_postfix`** now delegates to `sceKernelFdatasync` through `PosixResult`, so the socket guard and error mapping live in one place — no duplicated logic. The targeted `guest_filesystem_tests` passed on Windows/MinGW and Linux/WSL, including the new assertions for a valid socket (EINVAL), a closed socket (EBADF), and a high invalid descriptor like `0x7fffffff` (EBADF). The full test suite and Dying Light 2 were not tested.
orishamir commented 2026-10-10 16:53:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orishamir on 2026-10-10T16:53:41Z.


Confirmed on 57be03a4 merged with current main (Linux): guest_filesystem_tests passes, and the probe from above now gives sceKernelFdatasync(socket) = 0x80020016 for an open guest socket and 0x80020009 for a bad descriptor, matching fdatasync_nid_postfix. Nothing further from me on this one.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6099919326 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2129#issuecomment-6099919326). Originally posted by [orishamir](https://github.com/orishamir) on 2026-10-10T16:53:41Z. --- Confirmed on 57be03a4 merged with current main (Linux): `guest_filesystem_tests` passes, and the probe from above now gives `sceKernelFdatasync(socket)` = `0x80020016` for an open guest socket and `0x80020009` for a bad descriptor, matching `fdatasync_nid_postfix`. Nothing further from me on this one.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!2129
No description provided.