twizzler_abi/
aux.rs

1//! When running a new program (and thus, initializing a new runtime), the new program expects to
2//! receive some information about how it was started, including arguments, env vars, etc. These are
3//! passed to the new program through the _start function as an array of AuxEntries as its only
4//! argument.
5//!
6//! This array of entries is an unspecified length and is terminated by the Null entry at the end of
7//! the array.
8
9use crate::object::ObjID;
10
11/// Information about initrd object names.
12#[derive(Copy, Clone)]
13#[repr(C)]
14pub struct KernelInitName {
15    name: [u8; 256],
16    id: ObjID,
17    len: usize,
18    res: u64,
19}
20
21impl KernelInitName {
22    /// Constructor for a null name.
23    pub const fn null() -> Self {
24        Self {
25            name: [0; 256],
26            id: ObjID::new(0),
27            len: 0,
28            res: 0,
29        }
30    }
31
32    /// New mapping from name to ID.
33    pub fn new(name: &str, id: ObjID) -> Self {
34        let mut new = Self {
35            name: [0; 256],
36            id,
37            len: name.bytes().len(),
38            res: 0,
39        };
40        for b in name.bytes().enumerate() {
41            new.name[b.0] = b.1;
42        }
43        new
44    }
45
46    /// Get a name.
47    pub fn name(&self) -> &str {
48        unsafe { core::str::from_utf8_unchecked(&self.name[0..self.len]) }
49    }
50
51    /// Get an ID.
52    pub fn id(&self) -> ObjID {
53        self.id
54    }
55}
56
57/// Kernel init info, including initrd names.
58#[repr(C)]
59pub struct KernelInitInfo {
60    version: u32,
61    flags: u32,
62    boot_names_len: usize,
63    boot_names: [KernelInitName; 256],
64}
65
66impl KernelInitInfo {
67    /// Constructor.
68    pub const fn new() -> Self {
69        Self {
70            version: 0,
71            flags: 0,
72            boot_names_len: 0,
73            boot_names: [KernelInitName::null(); 256],
74        }
75    }
76
77    /// Add a name to the name list.
78    pub fn add_name(&mut self, name: KernelInitName) {
79        self.boot_names[self.boot_names_len] = name;
80        self.boot_names_len += 1;
81    }
82
83    /// Get the name list.
84    pub fn names(&self) -> &[KernelInitName] {
85        &self.boot_names[0..self.boot_names_len]
86    }
87}