change args from Iter to Vec<String>

master
WangRunji 6 years ago
parent 0ff24fe589
commit 520bb2d957

@ -158,15 +158,12 @@ impl Thread {
} }
/// Make a new user process from ELF `data` /// Make a new user process from ELF `data`
pub fn new_user<'a, Iter>( pub fn new_user(
data: &[u8], data: &[u8],
exec_path: &str, exec_path: &str,
args: Iter, mut args: Vec<String>,
envs: Vec<String>, envs: Vec<String>,
) -> Box<Thread> ) -> Box<Thread> {
where
Iter: Iterator<Item = &'a str>,
{
// Parse ELF // Parse ELF
let elf = ElfFile::new(data).expect("failed to read elf"); let elf = ElfFile::new(data).expect("failed to read elf");
@ -185,12 +182,11 @@ impl Thread {
debug!("using loader {}", &loader_path); debug!("using loader {}", &loader_path);
// Elf loader should not have INTERP // Elf loader should not have INTERP
// No infinite loop // No infinite loop
let mut new_args: Vec<&str> = args.collect(); args.insert(0, loader_path.into());
new_args.insert(0, loader_path); args.insert(1, exec_path.into());
new_args.insert(1, exec_path); args.remove(2);
new_args.remove(2); warn!("loader args: {:?}", args);
warn!("loader args: {:?}", new_args); return Thread::new_user(buf.as_slice(), exec_path, args, envs);
return Thread::new_user(buf.as_slice(), exec_path, new_args.into_iter(), envs);
} else { } else {
warn!("loader specified as {} but failed to read", &loader_path); warn!("loader specified as {} but failed to read", &loader_path);
} }
@ -219,7 +215,7 @@ impl Thread {
// Make init info // Make init info
let init_info = ProcInitInfo { let init_info = ProcInitInfo {
args: args.map(|s| String::from(s)).collect(), args,
envs, envs,
auxv: { auxv: {
let mut map = BTreeMap::new(); let mut map = BTreeMap::new();

@ -13,7 +13,7 @@ pub fn run_user_shell() {
processor().manager().add(Thread::new_user( processor().manager().add(Thread::new_user(
data.as_slice(), data.as_slice(),
"rust/sh", "rust/sh",
"sh".split(' '), vec!["sh".into()],
Vec::new(), Vec::new(),
)); ));
} else { } else {
@ -28,7 +28,7 @@ pub fn run_user_shell() {
let data = inode.read_as_vec().unwrap(); let data = inode.read_as_vec().unwrap();
processor().manager().add(Thread::new_user( processor().manager().add(Thread::new_user(
data.as_slice(), data.as_slice(),
cmdline.split(' '), cmdline.split(' ').map(|s| s.into()).collect(),
Vec::new(), Vec::new(),
)); ));
} }
@ -50,7 +50,7 @@ pub extern "C" fn shell(_arg: usize) -> ! {
let _pid = processor().manager().add(Thread::new_user( let _pid = processor().manager().add(Thread::new_user(
data.as_slice(), data.as_slice(),
&cmd, &cmd,
cmd.split(' '), cmd.split(' ').map(|s| s.into()).collect(),
Vec::new(), Vec::new(),
)); ));
// TODO: wait until process exits, or use user land shell completely // TODO: wait until process exits, or use user land shell completely

@ -176,8 +176,7 @@ pub fn sys_exec(
let buf = inode.read_as_vec()?; let buf = inode.read_as_vec()?;
// Make new Thread // 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, envs);
let mut thread = Thread::new_user(buf.as_slice(), exec_path, args_iter, envs);
thread.proc.lock().clone_for_exec(&proc); thread.proc.lock().clone_for_exec(&proc);
// Activate new page table // Activate new page table

Loading…
Cancel
Save