Prechádzať zdrojové kódy

multiboot2: tiny code improvement

Philipp Schuster 8 mesiacov pred
rodič
commit
41cbe18ecf

+ 4 - 4
integration-test/bins/multiboot2_chainloader/src/loader.rs

@@ -44,15 +44,15 @@ pub fn load_module(mut modules: multiboot::information::ModuleIter) -> ! {
 
     // build MBI
     let mbi = multiboot2::builder::InformationBuilder::new()
-        .bootloader_name_tag(BootLoaderNameTag::new("mb2_integrationtest_chainloader"))
-        .command_line_tag(CommandLineTag::new("chainloaded YEAH"))
+        .bootloader_name_tag(&BootLoaderNameTag::new("mb2_integrationtest_chainloader"))
+        .command_line_tag(&CommandLineTag::new("chainloaded YEAH"))
         // random non-sense memory map
-        .memory_map_tag(MemoryMapTag::new(&[MemoryArea::new(
+        .memory_map_tag(&MemoryMapTag::new(&[MemoryArea::new(
             0,
             0xffffffff,
             MemoryAreaType::Reserved,
         )]))
-        .add_module_tag(ModuleTag::new(
+        .add_module_tag(&ModuleTag::new(
             elf_mod.start as u32,
             elf_mod.end as u32,
             elf_mod.string.unwrap(),

+ 2 - 1
multiboot2/src/boot_loader_name.rs

@@ -89,6 +89,7 @@ mod tests {
     use super::*;
     use crate::tag::{GenericTag, TagBytesRef};
     use crate::test_util::AlignedBytes;
+    use core::borrow::Borrow;
 
     #[rustfmt::skip]
     fn get_bytes() -> AlignedBytes<16> {
@@ -105,7 +106,7 @@ mod tests {
     #[test]
     fn test_parse_str() {
         let bytes = get_bytes();
-        let bytes = TagBytesRef::try_from(&bytes[..]).unwrap();
+        let bytes = TagBytesRef::try_from(bytes.borrow()).unwrap();
         let tag = GenericTag::ref_from(bytes);
         let tag = tag.cast::<BootLoaderNameTag>();
         assert_eq!(tag.header.typ, TagType::BootLoaderName);

+ 2 - 1
multiboot2/src/command_line.rs

@@ -83,6 +83,7 @@ mod tests {
     use super::*;
     use crate::tag::{GenericTag, TagBytesRef};
     use crate::test_util::AlignedBytes;
+    use core::borrow::Borrow;
 
     #[rustfmt::skip]
     fn get_bytes() -> AlignedBytes<16> {
@@ -99,7 +100,7 @@ mod tests {
     #[test]
     fn test_parse_str() {
         let bytes = get_bytes();
-        let bytes = TagBytesRef::try_from(&bytes[..]).unwrap();
+        let bytes = TagBytesRef::try_from(bytes.borrow()).unwrap();
         let tag = GenericTag::ref_from(bytes);
         let tag = tag.cast::<CommandLineTag>();
         assert_eq!(tag.header.typ, TagType::Cmdline);

+ 2 - 1
multiboot2/src/module.rs

@@ -130,6 +130,7 @@ mod tests {
     use super::*;
     use crate::tag::{GenericTag, TagBytesRef};
     use crate::test_util::AlignedBytes;
+    use core::borrow::Borrow;
 
     #[rustfmt::skip]
     fn get_bytes() -> AlignedBytes<24> {
@@ -150,7 +151,7 @@ mod tests {
     #[test]
     fn test_parse_str() {
         let bytes = get_bytes();
-        let bytes = TagBytesRef::try_from(&bytes[..]).unwrap();
+        let bytes = TagBytesRef::try_from(bytes.borrow()).unwrap();
         let tag = GenericTag::ref_from(bytes);
         let tag = tag.cast::<ModuleTag>();
         assert_eq!(tag.header.typ, TagType::Module);

+ 2 - 1
multiboot2/src/smbios.rs

@@ -73,6 +73,7 @@ mod tests {
     use super::*;
     use crate::tag::{GenericTag, TagBytesRef};
     use crate::test_util::AlignedBytes;
+    use core::borrow::Borrow;
 
     #[rustfmt::skip]
     fn get_bytes() -> AlignedBytes<32> {
@@ -96,7 +97,7 @@ mod tests {
     #[test]
     fn test_parse() {
         let bytes = get_bytes();
-        let bytes = TagBytesRef::try_from(&bytes[..]).unwrap();
+        let bytes = TagBytesRef::try_from(bytes.borrow()).unwrap();
         let tag = GenericTag::ref_from(bytes);
         let tag = tag.cast::<SmbiosTag>();
         assert_eq!(tag.header.typ, TagType::Smbios);

+ 7 - 6
multiboot2/src/tag.rs

@@ -236,6 +236,7 @@ impl<'a> Iterator for TagIter<'a> {
 mod tests {
     use super::*;
     use crate::test_util::AlignedBytes;
+    use core::borrow::Borrow;
     use core::mem;
 
     #[test]
@@ -248,7 +249,7 @@ mod tests {
             0x13, 0x37, 0x13, 0x37,
         ]);
 
-        let bytes = TagBytesRef::try_from(&bytes[..]).unwrap();
+        let bytes = TagBytesRef::try_from(bytes.borrow()).unwrap();
         let tag = GenericTag::ref_from(bytes);
         assert_eq!(tag.header.typ, 0xffff_ffff);
         assert_eq!(tag.header.size, 16);
@@ -277,7 +278,7 @@ mod tests {
             0xef, 0xbe, 0xad, 0xde, /* field b: 0x1337_1337 */
             0x37, 0x13, 0x37, 0x13,
         ]);
-        let bytes = TagBytesRef::try_from(&bytes[..]).unwrap();
+        let bytes = TagBytesRef::try_from(bytes.borrow()).unwrap();
         let tag = GenericTag::ref_from(bytes);
         let custom_tag = tag.cast::<CustomTag>();
 
@@ -313,7 +314,7 @@ mod tests {
             0x37, 0x13, 0x37, 0x13,
         ]);
 
-        let bytes = TagBytesRef::try_from(&bytes[..]).unwrap();
+        let bytes = TagBytesRef::try_from(bytes.borrow()).unwrap();
         let tag = GenericTag::ref_from(bytes);
         let custom_tag = tag.cast::<CustomDstTag>();
 
@@ -369,7 +370,7 @@ mod tests {
                 0, 0, 0, 0, 0, 0
             ],
         );
-        let bytes = TagBytesRef::try_from(&bytes[..]).unwrap();
+        let bytes = TagBytesRef::try_from(bytes.borrow()).unwrap();
         let tag = GenericTag::ref_from(bytes);
         assert_eq!(tag.header.typ, TagType::Cmdline);
         assert_eq!(tag.header.size, 8 + 10);
@@ -391,7 +392,7 @@ mod tests {
                 0, 0, 0, 0, 0, 0
             ],
         );
-        let bytes = TagBytesRef::try_from(&bytes[..]).unwrap();
+        let bytes = TagBytesRef::try_from(bytes.borrow()).unwrap();
         let tag = GenericTag::ref_from(bytes);
 
         // Main objective here is also that this test passes Miri.
@@ -419,7 +420,7 @@ mod tests {
                 8, 0, 0, 0,
             ],
         );
-        let mut iter = TagIter::new(&bytes[..]);
+        let mut iter = TagIter::new(bytes.borrow());
         let first = iter.next().unwrap();
         assert_eq!(first.header.typ, TagType::Custom(0xff));
         assert_eq!(first.header.size, 8);

+ 1 - 1
multiboot2/src/test_util.rs

@@ -82,6 +82,6 @@ mod tests {
                 0, 0,
             ]
         );
-        let _a = TagBytesRef::try_from(&bytes[..]).unwrap();
+        let _a = TagBytesRef::try_from(bytes.borrow()).unwrap();
     }
 }