@ -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