Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syscall-exec #4

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
3 changes: 2 additions & 1 deletion usr/rust/src/bin/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use user::syscall::{sys_exec, sys_fork};

#[no_mangle]
pub fn main() -> usize {
sys_exec("/rust/hello_world".as_ptr() as *const u8);
println!("this is exec_test ^o^");
sys_exec("/rust/hello_world".as_ptr());
println!("should not arrive here. exec error.");
0
}
9 changes: 8 additions & 1 deletion usr/rust/src/bin/user_shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ use alloc::string::String;
use user::io::getc;
use user::syscall::{sys_exec, sys_exit, sys_fork};

unsafe fn to_cstr(s: &mut String) -> *const u8 {
let ptr = s.as_mut_ptr();
let len = s.len();
*ptr.add(len) = 0;
jiegec marked this conversation as resolved.
Show resolved Hide resolved
ptr
}

#[no_mangle]
pub fn main() {
println!("Rust user shell");
Expand All @@ -26,7 +33,7 @@ pub fn main() {
if !line.is_empty() {
println!("searching for program {}", line);
if sys_fork() == 0 {
sys_exec(line.as_ptr());
sys_exec(unsafe { to_cstr(&mut line) });
sys_exit(0);
}
line.clear();
Expand Down