Support cmdline_args when sys_exec.
This commit is contained in:
parent
c43ec12175
commit
c8d851fc2b
16 changed files with 132 additions and 24 deletions
|
@ -15,6 +15,7 @@ extern crate bitflags;
|
|||
|
||||
use syscall::*;
|
||||
use buddy_system_allocator::LockedHeap;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
const USER_HEAP_SIZE: usize = 16384;
|
||||
|
||||
|
@ -30,17 +31,31 @@ pub fn handle_alloc_error(layout: core::alloc::Layout) -> ! {
|
|||
|
||||
#[no_mangle]
|
||||
#[link_section = ".text.entry"]
|
||||
pub extern "C" fn _start() -> ! {
|
||||
pub extern "C" fn _start(argc: usize, argv: usize) -> ! {
|
||||
unsafe {
|
||||
HEAP.lock()
|
||||
.init(HEAP_SPACE.as_ptr() as usize, USER_HEAP_SIZE);
|
||||
}
|
||||
exit(main());
|
||||
let mut v: Vec<&'static str> = Vec::new();
|
||||
for i in 0..argc {
|
||||
let str_start = unsafe {
|
||||
((argv + i * core::mem::size_of::<usize>()) as *const usize).read_volatile()
|
||||
};
|
||||
let len = (0usize..).find(|i| unsafe {
|
||||
((str_start + *i) as *const u8).read_volatile() == 0
|
||||
}).unwrap();
|
||||
v.push(
|
||||
core::str::from_utf8(unsafe {
|
||||
core::slice::from_raw_parts(str_start as *const u8, len)
|
||||
}).unwrap()
|
||||
);
|
||||
}
|
||||
exit(main(argc, v.as_slice()));
|
||||
}
|
||||
|
||||
#[linkage = "weak"]
|
||||
#[no_mangle]
|
||||
fn main() -> i32 {
|
||||
fn main(_argc: usize, _argv: &[&str]) -> i32 {
|
||||
panic!("Cannot find main!");
|
||||
}
|
||||
|
||||
|
@ -64,7 +79,7 @@ pub fn yield_() -> isize { sys_yield() }
|
|||
pub fn get_time() -> isize { sys_get_time() }
|
||||
pub fn getpid() -> isize { sys_getpid() }
|
||||
pub fn fork() -> isize { sys_fork() }
|
||||
pub fn exec(path: &str) -> isize { sys_exec(path) }
|
||||
pub fn exec(path: &str, args: &[*const u8]) -> isize { sys_exec(path, args) }
|
||||
pub fn wait(exit_code: &mut i32) -> isize {
|
||||
loop {
|
||||
match sys_waitpid(-1, exit_code as *mut _) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue