Skip to main content

uhyve_interface/
lib.rs

1#![doc(
2	html_favicon_url = "https://media.githubusercontent.com/media/hermit-os/uhyve/main/img/uhyve_128.png"
3)]
4#![doc(
5	html_logo_url = "https://media.githubusercontent.com/media/hermit-os/uhyve/main/img/uhyve_512.png"
6)]
7//! # Uhyve Hypercall Interface
8//!
9//! This crate specifies the interface between the [Hermit Unikernel](https://github.com/hermit-os/kernel) and the hypervisor [Uhyve](https://github.com/hermit-os/uhyve).
10//! It includes the definition of the hypercalls and hypercall parameters and is intended to be used in both projects to ensure a coherent and well defined interface.
11
12#![cfg_attr(not(feature = "std"), no_std)]
13
14/// Each hypercall corresponds to an address, used by Uhyve to tell each hypercall apart.
15/// "Converting" hypercall objects to hypercall addresses is done often.
16/// This similarly applies to references of hypercall objects.
17/// Normally, we would have to implement two similar From traits for each version.
18/// This macro helps us reduce the boilerplate.
19macro_rules! into_hypercall_addresses {
20	(@internal $Self:ty; $name1:ident => $name2:ident) => { <$Self>::$name2 };
21	(@internal $Self:ty; $name1:ident) => { <$Self>::$name1 };
22
23	(
24	impl From<$hc:ident> for $hca:ty {
25		match {
26			$( $name1:ident $(=> $name2:ident)? ),*
27			$(,)?
28		}
29	}
30	) => {
31		impl From<$hc<'_>> for $hca {
32			fn from(value: $hc<'_>) -> Self {
33				match value {
34					$($hc::$name1 { .. } => into_hypercall_addresses!(@internal Self; $name1 $(=> $name2)?)),*
35				}
36			}
37		}
38		impl From<&$hc<'_>> for $hca {
39			fn from(value: &$hc<'_>) -> Self {
40				match value {
41					$($hc::$name1 { .. } => into_hypercall_addresses!(@internal Self; $name1 $(=> $name2)?)),*
42				}
43			}
44		}
45	}
46}
47
48/// Common parameters for versions 1 and 2 of the Hypercall Interface
49mod parameters;
50
51/// Version 1 of the Hypercall Interface
52pub mod v1;
53/// Version 2 of the Hypercall Interface
54pub mod v2;
55
56pub use memory_addresses::{PhysAddr as GuestPhysAddr, VirtAddr as GuestVirtAddr};
57
58#[cfg(not(target_pointer_width = "64"))]
59compile_error!("Using uhyve-interface on a non-64-bit system is not (yet?) supported");
60
61/// The version of the Uhyve interface. Note: This is not the same as the semver of the crate but
62/// should be increased on every version bump that changes the API.
63pub const UHYVE_INTERFACE_VERSION: u32 = 2;