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