Repository navigation
feat(libkernel_sys): implement fchdir - #3392
Conversation
adriadam10
left a comment
There was a problem hiding this comment.
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.- Cause:
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*). - Fix: expose one
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/ENOTDIR match FreeBSD fchdir, the chdir refactor keeps resolution and update under one lock, and the TechnicalDebt line is in place.
|
Rebased the fix onto current
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. |
a1732d1 to
714f609
Compare
714f609 to
1aa2343
Compare
FreeBSD fchdir(2) changes the working directory to the directory referenced by a descriptor. The guest imports fchdir from libkernel_sys (PPSA99764, issue boykopovar#1578) and the module did not export it. The descriptor's directory is resolved from the path recorded when the directory was opened on Windows, and from the /proc/self/fd link target on Linux. The guest working directory is then set through the libc routine shared with chdir. A descriptor that is not open returns EBADF and one that is not a directory returns ENOTDIR. AI-assisted: yes (cherry picked from commit 76329cb)
1aa2343 to
1a73d01
Compare
adriadam10
left a comment
There was a problem hiding this comment.
Checked on current main: patched_libraries, guest_kernel_sys and guest_working_directory pass, libkernel_sys.prx now loads, and guest_kernel_sys fails to link without the change. The C-ABI helpers fix the earlier undefined symbol; merging.
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 implementsfchdir