Skip to content

Remove host_print_writer from the arguments to UninitializedSandbox::new #487

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

Merged
merged 1 commit into from
May 14, 2025
Merged
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
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ fn main() -> hyperlight_host::Result<()> {
hyperlight_host::GuestBinary::FilePath(hyperlight_testing::simple_guest_as_string().unwrap()),
None, // default configuration
None, // default run options
None, // default host print function
)?;

// Registering a host function makes it available to be called by the guest
Expand Down
1 change: 0 additions & 1 deletion fuzz/fuzz_targets/guest_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ fuzz_target!(
GuestBinary::FilePath(simple_guest_for_fuzzing_as_string().expect("Guest Binary Missing")),
None,
None,
None,
)
.unwrap();

Expand Down
2 changes: 0 additions & 2 deletions fuzz/fuzz_targets/host_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use std::sync::{Mutex, OnceLock};

use hyperlight_host::func::{ParameterValue, ReturnType};
use hyperlight_host::sandbox::uninitialized::GuestBinary;
use hyperlight_host::sandbox::SandboxConfiguration;
use hyperlight_host::sandbox_state::sandbox::EvolvableSandbox;
use hyperlight_host::sandbox_state::transition::Noop;
use hyperlight_host::{HyperlightError, MultiUseSandbox, UninitializedSandbox};
Expand All @@ -36,7 +35,6 @@ fuzz_target!(
GuestBinary::FilePath(simple_guest_for_fuzzing_as_string().expect("Guest Binary Missing")),
None,
None,
None,
)
.unwrap();

Expand Down
1 change: 0 additions & 1 deletion fuzz/fuzz_targets/host_print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ fuzz_target!(
GuestBinary::FilePath(simple_guest_for_fuzzing_as_string().expect("Guest Binary Missing")),
None,
None,
None,
)
.unwrap();

Expand Down
3 changes: 1 addition & 2 deletions src/hyperlight_host/benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use hyperlight_testing::simple_guest_as_string;

fn create_uninit_sandbox() -> UninitializedSandbox {
let path = simple_guest_as_string().unwrap();
UninitializedSandbox::new(GuestBinary::FilePath(path), None, None, None).unwrap()
UninitializedSandbox::new(GuestBinary::FilePath(path), None, None).unwrap()
}

fn create_multiuse_sandbox() -> MultiUseSandbox {
Expand Down Expand Up @@ -83,7 +83,6 @@ fn guest_call_benchmark(c: &mut Criterion) {
GuestBinary::FilePath(simple_guest_as_string().unwrap()),
Some(config),
None,
None,
)
.unwrap();
let mut sandbox = sandbox.evolve(Noop::default()).unwrap();
Expand Down
3 changes: 1 addition & 2 deletions src/hyperlight_host/examples/func_ctx/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ fn main() {
// test guest binary
let sbox1: MultiUseSandbox = {
let path = simple_guest_as_string().unwrap();
let u_sbox =
UninitializedSandbox::new(GuestBinary::FilePath(path), None, None, None).unwrap();
let u_sbox = UninitializedSandbox::new(GuestBinary::FilePath(path), None, None).unwrap();
u_sbox.evolve(Noop::default())
}
.unwrap();
Expand Down
1 change: 0 additions & 1 deletion src/hyperlight_host/examples/guest-debugging/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ fn main() -> hyperlight_host::Result<()> {
),
cfg, // sandbox configuration
None, // default run options
None, // default host print function
)?;

// Register a host functions
Expand Down
1 change: 0 additions & 1 deletion src/hyperlight_host/examples/hello-world/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ fn main() -> hyperlight_host::Result<()> {
),
None, // default configuration
None, // default run options
None, // default host print function
)?;

// Register a host functions
Expand Down
11 changes: 2 additions & 9 deletions src/hyperlight_host/examples/logging/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ limitations under the License.
*/
#![allow(clippy::disallowed_macros)]
extern crate hyperlight_host;
use std::sync::{Arc, Mutex};

use hyperlight_common::flatbuffer_wrappers::function_types::{ParameterValue, ReturnType};
use hyperlight_host::sandbox::uninitialized::UninitializedSandbox;
Expand All @@ -41,15 +40,10 @@ fn main() -> Result<()> {

for _ in 0..20 {
let path = hyperlight_guest_path.clone();
let writer_func = Arc::new(Mutex::new(fn_writer));
let res: Result<()> = {
// Create a new sandbox.
let usandbox = UninitializedSandbox::new(
GuestBinary::FilePath(path),
None,
None,
Some(&writer_func),
)?;
let mut usandbox = UninitializedSandbox::new(GuestBinary::FilePath(path), None, None)?;
usandbox.register_print(fn_writer)?;

// Initialize the sandbox.

Expand Down Expand Up @@ -91,7 +85,6 @@ fn main() -> Result<()> {
GuestBinary::FilePath(hyperlight_guest_path.clone()),
None,
None,
None,
)?;

// Initialize the sandbox.
Expand Down
11 changes: 2 additions & 9 deletions src/hyperlight_host/examples/metrics/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ limitations under the License.
*/
#![allow(clippy::disallowed_macros)]
extern crate hyperlight_host;
use std::sync::{Arc, Mutex};
use std::thread::{spawn, JoinHandle};

use hyperlight_common::flatbuffer_wrappers::function_types::{ParameterValue, ReturnType};
Expand Down Expand Up @@ -53,15 +52,10 @@ fn do_hyperlight_stuff() {

for _ in 0..20 {
let path = hyperlight_guest_path.clone();
let writer_func = Arc::new(Mutex::new(fn_writer));
let handle = spawn(move || -> Result<()> {
// Create a new sandbox.
let usandbox = UninitializedSandbox::new(
GuestBinary::FilePath(path),
None,
None,
Some(&writer_func),
)?;
let mut usandbox = UninitializedSandbox::new(GuestBinary::FilePath(path), None, None)?;
usandbox.register_print(fn_writer)?;

// Initialize the sandbox.

Expand Down Expand Up @@ -103,7 +97,6 @@ fn do_hyperlight_stuff() {
GuestBinary::FilePath(hyperlight_guest_path.clone()),
None,
None,
None,
)
.expect("Failed to create UninitializedSandbox");

Expand Down
3 changes: 1 addition & 2 deletions src/hyperlight_host/examples/tracing-chrome/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ fn main() -> Result<()> {
simple_guest_as_string().expect("Cannot find the guest binary at the expected location.");

// Create a new sandbox.
let usandbox =
UninitializedSandbox::new(GuestBinary::FilePath(simple_guest_path), None, None, None)?;
let usandbox = UninitializedSandbox::new(GuestBinary::FilePath(simple_guest_path), None, None)?;

let mut sbox = usandbox
.evolve(Noop::<UninitializedSandbox, MultiUseSandbox>::default())
Expand Down
10 changes: 3 additions & 7 deletions src/hyperlight_host/examples/tracing-otlp/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ fn run_example(wait_input: bool) -> HyperlightResult<()> {
for i in 0..10 {
let path = hyperlight_guest_path.clone();
let exit = Arc::clone(&should_exit);
let writer_func = Arc::new(Mutex::new(fn_writer));
let handle = spawn(move || -> HyperlightResult<()> {
while !*exit.try_lock().unwrap() {
// Construct a new span named "hyperlight tracing example thread" with INFO level.
Expand All @@ -130,12 +129,9 @@ fn run_example(wait_input: bool) -> HyperlightResult<()> {
let _entered = span.enter();

// Create a new sandbox.
let usandbox = UninitializedSandbox::new(
GuestBinary::FilePath(path.clone()),
None,
None,
Some(&writer_func),
)?;
let mut usandbox =
UninitializedSandbox::new(GuestBinary::FilePath(path.clone()), None, None)?;
usandbox.register_print(fn_writer)?;

// Initialize the sandbox.

Expand Down
3 changes: 1 addition & 2 deletions src/hyperlight_host/examples/tracing-tracy/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ fn main() -> Result<()> {
simple_guest_as_string().expect("Cannot find the guest binary at the expected location.");

// Create a new sandbox.
let usandbox =
UninitializedSandbox::new(GuestBinary::FilePath(simple_guest_path), None, None, None)?;
let usandbox = UninitializedSandbox::new(GuestBinary::FilePath(simple_guest_path), None, None)?;

let mut sbox = usandbox
.evolve(Noop::<UninitializedSandbox, MultiUseSandbox>::default())
Expand Down
11 changes: 2 additions & 9 deletions src/hyperlight_host/examples/tracing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
use hyperlight_common::flatbuffer_wrappers::function_types::{ParameterValue, ReturnType};
use tracing::{span, Level};
extern crate hyperlight_host;
use std::sync::{Arc, Mutex};
use std::thread::{spawn, JoinHandle};

use hyperlight_host::sandbox::uninitialized::UninitializedSandbox;
Expand Down Expand Up @@ -60,7 +59,6 @@ fn run_example() -> Result<()> {

for i in 0..10 {
let path = hyperlight_guest_path.clone();
let writer_func = Arc::new(Mutex::new(fn_writer));
let handle = spawn(move || -> Result<()> {
// Construct a new span named "hyperlight tracing example thread" with INFO level.
let id = Uuid::new_v4();
Expand All @@ -73,12 +71,8 @@ fn run_example() -> Result<()> {
let _entered = span.enter();

// Create a new sandbox.
let usandbox = UninitializedSandbox::new(
GuestBinary::FilePath(path),
None,
None,
Some(&writer_func),
)?;
let mut usandbox = UninitializedSandbox::new(GuestBinary::FilePath(path), None, None)?;
usandbox.register_print(fn_writer)?;

// Initialize the sandbox.

Expand Down Expand Up @@ -119,7 +113,6 @@ fn run_example() -> Result<()> {
GuestBinary::FilePath(hyperlight_guest_path.clone()),
None,
None,
None,
)?;

// Initialize the sandbox.
Expand Down
2 changes: 1 addition & 1 deletion src/hyperlight_host/src/func/call_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ mod tests {
let path = simple_guest_as_string().map_err(|e| {
HyperlightError::Error(format!("failed to get simple guest path ({e:?})"))
})?;
UninitializedSandbox::new(GuestBinary::FilePath(path), None, None, None)
UninitializedSandbox::new(GuestBinary::FilePath(path), None, None)
}

/// Test to create a `MultiUseSandbox`, then call several guest functions
Expand Down
8 changes: 0 additions & 8 deletions src/hyperlight_host/src/func/guest_dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ mod tests {
GuestBinary::FilePath(simple_guest_as_string().expect("Guest Binary Missing")),
None,
None,
None,
)
.unwrap();

Expand Down Expand Up @@ -189,7 +188,6 @@ mod tests {
GuestBinary::FilePath(simple_guest_as_string().expect("Guest Binary Missing")),
None,
None,
None,
)
.unwrap();

Expand Down Expand Up @@ -221,7 +219,6 @@ mod tests {
GuestBinary::FilePath(simple_guest_as_string().expect("Guest Binary Missing")),
None,
None,
None,
)
.unwrap()
};
Expand Down Expand Up @@ -337,8 +334,6 @@ mod tests {
None,
// by default, the below represents in-hypervisor mode
None,
// just use the built-in host print function
None,
)
.unwrap();
test_call_guest_function_by_name(u_sbox);
Expand All @@ -360,7 +355,6 @@ mod tests {
GuestBinary::FilePath(simple_guest_as_string().expect("Guest Binary Missing")),
None,
None,
None,
)?;
let sandbox: MultiUseSandbox = usbox.evolve(Noop::default())?;
let mut ctx = sandbox.new_call_context();
Expand Down Expand Up @@ -409,7 +403,6 @@ mod tests {
GuestBinary::FilePath(callback_guest_as_string().expect("Guest Binary Missing")),
None,
None,
None,
)
.unwrap();

Expand Down Expand Up @@ -448,7 +441,6 @@ mod tests {
GuestBinary::FilePath(simple_guest_as_string().expect("Guest Binary Missing")),
None,
None,
None,
)
.unwrap();

Expand Down
45 changes: 45 additions & 0 deletions src/hyperlight_host/src/func/host_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,39 @@ macro_rules! impl_host_function {
}
}

impl<R $(, $P)*> HostFunction<R, ($($P,)*)> for &dyn HostFunction<R, ($($P,)*)>
where
$($P: SupportedParameterType + Clone,)*
R: SupportedReturnType,
{
/// Register the host function with the given name in the sandbox.
#[instrument(
err(Debug), skip(self, sandbox), parent = Span::current(), level = "Trace"
)]
fn register(
&self,
sandbox: &mut UninitializedSandbox,
name: &str,
) -> Result<()> {
(**self).register(sandbox, name)
}

/// Register the host function with the given name in the sandbox, allowing extra syscalls.
#[cfg(all(feature = "seccomp", target_os = "linux"))]
#[instrument(
err(Debug), skip(self, sandbox, extra_allowed_syscalls),
parent = Span::current(), level = "Trace"
)]
fn register_with_extra_allowed_syscalls(
&self,
sandbox: &mut UninitializedSandbox,
name: &str,
extra_allowed_syscalls: Vec<ExtraAllowedSyscall>,
) -> Result<()> {
(**self).register_with_extra_allowed_syscalls(sandbox, name, extra_allowed_syscalls)
}
}

impl<R $(, $P)*, F> IntoHostFunction<R, ($($P,)*)> for F
where
F: FnMut($($P),*) -> Result<R> + Send + 'static,
Expand Down Expand Up @@ -126,6 +159,18 @@ macro_rules! impl_host_function {
}
}

impl<R $(, $P)*> IntoHostFunction<R, ($($P,)*)> for &dyn HostFunction<R, ($($P,)*)>
where
R: SupportedReturnType,
$($P: SupportedParameterType + Clone,)*
{
type Output = Self;

fn into_host_function(self) -> Self::Output {
self
}
}

fn register_host_function<T, $($P,)* R>(
self_: Arc<Mutex<T>>,
sandbox: &mut UninitializedSandbox,
Expand Down
1 change: 0 additions & 1 deletion src/hyperlight_host/src/hypervisor/hypervisor_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,6 @@ mod tests {
GuestBinary::FilePath(simple_guest_as_string().expect("Guest Binary Missing")),
cfg,
None,
None,
)
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion src/hyperlight_host/src/hypervisor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ pub(crate) mod tests {
}

let sandbox =
UninitializedSandbox::new(GuestBinary::FilePath(filename.clone()), None, None, None)?;
UninitializedSandbox::new(GuestBinary::FilePath(filename.clone()), None, None)?;
let (hshm, gshm) = sandbox.mgr.build();
drop(hshm);

Expand Down
1 change: 0 additions & 1 deletion src/hyperlight_host/src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ mod tests {
GuestBinary::FilePath(simple_guest_as_string().unwrap()),
None,
None,
None,
)
.unwrap();

Expand Down
Loading