OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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-2009 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     Foam::sigFpe
00027 
00028 Description
00029     Set up trapping for floating point exceptions (signal FPE).
00030 
00031     Controlled by two env vars:
00032     @param FOAM_SIGFPE \n
00033         exception trapping
00034     @param FOAM_SETNAN \n
00035         initialization of all malloced memory to NaN. If FOAM_SIGFPE
00036         also set, this will cause usage of uninitialized scalars to trigger
00037         an abort.
00038 
00039 SourceFiles
00040     sigFpe.C
00041 
00042 \*---------------------------------------------------------------------------*/
00043 
00044 #ifndef sigFpe_H
00045 #define sigFpe_H
00046 
00047 #include "OSspecific.H"
00048 #include <signal.h>
00049 
00050 #if defined(linux) || defined(linuxAMD64) || defined(linuxIA64)
00051 #    define LINUX
00052 #endif
00053 
00054 #if defined(LINUX) && defined(__GNUC__)
00055 #    define LINUX_GNUC
00056 #endif
00057 
00058 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00059 
00060 namespace Foam
00061 {
00062 
00063 /*---------------------------------------------------------------------------*\
00064                            Class sigFpe Declaration
00065 \*---------------------------------------------------------------------------*/
00066 
00067 class sigFpe
00068 {
00069     // Private data
00070 
00071         //- Saved old signal trapping setting
00072         static struct sigaction oldAction_;
00073 
00074 #       ifdef LINUX
00075 
00076             //- Saved old malloc
00077             static void *(*old_malloc_hook)(size_t, const void *);
00078 
00079             //- nan malloc function. From malloc_hook manpage.
00080             static void* my_malloc_hook(size_t size, const void *caller);
00081 
00082 #       endif
00083 
00084 
00085     // Static data members
00086 
00087 #   ifdef LINUX_GNUC
00088 
00089         //- Handler for caught signals
00090         static void sigFpeHandler(int);
00091 
00092 #   endif
00093 
00094 
00095 public:
00096 
00097 
00098     // Constructors
00099 
00100         sigFpe();
00101 
00102 
00103     // Destructor
00104 
00105         ~sigFpe();
00106 
00107 
00108     // Member functions
00109 
00110         void set(const bool verbose);
00111 };
00112 
00113 
00114 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00115 
00116 } // End namespace Foam
00117 
00118 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00119 
00120 #endif
00121 
00122 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd