瀏覽代碼

fix a memory overwrite bug by wys

Runji Wang 4 年之前
父節點
當前提交
5682762714

+ 1 - 0
examples/riscv/Cargo.toml

@@ -12,3 +12,4 @@ riscv = "0.5"
 opensbi-rt = { git = "https://github.com/rcore-os/opensbi-rt.git", rev = "38399b6" }
 device_tree = { git = "https://github.com/rcore-os/device_tree-rs", rev = "2fa8411" }
 virtio-drivers = { path = "../.." }
+lazy_static = { version = "1.4", features = ["spin_no_std"] }

+ 3 - 0
examples/riscv/linker32.ld

@@ -27,6 +27,7 @@ SECTIONS
     .data : {
         sdata = .;
         *(.data .data.*)
+        *(.sdata .sdata.*)
         edata = .;
     }
 
@@ -37,8 +38,10 @@ SECTIONS
     .bss : {
         sbss = .;
         *(.bss .bss.*)
+        *(.sbss .sbss.*)
         ebss = .;
     }
 
+    . = ALIGN(4K);
     PROVIDE(end = .);
 }

+ 3 - 0
examples/riscv/linker64.ld

@@ -27,6 +27,7 @@ SECTIONS
     .data : {
         sdata = .;
         *(.data .data.*)
+        *(.sdata .sdata.*)
         edata = .;
     }
 
@@ -37,8 +38,10 @@ SECTIONS
     .bss : {
         sbss = .;
         *(.bss .bss.*)
+        *(.sbss .sbss.*)
         ebss = .;
     }
 
+    . = ALIGN(4K);
     PROVIDE(end = .);
 }

+ 1 - 1
examples/riscv/rust-toolchain

@@ -1 +1 @@
-nightly
+nightly-2020-04-07

+ 8 - 1
examples/riscv/src/virtio_impl.rs

@@ -1,6 +1,13 @@
 use core::sync::atomic::*;
+use lazy_static::lazy_static;
 
-static DMA_PADDR: AtomicUsize = AtomicUsize::new(0x80300000);
+extern "C" {
+    fn end();
+}
+
+lazy_static! {
+    static ref DMA_PADDR: AtomicUsize = AtomicUsize::new(end as usize);
+}
 
 #[no_mangle]
 extern "C" fn virtio_dma_alloc(pages: usize) -> PhysAddr {