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

Open
opened 2026-10-19 01:14:39 +00:00 by frankea · 12 comments
frankea commented 2026-10-19 01:14:39 +00:00 (Migrated from github.com)
Contributor

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, main 376c04029 + #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:

FATAL: unhandled exception 0xc0000005 on thread 5052 'Heartbeat'
  rip 0x00000001417099e0 app.exe+0x17099e0
  read of 0x0000000124b7fff0
  rax 000000000000003e rbx 0000000124b7fff0 rcx 0000000124b7fff0 rdx 0000000000000000
  rsi 0000000000000000 rdi 00000000060bee20 rbp 00000000060bf050 rsp 00000000060be5a0
  r8  00000010f2a00000 r9  00000010f28312e0 r10 00000010f28312e0 r11 0000000000000083
  r12 00000010f281b3d0 r13 00000010391f0040 r14 0000000124b60000 r15 0000000000000032
  [r14] 0000002643535041 e1a9668d4734dbb5 0000000000001034 0000000000003eb4 8354dd21947a96d1 536b7d9856b2c112 0000002643535041 e1a9668d4734dbb5
  [r14] "APSC&"
  frame pointer chain:
    #0 0x00000001414d2f88 app.exe+0x14d2f88
    #1 0x00000001414d4310 app.exe+0x14d4310
    #2 0x000000014145ba1d app.exe+0x145ba1d
    #3 0x0000000140f56e8e app.exe+0xf56e8e
    #4 0x000000014143c196 app.exe+0x143c196
    #5 0x0000000141b80a4c app.exe+0x1b80a4c
    #6 0x000000014a93dfe0 app.exe+0xa93dfe0
    #7 0x00007fffa4eefcd0 libkernel.prx+0x4fcd0

What the code at rip does (relinked app.exe, same offsets as the dump):

0x1417099a9  mov rbx, [r14]        ; stack top from a record
0x1417099ac  mov r14, [r14+8]      ; stack base
0x1417099be  add rbx, -0x10
0x1417099cb  mov eax, 0x3e         ; up to 62 entries
0x1417099e0  mov rdx, [rcx]        ; <- faults on the first read, rcx = top - 16
0x1417099e3  cmp rdx, r14 / setbe ; keep words that point inside [base, top]
0x1417099ea  cmp rdx, rbx / seta
0x1417099f6  add rcx, -0x10 ; cmp rcx, r14 ; jbe done ; jns loop

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's shader_cache directory), 0x1034 key bytes, 0x3eb4 payload bytes, two hashes, i.e. a MapViewOfFile view of one of the *.bin files that core/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 with scePthreadAttrSetstack is 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.exe working 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).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5916135064 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7700). Originally posted by [frankea](https://github.com/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`, `main` 376c04029 + #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: ``` FATAL: unhandled exception 0xc0000005 on thread 5052 'Heartbeat' rip 0x00000001417099e0 app.exe+0x17099e0 read of 0x0000000124b7fff0 rax 000000000000003e rbx 0000000124b7fff0 rcx 0000000124b7fff0 rdx 0000000000000000 rsi 0000000000000000 rdi 00000000060bee20 rbp 00000000060bf050 rsp 00000000060be5a0 r8 00000010f2a00000 r9 00000010f28312e0 r10 00000010f28312e0 r11 0000000000000083 r12 00000010f281b3d0 r13 00000010391f0040 r14 0000000124b60000 r15 0000000000000032 [r14] 0000002643535041 e1a9668d4734dbb5 0000000000001034 0000000000003eb4 8354dd21947a96d1 536b7d9856b2c112 0000002643535041 e1a9668d4734dbb5 [r14] "APSC&" frame pointer chain: #0 0x00000001414d2f88 app.exe+0x14d2f88 #1 0x00000001414d4310 app.exe+0x14d4310 #2 0x000000014145ba1d app.exe+0x145ba1d #3 0x0000000140f56e8e app.exe+0xf56e8e #4 0x000000014143c196 app.exe+0x143c196 #5 0x0000000141b80a4c app.exe+0x1b80a4c #6 0x000000014a93dfe0 app.exe+0xa93dfe0 #7 0x00007fffa4eefcd0 libkernel.prx+0x4fcd0 ``` What the code at `rip` does (relinked `app.exe`, same offsets as the dump): ``` 0x1417099a9 mov rbx, [r14] ; stack top from a record 0x1417099ac mov r14, [r14+8] ; stack base 0x1417099be add rbx, -0x10 0x1417099cb mov eax, 0x3e ; up to 62 entries 0x1417099e0 mov rdx, [rcx] ; <- faults on the first read, rcx = top - 16 0x1417099e3 cmp rdx, r14 / setbe ; keep words that point inside [base, top] 0x1417099ea cmp rdx, rbx / seta 0x1417099f6 add rcx, -0x10 ; cmp rcx, r14 ; jbe done ; jns loop ``` 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's `shader_cache` directory), 0x1034 key bytes, 0x3eb4 payload bytes, two hashes, i.e. a `MapViewOfFile` view of one of the `*.bin` files that `core/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 with `scePthreadAttrSetstack` is 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.exe` working 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).
milescoviello commented 2026-10-19 02:38:03 +00:00 (Migrated from github.com)
Author
Contributor

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_free puts a dead thread's stack on a spare list (dstackq for the default size, mstackq for others), and _thr_stack_alloc hands 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:

  • Windows: the guest runs on the stack _beginthreadex gave its host thread, and Windows frees that stack when the thread ends, as you found.
  • Linux: Thread.cpp maps the guest stack itself (AllocateGuestStack) and unmaps it when the thread is joined (FreeGuestStack), or, for a detached thread, at the next scePthreadCreate after its host thread is gone (ReapRetiredStacks). GuestPthreadStack.cpp requires 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:

  • Linux is mostly a change to FreeGuestStack and ReapRetiredStacks, plus flipping that test's requirement to "stays mapped and is reused".
  • Windows first needs the guest stack to be memory AnyPS5 allocates (as on Linux), with the thread switched onto it at start and the TEB's stack bounds updated, since _beginthreadex can'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 main that read should fault, since both ranges are unmapped).

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6258466591 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7700#issuecomment-6258466591). Originally posted by [milescoviello](https://github.com/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_free` puts a dead thread's stack on a spare list (`dstackq` for the default size, `mstackq` for others), and `_thr_stack_alloc` hands 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: - **Windows:** the guest runs on the stack `_beginthreadex` gave its host thread, and Windows frees that stack when the thread ends, as you found. - **Linux:** `Thread.cpp` maps the guest stack itself (`AllocateGuestStack`) and unmaps it when the thread is joined (`FreeGuestStack`), or, for a detached thread, at the next `scePthreadCreate` after its host thread is gone (`ReapRetiredStacks`). `GuestPthreadStack.cpp` requires 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: - **Linux** is mostly a change to `FreeGuestStack` and `ReapRetiredStacks`, plus flipping that test's requirement to "stays mapped and is reused". - **Windows** first needs the guest stack to be memory AnyPS5 allocates (as on Linux), with the thread switched onto it at start and the TEB's stack bounds updated, since `_beginthreadex` can'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 `main` that read should fault, since both ranges are unmapped). AI-assisted: yes (Claude Code)
ionut27001 commented 2026-10-19 09:11:11 +00:00 (Migrated from github.com)
Author
Contributor

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 through scePthreadAttrGet and scePthreadAttrGetstack, 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. Probe p77_libkernel, source and both logs: p77-thread-stacks.zip (the first log is version 1 of the probe, without the twelve case and the addr= field). Lines are quoted unchanged with a p77: prefix, from the second run unless marked.

1. The stack of an ended thread stays mapped, with its content. After scePthreadJoin, sceKernelQueryMemoryProtection on the top byte reports protection 3 over exactly the thread's range and 0 over the 16 KiB below it; sceKernelVirtualQuery reports the range with protection 3, the stack bit (byte 32 is 0x05, which reads as is_flexible and is_stack in AnyPS5's VirtualQueryInfo, core/libs/SceTypes.hpp) and the thread's name; the marker reads back unchanged:

p77: case thread who=seq1 id=0x7701 get_ret=0 stack_ret=0 addr=7eee3c000 size=0x10000 join_ret=0 detach_ret=0 marker_from_top=-2144 seen_at_entry=0
p77: case mapping who=seq1_after_join top_query_ret=0 prot=0x3 region_start_from_addr=0 region_end_from_top=0
p77: case mapping_below who=seq1_after_join query_ret=0 prot=0 start_from_addr=-16384 end_from_addr=0
p77: case vquery who=seq1_after_join ret=0 touched=72 bytes=00c0e3ee0700000000c0e4ee0700000000000000000000000300000000000000056f7261636c655f7037370000000000000000000000000000000000000000000000000000000000
p77: case marker who=seq1_after_join value=0x7701 expected=0x7701 same=1 marker_from_top=-2144
p77: case top64_words who=seq1_after_join w0=0x7eee4bff0 w1=0x835d94355 w2=0 w3=0 w4=0 w5=0x880488020 w6=0 w7=0

The same for a thread detached after creation, at least 200 ms after it set its done flag:

p77: case thread who=detached id=0x7730 get_ret=0 stack_ret=0 addr=7eed64000 size=0x10000 join_ret=0 detach_ret=0 marker_from_top=-2144 seen_at_entry=0
p77: case mapping who=detached_after_exit top_query_ret=0 prot=0x3 region_start_from_addr=0 region_end_from_top=0
p77: case vquery who=detached_after_exit ret=0 touched=72 bytes=0040d6ee070000000040d7ee0700000000000000000000000300000000000000056f7261636c655f7037370000000000000000000000000000000000000000000000000000000000
p77: case marker who=detached_after_exit value=0x7730 expected=0x7730 same=1 marker_from_top=-2144
p77: case top64_words who=detached_after_exit w0=0x7eed73ff0 w1=0x835d94355 w2=0 w3=0x7eed5ffd8 w4=0 w5=0x880488020 w6=0 w7=0

2. Another thread reads it. seen_at_entry is 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, saw seq1's marker; new2 and aft4, running on the very stack of conc0 and of the detached thread, saw their markers:

p77: case thread who=seq2 id=0x7702 get_ret=0 stack_ret=0 addr=7eee28000 size=0x10000 join_ret=0 detach_ret=0 marker_from_top=-2144 seen_at_entry=0x7701
p77: case reuse who=seq2 same_addr_as_seq1=0 addr_diff=-81920 seen_seq1_marker_at_entry=1
p77: case thread who=new2 id=0x7722 get_ret=0 stack_ret=0 addr=7eedd0000 size=0x10000 join_ret=0 detach_ret=0 marker_from_top=-2144 seen_at_entry=0x7710
p77: case reuse who=new2 got_stack_of_conc=0 seen_conc0_marker_at_entry=1
p77: case thread who=aft4 id=0x7744 get_ret=0 stack_ret=0 addr=7eed64000 size=0x10000 join_ret=0 detach_ret=0 marker_from_top=-2144 seen_at_entry=0x7730
p77: case reuse who=aft4 same_addr_as_detached=1 seen_detached_marker_at_entry=1

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):

p77: case thread who=seq1 id=0x7701 get_ret=0 stack_ret=0 addr=7eee3c000 size=0x10000 join_ret=0 detach_ret=0 marker_from_top=-2144 seen_at_entry=0
p77: case thread who=seq2 id=0x7702 get_ret=0 stack_ret=0 addr=7eee28000 size=0x10000 join_ret=0 detach_ret=0 marker_from_top=-2144 seen_at_entry=0x7701
p77: case thread who=seq4_default id=0x7704 get_ret=0 stack_ret=0 addr=7eedd0000 size=0x10000 join_ret=0 detach_ret=0 marker_from_top=-2144 seen_at_entry=0x7701

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:

p77: case twelve who=twa index=0 addr=7eee3c000 from_first=0 reused_stack_of=-1
p77: case twelve who=twb index=1 addr=7eee28000 from_first=-81920 reused_stack_of=-1
p77: case twelve who=twc index=2 addr=7eedd0000 from_first=-442368 reused_stack_of=-1
p77: case twelve who=twd index=3 addr=7eed78000 from_first=-802816 reused_stack_of=-1
p77: case twelve who=twe index=4 addr=7eed64000 from_first=-884736 reused_stack_of=-1
p77: case twelve who=twf index=5 addr=7eee3c000 from_first=0 reused_stack_of=0
p77: case twelve who=twg index=6 addr=7eee28000 from_first=-81920 reused_stack_of=1
p77: case twelve who=twh index=7 addr=7eedd0000 from_first=-442368 reused_stack_of=2
p77: case twelve who=twi index=8 addr=7eed78000 from_first=-802816 reused_stack_of=3
p77: case twelve who=twj index=9 addr=7eed64000 from_first=-884736 reused_stack_of=4
p77: case twelve who=twk index=10 addr=7eee3c000 from_first=0 reused_stack_of=5
p77: case twelve who=twl index=11 addr=7eee28000 from_first=-81920 reused_stack_of=6

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_8 label is the probe's; its loop stopped at the fifth thread):

p77: case conc_alive who=conc0 addr=7eedd0000 addr_from_conc0=0 size=0x10000
p77: case conc_alive who=conc1 addr=7eed78000 addr_from_conc0=-360448 size=0x10000
p77: case conc_alive who=conc2 addr=7eed64000 addr_from_conc0=-442368 size=0x10000
p77: case conc_alive who=conc3 addr=7eed50000 addr_from_conc0=-524288 size=0x10000
p77: case reuse who=new0 got_stack_of_conc=-1 seen_conc0_marker_at_entry=1
p77: case reuse who=new1 got_stack_of_conc=-1 seen_conc0_marker_at_entry=1
p77: case reuse who=new2 got_stack_of_conc=0 seen_conc0_marker_at_entry=1
p77: case reuse who=new3 got_stack_of_conc=1 seen_conc0_marker_at_entry=0
p77: case reuse who=aft3 same_addr_as_detached=0 seen_detached_marker_at_entry=1
p77: case reuse who=aft4 same_addr_as_detached=1 seen_detached_marker_at_entry=1
p77: case mapping who=detached_after_8 top_query_ret=0 prot=0x3 region_start_from_addr=0 region_end_from_top=0

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, from join_common under _pthread_join and from exit_thread under _pthread_exit), pthread_create runs _thr_gc only once five are waiting (GC_NEEDED(), _thr_alloc), which returns their stacks to the spare list (_thr_stack_free), and _thr_stack_alloc hands 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_alloc does. libthr never unmaps a spare stack; the only munmap in thr_stack.c is of a new mapping whose guard mprotect failed (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 when new0 was 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.

p77: case top64_words who=seq1_after_join w0=0x7efc7fff0 w1=0x816cc0355 w2=0 w3=0 w4=0 w5=0x8801e0020 w6=0 w7=0

(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.

p77: case thread who=seq3_bigger id=0x7703 get_ret=0 stack_ret=0 addr=7eede4000 size=0x40000 join_ret=0 detach_ret=0 marker_from_top=-2144 seen_at_entry=0x7701
p77: case mapping who=seq3_bigger_after_join top_query_ret=0 prot=0x3 region_start_from_addr=0 region_end_from_top=0
p77: case thread who=seq5_bigger id=0x7705 get_ret=0 stack_ret=0 addr=7eed8c000 size=0x40000 join_ret=0 detach_ret=0 marker_from_top=-2144 seen_at_entry=0x7703
p77: case reuse who=seq5_bigger same_addr_as_seq3=0 same_addr_as_seq1=0 seen_seq3_marker_at_entry=1

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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6263736446 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7700#issuecomment-6263736446). Originally posted by [ionut27001](https://github.com/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 through `scePthreadAttrGet` and `scePthreadAttrGetstack`, 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. Probe `p77_libkernel`, source and both logs: [p77-thread-stacks.zip](https://github.com/user-attachments/files/33657311/p77-thread-stacks.zip) (the first log is version 1 of the probe, without the `twelve` case and the `addr=` field). Lines are quoted unchanged with a `p77:` prefix, from the second run unless marked. **1. The stack of an ended thread stays mapped, with its content.** After `scePthreadJoin`, `sceKernelQueryMemoryProtection` on the top byte reports protection 3 over exactly the thread's range and 0 over the 16 KiB below it; `sceKernelVirtualQuery` reports the range with protection 3, the stack bit (byte 32 is 0x05, which reads as `is_flexible` and `is_stack` in AnyPS5's `VirtualQueryInfo`, `core/libs/SceTypes.hpp`) and the thread's name; the marker reads back unchanged: ``` p77: case thread who=seq1 id=0x7701 get_ret=0 stack_ret=0 addr=7eee3c000 size=0x10000 join_ret=0 detach_ret=0 marker_from_top=-2144 seen_at_entry=0 p77: case mapping who=seq1_after_join top_query_ret=0 prot=0x3 region_start_from_addr=0 region_end_from_top=0 p77: case mapping_below who=seq1_after_join query_ret=0 prot=0 start_from_addr=-16384 end_from_addr=0 p77: case vquery who=seq1_after_join ret=0 touched=72 bytes=00c0e3ee0700000000c0e4ee0700000000000000000000000300000000000000056f7261636c655f7037370000000000000000000000000000000000000000000000000000000000 p77: case marker who=seq1_after_join value=0x7701 expected=0x7701 same=1 marker_from_top=-2144 p77: case top64_words who=seq1_after_join w0=0x7eee4bff0 w1=0x835d94355 w2=0 w3=0 w4=0 w5=0x880488020 w6=0 w7=0 ``` The same for a thread detached after creation, at least 200 ms after it set its done flag: ``` p77: case thread who=detached id=0x7730 get_ret=0 stack_ret=0 addr=7eed64000 size=0x10000 join_ret=0 detach_ret=0 marker_from_top=-2144 seen_at_entry=0 p77: case mapping who=detached_after_exit top_query_ret=0 prot=0x3 region_start_from_addr=0 region_end_from_top=0 p77: case vquery who=detached_after_exit ret=0 touched=72 bytes=0040d6ee070000000040d7ee0700000000000000000000000300000000000000056f7261636c655f7037370000000000000000000000000000000000000000000000000000000000 p77: case marker who=detached_after_exit value=0x7730 expected=0x7730 same=1 marker_from_top=-2144 p77: case top64_words who=detached_after_exit w0=0x7eed73ff0 w1=0x835d94355 w2=0 w3=0x7eed5ffd8 w4=0 w5=0x880488020 w6=0 w7=0 ``` **2. Another thread reads it.** `seen_at_entry` is 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, saw `seq1`'s marker; `new2` and `aft4`, running on the very stack of `conc0` and of the detached thread, saw their markers: ``` p77: case thread who=seq2 id=0x7702 get_ret=0 stack_ret=0 addr=7eee28000 size=0x10000 join_ret=0 detach_ret=0 marker_from_top=-2144 seen_at_entry=0x7701 p77: case reuse who=seq2 same_addr_as_seq1=0 addr_diff=-81920 seen_seq1_marker_at_entry=1 p77: case thread who=new2 id=0x7722 get_ret=0 stack_ret=0 addr=7eedd0000 size=0x10000 join_ret=0 detach_ret=0 marker_from_top=-2144 seen_at_entry=0x7710 p77: case reuse who=new2 got_stack_of_conc=0 seen_conc0_marker_at_entry=1 p77: case thread who=aft4 id=0x7744 get_ret=0 stack_ret=0 addr=7eed64000 size=0x10000 join_ret=0 detach_ret=0 marker_from_top=-2144 seen_at_entry=0x7730 p77: case reuse who=aft4 same_addr_as_detached=1 seen_detached_marker_at_entry=1 ``` **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): ``` p77: case thread who=seq1 id=0x7701 get_ret=0 stack_ret=0 addr=7eee3c000 size=0x10000 join_ret=0 detach_ret=0 marker_from_top=-2144 seen_at_entry=0 p77: case thread who=seq2 id=0x7702 get_ret=0 stack_ret=0 addr=7eee28000 size=0x10000 join_ret=0 detach_ret=0 marker_from_top=-2144 seen_at_entry=0x7701 p77: case thread who=seq4_default id=0x7704 get_ret=0 stack_ret=0 addr=7eedd0000 size=0x10000 join_ret=0 detach_ret=0 marker_from_top=-2144 seen_at_entry=0x7701 ``` 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: ``` p77: case twelve who=twa index=0 addr=7eee3c000 from_first=0 reused_stack_of=-1 p77: case twelve who=twb index=1 addr=7eee28000 from_first=-81920 reused_stack_of=-1 p77: case twelve who=twc index=2 addr=7eedd0000 from_first=-442368 reused_stack_of=-1 p77: case twelve who=twd index=3 addr=7eed78000 from_first=-802816 reused_stack_of=-1 p77: case twelve who=twe index=4 addr=7eed64000 from_first=-884736 reused_stack_of=-1 p77: case twelve who=twf index=5 addr=7eee3c000 from_first=0 reused_stack_of=0 p77: case twelve who=twg index=6 addr=7eee28000 from_first=-81920 reused_stack_of=1 p77: case twelve who=twh index=7 addr=7eedd0000 from_first=-442368 reused_stack_of=2 p77: case twelve who=twi index=8 addr=7eed78000 from_first=-802816 reused_stack_of=3 p77: case twelve who=twj index=9 addr=7eed64000 from_first=-884736 reused_stack_of=4 p77: case twelve who=twk index=10 addr=7eee3c000 from_first=0 reused_stack_of=5 p77: case twelve who=twl index=11 addr=7eee28000 from_first=-81920 reused_stack_of=6 ``` 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_8` label is the probe's; its loop stopped at the fifth thread): ``` p77: case conc_alive who=conc0 addr=7eedd0000 addr_from_conc0=0 size=0x10000 p77: case conc_alive who=conc1 addr=7eed78000 addr_from_conc0=-360448 size=0x10000 p77: case conc_alive who=conc2 addr=7eed64000 addr_from_conc0=-442368 size=0x10000 p77: case conc_alive who=conc3 addr=7eed50000 addr_from_conc0=-524288 size=0x10000 p77: case reuse who=new0 got_stack_of_conc=-1 seen_conc0_marker_at_entry=1 p77: case reuse who=new1 got_stack_of_conc=-1 seen_conc0_marker_at_entry=1 p77: case reuse who=new2 got_stack_of_conc=0 seen_conc0_marker_at_entry=1 p77: case reuse who=new3 got_stack_of_conc=1 seen_conc0_marker_at_entry=0 p77: case reuse who=aft3 same_addr_as_detached=0 seen_detached_marker_at_entry=1 p77: case reuse who=aft4 same_addr_as_detached=1 seen_detached_marker_at_entry=1 p77: case mapping who=detached_after_8 top_query_ret=0 prot=0x3 region_start_from_addr=0 region_end_from_top=0 ``` 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`](https://github.com/freebsd/freebsd-src/blob/stable/11/lib/libthr/thread/thr_list.c#L319-L336), from `join_common` under [`_pthread_join`](https://github.com/freebsd/freebsd-src/blob/stable/11/lib/libthr/thread/thr_join.c#L141-L143) and from `exit_thread` under `_pthread_exit`), `pthread_create` runs `_thr_gc` only once five are waiting ([`GC_NEEDED()`](https://github.com/freebsd/freebsd-src/blob/stable/11/lib/libthr/thread/thr_private.h#L703), [`_thr_alloc`](https://github.com/freebsd/freebsd-src/blob/stable/11/lib/libthr/thread/thr_list.c#L139-L140)), which returns their stacks to the spare list ([`_thr_stack_free`](https://github.com/freebsd/freebsd-src/blob/stable/11/lib/libthr/thread/thr_stack.c#L295-L318)), and [`_thr_stack_alloc`](https://github.com/freebsd/freebsd-src/blob/stable/11/lib/libthr/thread/thr_stack.c#L223-L226) hands 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_alloc`](https://github.com/freebsd/freebsd-src/blob/stable/11/lib/libthr/thread/thr_stack.c#L253-L267) does. libthr never unmaps a spare stack; the only `munmap` in `thr_stack.c` is of a new mapping whose guard `mprotect` failed ([L274-L284](https://github.com/freebsd/freebsd-src/blob/stable/11/lib/libthr/thread/thr_stack.c#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 when `new0` was 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. ``` p77: case top64_words who=seq1_after_join w0=0x7efc7fff0 w1=0x816cc0355 w2=0 w3=0 w4=0 w5=0x8801e0020 w6=0 w7=0 ``` (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. ``` p77: case thread who=seq3_bigger id=0x7703 get_ret=0 stack_ret=0 addr=7eede4000 size=0x40000 join_ret=0 detach_ret=0 marker_from_top=-2144 seen_at_entry=0x7701 p77: case mapping who=seq3_bigger_after_join top_query_ret=0 prot=0x3 region_start_from_addr=0 region_end_from_top=0 p77: case thread who=seq5_bigger id=0x7705 get_ret=0 stack_ret=0 addr=7eed8c000 size=0x40000 join_ret=0 detach_ret=0 marker_from_top=-2144 seen_at_entry=0x7703 p77: case reuse who=seq5_bigger same_addr_as_seq3=0 same_addr_as_seq1=0 seen_seq3_marker_at_entry=1 ``` 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`](https://github.com/freebsd/freebsd-src/blob/stable/11/lib/libthr/thread/thr_stack.c#L235-L242)); 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.
milescoviello commented 2026-10-19 11:35:46 +00:00 (Migrated from github.com)
Author
Contributor

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:

  • a joined or detached thread's stack stays mapped read/write over exactly its range, with its contents;
  • a later thread of the same size gets it back at the same address, in libthr's order: a batch is freed once five ended threads wait, and comes out oldest first;
  • nothing in libthr unmaps a spare stack.

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_next link 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 main and 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)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6266270409 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7700#issuecomment-6266270409). Originally posted by [milescoviello](https://github.com/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: - a joined or detached thread's stack stays mapped read/write over exactly its range, with its contents; - a later thread of the same size gets it back at the same address, in libthr's order: a batch is freed once five ended threads wait, and comes out oldest first; - nothing in libthr unmaps a spare stack. 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_next` link 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](https://github.com/boykopovar/AnyPS5/pull/7838#pullrequestreview-5570663684), with a red check against `main` and 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)
frankea commented 2026-10-19 16:46:30 +00:00 (Migrated from github.com)
Author
Contributor

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_libkernel unchanged 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)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6272350814 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7700#issuecomment-6272350814). Originally posted by [frankea](https://github.com/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_libkernel` unchanged 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)
milescoviello commented 2026-10-19 16:47:11 +00:00 (Migrated from github.com)
Author
Contributor

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_libkernel unchanged 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 main and 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)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6272367529 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7700#issuecomment-6272367529). Originally posted by [milescoviello](https://github.com/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_libkernel` unchanged 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 `main` and 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)
frankea commented 2026-10-19 17:14:40 +00:00 (Migrated from github.com)
Author
Contributor

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.d lists 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.cpp is inside the #if defined(__linux__) block, so on Windows it runs the same stack code as main.

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)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6272908463 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7700#issuecomment-6272908463). Originally posted by [frankea](https://github.com/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.d` lists 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.cpp` is inside the `#if defined(__linux__)` block, so on Windows it runs the same stack code as `main`. 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)
milescoviello commented 2026-10-19 17:28:35 +00:00 (Migrated from github.com)
Author
Contributor

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 _beginthreadex gives 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)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6273170500 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7700#issuecomment-6273170500). Originally posted by [milescoviello](https://github.com/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 `_beginthreadex` gives 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)
frankea commented 2026-10-19 18:12:31 +00:00 (Migrated from github.com)
Author
Contributor

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 (scePthreadAttrSetstacksize 0x20000 or 0x10000) with sceKernelUsleep as its entry and 300 ms as its argument, so it runs no code of mine. While it sleeps, scePthreadAttrGet + scePthreadAttrGetstack give its stack, and the payload writes a marker 0x100 bytes above the stack's base. Then it is joined (or detached), and sceKernelQueryMemoryProtection on the marker's address and a read of the marker show what is left.

128 KiB (0x20000) 64 KiB (0x10000)
joined thread, after join sceKernelQueryMemoryProtection 0, prot 3, region exactly the stack (e.g. 0x7ede84000-0x7edea4000); marker intact prot 3, region exactly the stack (0x7ee3c8000-0x7ee3d8000); marker intact
detached thread, 400 ms after it ended prot 3, region exactly the stack; marker intact prot 3, region exactly the stack; marker intact
12 threads created and joined one after another 4 new ranges, then threads 4-7 got the stacks of 0-3, thread 8 a new range, threads 9-11 the stacks of 4-6 5 new ranges, then each thread got the stack of the thread 5 before it (5 ← 0 … 11 ← 6)
the detached thread's stack handed to the 5th thread created after it ended; still mapped afterwards same

The 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 (POSIX pthread_* 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)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6274025748 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7700#issuecomment-6274025748). Originally posted by [frankea](https://github.com/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` (`scePthreadAttrSetstacksize` 0x20000 or 0x10000) with `sceKernelUsleep` as its entry and 300 ms as its argument, so it runs no code of mine. While it sleeps, `scePthreadAttrGet` + `scePthreadAttrGetstack` give its stack, and the payload writes a marker 0x100 bytes above the stack's base. Then it is joined (or detached), and `sceKernelQueryMemoryProtection` on the marker's address and a read of the marker show what is left. | | 128 KiB (0x20000) | 64 KiB (0x10000) | |---|---|---| | joined thread, after join | `sceKernelQueryMemoryProtection` 0, prot 3, region exactly the stack (e.g. 0x7ede84000-0x7edea4000); marker intact | prot 3, region exactly the stack (0x7ee3c8000-0x7ee3d8000); marker intact | | detached thread, 400 ms after it ended | prot 3, region exactly the stack; marker intact | prot 3, region exactly the stack; marker intact | | 12 threads created and joined one after another | 4 new ranges, then threads 4-7 got the stacks of 0-3, thread 8 a new range, threads 9-11 the stacks of 4-6 | 5 new ranges, then each thread got the stack of the thread 5 before it (5 ← 0 … 11 ← 6) | | the detached thread's stack | handed to the 5th thread created after it ended; still mapped afterwards | same | The 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` (POSIX `pthread_*` 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)
milescoviello commented 2026-10-19 21:08:40 +00:00 (Migrated from github.com)
Author
Contributor

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.c the 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-stacks on my fork.

  • Each guest thread runs on a fiber whose stack AnyPS5 allocates at the thread's stack size (CreateFiberEx). The host thread switches to it at start and back when the guest returns or calls scePthreadExit.
  • An ended fiber's stack stays mapped and is reused by size.

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)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6277363573 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7700#issuecomment-6277363573). Originally posted by [milescoviello](https://github.com/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.c` the 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-stacks`](https://github.com/milescoviello/AnyPS5/tree/fix/windows-retained-guest-stacks) on my fork. - Each guest thread runs on a fiber whose stack AnyPS5 allocates at the thread's stack size (`CreateFiberEx`). The host thread switches to it at start and back when the guest returns or calls `scePthreadExit`. - An ended fiber's stack stays mapped and is reused by size. 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)
milescoviello commented 2026-10-19 21:20:01 +00:00 (Migrated from github.com)
Author
Contributor

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:

  • #4563 (poonasor) holds the host thread, and with it its stack, until the thread is joined or detached. Your run shows the range also survives the join and the detach on the console, so #4563 covers only the time before the join.
  • #7149 (Pouare514, in review with oneandonlydean) runs Windows guest threads on stacks mapped in the guest arena and switches the TEB bounds at entry and exit. That is the right base for the Windows half. The arena puts guest stacks above 4 GiB, which #7149 needs for the rsp-masking idiom it fixes, and a CreateFiberEx stack 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)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6277563078 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7700#issuecomment-6277563078). Originally posted by [milescoviello](https://github.com/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: - #4563 (poonasor) holds the host thread, and with it its stack, until the thread is joined or detached. Your run shows the range also survives the join and the detach on the console, so #4563 covers only the time before the join. - #7149 (Pouare514, in review with oneandonlydean) runs Windows guest threads on stacks mapped in the guest arena and switches the TEB bounds at entry and exit. That is the right base for the Windows half. The arena puts guest stacks above 4 GiB, which #7149 needs for the rsp-masking idiom it fixes, and a `CreateFiberEx` stack 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)
frankea commented 2026-10-19 22:58:13 +00:00 (Migrated from github.com)
Author
Contributor

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 Windows FreeGuestStack and 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_stack with those checks fails 3/3 without the change and passes 3/3 with it, and guest_pthread_start stays 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_protect fails at line 109 (the errno check when a fixed mmap over a worker's stack is refused) with main + #7149 alone, 3 of 3, and passes on main f29546ac4. That's separate from the Linux build break MarcZX10 listed there.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6279192895 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7700#issuecomment-6279192895). Originally posted by [frankea](https://github.com/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 Windows `FreeGuestStack` and 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_stack` with those checks fails 3/3 without the change and passes 3/3 with it, and `guest_pthread_start` stays 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_protect` fails at line 109 (the errno check when a fixed `mmap` over a worker's stack is refused) with main + #7149 alone, 3 of 3, and passes on main f29546ac4. That's separate from the Linux build break MarcZX10 listed there. AI-assisted: yes (Claude Code)
milescoviello commented 2026-10-19 22:59:27 +00:00 (Migrated from github.com)
Author
Contributor

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_stack on 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_protect failure on to Pouare514 on #7149, with a link to your comment.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6279210029 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7700#issuecomment-6279210029). Originally posted by [milescoviello](https://github.com/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_stack` on 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_protect` failure on to Pouare514 on #7149, with a link to your comment. AI-assisted: yes (Claude Code)
Sign in to join this conversation.
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#7700
No description provided.