All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sigFpe.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::sigFpe
26 
27 Description
28  Set up trapping for floating point exceptions (signal FPE).
29 
30  Controlled by two env vars:
31  - \par FOAM_SIGFPE
32  Exception trapping
33  - \par FOAM_SETNAN
34  Initialisation of all malloced memory to NaN. If FOAM_SIGFPE
35  also set, this will cause usage of uninitialised scalars to trigger
36  an abort.
37 
38 SourceFiles
39  sigFpe.C
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef sigFpe_H
44 #define sigFpe_H
45 
46 #include <signal.h>
47 
48 #if defined(linux) || defined(linux64) || \
49  defined(linuxARM7) || defined(linuxPPC64) || defined(linuxPPC64le)
50  #define LINUX
51 #endif
52 
53 #if defined(LINUX) && defined(__GNUC__)
54  #define LINUX_GNUC
55 #endif
56 
57 #include "UList.H"
58 
59 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60 
61 namespace Foam
62 {
63 
64 /*---------------------------------------------------------------------------*\
65  Class sigFpe Declaration
66 \*---------------------------------------------------------------------------*/
67 
68 class sigFpe
69 {
70  // Private Data
71 
72  //- Saved old signal trapping setting
73  static struct sigaction oldAction_;
74 
75 
76  // Static Data Members
77 
78  #ifdef LINUX_GNUC
79  //- Handler for caught signals
80  static void sigHandler(int);
81  #endif
82 
83 
84 public:
85 
86 
87  // Constructors
88 
89  //- Construct null
90  sigFpe();
91 
92 
93  //- Destructor
94  ~sigFpe();
95 
96 
97  // Member Functions
98 
99  //- Activate SIGFPE signal handler when FOAM_SIGFPE is %set
100  // Fill memory with NaN when FOAM_SETNAN is %set
101  void set(const bool verbose);
102 
103  //- Flag to indicate mallocNan is enabled
104  static bool mallocNanActive_;
105 
106  #ifdef LINUX
107  //- Malloc function which initialises to NaN
108  static void* mallocNan(size_t size);
109  #endif
110 
111  //- Fill block of data with NaN
112  static void fillNan(UList<scalar>&);
113 };
114 
115 
116 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
117 
118 } // End namespace Foam
119 
120 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
121 
122 #endif
123 
124 // ************************************************************************* //
~sigFpe()
Destructor.
Definition: sigFpe.C:119
Set up trapping for floating point exceptions (signal FPE).
Definition: sigFpe.H:67
static void fillNan(UList< scalar > &)
Fill block of data with NaN.
Definition: sigFpe.C:46
static bool mallocNanActive_
Flag to indicate mallocNan is enabled.
Definition: sigFpe.H:103
sigFpe()
Construct null.
Definition: sigFpe.C:111
Namespace for OpenFOAM.