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>,
}
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
impl BootParams
Sourcepub fn new<T: ByteValued>(header: &T, header_addr: GuestAddress) -> Self
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 whereheader
will be written.
§Examples
let boot_params = BootParams::new(&Header::default(), GuestAddress(0x1000));
Sourcepub fn set_sections<T: ByteValued>(
&mut self,
sections: &[T],
sections_addr: GuestAddress,
)
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 ofByteValued
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));
Sourcepub fn add_section<T: ByteValued>(
&mut self,
section: &T,
section_addr: Option<GuestAddress>,
) -> Result<GuestAddress>
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>(§ion, None).is_err());
let sections_start = GuestAddress(0x2000);
assert!(boot_params
.add_section::<Section>(§ion, Some(sections_start))
.is_ok());
// It can be overwritten...
assert_eq!(
boot_params
.add_section::<Section>(§ion, Some(sections_start))
.unwrap(),
sections_start
);
// But only if the address is valid.
assert!(boot_params
.add_section::<Section>(§ion, Some(sections_start.unchecked_sub(0x100)))
.is_err());
// Or appended...
assert_eq!(
boot_params.add_section::<Section>(§ion, None).unwrap(),
sections_start.unchecked_add(size_of::<Section>() as u64)
);
Sourcepub fn set_modules<T: ByteValued>(
&mut self,
modules: &[T],
modules_addr: GuestAddress,
)
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 ofByteValued
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));
Sourcepub fn add_module<T: ByteValued>(
&mut self,
module: &T,
module_addr: Option<GuestAddress>,
) -> Result<GuestAddress>
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
impl Clone for BootParams
Source§fn clone(&self) -> BootParams
fn clone(&self) -> BootParams
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more