The tug-of-war over server-side WebAssembly
The other day I came across an interesting &quot;alternative&quot; to WASM which gives you OS portability using fully native code, without CPU portability, the latter seeming not that big of a deal these days anyway as cross compilers have got quite good and there are only two CPU archs in wide usage anyway.<p>The idea is to simply run normal Linux binaries on macOS and Windows. How? You create a virtual machine using the Mac&#x2F;Windows APIs <i>without</i> any OS inside, in fact without even any virtual hardware. It&#x27;s literally just a new address space and some trivial min-viable VM configuration. Then you map the ELF binary and a ld.so into the VM with a minimal ELF interpreter, kick off execution and anytime there&#x27;s a syscall you trap it and translate to the host OS syscalls. It can work quite well on macOS because the syscall interface is so similar.<p>Note that this sort of VM is not:<p>• A sandbox<p>• A hardware abstraction<p>Apps run this way hold all their data in the filing system of the host OS, they use the network stack of the host OS, etc. The VM is only being used to allow trapping and emulation of the syscall interface. The app isn&#x27;t aware that it&#x27;s being run in a special CPU mode on top of an emulated kernel.<p>Advantages: lightweight, simple, apps can use all CPU features, can run at native speed, the Linux syscall interface is highly stable, based on POSIX specifications and you can easily pick a subset of it to standardize.<p>Disadvantages: requires the emulator, apps exposed to missing features or quirks of the host OS e.g. Windows file system performance is much lower than Linux.<p>WSL1 sort of worked that way, albeit without the VM aspect that lets userspace apps do it. They abandoned it partly for performance reasons and users expected all existing Linux apps to just work. But WASM doesn&#x27;t target existing apps. It expects developers to bend and do things the WASM way, and accepts that not all apps are compatible with it, so that&#x27;s not necessarily a problem.<p>An example of how to implement this is NOAH:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;linux-noah&#x2F;noah&#x2F;">https:&#x2F;&#x2F;github.com&#x2F;linux-noah&#x2F;noah&#x2F;</a>