jehanne: exploring a deep refactoring for signals

This commit is contained in:
Giacomo Tesio 2017-09-13 01:37:54 +02:00
parent 31d2a8df16
commit b891b3c8da
2 changed files with 83 additions and 50 deletions

View File

@ -0,0 +1,37 @@
#ifndef _SIGNAL_H_
#define _SIGNAL_H_
#define GIACOMO
#include "_ansi.h"
#include <sys/cdefs.h>
#include <sys/signal.h>
_BEGIN_STD_C
typedef int sig_atomic_t; /* Atomic entity type (ANSI) */
#if __BSD_VISIBLE
typedef _sig_func_ptr sig_t; /* BSD naming */
#endif
#if __GNU_VISIBLE
typedef _sig_func_ptr sighandler_t; /* glibc naming */
#endif
#define SIG_DFL ((_sig_func_ptr)0) /* Default action */
#define SIG_IGN ((_sig_func_ptr)1) /* Ignore action */
#define SIG_ERR ((_sig_func_ptr)-1) /* Error return */
struct _reent;
_sig_func_ptr _EXFUN(_signal_r, (struct _reent *, int, _sig_func_ptr));
int _EXFUN(_raise_r, (struct _reent *, int));
#ifndef _REENT_ONLY
_sig_func_ptr _EXFUN(signal, (int, _sig_func_ptr));
int _EXFUN(raise, (int));
void _EXFUN(psignal, (int, const char *));
#endif
_END_STD_C
#endif /* _SIGNAL_H_ */

View File

@ -32,8 +32,12 @@ extern "C" {
#include <sys/_timespec.h> #include <sys/_timespec.h>
#include <sys/_pthreadtypes.h> #include <sys/_pthreadtypes.h>
#define _LIBPOSIX_H
#include <posix.h> /* get libposix defines from posix.h */
#undef _LIBPOSIX_H
#define _SIGSET_T_DECLARED #define _SIGSET_T_DECLARED
typedef unsigned long sigset_t; typedef PosixSignalMask sigset_t;
/* sigev_notify values /* sigev_notify values
NOTE: P1003.1c/D10, p. 34 adds SIGEV_THREAD. */ NOTE: P1003.1c/D10, p. 34 adds SIGEV_THREAD. */
@ -73,11 +77,7 @@ struct sigevent {
#define SI_ASYNCIO 4 /* Indicates completion of asycnhronous IO */ #define SI_ASYNCIO 4 /* Indicates completion of asycnhronous IO */
#define SI_MESGQ 5 /* Indicates arrival of a message at an empty queue */ #define SI_MESGQ 5 /* Indicates arrival of a message at an empty queue */
typedef struct { #define siginfo_t PosixSignalInfo;
int si_signo; /* Signal number */
int si_code; /* Cause of the signal */
union sigval si_value; /* Signal value */
} siginfo_t;
/* 3.3.8 Synchronously Accept a Signal, P1003.1b-1993, p. 76 */ /* 3.3.8 Synchronously Accept a Signal, P1003.1b-1993, p. 76 */
@ -96,10 +96,6 @@ typedef struct {
* (2) The fields sa_handler and sa_sigaction may overlap, and a conforming * (2) The fields sa_handler and sa_sigaction may overlap, and a conforming
* application should not use both simultaneously. * application should not use both simultaneously.
*/ */
typedef void (*_sig_func_ptr)(int);
typedef void (*_sig_act_ptr)(int, siginfo_t *, void * );
struct sigaction { struct sigaction {
int sa_flags; /* Special flags to affect behavior of signal */ int sa_flags; /* Special flags to affect behavior of signal */
sigset_t sa_mask; /* Additional set of signals to be blocked */ sigset_t sa_mask; /* Additional set of signals to be blocked */
@ -144,9 +140,9 @@ typedef struct sigaltstack {
} stack_t; } stack_t;
#if __POSIX_VISIBLE #if __POSIX_VISIBLE
#define SIG_SETMASK 0 /* set mask with sigprocmask() */ #define SIG_SETMASK PosixSPMSetMask
#define SIG_BLOCK 1 /* set of signals to block */ #define SIG_BLOCK PosixSPMBlock
#define SIG_UNBLOCK 2 /* set of signals to, well, unblock */ #define SIG_UNBLOCK PosixSPMUnblock
int sigprocmask (int how, const sigset_t *set, sigset_t *oset); int sigprocmask (int how, const sigset_t *set, sigset_t *oset);
#endif #endif
@ -198,47 +194,47 @@ int sigqueue (pid_t pid, int signo, const union sigval value);
#endif /* __POSIX_VISIBLE >= 199309 */ #endif /* __POSIX_VISIBLE >= 199309 */
#define SIGHUP 1 /* hangup */ #define SIGHUP PosixSIGHUP /* hangup */
#define SIGINT 2 /* interrupt */ #define SIGINT PosixSIGINT /* interrupt */
#define SIGQUIT 3 /* quit */ #define SIGQUIT PosixSIGQUIT /* quit */
#define SIGILL 4 /* illegal instruction (not reset when caught) */ #define SIGILL PosixSIGILL /* illegal instruction (not reset when caught) */
#define SIGTRAP 5 /* trace trap (not reset when caught) */ #define SIGTRAP PosixSIGTRAP /* trace trap (not reset when caught) */
#define SIGIOT 6 /* IOT instruction */ #define SIGIOT PosixSIGIOT /* IOT instruction */
#define SIGABRT 6 /* used by abort, replace SIGIOT in the future */ #define SIGABRT PosixSIGABRT /* used by abort, replace SIGIOT in the future */
#define SIGEMT 7 /* EMT instruction */ #define SIGEMT PosixSIGEMT /* EMT instruction */
#define SIGFPE 8 /* floating point exception */ #define SIGFPE PosixSIGFPE /* floating point exception */
#define SIGKILL 9 /* kill (cannot be caught or ignored) */ #define SIGKILL PosixSIGKILL /* kill (cannot be caught or ignored) */
#define SIGBUS 10 /* bus error */ #define SIGBUS PosixSIGBUS /* bus error */
#define SIGSEGV 11 /* segmentation violation */ #define SIGSEGV PosixSIGSEGV /* segmentation violation */
#define SIGSYS 12 /* bad argument to system call */ #define SIGSYS PosixSIGSYS /* bad argument to system call */
#define SIGPIPE 13 /* write on a pipe with no one to read it */ #define SIGPIPE PosixSIGPIPE /* write on a pipe with no one to read it */
#define SIGALRM 14 /* alarm clock */ #define SIGALRM PosixSIGALRM /* alarm clock */
#define SIGTERM 15 /* software termination signal from kill */ #define SIGTERM PosixSIGTERM /* software termination signal from kill */
#define SIGURG 16 /* urgent condition on IO channel */ #define SIGURG PosixSIGURG /* urgent condition on IO channel */
#define SIGSTOP 17 /* sendable stop signal not from tty */ #define SIGSTOP PosixSIGSTOP /* sendable stop signal not from tty */
#define SIGTSTP 18 /* stop signal from tty */ #define SIGTSTP PosixSIGTSTP /* stop signal from tty */
#define SIGCONT 19 /* continue a stopped process */ #define SIGCONT PosixSIGCONT /* continue a stopped process */
#define SIGCHLD 20 /* to parent on child stop or exit */ #define SIGCHLD PosixSIGCHLD /* to parent on child stop or exit */
#define SIGCLD 20 /* System V name for SIGCHLD */ #define SIGCLD PosixSIGCLD /* System V name for SIGCHLD */
#define SIGTTIN 21 /* to readers pgrp upon background tty read */ #define SIGTTIN PosixSIGTTIN /* to readers pgrp upon background tty read */
#define SIGTTOU 22 /* like TTIN for output if (tp->t_local&LTOSTOP) */ #define SIGTTOU PosixSIGTTOU /* like TTIN for output if (tp->t_local&LTOSTOP) */
#define SIGIO 23 /* input/output possible signal */ #define SIGIO PosixSIGIO /* input/output possible signal */
#define SIGPOLL SIGIO /* System V name for SIGIO */ #define SIGPOLL PosixSIGIO /* System V name for SIGIO */
#define SIGXCPU 24 /* exceeded CPU time limit */ #define SIGXCPU PosixSIGXCPU /* exceeded CPU time limit */
#define SIGXFSZ 25 /* exceeded file size limit */ #define SIGXFSZ PosixSIGXFSZ /* exceeded file size limit */
#define SIGVTALRM 26 /* virtual time alarm */ #define SIGVTALRM PosixSIGVTALRM /* virtual time alarm */
#define SIGPROF 27 /* profiling time alarm */ #define SIGPROF PosixSIGPROF /* profiling time alarm */
#define SIGWINCH 28 /* window changed */ #define SIGWINCH PosixSIGWINCH /* window changed */
#define SIGLOST 29 /* resource lost (eg, record-lock lost) */ #define SIGLOST PosixSIGLOST /* resource lost (eg, record-lock lost) */
#define SIGUSR1 30 /* user defined signal 1 */ #define SIGUSR1 PosixSIGUSR1 /* user defined signal 1 */
#define SIGUSR2 31 /* user defined signal 2 */ #define SIGUSR2 PosixSIGUSR2 /* user defined signal 2 */
/* Real-Time Signals Range, P1003.1b-1993, p. 61 /* Real-Time Signals Range, P1003.1b-1993, p. 61
NOTE: By P1003.1b-1993, this should be at least RTSIG_MAX NOTE: By P1003.1b-1993, this should be at least RTSIG_MAX
(which is a minimum of 8) signals. (which is a minimum of 8) signals.
*/ */
#define SIGRTMIN 32 #define SIGRTMIN PosixSIGRTMIN
#define SIGRTMAX 63 #define SIGRTMAX PosixSIGRTMAX
#define NSIG 64 /* signal 0 implied */ #define NSIG 64 /* signal 0 implied */