Trait multiboot2_header::MaybeDynSized

source ·
pub trait MaybeDynSized: Pointee {
    type Header: Header;

    const BASE_SIZE: usize;

    // Required method
    fn dst_len(header: &Self::Header) -> Self::Metadata;

    // Provided methods
    fn header(&self) -> &Self::Header { ... }
    fn payload(&self) -> &[u8] { ... }
    fn as_bytes(&self) -> BytesRef<'_, Self::Header> { ... }
    fn as_ptr(&self) -> *const Self::Header { ... }
}
Expand description

A trait to abstract sized and unsized structures (DSTs). It enables casting a DynSizedStructure to sized or unsized structures using DynSizedStructure::cast.

Structs that are a DST must provide a correct MaybeDynSized::dst_len implementation. Further, implementors must use #[repr(C)].

Required Associated Types§

source

type Header: Header

The associated Header of this tag.

Required Associated Constants§

source

const BASE_SIZE: usize

The true base size of the struct without any implicit or additional padding. Note that size_of::<T>() isn’t sufficient, as for example the type could have three u32 fields, which would add an implicit u32 padding. However, this constant must always fulfill BASE_SIZE >= size_of::<Self::Header>().

The main purpose of this constant is to create awareness when you implement Self::dst_len, where you should use this. If this value is correct, we prevent situations where we read uninitialized bytes, especially when creating tags in builders.

Required Methods§

source

fn dst_len(header: &Self::Header) -> Self::Metadata

Returns the amount of items in the dynamically sized portion of the DST. Note that this is not the amount of bytes. So if the dynamically sized portion is 16 bytes in size and each element is 4 bytes big, then this function must return 4.

For sized tags, this just returns (). For DSTs, this returns an usize.

Provided Methods§

source

fn header(&self) -> &Self::Header

Returns the corresponding Header.

source

fn payload(&self) -> &[u8]

Returns the payload, i.e., all memory that is not occupied by the Header of the type.

source

fn as_bytes(&self) -> BytesRef<'_, Self::Header>

Returns the whole allocated bytes for this structure encapsulated in BytesRef. This includes padding bytes. To only get the “true” tag data, read the tag size from Self::header and create a sub slice.

Examples found in repository?
examples/minimal.rs (line 31)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
fn main() {
    // We create a Multiboot2 header during runtime here. A more practical
    // example, however, would be that you parse the header from kernel binary
    // at runtime.
    let mb2_hdr_bytes = Builder::new(HeaderTagISA::I386)
        .relocatable_tag(RelocatableHeaderTag::new(
            HeaderTagFlag::Required,
            0x1337,
            0xdeadbeef,
            4096,
            RelocatableHeaderTagPreference::None,
        ))
        .information_request_tag(InformationRequestHeaderTag::new(
            HeaderTagFlag::Required,
            &[
                MbiTagType::Cmdline.into(),
                MbiTagType::BootLoaderName.into(),
            ],
        ))
        .build();

    // Cast bytes in vector to Multiboot2 information structure
    let ptr = mb2_hdr_bytes.as_bytes().as_ptr();
    let mb2_hdr = unsafe { Multiboot2Header::load(ptr.cast()) };
    let mb2_hdr = mb2_hdr.unwrap();
    println!("{:#?}", mb2_hdr);
}
source

fn as_ptr(&self) -> *const Self::Header

Returns a pointer to this structure.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl MaybeDynSized for BootLoaderNameTag

source§

impl MaybeDynSized for CommandLineTag

source§

impl MaybeDynSized for EFIBootServicesNotExitedTag

source§

impl MaybeDynSized for EFIImageHandle32Tag

source§

impl MaybeDynSized for EFIImageHandle64Tag

source§

impl MaybeDynSized for EFISdt32Tag

source§

impl MaybeDynSized for EFISdt64Tag

source§

impl MaybeDynSized for ElfSectionsTag

source§

impl MaybeDynSized for EndTag

source§

impl MaybeDynSized for FramebufferTag

source§

impl MaybeDynSized for ImageLoadPhysAddrTag

source§

impl MaybeDynSized for BasicMemoryInfoTag

source§

impl MaybeDynSized for EFIMemoryMapTag

source§

impl MaybeDynSized for MemoryMapTag

source§

impl MaybeDynSized for ModuleTag

source§

impl MaybeDynSized for RsdpV1Tag

source§

impl MaybeDynSized for RsdpV2Tag

source§

impl MaybeDynSized for SmbiosTag

source§

impl MaybeDynSized for VBEInfoTag

Implementors§

source§

impl MaybeDynSized for DummyDstTag

source§

impl MaybeDynSized for AddressHeaderTag

source§

impl MaybeDynSized for ConsoleHeaderTag

source§

impl MaybeDynSized for EfiBootServiceHeaderTag

source§

impl MaybeDynSized for EndHeaderTag

source§

impl MaybeDynSized for EntryAddressHeaderTag

source§

impl MaybeDynSized for EntryEfi32HeaderTag

source§

impl MaybeDynSized for EntryEfi64HeaderTag

source§

impl MaybeDynSized for FramebufferHeaderTag

source§

impl MaybeDynSized for InformationRequestHeaderTag

source§

impl MaybeDynSized for ModuleAlignHeaderTag

source§

impl MaybeDynSized for RelocatableHeaderTag

source§

impl<H> MaybeDynSized for DynSizedStructure<H>
where H: Header,

§

type Header = H

source§

const BASE_SIZE: usize = _