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

Lines changed: 40 additions & 35 deletions
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

Lines changed: 11 additions & 19 deletions
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

0 commit comments

Comments
 (0)