My Kernel v0.1.0
signal.h
1/*
2 * Posix signals
3 *
4 * Reference:
5 * * POSIX 2.4 - Signal Concepts
6 */
7
8#ifndef KERNEL_SIGNAL_H
9#define KERNEL_SIGNAL_H
10
11#include <kernel/spinlock.h>
12#include <kernel/atomic.h>
13#include <kernel/error.h>
14
15#include <libalgo/queue.h>
16
17#include <sys/signal.h>
18
19#if ARCH == i686
20#include <kernel/arch/i686/signal.h>
21#endif
22
23struct thread;
24struct process;
25
26#define SIGNAL_MIN 1
27#define SIGNAL_MAX (SIGNAL_COUNT - 1)
28#define SIGNAL_COUNT NSIG
29
30/*
31 * A pending signal.
32 *
33 * This struct holds information about a pending signals that is necessary
34 * to take decisions and fill the structures during signal delivery.
35 */
36struct signal_context {
37 node_t this; /* used by struct signal_queue */
38 siginfo_t si_info;
39 int si_signo;
40};
41
42/*
43 * A queue of pending signals.
44 *
45 * There exists one queue of pending signal per process AND per thread.
46 */
47struct signal_queue {
48 spinlock_t lock;
49 llist_t signals; /* struct signal_context */
50 sigset_t pending;
51};
52
53static inline void signal_queue_init(struct signal_queue *queue)
54{
55 INIT_SPINLOCK(queue->lock);
56 INIT_LLIST(queue->signals);
57}
58
59/*
60 * Reflects what is specified in sigaction().
61 */
62struct signal_action {
63 struct sigaction sa_action;
64};
65
66/*
67 *
68 */
69struct signal_set {
70 spinlock_t lock; /* should be held when accessing this structure. */
71 struct signal_action sig_actions[SIGNAL_COUNT];
72};
73
74/*
75 * Frame pushed onto the stack before calling the signal handler.
76 */
77struct signal_frame {
78 int signo;
79 siginfo_t *p_siginfo;
80 ucontext_t *p_ucontext;
81 /* Above are the arguments passed to the signal handler. */
82 siginfo_t siginfo;
83 ucontext_t ucontext;
84};
85
87void signal_set_free(struct signal_set *set);
88
90struct signal_set *signal_set_clone(struct signal_set *set);
91
93void signal_set_reset(struct signal_set *set);
94
95struct signal_context *signal_queue_pop(struct signal_queue *queue,
96 sigset_t blocked);
97
99size_t signal_queue_flush(struct signal_queue *queue);
100
101void signal_deliver(struct thread *thread, struct signal_context *sig_ctx);
102
103/*
104 * Generate a process-wide signal.
105 */
106error_t signal_process(struct process *process, const siginfo_t *sig_info);
107
108/*
109 * Generate a thread-specific signal.
110 */
111error_t signal_thread(struct thread *thread, const siginfo_t *sig_info);
112
113/*
114 * Arch-specific signal related functions.
115 */
116
117error_t arch_signal_deliver_catch(struct thread *, const struct signal_action *,
118 const struct signal_context *);
119
120#endif /* KERNEL_SIGNAL_H */
The head of a doubly linked list.
Definition: linked_list.h:43
Intrusive doubly-linked list node.
Definition: linked_list.h:27
A single process.
Definition: process.h:86
Spinlock.
Definition: spinlock.h:29
A single thread.
Definition: process.h:149