diff --git a/kernel/src/process/structs.rs b/kernel/src/process/structs.rs index a8b0b63..06cb0b7 100644 --- a/kernel/src/process/structs.rs +++ b/kernel/src/process/structs.rs @@ -158,15 +158,12 @@ impl Thread { } /// Make a new user process from ELF `data` - pub fn new_user<'a, Iter>( + pub fn new_user( data: &[u8], exec_path: &str, - args: Iter, + mut args: Vec, envs: Vec, - ) -> Box - where - Iter: Iterator, - { + ) -> Box { // Parse ELF let elf = ElfFile::new(data).expect("failed to read elf"); @@ -185,12 +182,11 @@ impl Thread { debug!("using loader {}", &loader_path); // Elf loader should not have INTERP // No infinite loop - let mut new_args: Vec<&str> = args.collect(); - new_args.insert(0, loader_path); - new_args.insert(1, exec_path); - new_args.remove(2); - warn!("loader args: {:?}", new_args); - return Thread::new_user(buf.as_slice(), exec_path, new_args.into_iter(), envs); + args.insert(0, loader_path.into()); + args.insert(1, exec_path.into()); + args.remove(2); + warn!("loader args: {:?}", args); + return Thread::new_user(buf.as_slice(), exec_path, args, envs); } else { warn!("loader specified as {} but failed to read", &loader_path); } @@ -219,7 +215,7 @@ impl Thread { // Make init info let init_info = ProcInitInfo { - args: args.map(|s| String::from(s)).collect(), + args, envs, auxv: { let mut map = BTreeMap::new(); diff --git a/kernel/src/shell.rs b/kernel/src/shell.rs index 4c88786..fe8dc61 100644 --- a/kernel/src/shell.rs +++ b/kernel/src/shell.rs @@ -13,7 +13,7 @@ pub fn run_user_shell() { processor().manager().add(Thread::new_user( data.as_slice(), "rust/sh", - "sh".split(' '), + vec!["sh".into()], Vec::new(), )); } else { @@ -28,7 +28,7 @@ pub fn run_user_shell() { let data = inode.read_as_vec().unwrap(); processor().manager().add(Thread::new_user( data.as_slice(), - cmdline.split(' '), + cmdline.split(' ').map(|s| s.into()).collect(), Vec::new(), )); } @@ -50,7 +50,7 @@ pub extern "C" fn shell(_arg: usize) -> ! { let _pid = processor().manager().add(Thread::new_user( data.as_slice(), &cmd, - cmd.split(' '), + cmd.split(' ').map(|s| s.into()).collect(), Vec::new(), )); // TODO: wait until process exits, or use user land shell completely diff --git a/kernel/src/syscall/proc.rs b/kernel/src/syscall/proc.rs index 7e68948..9f3c97c 100644 --- a/kernel/src/syscall/proc.rs +++ b/kernel/src/syscall/proc.rs @@ -176,8 +176,7 @@ pub fn sys_exec( let buf = inode.read_as_vec()?; // Make new Thread - let args_iter = args.iter().map(|s| s.as_str()); - let mut thread = Thread::new_user(buf.as_slice(), exec_path, args_iter, envs); + let mut thread = Thread::new_user(buf.as_slice(), exec_path, args, envs); thread.proc.lock().clone_for_exec(&proc); // Activate new page table