feat(libkernel): implement sceKernelIsStack #702

Merged
merwie merged 2 commits from upstream-pr/702 into main 2026-10-06 21:00:47 +00:00
merwie commented 2026-10-05 17:10:31 +00:00 (Migrated from github.com)

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


What

sceKernelIsStack(addr, start, end) threw not implemented.

  • Thread.cpp keeps the stack range of every running guest thread: registered in RunThread (the guest range on Windows, the host range on Linux, where stackAddress is not set) and removed in finishThread.
  • GuestThreadStack answers from the calling thread's stack first (its guest range, or the host limits for an adopted thread such as the main thread), then from the registry.
  • sceKernelIsStack: an address in a stack returns its bounds; a mapped address outside every stack succeeds with null bounds; an address sceKernelVirtualQuery rejects returns SCE_KERNEL_ERROR_EACCES. Null start / end are allowed. The non-stack and unmapped results follow shadPS4's MemoryManager::IsStack.
  • New test guest_kernel_is_stack: main thread stack, a running worker's stack queried from the worker and from the main thread (disjoint from the main stack), a global, null outputs, a mapped and then unmapped flexible page.

Tested

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

  • ctest: 288/290 passed, including guest_kernel_is_stack. 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: calls sceKernelIsStack after reading RuntimeInitializeOnLoads.json, then continues to ScriptingAssemblies.json and VideoOut setup.

Not tested on Linux.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4748403420 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/702). Originally posted by [merwie](https://github.com/merwie) on 2026-10-05T17:10:31Z. --- ### What `sceKernelIsStack(addr, start, end)` threw `not implemented`. - `Thread.cpp` keeps the stack range of every running guest thread: registered in `RunThread` (the guest range on Windows, the host range on Linux, where `stackAddress` is not set) and removed in `finishThread`. - `GuestThreadStack` answers from the calling thread's stack first (its guest range, or the host limits for an adopted thread such as the main thread), then from the registry. - `sceKernelIsStack`: an address in a stack returns its bounds; a mapped address outside every stack succeeds with null bounds; an address `sceKernelVirtualQuery` rejects returns `SCE_KERNEL_ERROR_EACCES`. Null `start` / `end` are allowed. The non-stack and unmapped results follow shadPS4's `MemoryManager::IsStack`. - New test `guest_kernel_is_stack`: main thread stack, a running worker's stack queried from the worker and from the main thread (disjoint from the main stack), a global, null outputs, a mapped and then unmapped flexible page. ### Tested Windows 11, WinLibs GCC 15.2.0 r7, Ryzen 7 9800X3D, Radeon RX 9070 XT. - `ctest`: 288/290 passed, including `guest_kernel_is_stack`. `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: calls `sceKernelIsStack` after reading `RuntimeInitializeOnLoads.json`, then continues to `ScriptingAssemblies.json` and VideoOut setup. Not tested on Linux. ### 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 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
oneandonlydean commented 2026-10-06 05:34:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-06T05:34:22Z.


Thanks for this. It needs a rebase now that #761 has landed. Both change the same part of core/libs/prx/libkernel/Pthread/src/Thread.cpp: #761 added SetStackFromHost(), which queries the host stack with GetCurrentThreadStackLimits / pthread_getattr_np, and this PR adds NativeStackLimits(), which does the same query. Rather than keeping two copies, sceKernelIsStack could build on #761's query (or both could share one helper) when you resolve it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6010066262 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/702#issuecomment-6010066262). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-06T05:34:22Z. --- Thanks for this. It needs a rebase now that #761 has landed. Both change the same part of `core/libs/prx/libkernel/Pthread/src/Thread.cpp`: #761 added `SetStackFromHost()`, which queries the host stack with `GetCurrentThreadStackLimits` / `pthread_getattr_np`, and this PR adds `NativeStackLimits()`, which does the same query. Rather than keeping two copies, `sceKernelIsStack` could build on #761's query (or both could share one helper) when you resolve it.
merwie commented 2026-10-06 07:58:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by merwie on 2026-10-06T07:58:33Z.


Merged main (no rebase, to keep the review history). NativeStackLimits and #761's query are now one helper, HostStackLimits: SetStackFromHost throws when it fails, and sceKernelIsStack uses it only for a host thread that has no PthreadPrivate yet. Non-GPU tests pass.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6011966968 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/702#issuecomment-6011966968). Originally posted by [merwie](https://github.com/merwie) on 2026-10-06T07:58:33Z. --- Merged `main` (no rebase, to keep the review history). `NativeStackLimits` and #761's query are now one helper, `HostStackLimits`: `SetStackFromHost` throws when it fails, and `sceKernelIsStack` uses it only for a host thread that has no `PthreadPrivate` yet. Non-GPU tests pass.
github-actions[bot] commented 2026-10-06 07:58:54 +00:00 (Migrated from github.com)

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


Progress report (481c85e → 17332ed)

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

✅ 1 implemented
Library Name
libkernel sceKernelIsStack
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6011971962 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/702#issuecomment-6011971962). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-06T07:58:54Z. --- <!-- progress-report --> ### Progress report (481c85e → 17332ed) 📈 **System libraries**: 82.34% (+0.03%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel | `sceKernelIsStack` | </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!702
No description provided.