fix(libkernel): read the APR resolver paths and write its outputs through guest copies #21585

Merged
milescoviello merged 4 commits from upstream-pr/21585 into main 2026-11-17 17:16:13 +00:00
milescoviello commented 2026-11-16 12:57:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-11-16T12:57:01Z.


What

The APR path resolvers touched most of their guest arguments in place:

  • sceKernelAprResolveFilepathsToIds handed each paths[index] pointer straight to ResolvePath, which reads the string in place, wrote ids[index] through _resolve, and stored *error_index directly.
  • The two ...AndFileSizes forms and the four ...ForEach forms read paths[index] and built std::string(prefix) + paths[index] in place. The ForEach forms also wrote ids, sizes and results directly.

So an unreadable paths table, path or prefix, or an unwritable output array, crashed the host. Three forms already copied their outputs out (AndFileSizes, WithPrefixToIdsAndFileSizes, WithPrefixToIds); their inputs did not.

Now all eight forms go through two helpers, _resolveAll (stop at the first miss, error_index) and _resolveForEach (resolve every path, results):

  • The prefix is copied once with CopyGuestPath_nid_no_patch.
  • Each table element is read with GuestCopyIn_nid_no_patch as the loop reaches it, and each path is copied with CopyGuestPath_nid_no_patch.
  • ids, sizes, results and error_index are written with GuestCopyOut_nid_no_patch.
  • An unreadable element, path or prefix, or an unwritable output, fails with EFAULT at that index; the indices before it were already written, as before. A path or prefix past the 1024-byte path limit resolves to nothing, like a missing file.

What stays the same: the EINVAL checks for null prefix, paths, ids and sizes, a null element counting as a missing file at its own index, the invalid id and size 0 in a failing slot, error_index left untouched on success, the stop at the first miss, the ForEach return count, and the plain prefix concatenation. These are what the "APR resolve argument checks and prefix join" debt entry describes. A new debt entry records the EFAULT fallback.

What changes besides the checked copies: a path or prefix longer than 1024 bytes (the guest PATH_MAX, from CopyGuestPath_nid_no_patch) now resolves to nothing, as a missing file does, where before it was passed through in full. The debt entry records this.

Tested

Linux (Ubuntu 26.04.1, kernel 7.0), GCC 15.2, Ninja, Release, -DBUILD_TESTING=ON:

  • guest_ampr_markers (the guest_ampr_tests binary) gains nine cases in TestResolveFailures. Each returns -1 with the guest errno at EFAULT (14):
    • an unmapped (0x10) paths table;
    • an unmapped path element, for the ForEach and AndFileSizes forms;
    • an unmapped prefix, for WithPrefixToIds and WithPrefixToIdsForEach;
    • an unmapped ids, sizes or results array;
    • an unmapped error_index, where the missing second path still gets the invalid id before the fault.
  • guest_ampr_markers passes, 3 runs of 3.
  • Negative control: with main's Apr.cpp and the new cases, guest_ampr_markers ends in fatal SIGSEGV (code 1) at address 0x0000000000000010.
  • tools/check_conventions.py passes on the branch and this body. The fragment folds; tools/debt_fold.py --check fails only on main's own docs-nkwebkit-drop-readded-count-lines.md, which #21458, #21512 and #21531 fix.

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:5337398171 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21585). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-11-16T12:57:01Z. --- ### What The APR path resolvers touched most of their guest arguments in place: - `sceKernelAprResolveFilepathsToIds` handed each `paths[index]` pointer straight to `ResolvePath`, which reads the string in place, wrote `ids[index]` through `_resolve`, and stored `*error_index` directly. - The two `...AndFileSizes` forms and the four `...ForEach` forms read `paths[index]` and built `std::string(prefix) + paths[index]` in place. The `ForEach` forms also wrote `ids`, `sizes` and `results` directly. So an unreadable `paths` table, path or prefix, or an unwritable output array, crashed the host. Three forms already copied their outputs out (`AndFileSizes`, `WithPrefixToIdsAndFileSizes`, `WithPrefixToIds`); their inputs did not. Now all eight forms go through two helpers, `_resolveAll` (stop at the first miss, `error_index`) and `_resolveForEach` (resolve every path, `results`): - The prefix is copied once with `CopyGuestPath_nid_no_patch`. - Each table element is read with `GuestCopyIn_nid_no_patch` as the loop reaches it, and each path is copied with `CopyGuestPath_nid_no_patch`. - `ids`, `sizes`, `results` and `error_index` are written with `GuestCopyOut_nid_no_patch`. - An unreadable element, path or prefix, or an unwritable output, fails with `EFAULT` at that index; the indices before it were already written, as before. A path or prefix past the 1024-byte path limit resolves to nothing, like a missing file. What stays the same: the `EINVAL` checks for null `prefix`, `paths`, `ids` and `sizes`, a null element counting as a missing file at its own index, the invalid id and size 0 in a failing slot, `error_index` left untouched on success, the stop at the first miss, the `ForEach` return count, and the plain prefix concatenation. These are what the "APR resolve argument checks and prefix join" debt entry describes. A new debt entry records the `EFAULT` fallback. What changes besides the checked copies: a path or prefix longer than 1024 bytes (the guest `PATH_MAX`, from `CopyGuestPath_nid_no_patch`) now resolves to nothing, as a missing file does, where before it was passed through in full. The debt entry records this. ### Tested Linux (Ubuntu 26.04.1, kernel 7.0), GCC 15.2, Ninja, Release, `-DBUILD_TESTING=ON`: - `guest_ampr_markers` (the `guest_ampr_tests` binary) gains nine cases in `TestResolveFailures`. Each returns -1 with the guest `errno` at `EFAULT` (14): - an unmapped (`0x10`) `paths` table; - an unmapped path element, for the `ForEach` and `AndFileSizes` forms; - an unmapped prefix, for `WithPrefixToIds` and `WithPrefixToIdsForEach`; - an unmapped `ids`, `sizes` or `results` array; - an unmapped `error_index`, where the missing second path still gets the invalid id before the fault. - `guest_ampr_markers` passes, 3 runs of 3. - Negative control: with `main`'s `Apr.cpp` and the new cases, `guest_ampr_markers` ends in `fatal SIGSEGV (code 1) at address 0x0000000000000010`. - `tools/check_conventions.py` passes on the branch and this body. The fragment folds; `tools/debt_fold.py --check` fails only on `main`'s own `docs-nkwebkit-drop-readded-count-lines.md`, which #21458, #21512 and #21531 fix. ### Checklist - [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-16 13:01:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-16T13:01:04Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_ampr_tests built cleanly.
  • CTest (guest_ampr_markers):
    1/1 Test #3271: guest_ampr_markers ...............   Passed    2.56 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libkernel/Apr/src/Apr.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #3271: guest_ampr_markers ...............***Exception: SegFault  3.21 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • core/libs/prx/libkernel/Apr/src/Apr.cpp: verified _copyPrefix, _entryPath, and _store use CopyGuestPath_nid_no_patch, GuestCopyIn_nid_no_patch, and GuestCopyOut_nid_no_patch to validate guest pointers and return GUEST_EFAULT (14) on bad addresses
    • core/libs/prx/libkernel/Apr/src/Apr.cpp: verified _resolveAll and _resolveForEach preserve null argument validation (GUEST_EINVAL), null entry handling, INVALID_FILE_ID (0xFFFFFFFFu) and size=0 fallback on unresolved paths, and SCE_KERNEL_ERROR_ENOENT / GUEST_ENOENT error reporting
    • core/libs/prx/libkernel/Apr/src/Apr.cpp: verified non-EFAULT errors from CopyGuestPath_nid_no_patch (e.g., ENAMETOOLONG) set prefix.fits = false or leave path empty so the entry fails resolution with ENOENT as documented in the technical debt fragment
    • docs/dev/debt/changes/fix-libkernel-apr-resolve-guest-copies.md: verified technical debt fragment accurately documents the host-safety fallback behavior for APR resolver guest pointers
    • core/libs/tests/GuestAmpr.cpp: verified TestResolveFailures tests unreadable paths table, unreadable path entry, unreadable prefix, and unwritable ids, sizes, results, and error_index pointers, cleaning up paths[0] afterward

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5920368803 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21585#pullrequestreview-5920368803). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-16T13:01:04Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `3299b61e76`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_ampr_tests` built cleanly. - **CTest** (`guest_ampr_markers`): ``` 1/1 Test #3271: guest_ampr_markers ............... Passed 2.56 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libkernel/Apr/src/Apr.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #3271: guest_ampr_markers ...............***Exception: SegFault 3.21 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - core/libs/prx/libkernel/Apr/src/Apr.cpp: verified _copyPrefix, _entryPath, and _store use CopyGuestPath_nid_no_patch, GuestCopyIn_nid_no_patch, and GuestCopyOut_nid_no_patch to validate guest pointers and return GUEST_EFAULT (14) on bad addresses - core/libs/prx/libkernel/Apr/src/Apr.cpp: verified _resolveAll and _resolveForEach preserve null argument validation (GUEST_EINVAL), null entry handling, INVALID_FILE_ID (0xFFFFFFFFu) and size=0 fallback on unresolved paths, and SCE_KERNEL_ERROR_ENOENT / GUEST_ENOENT error reporting - core/libs/prx/libkernel/Apr/src/Apr.cpp: verified non-EFAULT errors from CopyGuestPath_nid_no_patch (e.g., ENAMETOOLONG) set prefix.fits = false or leave path empty so the entry fails resolution with ENOENT as documented in the technical debt fragment - docs/dev/debt/changes/fix-libkernel-apr-resolve-guest-copies.md: verified technical debt fragment accurately documents the host-safety fallback behavior for APR resolver guest pointers - core/libs/tests/GuestAmpr.cpp: verified TestResolveFailures tests unreadable paths table, unreadable path entry, unreadable prefix, and unwritable ids, sizes, results, and error_index pointers, cleaning up paths[0] afterward Looks Good To Me
MarcZX10 commented 2026-11-16 13:21:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T13:21:46Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the implementation and added fault cases support merging.

What I ran

Reviewed head 3299b61e768816cb074958430c19b2952fda6cad. I read the prepared diff and all three changed files, then checked the affected APR wrappers and guest string-copy helper at the pinned head. I did not run commands or tests.

Results

Check Result Note
Changed-file review passed Three changed files read
Tests not run Author reports Linux runs
Negative control not run Author reports a SIGSEGV

Findings

Blocking

None.

Non-blocking

None.

Sources

Not verified

No checks were run. Test and negative-control results in the description are author-reported. files.json was unavailable; the manifest and review-folder listing show three changed files, all included and read. No other changed files were excluded.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5920649848 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21585#pullrequestreview-5920649848). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-16T13:21:46Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the implementation and added fault cases support merging. ## What I ran Reviewed head `3299b61e768816cb074958430c19b2952fda6cad`. I read the prepared diff and all three changed files, then checked the affected APR wrappers and guest string-copy helper at the pinned head. I did not run commands or tests. ## Results | Check | Result | Note | |---|---|---| | Changed-file review | passed | Three changed files read | | Tests | not run | Author reports Linux runs | | Negative control | not run | Author reports a SIGSEGV | ## Findings ### Blocking None. ### Non-blocking None. ## Sources - [Apr.cpp at reviewed head](https://github.com/boykopovar/AnyPS5/blob/3299b61e768816cb074958430c19b2952fda6cad/core/libs/prx/libkernel/Apr/src/Apr.cpp) - [GuestAmpr.cpp at reviewed head](https://github.com/boykopovar/AnyPS5/blob/3299b61e768816cb074958430c19b2952fda6cad/core/libs/tests/GuestAmpr.cpp) - [APR debt entry at reviewed head](https://github.com/boykopovar/AnyPS5/blob/3299b61e768816cb074958430c19b2952fda6cad/docs/dev/debt/changes/fix-libkernel-apr-resolve-guest-copies.md) ## Not verified No checks were run. Test and negative-control results in the description are author-reported. `files.json` was unavailable; the manifest and review-folder listing show three changed files, all included and read. No other changed files were excluded. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-17 13:25:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T13:25:09Z.

Review: APPROVED


Reviewed — looks good

The eight sceKernelAprResolveFilepaths* forms now read and write guest memory through checked copies, and the code I read is sound. Nothing blocks this; the points below are optional.

Head reviewed: 421155f04d47a4927523d801c55ee2fcd198fa4b.

What I ran

No build and no test binary in this review. I read the changed code at the head and the callers it touches, using repo_read.py:

repo_read.py search CopyGuestPath_nid_no_patch
repo_read.py cat core/libs/prx/libc/src/General.cpp 586 606

Files read: core/libs/prx/libkernel/Apr/src/Apr.cpp (changed hunks, the four ForEach callers at lines 1055–1070), core/libs/tests/GuestAmpr.cpp (changed hunk and the setup it relies on, lines 776–826), and docs/dev/debt/changes/fix-libkernel-apr-resolve-guest-copies.md. Files excluded by rule: none. Files reviewed: 3 of 3 read.

Results

Check Result Note
Read review of changed code passed No blocking defect found
Build and guest_ampr_markers not run No build in this review
Author's test run (3 of 3) not run Author report only
Negative control on main not run Author report only

Findings

Blocking

None.

Non-blocking

  • core/libs/prx/libkernel/Apr/src/Apr.cpp:171 and :179: a path or prefix over 1024 bytes now resolves to nothing, like a missing file. Before this change it was passed through in full. The debt entry records this, but the description's "What stays the same" list does not. Worth one line in the PR body so the behaviour change is visible.
  • core/libs/tests/GuestAmpr.cpp:809: auto** const unreadableTable deduces const char** correctly, but const char** const unreadableTable says the same thing more plainly.
  • core/libs/tests/GuestAmpr.cpp:809–826: no new case covers the over-long path or prefix that the debt entry describes. A test with a 1025-byte path would pin that behaviour.

Not verified

  • The build, and the new guest_ampr_markers cases, were not run here. The 3-of-3 passes and the main negative control (SIGSEGV at 0x10) are the author's reports.
  • What the console does with unmapped pointers is not measured; the debt entry says so as well.
  • CopyGuestString_nid_no_patch was not read. The 1024 limit and the return codes (0, Fault, 63 for unterminated) are taken from CopyGuestPath_nid_no_patch and its test in GuestKernelSys.cpp.
  • tools/check_conventions.py and tools/debt_fold.py --check were not run.
  • The ForEach forms were checked only through their callers at Apr.cpp:1055–1070; their argument checks were not re-read beyond those lines.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5939282853 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21585#pullrequestreview-5939282853). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-17T13:25:09Z. **Review:** APPROVED --- # Reviewed — looks good The eight `sceKernelAprResolveFilepaths*` forms now read and write guest memory through checked copies, and the code I read is sound. Nothing blocks this; the points below are optional. Head reviewed: `421155f04d47a4927523d801c55ee2fcd198fa4b`. ## What I ran No build and no test binary in this review. I read the changed code at the head and the callers it touches, using `repo_read.py`: ``` repo_read.py search CopyGuestPath_nid_no_patch repo_read.py cat core/libs/prx/libc/src/General.cpp 586 606 ``` Files read: `core/libs/prx/libkernel/Apr/src/Apr.cpp` (changed hunks, the four `ForEach` callers at lines 1055–1070), `core/libs/tests/GuestAmpr.cpp` (changed hunk and the setup it relies on, lines 776–826), and `docs/dev/debt/changes/fix-libkernel-apr-resolve-guest-copies.md`. Files excluded by rule: none. Files reviewed: 3 of 3 read. ## Results | Check | Result | Note | |---|---|---| | Read review of changed code | passed | No blocking defect found | | Build and `guest_ampr_markers` | not run | No build in this review | | Author's test run (3 of 3) | not run | Author report only | | Negative control on `main` | not run | Author report only | ## Findings **Blocking** None. **Non-blocking** - `core/libs/prx/libkernel/Apr/src/Apr.cpp:171` and `:179`: a path or prefix over 1024 bytes now resolves to nothing, like a missing file. Before this change it was passed through in full. The debt entry records this, but the description's "What stays the same" list does not. Worth one line in the PR body so the behaviour change is visible. - `core/libs/tests/GuestAmpr.cpp:809`: `auto** const unreadableTable` deduces `const char**` correctly, but `const char** const unreadableTable` says the same thing more plainly. - `core/libs/tests/GuestAmpr.cpp:809–826`: no new case covers the over-long path or prefix that the debt entry describes. A test with a 1025-byte path would pin that behaviour. ## Not verified - The build, and the new `guest_ampr_markers` cases, were not run here. The 3-of-3 passes and the `main` negative control (SIGSEGV at `0x10`) are the author's reports. - What the console does with unmapped pointers is not measured; the debt entry says so as well. - `CopyGuestString_nid_no_patch` was not read. The 1024 limit and the return codes (`0`, `Fault`, `63` for unterminated) are taken from `CopyGuestPath_nid_no_patch` and its test in `GuestKernelSys.cpp`. - `tools/check_conventions.py` and `tools/debt_fold.py --check` were not run. - The `ForEach` forms were checked only through their callers at `Apr.cpp:1055–1070`; their argument checks were not re-read beyond those lines. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-17 15:32:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T15:32:54Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this; the points below are optional.

What I ran

Head 436d2fe349bc099a7fb486ab3884538f04e2e2ff, base main. Static review only: I read diff.patch in full, then the head code around the changed helpers and their callers through repo_read.py. I did not build or run any test.

python3 repo_read.py search CopyGuestPath_nid_no_patch core/libs
python3 repo_read.py search GUEST_EFAULT core/libs
python3 repo_read.py cat core/libs/prx/libc/src/General.cpp 588 615
python3 repo_read.py cat core/libs/prx/libkernel/Apr/src/Apr.cpp 40 60
python3 repo_read.py cat core/libs/prx/libkernel/Apr/src/Apr.cpp 966 1100
python3 repo_read.py cat core/libs/tests/GuestAmpr.cpp 780 808

Results

Check Result Note
Diff read in full passed 3 files
Callers at head passed All eight forms reach the two helpers
Guest errno values passed EFAULT 14, ENOENT 2, EINVAL 22
Build and guest_ampr_markers not run Author-reported only
Negative control not run Author-reported only
check_conventions.py, debt_fold.py not run Author-reported only

Findings

Blocking

None.

Non-blocking

  1. Apr.cpp:195 and Apr.cpp:221: both helpers copy the prefix before the loop, so with count 0 an unreadable prefix now returns EFAULT. The old code returned 0 without reading it. This is not in the list of changes in the description. The smallest fix is to copy the prefix only when count is greater than 0, or to list the case in the debt entry.
  2. Apr.cpp:161: PathPrefix::present is set at Apr.cpp:167 and never read. _entryPath uses only fits and text. Remove the field and its assignment.

Sources

Not verified

  • The build, the guest_ampr_markers run, the negative control, and check_conventions.py and debt_fold.py are author-reported. I did not run them.
  • The console behaviour for the EFAULT fallback. The debt entry says it is not measured, and I did not check it.
  • Performance. Each path now costs one guest copy-in, one copy into a new std::string, and a separate copy-out per output. Startup resolves thousands of paths (comment at Apr.cpp:60). Not measured.
  • The 1024-byte limit relies on CopyGuestString_nid_no_patch returning a non-zero code for an over-long string. I read only the call in General.cpp:588-590, not its body. The existing GuestKernelSys test expects 63 for an unterminated string, which fits a non-zero code.
  • The debt file location docs/dev/debt/changes/ and the "APR resolve argument checks and prefix join" entry were not checked against the repository's convention or existing debt files.
  • The presence of validate_review_body.py was not checked, so it was not run.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5941441680 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21585#pullrequestreview-5941441680). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-17T15:32:54Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this; the points below are optional. ## What I ran Head `436d2fe349bc099a7fb486ab3884538f04e2e2ff`, base `main`. Static review only: I read `diff.patch` in full, then the head code around the changed helpers and their callers through `repo_read.py`. I did not build or run any test. ``` python3 repo_read.py search CopyGuestPath_nid_no_patch core/libs python3 repo_read.py search GUEST_EFAULT core/libs python3 repo_read.py cat core/libs/prx/libc/src/General.cpp 588 615 python3 repo_read.py cat core/libs/prx/libkernel/Apr/src/Apr.cpp 40 60 python3 repo_read.py cat core/libs/prx/libkernel/Apr/src/Apr.cpp 966 1100 python3 repo_read.py cat core/libs/tests/GuestAmpr.cpp 780 808 ``` ## Results | Check | Result | Note | |---|---|---| | Diff read in full | passed | 3 files | | Callers at head | passed | All eight forms reach the two helpers | | Guest errno values | passed | EFAULT 14, ENOENT 2, EINVAL 22 | | Build and `guest_ampr_markers` | not run | Author-reported only | | Negative control | not run | Author-reported only | | `check_conventions.py`, `debt_fold.py` | not run | Author-reported only | ## Findings ### Blocking None. ### Non-blocking 1. `Apr.cpp:195` and `Apr.cpp:221`: both helpers copy the prefix before the loop, so with `count` 0 an unreadable prefix now returns `EFAULT`. The old code returned 0 without reading it. This is not in the list of changes in the description. The smallest fix is to copy the prefix only when `count` is greater than 0, or to list the case in the debt entry. 2. `Apr.cpp:161`: `PathPrefix::present` is set at `Apr.cpp:167` and never read. `_entryPath` uses only `fits` and `text`. Remove the field and its assignment. ## Sources - Helpers: https://github.com/boykopovar/AnyPS5/blob/436d2fe349bc099a7fb486ab3884538f04e2e2ff/core/libs/prx/libkernel/Apr/src/Apr.cpp#L157-L229 - New test cases: https://github.com/boykopovar/AnyPS5/blob/436d2fe349bc099a7fb486ab3884538f04e2e2ff/core/libs/tests/GuestAmpr.cpp#L809-L838 - Path copy limit: https://github.com/boykopovar/AnyPS5/blob/436d2fe349bc099a7fb486ab3884538f04e2e2ff/core/libs/prx/libc/src/General.cpp#L588-L590 ## Not verified - The build, the `guest_ampr_markers` run, the negative control, and `check_conventions.py` and `debt_fold.py` are author-reported. I did not run them. - The console behaviour for the `EFAULT` fallback. The debt entry says it is not measured, and I did not check it. - Performance. Each path now costs one guest copy-in, one copy into a new `std::string`, and a separate copy-out per output. Startup resolves thousands of paths (comment at `Apr.cpp:60`). Not measured. - The 1024-byte limit relies on `CopyGuestString_nid_no_patch` returning a non-zero code for an over-long string. I read only the call in `General.cpp:588-590`, not its body. The existing `GuestKernelSys` test expects 63 for an unterminated string, which fits a non-zero code. - The debt file location `docs/dev/debt/changes/` and the "APR resolve argument checks and prefix join" entry were not checked against the repository's convention or existing debt files. - The presence of `validate_review_body.py` was not checked, so it was not run. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-17 16:32:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T16:32:36Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this; the points below are optional.

What I ran

  • Head 6665f8219e65a0dd9760235733013e78cedbd9b0, base main.
  • Read the diff of the three changed files, then the head code they call, with the repository reader:
repo_read.py search "sceKernelAprResolveFilepaths" core/libs/prx/libkernel/Apr/src/Apr.cpp
repo_read.py search "CopyGuestPath_nid_no_patch" core/libs
repo_read.py cat core/libs/prx/libc/src/General.cpp 559 615
repo_read.py cat core/libs/prx/libkernel/Apr/src/Apr.cpp 150 160
repo_read.py cat core/libs/prx/libkernel/Apr/src/Apr.cpp 1052 1071
repo_read.py cat core/libs/tests/GuestAmpr.cpp 776 812
  • No build and no test run: the initial review checks do not build.

Results

Check Result Note
Diff read passed 3 of 3 files
Build and unit tests not run No builds in this review
Hosted checks on head not run Status not available here
Convention checker not run Author-reported
Author-reported results (not reproduced here)
  • guest_ampr_markers, 3 runs of 3, passed.
  • Negative control with main's Apr.cpp: fatal SIGSEGV at address 0x10.
  • tools/check_conventions.py passed; tools/debt_fold.py --check fails only on a main fragment.

Findings

Blocking

None.

Non-blocking

  1. core/libs/prx/libkernel/Apr/src/Apr.cpp:169: _copyPrefix sets fits = error == 0, so every non-EFAULT error means "does not fit". CopyGuestString_nid_no_patch also returns 12 when its buffer allocation fails (core/libs/prx/libc/src/General.cpp:565-567). A failed allocation would then resolve to nothing, like a missing file, instead of returning ENOMEM. _entryPath has the same pattern at Apr.cpp:180. Smallest fix: return ENOMEM when the error is 12.
  2. core/libs/tests/GuestAmpr.cpp:831: the new "too long" cases cover WithPrefixToIds and ToIds only. The ForEach and AndFileSizes forms share _resolveForEach and _resolveAll, which now resolve an over-long path to nothing, and no test checks that.

Not verified

  • The build, the GuestAmpr runs and the negative control are author-reported and were not run here.
  • Hosted checks on head 6665f8219e65: status unknown to me. Formal approval waits for them to pass.
  • tools/check_conventions.py and tools/debt_fold.py were not run. The debt fragment's heading was not compared with other fragments.
  • Read in part: Apr.cpp (the diff hunks, the head helpers, the ForEach wrappers and search hits for the other forms) and GuestAmpr.cpp (the diff and lines 776-812). The rest of each file was not read.
  • Performance: each table element goes through a path copy that allocates a 1024-byte buffer (General.cpp:564). The cost is not measured.
  • Console behaviour for these pointers: the debt entry says it is not measured, and this review does not measure it either.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5942463017 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21585#pullrequestreview-5942463017). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-17T16:32:36Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this; the points below are optional. ## What I ran - Head `6665f8219e65a0dd9760235733013e78cedbd9b0`, base `main`. - Read the diff of the three changed files, then the head code they call, with the repository reader: ``` repo_read.py search "sceKernelAprResolveFilepaths" core/libs/prx/libkernel/Apr/src/Apr.cpp repo_read.py search "CopyGuestPath_nid_no_patch" core/libs repo_read.py cat core/libs/prx/libc/src/General.cpp 559 615 repo_read.py cat core/libs/prx/libkernel/Apr/src/Apr.cpp 150 160 repo_read.py cat core/libs/prx/libkernel/Apr/src/Apr.cpp 1052 1071 repo_read.py cat core/libs/tests/GuestAmpr.cpp 776 812 ``` - No build and no test run: the initial review checks do not build. ## Results | Check | Result | Note | |---|---|---| | Diff read | passed | 3 of 3 files | | Build and unit tests | not run | No builds in this review | | Hosted checks on head | not run | Status not available here | | Convention checker | not run | Author-reported | <details> <summary>Author-reported results (not reproduced here)</summary> - `guest_ampr_markers`, 3 runs of 3, passed. - Negative control with `main`'s `Apr.cpp`: `fatal SIGSEGV at address 0x10`. - `tools/check_conventions.py` passed; `tools/debt_fold.py --check` fails only on a `main` fragment. </details> ## Findings ### Blocking None. ### Non-blocking 1. `core/libs/prx/libkernel/Apr/src/Apr.cpp:169`: `_copyPrefix` sets `fits = error == 0`, so every non-EFAULT error means "does not fit". `CopyGuestString_nid_no_patch` also returns 12 when its buffer allocation fails (`core/libs/prx/libc/src/General.cpp:565-567`). A failed allocation would then resolve to nothing, like a missing file, instead of returning ENOMEM. `_entryPath` has the same pattern at `Apr.cpp:180`. Smallest fix: return ENOMEM when the error is 12. 2. `core/libs/tests/GuestAmpr.cpp:831`: the new "too long" cases cover `WithPrefixToIds` and `ToIds` only. The `ForEach` and `AndFileSizes` forms share `_resolveForEach` and `_resolveAll`, which now resolve an over-long path to nothing, and no test checks that. ## Not verified - The build, the GuestAmpr runs and the negative control are author-reported and were not run here. - Hosted checks on head `6665f8219e65`: status unknown to me. Formal approval waits for them to pass. - `tools/check_conventions.py` and `tools/debt_fold.py` were not run. The debt fragment's heading was not compared with other fragments. - Read in part: `Apr.cpp` (the diff hunks, the head helpers, the `ForEach` wrappers and search hits for the other forms) and `GuestAmpr.cpp` (the diff and lines 776-812). The rest of each file was not read. - Performance: each table element goes through a path copy that allocates a 1024-byte buffer (`General.cpp:564`). The cost is not measured. - Console behaviour for these pointers: the debt entry says it is not measured, and this review does not measure it either. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-17 16:49:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T16:49:18Z.

Review: COMMENTED


fix(libkernel): read the APR resolver paths and write its outputs through guest copies — no blocking findings

Nothing blocks this; the points below are optional.

What I ran

  • Head 97c8dd2f5adacf4deda6100ae93cf684a22ac1c4, base main.
  • No build and no test run in this review. I read the diff and used read-only reader searches and line ranges at the head.

Results

Check Result Note
Build not run No build in this review
guest_ampr_markers tests not run Author-reported only
Diff read passed All three changed files, every hunk
Helper signatures passed CopyGuestPath_nid_no_patch, GuestCopyIn_nid_no_patch, GuestCopyOut_nid_no_patch match their call sites
Call sites passed All eight sceKernelAprResolveFilepaths* forms go through _resolveAll or _resolveForEach

Findings

Blocking

None.

Non-blocking

None in the code I read.

Not verified

  • Compilation of the changed C++ and the GuestAmpr.cpp test run. The 3-of-3 pass and the SIGSEGV negative control are the author's report, not my run.
  • The 1024-byte limit of CopyGuestPath_nid_no_patch (core/libs/prx/libc/src/General.cpp, line 588) was not read. The new tests and the debt entry assume it.
  • Console behaviour on unmapped pointers. The debt entry already says this is unmeasured, and I did not check it.
  • The debt entry heading (## add Unknown function info) against the debt conventions in docs/dev/CONVENTIONS.md.

Files read: core/libs/prx/libkernel/Apr/src/Apr.cpp, core/libs/tests/GuestAmpr.cpp, docs/dev/debt/changes/fix-libkernel-apr-resolve-guest-copies.md. Files excluded: none.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5942744078 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21585#pullrequestreview-5942744078). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-17T16:49:18Z. **Review:** COMMENTED --- # fix(libkernel): read the APR resolver paths and write its outputs through guest copies — no blocking findings Nothing blocks this; the points below are optional. ## What I ran - Head `97c8dd2f5adacf4deda6100ae93cf684a22ac1c4`, base `main`. - No build and no test run in this review. I read the diff and used read-only reader searches and line ranges at the head. ## Results | Check | Result | Note | |---|---|---| | Build | not run | No build in this review | | `guest_ampr_markers` tests | not run | Author-reported only | | Diff read | passed | All three changed files, every hunk | | Helper signatures | passed | `CopyGuestPath_nid_no_patch`, `GuestCopyIn_nid_no_patch`, `GuestCopyOut_nid_no_patch` match their call sites | | Call sites | passed | All eight `sceKernelAprResolveFilepaths*` forms go through `_resolveAll` or `_resolveForEach` | ## Findings ### Blocking None. ### Non-blocking None in the code I read. ## Not verified - Compilation of the changed C++ and the `GuestAmpr.cpp` test run. The 3-of-3 pass and the SIGSEGV negative control are the author's report, not my run. - The 1024-byte limit of `CopyGuestPath_nid_no_patch` (`core/libs/prx/libc/src/General.cpp`, line 588) was not read. The new tests and the debt entry assume it. - Console behaviour on unmapped pointers. The debt entry already says this is unmeasured, and I did not check it. - The debt entry heading (`## add Unknown function info`) against the debt conventions in `docs/dev/CONVENTIONS.md`. Files read: `core/libs/prx/libkernel/Apr/src/Apr.cpp`, `core/libs/tests/GuestAmpr.cpp`, `docs/dev/debt/changes/fix-libkernel-apr-resolve-guest-copies.md`. Files excluded: none. ## To get this to a good state Nothing is required.
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!21585
No description provided.