Skip to content

Commit 455f7bc

Browse files
authored
Merge pull request #138 from YtvwlD/end-tag
multiboot2: Add the end tag
2 parents 798e081 + 2e37c51 commit 455f7bc

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

multiboot2/src/lib.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub use module::{ModuleIter, ModuleTag};
5959
pub use rsdp::{RsdpV1Tag, RsdpV2Tag};
6060
pub use smbios::SmbiosTag;
6161
use tag_type::TagIter;
62-
pub use tag_type::{Tag, TagType, TagTypeId};
62+
pub use tag_type::{EndTag, Tag, TagType, TagTypeId};
6363
pub use vbe_info::{
6464
VBECapabilities, VBEControlInfo, VBEDirectColorAttributes, VBEField, VBEInfoTag,
6565
VBEMemoryModel, VBEModeAttributes, VBEModeInfo, VBEWindowAttributes,
@@ -391,10 +391,7 @@ impl BootInformation {
391391

392392
impl BootInformationInner {
393393
fn has_valid_end_tag(&self) -> bool {
394-
let end_tag_prototype: Tag = Tag {
395-
typ: TagType::End.into(),
396-
size: 8,
397-
};
394+
let end_tag_prototype = EndTag::default();
398395

399396
let self_ptr = self as *const _;
400397
let end_tag_addr = self_ptr as usize + (self.total_size - end_tag_prototype.size) as usize;

multiboot2/src/tag_type.rs

+26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Module for the basic Multiboot2 tag and corresponding tag types.
22
//!
33
//! The relevant exports of this module are:
4+
//! - [`EndTag`]
45
//! - [`TagTypeId`]
56
//! - [`TagType`]
67
//! - [`Tag`]
@@ -350,6 +351,23 @@ impl Debug for Tag {
350351
}
351352
}
352353

354+
/// The end tag ends the information struct.
355+
#[repr(C)]
356+
#[derive(Debug)]
357+
pub struct EndTag {
358+
pub typ: TagTypeId,
359+
pub size: u32,
360+
}
361+
362+
impl Default for EndTag {
363+
fn default() -> Self {
364+
Self {
365+
typ: TagType::End.into(),
366+
size: 8,
367+
}
368+
}
369+
}
370+
353371
#[derive(Clone, Debug)]
354372
pub struct TagIter<'a> {
355373
pub current: *const Tag,
@@ -478,4 +496,12 @@ mod tests {
478496
Err(Utf8Error { .. })
479497
));
480498
}
499+
500+
#[test]
501+
/// Compile time test for [`EndTag`].
502+
fn test_end_tag_size() {
503+
unsafe {
504+
core::mem::transmute::<[u8; 8], EndTag>([0u8; 8]);
505+
}
506+
}
481507
}

0 commit comments

Comments
 (0)