@@ -576,9 +576,14 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {
576576 let msg = info. message ( ) . unwrap ( ) ; // The current implementation always returns Some
577577 crate :: sys_common:: backtrace:: __rust_end_short_backtrace ( move || {
578578 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 ( ) ) ;
580580 } 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+ ) ;
582587 }
583588 } )
584589}
@@ -602,7 +607,7 @@ pub const fn begin_panic<M: Any + Send>(msg: M) -> ! {
602607
603608 let loc = Location :: caller ( ) ;
604609 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 )
606611 } ) ;
607612
608613 struct PanicPayload < A > {
@@ -647,6 +652,7 @@ fn rust_panic_with_hook(
647652 payload : & mut dyn BoxMeUp ,
648653 message : Option < & fmt:: Arguments < ' _ > > ,
649654 location : & Location < ' _ > ,
655+ can_unwind : bool ,
650656) -> ! {
651657 let ( must_abort, panics) = panic_count:: increase ( ) ;
652658
@@ -663,14 +669,14 @@ fn rust_panic_with_hook(
663669 } else {
664670 // Unfortunately, this does not print a backtrace, because creating
665671 // 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 ) ;
667673 rtprintpanic ! ( "{}\n panicked after panic::always_abort(), aborting.\n " , panicinfo) ;
668674 }
669- intrinsics :: abort ( )
675+ crate :: sys :: abort_internal ( ) ;
670676 }
671677
672678 unsafe {
673- let mut info = PanicInfo :: internal_constructor ( message, location) ;
679+ let mut info = PanicInfo :: internal_constructor ( message, location, can_unwind ) ;
674680 let _guard = HOOK_LOCK . read ( ) ;
675681 match HOOK {
676682 // Some platforms (like wasm) know that printing to stderr won't ever actually
@@ -691,13 +697,13 @@ fn rust_panic_with_hook(
691697 } ;
692698 }
693699
694- if panics > 1 {
700+ if panics > 1 || !can_unwind {
695701 // If a thread panics while it's already unwinding then we
696702 // have limited options. Currently our preference is to
697703 // just abort. In the future we may consider resuming
698704 // unwinding or otherwise exiting the thread cleanly.
699705 rtprintpanic ! ( "thread panicked while panicking. aborting.\n " ) ;
700- intrinsics :: abort ( )
706+ crate :: sys :: abort_internal ( ) ;
701707 }
702708
703709 rust_panic ( payload)
0 commit comments