MentOS  0.8.0
The Mentoring Operating System
Macros | Functions | Variables
signal.c File Reference

Signals definition. More...

Macros

#define __DEBUG_HEADER__   "[SIGNAL]"
 Change header.
 
#define __DEBUG_LEVEL__   LOGLEVEL_NOTICE
 Set log level.
 
#define GET_EXIT_STATUS(status)   (((status) & 0x00FF) << 8)
 Extracts the exit status.
 

Functions

static void __copy_sigaction (sigaction_t *to, const sigaction_t *from)
 Copies the sigaction. More...
 
static void __copy_sigset (sigset_t *to, const sigset_t *from)
 Copies a signal set. More...
 
static void __copy_siginfo (siginfo_t *to, const siginfo_t *from)
 Copies a signal information structure. More...
 
static void __clear_siginfo (siginfo_t *info)
 Clears the memory of a signal information structure. More...
 
static void __lock_task_sighand (struct task_struct *t)
 Locks the signal handling of a given task. More...
 
static void __unlock_task_sighand (struct task_struct *t)
 Unlocks the signal handling of a given task. More...
 
static sighandler_t __get_handler (struct task_struct *t, int sig)
 Returns the handler for a given signal, for a given task. More...
 
static int __sig_is_ignored (struct task_struct *t, int sig)
 Checks if the given signal is ignored. More...
 
static sigqueue_t__sigqueue_alloc (struct task_struct *t, int sig, gfp_t flags)
 Allocate a new signal queue record. More...
 
static void __sigqueue_dealloc (sigqueue_t *sigqueue)
 Freest the memory of a signal queue. More...
 
static int __send_signal (int sig, siginfo_t *info, struct task_struct *t)
 Sends a signal. More...
 
static int __next_signal (sigpending_t *pending, sigset_t *mask)
 Gets the next signal that abides by the given mask. More...
 
static void __collect_signal (int sig, sigpending_t *list, siginfo_t *info)
 Collects the signals from the list. More...
 
static int __dequeue_signal (sigpending_t *pending, sigset_t *mask, siginfo_t *info)
 Dequeues a signal that abides by the mask. More...
 
static int __handle_signal (int signr, siginfo_t *info, sigaction_t *ka, struct pt_regs *regs)
 Handels the signals for the current process. More...
 
long sys_sigreturn (struct pt_regs *f)
 Handle the return from a signal handler. More...
 
static int __notify_parent (struct task_struct *current, int signr)
 Send signal to parent. More...
 
static void __rm_from_queue (sigset_t *mask, sigpending_t *q)
 Removes from the pending signal queue q the pending signals corresponding to the bit mask mask. More...
 
static void __do_signal_stop (struct task_struct *current, struct pt_regs *f, int signr)
 We do not consider group stopping because for now we don't have thread groups. More...
 
int do_signal (struct pt_regs *f)
 Handles the signals of the current process. More...
 
int signals_init (void)
 Initialize the signals. More...
 
void handle_stop_signal (int sig, siginfo_t *info, struct task_struct *p)
 Checks for some types of signals that might nullify other pending signals for the destination thread group. More...
 
int __send_sig_info (int sig, siginfo_t *info, struct task_struct *p)
 Send siginfo to target process. More...
 
int sys_kill (pid_t pid, int sig)
 Send signal to one specific process. More...
 
sighandler_t sys_signal (int signum, sighandler_t handler, uint32_t sigreturn_addr)
 Sets the disposition of the signal signum to handler. More...
 
int sys_sigaction (int signum, const sigaction_t *act, sigaction_t *oldact, uint32_t sigreturn_addr)
 Examine and change a signal action. More...
 
int sys_sigprocmask (int how, const sigset_t *set, sigset_t *oldset)
 Examine and change blocked signals. More...
 
int sys_sigpending (sigset_t *set)
 Provides a snapshot of pending signals. More...
 
const char * strsignal (int sig)
 Returns the string describing the given signal. More...
 
int sigemptyset (sigset_t *set)
 Prepare an empty set. More...
 
int sigfillset (sigset_t *set)
 Prepare a full set. More...
 
int sigaddset (sigset_t *set, int signum)
 Adds the given signal to the correct set. More...
 
int sigdelset (sigset_t *set, int signum)
 Removes the given signal to the correct set. More...
 
int sigismember (sigset_t *set, int signum)
 Checks if the given signal is part of the set. More...
 

Variables

static kmem_cache_tsigqueue_cachep
 SLAB caches for signal bits.
 
static struct wait_queue_head_t stopped_queue
 Contains all stopped process waiting for a continue signal.
 
static const char * sys_siglist []
 The list of signal names.
 

Detailed Description

Signals definition.

Function Documentation

◆ __clear_siginfo()

static void __clear_siginfo ( siginfo_t info)
inlinestatic

Clears the memory of a signal information structure.

Parameters
infothe signal information structure.

◆ __collect_signal()

static void __collect_signal ( int  sig,
sigpending_t list,
siginfo_t info 
)
inlinestatic

Collects the signals from the list.

Parameters
sigthe signal.
listthe list of pending signals.
infothe where we store the signal information.

◆ __copy_sigaction()

static void __copy_sigaction ( sigaction_t to,
const sigaction_t from 
)
inlinestatic

Copies the sigaction.

Parameters
tothe target.
fromthe source.

◆ __copy_siginfo()

static void __copy_siginfo ( siginfo_t to,
const siginfo_t from 
)
inlinestatic

Copies a signal information structure.

Parameters
tothe target.
fromthe source.

◆ __copy_sigset()

static void __copy_sigset ( sigset_t to,
const sigset_t from 
)
inlinestatic

Copies a signal set.

Parameters
tothe target.
fromthe source.

◆ __dequeue_signal()

static int __dequeue_signal ( sigpending_t pending,
sigset_t mask,
siginfo_t info 
)
inlinestatic

Dequeues a signal that abides by the mask.

Parameters
pendingthe list of pending signals.
maskthe mask used to select the signals.
infothe signal information, where we store the information of the dequeued signal.
Returns
the signal index on success, a negative value on failure.

◆ __do_signal_stop()

static void __do_signal_stop ( struct task_struct current,
struct pt_regs f,
int  signr 
)
static

We do not consider group stopping because for now we don't have thread groups.

Parameters
currentthe current process.
fthe stack frame.
signrsignal number.

◆ __get_handler()

static sighandler_t __get_handler ( struct task_struct t,
int  sig 
)
static

Returns the handler for a given signal, for a given task.

Parameters
tthe task.
sigthe signal index.
Returns
a pointer to the handler.

◆ __handle_signal()

static int __handle_signal ( int  signr,
siginfo_t info,
sigaction_t ka,
struct pt_regs regs 
)
inlinestatic

Handels the signals for the current process.

Parameters
signrthe signal number.
infothe signal information.
kathe action associated with the signal.
regsthe current registers.
Returns
1 on success, 0 on failure.

◆ __lock_task_sighand()

static void __lock_task_sighand ( struct task_struct t)
inlinestatic

Locks the signal handling of a given task.

Parameters
tthe task.

◆ __next_signal()

static int __next_signal ( sigpending_t pending,
sigset_t mask 
)
inlinestatic

Gets the next signal that abides by the given mask.

Parameters
pendingthe list of pending signals.
maskthe mask we are checking against.
Returns
index of the next signal to handle.

◆ __notify_parent()

static int __notify_parent ( struct task_struct current,
int  signr 
)
static

Send signal to parent.

Parameters
currentthe current task.
signrthe signal number.
Returns
the result of the operation.

◆ __rm_from_queue()

static void __rm_from_queue ( sigset_t mask,
sigpending_t q 
)
static

Removes from the pending signal queue q the pending signals corresponding to the bit mask mask.

Parameters
maskthe mask we use to guide signals removal.
qpensing signals.

◆ __send_sig_info()

int __send_sig_info ( int  sig,
siginfo_t info,
struct task_struct p 
)

Send siginfo to target process.

Parameters
sigSignal number
infosiginfo struct of the signal to be sent
pTarget process where the signal will be sent
Returns
Returns 0 if there is no error, otherwise returns an error code

◆ __send_signal()

static int __send_signal ( int  sig,
siginfo_t info,
struct task_struct t 
)
static

Sends a signal.

Parameters
sigSignal to be sent.
infoThe signal info
tThe process to which we send the signal.
Returns
0 on success, a negative value on failure.

◆ __sig_is_ignored()

static int __sig_is_ignored ( struct task_struct t,
int  sig 
)
static

Checks if the given signal is ignored.

Parameters
tthe task.
sigthe signal to check.
Returns
0 if not ignored, 1 if ignored.

◆ __sigqueue_alloc()

static sigqueue_t* __sigqueue_alloc ( struct task_struct t,
int  sig,
gfp_t  flags 
)
inlinestatic

Allocate a new signal queue record.

Parameters
tThe task to which the signal belongs.
sigThe signal to set.
flagsFlags identifying from where we are going to take the memory.
Returns
a pointer to the newly allocated signal queue.

◆ __sigqueue_dealloc()

static void __sigqueue_dealloc ( sigqueue_t sigqueue)
inlinestatic

Freest the memory of a signal queue.

Parameters
sigqueuethe signal queue to free.

◆ __unlock_task_sighand()

static void __unlock_task_sighand ( struct task_struct t)
inlinestatic

Unlocks the signal handling of a given task.

Parameters
tthe task.

◆ do_signal()

int do_signal ( struct pt_regs f)

Handles the signals of the current process.

Parameters
fThe address of the stack area where the User Mode register contents of the current process are saved.
Returns
If we are handling a signal, thus, regs have been modified to handle it (e.g., eip is now poiting at the handler).

◆ handle_stop_signal()

void handle_stop_signal ( int  sig,
siginfo_t info,
struct task_struct p 
)

Checks for some types of signals that might nullify other pending signals for the destination thread group.

Parameters
sigSignal number
infosiginfo struct of the signal
pTarget process of the signal

◆ sigaddset()

int sigaddset ( sigset_t set,
int  signum 
)

Adds the given signal to the correct set.

Parameters
setThe set to manipulate.
signumThe signalt to handle.
Returns
0 on success and -1 on error.

◆ sigdelset()

int sigdelset ( sigset_t set,
int  signum 
)

Removes the given signal to the correct set.

Parameters
setThe set to manipulate.
signumThe signalt to handle.
Returns
0 on success and -1 on error.

◆ sigemptyset()

int sigemptyset ( sigset_t set)

Prepare an empty set.

Parameters
setThe set to manipulate.
Returns
0 on success and -1 on error.

◆ sigfillset()

int sigfillset ( sigset_t set)

Prepare a full set.

Parameters
setThe set to manipulate.
Returns
0 on success and -1 on error.

◆ sigismember()

int sigismember ( sigset_t set,
int  signum 
)

Checks if the given signal is part of the set.

Parameters
setThe set to manipulate.
signumThe signalt to handle.
Returns
1 if signum is a member of set, 0 if signum is not a member, and -1 on error.

◆ signals_init()

int signals_init ( void  )

Initialize the signals.

Returns
1 on success, 0 on failure.

◆ strsignal()

const char* strsignal ( int  sig)

Returns the string describing the given signal.

Parameters
sigThe signal to inquire.
Returns
String representing the signal.

◆ sys_kill()

int sys_kill ( pid_t  pid,
int  sig 
)

Send signal to one specific process.

Parameters
pidThe PID of the process.
sigThe signal to be sent.
Returns

◆ sys_sigaction()

int sys_sigaction ( int  signum,
const sigaction_t act,
sigaction_t oldact,
uint32_t  sigreturn_addr 
)

Examine and change a signal action.

Parameters
signumSpecifies the signal and can be any valid signal except SIGKILL and SIGSTOP.
actIf non-NULL, the new action for signal signum is installed from act.
oldactIf non-NULL, the previous action is saved in oldact.
sigreturn_addrThe address of the sigreturn function.
Returns
returns 0 on success; on error, -1 is returned, and errno is set to indicate the error.

◆ sys_signal()

sighandler_t sys_signal ( int  signum,
sighandler_t  handler,
uint32_t  sigreturn_addr 
)

Sets the disposition of the signal signum to handler.

Parameters
signumThe signal number.
handlerThe handler for the signal.
sigreturn_addrThe address of the sigreturn function.
Returns
The previous value of the signal handler, or SIG_ERR on error.

◆ sys_sigpending()

int sys_sigpending ( sigset_t set)

Provides a snapshot of pending signals.

Parameters
setwhere the set of pending signals is returned.
Returns
0 on success, -1 on failure and errno is set to indicate the error.

◆ sys_sigprocmask()

int sys_sigprocmask ( int  how,
const sigset_t set,
sigset_t oldset 
)

Examine and change blocked signals.

Parameters
howDetermines the behavior of the call.
setThe set of signals to manage by the function.
oldsetIf non-NULL, the previous value of the signal mask is stored here.
Returns
returns 0 on success, and -1 on error (errno is set to indicate the cause).

If set is NULL, then the signal mask is unchanged (i.e., how is ignored), but the current value of the signal mask is nevertheless returned in oldset (if it is not NULL).

◆ sys_sigreturn()

long sys_sigreturn ( struct pt_regs f)

Handle the return from a signal handler.

Parameters
fThe stack frame when returning from a signal handler.
Returns
never.