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 26)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
fn main() {
    // We create a Multiboot2 header during runtime here. A practical example is that your
    // program gets the header from a file and parses it afterwards.
    let mb2_hdr_bytes = HeaderBuilder::new(HeaderTagISA::I386)
        .relocatable_tag(RelocatableHeaderTag::new(
            HeaderTagFlag::Required,
            0x1337,
            0xdeadbeef,
            4096,
            RelocatableHeaderTagPreference::None,
        ))
        .information_request_tag(
            InformationRequestHeaderTagBuilder::new(HeaderTagFlag::Required)
                .add_irs(&[MbiTagType::Cmdline, MbiTagType::BootLoaderName]),
        )
        .build();

    // Cast bytes in vector to Multiboot2 information structure
    let mb2_hdr = unsafe { Multiboot2Header::load(mb2_hdr_bytes.as_ptr().cast()) };
    println!("{:#?}", mb2_hdr);
}
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 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 fn iter(&self) -> Multiboot2HeaderTagIter

source

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

source

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

Search for the address header tag.

source

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

Search for the entry address header tag.

source

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

Search for the EFI32 entry address header tag.

source

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

Search for the EFI64 entry address header tag.

source

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

Search for the console flags header tag.

source

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

Search for the framebuffer header tag.

source

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

Search for the module align header tag.

source

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

Search for the EFI Boot Services header tag.

source

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

Search for the EFI32 entry address header tag.

Trait Implementations§

source§

impl<'a> Debug for Multiboot2Header<'a>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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.

§

impl<T> Pointee for T

§

type Metadata = ()

The type for metadata in pointers and references to Self.
source§

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

§

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

§

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.