24
24
use dwarf:: DwarfReader ;
25
25
use core:: mem;
26
26
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 ;
46
46
47
47
#[ derive( Copy , Clone ) ]
48
48
pub struct EHContext {
49
- pub ip : usize , // Current instruction pointer
49
+ pub ip : usize , // Current instruction pointer
50
50
pub func_start : usize , // Address of the current function
51
51
pub text_start : usize , // Address of the code section
52
52
pub data_start : usize , // Address of the data section
53
53
}
54
54
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 > {
57
56
if lsda. is_null ( ) {
58
57
return None ;
59
58
}
@@ -80,7 +79,7 @@ pub unsafe fn find_landing_pad(lsda: *const u8, context: &EHContext)
80
79
let action_table = reader. ptr . offset ( call_site_table_length as isize ) ;
81
80
// Return addresses point 1 byte past the call instruction, which could
82
81
// be in the next IP range.
83
- let ip = context. ip - 1 ;
82
+ let ip = context. ip - 1 ;
84
83
85
84
while reader. ptr < action_table {
86
85
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)
90
89
// Callsite table is sorted by cs_start, so if we've passed the ip, we
91
90
// may stop searching.
92
91
if ip < func_start + cs_start {
93
- break
92
+ break ;
94
93
}
95
94
if ip < func_start + cs_start + cs_len {
96
95
if cs_lpad != 0 {
@@ -114,13 +113,13 @@ fn round_up(unrounded: usize, align: usize) -> usize {
114
113
115
114
unsafe fn read_encoded_pointer ( reader : & mut DwarfReader ,
116
115
context : & EHContext ,
117
- encoding : u8 ) -> usize {
116
+ encoding : u8 )
117
+ -> usize {
118
118
assert ! ( encoding != DW_EH_PE_omit ) ;
119
119
120
120
// DW_EH_PE_aligned implies it's an absolute pointer value
121
121
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 ;
124
123
return reader. read :: < usize > ( ) ;
125
124
}
126
125
@@ -134,20 +133,26 @@ unsafe fn read_encoded_pointer(reader: &mut DwarfReader,
134
133
DW_EH_PE_sdata2 => reader. read :: < i16 > ( ) as usize ,
135
134
DW_EH_PE_sdata4 => reader. read :: < i32 > ( ) as usize ,
136
135
DW_EH_PE_sdata8 => reader. read :: < i64 > ( ) as usize ,
137
- _ => panic ! ( )
136
+ _ => panic ! ( ) ,
138
137
} ;
139
138
140
139
result += match encoding & 0x70 {
141
140
DW_EH_PE_absptr => 0 ,
142
141
// relative to address of the encoded value, despite the name
143
142
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 ! ( ) ,
151
156
} ;
152
157
153
158
if encoding & DW_EH_PE_indirect != 0 {
0 commit comments