qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v7 6/7] rust: add crate to expose bindings and interfaces


From: Junjie Mao
Subject: Re: [PATCH v7 6/7] rust: add crate to expose bindings and interfaces
Date: Fri, 16 Aug 2024 16:26:44 +0800
User-agent: Mozilla Thunderbird

On 8/15/2024 7:42 PM, Manos Pitsidianakis wrote:
Add rust/qemu-api, which exposes rust-bindgen generated FFI bindings and
provides some declaration macros for symbols visible to the rest of
QEMU.

Co-authored-by: Junjie Mao <junjie.mao@intel.com>
Co-authored-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
---
[snip]
+
+#[macro_export]
+macro_rules! declare_properties {
+    ($ident:ident, $($prop:expr),*$(,)*) => {
+
+        const fn _calc_prop_len() -> usize {
+            let mut len = 1;
+            $({
+                _ = stringify!($prop);
+                len += 1;
+            })*
+            len
+        }
+        const PROP_LEN: usize = _calc_prop_len();
+
+        #[no_mangle]
+        fn _make_properties() -> [$crate::bindings::Property; PROP_LEN] {

#[no_mangle] also makes _make_properties externally visible and thus will cause duplicate-symbol-definition errors at link time when multiple devices are enabled.

Since it is only used in the definition of $ident below, shall we just remove #[no_mangle] for _make_properties?

---
Best Regards
Junjie Mao

+            [
+                $($prop),*,
+                    unsafe { 
::core::mem::MaybeUninit::<$crate::bindings::Property>::zeroed().assume_init() 
},
+            ]
+        }
+
+        #[no_mangle]
+        pub static mut $ident: $crate::device_class::Properties<PROP_LEN> = 
$crate::device_class::Properties(::std::sync::OnceLock::new(), _make_properties);
+    };
+}
+
+#[macro_export]
+macro_rules! vm_state_description {
+    ($(#[$outer:meta])*
+     $name:ident,
+     $(name: $vname:expr,)*
+     $(unmigratable: $um_val:expr,)*
+    ) => {
+        #[used]
+        $(#[$outer])*
+        pub static $name: $crate::bindings::VMStateDescription = 
$crate::bindings::VMStateDescription {
+            $(name: {
+                #[used]
+                static VMSTATE_NAME: &::core::ffi::CStr = $vname;
+                $vname.as_ptr()
+            },)*
+            unmigratable: true,
+            ..unsafe { 
::core::mem::MaybeUninit::<$crate::bindings::VMStateDescription>::zeroed().assume_init()
 }
+        };
+    }
+}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]