@@ -61,9 +61,11 @@ pub enum EHAction {
61
61
62
62
pub const USING_SJLJ_EXCEPTIONS : bool = cfg ! ( all( target_os = "ios" , target_arch = "arm" ) ) ;
63
63
64
- pub unsafe fn find_eh_action ( lsda : * const u8 , context : & EHContext ) -> EHAction {
64
+ pub unsafe fn find_eh_action ( lsda : * const u8 , context : & EHContext )
65
+ -> Result < EHAction , ( ) >
66
+ {
65
67
if lsda. is_null ( ) {
66
- return EHAction :: None ;
68
+ return Ok ( EHAction :: None )
67
69
}
68
70
69
71
let func_start = context. func_start ;
@@ -72,7 +74,7 @@ pub unsafe fn find_eh_action(lsda: *const u8, context: &EHContext) -> EHAction {
72
74
let start_encoding = reader. read :: < u8 > ( ) ;
73
75
// base address for landing pad offsets
74
76
let lpad_base = if start_encoding != DW_EH_PE_omit {
75
- read_encoded_pointer ( & mut reader, context, start_encoding)
77
+ read_encoded_pointer ( & mut reader, context, start_encoding) ?
76
78
} else {
77
79
func_start
78
80
} ;
@@ -90,9 +92,9 @@ pub unsafe fn find_eh_action(lsda: *const u8, context: &EHContext) -> EHAction {
90
92
91
93
if !USING_SJLJ_EXCEPTIONS {
92
94
while reader. ptr < action_table {
93
- let cs_start = read_encoded_pointer ( & mut reader, context, call_site_encoding) ;
94
- let cs_len = read_encoded_pointer ( & mut reader, context, call_site_encoding) ;
95
- let cs_lpad = read_encoded_pointer ( & mut reader, context, call_site_encoding) ;
95
+ let cs_start = read_encoded_pointer ( & mut reader, context, call_site_encoding) ? ;
96
+ let cs_len = read_encoded_pointer ( & mut reader, context, call_site_encoding) ? ;
97
+ let cs_lpad = read_encoded_pointer ( & mut reader, context, call_site_encoding) ? ;
96
98
let cs_action = reader. read_uleb128 ( ) ;
97
99
// Callsite table is sorted by cs_start, so if we've passed the ip, we
98
100
// may stop searching.
@@ -101,23 +103,23 @@ pub unsafe fn find_eh_action(lsda: *const u8, context: &EHContext) -> EHAction {
101
103
}
102
104
if ip < func_start + cs_start + cs_len {
103
105
if cs_lpad == 0 {
104
- return EHAction :: None ;
106
+ return Ok ( EHAction :: None )
105
107
} else {
106
108
let lpad = lpad_base + cs_lpad;
107
- return interpret_cs_action ( cs_action, lpad) ;
109
+ return Ok ( interpret_cs_action ( cs_action, lpad) )
108
110
}
109
111
}
110
112
}
111
113
// Ip is not present in the table. This should not happen... but it does: issue #35011.
112
114
// So rather than returning EHAction::Terminate, we do this.
113
- EHAction :: None
115
+ Ok ( EHAction :: None )
114
116
} else {
115
117
// SjLj version:
116
118
// The "IP" is an index into the call-site table, with two exceptions:
117
119
// -1 means 'no-action', and 0 means 'terminate'.
118
120
match ip as isize {
119
- -1 => return EHAction :: None ,
120
- 0 => return EHAction :: Terminate ,
121
+ -1 => return Ok ( EHAction :: None ) ,
122
+ 0 => return Ok ( EHAction :: Terminate ) ,
121
123
_ => ( ) ,
122
124
}
123
125
let mut idx = ip;
@@ -129,7 +131,7 @@ pub unsafe fn find_eh_action(lsda: *const u8, context: &EHContext) -> EHAction {
129
131
// Can never have null landing pad for sjlj -- that would have
130
132
// been indicated by a -1 call site index.
131
133
let lpad = ( cs_lpad + 1 ) as usize ;
132
- return interpret_cs_action ( cs_action, lpad) ;
134
+ return Ok ( interpret_cs_action ( cs_action, lpad) )
133
135
}
134
136
}
135
137
}
@@ -144,21 +146,26 @@ fn interpret_cs_action(cs_action: u64, lpad: usize) -> EHAction {
144
146
}
145
147
146
148
#[ inline]
147
- fn round_up ( unrounded : usize , align : usize ) -> usize {
148
- assert ! ( align. is_power_of_two( ) ) ;
149
- ( unrounded + align - 1 ) & !( align - 1 )
149
+ fn round_up ( unrounded : usize , align : usize ) -> Result < usize , ( ) > {
150
+ if align. is_power_of_two ( ) {
151
+ Ok ( ( unrounded + align - 1 ) & !( align - 1 ) )
152
+ } else {
153
+ Err ( ( ) )
154
+ }
150
155
}
151
156
152
157
unsafe fn read_encoded_pointer ( reader : & mut DwarfReader ,
153
158
context : & EHContext ,
154
159
encoding : u8 )
155
- -> usize {
156
- assert ! ( encoding != DW_EH_PE_omit ) ;
160
+ -> Result < usize , ( ) > {
161
+ if encoding == DW_EH_PE_omit {
162
+ return Err ( ( ) )
163
+ }
157
164
158
165
// DW_EH_PE_aligned implies it's an absolute pointer value
159
166
if encoding == DW_EH_PE_aligned {
160
- reader. ptr = round_up ( reader. ptr as usize , mem:: size_of :: < usize > ( ) ) as * const u8 ;
161
- return reader. read :: < usize > ( ) ;
167
+ reader. ptr = round_up ( reader. ptr as usize , mem:: size_of :: < usize > ( ) ) ? as * const u8 ;
168
+ return Ok ( reader. read :: < usize > ( ) )
162
169
}
163
170
164
171
let mut result = match encoding & 0x0F {
@@ -171,25 +178,27 @@ unsafe fn read_encoded_pointer(reader: &mut DwarfReader,
171
178
DW_EH_PE_sdata2 => reader. read :: < i16 > ( ) as usize ,
172
179
DW_EH_PE_sdata4 => reader. read :: < i32 > ( ) as usize ,
173
180
DW_EH_PE_sdata8 => reader. read :: < i64 > ( ) as usize ,
174
- _ => panic ! ( ) ,
181
+ _ => return Err ( ( ) ) ,
175
182
} ;
176
183
177
184
result += match encoding & 0x70 {
178
185
DW_EH_PE_absptr => 0 ,
179
186
// relative to address of the encoded value, despite the name
180
187
DW_EH_PE_pcrel => reader. ptr as usize ,
181
188
DW_EH_PE_funcrel => {
182
- assert ! ( context. func_start != 0 ) ;
189
+ if context. func_start == 0 {
190
+ return Err ( ( ) )
191
+ }
183
192
context. func_start
184
193
}
185
194
DW_EH_PE_textrel => ( * context. get_text_start ) ( ) ,
186
195
DW_EH_PE_datarel => ( * context. get_data_start ) ( ) ,
187
- _ => panic ! ( ) ,
196
+ _ => return Err ( ( ) ) ,
188
197
} ;
189
198
190
199
if encoding & DW_EH_PE_indirect != 0 {
191
200
result = * ( result as * const usize ) ;
192
201
}
193
202
194
- result
203
+ Ok ( result)
195
204
}
0 commit comments