File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed 
tests/rust_guests/simpleguest/src Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -480,4 +480,36 @@ mod tests {
480480            ) , 
481481        } 
482482    } 
483+ 
484+     #[ test]  
485+     fn  test_trigger_exception_on_guest ( )  { 
486+         let  usbox = UninitializedSandbox :: new ( 
487+             GuestBinary :: FilePath ( simple_guest_as_string ( ) . expect ( "Guest Binary Missing" ) ) , 
488+             None , 
489+             None , 
490+             None , 
491+         ) 
492+         . unwrap ( ) ; 
493+ 
494+         let  mut  multi_use_sandbox:  MultiUseSandbox  = usbox. evolve ( Noop :: default ( ) ) . unwrap ( ) ; 
495+ 
496+         let  res = multi_use_sandbox. call_guest_function_by_name ( 
497+             "TriggerException" , 
498+             ReturnType :: Void , 
499+             None , 
500+         ) ; 
501+ 
502+         assert ! ( res. is_err( ) ) ; 
503+ 
504+         match  res. unwrap_err ( )  { 
505+             HyperlightError :: GuestAborted ( _,  msg)  => { 
506+                 // msg should indicate we got an invalid opcode exception 
507+                 assert ! ( msg. contains( "EXCEPTION: 0x6" ) ) ; 
508+             } 
509+             e => panic ! ( 
510+                 "Expected HyperlightError::GuestExecutionError but got {:?}" , 
511+                 e
512+             ) , 
513+         } 
514+     } 
483515} 
Original file line number Diff line number Diff line change @@ -637,6 +637,13 @@ fn log_message(function_call: &FunctionCall) -> Result<Vec<u8>> {
637637    } 
638638} 
639639
640+ fn  trigger_exception ( _:  & FunctionCall )  -> Result < Vec < u8 > >  { 
641+     unsafe  { 
642+         core:: arch:: asm!( "ud2" ) ; 
643+     }  // trigger an undefined instruction exception 
644+     Ok ( get_flatbuffer_result_from_void ( ) ) 
645+ } 
646+ 
640647static  mut  COUNTER :  i32  = 0 ; 
641648
642649fn  add_to_static ( function_call :  & FunctionCall )  -> Result < Vec < u8 > >  { 
@@ -1094,6 +1101,14 @@ pub extern "C" fn hyperlight_main() {
10941101        add as  i64 , 
10951102    ) ; 
10961103    register_function ( add_def) ; 
1104+ 
1105+     let  trigger_exception_def = GuestFunctionDefinition :: new ( 
1106+         "TriggerException" . to_string ( ) , 
1107+         Vec :: new ( ) , 
1108+         ReturnType :: Void , 
1109+         trigger_exception as  i64 , 
1110+     ) ; 
1111+     register_function ( trigger_exception_def) ; 
10971112} 
10981113
10991114#[ no_mangle]  
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments