uhyve_interface/
elf.rs

1//! Utility to place the Uhyve interface version in the elf header of the hermit kernel.
2
3/// Defines the Uhyve interface version in the note section.
4///
5/// This macro must be used in a module that is guaranteed to be linked.
6/// See <https://github.com/rust-lang/rust/issues/99721>.
7#[macro_export]
8macro_rules! define_uhyve_interface_version {
9	() => {
10		#[used]
11		#[link_section = ".note.hermit.uhyve-interface-version"]
12		static INTERFACE_VERSION: $crate::elf::Note = $crate::elf::Note::uhyveif_version();
13	};
14}
15
16/// Note type for specifying the Uhyve interface version in an elf header.
17pub const NT_UHYVE_INTERFACE_VERSION: u32 = 0x5b00;
18
19/// A elf note header entry containing the used Uhyve interface version as little-endian 32-bit value.
20#[repr(C)]
21pub struct Note {
22	header: Nhdr32,
23	name: [u8; 8],
24	data: [u8; 4],
25}
26
27impl Note {
28	pub const fn uhyveif_version() -> Self {
29		Self {
30			header: Nhdr32 {
31				n_namesz: 8,
32				n_descsz: 4,
33				n_type: NT_UHYVE_INTERFACE_VERSION,
34			},
35			name: *b"UHYVEIF\0",
36			data: crate::UHYVE_INTERFACE_VERSION.to_be_bytes(),
37		}
38	}
39}
40
41/// The sizes of the fields in [`Note`]
42#[repr(C)]
43struct Nhdr32 {
44	n_namesz: u32,
45	n_descsz: u32,
46	n_type: u32,
47}