[dbe9b08] | 1 | //
|
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
|
---|
| 3 | //
|
---|
| 4 | // The contents of this file are covered under the licence agreement in the
|
---|
| 5 | // file "LICENCE" distributed with Cforall.
|
---|
| 6 | //
|
---|
[73abe95] | 7 | // bits/signal.hfa -- Helper functions and defines to use signals
|
---|
[dbe9b08] | 8 | //
|
---|
| 9 | // Author : Thierry Delisle
|
---|
| 10 | // Created On : Thu Jan 25 16:06:29 2018
|
---|
| 11 | // Last Modified By :
|
---|
| 12 | // Last Modified On :
|
---|
| 13 | // Update Count :
|
---|
| 14 | //
|
---|
| 15 |
|
---|
| 16 | #pragma once
|
---|
| 17 |
|
---|
[73abe95] | 18 | #include "bits/debug.hfa"
|
---|
| 19 | #include "bits/defs.hfa"
|
---|
[dbe9b08] | 20 |
|
---|
| 21 | #include <errno.h>
|
---|
| 22 | #define __USE_GNU
|
---|
[58b6d1b] | 23 | #include <signal.h>
|
---|
[dbe9b08] | 24 | #undef __USE_GNU
|
---|
| 25 | #include <stdlib.h>
|
---|
| 26 | #include <string.h>
|
---|
| 27 |
|
---|
| 28 | // Short hands for signal context information
|
---|
| 29 | #define __CFA_SIGCXT__ ucontext_t *
|
---|
| 30 | #define __CFA_SIGPARMS__ __attribute__((unused)) int sig, __attribute__((unused)) siginfo_t *sfp, __attribute__((unused)) __CFA_SIGCXT__ cxt
|
---|
| 31 |
|
---|
| 32 | // Sigaction wrapper : register an signal handler
|
---|
[2b8bc41] | 33 | static void __cfaabi_sigaction( int sig, void (*handler)(__CFA_SIGPARMS__), int flags ) {
|
---|
[dbe9b08] | 34 | struct sigaction act;
|
---|
| 35 |
|
---|
| 36 | act.sa_sigaction = (void (*)(int, siginfo_t *, void *))handler;
|
---|
[7006ba5] | 37 | sigemptyset( &act.sa_mask );
|
---|
| 38 | sigaddset( &act.sa_mask, SIGALRM ); // disabled during signal handler
|
---|
| 39 | sigaddset( &act.sa_mask, SIGUSR1 );
|
---|
[8a13c47] | 40 | sigaddset( &act.sa_mask, SIGSEGV );
|
---|
| 41 | sigaddset( &act.sa_mask, SIGBUS );
|
---|
| 42 | sigaddset( &act.sa_mask, SIGILL );
|
---|
| 43 | sigaddset( &act.sa_mask, SIGFPE );
|
---|
| 44 | sigaddset( &act.sa_mask, SIGHUP ); // revert to default on second delivery
|
---|
| 45 | sigaddset( &act.sa_mask, SIGTERM );
|
---|
| 46 | sigaddset( &act.sa_mask, SIGINT );
|
---|
[dbe9b08] | 47 | act.sa_flags = flags;
|
---|
| 48 |
|
---|
[8a13c47] | 49 | if ( sigaction( sig, &act, 0p ) == -1 ) {
|
---|
[dbe9b08] | 50 | __cfaabi_dbg_print_buffer_decl(
|
---|
[2b8bc41] | 51 | " __cfaabi_sigaction( sig:%d, handler:%p, flags:%d ), problem installing signal handler, error(%d) %s.\n",
|
---|
[dbe9b08] | 52 | sig, handler, flags, errno, strerror( errno )
|
---|
| 53 | );
|
---|
[c59a346] | 54 | _Exit( EXIT_FAILURE );
|
---|
[8a13c47] | 55 | } // if
|
---|
[2b8bc41] | 56 | }
|
---|