feat(libkernel): implement sceKernelCheckedReleaseDirectMemory #721

Merged
merwie merged 1 commit from upstream-pr/721 into main 2026-10-06 09:28:19 +00:00
merwie commented 2026-10-05 17:59:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by merwie on 2026-10-05T17:59:08Z.


What

sceKernelCheckedReleaseDirectMemory(start, len) threw not implemented. It now releases direct memory only when the whole range is allocated, with the semantics of shadPS4's sceKernelCheckedReleaseDirectMemory / MemoryManager::Free(..., is_checked):

  • a start or length that is not 16 KiB aligned (or a negative start) returns SCE_KERNEL_ERROR_EINVAL;
  • a zero length succeeds;
  • a range that leaves direct memory or covers an unallocated page returns SCE_KERNEL_ERROR_ENOENT and releases nothing;
  • otherwise it releases like sceKernelReleaseDirectMemory.

PhysicalMemoryPool gets CheckedFree, which checks and releases under the pool lock; Free and CheckedFree share the release body.

  • GuestMemory: new CheckCheckedReleaseDirectMemory covering misalignment, zero length, a range past the allocation (nothing released), a partial release after unmapping, a range overlapping a released page, and a double release.

Tested

Windows 11, WinLibs GCC 15.2.0 r7, Ryzen 7 9800X3D, Radeon RX 9070 XT.

  • ctest: 286/288 passed, including guest_memory. agc_driver_lds_atomics64 and agc_driver_vopc_compare_table fail on this machine on main as well (Vulkan device tests).
  • PPSA12544 (Hollow Knight: Silksong, Unity) with #698, #699, #700, #702, #705, #709, #710, #648: called after its save data memory setup; the title continues to UnitySubsystems, globalgamemanagers.assets and unity default resources.

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 in TechnicalDebt
  • 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 (#686 and #700 also add checks to GuestMemory.cpp, in other places)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4748918937 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/721). Originally posted by [merwie](https://github.com/merwie) on 2026-10-05T17:59:08Z. --- ### What `sceKernelCheckedReleaseDirectMemory(start, len)` threw `not implemented`. It now releases direct memory only when the whole range is allocated, with the semantics of shadPS4's `sceKernelCheckedReleaseDirectMemory` / `MemoryManager::Free(..., is_checked)`: - a start or length that is not 16 KiB aligned (or a negative start) returns `SCE_KERNEL_ERROR_EINVAL`; - a zero length succeeds; - a range that leaves direct memory or covers an unallocated page returns `SCE_KERNEL_ERROR_ENOENT` and releases nothing; - otherwise it releases like `sceKernelReleaseDirectMemory`. `PhysicalMemoryPool` gets `CheckedFree`, which checks and releases under the pool lock; `Free` and `CheckedFree` share the release body. - `GuestMemory`: new `CheckCheckedReleaseDirectMemory` covering misalignment, zero length, a range past the allocation (nothing released), a partial release after unmapping, a range overlapping a released page, and a double release. ### Tested Windows 11, WinLibs GCC 15.2.0 r7, Ryzen 7 9800X3D, Radeon RX 9070 XT. - `ctest`: 286/288 passed, including `guest_memory`. `agc_driver_lds_atomics64` and `agc_driver_vopc_compare_table` fail on this machine on `main` as well (Vulkan device tests). - PPSA12544 (Hollow Knight: Silksong, Unity) with #698, #699, #700, #702, #705, #709, #710, #648: called after its save data memory setup; the title continues to `UnitySubsystems`, `globalgamemanagers.assets` and `unity default resources`. ### 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 (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [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 (#686 and #700 also add checks to `GuestMemory.cpp`, in other places) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-06 05:46:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-06T05:46:58Z.


Progress report (0518f0e → 65e5c99)

📈 System libraries: 79.24% (+0.03%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel sceKernelCheckedReleaseDirectMemory
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6010203248 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/721#issuecomment-6010203248). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-06T05:46:58Z. --- <!-- progress-report --> ### Progress report (0518f0e → 65e5c99) 📈 **System libraries**: 79.24% (+0.03%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel | `sceKernelCheckedReleaseDirectMemory` | </details>
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!721
No description provided.