fix bug: sys_exec should name as exec_path, then loader can find the exec file.

items of VEC args from argv is the args lists, and args[0] isn't the complete exec_path.
the new_user function should add exec_path as a new args.

BUGS:
ls app doesn't show any thing. Why?
master
chyyuu 6 years ago
parent 53bf9d4fc3
commit 56e472c8f8

@ -158,7 +158,7 @@ impl Thread {
}
/// Make a new user process from ELF `data`
pub fn new_user<'a, Iter>(data: &[u8], args: Iter) -> Box<Thread>
pub fn new_user<'a, Iter>(data: &[u8], exec_path: &str, args: Iter) -> Box<Thread>
where
Iter: Iterator<Item = &'a str>,
{
@ -182,7 +182,10 @@ impl Thread {
// No infinite loop
let mut new_args: Vec<&str> = args.collect();
new_args.insert(0, loader_path);
return Thread::new_user(buf.as_slice(), new_args.into_iter());
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());
} else {
warn!("loader specified as {} but failed to read", &loader_path);
}

@ -12,7 +12,7 @@ pub fn run_user_shell() {
let data = inode.read_as_vec().unwrap();
processor()
.manager()
.add(Thread::new_user(data.as_slice(), "sh".split(' ')));
.add(Thread::new_user(data.as_slice(), "rust/sh", "sh".split(' ')));
} else {
processor().manager().add(Thread::new_kernel(shell, 0));
}
@ -44,7 +44,7 @@ pub extern "C" fn shell(_arg: usize) -> ! {
let data = file.read_as_vec().unwrap();
let _pid = processor()
.manager()
.add(Thread::new_user(data.as_slice(), cmd.split(' ')));
.add(Thread::new_user(data.as_slice(), &cmd, cmd.split(' ')));
// TODO: wait until process exits, or use user land shell completely
//unsafe { thread::JoinHandle::<()>::_of(pid) }.join().unwrap();
} else {

@ -126,7 +126,7 @@ pub fn sys_exec(
) -> SysResult {
info!("exec: name: {:?}, argv: {:?} envp: {:?}", name, argv, envp);
let proc = process();
let _name = if name.is_null() {
let exec_name = if name.is_null() {
String::from("")
} else {
unsafe { proc.vm.check_and_clone_cstr(name)? }
@ -146,19 +146,33 @@ pub fn sys_exec(
current_argv = current_argv.add(1);
}
}
info!("exec: args {:?}", args);
// // Check and copy envs to kernel
// let mut envs = Vec::new();
// unsafe {
// let mut current_env = envp as *const *const u8;
// proc.vm.check_read_ptr(current_env)?;
// while !(*current_env).is_null() {
// let env = proc.vm.check_and_clone_cstr(*current_env)?;
// envs.push(env);
// current_env = current_env.add(1);
// }
// }
//
if args.is_empty() {
return Err(SysError::EINVAL);
}
info!("EXEC: name:{:?} , args {:?}", exec_name, args);
// Read program file
let path = args[0].as_str();
let inode = proc.lookup_inode(path)?;
//let path = args[0].as_str();
let exec_path = exec_name.as_str();
let inode = proc.lookup_inode(exec_path)?;
let buf = inode.read_as_vec()?;
// Make new Thread
let iter = args.iter().map(|s| s.as_str());
let mut thread = Thread::new_user(buf.as_slice(), iter);
let mut thread = Thread::new_user(buf.as_slice(), exec_path, iter);
thread.proc.lock().clone_for_exec(&proc);
// Activate new page table

Loading…
Cancel
Save