Skip to content

Commit f60c519

Browse files
committed
multiboot2: remove BoxedDst + run builder tests by Miri
1 parent 0e8c391 commit f60c519

File tree

11 files changed

+50
-216
lines changed

11 files changed

+50
-216
lines changed

multiboot2/src/boot_loader_name.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//! Module for [`BootLoaderNameTag`].
22
33
use crate::tag::TagHeader;
4-
use crate::{parse_slice_as_string, StringError, TagTrait, TagType};
4+
use crate::{new_boxed, parse_slice_as_string, StringError, TagTrait, TagType};
55
use core::fmt::{Debug, Formatter};
66
use core::mem;
77
#[cfg(feature = "builder")]
8-
use {crate::builder::BoxedDst, alloc::vec::Vec};
8+
use {alloc::boxed::Box, alloc::vec::Vec};
99

1010
const METADATA_SIZE: usize = mem::size_of::<TagHeader>();
1111

@@ -22,13 +22,13 @@ impl BootLoaderNameTag {
2222
/// Constructs a new tag.
2323
#[cfg(feature = "builder")]
2424
#[must_use]
25-
pub fn new(name: &str) -> BoxedDst<Self> {
25+
pub fn new(name: &str) -> Box<Self> {
2626
let mut bytes: Vec<_> = name.bytes().collect();
2727
if !bytes.ends_with(&[0]) {
2828
// terminating null-byte
2929
bytes.push(0);
3030
}
31-
BoxedDst::new(&bytes)
31+
new_boxed(&bytes)
3232
}
3333

3434
/// Returns the underlying [`TagType`].
@@ -94,7 +94,7 @@ mod tests {
9494
fn get_bytes() -> AlignedBytes<16> {
9595
AlignedBytes::new([
9696
TagType::BootLoaderName.val() as u8, 0, 0, 0,
97-
15, 0, 0, 0,
97+
14, 0, 0, 0,
9898
b'h', b'e', b'l', b'l', b'o', b'\0',
9999
/* padding */
100100
0, 0
@@ -115,11 +115,10 @@ mod tests {
115115
/// Test to generate a tag from a given string.
116116
#[test]
117117
#[cfg(feature = "builder")]
118-
#[ignore]
119118
fn test_build_str() {
120119
let tag = BootLoaderNameTag::new("hello");
121120
let bytes = tag.as_bytes();
122-
assert_eq!(bytes, &get_bytes()[..]);
121+
assert_eq!(bytes, &get_bytes()[..tag.size()]);
123122
assert_eq!(tag.name(), Ok("hello"));
124123

125124
// test also some bigger message

multiboot2/src/builder/boxed_dst.rs

Lines changed: 0 additions & 151 deletions
This file was deleted.

multiboot2/src/builder/information.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
//! Exports item [`InformationBuilder`].
2-
use crate::builder::{AsBytes, BoxedDst};
2+
use crate::builder::AsBytes;
33
use crate::util::increase_to_alignment;
44
use crate::{
55
BasicMemoryInfoTag, BootInformationHeader, BootLoaderNameTag, CommandLineTag,
66
EFIBootServicesNotExitedTag, EFIImageHandle32Tag, EFIImageHandle64Tag, EFIMemoryMapTag,
77
EFISdt32Tag, EFISdt64Tag, ElfSectionsTag, EndTag, FramebufferTag, ImageLoadPhysAddrTag,
8-
MemoryMapTag, ModuleTag, RsdpV1Tag, RsdpV2Tag, SmbiosTag, TagTrait, TagType,
8+
MemoryMapTag, ModuleTag, RsdpV1Tag, RsdpV2Tag, SmbiosTag, TagTrait, TagType, ALIGNMENT,
99
};
10+
use alloc::boxed::Box;
1011
use alloc::vec::Vec;
1112
use core::fmt::{Display, Formatter};
1213
use core::mem::size_of;
@@ -115,8 +116,6 @@ impl InformationBuilder {
115116
/// Constructs the bytes for a valid Multiboot2 information with the given properties.
116117
#[must_use]
117118
pub fn build(self) -> BootInformationBytes {
118-
const ALIGN: usize = 8;
119-
120119
// PHASE 1/2: Prepare Vector
121120

122121
// We allocate more than necessary so that we can ensure an correct
@@ -134,7 +133,7 @@ impl InformationBuilder {
134133
// Unfortunately, it is not possible to reliably test this in a unit
135134
// test as long as the allocator_api feature is not stable.
136135
// Due to my manual testing, however, it works.
137-
let offset = bytes.as_ptr().align_offset(ALIGN);
136+
let offset = bytes.as_ptr().align_offset(ALIGNMENT);
138137
bytes.extend([0].repeat(offset));
139138

140139
// -----------------------------------------------
@@ -182,6 +181,8 @@ impl InformationBuilder {
182181
.0
183182
.iter()
184183
.map(|(typ, _)| *typ)
184+
// TODO make a type for tag_is_allowed_multiple_times so that we can
185+
// link to it in the doc.
185186
.any(|typ| typ == T::ID && !Self::tag_is_allowed_multiple_times(typ));
186187

187188
if is_redundant_tag {
@@ -205,13 +206,13 @@ impl InformationBuilder {
205206

206207
/// Adds a 'bootloader name' tag (represented by [`BootLoaderNameTag`]) to the builder.
207208
#[must_use]
208-
pub fn bootloader_name_tag(self, tag: BoxedDst<BootLoaderNameTag>) -> Self {
209+
pub fn bootloader_name_tag(self, tag: Box<BootLoaderNameTag>) -> Self {
209210
self.add_tag(&*tag).unwrap()
210211
}
211212

212213
/// Adds a 'command line' tag (represented by [`CommandLineTag`]) to the builder.
213214
#[must_use]
214-
pub fn command_line_tag(self, tag: BoxedDst<CommandLineTag>) -> Self {
215+
pub fn command_line_tag(self, tag: Box<CommandLineTag>) -> Self {
215216
self.add_tag(&*tag).unwrap()
216217
}
217218

@@ -247,19 +248,19 @@ impl InformationBuilder {
247248

248249
/// Adds a 'EFI Memory map' tag (represented by [`EFIMemoryMapTag`]) to the builder.
249250
#[must_use]
250-
pub fn efi_memory_map_tag(self, tag: BoxedDst<EFIMemoryMapTag>) -> Self {
251+
pub fn efi_memory_map_tag(self, tag: Box<EFIMemoryMapTag>) -> Self {
251252
self.add_tag(&*tag).unwrap()
252253
}
253254

254255
/// Adds a 'ELF-Symbols' tag (represented by [`ElfSectionsTag`]) to the builder.
255256
#[must_use]
256-
pub fn elf_sections_tag(self, tag: BoxedDst<ElfSectionsTag>) -> Self {
257+
pub fn elf_sections_tag(self, tag: Box<ElfSectionsTag>) -> Self {
257258
self.add_tag(&*tag).unwrap()
258259
}
259260

260261
/// Adds a 'Framebuffer info' tag (represented by [`FramebufferTag`]) to the builder.
261262
#[must_use]
262-
pub fn framebuffer_tag(self, tag: BoxedDst<FramebufferTag>) -> Self {
263+
pub fn framebuffer_tag(self, tag: Box<FramebufferTag>) -> Self {
263264
self.add_tag(&*tag).unwrap()
264265
}
265266

@@ -271,14 +272,14 @@ impl InformationBuilder {
271272

272273
/// Adds a (*none EFI*) 'memory map' tag (represented by [`MemoryMapTag`]) to the builder.
273274
#[must_use]
274-
pub fn memory_map_tag(self, tag: BoxedDst<MemoryMapTag>) -> Self {
275+
pub fn memory_map_tag(self, tag: Box<MemoryMapTag>) -> Self {
275276
self.add_tag(&*tag).unwrap()
276277
}
277278

278279
/// Adds a 'Modules' tag (represented by [`ModuleTag`]) to the builder.
279280
/// This tag can occur multiple times in boot information.
280281
#[must_use]
281-
pub fn add_module_tag(self, tag: BoxedDst<ModuleTag>) -> Self {
282+
pub fn add_module_tag(self, tag: Box<ModuleTag>) -> Self {
282283
self.add_tag(&*tag).unwrap()
283284
}
284285

@@ -296,7 +297,7 @@ impl InformationBuilder {
296297

297298
/// Adds a 'SMBIOS tables' tag (represented by [`SmbiosTag`]) to the builder.
298299
#[must_use]
299-
pub fn smbios_tag(self, tag: BoxedDst<SmbiosTag>) -> Self {
300+
pub fn smbios_tag(self, tag: Box<SmbiosTag>) -> Self {
300301
self.add_tag(&*tag).unwrap()
301302
}
302303

@@ -309,7 +310,6 @@ impl InformationBuilder {
309310
}
310311

311312
#[cfg(test)]
312-
#[cfg(not(miri))]
313313
mod tests {
314314
use crate::builder::information::InformationBuilder;
315315
use crate::{BasicMemoryInfoTag, BootInformation, CommandLineTag, ModuleTag};
@@ -353,7 +353,6 @@ mod tests {
353353
}
354354

355355
#[test]
356-
#[cfg_attr(miri, ignore)]
357356
fn test_builder() {
358357
// Step 1/2: Build MBI
359358
let mb2i_data = create_builder().build();

multiboot2/src/builder/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
//! Module for the builder-feature.
22
3-
mod boxed_dst;
43
mod information;
54

6-
// This must be public to support external people to create boxed DSTs.
7-
pub use boxed_dst::BoxedDst;
85
pub use information::InformationBuilder;
96

107
/// Helper trait for all structs that need to be serialized that do not

multiboot2/src/command_line.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use core::fmt::{Debug, Formatter};
66
use core::mem;
77
use core::str;
88
#[cfg(feature = "builder")]
9-
use {crate::builder::BoxedDst, alloc::vec::Vec};
9+
use {crate::new_boxed, alloc::boxed::Box, alloc::vec::Vec};
1010

1111
const METADATA_SIZE: usize = mem::size_of::<TagHeader>();
1212

@@ -26,13 +26,13 @@ impl CommandLineTag {
2626
/// Create a new command line tag from the given string.
2727
#[cfg(feature = "builder")]
2828
#[must_use]
29-
pub fn new(command_line: &str) -> BoxedDst<Self> {
29+
pub fn new(command_line: &str) -> Box<Self> {
3030
let mut bytes: Vec<_> = command_line.bytes().collect();
3131
if !bytes.ends_with(&[0]) {
3232
// terminating null-byte
3333
bytes.push(0);
3434
}
35-
BoxedDst::new(&bytes)
35+
new_boxed(&bytes)
3636
}
3737

3838
/// Reads the command line of the kernel as Rust string slice without
@@ -109,11 +109,10 @@ mod tests {
109109
/// Test to generate a tag from a given string.
110110
#[test]
111111
#[cfg(feature = "builder")]
112-
#[ignore]
113112
fn test_build_str() {
114113
let tag = CommandLineTag::new("hello");
115114
let bytes = tag.as_bytes();
116-
assert_eq!(bytes, &get_bytes()[..]);
115+
assert_eq!(bytes, &get_bytes()[..tag.size()]);
117116
assert_eq!(tag.cmdline(), Ok("hello"));
118117

119118
// test also some bigger message

0 commit comments

Comments
 (0)