Support cmdline_args when sys_exec.

This commit is contained in:
Yifan Wu 2021-02-26 12:06:55 +08:00
parent c43ec12175
commit c8d851fc2b
16 changed files with 132 additions and 24 deletions

View file

@ -9,12 +9,15 @@ use crate::timer::get_time_ms;
use crate::mm::{
translated_str,
translated_refmut,
translated_ref,
};
use crate::fs::{
open_file,
OpenFlags,
};
use alloc::sync::Arc;
use alloc::vec::Vec;
use alloc::string::String;
pub fn sys_exit(exit_code: i32) -> ! {
exit_current_and_run_next(exit_code);
@ -48,14 +51,25 @@ pub fn sys_fork() -> isize {
new_pid as isize
}
pub fn sys_exec(path: *const u8) -> isize {
pub fn sys_exec(path: *const u8, mut args: *const usize) -> isize {
let token = current_user_token();
let path = translated_str(token, path);
let mut args_vec: Vec<String> = Vec::new();
loop {
let arg_str_ptr = *translated_ref(token, args);
if arg_str_ptr == 0 {
break;
}
args_vec.push(translated_str(token, arg_str_ptr as *const u8));
unsafe { args = args.add(1); }
}
if let Some(app_inode) = open_file(path.as_str(), OpenFlags::RDONLY) {
let all_data = app_inode.read_all();
let task = current_task().unwrap();
task.exec(all_data.as_slice());
0
let argc = args_vec.len();
task.exec(all_data.as_slice(), args_vec);
// return argc because cx.x[10] will be covered with it later
argc as isize
} else {
-1
}