feat(libkernel): implement sceKernelGetDirectMemoryType #808

Merged
adriadam10 merged 1 commit from upstream-pr/808 into main 2026-10-06 09:32:52 +00:00
adriadam10 commented 2026-10-06 05:44:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-06T05:44:49Z.


What

Implements sceKernelGetDirectMemoryType(offset, *type, *start, *end) (BC+OG5m9+bw, not declared on main until now) on top of the existing physical pool lookup (DirectMemoryFind, the same one sceKernelDirectMemoryQuery uses).

  • Offset inside an allocated block: writes the block's memory type, start and end, returns 0. Released ranges split blocks, so after a partial release the query returns the remaining part. shadPS4 (MemoryManager::GetDirectMemoryType) and prosper (k_get_direct_memory_type) both work this way.
  • Offset not inside an allocated block (free, released, negative or past the end): SCE_KERNEL_ERROR_ENOENT and the outputs stay as they were. shadPS4 and prosper both return ENOENT here.
  • Any null output: SCE_KERNEL_ERROR_EINVAL. This comes from prosper (PS5 HLE). shadPS4 doesn't check for null.
  • Signature (long offset, int*, long*, long*) from SharpProspero KernelMemoryQuery.cs.

Tested

Linux, guest_memory_tests (new CheckGetDirectMemoryType): two adjacent blocks of different types (first byte, last byte, and the boundary that lands on the second block), each null output, a released offset (outputs unchanged), a negative offset, a partially released block, and releasing a range that spans both blocks. The test doesn't build on main because the export is missing. Mutation checks: dropping the null checks, returning EACCES, using find-next, writing the wrong type, and writing the wrong end each make it fail. Release build (GCC) passes, and all 119 guest_ ctests pass.

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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4754669427 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/808). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-06T05:44:49Z. --- ### What Implements `sceKernelGetDirectMemoryType(offset, *type, *start, *end)` (`BC+OG5m9+bw`, not declared on `main` until now) on top of the existing physical pool lookup (`DirectMemoryFind`, the same one `sceKernelDirectMemoryQuery` uses). - Offset inside an allocated block: writes the block's memory type, start and end, returns 0. Released ranges split blocks, so after a partial release the query returns the remaining part. shadPS4 (`MemoryManager::GetDirectMemoryType`) and prosper (`k_get_direct_memory_type`) both work this way. - Offset not inside an allocated block (free, released, negative or past the end): `SCE_KERNEL_ERROR_ENOENT` and the outputs stay as they were. shadPS4 and prosper both return ENOENT here. - Any null output: `SCE_KERNEL_ERROR_EINVAL`. This comes from prosper (PS5 HLE). shadPS4 doesn't check for null. - Signature (`long offset, int*, long*, long*`) from SharpProspero `KernelMemoryQuery.cs`. ### Tested Linux, `guest_memory_tests` (new `CheckGetDirectMemoryType`): two adjacent blocks of different types (first byte, last byte, and the boundary that lands on the second block), each null output, a released offset (outputs unchanged), a negative offset, a partially released block, and releasing a range that spans both blocks. The test doesn't build on `main` because the export is missing. Mutation checks: dropping the null checks, returning EACCES, using find-next, writing the wrong type, and writing the wrong end each make it fail. Release build (GCC) passes, and all 119 `guest_` ctests pass. ### 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) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes
github-actions[bot] commented 2026-10-06 05:48:15 +00:00 (Migrated from github.com)

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


Progress report (481c85e → 6d2713c)

📈 System libraries: 82.32% (+0.01%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel sceKernelGetDirectMemoryType
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6010217887 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/808#issuecomment-6010217887). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-06T05:48:15Z. --- <!-- progress-report --> ### Progress report (481c85e → 6d2713c) 📈 **System libraries**: 82.32% (+0.01%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel | `sceKernelGetDirectMemoryType` | </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!808
No description provided.