Skip to content

Commit 1355587

Browse files
authored
Merge pull request hermit-os#64 from fogti/no-uhyve-dep
deps: get rid of `uhyve-interface` dependency
2 parents 6e3695f + a0e56f1 commit 1355587

File tree

5 files changed

+47
-6
lines changed

5 files changed

+47
-6
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ goblin = { version = "0.10", default-features = false, features = ["elf64"], opt
2626
log = { version = "0.4", optional = true }
2727
plain = { version = "0.2", optional = true }
2828
time = { version = "0.3", default-features = false }
29-
uhyve-interface = "0.1"
3029

3130
[features]
3231
default = []

src/elf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl TryFrom<Note<'_>> for UhyveIfVersion {
168168
return Err(ParseUhyveIfVersionError);
169169
}
170170

171-
if value.ty != uhyve_interface::elf::NT_UHYVE_INTERFACE_VERSION {
171+
if value.ty != crate::NT_UHYVE_INTERFACE_VERSION {
172172
return Err(ParseUhyveIfVersionError);
173173
}
174174

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ const NT_HERMIT_ENTRY_VERSION: u32 = 0x5a00;
9090
#[cfg_attr(not(any(feature = "loader", feature = "kernel")), expect(dead_code))]
9191
const HERMIT_ENTRY_VERSION: u8 = 4;
9292

93+
/// Note type for specifying the Uhyve interface version in an elf header.
94+
#[cfg_attr(not(any(feature = "loader", feature = "kernel")), expect(dead_code))]
95+
const NT_UHYVE_INTERFACE_VERSION: u32 = 0x5b00;
96+
9397
/// Offsets and values used to interpret the boot params ("zeropage") setup by firecracker
9498
/// For the full list of values see
9599
/// <https://github.com/torvalds/linux/blob/b6839ef26e549de68c10359d45163b0cfb031183/arch/x86/include/uapi/asm/bootparam.h#L151-L198>

src/note.rs

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,42 @@ macro_rules! define_entry_version {
1111
() => {
1212
#[used]
1313
#[unsafe(link_section = ".note.hermit.entry-version")]
14-
static ENTRY_VERSION: $crate::_Note = $crate::_Note::entry_version();
14+
static ENTRY_VERSION: $crate::_Note<1> = $crate::_Note::entry_version();
15+
};
16+
}
17+
18+
/// Defines the Uhyve interface version in the note section.
19+
///
20+
/// This macro must be used in a module that is guaranteed to be linked.
21+
/// See <https://github.com/rust-lang/rust/issues/99721>.
22+
///
23+
/// # Examples
24+
///
25+
/// ```
26+
/// # mod uhyve_interface {
27+
/// # pub const UHYVE_INTERFACE_VERSION: u32 = 1;
28+
/// # }
29+
/// #
30+
/// hermit_entry::define_uhyve_interface_version!(uhyve_interface::UHYVE_INTERFACE_VERSION);
31+
/// ```
32+
#[macro_export]
33+
macro_rules! define_uhyve_interface_version {
34+
($version:expr) => {
35+
#[used]
36+
#[unsafe(link_section = ".note.hermit.uhyve-interface-version")]
37+
static INTERFACE_VERSION: $crate::_Note<4> = $crate::_Note::uhyveif_version($version);
1538
};
1639
}
1740

1841
#[repr(C)]
1942
#[doc(hidden)]
20-
pub struct _Note {
43+
pub struct _Note<const N: usize> {
2144
header: Nhdr32,
2245
name: [u8; 8],
23-
data: [u8; 1],
46+
data: [u8; N],
2447
}
2548

26-
impl _Note {
49+
impl _Note<1> {
2750
pub const fn entry_version() -> Self {
2851
Self {
2952
header: Nhdr32 {
@@ -37,6 +60,20 @@ impl _Note {
3760
}
3861
}
3962

63+
impl _Note<4> {
64+
pub const fn uhyveif_version(ver: u32) -> Self {
65+
Self {
66+
header: Nhdr32 {
67+
n_namesz: 8,
68+
n_descsz: 4,
69+
n_type: crate::NT_UHYVE_INTERFACE_VERSION,
70+
},
71+
name: *b"UHYVEIF\0",
72+
data: ver.to_be_bytes(),
73+
}
74+
}
75+
}
76+
4077
#[repr(C)]
4178
struct Nhdr32 {
4279
n_namesz: u32,

tests/macros.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
44
hermit_entry::define_abi_tag!();
55
hermit_entry::define_entry_version!();
6+
hermit_entry::define_uhyve_interface_version!(1);

0 commit comments

Comments
 (0)