fix(libkernel): close an unopened descriptor on Windows without the invalid-parameter report #3923
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3923"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-11T19:10:45Z.
What
On Windows,
close_nid_postfixcalls_close(d)directly. For a descriptor that isn't open, the UCRT runs the process's invalid-parameter handler before returningEBADF. In a relinked title that handler is libc's crash reporter (CrashReport.cpp), so a plainclose()of an already-closed descriptor (legal POSIX: -1/EBADF) printsFATAL: UCRT invalid parameter on thread …, then every thread's stack, and the title carries on.closenow runs_closeunder the thread-local no-op handler (WithoutParameterHandler), asdupanddup2beside it already do. The return value anderrnoare unchanged.Title: ProsperoLight (PPSA99002) prints that report on every launcher refresh. On
maina11c8f7fit stops earlier (pthread_attr_getscope, #3494, thenpollon a pipe, #3584 / #3649). With those, its log (download0/prosperolight-launcher.log) shows:The stack scan from #3887 placed it in
fclose→_close(ucrtbase_close+0x41) called fromlibkernel.prx. With this change the report is gone (0 in a 60 s run, 2 before) and the launcher renders 1303 frames.Tested
Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release,
maina11c8f7f:guest_dup(BadDescriptors):closeof a closed descriptor and of -1 fail withEBADF(9). On Windows the test installs its own process-wide invalid-parameter handler around those calls and requires it not to run. That fails with main'sStdio.cppand passes with this change.ctest -E "^agc_|video_out": 450/453. The 3 failures also fail onmainon Windows:windows_exceptions(#3411),guest_kernel_sys(#3510) andguest_filesystem(#3518).main+ #3494 + a pipe-pollfix, with and without this change (above).tools/check_conventions.py: clean.tools/pr_overlap.pyreports #3649, which addsFile::ForgetPipeEnd(d);on the line above the_closecall. That's a one-line rebase for whichever lands second, not the same change.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)pollfix)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T00:50:06Z.
The fix follows the file's own established pattern exactly -
dup/dup2in this same file already wrap their libc calls inWithoutParameterHandlerfor the identical reason (suppressing the UCRT invalid-parameter handler on a bad descriptor), so this isn't a new mechanism, just applying an existing one to a call site that was missed. The test's approach (install a recording handler, assert it never fires) directly proves the claimed mechanism rather than just testing the return value, which is the right level for this kind of host-API-suppression bug.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-12T01:24:54Z.
A catalog title hits this. On Windows 11 (MinGW GCC 15.2), Cloud Play (PPSA99600, on
main7a84b222with #3798 merged so it gets pastgetservbyname) printsFATAL: UCRT invalid parameterwith a backtrace fromclose_nid_postfix→_close:close(32)on a descriptor that is no longer open, between two of its manyopen("/download0/debug.log.tmp", O_WRONLY|O_CREAT|O_TRUNC)calls.sysctl_nid_postfix: unsupported MIB 1.37.With this PR merged on top (
6eacac2e, clean):sysctlstop.guest_duppasses 5/5 (--repeat until-fail:5), with no warnings inStdio.cpporGuestDup.cpp.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T02:38:35Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libkernel/File/src/Stdio.cppL472-473