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

Closed
opened 2026-10-11 05:33:09 +00:00 by sktharunbalaji13-cmd · 0 comments
sktharunbalaji13-cmd commented 2026-10-11 05:33:09 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by sktharunbalaji13-cmd on 2026-10-11T05:33:09Z.


fchdir (NID gnyVA6Tj-ak) is missing from libkernel_sys, and PPSA99764 Porpoise imports it. Issue #1578 lists Porpoise's missing libkernel_sys imports as chroot, fchdir, pathconf, and #1578 comment #44 confirms the module split ("libkernel and libkernel_sys are separate modules; exporting it from libkernel did not resolve this import"), so fchdir has to be exported from libkernel_sys.

Bug fixes in the same directory/file area keep landing, but no open issue or PR implements fchdir (a title/body search returns only #1578).

A ready, self-contained implementation following the conventions (one commit, no code comments outside TechnicalDebt, a TechnicalDebt entry, no third-party code):

What

  • fchdir_nid_postfix(int) in core/libs/prx/libkernel_sys/Export.cpp: sets the guest working directory to the descriptor's directory. Returns EBADF for a descriptor that is not open and ENOTDIR for one that is not a directory, following FreeBSD fchdir(2).
  • The guest cwd update is factored into SetWorkingDirectory_nid_no_patch, shared with chdir; the refactor is behaviour-neutral (same guest errno values, chdir unchanged).
  • File::DirectoryDescriptorPath becomes cross-platform: the path recorded when the directory was opened on Windows, and the /proc/self/fd link target on Linux.

Tested

Windows 11, WinLibs MinGW-w64 GCC 15.2.0, Ninja, Release:

  • guest_kernel_sys_tests and the related directory/filesystem targets build; ctest for guest_kernel_sys, guest_access, guest_working_directory, guest_realpath, guest_path_case, guest_directory, guest_filesystem, guest_directory_buffer, guest_directory_close — 9 passed, 0 failed.
  • nid_patcher export verified: libkernel_sys.prx exposes gnyVA6Tj-ak (= fchdir).
  • Stubbing fchdir makes guest_kernel_sys fail and restoring it makes it pass, so the new cases are a real regression guard.

Linux (WSL Ubuntu 24.04, GCC 13.3.0, CMake 3.28.3, Ninja 1.11.1):

  • Linux libkernel_sys (including the /proc/self/fd branch) builds.
  • guest_kernel_sys, guest_working_directory, guest_realpath, guest_directory, guest_filesystem, guest_access, guest_path_case all pass (7/7) when run from an ext4 filesystem.
  • Caveat: with the ctest working directory on /mnt/c (drvfs), guest_access and guest_path_case abort; the same binaries pass from /tmp (ext4). This is a WSL drvfs artifact of this machine (permission/case-sensitivity), and neither test is affected by the changed files. A full Linux suite and a baseline differential were not run.

Limitations (also recorded in TechnicalDebt): FreeBSD change_dir's search-permission check (EACCES) is not modelled, a directory renamed after it was opened is still reached through the recorded path, and console behaviour is unverified.

tools/check_conventions.py --base origin/main and tools/check_test_registration.py pass. tools/pr_overlap.py --branch reports one overlap: #3160 (fork/setsid/umask) also edits core/libs/tests/GuestKernelSys.cpp. It implements different functions; the overlap is limited to the shared test file and would be resolved by a rebase.

Request

PR intake currently requires 10 merged PRs into main and this account has 2 (.github/workflows/pr-intake.yml, minimumMergedPRs = 10), so I did not open a PR to avoid an automatic close. Would a maintainer be able to carry the commit, or sponsor reopening a PR for it? I am happy to rebase onto current main and re-run the tests first.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5798303311 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3288). Originally posted by [sktharunbalaji13-cmd](https://github.com/sktharunbalaji13-cmd) on 2026-10-11T05:33:09Z. --- `fchdir` (NID `gnyVA6Tj-ak`) is missing from `libkernel_sys`, and PPSA99764 Porpoise imports it. Issue #1578 lists Porpoise's missing `libkernel_sys` imports as `chroot`, `fchdir`, `pathconf`, and #1578 comment #44 confirms the module split ("`libkernel` and `libkernel_sys` are separate modules; exporting it from `libkernel` did not resolve this import"), so `fchdir` has to be exported from `libkernel_sys`. Bug fixes in the same directory/file area keep landing, but no open issue or PR implements `fchdir` (a title/body search returns only #1578). A ready, self-contained implementation following the conventions (one commit, no code comments outside TechnicalDebt, a TechnicalDebt entry, no third-party code): - Branch: [`sktharunbalaji13-cmd:contrib/libkernel-sys-fchdir`](https://github.com/sktharunbalaji13-cmd/AnyPS5/tree/contrib/libkernel-sys-fchdir) - Commit: `76329cbb08781e13d757c3ff955acf71f8bd506f` ### What - `fchdir_nid_postfix(int)` in `core/libs/prx/libkernel_sys/Export.cpp`: sets the guest working directory to the descriptor's directory. Returns `EBADF` for a descriptor that is not open and `ENOTDIR` for one that is not a directory, following FreeBSD `fchdir(2)`. - The guest cwd update is factored into `SetWorkingDirectory_nid_no_patch`, shared with `chdir`; the refactor is behaviour-neutral (same guest errno values, `chdir` unchanged). - `File::DirectoryDescriptorPath` becomes cross-platform: the path recorded when the directory was opened on Windows, and the `/proc/self/fd` link target on Linux. ### Tested Windows 11, WinLibs MinGW-w64 GCC 15.2.0, Ninja, Release: - `guest_kernel_sys_tests` and the related directory/filesystem targets build; `ctest` for `guest_kernel_sys`, `guest_access`, `guest_working_directory`, `guest_realpath`, `guest_path_case`, `guest_directory`, `guest_filesystem`, `guest_directory_buffer`, `guest_directory_close` — 9 passed, 0 failed. - `nid_patcher` export verified: `libkernel_sys.prx` exposes `gnyVA6Tj-ak` (= `fchdir`). - Stubbing `fchdir` makes `guest_kernel_sys` fail and restoring it makes it pass, so the new cases are a real regression guard. Linux (WSL Ubuntu 24.04, GCC 13.3.0, CMake 3.28.3, Ninja 1.11.1): - Linux `libkernel_sys` (including the `/proc/self/fd` branch) builds. - `guest_kernel_sys`, `guest_working_directory`, `guest_realpath`, `guest_directory`, `guest_filesystem`, `guest_access`, `guest_path_case` all pass (7/7) when run from an ext4 filesystem. - Caveat: with the ctest working directory on `/mnt/c` (drvfs), `guest_access` and `guest_path_case` abort; the same binaries pass from `/tmp` (ext4). This is a WSL drvfs artifact of this machine (permission/case-sensitivity), and neither test is affected by the changed files. A full Linux suite and a baseline differential were not run. Limitations (also recorded in TechnicalDebt): FreeBSD `change_dir`'s search-permission check (`EACCES`) is not modelled, a directory renamed after it was opened is still reached through the recorded path, and console behaviour is unverified. `tools/check_conventions.py --base origin/main` and `tools/check_test_registration.py` pass. `tools/pr_overlap.py --branch` reports one overlap: **#3160** (`fork`/`setsid`/`umask`) also edits `core/libs/tests/GuestKernelSys.cpp`. It implements different functions; the overlap is limited to the shared test file and would be resolved by a rebase. ### Request PR intake currently requires 10 merged PRs into `main` and this account has 2 (`.github/workflows/pr-intake.yml`, `minimumMergedPRs = 10`), so I did not open a PR to avoid an automatic close. Would a maintainer be able to carry the commit, or sponsor reopening a PR for it? I am happy to rebase onto current `main` and re-run the tests first. AI-assisted: yes
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#3288
No description provided.