[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 | // |
---|
| 7 | // bits/signal.h -- Helper functions and defines to use signals |
---|
| 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 | |
---|
| 18 | #include "bits/debug.h" |
---|
| 19 | #include "bits/defs.h" |
---|
| 20 | |
---|
| 21 | extern "C" { |
---|
| 22 | #include <errno.h> |
---|
| 23 | #define __USE_GNU |
---|
| 24 | #include <signal.h> |
---|
| 25 | #undef __USE_GNU |
---|
| 26 | #include <stdlib.h> |
---|
| 27 | #include <string.h> |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | // Short hands for signal context information |
---|
| 31 | #define __CFA_SIGCXT__ ucontext_t * |
---|
| 32 | #define __CFA_SIGPARMS__ __attribute__((unused)) int sig, __attribute__((unused)) siginfo_t *sfp, __attribute__((unused)) __CFA_SIGCXT__ cxt |
---|
| 33 | |
---|
| 34 | // Sigaction wrapper : register an signal handler |
---|
| 35 | static void __kernel_sigaction( int sig, void (*handler)(__CFA_SIGPARMS__), int flags ) { |
---|
| 36 | struct sigaction act; |
---|
| 37 | |
---|
| 38 | act.sa_sigaction = (void (*)(int, siginfo_t *, void *))handler; |
---|
| 39 | act.sa_flags = flags; |
---|
| 40 | |
---|
| 41 | if ( sigaction( sig, &act, NULL ) == -1 ) { |
---|
| 42 | __cfaabi_dbg_print_buffer_decl( |
---|
| 43 | " __kernel_sigaction( sig:%d, handler:%p, flags:%d ), problem installing signal handler, error(%d) %s.\n", |
---|
| 44 | sig, handler, flags, errno, strerror( errno ) |
---|
| 45 | ); |
---|
| 46 | _exit( EXIT_FAILURE ); |
---|
| 47 | } |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | // Sigaction wrapper : restore default handler |
---|
| 51 | static void __kernel_sigdefault( int sig ) { |
---|
| 52 | struct sigaction act; |
---|
| 53 | |
---|
| 54 | act.sa_handler = SIG_DFL; |
---|
| 55 | act.sa_flags = 0; |
---|
| 56 | sigemptyset( &act.sa_mask ); |
---|
| 57 | |
---|
| 58 | if ( sigaction( sig, &act, NULL ) == -1 ) { |
---|
| 59 | __cfaabi_dbg_print_buffer_decl( |
---|
| 60 | " __kernel_sigdefault( sig:%d ), problem reseting signal handler, error(%d) %s.\n", |
---|
| 61 | sig, errno, strerror( errno ) |
---|
| 62 | ); |
---|
| 63 | _exit( EXIT_FAILURE ); |
---|
| 64 | } |
---|
| 65 | } |
---|