-
-
Notifications
You must be signed in to change notification settings - Fork 4
Avoid repeating original argv[0] #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
resolves AsahiLinux#6 binfmt-dispatcher gets typically registered to binfmt-misc with flags `POCF`. - `P` will preserve the original argv[0] used - `O` will give the resolved binary (e.g. after symlink derefence) as an open file in fd 3 - but we can't use it as-is as FEX (at least) doesn't support taking "pathname" (execve) as an open file descriptor. - `C` and `F` are irrelevant here. To support properly binary file already open as fd 3, FEX needs to be patched to use `fexecve(3, argv, env)` kind of call when requested, it doesn't appear to support it yet. Signed-off-by: Fabrice A. Marie <[email protected]>
91ccc2e
to
7345eec
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have an x64 Rust binary which prints std::env::args().collect::<Vec<String>>()
which previously resulted in
gnome@daisy-macbookpro:~/Coding/Personal/temp$ ./target/x86_64-unknown-linux-musl/debug/temp foo bar
[binfmt_dispatcher] Using FEX with muvm
Failed to set the new pressure in the guest: could not connect to muvm server: No such file or directory (os error 2)
No IPv6 nameserver available for NDP/DHCPv6
Using default interface naming scheme 'v257'.
["/home/gnome/Coding/Personal/temp/target/x86_64-unknown-linux-musl/debug/temp", "./target/x86_64-unknown-linux-musl/debug/temp", "./target/x86_64-unknown-linux-musl/debug/temp", "foo", "bar"]
(mangled args, but executes the binary)
I have attempted testing this patch by building this branch and replacing /usr/bin/binfmt-dispatcher
(and fixing the SELinux junk), and now I get the following error when executing the same binary.
gnome@daisy-macbookpro:~/Coding/Personal/temp$ ./target/x86_64-unknown-linux-musl/debug/temp foo bar
[binfmt_dispatcher] Using FEX with muvm
Failed to set the new pressure in the guest: could not connect to muvm server: No such file or directory (os error 2)
No IPv6 nameserver available for NDP/DHCPv6
Using default interface naming scheme 'v257'.
./target/x86_64-unknown-linux-musl/debug/temp: command not found
"/usr/bin/FEXInterpreter" process exited with status code: 248
(cannot execute the binary anymore)
muvm does not preserve cwd. AsahiLinux/muvm@1edd91d |
Before:
After:
Thanks for your patch! Leslie Zhai |
} | ||
|
||
// File descriptor 3 is where binfmt_misc typically passes the executable | ||
let binary: PathBuf = read_link("/proc/self/fd/3").unwrap_or_else(|e| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: unused import: `read_link`
--> src/main.rs:12:29
|
12 | use std::fs::{canonicalize, read_link};
| ^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
warning: unused import: `PathBuf`
--> src/main.rs:15:23
|
15 | use std::path::{Path, PathBuf};
| ^^^^^^^
warning: `binfmt-dispatcher` (bin "binfmt-dispatcher") generated 2 warnings (run `cargo fix --bin "binfmt-dispatcher"` to apply 2 suggestions)
resolves #6
binfmt-dispatcher gets typically registered to binfmt-misc with flags
POCF
.P
will preserve the original argv[0] usedO
will give the resolved binary (e.g. after symlink derefence) as an open file in fd 3C
andF
are irrelevant here.To support properly binary file already open as fd 3, FEX needs to be patched to use
fexecve(3, argv, env)
kind of call when requested, it doesn't appear to support it yet.Signed-off-by: Fabrice A. Marie [email protected]