From 5e1d2f8c64058ff63531a4a4663cae590939b121 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 28 Sep 2016 20:42:03 -0600 Subject: [PATCH] 64-bit stat size, read entire executable in one go --- kernel/scheme/env.rs | 2 +- kernel/scheme/initfs.rs | 2 +- kernel/syscall/process.rs | 15 +++++---------- libstd | 2 +- schemes/redoxfs | 2 +- syscall/src/data.rs | 13 +++---------- 6 files changed, 12 insertions(+), 24 deletions(-) diff --git a/kernel/scheme/env.rs b/kernel/scheme/env.rs index 7f2bcb8..807c273 100644 --- a/kernel/scheme/env.rs +++ b/kernel/scheme/env.rs @@ -159,7 +159,7 @@ impl Scheme for EnvScheme { let handle = handles.get(&id).ok_or(Error::new(EBADF))?; stat.st_mode = handle.mode; - stat.st_size = handle.data.lock().len() as u32; //TODO: st_size 64-bit + stat.st_size = handle.data.lock().len() as u64; Ok(0) } diff --git a/kernel/scheme/initfs.rs b/kernel/scheme/initfs.rs index d23adc7..c3a795c 100644 --- a/kernel/scheme/initfs.rs +++ b/kernel/scheme/initfs.rs @@ -130,7 +130,7 @@ impl Scheme for InitFsScheme { let handle = handles.get(&id).ok_or(Error::new(EBADF))?; stat.st_mode = handle.mode; - stat.st_size = handle.data.len() as u32; //TODO: st_size 64-bit + stat.st_size = handle.data.len() as u64; Ok(0) } diff --git a/kernel/syscall/process.rs b/kernel/syscall/process.rs index d953e42..5796512 100644 --- a/kernel/syscall/process.rs +++ b/kernel/syscall/process.rs @@ -17,6 +17,7 @@ use context::memory::Grant; use elf::{self, program_header}; use scheme; use syscall; +use syscall::data::Stat; use syscall::error::*; use syscall::flag::{CLONE_VM, CLONE_FS, CLONE_FILES, MAP_WRITE, MAP_WRITE_COMBINE, WNOHANG}; use syscall::validate::{validate_slice, validate_slice_mut}; @@ -391,17 +392,11 @@ pub fn exec(path: &[u8], arg_ptrs: &[[usize; 2]]) -> Result { } let file = syscall::open(path, 0)?; + let mut stat = Stat::default(); + syscall::fstat(file, &mut stat)?; //TODO: Only read elf header, not entire file. Then read required segments - let mut data = vec![]; - loop { - let mut buf = [0; 16384]; - let count = syscall::read(file, &mut buf)?; - if count > 0 { - data.extend_from_slice(&buf[..count]); - } else { - break; - } - } + let mut data = vec![0; stat.st_size as usize]; + syscall::read(file, &mut data)?; let _ = syscall::close(file); match elf::Elf::from(&data) { diff --git a/libstd b/libstd index 4dbfda1..9b2e8ea 160000 --- a/libstd +++ b/libstd @@ -1 +1 @@ -Subproject commit 4dbfda17c3c2e2a0d88687a42151fc8a81f28ca0 +Subproject commit 9b2e8ea8196cdf8023fb54e8581f94e45b8dec4f diff --git a/schemes/redoxfs b/schemes/redoxfs index 36b3cf0..1488d1e 160000 --- a/schemes/redoxfs +++ b/schemes/redoxfs @@ -1 +1 @@ -Subproject commit 36b3cf04a9d35b85d481acdf99494fc535152cf0 +Subproject commit 1488d1ef5661496aff695f2e1bf67997d4654329 diff --git a/syscall/src/data.rs b/syscall/src/data.rs index 5ed4cd4..7200006 100644 --- a/syscall/src/data.rs +++ b/syscall/src/data.rs @@ -55,17 +55,10 @@ impl DerefMut for Packet { #[derive(Copy, Clone, Debug, Default)] #[repr(packed)] pub struct Stat { - pub st_dev: u16, - pub st_ino: u16, pub st_mode: u16, - pub st_nlink: u16, - pub st_uid: u16, - pub st_gid: u16, - pub st_rdev: u16, - pub st_size: u32, - pub st_atime: u32, - pub st_mtime: u32, - pub st_ctime: u32 + pub st_uid: u32, + pub st_gid: u32, + pub st_size: u64 } impl Deref for Stat {