feat(libSceLibcInternal): implement _readdir_unlocked and _seekdir #13881
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13881"
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 heditrigui on 2026-10-31T11:01:29Z.
What
Implements
_readdir_unlockedand_seekdirinlibSceLibcInternal(core/libs/prx/libSceLibcInternal/Directory.cpp), replacing their placeholder stub declarations inInventoryExports.cpp(libSceLibcInternalInventory_276_nid_no_patchandlibSceLibcInternalInventory_282_nid_no_patch):_readdir_unlocked(-u3XfqNumMU): implements FreeBSD 11.4_readdir_unlocked(dirp, skip)(lib/libc/gen/readdir.c), performing unlocked traversal without acquiringdd_lock. Skips zero-inode entries (fileNumber == 0) whenskip != 0(adopted also inreaddirandreaddir_rwrappers) and preserves them whenskip == 0. Returnsnullptrwitherrno = EBADF(9) on a null directory pointer._seekdir(Do3zPpsXj1o): implements FreeBSD 11.4_seekdir(dirp, loc)(lib/libc/gen/telldir.c), performing unlocked repositioning without acquiringdd_lock. Shares the underlying seek handler where unrecognized offsets setEINVAL(indexed), forward to seek callbacks (descriptor), or pass to hostseekdir(native). Setserrno = EBADF(9) on a null directory pointer.Tested
core/libs/tests/GuestOpendir2.cppverifying:_readdir_unlocked_nid_postfix(nullptr, 0)fails withnullptrand setserrno = 9(EBADF)._seekdir_nid_postfix(nullptr, 0)setserrno = 9(EBADF)._readdir_unlocked_nid_postfixretrieves all directory entries matching standardreaddir.telldir_nid_postfixand seeking back via_seekdir_nid_postfixcorrectly rewinds traversal so_readdir_unlocked_nid_postfixreads the bookmarked entry again.readdir_nid_postfixandreaddir_r_nid_postfixskip zero-inode records and returnactivefirst._readdir_unlocked_nid_postfix(fakeDir, 1)skips zero-inode records (fileNumber == 0) and returnsactive._readdir_unlocked_nid_postfix(fakeDir, 0)preserves zero-inode records and returnsdeleted.python core/libs/tests/test_public_headers.py --audit-only(399 libraries, 26,745 exports checked; 0 errors).python tools/check_conventions.py --base upstream/main --head HEAD(all conventions checks passed; 0 errors).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T11:05:36Z.
Review: DISMISSED
Reviewed — changes requested
The replacement functions currently lose their NID export aliases, and
_readdir_unlockeddoes not preserve the referenced FreeBSD argument or behavior.What I ran
Reviewed head
21960ccf49288d0e342c59cbe7b6f9b18d01df9dagainst base1847a6f9da38f03d1b92952ca6977a40278615e7; the dependency and merge previews were clean. Environment: Debian Linux x86_64, Python 3.11.2. No local build or C++ test was run.Results
passed_with_warnings; it reports both previous NID stub exports as removed. The exact-head implementation has no replacement aliases.Relevant unedited output
Findings
Blocking
The new implementations are not exported under either PRX NID. The base registers
-u3XfqNumMUandDo3zPpsXj1owithAPS5_EXPORT, but the PR removes those registrations and adds noAPS5_EXPORTfor the new functions.APS5_EXPORTcreates the linker aliases ending in_nid_no_patch_cut; the tests call the C++ function names directly, so they do not catch the missing NID aliases. Register both NIDs against the new implementations._readdir_unlockedhas the wrong signature and behavior for the cited FreeBSD implementation. The PR declares one argument and forwards toreaddir_nid_postfix, which always uses the normal readdir behavior. FreeBSD 11.4 declares_readdir_unlocked(DIR *, int skip);skipcontrols whether entries withd_ino == 0are skipped. The current test only exercises the readdir-equivalent path and cannot validateskip == 0. Add theskipargument and implement/test both values, or provide pinned PS5 disassembly demonstrating that this NID uses a different signature and behavior._seekdirforwards to the locking wrapper rather than the unlocked implementation. In the cited FreeBSD source,seekdiracquires the directory mutex and then calls_seekdir;_seekdiritself performs the seek without reacquiring the lock. The PR forwards_seekdirtoseekdir_nid_postfix, which takes the mutex. Preserve the unlocked helper semantics or provide PS5-specific evidence that this export intentionally aliases the public locking wrapper.Non-blocking
None.
Sources
_readdir_unlockedsignature andskipbehavior at readdir.c, pinned commit.Not verified
guest_opendir2, test console behavior, or perform negative controls.To get this to a good state
Restore the two NID aliases, correct or document the PS5-specific
_readdir_unlockedsignature/behavior, and preserve or substantiate the_seekdirlocking behavior. I will rerun the same checks and inspect the updated head.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-11-01T05:10:42Z.
Review: CHANGES_REQUESTED
Thanks for the update; the
skipsignature and the unlocked helpers look right. Still open on7d437d4245:core/libs/prx/libSceLibcInternal/Directory.cpp:36and:41:_readdir_unlocked_nid_postfixand_seekdir_nid_postfixalready hash to-u3XfqNumMUandDo3zPpsXj1o, so theAPS5_EXPORTlines export each NID twice. This is what fails the Windows job (duplicate patched export name: -u3XfqNumMU). Delete both lines; the names alone are the exports. Until thenguest_opendir2has not run on any job.core/libs/tests/GuestOpendir2.cpp:118:readdirandreaddir_rnow callReadEntry(directory, 1)and skip zero file numbers on descriptor-backed and indexed directories (core/libs/prx/libc/src/Directory.cpp:360,372). This matches FreeBSD'sreaddir, but it is a behaviour change with no test. Callreaddir_nid_postfixandreaddir_r_nid_postfixon the fake directory and requireactivefirst, and say so in the debt entry.docs/dev/debt/libSceLibcInternal.md:347:_seekdirshares the oldseekdirbody, so a locationtelldirdid not return is not ignored as in FreeBSD's_seekdir(indexed directories setEINVAL, descriptor directories pass it to the seek callback, native ones to the hostseekdir). Either make that case a no-op or add a clause to the entry so "follows FreeBSD" stays true.### What/### Testedfor the two-argument signature, the unlocked helpers and theskiptest.The macOS
write-watchfailures (duplicatewrite_watch_*-faulttest names) are not from this PR.Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-11-06T11:02:23Z.
Review: COMMENTED
Reviewed head
7e51d31a201fa6c68cb7cb5b52b1b9dc2cf70a23against PR basef79ea3f893cb854c68e7ed2d4a0223bd2cbe2454.On Ubuntu 24.04/WSL2, GCC 13.3, the focused build and
guest_opendir2pass. Conventions and the public header audit pass too.The separate probe runs are:
A separate probe linked to this head's actual
libSceLibcInternal,libkernel, andlibcfinds one refill gap:A deleted-only descriptor batch ends iteration too early. In ReadEntry, the skip loop exhausts
pendingand returns null without refilling.I return a valid 16-byte deleted record, then an active record (
inode=42,name="active") in the next callback._readdir_unlocked(dir, 1),readdir, andreaddir_rall stop after one read. The first two return null;readdir_rreturns 0 with a null result. Each should reach the active record after two reads. A following EIO is also hidden by this early return.The three same-batch controls pass.
skip=0also returns deleted, then active, after one and two reads. The existing fixture puts both records in one batch, so it misses this boundary.An isolated copy with an outer refill loop passes all 16 probe cases. Removing that overlay restores all 23 assertion failures. A control built from
Directory.cppat main5299939ecfa9e186e1eb457c6f4bd133bdb087c7returns deleted, then active, through both existing wrappers. That control uses head dependencies; it is not a full main build.Please refill when skipping exhausts a batch, and add a separate-batch assertion for each wrapper. The adopted FreeBSD source keeps refill and skip in one outer loop.
This is a synthetic callback contract check. The current libkernel producer normalizes zero inode values, so I do not establish title reachability or console behavior. GPU testing is n/a. Hosted CI remains queued.