feat(libkernel_sys): implement swapon #11034

Merged
Gruzzberry merged 1 commit from upstream-pr/11034 into main 2026-11-09 22:54:05 +00:00
Gruzzberry commented 2026-10-25 14:38:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-10-25T14:38:38Z.


What

swapon was a throwing stub in libkernel_sys. FreeBSD 11.4's sys_swapon (after the PRIV_SWAPON check, which a root guest passes) looks the name up and hands a vnode to swapongeom only if vn_isdisk accepts it; otherwise it fails with ENOTBLK. Here the name is copied with CopyGuestPath_nid_no_patch (an unreadable pointer fails with EFAULT, an empty name with ENOENT), and a path of 1024 bytes or more or a component over 255 gives ENAMETOOLONG. The lookup then goes through the guest stat, so it follows symbolic links as namei with FOLLOW does: a missing path or a dangling link gives ENOENT, a path through a file ENOTDIR, and any existing file or directory, directly or through a link, ENOTBLK. A host character or block device throws std::runtime_error, as nothing here backs swap space. The new debt entry records that PRIV_SWAPON for titles is unverified.

Tested

Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, -DBUILD_TESTING=ON, on main 7a25f87620.

  • guest_kernel_sys: new checks next to the chroot ones for a null name and the unreadable address 0x10 (EFAULT), "" and a missing path (ENOENT), a path through a file (ENOTDIR), a 256-byte component and a 1024-byte path (ENAMETOOLONG), a file and a directory (ENOTBLK), and, with Windows symbolic links, a link to a file and a link to a directory (ENOTBLK) and a dangling link (ENOENT). The earlier head of this PR gave ENOTBLK for the dangling link, because MinGW's std::filesystem::status does not see Windows links. With the body reverted to the stub the test crashes (0xc0000409); with this change it passes, three runs out of three.
  • Full suite on main and on this branch: the only differences are agc_driver_bda_device, agc_driver_depth_clear_hle and guest_ampr_threads, which fail under ctest -j 12 on the branch but pass alone three times out of three, and agc_driver_depth_plane_partial_store, which fails on main too.
  • python tools/check_conventions.py --base upstream/main: passes.
  • Not tested: Linux, a console, a title run.

Overlaps

  • #9161 (statfs/symlinkat) removes the neighbouring stubs in Export.Discovery.cpp and include/Api.hpp and adds code at Export.cpp L534-535, and #10799 edits libkernel_sys.md debt L40: proposed on each that it goes first and this PR rebases.
  • #11031 (getfsstat, mine) adds a debt entry at the same place: #11031 goes first, then this PR rebases.
  • #9379 (swapcontext) has merged and this branch is rebased on it. #11026 no longer contains swapon, so this is the only PR implementing it.

Checklist

  • Based on current main; no other open PR implements the same function
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source: none added
  • Generic behaviour, not specific to one title
  • Depends on: #9161; merge order: after #9161, #10799 and #11031 (neighbouring lines)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5005683093 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11034). Originally posted by [Gruzzberry](https://github.com/Gruzzberry) on 2026-10-25T14:38:38Z. --- ### What `swapon` was a throwing stub in libkernel_sys. FreeBSD 11.4's [`sys_swapon`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/vm/swap_pager.c) (after the `PRIV_SWAPON` check, which a root guest passes) looks the name up and hands a vnode to `swapongeom` only if `vn_isdisk` accepts it; otherwise it fails with `ENOTBLK`. Here the name is copied with `CopyGuestPath_nid_no_patch` (an unreadable pointer fails with `EFAULT`, an empty name with `ENOENT`), and a path of 1024 bytes or more or a component over 255 gives `ENAMETOOLONG`. The lookup then goes through the guest `stat`, so it follows symbolic links as `namei` with `FOLLOW` does: a missing path or a dangling link gives `ENOENT`, a path through a file `ENOTDIR`, and any existing file or directory, directly or through a link, `ENOTBLK`. A host character or block device throws `std::runtime_error`, as nothing here backs swap space. The new debt entry records that `PRIV_SWAPON` for titles is unverified. ### Tested Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, `-DBUILD_TESTING=ON`, on `main` 7a25f87620. - `guest_kernel_sys`: new checks next to the `chroot` ones for a null name and the unreadable address `0x10` (`EFAULT`), `""` and a missing path (`ENOENT`), a path through a file (`ENOTDIR`), a 256-byte component and a 1024-byte path (`ENAMETOOLONG`), a file and a directory (`ENOTBLK`), and, with Windows symbolic links, a link to a file and a link to a directory (`ENOTBLK`) and a dangling link (`ENOENT`). The earlier head of this PR gave `ENOTBLK` for the dangling link, because MinGW's `std::filesystem::status` does not see Windows links. With the body reverted to the stub the test crashes (`0xc0000409`); with this change it passes, three runs out of three. - Full suite on `main` and on this branch: the only differences are `agc_driver_bda_device`, `agc_driver_depth_clear_hle` and `guest_ampr_threads`, which fail under `ctest -j 12` on the branch but pass alone three times out of three, and `agc_driver_depth_plane_partial_store`, which fails on `main` too. - `python tools/check_conventions.py --base upstream/main`: passes. - Not tested: Linux, a console, a title run. ### Overlaps - #9161 (`statfs`/`symlinkat`) removes the neighbouring stubs in `Export.Discovery.cpp` and `include/Api.hpp` and adds code at `Export.cpp` L534-535, and #10799 edits `libkernel_sys.md` debt L40: proposed on each that it goes first and this PR rebases. - #11031 (`getfsstat`, mine) adds a debt entry at the same place: #11031 goes first, then this PR rebases. - #9379 (`swapcontext`) has merged and this branch is rebased on it. #11026 no longer contains `swapon`, so this is the only PR implementing it. ### Checklist - [x] Based on current `main`; no other open PR implements the same function - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); no silent stubs added - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source: none added - [x] Generic behaviour, not specific to one title - [x] Depends on: #9161; merge order: after #9161, #10799 and #11031 (neighbouring lines) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-25 14:39:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T14:39:03Z.

Review: DISMISSED


Requesting a fix to the open-PR overlap before this can be merged. #11026 is still open and its current diff also implements swapon_nid_postfix, changes the same declaration/stub, and adds tests for the same path errors. That means this PR’s checklist claim that no open PR implements swapon is currently inaccurate, and the duplicate symbols/file edits cannot both merge unchanged. CONTRIBUTING.md requires checking same-function open PRs and agreeing merge order for overlapping work. Please coordinate with the #11026 author so that PR is reduced to its profil topic, then update this PR’s overlap/checklist evidence; there is no need to close either PR. The focused Windows results are author-reported, and the hosted product tests are skipped, so I have not independently verified runtime behavior at this head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643699439 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11034#pullrequestreview-5643699439). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T14:39:03Z. **Review:** DISMISSED --- Requesting a fix to the open-PR overlap before this can be merged. #11026 is still open and its current diff also implements `swapon_nid_postfix`, changes the same declaration/stub, and adds tests for the same path errors. That means this PR’s checklist claim that no open PR implements `swapon` is currently inaccurate, and the duplicate symbols/file edits cannot both merge unchanged. CONTRIBUTING.md requires checking same-function open PRs and agreeing merge order for overlapping work. Please coordinate with the #11026 author so that PR is reduced to its `profil` topic, then update this PR’s overlap/checklist evidence; there is no need to close either PR. The focused Windows results are author-reported, and the hosted product tests are skipped, so I have not independently verified runtime behavior at this head.
Sign in to join this conversation.
No reviewers
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!11034
No description provided.