@@ -32,6 +32,7 @@ use alloc::{format, vec};
3232use core:: ffi:: c_char;
3333use core:: hint:: black_box;
3434use core:: ptr:: write_volatile;
35+ use spin:: Mutex ;
3536
3637use hyperlight_common:: flatbuffer_wrappers:: function_call:: { FunctionCall , FunctionCallType } ;
3738use hyperlight_common:: flatbuffer_wrappers:: function_types:: {
@@ -52,15 +53,14 @@ use log::{error, LevelFilter};
5253
5354extern 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
5758fn 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
6666fn 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) ]
718718pub 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) ]
11141114pub 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