Repository navigation
fix(libkernel): commit a reserved host stack before protecting it - #5703
adriadam10 merged 1 commit into
Conversation
Guest threads run on host stacks that Windows reserves (0x210000 bytes by default) and commits on demand. Resident Evil Village protects one thread's whole host stack with 0xc2 at startup while its lowest 0xd000 bytes are still only reserved, so the Windows mprotect emulation threw. When such a stack sat inside the arena bounds as a host region, the call took the arena commit path and failed to split a placeholder that was never one. Commit the reserved pages of a host range before protecting it, and only use the arena commit for ranges the arena owns.
|
This overlaps in effect with #5918, which is about the same Windows host-stack layout (a 0x210000 reservation with only the top committed). The two take different routes:
With this PR alone, HotSpot's guard-page |
|
Answered on #5918 with our trace: #5918 (comment). We'll boot Village with #5918 in place of this PR. |
|
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.
|
|
Checked the diff: |
What
This complements #3965.
On Windows, guest threads run on host stacks that Windows reserves (0x210000 bytes by default) and commits on demand. When a title protects such a stack while its lowest pages are still only reserved, the mprotect emulation throws
Where the stack lay inside the arena bounds as a host region, the call took the arena commit path instead, and failed to split a placeholder that was never one.
Resident Evil Village (PPSA01556, 01.210.000) hits this at startup. One guest thread protects its whole 0x210000-byte host stack with 0xc2 while the lowest 0xd000 bytes are still only reserved.
With #3965 (49b51d2), which moves the main thread onto an arena-backed stack, the main thread runs on that stack as intended. Village still stops 44 s in, on this other thread. The emulation sees native protection 0x3, read/write (this trace prints only the native value):
DoMprotectcommits the reserved pages of a range the arena doesn't own (CommitReservedPages) before it protects them.mprotectuses the arena commit only for ranges the arena owns.KernelArena::Ownsmeans inside the arena and not overlapping a host region.The change applies to any host stack the arena doesn't own.
Tested
guest_kernel_stack_protect(core/libs/tests/GuestKernelStackProtect.cpp), on Windows:sceKernelIsStack) with 0xc2 and writes to it;STACK_SIZE_PARAM_IS_A_RESERVATION).main'sDirectMemory.cpp(abort), and passes 20 of 20 runs with the change;mainf87799a (https://github.com/EagleBearerYS/AnyPS5/actions/runs/38523213127). Windows: 1137 of 1137 pass, with the Vulkan tests skipped because the runner has no Vulkan device. Linux: 1114 of 1114 pass.main0b6d033. NVIDIA GeForce RTX 3070 Laptop GPU, driver 617.42; Windows 11 Home 10.0.26300; AMD Ryzen 9 5900HS, 15.4 GB of RAM.Plain
maincan't boot Village on this PC. Preparing every shader at registration gave a black screen for 10 minutes here, with private memory at 21.9 GB and heading for the commit limit. So these runs add two local commits and a one-line adaptation that prepare each shader at its first draw instead (APS5_RE8_LAZY_PREPARE=1), plusAPS5_NO_GPL=1. They change onlyShaderRegistry.cpp.fix(agc): heap-mirror ranges whose import windows left the write watch #5688 is added too, for a separate startup abort.
Without this change, Village stops with the message above:
APS5_ADDRESS_COPY_MAX_MIB=512in place of fix(agc): heap-mirror ranges whose import windows left the write watch #5688;With this change (and fix(agc): heap-mirror ranges whose import windows left the write watch #5688, without fix(windows): enter guest startup on an arena-backed main stack #3965), there's no stop. Village shows the autosave notice and the VR question, then goes on to the title. It was still running 300-360 s in, when the test stopped it.
A trace of every protect that overlaps a thread's own stack showed 10 of them. Nine worker threads protect part of their own already committed stack. One protects its whole 0x210000-byte host stack, and the change commits its 0xd000 reserved bytes first:
python3 tools/check_conventions.py --base origin/main: passed.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)main)