From a1f4cba7a2f76776f32aad260c5ff9e35d04b757 Mon Sep 17 00:00:00 2001 From: Alex Arnold Date: Sun, 19 Jan 2025 03:19:12 -0500 Subject: [PATCH 1/3] Create Box64 PR based off ptitSebs code --- crates/muvm/src/guest/bin/muvm-guest.rs | 3 ++- crates/muvm/src/guest/mod.rs | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/muvm/src/guest/bin/muvm-guest.rs b/crates/muvm/src/guest/bin/muvm-guest.rs index 2ca20f2..6addfd2 100644 --- a/crates/muvm/src/guest/bin/muvm-guest.rs +++ b/crates/muvm/src/guest/bin/muvm-guest.rs @@ -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; @@ -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()?; diff --git a/crates/muvm/src/guest/mod.rs b/crates/muvm/src/guest/mod.rs index 78fd5e4..0886ee8 100644 --- a/crates/muvm/src/guest/mod.rs +++ b/crates/muvm/src/guest/mod.rs @@ -1,5 +1,6 @@ pub mod cli_options; pub mod fex; +pub mod box64; pub mod mount; pub mod net; pub mod socket; From c37c980f882d3c397772dd5badb775ace55dda42 Mon Sep 17 00:00:00 2001 From: Alex Arnold Date: Sun, 19 Jan 2025 03:22:02 -0500 Subject: [PATCH 2/3] Create Box64 PR based off ptitSebs code --- crates/muvm/src/guest/box64.rs | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 crates/muvm/src/guest/box64.rs diff --git a/crates/muvm/src/guest/box64.rs b/crates/muvm/src/guest/box64.rs new file mode 100644 index 0000000..826eac5 --- /dev/null +++ b/crates/muvm/src/guest/box64.rs @@ -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 = ":FEX-x86: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 = + ":FEX-x86_64: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(()) +} From 0f88d845a581183ffab26ca81b2b1abdc015e19c Mon Sep 17 00:00:00 2001 From: Alex <83061466+m1m1k4tz@users.noreply.github.com> Date: Sun, 19 Jan 2025 04:50:18 -0500 Subject: [PATCH 3/3] Change rule names --- crates/muvm/src/guest/box64.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/muvm/src/guest/box64.rs b/crates/muvm/src/guest/box64.rs index 826eac5..268c3e2 100644 --- a/crates/muvm/src/guest/box64.rs +++ b/crates/muvm/src/guest/box64.rs @@ -5,12 +5,12 @@ use anyhow::{Context, Result}; use crate::utils::env::find_in_path; -const BOX32_BINFMT_MISC_RULE: &str = ":FEX-x86:M:0:\\x7fELF\\x01\\x01\\x01\\x00\\x00\\x00\\x00\\\ +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 = - ":FEX-x86_64:M:0:\\x7fELF\\x02\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\\ + ":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";