-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support using Box64 for x86 emulation
Add the "emu" command line argument to let users choose the emulator to be used for running x86 binaries. Add support for installing Box64 in binfmt_misc. If the argument is not present in the command line, try to use FEX first and if it can't be set up, try again with Box64. Supersedes: #140 Co-authored-by: ptitSeb <[email protected]> Co-authored-by: Alex Arnold <[email protected]> Signed-off-by: Sergio Lopez <[email protected]>
- Loading branch information
1 parent
49a0346
commit 4a3fc58
Showing
7 changed files
with
99 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use std::fs::File; | ||
use std::io::Write; | ||
|
||
use anyhow::{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 Err(anyhow!("Failed to find `box64` in PATH")); | ||
}; | ||
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(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod box64; | ||
pub mod fex; | ||
pub mod hidpipe; | ||
pub mod mount; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters