1 /* Signal handling <string.h>
3 This file is part of the Public Domain C Library (PDCLib).
4 Permission is granted to use, modify, and / or redistribute at will.
7 #ifndef _PDCLIB_SIGNAL_H
8 #define _PDCLIB_SIGNAL_H _PDCLIB_SIGNAL_H
10 #include <_PDCLIB_config.h>
12 /* Signals ------------------------------------------------------------------ */
14 /* A word on signals, to the people using PDCLib in their OS projects.
16 The definitions of the C standard leave about everything that *could* be
17 useful to be "implementation defined". Without additional, non-standard
18 arrangements, it is not possible to turn them into a useful tool.
20 This example implementation chose to "not generate any of these signals,
21 except as a result of explicit calls to the raise function", which is
22 allowed by the standard but of course does nothing for the usefulness of
25 A useful signal handling would:
26 1) make signal() a system call that registers the signal handler with the OS
27 2) make raise() a system call triggering an OS signal to the running process
28 3) make provisions that further signals of the same type are blocked until
29 the signal handler returns (optional for SIGILL)
32 /* These are the values used by Linux. */
34 /* Abnormal termination / abort() */
36 /* Arithmetic exception / division by zero / overflow */
38 /* Illegal instruction */
40 /* Interactive attention signal */
42 /* Invalid memory access */
44 /* Termination request */
47 /* The following should be defined to pointer values that could NEVER point to
48 a valid signal handler function. (They are used as special arguments to
49 signal().) Again, these are the values used by Linux.
51 #define SIG_DFL (void (*)( int ))0
52 #define SIG_ERR (void (*)( int ))-1
53 #define SIG_IGN (void (*)( int ))1
55 typedef _PDCLIB_sig_atomic sig_atomic_t;
57 /* Installs a signal handler "func" for the given signal.
58 A signal handler is a function that takes an integer as argument (the signal
59 number) and returns void.
61 Note that a signal handler can do very little else than:
62 1) assign a value to a static object of type "volatile sig_atomic_t",
63 2) call signal() with the value of sig equal to the signal received,
66 Virtually everything else is undefind.
68 The signal() function returns the previous installed signal handler, which
69 at program start may be SIG_DFL or SIG_ILL. (This implementation uses
70 SIG_DFL for all handlers.) If the request cannot be honored, SIG_ERR is
71 returned and errno is set to an unspecified positive value.
73 void (*signal( int sig, void (*func)( int ) ) )( int );
75 /* Raises the given signal (executing the registered signal handler with the
76 given signal number as parameter).
77 This implementation does not prevent further signals of the same time from
78 occuring, but executes signal( sig, SIG_DFL ) before entering the signal
79 handler (i.e., a second signal before the signal handler re-registers itself
80 or SIG_IGN will end the program).
81 Returns zero if successful, nonzero otherwise. */