AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
sys_signal.c File Reference

System calls about signals, timers and the time: kill(), sigaction(), the signal mask, sigsuspend() and sigreturn(), setitimer(), nanosleep(), and the clocks. More...

#include "syscalls.h"

Go to the source code of this file.

Functions

long sys_kill (pid_t pid, int sig)
 Implements kill(): sends a signal to a process or a process group.
long sys_sigaction (int sig, const struct aquila_sigaction *act, struct aquila_sigaction *oact)
 Implements sigaction(): reads a signal's action, and sets a new one.
long sys_gettimeofday (struct timeval *tv, struct timezone *tz)
 Implements gettimeofday(): the time of day.
long sys_sigmask (int how, const sigset_t *set, sigset_t *oldset)
 Implements sigprocmask(): reads and changes the process's signal mask.
long sys_sigsuspend (const sigset_t *set)
 Implements sigsuspend(): replaces the signal mask and waits for a signal.
long sys_sigreturn (void)
 Implements sigreturn(): a signal handler returns, and the registers and signal mask that its frame saved are restored.
long sys_setitimer (int which, const struct aquila_itimer *new, struct aquila_itimer *old)
 Implements setitimer(): sets the real time timer, which sends SIGALRM, and reads the old one.
long sys_nanosleep (const struct aquila_timespec *req, struct aquila_timespec *rem)
 Implements nanosleep(): sleeps for a time.
long sys_clock_gettime (int clock, struct aquila_timespec *ts)
 Implements clock_gettime(): reads a clock.

Detailed Description

System calls about signals, timers and the time: kill(), sigaction(), the signal mask, sigsuspend() and sigreturn(), setitimer(), nanosleep(), and the clocks.

Definition in file sys_signal.c.

Function Documentation

◆ sys_clock_gettime()

long sys_clock_gettime ( int clock,
struct aquila_timespec * ts )

Implements clock_gettime(): reads a clock.

Parameters
clockCLOCK_REALTIME or CLOCK_MONOTONIC
tswhere to put the time
Returns
0, -EINVAL for another clock, or -EFAULT

Definition at line 293 of file sys_signal.c.

References arch_rtime_ns(), clock, gettime(), LOG_DEBUG, sys_clock_gettime(), timespec::tv_nsec, and timespec::tv_sec.

Referenced by sys_clock_gettime().

◆ sys_gettimeofday()

long sys_gettimeofday ( struct timeval * tv,
struct timezone * tz )

Implements gettimeofday(): the time of day.

Parameters
tvwhere to put the time, or NULL
tzwhere to put the time zone, or NULL
Returns
0, or -EFAULT

Definition at line 85 of file sys_signal.c.

References gettimeofday(), LOG_DEBUG, and sys_gettimeofday().

Referenced by sys_gettimeofday().

◆ sys_kill()

long sys_kill ( pid_t pid,
int sig )

Implements kill(): sends a signal to a process or a process group.

Parameters
pidwhom to: a process if > 0, the caller's process group if 0, every process but init and the caller if -1, or process group -pid if < -1
sigthe signal, or 0 to only check that the target exists
Returns
0, -EINVAL for a bad signal, or -ESRCH if there is no such process or group

Definition at line 19 of file sys_signal.c.

References LOG_DEBUG, signal_send(), and sys_kill().

Referenced by sys_kill().

◆ sys_nanosleep()

long sys_nanosleep ( const struct aquila_timespec * req,
struct aquila_timespec * rem )

Implements nanosleep(): sleeps for a time.

A stop doesn't change the deadline: the call is restarted until the same time.

Parameters
reqhow long to sleep
remwhere to put the time left if a signal ends the sleep, or NULL
Returns
0, -EINTR if a handler ran, -EINVAL for a bad time, or -EFAULT

Definition at line 242 of file sys_signal.c.

References arch_rtime_ns(), curthread, ERESTARTNOHAND, LOG_DEBUG, sched_sleep(), and sys_nanosleep().

Referenced by sys_nanosleep().

◆ sys_setitimer()

long sys_setitimer ( int which,
const struct aquila_itimer * new,
struct aquila_itimer * old )

Implements setitimer(): sets the real time timer, which sends SIGALRM, and reads the old one.

Parameters
whichAQUILA_ITIMER_REAL (the only timer supported)
newthe new timer, or NULL to only read the old one
oldwhere to put the old timer, or NULL
Returns
0, -EINVAL for another timer, or -EFAULT

Definition at line 201 of file sys_signal.c.

References curproc, LOG_DEBUG, sched_alarm(), sched_alarm_get(), and sys_setitimer().

Referenced by sys_setitimer().

◆ sys_sigaction()

long sys_sigaction ( int sig,
const struct aquila_sigaction * act,
struct aquila_sigaction * oact )

Implements sigaction(): reads a signal's action, and sets a new one.

Parameters
sigthe signal
actthe new action, or NULL to leave it
oactwhere to put the old action, or NULL
Returns
0, -EINVAL for a bad signal (or catching SIGKILL or SIGSTOP), or -EFAULT

Definition at line 37 of file sys_signal.c.

References curproc, LOG_DEBUG, SIG_DFL, SIG_IGN, SIG_MAX, signal_action_set(), sys_sigaction(), and uaccess_check().

Referenced by sys_sigaction().

◆ sys_sigmask()

long sys_sigmask ( int how,
const sigset_t * set,
sigset_t * oldset )

Implements sigprocmask(): reads and changes the process's signal mask.

SIGKILL and SIGSTOP can't be blocked.

Parameters
howSIG_BLOCK, SIG_UNBLOCK or SIG_SETMASK
setthe signals, or NULL to leave the mask
oldsetwhere to put the old mask, or NULL
Returns
0, -EINVAL for a bad how, or -EFAULT

Definition at line 108 of file sys_signal.c.

References curproc, LOG_DEBUG, SIG_UNMASKABLE, and sys_sigmask().

Referenced by sys_sigmask().

◆ sys_sigreturn()

long sys_sigreturn ( void )

Implements sigreturn(): a signal handler returns, and the registers and signal mask that its frame saved are restored.

The kernel's signal code page calls it when a handler returns.

Returns
0, which syscall_dispatch() ignores: the registers are the frame's

Definition at line 182 of file sys_signal.c.

References arch_sigreturn(), LOG_DEBUG, and sys_sigreturn().

Referenced by sys_sigreturn().

◆ sys_sigsuspend()

long sys_sigsuspend ( const sigset_t * set)

Implements sigsuspend(): replaces the signal mask and waits for a signal.

The old mask comes back once a handler has run.

Parameters
setthe mask to wait with
Returns
-EINTR once a handler has run (it is restarted after a stop), or -EFAULT

Definition at line 146 of file sys_signal.c.

References curproc, curthread, ERESTARTNOHAND, LOG_DEBUG, thread::sig_oldmask, thread::sig_oldmask_set, SIG_UNMASKABLE, sys_sigsuspend(), and waitq_sleep().

Referenced by sys_sigsuspend().