| 1 |
/* |
| 2 |
* (C) Copyright 2013 ECMWF. |
| 3 |
* |
| 4 |
* This software is licensed under the terms of the Apache Licence Version 2.0 |
| 5 |
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
| 6 |
* In applying this licence, ECMWF does not waive the privileges and immunities |
| 7 |
* granted to it by virtue of its status as an intergovernmental organisation |
| 8 |
* nor does it submit to any jurisdiction. |
| 9 |
*/ |
| 10 |
|
| 11 |
#include <csignal> |
| 12 |
#include <iosfwd> |
| 13 |
#include <map> |
| 14 |
#include <string> |
| 15 |
#include <cfenv> |
| 16 |
|
| 17 |
namespace atlas { |
| 18 |
namespace library { |
| 19 |
|
| 20 |
// ------------------------------------------------------------------------------------ |
| 21 |
|
| 22 |
/* @brief Enable floating point exceptions |
| 23 |
* |
| 24 |
* An environment variable is responsible to enable: |
| 25 |
* - ATLAS_FPE=0 --> Default. do not enable anything in Atlas (other libraries or programs may still do so) |
| 26 |
* - ATLAS_FPE=1 --> FE_INVALID, FE_DIVBYZERO, FE_OVERFLOW |
| 27 |
* - ATLAS_FPE=VALUE1,VALUE2,... --> Specified codes only. Valid codes: |
| 28 |
* FE_INVALID, FE_DIVBYZERO, FE_OVERFLOW, FE_UNDERFLOW, FE_INEXACT, FE_ALL_EXCEPT |
| 29 |
* |
| 30 |
* @note This function is called automatically within Library::initialize() and should |
| 31 |
* not be called directly |
| 32 |
*/ |
| 33 |
void enable_floating_point_exceptions(); |
| 34 |
|
| 35 |
/* @brief Enable floating point exception |
| 36 |
* |
| 37 |
* Valid codes: |
| 38 |
* FE_INVALID, FE_DIVBYZERO, FE_OVERFLOW, FE_UNDERFLOW, FE_INEXACT, FE_ALL_EXCEPT |
| 39 |
* |
| 40 |
* @return false when the exception was already enabled, true when change was made |
| 41 |
*/ |
| 42 |
bool enable_floating_point_exception(const std::string&); |
| 43 |
bool enable_floating_point_exception(int); |
| 44 |
|
| 45 |
/* @brief Disable floating point exception |
| 46 |
* |
| 47 |
* Valid codes: |
| 48 |
* FE_INVALID, FE_DIVBYZERO, FE_OVERFLOW, FE_UNDERFLOW, FE_INEXACT, FE_ALL_EXCEPT |
| 49 |
* |
| 50 |
* @return false when the exception was already disabled, true when change was made |
| 51 |
*/ |
| 52 |
bool disable_floating_point_exception(const std::string&); |
| 53 |
bool disable_floating_point_exception(int); |
| 54 |
|
| 55 |
// ------------------------------------------------------------------------------------ |
| 56 |
|
| 57 |
/* @brief Enable atlas signal handler for all signals |
| 58 |
* |
| 59 |
* An environment variable is responsible to enable: |
| 60 |
* - ATLAS_SIGNAL_HANDLER=0 --> Default. Atlas will not set any signal handlers |
| 61 |
* - ATLAS_SIGNAL_HANDLER=1 --> Enable atlas_signal_handler instead of the default for signals: |
| 62 |
* |
| 63 |
* Enabled signals: |
| 64 |
* - SIGABRT |
| 65 |
* - SIGFPE |
| 66 |
* - SIGILL |
| 67 |
* - SIGINT |
| 68 |
* - SIGSEGV |
| 69 |
* - SIGTERM |
| 70 |
* - SIGKILL |
| 71 |
* |
| 72 |
* @note This function is called automatically within Library::initialize() and should |
| 73 |
* not be called directly |
| 74 |
*/ |
| 75 |
void enable_atlas_signal_handler(); |
| 76 |
|
| 77 |
// ------------------------------------------------------------------------------------ |
| 78 |
|
| 79 |
using signal_handler_t = void (*)(int); |
| 80 |
using signal_action_t = void (*)(int, ::siginfo_t*, void*); |
| 81 |
|
| 82 |
[[noreturn]] void atlas_signal_handler(int signum, ::siginfo_t* si, void* unused); |
| 83 |
|
| 84 |
// ------------------------------------------------------------------------------------ |
| 85 |
|
| 86 |
} // namespace library |
| 87 |
} // namespace atlas |