@@ -905,9 +905,8 @@ pub mod statik {
905
905
pub mod fast {
906
906
use super :: lazy:: LazyKeyInner ;
907
907
use crate :: cell:: Cell ;
908
- use crate :: fmt;
909
- use crate :: mem;
910
908
use crate :: sys:: thread_local_dtor:: register_dtor;
909
+ use crate :: { fmt, mem, panic} ;
911
910
912
911
#[ derive( Copy , Clone ) ]
913
912
enum DtorState {
@@ -1028,10 +1027,15 @@ pub mod fast {
1028
1027
// `Option<T>` to `None`, and `dtor_state` to `RunningOrHasRun`. This
1029
1028
// causes future calls to `get` to run `try_initialize_drop` again,
1030
1029
// which will now fail, and return `None`.
1031
- unsafe {
1030
+ //
1031
+ // Wrap the call in a catch to ensure unwinding is caught in the event
1032
+ // a panic takes place in a destructor.
1033
+ if let Err ( _) = panic:: catch_unwind ( panic:: AssertUnwindSafe ( || unsafe {
1032
1034
let value = ( * ptr) . inner . take ( ) ;
1033
1035
( * ptr) . dtor_state . set ( DtorState :: RunningOrHasRun ) ;
1034
1036
drop ( value) ;
1037
+ } ) ) {
1038
+ rtabort ! ( "thread local panicked on drop" ) ;
1035
1039
}
1036
1040
}
1037
1041
}
@@ -1044,10 +1048,8 @@ pub mod fast {
1044
1048
pub mod os {
1045
1049
use super :: lazy:: LazyKeyInner ;
1046
1050
use crate :: cell:: Cell ;
1047
- use crate :: fmt;
1048
- use crate :: marker;
1049
- use crate :: ptr;
1050
1051
use crate :: sys_common:: thread_local_key:: StaticKey as OsStaticKey ;
1052
+ use crate :: { fmt, marker, panic, ptr} ;
1051
1053
1052
1054
/// Use a regular global static to store this key; the state provided will then be
1053
1055
/// thread-local.
@@ -1137,12 +1139,17 @@ pub mod os {
1137
1139
//
1138
1140
// Note that to prevent an infinite loop we reset it back to null right
1139
1141
// before we return from the destructor ourselves.
1140
- unsafe {
1142
+ //
1143
+ // Wrap the call in a catch to ensure unwinding is caught in the event
1144
+ // a panic takes place in a destructor.
1145
+ if let Err ( _) = panic:: catch_unwind ( || unsafe {
1141
1146
let ptr = Box :: from_raw ( ptr as * mut Value < T > ) ;
1142
1147
let key = ptr. key ;
1143
1148
key. os . set ( ptr:: invalid_mut ( 1 ) ) ;
1144
1149
drop ( ptr) ;
1145
1150
key. os . set ( ptr:: null_mut ( ) ) ;
1151
+ } ) {
1152
+ rtabort ! ( "thread local panicked on drop" ) ;
1146
1153
}
1147
1154
}
1148
1155
}
0 commit comments