Skip to content

Commit ea78652

Browse files
committed
update uses of call_guest_function_by_name with run
Signed-off-by: Jorge Prendes <[email protected]>
1 parent 65ff6ff commit ea78652

File tree

16 files changed

+98
-163
lines changed

16 files changed

+98
-163
lines changed

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.run::<i32>(
3131
"PrintOutput",
3232
data,
3333
)

src/hyperlight_host/benches/benchmarks.rs

Lines changed: 5 additions & 14 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 {
@@ -38,7 +36,7 @@ fn guest_call_benchmark(c: &mut Criterion) {
3836
group.bench_function("guest_call", |b| {
3937
let mut sbox = create_multiuse_sandbox();
4038

41-
b.iter(|| sbox.call::<String>("Echo", "hello\n".to_string()).unwrap());
39+
b.iter(|| sbox.run::<String>("Echo", "hello\n".to_string()).unwrap());
4240
});
4341

4442
// Benchmarks a single guest function call.
@@ -48,7 +46,7 @@ fn guest_call_benchmark(c: &mut Criterion) {
4846
let snapshot = sbox.snapshot().unwrap();
4947

5048
b.iter(|| {
51-
sbox.call::<String>("Echo", "hello\n".to_string()).unwrap();
49+
sbox.run::<String>("Echo", "hello\n".to_string()).unwrap();
5250
sbox.restore(&snapshot).unwrap();
5351
});
5452
});
@@ -65,11 +63,7 @@ fn guest_call_benchmark(c: &mut Criterion) {
6563

6664
let mut multiuse_sandbox: MultiUseSandbox = uninitialized_sandbox.evolve().unwrap();
6765

68-
b.iter(|| {
69-
multiuse_sandbox
70-
.call::<i32>("Add", (1_i32, 41_i32))
71-
.unwrap()
72-
});
66+
b.iter(|| multiuse_sandbox.run::<i32>("Add", (1_i32, 41_i32)).unwrap());
7367
});
7468

7569
group.finish();
@@ -99,10 +93,7 @@ fn guest_call_benchmark_large_param(c: &mut Criterion) {
9993

10094
b.iter(|| {
10195
sandbox
102-
.call_guest_function_by_name::<()>(
103-
"LargeParameters",
104-
(large_vec.clone(), large_string.clone()),
105-
)
96+
.run::<()>("LargeParameters", (large_vec.clone(), large_string.clone()))
10697
.unwrap()
10798
});
10899
});

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.run("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.run("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+
.run::<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+
.run::<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+
.run::<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+
.run::<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+
.run::<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.run::<()>("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+
.run::<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+
.run::<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.run::<()>("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.run("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+
.run::<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+
.run::<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.run::<()>("Spin", ()).unwrap_err();
185183
}
186184
thread.join().expect("Thread panicked");
187185
}

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

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

4343
// do the function call
4444
let current_time = std::time::Instant::now();
45-
let res: String = sbox.call_guest_function_by_name("Echo", "Hello, World!".to_string())?;
45+
let res: String = sbox.run("Echo", "Hello, World!".to_string())?;
4646
let elapsed = current_time.elapsed();
4747
println!("Function call finished in {:?}.", elapsed);
4848
assert_eq!(res, "Hello, World!");

0 commit comments

Comments
 (0)