@@ -18,17 +18,14 @@ limitations under the License.
1818
1919use std:: sync:: { Mutex , OnceLock } ;
2020
21+ use hyperlight_common:: flatbuffer_wrappers:: guest_error:: ErrorCode ;
2122use hyperlight_host:: func:: { ParameterValue , ReturnType } ;
2223use hyperlight_host:: sandbox:: SandboxConfiguration ;
23- use hyperlight_host:: sandbox:: snapshot:: Snapshot ;
2424use hyperlight_host:: sandbox:: uninitialized:: GuestBinary ;
2525use hyperlight_host:: { HyperlightError , MultiUseSandbox , UninitializedSandbox } ;
2626use hyperlight_testing:: simple_guest_for_fuzzing_as_string;
2727use libfuzzer_sys:: fuzz_target;
2828
29- // TODO: this SNAPSHOT is needed because of the memory leak in: https://github.com/hyperlight-dev/hyperlight/issues/826
30- // This should be removed once the leak is fixed
31- static SNAPSHOT : OnceLock < Mutex < Snapshot > > = OnceLock :: new ( ) ;
3229static SANDBOX : OnceLock < Mutex < MultiUseSandbox > > = OnceLock :: new ( ) ;
3330
3431// This fuzz target tests all combinations of ReturnType and Parameters for `call_guest_function_by_name`.
@@ -44,27 +41,25 @@ fuzz_target!(
4441 )
4542 . unwrap( ) ;
4643
47- let mut mu_sbox: MultiUseSandbox = u_sbox. evolve( ) . unwrap( ) ;
48- let snapshot = mu_sbox. snapshot( ) . unwrap( ) ;
44+ let mu_sbox: MultiUseSandbox = u_sbox. evolve( ) . unwrap( ) ;
4945 SANDBOX . set( Mutex :: new( mu_sbox) ) . unwrap( ) ;
50- SNAPSHOT . set( Mutex :: new( snapshot) ) . map_err( |_| "Snapshot already set" ) . unwrap( ) ;
5146 } ,
5247
5348 |data: ( String , ReturnType , Vec <ParameterValue >) | {
5449 let ( host_func_name, host_func_return, mut host_func_params) = data;
5550 let mut sandbox = SANDBOX . get( ) . unwrap( ) . lock( ) . unwrap( ) ;
56- let snapshot = SNAPSHOT . get( ) . unwrap( ) . lock( ) . unwrap( ) ;
57- sandbox. restore( & snapshot) . unwrap( ) ;
58-
59- host_func_params. insert( 0 , ParameterValue :: String ( host_func_name) ) ;
51+ host_func_params. insert( 0 , ParameterValue :: String ( host_func_name. clone( ) ) ) ;
6052 if let Err ( e) = sandbox. call_type_erased_guest_function_by_name( "FuzzHostFunc" , host_func_return, host_func_params) {
6153 match e {
6254 // the following are expected errors and occur frequently since
6355 // we are randomly generating the function name and parameters
6456 // to call with.
6557 HyperlightError :: HostFunctionNotFound ( _) => { }
58+ HyperlightError :: GuestError ( ErrorCode :: HostFunctionError , msg) if msg == format!( "HostFunction {} was not found" , host_func_name) => { }
6659 HyperlightError :: UnexpectedNoOfArguments ( _, _) => { } ,
60+ HyperlightError :: GuestError ( ErrorCode :: HostFunctionError , msg) if msg. contains( "The number of arguments to the function is wrong" ) => { }
6761 HyperlightError :: ParameterValueConversionFailure ( _, _) => { } ,
62+ HyperlightError :: GuestError ( ErrorCode :: HostFunctionError , msg) if msg. contains( "Failed To Convert Parameter Value" ) => { }
6863
6964 // any other error should be reported
7065 _ => panic!( "Guest Aborted with Unexpected Error: {:?}" , e) ,
0 commit comments