Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

351 lines
8.8 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Header Name:
  4. support.h
  5. Abstract:
  6. Internal support interfaces for the standard
  7. application verifier provider.
  8. Author:
  9. Silviu Calinoiu (SilviuC) 1-Mar-2001
  10. Revision History:
  11. --*/
  12. #ifndef _SUPPORT_H_
  13. #define _SUPPORT_H_
  14. #include "public.h"
  15. //
  16. // Internal verifier debug flags.
  17. //
  18. #define VRFP_DEBUG_GENERIC 0x00000100
  19. #define VRFP_DEBUG_LOCKS_VERIFIER 0x00000200
  20. #define VRFP_DEBUG_LOCKS_DUMP_TREE 0x00000400
  21. #define VRFP_DEBUG_LOCKS_INITIALIZE_DELETE 0x00000800
  22. #define VRFP_DEBUG_DIRTY_STACKS 0x00001000
  23. #define VRFP_DEBUG_EXCEPTIONS 0x00002000
  24. #define VRFP_DEBUG_LOADLIBRARY_CALLS 0x00004000
  25. #define VRFP_DEBUG_LOADLIBRARY_THUNKED 0x00008000
  26. #define VRFP_DEBUG_DLLMAIN_HOOKING 0x00010000
  27. #define VRFP_DEBUG_DLLMAIN_CALL 0x00020000
  28. #define VRFP_DEBUG_SHOW_VSPACE_OPERATIONS 0x00040000
  29. #define VRFP_DEBUG_SHOW_VSPACE_TRACKING 0x00080000
  30. //
  31. // Global data.
  32. //
  33. extern SYSTEM_BASIC_INFORMATION AVrfpSysBasicInfo;
  34. //
  35. // Useful macro
  36. //
  37. #define ROUND_UP(VALUE,ROUND) ((SIZE_T)(((SIZE_T)VALUE + \
  38. ((SIZE_T)ROUND - 1L)) & (~((SIZE_T)ROUND - 1L))))
  39. //
  40. // Exception logging support.
  41. //
  42. VOID
  43. AVrfpInitializeExceptionChecking (
  44. VOID
  45. );
  46. VOID
  47. AVrfpCleanupExceptionChecking (
  48. VOID
  49. );
  50. //
  51. // Write garbage in unused areas of stack.
  52. //
  53. VOID
  54. AVrfpDirtyThreadStack (
  55. );
  56. VOID
  57. AVrfpDllLoadCallback (
  58. PWSTR DllName,
  59. PVOID DllBase,
  60. SIZE_T DllSize,
  61. PVOID Reserved
  62. );
  63. VOID
  64. AVrfpDllUnloadCallback(
  65. PWSTR DllName,
  66. PVOID DllBase,
  67. SIZE_T DllSize,
  68. PVOID Reserved
  69. );
  70. VOID
  71. AVrfpNtdllHeapFreeCallback (
  72. PVOID AllocationBase,
  73. SIZE_T AllocationSize
  74. );
  75. NTSTATUS
  76. AVrfpDllInitialize (
  77. VOID
  78. );
  79. /////////////////////////////////////////////////////////////////////
  80. //////////////////////////////////////////////////// Per thread table
  81. /////////////////////////////////////////////////////////////////////
  82. NTSTATUS
  83. AVrfpThreadTableInitialize (
  84. VOID
  85. );
  86. VOID
  87. AVrfpThreadTableAddEntry (
  88. PAVRF_THREAD_ENTRY Entry
  89. );
  90. VOID
  91. AVrfpThreadTableRemoveEntry (
  92. PAVRF_THREAD_ENTRY Entry
  93. );
  94. PAVRF_THREAD_ENTRY
  95. AVrfpThreadTableSearchEntry (
  96. HANDLE Id
  97. );
  98. /////////////////////////////////////////////////////////////////////
  99. ///////////////////////////////////////////////////// Global counters
  100. /////////////////////////////////////////////////////////////////////
  101. #define BUMP_COUNTER(cnt) InterlockedIncrement((PLONG)(&(AVrfpCounter[(cnt)])))
  102. #define CNT_WAIT_SINGLE_CALLS 0
  103. #define CNT_WAIT_SINGLEEX_CALLS 1
  104. #define CNT_WAIT_MULTIPLE_CALLS 2
  105. #define CNT_WAIT_MULTIPLEEX_CALLS 3
  106. #define CNT_WAIT_WITH_TIMEOUT_CALLS 4
  107. #define CNT_WAIT_WITH_TIMEOUT_FAILS 5
  108. #define CNT_CREATE_EVENT_CALLS 6
  109. #define CNT_CREATE_EVENT_FAILS 7
  110. #define CNT_HEAP_ALLOC_CALLS 8
  111. #define CNT_HEAP_ALLOC_FAILS 9
  112. #define CNT_CLOSE_NULL_HANDLE_CALLS 10
  113. #define CNT_CLOSE_PSEUDO_HANDLE_CALLS 11
  114. #define CNT_HEAPS_CREATED 12
  115. #define CNT_HEAPS_DESTROYED 13
  116. #define CNT_VIRTUAL_ALLOC_CALLS 14
  117. #define CNT_VIRTUAL_ALLOC_FAILS 15
  118. #define CNT_MAP_VIEW_CALLS 16
  119. #define CNT_MAP_VIEW_FAILS 17
  120. #define CNT_OLE_ALLOC_CALLS 18
  121. #define CNT_OLE_ALLOC_FAILS 19
  122. #define CNT_RACE_DELAYS_INJECTED 20
  123. #define CNT_RACE_DELAYS_SKIPPED 21
  124. #define CNT_MAXIMUM_INDEX 64
  125. extern ULONG AVrfpCounter[CNT_MAXIMUM_INDEX];
  126. /////////////////////////////////////////////////////////////////////
  127. ////////////////////////////////////////////////////// Break triggers
  128. /////////////////////////////////////////////////////////////////////
  129. #define BRK_CLOSE_NULL_HANDLE 0
  130. #define BRK_CLOSE_PSEUDO_HANDLE 1
  131. #define BRK_CREATE_EVENT_FAIL 2
  132. #define BRK_HEAP_ALLOC_FAIL 3
  133. #define BRK_WAIT_WITH_TIMEOUT_FAIL 4
  134. #define BRK_VIRTUAL_ALLOC_FAIL 5
  135. #define BRK_MAP_VIEW_FAIL 6
  136. #define BRK_CREATE_FILE_FAIL 7
  137. #define BRK_CREATE_KEY_FAIL 8
  138. #define BRK_OLE_ALLOC_FAIL 9
  139. #define BRK_MAXIMUM_INDEX 64
  140. extern ULONG AVrfpBreak [BRK_MAXIMUM_INDEX];
  141. #define CHECK_BREAK(indx) \
  142. if (AVrfpBreak[(indx)] != 0) { \
  143. DbgPrint ("AVRF: conditional breakpoint %X hit.\n", (indx)); \
  144. DbgBreakPoint (); \
  145. }
  146. /////////////////////////////////////////////////////////////////////
  147. /////////////////////////////////////////////////// Verifier TLS slot
  148. /////////////////////////////////////////////////////////////////////
  149. typedef struct _AVRF_TLS_STRUCT {
  150. LONG CountOfOwnedCriticalSections;
  151. ULONG Flags;
  152. LIST_ENTRY ListEntry;
  153. HANDLE ThreadId;
  154. PVOID Teb;
  155. PRTL_CRITICAL_SECTION IgnoredIncorrectDeleteCS;
  156. } AVRF_TLS_STRUCT, *PAVRF_TLS_STRUCT;
  157. //
  158. // Possible values for TlsStruct->Flags.
  159. //
  160. #define VRFP_THREAD_FLAGS_LOADER_LOCK_OWNER 0x1
  161. NTSTATUS
  162. AVrfpAllocateVerifierTlsSlot (
  163. VOID
  164. );
  165. PAVRF_TLS_STRUCT
  166. AVrfpGetVerifierTlsValue(
  167. VOID
  168. );
  169. VOID
  170. AVrfpSetVerifierTlsValue(
  171. PAVRF_TLS_STRUCT Value
  172. );
  173. VOID
  174. AvrfpThreadAttach (
  175. VOID
  176. );
  177. VOID
  178. AvrfpThreadDetach (
  179. VOID
  180. );
  181. /////////////////////////////////////////////////////////////////////
  182. ////////////////////////////////////////////////////// DllMain checks
  183. /////////////////////////////////////////////////////////////////////
  184. extern UNICODE_STRING AVrfpThreadObjectName;
  185. VOID
  186. AVrfpVerifyLegalWait (
  187. CONST HANDLE *Handles,
  188. DWORD Count,
  189. BOOL WaitAll
  190. );
  191. /////////////////////////////////////////////////////////////////////
  192. //////////////////////////// Signatures for private ntdll entrypoints
  193. /////////////////////////////////////////////////////////////////////
  194. typedef PVOID (NTAPI * PFN_RTLP_DEBUG_PAGE_HEAP_CREATE) (
  195. IN ULONG Flags,
  196. IN PVOID HeapBase OPTIONAL,
  197. IN SIZE_T ReserveSize OPTIONAL,
  198. IN SIZE_T CommitSize OPTIONAL,
  199. IN PVOID Lock OPTIONAL,
  200. IN PRTL_HEAP_PARAMETERS Parameters OPTIONAL
  201. );
  202. typedef PVOID (NTAPI * PFN_RTLP_DEBUG_PAGE_HEAP_DESTROY) (
  203. IN PVOID HeapHandle
  204. );
  205. extern PFN_RTLP_DEBUG_PAGE_HEAP_CREATE AVrfpRtlpDebugPageHeapCreate;
  206. extern PFN_RTLP_DEBUG_PAGE_HEAP_DESTROY AVrfpRtlpDebugPageHeapDestroy;
  207. typedef PVOID (* PFN_RTLP_GET_STACK_TRACE_ADDRESS) (
  208. USHORT Index
  209. );
  210. extern PFN_RTLP_GET_STACK_TRACE_ADDRESS AVrfpGetStackTraceAddress;
  211. /////////////////////////////////////////////////////////////////////
  212. ///////////////////////////////////// Random delays for race verifier
  213. /////////////////////////////////////////////////////////////////////
  214. VOID
  215. AVrfpCreateRandomDelay (
  216. VOID
  217. );
  218. /////////////////////////////////////////////////////////////////////
  219. ////////////////////////////////////////////////// Free memory checks
  220. /////////////////////////////////////////////////////////////////////
  221. typedef enum {
  222. VerifierFreeMemTypeFreeHeap,
  223. VerifierFreeMemTypeVirtualFree,
  224. VerifierFreeMemTypeUnloadDll,
  225. VerifierFreeMemTypeUnmap
  226. } VERIFIER_DLL_FREEMEM_TYPE;
  227. VOID
  228. AVrfpFreeMemNotify (
  229. VERIFIER_DLL_FREEMEM_TYPE FreeMemType,
  230. PVOID StartAddress,
  231. SIZE_T RegionSize,
  232. PWSTR UnloadedDllName
  233. );
  234. NTSTATUS
  235. AVrfpAddFreeMemoryCallback (
  236. VERIFIER_FREE_MEMORY_CALLBACK Callback
  237. );
  238. NTSTATUS
  239. AVrfpDeleteFreeMemoryCallback (
  240. VERIFIER_FREE_MEMORY_CALLBACK Callback
  241. );
  242. VOID
  243. AVrfpCallFreeMemoryCallbacks (
  244. PVOID StartAddress,
  245. SIZE_T RegionSize,
  246. PWSTR UnloadedDllName
  247. );
  248. /////////////////////////////////////////////////////////////////////
  249. /////////////////////////////////// Private verifier heap allocations
  250. /////////////////////////////////////////////////////////////////////
  251. extern PVOID AVrfpHeap;
  252. PVOID
  253. AVrfpAllocate (
  254. SIZE_T Size
  255. );
  256. VOID
  257. AVrfpFree (
  258. PVOID Address
  259. );
  260. /////////////////////////////////////////////////////////////////////
  261. /////////////////////////////////////////////////////// Call trackers
  262. /////////////////////////////////////////////////////////////////////
  263. extern PAVRF_TRACKER AVrfThreadTracker;
  264. extern PAVRF_TRACKER AVrfHeapTracker;
  265. extern PAVRF_TRACKER AVrfVspaceTracker;
  266. NTSTATUS
  267. AVrfCreateTrackers (
  268. VOID
  269. );
  270. #endif // _SUPPORT_H_