1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
28 Set up trapping for floating point exceptions (signal FPE).
30 Controlled by two env vars:
34 initialization of all malloced memory to NaN. If FOAM_SIGFPE
35 also set, this will cause usage of uninitialized scalars to trigger
41 \*---------------------------------------------------------------------------*/
46 #include "OSspecific.H"
49 #if defined(linux) || defined(linuxAMD64) || defined(linuxIA64) || defined(linuxARM7)
53 #if defined(LINUX) && defined(__GNUC__)
58 #include <malloc/malloc.h>
60 // these are defined by the mach-headers and would break compilation of Switch.H
66 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
71 /*---------------------------------------------------------------------------*\
72 Class sigFpe Declaration
73 \*---------------------------------------------------------------------------*/
79 //- Saved old signal trapping setting
80 static struct sigaction oldAction_;
85 static void *(*old_malloc_hook)(size_t, const void *);
87 //- nan malloc function. From malloc_hook manpage.
88 static void* my_malloc_hook(size_t size, const void *caller);
90 #elif defined (__APPLE__)
92 //- pointer to the original malloc that is overrided
93 static void *(*system_malloc_)(malloc_zone_t *zone, size_t size);
95 //- the overriding handler
96 static void* nan_malloc_(malloc_zone_t *zone, size_t size);
101 // Static data members
103 # if defined(LINUX_GNUC) || defined(__APPLE__)
105 //- Handler for caught signals
106 static void sigFpeHandler(int);
126 void set(const bool verbose);
130 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
132 } // End namespace Foam
134 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
138 // ************************************************************************* //