Skip to content

Commit 5be9cc5

Browse files
Rollup merge of rust-lang#104070 - nbdd0121:unwind, r=Amanieu
Prevent aborting guard from aborting the process in a forced unwind Fix rust-lang#101469
2 parents cf3404d + 4d4823a commit 5be9cc5

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

std/src/personality/dwarf/eh.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pub enum EHAction {
4747
None,
4848
Cleanup(usize),
4949
Catch(usize),
50+
Filter(usize),
5051
Terminate,
5152
}
5253

@@ -142,9 +143,11 @@ unsafe fn interpret_cs_action(
142143
let ttype_index = action_reader.read_sleb128();
143144
if ttype_index == 0 {
144145
EHAction::Cleanup(lpad)
145-
} else {
146+
} else if ttype_index > 0 {
146147
// Stop unwinding Rust panics at catch_unwind.
147148
EHAction::Catch(lpad)
149+
} else {
150+
EHAction::Filter(lpad)
148151
}
149152
}
150153
}

std/src/personality/gcc.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ cfg_if::cfg_if! {
135135
EHAction::None | EHAction::Cleanup(_) => {
136136
return continue_unwind(exception_object, context);
137137
}
138-
EHAction::Catch(_) => {
138+
EHAction::Catch(_) | EHAction::Filter(_) => {
139139
// EHABI requires the personality routine to update the
140140
// SP value in the barrier cache of the exception object.
141141
(*exception_object).private[5] =
@@ -147,7 +147,8 @@ cfg_if::cfg_if! {
147147
} else {
148148
match eh_action {
149149
EHAction::None => return continue_unwind(exception_object, context),
150-
EHAction::Cleanup(lpad) | EHAction::Catch(lpad) => {
150+
EHAction::Filter(_) if state & uw::_US_FORCE_UNWIND as c_int != 0 => return continue_unwind(exception_object, context),
151+
EHAction::Cleanup(lpad) | EHAction::Catch(lpad) | EHAction::Filter(lpad) => {
151152
uw::_Unwind_SetGR(
152153
context,
153154
UNWIND_DATA_REG.0,
@@ -201,13 +202,15 @@ cfg_if::cfg_if! {
201202
if actions as i32 & uw::_UA_SEARCH_PHASE as i32 != 0 {
202203
match eh_action {
203204
EHAction::None | EHAction::Cleanup(_) => uw::_URC_CONTINUE_UNWIND,
204-
EHAction::Catch(_) => uw::_URC_HANDLER_FOUND,
205+
EHAction::Catch(_) | EHAction::Filter(_) => uw::_URC_HANDLER_FOUND,
205206
EHAction::Terminate => uw::_URC_FATAL_PHASE1_ERROR,
206207
}
207208
} else {
208209
match eh_action {
209210
EHAction::None => uw::_URC_CONTINUE_UNWIND,
210-
EHAction::Cleanup(lpad) | EHAction::Catch(lpad) => {
211+
// Forced unwinding hits a terminate action.
212+
EHAction::Filter(_) if actions as i32 & uw::_UA_FORCE_UNWIND as i32 != 0 => uw::_URC_CONTINUE_UNWIND,
213+
EHAction::Cleanup(lpad) | EHAction::Catch(lpad) | EHAction::Filter(lpad) => {
211214
uw::_Unwind_SetGR(
212215
context,
213216
UNWIND_DATA_REG.0,

0 commit comments

Comments
 (0)