Skip to content

Commit 989d05e

Browse files
authored
Merge pull request #164 from rust-osdev/foobar
multiboot2: API refactorings and simplifications: Make TagTrait more useful
2 parents 51f16f1 + 010c9c3 commit 989d05e

21 files changed

+324
-428
lines changed

Cargo.lock

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration-test/bins/Cargo.lock

Lines changed: 16 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

multiboot2-header/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ What this library is not optimal for:
1616
- compiling a Multiboot2 header statically into an object file using only Rust code
1717

1818
## Features and `no_std` Compatibility
19-
This library is always `no_std`. However, the default `builder`-feature requires
20-
the `alloc`-crate to be available. You need the `builder` only if you want to
21-
construct new headers at run time. For parsing, this is not relevant, and you
22-
can deactivate the default feature.
19+
This library is always `no_std` without `alloc`. However, the default `builder`-
20+
feature requires the `alloc`-crate and an `#[global_allocator]` to be available.
21+
You need the `builder` only if you want to construct new headers at runtime.
22+
For parsing, this is not relevant, and you can deactivate the default feature.
2323

2424
```toml
2525
# without `builder`-feature (and without `alloc`-crate)

multiboot2/Changelog.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# CHANGELOG for crate `multiboot2`
22

3+
## 0.18.0 (2023-xx-xx)
4+
- **BREAKING** The `TagTrait` was enhanced and now has an associated `ID`
5+
constant. This is only breaking to users that used `BootInformation::get_tag`
6+
or that implement custom tags. `BootInformation::get_tag` doesn't need the
7+
`typ` parameter anymore, as it can be deduced from the provided type.
8+
- **BREAKING** `BoxedDst::new` doesn't have the `typ` parameter anymore. This
9+
only effects you when you wrote a custom DST tag.
10+
- **BREAKING** Removed deprecated functions `load` and `load_with_offset`. Use
11+
`BootInformation::load` instead.
12+
313
## 0.17.0 (2023-07-12)
414
- **BREAKING** Make functions of `InformationBuilder` chainable. They now consume the builder.
515
- **BREAKING** Allow non-standard memory area types by using new pair of

multiboot2/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ is `no_std` and can be used in a Multiboot2-kernel.
1111
It follows the Multiboot 2.0 specification at https://www.gnu.org/software/grub/manual/multiboot2/multiboot.html and the ELF 64 specification at http://www.uclibc.org/docs/elf-64-gen.pdf.
1212

1313
## Features and `no_std` Compatibility
14-
This library is always `no_std`. However, the default `builder`-feature requires
15-
the `alloc`-crate to be available. You need the `builder` only if you want to
16-
construct new boot information structures at run time. For parsing, this is not
17-
relevant, and you can deactivate the default feature.
14+
This library is always `no_std` without `alloc`. However, the default `builder`-
15+
feature requires the `alloc`-crate and an `#[global_allocator]` to be available.
16+
You need the `builder` only if you want to construct new boot information
17+
structures at runtime. For parsing, this is not relevant, and you can
18+
deactivate the default feature.
1819

1920
## Background: The Multiboot 2 Information Structure
2021
The Multiboot information structure looks like this:

multiboot2/src/boot_loader_name.rs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
use crate::{Tag, TagTrait, TagTypeId};
1+
use crate::{Tag, TagTrait, TagType, TagTypeId};
22
use core::fmt::{Debug, Formatter};
33
use core::mem::size_of;
44
use core::str::Utf8Error;
5-
65
#[cfg(feature = "builder")]
7-
use {
8-
crate::builder::traits::StructAsBytes, crate::builder::BoxedDst, crate::TagType,
9-
alloc::vec::Vec,
10-
};
6+
use {crate::builder::BoxedDst, alloc::vec::Vec};
117

128
const METADATA_SIZE: usize = size_of::<TagTypeId>() + size_of::<u32>();
139

@@ -29,7 +25,7 @@ impl BootLoaderNameTag {
2925
// terminating null-byte
3026
bytes.push(0);
3127
}
32-
BoxedDst::new(TagType::BootLoaderName, &bytes)
28+
BoxedDst::new(&bytes)
3329
}
3430

3531
/// Reads the name of the bootloader that is booting the kernel as Rust
@@ -42,7 +38,9 @@ impl BootLoaderNameTag {
4238
/// # Examples
4339
///
4440
/// ```rust,no_run
45-
/// # let boot_info = unsafe { multiboot2::load(0xdeadbeef).unwrap() };
41+
/// # use multiboot2::{BootInformation, BootInformationHeader};
42+
/// # let ptr = 0xdeadbeef as *const BootInformationHeader;
43+
/// # let boot_info = unsafe { BootInformation::load(ptr).unwrap() };
4644
/// if let Some(tag) = boot_info.boot_loader_name_tag() {
4745
/// assert_eq!(Ok("GRUB 2.02~beta3-5"), tag.name());
4846
/// }
@@ -63,22 +61,17 @@ impl Debug for BootLoaderNameTag {
6361
}
6462

6563
impl TagTrait for BootLoaderNameTag {
64+
const ID: TagType = TagType::BootLoaderName;
65+
6666
fn dst_size(base_tag: &Tag) -> usize {
6767
assert!(base_tag.size as usize >= METADATA_SIZE);
6868
base_tag.size as usize - METADATA_SIZE
6969
}
7070
}
7171

72-
#[cfg(feature = "builder")]
73-
impl StructAsBytes for BootLoaderNameTag {
74-
fn byte_size(&self) -> usize {
75-
self.size.try_into().unwrap()
76-
}
77-
}
78-
7972
#[cfg(test)]
8073
mod tests {
81-
use crate::{BootLoaderNameTag, Tag, TagType};
74+
use crate::{BootLoaderNameTag, Tag, TagTrait, TagType};
8275

8376
const MSG: &str = "hello";
8477

@@ -114,10 +107,8 @@ mod tests {
114107
#[test]
115108
#[cfg(feature = "builder")]
116109
fn test_build_str() {
117-
use crate::builder::traits::StructAsBytes;
118-
119110
let tag = BootLoaderNameTag::new(MSG);
120-
let bytes = tag.struct_as_bytes();
111+
let bytes = tag.as_bytes();
121112
assert_eq!(bytes, get_bytes());
122113
assert_eq!(tag.name(), Ok(MSG));
123114

0 commit comments

Comments
 (0)