Runtime code generation and execution in Go
mathetake.github.io
mathetake.github.io
[1] A common optimization technique, like in the superb https://github.com/klauspost/compress
The few tools that generate that asm, such as https://github.com/mmcloughlin/avo , would also have follow the rules.
You're not meant to take C source, crank it through GCC, and slurp that in as inline asm in Go.
Background: https://www.youtube.com/watch?v=KINIAgRpkDA
So if they break wazero, they'll know pretty soon from failing tests of their own Wasm/WASI toolchain.
https://github.com/golang/go/blob/go1.22.3/misc/wasm/go_wasi...
As for sandboxing, wazero tends to take sandboxing rather more seriously than other similar runtimes.
Memory sandboxing is implemented through explicit bounds checks (rather than memory mapping and guard pages), which allows denser deployments and requires less runtime support.
And, by default, the WASI implementation doesn't expose any capabilities (not even access to the system clock). You can also interject any relevant WASI host calls, and do your own filtering.
And if the compiler is not your cup of tea, you can also use the (much slower) interpreter.
I wonder what it would take to make a version that works on Windows. Will you indulge me?
In fact the exact same assembly works across Windows, macOS, Linux and FreeBSD: the calling convention used by the compiler is entirely custom, and all "host calls" are provided by wazero, so assembly ports fine across OSes.
> The following is the tiny demo of the runtime code generation and execution in Go. I assume you are on a Unix-like system like Linux or macOS on an AArch64 machine.
Is there a way to get tinydemo working on Windows?
You need to replace calls to syscall.Mmap with windows.VirtualAlloc [1], syscall.Mprotect with windows.VirtualProtect, etc.
You don't even need to change the ASM preamble.
[1]: https://pkg.go.dev/golang.org/x/sys/windows#VirtualAlloc