@@ -21,15 +21,15 @@ use derive_more::Display;
21
21
pub enum MbiLoadError {
22
22
/// The address is invalid. Make sure that the address is 8-byte aligned,
23
23
/// according to the spec.
24
- #[ display( "The address is invalid" ) ]
24
+ #[ display( fmt = "The address is invalid" ) ]
25
25
IllegalAddress ,
26
26
/// The total size of the multiboot2 information structure must be not zero
27
27
/// and a multiple of 8.
28
- #[ display( "The size of the MBI is unexpected" ) ]
28
+ #[ display( fmt = "The size of the MBI is unexpected" ) ]
29
29
IllegalTotalSize ( u32 ) ,
30
30
/// Missing end tag. Each multiboot2 boot information requires to have an
31
31
/// end tag.
32
- #[ display( "There is no end tag" ) ]
32
+ #[ display( fmt = "There is no end tag" ) ]
33
33
NoEndTag ,
34
34
}
35
35
@@ -38,7 +38,7 @@ impl core::error::Error for MbiLoadError {}
38
38
39
39
/// The basic header of a [`BootInformation`] as sized Rust type.
40
40
#[ derive( Copy , Clone , Debug , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
41
- #[ repr( C ) ]
41
+ #[ repr( C , align ( 8 ) ) ]
42
42
pub struct BootInformationHeader {
43
43
// size is multiple of 8
44
44
total_size : u32 ,
@@ -68,7 +68,7 @@ impl AsBytes for BootInformationHeader {}
68
68
/// This type holds the whole data of the MBI. This helps to better satisfy miri
69
69
/// when it checks for memory issues.
70
70
#[ derive( ptr_meta:: Pointee ) ]
71
- #[ repr( C ) ]
71
+ #[ repr( C , align ( 8 ) ) ]
72
72
struct BootInformationInner {
73
73
header : BootInformationHeader ,
74
74
tags : [ u8 ] ,
@@ -221,6 +221,8 @@ impl<'a> BootInformation<'a> {
221
221
/// Otherwise, if the [`TagType::EfiBs`] tag is present, this returns `None`
222
222
/// as it is strictly recommended to get the memory map from the `uefi`
223
223
/// services.
224
+ ///
225
+ /// [`TagType::EfiBs`]: crate::TagType::EfiBs
224
226
#[ must_use]
225
227
pub fn efi_memory_map_tag ( & self ) -> Option < & EFIMemoryMapTag > {
226
228
// If the EFIBootServicesNotExited is present, then we should not use
@@ -277,8 +279,8 @@ impl<'a> BootInformation<'a> {
277
279
pub fn elf_sections ( & self ) -> Option < ElfSectionIter > {
278
280
let tag = self . get_tag :: < ElfSectionsTag > ( ) ;
279
281
tag. map ( |t| {
280
- assert ! ( ( t. entry_size * t. shndx) <= t. size) ;
281
- t. sections ( )
282
+ assert ! ( ( t. entry_size( ) * t. shndx( ) ) <= t. size( ) as u32 ) ;
283
+ t. sections_iter ( )
282
284
} )
283
285
}
284
286
@@ -359,7 +361,7 @@ impl<'a> BootInformation<'a> {
359
361
/// special handling is required. This is reflected by code-comments.
360
362
///
361
363
/// ```no_run
362
- /// use multiboot2::{BootInformation, BootInformationHeader, StringError, Tag , TagTrait, TagType, TagTypeId};
364
+ /// use multiboot2::{BootInformation, BootInformationHeader, parse_slice_as_string, StringError, TagHeader , TagTrait, TagType, TagTypeId};
363
365
///
364
366
/// #[repr(C)]
365
367
/// #[derive(multiboot2::Pointee)] // Only needed for DSTs.
@@ -374,17 +376,17 @@ impl<'a> BootInformation<'a> {
374
376
/// impl TagTrait for CustomTag {
375
377
/// const ID: TagType = TagType::Custom(0x1337);
376
378
///
377
- /// fn dst_size(base_tag : &Tag ) -> usize {
379
+ /// fn dst_len(header : &TagHeader ) -> usize {
378
380
/// // The size of the sized portion of the custom tag.
379
381
/// let tag_base_size = 8; // id + size is 8 byte in size
380
- /// assert!(base_tag .size >= 8);
381
- /// base_tag .size as usize - tag_base_size
382
+ /// assert!(header .size >= 8);
383
+ /// header .size as usize - tag_base_size
382
384
/// }
383
385
/// }
384
386
///
385
387
/// impl CustomTag {
386
388
/// fn name(&self) -> Result<&str, StringError> {
387
- /// Tag:: parse_slice_as_string(&self.name)
389
+ /// parse_slice_as_string(&self.name)
388
390
/// }
389
391
/// }
390
392
/// let mbi_ptr = 0xdeadbeef as *const BootInformationHeader;
@@ -395,11 +397,13 @@ impl<'a> BootInformation<'a> {
395
397
/// .unwrap();
396
398
/// assert_eq!(tag.name(), Ok("name"));
397
399
/// ```
400
+ ///
401
+ /// [`TagType`]: crate::TagType
398
402
#[ must_use]
399
403
pub fn get_tag < TagT : TagTrait + ?Sized + ' a > ( & ' a self ) -> Option < & ' a TagT > {
400
404
self . tags ( )
401
- . find ( |tag| tag. typ == TagT :: ID )
402
- . map ( |tag| tag. cast_tag :: < TagT > ( ) )
405
+ . find ( |tag| tag. header ( ) . typ == TagT :: ID )
406
+ . map ( |tag| tag. cast :: < TagT > ( ) )
403
407
}
404
408
405
409
/// Returns an iterator over all tags.
@@ -440,7 +444,7 @@ impl fmt::Debug for BootInformation<'_> {
440
444
if elf_sections_tag_entries_count > ELF_SECTIONS_LIMIT {
441
445
debug. field ( "elf_sections (count)" , & elf_sections_tag_entries_count) ;
442
446
} else {
443
- debug. field ( "elf_sections" , & self . elf_sections ( ) . unwrap_or_default ( ) ) ;
447
+ debug. field ( "elf_sections" , & self . elf_sections ( ) ) ;
444
448
}
445
449
}
446
450
0 commit comments