fix(files): isolate guest descriptors from host resources #2170
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2170"
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 MichalSy on 2026-10-09T10:38:02Z.
What
Guest file descriptors currently contain host descriptor numbers. A guest can therefore read, seek or close a private runtime file by supplying its host descriptor. This change gives guest files their own descriptor table, shared by libc, libkernel, POSIX file operations and AIO.
Descriptors 0-2 retain their guest meanings through owned duplicates of the host standard streams. Ordinary guest descriptors occupy 3-32767, preserving the existing signed 16-bit FILE prefix. Operations hold a native ownership lease, so a concurrent guest close retires the logical descriptor while an in-flight operation can finish. FILE wrappers retain the original descriptor identity; after close and slot reuse, a stale stream reports EBADF without accessing or closing the replacement. Pipe adoption publishes both guest descriptors atomically and releases native resources on failure.
Existing platform backends remain in place, including the Windows/Linux ftruncate error handling. Existing tests now obtain file descriptors through the guest API. The same new isolation fixture runs against both the ordinary libraries and the actual NID-patched libc.prx/libkernel.prx.
The overlap bot reported eight other PRs. Their current heads were read and fetched for three-way merge simulations against
b14cd621. Each of the eight produces a textual conflict; none implements the guest descriptor namespace, ownership leases or stale-FILE identity mechanism introduced here.These are not functional prerequisites for this standalone branch, so Depends on remains none. Merge order matters: after any of these lands, rebase and validate the combined behavior rather than selecting one side of a conflict. The simulations above only examine merges; no combined-branch build or runtime pass is claimed.
Previously reviewed scalar POSIX I/O errors and Windows positioned I/O also touch file APIs, without implementing the ownership registry. File/pipe polling will need logical-descriptor lookup if both changes land.
Tested
allandlibsbuild; 13 selected tests passed covering ordinary and patched isolation, standard streams, file positioning, filesystem operations, vector I/O, directory buffers/close, AIO, guest memory and narrow/wide formatting. The new socket-pair test also passed. After cleanup and the final upstream rebase, the full build and all 13 selected tests passed again. One intermediate parallel run timed out after the isolation fixture printed its success message; the immediate isolated run and the repeated parallel selection passed without code or timeout changes.python tools/check_conventions.py --base upstream/mainand the whitespace check passed. No full CTest suite was run.The runtime/build results above were obtained at
2b12fd51, based on upstream51f69aa2. The subsequent conflict-free rebase ontod70b8998brings upstream AGC profiling/video-output build changes; libc, libkernel, the NID patcher and the file test sources are unchanged. The conventions check including the PR title and description was rerun onb14cd621.Checklist
main; no duplicate implementation of this descriptor-isolation change was found.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T10:48: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/Open.cppL37-43, L135-138, L140-145, L148-156, L159-167core/libs/tests/GuestFileVector.cppL13-22, L31, L129core/libs/prx/libkernel/CMakeLists.txtL503core/libs/prx/libc/CMakeLists.txtL48core/libs/CMakeLists.txtL133core/libs/CMakeLists.txtL133core/libs/prx/libc/CMakeLists.txtL48core/libs/prx/libc/CMakeLists.txtL48core/libs/prx/libc/include/FileStream.hppL3-5, L34, L69-107core/libs/prx/libc/src/FileAndHeap.cppL65-66, L79-109Imported from boykopovar/AnyPS5. Originally posted by popeee99 on 2026-10-09T19:57:12Z.
Independent allocation-failure validation on
b14cd621f4055f501378762f9fb86430c5146420(Linux under WSL, GCC 15.2).The existing ownership tests cover invalid arguments, stale identities and rollback, but I did not find allocation-failure injection. I compiled the unchanged
GuestFileDescriptors.cppwith a standalone harness that injectsstd::bad_allocat all three standard-stream initialization allocations, single adoption, both pair-adoption allocations, and replacement.All cases passed: guest
ENOMEM, no partial pair publication, owned descriptors cleaned exactly once, original identity/resource retained after failed replacement, and successful retries. Cleanup re-entersGuestFileAcquire_nid_no_patch(1), so the pair rollback also checks that cleanup runs outside the table mutex.Each mode passed five fresh-process runs in both Release and ASan/UBSan builds (40 runs total), with no sanitizer diagnostics. The existing
GuestFileDescriptorOwnership.cpptest also passed. As a harness control, removing the pair rollback's unlock in an isolated source copy caused the expected five-second timeout; the unchanged implementation passed the bounded checks.This is focused registry validation, not a full library, Windows, NID-patched-library or game test. No defect found in these tested paths; this does not establish correctness of the entire implementation. AI-assisted investigation and harness.
Standalone harness and reproduction commands
Check out the exact PR head, then save the following as
allocation_failure.cppoutside the checkout:From the PR checkout, with
PROBEset to the harness's absolute path:Every
sNrun printedPASS sN injected=1 cleanups=0; every rollback run printedPASS rollback injected=4 cleanups=8. The ownership test printed its PASS message. All returned zero. Run with stdin/stdout/stderr open; the fixture keeps its native descriptors below 256 and compares their inventory before and after rollback.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T20:09:31Z.
Closing: this replaces how every file descriptor works (+2275 lines, real conflicts with about 15 open PRs) without a title that fails because of host descriptor numbers. If a title breaks on that, please open an issue with the title ID and the log first, so the fix can be sized to it.
Pull request closed