How does dynamic dispatch work in WebAssembly?
fitzgeraldnick.com
How does dynamic dispatch work in WebAssembly?
1–10 of 22 posts
Re: How does dynamic dispatch work in WebAssembly?
#2Re: How does dynamic dispatch work in WebAssembly?
#3Someone should make a CPU that does this. Intel CET is a bit of a start, but a CALL instruction that takes a “type” operand and only calls functions of that type would be a big improvement. So would a totally separate return address stack.
Re: How does dynamic dispatch work in WebAssembly?
#4Someone should make a CPU that does this. Intel CET is a bit of a start, but a CALL instruction that takes a “type” operand and only calls functions of that type would be a big improvement. So would a totally separate return address stack.
It seems pretty difficult to define function types at the ISA level, since anything to do with typing is language/VM-specific. What types can arguments have? Are varargs supported? Multiple parameter returns?
Maybe the type would just be an integer that the ABI would assign meaning to. But if you did that, how would the function's type be determined? Some pseudo-instruction at the CALL target? I guess looking at CET it does have some things like this: the ENDBRANCH instructions notate valid indirect branch targets.
Re: How does dynamic dispatch work in WebAssembly?
#5Re: How does dynamic dispatch work in WebAssembly?
#6Someone should make a CPU that does this. Intel CET is a bit of a start, but a CALL instruction that takes a “type” operand and only calls functions of that type would be a big improvement. So would a totally separate return address stack.
And what about CET's shadow stack is deficient compared to a "totally separate return address stack"?
Re: How does dynamic dispatch work in WebAssembly?
#7Creative uses of computed jumps, messing with the stack, dynamic codegen, all sorts of weird things your new language might do to efficiently implement some new control or data structure aren't likely to be possible.
At least in the short term nobody is going to be too upset. Today if something needs to wring all the power available from your CPU it isn't reasonable to put it on the web. That will continue to be true. WASM is the wise 80% solution, not a toy for ASM hackers and people messing around with weird prototype programming languages.
Re: How does dynamic dispatch work in WebAssembly?
#8So how are function pointers in (say) C implemented?
Re: How does dynamic dispatch work in WebAssembly?
#9Re: How does dynamic dispatch work in WebAssembly?
#10So how are function pointers in (say) C implemented?
C is high-level enough that IIRC it doesn't guarantee that arbitrary addresses can successfully be used as function pointers; the only valid function pointers are results of addresses of functions, or (possibly) values that have been cast from and then to them. Which is enough for wasm.
Try compiling this (to wat, which is an S-expression format that otherwise resembles the assembly in this article): https://wasdk.github.io/WasmFiddle/?5zbjb