Live data from Hacker News

Ported my C game to WASM, here's every bug that I hit

ernesernesto.github.io

91–100 of 116 posts

Re: Ported my C game to WASM, here's every bug that I hit

#91

Earlier quoted context omitted.

You sounds like the misattributed Bill Gates of 2026.

No? Most consumer desktops have 8 or 16 GB and phones less. You want to use more than half for a web page? For reference 4 GB is 8x more than a ps3.

Game consoles are weird though, they have less RAM than contemporary PCs. Like PS3 and Xbox360 both had 512MB, while my iMac G5 had 1GB. Maybe cause the console's RAM is unified with the GPU, while the G5 only had 64-128MB VRAM.

Re: Ported my C game to WASM, here's every bug that I hit

#92
post #62

You can get real breakpoints, memory watching, etc in browser with the chrome debugging extension

I would recommend the VSCode WASM DWARF debugging extension instead of the Chrome extension nowadays:

https://marketplace.visualstudio.com/items?itemName=ms-vscod...

This allows to setup an IDE-like 'press F5 to build and start into a debug session' in VSCode, with the debuggee running in Chrome.

E.g. see:

https://floooh.github.io/2023/11/11/emscripten-ide.html

Re: Ported my C game to WASM, here's every bug that I hit

#93

Earlier quoted context omitted.

> I had no idea WASM is 32bit until I read your article! WASM(32) is a hybrid 32/64 bit architecture. The address range (and thus pointer size) is 32 bits, but it has native 64-bit integers. E.g. it's similar to the Linux x32 ABI. There is also a 'true' 64-bit wasm, but that's still too recent to be used in real-world code: https://caniuse.com/wf-wasm-memory64 (but wasm64 doesn't really make sense unless you really n…

> (but wasm64 doesn't really make sense unless you really need an address space greater than 32 bits, because the downside is slower performance) Or unless you need to use integer types that depend on pointer size (such as size_t or usize), but your integers are too large to fit in 32 bits. That's a pretty common occurrence in bioinformatics. I've been waiting for years for Wasm to become usable, but it looks like Ap…

Actually, WASM32 usually runs in a 64-bit browser, so it can utilize most of the 64-bit instructions and general purpose registers. The problem is it's much harder to ensure that 64-bit pointer don't access browser critical data structures such as stack or heap contents. At least for WASM32, the pointer arithmetic is easily forced to be 32-bit in natively running JIT-ed code without dramatic performance loses. So, it's guaranteed that the WASM32 module won't access anything further than 4 or 8GiB (4GiB + 4GiB, when doing more complicated effective memory addressing instructions), thus, it's easy to cage a 4GiB memory block and surround it with guard buffers of comparable size inside a 64-bit virtual address space. With WASM64 you can't do this optimization because 64-bit pointers easily access your browser's memory, you have to add a lot of runtime bound checks if the compiler static checker can't guarantee landing inside the safe address range.

Re: Ported my C game to WASM, here's every bug that I hit

#94

Earlier quoted context omitted.

looks like I was wrong, but here is the de-facto standard I was relying on over the years ;-). Not that I've memcpied many structs to file directly btw. http://www.catb.org/esr/structure-packing/

The general struct layout algorithm is that you lay out the first member at the address of the struct (this is guaranteed by C), and then subsequent fields in order (also guaranteed by C). What isn't guaranteed is how fields get their alignment, in particular shenanigans you can do with allocating fields in the padding of their prior field, and bitfields in general are horribly underspecified. In practice, C doesn't…

If you sort your fields by size or manually pad them with natural alignment, and use #pragma pack or equivalent non-standard directives that gets you most of the way there. But yes, avoid bitfields.

C++ "standard layout type" is the modern equivalent of "POD" I think.

Re: Ported my C game to WASM, here's every bug that I hit

#95
post #45

Earlier quoted context omitted.

Sometimes I wonder whether it's possible to run the wasm code in a separate sandboxed process to eliminate a lot of checks. I mean optionally, because normally JS calls wasm code synchronously in the same address space. The bridge will add more latency when there is a transition between JS and wasm. It's obviously complicated because some data structures can also be shared, such as SharedArrayBuffer.

> The bridge will add more latency when there is a transition between JS and wasm. This would be similar to how NaCl/PNaCl communicated with the JS side (via message passing), and that really sucked and would also be prohibitively slow for talking to 'high frequency APIs' like WebGL2 or WebGPU (or the DOM heh).

[deleted]

Re: Ported my C game to WASM, here's every bug that I hit

#96

Earlier quoted context omitted.

Wasm still doesn't let you make native user interfaces, the UI is in the web browser. You can put native UI components into a React Native or Electron app though.

> Wasm still doesn't let you make native user interfaces That's currently only not possible because nobody wants to do the work to create something like wasi-gfx ( https://wasi-gfx.dev/ ), but for native UI frameworks instead of 3D APIs. The inconvenient truth is that even "native" cross-platform applications hardly ever go through the trouble to target the platform-native UI framework (and instead they go through no…

I meant, in-browser wasm can't do native things like creating a blank non-browser window on my Mac like a Swift app could, no matter what libraries it uses.

Re: Ported my C game to WASM, here's every bug that I hit

#97
post #88
post #23

Earlier quoted context omitted.

which of these vulnerabilities are most concerning to you in wasm programs?

All of them.

Can you explain why atleast one of them is bad in WASM in your own words? Why be concerned? There are not really that many capabilities inside the WASM program that can be exploited and its hard to imagine a realistic example. An example that paper gave is doing document.write from WASM with unsantized strings but that is bad practice even in Javascript.

Re: Ported my C game to WASM, here's every bug that I hit

#98
post #68
post #19

Earlier quoted context omitted.

32 is better for a lot of things like simd. the strength of it is wasm can do both types now and js can't unfortunately. a number in js is strictly 64.

Not sure about SIMD. If you mean WASM, the main advantage of WASM32 over WASM64 is execution speed if it runs on a 64-bit runtime. This is because pointer accesses are simply 64-bit base pointer + 32/33-bit offset (the 32-bit pointer value in WASM program + some 32-bit optional offset). Since the offset in the memory access is already trimmed to 32/33-bit (in a 32-bit half of the register) at machine instruction leve…

I just meant getting to use 32-bit numbers in general and not just for memory. It's nice to be able to use them for speed but also when things like GPUs only support them. I wish JS supported using them too.

Re: Ported my C game to WASM, here's every bug that I hit

#99
post #66

Earlier quoted context omitted.

Why /s? That does massively reduce the exposure

As much as an OS process, on a modern OS that is. The bounds checking story is only on the external limits of linear memory segments. If memory gets corrupted inside a linear memory segment, it can equally well be exploited to change execution behaviour, which for many scenarios is already good enough for the attacker. Yet these kind of attack vectors usually are dropped from blog posts selling WebAssembly as a revol…

How could any general execution environment guarantee memory like that? That doesn't seem like a realistic expectation. You can write safe Rust code if you want memory guarantees in WASM but would you really want it to block the ability to run unsafe Rust code too?

Re: Ported my C game to WASM, here's every bug that I hit

#100
post #16

I love how WASM is the thing that finally blurred the line between Web and Native programming, formely two realms isolated from each other for a long time. This both develops better awareness of how the code is executed by the hardware, which JavaScript devs often lack, and also brings skilled folks from the Native platforms who seem to be not so against WASM as they were against JavaScript (and all other parts of th…

ActiveX, Alchemy, PNaCL,...

Saying ActiveX here shows a fundamental misunderstanding of what both WASM and ActiveX are.

Is ActiveX platform independent? No. it's exclusive to windows. Is it sandboxed? Nope, digital signing and prayer, does it implement a virtual machine? Nope. Compromises out the wazoo? efficiency, data orientation, or predictable performance? You betcha. ActiveX is closer to a DOM sandbox escape exploit than a real piece of engineering. Why do we need WASM when we've have GET since 1990?

Don't confuse the map for the territory, implementation details matter, just labeling something "Mars Colonial Transporter" doesn't mean it actually flew to mars.

Post reply on HN