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