-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
22da826
commit 156e25d
Showing
7 changed files
with
105 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#![allow(dead_code)] | ||
|
||
use arceos_posix_api as api; | ||
use axerrno::LinuxError; | ||
use axhal::arch::{TrapFrame, UspaceContext}; | ||
use axhal::trap::SyscallHandler; | ||
use axtask::TaskExtRef; | ||
|
||
const SYS_READ: usize = 0; | ||
const SYS_WRITE: usize = 1; | ||
const SYS_SCHED_YIELD: usize = 24; | ||
const SYS_GETPID: usize = 39; | ||
const SYS_CLONE: usize = 56; | ||
const SYS_FORK: usize = 57; | ||
const SYS_EXECVE: usize = 59; | ||
const SYS_EXIT: usize = 60; | ||
|
||
fn sys_clone(tf: &TrapFrame, newsp: usize) -> usize { | ||
let page_table_root = axtask::current().task_ext().page_table_root; | ||
let mut uctx = UspaceContext::from(tf); | ||
uctx.set_sp(newsp); | ||
uctx.set_ret_reg(0); | ||
let new_task = super::spawn_user_task(page_table_root, uctx); | ||
new_task.id().as_u64() as usize | ||
} | ||
|
||
struct SyscallHandlerImpl; | ||
|
||
#[crate_interface::impl_interface] | ||
impl SyscallHandler for SyscallHandlerImpl { | ||
fn handle_syscall(syscall_num: usize, tf: &TrapFrame) -> isize { | ||
let ret = match syscall_num { | ||
SYS_READ => api::sys_read(tf.arg0() as _, tf.arg1() as _, tf.arg2() as _), | ||
SYS_WRITE => api::sys_write(tf.arg0() as _, tf.arg1() as _, tf.arg2() as _), | ||
SYS_SCHED_YIELD => api::sys_sched_yield() as isize, | ||
SYS_GETPID => api::sys_getpid() as isize, | ||
_ => { | ||
warn!("Unimplemented syscall: {}", syscall_num); | ||
-LinuxError::ENOSYS.code() as _ | ||
} | ||
}; | ||
ret | ||
} | ||
} |