Add syscall pause

This commit is contained in:
Jianfeng Jiang 2023-03-15 17:02:20 +08:00 committed by Tate, Hongliang Tian
parent 72e0725a0e
commit 44904f00c8
2 changed files with 24 additions and 0 deletions

View File

@ -34,6 +34,7 @@ use crate::syscall::mmap::sys_mmap;
use crate::syscall::mprotect::sys_mprotect;
use crate::syscall::munmap::sys_munmap;
use crate::syscall::open::{sys_open, sys_openat};
use crate::syscall::pause::sys_pause;
use crate::syscall::poll::sys_poll;
use crate::syscall::prctl::sys_prctl;
use crate::syscall::prlimit64::sys_prlimit64;
@ -96,6 +97,7 @@ mod mmap;
mod mprotect;
mod munmap;
mod open;
mod pause;
mod poll;
mod prctl;
mod prlimit64;
@ -177,6 +179,7 @@ define_syscall_nums!(
SYS_MADVISE = 28,
SYS_DUP = 32,
SYS_DUP2 = 33,
SYS_PAUSE = 34,
SYS_GETPID = 39,
SYS_CLONE = 56,
SYS_FORK = 57,
@ -306,6 +309,7 @@ pub fn syscall_dispatch(
SYS_MADVISE => syscall_handler!(3, sys_madvise, args),
SYS_DUP => syscall_handler!(1, sys_dup, args),
SYS_DUP2 => syscall_handler!(2, sys_dup2, args),
SYS_PAUSE => syscall_handler!(0, sys_pause),
SYS_GETPID => syscall_handler!(0, sys_getpid),
SYS_CLONE => syscall_handler!(5, sys_clone, args, context.clone()),
SYS_FORK => syscall_handler!(0, sys_fork, context.clone()),

View File

@ -0,0 +1,20 @@
use crate::{prelude::*, process::posix_thread::posix_thread_ext::PosixThreadExt, thread::Thread};
use super::SyscallReturn;
pub fn sys_pause() -> Result<SyscallReturn> {
loop {
let current_thread = current_thread!();
// check sig_queue of current thread and process,
// if there's any pending signal, break loop
let posix_thread = current_thread.as_posix_thread().unwrap();
if !posix_thread.sig_queues().lock().empty() || !current!().sig_queues().lock().empty() {
break;
}
// there's no pending signal, yield execution
// FIXME: set current thread interruptible here
Thread::yield_now();
}
// handle signal before returning to user space
return_errno_with_message!(Errno::ERESTART, "catch signal")
}