@Dan Gohman hey so I'm poking around (after yesterday) at more of the stack limit/interrupt stuff, and I was looking to tackle #900 while I was at it. I'm thinking of mirroring spidermonkey where each relevant function has a prologue which checks the stack limit and traps if we ran out. It looks like there's an ArgumentPurpose::StackLimit
parameter which is already in cranelift which is roughly analagous to this, but it seems like it may not be quite right? Does that require that every caller of the function pass in the stack limit? I'd ideally prefer to avoid reserving another argument for our purposes (we already take 2 with the two vmctx arguments)
and fwiw you seemed active on both https://github.com/bytecodealliance/cranelift/pull/372 and https://github.com/bytecodealliance/cranelift/issues/349
or is there a way we could like synthesize an "argument" inside of each function?
so it's calculated from other arguments
right now, you're right, StackLimit is an argument that needs to be passed in
bah ok, so this isn't quite what I want then
take a look at insert_common_prologue
in cranelift/codegen/src/isa/x86/abi.rs
You probably want to reuse insert_stack_check
, but you just need another way of telling it where to find the limit
kk, I'll see if I can whip up something
error[E0061]: this function takes 12 parameters but 11 parameters were supplied
cry
@Dan Gohman so I'm getting can't encode v17 = ifcmp_sp.i32 v16
as a panic message which is called from here and panics here
it seems like this previous StackLimit
stuff just wasn't ever fully tested before? do you know if that's the case?
I see a text test or two but I don't know why that doesn't panic but what I'm doing panics (unless something is specific to actually encoding instructions)
cranelift/filetests/filetests/isa/x86/prologue-epilogue.clif is a test which exercises a stack_limit argument
right yeah
is that testing the actual x86 encoding/emission
which means that I'm just doing something wrong?
but, I wouldn't be too surprised if it doesn't work if you use it differently
hm ok, I know very little about cranelift and all this...
oh, you probably want to do ifcmp_sp.i64, not i32, on x86-64
It probably doesn't know how to encode a 32-bit version of that
is there a separate method for that?
oh wait I think I had a type error in the IR
It's inferred from the operand.
yeah that made me realize I was doing a 32-bit load when I wanted a 64-bit one
which may be why the encoding failed
oh hey!
now it works!
sorta at least
ok cool thanks
for being a rubber duck :)
and pointing out bit-nes
@Dan Gohman is there a way to dump generated code to stderr?
or otherwise debug what's happening?
Not from wasmtime right now.
Cranelift has some utilities in cranelift/src/disasm.rs which can use capstone to disassemble the output, but they're not yet wired up in convenient ways
outside of clif-util, at least
or use lldb :P
that too :smile:
ok no worries, I've now got every single wasm function to immediately trap
which is good, and it seems to be passing the verifier too
Fwiw, Spidermonkey doesn't pass the stack check limit as an argument; stack checks are generated in Cranelift IR directly.
Last updated: Dec 23 2024 at 12:05 UTC