Skip to main content

StartInfoReader

Struct StartInfoReader 

Source
pub struct StartInfoReader<'a, M> { /* private fields */ }
Available on crate feature reader only.
Expand description

A start info reader.

This struct allows reading the data that is provided as physical addresses via the start info.

For this, a way of creating pointers from physical addresses is needed (MemMap), for example IdentityMap.

§Examples

use pvh::start_info::reader::StartInfoReader;

let start_info = unsafe { StartInfoReader::from_paddr_identity(start_info_paddr).unwrap() };

println!("Start info:");
println!("{start_info:#?}");

Implementations§

Source§

impl StartInfoReader<'_, IdentityMap>

Source

pub unsafe fn from_paddr_identity(paddr: u32) -> Option<Self>

Creates a start info reader from a physical address that relies on identity-mapping.

This is a convenience method for from_paddr(IdentityMap).

§Safety
  • The structure at paddr must be valid. Specifically, the physical addresses in the structure’s fields must be valid.
  • IdentityMap must be valid for the lifetime of the start info.
Examples found in repository?
examples/print/main.rs (line 32)
29unsafe extern "C" fn rust_start(start_info_paddr: u32) -> ! {
30    // SAFETY: The caller upholds that `start_info_paddr` is valid.
31    // We have configured the machine to use identity-mapping.
32    let start_info = unsafe { StartInfoReader::from_paddr_identity(start_info_paddr).unwrap() };
33
34    println!("Raw start info:\n\n{:#x?}\n", start_info.raw());
35
36    println!("Start info reader:\n\n{start_info:?}\n");
37    println!("Alternative start info reader:\n\n{start_info:#?}\n");
38
39    for module in start_info.modlist() {
40        let bytes = module.as_slice();
41        if let Ok(s) = str::from_utf8(bytes) {
42            println!("Module: {s:?}\n");
43        } else {
44            println!("Module: {bytes:?}\n");
45        }
46    }
47
48    println!("Done!");
49
50    loop {
51        hint::spin_loop();
52    }
53}
Source§

impl<'a, M: MemMap> StartInfoReader<'a, M>

Source

pub unsafe fn from_paddr(paddr: u32, mem_map: M) -> Option<Self>

Creates a start info reader from a physical address and a memory map.

from_paddr_identity is convenience method for identity-mappings.

§Safety
  • The structure at paddr must be valid. Specifically, the physical addresses in the structure’s fields must be valid.
  • mem_map must be valid for the lifetime of the start info. For details, see MemMap.
Source

pub fn raw(&self) -> &'a StartInfo

Returns the underlying raw start info.

Examples found in repository?
examples/print/main.rs (line 34)
29unsafe extern "C" fn rust_start(start_info_paddr: u32) -> ! {
30    // SAFETY: The caller upholds that `start_info_paddr` is valid.
31    // We have configured the machine to use identity-mapping.
32    let start_info = unsafe { StartInfoReader::from_paddr_identity(start_info_paddr).unwrap() };
33
34    println!("Raw start info:\n\n{:#x?}\n", start_info.raw());
35
36    println!("Start info reader:\n\n{start_info:?}\n");
37    println!("Alternative start info reader:\n\n{start_info:#?}\n");
38
39    for module in start_info.modlist() {
40        let bytes = module.as_slice();
41        if let Ok(s) = str::from_utf8(bytes) {
42            println!("Module: {s:?}\n");
43        } else {
44            println!("Module: {bytes:?}\n");
45        }
46    }
47
48    println!("Done!");
49
50    loop {
51        hint::spin_loop();
52    }
53}
Source

pub fn modlist(&self) -> impl Iterator<Item = ModlistEntryReader<'a, &M>>

Returns an iterator of module list entry readers.

Examples found in repository?
examples/print/main.rs (line 39)
29unsafe extern "C" fn rust_start(start_info_paddr: u32) -> ! {
30    // SAFETY: The caller upholds that `start_info_paddr` is valid.
31    // We have configured the machine to use identity-mapping.
32    let start_info = unsafe { StartInfoReader::from_paddr_identity(start_info_paddr).unwrap() };
33
34    println!("Raw start info:\n\n{:#x?}\n", start_info.raw());
35
36    println!("Start info reader:\n\n{start_info:?}\n");
37    println!("Alternative start info reader:\n\n{start_info:#?}\n");
38
39    for module in start_info.modlist() {
40        let bytes = module.as_slice();
41        if let Ok(s) = str::from_utf8(bytes) {
42            println!("Module: {s:?}\n");
43        } else {
44            println!("Module: {bytes:?}\n");
45        }
46    }
47
48    println!("Done!");
49
50    loop {
51        hint::spin_loop();
52    }
53}
Source

pub fn cmdline(&self) -> Option<&'a CStr>

Returns the command line.

Source

pub fn memmap(&self) -> &'a [MemmapTableEntry]

Returns the memory map.

Trait Implementations§

Source§

impl<M: MemMap> Debug for StartInfoReader<'_, M>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, M> Freeze for StartInfoReader<'a, M>
where M: Freeze,

§

impl<'a, M> RefUnwindSafe for StartInfoReader<'a, M>
where M: RefUnwindSafe,

§

impl<'a, M> Send for StartInfoReader<'a, M>
where M: Send,

§

impl<'a, M> Sync for StartInfoReader<'a, M>
where M: Sync,

§

impl<'a, M> Unpin for StartInfoReader<'a, M>
where M: Unpin,

§

impl<'a, M> UnsafeUnpin for StartInfoReader<'a, M>
where M: UnsafeUnpin,

§

impl<'a, M> UnwindSafe for StartInfoReader<'a, M>
where M: UnwindSafe,

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