Skip to content

Commit 53af759

Browse files
authored
Merge pull request #157 from rust-osdev/fixes
various fixes
2 parents cb4a10b + ca1c9a6 commit 53af759

File tree

7 files changed

+15
-18
lines changed

7 files changed

+15
-18
lines changed

multiboot2/Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- **BREAKING** Renamed `EFISdt32` to `EFISdt32Tag`
1818
- **BREAKING** Renamed `EFISdt64` to `EFISdt64Tag`
1919
- **BREAKING** Renamed `EFIBootServicesNotExited` to `EFIBootServicesNotExitedTag`
20+
- **BREAKING** Renamed `CommandLineTag::command_line` renamed to `CommandLineTag::cmdline`
2021
- **\[Might be\] BREAKING** Added `TagTrait` trait which enables to use DSTs as multiboot2 tags. This is
2122
mostly relevant for the command line tag, the modules tag, and the bootloader
2223
name tag. However, this might also be relevant for users of custom multiboot2

multiboot2/src/boot_loader_name.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,6 @@ mod tests {
118118
let tag = BootLoaderNameTag::new(MSG);
119119
let bytes = tag.struct_as_bytes();
120120
assert_eq!(bytes, get_bytes());
121+
assert_eq!(tag.name(), Ok(MSG));
121122
}
122123
}

multiboot2/src/builder/information.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,7 @@ mod tests {
335335
mb2i.basic_memory_info_tag().unwrap().memory_upper(),
336336
7 * 1024
337337
);
338-
assert_eq!(
339-
mb2i.command_line_tag().unwrap().command_line().unwrap(),
340-
"test"
341-
);
338+
assert_eq!(mb2i.command_line_tag().unwrap().cmdline().unwrap(), "test");
342339
let mut modules = mb2i.module_tags();
343340
let module_1 = modules.next().unwrap();
344341
assert_eq!(module_1.start_address(), 0);

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
}

multiboot2/src/command_line.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ impl CommandLineTag {
5252
/// ```rust,no_run
5353
/// # let boot_info = unsafe { multiboot2::load(0xdeadbeef).unwrap() };
5454
/// if let Some(tag) = boot_info.command_line_tag() {
55-
/// let command_line = tag.command_line();
55+
/// let command_line = tag.cmdline();
5656
/// assert_eq!(Ok("/bootarg"), command_line);
5757
/// }
5858
/// ```
59-
pub fn command_line(&self) -> Result<&str, str::Utf8Error> {
59+
pub fn cmdline(&self) -> Result<&str, str::Utf8Error> {
6060
Tag::get_dst_str_slice(&self.cmdline)
6161
}
6262
}
@@ -66,7 +66,7 @@ impl Debug for CommandLineTag {
6666
f.debug_struct("CommandLineTag")
6767
.field("typ", &{ self.typ })
6868
.field("size", &{ self.size })
69-
.field("cmdline", &self.command_line())
69+
.field("cmdline", &self.cmdline())
7070
.finish()
7171
}
7272
}
@@ -115,7 +115,7 @@ mod tests {
115115
let tag = unsafe { &*tag.as_ptr().cast::<Tag>() };
116116
let tag = tag.cast_tag::<CommandLineTag>();
117117
assert_eq!({ tag.typ }, TagType::Cmdline);
118-
assert_eq!(tag.command_line().expect("must be valid UTF-8"), MSG);
118+
assert_eq!(tag.cmdline().expect("must be valid UTF-8"), MSG);
119119
}
120120

121121
/// Test to generate a tag from a given string.
@@ -127,5 +127,6 @@ mod tests {
127127
let tag = CommandLineTag::new(MSG);
128128
let bytes = tag.struct_as_bytes();
129129
assert_eq!(bytes, get_bytes());
130+
assert_eq!(tag.cmdline(), Ok(MSG));
130131
}
131132
}

multiboot2/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ impl<'a> BootInformation<'a> {
285285
self.get_tag::<BasicMemoryInfoTag, _>(TagType::BasicMeminfo)
286286
}
287287

288-
/// Search for the ELF Sections.
288+
/// Returns an [`ElfSectionIter`] iterator over the ELF Sections, if the
289+
/// [`ElfSectionsTag`] is present.
289290
///
290291
/// # Examples
291292
///
@@ -497,7 +498,7 @@ impl fmt::Debug for BootInformation<'_> {
497498
"command_line",
498499
&self
499500
.command_line_tag()
500-
.and_then(|x| x.command_line().ok())
501+
.and_then(|x| x.cmdline().ok())
501502
.unwrap_or(""),
502503
)
503504
.field("memory_areas", &self.memory_map_tag())
@@ -1392,7 +1393,7 @@ mod tests {
13921393
"",
13931394
bi.command_line_tag()
13941395
.expect("tag must present")
1395-
.command_line()
1396+
.cmdline()
13961397
.expect("must be valid utf-8")
13971398
);
13981399

multiboot2/src/module.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,5 +173,6 @@ mod tests {
173173
let tag = ModuleTag::new(0, 0, MSG);
174174
let bytes = tag.struct_as_bytes();
175175
assert_eq!(bytes, get_bytes());
176+
assert_eq!(tag.cmdline(), Ok(MSG));
176177
}
177178
}

0 commit comments

Comments
 (0)