qemu-devel
[Top][All Lists]
Advanced

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

Re: [PATCH v10 7/9] rust: add crate to expose bindings and interfaces


From: Paolo Bonzini
Subject: Re: [PATCH v10 7/9] rust: add crate to expose bindings and interfaces
Date: Mon, 30 Sep 2024 11:24:02 +0200
User-agent: Mozilla Thunderbird

On 9/10/24 14:35, Manos Pitsidianakis wrote:
+unsafe impl GlobalAlloc for QemuAllocator {
+    unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
+        if matches!(Self::DEFAULT_ALIGNMENT_BYTES, Some(default) if 
default.checked_rem(layout.align()) == Some(0))
+        {
+            g_malloc0(layout.size().try_into().unwrap()).cast::<u8>()
+        } else {
+            #[cfg(HAVE_GLIB_WITH_ALIGNED_ALLOC)]
+            {
+                g_aligned_alloc0(
+                    layout.size().try_into().unwrap(),
+                    1,
+                    (8 * layout.align()).try_into().unwrap(),
+                )
+                .cast::<u8>()
+            }
+            #[cfg(not(HAVE_GLIB_WITH_ALIGNED_ALLOC))]
+            {
+                qemu_memalign(8 * layout.align(), layout.size()).cast::<u8>()
+            }

The "8 *" is not needed in either case.

To be honest I'd simply drop the allocator code since you have to respin (see Junjie's answer). The DEFAULT_ALIGNMENT_BYTES trick is nice but I'm afraid it can be a source of hard-to-debug bugs.

Anyhow, I'll leave the choice to you as long as it's disabled by default, and I think with v11 everything should be ready.

Paolo




reply via email to

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