Skip to content

Commit 6b15cfb

Browse files
authored
Merge pull request #245 from rust-osdev/doc
multiboot2: various small fixes and doc improvements
2 parents 37a2aa0 + b9b6e05 commit 6b15cfb

File tree

14 files changed

+125
-87
lines changed

14 files changed

+125
-87
lines changed

multiboot2-common/README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ safely cast to the target type.
2525
![Generic parsing flow overview](./parsing-flow-generic.drawio.png "Generic parsing flow overview: From raw bytes to specific structures")
2626

2727
The next figure is like the previous figure, but shows a more specific parsing
28-
flow by using types of the `multiboot2` crate. Green shows the raw memory.
29-
Purple boxes refers to logic in `multiboot2-common`. Red components show structs
30-
from the `multiboot2` crate.
28+
flow by using example types of the `multiboot2` crate. Specifically, it shows
29+
how the header structs for each multiboot2 structure, each implementing
30+
the `Header` trait, are utilized as generic types to get the right size
31+
information of the final type tag type.
32+
33+
Green shows the raw memory, purple boxes refer to logic in `multiboot2-common`,
34+
and red components show structs from the `multiboot2` crate.
3135

3236
![Specific parsing flow overview](./parsing-flow-specific.drawio.png "Specific parsing flow overview: From raw bytes to multiboot2 structures")
3337

Loading

multiboot2-common/parsing-flow-specific.drawio.xml

Lines changed: 94 additions & 67 deletions
Large diffs are not rendered by default.

multiboot2-common/src/iter.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ use core::marker::PhantomData;
77
use core::mem;
88

99
/// Iterates over the tags (modelled by [`DynSizedStructure`]) of the underlying
10-
/// byte slice. Each tag is expected to have the same common [`Header`].
10+
/// byte slice. Each tag is expected to have the same common [`Header`] with
11+
/// the corresponding ABI guarantees.
1112
///
1213
/// As the iterator emits elements of type [`DynSizedStructure`], users should
13-
/// casted them to specific [`Tag`]s using [`DynSizedStructure::cast`] following
14-
/// a user policy. This can for example happen on the basis of some ID.
14+
/// cast them to specific [`Tag`]s using [`DynSizedStructure::cast`] following
15+
/// a user-specific policy. This can for example happen on the basis of some ID.
16+
///
17+
/// This iterator also emits end tags and doesn't treat them separately.
1518
///
1619
/// This type ensures the memory safety guarantees promised by this crates
1720
/// documentation.
@@ -30,6 +33,8 @@ pub struct TagIter<'a, H: Header> {
3033
impl<'a, H: Header> TagIter<'a, H> {
3134
/// Creates a new iterator.
3235
#[must_use]
36+
// TODO we could take a BytesRef here, but the surrounding code should be
37+
// bullet-proof enough.
3338
pub fn new(mem: &'a [u8]) -> Self {
3439
// Assert alignment.
3540
assert_eq!(mem.as_ptr().align_offset(ALIGNMENT), 0);

multiboot2-common/src/tag.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub trait MaybeDynSized: Pointee {
6464
/// data, read the tag size from [`Self::header`] and create a sub slice.
6565
fn as_bytes(&self) -> BytesRef<Self::Header> {
6666
let ptr = core::ptr::addr_of!(*self);
67-
// Actual tag size, optionally with terminating padding.
67+
// Actual tag size with optional terminating padding.
6868
let size = mem::size_of_val(self);
6969
let slice = unsafe { slice::from_raw_parts(ptr.cast::<u8>(), size) };
7070
// Unwrap is fine as this type can't exist without the underlying memory

multiboot2-header/src/entry_address.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl Debug for EntryAddressHeaderTag {
5353
.field("type", &self.typ())
5454
.field("flags", &self.flags())
5555
.field("size", &self.size())
56-
.field("entry_addr", &(self.entry_addr as *const u32))
56+
.field("entry_addr", &self.entry_addr)
5757
.finish()
5858
}
5959
}

multiboot2-header/src/entry_efi_32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl Debug for EntryEfi32HeaderTag {
6262
.field("type", &self.typ())
6363
.field("flags", &self.flags())
6464
.field("size", &self.size())
65-
.field("entry_addr", &(self.entry_addr as *const u32))
65+
.field("entry_addr", &self.entry_addr)
6666
.finish()
6767
}
6868
}

multiboot2-header/src/entry_efi_64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl Debug for EntryEfi64HeaderTag {
6262
.field("type", &self.typ())
6363
.field("flags", &self.flags())
6464
.field("size", &self.size())
65-
.field("entry_addr", &(self.entry_addr as *const u32))
65+
.field("entry_addr", &self.entry_addr)
6666
.finish()
6767
}
6868
}

multiboot2-header/src/relocatable.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ impl Debug for RelocatableHeaderTag {
108108
.field("flags", &self.flags())
109109
.field("size", &self.size())
110110
// trick to print this as hexadecimal pointer
111-
.field("min_addr", &(self.min_addr as *const u32))
112-
.field("max_addr", &(self.max_addr as *const u32))
113-
.field("align", &{ self.align })
114-
.field("preference", &{ self.preference })
111+
.field("min_addr", &self.min_addr)
112+
.field("max_addr", &self.max_addr)
113+
.field("align", &self.align)
114+
.field("preference", &self.preference)
115115
.finish()
116116
}
117117
}

multiboot2/src/boot_information.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ impl<'a> BootInformation<'a> {
132132

133133
/// Get the start address of the boot info.
134134
#[must_use]
135+
// TODO deprecated and use pointers only (see provenance discussions)
135136
pub fn start_address(&self) -> usize {
136137
self.as_ptr() as usize
137138
}
@@ -153,6 +154,7 @@ impl<'a> BootInformation<'a> {
153154
/// let end_addr = boot_info.start_address() + boot_info.total_size();
154155
/// ```
155156
#[must_use]
157+
// TODO deprecated and use pointers only (see provenance discussions)
156158
pub fn end_address(&self) -> usize {
157159
self.start_address() + self.total_size()
158160
}

multiboot2/src/elf_sections.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl<'a> Iterator for ElfSectionIter<'a> {
134134
}
135135
}
136136

137-
impl<'a> Debug for ElfSectionIter<'a> {
137+
impl Debug for ElfSectionIter<'_> {
138138
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
139139
let mut debug = f.debug_list();
140140
self.clone().for_each(|ref e| {
@@ -183,7 +183,7 @@ struct ElfSectionInner64 {
183183
entry_size: u64,
184184
}
185185

186-
impl<'a> ElfSection<'a> {
186+
impl ElfSection<'_> {
187187
/// Get the section type as a `ElfSectionType` enum variant.
188188
#[must_use]
189189
pub fn section_type(&self) -> ElfSectionType {

multiboot2/src/framebuffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ pub enum FramebufferType<'a> {
319319
Text,
320320
}
321321

322-
impl<'a> FramebufferType<'a> {
322+
impl FramebufferType<'_> {
323323
#[must_use]
324324
#[cfg(feature = "builder")]
325325
const fn id(&self) -> FramebufferTypeId {

multiboot2/src/memory_map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,13 +455,13 @@ impl<'a> Iterator for EFIMemoryAreaIter<'a> {
455455
}
456456
}
457457

458-
impl<'a> ExactSizeIterator for EFIMemoryAreaIter<'a> {
458+
impl ExactSizeIterator for EFIMemoryAreaIter<'_> {
459459
fn len(&self) -> usize {
460460
self.entries
461461
}
462462
}
463463

464-
impl<'a> Debug for EFIMemoryAreaIter<'a> {
464+
impl Debug for EFIMemoryAreaIter<'_> {
465465
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
466466
let mut debug = f.debug_list();
467467
let iter = self.clone();

multiboot2/src/module.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl<'a> Iterator for ModuleIter<'a> {
123123
}
124124
}
125125

126-
impl<'a> Debug for ModuleIter<'a> {
126+
impl Debug for ModuleIter<'_> {
127127
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
128128
let mut list = f.debug_list();
129129
self.clone().for_each(|tag| {

0 commit comments

Comments
 (0)