fix(libkernel): answer sysarch XFPUSTATE's measured errors and empty copy, as a PS5 does #22046

Merged
brajankw merged 1 commit from upstream-pr/22046 into main 2026-12-03 19:29:14 +00:00
brajankw commented 2026-11-17 03:06:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by brajankw on 2026-11-17T03:06:23Z.


What

sysarch threw for any non-null XFPUSTATE argument (operations 11 and 132). On a PS5 (firmware 12.70) operation 132 rejected lengths 1024 to 8192 with EINVAL and null arguments and addresses with EFAULT, and accepted lengths 0, 64, 128, 256 and 512 (the sysarch entry in docs/dev/debt/libkernel.md).

Following FreeBSD 11.4's order (copy the arguments in, compare the length unsigned, copy the state out):

  • an unreadable argument gives EFAULT, including one whose last bytes are unreadable: operation 11 copies in 8 bytes and 132 copies in 16;
  • a length from 1024 gives EINVAL;
  • length 0 returns 0 without copying;
  • a null address with a length up to 512 gives EFAULT.

Lengths 513 to 1023, whose limit was not measured, and copying out the live state still throw. GuestSysarch.cpp covers both operations; the pending sysarch debt fragment from #22039 is updated here, as both change the same entry. It keeps the 13.60 LDT wording that 136484585e added.

Tested

Linux (Debian 13, GCC 14.2.0, Release). Head 3d354f3678, rebased onto main 11c9e7764e without conflicts. The runs after the first two bullets are from earlier heads.

  • At 3d354f3678, merged with #22013 and #22049 onto main 11c9e7764e: ctest -R '^(guest_sysarch|guest_memory|guest_mmap_fixed_anonymous|guest_virtual_query_arguments|np_uds_events|guest_np_uds_.*|guest_np_trophy_.*)$': 16 passed, and guest_mmap_executable skipped itself (exit 77) in this environment. This head adds Helldiverr's three pins: an unreadable argument (0x10) for both operations, length 512 with a null address, and an argument at the end of a readable page.
  • Mutations, each caught by guest_sysarch: operation 132 copying in 12 bytes instead of 16; EINVAL instead of EFAULT for an unreadable argument, for each operation; throwing from length 512.
  • ctest -R '^guest_sysarch$': passed.
  • Negative control: with #22039's Process.cpp and this branch's test, guest_sysarch aborts at the first XFPUSTATE length check, which throws there.
  • Full ctest (5896 tests, -j 12) with this branch and my other twelve branches of this round merged onto main 521fb7fec4: 5880 passed. The 16 failures are the set that fails on main in the same environment: six agc_driver cases (agc_driver_image_table_packed_guards passes when run on its own) and ten that need a .git directory, network or a passwd entry for the user.
  • python3 tools/check_conventions.py --base origin/main: passed.
  • python3 tools/pr_overlap.py --branch at 3d354f3678: no conflicting pull request. #18190, which conflicts with main, shares Process.cpp and could not be compared; it renames exports and does not change sysarch's XFPUSTATE handling.
  • Not tested on Windows or macOS. No title.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5349752517 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22046). Originally posted by [brajankw](https://github.com/brajankw) on 2026-11-17T03:06:23Z. --- ### What `sysarch` threw for any non-null XFPUSTATE argument (operations 11 and 132). On a PS5 (firmware 12.70) operation 132 rejected lengths 1024 to 8192 with `EINVAL` and null arguments and addresses with `EFAULT`, and accepted lengths 0, 64, 128, 256 and 512 (the `sysarch` entry in `docs/dev/debt/libkernel.md`). Following FreeBSD 11.4's order (copy the arguments in, compare the length unsigned, copy the state out): - an unreadable argument gives `EFAULT`, including one whose last bytes are unreadable: operation 11 copies in 8 bytes and 132 copies in 16; - a length from 1024 gives `EINVAL`; - length 0 returns 0 without copying; - a null address with a length up to 512 gives `EFAULT`. Lengths 513 to 1023, whose limit was not measured, and copying out the live state still throw. `GuestSysarch.cpp` covers both operations; the pending `sysarch` debt fragment from #22039 is updated here, as both change the same entry. It keeps the 13.60 LDT wording that 136484585e added. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Linux (Debian 13, GCC 14.2.0, Release). Head `3d354f3678`, rebased onto `main` `11c9e7764e` without conflicts. The runs after the first two bullets are from earlier heads. - At `3d354f3678`, merged with #22013 and #22049 onto `main` `11c9e7764e`: `ctest -R '^(guest_sysarch|guest_memory|guest_mmap_fixed_anonymous|guest_virtual_query_arguments|np_uds_events|guest_np_uds_.*|guest_np_trophy_.*)$'`: 16 passed, and `guest_mmap_executable` skipped itself (exit 77) in this environment. This head adds Helldiverr's three pins: an unreadable argument (0x10) for both operations, length 512 with a null address, and an argument at the end of a readable page. - Mutations, each caught by `guest_sysarch`: operation 132 copying in 12 bytes instead of 16; `EINVAL` instead of `EFAULT` for an unreadable argument, for each operation; throwing from length 512. - `ctest -R '^guest_sysarch$'`: passed. - Negative control: with #22039's `Process.cpp` and this branch's test, `guest_sysarch` aborts at the first XFPUSTATE length check, which throws there. - Full `ctest` (5896 tests, `-j 12`) with this branch and my other twelve branches of this round merged onto `main` `521fb7fec4`: 5880 passed. The 16 failures are the set that fails on `main` in the same environment: six `agc_driver` cases (`agc_driver_image_table_packed_guards` passes when run on its own) and ten that need a `.git` directory, network or a passwd entry for the user. - `python3 tools/check_conventions.py --base origin/main`: passed. - `python3 tools/pr_overlap.py --branch` at `3d354f3678`: no conflicting pull request. #18190, which conflicts with `main`, shares `Process.cpp` and could not be compared; it renames exports and does not change `sysarch`'s XFPUSTATE handling. - Not tested on Windows or macOS. No title. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [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) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
PrivacyOnion commented 2026-11-17 03:14:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T03:14:21Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against b8db0447b8:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_sysarch_tests built cleanly.
  • CTest (guest_sysarch):
    1/1 Test #5359: guest_sysarch ....................   Passed    0.03 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libkernel/System/src/Process.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #5359: guest_sysarch ....................Subprocess aborted***Exception:   0.41 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified ExtendedFpuState in Process.cpp:1054-1076 handles both i386GetXfpustate (11) and AMD64 getxfpustate (132) argument unpacking via GuestCopyIn_nid_no_patch, correctly reporting EFAULT on bad guest pointers
    • Verified boundary conditions for length: length >= 1024 returns EINVAL (-1 with errno 22), length == 0 returns 0 without copying, and length > 512 throws NotImplemented_nid_no_patch
    • Verified address validation: null address (0) with non-zero length <= 512 correctly returns EFAULT (-1 with errno 14) via SysarchFailure(guestFault)
    • Verified integration into sysarch: xfpuStateOperations check dispatches correctly prior to default unimplemented operations, preserving FreeBSD semantics and conventions
    • Verified AGENTS.md compliance, debt fragment tracking in docs/dev/debt/changes/fix-libkernel-sysarch-ldt-ioperm-gsbase.md, and test coverage in GuestSysarch.cpp

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5932177203 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22046#pullrequestreview-5932177203). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-17T03:14:21Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `b8db0447b8`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_sysarch_tests` built cleanly. - **CTest** (`guest_sysarch`): ``` 1/1 Test #5359: guest_sysarch .................... Passed 0.03 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libkernel/System/src/Process.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #5359: guest_sysarch ....................Subprocess aborted***Exception: 0.41 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified ExtendedFpuState in Process.cpp:1054-1076 handles both i386GetXfpustate (11) and AMD64 getxfpustate (132) argument unpacking via GuestCopyIn_nid_no_patch, correctly reporting EFAULT on bad guest pointers - Verified boundary conditions for length: length >= 1024 returns EINVAL (-1 with errno 22), length == 0 returns 0 without copying, and length > 512 throws NotImplemented_nid_no_patch - Verified address validation: null address (0) with non-zero length <= 512 correctly returns EFAULT (-1 with errno 14) via SysarchFailure(guestFault) - Verified integration into sysarch: xfpuStateOperations check dispatches correctly prior to default unimplemented operations, preserving FreeBSD semantics and conventions - Verified AGENTS.md compliance, debt fragment tracking in docs/dev/debt/changes/fix-libkernel-sysarch-ldt-ioperm-gsbase.md, and test coverage in GuestSysarch.cpp Looks Good To Me
MarcZX10 commented 2026-11-23 03:57:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T03:57:27Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the inspected implementation follows the documented measured behavior and adds coverage for both operation layouts.

What I ran

Reviewed head be0bcdc4cafbd0ca72e3e2f15b2467b44df383b7. I did not run commands or tests. Read description.md, commits.md, manifest.json, diff.patch, README.md, and all changed lines in Process.cpp, GuestSysarch.cpp, and the debt fragment using the pinned reader.

Results

Check Result Note
Patch and changed lines passed All changed lines inspected
Automated checks not run No test commands executed

Findings

Blocking

None.

Non-blocking

None.

Not verified

Tests and the author's reported test results were not independently verified. Windows, macOS, and physical-console behavior were not tested during this review. Unchanged portions of the changed files were not read.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6016390612 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22046#pullrequestreview-6016390612). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T03:57:27Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the inspected implementation follows the documented measured behavior and adds coverage for both operation layouts. ## What I ran Reviewed head `be0bcdc4cafbd0ca72e3e2f15b2467b44df383b7`. I did not run commands or tests. Read `description.md`, `commits.md`, `manifest.json`, `diff.patch`, `README.md`, and all changed lines in `Process.cpp`, `GuestSysarch.cpp`, and the debt fragment using the pinned reader. ## Results | Check | Result | Note | |---|---|---| | Patch and changed lines | passed | All changed lines inspected | | Automated checks | not run | No test commands executed | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified Tests and the author's reported test results were not independently verified. Windows, macOS, and physical-console behavior were not tested during this review. Unchanged portions of the changed files were not read. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-25 11:36:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T11:36:41Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; its measured XFPUSTATE cases and deliberately unimplemented cases are handled consistently with the stated behavior.

What I ran

Reviewed head 3d354f3678db0debd914f58cedd2a24828e1eb27. I read the prepared description, commits, manifest, diff, and all three changed files listed as reviewed. I did not run commands or tests; the test results in the description are author-reported.

Results

Check Result Note
Diff and changed code passed Three changed files read
Tests in this review not run Description reports prior runs

Findings

Blocking

None.

Non-blocking

None.

Not verified

I did not independently verify PS5 firmware behavior, run the reported tests, or inspect excluded files. The listed changed files were all included and read; files.json was unavailable as a review document, and the manifest lists no excluded changed files.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6056890849 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22046#pullrequestreview-6056890849). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-25T11:36:41Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; its measured XFPUSTATE cases and deliberately unimplemented cases are handled consistently with the stated behavior. ## What I ran Reviewed head `3d354f3678db0debd914f58cedd2a24828e1eb27`. I read the prepared description, commits, manifest, diff, and all three changed files listed as reviewed. I did not run commands or tests; the test results in the description are author-reported. ## Results | Check | Result | Note | |---|---|---| | Diff and changed code | passed | Three changed files read | | Tests in this review | not run | Description reports prior runs | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified I did not independently verify PS5 firmware behavior, run the reported tests, or inspect excluded files. The listed changed files were all included and read; `files.json` was unavailable as a review document, and the manifest lists no excluded changed files. ## To get this to a good state Nothing is required.
ligmaSec commented 2026-12-03 12:59:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T12:59:27Z.

Review: COMMENTED


Built the branch’s changed sources and ran GuestSysarch on Linux against the existing runtime libraries. The test run passed and covered the XFPUSTATE argument and empty-copy cases.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6170277714 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22046#pullrequestreview-6170277714). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T12:59:27Z. **Review:** COMMENTED --- Built the branch’s changed sources and ran GuestSysarch on Linux against the existing runtime libraries. The test run passed and covered the XFPUSTATE argument and empty-copy cases. AI-assisted: yes.
Plyxen commented 2026-12-03 14:08:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-03T14:08:23Z.

Review: APPROVED


I read the diff at 3d354f3678. Windows 11 with GCC 15.2 and Linux (Ubuntu 24.04 in WSL2, GCC 13.3), merged into main at 6c6b29320fe together with other open PRs (so not an isolated build).

  • guest_sysarch: pass on both.
  • Control (the same tree with only this PR's source change taken out): on Windows it stops with "sysarch: operation 132 not implemented". On Linux, with the changed sources of the tested CPU PRs put back to main's, the same test fails too.

Not checked: a console.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6171379930 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22046#pullrequestreview-6171379930). Originally posted by [Plyxen](https://github.com/Plyxen) on 2026-12-03T14:08:23Z. **Review:** APPROVED --- I read the diff at `3d354f3678`. Windows 11 with GCC 15.2 and Linux (Ubuntu 24.04 in WSL2, GCC 13.3), merged into `main` at `6c6b29320fe` together with other open PRs (so not an isolated build). - `guest_sysarch`: pass on both. - Control (the same tree with only this PR's source change taken out): on Windows it stops with "sysarch: operation 132 not implemented". On Linux, with the changed sources of the tested CPU PRs put back to `main`'s, the same test fails too. Not checked: a console. AI-assisted: yes (Claude Code)
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!22046
No description provided.