Skip to content

multiboot2: Fix EFI Memory Map 'last_area' calculation #119

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 2 commits into from
Mar 9, 2023

Conversation

A0lson
Copy link
Contributor

@A0lson A0lson commented Feb 24, 2023

Correct EFI 'last_area' calculation and align it to be more similar the E820 version.

(Previously, iterating the EFI Memory map resulted in a superfluous entry as it ran over the next tag)

@@ -140,7 +140,7 @@ impl EFIMemoryMapTag {
let start_area = (&self.first_desc) as *const EFIMemoryDesc;
EFIMemoryAreaIter {
current_area: start_area as u64,
last_area: (self_ptr as u64 + self.size as u64),
last_area: (self_ptr as u64 + (self.size - self.desc_size) as u64),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the root problem is that size_of::<EFIMemoryMapTag>() contains already the size of the first entry. I think a nicer solution would be to type the EFIMemoryMapTag as

pub struct EFIMemoryMapTag {
    typ: TagType,
    size: u32,
    desc_size: u32,
    desc_version: u32,
    first_desc: [EFIMemoryDesc; 0],
}

instead. Depending on your skill and time you'd like to invest, feel free to look into it. Otherwise, I can take care of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. I'm a bit new to Rust, but the zero length arrays seem much more elegant.

I've updated both the E820 and EFI code to use them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good!

@phip1611
Copy link
Member

Hi and thanks a lot for your contribution! There are unit-test failures, but it might also be the case, that the unit test itself is wrong. I can't look into it right now.

If you'd like to invest more time into it, I'd appreciate it. Otherwise, I try to look into it within the next 10 days.

A0lson added 2 commits March 6, 2023 12:17
Correct EFI 'last_area' calculation so it correctly describes the greatest possible starting
address of the last record.

(Previously, iterating the EFI Memory map resulted in a superfluous entry as it ran over the next tag)

This revision also cleans up the E820/EFI parsing to use 0-length arrays for the records
and to faciliate a more natural 'sizeof' operation on the Multiboot2 tag.
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An oddly formed multiboot tag could have a combination of "tag size" and "EFI descriptor size" that represents a non-integer multiple of descriptors. Thus, I wanted to make it clear that "last_area" should only be used as a bound and not a direct pointer to the last descriptor.

@phip1611
Copy link
Member

phip1611 commented Mar 9, 2023

Thanks very much for the contribution. I merge it as it and fix the CI issue myself.

@phip1611 phip1611 changed the base branch from main to dev March 9, 2023 15:13
@phip1611 phip1611 merged commit f71aedc into rust-osdev:dev Mar 9, 2023
phip1611 added a commit that referenced this pull request Mar 9, 2023
Merge #119 + necessary fixed into main + multiboot2-0.14.1
@phip1611
Copy link
Member

phip1611 commented Mar 9, 2023

thanks! the bug fix is live on crates.io!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants