(path: *const u8, mut args: *const usize)
| 42 | } |
| 43 | |
| 44 | pub fn sys_exec(path: *const u8, mut args: *const usize) -> isize { |
| 45 | let token = current_user_token(); |
| 46 | let path = translated_str(token, path); |
| 47 | let mut args_vec: Vec<String> = Vec::new(); |
| 48 | loop { |
| 49 | let arg_str_ptr = *translated_ref(token, args); |
| 50 | if arg_str_ptr == 0 { |
| 51 | break; |
| 52 | } |
| 53 | args_vec.push(translated_str(token, arg_str_ptr as *const u8)); |
| 54 | unsafe { |
| 55 | args = args.add(1); |
| 56 | } |
| 57 | } |
| 58 | if let Some(app_inode) = open_file(path.as_str(), OpenFlags::RDONLY) { |
| 59 | let all_data = app_inode.read_all(); |
| 60 | let process = current_process(); |
| 61 | let argc = args_vec.len(); |
| 62 | process.exec(all_data.as_slice(), args_vec); |
| 63 | // return argc because cx.x[10] will be covered with it later |
| 64 | argc as isize |
| 65 | } else { |
| 66 | -1 |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | /// If there is not a child process whose pid is same as given, return -1. |
| 71 | /// Else if there is a child process but it is still running, return -2. |
no test coverage detected