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_,
nullptr) < 0)
96 <<
"Cannot reset SIGFPE trapping" 103 error::printStack(
Perr);
115 oldAction_.sa_handler =
nullptr;
123 if (
env(
"FOAM_SIGFPE"))
129 oldAction_.sa_handler
130 && sigaction(SIGFPE, &oldAction_,
nullptr) < 0
134 <<
"Cannot reset SIGFPE trapping" 140 if (
env(
"FOAM_SETNAN"))
144 mallocNanActive_ =
false;
154 if (oldAction_.sa_handler)
157 <<
"Cannot call sigFpe::set() more than once" 161 if (
env(
"FOAM_SIGFPE"))
163 bool supported =
false;
175 struct sigaction newAction;
176 newAction.sa_handler = sigHandler;
177 newAction.sa_flags = SA_NODEFER;
178 sigemptyset(&newAction.sa_mask);
179 if (sigaction(SIGFPE, &newAction, &oldAction_) < 0)
182 <<
"Cannot set SIGFPE trapping" 187 #elif defined(sgiN32) || defined(sgiN32Gcc) 190 sigfpe_[_DIVZERO].abort=1;
191 sigfpe_[_OVERFL].abort=1;
192 sigfpe_[_INVALID].abort=1;
194 sigfpe_[_DIVZERO].trace=1;
195 sigfpe_[_OVERFL].trace=1;
196 sigfpe_[_INVALID].trace=1;
215 Info<<
"sigFpe : Enabling floating point exception trapping" 216 <<
" (FOAM_SIGFPE)." <<
endl;
220 Info<<
"sigFpe : Floating point exception trapping" 221 <<
" - not supported on this platform" <<
endl;
227 if (
env(
"FOAM_SETNAN"))
230 mallocNanActive_ =
true;
235 if (mallocNanActive_)
237 Info<<
"SetNaN : Initialising allocated memory to NaN" 238 <<
" (FOAM_SETNAN)." <<
endl;
242 Info<<
"SetNaN : Initialise allocated memory to NaN" 243 <<
" - 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.