Sfoglia il codice sorgente

Merge branch 'master' into master

Tuomas Laakkonen 5 anni fa
parent
commit
a68e03d1bf
6 ha cambiato i file con 40 aggiunte e 24 eliminazioni
  1. 1 1
      Cargo.toml
  2. 1 1
      src/framebuffer.rs
  3. 16 4
      src/header.rs
  4. 9 9
      src/lib.rs
  5. 8 4
      src/memory_map.rs
  6. 5 5
      src/module.rs

+ 1 - 1
Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "multiboot2"
-version = "0.7.1"
+version = "0.8.0"
 authors = ["Philipp Oppermann <dev@phil-opp.com>", "Calvin Lee <cyrus296@gmail.com>"]
 license = "MIT/Apache-2.0"
 description = "An experimental Multiboot 2 crate for ELF-64/32 kernels."

+ 1 - 1
src/framebuffer.rs

@@ -15,7 +15,7 @@ pub struct FramebufferTag<'a> {
 #[derive(Debug, PartialEq)]
 pub enum FramebufferType<'a> {
     Indexed {
-        palette: &'a [FramebufferColor]   
+        palette: &'a [FramebufferColor]
     },
     RGB {
         red: FramebufferField,

+ 16 - 4
src/header.rs

@@ -1,3 +1,5 @@
+use core::marker::PhantomData;
+
 #[derive(Clone, Copy, Debug)]
 #[repr(C)]
 pub struct Tag {
@@ -7,14 +9,24 @@ pub struct Tag {
 }
 
 #[derive(Clone, Debug)]
-pub struct TagIter {
+pub struct TagIter<'a> {
     pub current: *const Tag,
+    phantom: PhantomData<&'a Tag>,
+}
+
+impl<'a> TagIter<'a> {
+    pub fn new(first: *const Tag) -> Self {
+        TagIter {
+            current: first,
+            phantom: PhantomData,
+        }
+    }
 }
 
-impl Iterator for TagIter {
-    type Item = &'static Tag;
+impl<'a> Iterator for TagIter<'a> {
+    type Item = &'a Tag;
 
-    fn next(&mut self) -> Option<&'static Tag> {
+    fn next(&mut self) -> Option<&'a Tag> {
         match unsafe{&*self.current} {
             &Tag{typ:0, size:8} => None, // end tag
             tag => {

+ 9 - 9
src/lib.rs

@@ -76,7 +76,7 @@ impl BootInformation {
         })
     }
 
-    pub fn memory_map_tag(&self) -> Option<&'static MemoryMapTag> {
+    pub fn memory_map_tag<'a>(&'a self) -> Option<&'a MemoryMapTag> {
         self.get_tag(6).map(|tag| unsafe { &*(tag as *const Tag as *const MemoryMapTag) })
     }
 
@@ -84,23 +84,23 @@ impl BootInformation {
         module::module_iter(self.tags())
     }
 
-    pub fn boot_loader_name_tag(&self) -> Option<&'static BootLoaderNameTag> {
+    pub fn boot_loader_name_tag<'a>(&'a self) -> Option<&'a BootLoaderNameTag> {
         self.get_tag(2).map(|tag| unsafe { &*(tag as *const Tag as *const BootLoaderNameTag) })
     }
 
-    pub fn command_line_tag(&self) -> Option<&'static CommandLineTag> {
+    pub fn command_line_tag<'a>(&'a self) -> Option<&'a CommandLineTag> {
         self.get_tag(1).map(|tag| unsafe { &*(tag as *const Tag as *const CommandLineTag) })
     }
 
-    pub fn framebuffer_tag(&self) -> Option<FramebufferTag<'static>> {
+    pub fn framebuffer_tag<'a>(&'a self) -> Option<FramebufferTag<'a>> {
         self.get_tag(8).map(|tag| framebuffer::framebuffer_tag(tag))
     }
 
-    pub fn rsdp_v1_tag(&self) -> Option<&'static RsdpV1Tag> {
+    pub fn rsdp_v1_tag<'a>(&self) -> Option<&'a RsdpV1Tag> {
         self.get_tag(14).map(|tag| unsafe { &*(tag as *const Tag as *const RsdpV1Tag) })
     }
 
-    pub fn rsdp_v2_tag(&self) -> Option<&'static RsdpV2Tag> {
+    pub fn rsdp_v2_tag<'a>(&'a self) -> Option<&'a RsdpV2Tag> {
         self.get_tag(15).map(|tag| unsafe { &*(tag as *const Tag as *const RsdpV2Tag) })
     }
 
@@ -112,12 +112,12 @@ impl BootInformation {
         unsafe { &*self.inner }
     }
 
-    fn get_tag(&self, typ: u32) -> Option<&'static Tag> {
+    fn get_tag<'a>(&'a self, typ: u32) -> Option<&'a Tag> {
         self.tags().find(|tag| tag.typ == typ)
     }
 
     fn tags(&self) -> TagIter {
-        TagIter { current: unsafe { self.inner.offset(1) } as *const _ }
+        TagIter::new(unsafe { self.inner.offset(1) } as *const _)
     }
 }
 
@@ -323,7 +323,7 @@ mod tests {
     #[test]
     fn framebuffer_tag_rgb() {
         // direct RGB mode test:
-        // taken from GRUB2 running in QEMU at 
+        // taken from GRUB2 running in QEMU at
         // 1280x720 with 32bpp in BGRA format.
         #[repr(C, align(8))]
         struct Bytes([u8; 56]);

+ 8 - 4
src/memory_map.rs

@@ -1,3 +1,5 @@
+use core::marker::PhantomData;
+
 #[derive(Debug)]
 #[repr(C)]
 pub struct MemoryMapTag {
@@ -16,6 +18,7 @@ impl MemoryMapTag {
             current_area: start_area as u64,
             last_area: (self_ptr as u64 + (self.size - self.entry_size) as u64),
             entry_size: self.entry_size,
+            phantom: PhantomData,
         }
     }
 }
@@ -44,15 +47,16 @@ impl MemoryArea {
 }
 
 #[derive(Clone, Debug)]
-pub struct MemoryAreaIter {
+pub struct MemoryAreaIter<'a> {
     current_area: u64,
     last_area: u64,
     entry_size: u32,
+    phantom: PhantomData<&'a MemoryArea>,
 }
 
-impl Iterator for MemoryAreaIter {
-    type Item = &'static MemoryArea;
-    fn next(&mut self) -> Option<&'static MemoryArea> {
+impl<'a> Iterator for MemoryAreaIter<'a> {
+    type Item = &'a MemoryArea;
+    fn next(&mut self) -> Option<&'a MemoryArea> {
         if self.current_area > self.last_area {
             None
         } else {

+ 5 - 5
src/module.rs

@@ -37,14 +37,14 @@ pub fn module_iter(iter: TagIter) -> ModuleIter {
 }
 
 #[derive(Clone, Debug)]
-pub struct ModuleIter {
-    iter: TagIter,
+pub struct ModuleIter<'a> {
+    iter: TagIter<'a>,
 }
 
-impl Iterator for ModuleIter {
-    type Item = &'static ModuleTag;
+impl<'a> Iterator for ModuleIter<'a> {
+    type Item = &'a ModuleTag;
 
-    fn next(&mut self) -> Option<&'static ModuleTag> {
+    fn next(&mut self) -> Option<&'a ModuleTag> {
         self.iter.find(|x| x.typ == 3)
             .map(|tag| unsafe{&*(tag as *const Tag as *const ModuleTag)})
     }