Skip to content

Commit

Permalink
feat: refactor syscall fork -> clone
Browse files Browse the repository at this point in the history
  • Loading branch information
Yttehs-HDX committed Dec 8, 2024
1 parent 055c800 commit a2910fa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn run_test() -> ! {
"getppid",
"chdir",
"open",
// "clone",
"clone",
"mount",
"exit",
"sleep",
Expand Down
4 changes: 2 additions & 2 deletions kernel/src/syscall/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const SYSCALL_GET_TIME: usize = 169;
const SYSCALL_BRK: usize = 214;
const SYSCALL_GETPID: usize = 172;
const SYSCALL_GETPPID: usize = 173;
const SYSCALL_FORK: usize = 220;
const SYSCALL_CLONE: usize = 220;
const SYSCALL_EXEC: usize = 221;
const SYSCALL_WAITPID: usize = 260;
const SYSCALL_GETCWD: usize = 17;
Expand All @@ -40,7 +40,7 @@ pub fn syscall(id: usize, args: [usize; 6]) -> isize {
SYSCALL_BRK => sys_brk(args[0] as i32),
SYSCALL_GETPID => sys_getpid(),
SYSCALL_GETPPID => sys_getppid(),
SYSCALL_FORK => sys_fork(),
SYSCALL_CLONE => sys_clone(args[0], args[1]),
SYSCALL_EXEC => sys_exec(args[0] as *const u8, args[1] as *const u8),
SYSCALL_WAITPID => sys_waitpid(args[0] as isize, args[1] as *mut i32, args[2]),
SYSCALL_GETCWD => sys_getcwd(args[0] as *mut u8, args[1]),
Expand Down
10 changes: 7 additions & 3 deletions kernel/src/syscall/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,16 @@ pub fn sys_getppid() -> isize {
parent_pid as isize
}

pub fn sys_fork() -> isize {
pub fn sys_clone(flags: usize, sp: usize) -> isize {
const SIGCHLD: usize = 17;

let current_task = task::get_processor().current();
let new_task = current_task.fork();
let new_pid = new_task.get_pid();
let trap_cx = new_task.get_trap_cx_mut();
trap_cx.set_a0(0);
if flags != SIGCHLD || sp != 0 {
new_task.get_trap_cx_mut().set_sp(sp as usize);
}
new_task.get_trap_cx_mut().set_a0(0);
task::add_task(new_task);

new_pid as isize
Expand Down

0 comments on commit a2910fa

Please sign in to comment.