NIST Biometric Evaluation Framework
Software components for biometric technology evaluations
be_error_signal_manager.h
Go to the documentation of this file.
1/******************************************************************************
2 * This software was developed at the National Institute of Standards and
3 * Technology (NIST) by employees of the Federal Government in the course
4 * of their official duties. Pursuant to title 17 Section 105 of the
5 * United States Code, this software is not subject to copyright protection
6 * and is in the public domain. NIST assumes no responsibility whatsoever for
7 * its use by other parties, and makes no guarantees, expressed or implied,
8 * about its quality, reliability, or any other characteristic.
9 ******************************************************************************/
10#ifndef __BE_ERROR_SIGNAL_MANAGER_H__
11#define __BE_ERROR_SIGNAL_MANAGER_H__
12
13#include <csetjmp>
14#include <csignal>
15
16#include <be_error_exception.h>
17
18/*
19 * Macros that are used by applications to indicate the start and end of
20 * a signal handling block.
21 */
22#define BEGIN_SIGNAL_BLOCK(_sigmgr, _blockname) do { \
23 if (!(_sigmgr)->isEnabled()) \
24 break; \
25 (_sigmgr)->clearSigHandled(); \
26 (_sigmgr)->stop(); \
27 if (sigsetjmp( \
28 BiometricEvaluation::Error::SignalManager::_sigJumpBuf, 1) != 0) \
29 { \
30 (_sigmgr)->setSigHandled(); \
31 goto _blockname ## _end; \
32 } \
33 (_sigmgr)->start(); \
34} while (0)
35
36#define END_SIGNAL_BLOCK(_sigmgr, _blockname) do { \
37 if (!(_sigmgr)->isEnabled()) \
38 break; \
39 _blockname ## _end: \
40 (_sigmgr)->stop(); \
41} while (0);
42
43#define ABORT_SIGNAL_MANAGER(_sigmgr) do { \
44 if (!(_sigmgr)->isEnabled()) \
45 break; \
46 (_sigmgr)->stop(); \
47} while (0);
48
49namespace BiometricEvaluation {
50
51 namespace Error {
52
97
98 public:
99
109
124 const sigset_t signalSet);
125
139 const sigset_t signalSet);
140
145
151
158
170 void start();
171
178 void stop();
179
184
189
201 const bool enabled);
202
204 bool isEnabled() const;
205
210 static bool _canSigJump;
215 static sigjmp_buf _sigJumpBuf;
216
217 protected:
218
219 private:
221 bool _enabled{true};
222
226 sigset_t _signalSet;
227
231 bool _sigHandled{false};
232 };
233
234 /*
235 * Declaration of the signal handler, a function with C linkage
236 * that will handle all signals managed by this object,
237 * conditionally jumping to a jump block within the application
238 * process. This function is of no interest to applications,
239 * which should use the BEGIN_SIGNAL_BLOCK()/END_SIGNAL_BLOCK()
240 * macro pair to take advantage of signal handling.
241 */
242 extern "C" {
244 siginfo_t *info, void *uap);
245 }
246 }
247}
248#endif /* __BE_ERROR_SIGNAL_MANAGER_H__ */
A SignalManager object is used to handle signals that come from the operating system.
static sigjmp_buf _sigJumpBuf
The jump buffer used by the signal handler.
void setSignalSet(const sigset_t signalSet)
Set the signals this object will manage.
void start()
Start handling signals of the current signal set.
void clearSigHandled()
Clear the indication that a signal was handled.
void stop()
Stop handling signals of the current signal set.
SignalManager(const sigset_t signalSet)
Construct a new SignalManager object with the specified signal handling, no defaults.
bool sigHandled()
Indicate whether a signal was handled.
bool isEnabled() const
Check the enabled status of signal handling.
void setEnabled(const bool enabled)
Enable or disable signal handling.
void setSigHandled()
Set a flag to indicate a signal was handled.
SignalManager()
Construct a new SignalManager object with the default signal handling: SIGSEGV and SIGBUS.
static bool _canSigJump
Flag indicating can jump after handling a signal.
void clearSignalSet()
Clear all signal handling.
void setDefaultSignalSet()
Set the default signals this object will manage: SIGSEGV and SIGBUS.
void SignalManagerSighandler(int signo, siginfo_t *info, void *uap)
This software was developed at the National Institute of Standards and Technology (NIST) by employees...