Skip to content

Commit e88de8c

Browse files
committed
multiboot2: cleanup
1 parent 45183b2 commit e88de8c

File tree

4 files changed

+44
-44
lines changed

4 files changed

+44
-44
lines changed

multiboot2/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "multiboot2"
33
description = """
4-
Library that helps you to parse the multiboot information structure (mbi) from
4+
Library that assists parsing the Multiboot2 Information Structure (MBI) from
55
Multiboot2-compliant bootloaders, like GRUB. It supports all tags from the specification
66
including full support for the sections of ELF-64. This library is `no_std` and can be
77
used in a Multiboot2-kernel.

multiboot2/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![crates.io](https://img.shields.io/crates/v/multiboot2.svg)](https://crates.io/crates/multiboot2)
44
[![docs](https://docs.rs/multiboot2/badge.svg)](https://docs.rs/multiboot2/)
55

6-
Rust library that helps you to parse the multiboot information structure (mbi) from
6+
Rust library that assists parsing the Multiboot2 Information Structure (MBI) from
77
Multiboot2-compliant bootloaders, like GRUB. It supports all tags from the specification
88
including full support for the sections of ELF-64 files. This library is `no_std` and can be
99
used in a Multiboot2-kernel.

multiboot2/src/lib.rs

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#![allow(rustdoc::private_doc_tests)]
1010
// --- END STYLE CHECKS ---
1111

12-
//! Library that helps you to parse the multiboot information structure (mbi) from
12+
//! Library that assists parsing the Multiboot2 Information Structure (MBI) from
1313
//! Multiboot2-compliant bootloaders, like GRUB. It supports all tags from the specification
1414
//! including full support for the sections of ELF-64. This library is `no_std` and can be
1515
//! used in a Multiboot2-kernel.
@@ -98,12 +98,16 @@ pub mod builder;
9898
/// that the Rust compiler output changes `eax` before you can access it.
9999
pub const MAGIC: u32 = 0x36d76289;
100100

101+
/// # Safety
102+
/// Deprecated. Please use BootInformation::load() instead.
101103
#[deprecated = "Please use BootInformation::load() instead."]
102104
pub unsafe fn load<'a>(address: usize) -> Result<BootInformation<'a>, MbiLoadError> {
103105
let ptr = address as *const u8;
104106
BootInformation::load(ptr)
105107
}
106108

109+
/// # Safety
110+
/// Deprecated. Please use BootInformation::load() instead.
107111
#[deprecated = "Please use BootInformation::load() instead."]
108112
pub unsafe fn load_with_offset<'a>(
109113
address: usize,
@@ -135,6 +139,42 @@ pub enum MbiLoadError {
135139
#[cfg(feature = "unstable")]
136140
impl core::error::Error for MbiLoadError {}
137141

142+
#[repr(C, align(8))]
143+
struct BootInformationInner {
144+
total_size: u32,
145+
_reserved: u32,
146+
// followed by various, dynamically sized multiboot2 tags
147+
tags: [Tag; 0],
148+
}
149+
150+
impl BootInformationInner {
151+
#[cfg(feature = "builder")]
152+
fn new(total_size: u32) -> Self {
153+
Self {
154+
total_size,
155+
_reserved: 0,
156+
tags: [],
157+
}
158+
}
159+
160+
fn has_valid_end_tag(&self) -> bool {
161+
let end_tag_prototype = EndTag::default();
162+
163+
let self_ptr = self as *const _;
164+
let end_tag_addr = self_ptr as usize + (self.total_size - end_tag_prototype.size) as usize;
165+
let end_tag = unsafe { &*(end_tag_addr as *const Tag) };
166+
167+
end_tag.typ == end_tag_prototype.typ && end_tag.size == end_tag_prototype.size
168+
}
169+
}
170+
171+
#[cfg(feature = "builder")]
172+
impl StructAsBytes for BootInformationInner {
173+
fn byte_size(&self) -> usize {
174+
core::mem::size_of::<Self>()
175+
}
176+
}
177+
138178
/// A Multiboot 2 Boot Information (MBI) accessor.
139179
#[repr(transparent)]
140180
pub struct BootInformation<'a>(&'a BootInformationInner);
@@ -185,35 +225,7 @@ impl BootInformation<'_> {
185225

186226
Ok(Self(mbi))
187227
}
188-
}
189-
190-
#[repr(C, align(8))]
191-
struct BootInformationInner {
192-
total_size: u32,
193-
_reserved: u32,
194-
// followed by various, dynamically sized multiboot2 tags
195-
tags: [Tag; 0],
196-
}
197-
198-
impl BootInformationInner {
199-
#[cfg(feature = "builder")]
200-
fn new(total_size: u32) -> Self {
201-
Self {
202-
total_size,
203-
_reserved: 0,
204-
tags: [],
205-
}
206-
}
207-
}
208-
209-
#[cfg(feature = "builder")]
210-
impl StructAsBytes for BootInformationInner {
211-
fn byte_size(&self) -> usize {
212-
core::mem::size_of::<Self>()
213-
}
214-
}
215228

216-
impl BootInformation<'_> {
217229
/// Get the start address of the boot info.
218230
pub fn start_address(&self) -> usize {
219231
core::ptr::addr_of!(*self.0) as usize
@@ -427,18 +439,6 @@ impl BootInformation<'_> {
427439
}
428440
}
429441

430-
impl BootInformationInner {
431-
fn has_valid_end_tag(&self) -> bool {
432-
let end_tag_prototype = EndTag::default();
433-
434-
let self_ptr = self as *const _;
435-
let end_tag_addr = self_ptr as usize + (self.total_size - end_tag_prototype.size) as usize;
436-
let end_tag = unsafe { &*(end_tag_addr as *const Tag) };
437-
438-
end_tag.typ == end_tag_prototype.typ && end_tag.size == end_tag_prototype.size
439-
}
440-
}
441-
442442
// SAFETY: BootInformation contains a const ptr to memory that is never mutated.
443443
// Sending this pointer to other threads is sound.
444444
unsafe impl Send for BootInformation<'_> {}

multiboot2/src/tag_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ mod partial_eq_impls {
287287
}
288288

289289
/// Common base structure for all tags that can be passed via the Multiboot2
290-
/// information structure (MBI) to a Multiboot2 payload/program/kernel.
290+
/// Information Structure (MBI) to a Multiboot2 payload/program/kernel.
291291
///
292292
/// Can be transformed to any other tag (sized or unsized/DST) via
293293
/// [`Tag::cast_tag`].

0 commit comments

Comments
 (0)