HyperPlatform Programmer's Reference
common.h
Go to the documentation of this file.
1 // Copyright (c) 2015-2018, Satoshi Tanda. All rights reserved.
2 // Use of this source code is governed by a MIT-style license that can be
3 // found in the LICENSE file.
4 
7 
34 
35 #ifndef HYPERPLATFORM_COMMON_H_
36 #define HYPERPLATFORM_COMMON_H_
37 
38 #include <fltKernel.h>
39 
40 // C30030: Calling a memory allocating function and passing a parameter that
41 // indicates executable memory
42 //
43 // Disable C30030 since POOL_NX_OPTIN + ExInitializeDriverRuntime is in place.
44 // This warning is false positive and can be seen when Target Platform Version
45 // equals to 10.0.14393.0.
46 #pragma prefast(disable : 30030)
47 
49 //
50 // macro utilities
51 //
52 
54 #if !defined(HYPERPLATFORM_COMMON_DBG_BREAK)
55 #define HYPERPLATFORM_COMMON_DBG_BREAK() \
56  if (KD_DEBUGGER_NOT_PRESENT) { \
57  } else { \
58  __debugbreak(); \
59  } \
60  reinterpret_cast<void*>(0)
61 #endif
62 
68 #if !defined(HYPERPLATFORM_COMMON_BUG_CHECK)
69 #define HYPERPLATFORM_COMMON_BUG_CHECK(hp_bug_check_code, param1, param2, \
70  param3) \
71  HYPERPLATFORM_COMMON_DBG_BREAK(); \
72  const HyperPlatformBugCheck code = (hp_bug_check_code); \
73  __pragma(warning(push)) \
74  __pragma(warning(disable: __WARNING_USE_OTHER_FUNCTION)) \
75  KeBugCheckEx(MANUALLY_INITIATED_CRASH, static_cast<ULONG>(code), (param1), \
76  (param2), (param3)) \
77  __pragma(warning(pop))
78 #endif
79 
81 //
82 // constants and macros
83 //
84 
90 #define HYPERPLATFORM_PERFORMANCE_ENABLE_PERFCOUNTER 1
91 
93 static const ULONG kHyperPlatformCommonPoolTag = 'PpyH';
94 
96 //
97 // types
98 //
99 
101 enum class HyperPlatformBugCheck : ULONG {
102  kUnspecified,
109 };
110 
112 //
113 // prototypes
114 //
115 
117 //
118 // variables
119 //
120 
122 //
123 // implementations
124 //
125 
128 constexpr bool IsX64() {
129 #if defined(_AMD64_)
130  return true;
131 #else
132  return false;
133 #endif
134 }
135 
138 constexpr bool IsReleaseBuild() {
139 #if defined(DBG)
140  return false;
141 #else
142  return true;
143 #endif
144 }
145 
146 #endif // HYPERPLATFORM_COMMON_H_
A triple fault VM-exit occurred.
static const ULONG kHyperPlatformCommonPoolTag
A pool tag.
Definition: common.h:93
constexpr bool IsX64()
Checks if a system is x64.
Definition: common.h:128
EPT misconfiguration VM-exit occurred.
An unspecified bug occurred.
constexpr bool IsReleaseBuild()
Checks if the project is compiled as Release.
Definition: common.h:138
HyperPlatformBugCheck
BugCheck codes for HYPERPLATFORM_COMMON_BUG_CHECK().
Definition: common.h:101
All pre-allocated entries are used.
An unexpected VM-exit occurred.