Open lilianmoraru opened 5 years ago
I guess this would need some kind of wrapper (script), as just adding :wasm:M::\x00asm\x01\x00\x00::/usr/bin/wasmer:
(to /usr/lib/binfmt.d/wasm.conf
for systemd-binfmt) only works correctly if you don't pass any arguments.
[Edit:] I currently have this set up as
/usr/lib/binfmt.d/wasm.conf |
---|
:wasm:M::\x00asm\x01\x00\x00::/usr/local/bin/wasmerwrapper: |
/usr/local/bin/wasmerwrapper |
#!/usr/bin/env sh
exec /usr/bin/wasmer -- "$@"`
|
@jcaesar Can you please open a PR? It seems to be a really good feature to provide!
Could, but I learned some new stuff and now I kind-of don't want to, the way it is currently.
--dir
(probably from environment variables)The latter point is a bit tricky. You need to set the F and C flag on the binfmt_misc spec, and then make sure that whatever interpreter you specified is a static executable. The question is... do you want to ship an extra executable just for this? (qemu does.) Or do you want to mess up wasmer-cli's command structure so that it will first check if $1
is a wasm binary and execute it if so?
(Experimented a bit. binfmt-interpreting wasm files in docker containers is definitely doable: https://github.com/jcaesar/universal-docker-containers#experiment And of course I'm not the first person to have this idea.)
do you want to ship an extra executable just for this?
Yeah, nothing against that.
Or do you want to mess up wasmer-cli's command structure so that it will first check if $1 is a wasm binary and execute it if so?
It depends how complex that is, but I'm not against neither.
It depends how complex that is, but I'm not against neither.
Not awfully complex, but it'll stay relatively nasty for UX in some edge cases: binaries may be named the same was wasmer-cli subcommands. From what I see, there is nothing that would allow you to know that you're currently being run as a binfmt-interpreter or not.
Any ideas what to do about preopened directories? If WASI had a concept of $CWD
and you could preopen /
, that'd be nice…
From what I see, there is nothing that would allow you to know that you're currently being run as a binfmt-interpreter or not.
Correction: If you hardlink or copy, $0
will be set to whatever path you registered the binfmt interpreter from. I suppose I'll do a PR that:
$0
to /tmp/wasmer-exec
/tmp/wasmer-exec
is a statically linked executable and prints a warning otherwise/proc/sys/fs/binfmt_misc/wasm
basename $0
is wasmer-exec
, and then doesn't invoke the normal argument parser
/tmp
exists before enabling the normal cachingWASMER_BINFMT_
env variablesAnd a second PR that:
@lilianmoraru Doing the registering in the startup script would now be relatively easy. But I have one conceptual problem with it: The install script installs wasmer for one user, who could easily modify the wasmer executable. But the registration is global. A user-controlled file will be executed if root runs a wasm file. If you have a good suggestion for how to deal with that, please do tell.
My ideas so far:
Arch/Manjaro Linux already has WAPM as a separate package from Wasmer. It's currently in AUR though which is essentially installing from source using a script.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
not stale
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Feel free to reopen the issue if it has been closed by mistake.
Motivation
On Linux,
Wasmer
could usebinfmt_misc
to allow users to run WASM binaries like any other binary, without even knowing thewasmer
name or flags.Proposed solution
The installer script should register
Wasmer
as a newbinfmt_misc
interpreter.Additional context
QEMU uses this feature to run for example ARM binaries on x86_64 PCs. The package on Ubuntu that adds these configurations for QEMU is called
qemu-user-binfmt
. In order to make this work,binfmt-support
might be required.