fix(libkernel): keep host stack room below guest thread stacks #2647
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2647"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T09:57:46Z.
What
Fixes #2603.
Since #1988, a guest thread's stack is exactly the size the title asked for. Host code that the thread calls runs on that stack too.
sceAgcCreateShaderreachesDriver::RegisterShader, whose frame is about 50 KiB, so threads that ask for 48 KiB overflow. The same overflow crashes Astro Bot (PPSA21564) at start-up onmain, in shader building undersceAgcCreatePrimState.scePthreadAttrGet,sceKernelIsStack). Only host calls use the extra room.ulimit -s192 passes, 128 crashes), Vulkan setup included.Tested
Linux (CachyOS, GCC, Release).
maincrashes at about 40–49 s (2 of 2 runs).mainwith this change gets past that point to the intro.guest_pthread_stacknow also calls host code that uses 256 KiB of stack below each thread's guest range (16 KiB, 64 KiB, 1 MiB and 16 MiB requests). It crashes with SIGSEGV without the fix and passes with it, 20 of 20 runs.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-10T10:16:27Z.
Additional platform validation on standalone PR head
84d90152b4cf6bf6e1ce1f12e3090b02b5fe16fa:Windows: four focused checks passed; one unrelated parent failure — Windows 11, supported WinLibs GCC 15.2.0 UCRT/POSIX/SEH r7; CMake 4.3.1 / Ninja.
Release /
BUILD_TESTING=ON: built the selected test targets; 5 CTest cases, 1 failures, 0 CTest skips.Tests:
guest_kernel_sync,guest_pthread_attr,guest_pthread_stack,guest_pthread_rwlock,guest_memory.Reproduce after building the test targets:
ctest --test-dir <build> --verbose --no-tests=error --timeout 30 -R "^guest_(pthread_stack|thread|thread_stack|memory|pthread_attr|kernel_thread|kernel_sync|pthread_rwlock)$".Failed cases:
guest_memory.Parent
be403084c6reproduces the identical GuestMemory.cpp:1035 read-only pread refusal assertion (abort/0xc0000409); the broader guest_memory failure is pre-existing, not introduced by the stack change. The PR head passed guest_pthread_stack and three other focused pthread/sync cases. The expanded stack test from this PR also segfaults against the parent implementation, while it passes on the PR head.Imported from boykopovar/AnyPS5. Originally posted by husseinkad on 2026-10-10T10:29:31Z.
Windows check of this PR, since the description says Windows was not built or tested. Windows 11 Pro 10.0.26200, WinLibs GCC 15.2.0 r7, Release, PR head merged onto
maina29ef592.guest_pthread_stackpasses 10/10 (--repeat until-fail:10).Thread.cppreverted tomainand this PR's test kept,guest_pthread_stacksegfaults; with the change it passes, so the test fails before and passes after on Windows too.-R "pthread|thread|stack"set passes (20 of 22). The other two,host_thread_localandlinux_guest_stack, were not built in this run, so they say nothing about the PR.tools/check_conventions.py --base origin/mainpasses.Reading the Windows path (
Thread.cpparound lines 485-487): the margin is applied,_beginthreadexgetsstackSize + 1 MiBrounded to pages, and the guest range,scePthreadAttrGetstackandsceKernelIsStackstill report only the requested size.One thing to be aware of, not measured: on Windows the margin is committed, not just reserved, so every thread now costs 1 MiB more commit charge up front (a title that creates hundreds of threads pays hundreds of MiB). On Linux it is lazily mapped. If that matters, a reserve-only margin would avoid it. The 1 MiB value also comes from the PR's own measurements (128 to 192 KiB needed) and has no TechnicalDebt entry.
AI-assisted: yes.