Skip to content

Commit 4d0e166

Browse files
committed
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.
1 parent 026ae56 commit 4d0e166

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

multiboot2/src/builder/mod.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub use information::InformationBuilder;
88
use alloc::alloc::alloc;
99
use alloc::boxed::Box;
1010
use core::alloc::Layout;
11-
use core::mem::{align_of_val, size_of, size_of_val};
11+
use core::mem::{align_of_val, size_of};
1212
use core::ops::Deref;
1313

1414
use crate::{Tag, TagTrait, TagTypeId};
@@ -28,11 +28,7 @@ pub(super) fn boxed_dst_tag<T: TagTrait<Metadata = usize> + ?Sized>(
2828
const ALIGN: usize = 4;
2929

3030
let tag_size = size_of::<TagTypeId>() + size_of::<u32>() + content.len();
31-
// round up to the next multiple of 8
32-
// Rust uses this convention for all types. I found out so by checking
33-
// miris output of the corresponding unit test.
34-
let alloc_size = (tag_size + 7) & !0b111;
35-
let layout = Layout::from_size_align(alloc_size, ALIGN).unwrap();
31+
let layout = Layout::from_size_align(tag_size, ALIGN).unwrap();
3632
let ptr = unsafe { alloc(layout) };
3733
assert!(!ptr.is_null());
3834

@@ -61,7 +57,6 @@ pub(super) fn boxed_dst_tag<T: TagTrait<Metadata = usize> + ?Sized>(
6157
let boxed = Box::from_raw(raw);
6258
let reference: &T = boxed.deref();
6359
// If this panics, please create an issue on GitHub.
64-
assert_eq!(size_of_val(reference), alloc_size);
6560
assert_eq!(align_of_val(reference), ALIGN);
6661
boxed
6762
}

0 commit comments

Comments
 (0)