Skip to content
Merged
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
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ goblin = { version = "0.10", default-features = false, features = ["elf64"], opt
log = { version = "0.4", optional = true }
plain = { version = "0.2", optional = true }
time = { version = "0.3", default-features = false }
uhyve-interface = "0.1"

[features]
default = []
Expand Down
2 changes: 1 addition & 1 deletion src/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl TryFrom<Note<'_>> for UhyveIfVersion {
return Err(ParseUhyveIfVersionError);
}

if value.ty != uhyve_interface::elf::NT_UHYVE_INTERFACE_VERSION {
if value.ty != crate::NT_UHYVE_INTERFACE_VERSION {
return Err(ParseUhyveIfVersionError);
}

Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ const NT_HERMIT_ENTRY_VERSION: u32 = 0x5a00;
#[cfg_attr(not(any(feature = "loader", feature = "kernel")), expect(dead_code))]
const HERMIT_ENTRY_VERSION: u8 = 4;

/// Note type for specifying the Uhyve interface version in an elf header.
#[cfg_attr(not(any(feature = "loader", feature = "kernel")), expect(dead_code))]
const NT_UHYVE_INTERFACE_VERSION: u32 = 0x5b00;

/// Offsets and values used to interpret the boot params ("zeropage") setup by firecracker
/// For the full list of values see
/// <https://github.com/torvalds/linux/blob/b6839ef26e549de68c10359d45163b0cfb031183/arch/x86/include/uapi/asm/bootparam.h#L151-L198>
Expand Down
45 changes: 41 additions & 4 deletions src/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,42 @@ macro_rules! define_entry_version {
() => {
#[used]
#[unsafe(link_section = ".note.hermit.entry-version")]
static ENTRY_VERSION: $crate::_Note = $crate::_Note::entry_version();
static ENTRY_VERSION: $crate::_Note<1> = $crate::_Note::entry_version();
};
}

/// Defines the Uhyve interface version in the note section.
///
/// This macro must be used in a module that is guaranteed to be linked.
/// See <https://github.com/rust-lang/rust/issues/99721>.
///
/// # Examples
///
/// ```
/// # mod uhyve_interface {
/// # pub const UHYVE_INTERFACE_VERSION: u32 = 1;
/// # }
/// #
/// hermit_entry::define_uhyve_interface_version!(uhyve_interface::UHYVE_INTERFACE_VERSION);
/// ```
#[macro_export]
macro_rules! define_uhyve_interface_version {
($version:expr) => {
#[used]
#[unsafe(link_section = ".note.hermit.uhyve-interface-version")]
static INTERFACE_VERSION: $crate::_Note<4> = $crate::_Note::uhyveif_version($version);
};
}

#[repr(C)]
#[doc(hidden)]
pub struct _Note {
pub struct _Note<const N: usize> {
header: Nhdr32,
name: [u8; 8],
data: [u8; 1],
data: [u8; N],
}

impl _Note {
impl _Note<1> {
pub const fn entry_version() -> Self {
Self {
header: Nhdr32 {
Expand All @@ -37,6 +60,20 @@ impl _Note {
}
}

impl _Note<4> {
pub const fn uhyveif_version(ver: u32) -> Self {
Self {
header: Nhdr32 {
n_namesz: 8,
n_descsz: 4,
n_type: crate::NT_UHYVE_INTERFACE_VERSION,
},
name: *b"UHYVEIF\0",
data: ver.to_be_bytes(),
}
}
}

#[repr(C)]
struct Nhdr32 {
n_namesz: u32,
Expand Down
1 change: 1 addition & 0 deletions tests/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

hermit_entry::define_abi_tag!();
hermit_entry::define_entry_version!();
hermit_entry::define_uhyve_interface_version!(1);