소스 검색

Merge pull request #138 from YtvwlD/end-tag

multiboot2: Add the end tag
Philipp Schuster 1 년 전
부모
커밋
455f7bcf89
2개의 변경된 파일28개의 추가작업 그리고 5개의 파일을 삭제
  1. 2 5
      multiboot2/src/lib.rs
  2. 26 0
      multiboot2/src/tag_type.rs

+ 2 - 5
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;

+ 26 - 0
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]);
+        }
+    }
 }