Stream: git-wasmtime

Topic: wasmtime / PR #13189 Fix GC heap using wrong `MemoryKind`...


view this post on Zulip Wasmtime GitHub notifications bot (Apr 24 2026 at 15:57):

fitzgen opened PR #13189 from fitzgen:wasmtime-issue-13173 to bytecodealliance:main:

The on-demand instance allocator's allocate_memory always passed MemoryKind::LinearMemory to Memory::new_dynamic, even when allocating the backing memory for a GC heap. This caused the GC heap to use the wrong set of tunables.

The consequences were two distinct crash modes:

  1. When memory_reservation=0: the GC heap got a 0-byte reservation, so every growth triggered an mmap reallocation that changed the base pointer. Code held a stale cached copy of the old base pointer, causing use-after-free crashes.

  2. When gc_heap_guard_size != memory_guard_size: Cranelift correctly compiled GC heap accesses using gc_heap_guard_size bytes of virtual guard, but the runtime memory incorrectly only had memory_guard_size bytes of actual guard, so accesses beyond the actual guard caused uncaught segfaults.

This commit fixes the bug by threading a MemoryKind through the InstanceAllocator::allocate_memory trait method.

Also, now that the GC heap correctly uses gc_heap_reservation, the workaround in MemoryTunables::may_move that always returned true for GC heaps is no longer needed. That workaround was masking the actual root cause, and with the fix, gc_heap_may_move can now be respected correctly.

There were three existing tests that were accidentally relying on the GC heap using linear-memory tunables; this commit adds explicit GC heap tunable configuration so they continue to work correctly.

Fixes https://github.com/bytecodealliance/wasmtime/issues/13173

<!--
Please make sure you include the following information:

Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.html

Please ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->

view this post on Zulip Wasmtime GitHub notifications bot (Apr 24 2026 at 15:57):

fitzgen requested alexcrichton for a review on PR #13189.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 24 2026 at 15:57):

fitzgen requested wasmtime-core-reviewers for a review on PR #13189.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 24 2026 at 17:03):

github-actions[bot] added the label wasmtime:api on PR #13189.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 24 2026 at 17:24):

alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 24 2026 at 18:40):

fitzgen updated PR #13189.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 24 2026 at 18:43):

fitzgen updated PR #13189.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 24 2026 at 18:43):

fitzgen has enabled auto merge for PR #13189.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 24 2026 at 18:56):

fitzgen added PR #13189 Fix GC heap using wrong MemoryKind tunables in on-demand allocator to the merge queue.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 24 2026 at 19:20):

fitzgen merged PR #13189.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 24 2026 at 19:20):

fitzgen removed PR #13189 Fix GC heap using wrong MemoryKind tunables in on-demand allocator from the merge queue.


Last updated: May 03 2026 at 22:13 UTC