1 /*++ 2 3 Copyright (c) Microsoft Corporation. All rights reserved. 4 5 _WdfVersionBuild_ 6 7 Module Name: 8 9 wdfcore.h 10 11 Abstract: 12 13 This is the main driver framework. 14 15 Environment: 16 17 kernel mode only 18 19 Revision History: 20 21 --*/ 22 23 // 24 // NOTE: This header is generated by stubwork. Please make any 25 // modifications to the corresponding template files 26 // (.x or .y) and use stubwork to regenerate the header 27 // 28 29 #ifndef _WDFCORE_H_ 30 #define _WDFCORE_H_ 31 32 #ifndef WDF_EXTERN_C 33 #ifdef __cplusplus 34 #define WDF_EXTERN_C extern "C" 35 #define WDF_EXTERN_C_START extern "C" { 36 #define WDF_EXTERN_C_END } 37 #else 38 #define WDF_EXTERN_C 39 #define WDF_EXTERN_C_START 40 #define WDF_EXTERN_C_END 41 #endif 42 #endif 43 44 WDF_EXTERN_C_START 45 46 47 48 #if (NTDDI_VERSION >= NTDDI_WIN2K) 49 50 51 52 // 53 // Time conversion related macros 54 // 55 // to to to 56 // us ms sec 57 #define WDF_TIMEOUT_TO_SEC ((LONGLONG) 1 * 10 * 1000 * 1000) 58 #define WDF_TIMEOUT_TO_MS ((LONGLONG) 1 * 10 * 1000) 59 #define WDF_TIMEOUT_TO_US ((LONGLONG) 1 * 10) 60 FORCEINLINE 61 LONGLONG 62 WDF_REL_TIMEOUT_IN_SEC( 63 _In_ ULONGLONG Time 64 ) 65 { 66 return Time * -1 * WDF_TIMEOUT_TO_SEC; 67 } 68 69 FORCEINLINE 70 LONGLONG 71 WDF_ABS_TIMEOUT_IN_SEC( 72 _In_ ULONGLONG Time 73 ) 74 { 75 return Time * 1 * WDF_TIMEOUT_TO_SEC; 76 } 77 78 FORCEINLINE 79 LONGLONG 80 WDF_REL_TIMEOUT_IN_MS( 81 _In_ ULONGLONG Time 82 ) 83 { 84 return Time * -1 * WDF_TIMEOUT_TO_MS; 85 } 86 87 FORCEINLINE 88 LONGLONG 89 WDF_ABS_TIMEOUT_IN_MS( 90 _In_ ULONGLONG Time 91 ) 92 { 93 return Time * 1 * WDF_TIMEOUT_TO_MS; 94 } 95 96 FORCEINLINE 97 LONGLONG 98 WDF_REL_TIMEOUT_IN_US( 99 _In_ ULONGLONG Time 100 ) 101 { 102 return Time * -1 * WDF_TIMEOUT_TO_US; 103 } 104 105 FORCEINLINE 106 LONGLONG 107 WDF_ABS_TIMEOUT_IN_US( 108 _In_ ULONGLONG Time 109 ) 110 { 111 return Time * 1 * WDF_TIMEOUT_TO_US; 112 } 113 114 // 115 // Rounding functions 116 // 117 FORCEINLINE 118 size_t 119 WDF_ALIGN_SIZE_DOWN( 120 _In_ size_t Length, 121 _In_ size_t AlignTo 122 ) 123 { 124 return Length & ~(AlignTo - 1); 125 } 126 127 FORCEINLINE 128 size_t 129 WDF_ALIGN_SIZE_UP( 130 _In_ size_t Length, 131 _In_ size_t AlignTo 132 ) 133 { 134 return WDF_ALIGN_SIZE_DOWN(Length + AlignTo - 1, AlignTo); 135 } 136 137 138 // 139 // Pointer math 140 // 141 #define WDF_PTR_ADD_OFFSET_TYPE(_ptr, _offset, _type) \ 142 ((_type) (((PUCHAR) (_ptr)) + (_offset))) 143 144 #define WDF_PTR_ADD_OFFSET(_ptr, _offset) \ 145 WDF_PTR_ADD_OFFSET_TYPE(_ptr, _offset, PVOID) 146 147 #define WDF_PTR_GET_OFFSET(_base, _addr) \ 148 (size_t) (((PUCHAR) _addr) - ((PUCHAR) _base)) 149 150 #if (OSVER(NTDDI_VERSION) == NTDDI_WIN2K) 151 // 152 // These definitions are necessary for building under a Win2K Environment. 153 // 154 #ifndef DECLARE_UNICODE_STRING_SIZE 155 #define DECLARE_UNICODE_STRING_SIZE(_var, _size) \ 156 WCHAR _var ## _buffer[_size]; \ 157 UNICODE_STRING _var = { 0, _size * sizeof(WCHAR) , _var ## _buffer } 158 #endif 159 160 #undef DECLARE_CONST_UNICODE_STRING 161 #define DECLARE_CONST_UNICODE_STRING(_variablename, _string) \ 162 const WCHAR _variablename ## _buffer[] = _string; \ 163 __pragma(warning(suppress:4204)) __pragma(warning(suppress:4221)) \ 164 const UNICODE_STRING _variablename = { sizeof(_string) - sizeof(WCHAR), sizeof(_string), (PWSTR) _variablename ## _buffer } 165 166 #endif // (OSVER(NTDDI_VERSION) == NTDDI_WIN2K) 167 168 169 170 #endif // (NTDDI_VERSION >= NTDDI_WIN2K) 171 172 173 WDF_EXTERN_C_END 174 175 #endif // _WDFCORE_H_ 176 177