From bc1bad3060bc1b0f65b84f273dc54e91d7d27ed5 Mon Sep 17 00:00:00 2001 From: WangRunji Date: Tue, 30 Apr 2019 19:21:14 +0800 Subject: [PATCH] optimize sys_exec: only read ELF header --- kernel/src/process/structs.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kernel/src/process/structs.rs b/kernel/src/process/structs.rs index bdb72d7..2ec8dcf 100644 --- a/kernel/src/process/structs.rs +++ b/kernel/src/process/structs.rs @@ -20,6 +20,7 @@ use crate::memory::{ use crate::sync::{Condvar, SpinNoIrqLock as Mutex}; use super::abi::{self, ProcInitInfo}; +use core::mem::uninitialized; use rcore_fs::vfs::INode; // TODO: avoid pub @@ -138,9 +139,11 @@ impl Thread { mut args: Vec, envs: Vec, ) -> Result<(MemorySet, usize, usize), &'static str> { - // Read data - let data = inode - .read_as_vec() + // Read ELF header + // 0x3c0: magic number from ld-musl.so + let mut data: [u8; 0x3c0] = unsafe { uninitialized() }; + inode + .read_at(0, &mut data) .map_err(|_| "failed to read from INode")?; // Parse ELF