libkernel: on Linux, guest thread stacks are mapped near 0x7fff00000000, outside the application area (ChakraCore OutOfMemoryException in Ratchet & Clank: Rift Apart) #3283
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 Tamalero on 2026-10-11T05:12:13Z.
On Linux, Ratchet & Clank: Rift Apart ends early in its intro with
Terminating due to uncaught exception of type Js::OutOfMemoryException. The JavaScript engine it ships (ChakraCore, used by its UI) runs out of memory not for lack of memory, but because of where AnyPS5 puts guest thread stacks.glibc maps each guest thread's stack near the top of the host address space, around
0x7fff00000000(~128 TiB). On the console, application memory, stacks included, lies in the application area below0xFC00000000(AnyPS5's ownApplicationAreaEndinGuestArena.cpp), and ChakraCore relies on that. Its garbage collector indexes a 4 MiB table withaddress >> 18, which covers addresses up to 1 TiB, so a stack address far above that falls outside the table and the engine reports out-of-memory.I have a fix on a branch with a test, and I'm opening this as an issue because PRs from new authors are closed by intake:
github.com/Tamalero/AnyPS5@4e97c683(branchfix/guest-thread-stackson my fork, based onmain961b25fe). If it looks right, I can open it as a PR whenever that suits you.Details
Title: Ratchet & Clank: Rift Apart (PPSA01474, content 01.005.003)
Where it stops: early in the intro, a few frames in, in every run without the change. CachyOS (Linux 7.2), GCC, Release, RTX 4090, i9-14900K, relinked with
--to-intel. The title needs other local changes to get this far (see #3272), but this failure is independent of them: removing only this change from that tree brings the exception back.What the trace shows
table + (address >> 18)for an address around0x7fff00000000. That offset (~512 MiB) is past the end of the table, the commit fails, and the engine throwsJs::OutOfMemoryException.pthread_createwith a size-only attribute, so glibc placed it.The change
scePthreadCreatemaps each guest thread's stack withDoMapAnon, so it comes from the guest arena and is a registered guest allocation. APROT_NONEguard page sits below it, and it is passed topthread_attr_setstack.nativeStack, so #2647'sHOST_STACK_MARGINbelow the guest range is unchanged./proc/self/task.Tested
guest_kernel_is_stacknow also checks, from a guest thread, that its stack is below0xFC00000000and thatsceKernelVirtualQueryfinds it. Without the change the test aborts; with it, it passes.guest_pthread_stack(#2647's host-margin test),linux_guest_stack,guest_sigaltstack, and the thread, TLS, cancel and memory tests: 80/80.pr_overlap_encoding, a local Python 3.10 environment issue that also fails onmain.tools/check_conventions.pypasses.mprotecton Windows.Related: #2647, #2982, #3272.
Tested and written by Claude (AI assistant) on a contributor's machine.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T00:08:30Z.
Fixed by #4283, which carried your branch: guest thread stacks on Linux now come from the guest arena. If ChakraCore still runs out of memory on current main, comment here.