feat(libkernel_sys): implement fchdir #3392
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3392"
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 MarcZX10 on 2026-10-11T09:40:51Z.
What
Implements
fchdirinlibkernel_sysfor PPSA99764. It resolves an open directory descriptor on Windows from its recorded path and on Linux through/proc/self/fd, then updates the guest working directory. Invalid descriptors returnEBADF; open non-directory descriptors returnENOTDIR.The original implementation commit by Tharun Balaji is preserved with its author attribution. Follow-up commits keep
chdirresolution and cwd updates atomic, and use C ABI helpers across PRXs for descriptor-path lookup and cwd updates.Closes #3288.
Tested
Linux, Debian, GCC 12.2.0, Release, Unix Makefiles, based on current
main99c1c26347:libstarget and the affected test executables.patched_libraries,guest_kernel_sys,guest_access,guest_working_directory,guest_realpath,guest_path_case,guest_directory, andguest_filesystemeach passed three consecutive runs (24 test executions).tools/check_conventions.py --base upstream/mainandgit diff --checkpassed.Windows tests were reported for the source commit in the issue, but were not rerun on this rebased head. Console behavior is unverified. Repository CI skips the full Linux/Windows build jobs on ordinary PR runs.
Checklist
main; no open PR implementsfchdirImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T09:43:40Z.
Progress report (
99c1c26→1a73d01)➖ System libraries: 85.76% (+0.0%, +1 implemented functions)
✅ 1 implemented
fchdir_nid_postfixImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T09:53:24Z.
Review: CHANGES_REQUESTED
Thanks for picking this up. One blocker:
patched_librariesfails on this head:libkernel_sys.prx: undefined symbol: _Z29DescriptorIsOpen_nid_no_patchi(core/libs/prx/libkernel_sys/Export.cpp:73).guest_kernel_syspasses only because the test links the libraries statically, but the reallibkernel_sys.prxdoesn't load, sofchdirwould not resolve in a title.DescriptorIsOpen_nid_no_patch(File.hpp) andFile::DirectoryDescriptorPath(DirectoryDescriptor.hpp, used atExport.cpp:74) are plain C++ symbols, notextern "C"exports. Cross-library_nid_no_patchhelpers areextern "C"(likeResolvePath_nid_no_patch), and their signatures should avoid C++ types where possible (SetWorkingDirectory_nid_no_patchtakesconst std::filesystem::path&in anextern "C"function; check the other helpers for how they pass paths, e.g.const char*).extern "C"helper from libkernel that takes the fd and returns the directory path as a C string or errno (checking open + directory there), and call it fromfchdir; then runctest -R patched_librariesto confirm all patched libraries load.The rest looks right:
EBADF/ENOTDIRmatch FreeBSDfchdir, thechdirrefactor keeps resolution and update under one lock, and the TechnicalDebt line is in place.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T10:03:08Z.
Rebased the fix onto current
main(99c1c26347); the updated head is1a73d0165.libkernelexposes a C-linkage helper that validates the descriptor and directory, then returns a UTF-8 path or POSIXEBADF/ENOTDIR.libkernel_sysno longer imports C++-mangled descriptor helpers.SetWorkingDirectory_nid_no_patchtakes a C string and converts UTF-8 insidelibc.libstarget and affected test executables.patched_libraries,guest_kernel_sys,guest_access,guest_working_directory,guest_realpath,guest_path_case,guest_directory, andguest_filesystemeach passed three consecutive runs (24 passes total). Conventions andgit diff --checkpass.The new head has fresh GitHub Actions checks running. Could you please re-review it once those checks finish? Windows tests from the source commit have not been rerun on this head, and console behavior remains unverified.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T10:40:38Z.
Review: APPROVED
Checked on current main:
patched_libraries,guest_kernel_sysandguest_working_directorypass,libkernel_sys.prxnow loads, andguest_kernel_sysfails to link without the change. The C-ABI helpers fix the earlier undefined symbol; merging.