fix(libkernel): stage Windows APR reads through host memory #6449

Merged
Izamaru merged 1 commit from upstream-pr/6449 into main 2026-10-19 01:17:26 +00:00
Izamaru commented 2026-10-15 16:00:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Izamaru on 2026-10-15T16:00:25Z.


What

On Windows, read APR file data into a bounded 64 KiB host buffer and copy it into the destination in user mode. A direct stream read can fail when writing the destination needs the process's page-fault handler; the CPU copy can take that handler. Keep the existing HostWrite protection checks, short-read validation and zero-fill at EOF. Other platforms keep their existing read path.

Add synthetic tests for large and unaligned reads, host and direct-memory destinations, chunk boundaries, EOF, missing files, unseekable offsets and read-only guest memory. The Windows regression reserves a destination and commits its pages through a vectored handler on CPU writes. With the original APR implementation from main 0029e62f974c453a5f6c7333f3bdb13e770e3903, that case fails with an APR read error; with this change it passes. All file contents are generated by the test.

Tested

Windows x86-64, supported MinGW-w64 GCC 15.2.0, Release:

  • Built libc, libkernel, libSceAmpr and the test targets using the normal project CMake configuration.
  • 8/8 native cases passed: five guest_apr_read_* cases plus guest_ampr_markers, guest_ampr_threads and guest_ampr_cpp_error.
  • 27/27 Python test-registration tests passed.
  • Conventions and diff whitespace checks passed.
  • Linux and macOS were not run. No game files, credentials, local logs or binaries are included.

To run after configuring with BUILD_TESTING=ON as described in docs/dev/BUILD.md:

cmake --build build --target guest_apr_read_tests guest_ampr_tests guest_ampr_threads_tests guest_ampr_cpp_error_tests --parallel 4
ctest --test-dir build -R '^(guest_apr_read_.*|guest_ampr_(markers|threads|cpp_error))$' --output-on-failure

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
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation 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: none
  • Unblocks: none; synthetic regression only
  • GPUs tested: n/a; libkernel CPU file-read change
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4876128613 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6449). Originally posted by [Izamaru](https://github.com/Izamaru) on 2026-10-15T16:00:25Z. --- ### What On Windows, read APR file data into a bounded 64 KiB host buffer and copy it into the destination in user mode. A direct stream read can fail when writing the destination needs the process's page-fault handler; the CPU copy can take that handler. Keep the existing `HostWrite` protection checks, short-read validation and zero-fill at EOF. Other platforms keep their existing read path. Add synthetic tests for large and unaligned reads, host and direct-memory destinations, chunk boundaries, EOF, missing files, unseekable offsets and read-only guest memory. The Windows regression reserves a destination and commits its pages through a vectored handler on CPU writes. With the original APR implementation from main `0029e62f974c453a5f6c7333f3bdb13e770e3903`, that case fails with an APR read error; with this change it passes. All file contents are generated by the test. ### Tested Windows x86-64, supported MinGW-w64 GCC 15.2.0, Release: - Built `libc`, `libkernel`, `libSceAmpr` and the test targets using the normal project CMake configuration. - 8/8 native cases passed: five `guest_apr_read_*` cases plus `guest_ampr_markers`, `guest_ampr_threads` and `guest_ampr_cpp_error`. - 27/27 Python test-registration tests passed. - Conventions and diff whitespace checks passed. - Linux and macOS were not run. No game files, credentials, local logs or binaries are included. To run after configuring with `BUILD_TESTING=ON` as described in `docs/dev/BUILD.md`: ```sh cmake --build build --target guest_apr_read_tests guest_ampr_tests guest_ampr_threads_tests guest_ampr_cpp_error_tests --parallel 4 ctest --test-dir build -R '^(guest_apr_read_.*|guest_ampr_(markers|threads|cpp_error))$' --output-on-failure ``` ### 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 - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation 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: none - [x] Unblocks: none; synthetic regression only - [x] GPUs tested: n/a; libkernel CPU file-read change - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-15 16:37:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T16:37:03Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 4972 core/libs/prx/libkernel/CMakeLists.txt
PR 5021 core/libs/prx/libkernel/CMakeLists.txt
PR 6044 core/libs/prx/libkernel/CMakeLists.txt
PR 6226 core/libs/prx/libkernel/CMakeLists.txt
PR 6487 core/libs/prx/libkernel/CMakeLists.txt
PR 6908 core/libs/prx/libkernel/CMakeLists.txt
PR 6936 core/libs/prx/libkernel/CMakeLists.txt
PR 6977 core/libs/prx/libkernel/CMakeLists.txt
PR 7129 core/libs/prx/libkernel/CMakeLists.txt
PR 7192 core/libs/prx/libkernel/CMakeLists.txt
PR 7201 core/libs/prx/libkernel/CMakeLists.txt
PR 7332 core/libs/prx/libkernel/CMakeLists.txt
PR 7450 core/libs/prx/libkernel/CMakeLists.txt
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6197187643 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6449#issuecomment-6197187643). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T16:37:03Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 4972](https://www.github.com/boykopovar/AnyPS5/pull/4972) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6226](https://www.github.com/boykopovar/AnyPS5/pull/6226) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6487](https://www.github.com/boykopovar/AnyPS5/pull/6487) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6908](https://www.github.com/boykopovar/AnyPS5/pull/6908) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6936](https://www.github.com/boykopovar/AnyPS5/pull/6936) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 7129](https://www.github.com/boykopovar/AnyPS5/pull/7129) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 7192](https://www.github.com/boykopovar/AnyPS5/pull/7192) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 7450](https://www.github.com/boykopovar/AnyPS5/pull/7450) | `core/libs/prx/libkernel/CMakeLists.txt` |
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!6449
No description provided.