MCPcopy Create free account
hub / github.com/chyyuu/os_kernel_lab / sys_exec

Function sys_exec

os/src/syscall/process.rs:44–68  ·  view source on GitHub ↗
(path: *const u8, mut args: *const usize)

Source from the content-addressed store, hash-verified

42}
43
44pub 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.

Callers 1

syscallFunction · 0.70

Calls 10

current_user_tokenFunction · 0.85
translated_strFunction · 0.85
translated_refFunction · 0.85
open_fileFunction · 0.85
current_processFunction · 0.85
addMethod · 0.80
read_allMethod · 0.80
lenMethod · 0.80
execMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected