Skip to content

feat(libkernel_sys): implement fchdir - #3392

Merged
adriadam10 merged 3 commits into
boykopovar:mainfrom
MarcZX10:codex/fchdir-3288
Oct 11, 2026
Merged

adriadam10 merged 3 commits into
boykopovar:mainfrom
MarcZX10:codex/fchdir-3288

Conversation

@MarcZX10

@MarcZX10 MarcZX10 commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

What

Implements fchdir in libkernel_sys for 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 return EBADF; open non-directory descriptors return ENOTDIR.

The original implementation commit by Tharun Balaji is preserved with its author attribution. Follow-up commits keep chdir resolution 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 main 99c1c26347:

  • Built the full libs target and the affected test executables.
  • patched_libraries, guest_kernel_sys, guest_access, guest_working_directory, guest_realpath, guest_path_case, guest_directory, and guest_filesystem each passed three consecutive runs (24 test executions).
  • tools/check_conventions.py --base upstream/main and git diff --check passed.

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

  • Based on current main; no open PR implements fchdir
  • One topic; no comments added to code
  • No silent stubs, third-party code, investigation notes, or images added
  • Generic behavior; limitations are recorded in TechnicalDebt
  • Depends on: none
  • AI-assisted: yes

@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Progress report (99c1c26 → 1a73d01)

➖ System libraries: 85.76% (+0.0%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel_sys fchdir_nid_postfix

@github-actions github-actions Bot mentioned this pull request Oct 11, 2026
9 tasks done

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking this up. One blocker:

  • patched_libraries fails on this head: libkernel_sys.prx: undefined symbol: _Z29DescriptorIsOpen_nid_no_patchi (core/libs/prx/libkernel_sys/Export.cpp:73). guest_kernel_sys passes only because the test links the libraries statically, but the real libkernel_sys.prx doesn't load, so fchdir would not resolve in a title.
  • Cause: DescriptorIsOpen_nid_no_patch (File.hpp) and File::DirectoryDescriptorPath (DirectoryDescriptor.hpp, used at Export.cpp:74) are plain C++ symbols, not extern "C" exports. Cross-library _nid_no_patch helpers are extern "C" (like ResolvePath_nid_no_patch), and their signatures should avoid C++ types where possible (SetWorkingDirectory_nid_no_patch takes const std::filesystem::path& in an extern "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 from fchdir; then run ctest -R patched_libraries to 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.

@MarcZX10

MarcZX10 commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Rebased the fix onto current main (99c1c26347); the updated head is 1a73d0165.

  • libkernel exposes a C-linkage helper that validates the descriptor and directory, then returns a UTF-8 path or POSIX EBADF / ENOTDIR. libkernel_sys no longer imports C++-mangled descriptor helpers.
  • SetWorkingDirectory_nid_no_patch takes a C string and converts UTF-8 inside libc.
  • I rebuilt the full libs target and affected test executables. patched_libraries, guest_kernel_sys, guest_access, guest_working_directory, guest_realpath, guest_path_case, guest_directory, and guest_filesystem each passed three consecutive runs (24 passes total). Conventions and git diff --check pass.

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.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 11, 2026
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 11, 2026
sktharunbalaji13-cmd and others added 3 commits October 11, 2026 10:26
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)

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@adriadam10
adriadam10 merged commit 03a84d0 into boykopovar:main Oct 11, 2026
15 checks passed
@babyhuey babyhuey mentioned this pull request Oct 11, 2026
9 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

libkernel_sys: implement fchdir (PPSA99764); branch and commit ready

3 participants