Skip to content

multiboot2: Add the end tag #138

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 1 commit into from
May 23, 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
7 changes: 2 additions & 5 deletions multiboot2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub use module::{ModuleIter, ModuleTag};
pub use rsdp::{RsdpV1Tag, RsdpV2Tag};
pub use smbios::SmbiosTag;
use tag_type::TagIter;
pub use tag_type::{Tag, TagType, TagTypeId};
pub use tag_type::{EndTag, Tag, TagType, TagTypeId};
pub use vbe_info::{
VBECapabilities, VBEControlInfo, VBEDirectColorAttributes, VBEField, VBEInfoTag,
VBEMemoryModel, VBEModeAttributes, VBEModeInfo, VBEWindowAttributes,
Expand Down Expand Up @@ -391,10 +391,7 @@ impl BootInformation {

impl BootInformationInner {
fn has_valid_end_tag(&self) -> bool {
let end_tag_prototype: Tag = Tag {
typ: TagType::End.into(),
size: 8,
};
let end_tag_prototype = EndTag::default();

let self_ptr = self as *const _;
let end_tag_addr = self_ptr as usize + (self.total_size - end_tag_prototype.size) as usize;
Expand Down
26 changes: 26 additions & 0 deletions multiboot2/src/tag_type.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Module for the basic Multiboot2 tag and corresponding tag types.
//!
//! The relevant exports of this module are:
//! - [`EndTag`]
//! - [`TagTypeId`]
//! - [`TagType`]
//! - [`Tag`]
Expand Down Expand Up @@ -350,6 +351,23 @@ impl Debug for Tag {
}
}

/// The end tag ends the information struct.
#[repr(C)]
#[derive(Debug)]
pub struct EndTag {
pub typ: TagTypeId,
pub size: u32,
}

impl Default for EndTag {
fn default() -> Self {
Self {
typ: TagType::End.into(),
size: 8,
}
}
}

#[derive(Clone, Debug)]
pub struct TagIter<'a> {
pub current: *const Tag,
Expand Down Expand Up @@ -478,4 +496,12 @@ mod tests {
Err(Utf8Error { .. })
));
}

#[test]
/// Compile time test for [`EndTag`].
fn test_end_tag_size() {
unsafe {
core::mem::transmute::<[u8; 8], EndTag>([0u8; 8]);
}
}
}