Răsfoiți Sursa

Merge pull request #157 from rust-osdev/fixes

various fixes
Philipp Schuster 1 an în urmă
părinte
comite
53af75990e

+ 1 - 0
multiboot2/Changelog.md

@@ -17,6 +17,7 @@
 - **BREAKING** Renamed `EFISdt32` to `EFISdt32Tag`
 - **BREAKING** Renamed `EFISdt64` to `EFISdt64Tag`
 - **BREAKING** Renamed `EFIBootServicesNotExited` to `EFIBootServicesNotExitedTag`
+- **BREAKING** Renamed `CommandLineTag::command_line` renamed to `CommandLineTag::cmdline`
 - **\[Might be\] BREAKING** Added `TagTrait` trait which enables to use DSTs as multiboot2 tags. This is
   mostly relevant for the command line tag, the modules tag, and the bootloader
   name tag. However, this might also be relevant for users of custom multiboot2

+ 1 - 0
multiboot2/src/boot_loader_name.rs

@@ -118,5 +118,6 @@ mod tests {
         let tag = BootLoaderNameTag::new(MSG);
         let bytes = tag.struct_as_bytes();
         assert_eq!(bytes, get_bytes());
+        assert_eq!(tag.name(), Ok(MSG));
     }
 }

+ 1 - 4
multiboot2/src/builder/information.rs

@@ -335,10 +335,7 @@ mod tests {
             mb2i.basic_memory_info_tag().unwrap().memory_upper(),
             7 * 1024
         );
-        assert_eq!(
-            mb2i.command_line_tag().unwrap().command_line().unwrap(),
-            "test"
-        );
+        assert_eq!(mb2i.command_line_tag().unwrap().cmdline().unwrap(), "test");
         let mut modules = mb2i.module_tags();
         let module_1 = modules.next().unwrap();
         assert_eq!(module_1.start_address(), 0);

+ 2 - 7
multiboot2/src/builder/mod.rs

@@ -8,7 +8,7 @@ pub use information::InformationBuilder;
 use alloc::alloc::alloc;
 use alloc::boxed::Box;
 use core::alloc::Layout;
-use core::mem::{align_of_val, size_of, size_of_val};
+use core::mem::{align_of_val, size_of};
 use core::ops::Deref;
 
 use crate::{Tag, TagTrait, TagTypeId};
@@ -28,11 +28,7 @@ pub(super) fn boxed_dst_tag<T: TagTrait<Metadata = usize> + ?Sized>(
     const ALIGN: usize = 4;
 
     let tag_size = size_of::<TagTypeId>() + size_of::<u32>() + content.len();
-    // round up to the next multiple of 8
-    // Rust uses this convention for all types. I found out so by checking
-    // miris output of the corresponding unit test.
-    let alloc_size = (tag_size + 7) & !0b111;
-    let layout = Layout::from_size_align(alloc_size, ALIGN).unwrap();
+    let layout = Layout::from_size_align(tag_size, ALIGN).unwrap();
     let ptr = unsafe { alloc(layout) };
     assert!(!ptr.is_null());
 
@@ -61,7 +57,6 @@ pub(super) fn boxed_dst_tag<T: TagTrait<Metadata = usize> + ?Sized>(
         let boxed = Box::from_raw(raw);
         let reference: &T = boxed.deref();
         // If this panics, please create an issue on GitHub.
-        assert_eq!(size_of_val(reference), alloc_size);
         assert_eq!(align_of_val(reference), ALIGN);
         boxed
     }

+ 5 - 4
multiboot2/src/command_line.rs

@@ -52,11 +52,11 @@ impl CommandLineTag {
     /// ```rust,no_run
     /// # let boot_info = unsafe { multiboot2::load(0xdeadbeef).unwrap() };
     /// if let Some(tag) = boot_info.command_line_tag() {
-    ///     let command_line = tag.command_line();
+    ///     let command_line = tag.cmdline();
     ///     assert_eq!(Ok("/bootarg"), command_line);
     /// }
     /// ```
-    pub fn command_line(&self) -> Result<&str, str::Utf8Error> {
+    pub fn cmdline(&self) -> Result<&str, str::Utf8Error> {
         Tag::get_dst_str_slice(&self.cmdline)
     }
 }
@@ -66,7 +66,7 @@ impl Debug for CommandLineTag {
         f.debug_struct("CommandLineTag")
             .field("typ", &{ self.typ })
             .field("size", &{ self.size })
-            .field("cmdline", &self.command_line())
+            .field("cmdline", &self.cmdline())
             .finish()
     }
 }
@@ -115,7 +115,7 @@ mod tests {
         let tag = unsafe { &*tag.as_ptr().cast::<Tag>() };
         let tag = tag.cast_tag::<CommandLineTag>();
         assert_eq!({ tag.typ }, TagType::Cmdline);
-        assert_eq!(tag.command_line().expect("must be valid UTF-8"), MSG);
+        assert_eq!(tag.cmdline().expect("must be valid UTF-8"), MSG);
     }
 
     /// Test to generate a tag from a given string.
@@ -127,5 +127,6 @@ mod tests {
         let tag = CommandLineTag::new(MSG);
         let bytes = tag.struct_as_bytes();
         assert_eq!(bytes, get_bytes());
+        assert_eq!(tag.cmdline(), Ok(MSG));
     }
 }

+ 4 - 3
multiboot2/src/lib.rs

@@ -285,7 +285,8 @@ impl<'a> BootInformation<'a> {
         self.get_tag::<BasicMemoryInfoTag, _>(TagType::BasicMeminfo)
     }
 
-    /// Search for the ELF Sections.
+    /// Returns an [`ElfSectionIter`] iterator over the ELF Sections, if the
+    /// [`ElfSectionsTag`] is present.
     ///
     /// # Examples
     ///
@@ -497,7 +498,7 @@ impl fmt::Debug for BootInformation<'_> {
                 "command_line",
                 &self
                     .command_line_tag()
-                    .and_then(|x| x.command_line().ok())
+                    .and_then(|x| x.cmdline().ok())
                     .unwrap_or(""),
             )
             .field("memory_areas", &self.memory_map_tag())
@@ -1392,7 +1393,7 @@ mod tests {
             "",
             bi.command_line_tag()
                 .expect("tag must present")
-                .command_line()
+                .cmdline()
                 .expect("must be valid utf-8")
         );
 

+ 1 - 0
multiboot2/src/module.rs

@@ -173,5 +173,6 @@ mod tests {
         let tag = ModuleTag::new(0, 0, MSG);
         let bytes = tag.struct_as_bytes();
         assert_eq!(bytes, get_bytes());
+        assert_eq!(tag.cmdline(), Ok(MSG));
     }
 }