@@ -576,9 +576,14 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {
576
576
let msg = info. message ( ) . unwrap ( ) ; // The current implementation always returns Some
577
577
crate :: sys_common:: backtrace:: __rust_end_short_backtrace ( move || {
578
578
if let Some ( msg) = msg. as_str ( ) {
579
- rust_panic_with_hook ( & mut StrPanicPayload ( msg) , info. message ( ) , loc) ;
579
+ rust_panic_with_hook ( & mut StrPanicPayload ( msg) , info. message ( ) , loc, info . can_unwind ( ) ) ;
580
580
} else {
581
- rust_panic_with_hook ( & mut PanicPayload :: new ( msg) , info. message ( ) , loc) ;
581
+ rust_panic_with_hook (
582
+ & mut PanicPayload :: new ( msg) ,
583
+ info. message ( ) ,
584
+ loc,
585
+ info. can_unwind ( ) ,
586
+ ) ;
582
587
}
583
588
} )
584
589
}
@@ -602,7 +607,7 @@ pub const fn begin_panic<M: Any + Send>(msg: M) -> ! {
602
607
603
608
let loc = Location :: caller ( ) ;
604
609
return crate :: sys_common:: backtrace:: __rust_end_short_backtrace ( move || {
605
- rust_panic_with_hook ( & mut PanicPayload :: new ( msg) , None , loc)
610
+ rust_panic_with_hook ( & mut PanicPayload :: new ( msg) , None , loc, true )
606
611
} ) ;
607
612
608
613
struct PanicPayload < A > {
@@ -647,6 +652,7 @@ fn rust_panic_with_hook(
647
652
payload : & mut dyn BoxMeUp ,
648
653
message : Option < & fmt:: Arguments < ' _ > > ,
649
654
location : & Location < ' _ > ,
655
+ can_unwind : bool ,
650
656
) -> ! {
651
657
let ( must_abort, panics) = panic_count:: increase ( ) ;
652
658
@@ -663,14 +669,14 @@ fn rust_panic_with_hook(
663
669
} else {
664
670
// Unfortunately, this does not print a backtrace, because creating
665
671
// a `Backtrace` will allocate, which we must to avoid here.
666
- let panicinfo = PanicInfo :: internal_constructor ( message, location) ;
672
+ let panicinfo = PanicInfo :: internal_constructor ( message, location, can_unwind ) ;
667
673
rtprintpanic ! ( "{}\n panicked after panic::always_abort(), aborting.\n " , panicinfo) ;
668
674
}
669
- intrinsics :: abort ( )
675
+ crate :: sys :: abort_internal ( ) ;
670
676
}
671
677
672
678
unsafe {
673
- let mut info = PanicInfo :: internal_constructor ( message, location) ;
679
+ let mut info = PanicInfo :: internal_constructor ( message, location, can_unwind ) ;
674
680
let _guard = HOOK_LOCK . read ( ) ;
675
681
match HOOK {
676
682
// Some platforms (like wasm) know that printing to stderr won't ever actually
@@ -691,13 +697,13 @@ fn rust_panic_with_hook(
691
697
} ;
692
698
}
693
699
694
- if panics > 1 {
700
+ if panics > 1 || !can_unwind {
695
701
// If a thread panics while it's already unwinding then we
696
702
// have limited options. Currently our preference is to
697
703
// just abort. In the future we may consider resuming
698
704
// unwinding or otherwise exiting the thread cleanly.
699
705
rtprintpanic ! ( "thread panicked while panicking. aborting.\n " ) ;
700
- intrinsics :: abort ( )
706
+ crate :: sys :: abort_internal ( ) ;
701
707
}
702
708
703
709
rust_panic ( payload)
0 commit comments