Struct BootParams

Source
pub struct BootParams {
    pub header: Vec<u8>,
    pub header_start: GuestAddress,
    pub sections: Option<Vec<u8>>,
    pub sections_start: Option<GuestAddress>,
    pub modules: Option<Vec<u8>>,
    pub modules_start: Option<GuestAddress>,
}
Available on crate features elf or pe or bzimage only.
Expand description

Boot parameters to be written in guest memory.

Fields§

§header: Vec<u8>

“Header section”, always written in guest memory irrespective of boot protocol.

§header_start: GuestAddress

Header section address.

§sections: Option<Vec<u8>>

Optional sections containing boot configurations (e.g. E820 map).

§sections_start: Option<GuestAddress>

Sections starting address.

§modules: Option<Vec<u8>>

Optional modules specified at boot configuration time.

§modules_start: Option<GuestAddress>

Modules starting address.

Implementations§

Source§

impl BootParams

Source

pub fn new<T: ByteValued>(header: &T, header_addr: GuestAddress) -> Self

Creates a new BootParams struct with the specified header.

§Arguments
  • header - ByteValued representation of mandatory boot parameters.
  • header_addr - address in guest memory where header will be written.
§Examples
let boot_params = BootParams::new(&Header::default(), GuestAddress(0x1000));
Source

pub fn set_sections<T: ByteValued>( &mut self, sections: &[T], sections_addr: GuestAddress, )

Sets or overwrites the boot sections and associated memory address.

Unused on aarch64 and riscv64 for the Linux boot protocol. For the PVH boot protocol, the sections specify the memory map table in hvm_memmap_table_entry structs.

§Arguments
  • sections - vector of ByteValued boot configurations.
  • sections_addr - address where the sections will be written in guest memory.
§Examples
let mut boot_params = BootParams::new(&Header::default(), GuestAddress(0x1000));
let mut sections: Vec<Section> = vec![Section::default()];
boot_params.set_sections(sections.as_slice(), GuestAddress(0x2000));
// Another call overwrites the sections.
sections.clear();
boot_params.set_sections(sections.as_slice(), GuestAddress(0x3000));
assert_eq!(boot_params.sections.unwrap().len(), 0);
assert_eq!(boot_params.sections_start.unwrap(), GuestAddress(0x3000));
Source

pub fn add_section<T: ByteValued>( &mut self, section: &T, section_addr: Option<GuestAddress>, ) -> Result<GuestAddress>

Adds a boot section at the specified address (if specified and valid), or appends it.

It’s up to the caller to ensure that the section will not overlap with existing content or leave a gap past the current sections in the list.

§Arguments
  • section - ByteValued boot section element.
  • section_addr - optional address for the section in guest memory.
§Returns

Starting address of the section in guest memory, or an error.

§Examples
let mut boot_params = BootParams::new(&Header::default(), GuestAddress(0x1000));
let section = Section::default();
// Sections start address needs to be configured first.
assert!(boot_params.add_section::<Section>(&section, None).is_err());
let sections_start = GuestAddress(0x2000);
assert!(boot_params
    .add_section::<Section>(&section, Some(sections_start))
    .is_ok());
// It can be overwritten...
assert_eq!(
    boot_params
        .add_section::<Section>(&section, Some(sections_start))
        .unwrap(),
    sections_start
);
// But only if the address is valid.
assert!(boot_params
    .add_section::<Section>(&section, Some(sections_start.unchecked_sub(0x100)))
    .is_err());
// Or appended...
assert_eq!(
    boot_params.add_section::<Section>(&section, None).unwrap(),
    sections_start.unchecked_add(size_of::<Section>() as u64)
);
Source

pub fn set_modules<T: ByteValued>( &mut self, modules: &[T], modules_addr: GuestAddress, )

Sets or overwrites the boot modules and associated memory address.

Unused on aarch64 and riscv64 for the Linux boot protocol. For the PVH boot protocol, the modules are specified in hvm_modlist_entry structs.

§Arguments
  • modules - vector of ByteValued boot configurations.
  • modules_addr - address where the modules will be written in guest memory.
§Examples
let mut boot_params = BootParams::new(&Header::default(), GuestAddress(0x1000));
let mut modules: Vec<Module> = vec![Module::default()];
boot_params.set_modules(modules.as_slice(), GuestAddress(0x2000));
// Another call overwrites the sections.
modules.clear();
boot_params.set_modules(modules.as_slice(), GuestAddress(0x3000));
assert_eq!(boot_params.modules.unwrap().len(), 0);
assert_eq!(boot_params.modules_start.unwrap(), GuestAddress(0x3000));
Source

pub fn add_module<T: ByteValued>( &mut self, module: &T, module_addr: Option<GuestAddress>, ) -> Result<GuestAddress>

Adds a boot module at the specified address (if specified and valid), or appends it.

It’s up to the caller to ensure that the module will not overlap with existing content or leave a gap past the current modules in the list.

§Arguments
  • module - ByteValued boot module element.
  • module_addr - optional address for the module in guest memory.
§Returns

Starting address of the module in guest memory, or an error.

§Examples
let mut boot_params = BootParams::new(&Header::default(), GuestAddress(0x1000));
let module = Module::default();
// Modules start address needs to be configured first.
assert!(boot_params.add_module::<Module>(&module, None).is_err());
let modules_start = GuestAddress(0x2000);
assert!(boot_params
    .add_module::<Module>(&module, Some(modules_start))
    .is_ok());
// It can be overwritten...
assert_eq!(
    boot_params
        .add_module::<Module>(&module, Some(modules_start))
        .unwrap(),
    modules_start
);
// But only if the address is valid.
assert!(boot_params
    .add_module::<Module>(&module, Some(modules_start.unchecked_sub(0x100)))
    .is_err());
// Or appended...
assert_eq!(
    boot_params.add_module::<Module>(&module, None).unwrap(),
    modules_start.unchecked_add(size_of::<Module>() as u64)
);

Trait Implementations§

Source§

impl Clone for BootParams

Source§

fn clone(&self) -> BootParams

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.