Skip to content

Commit bdb0db1

Browse files
authored
Merge pull request #123 from rust-osdev/multiboot2-v0.14.2-dev
Multiboot2 v0.14.2 dev
2 parents fd8e694 + bd060ab commit bdb0db1

File tree

14 files changed

+105
-29
lines changed

14 files changed

+105
-29
lines changed

.editorconfig

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ insert_final_newline = true
99
indent_style = space
1010
indent_size = 4
1111
trim_trailing_whitespace = true
12+
max_line_length = 80
1213

1314
[*.yml]
1415
indent_size = 2

.github/workflows/qa.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: QA
2+
3+
on: [ push, pull_request ]
4+
5+
jobs:
6+
spellcheck:
7+
name: Spellcheck
8+
runs-on: ubuntu-22.04
9+
steps:
10+
- uses: actions/checkout@v3
11+
# Executes "typos ."
12+
- uses: crate-ci/[email protected]

.github/workflows/rust.yml

+28-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ env:
1010
CARGO_TERM_COLOR: always
1111

1212
jobs:
13+
# Regular build (with std) + test execution
1314
build:
1415
runs-on: ubuntu-latest
1516
strategy:
@@ -19,7 +20,7 @@ jobs:
1920
- nightly
2021
- 1.52.1 # MSVR
2122
steps:
22-
- uses: actions/checkout@v2
23+
- uses: actions/checkout@v3
2324
# Important preparation step: override the latest default Rust version in GitHub CI
2425
# with the current value of the iteration in the "strategy.matrix.rust"-array.
2526
- uses: actions-rs/toolchain@v1
@@ -30,10 +31,11 @@ jobs:
3031
# helps to identify if the right cargo version is actually used
3132
- run: cargo version
3233
- name: Build
33-
run: cargo build --verbose
34+
run: cargo build --all-targets --verbose
3435
- name: Run tests
3536
run: cargo test --verbose
3637

38+
# no-std build without tests
3739
build_no_std:
3840
runs-on: ubuntu-latest
3941
strategy:
@@ -43,7 +45,7 @@ jobs:
4345
- nightly
4446
- 1.52.1 # MSVR
4547
steps:
46-
- uses: actions/checkout@v2
48+
- uses: actions/checkout@v3
4749
# Important preparation step: override the latest default Rust version in GitHub CI
4850
# with the current value of the iteration in the "strategy.matrix.rust"-array.
4951
- uses: actions-rs/toolchain@v1
@@ -58,6 +60,26 @@ jobs:
5860
- name: Build (no_std)
5961
run: cargo build --target thumbv7em-none-eabihf
6062

63+
# Tests that the unstable feature, which requires nightly, builds.
64+
build_unstable:
65+
runs-on: ubuntu-latest
66+
strategy:
67+
matrix:
68+
rust:
69+
- nightly
70+
steps:
71+
- uses: actions/checkout@v3
72+
# Important preparation step: override the latest default Rust version in GitHub CI
73+
# with the current value of the iteration in the "strategy.matrix.rust"-array.
74+
- uses: actions-rs/toolchain@v1
75+
with:
76+
profile: default
77+
toolchain: ${{ matrix.rust }}
78+
override: true
79+
- name: Build (unstable)
80+
run: cargo build --all-targets --features unstable
81+
- name: Test (unstable)
82+
run: cargo test --all-targets --features unstable
6183

6284
# As discussed, these tasks are optional for PRs.
6385
style_checks:
@@ -67,7 +89,7 @@ jobs:
6789
rust:
6890
- 1.52.1 # MSVR
6991
steps:
70-
- uses: actions/checkout@v2
92+
- uses: actions/checkout@v3
7193
# Important preparation step: override the latest default Rust version in GitHub CI
7294
# with the current value of the iteration in the "strategy.matrix.rust"-array.
7395
- uses: actions-rs/toolchain@v1
@@ -80,6 +102,6 @@ jobs:
80102
- name: Rustfmt
81103
run: cargo fmt -- --check
82104
- name: Clippy
83-
run: cargo clippy
105+
run: cargo clippy --all-targets
84106
- name: Rustdoc
85-
run: cargo doc
107+
run: cargo doc --document-private-items

.typos.toml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Configuration for the typos spell checker utility (<https://github.com/crate-ci/typos>).
2+
3+
[files]
4+
extend-exclude = [
5+
# "uefi/src/table/boot.rs"
6+
]
7+
8+
[default.extend-words]
9+
Rela = "Rela"
10+
11+
[default.extend-identifiers]
12+
# FOOBAR = "FOOBAR"
13+

Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
[workspace]
22
members = [
3-
# Multiboot2 Information Structure (MBI)
43
"multiboot2",
5-
# Multiboot2 headers
64
"multiboot2-header",
75
]

multiboot2-header/src/builder/traits.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub(crate) trait StructAsBytes: Sized {
2323
}
2424

2525
/// Returns the structure as a vector of its bytes.
26-
/// The length is determined by [`size`].
26+
/// The length is determined by [`Self::byte_size`].
2727
fn struct_as_bytes(&self) -> alloc::vec::Vec<u8> {
2828
let ptr = self.as_ptr();
2929
let mut vec = alloc::vec::Vec::with_capacity(self.byte_size());

multiboot2/Cargo.toml

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Multiboot2-compliant bootloaders, like GRUB. It supports all tags from the speci
66
including full support for the sections of ELF-64. This library is `no_std` and can be
77
used in a Multiboot2-kernel.
88
"""
9-
version = "0.14.1"
9+
version = "0.14.2"
1010
authors = [
1111
"Philipp Oppermann <[email protected]>",
1212
"Calvin Lee <[email protected]>",
@@ -31,5 +31,11 @@ homepage = "https://github.com/rust-osdev/multiboot2"
3131
repository = "https://github.com/rust-osdev/multiboot2"
3232
documentation = "https://docs.rs/multiboot2"
3333

34+
[features]
35+
default = []
36+
# Nightly-only features that will eventually be stabilized.
37+
unstable = []
38+
3439
[dependencies]
3540
bitflags = "1"
41+
derive_more = { version = "0.99.17", default-features = false, features = ["display"] }

multiboot2/Changelog.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# CHANGELOG for crate `multiboot2`
22

3+
## 0.14.2 (2023-03-17)
4+
- documentation fixes
5+
- `MbiLoadError` now implements `Display`
6+
- Added the `unstable` feature, which enables nightly-only functionality.
7+
With this feature, `MbiLoadError` now implements `core::error::Error` and can
8+
be used with `anyhow::Result` for example.
9+
310
## 0.14.1 (2023-03-09)
411
- fixed the calculation of the last area of the memory map tag ([#119](https://github.com/rust-osdev/multiboot2/pull/119))
512
(Previously, iterating the EFI Memory map resulted in a superfluous entry as it ran over the next tag)

multiboot2/src/boot_loader_name.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ impl BootLoaderNameTag {
2121
///
2222
/// # Examples
2323
///
24-
/// ```ignore
24+
/// ```rust,no_run
25+
/// # let boot_info = unsafe { multiboot2::load(0xdeadbeef).unwrap() };
2526
/// if let Some(tag) = boot_info.boot_loader_name_tag() {
26-
/// let name = tag.name();
27-
/// assert_eq!("GRUB 2.02~beta3-5", name);
27+
/// assert_eq!(Ok("GRUB 2.02~beta3-5"), tag.name());
2828
/// }
2929
/// ```
3030
pub fn name(&self) -> Result<&str, Utf8Error> {

multiboot2/src/command_line.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ impl CommandLineTag {
2525
///
2626
/// # Examples
2727
///
28-
/// ```ignore
28+
/// ```rust,no_run
29+
/// # let boot_info = unsafe { multiboot2::load(0xdeadbeef).unwrap() };
2930
/// if let Some(tag) = boot_info.command_line_tag() {
3031
/// let command_line = tag.command_line();
31-
/// assert_eq!("/bootarg", command_line);
32+
/// assert_eq!(Ok("/bootarg"), command_line);
3233
/// }
3334
/// ```
3435
pub fn command_line(&self) -> Result<&str, str::Utf8Error> {

multiboot2/src/elf_sections.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ impl ElfSectionsTag {
3333
///
3434
/// # Examples
3535
///
36-
/// ```ignore
36+
/// ```rust,no_run
37+
/// # let boot_info = unsafe { multiboot2::load(0xdeadbeef).unwrap() };
3738
/// if let Some(elf_tag) = boot_info.elf_sections_tag() {
3839
/// let mut total = 0;
3940
/// for section in elf_tag.sections() {

multiboot2/src/lib.rs

+26-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
// this crate can use `std` in tests only
2-
#![cfg_attr(not(test), no_std)]
1+
#![no_std]
2+
#![cfg_attr(feature = "unstable", feature(error_in_core))]
33
#![deny(missing_debug_implementations)]
44
// --- BEGIN STYLE CHECKS ---
55
// These checks are optional in CI for PRs, as discussed in
66
// https://github.com/rust-osdev/multiboot2/pull/92
77
#![deny(clippy::all)]
88
#![deny(rustdoc::all)]
9-
// Forcing this would be a little bit ridiculous, because it would require code examples for
10-
// each getter and each trivial trait implementation (like Debug).
9+
#![allow(rustdoc::private_doc_tests)]
1110
#![allow(rustdoc::missing_doc_code_examples)]
1211
// --- END STYLE CHECKS ---
1312

@@ -40,6 +39,7 @@
4039
extern crate std;
4140

4241
use core::fmt;
42+
use derive_more::Display;
4343

4444
pub use boot_loader_name::BootLoaderNameTag;
4545
pub use command_line::CommandLineTag;
@@ -88,7 +88,7 @@ pub const MULTIBOOT2_BOOTLOADER_MAGIC: u32 = 0x36d76289;
8888

8989
/// Load the multiboot boot information struct from an address.
9090
///
91-
/// This is the same as `load_with_offset` but the offset is omitted and set
91+
/// This is the same as [`load_with_offset`] but the offset is omitted and set
9292
/// to zero.
9393
///
9494
/// ## Example
@@ -108,7 +108,7 @@ pub const MULTIBOOT2_BOOTLOADER_MAGIC: u32 = 0x36d76289;
108108
/// environment (segfault) but also in UEFI-applications, where the referenced
109109
/// memory is not (identity) mapped (UEFI does only identity mapping).
110110
/// * The memory at `address` must not be modified after calling `load` or the
111-
/// program may observe unsychronized mutation.
111+
/// program may observe unsynchronized mutation.
112112
pub unsafe fn load(address: usize) -> Result<BootInformation, MbiLoadError> {
113113
load_with_offset(address, 0)
114114
}
@@ -117,7 +117,7 @@ pub unsafe fn load(address: usize) -> Result<BootInformation, MbiLoadError> {
117117
///
118118
/// ## Example
119119
///
120-
/// ```ignore
120+
/// ```rust,no_run
121121
/// use multiboot2::load_with_offset;
122122
///
123123
/// let ptr = 0xDEADBEEF as *const u32;
@@ -131,7 +131,7 @@ pub unsafe fn load(address: usize) -> Result<BootInformation, MbiLoadError> {
131131
/// environment (segfault) but also in UEFI-applications, where the referenced
132132
/// memory is not (identity) mapped (UEFI does only identity mapping).
133133
/// * The memory at `address` must not be modified after calling `load` or the
134-
/// program may observe unsychronized mutation.
134+
/// program may observe unsynchronized mutation.
135135
pub unsafe fn load_with_offset(
136136
address: usize,
137137
offset: usize,
@@ -161,19 +161,25 @@ pub unsafe fn load_with_offset(
161161

162162
/// Error type that describes errors while loading/parsing a multiboot2 information structure
163163
/// from a given address.
164-
#[derive(Debug)]
164+
#[derive(Debug, Display)]
165165
pub enum MbiLoadError {
166166
/// The address is invalid. Make sure that the address is 8-byte aligned,
167167
/// according to the spec.
168+
#[display(fmt = "The address is invalid")]
168169
IllegalAddress,
169170
/// The total size of the multiboot2 information structure must be a multiple of 8.
170171
/// (Not in spec, but it is implicitly the case, because the begin of MBI
171172
/// and all tags are 8-byte aligned and the end tag is exactly 8 byte long).
173+
#[display(fmt = "The size of the MBI is unexpected")]
172174
IllegalTotalSize(u32),
173175
/// End tag missing. Each multiboot2 header requires to have an end tag.
176+
#[display(fmt = "There is no end tag")]
174177
NoEndTag,
175178
}
176179

180+
#[cfg(feature = "unstable")]
181+
impl core::error::Error for MbiLoadError {}
182+
177183
/// A Multiboot 2 Boot Information struct.
178184
pub struct BootInformation {
179185
inner: *const BootInformationInner,
@@ -197,8 +203,9 @@ impl BootInformation {
197203
///
198204
/// This is the same as doing:
199205
///
200-
/// ```ignore
201-
/// let end_addr = boot_info.start_address() + boot_info.size();
206+
/// ```rust,no_run
207+
/// # let boot_info = unsafe { multiboot2::load(0xdeadbeef).unwrap() };
208+
/// let end_addr = boot_info.start_address() + boot_info.total_size();
202209
/// ```
203210
pub fn end_address(&self) -> usize {
204211
self.start_address() + self.total_size()
@@ -1434,4 +1441,12 @@ mod tests {
14341441
core::mem::transmute::<[u8; 16], EFIMemoryMapTag>([0u8; 16]);
14351442
}
14361443
}
1444+
1445+
#[test]
1446+
#[cfg(feature = "unstable")]
1447+
/// This test succeeds if it compiles.
1448+
fn mbi_load_error_implements_error() {
1449+
fn consumer<E: core::error::Error>(_e: E) {}
1450+
consumer(MbiLoadError::IllegalAddress)
1451+
}
14371452
}

multiboot2/src/rsdp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub struct RsdpV1Tag {
2929
}
3030

3131
impl RsdpV1Tag {
32-
/// The "RSD PTR " marker singature.
32+
/// The "RSD PTR " marker signature.
3333
///
3434
/// This is originally a 8-byte C string (not null terminated!) that must contain "RSD PTR "
3535
pub fn signature(&self) -> Result<&str, Utf8Error> {

multiboot2/src/vbe_info.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ impl fmt::Debug for VBEModeInfo {
233233

234234
/// A VBE colour field.
235235
///
236-
/// Descirbes the size and position of some colour capability.
236+
/// Describes the size and position of some colour capability.
237237
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
238238
#[repr(C, packed)]
239239
pub struct VBEField {

0 commit comments

Comments
 (0)