Skip to content

Commit 00bbc27

Browse files
committedJun 5, 2016
run rustfmt on libpanic_unwind folder
1 parent 8cbffc5 commit 00bbc27

File tree

7 files changed

+155
-190
lines changed

7 files changed

+155
-190
lines changed
 

‎src/libpanic_unwind/dwarf/eh.rs

+40-35
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,35 @@
2424
use dwarf::DwarfReader;
2525
use core::mem;
2626

27-
pub const DW_EH_PE_omit : u8 = 0xFF;
28-
pub const DW_EH_PE_absptr : u8 = 0x00;
29-
30-
pub const DW_EH_PE_uleb128 : u8 = 0x01;
31-
pub const DW_EH_PE_udata2 : u8 = 0x02;
32-
pub const DW_EH_PE_udata4 : u8 = 0x03;
33-
pub const DW_EH_PE_udata8 : u8 = 0x04;
34-
pub const DW_EH_PE_sleb128 : u8 = 0x09;
35-
pub const DW_EH_PE_sdata2 : u8 = 0x0A;
36-
pub const DW_EH_PE_sdata4 : u8 = 0x0B;
37-
pub const DW_EH_PE_sdata8 : u8 = 0x0C;
38-
39-
pub const DW_EH_PE_pcrel : u8 = 0x10;
40-
pub const DW_EH_PE_textrel : u8 = 0x20;
41-
pub const DW_EH_PE_datarel : u8 = 0x30;
42-
pub const DW_EH_PE_funcrel : u8 = 0x40;
43-
pub const DW_EH_PE_aligned : u8 = 0x50;
44-
45-
pub const DW_EH_PE_indirect : u8 = 0x80;
27+
pub const DW_EH_PE_omit: u8 = 0xFF;
28+
pub const DW_EH_PE_absptr: u8 = 0x00;
29+
30+
pub const DW_EH_PE_uleb128: u8 = 0x01;
31+
pub const DW_EH_PE_udata2: u8 = 0x02;
32+
pub const DW_EH_PE_udata4: u8 = 0x03;
33+
pub const DW_EH_PE_udata8: u8 = 0x04;
34+
pub const DW_EH_PE_sleb128: u8 = 0x09;
35+
pub const DW_EH_PE_sdata2: u8 = 0x0A;
36+
pub const DW_EH_PE_sdata4: u8 = 0x0B;
37+
pub const DW_EH_PE_sdata8: u8 = 0x0C;
38+
39+
pub const DW_EH_PE_pcrel: u8 = 0x10;
40+
pub const DW_EH_PE_textrel: u8 = 0x20;
41+
pub const DW_EH_PE_datarel: u8 = 0x30;
42+
pub const DW_EH_PE_funcrel: u8 = 0x40;
43+
pub const DW_EH_PE_aligned: u8 = 0x50;
44+
45+
pub const DW_EH_PE_indirect: u8 = 0x80;
4646

4747
#[derive(Copy, Clone)]
4848
pub struct EHContext {
49-
pub ip: usize, // Current instruction pointer
49+
pub ip: usize, // Current instruction pointer
5050
pub func_start: usize, // Address of the current function
5151
pub text_start: usize, // Address of the code section
5252
pub data_start: usize, // Address of the data section
5353
}
5454

55-
pub unsafe fn find_landing_pad(lsda: *const u8, context: &EHContext)
56-
-> Option<usize> {
55+
pub unsafe fn find_landing_pad(lsda: *const u8, context: &EHContext) -> Option<usize> {
5756
if lsda.is_null() {
5857
return None;
5958
}
@@ -80,7 +79,7 @@ pub unsafe fn find_landing_pad(lsda: *const u8, context: &EHContext)
8079
let action_table = reader.ptr.offset(call_site_table_length as isize);
8180
// Return addresses point 1 byte past the call instruction, which could
8281
// be in the next IP range.
83-
let ip = context.ip-1;
82+
let ip = context.ip - 1;
8483

8584
while reader.ptr < action_table {
8685
let cs_start = read_encoded_pointer(&mut reader, context, call_site_encoding);
@@ -90,7 +89,7 @@ pub unsafe fn find_landing_pad(lsda: *const u8, context: &EHContext)
9089
// Callsite table is sorted by cs_start, so if we've passed the ip, we
9190
// may stop searching.
9291
if ip < func_start + cs_start {
93-
break
92+
break;
9493
}
9594
if ip < func_start + cs_start + cs_len {
9695
if cs_lpad != 0 {
@@ -114,13 +113,13 @@ fn round_up(unrounded: usize, align: usize) -> usize {
114113

115114
unsafe fn read_encoded_pointer(reader: &mut DwarfReader,
116115
context: &EHContext,
117-
encoding: u8) -> usize {
116+
encoding: u8)
117+
-> usize {
118118
assert!(encoding != DW_EH_PE_omit);
119119

120120
// DW_EH_PE_aligned implies it's an absolute pointer value
121121
if encoding == DW_EH_PE_aligned {
122-
reader.ptr = round_up(reader.ptr as usize,
123-
mem::size_of::<usize>()) as *const u8;
122+
reader.ptr = round_up(reader.ptr as usize, mem::size_of::<usize>()) as *const u8;
124123
return reader.read::<usize>();
125124
}
126125

@@ -134,20 +133,26 @@ unsafe fn read_encoded_pointer(reader: &mut DwarfReader,
134133
DW_EH_PE_sdata2 => reader.read::<i16>() as usize,
135134
DW_EH_PE_sdata4 => reader.read::<i32>() as usize,
136135
DW_EH_PE_sdata8 => reader.read::<i64>() as usize,
137-
_ => panic!()
136+
_ => panic!(),
138137
};
139138

140139
result += match encoding & 0x70 {
141140
DW_EH_PE_absptr => 0,
142141
// relative to address of the encoded value, despite the name
143142
DW_EH_PE_pcrel => reader.ptr as usize,
144-
DW_EH_PE_textrel => { assert!(context.text_start != 0);
145-
context.text_start },
146-
DW_EH_PE_datarel => { assert!(context.data_start != 0);
147-
context.data_start },
148-
DW_EH_PE_funcrel => { assert!(context.func_start != 0);
149-
context.func_start },
150-
_ => panic!()
143+
DW_EH_PE_textrel => {
144+
assert!(context.text_start != 0);
145+
context.text_start
146+
}
147+
DW_EH_PE_datarel => {
148+
assert!(context.data_start != 0);
149+
context.data_start
150+
}
151+
DW_EH_PE_funcrel => {
152+
assert!(context.func_start != 0);
153+
context.func_start
154+
}
155+
_ => panic!(),
151156
};
152157

153158
if encoding & DW_EH_PE_indirect != 0 {

‎src/libpanic_unwind/dwarf/mod.rs

+11-19
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,22 @@ pub mod eh;
2121
use core::mem;
2222

2323
pub struct DwarfReader {
24-
pub ptr : *const u8
24+
pub ptr: *const u8,
2525
}
2626

2727
#[repr(C,packed)]
2828
struct Unaligned<T>(T);
2929

3030
impl DwarfReader {
31-
32-
pub fn new(ptr : *const u8) -> DwarfReader {
33-
DwarfReader {
34-
ptr : ptr
35-
}
31+
pub fn new(ptr: *const u8) -> DwarfReader {
32+
DwarfReader { ptr: ptr }
3633
}
3734

3835
// DWARF streams are packed, so e.g. a u32 would not necessarily be aligned
3936
// on a 4-byte boundary. This may cause problems on platforms with strict
4037
// alignment requirements. By wrapping data in a "packed" struct, we are
4138
// telling the backend to generate "misalignment-safe" code.
42-
pub unsafe fn read<T:Copy>(&mut self) -> T {
39+
pub unsafe fn read<T: Copy>(&mut self) -> T {
4340
let Unaligned(result) = *(self.ptr as *const Unaligned<T>);
4441
self.ptr = self.ptr.offset(mem::size_of::<T>() as isize);
4542
result
@@ -48,9 +45,9 @@ impl DwarfReader {
4845
// ULEB128 and SLEB128 encodings are defined in Section 7.6 - "Variable
4946
// Length Data".
5047
pub unsafe fn read_uleb128(&mut self) -> u64 {
51-
let mut shift : usize = 0;
52-
let mut result : u64 = 0;
53-
let mut byte : u8;
48+
let mut shift: usize = 0;
49+
let mut result: u64 = 0;
50+
let mut byte: u8;
5451
loop {
5552
byte = self.read::<u8>();
5653
result |= ((byte & 0x7F) as u64) << shift;
@@ -63,9 +60,9 @@ impl DwarfReader {
6360
}
6461

6562
pub unsafe fn read_sleb128(&mut self) -> i64 {
66-
let mut shift : usize = 0;
67-
let mut result : u64 = 0;
68-
let mut byte : u8;
63+
let mut shift: usize = 0;
64+
let mut result: u64 = 0;
65+
let mut byte: u8;
6966
loop {
7067
byte = self.read::<u8>();
7168
result |= ((byte & 0x7F) as u64) << shift;
@@ -84,12 +81,7 @@ impl DwarfReader {
8481

8582
#[test]
8683
fn dwarf_reader() {
87-
let encoded: &[u8] = &[1,
88-
2, 3,
89-
4, 5, 6, 7,
90-
0xE5, 0x8E, 0x26,
91-
0x9B, 0xF1, 0x59,
92-
0xFF, 0xFF];
84+
let encoded: &[u8] = &[1, 2, 3, 4, 5, 6, 7, 0xE5, 0x8E, 0x26, 0x9B, 0xF1, 0x59, 0xFF, 0xFF];
9385

9486
let mut reader = DwarfReader::new(encoded.as_ptr());
9587

‎src/libpanic_unwind/gcc.rs

+70-96
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ pub unsafe fn panic(data: Box<Any + Send>) -> u32 {
7979
let exception_param = Box::into_raw(exception) as *mut uw::_Unwind_Exception;
8080
return uw::_Unwind_RaiseException(exception_param) as u32;
8181

82-
extern fn exception_cleanup(_unwind_code: uw::_Unwind_Reason_Code,
83-
exception: *mut uw::_Unwind_Exception) {
82+
extern "C" fn exception_cleanup(_unwind_code: uw::_Unwind_Reason_Code,
83+
exception: *mut uw::_Unwind_Exception) {
8484
unsafe {
8585
let _: Box<Exception> = Box::from_raw(exception as *mut Exception);
8686
}
@@ -130,50 +130,41 @@ pub mod eabi {
130130
use unwind as uw;
131131
use libc::c_int;
132132

133-
extern {
133+
extern "C" {
134134
fn __gcc_personality_v0(version: c_int,
135135
actions: uw::_Unwind_Action,
136136
exception_class: uw::_Unwind_Exception_Class,
137137
ue_header: *mut uw::_Unwind_Exception,
138138
context: *mut uw::_Unwind_Context)
139-
-> uw::_Unwind_Reason_Code;
139+
-> uw::_Unwind_Reason_Code;
140140
}
141141

142142
#[lang = "eh_personality"]
143143
#[no_mangle]
144-
extern fn rust_eh_personality(
145-
version: c_int,
146-
actions: uw::_Unwind_Action,
147-
exception_class: uw::_Unwind_Exception_Class,
148-
ue_header: *mut uw::_Unwind_Exception,
149-
context: *mut uw::_Unwind_Context
150-
) -> uw::_Unwind_Reason_Code
151-
{
152-
unsafe {
153-
__gcc_personality_v0(version, actions, exception_class, ue_header,
154-
context)
155-
}
144+
extern "C" fn rust_eh_personality(version: c_int,
145+
actions: uw::_Unwind_Action,
146+
exception_class: uw::_Unwind_Exception_Class,
147+
ue_header: *mut uw::_Unwind_Exception,
148+
context: *mut uw::_Unwind_Context)
149+
-> uw::_Unwind_Reason_Code {
150+
unsafe { __gcc_personality_v0(version, actions, exception_class, ue_header, context) }
156151
}
157152

158153
#[lang = "eh_personality_catch"]
159154
#[no_mangle]
160-
pub extern fn rust_eh_personality_catch(
161-
version: c_int,
162-
actions: uw::_Unwind_Action,
163-
exception_class: uw::_Unwind_Exception_Class,
164-
ue_header: *mut uw::_Unwind_Exception,
165-
context: *mut uw::_Unwind_Context
166-
) -> uw::_Unwind_Reason_Code
167-
{
155+
pub extern "C" fn rust_eh_personality_catch(version: c_int,
156+
actions: uw::_Unwind_Action,
157+
exception_class: uw::_Unwind_Exception_Class,
158+
ue_header: *mut uw::_Unwind_Exception,
159+
context: *mut uw::_Unwind_Context)
160+
-> uw::_Unwind_Reason_Code {
168161

169-
if (actions as c_int & uw::_UA_SEARCH_PHASE as c_int) != 0 { // search phase
162+
if (actions as c_int & uw::_UA_SEARCH_PHASE as c_int) != 0 {
163+
// search phase
170164
uw::_URC_HANDLER_FOUND // catch!
171-
}
172-
else { // cleanup phase
173-
unsafe {
174-
__gcc_personality_v0(version, actions, exception_class, ue_header,
175-
context)
176-
}
165+
} else {
166+
// cleanup phase
167+
unsafe { __gcc_personality_v0(version, actions, exception_class, ue_header, context) }
177168
}
178169
}
179170
}
@@ -186,49 +177,40 @@ pub mod eabi {
186177
use unwind as uw;
187178
use libc::c_int;
188179

189-
extern {
180+
extern "C" {
190181
fn __gcc_personality_sj0(version: c_int,
191-
actions: uw::_Unwind_Action,
192-
exception_class: uw::_Unwind_Exception_Class,
193-
ue_header: *mut uw::_Unwind_Exception,
194-
context: *mut uw::_Unwind_Context)
195-
-> uw::_Unwind_Reason_Code;
182+
actions: uw::_Unwind_Action,
183+
exception_class: uw::_Unwind_Exception_Class,
184+
ue_header: *mut uw::_Unwind_Exception,
185+
context: *mut uw::_Unwind_Context)
186+
-> uw::_Unwind_Reason_Code;
196187
}
197188

198189
#[lang = "eh_personality"]
199190
#[no_mangle]
200-
pub extern fn rust_eh_personality(
201-
version: c_int,
202-
actions: uw::_Unwind_Action,
203-
exception_class: uw::_Unwind_Exception_Class,
204-
ue_header: *mut uw::_Unwind_Exception,
205-
context: *mut uw::_Unwind_Context
206-
) -> uw::_Unwind_Reason_Code
207-
{
208-
unsafe {
209-
__gcc_personality_sj0(version, actions, exception_class, ue_header,
210-
context)
211-
}
191+
pub extern "C" fn rust_eh_personality(version: c_int,
192+
actions: uw::_Unwind_Action,
193+
exception_class: uw::_Unwind_Exception_Class,
194+
ue_header: *mut uw::_Unwind_Exception,
195+
context: *mut uw::_Unwind_Context)
196+
-> uw::_Unwind_Reason_Code {
197+
unsafe { __gcc_personality_sj0(version, actions, exception_class, ue_header, context) }
212198
}
213199

214200
#[lang = "eh_personality_catch"]
215201
#[no_mangle]
216-
pub extern fn rust_eh_personality_catch(
217-
version: c_int,
218-
actions: uw::_Unwind_Action,
219-
exception_class: uw::_Unwind_Exception_Class,
220-
ue_header: *mut uw::_Unwind_Exception,
221-
context: *mut uw::_Unwind_Context
222-
) -> uw::_Unwind_Reason_Code
223-
{
224-
if (actions as c_int & uw::_UA_SEARCH_PHASE as c_int) != 0 { // search phase
202+
pub extern "C" fn rust_eh_personality_catch(version: c_int,
203+
actions: uw::_Unwind_Action,
204+
exception_class: uw::_Unwind_Exception_Class,
205+
ue_header: *mut uw::_Unwind_Exception,
206+
context: *mut uw::_Unwind_Context)
207+
-> uw::_Unwind_Reason_Code {
208+
if (actions as c_int & uw::_UA_SEARCH_PHASE as c_int) != 0 {
209+
// search phase
225210
uw::_URC_HANDLER_FOUND // catch!
226-
}
227-
else { // cleanup phase
228-
unsafe {
229-
__gcc_personality_sj0(version, actions, exception_class, ue_header,
230-
context)
231-
}
211+
} else {
212+
// cleanup phase
213+
unsafe { __gcc_personality_sj0(version, actions, exception_class, ue_header, context) }
232214
}
233215
}
234216
}
@@ -241,47 +223,40 @@ pub mod eabi {
241223
use unwind as uw;
242224
use libc::c_int;
243225

244-
extern {
226+
extern "C" {
245227
fn __gcc_personality_v0(state: uw::_Unwind_State,
246228
ue_header: *mut uw::_Unwind_Exception,
247229
context: *mut uw::_Unwind_Context)
248-
-> uw::_Unwind_Reason_Code;
230+
-> uw::_Unwind_Reason_Code;
249231
}
250232

251233
#[lang = "eh_personality"]
252234
#[no_mangle]
253-
extern fn rust_eh_personality(
254-
state: uw::_Unwind_State,
255-
ue_header: *mut uw::_Unwind_Exception,
256-
context: *mut uw::_Unwind_Context
257-
) -> uw::_Unwind_Reason_Code
258-
{
259-
unsafe {
260-
__gcc_personality_v0(state, ue_header, context)
261-
}
235+
extern "C" fn rust_eh_personality(state: uw::_Unwind_State,
236+
ue_header: *mut uw::_Unwind_Exception,
237+
context: *mut uw::_Unwind_Context)
238+
-> uw::_Unwind_Reason_Code {
239+
unsafe { __gcc_personality_v0(state, ue_header, context) }
262240
}
263241

264242
#[lang = "eh_personality_catch"]
265243
#[no_mangle]
266-
pub extern fn rust_eh_personality_catch(
267-
state: uw::_Unwind_State,
268-
ue_header: *mut uw::_Unwind_Exception,
269-
context: *mut uw::_Unwind_Context
270-
) -> uw::_Unwind_Reason_Code
271-
{
244+
pub extern "C" fn rust_eh_personality_catch(state: uw::_Unwind_State,
245+
ue_header: *mut uw::_Unwind_Exception,
246+
context: *mut uw::_Unwind_Context)
247+
-> uw::_Unwind_Reason_Code {
272248
// Backtraces on ARM will call the personality routine with
273249
// state == _US_VIRTUAL_UNWIND_FRAME | _US_FORCE_UNWIND. In those cases
274250
// we want to continue unwinding the stack, otherwise all our backtraces
275251
// would end at __rust_try.
276-
if (state as c_int & uw::_US_ACTION_MASK as c_int)
277-
== uw::_US_VIRTUAL_UNWIND_FRAME as c_int
278-
&& (state as c_int & uw::_US_FORCE_UNWIND as c_int) == 0 { // search phase
252+
if (state as c_int & uw::_US_ACTION_MASK as c_int) ==
253+
uw::_US_VIRTUAL_UNWIND_FRAME as c_int &&
254+
(state as c_int & uw::_US_FORCE_UNWIND as c_int) == 0 {
255+
// search phase
279256
uw::_URC_HANDLER_FOUND // catch!
280-
}
281-
else { // cleanup phase
282-
unsafe {
283-
__gcc_personality_v0(state, ue_header, context)
284-
}
257+
} else {
258+
// cleanup phase
259+
unsafe { __gcc_personality_v0(state, ue_header, context) }
285260
}
286261
}
287262
}
@@ -290,7 +265,7 @@ pub mod eabi {
290265
#[cfg(all(target_os="windows", target_arch = "x86", target_env="gnu"))]
291266
#[lang = "eh_unwind_resume"]
292267
#[unwind]
293-
unsafe extern fn rust_eh_unwind_resume(panic_ctx: *mut u8) -> ! {
268+
unsafe extern "C" fn rust_eh_unwind_resume(panic_ctx: *mut u8) -> ! {
294269
uw::_Unwind_Resume(panic_ctx as *mut uw::_Unwind_Exception);
295270
}
296271

@@ -314,22 +289,21 @@ unsafe extern fn rust_eh_unwind_resume(panic_ctx: *mut u8) -> ! {
314289
pub mod eh_frame_registry {
315290
#[link(name = "gcc_eh")]
316291
#[cfg(not(cargobuild))]
317-
extern {}
292+
extern "C" {}
318293

319-
extern {
294+
extern "C" {
320295
fn __register_frame_info(eh_frame_begin: *const u8, object: *mut u8);
321296
fn __deregister_frame_info(eh_frame_begin: *const u8, object: *mut u8);
322297
}
323298

324299
#[no_mangle]
325-
pub unsafe extern fn rust_eh_register_frames(eh_frame_begin: *const u8,
326-
object: *mut u8) {
300+
pub unsafe extern "C" fn rust_eh_register_frames(eh_frame_begin: *const u8, object: *mut u8) {
327301
__register_frame_info(eh_frame_begin, object);
328302
}
329303

330304
#[no_mangle]
331-
pub unsafe extern fn rust_eh_unregister_frames(eh_frame_begin: *const u8,
332-
object: *mut u8) {
305+
pub unsafe extern "C" fn rust_eh_unregister_frames(eh_frame_begin: *const u8,
306+
object: *mut u8) {
333307
__deregister_frame_info(eh_frame_begin, object);
334308
}
335309
}

‎src/libpanic_unwind/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ mod windows;
8282
// hairy and tightly coupled, for more information see the compiler's
8383
// implementation of this.
8484
#[no_mangle]
85-
pub unsafe extern fn __rust_maybe_catch_panic(f: fn(*mut u8),
86-
data: *mut u8,
87-
data_ptr: *mut usize,
88-
vtable_ptr: *mut usize)
89-
-> u32 {
85+
pub unsafe extern "C" fn __rust_maybe_catch_panic(f: fn(*mut u8),
86+
data: *mut u8,
87+
data_ptr: *mut usize,
88+
vtable_ptr: *mut usize)
89+
-> u32 {
9090
let mut payload = imp::payload();
9191
if intrinsics::try(f, data, &mut payload as *mut _ as *mut _) == 0 {
9292
0
@@ -101,7 +101,7 @@ pub unsafe extern fn __rust_maybe_catch_panic(f: fn(*mut u8),
101101
// Entry point for raising an exception, just delegates to the platform-specific
102102
// implementation.
103103
#[no_mangle]
104-
pub unsafe extern fn __rust_start_panic(data: usize, vtable: usize) -> u32 {
104+
pub unsafe extern "C" fn __rust_start_panic(data: usize, vtable: usize) -> u32 {
105105
imp::panic(mem::transmute(raw::TraitObject {
106106
data: data as *mut (),
107107
vtable: vtable as *mut (),

‎src/libpanic_unwind/seh.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ mod imp {
128128
pub const NAME1: [u8; 7] = [b'.', b'P', b'E', b'A', b'_', b'K', 0];
129129
pub const NAME2: [u8; 7] = [b'.', b'P', b'E', b'A', b'X', 0, 0];
130130

131-
extern {
131+
extern "C" {
132132
pub static __ImageBase: u8;
133133
}
134134

@@ -186,10 +186,7 @@ static mut THROW_INFO: _ThrowInfo = _ThrowInfo {
186186

187187
static mut CATCHABLE_TYPE_ARRAY: _CatchableTypeArray = _CatchableTypeArray {
188188
nCatchableTypes: 2,
189-
arrayOfCatchableTypes: [
190-
ptr!(0),
191-
ptr!(0),
192-
],
189+
arrayOfCatchableTypes: [ptr!(0), ptr!(0)],
193190
};
194191

195192
static mut CATCHABLE_TYPE1: _CatchableType = _CatchableType {
@@ -216,7 +213,7 @@ static mut CATCHABLE_TYPE2: _CatchableType = _CatchableType {
216213
copy_function: ptr!(0),
217214
};
218215

219-
extern {
216+
extern "C" {
220217
// The leading `\x01` byte here is actually a magical signal to LLVM to
221218
// *not* apply any other mangling like prefixing with a `_` character.
222219
//

‎src/libpanic_unwind/seh64_gnu.rs

+20-21
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ use windows as c;
3232
const ETYPE: c::DWORD = 0b1110_u32 << 28;
3333
const MAGIC: c::DWORD = 0x525354; // "RST"
3434

35-
const RUST_PANIC: c::DWORD = ETYPE | (1 << 24) | MAGIC;
35+
const RUST_PANIC: c::DWORD = ETYPE | (1 << 24) | MAGIC;
3636

3737
#[repr(C)]
3838
struct PanicData {
39-
data: Box<Any + Send>
39+
data: Box<Any + Send>,
4040
}
4141

4242
pub unsafe fn panic(data: Box<Any + Send>) -> u32 {
@@ -82,30 +82,29 @@ pub unsafe fn cleanup(ptr: *mut u8) -> Box<Any + Send> {
8282

8383
#[lang = "eh_personality_catch"]
8484
#[cfg(not(test))]
85-
unsafe extern fn rust_eh_personality_catch(
86-
exceptionRecord: *mut c::EXCEPTION_RECORD,
87-
establisherFrame: c::LPVOID,
88-
contextRecord: *mut c::CONTEXT,
89-
dispatcherContext: *mut c::DISPATCHER_CONTEXT
90-
) -> c::EXCEPTION_DISPOSITION
91-
{
92-
rust_eh_personality(exceptionRecord, establisherFrame,
93-
contextRecord, dispatcherContext)
85+
unsafe extern "C" fn rust_eh_personality_catch(exceptionRecord: *mut c::EXCEPTION_RECORD,
86+
establisherFrame: c::LPVOID,
87+
contextRecord: *mut c::CONTEXT,
88+
dispatcherContext: *mut c::DISPATCHER_CONTEXT)
89+
-> c::EXCEPTION_DISPOSITION {
90+
rust_eh_personality(exceptionRecord,
91+
establisherFrame,
92+
contextRecord,
93+
dispatcherContext)
9494
}
9595

9696
#[lang = "eh_personality"]
9797
#[cfg(not(test))]
98-
unsafe extern fn rust_eh_personality(
99-
exceptionRecord: *mut c::EXCEPTION_RECORD,
100-
establisherFrame: c::LPVOID,
101-
contextRecord: *mut c::CONTEXT,
102-
dispatcherContext: *mut c::DISPATCHER_CONTEXT
103-
) -> c::EXCEPTION_DISPOSITION
104-
{
98+
unsafe extern "C" fn rust_eh_personality(exceptionRecord: *mut c::EXCEPTION_RECORD,
99+
establisherFrame: c::LPVOID,
100+
contextRecord: *mut c::CONTEXT,
101+
dispatcherContext: *mut c::DISPATCHER_CONTEXT)
102+
-> c::EXCEPTION_DISPOSITION {
105103
let er = &*exceptionRecord;
106104
let dc = &*dispatcherContext;
107105

108-
if er.ExceptionFlags & c::EXCEPTION_UNWIND == 0 { // we are in the dispatch phase
106+
if er.ExceptionFlags & c::EXCEPTION_UNWIND == 0 {
107+
// we are in the dispatch phase
109108
if er.ExceptionCode == RUST_PANIC {
110109
if let Some(lpad) = find_landing_pad(dc) {
111110
c::RtlUnwindEx(establisherFrame,
@@ -122,7 +121,7 @@ unsafe extern fn rust_eh_personality(
122121

123122
#[lang = "eh_unwind_resume"]
124123
#[unwind]
125-
unsafe extern fn rust_eh_unwind_resume(panic_ctx: c::LPVOID) -> ! {
124+
unsafe extern "C" fn rust_eh_unwind_resume(panic_ctx: c::LPVOID) -> ! {
126125
let params = [panic_ctx as c::ULONG_PTR];
127126
c::RaiseException(RUST_PANIC,
128127
c::EXCEPTION_NONCONTINUABLE,
@@ -136,7 +135,7 @@ unsafe fn find_landing_pad(dc: &c::DISPATCHER_CONTEXT) -> Option<usize> {
136135
ip: dc.ControlPc as usize,
137136
func_start: dc.ImageBase as usize + (*dc.FunctionEntry).BeginAddress as usize,
138137
text_start: dc.ImageBase as usize,
139-
data_start: 0
138+
data_start: 0,
140139
};
141140
eh::find_landing_pad(dc.HandlerData, &eh_ctx)
142141
}

‎src/libpanic_unwind/windows.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#![allow(dead_code)]
1313
#![cfg(windows)]
1414

15-
use libc::{c_void, c_ulong, c_long, c_ulonglong};
15+
use libc::{c_long, c_ulong, c_ulonglong, c_void};
1616

1717
pub type DWORD = c_ulong;
1818
pub type LONG = c_long;
@@ -25,8 +25,7 @@ pub const EXCEPTION_UNWINDING: DWORD = 0x2; // Unwind is in progress
2525
pub const EXCEPTION_EXIT_UNWIND: DWORD = 0x4; // Exit unwind is in progress
2626
pub const EXCEPTION_TARGET_UNWIND: DWORD = 0x20; // Target unwind in progress
2727
pub const EXCEPTION_COLLIDED_UNWIND: DWORD = 0x40; // Collided exception handler call
28-
pub const EXCEPTION_UNWIND: DWORD = EXCEPTION_UNWINDING |
29-
EXCEPTION_EXIT_UNWIND |
28+
pub const EXCEPTION_UNWIND: DWORD = EXCEPTION_UNWINDING | EXCEPTION_EXIT_UNWIND |
3029
EXCEPTION_TARGET_UNWIND |
3130
EXCEPTION_COLLIDED_UNWIND;
3231

@@ -37,7 +36,7 @@ pub struct EXCEPTION_RECORD {
3736
pub ExceptionRecord: *mut EXCEPTION_RECORD,
3837
pub ExceptionAddress: LPVOID,
3938
pub NumberParameters: DWORD,
40-
pub ExceptionInformation: [LPVOID; EXCEPTION_MAXIMUM_PARAMETERS]
39+
pub ExceptionInformation: [LPVOID; EXCEPTION_MAXIMUM_PARAMETERS],
4140
}
4241

4342
#[repr(C)]
@@ -75,7 +74,7 @@ pub enum EXCEPTION_DISPOSITION {
7574
ExceptionContinueExecution,
7675
ExceptionContinueSearch,
7776
ExceptionNestedException,
78-
ExceptionCollidedUnwind
77+
ExceptionCollidedUnwind,
7978
}
8079
pub use self::EXCEPTION_DISPOSITION::*;
8180

@@ -93,6 +92,5 @@ extern "system" {
9392
OriginalContext: *const CONTEXT,
9493
HistoryTable: *const UNWIND_HISTORY_TABLE);
9594
#[unwind]
96-
pub fn _CxxThrowException(pExceptionObject: *mut c_void,
97-
pThrowInfo: *mut u8);
95+
pub fn _CxxThrowException(pExceptionObject: *mut c_void, pThrowInfo: *mut u8);
9896
}

0 commit comments

Comments
 (0)
Please sign in to comment.