diff --git a/build.rs b/build.rs index 296676966010403994c9be2b6fae78070965fd73..cddbfab08028789c8c9a1620f78784d13008b55b 100644 --- a/build.rs +++ b/build.rs @@ -87,6 +87,8 @@ fn fill_from_location(f: &mut fs::File, loc: &Path ) -> Result<(), (Error)> { } fn main() { + println!("cargo:rustc-env=TARGET={}", env::var("TARGET").unwrap()); + let out_dir = env::var("OUT_DIR").unwrap(); let dest_path = Path::new(&out_dir).join("gen.rs"); let mut f = fs::File::create(&dest_path).unwrap(); @@ -114,8 +116,4 @@ b" files.clear();" // Silence mutability warning } } ").unwrap(); - - fn main() { - println!("cargo:rustc-env=TARGET={}", env::var("TARGET").unwrap()); - } } diff --git a/src/consts.rs b/src/consts.rs index c8acb3942ee826a1d8002610e4b6b0eb64651457..be856c35b7ed5a204fe122fb03b751335d1c7f99 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -15,10 +15,7 @@ /// Offset to kernel heap pub const KERNEL_HEAP_OFFSET: usize = KERNEL_OFFSET + PML4_SIZE/2; /// Size of kernel heap - #[cfg(not(feature = "live"))] - pub const KERNEL_HEAP_SIZE: usize = 128 * 1024 * 1024; // 128 MB - #[cfg(feature = "live")] - pub const KERNEL_HEAP_SIZE: usize = 640 * 1024 * 1024; // 640 MB - 128 default + 512 for the live disk + pub const KERNEL_HEAP_SIZE: usize = 64 * 1024 * 1024; // 64 MB /// Offset to kernel percpu variables //TODO: Use 64-bit fs offset to enable this pub const KERNEL_PERCPU_OFFSET: usize = KERNEL_HEAP_OFFSET - PML4_SIZE; diff --git a/src/scheme/live.rs b/src/scheme/live.rs index 93835ca476d64c150943163c98a8e840b49e238d..4ea1eef3bca2922a74bdcb9e5daf23f473fea558 100644 --- a/src/scheme/live.rs +++ b/src/scheme/live.rs @@ -1,8 +1,8 @@ /// Disk scheme replacement when making live disk use alloc::arc::Arc; -use collections::{BTreeMap, Vec}; -use core::cmp; +use collections::BTreeMap; +use core::{cmp, slice}; use core::sync::atomic::{AtomicUsize, Ordering}; use spin::RwLock; @@ -11,26 +11,41 @@ use syscall::error::*; use syscall::flag::{MODE_FILE, SEEK_SET, SEEK_CUR, SEEK_END}; use syscall::scheme::Scheme; -static FILESYSTEM: &'static [u8] = include_bytes!(env!("FILESYSTEM")); - struct Handle { path: &'static [u8], - data: Arc<RwLock<Vec<u8>>>, + data: Arc<RwLock<&'static mut [u8]>>, mode: u16, seek: usize } pub struct DiskScheme { next_id: AtomicUsize, - data: Arc<RwLock<Vec<u8>>>, + data: Arc<RwLock<&'static mut [u8]>>, handles: RwLock<BTreeMap<usize, Handle>> } impl DiskScheme { pub fn new() -> DiskScheme { + let data; + unsafe { + extern { + static mut __live_start: u8; + static mut __live_end: u8; + } + + let start = &mut __live_start as *mut u8; + let end = &mut __live_end as *mut u8; + + if end as usize >= start as usize { + data = slice::from_raw_parts_mut(start, end as usize - start as usize); + } else { + data = &mut []; + }; + } + DiskScheme { next_id: AtomicUsize::new(0), - data: Arc::new(RwLock::new(FILESYSTEM.to_vec())), + data: Arc::new(RwLock::new(data)), handles: RwLock::new(BTreeMap::new()) } }