feat(libkernel): export the AMM mapper and command-buffer functions from libkernel too #18035

Merged
akkadbakkad89 merged 4 commits from upstream-pr/18035 into main 2026-11-23 08:24:44 +00:00
akkadbakkad89 commented 2026-11-10 06:47:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-11-10T06:47:10Z.


What

Final Fantasy XVI (PPSA10665, 01.003.000) imports sceKernelCallIndirectBuffer, sceKernelCallIndirectBuffer2, sceKernelGiveDirectMemoryToMapper, sceKernelMapperGetParam, sceKernelWaitCommandBufferCompletion and the sceKernelWrite*Command GPU-mask writers (sceKernelWriteMapCommand2, sceKernelWriteMapDirectCommand, sceKernelWriteMapDirectWithGpuMaskIdCommand, sceKernelWriteMapWithGpuMaskIdCommand, sceKernelWriteMultiMapCommand, sceKernelWriteMultiMapWithGpuMaskIdCommand, sceKernelWriteRemapCommand, sceKernelWriteRemapWithGpuMaskIdCommand, sceKernelWriteModifyProtectCommand, sceKernelWriteModifyProtectWithGpuMaskIdCommand, sceKernelWriteModifyMtypeProtectWithGpuMaskIdCommand, sceKernelWriteUnmapCommand) under the libkernel library, but only libkernel_sys.prx exported them, so the imports failed to resolve.

The definitions move to core/libs/prx/libkernel/SysExports.Mapper.cpp, compiled into both libkernel.prx and libkernel_sys.prx. The AMM command-writer helpers shared with libkernel_sys's remaining writers (sceKernelWriteMapCommand, sceKernelCallIndirectBuffer3, etc.) move into core/libs/prx/libkernel/Apr/include/AmmExportCommands.hpp. The moved debt entries sit in docs/dev/debt/libkernel.md.

Tested

Windows 11, MinGW build. Relinked Final Fantasy XVI eboot.bin (unwrapped SELF) and ran tools/import_audit.py against the built libraries: before the change the audit reported 17 library_mismatch entries (libkernel.prx named, libkernel_sys.prx providing); after rebuilding and NID-patching both libraries it reports 0 mismatches, 0 absent, 0 stubs. Verified the patched PE export tables directly: all 17 NIDs are exported by libkernel.prx (2090 names) and still exported by libkernel_sys.prx (1111 names); sceKernelMapperGetParam fills the full 0x38-byte param block (7 qwords) matching main's updated body. ctest focused set: 55/57 kernel_sys/kernel_process_exports pass, 2 skipped on their configured condition. check_conventions.py --base origin/main passes; pr_overlap.py reports no overlap.

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 (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: PPSA10665
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5237088644 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18035). Originally posted by [akkadbakkad89](https://github.com/akkadbakkad89) on 2026-11-10T06:47:10Z. --- ### What Final Fantasy XVI (PPSA10665, 01.003.000) imports `sceKernelCallIndirectBuffer`, `sceKernelCallIndirectBuffer2`, `sceKernelGiveDirectMemoryToMapper`, `sceKernelMapperGetParam`, `sceKernelWaitCommandBufferCompletion` and the `sceKernelWrite*Command` GPU-mask writers (`sceKernelWriteMapCommand2`, `sceKernelWriteMapDirectCommand`, `sceKernelWriteMapDirectWithGpuMaskIdCommand`, `sceKernelWriteMapWithGpuMaskIdCommand`, `sceKernelWriteMultiMapCommand`, `sceKernelWriteMultiMapWithGpuMaskIdCommand`, `sceKernelWriteRemapCommand`, `sceKernelWriteRemapWithGpuMaskIdCommand`, `sceKernelWriteModifyProtectCommand`, `sceKernelWriteModifyProtectWithGpuMaskIdCommand`, `sceKernelWriteModifyMtypeProtectWithGpuMaskIdCommand`, `sceKernelWriteUnmapCommand`) under the `libkernel` library, but only `libkernel_sys.prx` exported them, so the imports failed to resolve. The definitions move to `core/libs/prx/libkernel/SysExports.Mapper.cpp`, compiled into both `libkernel.prx` and `libkernel_sys.prx`. The AMM command-writer helpers shared with `libkernel_sys`'s remaining writers (`sceKernelWriteMapCommand`, `sceKernelCallIndirectBuffer3`, etc.) move into `core/libs/prx/libkernel/Apr/include/AmmExportCommands.hpp`. The moved debt entries sit in `docs/dev/debt/libkernel.md`. ### Tested Windows 11, MinGW build. Relinked Final Fantasy XVI `eboot.bin` (unwrapped SELF) and ran `tools/import_audit.py` against the built libraries: before the change the audit reported 17 `library_mismatch` entries (`libkernel.prx` named, `libkernel_sys.prx` providing); after rebuilding and NID-patching both libraries it reports 0 mismatches, 0 absent, 0 stubs. Verified the patched PE export tables directly: all 17 NIDs are exported by `libkernel.prx` (2090 names) and still exported by `libkernel_sys.prx` (1111 names); `sceKernelMapperGetParam` fills the full 0x38-byte param block (7 qwords) matching main's updated body. `ctest` focused set: 55/57 kernel_sys/kernel_process_exports pass, 2 skipped on their configured condition. `check_conventions.py --base origin/main` passes; `pr_overlap.py` reports no overlap. ### 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) - [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: PPSA10665 - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-11-20 14:22:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T14:22:46Z.

Review: COMMENTED


Reviewed — comments

Nothing blocks the export move, but the review found a test gap and a documented edge case that can produce an invalid AMM range.

What I ran

Reviewed head ec3d47c2fc9ce6e88674def90d146ea8005e4295 against main using the prepared diff and repo_read.py. No build or test commands were run; the test results in the PR description are author-reported.

Results

Check Result Note
Changed source review passed Included changed files inspected
Build and tests not run PR description reports Windows MinGW checks
Excluded-file review not applicable No excluded files were listed

Findings

Blocking

None.

Non-blocking

  • core/libs/prx/libkernel/Apr/include/AmmExportCommands.hpp:33: address + size <= end can accept a range whose addition wraps around uint64_t, as the debt note itself describes. Since this helper guards PRT map/unmap command creation, check that address + size does not overflow before comparing it with end.
  • core/libs/tests/GuestKernelMapperExportParity.cpp:47: the added test verifies that each library resolves all listed exports, but does not verify that each library owns the exports. A test can therefore pass when one library resolves a symbol through the other library's dependencies, which would not catch a provider-attribution regression. Check the module's own export table for each NID.

Not verified

No tests or build were run in this review. The PR description's reported results were not independently verified. Files listed as included in the manifest were available; the prepared review listing showed no excluded files. The changed implementation, declarations, build wiring, parity test, and debt documentation were read; unchanged callers and runtime behavior were not exhaustively checked.

To get this to a good state

Nothing is required. Optional: guard range addition against overflow and make the parity test verify exports owned by each library.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5994146586 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18035#pullrequestreview-5994146586). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T14:22:46Z. **Review:** COMMENTED --- # Reviewed — comments Nothing blocks the export move, but the review found a test gap and a documented edge case that can produce an invalid AMM range. ## What I ran Reviewed head `ec3d47c2fc9ce6e88674def90d146ea8005e4295` against `main` using the prepared diff and `repo_read.py`. No build or test commands were run; the test results in the PR description are author-reported. ## Results | Check | Result | Note | |---|---|---| | Changed source review | passed | Included changed files inspected | | Build and tests | not run | PR description reports Windows MinGW checks | | Excluded-file review | not applicable | No excluded files were listed | ## Findings ### Blocking None. ### Non-blocking - `core/libs/prx/libkernel/Apr/include/AmmExportCommands.hpp:33`: `address + size <= end` can accept a range whose addition wraps around `uint64_t`, as the debt note itself describes. Since this helper guards PRT map/unmap command creation, check that `address + size` does not overflow before comparing it with `end`. - `core/libs/tests/GuestKernelMapperExportParity.cpp:47`: the added test verifies that each library resolves all listed exports, but does not verify that each library owns the exports. A test can therefore pass when one library resolves a symbol through the other library's dependencies, which would not catch a provider-attribution regression. Check the module's own export table for each NID. ## Not verified No tests or build were run in this review. The PR description's reported results were not independently verified. Files listed as included in the manifest were available; the prepared review listing showed no excluded files. The changed implementation, declarations, build wiring, parity test, and debt documentation were read; unchanged callers and runtime behavior were not exhaustively checked. ## To get this to a good state Nothing is required. Optional: guard range addition against overflow and make the parity test verify exports owned by each library.
MarcZX10 commented 2026-11-22 05:32:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T05:32:20Z.

Review: COMMENTED


Reviewed — comments

The implementation is read, but several changed files and the reported checks were not independently verified.

What I ran

Reviewed head bf7b49d659d1ac7beba53d0180500b6181b43988 using the prepared diff and pinned reader. No build or tests were run. Read core/libs/prx/libkernel/SysExports.Mapper.cpp, core/libs/prx/libkernel/Apr/include/AprCommandBuffer.hpp, core/libs/tests/GuestKernelMapperExportParity.cpp, and the first 50 lines of core/libs/prx/libkernel_sys/Export.Discovery.cpp; reviewed the prepared diff, description, commits, and manifest. Other changed file bodies were not read.

Results

Check Result Note
Diff and implementation review passed No verified blocking defect
Build and tests not run Reported results were not reproduced
Full changed-file review not run Several changed file bodies were not read

Negative control

Not run; no tests were executed.

Findings

Blocking

None verified in the code read.

Non-blocking

The change description reports build, import-audit, and focused test results, but those checks were not independently run. The debt notes also describe known differences from console behavior in command validation and encoding; those limitations are documented in docs/dev/debt/libkernel.md:723-727.

Sources

Not verified

The remaining changed files were not read: core/libs/CMakeLists.txt, core/libs/prx/libkernel/CMakeLists.txt, core/libs/prx/libkernel/include/Api.hpp, core/libs/prx/libkernel_sys/CMakeLists.txt, core/libs/prx/libkernel_sys/include/Api.hpp, and both debt files in full. The implementation was not built or tested here; claimed Windows build, import audit, PE export inspection, ctest, convention check, and overlap check remain author-reported.

To get this to a good state

Nothing is required. Optional: independently run the reported checks and complete review of the unread changed files before relying on approval.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6010556496 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18035#pullrequestreview-6010556496). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-22T05:32:20Z. **Review:** COMMENTED --- # Reviewed — comments The implementation is read, but several changed files and the reported checks were not independently verified. ## What I ran Reviewed head `bf7b49d659d1ac7beba53d0180500b6181b43988` using the prepared diff and pinned reader. No build or tests were run. Read `core/libs/prx/libkernel/SysExports.Mapper.cpp`, `core/libs/prx/libkernel/Apr/include/AprCommandBuffer.hpp`, `core/libs/tests/GuestKernelMapperExportParity.cpp`, and the first 50 lines of `core/libs/prx/libkernel_sys/Export.Discovery.cpp`; reviewed the prepared diff, description, commits, and manifest. Other changed file bodies were not read. ## Results | Check | Result | Note | |---|---|---| | Diff and implementation review | passed | No verified blocking defect | | Build and tests | not run | Reported results were not reproduced | | Full changed-file review | not run | Several changed file bodies were not read | ## Negative control Not run; no tests were executed. ## Findings ### Blocking None verified in the code read. ### Non-blocking The change description reports build, import-audit, and focused test results, but those checks were not independently run. The debt notes also describe known differences from console behavior in command validation and encoding; those limitations are documented in `docs/dev/debt/libkernel.md:723-727`. ## Sources - [Mapper exports at reviewed head](https://github.com/boykopovar/AnyPS5/blob/bf7b49d659d1ac7beba53d0180500b6181b43988/core/libs/prx/libkernel/SysExports.Mapper.cpp) - [Known behavior limitations at reviewed head](https://github.com/boykopovar/AnyPS5/blob/bf7b49d659d1ac7beba53d0180500b6181b43988/docs/dev/debt/libkernel.md) ## Not verified The remaining changed files were not read: `core/libs/CMakeLists.txt`, `core/libs/prx/libkernel/CMakeLists.txt`, `core/libs/prx/libkernel/include/Api.hpp`, `core/libs/prx/libkernel_sys/CMakeLists.txt`, `core/libs/prx/libkernel_sys/include/Api.hpp`, and both debt files in full. The implementation was not built or tested here; claimed Windows build, import audit, PE export inspection, ctest, convention check, and overlap check remain author-reported. ## To get this to a good state Nothing is required. Optional: independently run the reported checks and complete review of the unread changed files before relying on approval.
Superseabas commented 2026-11-22 11:01:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Superseabas on 2026-11-22T11:01:44Z.

Review: COMMENTED


Windows check of head bf7b49d659 with GCC 16, merged onto main 6c70b74203 (f36af3e74d, clean merge).

Setup: Windows 11 Home 10.0.26200, Ryzen 7 7700X, WinLibs GCC 16.2.0 (x86_64-ucrt-posix-seh, r3), CMake 4.4.4, Ninja 1.13.2, Release full build, run from PowerShell.

  • Exports: in the unpatched .prx export tables (exact names from objdump -p), main's libkernel.prx exports 0 of the 17 functions and libkernel_sys.prx 17. With this PR both export all 17.
  • Kernel, AMM and APR tests (^guest_(kernel_sys|kernel_mapper|apr|amm|kernel_process_exports|kernel_amm)): main 84 of 84, and with this PR 86 of 86 in 3 of 3 runs. The two new ones are guest_kernel_mapper_export_parity and _patched.
  • Red check: with SysExports.Mapper.cpp taken out of libkernel's sources, libkernel.prx exports none of the 17, and both parity tests fail. The other 84 still pass.
  • On MarcZX10's non-blocking point about the parity test: on Windows the test resolves the names with GetProcAddress, which reads only that DLL's own export table, so here it does check that each library provides them itself. The dependency fallback applies to dlsym on Linux.
  • Merged onto main 6c70b74203, tools/check_conventions.py --base upstream/main and tools/debt_fold.py --check pass.

Debt files, worth fixing. At this head docs/dev/debt/libkernel_sys.md still carries entries for code the PR moves out of libkernel_sys, next to their new copies in libkernel.md:

  • Lines 330, 331, 333 and 334 ("AMM kernel write commands", "AMM kernel write command checks", "sceKernelWriteWaitOnAddressCommand and sceKernelWriteWaitOnCounterCommand", and "sceKernelCallIndirectBuffer, … and sceKernelMapperGetParam") link to libkernel_sys/Export.Discovery.cpp. None of those functions is defined in libkernel_sys any more; they're all in libkernel/SysExports.Mapper.cpp. Only the sceKernelCallIndirectBuffer2 and sceKernelWaitCommandBufferCompletion entries were removed.
  • Lines 328 and 329 are the same scePthreadMutexInitForInternalLibc, scePthreadMutexattrInitForInternalLibc entry twice. It's once on main, so it looks like a merge artefact.

CONTRIBUTING.md now asks for debt changes to go through a fragment in docs/dev/debt/changes/. Doing the move that way (remove the libkernel_sys entries, add the libkernel ones) would also avoid both of these.

AmmExportCommands.hpp:33's address + size <= end, which MarcZX10 noted can wrap, is the same line main has in libkernel_sys/Export.Discovery.cpp:74, moved unchanged, so it isn't new here.

Not run: Linux and macOS, and PPSA10665 itself (I don't have it).

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6011891359 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18035#pullrequestreview-6011891359). Originally posted by [Superseabas](https://github.com/Superseabas) on 2026-11-22T11:01:44Z. **Review:** COMMENTED --- Windows check of head `bf7b49d659` with GCC 16, merged onto `main` `6c70b74203` (`f36af3e74d`, clean merge). **Setup:** Windows 11 Home 10.0.26200, Ryzen 7 7700X, WinLibs GCC 16.2.0 (`x86_64-ucrt-posix-seh`, r3), CMake 4.4.4, Ninja 1.13.2, Release full build, run from PowerShell. - **Exports:** in the unpatched `.prx` export tables (exact names from `objdump -p`), `main`'s `libkernel.prx` exports 0 of the 17 functions and `libkernel_sys.prx` 17. With this PR both export all 17. - **Kernel, AMM and APR tests** (`^guest_(kernel_sys|kernel_mapper|apr|amm|kernel_process_exports|kernel_amm)`): `main` 84 of 84, and with this PR 86 of 86 in 3 of 3 runs. The two new ones are `guest_kernel_mapper_export_parity` and `_patched`. - **Red check:** with `SysExports.Mapper.cpp` taken out of `libkernel`'s sources, `libkernel.prx` exports none of the 17, and both parity tests fail. The other 84 still pass. - On MarcZX10's non-blocking point about the parity test: on Windows the test resolves the names with `GetProcAddress`, which reads only that DLL's own export table, so here it does check that each library provides them itself. The dependency fallback applies to `dlsym` on Linux. - Merged onto `main` `6c70b74203`, `tools/check_conventions.py --base upstream/main` and `tools/debt_fold.py --check` pass. **Debt files, worth fixing.** At this head `docs/dev/debt/libkernel_sys.md` still carries entries for code the PR moves out of `libkernel_sys`, next to their new copies in `libkernel.md`: - Lines 330, 331, 333 and 334 ("AMM kernel write commands", "AMM kernel write command checks", "sceKernelWriteWaitOnAddressCommand and sceKernelWriteWaitOnCounterCommand", and "sceKernelCallIndirectBuffer, … and sceKernelMapperGetParam") link to `libkernel_sys/Export.Discovery.cpp`. None of those functions is defined in `libkernel_sys` any more; they're all in `libkernel/SysExports.Mapper.cpp`. Only the `sceKernelCallIndirectBuffer2` and `sceKernelWaitCommandBufferCompletion` entries were removed. - Lines 328 and 329 are the same `scePthreadMutexInitForInternalLibc, scePthreadMutexattrInitForInternalLibc` entry twice. It's once on `main`, so it looks like a merge artefact. `CONTRIBUTING.md` now asks for debt changes to go through a fragment in `docs/dev/debt/changes/`. Doing the move that way (remove the `libkernel_sys` entries, add the `libkernel` ones) would also avoid both of these. `AmmExportCommands.hpp:33`'s `address + size <= end`, which MarcZX10 noted can wrap, is the same line `main` has in `libkernel_sys/Export.Discovery.cpp:74`, moved unchanged, so it isn't new here. Not run: Linux and macOS, and PPSA10665 itself (I don't have it). AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-11-22 20:22:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T20:22:31Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the implementation and export parity are supported by the inspected source and existing focused tests.

What I ran

Reviewed head 13da2bfe9c968356d959b69fb61217c7b44ac787. No commands or tests were run in this review; the build and test results in the PR description are author-reported.

Results

Check Result Note
Source and diff review passed All changed files were included and read
Build and tests not run Reported results were not independently verified
Export parity test not run Test implementation and registration were inspected

Findings

Blocking

None.

Non-blocking

None.

Not verified

The reported MinGW build, CTest results, import audit, PE export tables, conventions check, overlap check, and title behavior were not independently run or confirmed. The repository files listed in the manifest were all included; files.json was not available through the reader, so no additional exclusions were confirmed. I read the prepared description, commits, manifest and diff, plus the changed source and test files, related AMM implementation and existing tests, and the debt fragment and related debt entries.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6014320531 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18035#pullrequestreview-6014320531). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-22T20:22:31Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the implementation and export parity are supported by the inspected source and existing focused tests. ## What I ran Reviewed head `13da2bfe9c968356d959b69fb61217c7b44ac787`. No commands or tests were run in this review; the build and test results in the PR description are author-reported. ## Results | Check | Result | Note | |---|---|---| | Source and diff review | passed | All changed files were included and read | | Build and tests | not run | Reported results were not independently verified | | Export parity test | not run | Test implementation and registration were inspected | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The reported MinGW build, CTest results, import audit, PE export tables, conventions check, overlap check, and title behavior were not independently run or confirmed. The repository files listed in the manifest were all included; `files.json` was not available through the reader, so no additional exclusions were confirmed. I read the prepared description, commits, manifest and diff, plus the changed source and test files, related AMM implementation and existing tests, and the debt fragment and related debt entries. ## 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!18035
No description provided.