diff --git a/asm/lumbda.s b/asm/lumbda.s index c0e68ca..4080f4e 100644 --- a/asm/lumbda.s +++ b/asm/lumbda.s @@ -1044,6 +1044,20 @@ heap_alloc: movq %r15, gc_free_list(%rip) addq %rax, %r15 # %r15 now == %r13 .ha_grow_no_pad: + # Pin the abandoned chunk's stored end to %r15 (its high-water). + # In the padded path above this is a no-op (r15 already == r13). + # In the un-padded path (tail < 16) r15 sits short of r13 and the + # gap holds mmap-zeros. Without this update, gc_sweep would still + # walk to the original mmap end, decode the zero pages as fake + # dead blocks, and on the final iteration write the free-list + # next-pointer to (chunk_end - 8) + 8 == chunk_end — the first + # byte of an unmapped page — and segfault in .gsw_dead. Tying + # chunk_end to r15 stops the walker at the high-water mark. + # Discovered while diagnosing ecdsa task #45, 2026-06-05. + movq gc_chunk_count(%rip), %rdx + decq %rdx + leaq gc_chunk_end(%rip), %rcx + movq %r15, (%rcx,%rdx,8) # Chunk size: at least HEAP_SIZE, but large enough for this one # block. A single big allocation (e.g. file->string on a ~3 MB # PDF) would otherwise loop forever because each mmap'd 1 MB