Skip to content

Commit 6fcffdb

Browse files
committed
Update simpleguest to 2024 edition
Signed-off-by: Ludvig Liljenberg <[email protected]>
1 parent 4c650d6 commit 6fcffdb

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/tests/rust_guests/simpleguest/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ edition = "2021"
77
hyperlight-guest = { path = "../../../hyperlight_guest" }
88
hyperlight-common = { path = "../../../hyperlight_common", default-features = false }
99
log = {version = "0.4", default-features = false }
10+
spin = "0.9.8"

src/tests/rust_guests/simpleguest/src/main.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use alloc::{format, vec};
3232
use core::ffi::c_char;
3333
use core::hint::black_box;
3434
use core::ptr::write_volatile;
35+
use spin::Mutex;
3536

3637
use hyperlight_common::flatbuffer_wrappers::function_call::{FunctionCall, FunctionCallType};
3738
use hyperlight_common::flatbuffer_wrappers::function_types::{
@@ -52,15 +53,14 @@ use log::{error, LevelFilter};
5253

5354
extern crate hyperlight_guest;
5455

55-
static mut BIGARRAY: [i32; 1024 * 1024] = [0; 1024 * 1024];
56+
static BIGARRAY: Mutex<[i32; 1024 * 1024]> = Mutex::new([0; 1024 * 1024]);
5657

5758
fn set_static(_: &FunctionCall) -> Result<Vec<u8>> {
58-
unsafe {
59-
for val in BIGARRAY.iter_mut() {
60-
*val = 1;
61-
}
62-
Ok(get_flatbuffer_result(BIGARRAY.len() as i32))
59+
let mut lock = BIGARRAY.lock();
60+
for val in lock.iter_mut() {
61+
*val = 1;
6362
}
63+
Ok(get_flatbuffer_result(lock.len() as i32))
6464
}
6565

6666
fn echo_double(function_call: &FunctionCall) -> Result<Vec<u8>> {
@@ -714,7 +714,7 @@ fn add(function_call: &FunctionCall) -> Result<Vec<u8>> {
714714
}
715715
}
716716

717-
#[no_mangle]
717+
#[unsafe(no_mangle)]
718718
pub extern "C" fn hyperlight_main() {
719719
let set_static_def = GuestFunctionDefinition::new(
720720
"SetStatic".to_string(),
@@ -1110,7 +1110,7 @@ pub extern "C" fn hyperlight_main() {
11101110
register_function(trigger_exception_def);
11111111
}
11121112

1113-
#[no_mangle]
1113+
#[unsafe(no_mangle)]
11141114
pub fn guest_dispatch_function(function_call: FunctionCall) -> Result<Vec<u8>> {
11151115
// This test checks the stack behavior of the input/output buffer
11161116
// by calling the host before serializing the function call.

0 commit comments

Comments
 (0)