pub struct Multiboot2Header<'a>(/* private fields */);Expand description
Wrapper type around a pointer to the Multiboot2 header.
The Multiboot2 header is the Multiboot2BasicHeader followed
by all tags (see crate::tags::HeaderTagType).
Use this if you get a pointer to the header and just want
to parse it. If you want to construct the type by yourself,
please look at HeaderBuilder (requires the builder feature).
Implementations§
Source§impl<'a> Multiboot2Header<'a>
impl<'a> Multiboot2Header<'a>
Sourcepub unsafe fn load(ptr: *const Multiboot2BasicHeader) -> Result<Self, LoadError>
pub unsafe fn load(ptr: *const Multiboot2BasicHeader) -> Result<Self, LoadError>
Loads the Multiboot2Header from a pointer.
If the header is invalid, it returns a LoadError.
This may be because:
ptris a null pointerptris not 8-byte aligned- the reported total size is invalid
- the magic value of the header is not present
- the checksum field is invalid
- the tag sequence is incomplete or malformed
- the mandatory end tag is missing
§Safety
ptrmust be valid for reading the complete reported header size. Otherwise, this function might cause invalid machine state or crash your binary.- The memory at
ptrmust not be modified after callingloador the program may observe unsynchronized mutation.
Examples found in repository?
9fn main() {
10 // We create a Multiboot2 header during runtime here. A more practical
11 // example, however, would be that you parse the header from kernel binary
12 // at runtime.
13 let mb2_hdr_bytes = Builder::new(HeaderTagISA::I386)
14 .relocatable_tag(RelocatableHeaderTag::new(
15 HeaderTagFlag::Required,
16 0x1337,
17 0xdeadbeef,
18 4096,
19 RelocatableHeaderTagPreference::None,
20 ))
21 .information_request_tag(InformationRequestHeaderTag::new(
22 HeaderTagFlag::Required,
23 &[
24 MbiTagType::Cmdline.into(),
25 MbiTagType::BootLoaderName.into(),
26 ],
27 ))
28 .build();
29
30 // Cast bytes in vector to Multiboot2 information structure
31 let ptr = mb2_hdr_bytes.as_bytes().as_ptr();
32 let mb2_hdr = unsafe { Multiboot2Header::load(ptr.cast()) };
33 let mb2_hdr = mb2_hdr.unwrap();
34 println!("{mb2_hdr:#?}");
35}Sourcepub fn find_header(buffer: &[u8]) -> Result<(Self, usize), LoadError>
pub fn find_header(buffer: &[u8]) -> Result<(Self, usize), LoadError>
Tries finding a Multiboot2 header in a given slice of binary data.
Performs basic checks, such as length checks and a checksum match.
The Multiboot2 header must be contained completely within the first
HEADER_SEARCH_LIMIT bytes of the OS image, and must be
64-bit aligned.
On success, it returns the parsed header and an index into the original buffer pointing to where the header starts.
§Parameter
buffer: 64-bit aligned buffer describing the firstHEADER_SEARCH_LIMITbytes of a potential Multiboot2 kernel image.
Sourcepub const fn verify_checksum(&self) -> Result<(), (u32, u32)>
pub const fn verify_checksum(&self) -> Result<(), (u32, u32)>
Wrapper around Multiboot2BasicHeader::verify_checksum.
Sourcepub const fn header_magic(&self) -> u32
pub const fn header_magic(&self) -> u32
Wrapper around Multiboot2BasicHeader::header_magic.
Sourcepub const fn arch(&self) -> HeaderTagISA
pub const fn arch(&self) -> HeaderTagISA
Wrapper around Multiboot2BasicHeader::arch.
Sourcepub const fn length(&self) -> u32
pub const fn length(&self) -> u32
Wrapper around Multiboot2BasicHeader::length.
Sourcepub const fn checksum(&self) -> u32
pub const fn checksum(&self) -> u32
Wrapper around Multiboot2BasicHeader::checksum.
Sourcepub const fn calc_checksum(magic: u32, arch: HeaderTagISA, length: u32) -> u32
pub const fn calc_checksum(magic: u32, arch: HeaderTagISA, length: u32) -> u32
Wrapper around Multiboot2BasicHeader::calc_checksum.
Sourcepub fn information_request_tag(&self) -> Option<&InformationRequestHeaderTag>
pub fn information_request_tag(&self) -> Option<&InformationRequestHeaderTag>
Search for the InformationRequestHeaderTag header tag.
Sourcepub fn address_tag(&self) -> Option<&AddressHeaderTag>
pub fn address_tag(&self) -> Option<&AddressHeaderTag>
Search for the AddressHeaderTag header tag.
Sourcepub fn entry_address_tag(&self) -> Option<&EntryAddressHeaderTag>
pub fn entry_address_tag(&self) -> Option<&EntryAddressHeaderTag>
Search for the EntryAddressHeaderTag header tag.
Sourcepub fn entry_address_efi32_tag(&self) -> Option<&EntryEfi32HeaderTag>
pub fn entry_address_efi32_tag(&self) -> Option<&EntryEfi32HeaderTag>
Search for the EntryEfi32HeaderTag header tag.
Sourcepub fn entry_address_efi64_tag(&self) -> Option<&EntryEfi64HeaderTag>
pub fn entry_address_efi64_tag(&self) -> Option<&EntryEfi64HeaderTag>
Search for the EntryEfi64HeaderTag header tag.
Sourcepub fn console_flags_tag(&self) -> Option<&ConsoleHeaderTag>
pub fn console_flags_tag(&self) -> Option<&ConsoleHeaderTag>
Search for the ConsoleHeaderTag header tag.
Sourcepub fn framebuffer_tag(&self) -> Option<&FramebufferHeaderTag>
pub fn framebuffer_tag(&self) -> Option<&FramebufferHeaderTag>
Search for the FramebufferHeaderTag header tag.
Sourcepub fn module_align_tag(&self) -> Option<&ModuleAlignHeaderTag>
pub fn module_align_tag(&self) -> Option<&ModuleAlignHeaderTag>
Search for the ModuleAlignHeaderTag header tag.
Sourcepub fn efi_boot_services_tag(&self) -> Option<&EfiBootServiceHeaderTag>
pub fn efi_boot_services_tag(&self) -> Option<&EfiBootServiceHeaderTag>
Search for the EfiBootServiceHeaderTag header tag.
Sourcepub fn relocatable_tag(&self) -> Option<&RelocatableHeaderTag>
pub fn relocatable_tag(&self) -> Option<&RelocatableHeaderTag>
Search for the RelocatableHeaderTag header tag.
Trait Implementations§
Source§impl Debug for Multiboot2Header<'_>
impl Debug for Multiboot2Header<'_>
impl<'a> Eq for Multiboot2Header<'a>
Source§impl<'a> PartialEq for Multiboot2Header<'a>
impl<'a> PartialEq for Multiboot2Header<'a>
Source§fn eq(&self, other: &Multiboot2Header<'a>) -> bool
fn eq(&self, other: &Multiboot2Header<'a>) -> bool
self and other values to be equal, and is used by ==.