Skip to content

Commit 0f88a66

Browse files
authored
Bring back the previous behavior of call_guest_function_by_name (#761)
* bring back the previous call_guest_function_by_name behavior Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com> * update uses of call_guest_function_by_name with call Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com> * use the snapshot member as a mini snapshot cache Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com> * Use non-persisting guest calls for Callable trait Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com> --------- Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
1 parent 65217f3 commit 0f88a66

File tree

18 files changed

+194
-163
lines changed

18 files changed

+194
-163
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn main() -> hyperlight_host::Result<()> {
5858
let message = "Hello, World! I am executing inside of a VM :)\n".to_string();
5959
// in order to call a function it first must be defined in the guest and exposed so that
6060
// the host can call it
61-
multi_use_sandbox.call_guest_function_by_name::<i32>(
61+
multi_use_sandbox.call::<i32>(
6262
"PrintOutput",
6363
message,
6464
)?;

fuzz/fuzz_targets/host_print.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fuzz_target!(
2727

2828
|data: String| -> Corpus {
2929
let mut sandbox = SANDBOX.get().unwrap().lock().unwrap();
30-
let len: i32 = sandbox.call_guest_function_by_name::<i32>(
30+
let len: i32 = sandbox.call::<i32>(
3131
"PrintOutput",
3232
data,
3333
)

src/hyperlight_host/benches/benchmarks.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ limitations under the License.
1616

1717
use criterion::{Criterion, criterion_group, criterion_main};
1818
use hyperlight_host::GuestBinary;
19-
use hyperlight_host::sandbox::{
20-
Callable, MultiUseSandbox, SandboxConfiguration, UninitializedSandbox,
21-
};
19+
use hyperlight_host::sandbox::{MultiUseSandbox, SandboxConfiguration, UninitializedSandbox};
2220
use hyperlight_testing::simple_guest_as_string;
2321

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

10098
b.iter(|| {
10199
sandbox
102-
.call_guest_function_by_name::<()>(
103-
"LargeParameters",
104-
(large_vec.clone(), large_string.clone()),
105-
)
100+
.call::<()>("LargeParameters", (large_vec.clone(), large_string.clone()))
106101
.unwrap()
107102
});
108103
});

src/hyperlight_host/examples/func_ctx/main.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,9 @@ fn main() {
2929

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

37-
let res: i32 = sbox
38-
.call_guest_function_by_name("CallMalloc", 200_i32)
39-
.unwrap();
35+
let res: i32 = sbox.call("CallMalloc", 200_i32).unwrap();
4036
println!("got CallMalloc res: {res}");
4137
}

src/hyperlight_host/examples/guest-debugging/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn main() -> hyperlight_host::Result<()> {
7575
let message =
7676
"Hello, World! I am executing inside of a VM with debugger attached :)\n".to_string();
7777
multi_use_sandbox_dbg
78-
.call_guest_function_by_name::<i32>(
78+
.call::<i32>(
7979
"PrintOutput", // function must be defined in the guest binary
8080
message.clone(),
8181
)
@@ -84,7 +84,7 @@ fn main() -> hyperlight_host::Result<()> {
8484
let message =
8585
"Hello, World! I am executing inside of a VM without debugger attached :)\n".to_string();
8686
multi_use_sandbox
87-
.call_guest_function_by_name::<i32>(
87+
.call::<i32>(
8888
"PrintOutput", // function must be defined in the guest binary
8989
message.clone(),
9090
)

src/hyperlight_host/examples/hello-world/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn main() -> hyperlight_host::Result<()> {
4040
// Call guest function
4141
let message = "Hello, World! I am executing inside of a VM :)\n".to_string();
4242
multi_use_sandbox
43-
.call_guest_function_by_name::<i32>(
43+
.call::<i32>(
4444
"PrintOutput", // function must be defined in the guest binary
4545
message,
4646
)

src/hyperlight_host/examples/logging/main.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn main() -> Result<()> {
5050
// Call a guest function 5 times to generate some log entries.
5151
for _ in 0..5 {
5252
multiuse_sandbox
53-
.call_guest_function_by_name::<String>("Echo", "a".to_string())
53+
.call::<String>("Echo", "a".to_string())
5454
.unwrap();
5555
}
5656

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

9595
for _ in 0..NUM_CALLS {
9696
barrier.wait();
97-
multiuse_sandbox
98-
.call_guest_function_by_name::<()>("Spin", ())
99-
.unwrap_err();
97+
multiuse_sandbox.call::<()>("Spin", ()).unwrap_err();
10098
}
10199
thread.join().unwrap();
102100

src/hyperlight_host/examples/metrics/main.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn do_hyperlight_stuff() {
6161
// Call a guest function 5 times to generate some metrics.
6262
for _ in 0..5 {
6363
multiuse_sandbox
64-
.call_guest_function_by_name::<String>("Echo", "a".to_string())
64+
.call::<String>("Echo", "a".to_string())
6565
.unwrap();
6666
}
6767

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

109109
for _ in 0..NUM_CALLS {
110110
barrier.wait();
111-
multiuse_sandbox
112-
.call_guest_function_by_name::<()>("Spin", ())
113-
.unwrap_err();
111+
multiuse_sandbox.call::<()>("Spin", ()).unwrap_err();
114112
}
115113

116114
for join_handle in join_handles {

src/hyperlight_host/examples/tracing-chrome/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn main() -> Result<()> {
3636

3737
// do the function call
3838
let current_time = std::time::Instant::now();
39-
let res: String = sbox.call_guest_function_by_name("Echo", "Hello, World!".to_string())?;
39+
let res: String = sbox.call("Echo", "Hello, World!".to_string())?;
4040
let elapsed = current_time.elapsed();
4141
println!("Function call finished in {:?}.", elapsed);
4242
assert_eq!(res, "Hello, World!");

src/hyperlight_host/examples/tracing-otlp/main.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ fn run_example(wait_input: bool) -> HyperlightResult<()> {
136136
// Call a guest function 5 times to generate some log entries.
137137
for _ in 0..5 {
138138
multiuse_sandbox
139-
.call_guest_function_by_name::<String>("Echo", "a".to_string())
139+
.call::<String>("Echo", "a".to_string())
140140
.unwrap();
141141
}
142142

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

@@ -179,9 +179,7 @@ fn run_example(wait_input: bool) -> HyperlightResult<()> {
179179
);
180180
let _entered = span.enter();
181181
barrier.wait();
182-
multiuse_sandbox
183-
.call_guest_function_by_name::<()>("Spin", ())
184-
.unwrap_err();
182+
multiuse_sandbox.call::<()>("Spin", ()).unwrap_err();
185183
}
186184
thread.join().expect("Thread panicked");
187185
}

0 commit comments

Comments
 (0)