feat(libSceLibcInternal): implement fdopendir #4569
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4569"
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 pipe1os on 2026-10-12T15:53:10Z.
What
fdopendir(j+XjoRSIvwU) is not exported, and three catalog homebrew titles stop on it:--trap-sdk-syscall-stubs(#3804), it stops atfdopendir(@babyhuey's run below).fdopendir(@overlordxrz-source's run below).fdopendirnext oncefchmodatis in (#4553).These titles import
fdopendirfromlibSceLibcInternal.prx, as does the ps5-payload-dev SDK (itssce_stubslist it only inlibSceLibcInternal.c). On Windows the import builder only looks inlibSceLibcInternal.prxand thenlibc.prxfor such an import, so the export lives in libSceLibcInternal. It can't sit next toopendirin libc: it needs libkernel's descriptor lookup, and libc doesn't link libkernel, while libSceLibcInternal links both.The semantics follow FreeBSD 11's
fdopendirandclosedir:fdopendir(libSceLibcInternal). It looks up the descriptor's directory with libkernel'sGetDirectoryDescriptorPath_nid_no_patch. A descriptor that isn't open fails withEBADF, as FreeBSD'sF_SETFDcall does, and one that isn't a directory fails withENOTDIR; both leave the descriptor open.OpenDescriptorDirectory_nid_no_patch(libc). It opens the stream on that directory the wayopendirdoes and keeps the descriptor.closedirthen closes it through libkernel'sclose, as FreeBSD'sclosedirdoes with_close(fdclosedir(dirp)).docs/dev/debt/libSceLibcInternal.md. Two differences from FreeBSD are recorded:FD_CLOEXECisn't set on the descriptor.Tested
Windows 11, WinLibs GCC 15.2.0 r7, Release, on
main682ef0c17.guest_fdopendirtest. It links libSceLibcInternal, libkernel and libc.open(O_DIRECTORY), andfdopendirandreaddirlist a file (type 8) and a subdirectory (type 4).closedirreturns 0 and closes the descriptor.-1then fail withEBADF.ENOTDIRand stays open.test/verify-sx5stack with this commit in place of the earlier libkernel export.j+XjoRSIvwUis now exported bylibSceLibcInternal.prxonly. PS5SX2, relinked with--trap-sdk-syscall-stubs, gets past the loader on Windows and runs guest code ([notification] PS5SX2: starting, its HEN config checks,[elevate] already root), as it does on Linux. Before, it failed withFAIL: unresolved ELF import j+XjoRSIvwU (fdopendir) from libSceLibcInternal.prx.ctest: 993 of 993 pass.guest_np_auth_authorized_app_dialogand two AGC execution tests aren't built here, because their object paths exceed WindowsMAX_PATHin my checkout. The same happens onmain.tools/check_conventions.py,tools/check_test_registration.pyandtools/pr_overlap.py --branchpass. The new source line inlibSceLibcInternal/CMakeLists.txtand the libc helper are placed away from the lines that #3635, #3651, #3694 and #4653 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)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T16:06:29Z.
Progress report (
2f4cc89→f3b8ef7)📈 System libraries: 86.37% (+0.01%, +1 implemented functions)
✅ 1 implemented
fdopendir_nid_postfixImported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-12T16:35:40Z.
I ran PS5SX2 (PPSA99203) with this PR. Its earlier stops come from open PRs, so I stacked them on
maind592d54e: #4466, #4382, #4530, #3787, #4426 and #3658 (statvfs), all with--trap-sdk-syscall-stubs. Without this PR, that stack stops atfdopendiron both systems. With it (fork branchtest/verify-sx5, a7efa4a1), the two systems differ:[notification] PS5SX2: starting, its USB and HEN checks,[elevate] already root) and then stops atsysctlbyname("hw.model"), which AnyPS5 doesn't support yet.FAIL: unresolved ELF import j+XjoRSIvwU (fdopendir) from libSceLibcInternal.prx.The cause is the module. The title imports
fdopendirfromlibSceLibcInternal.prx, and so does the ps5-payload-dev SDK: itssce_stubslistfdopendironly inlibSceLibcInternal.c, notlibkernel.c. This PR exports it fromlibkernel.prx(objdump -pshowsj+XjoRSIvwUonly there). The Linux loader finds the symbol in any loaded library. The Windows import builder only searcheslibSceLibcInternal.prxand thenlibc.prxfor a libSceLibcInternal import (WindowsEntryStubBuilder.cppL146-L156,WindowsImportBuilder.cppL55), so it never looks in libkernel.So the export probably belongs in libc, next to
opendirinDirectory.cpp. That would also match 2 Ship 2 Harkinian on Windows (#4553), assuming it importsfdopendirfrom libSceLibcInternal like the SDK does. Yourguest_fdopendirpasses 5/5 on Windows with no warnings in the PR's files, but that test links libkernel directly, so it can't show the module lookup.Imported from boykopovar/AnyPS5. Originally posted by overlordxrz-source on 2026-10-12T18:41:55Z.
Another title for this one: OliSe Player (PPSA01153). Tested on Linux (Ubuntu 24.04, lavapipe) with main
b538b28d8+ #4452 + this PR + #4470, relinked with--trap-sdk-syscall-stubs../app.elf: symbol lookup error: ./app.elf: undefined symbol: j+XjoRSIvwU./app.elf: symbol lookup error: ./app.elf: undefined symbol: ayTeobcoGj8.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-12T19:31:18Z.
Windows result for the OliSe Player (PPSA01153) run above: on
main682ef0c1+ this PR (e3e796cf) + #4653, relinked with--trap-sdk-syscall-stubs, Windows 11 (WinLibs GCC 15.2) still stops at the import:OliSe imports
fdopendirfrom libSceLibcInternal, as PS5SX2 does.j+XjoRSIvwUis exported only bylibkernel.prxin that build, and Windows resolves a libSceLibcInternal import only from libSceLibcInternal andlibc.prx. So both titles pass on Linux and stop on Windows until the export moves into libc.Imported from boykopovar/AnyPS5. Originally posted by pipe1os on 2026-10-12T19:39:32Z.
Thanks for testing it on both, that was the bug. The title and the SDK both import
fdopendirfrom libSceLibcInternal, so my libkernel export was invisible on Windows.It lives in libSceLibcInternal now (
core/libs/prx/libSceLibcInternal/Directory.cpp). I'd have put it next toopendirin libc, but it needs libkernel's descriptor lookup and libc doesn't link libkernel. libSceLibcInternal links both, and theDIRis still libc's, soclosedirworks the same. The import builder checks libSceLibcInternal first, so that's enough for Windows.I rebuilt your
test/verify-sx5stack on Windows, reverted the old commit and put this one on top. PS5SX2 gets past the loader now and runs guest code ([notification] PS5SX2: starting, the HEN config checks,[elevate] already root), same as your Linux run. The test links libSceLibcInternal too.Your OliSe run used
e3e796c, the old head.f3b8ef7exportsj+XjoRSIvwUfromlibSceLibcInternal.prx, the module OliSe imports it from, so it should resolve there the same way. I haven't run OliSe on Windows myself, though.Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-12T20:36:03Z.
Retested the new head
f3b8ef7aon Windows 11 (WinLibs GCC 15.2), with--trap-sdk-syscall-stubs:j+XjoRSIvwUnow resolves from libSceLibcInternal.OliSe Player (PPSA01153) on
main9f8a1080+ this PR + #4653 (statvfs) gets past both imports and renders. It creates its swapchain, holdsfps: 59.9, and was still running at the 60 s limit. The only failure in its log is its music radio's HTTP fetch (radio: DOWNLOAD FAILED (-2)), not a throw. Without this PR, that build stopped atFAIL: unresolved ELF import j+XjoRSIvwU (fdopendir) from libSceLibcInternal.prx.PS5SX2 (PPSA99203), stacked with its other open PRs (#4382, #4530, #3787, #4653), also resolves
fdopendirnow on Windows and starts running.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T21:00:12Z.
Checked on the PR merged onto current main: build and the 96 libs/libc/LibcInternal tests pass,
guest_fdopendirincluded (it can't even build without the change).fdopendirerrors (EBADF,ENOTDIR, descriptor left open) and theclosedirclosing the descriptor match FreeBSD 11opendir.c/closedir.c; the two differences are in the debt file. Windows import resolution is confirmed by @babyhuey's runs (OliSe Player, PS5SX2); merging.