Skip to content

Commit fd8e694

Browse files
authored
Merge pull request #120 from rust-osdev/dev
Merge #119 + necessary fixed into main + multiboot2-0.14.1
2 parents ec24c49 + 76c3377 commit fd8e694

File tree

8 files changed

+33
-10
lines changed

8 files changed

+33
-10
lines changed

.github/workflows/rust.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
strategy:
6666
matrix:
6767
rust:
68-
- stable
68+
- 1.52.1 # MSVR
6969
steps:
7070
- uses: actions/checkout@v2
7171
# Important preparation step: override the latest default Rust version in GitHub CI

multiboot2-header/src/builder/information_request.rs

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub struct InformationRequestHeaderTagBuilder {
2121
#[cfg(feature = "builder")]
2222
impl InformationRequestHeaderTagBuilder {
2323
/// New builder.
24+
#[allow(clippy::missing_const_for_fn)] // TODO remove once MSRV is higher than 1.52.1
2425
pub fn new(flag: HeaderTagFlag) -> Self {
2526
Self {
2627
irs: BTreeSet::new(),
@@ -30,6 +31,7 @@ impl InformationRequestHeaderTagBuilder {
3031

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

multiboot2/Cargo.toml

+1-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.0"
9+
version = "0.14.1"
1010
authors = [
1111
"Philipp Oppermann <[email protected]>",
1212
"Calvin Lee <[email protected]>",

multiboot2/Changelog.md

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

3+
## 0.14.1 (2023-03-09)
4+
- fixed the calculation of the last area of the memory map tag ([#119](https://github.com/rust-osdev/multiboot2/pull/119))
5+
(Previously, iterating the EFI Memory map resulted in a superfluous entry as it ran over the next tag)
6+
37
## 0.14.0 (2022-06-30)
48
- **BREAKING CHANGES** \
59
This version includes a few small breaking changes that brings more safety when parsing strings from the

multiboot2/src/framebuffer.rs

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub enum FramebufferType<'a> {
3939

4040
/// Direct RGB color.
4141
#[allow(missing_docs)]
42+
#[allow(clippy::upper_case_acronyms)]
4243
RGB {
4344
red: FramebufferField,
4445
green: FramebufferField,

multiboot2/src/lib.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -1415,13 +1415,23 @@ mod tests {
14151415
assert!(efi_mmap.is_none());
14161416
}
14171417

1418+
#[test]
1419+
/// Compile time test for `MemoryMapTag`.
1420+
fn e820_memory_map_tag_size() {
1421+
use super::MemoryMapTag;
1422+
unsafe {
1423+
// `MemoryMapTag` is 16 bytes without the 1st entry
1424+
core::mem::transmute::<[u8; 16], MemoryMapTag>([0u8; 16]);
1425+
}
1426+
}
1427+
14181428
#[test]
14191429
/// Compile time test for `EFIMemoryMapTag`.
14201430
fn efi_memory_map_tag_size() {
14211431
use super::EFIMemoryMapTag;
14221432
unsafe {
1423-
// `EFIMemoryMapTag` is 16 bytes + `EFIMemoryDesc` is 40 bytes.
1424-
core::mem::transmute::<[u8; 56], EFIMemoryMapTag>([0u8; 56]);
1433+
// `EFIMemoryMapTag` is 16 bytes without the 1st entry
1434+
core::mem::transmute::<[u8; 16], EFIMemoryMapTag>([0u8; 16]);
14251435
}
14261436
}
14271437
}

multiboot2/src/memory_map.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct MemoryMapTag {
1818
size: u32,
1919
entry_size: u32,
2020
entry_version: u32,
21-
first_area: MemoryArea,
21+
first_area: [MemoryArea; 0],
2222
}
2323

2424
impl MemoryMapTag {
@@ -31,10 +31,13 @@ impl MemoryMapTag {
3131
/// Return an iterator over all marked memory areas.
3232
pub fn all_memory_areas(&self) -> impl Iterator<Item = &MemoryArea> {
3333
let self_ptr = self as *const MemoryMapTag;
34-
let start_area = (&self.first_area) as *const MemoryArea;
34+
let start_area = self.first_area.as_ptr();
35+
3536
MemoryAreaIter {
3637
current_area: start_area as u64,
37-
last_area: (self_ptr as u64 + (self.size - self.entry_size) as u64),
38+
// NOTE: `last_area` is only a bound, it doesn't necessarily point exactly to the last element
39+
last_area: (self_ptr as u64
40+
+ (self.size as u64 - core::mem::size_of::<MemoryMapTag>() as u64)),
3841
entry_size: self.entry_size,
3942
phantom: PhantomData,
4043
}
@@ -127,7 +130,7 @@ pub struct EFIMemoryMapTag {
127130
size: u32,
128131
desc_size: u32,
129132
desc_version: u32,
130-
first_desc: EFIMemoryDesc,
133+
first_desc: [EFIMemoryDesc; 0],
131134
}
132135

133136
impl EFIMemoryMapTag {
@@ -137,10 +140,12 @@ impl EFIMemoryMapTag {
137140
/// available memory areas for tables and such.
138141
pub fn memory_areas(&self) -> EFIMemoryAreaIter {
139142
let self_ptr = self as *const EFIMemoryMapTag;
140-
let start_area = (&self.first_desc) as *const EFIMemoryDesc;
143+
let start_area = self.first_desc.as_ptr();
141144
EFIMemoryAreaIter {
142145
current_area: start_area as u64,
143-
last_area: (self_ptr as u64 + self.size as u64),
146+
// NOTE: `last_area` is only a bound, it doesn't necessarily point exactly to the last element
147+
last_area: (self_ptr as u64
148+
+ (self.size as u64 - core::mem::size_of::<EFIMemoryMapTag>() as u64)),
144149
entry_size: self.desc_size,
145150
phantom: PhantomData,
146151
}

multiboot2/src/vbe_info.rs

+1
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ bitflags! {
330330
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
331331
#[repr(u8)]
332332
#[allow(missing_docs)]
333+
#[allow(clippy::upper_case_acronyms)]
333334
pub enum VBEMemoryModel {
334335
Text = 0x00,
335336
CGAGraphics = 0x01,

0 commit comments

Comments
 (0)