1
1
use crate :: tag_type:: Tag ;
2
2
use crate :: TagType ;
3
3
use core:: fmt:: { Debug , Formatter } ;
4
+ use std:: str:: Utf8Error ;
5
+ use derive_more:: Display ;
4
6
5
7
/// This tag contains section header table from an ELF kernel.
6
8
///
@@ -178,7 +180,10 @@ impl ElfSection {
178
180
11 => ElfSectionType :: DynamicLoaderSymbolTable ,
179
181
0x6000_0000 ..=0x6FFF_FFFF => ElfSectionType :: EnvironmentSpecific ,
180
182
0x7000_0000 ..=0x7FFF_FFFF => ElfSectionType :: ProcessorSpecific ,
181
- _ => panic ! ( ) ,
183
+ e => {
184
+ log:: error!( "Unknown section type {e:x}. Treating as ElfSectionType::Unused" ) ;
185
+ ElfSectionType :: Unused
186
+ }
182
187
}
183
188
}
184
189
@@ -188,7 +193,7 @@ impl ElfSection {
188
193
}
189
194
190
195
/// Read the name of the section.
191
- pub fn name ( & self ) -> & str {
196
+ pub fn name ( & self ) -> Result < & str , Utf8Error > {
192
197
use core:: { slice, str} ;
193
198
194
199
let name_ptr = unsafe { self . string_table ( ) . offset ( self . get ( ) . name_index ( ) as isize ) } ;
@@ -202,7 +207,7 @@ impl ElfSection {
202
207
len as usize
203
208
} ;
204
209
205
- str:: from_utf8 ( unsafe { slice:: from_raw_parts ( name_ptr, strlen) } ) . unwrap ( )
210
+ str:: from_utf8 ( unsafe { slice:: from_raw_parts ( name_ptr, strlen) } )
206
211
}
207
212
208
213
/// Get the physical start address of the section.
@@ -246,15 +251,15 @@ impl ElfSection {
246
251
match self . entry_size {
247
252
40 => unsafe { & * ( self . inner as * const ElfSectionInner32 ) } ,
248
253
64 => unsafe { & * ( self . inner as * const ElfSectionInner64 ) } ,
249
- _ => panic ! ( ) ,
254
+ s => panic ! ( "Unexpected entry size: {s}" ) ,
250
255
}
251
256
}
252
257
253
258
unsafe fn string_table ( & self ) -> * const u8 {
254
259
let addr = match self . entry_size {
255
260
40 => ( * ( self . string_section as * const ElfSectionInner32 ) ) . addr as usize ,
256
261
64 => ( * ( self . string_section as * const ElfSectionInner64 ) ) . addr as usize ,
257
- _ => panic ! ( ) ,
262
+ s => panic ! ( "Unexpected entry size: {s}" ) ,
258
263
} ;
259
264
( addr + self . offset ) as * const _
260
265
}
0 commit comments