Browse Source

multiboot2: remove BoxedDst + run builder tests by Miri

Philipp Schuster 8 months ago
parent
commit
e5cccec259

+ 6 - 7
multiboot2/src/boot_loader_name.rs

@@ -1,11 +1,11 @@
 //! Module for [`BootLoaderNameTag`].
 
 use crate::tag::TagHeader;
-use crate::{parse_slice_as_string, StringError, TagTrait, TagType};
+use crate::{new_boxed, parse_slice_as_string, StringError, TagTrait, TagType};
 use core::fmt::{Debug, Formatter};
 use core::mem;
 #[cfg(feature = "builder")]
-use {crate::builder::BoxedDst, alloc::vec::Vec};
+use {alloc::boxed::Box, alloc::vec::Vec};
 
 const METADATA_SIZE: usize = mem::size_of::<TagHeader>();
 
@@ -22,13 +22,13 @@ impl BootLoaderNameTag {
     /// Constructs a new tag.
     #[cfg(feature = "builder")]
     #[must_use]
-    pub fn new(name: &str) -> BoxedDst<Self> {
+    pub fn new(name: &str) -> Box<Self> {
         let mut bytes: Vec<_> = name.bytes().collect();
         if !bytes.ends_with(&[0]) {
             // terminating null-byte
             bytes.push(0);
         }
-        BoxedDst::new(&bytes)
+        new_boxed(&bytes)
     }
 
     /// Returns the underlying [`TagType`].
@@ -94,7 +94,7 @@ mod tests {
     fn get_bytes() -> AlignedBytes<16> {
         AlignedBytes::new([
             TagType::BootLoaderName.val() as u8, 0, 0, 0,
-            15, 0, 0, 0,
+            14, 0, 0, 0,
             b'h', b'e', b'l', b'l', b'o', b'\0',
             /* padding */
             0, 0
@@ -115,11 +115,10 @@ mod tests {
     /// Test to generate a tag from a given string.
     #[test]
     #[cfg(feature = "builder")]
-    #[ignore]
     fn test_build_str() {
         let tag = BootLoaderNameTag::new("hello");
         let bytes = tag.as_bytes();
-        assert_eq!(bytes, &get_bytes()[..]);
+        assert_eq!(bytes, &get_bytes()[..tag.size()]);
         assert_eq!(tag.name(), Ok("hello"));
 
         // test also some bigger message

+ 0 - 151
multiboot2/src/builder/boxed_dst.rs

@@ -1,151 +0,0 @@
-//! Module for [`BoxedDst`].
-
-use crate::util::increase_to_alignment;
-use crate::{TagHeader, TagTrait, TagTypeId};
-use alloc::alloc::alloc;
-use core::alloc::Layout;
-use core::marker::PhantomData;
-use core::mem::size_of;
-use core::ops::Deref;
-use core::ptr::NonNull;
-
-/// A helper type to create boxed DST, i.e., tags with a dynamic size for the
-/// builder. This is tricky in Rust. This type behaves similar to the regular
-/// `Box` type except that it ensure the same layout is used for the (explicit)
-/// allocation and the (implicit) deallocation of memory. Otherwise, I didn't
-/// find any way to figure out the right layout for a DST. Miri always reported
-/// issues that the deallocation used a wrong layout.
-///
-/// Technically, I'm certain this code is memory safe. But with this type, I
-/// also can convince miri that it is.
-#[derive(Debug, Eq)]
-pub struct BoxedDst<T: ?Sized> {
-    ptr: core::ptr::NonNull<T>,
-    layout: Layout,
-    // marker: I used this only as the regular Box impl also does it.
-    _marker: PhantomData<T>,
-}
-
-impl<T: TagTrait<Metadata = usize> + ?Sized> BoxedDst<T> {
-    /// Create a boxed tag with the given content.
-    ///
-    /// # Parameters
-    /// - `content` - All payload bytes of the DST tag without the tag type or
-    ///               the size. The memory is only read and can be discarded
-    ///               afterwards.
-    pub(crate) fn new(content: &[u8]) -> Self {
-        // Currently, I do not find a nice way of making this dynamic so that
-        // also miri is guaranteed to be happy. But it seems that 4 is fine
-        // here. I do have control over allocation and deallocation.
-        const ALIGN: usize = 4;
-
-        let tag_size = size_of::<TagTypeId>() + size_of::<u32>() + content.len();
-
-        // The size of [the allocation for] a value is always a multiple of its
-        // alignment.
-        // https://doc.rust-lang.org/reference/type-layout.html
-        let alloc_size = increase_to_alignment(tag_size);
-        let layout = Layout::from_size_align(alloc_size, ALIGN).unwrap();
-        let ptr = unsafe { alloc(layout) };
-        assert!(!ptr.is_null());
-
-        // write tag content to memory
-        unsafe {
-            // write tag type
-            let ptrx = ptr.cast::<TagTypeId>();
-            ptrx.write(T::ID.into());
-
-            // write tag size
-            let ptrx = ptrx.add(1).cast::<u32>();
-            ptrx.write(tag_size as u32);
-
-            // write rest of content
-            let ptrx = ptrx.add(1).cast::<u8>();
-            let tag_content_slice = core::slice::from_raw_parts_mut(ptrx, content.len());
-            for (i, &byte) in content.iter().enumerate() {
-                tag_content_slice[i] = byte;
-            }
-        }
-
-        let base_tag = unsafe { &*ptr.cast::<TagHeader>() };
-        let raw: *mut T = ptr_meta::from_raw_parts_mut(ptr.cast(), T::dst_len(base_tag));
-
-        Self {
-            ptr: NonNull::new(raw).unwrap(),
-            layout,
-            _marker: PhantomData,
-        }
-    }
-}
-
-impl<T: ?Sized> Drop for BoxedDst<T> {
-    fn drop(&mut self) {
-        unsafe { alloc::alloc::dealloc(self.ptr.as_ptr().cast(), self.layout) }
-    }
-}
-
-impl<T: ?Sized> Deref for BoxedDst<T> {
-    type Target = T;
-    fn deref(&self) -> &Self::Target {
-        unsafe { self.ptr.as_ref() }
-    }
-}
-
-impl<T: ?Sized + PartialEq> PartialEq for BoxedDst<T> {
-    fn eq(&self, other: &Self) -> bool {
-        self.deref().eq(other.deref())
-    }
-}
-
-#[cfg(test)]
-#[cfg(not(miri))]
-mod tests {
-    use super::*;
-    use crate::test_util::AlignedBytes;
-    use crate::{parse_slice_as_string, StringError, TagHeader, TagType};
-    use core::borrow::Borrow;
-
-    const METADATA_SIZE: usize = 8;
-
-    #[derive(ptr_meta::Pointee)]
-    #[repr(C)]
-    struct CustomTag {
-        typ: TagTypeId,
-        size: u32,
-        string: [u8],
-    }
-
-    impl CustomTag {
-        fn string(&self) -> Result<&str, StringError> {
-            parse_slice_as_string(&self.string)
-        }
-    }
-
-    impl TagTrait for CustomTag {
-        const ID: TagType = TagType::Custom(0x1337);
-
-        fn dst_len(header: &TagHeader) -> usize {
-            assert!(header.size as usize >= METADATA_SIZE);
-            header.size as usize - METADATA_SIZE
-        }
-    }
-
-    #[test]
-    fn test_boxed_dst_tag() {
-        let content = AlignedBytes::new(*b"hallo\0");
-        let content_rust_str = "hallo";
-        let tag = BoxedDst::<CustomTag>::new(content.borrow());
-        assert_eq!(tag.typ, CustomTag::ID);
-        assert_eq!(tag.size as usize, METADATA_SIZE + content.len());
-        assert_eq!(tag.string(), Ok(content_rust_str));
-    }
-
-    #[test]
-    fn can_hold_tag_trait() {
-        const fn consume<T: TagTrait + ?Sized>(_: &T) {}
-        let content = AlignedBytes::new(*b"hallo\0");
-        let tag = BoxedDst::<CustomTag>::new(content.borrow());
-        consume(tag.deref());
-        consume(&*tag);
-    }
-}

+ 14 - 15
multiboot2/src/builder/information.rs

@@ -1,12 +1,13 @@
 //! Exports item [`InformationBuilder`].
-use crate::builder::{AsBytes, BoxedDst};
+use crate::builder::AsBytes;
 use crate::util::increase_to_alignment;
 use crate::{
     BasicMemoryInfoTag, BootInformationHeader, BootLoaderNameTag, CommandLineTag,
     EFIBootServicesNotExitedTag, EFIImageHandle32Tag, EFIImageHandle64Tag, EFIMemoryMapTag,
     EFISdt32Tag, EFISdt64Tag, ElfSectionsTag, EndTag, FramebufferTag, ImageLoadPhysAddrTag,
-    MemoryMapTag, ModuleTag, RsdpV1Tag, RsdpV2Tag, SmbiosTag, TagTrait, TagType,
+    MemoryMapTag, ModuleTag, RsdpV1Tag, RsdpV2Tag, SmbiosTag, TagTrait, TagType, ALIGNMENT,
 };
+use alloc::boxed::Box;
 use alloc::vec::Vec;
 use core::fmt::{Display, Formatter};
 use core::mem::size_of;
@@ -115,8 +116,6 @@ impl InformationBuilder {
     /// Constructs the bytes for a valid Multiboot2 information with the given properties.
     #[must_use]
     pub fn build(self) -> BootInformationBytes {
-        const ALIGN: usize = 8;
-
         // PHASE 1/2: Prepare Vector
 
         // We allocate more than necessary so that we can ensure an correct
@@ -134,7 +133,7 @@ impl InformationBuilder {
         // Unfortunately, it is not possible to reliably test this in a unit
         // test as long as the allocator_api feature is not stable.
         // Due to my manual testing, however, it works.
-        let offset = bytes.as_ptr().align_offset(ALIGN);
+        let offset = bytes.as_ptr().align_offset(ALIGNMENT);
         bytes.extend([0].repeat(offset));
 
         // -----------------------------------------------
@@ -182,6 +181,8 @@ impl InformationBuilder {
             .0
             .iter()
             .map(|(typ, _)| *typ)
+            // TODO make a type for tag_is_allowed_multiple_times so that we can
+            // link to it in the doc.
             .any(|typ| typ == T::ID && !Self::tag_is_allowed_multiple_times(typ));
 
         if is_redundant_tag {
@@ -205,13 +206,13 @@ impl InformationBuilder {
 
     /// Adds a 'bootloader name' tag (represented by [`BootLoaderNameTag`]) to the builder.
     #[must_use]
-    pub fn bootloader_name_tag(self, tag: BoxedDst<BootLoaderNameTag>) -> Self {
+    pub fn bootloader_name_tag(self, tag: Box<BootLoaderNameTag>) -> Self {
         self.add_tag(&*tag).unwrap()
     }
 
     /// Adds a 'command line' tag (represented by [`CommandLineTag`]) to the builder.
     #[must_use]
-    pub fn command_line_tag(self, tag: BoxedDst<CommandLineTag>) -> Self {
+    pub fn command_line_tag(self, tag: Box<CommandLineTag>) -> Self {
         self.add_tag(&*tag).unwrap()
     }
 
@@ -247,19 +248,19 @@ impl InformationBuilder {
 
     /// Adds a 'EFI Memory map' tag (represented by [`EFIMemoryMapTag`]) to the builder.
     #[must_use]
-    pub fn efi_memory_map_tag(self, tag: BoxedDst<EFIMemoryMapTag>) -> Self {
+    pub fn efi_memory_map_tag(self, tag: Box<EFIMemoryMapTag>) -> Self {
         self.add_tag(&*tag).unwrap()
     }
 
     /// Adds a 'ELF-Symbols' tag (represented by [`ElfSectionsTag`]) to the builder.
     #[must_use]
-    pub fn elf_sections_tag(self, tag: BoxedDst<ElfSectionsTag>) -> Self {
+    pub fn elf_sections_tag(self, tag: Box<ElfSectionsTag>) -> Self {
         self.add_tag(&*tag).unwrap()
     }
 
     /// Adds a 'Framebuffer info' tag (represented by [`FramebufferTag`]) to the builder.
     #[must_use]
-    pub fn framebuffer_tag(self, tag: BoxedDst<FramebufferTag>) -> Self {
+    pub fn framebuffer_tag(self, tag: Box<FramebufferTag>) -> Self {
         self.add_tag(&*tag).unwrap()
     }
 
@@ -271,14 +272,14 @@ impl InformationBuilder {
 
     /// Adds a (*none EFI*) 'memory map' tag (represented by [`MemoryMapTag`]) to the builder.
     #[must_use]
-    pub fn memory_map_tag(self, tag: BoxedDst<MemoryMapTag>) -> Self {
+    pub fn memory_map_tag(self, tag: Box<MemoryMapTag>) -> Self {
         self.add_tag(&*tag).unwrap()
     }
 
     /// Adds a 'Modules' tag (represented by [`ModuleTag`]) to the builder.
     /// This tag can occur multiple times in boot information.
     #[must_use]
-    pub fn add_module_tag(self, tag: BoxedDst<ModuleTag>) -> Self {
+    pub fn add_module_tag(self, tag: Box<ModuleTag>) -> Self {
         self.add_tag(&*tag).unwrap()
     }
 
@@ -296,7 +297,7 @@ impl InformationBuilder {
 
     /// Adds a 'SMBIOS tables' tag (represented by [`SmbiosTag`]) to the builder.
     #[must_use]
-    pub fn smbios_tag(self, tag: BoxedDst<SmbiosTag>) -> Self {
+    pub fn smbios_tag(self, tag: Box<SmbiosTag>) -> Self {
         self.add_tag(&*tag).unwrap()
     }
 
@@ -309,7 +310,6 @@ impl InformationBuilder {
 }
 
 #[cfg(test)]
-#[cfg(not(miri))]
 mod tests {
     use crate::builder::information::InformationBuilder;
     use crate::{BasicMemoryInfoTag, BootInformation, CommandLineTag, ModuleTag};
@@ -353,7 +353,6 @@ mod tests {
     }
 
     #[test]
-    #[cfg_attr(miri, ignore)]
     fn test_builder() {
         // Step 1/2: Build MBI
         let mb2i_data = create_builder().build();

+ 0 - 3
multiboot2/src/builder/mod.rs

@@ -1,10 +1,7 @@
 //! Module for the builder-feature.
 
-mod boxed_dst;
 mod information;
 
-// This must be public to support external people to create boxed DSTs.
-pub use boxed_dst::BoxedDst;
 pub use information::InformationBuilder;
 
 /// Helper trait for all structs that need to be serialized that do not

+ 4 - 5
multiboot2/src/command_line.rs

@@ -6,7 +6,7 @@ use core::fmt::{Debug, Formatter};
 use core::mem;
 use core::str;
 #[cfg(feature = "builder")]
-use {crate::builder::BoxedDst, alloc::vec::Vec};
+use {crate::new_boxed, alloc::boxed::Box, alloc::vec::Vec};
 
 const METADATA_SIZE: usize = mem::size_of::<TagHeader>();
 
@@ -26,13 +26,13 @@ impl CommandLineTag {
     /// Create a new command line tag from the given string.
     #[cfg(feature = "builder")]
     #[must_use]
-    pub fn new(command_line: &str) -> BoxedDst<Self> {
+    pub fn new(command_line: &str) -> Box<Self> {
         let mut bytes: Vec<_> = command_line.bytes().collect();
         if !bytes.ends_with(&[0]) {
             // terminating null-byte
             bytes.push(0);
         }
-        BoxedDst::new(&bytes)
+        new_boxed(&bytes)
     }
 
     /// Reads the command line of the kernel as Rust string slice without
@@ -109,11 +109,10 @@ mod tests {
     /// Test to generate a tag from a given string.
     #[test]
     #[cfg(feature = "builder")]
-    #[ignore]
     fn test_build_str() {
         let tag = CommandLineTag::new("hello");
         let bytes = tag.as_bytes();
-        assert_eq!(bytes, &get_bytes()[..]);
+        assert_eq!(bytes, &get_bytes()[..tag.size()]);
         assert_eq!(tag.cmdline(), Ok("hello"));
 
         // test also some bigger message

+ 4 - 9
multiboot2/src/elf_sections.rs

@@ -1,11 +1,11 @@
 //! Module for [`ElfSectionsTag`].
 
-#[cfg(feature = "builder")]
-use crate::builder::BoxedDst;
 use crate::{TagHeader, TagTrait, TagType};
 use core::fmt::{Debug, Formatter};
 use core::mem;
 use core::str::Utf8Error;
+#[cfg(feature = "builder")]
+use {crate::new_boxed, alloc::boxed::Box};
 
 const METADATA_SIZE: usize = mem::size_of::<TagHeader>() + 3 * mem::size_of::<u32>();
 
@@ -26,12 +26,7 @@ impl ElfSectionsTag {
     /// Create a new ElfSectionsTag with the given data.
     #[cfg(feature = "builder")]
     #[must_use]
-    pub fn new(
-        number_of_sections: u32,
-        entry_size: u32,
-        shndx: u32,
-        sections: &[u8],
-    ) -> BoxedDst<Self> {
+    pub fn new(number_of_sections: u32, entry_size: u32, shndx: u32, sections: &[u8]) -> Box<Self> {
         let mut bytes = [
             number_of_sections.to_le_bytes(),
             entry_size.to_le_bytes(),
@@ -39,7 +34,7 @@ impl ElfSectionsTag {
         ]
         .concat();
         bytes.extend_from_slice(sections);
-        BoxedDst::new(&bytes)
+        new_boxed(&bytes)
     }
 
     /// Get an iterator of loaded ELF sections.

+ 3 - 3
multiboot2/src/framebuffer.rs

@@ -7,7 +7,7 @@ use core::mem;
 use core::slice;
 use derive_more::Display;
 #[cfg(feature = "builder")]
-use {crate::builder::AsBytes, crate::builder::BoxedDst, alloc::vec::Vec};
+use {crate::builder::AsBytes, crate::new_boxed, alloc::boxed::Box, alloc::vec::Vec};
 
 /// Helper struct to read bytes from a raw pointer and increase the pointer
 /// automatically.
@@ -94,14 +94,14 @@ impl FramebufferTag {
         height: u32,
         bpp: u8,
         buffer_type: FramebufferType,
-    ) -> BoxedDst<Self> {
+    ) -> Box<Self> {
         let mut bytes: Vec<u8> = address.to_le_bytes().into();
         bytes.extend(pitch.to_le_bytes());
         bytes.extend(width.to_le_bytes());
         bytes.extend(height.to_le_bytes());
         bytes.extend(bpp.to_le_bytes());
         bytes.extend(buffer_type.to_bytes());
-        BoxedDst::new(&bytes)
+        new_boxed(&bytes)
     }
 
     /// Contains framebuffer physical address.

+ 3 - 5
multiboot2/src/lib.rs

@@ -298,6 +298,7 @@ mod tests {
     }
 
     #[test]
+    #[cfg_attr(miri, ignore)]
     fn framebuffer_tag_indexed() {
         // indexed mode test:
         // this is synthetic, as I can't get QEMU
@@ -1056,10 +1057,7 @@ mod tests {
         assert_eq!(desc.phys_start, 0x100000);
         assert_eq!(desc.page_count, 4);
         assert_eq!(desc.ty, EFIMemoryAreaType::CONVENTIONAL);
-        // test that the EFI memory map is not detected if the boot services
-        // are not exited.
-        struct Bytes2([u8; 80]);
-        let bytes2: Bytes2 = Bytes2([
+        let bytes2 = AlignedBytes([
             80, 0, 0, 0, // size
             0, 0, 0, 0, // reserved
             17, 0, 0, 0, // EFI memory map type
@@ -1081,7 +1079,7 @@ mod tests {
             0, 0, 0, 0, // end tag type.
             8, 0, 0, 0, // end tag size.
         ]);
-        let bi = unsafe { BootInformation::load(bytes2.0.as_ptr().cast()) };
+        let bi = unsafe { BootInformation::load(bytes2.as_ptr().cast()) };
         let bi = bi.unwrap();
         let efi_mmap = bi.efi_memory_map_tag();
         assert!(efi_mmap.is_none());

+ 7 - 7
multiboot2/src/memory_map.rs

@@ -11,7 +11,7 @@ use core::fmt::{Debug, Formatter};
 use core::marker::PhantomData;
 use core::mem;
 #[cfg(feature = "builder")]
-use {crate::builder::AsBytes, crate::builder::BoxedDst};
+use {crate::builder::AsBytes, crate::new_boxed, alloc::boxed::Box};
 
 const METADATA_SIZE: usize = mem::size_of::<TagHeader>() + 2 * mem::size_of::<u32>();
 
@@ -38,14 +38,14 @@ impl MemoryMapTag {
     /// Constructs a new tag.
     #[cfg(feature = "builder")]
     #[must_use]
-    pub fn new(areas: &[MemoryArea]) -> BoxedDst<Self> {
+    pub fn new(areas: &[MemoryArea]) -> Box<Self> {
         let entry_size: u32 = mem::size_of::<MemoryArea>().try_into().unwrap();
         let entry_version: u32 = 0;
         let mut bytes = [entry_size.to_le_bytes(), entry_version.to_le_bytes()].concat();
         for area in areas {
             bytes.extend(area.as_bytes());
         }
-        BoxedDst::new(bytes.as_slice())
+        new_boxed(bytes.as_slice())
     }
 
     /// Returns the entry size.
@@ -326,7 +326,7 @@ impl EFIMemoryMapTag {
     /// EFIMemoryDescs, not the ones you might have gotten from the firmware.
     #[cfg(feature = "builder")]
     #[must_use]
-    pub fn new_from_descs(descs: &[EFIMemoryDesc]) -> BoxedDst<Self> {
+    pub fn new_from_descs(descs: &[EFIMemoryDesc]) -> Box<Self> {
         // TODO replace this EfiMemorydesc::uefi_desc_size() in the next uefi_raw
         // release.
 
@@ -354,7 +354,7 @@ impl EFIMemoryMapTag {
     /// Create a new EFI memory map tag from the given EFI memory map.
     #[cfg(feature = "builder")]
     #[must_use]
-    pub fn new_from_map(desc_size: u32, desc_version: u32, efi_mmap: &[u8]) -> BoxedDst<Self> {
+    pub fn new_from_map(desc_size: u32, desc_version: u32, efi_mmap: &[u8]) -> Box<Self> {
         assert!(desc_size > 0);
         assert_eq!(efi_mmap.len() % desc_size as usize, 0);
         assert_eq!(
@@ -369,7 +369,7 @@ impl EFIMemoryMapTag {
             efi_mmap,
         ]
         .concat();
-        BoxedDst::new(&bytes)
+        new_boxed(&bytes)
     }
 
     /// Returns an iterator over the provided memory areas.
@@ -466,7 +466,7 @@ impl<'a> ExactSizeIterator for EFIMemoryAreaIter<'a> {
     }
 }
 
-#[cfg(all(test, feature = "builder", not(miri)))]
+#[cfg(all(test, feature = "builder"))]
 mod tests {
     use super::*;
     use std::mem::size_of;

+ 4 - 5
multiboot2/src/module.rs

@@ -5,7 +5,7 @@ use crate::{parse_slice_as_string, StringError, TagTrait, TagType};
 use core::fmt::{Debug, Formatter};
 use core::mem;
 #[cfg(feature = "builder")]
-use {crate::builder::BoxedDst, alloc::vec::Vec};
+use {crate::new_boxed, alloc::boxed::Box, alloc::vec::Vec};
 
 const METADATA_SIZE: usize = mem::size_of::<TagHeader>() + 2 * mem::size_of::<u32>();
 
@@ -26,7 +26,7 @@ impl ModuleTag {
     /// Constructs a new tag.
     #[cfg(feature = "builder")]
     #[must_use]
-    pub fn new(start: u32, end: u32, cmdline: &str) -> BoxedDst<Self> {
+    pub fn new(start: u32, end: u32, cmdline: &str) -> Box<Self> {
         assert!(end > start, "must have a size");
 
         let mut cmdline_bytes: Vec<_> = cmdline.bytes().collect();
@@ -38,7 +38,7 @@ impl ModuleTag {
         let end_bytes = end.to_le_bytes();
         let mut content_bytes = [start_bytes, end_bytes].concat();
         content_bytes.extend_from_slice(&cmdline_bytes);
-        BoxedDst::new(&content_bytes)
+        new_boxed(&content_bytes)
     }
 
     /// Reads the command line of the boot module as Rust string slice without
@@ -161,11 +161,10 @@ mod tests {
     /// Test to generate a tag from a given string.
     #[test]
     #[cfg(feature = "builder")]
-    #[ignore]
     fn test_build_str() {
         let tag = ModuleTag::new(0xff00, 0xffff, "hello");
         let bytes = tag.as_bytes();
-        assert_eq!(bytes, &get_bytes()[..]);
+        assert_eq!(bytes, &get_bytes()[..tag.size()]);
         assert_eq!(tag.cmdline(), Ok("hello"));
 
         // test also some bigger message

+ 5 - 6
multiboot2/src/smbios.rs

@@ -1,11 +1,11 @@
 //! Module for [`SmbiosTag`].
 
-#[cfg(feature = "builder")]
-use crate::builder::BoxedDst;
 use crate::tag::TagHeader;
 use crate::{TagTrait, TagType};
 use core::fmt::Debug;
 use core::mem;
+#[cfg(feature = "builder")]
+use {crate::new_boxed, alloc::boxed::Box};
 
 const METADATA_SIZE: usize = mem::size_of::<TagHeader>() + mem::size_of::<u8>() * 8;
 
@@ -24,10 +24,10 @@ impl SmbiosTag {
     /// Constructs a new tag.
     #[cfg(feature = "builder")]
     #[must_use]
-    pub fn new(major: u8, minor: u8, tables: &[u8]) -> BoxedDst<Self> {
+    pub fn new(major: u8, minor: u8, tables: &[u8]) -> Box<Self> {
         let mut bytes = [major, minor, 0, 0, 0, 0, 0, 0].to_vec();
         bytes.extend(tables);
-        BoxedDst::new(&bytes)
+        new_boxed(&bytes)
     }
 
     /// Returns the major number.
@@ -109,10 +109,9 @@ mod tests {
     /// Test to generate a tag.
     #[test]
     #[cfg(feature = "builder")]
-    #[ignore]
     fn test_build() {
         let tag = SmbiosTag::new(7, 42, &[0, 1, 2, 3, 4, 5, 6, 7, 8]);
         let bytes = tag.as_bytes();
-        assert_eq!(bytes, &get_bytes()[..]);
+        assert_eq!(bytes, &get_bytes()[..tag.size()]);
     }
 }