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