From 557ed94d1d628fc3e83cd7f3b052d0f9d36c2c07 Mon Sep 17 00:00:00 2001 From: Simon Davies Date: Wed, 11 Jun 2025 21:03:35 +0100 Subject: [PATCH] Changes to allow hyperlight-host to build with x86_64-unknown-linux-musl target Signed-off-by: Simon Davies --- Justfile | 7 ++++++- rust-toolchain.toml | 2 +- .../src/hypervisor/hyperv_linux.rs | 13 ++++++++++++ src/hyperlight_host/src/hypervisor/kvm.rs | 13 ++++++++++++ src/hyperlight_host/src/seccomp/guest.rs | 20 ++++++++++++++++++- 5 files changed, 52 insertions(+), 3 deletions(-) diff --git a/Justfile b/Justfile index b14448166..59c095c52 100644 --- a/Justfile +++ b/Justfile @@ -24,7 +24,12 @@ alias cg := build-and-move-c-guests # build host library build target=default-target: - cargo build --profile={{ if target == "debug" { "dev" } else { target } }} + cargo build --profile={{ if target == "debug" { "dev" } else { target } }} + +# build host library +build-with-musl-libc target=default-target: + cargo build --profile={{ if target == "debug" { "dev" } else { target } }} --target x86_64-unknown-linux-musl + # build testing guest binaries guests: build-and-move-rust-guests build-and-move-c-guests diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 779844372..5432e53da 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -2,4 +2,4 @@ channel = "1.85" # Target used for guest binaries. This is an additive list of targets in addition to host platform. # Will install the target if not already installed when building guest binaries. -targets = ["x86_64-unknown-none"] \ No newline at end of file +targets = ["x86_64-unknown-none", "x86_64-unknown-linux-musl"] diff --git a/src/hyperlight_host/src/hypervisor/hyperv_linux.rs b/src/hyperlight_host/src/hypervisor/hyperv_linux.rs index a35ffe703..e7f34d171 100644 --- a/src/hyperlight_host/src/hypervisor/hyperv_linux.rs +++ b/src/hyperlight_host/src/hypervisor/hyperv_linux.rs @@ -405,6 +405,19 @@ impl HypervLinuxDriver { interrupt_handle: Arc::new(LinuxInterruptHandle { running: AtomicU64::new(0), cancel_requested: AtomicBool::new(false), + #[cfg(all( + target_arch = "x86_64", + target_vendor = "unknown", + target_os = "linux", + target_env = "musl" + ))] + tid: AtomicU64::new(unsafe { libc::pthread_self() as u64 }), + #[cfg(not(all( + target_arch = "x86_64", + target_vendor = "unknown", + target_os = "linux", + target_env = "musl" + )))] tid: AtomicU64::new(unsafe { libc::pthread_self() }), retry_delay: config.get_interrupt_retry_delay(), sig_rt_min_offset: config.get_interrupt_vcpu_sigrtmin_offset(), diff --git a/src/hyperlight_host/src/hypervisor/kvm.rs b/src/hyperlight_host/src/hypervisor/kvm.rs index 03f03aeaa..5fb772764 100644 --- a/src/hyperlight_host/src/hypervisor/kvm.rs +++ b/src/hyperlight_host/src/hypervisor/kvm.rs @@ -360,6 +360,19 @@ impl KVMDriver { interrupt_handle: Arc::new(LinuxInterruptHandle { running: AtomicU64::new(0), cancel_requested: AtomicBool::new(false), + #[cfg(all( + target_arch = "x86_64", + target_vendor = "unknown", + target_os = "linux", + target_env = "musl" + ))] + tid: AtomicU64::new(unsafe { libc::pthread_self() as u64 }), + #[cfg(not(all( + target_arch = "x86_64", + target_vendor = "unknown", + target_os = "linux", + target_env = "musl" + )))] tid: AtomicU64::new(unsafe { libc::pthread_self() }), retry_delay: config.get_interrupt_retry_delay(), dropped: AtomicBool::new(false), diff --git a/src/hyperlight_host/src/seccomp/guest.rs b/src/hyperlight_host/src/seccomp/guest.rs index c036cbc03..cd4801d89 100644 --- a/src/hyperlight_host/src/seccomp/guest.rs +++ b/src/hyperlight_host/src/seccomp/guest.rs @@ -49,7 +49,25 @@ fn syscalls_allowlist() -> Result)>> { // because we don't currently support registering parameterized syscalls. ( libc::SYS_ioctl, - or![and![Cond::new(1, ArgLen::Dword, Eq, libc::TCGETS)?]], + or![and![Cond::new( + 1, + ArgLen::Dword, + Eq, + #[cfg(all( + target_arch = "x86_64", + target_vendor = "unknown", + target_os = "linux", + target_env = "musl" + ))] + libc::TCGETS.try_into()?, + #[cfg(not(all( + target_arch = "x86_64", + target_vendor = "unknown", + target_os = "linux", + target_env = "musl" + )))] + libc::TCGETS, + )?]], ), // `futex` is needed for some tests that run in parallel (`simple_test_parallel`, // and `callback_test_parallel`).