Skip to content

feat(libkernel): implement sceKernelIsStack - #702

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
merwie:feat/kernel-is-stack
Oct 6, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
merwie:feat/kernel-is-stack

Conversation

@merwie

@merwie merwie commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

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.

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

Track the stack range of each running guest thread and answer
sceKernelIsStack from the calling thread's stack (the host limits for an
adopted thread) or from that registry. A mapped address outside every
stack succeeds with null bounds and an unmapped one returns EACCES; the
output pointers may be null.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@oneandonlydean

Copy link
Copy Markdown
Collaborator

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.

…/kernel-is-stack

# Conflicts:
#	core/libs/prx/libkernel/Pthread/src/Thread.cpp
@merwie

merwie commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

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

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown

Progress report (481c85e → 17332ed)

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

✅ 1 implemented
Library Name
libkernel sceKernelIsStack

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 6, 2026
@oneandonlydean
oneandonlydean merged commit 2d0bbbf into boykopovar:main Oct 6, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants