fix(libkernel): keep a protected host stack's guard page, and protect the Linux main stack #6443

Merged
EagleBearerYS merged 12 commits from upstream-pr/6443 into main 2026-10-19 00:41:10 +00:00
EagleBearerYS commented 2026-10-15 15:36:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-15T15:36:33Z.


What

Follow-up to #5703, which commits the reserved pages of a host stack before protecting it on Windows. This closes the three gaps that commit leaves.

1. Windows: the guard page. Committing every reserved page of the range also cleared the guard page's PAGE_GUARD:

  • the thread had no guard and no reserve left, so an overflow ran into whatever lay below the stack instead of raising a stack overflow;
  • the stack limit in the thread's TEB, which only a guard page hit moves, stopped following the stack;
  • a range that began inside the reserve left the reserved pages below it with no guard above them, so the stack could no longer grow into them.

A protect now leaves the guard page and the reserved pages below it as they are, and commits and protects only what lies above them. Reserved pages above the guard are still committed first, and the protection is recorded for the whole range. This also drops the commit charge #5703 adds, up to the whole reserve of each thread.

Resident Evil Village (PPSA01556, 01.210.000) does this at startup: thread 23012 protects its whole 0x210000-byte host stack with 0xc2 while its lowest 0xd000 bytes are still reserved, so with #5703 alone that thread loses its guard page. A trace of every protect that overlaps a thread's own stack, on main 0b6d033b8 with #5703's commit:

[stack-protect] thread 23012 (stack 0x176b40000-0x176d50000): guest-stack protect 0x176b40000+0x210000 prot 0xc2, guest stack 0x176b40000-0x176d50000, own stack, reserved bytes committed 0xd000

The other nine protect part of their own stack that is already committed.

2. Windows: the bottom of the reserve. HotSpot makes its stack guard zones with a read/write protect of the lowest pages of a thread's stack, then PROT_NONE. On native Windows it commits them there (os::pd_create_stack_guard_pages, then os::guard_memory, in OpenJDK's os_windows.cpp). Under change 1 alone such a protect would only be recorded: the pages would stay reserved, so they couldn't be written after the read/write protect.

  • A protect of reserved pages that starts at the bottom of the reserve and stops short of the guard page is still committed and protected, as #5703 does. The guard page and the reserve above it stay as they are, so the stack still grows through the guard down to the zones, and the TEB's stack limit still follows it.
  • Windows moves its guard page down by committing the pages below it as read/write guard pages, whether they were reserved or committed. So the zones hold until the stack grows to within one guard region of them (three 4 KiB pages on GitHub's runners), then the pages the guard reaches come in read/write. It's the same with #5703's commit; the test pins both halves, and the debt file records it.

3. Linux: the main thread's stack. sceKernelIsStack reports the range pthread_getattr_np gives, which for the main thread is sized by RLIMIT_STACK and mostly unmapped (0x7fd000 bytes, 0x23000 of them mapped, on glibc 2.39). A protect of that range failed with ENOMEM, and sceKernelMprotect let the exception through, which stopped the title. When the stack branch's mprotect fails with ENOMEM, the unmapped runs are now mapped read/write in place (MAP_FIXED_NOREPLACE, no swap reserved) and the protection is applied again. The usual call still costs one mprotect.

  • Up to the stack's top. The mapping runs from the bottom of the protect up to the top of the reported stack, not just over the protected pages. Linux won't grow a stack to within its guard gap (1 MiB by default) of a readable mapping below it, so after a read-only protect at the bottom of the stack a deep call above it faulted where the console has stack. The pages are mapped lazily and cost nothing until touched.
  • The range is kept. glibc builds the main thread's range from /proc/self/maps on each call and cuts it at the mapping below the stack, so after the first protect it reported a smaller stack that started above the mapped pages, and a second protect of the same pages failed. Each thread's first queried range is now kept, so the main thread's range is the one from before any protect. A thread's stack never moves, so this changes nothing for other threads.
  • Runs, not pages. Unmapped pages are found one run at a time, with one msync per run instead of one per page. Under ulimit -s unlimited glibc reports the main stack down to the heap (tens of TiB), and a whole-stack protect probed it page by page for hours; it now takes a few dozen calls.

The commits:

  1. fix(libkernel): map the unmapped pages of a host stack before protecting it on Linux (3).
  2. test(libkernel): protect the whole main-thread stack on Linux too.
  3. fix(libkernel): keep a host stack's guard page and reserve when protecting it on Windows (1).
  4. test(libkernel): protect the bottom of a reserved host stack, then make it inaccessible (passes at its own commit: both protects return 0, the guard page stays, and the stack still grows).
  5. fix(libkernel): commit a protect at the bottom of a host stack's reserve (2), with the test's checks that the zone is writable, then inaccessible, and how far it holds.
  6. fix(libkernel): map a host stack's unmapped pages in runs on Linux (3, runs), with an unlimited-stack check.
  7. fix(libkernel): keep a host thread's stack range once queried on Linux (3, the range is kept), with a check that protects the bottom of the main stack twice.
  8. fix(libkernel): map a protected main stack up to its top on Linux (3, up to the top), with read-only and re-protected bottom checks, and the debt entry's Linux sentence.
  9. fix(libkernel): keep the cached host stack range in two scalar thread-locals (3, the range is kept), after a merge of main. Commit 7 kept the range in one 16-byte thread_local std::pair, which GCC stores with an aligned SSE move; in CI's Linux link libkernel.prx's TLS segment isn't 16-byte aligned, so a library that loads libkernel.prx with dlopen got that pair 8 bytes off and faulted on the first store. Two 8-byte thread-locals carry no such alignment.

Scope:

  • Holding a bottom zone exactly as on the console, until the stack touches it, would mean removing Windows' guard page for that thread and keeping the stack limit in its TEB by hand. That trades the host's own overflow detection and the unwinder's invariant for an edge case, and it is fragile when one thread protects another's stack, so it isn't done here. The debt entry says so.
  • Elsewhere below the guard page, the reserved pages take a protection only as the stack grows into them, and then read/write. A protection other than read/write there, PROT_NONE included, doesn't hold, where on the console every page of the reported range takes it; the debt file records this. #5918 reports an adopted thread's committed range instead, which keeps such pages out of the range.
  • A host error while committing, mapping or protecting throws with the host's error code, which the posix mprotect doesn't map to an errno, so FreeBSD's ENOMEM for a failed commit isn't reproduced. Pages committed or mapped before a later step throws stay read/write; nothing rolls them back.
  • On Linux a host thread's reported range also holds its TCB and static TLS, which aren't guarded the way guest threads' host-only pages are.
  • On Linux, pages below a protect of the main stack that doesn't start at the stack's bottom are out of reach, because the stack can't grow through the new mapping; the debt entry says so. Mapping the whole reported range would cover it, but under an unlimited stack limit that range covers the heap's growth space, so it would need a cap on the reported range first.
  • A protect of another guest thread's stack can race that thread's exit, as before this PR.

Tested

  • guest_kernel_stack_protect (core/libs/tests/GuestKernelStackProtect.cpp):
    • Windows:
      • The main thread protects its whole stack (from sceKernelIsStack) with 0xc2. Host threads created with a reserved, uncommitted stack (STACK_SIZE_PARAM_IS_A_RESERVATION) protect their whole stack, and their stack from the middle of the reserve.
      • After each protect, the guard page is still above the reserved pages, the pages above it are writable, the TEB's stack limit is the committed start, and the stack grows through the guard: a recursion two pages below it commits the old guard page, moves the guard down, and moves the stack limit with it. A PROT_NONE protect of the lowest page leaves all of that as it is.
      • The bottom of the reserve: a read/write protect of the lowest 48 KiB makes them writable, and PROT_NONE makes them inaccessible and unreadable. The stack then grows through the guard to one guard region above them: the guard sits right on the zone, the zone is intact, and the stack limit matches. One page further, the guard's lowest page moves into the zone's top page as read/write guard, while the rest of the zone stays inaccessible.
    • Linux: the main thread protects its whole stack with 0xc2 and writes to its lowest page. Three more checks run each in a fresh child, so each starts with an untouched main stack:
      • protect the bottom 64 KiB PROT_NONE, then read/write: sceKernelIsStack reports the same range after each, and writes just above the zone and 256 KiB above it succeed;
      • protect the bottom 64 KiB read-only, then make the same two writes;
      • under an unlimited stack limit, protect the whole reported stack and write its bottom byte within 5 s (skipped where the hard limit isn't unlimited or overcommit is strict).
  • GitHub's runners, on my fork:
    • Commit 5: with commit 4's DirectMemory.cpp, the test fails on Windows in every one of 3 runs, at the check that the read/write-protected zone is writable; with commit 5 it passes 20 of 20 on both (run).
    • Commit 4 passes 20 of 20 on both at its own commit (run).
    • On #5703's commit alone the test fails on Linux, where the main thread's whole-stack mprotect returns an error, and on Windows at the check that a guard page is still above the reserved pages. With commits 1-3 it passes 20 of 20 on both (run). With commits 1-2 it still fails on Windows at the same guard-page check and passes on Linux; with commit 3, 20 of 20 on both (run).
    • The libc and libkernel suites pass in every build (75 and 143 tests on Linux, 96 and 146 on Windows at the head), apart from guest_kqueue on Windows, which fails on main in the same runs.
    • At the head, on main 92e50418f3, which has #5703: with main's DirectMemory.cpp the test fails in every one of 3 runs, on Linux at the main thread's whole-stack protect and on Windows at the check that a guard page is still above the reserved pages. With this PR it passes 20 of 20 on both (run). Commit 4 alone passes 5 of 5 on both (run).
    • The full Build workflow on my fork at the head (run): 1,294 of 1,294 pass on Windows, 485 skipped, all expected by check_skips.py, and the write-watch, relinker and register-context jobs (macOS and Linux) pass.
  • Linux (Ubuntu 24.04, GCC 13.3, CI's configure flags, unprivileged user), commits 6-8, each with the previous commit's code: commit 6's check is still probing when its 5-second alarm fires (exit 142), and with commit 6 it finishes in 25 ms with 32 msync calls; commit 7's check fails at "sceKernelIsStack after a protect must report the same range"; commit 8's two checks die with SIGSEGV at the write just above the zone. Each passes at its own commit, the test passes 10 of 10 at commit 8, and the libc and libkernel suites pass apart from five network tests that need IPv6, which that machine lacks and which fail the same at commit 5.
  • GitHub's runners, commits 6-8 (run): with commit 5's code and the new checks the test fails on Linux, at "sceKernelIsStack after a protect must report the same range"; with commits 6-8 it passes 5 of 5. On Windows, where the new checks don't run, it passes with and without them. The only suite failure is guest_kqueue on Windows, with and without the change.
  • Linux (Ubuntu 24.04, GCC 13.3, CI's configure flags) on commits 1-2, on the branch's earlier base: each builds. With commit 1's code reverted, commit 2's test fails at the whole-stack protect of the main thread (0x7fd000 bytes, 0x23000 mapped) and ctest reports "Subprocess aborted"; with it, it passes 20 of 20.
  • Resident Evil Village with commit 3, on a local test tree whose stack-protect code (AboveStackGuard, CommitReservedPages and DoMprotect's stack branch) is identical to commit 3's; the tree carries other local changes on an older main. NVIDIA GeForce RTX 3070 Laptop GPU, driver 617.42; Windows 11 Home 10.0.26300. Resident Evil Village went from the start-up dialogs to the title (0.28 fps) and was held there 5.5 min, with no access violation or stack overflow in any thread. The 17,734-line log has no FATAL or abort() line.
  • PPSA99869: karimibrahim07 ran #5703's commit (187e5fc0ac) on #5918. Its stack guard zones take the bottom-of-reserve path, which commits and protects them as that commit does: they behave as with #5703 until the stack grows to within one guard region of them (12 KiB on GitHub's runners). karimibrahim07 then ran commit 5 merged onto main 5d9dcc42d (review): VM creation gets as far as with #5703, HotSpot commits the main thread's guard zones at the bottom of the reservation, and JNI_CreateJavaVM returns 0; guest_kernel_stack_protect and guest_thread_self pass on that tree.
  • Commit 9, on Linux with CI's Linux job (Ubuntu 24.04, GCC 13.3, CI's configure flags and linker; tests run as root, since that worker couldn't create an unprivileged user), at the head merged with main e1ac3300d3: without it, guest_memory_lifetime fails 5 of 5 ("memory lifetime: child failed during native exit (status=11)", a SIGSEGV in HostStackLimits called from DoMprotect after the child's module loaded libkernel.prx with dlopen), while main passes it 5 of 5. With it, the test passes 10 of 10 and guest_kernel_stack_protect 10 of 10. The libkernel suite passes 10 times under --parallel 4 apart from two tests that fail on main on that machine (a shared-memory test that fails as root, and guest_tcp, which needs IPv6), and the full ctest run (1,328 tests) fails only the tests that fail on main there.
  • GitHub's runners at the head (run): guest_kernel_stack_protect and the guest_thread* and guest_pthread* tests pass 5 of 5 on Windows and on Linux, and guest_memory_lifetime 5 of 5 on Linux (it isn't built on Windows). The libc and libkernel suites pass on Linux. On Windows their only failure is guest_kqueue, which the same verify script fails on a branch without this PR too (run).
  • The full Build workflow on my fork at the head, merged with main 6a32550fd1 (run): 1,366 of 1,366 pass on Windows, guest_kqueue included, and the 505 skipped are all expected by check_skips.py.
  • python3 tools/check_conventions.py --base origin/main: passed.

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 under Silent stubs in their library's technical debt file
  • 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 (#5703 is merged)
  • Related: #3965, #5918
  • Unblocks: no new stop; PPSA01556's thread 23012 (#5169) keeps its guard page and stack limit, and PPSA99869's guard zones keep #5703's behaviour
  • GPUs tested: NVIDIA GeForce RTX 3070 Laptop GPU, driver 617.42, Windows 11
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4875814009 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6443). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-15T15:36:33Z. --- ### What Follow-up to #5703, which commits the reserved pages of a host stack before protecting it on Windows. This closes the three gaps that commit leaves. **1. Windows: the guard page.** Committing every reserved page of the range also cleared the guard page's `PAGE_GUARD`: - the thread had no guard and no reserve left, so an overflow ran into whatever lay below the stack instead of raising a stack overflow; - the stack limit in the thread's TEB, which only a guard page hit moves, stopped following the stack; - a range that began inside the reserve left the reserved pages below it with no guard above them, so the stack could no longer grow into them. A protect now leaves the guard page and the reserved pages below it as they are, and commits and protects only what lies above them. Reserved pages above the guard are still committed first, and the protection is recorded for the whole range. This also drops the commit charge #5703 adds, up to the whole reserve of each thread. Resident Evil Village (PPSA01556, 01.210.000) does this at startup: thread 23012 protects its whole 0x210000-byte host stack with 0xc2 while its lowest 0xd000 bytes are still reserved, so with #5703 alone that thread loses its guard page. A trace of every protect that overlaps a thread's own stack, on `main` 0b6d033b8 with #5703's commit: ``` [stack-protect] thread 23012 (stack 0x176b40000-0x176d50000): guest-stack protect 0x176b40000+0x210000 prot 0xc2, guest stack 0x176b40000-0x176d50000, own stack, reserved bytes committed 0xd000 ``` The other nine protect part of their own stack that is already committed. **2. Windows: the bottom of the reserve.** HotSpot makes its stack guard zones with a read/write protect of the lowest pages of a thread's stack, then `PROT_NONE`. On native Windows it commits them there (`os::pd_create_stack_guard_pages`, then `os::guard_memory`, in OpenJDK's `os_windows.cpp`). Under change 1 alone such a protect would only be recorded: the pages would stay reserved, so they couldn't be written after the read/write protect. - A protect of reserved pages that starts at the bottom of the reserve and stops short of the guard page is still committed and protected, as #5703 does. The guard page and the reserve above it stay as they are, so the stack still grows through the guard down to the zones, and the TEB's stack limit still follows it. - Windows moves its guard page down by committing the pages below it as read/write guard pages, whether they were reserved or committed. So the zones hold until the stack grows to within one guard region of them (three 4 KiB pages on GitHub's runners), then the pages the guard reaches come in read/write. It's the same with #5703's commit; the test pins both halves, and the debt file records it. **3. Linux: the main thread's stack.** `sceKernelIsStack` reports the range `pthread_getattr_np` gives, which for the main thread is sized by `RLIMIT_STACK` and mostly unmapped (0x7fd000 bytes, 0x23000 of them mapped, on glibc 2.39). A protect of that range failed with `ENOMEM`, and `sceKernelMprotect` let the exception through, which stopped the title. When the stack branch's `mprotect` fails with `ENOMEM`, the unmapped runs are now mapped read/write in place (`MAP_FIXED_NOREPLACE`, no swap reserved) and the protection is applied again. The usual call still costs one `mprotect`. - **Up to the stack's top.** The mapping runs from the bottom of the protect up to the top of the reported stack, not just over the protected pages. Linux won't grow a stack to within its guard gap (1 MiB by default) of a readable mapping below it, so after a read-only protect at the bottom of the stack a deep call above it faulted where the console has stack. The pages are mapped lazily and cost nothing until touched. - **The range is kept.** glibc builds the main thread's range from `/proc/self/maps` on each call and cuts it at the mapping below the stack, so after the first protect it reported a smaller stack that started above the mapped pages, and a second protect of the same pages failed. Each thread's first queried range is now kept, so the main thread's range is the one from before any protect. A thread's stack never moves, so this changes nothing for other threads. - **Runs, not pages.** Unmapped pages are found one run at a time, with one `msync` per run instead of one per page. Under `ulimit -s unlimited` glibc reports the main stack down to the heap (tens of TiB), and a whole-stack protect probed it page by page for hours; it now takes a few dozen calls. The commits: 1. `fix(libkernel)`: map the unmapped pages of a host stack before protecting it on Linux (3). 2. `test(libkernel)`: protect the whole main-thread stack on Linux too. 3. `fix(libkernel)`: keep a host stack's guard page and reserve when protecting it on Windows (1). 4. `test(libkernel)`: protect the bottom of a reserved host stack, then make it inaccessible (passes at its own commit: both protects return 0, the guard page stays, and the stack still grows). 5. `fix(libkernel)`: commit a protect at the bottom of a host stack's reserve (2), with the test's checks that the zone is writable, then inaccessible, and how far it holds. 6. `fix(libkernel)`: map a host stack's unmapped pages in runs on Linux (3, runs), with an unlimited-stack check. 7. `fix(libkernel)`: keep a host thread's stack range once queried on Linux (3, the range is kept), with a check that protects the bottom of the main stack twice. 8. `fix(libkernel)`: map a protected main stack up to its top on Linux (3, up to the top), with read-only and re-protected bottom checks, and the debt entry's Linux sentence. 9. `fix(libkernel)`: keep the cached host stack range in two scalar thread-locals (3, the range is kept), after a merge of `main`. Commit 7 kept the range in one 16-byte `thread_local std::pair`, which GCC stores with an aligned SSE move; in CI's Linux link `libkernel.prx`'s TLS segment isn't 16-byte aligned, so a library that loads `libkernel.prx` with `dlopen` got that pair 8 bytes off and faulted on the first store. Two 8-byte thread-locals carry no such alignment. Scope: - Holding a bottom zone exactly as on the console, until the stack touches it, would mean removing Windows' guard page for that thread and keeping the stack limit in its TEB by hand. That trades the host's own overflow detection and the unwinder's invariant for an edge case, and it is fragile when one thread protects another's stack, so it isn't done here. The debt entry says so. - Elsewhere below the guard page, the reserved pages take a protection only as the stack grows into them, and then read/write. A protection other than read/write there, `PROT_NONE` included, doesn't hold, where on the console every page of the reported range takes it; the debt file records this. #5918 reports an adopted thread's committed range instead, which keeps such pages out of the range. - A host error while committing, mapping or protecting throws with the host's error code, which the posix `mprotect` doesn't map to an errno, so FreeBSD's `ENOMEM` for a failed commit isn't reproduced. Pages committed or mapped before a later step throws stay read/write; nothing rolls them back. - On Linux a host thread's reported range also holds its TCB and static TLS, which aren't guarded the way guest threads' host-only pages are. - On Linux, pages below a protect of the main stack that doesn't start at the stack's bottom are out of reach, because the stack can't grow through the new mapping; the debt entry says so. Mapping the whole reported range would cover it, but under an unlimited stack limit that range covers the heap's growth space, so it would need a cap on the reported range first. - A protect of another guest thread's stack can race that thread's exit, as before this PR. ### Tested - `guest_kernel_stack_protect` (`core/libs/tests/GuestKernelStackProtect.cpp`): - **Windows:** - The main thread protects its whole stack (from `sceKernelIsStack`) with 0xc2. Host threads created with a reserved, uncommitted stack (`STACK_SIZE_PARAM_IS_A_RESERVATION`) protect their whole stack, and their stack from the middle of the reserve. - After each protect, the guard page is still above the reserved pages, the pages above it are writable, the TEB's stack limit is the committed start, and the stack grows through the guard: a recursion two pages below it commits the old guard page, moves the guard down, and moves the stack limit with it. A `PROT_NONE` protect of the lowest page leaves all of that as it is. - The bottom of the reserve: a read/write protect of the lowest 48 KiB makes them writable, and `PROT_NONE` makes them inaccessible and unreadable. The stack then grows through the guard to one guard region above them: the guard sits right on the zone, the zone is intact, and the stack limit matches. One page further, the guard's lowest page moves into the zone's top page as read/write guard, while the rest of the zone stays inaccessible. - **Linux:** the main thread protects its whole stack with 0xc2 and writes to its lowest page. Three more checks run each in a fresh child, so each starts with an untouched main stack: - protect the bottom 64 KiB `PROT_NONE`, then read/write: `sceKernelIsStack` reports the same range after each, and writes just above the zone and 256 KiB above it succeed; - protect the bottom 64 KiB read-only, then make the same two writes; - under an unlimited stack limit, protect the whole reported stack and write its bottom byte within 5 s (skipped where the hard limit isn't unlimited or overcommit is strict). - GitHub's runners, on my fork: - Commit 5: with commit 4's `DirectMemory.cpp`, the test fails on Windows in every one of 3 runs, at the check that the read/write-protected zone is writable; with commit 5 it passes 20 of 20 on both ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/38749036523)). - Commit 4 passes 20 of 20 on both at its own commit ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/38742972323)). - On #5703's commit alone the test fails on Linux, where the main thread's whole-stack `mprotect` returns an error, and on Windows at the check that a guard page is still above the reserved pages. With commits 1-3 it passes 20 of 20 on both ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/38719081478)). With commits 1-2 it still fails on Windows at the same guard-page check and passes on Linux; with commit 3, 20 of 20 on both ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/38719097595)). - The libc and libkernel suites pass in every build (75 and 143 tests on Linux, 96 and 146 on Windows at the head), apart from `guest_kqueue` on Windows, which fails on `main` in the same runs. - At the head, on `main` 92e50418f3, which has #5703: with `main`'s `DirectMemory.cpp` the test fails in every one of 3 runs, on Linux at the main thread's whole-stack protect and on Windows at the check that a guard page is still above the reserved pages. With this PR it passes 20 of 20 on both ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/38758072016)). Commit 4 alone passes 5 of 5 on both ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/38758085920)). - The full Build workflow on my fork at the head ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/38758112999)): 1,294 of 1,294 pass on Windows, 485 skipped, all expected by `check_skips.py`, and the write-watch, relinker and register-context jobs (macOS and Linux) pass. - Linux (Ubuntu 24.04, GCC 13.3, CI's configure flags, unprivileged user), commits 6-8, each with the previous commit's code: commit 6's check is still probing when its 5-second alarm fires (exit 142), and with commit 6 it finishes in 25 ms with 32 `msync` calls; commit 7's check fails at "`sceKernelIsStack` after a protect must report the same range"; commit 8's two checks die with SIGSEGV at the write just above the zone. Each passes at its own commit, the test passes 10 of 10 at commit 8, and the libc and libkernel suites pass apart from five network tests that need IPv6, which that machine lacks and which fail the same at commit 5. - GitHub's runners, commits 6-8 ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/38868320403)): with commit 5's code and the new checks the test fails on Linux, at "`sceKernelIsStack` after a protect must report the same range"; with commits 6-8 it passes 5 of 5. On Windows, where the new checks don't run, it passes with and without them. The only suite failure is `guest_kqueue` on Windows, with and without the change. - Linux (Ubuntu 24.04, GCC 13.3, CI's configure flags) on commits 1-2, on the branch's earlier base: each builds. With commit 1's code reverted, commit 2's test fails at the whole-stack protect of the main thread (0x7fd000 bytes, 0x23000 mapped) and ctest reports "Subprocess aborted"; with it, it passes 20 of 20. - **Resident Evil Village with commit 3**, on a local test tree whose stack-protect code (`AboveStackGuard`, `CommitReservedPages` and `DoMprotect`'s stack branch) is identical to commit 3's; the tree carries other local changes on an older `main`. NVIDIA GeForce RTX 3070 Laptop GPU, driver 617.42; Windows 11 Home 10.0.26300. Resident Evil Village went from the start-up dialogs to the title (0.28 fps) and was held there 5.5 min, with no access violation or stack overflow in any thread. The 17,734-line log has no FATAL or `abort()` line. - **PPSA99869:** karimibrahim07 ran #5703's commit (187e5fc0ac) on #5918. Its stack guard zones take the bottom-of-reserve path, which commits and protects them as that commit does: they behave as with #5703 until the stack grows to within one guard region of them (12 KiB on GitHub's runners). karimibrahim07 then ran commit 5 merged onto `main` 5d9dcc42d ([review](https://github.com/boykopovar/AnyPS5/pull/6443#pullrequestreview-5544440438)): VM creation gets as far as with #5703, HotSpot commits the main thread's guard zones at the bottom of the reservation, and `JNI_CreateJavaVM` returns 0; `guest_kernel_stack_protect` and `guest_thread_self` pass on that tree. - **Commit 9**, on Linux with CI's Linux job (Ubuntu 24.04, GCC 13.3, CI's configure flags and linker; tests run as root, since that worker couldn't create an unprivileged user), at the head merged with `main` e1ac3300d3: without it, `guest_memory_lifetime` fails 5 of 5 ("memory lifetime: child failed during native exit (status=11)", a SIGSEGV in `HostStackLimits` called from `DoMprotect` after the child's module loaded `libkernel.prx` with `dlopen`), while `main` passes it 5 of 5. With it, the test passes 10 of 10 and `guest_kernel_stack_protect` 10 of 10. The libkernel suite passes 10 times under `--parallel 4` apart from two tests that fail on `main` on that machine (a shared-memory test that fails as root, and `guest_tcp`, which needs IPv6), and the full ctest run (1,328 tests) fails only the tests that fail on `main` there. - GitHub's runners at the head ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39006540251)): `guest_kernel_stack_protect` and the `guest_thread*` and `guest_pthread*` tests pass 5 of 5 on Windows and on Linux, and `guest_memory_lifetime` 5 of 5 on Linux (it isn't built on Windows). The libc and libkernel suites pass on Linux. On Windows their only failure is `guest_kqueue`, which the same verify script fails on a branch without this PR too ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/38993506329)). - The full Build workflow on my fork at the head, merged with `main` 6a32550fd1 ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39010115285)): 1,366 of 1,366 pass on Windows, `guest_kqueue` included, and the 505 skipped are all expected by `check_skips.py`. - `python3 tools/check_conventions.py --base origin/main`: passed. ### 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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 (#5703 is merged) - [x] Related: #3965, #5918 - [x] Unblocks: no new stop; PPSA01556's thread 23012 (#5169) keeps its guard page and stack limit, and PPSA99869's guard zones keep #5703's behaviour - [x] GPUs tested: NVIDIA GeForce RTX 3070 Laptop GPU, driver 617.42, Windows 11 - [x] AI-assisted: yes
EagleBearerYS commented 2026-10-15 15:37:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-15T15:37:58Z.


@karimibrahim07, you ran #5703's commit on PPSA99869 (#5918). Could you run this one too, at 5796ddfcfd, when you have a moment? Its guard-zone path at the bottom of a thread's stack commits and protects the zones as #5703 did. What changes is that the guard page and the reserve above the zones now stay, so the zones behave as they did with #5703 until the stack grows to within one guard region of them. A run that gets as far as it did with #5703, or a log line if it doesn't, would confirm that.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6195984577 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6443#issuecomment-6195984577). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-15T15:37:58Z. --- @karimibrahim07, you ran #5703's commit on PPSA99869 (#5918). Could you run this one too, at 5796ddfcfd, when you have a moment? Its guard-zone path at the bottom of a thread's stack commits and protects the zones as #5703 did. What changes is that the guard page and the reserve above the zones now stay, so the zones behave as they did with #5703 until the stack grows to within one guard region of them. A run that gets as far as it did with #5703, or a log line if it doesn't, would confirm that.
github-actions[bot] commented 2026-10-15 15:45:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T15:45:46Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 3986 core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 5021 core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
docs/dev/debt/libkernel.md
PR 6044 core/libs/tests/GuestKernelStackProtect.cpp
PR 6149 docs/dev/debt/libkernel.md
PR 6446 docs/dev/debt/libkernel.md
PR 6487 core/libs/prx/libkernel/Pthread/src/Thread.cpp
docs/dev/debt/libkernel.md
PR 6510 docs/dev/debt/libkernel.md
PR 6519 docs/dev/debt/libkernel.md
PR 6534 core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
core/libs/tests/GuestKernelStackProtect.cpp
docs/dev/debt/libkernel.md
PR 6879 core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 6908 docs/dev/debt/libkernel.md
PR 6915 docs/dev/debt/libkernel.md
PR 6936 docs/dev/debt/libkernel.md
PR 6977 docs/dev/debt/libkernel.md
PR 7039 docs/dev/debt/libkernel.md
PR 7049 docs/dev/debt/libkernel.md
PR 7075 docs/dev/debt/libkernel.md
PR 7088 docs/dev/debt/libkernel.md
PR 7105 core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp
docs/dev/debt/libkernel.md
PR 7121 docs/dev/debt/libkernel.md
PR 7129 docs/dev/debt/libkernel.md
PR 7149 core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
docs/dev/debt/libkernel.md
PR 7192 docs/dev/debt/libkernel.md
PR 7201 core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
core/libs/tests/GuestKernelStackProtect.cpp
PR 7509 docs/dev/debt/libkernel.md
PR 7565 core/libs/prx/libkernel/Pthread/src/Thread.cpp
docs/dev/debt/libkernel.md
PR 7653 docs/dev/debt/libkernel.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6196140651 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6443#issuecomment-6196140651). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T15:45:46Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 3986](https://www.github.com/boykopovar/AnyPS5/pull/3986) | `core/libs/prx/libkernel/Pthread/src/Thread.cpp` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp`<br>`core/libs/prx/libkernel/Pthread/src/Thread.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestKernelStackProtect.cpp` | | [PR 6149](https://www.github.com/boykopovar/AnyPS5/pull/6149) | `docs/dev/debt/libkernel.md` | | [PR 6446](https://www.github.com/boykopovar/AnyPS5/pull/6446) | `docs/dev/debt/libkernel.md` | | [PR 6487](https://www.github.com/boykopovar/AnyPS5/pull/6487) | `core/libs/prx/libkernel/Pthread/src/Thread.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 6510](https://www.github.com/boykopovar/AnyPS5/pull/6510) | `docs/dev/debt/libkernel.md` | | [PR 6519](https://www.github.com/boykopovar/AnyPS5/pull/6519) | `docs/dev/debt/libkernel.md` | | [PR 6534](https://www.github.com/boykopovar/AnyPS5/pull/6534) | `core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp`<br>`core/libs/prx/libkernel/Pthread/src/Thread.cpp`<br>`core/libs/tests/GuestKernelStackProtect.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp`<br>`core/libs/prx/libkernel/Pthread/src/Thread.cpp` | | [PR 6908](https://www.github.com/boykopovar/AnyPS5/pull/6908) | `docs/dev/debt/libkernel.md` | | [PR 6915](https://www.github.com/boykopovar/AnyPS5/pull/6915) | `docs/dev/debt/libkernel.md` | | [PR 6936](https://www.github.com/boykopovar/AnyPS5/pull/6936) | `docs/dev/debt/libkernel.md` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `docs/dev/debt/libkernel.md` | | [PR 7039](https://www.github.com/boykopovar/AnyPS5/pull/7039) | `docs/dev/debt/libkernel.md` | | [PR 7049](https://www.github.com/boykopovar/AnyPS5/pull/7049) | `docs/dev/debt/libkernel.md` | | [PR 7075](https://www.github.com/boykopovar/AnyPS5/pull/7075) | `docs/dev/debt/libkernel.md` | | [PR 7088](https://www.github.com/boykopovar/AnyPS5/pull/7088) | `docs/dev/debt/libkernel.md` | | [PR 7105](https://www.github.com/boykopovar/AnyPS5/pull/7105) | `core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 7121](https://www.github.com/boykopovar/AnyPS5/pull/7121) | `docs/dev/debt/libkernel.md` | | [PR 7129](https://www.github.com/boykopovar/AnyPS5/pull/7129) | `docs/dev/debt/libkernel.md` | | [PR 7149](https://www.github.com/boykopovar/AnyPS5/pull/7149) | `core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp`<br>`core/libs/prx/libkernel/Pthread/src/Thread.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 7192](https://www.github.com/boykopovar/AnyPS5/pull/7192) | `docs/dev/debt/libkernel.md` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp`<br>`core/libs/prx/libkernel/Pthread/src/Thread.cpp`<br>`core/libs/tests/GuestKernelStackProtect.cpp` | | [PR 7509](https://www.github.com/boykopovar/AnyPS5/pull/7509) | `docs/dev/debt/libkernel.md` | | [PR 7565](https://www.github.com/boykopovar/AnyPS5/pull/7565) | `core/libs/prx/libkernel/Pthread/src/Thread.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 7653](https://www.github.com/boykopovar/AnyPS5/pull/7653) | `docs/dev/debt/libkernel.md` |
karimibrahim07 commented 2026-10-16 07:35:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by karimibrahim07 on 2026-10-16T07:35:58Z.

Review: COMMENTED


@EagleBearerYS here's PPSA99869 with this PR. Head f697e1a41 merged onto main 5d9dcc42d (clean merge; it also merges cleanly with #6534). Windows 11 Pro (26300), Ryzen 5 3600, RTX 3060, WinLibs GCC 15.2.0 r7, Ninja Release. Same setup as in #5918 (--windows --to-intel --trap-sdk-syscall-stubs --registry). Two runs:

  • VM creation gets as far as with #5703. HotSpot commits the main thread's guard zones at the bottom of the reservation: DONE: Native RW memory commit addr=0x400000 bytes=49152 mode=3 errno=0. There is no Attempt to allocate stack guard pages failed, and JNI_CreateJavaVM returned 0.
  • DestroyJavaVM complete, with the usual Attempt to deallocate stack guard pages failed for the main thread (0x400000) and one VM thread. #6534 addresses those.
  • DNS went past the app's 8-second limit in both runs. That isn't this PR: a control run on plain main 5d9dcc42d, same day and machine, times out the same way, while the host resolves example.com fine. With #5703 it passed here two days ago. The LAN row has no helper and wasn't run.

guest_kernel_stack_protect and guest_thread_self pass on this tree.

AI-assisted: yes. I ran the builds, the tests and the title above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5544440438 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6443#pullrequestreview-5544440438). Originally posted by [karimibrahim07](https://github.com/karimibrahim07) on 2026-10-16T07:35:58Z. **Review:** COMMENTED --- @EagleBearerYS here's PPSA99869 with this PR. Head `f697e1a41` merged onto `main` `5d9dcc42d` (clean merge; it also merges cleanly with #6534). Windows 11 Pro (26300), Ryzen 5 3600, RTX 3060, WinLibs GCC 15.2.0 r7, Ninja Release. Same setup as in #5918 (`--windows --to-intel --trap-sdk-syscall-stubs --registry`). Two runs: - **VM creation** gets as far as with #5703. HotSpot commits the main thread's guard zones at the bottom of the reservation: `DONE: Native RW memory commit addr=0x400000 bytes=49152 mode=3 errno=0`. There is no `Attempt to allocate stack guard pages failed`, and `JNI_CreateJavaVM returned 0`. - **`DestroyJavaVM complete`**, with the usual `Attempt to deallocate stack guard pages failed` for the main thread (`0x400000`) and one VM thread. #6534 addresses those. - **DNS** went past the app's 8-second limit in both runs. That isn't this PR: a control run on plain `main` `5d9dcc42d`, same day and machine, times out the same way, while the host resolves `example.com` fine. With #5703 it passed here two days ago. The LAN row has no helper and wasn't run. `guest_kernel_stack_protect` and `guest_thread_self` pass on this tree. AI-assisted: yes. I ran the builds, the tests and the title above.
EagleBearerYS commented 2026-10-16 07:49:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-16T07:49:05Z.


Thanks for running it on PPSA99869, @karimibrahim07. I've added your run to the Tested section.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6210721944 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6443#issuecomment-6210721944). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-16T07:49:05Z. --- Thanks for running it on PPSA99869, @karimibrahim07. I've added your run to the Tested section.
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!6443
No description provided.