11use crate :: { Error , Signal } ;
2- use std:: { mem, ptr} ;
2+ use std:: { mem, ops :: DerefMut , ptr} ;
33
44// std::cmp::max is not const :(
55const fn get_stack_size ( ) -> usize {
@@ -402,8 +402,8 @@ unsafe extern "C" fn signal_handler(
402402
403403/// The size of `CrashContext` can be too big w.r.t the size of alternatate stack
404404/// for `signal_handler`. Keep the crash context as a .bss field.
405- static CRASH_CONTEXT : parking_lot:: Mutex < mem :: MaybeUninit < crash_context:: CrashContext > > =
406- parking_lot:: const_mutex ( mem:: MaybeUninit :: uninit ( ) ) ;
405+ static CRASH_CONTEXT : parking_lot:: Mutex < crash_context:: CrashContext > =
406+ parking_lot:: const_mutex ( unsafe { mem:: zeroed ( ) } ) ;
407407
408408pub ( super ) struct HandlerInner {
409409 handler : Box < dyn crate :: CrashEvent > ,
@@ -435,12 +435,11 @@ impl HandlerInner {
435435 // Allow ourselves to be dumped, if that is what the user handler wishes to do
436436 let _set_dumpable = SetDumpable :: new ( self . dump_process ) ;
437437 debug_print ! ( "set dumpable" ) ;
438- let mut crash_ctx = CRASH_CONTEXT . lock ( ) ;
438+ let mut cc = CRASH_CONTEXT . lock ( ) ;
439439
440440 {
441- * crash_ctx = mem :: MaybeUninit :: zeroed ( ) ;
441+ ptr :: write_bytes ( cc . deref_mut ( ) , 0 , 1 ) ;
442442 debug_print ! ( "zeroed crashctx" ) ;
443- let cc = & mut * crash_ctx. as_mut_ptr ( ) ;
444443
445444 ptr:: copy_nonoverlapping ( nix_info, & mut cc. siginfo , 1 ) ;
446445 debug_print ! ( "copied siginfo" ) ;
@@ -451,24 +450,23 @@ impl HandlerInner {
451450
452451 cfg_if:: cfg_if! {
453452 if #[ cfg( target_arch = "aarch64" ) ] {
454- // let fp_ptr = uc_ptr.uc_mcontext.__reserved.as_ptr().cast::<crash_context::fpsimd_context>();
453+ let fp_ptr = uc_ptr. uc_mcontext. __reserved. as_ptr( ) . cast:: <crash_context:: fpsimd_context>( ) ;
455454
456- // if (*fp_ptr).head.magic == crash_context::FPSIMD_MAGIC {
457- // ptr::copy_nonoverlapping(fp_ptr, &mut cc.float_state, 1);
458- // }
455+ if ( * fp_ptr) . head. magic == crash_context:: FPSIMD_MAGIC {
456+ ptr:: copy_nonoverlapping( fp_ptr, & mut cc. float_state, 1 ) ;
457+ }
459458 } else if #[ cfg( not( target_arch = "arm" ) ) ] {
460- // if !uc_ptr.uc_mcontext.fpregs.is_null() {
461- // ptr::copy_nonoverlapping(uc_ptr.uc_mcontext.fpregs, ((&mut cc.float_state) as *mut crash_context::fpregset_t).cast(), 1);
462-
463- // }
459+ if !uc_ptr. uc_mcontext. fpregs. is_null( ) {
460+ ptr:: copy_nonoverlapping( uc_ptr. uc_mcontext. fpregs, ( ( & mut cc. float_state) as * mut crash_context:: fpregset_t) . cast( ) , 1 ) ;
461+ }
464462 }
465463 }
466464
467465 cc. pid = std:: process:: id ( ) as i32 ;
468466 cc. tid = libc:: syscall ( libc:: SYS_gettid ) as i32 ;
469467 }
470468
471- self . handler . on_crash ( & * crash_ctx . as_ptr ( ) )
469+ self . handler . on_crash ( & cc )
472470 }
473471 }
474472}
0 commit comments