fix(libkernel): translate fsync errors for guest callers #2030

Closed
STUPIDCONTEM wants to merge 1 commit from upstream-pr/2030 into main
STUPIDCONTEM commented 2026-10-09 05:30:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by STUPIDCONTEM on 2026-10-09T05:30:02Z.


Evidence review (2026-10-09)

Game/title evidence has not been established. Validation below is host regression/build evidence only; it does not establish title compatibility. Older checked items and test results describe their stated revisions, not current merge readiness.

Game/title ID: none verified. No PS5 title execution is claimed.

What

sceKernelFsync returned the host's -1 on failure instead of an encoded kernel error. It also sent guest socket descriptors to the host CRT, which could only report an invalid descriptor.

Translate native failures through the existing kernel error mapping and preserve the caller's errno in the kernel entry point. The POSIX fsync wrapper now decodes the kernel result into -1 plus guest errno. Open guest sockets return EINVAL, and invalid/closed descriptors return EBADF.

The socket/invalid-descriptor distinction follows FreeBSD 11 fsync; the kernel encoding is the project's existing KernelErrors/SceErrorFromErrno convention. Regular files still use the existing host flush operation.

Tested

Windows 10 Pro 19045, WinLibs MinGW-w64 GCC 15.2.0 UCRT/posix/SEH r7, Ninja Release, BUILD_TESTING=ON, SPIRV-Tools disabled. Based directly on f145139676a48306681d3a4d5fabf83938759daf; independent of #2029.

  • New guest_fsync fails against upstream at kernel result encodes the guest error.
  • With the fix, it checks negative/large invalid descriptors, closed regular descriptors, open/closed sockets, successful regular-file flushes, kernel errno preservation, and POSIX errno translation.
  • Focused guest_fsync, guest_filesystem, and guest_kernel_sync: 3/3 passed.
  • Full default and explicit libs builds succeed.
  • Full CTest suite: 489/489 passed, 27.52 s.
  • Committed-head conventions, whitespace, and test-registration checks pass.

Linux and PS5 hardware/title behavior were not tested. The regression checks API results, not crash/power-loss durability.

Overlap review: #1738 registers a terminal test at the same CMake insertion point; it changes different production functions and is not a dependency. #2001 deletes the POSIX fsync wrapper as part of broader removals; it does not implement the error translation here. This PR remains independently based on main; overlapping hunks need reconciliation if either change lands first.

An external review approved this exact head and reports a Linux/GCC 12.2 build plus passing guest_fsync (1/1). This is reviewer-reported validation, separate from the local Windows results above.

Checklist

  • Based on current main; no other open PR implements the same change (historical base; current readiness not asserted)
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes — OpenAI Codex assisted with implementation, testing, and this description.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4796407178 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2030). Originally posted by [STUPIDCONTEM](https://github.com/STUPIDCONTEM) on 2026-10-09T05:30:02Z. --- ### Evidence review (2026-10-09) Game/title evidence has not been established. Validation below is host regression/build evidence only; it does not establish title compatibility. Older checked items and test results describe their stated revisions, not current merge readiness. Game/title ID: **none verified**. No PS5 title execution is claimed. ### What `sceKernelFsync` returned the host's `-1` on failure instead of an encoded kernel error. It also sent guest socket descriptors to the host CRT, which could only report an invalid descriptor. Translate native failures through the existing kernel error mapping and preserve the caller's errno in the kernel entry point. The POSIX `fsync` wrapper now decodes the kernel result into `-1` plus guest errno. Open guest sockets return EINVAL, and invalid/closed descriptors return EBADF. The socket/invalid-descriptor distinction follows [FreeBSD 11 fsync](https://github.com/freebsd/freebsd-src/blob/stable/11/lib/libc/sys/fsync.2); the kernel encoding is the project's existing KernelErrors/SceErrorFromErrno convention. Regular files still use the existing host flush operation. ### Tested Windows 10 Pro 19045, WinLibs MinGW-w64 GCC 15.2.0 UCRT/posix/SEH r7, Ninja Release, BUILD_TESTING=ON, SPIRV-Tools disabled. Based directly on `f145139676a48306681d3a4d5fabf83938759daf`; independent of #2029. - New `guest_fsync` fails against upstream at `kernel result encodes the guest error`. - With the fix, it checks negative/large invalid descriptors, closed regular descriptors, open/closed sockets, successful regular-file flushes, kernel errno preservation, and POSIX errno translation. - Focused `guest_fsync`, `guest_filesystem`, and `guest_kernel_sync`: 3/3 passed. - Full default and explicit `libs` builds succeed. - Full CTest suite: **489/489 passed**, 27.52 s. - Committed-head conventions, whitespace, and test-registration checks pass. Linux and PS5 hardware/title behavior were not tested. The regression checks API results, not crash/power-loss durability. Overlap review: #1738 registers a terminal test at the same CMake insertion point; it changes different production functions and is not a dependency. #2001 deletes the POSIX fsync wrapper as part of broader removals; it does not implement the error translation here. This PR remains independently based on main; overlapping hunks need reconciliation if either change lands first. An [external review](https://github.com/boykopovar/AnyPS5/pull/2030#pullrequestreview-5466099238) approved this exact head and reports a Linux/GCC 12.2 build plus passing `guest_fsync` (1/1). This is reviewer-reported validation, separate from the local Windows results above. ### Checklist - [ ] Based on current `main`; no other open PR implements the same change (historical base; current readiness not asserted) - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes — OpenAI Codex assisted with implementation, testing, and this description.
MarcZX10 commented 2026-10-09 05:33:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T05:33:32Z.

Review: APPROVED


Reviewed the full three-file diff at 7ea7f59a5f. The kernel API now returns the project’s encoded error and preserves errno; the POSIX wrapper uses the existing PosixResult path. The new test covers regular files, sockets, invalid/closed descriptors, and errno behavior. Exact-head Linux/GCC 12.2 build passed and guest_fsync passed (1/1, 0.05 s); conventions and diff checks pass. The author reports the Windows run and full CTest. GitHub currently reports no checks.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5466099238 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2030#pullrequestreview-5466099238). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T05:33:32Z. **Review:** APPROVED --- Reviewed the full three-file diff at 7ea7f59a5f78b62c1d511957e47025ea98877048. The kernel API now returns the project’s encoded error and preserves errno; the POSIX wrapper uses the existing PosixResult path. The new test covers regular files, sockets, invalid/closed descriptors, and errno behavior. Exact-head Linux/GCC 12.2 build passed and `guest_fsync` passed (1/1, 0.05 s); conventions and diff checks pass. The author reports the Windows run and full CTest. GitHub currently reports no checks.

Pull request closed

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!2030
No description provided.