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