Skip to main content

Header

Struct Header 

Source
pub struct Header<'a>(/* private fields */);
Expand description

A parsed complete Multiboot2 header.

It consists of the fixed Multiboot2BasicHeader prefix followed by all header tags (see HeaderTagType). Multiboot2BasicHeader represents only that prefix; use this type when working with the complete, dynamically sized header.

Use this to parse a header from a pointer. To construct a header, use Builder (requires the builder feature).

Implementations§

Source§

impl<'a> Header<'a>

Source

pub unsafe fn load(ptr: *const Multiboot2BasicHeader) -> Result<Self, LoadError>

Loads a complete Header from a pointer.

If the header is invalid, it returns a LoadError. This may be because:

  • ptr is a null pointer
  • ptr is 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
  • ptr must be valid for reading the complete reported header size. Otherwise, this function might cause invalid machine state or crash your binary.
  • The memory at ptr must not be modified after calling load or the program may observe unsynchronized mutation.
Examples found in repository?
examples/minimal.rs (line 28)
7fn main() {
8    // We create a Multiboot2 header during runtime here. A more practical
9    // example, however, would be that you parse the header from kernel binary
10    // at runtime.
11    let header_bytes = Builder::new(HeaderTagISA::I386)
12        .relocatable_tag(RelocatableHeaderTag::new(
13            HeaderTagFlag::Required,
14            0x1337,
15            0xdeadbeef,
16            4096,
17            RelocatableHeaderTagPreference::None,
18        ))
19        .information_request_tag(InformationRequestHeaderTag::new(
20            HeaderTagFlag::Required,
21            &[
22                MbiTagType::Cmdline.into(),
23                MbiTagType::BootLoaderName.into(),
24            ],
25        ))
26        .build();
27
28    let header = unsafe { Header::load(header_bytes.as_ptr()) }.unwrap();
29    println!("{header:#?}");
30}
Source

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.

§Parameters
Source

pub fn iter(&self) -> TagIter<'_>

Returns a TagIter.

Source

pub const fn verify_checksum(&self) -> Result<(), (u32, u32)>

Source

pub const fn header_magic(&self) -> u32

Source

pub const fn arch(&self) -> HeaderTagISA

Source

pub const fn length(&self) -> u32

Source

pub const fn checksum(&self) -> u32

Source

pub const fn calc_checksum(magic: u32, arch: HeaderTagISA, length: u32) -> u32

Source

pub fn information_request_tag(&self) -> Option<&InformationRequestHeaderTag>

Search for the InformationRequestHeaderTag header tag.

Source

pub fn address_tag(&self) -> Option<&AddressHeaderTag>

Search for the AddressHeaderTag header tag.

Source

pub fn entry_address_tag(&self) -> Option<&EntryAddressHeaderTag>

Search for the EntryAddressHeaderTag header tag.

Source

pub fn entry_address_efi32_tag(&self) -> Option<&EntryEfi32HeaderTag>

Search for the EntryEfi32HeaderTag header tag.

Source

pub fn entry_address_efi64_tag(&self) -> Option<&EntryEfi64HeaderTag>

Search for the EntryEfi64HeaderTag header tag.

Source

pub fn console_flags_tag(&self) -> Option<&ConsoleHeaderTag>

Search for the ConsoleHeaderTag header tag.

Source

pub fn framebuffer_tag(&self) -> Option<&FramebufferHeaderTag>

Search for the FramebufferHeaderTag header tag.

Source

pub fn module_align_tag(&self) -> Option<&ModuleAlignHeaderTag>

Search for the ModuleAlignHeaderTag header tag.

Source

pub fn efi_boot_services_tag(&self) -> Option<&EfiBootServiceHeaderTag>

Search for the EfiBootServiceHeaderTag header tag.

Source

pub fn relocatable_tag(&self) -> Option<&RelocatableHeaderTag>

Search for the RelocatableHeaderTag header tag.

Trait Implementations§

Source§

impl Debug for Header<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Eq for Header<'a>

Source§

impl<'a> PartialEq for Header<'a>

Source§

fn eq(&self, other: &Header<'a>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<'a> StructuralPartialEq for Header<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Header<'a>

§

impl<'a> RefUnwindSafe for Header<'a>

§

impl<'a> Send for Header<'a>

§

impl<'a> Sync for Header<'a>

§

impl<'a> Unpin for Header<'a>

§

impl<'a> UnsafeUnpin for Header<'a>

§

impl<'a> UnwindSafe for Header<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.