Skip to content

Merge #119 + necessary fixed into main + multiboot2-0.14.1 #120

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 6 commits into from
Mar 9, 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
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
strategy:
matrix:
rust:
- stable
- 1.52.1 # MSVR
steps:
- uses: actions/checkout@v2
# Important preparation step: override the latest default Rust version in GitHub CI
Expand Down
2 changes: 2 additions & 0 deletions multiboot2-header/src/builder/information_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct InformationRequestHeaderTagBuilder {
#[cfg(feature = "builder")]
impl InformationRequestHeaderTagBuilder {
/// New builder.
#[allow(clippy::missing_const_for_fn)] // TODO remove once MSRV is higher than 1.52.1
pub fn new(flag: HeaderTagFlag) -> Self {
Self {
irs: BTreeSet::new(),
Expand All @@ -30,6 +31,7 @@ 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.52.1
pub fn expected_len(&self) -> usize {
let basic_header_size = size_of::<InformationRequestHeaderTag<0>>();
let req_tags_size = self.irs.len() * size_of::<MbiTagType>();
Expand Down
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.14.0"
version = "0.14.1"
authors = [
"Philipp Oppermann <[email protected]>",
"Calvin Lee <[email protected]>",
Expand Down
4 changes: 4 additions & 0 deletions multiboot2/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG for crate `multiboot2`

## 0.14.1 (2023-03-09)
- fixed the calculation of the last area of the memory map tag ([#119](https://github.com/rust-osdev/multiboot2/pull/119))
(Previously, iterating the EFI Memory map resulted in a superfluous entry as it ran over the next tag)

## 0.14.0 (2022-06-30)
- **BREAKING CHANGES** \
This version includes a few small breaking changes that brings more safety when parsing strings from the
Expand Down
1 change: 1 addition & 0 deletions multiboot2/src/framebuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub enum FramebufferType<'a> {

/// Direct RGB color.
#[allow(missing_docs)]
#[allow(clippy::upper_case_acronyms)]
RGB {
red: FramebufferField,
green: FramebufferField,
Expand Down
14 changes: 12 additions & 2 deletions multiboot2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1415,13 +1415,23 @@ mod tests {
assert!(efi_mmap.is_none());
}

#[test]
/// Compile time test for `MemoryMapTag`.
fn e820_memory_map_tag_size() {
use super::MemoryMapTag;
unsafe {
// `MemoryMapTag` is 16 bytes without the 1st entry
core::mem::transmute::<[u8; 16], MemoryMapTag>([0u8; 16]);
}
}

#[test]
/// Compile time test for `EFIMemoryMapTag`.
fn efi_memory_map_tag_size() {
use super::EFIMemoryMapTag;
unsafe {
// `EFIMemoryMapTag` is 16 bytes + `EFIMemoryDesc` is 40 bytes.
core::mem::transmute::<[u8; 56], EFIMemoryMapTag>([0u8; 56]);
// `EFIMemoryMapTag` is 16 bytes without the 1st entry
core::mem::transmute::<[u8; 16], EFIMemoryMapTag>([0u8; 16]);
}
}
}
17 changes: 11 additions & 6 deletions multiboot2/src/memory_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct MemoryMapTag {
size: u32,
entry_size: u32,
entry_version: u32,
first_area: MemoryArea,
first_area: [MemoryArea; 0],
}

impl MemoryMapTag {
Expand All @@ -31,10 +31,13 @@ impl MemoryMapTag {
/// Return an iterator over all marked memory areas.
pub fn all_memory_areas(&self) -> impl Iterator<Item = &MemoryArea> {
let self_ptr = self as *const MemoryMapTag;
let start_area = (&self.first_area) as *const MemoryArea;
let start_area = self.first_area.as_ptr();

MemoryAreaIter {
current_area: start_area as u64,
last_area: (self_ptr as u64 + (self.size - self.entry_size) as u64),
// NOTE: `last_area` is only a bound, it doesn't necessarily point exactly to the last element
last_area: (self_ptr as u64
+ (self.size as u64 - core::mem::size_of::<MemoryMapTag>() as u64)),
entry_size: self.entry_size,
phantom: PhantomData,
}
Expand Down Expand Up @@ -127,7 +130,7 @@ pub struct EFIMemoryMapTag {
size: u32,
desc_size: u32,
desc_version: u32,
first_desc: EFIMemoryDesc,
first_desc: [EFIMemoryDesc; 0],
}

impl EFIMemoryMapTag {
Expand All @@ -137,10 +140,12 @@ impl EFIMemoryMapTag {
/// available memory areas for tables and such.
pub fn memory_areas(&self) -> EFIMemoryAreaIter {
let self_ptr = self as *const EFIMemoryMapTag;
let start_area = (&self.first_desc) as *const EFIMemoryDesc;
let start_area = self.first_desc.as_ptr();
EFIMemoryAreaIter {
current_area: start_area as u64,
last_area: (self_ptr as u64 + self.size as u64),
// NOTE: `last_area` is only a bound, it doesn't necessarily point exactly to the last element
last_area: (self_ptr as u64
+ (self.size as u64 - core::mem::size_of::<EFIMemoryMapTag>() as u64)),
entry_size: self.desc_size,
phantom: PhantomData,
}
Expand Down
1 change: 1 addition & 0 deletions multiboot2/src/vbe_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ bitflags! {
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
#[repr(u8)]
#[allow(missing_docs)]
#[allow(clippy::upper_case_acronyms)]
pub enum VBEMemoryModel {
Text = 0x00,
CGAGraphics = 0x01,
Expand Down