38 #elif defined(sgiN32) || defined(sgiN32Gcc)
46 struct sigaction
Foam::sigFpe::oldAction_;
52 lst = std::numeric_limits<scalar>::signaling_NaN();
61 extern void* __libc_malloc(
size_t size);
64 void* malloc(
size_t size)
68 return Foam::sigFpe::mallocNan(size);
72 return __libc_malloc(size);
77 void* Foam::sigFpe::mallocNan(
size_t size)
80 void * result = __libc_malloc(size);
83 UList<scalar> lst(
reinterpret_cast<scalar*
>(result), size/
sizeof(scalar));
92 void Foam::sigFpe::sigHandler(
int)
95 if (sigaction(SIGFPE, &oldAction_, NULL) < 0)
98 <<
"Cannot reset SIGFPE trapping"
133 if (!sigFpeActive_ &&
env(
"FOAM_SIGFPE"))
135 bool supported =
false;
147 struct sigaction newAction;
148 newAction.sa_handler = sigHandler;
149 newAction.sa_flags = SA_NODEFER;
150 sigemptyset(&newAction.sa_mask);
151 if (sigaction(SIGFPE, &newAction, &oldAction_) < 0)
154 <<
"Cannot set SIGFPE trapping"
158 sigFpeActive_ =
true;
160 #elif defined(sgiN32) || defined(sgiN32Gcc)
163 sigfpe_[_DIVZERO].abort=1;
164 sigfpe_[_OVERFL].abort=1;
165 sigfpe_[_INVALID].abort=1;
167 sigfpe_[_DIVZERO].trace=1;
168 sigfpe_[_OVERFL].trace=1;
169 sigfpe_[_INVALID].trace=1;
182 sigFpeActive_ =
true;
191 Info<<
"sigFpe : Enabling floating point exception trapping"
192 <<
" (FOAM_SIGFPE)." <<
endl;
196 Info<<
"sigFpe : Floating point exception trapping"
197 <<
" - not supported on this platform" <<
endl;
203 if (
env(
"FOAM_SETNAN"))
206 mallocNanActive_ =
true;
211 if (mallocNanActive_)
213 Info<<
"SetNaN : Initialising allocated memory to NaN"
214 <<
" (FOAM_SETNAN)." <<
endl;
218 Info<<
"SetNaN : Initialise allocated memory to NaN"
219 <<
" - not supported on this platform" <<
endl;
234 Info<<
"sigFpe : Disabling floating point exception trapping"
238 if (sigaction(SIGFPE, &oldAction_, NULL) < 0)
241 <<
"Cannot reset SIGFPE trapping"
246 int oldExcept = fedisableexcept
256 <<
"Cannot reset SIGFPE trapping"
259 sigFpeActive_ =
false;
265 mallocNanActive_ =
false;