feat(libSceAmpr): record and execute native file reads #19060
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/19060"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by mjnhbg3 on 2026-11-12T18:08:54Z.
What
Record
sceAmprAprCommandBufferReadFileusing the SDK's 20/24-byte native packet, and execute that format in APR. Previously this export wrote a private 40-byte record and could expand the caller's buffer; APR rejected native packets as malformed. The size query now has its verified four-argument ABI and reports 20 or 24 bytes, or the native invalid-argument result. Other host command formats and their existing execution paths remain supported.Recording follows numeric validation, null buffer/base, capacity and command-count checks in the observed order. It preserves base/capacity, reports EBUSY without expanding a full buffer, ignores the two state pointers, masks the file ID to 31 bits, and preserves the SDK's packet-copy/count/cursor/flags mutation order even when command memory overlaps the descriptor. Unreadable or unwritable required memory throws through NotImplemented_nid_no_patch; native fault delivery and partial-fault effects are not claimed. The decoder checks header bits, packet extent and destination range before using the existing file-transfer and ReadCursor path. Native kernel scheduling, EOF and completion semantics retain their documented limits.
Evidence comes from the user's local PPSA02530 PRAGMATA 01.300.000 dump: unwrapped libSceAmpr.sprx SHA-256 a99e1a04a6b8eedf9f36478bcac4137770666390606ca141fd748c2ef79c3622. ReadFile NID mQ16-QdKv7k is at 0x2e6d0, forwarding through 0x9e30 to size helper 0x282d0 and encoder 0x28610 (ReadFile arms 0x28568 and 0x28d29). Measure NID vWU-odnS+fU at 0x2f750 takes file ID, destination, size and offset, returning uint32. PRAGMATA calls ReadFile through its wrapper at 0x9dd1a0 (call 0x9dd1bf to PLT 0x8fc5200); wrapper transfers at 0x9dcbbf, 0x9dcd59 and 0x82313f1 establish static use in file loading. It does not import the measure helper. No title-boot or speed improvement is claimed.
The local reference harness executes the unchanged SDK instructions with supplied stack-canary pointer (GOT 0x44220), memcpy import (0x442d0), and stack-failure hook (0x44258). This is local SDK verification, not console measurement or full module initialization. Historical validation at
9ec953f1c38fc1264e9a354c41ba9b222704afee: SDK and fixed host each passed 149,776 calls: 74,896 recorder and 74,880 measure calls. The matrix covers all 65,536 recording-flag values, numeric and capacity/count boundaries, 4,096 deterministic random inputs, 784 descriptor overlaps, ignored unreadable state pointers and page-boundary/error-precedence cases. Whole descriptor/backing bytes and rejection preservation are compared. Seven additional host-only inaccessible-memory calls throw as required. Proprietary libraries and game material stay local and are not included.Refreshed onto
4b83e9d22346619966e92f78a6953e230694fdee; the current branch head isef23232b9e937ef70c51b708c8f2d2ad0bbcd466. The latest rebase preserves all added/deleted lines, modes, author and commit, and includes main's APR resolver guest-copy changes from #21585. This addresses the review finding after #22070 merged: the native decoder now forwards the existingint& statusto_readResolved, preserving the first read failure through deferred execution and submission completion. It reuses main's status handling rather than adding another mechanism. The six-operationdocs/dev/debt/changes/ampr-native-file-reads-rebase.mdfragment preserves newer AMPR guest-copy safety information and unrelated kernel entries, and removes the obsolete no-argument measure signature.Tested
Latest refresh validation on Windows, clean
ef23232b9e937ef70c51b708c8f2d2ad0bbcd466based on main4b83e9d22346619966e92f78a6953e230694fdee:libc.prxembed this exact new head. This was a scoped incremental build, not a new uncached full-runtime build.guest_libressl3_ec_parametersandguest_libressl3_asn1. These were run once with original logs and JUnit retained locally. The prior hosted Windows failure on8bd88a7had exactly those two LibreSSL failures, also present on exact main1adc0e2; current main contains the #22388 revert. This PR adds no LibreSSL change and does not waive the failed historical run.read, statusforwarding remain intact after #21585.4b83e9dretained exit 2: expected old-head self-comparison with #19060, the previously reviewed #21552 helper insertion, and an unresolved comparison with #22108. Manual original-patch review at #215520942212497c32d9a39c139291828e760430720beand #22108781588cbb7ae25f21024498f1f787af42cb85466found no competing native ReadFile implementation or semantic prerequisite. #22108 changes resolver error-index copyout; those resolver/test blocks are unchanged by this PR. #21552 requires retaining both independent helper additions at the shared insertion point. No whole-peer build or author agreement is claimed.Fresh synchronize CI is required for this head; the results below describe the earlier local validation and remain historical.
Previous validation: clean
8bd88a763422acbf4a03d0a72f997b656c467743, based on99d95b9e267785ee3f5641f42493e6a18875ed2b, on Windows with WinLibs GCC 15.2.0 r7 x64 Release, Ninja and Python 3.13. All required dependency checkouts use their exact committed pins.Fresh full configure and uncached build of all six focused targets succeeded, including fresh
libc,libkernelandlibSceAmprruntime inputs. Compiler launchers were empty andCCACHE_DISABLE=1. The first run exposed an incorrect null-pointer EFAULT test fixture (16/17 passed); the fixture was corrected to tracked, read-only guest memory, as in main's existing APR error test. Production and dependency inputs were unchanged by that correction. The six targets were rebuilt on the final clean head before rerunning the complete focused suite.ctest --test-dir b -R "^(guest_ampr_|guest_amm_placement|guest_apr_read_)" -V --output-on-failure --output-junit focused-ampr.xml --parallel 1 --no-tests=error: 17/17 passed, zero skipped, CTest total 3.79 seconds (4.05 seconds including invocation overhead). The registered names were checked against the previous 17-case inventory. Every case finished below 30 seconds; the native packet case passed in 0.112 seconds. Existing sparse offsets beyond 4 GiB, mixed host/native reads, gather/scatter cursors, deferred snapshots, malformed packets, EOF, priorities, placement and AMPR error checks all remain covered.The passing native case includes eight error combinations on Windows; four are also enabled on non-Windows. Both 20/24-byte packet formats and waits before/after the failing read verify successful submission/result with an execution error returned by wait, stable repeated waits, first-error preservation across a later generic EIO, unchanged destination before release, and successful execution of a trailing native read. ENOENT cases are shared across platforms; EFAULT uses tracked read-only guest memory on Windows. Linux/macOS execution was not run for this refresh.
Public declaration/umbrella audit passed: 413 libraries and 34,705 exports, with unique declarations and umbrella coverage verified.
python tools/debt_fold.py --checkpassed for all current fragments.python tools/check_conventions.py --base origin/mainandgit diff --checkpassed. The reviewed working tree was clean.The rebase audit confirmed that the prior contribution's added/deleted lines, modes, author and commit were preserved before applying this review fix. The deliberate refresh changes are confined to the native status argument and its regression test.
The historical SDK differential results in What belong to
9ec953f1c38fc1264e9a354c41ba9b222704afee; that proprietary SDK harness has not been rerun for this refresh. No fresh Linux/macOS, console, title-boot, gameplay or performance result is claimed. GPU testing is n/a for these CPU-side APR changes. Earlier upstream full-build results precede this head; a maintainer rerun is needed to validate the refreshed PR in upstream full CI.Historical overlap evidence for the previous refresh:
Function-name lookup scanned 1,717 open PRs and found only this PR for
sceAmprAprCommandBufferReadFileandsceAmprMeasureCommandSizeReadFile. The final branch check for8bd88a763422acbf4a03d0a72f997b656c467743scanned 1,719 open PRs against main5a23c6303baf68166689edbfcc78adf7160b05cdand completed with exit 0. It reports the expected old-head self-comparison atd4e087096ba6ffdd44b17d6dd8b1fe602cad6d5dand the mechanical #21552 insertion conflict; exit 0 does not mean there are no overlaps. The touched AMPR/APR source and tests are unchanged between the build's main pin and that newer scan base.Pinned independent review of #21552 at
0942212497c32d9a39c139291828e760430720befound a shared insertion point afterValidRead: retain this PR'sReadFileBytesand the peer'sGuestBufferBase/UpdateRecordinghelpers, plus both downstream feature bodies. It does not duplicate the native ReadFile writer or MeasureReadFile. No author agreement or combined build is claimed.Pinned independent review also checked #21585 at
421155f04d47a4927523d801c55ee2fcd198fa4b(resolver guest copies), #20633 ata3470677b6f42a61ba90735a44b01f42509e9fb8(other command-buffer copies/gathers), #11446 at5c5b61fc844b49358dff28854c5ac87866a83663(resolver cache/tests), and #18190 at1515d5dffca40b5e8daa621bbcd9d2ea1966cf69(libkernel_sys mirrors). No competing native ReadFile encoder/decoder was identified in those exact patches; shared helper/selector insertions can require mechanical rebasing. This review does not claim those branches merge or build together.#18515 at
c87be26205f607ae7ffbb3b5ba2f4bef2caa4fffis now closed. Its status-propagation work is on main through merged #22070 and is accounted for by this refresh. It is not an open prerequisite.Checklist
Based on current
main; no other open PR implements the same functionsOne 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 fileNo notes, investigation
.mdfiles 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
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-12T21:08:10Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
9ec953f1c3:tools/check_conventions.pypassed;git diff --checkclean.guest_ampr_tests,guest_apr_read_testsbuilt cleanly.guest_ampr_div_and_buffer_size,guest_ampr_markers,guest_ampr_threads,guest_ampr_cpp_error,guest_apr_read_host,guest_apr_read_direct,guest_apr_read_eof,guest_apr_read_errors,guest_apr_read_streams,guest_apr_read_priorities,guest_apr_read_order,guest_apr_read_queries,guest_apr_read_native):core/libs/prx/libSceAmpr/Export.cpp,core/libs/prx/libSceAmpr/include/Api.hpp,core/libs/prx/libkernel/Apr/src/Apr.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T08:28:57Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks merging this change; the inspected implementation and reported checks support the native ReadFile recording and execution paths.
What I ran
ef23232b9e937ef70c51b708c8f2d2ad0bbcd466against the prepared patch; no commands or tests were run.description.md,commits.md,manifest.json, and all 551 lines ofdiff.patch. Read the changed code incore/libs/prx/libSceAmpr/Export.cpp(lines 205–235, 465–525, 790–815) andcore/libs/prx/libkernel/Apr/src/Apr.cpp(lines 650–730). The manifest marks all seven changed files as included; the additional changed tests and debt fragment are represented in the diff.files.jsonwas not available through the reader.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not independently run the reported build, CTest, SDK differential harness, or console checks. The full changed-file texts for
core/libs/prx/libkernel/tests/cmake/guest_apr_read_tests.cmake,core/libs/tests/GuestAmpr.cpp,core/libs/tests/GuestAprRead.cpp, anddocs/dev/debt/changes/ampr-native-file-reads-rebase.mdwere not read outside their patch hunks; their complete contents were included in the diff.files.jsonwas unavailable, so exclusions by rule could not be confirmed.To get this to a good state
Nothing is required.