Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added command line and environment to the hermit entry parameters #38

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "hermit-entry"
version = "0.10.1"
authors = ["Martin Kröning <[email protected]>"]
version = "0.11.0"
authors = ["Martin Kröning <[email protected]>", "Jonathan Klimt <[email protected]>"]
edition = "2021"
description = "Hermit's loading and entry API."
repository = "https://github.com/hermitcore/hermit-entry"
Expand Down
32 changes: 23 additions & 9 deletions src/boot_info/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,29 @@ impl From<RawPlatformInfo> for PlatformInfo {
num_cpus,
cpu_freq,
boot_time,
} => Self::Uhyve {
has_pci,
num_cpus,
cpu_freq,
boot_time: OffsetDateTime::from_unix_timestamp_nanos(i128::from_ne_bytes(
boot_time.0,
))
.unwrap(),
},
command_line_data,
command_line_len,
env,
} => {
let command_line = (!command_line_data.is_null()).then(|| {
// SAFETY: cmdline and cmdsize are valid forever.
let slice = unsafe {
core::slice::from_raw_parts(command_line_data, command_line_len as usize)
};
core::str::from_utf8(slice).unwrap()
});
Self::Uhyve {
has_pci,
num_cpus,
cpu_freq,
boot_time: OffsetDateTime::from_unix_timestamp_nanos(i128::from_ne_bytes(
boot_time.0,
))
.unwrap(),
command_line,
env,
}
}
RawPlatformInfo::LinuxBootParams {
command_line_data,
command_line_len,
Expand Down
7 changes: 7 additions & 0 deletions src/boot_info/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,18 @@ impl From<PlatformInfo> for RawPlatformInfo {
num_cpus,
cpu_freq,
boot_time,
command_line,
env,
} => Self::Uhyve {
has_pci,
num_cpus,
cpu_freq,
boot_time: boot_time.unix_timestamp_nanos().to_ne_bytes().into(),
env,
command_line_data: command_line
.map(|s| s.as_ptr())
.unwrap_or(core::ptr::null()),
command_line_len: command_line.map(|s| s.len() as u64).unwrap_or(0),
},
PlatformInfo::LinuxBootParams {
command_line,
Expand Down
15 changes: 15 additions & 0 deletions src/boot_info/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ pub enum PlatformInfo {

/// Boot time.
boot_time: OffsetDateTime,

/// Command line (program name and command line arguments) passed to
/// the kernel.
command_line: Option<&'static str>,

/// Environment variables: First element is a pointer to the beginning
/// of the envp, second element is a pointer to the beginning of the
/// raw env data. The length of the envp is
/// `(env.0 - env.1) / size_of::<u64>()`.
/// The last pointer in envp points to the end of the environemen data,
/// and not to a valid environment variable!
env: Option<(NonZeroU64, NonZeroU64)>,
},
/// Linux Boot Parameters.
LinuxBootParams {
Expand Down Expand Up @@ -191,6 +203,9 @@ enum RawPlatformInfo {
num_cpus: NonZeroU64,
cpu_freq: Option<NonZeroU32>,
boot_time: Align8<[u8; 16]>,
env: Option<(NonZeroU64, NonZeroU64)>,
command_line_data: *const u8,
command_line_len: u64,
},
LinuxBootParams {
command_line_data: *const u8,
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const NT_HERMIT_ENTRY_VERSION: u32 = 0x5a00;

/// The current hermit entry version.
#[cfg_attr(not(all(feature = "loader", feature = "kernel")), allow(dead_code))]
const HERMIT_ENTRY_VERSION: u8 = 4;
const HERMIT_ENTRY_VERSION: u8 = 5;

/// Offsets and values used to interpret the boot params ("zeropage") setup by firecracker
/// For the full list of values see
Expand Down