PStack  2.0
Stack trace printer for MSVC and GCC binaries
platform.hpp
Go to the documentation of this file.
1 // ===-- include/psystem/framework/platform.hpp ----------- -*- C++ -*- --=== //
2 // Copyright (c) 2014 Matt Bisson. All rights reserved.
3 
38 #pragma once
39 #ifndef PSYSTEM_FRAMEWORK_PLATFORM_HPP
40 #define PSYSTEM_FRAMEWORK_PLATFORM_HPP
41 
42 // Ignore MSVC-specific keywords on non-MSVC compilers
43 #if !defined(_MSC_VER) && !defined(__CYGWIN__)
44 # define __stdcall
45 #endif
46 
47 #include <Windows.h>
48 #include <cstddef>
49 #include <cstdint>
50 
51 // We need to include these for the @c ASSERT macro. This may cause
52 // complications with inclusions in the release builds...
53 #ifdef _DEBUG
54 # include <cstdlib>
55 # include <iostream>
56 #endif
57 
68 #if defined(_MSC_VER) && (_MSV_VER <= 1800)
69 # define _ALLOW_KEYWORD_MACROS
70 # define constexpr const
71 # define noexcept throw()
72 #endif
73 
84 
92 #if defined(__GNUC__) || defined(__INTEL_COMPILER)
93 # define LIKELY(cond) __builtin_expect(!!(cond), 1)
94 #else
95 # define LIKELY(cond) (cond)
96 #endif
97 
102 #if defined(__GNUC__) || defined(__INTEL_COMPILER)
103 # define UNLIKELY(cond) __builtin_expect(!!(cond), 0)
104 #else
105 # define UNLIKELY(cond) (cond)
106 #endif
107 
117 #ifdef _DEBUG
118 # define ASSERT(cond) \
119  { \
120  if (UNLIKELY( !(cond) )) \
121  { \
122  std::cerr \
123  << "Assertion failed (" #cond ") at " \
124  << __FILE__ << ":" << __LINE__ \
125  << " (" << __FUNCTION__ << ")" \
126  << std::endl; \
127  abort(); \
128  } \
129  }
130 #else // !DEBUG
131 # define ASSERT(cond)
132 #endif // DEBUG
133 
144 #ifdef _DEBUG
145 # define ASSERT_USING_VAR(var, cond) ASSERT(cond)
146 #else // !DEBUG
147 # define ASSERT_USING_VAR(var, cond) ((void)(var))
148 #endif // DEBUG
149 
153 
155 #ifdef _PRIVATE_BUILD
156 # define PRERELEASE_FLAGS VS_FF_PRERELEASE
157 #else
158 # define PRERELEASE_FLAGS 0
159 #endif
160 
162 #ifdef _DEBUG
163 # define FILE_FLAGS PRERELEASE_FLAGS | VS_FF_DEBUG
164 #else
165 # define FILE_FLAGS PRERELEASE_FLAGS
166 #endif
167 
179 #define STRINGIZE_SINGLE_VERSION_ID(id) #id
180 
188 #define MAKE_PRODUCT_VERSION_ID(maj,min,patch) \
189  STRINGIZE_SINGLE_VERSION_ID(maj) "." \
190  STRINGIZE_SINGLE_VERSION_ID(min) "." \
191  STRINGIZE_SINGLE_VERSION_ID(patch)
192 
201 #define MAKE_FILE_VERSION_ID(maj,min,patch,bld) \
202  STRINGIZE_SINGLE_VERSION_ID(maj) "." \
203  STRINGIZE_SINGLE_VERSION_ID(min) "." \
204  STRINGIZE_SINGLE_VERSION_ID(patch) " (build " \
205  STRINGIZE_SINGLE_VERSION_ID(bld) ")"
206 
208 
209 // We will inlcude this from all sources -- including the resource-file
210 // compiler -- so let's make sure it compiles.
211 #ifndef RC_INVOKED
212 
213 namespace psystem
214 {
217  typedef DWORD error_t;
218 
220 #ifndef NO_PTRDIFF_TYPE
221  typedef std::uintptr_t address_t;
222 #else // NO_PTRDIFF_TYPE
223  typedef void* address_t;
224 #endif
225 
227 #ifndef NO_PTRDIFF_TYPE
228  typedef std::ptrdiff_t integral_address_t;
229 #else // NO_PTRDIFF_TYPE
230 # if defined(_M_X64) || defined(__x86_64)
231  typedef uint64_t integral_address_t;
232 # else
233  typedef uint32_t integral_address_t;
234 # endif
235 #endif
236 
237  // If ever we move onto a non-64 bit system, integral_address_t will have to
238  // be adjusted...
239  static_assert(
240  sizeof(address_t) == sizeof(integral_address_t),
241  "Pointer size does not match size for integral_address_t");
242 
244  typedef DWORD process_id_t;
245 
247  typedef DWORD thread_id_t;
248 } // namespace psystem
249 
250 #include <string>
251 
252 namespace psystem
253 {
263 #ifdef UNICODE
264  typedef std::wstring tstring;
265 #else
266  typedef std::string tstring;
267 #endif
268 } // namespace psystem
269 
270 #endif // RC_INVOKED
271 
272 #endif // PSYSTEM_FRAMEWORK_PLATFORM_HPP
std::string tstring
A std::string implementation based on the UNICODE macro.
Definition: platform.hpp:266
std::uintptr_t address_t
Container type for a memory address.
Definition: platform.hpp:221
DWORD process_id_t
Data-type that stores a process ID (PID).
Definition: platform.hpp:241
Contains the process examination "system" and basic frameworks.
Definition: pstack_event_handler.hpp:28
std::ptrdiff_t integral_address_t
A memory address as an integer type (platform specific).
Definition: platform.hpp:228
DWORD error_t
Container type for system error codes.
Definition: platform.hpp:217
DWORD thread_id_t
Data-type that stores a thread ID (TID).
Definition: platform.hpp:247