Skip to content

fix(runtime): return after a tail call to a host function - #509

Open
kateinoigakukun wants to merge 1 commit into
mainfrom
fix/host-tail-call-return
Open

kateinoigakukun wants to merge 1 commit into
mainfrom
fix/host-tail-call-return

Conversation

@kateinoigakukun

@kateinoigakukun kateinoigakukun commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

A return_call to a host function ran whatever followed it in the caller's code:

(func $tail (param i32) (result i32)
  (block $b (return_call $host (local.get 0)))
  (call $mark)        ;; ran after $host returned
  (i32.const 99))

A tail call to a Wasm function jumps to the callee, but one to a host function comes back to the next instruction in the moved frame, which tailInvoke expects to return. The translator emitted nothing after a tail call (the rest is unreachable), so that only held when the tail call was the last instruction of the function. Otherwise the dead code ran in the moved, smaller frame; the resumable-call fuzzer hit it as a read below the stack (SIGBUS).

The translator now emits a _return after a return_call to a host function, and after every return_call_indirect / return_call_ref, whose callee is not known until it runs.

before after
return_call $host last in the function returns returns
return_call $host followed by code (e.g. in a block) runs that code in the moved frame returns
return_call to a Wasm function jumps to the callee unchanged (nothing emitted)

Metrics

  • Every wasmkit_tc_* handler, both dispatch loops, invoke and tailInvoke: byte-identical to main (arm64 release).
  • WasmKit module __TEXT: +208 B (translator only); return_call_indirect / return_call_ref code gains one slot.

The translator emitted nothing after a tail call, so a return_call to a host function that was not
the last instruction fell through into the code after it.
@kateinoigakukun
kateinoigakukun force-pushed the fix/host-tail-call-return branch from 9ed44eb to 41f96ea Compare October 24, 2026 07:36
@kateinoigakukun kateinoigakukun changed the title fix(runtime): return from the moved frame after a host tail call fix(runtime): return after a tail call to a host function Oct 24, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant