diff --git a/Cargo.toml b/Cargo.toml index 81a38fe..a59f160 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 = [] diff --git a/src/elf.rs b/src/elf.rs index de75473..6a63f10 100644 --- a/src/elf.rs +++ b/src/elf.rs @@ -168,7 +168,7 @@ impl TryFrom> 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); } diff --git a/src/lib.rs b/src/lib.rs index 029e7fe..0819db5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 /// diff --git a/src/note.rs b/src/note.rs index 4599519..6370b66 100644 --- a/src/note.rs +++ b/src/note.rs @@ -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 . +/// +/// # 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 { 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 { @@ -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, diff --git a/tests/macros.rs b/tests/macros.rs index 7390139..ca6f361 100644 --- a/tests/macros.rs +++ b/tests/macros.rs @@ -3,3 +3,4 @@ hermit_entry::define_abi_tag!(); hermit_entry::define_entry_version!(); +hermit_entry::define_uhyve_interface_version!(1);