fix(libkernel): return EBADF from sceKernelClose for a descriptor that is not open #1222

Merged
gjonn merged 1 commit from upstream-pr/1222 into main 2026-10-07 20:22:16 +00:00
gjonn commented 2026-10-07 18:14:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gjonn on 2026-10-07T18:14:19Z.


What

sceKernelClose threw std::runtime_error whenever the host close failed, so a title that closes a descriptor that is not open terminated the process. PPSA09706 (Persona 5 Tactica, Unity IL2CPP) closes descriptor 0 more than once: the first close succeeds, the next ones fail with sceKernelClose: close failed, fd=0, errno=9 and the title aborted about five seconds after start-up.

sceKernelClose now returns SCE_KERNEL_ERROR_EBADF when the descriptor is not open, and the title ignores the result as it does on a console. Any other close failure still throws.

On Windows the host _close runs with a thread-local no-op invalid-parameter handler. The UCRT dispatches an invalid-parameter report for a bad descriptor, and the crash reporter answers it with a backtrace of every thread, which is noise for a close that is reported to the title as an ordinary error.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs UCRT r7), Release: guest_filesystem passes with the new checks (closing a descriptor twice and closing -1 both return 0x80020009).
  • tools/check_conventions.py --base origin/main passes.
  • PPSA09706 (Windows): before, it terminated within 5 s with the message above; after, it ran for the whole 75 s test window (loading screen, about 60 FPS) without a termination or an invalid-parameter report.
  • Linux: not built locally.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • No new third-party code
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4776636288 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1222). Originally posted by [gjonn](https://github.com/gjonn) on 2026-10-07T18:14:19Z. --- ### What `sceKernelClose` threw `std::runtime_error` whenever the host close failed, so a title that closes a descriptor that is not open terminated the process. PPSA09706 (Persona 5 Tactica, Unity IL2CPP) closes descriptor 0 more than once: the first close succeeds, the next ones fail with `sceKernelClose: close failed, fd=0, errno=9` and the title aborted about five seconds after start-up. `sceKernelClose` now returns `SCE_KERNEL_ERROR_EBADF` when the descriptor is not open, and the title ignores the result as it does on a console. Any other close failure still throws. On Windows the host `_close` runs with a thread-local no-op invalid-parameter handler. The UCRT dispatches an invalid-parameter report for a bad descriptor, and the crash reporter answers it with a backtrace of every thread, which is noise for a close that is reported to the title as an ordinary error. ### Tested - Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs UCRT r7), Release: `guest_filesystem` passes with the new checks (closing a descriptor twice and closing -1 both return `0x80020009`). - `tools/check_conventions.py --base origin/main` passes. - PPSA09706 (Windows): before, it terminated within 5 s with the message above; after, it ran for the whole 75 s test window (loading screen, about 60 FPS) without a termination or an invalid-parameter report. - Linux: not built locally. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); no silent stubs added - [x] No notes, investigation `.md` files or images added to the repository - [x] No new third-party code - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
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!1222
No description provided.