feat(libkernel_sys): implement profil argument checks #11026

Merged
Gruzzberry merged 1 commit from upstream-pr/11026 into main 2026-10-27 07:18:37 +00:00
Gruzzberry commented 2026-10-25 14:25:25 +00:00 (Migrated from github.com)

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


What

profil was a throwing stub in libkernel_sys. FreeBSD 11.4's sys_profil fails with EINVAL when scale is above 1 << 16, stops profiling and returns 0 when scale is 0, and otherwise records the buffer and starts the profiling clock. It never reads the samples pointer at call time; the clock does that on each tick.

profil in libkernel_sys now returns EINVAL for a scale above 1 << 16 and 0 for a scale of 0 (profiling is never on, so there is nothing to stop). A non-zero scale still throws NotImplemented_nid_no_patch, because the profiling clock that fills the sample buffer is not modelled. The declaration in Api.hpp now carries the real four arguments.

Tested

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

  • guest_kernel_sys: scale of (1 << 16) + 1 and 0xFFFFFFFF give -1 with EINVAL; scale 0 returns 0 with a null buffer and with the unreadable address 0x10 (the pointer is not dereferenced). On main the test does not build against the stub, which takes no arguments; with this change it passes 3 runs out of 3. The non-zero scale throw is not asserted.
  • Full suite on this branch and on main: the same tests fail on both under load (pr_overlap_encoding, public_headers, agc_import_settle_initial_dcc, agc_host_import_cut_lifetime, agc_driver_depth_plane_partial_store, audio_out2_timing, guest_job_manager_failures, guest_pthread_start, guest_pthread_rwlock, guest_select, guest_mutex_contention, guest_named_shm_windows_short_temp); guest_ampr_threads fails intermittently on both (0 of 4 on main, 3 of 4 here). No build failures on either.
  • python tools/check_conventions.py --base upstream/main: passes.
  • Not tested: Linux, a console, a title run.

Overlaps

  • Line overlaps from tools/pr_overlap.py: #9156 (neighbouring stub in Export.Discovery.cpp), #9389 (Export.cpp L335) and #10421 (GuestKernelSys.cpp L532). Proposed on each that it goes first and this PR rebases.
  • The earlier head of this PR also carried a swapon implementation by mistake. That is removed; swapon is only in #11034.

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: #9156; merge order: after #9156, #9389 and #10421 (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:5005588534 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11026). Originally posted by [Gruzzberry](https://github.com/Gruzzberry) on 2026-10-25T14:25:25Z. --- ### What `profil` was a throwing stub in libkernel_sys. FreeBSD 11.4's [`sys_profil`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/subr_prof.c) fails with `EINVAL` when `scale` is above `1 << 16`, stops profiling and returns 0 when `scale` is 0, and otherwise records the buffer and starts the profiling clock. It never reads the `samples` pointer at call time; the clock does that on each tick. `profil` in libkernel_sys now returns `EINVAL` for a `scale` above `1 << 16` and 0 for a `scale` of 0 (profiling is never on, so there is nothing to stop). A non-zero `scale` still throws `NotImplemented_nid_no_patch`, because the profiling clock that fills the sample buffer is not modelled. The declaration in `Api.hpp` now carries the real four arguments. ### Tested Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, `-DBUILD_TESTING=ON`. - `guest_kernel_sys`: `scale` of `(1 << 16) + 1` and `0xFFFFFFFF` give `-1` with `EINVAL`; `scale` 0 returns 0 with a null buffer and with the unreadable address `0x10` (the pointer is not dereferenced). On `main` the test does not build against the stub, which takes no arguments; with this change it passes 3 runs out of 3. The non-zero `scale` throw is not asserted. - Full suite on this branch and on `main`: the same tests fail on both under load (`pr_overlap_encoding`, `public_headers`, `agc_import_settle_initial_dcc`, `agc_host_import_cut_lifetime`, `agc_driver_depth_plane_partial_store`, `audio_out2_timing`, `guest_job_manager_failures`, `guest_pthread_start`, `guest_pthread_rwlock`, `guest_select`, `guest_mutex_contention`, `guest_named_shm_windows_short_temp`); `guest_ampr_threads` fails intermittently on both (0 of 4 on `main`, 3 of 4 here). No build failures on either. - `python tools/check_conventions.py --base upstream/main`: passes. - Not tested: Linux, a console, a title run. ### Overlaps - Line overlaps from `tools/pr_overlap.py`: #9156 (neighbouring stub in `Export.Discovery.cpp`), #9389 (`Export.cpp` L335) and #10421 (`GuestKernelSys.cpp` L532). Proposed on each that it goes first and this PR rebases. - The earlier head of this PR also carried a `swapon` implementation by mistake. That is removed; `swapon` is only in #11034. ### 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: #9156; merge order: after #9156, #9389 and #10421 (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:31:22 +00:00 (Migrated from github.com)

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

Review: DISMISSED


Requesting changes for an unrelated implementation included in this profil PR. The diff also removes the swapon stub from Export.Discovery.cpp, adds a four-argument swapon declaration, implements path validation and host filesystem checks for swapon in Export.cpp, and adds GuestEnotblk. None of this is described in the PR's What/Test sections, has no tests here, and is a separate API topic. This conflicts with the repository's one-topic-per-PR rule.

Please remove the swapon changes from this branch; if that behavior is still wanted, submit it as a separate change after checking overlap and documenting/testing its contract. The profil portion itself follows FreeBSD 11.4's scale limit and scale-zero behavior (sys_profil): https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/subr_prof.c#L1988-L2025. The local and hosted product jobs are skipped, so I have not independently run the reported Windows test.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643675370 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11026#pullrequestreview-5643675370). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T14:31:22Z. **Review:** DISMISSED --- Requesting changes for an unrelated implementation included in this `profil` PR. The diff also removes the `swapon` stub from `Export.Discovery.cpp`, adds a four-argument `swapon` declaration, implements path validation and host filesystem checks for `swapon` in `Export.cpp`, and adds `GuestEnotblk`. None of this is described in the PR's What/Test sections, has no tests here, and is a separate API topic. This conflicts with the repository's one-topic-per-PR rule. Please remove the `swapon` changes from this branch; if that behavior is still wanted, submit it as a separate change after checking overlap and documenting/testing its contract. The `profil` portion itself follows FreeBSD 11.4's scale limit and scale-zero behavior (`sys_profil`): https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/subr_prof.c#L1988-L2025. The local and hosted product jobs are skipped, so I have not independently run the reported Windows test.
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!11026
No description provided.