This was a great read! Really cool to see someone dive deep into WebAssembly by building an interpreter from scratch.
Asd
I Wrote a WebAssembly VM in C
91–100 of 104 posts
Re: I Wrote a WebAssembly VM in C
#92Re: I Wrote a WebAssembly VM in C
#93Re: I Wrote a WebAssembly VM in C
#94Re: I Wrote a WebAssembly VM in C
#95Earlier quoted context omitted.
A JIT should be able to translate most arithmetic and binary instructions to single-opcodes, however anything involving memory and functions calls needs safety checks that becomes multi-instruction. branches could mostly be direct _unless_ the runtime has any kind of metering (it should) to stop eternal loops (if it also wants to be crash-safe even if it's exploit safe).
> anything involving memory [..] needs safety checks that becomes multi-instruction Not necessarily; on AMD64 you can do memory accesses in a single instruction relatively easily by using the CPU's paging machinery for safety checks plus some clever use of address space. > branches could mostly be direct _unless_ the runtime has any kind of metering (it should) to stop eternal loops Even with metering the branches wo…
Reserving 4gb address space oughta work on any 64bit machine with a decent OS/paging system though? I was looking into it but couldn't use it in my case however since it needs to cooperate with another VM that already hooks the PF handler (although maybe I should take another stab if there is a way to put in a hierarhcy).
Re: I Wrote a WebAssembly VM in C
#96Earlier quoted context omitted.
Metering also doesn't require a branch if you implement it with page faults. See "Implicit suspend checks" in https://android-developers.googleblog.com/2023/11/the-secret...
Yep. That's a nice trick; unfortunately it's non-deterministic.
Re: I Wrote a WebAssembly VM in C
#97Re: I Wrote a WebAssembly VM in C
#98This is great! The WebAssembly Core Specification is actually quite readable, although some of the language can be a bit intimidating if you're not used to reading programming language papers. If anyone is looking for a slightly more accessible way to learn WebAssembly, you might enjoy WebAssembly from the Ground Up: https://wasmgroundup.com (Disclaimer: I'm one of the authors)
I know one of WebAssembly's biggest features by design is security / "sandbox". But I've always gotten confused with... it is secure because by default it can't do much. I don't quite understand how to view WebAssembly. You write in one language, it compiles things like basic math (nothing with network or filesystem) to another and it runs in an interpreter. I feel like I have a severe lack/misunderstanding. There's…
Re: I Wrote a WebAssembly VM in C
#99Re: I Wrote a WebAssembly VM in C
#100This was a great read! Really cool to see someone dive deep into WebAssembly by building an interpreter from scratch.