some vm to accomodate needing to have a region search spot be
[newos.git] / include / signal.h
blob6a27119e08f0185a40f56ed8fdde409a34c78289
1 #ifndef _SIGNAL_H_
2 #define _SIGNAL_H_
4 /*
5 ** Distributed under the terms of the OpenBeOS License.
6 */
8 #include <sys/types.h>
11 typedef int sig_atomic_t;
12 typedef long sigset_t;
14 typedef void (*sig_func_t)(int);
15 typedef void (*__signal_func_ptr)(int); /* deprecated, for compatibility with BeOS only */
19 * macros defining the standard signal handling behavior
21 #define SIG_DFL ((sig_func_t) 0) /* the signal was treated in the "default" manner */
22 #define SIG_IGN ((sig_func_t) 1) /* the signal was ignored */
23 #define SIG_ERR ((sig_func_t)-1) /* an error ocurred during signal processing */
27 * structure used by sigaction()
29 * Note: the 'sa_userdata' field is a non-Posix extension.
30 * See the SPECIAL NOTES below for an explanation of this.
33 struct sigaction {
34 sig_func_t sa_handler;
35 sigset_t sa_mask;
36 int sa_flags;
37 void *sa_userdata; /* will be passed to the signal handler */
42 * values for sa_flags
44 #define SA_NOCLDSTOP 0x01
45 #define SA_ONESHOT 0x02
46 #define SA_NOMASK 0x04
47 #define SA_NODEFER SA_NOMASK
48 #define SA_RESTART 0x08
49 #define SA_STACK 0x10
54 * for signals using an alternate stack
56 typedef struct stack_t {
57 void *ss_sp;
58 size_t ss_size;
59 int ss_flags;
60 } stack_t;
64 * for the 'how' arg of sigprocmask()
66 #define SIG_BLOCK 1
67 #define SIG_UNBLOCK 2
68 #define SIG_SETMASK 3
73 * The list of all defined signals:
75 * The numbering of signals for OpenBeOS attempts to maintain
76 * some consistency with UN*X conventions so that things
77 * like "kill -9" do what you expect.
79 #define SIGHUP 1 /* hangup -- tty is gone! */
80 #define SIGINT 2 /* interrupt */
81 #define SIGQUIT 3 /* `quit' special character typed in tty */
82 #define SIGILL 4 /* illegal instruction */
83 #define SIGCHLD 5 /* child process exited */
84 #define SIGABRT 6 /* abort() called, dont' catch */
85 #define SIGPIPE 7 /* write to a pipe w/no readers */
86 #define SIGFPE 8 /* floating point exception */
87 #define SIGKILL 9 /* kill a team (not catchable) */
88 #define SIGSTOP 10 /* suspend a thread (not catchable) */
89 #define SIGSEGV 11 /* segmentation violation (read: invalid pointer) */
90 #define SIGCONT 12 /* continue execution if suspended */
91 #define SIGTSTP 13 /* `stop' special character typed in tty */
92 #define SIGALRM 14 /* an alarm has gone off (see alarm()) */
93 #define SIGTERM 15 /* termination requested */
94 #define SIGTTIN 16 /* read of tty from bg process */
95 #define SIGTTOU 17 /* write to tty from bg process */
96 #define SIGUSR1 18 /* app defined signal 1 */
97 #define SIGUSR2 19 /* app defined signal 2 */
98 #define SIGWINCH 20 /* tty window size changed */
99 #define SIGKILLTHR 21 /* be specific: kill just the thread, not team */
100 #define SIGTRAP 22
102 #define SIGBUS SIGSEGV /* for old style code */
106 * Signal numbers 23-32 are currently free but may be used in future
107 * releases. Use them at your own peril (if you do use them, at least
108 * be smart and use them backwards from signal 32).
110 #define MAX_SIGNO 32 /* the most signals that a single thread can reference */
111 #define __signal_max 22 /* the largest signal number that is actually defined */
112 #define NSIG (__signal_max+1) /* the number of defined signals */
115 #if !_KERNEL
117 /* the global table of text strings containing descriptions for each signal */
118 extern const char * const sys_siglist[NSIG];
121 #ifdef __cplusplus
122 extern "C" {
123 #endif
125 sig_func_t signal(int sig, sig_func_t signal_handler);
126 int raise(int sig);
127 int kill(pid_t pid, int sig);
128 int send_signal(pid_t pid, uint sig);
129 int send_signal_thr(tid_t tid, uint sig);
131 int sigaction(int sig, const struct sigaction *act, struct sigaction *oact);
132 int sigprocmask(int how, const sigset_t *set, sigset_t *oset);
133 int sigpending(sigset_t *set);
134 int sigsuspend(const sigset_t *mask);
136 int sigemptyset(sigset_t *set);
137 int sigfillset(sigset_t *set);
138 int sigaddset(sigset_t *set, int signo);
139 int sigdelset(sigset_t *set, int signo);
140 int sigismember(const sigset_t *set, int signo);
142 const char *strsignal(int sig);
144 int sigaltstack(const stack_t *ss, stack_t *oss); /* XXXdbg */
146 #ifdef __cplusplus
148 #endif
152 * ==================================================
153 * !!! SPECIAL NOTES CONCERNING NON-POSIX EXTENSIONS:
154 * ==================================================
156 * The standard Posix interface for signal handlers is not as useful
157 * as it could be. The handler can define only one single argument
158 * (the signal number). For example:
159 * void
160 * my_signal_handler(int sig)
162 * . . .
165 * // install the handler
166 * signal(SIGINT, &my_signal_handler);
168 * The sigaction() function allows finer grained control of the signal
169 * handling. It also allows an opportunity, via the 'sigaction' struct, to
170 * enable additional data to be passed to the handler. For example:
171 * void
172 * my_signal_handler(int sig, char *somedata, vregs regs)
174 * . . .
177 * struct sigaction sa;
178 * char data_buffer[32];
180 * sa.sa_handler = (sig_func_t) my_signal_handler;
181 * sigemptyset(&sa.sa_mask);
182 * sigaddset(&sa.sa_mask, SIGINT);
183 * sa.sa_userdata = data_buffer;
185 * // install the handler
186 * sigaction(SIGINT, &sa, NULL);
188 * The two additional arguments available to the signal handler are extensions
189 * to the Posix standard. This feature was introduced by the BeOS and retained
190 * by OpenBeOS. However, to remain compatible with Posix and ANSI C, the type
191 * of the sa_handler field is defined as 'sig_func_t'. This requires the handler
192 * to be cast when assigned to the sa_handler field, as in the example above.
194 * NOTE: C++ member functions can not be signal handlers!
195 * This is because they expect a "this" pointer as the first argument.
198 * The 3 arguments that OpenBeOS provides to signal handlers are as follows:
200 * - The first argument is the (usual) signal number.
202 * - The second argument is whatever value is put in the sa_userdata field
203 * of the sigaction struct.
205 * - The third argument is a pointer to a vregs struct (defined below).
206 * The vregs struct contains the contents of the volatile registers at
207 * the time the signal was delivered to your thread. You can change the fields
208 * of the structure. After your signal handler completes, the OS uses this struct
209 * to reload the registers for your thread (privileged registers are not loaded
210 * of course). The vregs struct is of course terribly machine dependent.
211 * If you use it, you should expect to have to re-work your code when new
212 * processors come out. Nonetheless, the ability to change the registers does
213 * open some interesting programming possibilities.
216 #endif // !_KERNEL
220 * the vregs struct:
222 * signal handlers get this as the last argument
225 typedef struct vregs vregs;
227 #if ARCH_ppc
228 struct vregs
230 ulong pc, /* program counter */
231 r0, /* scratch */
232 r1, /* stack ptr */
233 r2, /* TOC */
234 r3,r4,r5,r6,r7,r8,r9,r10, /* volatile regs */
235 r11,r12; /* scratch regs */
237 double f0, /* fp scratch */
238 f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13; /* fp volatile regs */
240 ulong filler1, /* place holder */
241 fpscr, /* fp condition codes */
242 ctr, xer, cr, msr, lr; /* misc. status */
244 #endif /* __POWERPC__ */
246 #if ARCH_i386
248 typedef struct packed_fp_stack {
249 unsigned char st0[10];
250 unsigned char st1[10];
251 unsigned char st2[10];
252 unsigned char st3[10];
253 unsigned char st4[10];
254 unsigned char st5[10];
255 unsigned char st6[10];
256 unsigned char st7[10];
257 } packed_fp_stack;
259 typedef struct packed_mmx_regs {
260 unsigned char mm0[10];
261 unsigned char mm1[10];
262 unsigned char mm2[10];
263 unsigned char mm3[10];
264 unsigned char mm4[10];
265 unsigned char mm5[10];
266 unsigned char mm6[10];
267 unsigned char mm7[10];
268 } packed_mmx_regs;
270 typedef struct old_extended_regs {
271 unsigned short fp_control;
272 unsigned short _reserved1;
273 unsigned short fp_status;
274 unsigned short _reserved2;
275 unsigned short fp_tag;
276 unsigned short _reserved3;
277 unsigned long fp_eip;
278 unsigned short fp_cs;
279 unsigned short fp_opcode;
280 unsigned long fp_datap;
281 unsigned short fp_ds;
282 unsigned short _reserved4;
283 union {
284 packed_fp_stack fp;
285 packed_mmx_regs mmx;
286 } fp_mmx;
287 } old_extended_regs;
289 typedef struct fp_stack {
290 unsigned char st0[10];
291 unsigned char _reserved_42_47[6];
292 unsigned char st1[10];
293 unsigned char _reserved_58_63[6];
294 unsigned char st2[10];
295 unsigned char _reserved_74_79[6];
296 unsigned char st3[10];
297 unsigned char _reserved_90_95[6];
298 unsigned char st4[10];
299 unsigned char _reserved_106_111[6];
300 unsigned char st5[10];
301 unsigned char _reserved_122_127[6];
302 unsigned char st6[10];
303 unsigned char _reserved_138_143[6];
304 unsigned char st7[10];
305 unsigned char _reserved_154_159[6];
306 } fp_stack;
308 typedef struct mmx_regs {
309 unsigned char mm0[10];
310 unsigned char _reserved_42_47[6];
311 unsigned char mm1[10];
312 unsigned char _reserved_58_63[6];
313 unsigned char mm2[10];
314 unsigned char _reserved_74_79[6];
315 unsigned char mm3[10];
316 unsigned char _reserved_90_95[6];
317 unsigned char mm4[10];
318 unsigned char _reserved_106_111[6];
319 unsigned char mm5[10];
320 unsigned char _reserved_122_127[6];
321 unsigned char mm6[10];
322 unsigned char _reserved_138_143[6];
323 unsigned char mm7[10];
324 unsigned char _reserved_154_159[6];
325 } mmx_regs;
327 typedef struct xmmx_regs {
328 unsigned char xmm0[16];
329 unsigned char xmm1[16];
330 unsigned char xmm2[16];
331 unsigned char xmm3[16];
332 unsigned char xmm4[16];
333 unsigned char xmm5[16];
334 unsigned char xmm6[16];
335 unsigned char xmm7[16];
336 } xmmx_regs;
338 typedef struct new_extended_regs {
339 unsigned short fp_control;
340 unsigned short fp_status;
341 unsigned short fp_tag;
342 unsigned short fp_opcode;
343 unsigned long fp_eip;
344 unsigned short fp_cs;
345 unsigned short res_14_15;
346 unsigned long fp_datap;
347 unsigned short fp_ds;
348 unsigned short _reserved_22_23;
349 unsigned long mxcsr;
350 unsigned long _reserved_28_31;
351 union {
352 fp_stack fp;
353 mmx_regs mmx;
354 } fp_mmx;
355 xmmx_regs xmmx;
356 unsigned char _reserved_288_511[224];
357 } new_extended_regs;
359 typedef struct extended_regs {
360 union {
361 old_extended_regs old_format;
362 new_extended_regs new_format;
363 } state;
364 unsigned long format;
365 } extended_regs;
367 struct vregs {
368 unsigned long eip;
369 unsigned long eflags;
370 unsigned long eax;
371 unsigned long ecx;
372 unsigned long edx;
373 unsigned long esp;
374 unsigned long ebp;
375 unsigned long _reserved_1;
376 extended_regs xregs;
377 unsigned long _reserved_2[3];
380 #endif /* __INTEL__ */
383 #endif /* _SIGNAL_H_ */