From: Alejandro Vallejo <alejandro.vallejo@cloud.com>
To: xen-devel@lists.xenproject.org
Cc: Alejandro Vallejo <alejandro.vallejo@cloud.com>,
Anthony PERARD <anthony.perard@vates.tech>
Subject: [RFC PATCH 20/25] tools/xen-sys: Create a crate with autogenerated Rust constructs
Date: Fri, 15 Nov 2024 11:51:49 +0000 [thread overview]
Message-ID: <20241115115200.2824-21-alejandro.vallejo@cloud.com> (raw)
In-Reply-To: <20241115115200.2824-1-alejandro.vallejo@cloud.com>
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
diff --git a/tools/rust/Makefile b/tools/rust/Makefile
index 80e2f0e2817e..814e5b94447f 100644
--- a/tools/rust/Makefile
+++ b/tools/rust/Makefile
@@ -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; \
diff --git a/tools/rust/xen-sys/.gitignore b/tools/rust/xen-sys/.gitignore
new file mode 100644
index 000000000000..ca98cd96efdc
--- /dev/null
+++ b/tools/rust/xen-sys/.gitignore
@@ -0,0 +1,2 @@
+/target/
+Cargo.lock
diff --git a/tools/rust/xen-sys/Cargo.toml b/tools/rust/xen-sys/Cargo.toml
new file mode 100644
index 000000000000..fb91beaa1525
--- /dev/null
+++ b/tools/rust/xen-sys/Cargo.toml
@@ -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 }
diff --git a/tools/rust/xen-sys/src/lib.rs b/tools/rust/xen-sys/src/lib.rs
new file mode 100644
index 000000000000..7b3ea6c8ad4c
--- /dev/null
+++ b/tools/rust/xen-sys/src/lib.rs
@@ -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
+ }
+}
--
2.47.0
next prev parent reply other threads:[~2024-11-15 11:53 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-15 11:51 [RFC PATCH 00/25] Introduce xenbindgen to autogen hypercall structs Alejandro Vallejo
2024-11-15 11:51 ` [RFC PATCH 01/25] xen/domctl: Refine grant_opts into max_grant_version Alejandro Vallejo
2024-11-15 11:51 ` [RFC PATCH 02/25] xen/domctl: Replace altp2m_opts with altp2m_mode Alejandro Vallejo
2024-11-15 11:51 ` [RFC PATCH 03/25] tools/xenbindgen: Introduce a Xen hypercall IDL generator Alejandro Vallejo
2024-11-15 11:51 ` [RFC PATCH 04/25] tools/xenbindgen: Add a TOML spec reader Alejandro Vallejo
2024-11-25 15:13 ` Teddy Astie
2024-11-25 16:51 ` Alejandro Vallejo
2024-11-15 11:51 ` [RFC PATCH 05/25] tools/xenbindgen: Add basic plumbing for the C backend Alejandro Vallejo
2024-11-15 11:51 ` [RFC PATCH 06/25] tools/xenbindgen: Add xenbindgen's Cargo.lock file Alejandro Vallejo
2024-11-15 11:51 ` [RFC PATCH 07/25] tools/xenbindgen: Add support for structs in TOML specs Alejandro Vallejo
2024-11-25 12:39 ` Teddy Astie
2024-11-25 17:07 ` Alejandro Vallejo
2024-11-25 15:03 ` Teddy Astie
2024-11-25 17:16 ` Alejandro Vallejo
2024-11-15 11:51 ` [RFC PATCH 08/25] tools/xenbindgen: Add support for enums " Alejandro Vallejo
2024-11-25 16:39 ` Teddy Astie
2024-11-25 17:18 ` Alejandro Vallejo
2024-11-15 11:51 ` [RFC PATCH 09/25] tools/xenbindgen: Add support for bitmaps " Alejandro Vallejo
2024-11-15 11:51 ` [RFC PATCH 10/25] tools/xenbindgen: Add support for includes in the " Alejandro Vallejo
2024-11-15 11:51 ` [RFC PATCH 11/25] tools/xenbindgen: Validate ABI rules at generation time Alejandro Vallejo
2024-11-15 11:51 ` [RFC PATCH 12/25] xen: Replace sysctl/readconsole with autogenerated version Alejandro Vallejo
2024-11-25 12:05 ` Jan Beulich
2024-11-25 18:51 ` Alejandro Vallejo
2024-11-26 9:40 ` Jan Beulich
2024-11-26 12:27 ` Alejandro Vallejo
2024-11-26 13:20 ` Jan Beulich
2024-11-26 14:36 ` Alejandro Vallejo
2024-11-26 16:30 ` Jan Beulich
2024-11-26 14:39 ` Teddy Astie
2024-11-26 16:28 ` Jan Beulich
2024-11-15 11:51 ` [RFC PATCH 13/25] xen: Replace hand-crafted altp2m_mode descriptions with autogenerated ones Alejandro Vallejo
2024-11-15 11:51 ` [RFC PATCH 14/25] xen: Replace common bitmaps in domctl.createdomain with autogenerated versions Alejandro Vallejo
2024-11-15 11:51 ` [RFC PATCH 15/25] xen/arm: Replace hand-crafted xen_arch_domainconfig with autogenerated one Alejandro Vallejo
2024-11-15 11:51 ` [RFC PATCH 16/25] xen/x86: " Alejandro Vallejo
2024-11-25 12:09 ` Jan Beulich
2024-11-25 18:53 ` Alejandro Vallejo
2024-11-15 11:51 ` [RFC PATCH 17/25] xen/ppc: Replace empty " Alejandro Vallejo
2024-11-15 11:51 ` [RFC PATCH 18/25] xen/riscv: " Alejandro Vallejo
2024-11-15 11:51 ` [RFC PATCH 19/25] xen: Replace hand-crafted domctl/createdomain with autogenerated version Alejandro Vallejo
2024-12-04 14:48 ` Teddy Astie
2024-11-15 11:51 ` Alejandro Vallejo [this message]
2024-11-15 11:51 ` [RFC PATCH 21/25] tools/xenbindgen: Add Rust backend to xenbindgen Alejandro Vallejo
2024-11-15 11:51 ` [RFC PATCH 22/25] tools/xen-sys: Add autogenerated Rust files Alejandro Vallejo
2024-11-15 11:51 ` [RFC PATCH 23/25] licence: Add Unicode-DFS-2016 to the list of licences Alejandro Vallejo
2024-11-15 11:51 ` [RFC PATCH 24/25] tools/rust: Add deny.toml Alejandro Vallejo
2024-11-15 11:51 ` [RFC PATCH 25/25] ci: Add a CI checker for Rust-related helpful properties Alejandro Vallejo
2024-11-21 17:46 ` [RFC PATCH 00/25] Introduce xenbindgen to autogen hypercall structs Anthony PERARD
2024-11-22 10:52 ` Teddy Astie
2024-11-22 13:26 ` Alejandro Vallejo
2024-11-22 13:12 ` Alejandro Vallejo
2024-11-22 16:34 ` Anthony PERARD
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241115115200.2824-21-alejandro.vallejo@cloud.com \
--to=alejandro.vallejo@cloud.com \
--cc=anthony.perard@vates.tech \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.