Windows: NHL 26 (PPSA26785) crashes with 0xc0000005 on its Heartbeat thread walking a thread's stack range after the stack was freed; a shader disk cache file view sat at its base #7700
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 frankea on 2026-10-19T01:14:39Z.
NHL 26 (PPSA26785, 01.060.000, Frostbite) on Windows 11 26200, RTX 4090 (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 r7, Release
libs,main376c04029+ #7048, relinked with--windows --registry, warm shader cache. After a scripted Cross on the title screen the title shows its legal agreements page; 57 s later, on that page at 0.5 FPS (frame 963), the process dies:What the code at
ripdoes (relinkedapp.exe, same offsets as the dump):So the Heartbeat thread (EA's health reporter) takes a conservative stack walk of a thread from a (top, base) record it keeps: 128 KiB from 0x124b80000 down to 0x124b60000. The top page of that range is not mapped, and the base holds a shader disk cache file header: magic
APSC, format 38, source version e1a9668d4734dbb5 (this tree'sshader_cachedirectory), 0x1034 key bytes, 0x3eb4 payload bytes, two hashes, i.e. aMapViewOfFileview of one of the*.binfiles thatcore/shader/recompiler/ShaderDiskCache.cpp(MapFile) maps while it loads shaders (129 cache hits in the 10 s before the crash). No thread in the dump's thread list has its stack in that range.Why a title thread's stack can end up there: on Windows a guest thread runs on the stack of its host thread, and that stack is what the guest sees as its own (
core/libs/prx/libkernel/Pthread/src/Thread.cpp,StartNativeThread:GetCurrentThreadStackLimits,stackAddress = high - stackSize; a stack set withscePthreadAttrSetstackis replaced by it). Windows releases that stack when the host thread ends, and the next system-placed allocation, here a cache file view, can take the address. A title that keeps the stack range of a thread it created and walks it later, as this one does from its Heartbeat thread, then reads foreign or unmapped memory. On a PS5 a stack the title supplied stays mapped as long as the title keeps it; whether NHL 26 supplies its own stack memory I cannot tell from the logs (the relinked executable's imports are by NID).Seen once in three visits to that page (two other runs sat on it for 8 and 5 min, one of them pressing on to the next menu); before the first visible frame the same thread never faulted in 10 runs. The 900 s runs also show the title's own "GPU stopped working" breadcrumb recovery on 7 to 8 frames when that page comes up (see my notes on the bring-up thread #7304), which is when the page runs at 0.2 to 0.6 FPS and the Heartbeat thread is presumably busy reporting. Host memory was tight (
app.exeworking set 23 GiB, 160 to 800 MiB of free physical memory on the 32 GiB box). Full logs, the title-bar frame log and the memory samples on request.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-19T02:38:03Z.
@frankea a note on the cause, since this isn't Windows-only in principle.
On FreeBSD, which the PS5's libkernel threads are based on, a thread's stack outlives the thread. In FreeBSD 11's
lib/libthr/thread/thr_stack.c,_thr_stack_freeputs a dead thread's stack on a spare list (dstackqfor the default size,mstackqfor others), and_thr_stack_allochands it to the next thread of the same size. A stack is only unmapped when mapping a new one fails. So on a console, a walk like NHL 26's Heartbeat reads stale but mapped memory: the old thread's frames, with libthr's 40-byte free-list record at the top of the range. I haven't checked this on a console; it's inferred from the FreeBSD source.AnyPS5 releases the stack on both hosts:
_beginthreadexgave its host thread, and Windows frees that stack when the thread ends, as you found.Thread.cppmaps the guest stack itself (AllocateGuestStack) and unmaps it when the thread is joined (FreeGuestStack), or, for a detached thread, at the nextscePthreadCreateafter its host thread is gone (ReapRetiredStacks).GuestPthreadStack.cpprequires that unmap (retiredUnmapped, from #5597). So the same walk could fault on Linux too, without any foreign mapping: the range is simply gone.A fix along libthr's lines would keep released stacks on a spare list and reuse them by size:
FreeGuestStackandReapRetiredStacks, plus flipping that test's requirement to "stays mapped and is reused"._beginthreadexcan't take a caller's stack.Memory would then be bounded by the peak number of live threads of each stack size, as on the console, rather than by the current number.
@JJenkx, you added the unmap requirement: would a libthr-style spare list be acceptable to you? If so, I can do the Linux half with a test that reads a joined thread's and a reaped detached thread's stack range after they exit (on
mainthat read should fault, since both ranges are unmapped).AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ionut27001 on 2026-10-19T09:11:11Z.
Measured in a payload process on a PS5 (firmware 12.70; payload SDK v0.44, clang 18.1.8). Threads are made with
scePthreadCreate(default attributes unless noted: 64 KiB stack, 16 KiB guard), report their own stack throughscePthreadAttrGetandscePthreadAttrGetstack, fill 4 KiB of their stack with a marker (the word quoted is 2144 bytes below the top), and end; the creating thread then queries and reads the range. Probep77_libkernel, source and both logs: p77-thread-stacks.zip (the first log is version 1 of the probe, without thetwelvecase and theaddr=field). Lines are quoted unchanged with ap77:prefix, from the second run unless marked.1. The stack of an ended thread stays mapped, with its content. After
scePthreadJoin,sceKernelQueryMemoryProtectionon the top byte reports protection 3 over exactly the thread's range and 0 over the 16 KiB below it;sceKernelVirtualQueryreports the range with protection 3, the stack bit (byte 32 is 0x05, which reads asis_flexibleandis_stackin AnyPS5'sVirtualQueryInfo,core/libs/SceTypes.hpp) and the thread's name; the marker reads back unchanged:The same for a thread detached after creation, at least 200 ms after it set its done flag:
2. Another thread reads it.
seen_at_entryis a word a new thread reads as the first statement of its entry function, at an address inside an earlier thread's stack, before writing anything of its own at that depth:seq2, on a different stack, sawseq1's marker;new2andaft4, running on the very stack ofconc0and of the detached thread, saw their markers:3. Reuse is late and in batches. No thread got the stack of the thread joined just before it. The first section ends five threads (
seq1,seq2,seq3_bigger,seq4_default,seq5_bigger), each on a new range (adjacent default stacks are 80 KiB apart: 64 KiB stack plus 16 KiB guard):Twelve default threads then created and joined one after another: the first three got the three default stacks of that section (
7eee3c000,7eee28000,7eedd0000), the fourth and fifth new ranges, and from the sixth on each got the stack of the thread created five before it:Four threads alive at once, joined in order, then four more, then a detached thread and threads after it: within each batch the stacks come back in the order their threads ended, and the detached thread's stack went to the fifth thread created after it ended, after which that range was still mapped (the
detached_after_8label is the probe's; its loop stopped at the fifth thread):This is the hand-out order FreeBSD 11's libthr produces: a dead thread that has been joined or detached goes on
_thread_gc_list(_thr_try_gc, fromjoin_commonunder_pthread_joinand fromexit_threadunder_pthread_exit),pthread_createruns_thr_gconly once five are waiting (GC_NEEDED(),_thr_alloc), which returns their stacks to the spare list (_thr_stack_free), and_thr_stack_allochands them out from its head; the two head insertions make a batch come out oldest first, in front of stacks freed earlier. A simulation of that mechanism reproduces every hand-out in both runs. Every range queried after its thread ended was still mapped, and every default stack handed out again came back at its old address; new ranges were placed below the previous one, as_thr_stack_allocdoes. libthr never unmaps a spare stack; the onlymunmapinthr_stack.cis of a new mapping whose guardmprotectfailed (L274-L284), not exercised here.4. The top of an ended thread's stack. Of the top 64 bytes, the words at top-64, top-56 and top-24 are not zero on every stack read and the others are zero, except top-40 on the detached thread's stack. The word at top-64 points at top-16, as a saved frame pointer would; the word at top-56 is the same address in every stack of a process (0x835d94355 in this run, 0x816cc0355 in the first), as a return address into libkernel's thread start routine would be; top-24 holds a second per-process constant (0x880488020 here, 0x8801e0020 in the first run). The probe only dumps the words; reading them as the entry function's first frame is an inference from the values, not traced further. On the detached thread's stack the word at top-40, where libthr keeps
le_next, pointed at top-40 of the free stack at 0x7eed50000 (0x7eed5ffd8). That is the stale link from that stack's own earlier free: in the libthr simulation it had been put on the spare list right after 0x7eed50000 in the batch freed whennew0was created, was handed out again to the detached thread, and was read here before any later free, so the word does not show a record written at exit. Every stack top was read before a batch free, so whether a full libthr record (stacksize,guardsize,stackaddr) appears after one was not measured.(first run)
Two threads with a 256 KiB stack: the first's range was still mapped after join, and the second, created before any batch had been freed, got a new range. Not measured: a 256 KiB thread created after a batch free, a thread with a caller-supplied stack, a mapping failure, and a game process.
For #7700: in this payload process, a walk like NHL 26's over a finished thread's range (from top-16 down in 16-byte steps) reads zeros and one in-range pointer in the top 64 bytes and then the thread's own stale frames, until the range is handed to a later thread of the same size and guard, which happens only once five ended threads have been joined or detached. NHL 26's range is 128 KiB, not the 64 KiB default seen here, which libthr serves from the by-size list (
mstackq); reuse at that size was not measured here.Edited after a second read: section 4's reading of the top-40 word (a stale free-list link, not a record written at exit) and three FreeBSD line ranges.
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-19T11:35:46Z.
@ionut27001 thank you, this is the console measurement my comment above could only infer from the FreeBSD source. On a PS5:
So NHL 26's Heartbeat walk over an ended thread's range reads that thread's stale frames on the console, not unmapped memory. Your top-of-stack words also show what it reads first: a frame pointer at top-64, a libkernel return address at top-56, and the stale
le_nextlink only on a stack that had already been on the spare list.@MarcZX10 has since opened #7838 for the Linux half: ended stacks stay mapped and are reused by size in batches of five, matching what you measured. Their test could only run in a container with the CPU guard bypassed, but @jotitadev has since run it unmodified on Linux, with a red check against
mainand a 5,400-thread stress run. The Windows half still needs AnyPS5 to allocate the guest stack itself, as described above.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by frankea on 2026-10-19T16:46:30Z.
Thank you both: @milescoviello for the libthr reading and @ionut27001 for the console run, which settles that the Heartbeat walk reads stale but mapped frames on a PS5 rather than unmapped memory. A spare-stack list along libthr's lines sounds right to me as the issue's author; I'll re-run NHL 26 (PPSA26785) on the RTX 4090 with the Linux half or a Windows build of it when there is a branch.
I have a PS5 on firmware 13.40 with a working payload setup, and I can also make calls inside a running retail game process (an elfldr payload attached with ptrace, which borrows a stopped game thread). If it helps, I can re-run
p77_libkernelunchanged on 13.40, and check the same thing from inside a title: that a joined thread's stack range in a game process stays mapped and is handed to the next thread of the same size, with the five-thread batching ionut27001 saw. Say if either would be useful and I'll post the logs here.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-19T16:47:11Z.
@frankea thanks, both would help, and the in-title check most. ionut27001's run used the 64 KiB default stacks, and says reuse at other sizes, which libthr serves from the by-size list (
mstackq), wasn't measured there. NHL 26's Heartbeat walks a 128 KiB range. So the most useful log is from inside a game process: whether a joined or detached 128 KiB thread's range stays mapped with its contents, and whether the next 128 KiB thread gets it back once five ended threads wait. The same check at 64 KiB would show whether a game process batches like ionut27001's payload did.p77_libkernelunchanged on 13.40 would confirm the behavior holds on a second firmware. That's cheap if you're set up for it, but less important.For the Linux half there's already a branch: MarcZX10's #7838 keeps ended stacks mapped and reuses them by size in batches of five, and jotitadev and simonbbby have validated it on Linux. On your 4090 you could run NHL 26 on
mainand on #7838's head (916bdb06a6) on Linux. The Windows half doesn't exist yet. It first needs AnyPS5 to allocate the guest stack itself instead of taking_beginthreadex's.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by frankea on 2026-10-19T17:14:40Z.
@milescoviello I looked into the main vs #7838 run and can't do it on the 4090 as things stand. The box runs Windows only, with no Linux install. Its WSL2 Ubuntu has NVIDIA's CUDA and D3D12 libraries but no NVIDIA Vulkan driver (
/usr/share/vulkan/icd.dlists only Mesa ICDs, lavapipe being the only one that would load). A Linux AnyPS5 there would render on the CPU, not the 4090, and that VM is shared with another long-running service under a 24 GB cap, while NHL 26 needs 22-24 GiB on its own.A Windows build of 916bdb06a6 wouldn't stand in for it either: every changed line in
Pthread/src/Thread.cppis inside the#if defined(__linux__)block, so on Windows it runs the same stack code asmain.If the Linux run turns out to be needed I can install Linux on the box later; I'll post the results here if I do. The Windows half is the one I can test right away: when there is a branch that allocates the guest stack itself, the NHL 26 layout and the scripted path to the legal and quick-settings pages (where the Heartbeat crash showed up in 1 of 3 runs) are ready on the box. The in-title PS5 check you asked for (128 KiB and 64 KiB thread stacks in a game process) is being done separately, and I'll post it here.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-19T17:28:35Z.
@frankea thanks for checking. You're right that a Windows build of #7838 changes nothing there: all of it is inside the
__linux__block. Don't install Linux for this; the Linux half is already covered by jotitadev's and simonbbby's runs on #7838.The Windows half doesn't exist yet. It needs the guest to run on a stack AnyPS5 allocates and keeps after the thread ends, instead of the one
_beginthreadexgives the host thread and Windows frees at exit. That means switching the thread onto that stack at guest entry, keeping the TEB's stack bounds in step for stack probes and exception unwinding, and switching back before the host thread exits. Ended stacks then go on a spare list by size, as on Linux and in libthr. I'll post here when there's a branch. Your scripted path to the legal and quick-settings pages is exactly what it needs.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by frankea on 2026-10-19T18:12:31Z.
@milescoviello both runs are done, on a PS5 with firmware 13.40. In short: inside a retail game a joined or detached thread's stack stays mapped read/write over exactly its range with its contents, at 128 KiB and at 64 KiB, and later threads of the same size get those stacks back oldest first.
Inside a title. Gran Turismo 7 (PPSA01317, 01.690.000), running. An elfldr payload attaches with ptrace, borrows a stopped game thread and calls the game's own libkernel exports. Each thread is made with
scePthreadCreate(scePthreadAttrSetstacksize0x20000 or 0x10000) withsceKernelUsleepas its entry and 300 ms as its argument, so it runs no code of mine. While it sleeps,scePthreadAttrGet+scePthreadAttrGetstackgive its stack, and the payload writes a marker 0x100 bytes above the stack's base. Then it is joined (or detached), andsceKernelQueryMemoryProtectionon the marker's address and a read of the marker show what is left.sceKernelQueryMemoryProtection0, prot 3, region exactly the stack (e.g. 0x7ede84000-0x7edea4000); marker intactThe 64 KiB column in the game matches ionut27001's batches of five. At 128 KiB, reuse started after four of my threads had ended; GT7's own threads may share that list, so I would not read the four as a different rule.
In a payload, 13.40. My own equivalent of
p77_libkernel(POSIXpthread_*in the payload, thread writes its marker itself, no attached game), not the zip, which I didn't run: at 128 KiB a clean batch of five (5 new ranges, then 5 ← 0 … 11 ← 6); at 64 KiB thread 1 got thread 0's stack straight away and the five-batch pattern followed; joined and detached stacks stayed mapped with their markers at both sizes, and the detached stack went to the 5th thread after it. So the 12.70 behaviour holds on 13.40.On the 4090 Linux run: as posted above, the box can't run the Linux build on its GPU right now.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-19T21:08:40Z.
@frankea thanks, this is the run that was missing. The 128 KiB column is the size NHL 26's Heartbeat walks. Inside a retail game, a joined or detached thread of that size keeps its range mapped read/write with its contents, and the range goes back to a later thread of the same size. So on the console that walk reads stale frames, never an unmapped range. 13.40 matches ionut27001's 12.70 payload.
The 128 KiB order also fits libthr without a second rule. In
thr_list.cthe batch threshold (GC_NEEDED, five threads on_thread_gc_list) counts every ended thread in the process, whatever its stack size. So if one GT7 thread had ended just before your first one, the first collection ran at your thread 4 and freed 0-3 (plus that thread's stack, onto its own size's list). Threads 4-7 then took 0-3 oldest first, and thread 8 found no spare and got a new range. At thread 9, ended threads 4-8 made the next batch of five, so 9-11 took 4-6. Your payload's 64 KiB start, where thread 1 got thread 0's stack straight away, reads the same way: four ended threads were already waiting in that process.For the Windows half, a branch is written but not yet tested:
fix/windows-retained-guest-stackson my fork.CreateFiberEx). The host thread switches to it at start and back when the guest returns or callsscePthreadExit.I'm changing it to the order you and ionut27001 measured: batches of five, handed out oldest first, as #7838 does on Linux. Then it needs the Windows CI tests. Once those pass I'll post a build here for your scripted run through the legal and quick-settings pages.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-19T21:20:01Z.
@frankea a correction to the plan in my last comment. Two open PRs already change Windows guest thread stacks, and I missed them:
CreateFiberExstack can't be placed there. As #7149 stands, an ended stack is still unmapped: beyond a cache of four, and for an exited thread once its handle signals. So the Heartbeat walk could still fault.So I won't open the fiber branch as a PR. Once #7149 lands, the follow-up is to give its Windows stacks the spare list #7838 gives Linux: kept mapped, reused by size, capped by host memory. The fiber branch stays on my fork for reference. Under Wine it reproduces the order you measured (batches of five, oldest first) and the cap, but it has not run on Windows.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by frankea on 2026-10-19T22:58:13Z.
@milescoviello agreed on #7149 as the base. I ran NHL 26 on the RTX 4090 (Windows 11, driver 616.92) through the scripted legal and quick-settings path on four trees, all on main
f52509acc+ #7048 (merged locally, since #7048 now conflicts): plain, + #4563, + #7149, and + #7149 + #7838 + the spare-list follow-up you describe, written locally. Each tree got 3 runs of 20 minutes. Every run that got past the title reached QUICK SETTINGS / WELCOME TO NHL 26 and ran to the cap with no stop. The Heartbeat crash did not occur in any tree, including the plain one (0 of 2 qualifying runs; the first lost its title press to a shader cache the new main had invalidated). It hit 1 of 3 runs on 10/18, so these runs show that none of the three changes adds a stop on this path, not that any of them fixes the crash.The follow-up moves #7838's spare-stack list (batches of five, reuse by size) out of the
__linux__block, so #7149's WindowsFreeGuestStackand its retired-stack reap collect into it instead of unmapping, and #7149's four-entry cache goes away. #7838's retained-and-reused test cases then run on Windows too. On the 4090,guest_pthread_stackwith those checks fails 3/3 without the change and passes 3/3 with it, andguest_pthread_startstays at 2.2 s. It is built on #7838 as of 916bdb06a6, so it still lacks the cap MarcZX10 has since added. I'll rebase it onto that and keep it local until #7149 lands rather than open a PR stacked on two open ones.One thing for #7149's rebase: on current main,
guest_kernel_stack_protectfails at line 109 (the errno check when a fixedmmapover a worker's stack is refused) with main + #7149 alone, 3 of 3, and passes on mainf29546ac4. That's separate from the Linux build break MarcZX10 listed there.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-19T22:59:27Z.
@frankea thanks, that's a thorough set of runs. Four trees at three 20-minute runs each, and you're right to read it as "nothing adds a stop" rather than a fix, since the plain tree didn't crash either.
Your follow-up is the Windows half I described: #7838's spare list shared by both hosts, #7149's four-entry cache dropped, and #7838's retained-and-reused checks running on Windows. A red/green
guest_pthread_stackon the 4090 is the test it needs. It's yours to open; I won't open a competing branch, and my fiber branch stays shelved. Keeping it local until #7149 lands makes sense. When you rebase it onto #7838's current head, the cap (1/1024 of RAM, 4-64 MiB, oldest evicted first) should apply to the shared list as well.I've passed the
guest_kernel_stack_protectfailure on to Pouare514 on #7149, with a link to your comment.AI-assisted: yes (Claude Code)