Security Scol plugin
trap.h
Go to the documentation of this file.
1// trap.h - written and placed in public domain by Jeffrey Walton.
2
17
18#ifndef CRYPTOPP_TRAP_H
19#define CRYPTOPP_TRAP_H
20
21#include "config.h"
22
23#if defined(CRYPTOPP_DEBUG)
24# include <iostream>
25# include <sstream>
26# if defined(UNIX_SIGNALS_AVAILABLE)
27# include "ossig.h"
28# elif defined(CRYPTOPP_WIN32_AVAILABLE) && !defined(__CYGWIN__)
29 extern "C" __declspec(dllimport) void __stdcall DebugBreak();
30 extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
31# endif
32#endif // CRYPTOPP_DEBUG
33
34// ************** run-time assertion ***************
35
36#if defined(CRYPTOPP_DOXYGEN_PROCESSING)
68# define CRYPTOPP_ASSERT(exp) { ... }
69#endif
70
71#if defined(CRYPTOPP_DEBUG)
72# if defined(UNIX_SIGNALS_AVAILABLE) || defined(__CYGWIN__)
73# define CRYPTOPP_ASSERT(exp) { \
74 if (!(exp)) { \
75 std::ostringstream oss; \
76 oss << "Assertion failed: " << __FILE__ << "(" \
77 << __LINE__ << "): " << __func__ \
78 << std::endl; \
79 std::cout << std::flush; \
80 std::cerr << oss.str(); \
81 raise(SIGTRAP); \
82 } \
83 }
84# elif CRYPTOPP_DEBUG && defined(CRYPTOPP_WIN32_AVAILABLE)
85# define CRYPTOPP_ASSERT(exp) { \
86 if (!(exp)) { \
87 std::ostringstream oss; \
88 oss << "Assertion failed: " << __FILE__ << "(" \
89 << __LINE__ << "): " << __FUNCTION__ \
90 << std::endl; \
91 std::cout << std::flush; \
92 std::cerr << oss.str(); \
93 if (IsDebuggerPresent()) {DebugBreak();} \
94 } \
95 }
96# endif // Unix or Windows
97#endif // CRYPTOPP_DEBUG
98
99// Remove CRYPTOPP_ASSERT in non-debug builds.
100#ifndef CRYPTOPP_ASSERT
101# define CRYPTOPP_ASSERT(exp) (void)0
102#endif
103
104NAMESPACE_BEGIN(CryptoPP)
105
106// ************** SIGTRAP handler ***************
107
108#if (CRYPTOPP_DEBUG && defined(UNIX_SIGNALS_AVAILABLE)) || defined(CRYPTOPP_DOXYGEN_PROCESSING)
152
153#if defined(CRYPTOPP_DOXYGEN_PROCESSING)
154class DebugTrapHandler : public SignalHandler<SIGTRAP, false> { };
155#else
156typedef SignalHandler<SIGTRAP, false> DebugTrapHandler;
157#endif
158
159#endif // Linux, Unix and Documentation
160
161NAMESPACE_END
162
163#endif // CRYPTOPP_TRAP_H
Library configuration file.
Utility class for trapping OS signals.