Multiboot2Header

Struct Multiboot2Header 

Source
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>

Source

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

Public constructor for this type with various validations.

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

  • addr is a null-pointer
  • addr isn’t 8-byte aligned
  • the magic value of the header is not present
  • the checksum field is invalid
§Safety

This function may produce undefined behaviour, if the provided addr is not a valid Multiboot2 header pointer.

Examples found in repository?
examples/minimal.rs (line 32)
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}
Source

pub fn find_header(buffer: &[u8]) -> Result<Option<(&[u8], u32)>, LoadError>

Find the header in a given slice.

If it succeeds, it returns a tuple consisting of the subslice containing just the header and the index of the header in the given slice. If it fails (either because the header is not properly 64-bit aligned or because it is truncated), it returns a LoadError. If there is no header, it returns None.

Source

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

Returns a TagIter.

Source

pub const fn verify_checksum(&self) -> bool

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 Multiboot2Header<'_>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Multiboot2Header<'a>

§

impl<'a> RefUnwindSafe for Multiboot2Header<'a>

§

impl<'a> Send for Multiboot2Header<'a>

§

impl<'a> Sync for Multiboot2Header<'a>

§

impl<'a> Unpin for Multiboot2Header<'a>

§

impl<'a> UnwindSafe for Multiboot2Header<'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.