OpenFOAM logo
Open Source CFD Toolkit

sigFpe.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2005 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     sigFpe
00027 
00028 Description
00029     Sets up trapping for floating point exceptions (sigfpe).
00030 
00031     Controlled by two env vars:
00032     FOAM_SIGFPE : exception trapping
00033     FOAM_SETNAN : initialization of all malloced memory to NaN. If also
00034                   FOAM_SIGFPE set this will cause usage of uninitialized scalars
00035                   to trigger an abort.
00036 
00037 SourceFiles
00038     sigFpe.C
00039 
00040 \*---------------------------------------------------------------------------*/
00041 
00042 #ifndef sigFpe_H
00043 #define sigFpe_H
00044 
00045 #include "OSspecific.H"
00046 #include <signal.h>
00047 
00048 #if defined(linux) || defined(linuxAMD64) || defined(linuxIA64)
00049 #    define LINUX
00050 #endif
00051 
00052 #if defined(LINUX) && defined(__GNUC__)
00053 #    define LINUX_GNUC
00054 #endif
00055 
00056 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00057 
00058 namespace Foam
00059 {
00060 
00061 /*---------------------------------------------------------------------------*\
00062                            Class sigFpe Declaration
00063 \*---------------------------------------------------------------------------*/
00064 
00065 class sigFpe
00066 {
00067     // Private data
00068 
00069         //- Saved old signal trapping setting
00070         static struct sigaction oldAction_;
00071 
00072 #       ifdef LINUX
00073 
00074             //- Saved old malloc
00075             static void *(*old_malloc_hook)(size_t, const void *);
00076 
00077             //- nan malloc function. From malloc_hook manpage.
00078             static void* my_malloc_hook(size_t size, const void *caller);
00079 
00080 #       endif
00081 
00082 
00083     // Static data members
00084 
00085 #   ifdef LINUX_GNUC
00086 
00087         //- Handler for caught signals
00088         static void sigFpeHandler(int);
00089 
00090 #   endif
00091 
00092 
00093 public:
00094 
00095 
00096     // Constructors
00097 
00098         sigFpe();
00099 
00100 
00101     // Destructor
00102 
00103         ~sigFpe();
00104 
00105 
00106     // Member functions
00107 
00108         void set();
00109 };
00110 
00111 
00112 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00113 
00114 } // End namespace Foam
00115 
00116 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00117 
00118 #endif
00119 
00120 // ************************************************************************* //
For further information go to www.openfoam.org