Parcourir la source

multiboot2: boxed_dst_tag: don't be too strict about allocation size

I don't exactly understand why, but running this in the integration test
revealed a different behaviour compared to the unit test. In the unit test
environment, it always seemed like the next multiple of 8 is used for each
allocation as size. In the integration test, I did not encounter this. I
don't know what's the best solution here. Probably, just don't be too
strict.
Philipp Schuster il y a 1 an
Parent
commit
4d0e1668e3
1 fichiers modifiés avec 2 ajouts et 7 suppressions
  1. 2 7
      multiboot2/src/builder/mod.rs

+ 2 - 7
multiboot2/src/builder/mod.rs

@@ -8,7 +8,7 @@ pub use information::InformationBuilder;
 use alloc::alloc::alloc;
 use alloc::boxed::Box;
 use core::alloc::Layout;
-use core::mem::{align_of_val, size_of, size_of_val};
+use core::mem::{align_of_val, size_of};
 use core::ops::Deref;
 
 use crate::{Tag, TagTrait, TagTypeId};
@@ -28,11 +28,7 @@ pub(super) fn boxed_dst_tag<T: TagTrait<Metadata = usize> + ?Sized>(
     const ALIGN: usize = 4;
 
     let tag_size = size_of::<TagTypeId>() + size_of::<u32>() + content.len();
-    // round up to the next multiple of 8
-    // Rust uses this convention for all types. I found out so by checking
-    // miris output of the corresponding unit test.
-    let alloc_size = (tag_size + 7) & !0b111;
-    let layout = Layout::from_size_align(alloc_size, ALIGN).unwrap();
+    let layout = Layout::from_size_align(tag_size, ALIGN).unwrap();
     let ptr = unsafe { alloc(layout) };
     assert!(!ptr.is_null());
 
@@ -61,7 +57,6 @@ pub(super) fn boxed_dst_tag<T: TagTrait<Metadata = usize> + ?Sized>(
         let boxed = Box::from_raw(raw);
         let reference: &T = boxed.deref();
         // If this panics, please create an issue on GitHub.
-        assert_eq!(size_of_val(reference), alloc_size);
         assert_eq!(align_of_val(reference), ALIGN);
         boxed
     }