Skip to content

Bring back the previous behavior of call_guest_function_by_name #761

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 4 commits into from
Aug 8, 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn main() -> hyperlight_host::Result<()> {
let message = "Hello, World! I am executing inside of a VM :)\n".to_string();
// in order to call a function it first must be defined in the guest and exposed so that
// the host can call it
multi_use_sandbox.call_guest_function_by_name::<i32>(
multi_use_sandbox.call::<i32>(
"PrintOutput",
message,
)?;
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/host_print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fuzz_target!(

|data: String| -> Corpus {
let mut sandbox = SANDBOX.get().unwrap().lock().unwrap();
let len: i32 = sandbox.call_guest_function_by_name::<i32>(
let len: i32 = sandbox.call::<i32>(
"PrintOutput",
data,
)
Expand Down
9 changes: 2 additions & 7 deletions src/hyperlight_host/benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ limitations under the License.

use criterion::{Criterion, criterion_group, criterion_main};
use hyperlight_host::GuestBinary;
use hyperlight_host::sandbox::{
Callable, MultiUseSandbox, SandboxConfiguration, UninitializedSandbox,
};
use hyperlight_host::sandbox::{MultiUseSandbox, SandboxConfiguration, UninitializedSandbox};
use hyperlight_testing::simple_guest_as_string;

fn create_uninit_sandbox() -> UninitializedSandbox {
Expand Down Expand Up @@ -99,10 +97,7 @@ fn guest_call_benchmark_large_param(c: &mut Criterion) {

b.iter(|| {
sandbox
.call_guest_function_by_name::<()>(
"LargeParameters",
(large_vec.clone(), large_string.clone()),
)
.call::<()>("LargeParameters", (large_vec.clone(), large_string.clone()))
.unwrap()
});
});
Expand Down
8 changes: 2 additions & 6 deletions src/hyperlight_host/examples/func_ctx/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,9 @@ fn main() {

// Do several calls against a sandbox running the `simpleguest.exe` binary,
// and print their results
let res: String = sbox
.call_guest_function_by_name("Echo", "hello".to_string())
.unwrap();
let res: String = sbox.call("Echo", "hello".to_string()).unwrap();
println!("got Echo res: {res}");

let res: i32 = sbox
.call_guest_function_by_name("CallMalloc", 200_i32)
.unwrap();
let res: i32 = sbox.call("CallMalloc", 200_i32).unwrap();
println!("got CallMalloc res: {res}");
}
4 changes: 2 additions & 2 deletions src/hyperlight_host/examples/guest-debugging/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn main() -> hyperlight_host::Result<()> {
let message =
"Hello, World! I am executing inside of a VM with debugger attached :)\n".to_string();
multi_use_sandbox_dbg
.call_guest_function_by_name::<i32>(
.call::<i32>(
"PrintOutput", // function must be defined in the guest binary
message.clone(),
)
Expand All @@ -84,7 +84,7 @@ fn main() -> hyperlight_host::Result<()> {
let message =
"Hello, World! I am executing inside of a VM without debugger attached :)\n".to_string();
multi_use_sandbox
.call_guest_function_by_name::<i32>(
.call::<i32>(
"PrintOutput", // function must be defined in the guest binary
message.clone(),
)
Expand Down
2 changes: 1 addition & 1 deletion src/hyperlight_host/examples/hello-world/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn main() -> hyperlight_host::Result<()> {
// Call guest function
let message = "Hello, World! I am executing inside of a VM :)\n".to_string();
multi_use_sandbox
.call_guest_function_by_name::<i32>(
.call::<i32>(
"PrintOutput", // function must be defined in the guest binary
message,
)
Expand Down
8 changes: 3 additions & 5 deletions src/hyperlight_host/examples/logging/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn main() -> Result<()> {
// Call a guest function 5 times to generate some log entries.
for _ in 0..5 {
multiuse_sandbox
.call_guest_function_by_name::<String>("Echo", "a".to_string())
.call::<String>("Echo", "a".to_string())
.unwrap();
}

Expand All @@ -61,7 +61,7 @@ fn main() -> Result<()> {
// Call a guest function that calls the HostPrint host function 5 times to generate some log entries.
for _ in 0..5 {
multiuse_sandbox
.call_guest_function_by_name::<i32>("PrintOutput", msg.clone())
.call::<i32>("PrintOutput", msg.clone())
.unwrap();
}
Ok(())
Expand Down Expand Up @@ -94,9 +94,7 @@ fn main() -> Result<()> {

for _ in 0..NUM_CALLS {
barrier.wait();
multiuse_sandbox
.call_guest_function_by_name::<()>("Spin", ())
.unwrap_err();
multiuse_sandbox.call::<()>("Spin", ()).unwrap_err();
}
thread.join().unwrap();

Expand Down
8 changes: 3 additions & 5 deletions src/hyperlight_host/examples/metrics/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn do_hyperlight_stuff() {
// Call a guest function 5 times to generate some metrics.
for _ in 0..5 {
multiuse_sandbox
.call_guest_function_by_name::<String>("Echo", "a".to_string())
.call::<String>("Echo", "a".to_string())
.unwrap();
}

Expand All @@ -72,7 +72,7 @@ fn do_hyperlight_stuff() {
// Call a guest function that calls the HostPrint host function 5 times to generate some metrics.
for _ in 0..5 {
multiuse_sandbox
.call_guest_function_by_name::<i32>("PrintOutput", msg.clone())
.call::<i32>("PrintOutput", msg.clone())
.unwrap();
}
Ok(())
Expand Down Expand Up @@ -108,9 +108,7 @@ fn do_hyperlight_stuff() {

for _ in 0..NUM_CALLS {
barrier.wait();
multiuse_sandbox
.call_guest_function_by_name::<()>("Spin", ())
.unwrap_err();
multiuse_sandbox.call::<()>("Spin", ()).unwrap_err();
}

for join_handle in join_handles {
Expand Down
2 changes: 1 addition & 1 deletion src/hyperlight_host/examples/tracing-chrome/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn main() -> Result<()> {

// do the function call
let current_time = std::time::Instant::now();
let res: String = sbox.call_guest_function_by_name("Echo", "Hello, World!".to_string())?;
let res: String = sbox.call("Echo", "Hello, World!".to_string())?;
let elapsed = current_time.elapsed();
println!("Function call finished in {:?}.", elapsed);
assert_eq!(res, "Hello, World!");
Expand Down
8 changes: 3 additions & 5 deletions src/hyperlight_host/examples/tracing-otlp/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ fn run_example(wait_input: bool) -> HyperlightResult<()> {
// Call a guest function 5 times to generate some log entries.
for _ in 0..5 {
multiuse_sandbox
.call_guest_function_by_name::<String>("Echo", "a".to_string())
.call::<String>("Echo", "a".to_string())
.unwrap();
}

Expand All @@ -147,7 +147,7 @@ fn run_example(wait_input: bool) -> HyperlightResult<()> {
// Call a guest function that calls the HostPrint host function 5 times to generate some log entries.
for _ in 0..5 {
multiuse_sandbox
.call_guest_function_by_name::<i32>("PrintOutput", msg.clone())
.call::<i32>("PrintOutput", msg.clone())
.unwrap();
}

Expand Down Expand Up @@ -179,9 +179,7 @@ fn run_example(wait_input: bool) -> HyperlightResult<()> {
);
let _entered = span.enter();
barrier.wait();
multiuse_sandbox
.call_guest_function_by_name::<()>("Spin", ())
.unwrap_err();
multiuse_sandbox.call::<()>("Spin", ()).unwrap_err();
}
thread.join().expect("Thread panicked");
}
Expand Down
2 changes: 1 addition & 1 deletion src/hyperlight_host/examples/tracing-tracy/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn main() -> Result<()> {

// do the function call
let current_time = std::time::Instant::now();
let res: String = sbox.call_guest_function_by_name("Echo", "Hello, World!".to_string())?;
let res: String = sbox.call("Echo", "Hello, World!".to_string())?;
let elapsed = current_time.elapsed();
println!("Function call finished in {:?}.", elapsed);
assert_eq!(res, "Hello, World!");
Expand Down
8 changes: 3 additions & 5 deletions src/hyperlight_host/examples/tracing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn run_example() -> Result<()> {
// Call a guest function 5 times to generate some log entries.
for _ in 0..5 {
multiuse_sandbox
.call_guest_function_by_name::<String>("Echo", "a".to_string())
.call::<String>("Echo", "a".to_string())
.unwrap();
}

Expand All @@ -89,7 +89,7 @@ fn run_example() -> Result<()> {
// Call a guest function that calls the HostPrint host function 5 times to generate some log entries.
for _ in 0..5 {
multiuse_sandbox
.call_guest_function_by_name::<i32>("PrintOutput", msg.clone())
.call::<i32>("PrintOutput", msg.clone())
.unwrap();
}
Ok(())
Expand Down Expand Up @@ -131,9 +131,7 @@ fn run_example() -> Result<()> {
);
let _entered = span.enter();
barrier.wait();
multiuse_sandbox
.call_guest_function_by_name::<()>("Spin", ())
.unwrap_err();
multiuse_sandbox.call::<()>("Spin", ()).unwrap_err();
}

for join_handle in join_handles {
Expand Down
6 changes: 2 additions & 4 deletions src/hyperlight_host/src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,10 @@ mod tests {
});

multi
.call_guest_function_by_name::<i32>("PrintOutput", "Hello".to_string())
.call::<i32>("PrintOutput", "Hello".to_string())
.unwrap();

multi
.call_guest_function_by_name::<i32>("Spin", ())
.unwrap_err();
multi.call::<i32>("Spin", ()).unwrap_err();
thread.join().unwrap();

snapshotter.snapshot()
Expand Down
Loading
Loading