Live data from Hacker News

I Wrote a WebAssembly VM in C

irreducible.io

21–30 of 104 posts

Re: I Wrote a WebAssembly VM in C

#21
post #10
post #2

This 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)

> actually quite readable, although some of the language can be a bit intimidating if you're not used to reading programming language papers You're more generous than me, I think it's rubbish. Would have been easier to read if they had written it more like an ISA manual.

This is an opportunity to learn. The way WebAssembly is defined is the standard way PL semantics are defined.

Re: I Wrote a WebAssembly VM in C

#22
This was a fun read! I wrote a Wasm interpreter in Scheme awhile back so it makes me happy to see more people writing their own. It is less difficult than you might think. I encourage others to give the spec a look and give it a try. No need to implement every instruction, just enough to have fun.

Re: I Wrote a WebAssembly VM in C

#24
post #10
post #2

This 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)

> actually quite readable, although some of the language can be a bit intimidating if you're not used to reading programming language papers You're more generous than me, I think it's rubbish. Would have been easier to read if they had written it more like an ISA manual.

You can understand the WASM spec in your sleep if you’ve ever worked through a type-system paper from the last two decades (or a logic paper from even earlier I guess).

Granted, not many people have, but there’s a reason why it makes sense for it to be written in that style: they want it to be very clear that the verification (typechecking, really) algorithm doesn’t have any holes, and for that it’s reasonable to speak the language of the people who prove that type of thing for a living.

The WASM spec is also the ultimate authoritative reference for both programmers and implementers. That’s different from the goals of an ISA manual, which usually only targets programmers and just says “don’t do that” for certain dark corners of the (sole) implementation. (The RISC-V manual is atypical in this respect; still, I challenge you to describe e.g. which PC value the handler will see if the user code traps on a base RV32IMA system.)

Re: I Wrote a WebAssembly VM in C

#25
post #7
post #5

Earlier quoted context omitted.

WebAssembly can communicate through buffers. WebAssembly can also import foreign functions (Javascript functions in the browser). You can get output by reading the buffer at the end of execution/when receiving callbacks. So, for instance, you pass a few frames worth of buffers to WASM, WASM renders pixels into the buffers, calls a callback, and the Javascript reads data from the buffer (sending it to a or similar). T…

I don’t believe it is currently possible for a WebAssembly instance to access any buffer other than its own memory. You have to copy data in and out.

Use the GC instructions and you can freely share heap references amongst other modules and the host.

Re: I Wrote a WebAssembly VM in C

#26
post #2

This 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…

You should check out the book :-)

We have a chapter called "What Makes WebAssembly Safe?" which covers the details. You can get a sneak peek here: https://bsky.app/profile/wasmgroundup.com/post/3lh2e4eiwnm2p

Re: I Wrote a WebAssembly VM in C

#27

This is an interesting approach, great work! For anyone that wants to check where the meat is at, is mostly in this file: https://github.com/irrio/semblance/blob/main/src/wrun.c Thinking out loud, I think it would have been a great idea to conform with the Wasm-C-API ( https://github.com/WebAssembly/wasm-c-api ) as a standard interface for the project (which most of the Wasm runtimes: Wasmer, V8, wasmi, etc. have ado…

> Wasmer > Installed-Size: 266 MB What the hell

[deleted]

Re: I Wrote a WebAssembly VM in C

#28
post #7

Earlier quoted context omitted.

I don’t believe it is currently possible for a WebAssembly instance to access any buffer other than its own memory. You have to copy data in and out.

Use the GC instructions and you can freely share heap references amongst other modules and the host.

How do you access the contents of a heap reference from JavaScript in order to “send it to a or similar”?

Re: I Wrote a WebAssembly VM in C

#29
post #28

Earlier quoted context omitted.

Use the GC instructions and you can freely share heap references amongst other modules and the host.

How do you access the contents of a heap reference from JavaScript in order to “send it to a or similar”?

Assuming you're talking about reading binary data like (array i8), the GC MVP doesn't have a great answer right now. Have to call back into wasm to read the bytes. Something for the group to address in future proposals. Sharing between wasm modules is better right now.

Re: I Wrote a WebAssembly VM in C

#30
post #2

This 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…

I think the biggest advantage of wasm in terms of security is that it doesn't accept machine language written in the target machine, only in this artificial machine language. This means that it cannot encode arbitrary code that could be executed by the host machine. Everything it runs has necessarily to go through the wasm interpreter.
Post reply on HN