@@ -106,47 +106,45 @@ impl LabelGatheringMachine {
106
106
use goblin_v023:: container:: Ctx ;
107
107
use goblin_v023:: elf:: { Header , SectionHeader } ;
108
108
109
- let header = program. pread :: < Header > ( 0 ) . map_err ( |_e| Error :: ParseError ) ?;
110
- let container = header. container ( ) . map_err ( |_e| Error :: InvalidElfBits ) ?;
111
- let endianness = header. endianness ( ) . map_err ( |_e| Error :: InvalidElfBits ) ?;
109
+ let header = program. pread :: < Header > ( 0 ) ?;
110
+ let container = header. container ( ) . map_err ( |_e| Error :: ElfBits ) ?;
111
+ let endianness = header. endianness ( ) . map_err ( |_e| Error :: ElfBits ) ?;
112
112
if <Self as CoreMachine >:: REG :: BITS != if container. is_big ( ) { 64 } else { 32 } {
113
- return Err ( Error :: InvalidElfBits ) ;
113
+ return Err ( Error :: ElfBits ) ;
114
114
}
115
115
let ctx = Ctx :: new ( container, endianness) ;
116
116
SectionHeader :: parse (
117
117
program,
118
118
header. e_shoff as usize ,
119
119
header. e_shnum as usize ,
120
120
ctx,
121
- )
122
- . map_err ( |_e| Error :: ParseError ) ?
121
+ ) ?
123
122
. iter ( )
124
123
. map ( elf_adaptor:: SectionHeader :: from_v0)
125
124
. collect ( )
126
125
} else {
127
126
use goblin_v040:: container:: Ctx ;
128
127
use goblin_v040:: elf:: { Header , SectionHeader } ;
129
128
130
- let header = program. pread :: < Header > ( 0 ) . map_err ( |_e| Error :: ParseError ) ?;
131
- let container = header. container ( ) . map_err ( |_e| Error :: InvalidElfBits ) ?;
132
- let endianness = header. endianness ( ) . map_err ( |_e| Error :: InvalidElfBits ) ?;
129
+ let header = program. pread :: < Header > ( 0 ) ?;
130
+ let container = header. container ( ) . map_err ( |_e| Error :: ElfBits ) ?;
131
+ let endianness = header. endianness ( ) . map_err ( |_e| Error :: ElfBits ) ?;
133
132
if <Self as CoreMachine >:: REG :: BITS != if container. is_big ( ) { 64 } else { 32 } {
134
- return Err ( Error :: InvalidElfBits ) ;
133
+ return Err ( Error :: ElfBits ) ;
135
134
}
136
135
let ctx = Ctx :: new ( container, endianness) ;
137
136
SectionHeader :: parse (
138
137
program,
139
138
header. e_shoff as usize ,
140
139
header. e_shnum as usize ,
141
140
ctx,
142
- )
143
- . map_err ( |_e| Error :: ParseError ) ?
141
+ ) ?
144
142
. iter ( )
145
143
. map ( elf_adaptor:: SectionHeader :: from_v1)
146
144
. collect ( )
147
145
} ;
148
146
if section_headers. len ( ) > MAXIMUM_SECTIONS {
149
- return Err ( Error :: LimitReached ) ;
147
+ return Err ( Error :: AotLimitReachedMaximumSections ) ;
150
148
}
151
149
let mut sections: Vec < ( u64 , u64 ) > = section_headers
152
150
. iter ( )
@@ -164,14 +162,14 @@ impl LabelGatheringMachine {
164
162
. collect ( ) ;
165
163
// Test there's no empty section
166
164
if sections. iter ( ) . any ( |( s, e) | s >= e) {
167
- return Err ( Error :: OutOfBound ) ;
165
+ return Err ( Error :: AotSectionIsEmpty ) ;
168
166
}
169
167
// Test no section overlaps with one another. We first sort section
170
168
// list by start, then we test if each end is equal or less than
171
169
// the next start.
172
170
sections. sort_by_key ( |section| section. 0 ) ;
173
171
if sections. windows ( 2 ) . any ( |w| w[ 0 ] . 1 > w[ 1 ] . 0 ) {
174
- return Err ( Error :: OutOfBound ) ;
172
+ return Err ( Error :: AotSectionOverlaps ) ;
175
173
}
176
174
// DefaultCoreMachine is only used here for loading ELF binaries
177
175
// into memory.
@@ -195,7 +193,7 @@ impl LabelGatheringMachine {
195
193
fn read_pc ( & self ) -> Result < u64 , Error > {
196
194
match & self . pc {
197
195
Value :: Imm ( pc) => Ok ( * pc) ,
198
- _ => Err ( Error :: Unexpected ) ,
196
+ _ => Err ( Error :: Unexpected ( String :: from ( "Unexpected value type" ) ) ) ,
199
197
}
200
198
}
201
199
@@ -222,7 +220,7 @@ impl LabelGatheringMachine {
222
220
}
223
221
}
224
222
if self . labels . len ( ) > MAXIMUM_LABELS {
225
- return Err ( Error :: LimitReached ) ;
223
+ return Err ( Error :: AotLimitReachedMaximumLabels ) ;
226
224
}
227
225
self . pc = Value :: from_u64 ( next_pc) ;
228
226
}
@@ -249,7 +247,7 @@ impl LabelGatheringMachine {
249
247
// allow us to signal correct error and revert back
250
248
// to assembly VM for those quirky programs.
251
249
if !start_of_basic_block {
252
- return Err ( Error :: OutOfBound ) ;
250
+ return Err ( Error :: AotOutOfBoundDueToNotStartOfBasicBlock ) ;
253
251
}
254
252
let mut dummy_end = pc + 2 ;
255
253
while dummy_end < section_end && self . memory . execute_load16 ( dummy_end) ? == 0
@@ -260,7 +258,7 @@ impl LabelGatheringMachine {
260
258
// sections won't overlap with each other as well.
261
259
self . dummy_sections . insert ( pc, dummy_end) ;
262
260
if self . dummy_sections . len ( ) > MAXIMUM_DUMMY_SECTIONS {
263
- return Err ( Error :: LimitReached ) ;
261
+ return Err ( Error :: AotLimitReachedMaximumDummySections ) ;
264
262
}
265
263
self . pc = Value :: from_u64 ( dummy_end) ;
266
264
}
@@ -270,7 +268,7 @@ impl LabelGatheringMachine {
270
268
// A section must end a basic block, otherwise we would run into
271
269
// out of bound error;
272
270
if !start_of_basic_block {
273
- return Err ( Error :: OutOfBound ) ;
271
+ return Err ( Error :: AotOutOfBoundDueToNotStartOfBasicBlock ) ;
274
272
}
275
273
debug_assert ! ( !self . labels. contains( & section_end) ) ;
276
274
}
@@ -478,7 +476,7 @@ impl AotCompilingMachine {
478
476
fn read_pc ( & self ) -> Result < u64 , Error > {
479
477
match & self . pc {
480
478
Value :: Imm ( pc) => Ok ( * pc) ,
481
- _ => Err ( Error :: Unexpected ) ,
479
+ _ => Err ( Error :: Unexpected ( String :: from ( "Unexpected value type" ) ) ) ,
482
480
}
483
481
}
484
482
@@ -525,7 +523,7 @@ impl AotCompilingMachine {
525
523
let pc = self . read_pc ( ) ?;
526
524
// Emit succeeding PC write only
527
525
if pc >= RISCV_MAX_MEMORY as u64 {
528
- return Err ( Error :: OutOfBound ) ;
526
+ return Err ( Error :: MemOutOfBound ) ;
529
527
}
530
528
self . emitter . emit ( & Write :: Pc {
531
529
value : Value :: Imm ( pc | ADDRESS_WRITE_ONLY_FLAG ) ,
@@ -619,7 +617,7 @@ impl AotCompilingMachine {
619
617
620
618
fn optimize_pc ( & self , pc : u64 ) -> Result < u64 , Error > {
621
619
if pc >= RISCV_MAX_MEMORY as u64 {
622
- return Err ( Error :: OutOfBound ) ;
620
+ return Err ( Error :: MemOutOfBound ) ;
623
621
}
624
622
if pc < MAXIMUM_ENCODED_ADDRESS {
625
623
if let Some ( label) = self . addresses_to_labels . get ( & pc) {
0 commit comments