Skip to content
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

Use Box64 with muvm #140

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/muvm/src/guest/bin/muvm-guest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use log::debug;
use muvm::env::find_muvm_exec;
use muvm::guest::cli_options::options;
use muvm::guest::fex::setup_fex;
use muvm::guest::box64::setup_box;
use muvm::guest::mount::mount_filesystems;
use muvm::guest::net::configure_network;
use muvm::guest::socket::setup_socket_proxy;
Expand Down Expand Up @@ -52,7 +53,7 @@ fn main() -> Result<()> {

Command::new("/usr/lib/systemd/systemd-udevd").spawn()?;

setup_fex()?;
setup_fex().unwrap_or_else(|_error|setup_box().unwrap());

configure_network()?;

Expand Down
44 changes: 44 additions & 0 deletions crates/muvm/src/guest/box64.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use std::fs::File;
use std::io::Write;

use anyhow::{Context, Result};

use crate::utils::env::find_in_path;

const BOX32_BINFMT_MISC_RULE: &str = ":BOX32:M:0:\\x7fELF\\x01\\x01\\x01\\x00\\x00\\x00\\x00\\\
x00\\x00\\x00\\x00\\x00\\x02\\x00\\x03\\x00:\\xff\\xff\\\
xff\\xff\\xff\\xfe\\xfe\\x00\\x00\\x00\\x00\\xff\\xff\\\
xff\\xff\\xff\\xfe\\xff\\xff\\xff:${BOX64}:POCF";
const BOX64_BINFMT_MISC_RULE: &str =
":BOX64:M:0:\\x7fELF\\x02\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\\
x00\\x3e\\x00:\\xff\\xff\\xff\\xff\\xff\\xfe\\xfe\\x00\\x00\\x00\\x00\\xff\\xff\\xff\\xff\\\
xff\\xfe\\xff\\xff\\xff:${BOX64}:POCF";

pub fn setup_box() -> Result<()> {
let box64_path =
find_in_path("box64").context("Failed to check existence of `box64`")?;
let Some(box64_path) = box64_path else {
return Ok(());
};
let box64_path = box64_path
.to_str()
.context("Failed to process `box64` path as it contains invalid UTF-8")?;

let mut file = File::options()
.write(true)
.open("/proc/sys/fs/binfmt_misc/register")
.context("Failed to open binfmt_misc/register for writing")?;

{
let rule = BOX32_BINFMT_MISC_RULE.replace("${BOX64}", box64_path);
file.write_all(rule.as_bytes())
.context("Failed to register `Box32` binfmt_misc rule")?;
}
{
let rule = BOX64_BINFMT_MISC_RULE.replace("${BOX64}", box64_path);
file.write_all(rule.as_bytes())
.context("Failed to register `Box64` binfmt_misc rule")?;
}

Ok(())
}
1 change: 1 addition & 0 deletions crates/muvm/src/guest/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod cli_options;
pub mod fex;
pub mod box64;
pub mod mount;
pub mod net;
pub mod socket;
Expand Down