Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 10 additions & 11 deletions src/hyperlight_host/examples/func_ctx/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

use hyperlight_host::func::call_ctx::MultiUseGuestCallContext;
use hyperlight_host::sandbox::{Callable, MultiUseSandbox, UninitializedSandbox};
use hyperlight_host::sandbox::{MultiUseSandbox, UninitializedSandbox};
use hyperlight_host::sandbox_state::sandbox::EvolvableSandbox;
use hyperlight_host::sandbox_state::transition::Noop;
use hyperlight_host::{GuestBinary, Result};
Expand All @@ -24,32 +23,32 @@ use hyperlight_testing::simple_guest_as_string;
fn main() {
// create a new `MultiUseSandbox` configured to run the `simpleguest.exe`
// test guest binary
let sbox1: MultiUseSandbox = {
let mut sbox1: MultiUseSandbox = {
let path = simple_guest_as_string().unwrap();
let u_sbox = UninitializedSandbox::new(GuestBinary::FilePath(path), None).unwrap();
u_sbox.evolve(Noop::default())
}
.unwrap();

// create a new call context from the sandbox, then do some calls with it.
let ctx1 = sbox1.new_call_context();
let sbox2 = do_calls(ctx1).unwrap();
do_calls(&mut sbox1).unwrap();

// create a new call context from the returned sandbox, then do some calls
// with that one
let ctx2 = sbox2.new_call_context();
do_calls(ctx2).unwrap();
do_calls(&mut sbox1).unwrap();
}

/// Given a `MultiUseGuestCallContext` derived from an existing
/// `MultiUseSandbox` configured to run the `simpleguest.exe` test guest
/// binary, do several calls against that binary, print their results, then
/// call `ctx.finish()` and return the resulting `MultiUseSandbox`. Return an `Err`
/// if anything failed.
fn do_calls(mut ctx: MultiUseGuestCallContext) -> Result<MultiUseSandbox> {
let res: String = ctx.call("Echo", "hello".to_string())?;
fn do_calls(sbox: &mut MultiUseSandbox) -> Result<()> {
let res: String = sbox.call_guest_function_by_name("Echo", "hello".to_string())?;
println!("got Echo res: {res}");

let res: i32 = ctx.call("CallMalloc", 200_i32)?;
let res: i32 = sbox.call_guest_function_by_name("CallMalloc", 200_i32)?;
println!("got CallMalloc res: {res}");
ctx.finish()

Ok(())
}
7 changes: 3 additions & 4 deletions src/hyperlight_host/examples/logging/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ extern crate hyperlight_host;

use std::sync::{Arc, Barrier};

use hyperlight_host::sandbox::Callable;
use hyperlight_host::sandbox::uninitialized::UninitializedSandbox;
use hyperlight_host::sandbox_state::sandbox::EvolvableSandbox;
use hyperlight_host::sandbox_state::transition::Noop;
Expand Down Expand Up @@ -102,10 +101,10 @@ fn main() -> Result<()> {
// Call a function that gets cancelled by the host function 5 times to generate some log entries.

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

Expand Down
7 changes: 3 additions & 4 deletions src/hyperlight_host/examples/metrics/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ extern crate hyperlight_host;
use std::sync::{Arc, Barrier};
use std::thread::{JoinHandle, spawn};

use hyperlight_host::sandbox::Callable;
use hyperlight_host::sandbox::uninitialized::UninitializedSandbox;
use hyperlight_host::sandbox_state::sandbox::EvolvableSandbox;
use hyperlight_host::sandbox_state::transition::Noop;
Expand Down Expand Up @@ -116,10 +115,10 @@ fn do_hyperlight_stuff() {
// Call a function that gets cancelled by the host function 5 times to generate some metrics.

for _ in 0..NUM_CALLS {
let mut ctx = multiuse_sandbox.new_call_context();
barrier.wait();
ctx.call::<()>("Spin", ()).unwrap_err();
multiuse_sandbox = ctx.finish().unwrap();
multiuse_sandbox
.call_guest_function_by_name::<()>("Spin", ())
.unwrap_err();
}

for join_handle in join_handles {
Expand Down
7 changes: 3 additions & 4 deletions src/hyperlight_host/examples/tracing-otlp/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use std::io::stdin;
use std::sync::{Arc, Barrier, Mutex};
use std::thread::{JoinHandle, spawn};

use hyperlight_host::sandbox::Callable;
use hyperlight_host::sandbox::uninitialized::UninitializedSandbox;
use hyperlight_host::sandbox_state::sandbox::EvolvableSandbox;
use hyperlight_host::sandbox_state::transition::Noop;
Expand Down Expand Up @@ -184,10 +183,10 @@ fn run_example(wait_input: bool) -> HyperlightResult<()> {
uuid = %id,
);
let _entered = span.enter();
let mut ctx = multiuse_sandbox.new_call_context();
barrier.wait();
ctx.call::<()>("Spin", ()).unwrap_err();
multiuse_sandbox = ctx.finish().unwrap();
multiuse_sandbox
.call_guest_function_by_name::<()>("Spin", ())
.unwrap_err();
}
thread.join().expect("Thread panicked");
}
Expand Down
7 changes: 3 additions & 4 deletions src/hyperlight_host/examples/tracing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ extern crate hyperlight_host;
use std::sync::{Arc, Barrier};
use std::thread::{JoinHandle, spawn};

use hyperlight_host::sandbox::Callable;
use hyperlight_host::sandbox::uninitialized::UninitializedSandbox;
use hyperlight_host::sandbox_state::sandbox::EvolvableSandbox;
use hyperlight_host::sandbox_state::transition::Noop;
Expand Down Expand Up @@ -139,10 +138,10 @@ fn run_example() -> Result<()> {
uuid = %id,
);
let _entered = span.enter();
let mut ctx = multiuse_sandbox.new_call_context();
barrier.wait();
ctx.call::<()>("Spin", ()).unwrap_err();
multiuse_sandbox = ctx.finish().unwrap();
multiuse_sandbox
.call_guest_function_by_name::<()>("Spin", ())
.unwrap_err();
}

for join_handle in join_handles {
Expand Down