Skip to content

Commit 9492d65

Browse files
committed
Fix ModuleTag cmdline
1 parent 3918c18 commit 9492d65

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/module.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,28 @@ use core::fmt::{Debug, Formatter};
33

44
/// This tag indicates to the kernel what boot module was loaded along with
55
/// the kernel image, and where it can be found.
6-
#[derive(Clone, Copy, Debug)]
6+
#[derive(Clone, Copy)]
77
#[repr(C, packed)] // only repr(C) would add unwanted padding near name_byte.
88
pub struct ModuleTag {
99
typ: u32,
1010
size: u32,
1111
mod_start: u32,
1212
mod_end: u32,
13-
name_byte: u8,
13+
/// Begin of the command line string.
14+
cmdline_str: u8,
1415
}
1516

1617
impl ModuleTag {
17-
// The multiboot specification defines the module str
18-
// as valid utf-8, therefore this function produces
19-
// defined behavior
20-
/// Get the name of the module.
21-
pub fn name(&self) -> &str {
18+
// The multiboot specification defines the module str as valid utf-8 (zero terminated string),
19+
// therefore this function produces defined behavior
20+
/// Get the cmdline of the module. If the GRUB configuration contains
21+
/// `module2 /foobar/some_boot_module --test cmdline-option`, then this method
22+
/// will return `--test cmdline-option`.
23+
pub fn cmdline(&self) -> &str {
2224
use core::{mem, slice, str};
2325
let strlen = self.size as usize - mem::size_of::<ModuleTag>();
2426
unsafe {
25-
str::from_utf8_unchecked(slice::from_raw_parts(&self.name_byte as *const u8, strlen))
27+
str::from_utf8_unchecked(slice::from_raw_parts(&self.cmdline_str as *const u8, strlen))
2628
}
2729
}
2830

@@ -37,6 +39,18 @@ impl ModuleTag {
3739
}
3840
}
3941

42+
impl Debug for ModuleTag {
43+
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
44+
f.debug_struct("ModuleTag")
45+
.field("type", &self.typ)
46+
.field("size", &self.size)
47+
.field("mod_start", &(self.mod_start as *const usize))
48+
.field("mod_end", &(self.mod_end as *const usize))
49+
.field("cmdline", &self.cmdline())
50+
.finish()
51+
}
52+
}
53+
4054
pub fn module_iter(iter: TagIter) -> ModuleIter {
4155
ModuleIter { iter }
4256
}

0 commit comments

Comments
 (0)