Skip to content

Commit 9a11495

Browse files
committed
multiboot2: simplify BoxedDst::new
1 parent 3d250eb commit 9a11495

File tree

13 files changed

+24
-24
lines changed

13 files changed

+24
-24
lines changed

multiboot2/Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
constant. This is only breaking to users that used `BootInformation::get_tag`
66
or that implement custom tags. `BootInformation::get_tag` doesn't need the
77
`typ` parameter anymore, as it can be deduced from the provided type.
8+
- **BREAKING** `BoxedDst::new` doesn't have the `typ` parameter anymore. This
9+
only effects you when you wrote a custom DST tag.
810

911
## 0.17.0 (2023-07-12)
1012
- **BREAKING** Make functions of `InformationBuilder` chainable. They now consume the builder.

multiboot2/src/boot_loader_name.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl BootLoaderNameTag {
2525
// terminating null-byte
2626
bytes.push(0);
2727
}
28-
BoxedDst::new(TagType::BootLoaderName, &bytes)
28+
BoxedDst::new(&bytes)
2929
}
3030

3131
/// Reads the name of the bootloader that is booting the kernel as Rust

multiboot2/src/builder/mod.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ impl<T: TagTrait<Metadata = usize> + ?Sized> BoxedDst<T> {
3535
/// Create a boxed tag with the given content.
3636
///
3737
/// # Parameters
38-
/// - `typ` - The given [`TagTypeId`]
3938
/// - `content` - All payload bytes of the DST tag without the tag type or
4039
/// the size. The memory is only read and can be discarded
4140
/// afterwards.
42-
pub(crate) fn new(typ: impl Into<TagTypeId>, content: &[u8]) -> Self {
41+
pub(crate) fn new(content: &[u8]) -> Self {
4342
// Currently, I do not find a nice way of making this dynamic so that
4443
// also miri is guaranteed to be happy. But it seems that 4 is fine
4544
// here. I do have control over allocation and deallocation.
@@ -63,7 +62,7 @@ impl<T: TagTrait<Metadata = usize> + ?Sized> BoxedDst<T> {
6362
unsafe {
6463
// write tag type
6564
let ptrx = ptr.cast::<TagTypeId>();
66-
ptrx.write(typ.into());
65+
ptrx.write(T::ID.into());
6766

6867
// write tag size
6968
let ptrx = ptrx.add(1).cast::<u32>();
@@ -139,11 +138,10 @@ mod tests {
139138

140139
#[test]
141140
fn test_boxed_dst_tag() {
142-
let tag_type_id = 1337_u32;
143141
let content = "hallo";
144142

145-
let tag = BoxedDst::<CustomTag>::new(tag_type_id, content.as_bytes());
146-
assert_eq!(tag.typ, tag_type_id);
143+
let tag = BoxedDst::<CustomTag>::new(content.as_bytes());
144+
assert_eq!(tag.typ, CustomTag::ID);
147145
assert_eq!(tag.size as usize, METADATA_SIZE + content.len());
148146
assert_eq!(tag.string(), Ok(content));
149147
}

multiboot2/src/command_line.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl CommandLineTag {
3333
// terminating null-byte
3434
bytes.push(0);
3535
}
36-
BoxedDst::new(TagType::Cmdline, &bytes)
36+
BoxedDst::new(&bytes)
3737
}
3838

3939
/// Reads the command line of the kernel as Rust string slice without

multiboot2/src/efi.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl EFISdt32Tag {
1818
/// Create a new tag to pass the EFI32 System Table pointer.
1919
pub fn new(pointer: u32) -> Self {
2020
Self {
21-
typ: TagType::Efi32.into(),
21+
typ: Self::ID.into(),
2222
size: size_of::<Self>().try_into().unwrap(),
2323
pointer,
2424
}
@@ -49,7 +49,7 @@ impl EFISdt64Tag {
4949
/// Create a new tag to pass the EFI64 System Table pointer.
5050
pub fn new(pointer: u64) -> Self {
5151
Self {
52-
typ: TagType::Efi64.into(),
52+
typ: Self::ID.into(),
5353
size: size_of::<Self>().try_into().unwrap(),
5454
pointer,
5555
}
@@ -81,7 +81,7 @@ impl EFIImageHandle32Tag {
8181
#[cfg(feature = "builder")]
8282
pub fn new(pointer: u32) -> Self {
8383
Self {
84-
typ: TagType::Efi32Ih.into(),
84+
typ: Self::ID.into(),
8585
size: size_of::<Self>().try_into().unwrap(),
8686
pointer,
8787
}
@@ -113,7 +113,7 @@ impl EFIImageHandle64Tag {
113113
#[cfg(feature = "builder")]
114114
pub fn new(pointer: u64) -> Self {
115115
Self {
116-
typ: TagType::Efi64Ih.into(),
116+
typ: Self::ID.into(),
117117
size: size_of::<Self>().try_into().unwrap(),
118118
pointer,
119119
}

multiboot2/src/elf_sections.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl ElfSectionsTag {
3737
]
3838
.concat();
3939
bytes.extend_from_slice(sections);
40-
BoxedDst::new(TagType::ElfSections, &bytes)
40+
BoxedDst::new(&bytes)
4141
}
4242

4343
/// Get an iterator of loaded ELF sections.

multiboot2/src/framebuffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl FramebufferTag {
9797
bytes.extend(height.to_le_bytes());
9898
bytes.extend(bpp.to_le_bytes());
9999
bytes.extend(buffer_type.to_bytes());
100-
BoxedDst::new(TagType::Framebuffer, &bytes)
100+
BoxedDst::new(&bytes)
101101
}
102102

103103
/// Contains framebuffer physical address.

multiboot2/src/image_load_addr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl ImageLoadPhysAddrTag {
1717
#[cfg(feature = "builder")]
1818
pub fn new(load_base_addr: u32) -> Self {
1919
Self {
20-
typ: TagType::ImageLoadPhysAddr.into(),
20+
typ: Self::ID.into(),
2121
size: size_of::<Self>().try_into().unwrap(),
2222
load_base_addr,
2323
}
@@ -30,7 +30,7 @@ impl ImageLoadPhysAddrTag {
3030
}
3131

3232
impl TagTrait for ImageLoadPhysAddrTag {
33-
const ID: TagType = TagType::ImageLoadPhysAddr;
33+
const ID: TagType = TagType::LoadBaseAddr;
3434

3535
fn dst_size(_base_tag: &Tag) {}
3636
}

multiboot2/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ impl fmt::Debug for BootInformation<'_> {
526526
///
527527
/// # Trivia
528528
/// This crate uses the [`Pointee`]-abstraction of the [`ptr_meta`] crate to
529-
/// create fat pointers.
529+
/// create fat pointers for tags that are DST.
530530
pub trait TagTrait: Pointee {
531531
/// The numeric ID of this tag.
532532
const ID: TagType;

multiboot2/src/memory_map.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl MemoryMapTag {
4040
for area in areas {
4141
bytes.extend(area.as_bytes());
4242
}
43-
BoxedDst::new(TagType::Mmap, bytes.as_slice())
43+
BoxedDst::new(bytes.as_slice())
4444
}
4545

4646
/// Returns the entry size.
@@ -239,7 +239,7 @@ pub struct BasicMemoryInfoTag {
239239
impl BasicMemoryInfoTag {
240240
pub fn new(memory_lower: u32, memory_upper: u32) -> Self {
241241
Self {
242-
typ: TagType::BasicMeminfo.into(),
242+
typ: Self::ID.into(),
243243
size: mem::size_of::<BasicMemoryInfoTag>().try_into().unwrap(),
244244
memory_lower,
245245
memory_upper,
@@ -293,7 +293,7 @@ impl EFIMemoryMapTag {
293293
for desc in descs {
294294
bytes.extend(desc.as_bytes());
295295
}
296-
BoxedDst::new(TagType::EfiMmap, bytes.as_slice())
296+
BoxedDst::new(bytes.as_slice())
297297
}
298298

299299
/// Return an iterator over ALL marked memory areas.

0 commit comments

Comments
 (0)