38 #elif defined(sgiN32) || defined(sgiN32Gcc) 46 struct sigaction
Foam::sigFpe::oldAction_;
50 lst = std::numeric_limits<scalar>::signaling_NaN();
59 extern void* __libc_malloc(
size_t size);
62 void* malloc(
size_t size)
66 return Foam::sigFpe::mallocNan(size);
70 return __libc_malloc(size);
75 void* Foam::sigFpe::mallocNan(
size_t size)
78 void * result = __libc_malloc(size);
81 UList<scalar> lst(reinterpret_cast<scalar*>(result), size/
sizeof(scalar));
90 void Foam::sigFpe::sigHandler(
int)
93 if (sigaction(SIGFPE, &oldAction_, NULL) < 0)
96 <<
"Cannot reset SIGFPE trapping" 103 error::printStack(
Perr);
115 oldAction_.sa_handler = NULL;
123 if (
env(
"FOAM_SIGFPE"))
127 if (oldAction_.sa_handler && sigaction(SIGFPE, &oldAction_, NULL) < 0)
130 <<
"Cannot reset SIGFPE trapping" 136 if (
env(
"FOAM_SETNAN"))
140 mallocNanActive_ =
false;
150 if (oldAction_.sa_handler)
153 <<
"Cannot call sigFpe::set() more than once" 157 if (
env(
"FOAM_SIGFPE"))
159 bool supported =
false;
171 struct sigaction newAction;
172 newAction.sa_handler = sigHandler;
173 newAction.sa_flags = SA_NODEFER;
174 sigemptyset(&newAction.sa_mask);
175 if (sigaction(SIGFPE, &newAction, &oldAction_) < 0)
178 <<
"Cannot set SIGFPE trapping" 183 #elif defined(sgiN32) || defined(sgiN32Gcc) 186 sigfpe_[_DIVZERO].abort=1;
187 sigfpe_[_OVERFL].abort=1;
188 sigfpe_[_INVALID].abort=1;
190 sigfpe_[_DIVZERO].trace=1;
191 sigfpe_[_OVERFL].trace=1;
192 sigfpe_[_INVALID].trace=1;
211 Info<<
"sigFpe : Enabling floating point exception trapping" 212 <<
" (FOAM_SIGFPE)." <<
endl;
216 Info<<
"sigFpe : Floating point exception trapping" 217 <<
" - not supported on this platform" <<
endl;
223 if (
env(
"FOAM_SETNAN"))
226 mallocNanActive_ =
true;
231 if (mallocNanActive_)
233 Info<<
"SetNaN : Initialising allocated memory to NaN" 234 <<
" (FOAM_SETNAN)." <<
endl;
238 Info<<
"SetNaN : Initialise allocated memory to NaN" 239 <<
" - not supported on this platform" <<
endl;
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Ostream & endl(Ostream &os)
Add newline and flush stream.
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 fillNan(UList< scalar > &)
Fill block of data with NaN.
errorManip< error > abort(error &err)
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
prefixOSstream Perr(cerr,"Perr")
void set(const bool verbose)
Activate SIGFPE signal handler when FOAM_SIGFPE is set.
static bool mallocNanActive_
Flag to indicate mallocNan is enabled.
bool env(const word &)
Return true if environment variable of given name is defined.