Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/waterbox/libc/includes/signal.h
2 views
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
/* These are the values used by Linux. */
32
33
/* Abnormal termination / abort() */
34
#define SIGABRT 6
35
/* Arithmetic exception / division by zero / overflow */
36
#define SIGFPE 8
37
/* Illegal instruction */
38
#define SIGILL 4
39
/* Interactive attention signal */
40
#define SIGINT 2
41
/* Invalid memory access */
42
#define SIGSEGV 11
43
/* Termination request */
44
#define SIGTERM 15
45
46
/* The following should be defined to pointer values that could NEVER point to
47
a valid signal handler function. (They are used as special arguments to
48
signal().) Again, these are the values used by Linux.
49
*/
50
#define SIG_DFL (void (*)( int ))0
51
#define SIG_ERR (void (*)( int ))-1
52
#define SIG_IGN (void (*)( int ))1
53
54
typedef _PDCLIB_sig_atomic sig_atomic_t;
55
56
/* Installs a signal handler "func" for the given signal.
57
A signal handler is a function that takes an integer as argument (the signal
58
number) and returns void.
59
60
Note that a signal handler can do very little else than:
61
1) assign a value to a static object of type "volatile sig_atomic_t",
62
2) call signal() with the value of sig equal to the signal received,
63
3) call _Exit(),
64
4) call abort().
65
Virtually everything else is undefind.
66
67
The signal() function returns the previous installed signal handler, which
68
at program start may be SIG_DFL or SIG_ILL. (This implementation uses
69
SIG_DFL for all handlers.) If the request cannot be honored, SIG_ERR is
70
returned and errno is set to an unspecified positive value.
71
*/
72
void (*signal( int sig, void (*func)( int ) ) )( int );
73
74
/* Raises the given signal (executing the registered signal handler with the
75
given signal number as parameter).
76
This implementation does not prevent further signals of the same time from
77
occuring, but executes signal( sig, SIG_DFL ) before entering the signal
78
handler (i.e., a second signal before the signal handler re-registers itself
79
or SIG_IGN will end the program).
80
Returns zero if successful, nonzero otherwise. */
81
int raise( int sig );
82
83
#endif
84
85
86