@@ -246,7 +246,11 @@ impl HypervisorHandler {
246246 #[ cfg( target_os = "windows" ) ]
247247 let in_process = sandbox_memory_manager. is_in_process ( ) ;
248248
249- * self . execution_variables . shm . try_lock ( ) . unwrap ( ) = Some ( sandbox_memory_manager) ;
249+ * self
250+ . execution_variables
251+ . shm
252+ . try_lock ( )
253+ . map_err ( |e| new_error ! ( "Failed to lock shm: {}" , e) ) ? = Some ( sandbox_memory_manager) ;
250254
251255 // Other than running initialization and code execution, the handler thread also handles
252256 // cancellation. When we need to cancel the execution there are 2 possible cases
@@ -299,13 +303,13 @@ impl HypervisorHandler {
299303 HypervisorHandlerAction :: Initialise => {
300304 {
301305 hv = Some ( set_up_hypervisor_partition (
302- execution_variables. shm . try_lock ( ) . unwrap ( ) . deref_mut ( ) . as_mut ( ) . unwrap ( ) ,
306+ execution_variables. shm . try_lock ( ) . map_err ( |e| new_error ! ( "Failed to lock shm: {}" , e ) ) ? . deref_mut ( ) . as_mut ( ) . ok_or_else ( || new_error ! ( "shm not set" ) ) ? ,
303307 configuration. outb_handler . clone ( ) ,
304308 #[ cfg( gdb) ]
305309 & debug_info,
306310 ) ?) ;
307311 }
308- let hv = hv. as_mut ( ) . unwrap ( ) ;
312+ let hv = hv. as_mut ( ) . ok_or_else ( || new_error ! ( "Hypervisor not set" ) ) ? ;
309313
310314 #[ cfg( target_os = "windows" ) ]
311315 if !in_process {
@@ -386,7 +390,7 @@ impl HypervisorHandler {
386390 }
387391 }
388392 HypervisorHandlerAction :: DispatchCallFromHost ( function_name) => {
389- let hv = hv. as_mut ( ) . unwrap ( ) ;
393+ let hv = hv. as_mut ( ) . ok_or_else ( || new_error ! ( "Hypervisor not initialized" ) ) ? ;
390394
391395 // Lock to indicate an action is being performed in the hypervisor
392396 execution_variables. running . store ( true , Ordering :: SeqCst ) ;
@@ -647,6 +651,8 @@ impl HypervisorHandler {
647651 // If the thread has finished, we try to join it and return the error if it has one
648652 let res = handle. join ( ) ;
649653 if res. as_ref ( ) . is_ok_and ( |inner_res| inner_res. is_err ( ) ) {
654+ #[ allow( clippy:: unwrap_used) ]
655+ // We know that the thread has finished and that the inner result is an error, so we can safely unwrap the result and the contained err
650656 return Err ( res. unwrap ( ) . unwrap_err ( ) ) ;
651657 }
652658 Err ( HyperlightError :: HypervisorHandlerMessageReceiveTimedout ( ) )
@@ -757,7 +763,7 @@ impl HypervisorHandler {
757763 if thread_id == u64:: MAX {
758764 log_then_return ! ( "Failed to get thread id to signal thread" ) ;
759765 }
760- let mut count: i32 = 0 ;
766+ let mut count: u128 = 0 ;
761767 // We need to send the signal multiple times in case the thread was between checking if it
762768 // should be cancelled and entering the run loop
763769
@@ -771,7 +777,7 @@ impl HypervisorHandler {
771777 while !self . execution_variables . run_cancelled . load ( ) {
772778 count += 1 ;
773779
774- if count > number_of_iterations. try_into ( ) . unwrap ( ) {
780+ if count > number_of_iterations {
775781 break ;
776782 }
777783
@@ -797,7 +803,8 @@ impl HypervisorHandler {
797803 // partition handle only set when running in-hypervisor (not in-process)
798804 unsafe {
799805 WHvCancelRunVirtualProcessor (
800- self . execution_variables . get_partition_handle ( ) ?. unwrap ( ) , // safe unwrap
806+ #[ allow( clippy:: unwrap_used) ]
807+ self . execution_variables . get_partition_handle ( ) ?. unwrap ( ) , // safe unwrap as we checked is some
801808 0 ,
802809 0 ,
803810 )
0 commit comments