From fc5a35d22a8b56cd66cca771e3d9a0a964fa2905 Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jackpot51@gmail.com>
Date: Wed, 28 Sep 2016 20:42:03 -0600
Subject: [PATCH] 64-bit stat size, read entire executable in one go

---
 scheme/env.rs      |  2 +-
 scheme/initfs.rs   |  2 +-
 syscall/process.rs | 15 +++++----------
 3 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/scheme/env.rs b/scheme/env.rs
index 7f2bcb83..807c2736 100644
--- a/scheme/env.rs
+++ b/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/scheme/initfs.rs b/scheme/initfs.rs
index d23adc75..c3a795c8 100644
--- a/scheme/initfs.rs
+++ b/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/syscall/process.rs b/syscall/process.rs
index d953e42b..57965123 100644
--- a/syscall/process.rs
+++ b/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<usize> {
         }
 
         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) {
-- 
GitLab