Skip to content

various fixes + cleanup + bump crate versions #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ jobs:
# check that devs can also use this on Windows.
build_nostd_stable_windows:
name: build no_std (stable) [Windows]
needs: build_stable
uses: ./.github/workflows/_build-rust.yml
with:
runs-on: windows-latest
Expand Down
50 changes: 13 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
[workspace]
resolver = "2"
members = [
"multiboot2",
"multiboot2-header",
]


# This way, the "multiboot2" dependency in the multiboot2-header crate can be
# referenced by version, while still the repository version is used
# transparently during local development.
[patch.crates-io]
multiboot2 = { path = "multiboot2" }
4 changes: 2 additions & 2 deletions multiboot2-header/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description = """
Library with type definitions and parsing functions for Multiboot2 headers.
This library is `no_std` and can be used in bootloaders.
"""
version = "0.2.0"
version = "0.3.0"
authors = [
"Philipp Schuster <phip1611@gmail.com>"
]
Expand Down Expand Up @@ -41,4 +41,4 @@ unstable = []

[dependencies]
# used for MBI tags
multiboot2 = "0.13.2"
multiboot2 = "0.16.0"
11 changes: 6 additions & 5 deletions multiboot2-header/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
# CHANGELOG for crate `multiboot2-header`

## Unreleased
## 0.3.0 (xxxx-xx-xx)
- MSRV is 1.68.0
- renamed the `std` feature to `alloc`
- added the optional `unstable` feature (requires nightly)
- implement `core::error::Error` for `LoadError`
- depends on `multiboot2@v0.16.0`

## v0.2.0 (2022-05-03)
## 0.2.0 (2022-05-03)
- **BREAKING** renamed `EntryHeaderTag` to `EntryAddressHeaderTag`
- **BREAKING** some paths changed from `multiboot2_header::header` to `multiboot2_header::builder`
-> thus, import paths are much more logically now
- internal code improvements

## v0.1.1 (2022-05-02)
## 0.1.1 (2022-05-02)
- fixed a bug that prevented the usage of the crate in `no_std` environments
- added a new default `builder`-feature to Cargo which requires the `alloc`-crate
(this feature can be disabled which will also remove the dependency to the `alloc` crate)

## v0.1.0 (2021-10-08)
## 0.1.0 (2021-10-08)
- initial release

## v0.0.0
## 0.0.0
Empty release to save the name on crates.io
34 changes: 23 additions & 11 deletions multiboot2-header/src/builder/information_request.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use super::traits::StructAsBytes;
use crate::InformationRequestHeaderTag;
use crate::{HeaderTagFlag, MbiTagType};
use crate::{InformationRequestHeaderTag, MbiTagTypeId};
use alloc::collections::BTreeSet;
use alloc::vec::Vec;
use core::fmt::Debug;
use core::mem::size_of;
use multiboot2::TagTypeId;

/// Helper to build the dynamically sized [`InformationRequestHeaderTag`]
/// at runtime. The information request tag has a dedicated builder because this way one
Expand All @@ -21,7 +22,6 @@ pub struct InformationRequestHeaderTagBuilder {
#[cfg(feature = "builder")]
impl InformationRequestHeaderTagBuilder {
/// New builder.
#[allow(clippy::missing_const_for_fn)] // TODO remove once MSRV is higher than 1.65.0
pub fn new(flag: HeaderTagFlag) -> Self {
Self {
irs: BTreeSet::new(),
Expand All @@ -31,10 +31,9 @@ impl InformationRequestHeaderTagBuilder {

/// Returns the expected length of the information request tag,
/// when the `build`-method gets called.
#[allow(clippy::missing_const_for_fn)] // TODO remove once MSRV is higher than 1.65.0
pub fn expected_len(&self) -> usize {
let basic_header_size = size_of::<InformationRequestHeaderTag<0>>();
let req_tags_size = self.irs.len() * size_of::<MbiTagType>();
let req_tags_size = self.irs.len() * size_of::<MbiTagTypeId>();
basic_header_size + req_tags_size
}

Expand Down Expand Up @@ -74,8 +73,13 @@ impl InformationRequestHeaderTagBuilder {
);
}

for tag in &self.irs {
let bytes: [u8; 4] = (*tag as u32).to_ne_bytes();
for tag_type in self
.irs
.into_iter()
// Transform to the ABI-compatible type
.map(TagTypeId::from)
{
let bytes: [u8; 4] = (u32::from(tag_type)).to_le_bytes();
data.extend(&bytes);
}

Expand All @@ -91,7 +95,7 @@ impl InformationRequestHeaderTagBuilder {
#[cfg(test)]
mod tests {
use crate::builder::information_request::InformationRequestHeaderTagBuilder;
use crate::{HeaderTagFlag, InformationRequestHeaderTag, MbiTagType};
use crate::{HeaderTagFlag, InformationRequestHeaderTag, MbiTagType, MbiTagTypeId};

#[test]
fn test_builder() {
Expand All @@ -111,11 +115,19 @@ mod tests {
// type(u16) + flags(u16) + size(u32) + 3 tags (u32)
assert_eq!(tag.size(), 2 + 2 + 4 + 3 * 4);
assert_eq!(tag.dynamic_requests_size(), 3);
assert!(tag.requests().contains(&MbiTagType::EfiMmap));
assert!(tag.requests().contains(&MbiTagType::BootLoaderName));
assert!(tag.requests().contains(&MbiTagType::Cmdline));
assert!(tag
.requests()
.contains(&MbiTagTypeId::from(MbiTagType::EfiMmap)));
assert!(tag
.requests()
.contains(&MbiTagTypeId::from(MbiTagType::BootLoaderName)));
assert!(tag
.requests()
.contains(&MbiTagTypeId::from(MbiTagType::Cmdline)));
assert_eq!(tag.requests().len(), 3);
assert!(!tag.requests().contains(&MbiTagType::AcpiV1));
assert!(!tag
.requests()
.contains(&MbiTagTypeId::from(MbiTagType::AcpiV1)));
println!("{:#?}", tag);
}
}
25 changes: 13 additions & 12 deletions multiboot2-header/src/information_request.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::HeaderTagType;
use crate::{HeaderTagFlag, MbiTagType};
use crate::{HeaderTagType, MbiTagTypeId};
use core::fmt;
use core::fmt::{Debug, Formatter};
use core::marker::PhantomData;
use core::mem::size_of;
use multiboot2::TagType;

/// Specifies what specific tag types the bootloader should provide
/// inside the mbi.
Expand All @@ -15,14 +16,14 @@ pub struct InformationRequestHeaderTag<const N: usize> {
size: u32,
// Length is determined by size.
// Must be parsed during runtime with unsafe pointer magic and the size field.
requests: [MbiTagType; N],
requests: [MbiTagTypeId; N],
}

impl<const N: usize> InformationRequestHeaderTag<N> {
/// Creates a new object. The size parameter is the value of the size property.
/// It doesn't have to match with `N` necessarily, because during compile time we
/// can't know the size of the tag in all runtime situations.
pub fn new(flags: HeaderTagFlag, requests: [MbiTagType; N], size: Option<u32>) -> Self {
pub fn new(flags: HeaderTagFlag, requests: [MbiTagTypeId; N], size: Option<u32>) -> Self {
InformationRequestHeaderTag {
typ: HeaderTagType::InformationRequest,
flags,
Expand All @@ -44,7 +45,7 @@ impl<const N: usize> InformationRequestHeaderTag<N> {
/// Returns the requests as array. Only works if the number of requests
/// is known at compile time. For safety and correctness during runtime,
/// you should use `req_iter()`.
pub const fn requests(&self) -> [MbiTagType; N] {
pub const fn requests(&self) -> [MbiTagTypeId; N] {
// cheap to copy, otherwise difficult with lifetime
self.requests
}
Expand All @@ -70,7 +71,7 @@ impl<const N: usize> InformationRequestHeaderTag<N> {
let base_ptr = self as *const InformationRequestHeaderTag<N>;
let base_ptr = base_ptr as *const u8;
let base_ptr = unsafe { base_ptr.add(base_struct_size) };
let base_ptr = base_ptr as *const MbiTagType;
let base_ptr = base_ptr as *const MbiTagTypeId;
InformationRequestHeaderTagIter::new(count, base_ptr)
}
}
Expand All @@ -90,32 +91,32 @@ impl<const N: usize> Debug for InformationRequestHeaderTag<N> {
/// that are requested.
#[derive(Copy, Clone)]
pub struct InformationRequestHeaderTagIter<'a> {
base_ptr: *const MbiTagType,
base_ptr: *const MbiTagTypeId,
i: u32,
count: u32,
_marker: PhantomData<&'a ()>,
}

impl<'a> InformationRequestHeaderTagIter<'a> {
fn new(count: u32, base_ptr: *const MbiTagType) -> Self {
#[allow(clippy::default_constructed_unit_structs)]
const fn new(count: u32, base_ptr: *const MbiTagTypeId) -> Self {
Self {
i: 0,
count,
base_ptr,
_marker: PhantomData::default(),
_marker: PhantomData,
}
}
}

impl<'a> Iterator for InformationRequestHeaderTagIter<'a> {
type Item = &'a MbiTagType;
type Item = MbiTagType;

fn next(&mut self) -> Option<Self::Item> {
if self.i < self.count {
let ptr = unsafe { self.base_ptr.offset(self.i as isize) };
self.i += 1;
Some(unsafe { &*ptr })
let tag_type_id = unsafe { *ptr };
Some(TagType::from(tag_type_id))
} else {
None
}
Expand All @@ -126,7 +127,7 @@ impl<'a> Debug for InformationRequestHeaderTagIter<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let mut debug = f.debug_list();
(*self).for_each(|e| {
debug.entry(e);
debug.entry(&e);
});
debug.finish()
}
Expand Down
2 changes: 1 addition & 1 deletion multiboot2-header/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ pub use self::tags::*;
pub use self::uefi_bs::*;

/// Re-export of [`multiboot2::TagType`] from `multiboot2`-crate.
pub use multiboot2::TagType as MbiTagType;
pub use multiboot2::{TagType as MbiTagType, TagTypeId as MbiTagTypeId};
2 changes: 1 addition & 1 deletion multiboot2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Multiboot2-compliant bootloaders, like GRUB. It supports all tags from the speci
including full support for the sections of ELF-64. This library is `no_std` and can be
used in a Multiboot2-kernel.
"""
version = "0.15.1"
version = "0.16.0"
authors = [
"Philipp Oppermann <dev@phil-opp.com>",
"Calvin Lee <cyrus296@gmail.com>",
Expand Down
2 changes: 1 addition & 1 deletion multiboot2/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CHANGELOG for crate `multiboot2`

## unreleased
## 0.16.0 (xxxx-xx-xx)
- Add `TagTrait` trait which enables to use DSTs as multiboot2 tags. This is
mostly relevant for the command line tag, the modules tag, and the bootloader
name tag. However, this might also be relevant for users of custom multiboot2
Expand Down
4 changes: 2 additions & 2 deletions multiboot2/src/boot_loader_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ mod tests {
// size is: 4 bytes for tag + 4 bytes for size + length of null-terminated string
let size = (4 + 4 + MSG.as_bytes().len() + 1) as u32;
[
&((TagType::BootLoaderName.val()).to_ne_bytes()),
&size.to_ne_bytes(),
&((TagType::BootLoaderName.val()).to_le_bytes()),
&size.to_le_bytes(),
MSG.as_bytes(),
// Null Byte
&[0],
Expand Down
4 changes: 2 additions & 2 deletions multiboot2/src/command_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ mod tests {
// size is: 4 bytes for tag + 4 bytes for size + length of null-terminated string
let size = (4 + 4 + MSG.as_bytes().len() + 1) as u32;
[
&((TagType::Cmdline.val()).to_ne_bytes()),
&size.to_ne_bytes(),
&((TagType::Cmdline.val()).to_le_bytes()),
&size.to_le_bytes(),
MSG.as_bytes(),
// Null Byte
&[0],
Expand Down
Loading