diff --git a/multiboot2/src/lib.rs b/multiboot2/src/lib.rs index b81f787c..c40c4507 100644 --- a/multiboot2/src/lib.rs +++ b/multiboot2/src/lib.rs @@ -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, @@ -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; diff --git a/multiboot2/src/tag_type.rs b/multiboot2/src/tag_type.rs index c8bd22f4..42aaac77 100644 --- a/multiboot2/src/tag_type.rs +++ b/multiboot2/src/tag_type.rs @@ -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`] @@ -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, @@ -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]); + } + } }