diff options
author | Jakob Kaivo <jkk@ung.org> | 2019-02-08 18:42:39 -0500 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2019-02-08 18:42:39 -0500 |
commit | 7ef8a7379f7f7d09e71ccae2a0b688c3cd80423f (patch) | |
tree | 092ab0aed1769117fd7b28b8592f6f96b0e0d5af /src/signal | |
parent | 6acf19370e8adff79cd83b257d3f04aeaf2a59dd (diff) |
merge sources into single tree
Diffstat (limited to 'src/signal')
-rw-r--r-- | src/signal/SIGABRT.c | 10 | ||||
-rw-r--r-- | src/signal/SIGFPE.c | 10 | ||||
-rw-r--r-- | src/signal/SIGILL.c | 10 | ||||
-rw-r--r-- | src/signal/SIGINT.c | 9 | ||||
-rw-r--r-- | src/signal/SIGSEGV.c | 10 | ||||
-rw-r--r-- | src/signal/SIGTERM.c | 9 | ||||
-rw-r--r-- | src/signal/SIG_DFL.c | 10 | ||||
-rw-r--r-- | src/signal/SIG_ERR.c | 12 | ||||
-rw-r--r-- | src/signal/SIG_IGN.c | 12 | ||||
-rw-r--r-- | src/signal/raise.c | 28 | ||||
-rw-r--r-- | src/signal/sig_atomic_t.c | 15 | ||||
-rw-r--r-- | src/signal/signal.c | 42 |
12 files changed, 177 insertions, 0 deletions
diff --git a/src/signal/SIGABRT.c b/src/signal/SIGABRT.c new file mode 100644 index 00000000..f1878ecf --- /dev/null +++ b/src/signal/SIGABRT.c @@ -0,0 +1,10 @@ +#include <signal.h> +#define SIGABRT (1) +/** abnormal termination **/ +/*** +is a signal indicating that the program is being terminated abnormally, +such as when FUNCTION(abort) is called. +***/ +/* +STDC(1) +*/ diff --git a/src/signal/SIGFPE.c b/src/signal/SIGFPE.c new file mode 100644 index 00000000..c61c78fe --- /dev/null +++ b/src/signal/SIGFPE.c @@ -0,0 +1,10 @@ +#include <signal.h> +#define SIGFPE (2) +/** floating point exception **/ +/*** +is a signal that indicates an error resulting from invalid arithmetic +operations, such as division by zero or overflows. +***/ +/* +STDC(1) +*/ diff --git a/src/signal/SIGILL.c b/src/signal/SIGILL.c new file mode 100644 index 00000000..1d6c588f --- /dev/null +++ b/src/signal/SIGILL.c @@ -0,0 +1,10 @@ +#include <signal.h> +#define SIGILL (3) +/** illegal instruction **/ +/*** +is a signal indicating that the program has attempted to execute an illegal +or improperly formed instruction. +***/ +/* +STDC(1) +*/ diff --git a/src/signal/SIGINT.c b/src/signal/SIGINT.c new file mode 100644 index 00000000..32169d73 --- /dev/null +++ b/src/signal/SIGINT.c @@ -0,0 +1,9 @@ +#include <signal.h> +#define SIGINT (4) +/** interrupt **/ +/*** +is a signal that indicates the program is being interactively interrupted. +***/ +/* +STDC(1) +*/ diff --git a/src/signal/SIGSEGV.c b/src/signal/SIGSEGV.c new file mode 100644 index 00000000..5d6da2b4 --- /dev/null +++ b/src/signal/SIGSEGV.c @@ -0,0 +1,10 @@ +#include <signal.h> +#define SIGSEGV (5) +/** segmentation fault **/ +/*** +is a signal that indicates the program is attempting to access an invalid +memory address. +***/ +/* +STDC(1) +*/ diff --git a/src/signal/SIGTERM.c b/src/signal/SIGTERM.c new file mode 100644 index 00000000..990c0730 --- /dev/null +++ b/src/signal/SIGTERM.c @@ -0,0 +1,9 @@ +#include <signal.h> +#define SIGTERM (6) +/** terminate **/ +/*** +is a signal indicating that the system is requesting the program to terminate. +***/ +/* +STDC(1) +*/ diff --git a/src/signal/SIG_DFL.c b/src/signal/SIG_DFL.c new file mode 100644 index 00000000..549fe6e4 --- /dev/null +++ b/src/signal/SIG_DFL.c @@ -0,0 +1,10 @@ +#include <signal.h> +#define SIG_DFL ((void(*)(int))-1) +/** default signal action **/ +/*** +is used as the ARGUMENT(func) argument to FUNCTION(signal) to indicate that +the default signal action should occur. +***/ +/* +STDC(1) +*/ diff --git a/src/signal/SIG_ERR.c b/src/signal/SIG_ERR.c new file mode 100644 index 00000000..0200a72f --- /dev/null +++ b/src/signal/SIG_ERR.c @@ -0,0 +1,12 @@ +#include <signal.h> +#define SIG_ERR ((void(*)(int))-2) + +/** error setting signal handler **/ + +/*** +is a sentinal value returned by FUNCTION(signal) to indicate that an error +occurred. +***/ +/* +STDC(1) +*/ diff --git a/src/signal/SIG_IGN.c b/src/signal/SIG_IGN.c new file mode 100644 index 00000000..a753adc7 --- /dev/null +++ b/src/signal/SIG_IGN.c @@ -0,0 +1,12 @@ +#include <signal.h> +#define SIG_IGN ((void(*)(int))-3) + +/** ignore signal **/ + +/*** +can be used as the ARGUMENT(func) argument in a call to FUNCTION(signal) to +ignore the specified signal. +***/ +/* +STDC(1) +*/ diff --git a/src/signal/raise.c b/src/signal/raise.c new file mode 100644 index 00000000..530f893b --- /dev/null +++ b/src/signal/raise.c @@ -0,0 +1,28 @@ +#if defined _POSIX_SOURCE || defined _POSIX_C_SOURCE || defined _XOPEN_SOURCE +#include "sys/types.h" +#include "unistd.h" +#else +#define kill(pid, sig) (sig ? -1 : -1) +#endif +#include <signal.h> + +/** send a signal to the current program **/ +int raise(int sig) +{ + /* + RETURN_FAILURE(NONZERO); + RETURN_SUCCESS(0); + */ + #if (defined _POSIX_C_SOURCE && _POSIX_C_SOURCE >= 199506L) + return pthread_kill(pthread_self(), sig); + #else + return kill(getpid(), sig); + #endif +} + +/*** +sends the signal ARGUMENT(sig) to the current program. +***/ +/* +STDC(1) +*/ diff --git a/src/signal/sig_atomic_t.c b/src/signal/sig_atomic_t.c new file mode 100644 index 00000000..b3ec2a84 --- /dev/null +++ b/src/signal/sig_atomic_t.c @@ -0,0 +1,15 @@ +#include <signal.h> +typedef volatile int sig_atomic_t; + +/** non-interruptible type **/ + +/*** +is a type of object that can be used atomically even in the presence of interrupts. +***/ + +/* +TYPEDEF(integer) +*/ +/* +STDC(1) +*/ diff --git a/src/signal/signal.c b/src/signal/signal.c new file mode 100644 index 00000000..373fddc5 --- /dev/null +++ b/src/signal/signal.c @@ -0,0 +1,42 @@ +#if defined _POSIX_SOURCE +#include "sys/types.h" +#endif + +#include <signal.h> + +/** set a signal handler **/ +void (*signal(int sig, void (*func)(int)))(int) +{ + (void)sig; + /* TODO */ + /* + RETURN_SUCCESS(a pointer to the signal handler); + RETURN_FAILURE(CONSTANT(SIG_ERR), the request could not be honored); + */ + return func; +} + +/*** +sets the signal handler for the signal specified by ARGUMENT(sig) to +ARGUMENT(func). + +Specifying CONSTANT(SIG_DFL) for ARGUMENT(func) resets the signal handler +to its default behavior. + +Specifying CONSTANT(SIG_IGN) for ARGUMENT(func) causes the signal +ARGUMENT(sig) to be ignored. + +Otherwise, ARGUMENT(func) must be a pointer to a function which takes a +single TYPE(int) argument and does not return a value. +***/ + +/* +UNDEFINED(A signal handler for CONSTANT(SIGFPE) returns) +UNDEFINED(A signal handler calling standard library functions other than THIS() if the signal occurs as other than as a result of calling FUNCTION(abort) or FUNCTION(raise)) +UNDEFINED(FIXME: some function calls from signal handlers) +IMPLEMENTATION(Whether signal blocking is performed when a signal occurs) +IMPLEMENTATION(Other signals corresponding to computation exceptions for which signal handlers must not return) +*/ +/* +STDC(1) +*/ |