@@ -3,6 +3,9 @@ XEN_ROOT=$(CURDIR)/../..
# Path to the Xen hypercall IDL parser
XENBINDGEN=$(CURDIR)/xenbindgen
+# Path to the autogenerated Rust bindings crate
+CRATE_XENSYS=$(CURDIR)/xen-sys
+
# Output folder for the autogenerated C headers
#
# Must contain autogenerated files only because they're all wiped on update
@@ -37,7 +40,7 @@ update: clean-autogen
.PHONY: verify
verify:
set -eu; \
- for i in "${XENBINDGEN}"; do \
+ for i in "${CRATE_XENSYS}" "${XENBINDGEN}"; do \
echo "Verifying $$i"; \
cd "$$i"; \
cargo fmt -- --check; \
new file mode 100644
@@ -0,0 +1,2 @@
+/target/
+Cargo.lock
new file mode 100644
@@ -0,0 +1,8 @@
+[package]
+name = "xen-sys"
+version = "0.1.0"
+edition = "2021"
+license = "MIT"
+
+[dependencies]
+bitflags = { version = "2.6.0", default-features = false }
new file mode 100644
@@ -0,0 +1,41 @@
+//! xen-sys
+//!
+//! This crate contains low-level primitives to interact with the Xen
+//! hypervisor. It relies on the autogenerated bindings of xenbindgen and
+//! a few closely related primitives, like [`Align64`].
+#![no_std]
+
+use core::ops::{Deref, DerefMut};
+
+/// Wrapper for pointers and 64bit integers so they are _always_ aligned to 8
+/// octets, even in 32bit machines.
+#[repr(align(8))]
+#[derive(Copy, Clone, Debug, Eq, PartialEq)]
+pub struct Align64<T>(pub T);
+
+impl<T> Default for Align64<T> {
+ fn default() -> Self {
+ // Experimental feature
+ //
+ // This is required because `*mut U` can't implement Default. We take
+ // the convention that `Default` means "zero". For `t: Align64<*mut T>`
+ // that means `t` is null.
+ //
+ // If the `xen` crate stops needing this, then this impl must go away.
+ unsafe { Self(core::mem::zeroed()) }
+ }
+}
+
+impl<T> Deref for Align64<T> {
+ type Target = T;
+
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
+
+impl<T> DerefMut for Align64<T> {
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ &mut self.0
+ }
+}
Signed-off-by: Alejandro Vallejo <alejandro.vallejo@cloud.com> --- tools/rust/Makefile | 5 ++++- tools/rust/xen-sys/.gitignore | 2 ++ tools/rust/xen-sys/Cargo.toml | 8 +++++++ tools/rust/xen-sys/src/lib.rs | 41 +++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 tools/rust/xen-sys/.gitignore create mode 100644 tools/rust/xen-sys/Cargo.toml create mode 100644 tools/rust/xen-sys/src/lib.rs