mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
COMP: protect headers against multiple inclusion in POSIX/signals
STYLE: report when SIGFPE handling is unsupported - move OSspecific.H include from signal headers to argList where it is more obvious
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 1991-2011 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -23,9 +23,8 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "error.H"
|
||||
#include "sigFpe.H"
|
||||
|
||||
#include "error.H"
|
||||
#include "JobInfo.H"
|
||||
#include "OSspecific.H"
|
||||
#include "IOstreams.H"
|
||||
@ -52,51 +51,42 @@ License
|
||||
struct sigaction Foam::sigFpe::oldAction_;
|
||||
|
||||
|
||||
#if defined(LINUX)
|
||||
#ifdef LINUX
|
||||
|
||||
void *(*Foam::sigFpe::old_malloc_hook)(size_t, const void *) = NULL;
|
||||
void *(*Foam::sigFpe::oldMallocHook_)(size_t, const void *) = NULL;
|
||||
|
||||
void* Foam::sigFpe::my_malloc_hook(size_t size, const void *caller)
|
||||
void* Foam::sigFpe::nanMallocHook_(size_t size, const void *caller)
|
||||
{
|
||||
void *result;
|
||||
|
||||
// Restore all old hooks
|
||||
__malloc_hook = old_malloc_hook;
|
||||
__malloc_hook = oldMallocHook_;
|
||||
|
||||
// Call recursively
|
||||
result = malloc (size);
|
||||
result = malloc(size);
|
||||
|
||||
// initialize to signalling nan
|
||||
// initialize to signalling NaN
|
||||
# ifdef WM_SP
|
||||
|
||||
const uint32_t sNAN = 0x7ff7fffflu;
|
||||
|
||||
int nScalars = size / sizeof(scalar);
|
||||
|
||||
uint32_t* dPtr = reinterpret_cast<uint32_t*>(result);
|
||||
|
||||
for (int i = 0; i < nScalars; i++)
|
||||
{
|
||||
*dPtr++ = sNAN;
|
||||
}
|
||||
|
||||
# else
|
||||
|
||||
const uint64_t sNAN = 0x7ff7ffffffffffffllu;
|
||||
|
||||
int nScalars = size/sizeof(scalar);
|
||||
|
||||
uint64_t* dPtr = reinterpret_cast<uint64_t*>(result);
|
||||
|
||||
for (int i = 0; i < nScalars; i++)
|
||||
# endif
|
||||
|
||||
const size_t nScalars = size/sizeof(scalar);
|
||||
for (size_t i = 0; i < nScalars; ++i)
|
||||
{
|
||||
*dPtr++ = sNAN;
|
||||
}
|
||||
|
||||
# endif
|
||||
|
||||
// Restore our own hooks
|
||||
__malloc_hook = my_malloc_hook;
|
||||
__malloc_hook = nanMallocHook_;
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -106,14 +96,14 @@ void* Foam::sigFpe::my_malloc_hook(size_t size, const void *caller)
|
||||
|
||||
#ifdef LINUX_GNUC
|
||||
|
||||
void Foam::sigFpe::sigFpeHandler(int)
|
||||
void Foam::sigFpe::sigHandler(int)
|
||||
{
|
||||
// Reset old handling
|
||||
if (sigaction(SIGFPE, &oldAction_, NULL) < 0)
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"Foam::sigSegv::sigFpeHandler()"
|
||||
"Foam::sigSegv::sigHandler()"
|
||||
) << "Cannot reset SIGFPE trapping"
|
||||
<< abort(FatalError);
|
||||
}
|
||||
@ -166,7 +156,7 @@ Foam::sigFpe::~sigFpe()
|
||||
// Reset to standard malloc
|
||||
if (oldAction_.sa_handler)
|
||||
{
|
||||
__malloc_hook = old_malloc_hook;
|
||||
__malloc_hook = oldMallocHook_;
|
||||
}
|
||||
|
||||
# endif
|
||||
@ -189,13 +179,10 @@ void Foam::sigFpe::set(const bool verbose)
|
||||
|
||||
if (env("FOAM_SIGFPE"))
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
Info<< "SigFpe : Enabling floating point exception trapping"
|
||||
<< " (FOAM_SIGFPE)." << endl;
|
||||
}
|
||||
bool supported = false;
|
||||
|
||||
# ifdef LINUX_GNUC
|
||||
supported = true;
|
||||
|
||||
feenableexcept
|
||||
(
|
||||
@ -205,7 +192,7 @@ void Foam::sigFpe::set(const bool verbose)
|
||||
);
|
||||
|
||||
struct sigaction newAction;
|
||||
newAction.sa_handler = sigFpeHandler;
|
||||
newAction.sa_handler = sigHandler;
|
||||
newAction.sa_flags = SA_NODEFER;
|
||||
sigemptyset(&newAction.sa_mask);
|
||||
if (sigaction(SIGFPE, &newAction, &oldAction_) < 0)
|
||||
@ -219,6 +206,7 @@ void Foam::sigFpe::set(const bool verbose)
|
||||
|
||||
|
||||
# elif defined(sgiN32) || defined(sgiN32Gcc)
|
||||
supported = true;
|
||||
|
||||
sigfpe_[_DIVZERO].abort=1;
|
||||
sigfpe_[_OVERFL].abort=1;
|
||||
@ -240,23 +228,50 @@ void Foam::sigFpe::set(const bool verbose)
|
||||
);
|
||||
|
||||
# endif
|
||||
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
if (supported)
|
||||
{
|
||||
Info<< "sigFpe : Enabling floating point exception trapping"
|
||||
<< " (FOAM_SIGFPE)." << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< "sigFpe : Floating point exception trapping"
|
||||
<< " - not supported on this platform" << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (env("FOAM_SETNAN"))
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
Info<< "SetNaN : Initialising allocated memory to NaN"
|
||||
<< " (FOAM_SETNAN)." << endl;
|
||||
}
|
||||
bool supported = false;
|
||||
|
||||
# ifdef LINUX_GNUC
|
||||
supported = true;
|
||||
|
||||
// Set our malloc
|
||||
__malloc_hook = Foam::sigFpe::my_malloc_hook;
|
||||
__malloc_hook = Foam::sigFpe::nanMallocHook_;
|
||||
|
||||
# endif
|
||||
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
if (supported)
|
||||
{
|
||||
Info<< "SetNaN : Initialising allocated memory to NaN"
|
||||
<< " (FOAM_SETNAN)." << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< "SetNaN : Initialise allocated memory to NaN"
|
||||
<< " - not supported on this platform" << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 1991-2011 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -43,7 +43,6 @@ SourceFiles
|
||||
#ifndef sigFpe_H
|
||||
#define sigFpe_H
|
||||
|
||||
#include "OSspecific.H"
|
||||
#include <signal.h>
|
||||
|
||||
#if defined(linux) || defined(linuxAMD64) || defined(linuxIA64)
|
||||
@ -73,10 +72,10 @@ class sigFpe
|
||||
# ifdef LINUX
|
||||
|
||||
//- Saved old malloc
|
||||
static void *(*old_malloc_hook)(size_t, const void *);
|
||||
static void *(*oldMallocHook_)(size_t, const void *);
|
||||
|
||||
//- nan malloc function. From malloc_hook manpage.
|
||||
static void* my_malloc_hook(size_t size, const void *caller);
|
||||
//- NaN malloc function. From malloc_hook manpage.
|
||||
static void* nanMallocHook_(size_t size, const void *caller);
|
||||
|
||||
# endif
|
||||
|
||||
@ -86,7 +85,7 @@ class sigFpe
|
||||
# ifdef LINUX_GNUC
|
||||
|
||||
//- Handler for caught signals
|
||||
static void sigFpeHandler(int);
|
||||
static void sigHandler(int);
|
||||
|
||||
# endif
|
||||
|
||||
@ -96,6 +95,7 @@ public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
sigFpe();
|
||||
|
||||
|
||||
@ -105,6 +105,8 @@ public:
|
||||
|
||||
// Member functions
|
||||
|
||||
//- Activate SIGFPE signal handler when FOAM_SIGFPE is %set
|
||||
// Fill memory with NaN when FOAM_SETNAN is %set
|
||||
void set(const bool verbose);
|
||||
};
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 1991-2011 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -23,8 +23,8 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "error.H"
|
||||
#include "sigInt.H"
|
||||
#include "error.H"
|
||||
#include "JobInfo.H"
|
||||
#include "IOstreams.H"
|
||||
|
||||
@ -32,16 +32,17 @@ License
|
||||
|
||||
struct sigaction Foam::sigInt::oldAction_;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::sigInt::sigIntHandler(int)
|
||||
void Foam::sigInt::sigHandler(int)
|
||||
{
|
||||
// Reset old handling
|
||||
if (sigaction(SIGINT, &oldAction_, NULL) < 0)
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"Foam::sigInt::sigIntHandler()"
|
||||
"Foam::sigInt::sigHandler()"
|
||||
) << "Cannot reset SIGINT trapping"
|
||||
<< abort(FatalError);
|
||||
}
|
||||
@ -80,7 +81,7 @@ Foam::sigInt::~sigInt()
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::sigInt::set(const bool verbose)
|
||||
void Foam::sigInt::set(const bool)
|
||||
{
|
||||
if (oldAction_.sa_handler)
|
||||
{
|
||||
@ -92,7 +93,7 @@ void Foam::sigInt::set(const bool verbose)
|
||||
}
|
||||
|
||||
struct sigaction newAction;
|
||||
newAction.sa_handler = sigIntHandler;
|
||||
newAction.sa_handler = sigHandler;
|
||||
newAction.sa_flags = SA_NODEFER;
|
||||
sigemptyset(&newAction.sa_mask);
|
||||
if (sigaction(SIGINT, &newAction, &oldAction_) < 0)
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 1991-2011 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -38,7 +38,9 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "OSspecific.H"
|
||||
#ifndef sigInt_H
|
||||
#define sigInt_H
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
@ -60,13 +62,14 @@ class sigInt
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
static void sigIntHandler(int);
|
||||
static void sigHandler(int);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
sigInt();
|
||||
|
||||
|
||||
@ -76,6 +79,7 @@ public:
|
||||
|
||||
// Member functions
|
||||
|
||||
//- Activate SIGINT signal handler
|
||||
void set(const bool verbose);
|
||||
};
|
||||
|
||||
@ -84,4 +88,8 @@ public:
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 1991-2011 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -23,8 +23,8 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "error.H"
|
||||
#include "sigQuit.H"
|
||||
#include "error.H"
|
||||
#include "JobInfo.H"
|
||||
#include "IOstreams.H"
|
||||
|
||||
@ -32,16 +32,17 @@ License
|
||||
|
||||
struct sigaction Foam::sigQuit::oldAction_;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::sigQuit::sigQuitHandler(int)
|
||||
void Foam::sigQuit::sigHandler(int)
|
||||
{
|
||||
// Reset old handling
|
||||
if (sigaction(SIGQUIT, &oldAction_, NULL) < 0)
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"Foam::sigQuit::sigQuitHandler()"
|
||||
"Foam::sigQuit::sigHandler()"
|
||||
) << "Cannot reset SIGQUIT trapping"
|
||||
<< abort(FatalError);
|
||||
}
|
||||
@ -94,7 +95,7 @@ void Foam::sigQuit::set(const bool verbose)
|
||||
}
|
||||
|
||||
struct sigaction newAction;
|
||||
newAction.sa_handler = sigQuitHandler;
|
||||
newAction.sa_handler = sigHandler;
|
||||
newAction.sa_flags = SA_NODEFER;
|
||||
sigemptyset(&newAction.sa_mask);
|
||||
if (sigaction(SIGQUIT, &newAction, &oldAction_) < 0)
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 1991-2011 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -38,7 +38,9 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "OSspecific.H"
|
||||
#ifndef sigQuit_H
|
||||
#define sigQuit_H
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
@ -60,13 +62,15 @@ class sigQuit
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
static void sigQuitHandler(int);
|
||||
//- Handler for caught signals
|
||||
static void sigHandler(int);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
sigQuit();
|
||||
|
||||
|
||||
@ -76,6 +80,7 @@ public:
|
||||
|
||||
// Member functions
|
||||
|
||||
//- Activate SIGQUIT signal handler
|
||||
void set(const bool verbose);
|
||||
};
|
||||
|
||||
@ -84,4 +89,8 @@ public:
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 1991-2011 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -23,8 +23,8 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "error.H"
|
||||
#include "sigSegv.H"
|
||||
#include "error.H"
|
||||
#include "JobInfo.H"
|
||||
#include "IOstreams.H"
|
||||
|
||||
@ -32,16 +32,17 @@ License
|
||||
|
||||
struct sigaction Foam::sigSegv::oldAction_;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::sigSegv::sigSegvHandler(int)
|
||||
void Foam::sigSegv::sigHandler(int)
|
||||
{
|
||||
// Reset old handling
|
||||
if (sigaction(SIGSEGV, &oldAction_, NULL) < 0)
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"Foam::sigSegv::sigSegvHandler()"
|
||||
"Foam::sigSegv::sigHandler()"
|
||||
) << "Cannot reset SIGSEGV trapping"
|
||||
<< abort(FatalError);
|
||||
}
|
||||
@ -82,7 +83,7 @@ Foam::sigSegv::~sigSegv()
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::sigSegv::set(const bool verbose)
|
||||
void Foam::sigSegv::set(const bool)
|
||||
{
|
||||
if (oldAction_.sa_handler)
|
||||
{
|
||||
@ -94,7 +95,7 @@ void Foam::sigSegv::set(const bool verbose)
|
||||
}
|
||||
|
||||
struct sigaction newAction;
|
||||
newAction.sa_handler = sigSegvHandler;
|
||||
newAction.sa_handler = sigHandler;
|
||||
newAction.sa_flags = SA_NODEFER;
|
||||
sigemptyset(&newAction.sa_mask);
|
||||
if (sigaction(SIGSEGV, &newAction, &oldAction_) < 0)
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 1991-2011 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -38,7 +38,9 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "OSspecific.H"
|
||||
#ifndef sigSegv_H
|
||||
#define sigSegv_H
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
@ -60,13 +62,15 @@ class sigSegv
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
static void sigSegvHandler(int);
|
||||
//- Handler for caught signals
|
||||
static void sigHandler(int);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
sigSegv();
|
||||
|
||||
|
||||
@ -76,6 +80,7 @@ public:
|
||||
|
||||
// Member functions
|
||||
|
||||
//- Activate SIGSEGV signal handler
|
||||
void set(const bool verbose);
|
||||
};
|
||||
|
||||
@ -84,4 +89,8 @@ public:
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -83,6 +83,7 @@ SourceFiles
|
||||
#include "fileName.H"
|
||||
#include "parRun.H"
|
||||
#include "IStringStream.H"
|
||||
#include "OSspecific.H"
|
||||
|
||||
#include "sigFpe.H"
|
||||
#include "sigInt.H"
|
||||
|
||||
Reference in New Issue
Block a user