44 struct sigaction
Foam::sigFpe::oldAction_;
48 lst = std::numeric_limits<scalar>::signaling_NaN();
57 extern void* __libc_malloc(
size_t size);
60 void* malloc(
size_t size)
64 return Foam::sigFpe::mallocNan(size);
68 return __libc_malloc(size);
73 void* Foam::sigFpe::mallocNan(
size_t size)
76 void * result = __libc_malloc(size);
79 UList<scalar> lst(
reinterpret_cast<scalar*
>(result), size/
sizeof(scalar));
88 void Foam::sigFpe::sigHandler(
int)
91 if (sigaction(SIGFPE, &oldAction_,
nullptr) < 0)
94 <<
"Cannot reset SIGFPE trapping"
113 oldAction_.sa_handler =
nullptr;
121 if (
env(
"FOAM_SIGFPE"))
127 oldAction_.sa_handler
128 && sigaction(SIGFPE, &oldAction_,
nullptr) < 0
132 <<
"Cannot reset SIGFPE trapping"
138 if (
env(
"FOAM_SETNAN"))
142 mallocNanActive_ =
false;
152 if (oldAction_.sa_handler)
155 <<
"Cannot call sigFpe::set() more than once"
159 if (
env(
"FOAM_SIGFPE"))
161 bool supported =
false;
173 struct sigaction newAction;
174 newAction.sa_handler = sigHandler;
175 newAction.sa_flags = SA_NODEFER;
176 sigemptyset(&newAction.sa_mask);
177 if (sigaction(SIGFPE, &newAction, &oldAction_) < 0)
180 <<
"Cannot set SIGFPE trapping"
189 Info<<
"sigFpe : Enabling floating point exception trapping"
190 <<
" (FOAM_SIGFPE)." <<
endl;
194 Info<<
"sigFpe : Floating point exception trapping"
195 <<
" - not supported on this platform" <<
endl;
201 if (
env(
"FOAM_SETNAN"))
204 mallocNanActive_ =
true;
209 if (mallocNanActive_)
211 Info<<
"SetNaN : Initialising allocated memory to NaN"
212 <<
" (FOAM_SETNAN)." <<
endl;
216 Info<<
"SetNaN : Initialise allocated memory to NaN"
217 <<
" - not supported on this platform" <<
endl;
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
static void printStack(Ostream &)
Helper function to print a stack.
static bool mallocNanActive_
Flag to indicate mallocNan is enabled.
static void fillNan(UList< scalar > &)
Fill block of data with NaN.
void set(const bool verbose)
Activate SIGFPE signal handler when FOAM_SIGFPE is set.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
prefixOSstream Perr(cerr, "Perr")
bool env(const word &)
Return true if environment variable of given name is defined.
Ostream & endl(Ostream &os)
Add newline and flush stream.
errorManip< error > abort(error &err)