I was wondering recently about how interrupting wasm code works in cranelift (I thought it wasn't implemented but turns out it was!) and I was looking at the spidermonkey integration for this. I see that in loop headers an interrupt flag is checked, but I wasn't actually able to find anywhere else that interrupt flags were checked. Do others know where the interrupt flag is checked for things like function exits/entries?
SpiderMonkey has its own function prologue which it inserts before Cranelift's prologue.
@Dan Gohman do you know where that code lives?
I think https://searchfox.org/mozilla-central/source/js/src/wasm/WasmIonCompile.cpp#933
er wait that's ion
perhaps starting from here? https://searchfox.org/mozilla-central/source/js/src/wasm/WasmFrameIter.cpp#559
Yeah, that's it, though I'm forgetting how interrupt checking happens offhand
@fitzgen (he/him) I saw that yeah but it was only called from loop headers as well, @Chris Fallin thanks! I'll investigate from there
fwiw, I recommend using searchfox, since you can jump to definition, find all uses, etc
It may just be that until we support tail calls, you don't need to check for interrupts in function headers because any loop would eventually run out of stack space anyway.
there's also interruptTlsOffset
which is seemingly unused, but seems like the thing that would be used: https://searchfox.org/mozilla-central/search?q=symbol:F_%3CT_CraneliftStaticEnvironment%3E_interruptTlsOffset&redirect=false
@Dan Gohman I thought that too but this wasm module executes effectively infinitely in bounded stack
yeah I cant seem to find this in WasmFrameIter.cpp either...
oh it's the stack limit
all spidermonkey functions check the stack limit before doing the call
and interruption sets the interrupt flag as well as the stack limit -- https://searchfox.org/mozilla-central/source/js/src/wasm/WasmTypes.cpp#963
which kills loops and kills function calls
Last updated: Nov 22 2024 at 16:03 UTC