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.

227 lines
6.8 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: verifier.hxx
  3. *
  4. * GRE DriverVerifier support.
  5. *
  6. * If DriverVerifier is enabled for a particular component, the loader will
  7. * substitute VerifierEngAllocMem for EngAllocMem, etc. The VerifierEngXX
  8. * functions will help test the robustness of components that use EngXX calls
  9. * by injecting random failures and using special pool (i.e., test low-mem
  10. * behavior and check for buffer overruns).
  11. *
  12. * See ntos\mm\verifier.c for further details on DriverVerifier support in
  13. * the memory manager.
  14. *
  15. * See sdk\inc\ntexapi.h for details on the DriverVerifier flags.
  16. *
  17. * Created: 30-Jan-1999 15:12:48
  18. * Author: Gilman Wong [gilmanw]
  19. *
  20. * Copyright (c) 1999 Microsoft Corporation
  21. *
  22. \**************************************************************************/
  23. #ifndef _VERIFIER_HXX_
  24. #define _VERIFIER_HXX_
  25. //
  26. // This bitfield definition is based on EX_POOL_PRIORITY
  27. // in ntos\inc\ex.h.
  28. //
  29. // Taken from ntos\mm\verifier.c.
  30. //
  31. #define POOL_SPECIAL_POOL_BIT 0x8
  32. //
  33. // Define VERIFIER_STATISTICS to enable statistics.
  34. //
  35. //#define VERIFIER_STATISTICS
  36. #ifdef VERIFIER_STATISTICS
  37. //
  38. // Verifier statistics structure.
  39. //
  40. typedef struct tagVSTATS
  41. {
  42. ULONG ulAttempts;
  43. ULONG ulFailures;
  44. } VSTATS;
  45. #endif
  46. //
  47. // Index values used to access the statistics array in VSTATE.
  48. //
  49. #define VERIFIER_INDEX_EngAllocMem 0
  50. #define VERIFIER_INDEX_EngFreeMem 1
  51. #define VERIFIER_INDEX_EngAllocUserMem 2
  52. #define VERIFIER_INDEX_EngFreeUserMem 3
  53. #define VERIFIER_INDEX_EngCreateBitmap 4
  54. #define VERIFIER_INDEX_EngCreateDeviceSurface 5
  55. #define VERIFIER_INDEX_EngCreateDeviceBitmap 6
  56. #define VERIFIER_INDEX_EngCreatePalette 7
  57. #define VERIFIER_INDEX_EngCreateClip 8
  58. #define VERIFIER_INDEX_EngCreatePath 9
  59. #define VERIFIER_INDEX_EngCreateWnd 10
  60. #define VERIFIER_INDEX_EngCreateDriverObj 11
  61. #define VERIFIER_INDEX_BRUSHOBJ_pvAllocRbrush 12
  62. #define VERIFIER_INDEX_CLIPOBJ_ppoGetPath 13
  63. #define VERIFIER_INDEX_LAST 14
  64. //
  65. // Verifier state structure.
  66. //
  67. // Members:
  68. //
  69. // fl May be any combination of the following flags
  70. // (see sdk\inc\ntexapi.h for the declarations):
  71. //
  72. // DRIVER_VERIFIER_SPECIAL_POOLING
  73. // Allocate from special pool.
  74. //
  75. // DRIVER_VERIFIER_FORCE_IRQL_CHECKING
  76. // Ignored by GRE's verifier support.
  77. //
  78. // DRIVER_VERIFIER_INJECT_ALLOCATION_FAILURES
  79. // Randomly fail the allocation routine.
  80. //
  81. // DRIVER_VERIFIER_TRACK_POOL_ALLOCATIONS
  82. // Track pool in a linked list.
  83. //
  84. // bSystemStable This is TRUE if enough time has elapsed since boot
  85. // for the system to be stable.
  86. //
  87. // ulRandomSeed Seed for random number generator, RtlRandom().
  88. //
  89. // ulFailureMask If AND-ed result of this and RtlRandom is zero,
  90. // failure is injected. Usually Power-of-2 MINUS 1.
  91. // For example, if ulFailureMask is 0x7, failure is
  92. // generated on average every 8 times; if 0xf, every
  93. // 16 times.
  94. //
  95. // ulDebugLevel Controls output of debug messages.
  96. //
  97. // hsemPoolTracker Semaphore that protects the pool tracking list.
  98. //
  99. // lePoolTrackerHead Head of the doubly-linked list that tracks
  100. // VerifierEngAllocMem allocations.
  101. //
  102. // avs Array of VSTATS to record attempts and failures for
  103. // each engine callback hooked. Only allocated if
  104. // compiled with the VERIFIER_STATISTICS flag defined.
  105. //
  106. typedef struct tagVSTATE
  107. {
  108. FLONG fl;
  109. BOOL bSystemStable;
  110. ULONG ulRandomSeed;
  111. ULONG ulFailureMask;
  112. ULONG ulDebugLevel;
  113. HSEMAPHORE hsemPoolTracker;
  114. LIST_ENTRY lePoolTrackerHead;
  115. #ifdef VERIFIER_STATISTICS
  116. VSTATS avs[VERIFIER_INDEX_LAST];
  117. #endif
  118. } VSTATE;
  119. //
  120. // Verifier pool tracking structure.
  121. //
  122. // Members:
  123. //
  124. // list Links for doubly-linked list.
  125. //
  126. // ulSize Size of allocation requested by driver (does not
  127. // include headers).
  128. //
  129. // ulTag Pool tag specified by driver.
  130. //
  131. typedef struct tagVERIFIERTRACKHDR
  132. {
  133. LIST_ENTRY list;
  134. SIZE_T ulSize;
  135. ULONG ulTag;
  136. } VERIFIERTRACKHDR;
  137. //
  138. // Verifier function declarations.
  139. //
  140. extern "C"
  141. {
  142. PVOID APIENTRY VerifierEngAllocMem(ULONG fl, ULONG cj, ULONG tag);
  143. VOID APIENTRY VerifierEngFreeMem(PVOID pv);
  144. PVOID APIENTRY VerifierEngAllocUserMem(SIZE_T cj, ULONG tag);
  145. VOID APIENTRY VerifierEngFreeUserMem(PVOID pv);
  146. HBITMAP APIENTRY VerifierEngCreateBitmap(
  147. SIZEL sizl,
  148. LONG lWidth,
  149. ULONG iFormat,
  150. FLONG fl,
  151. PVOID pvBits
  152. );
  153. HSURF APIENTRY VerifierEngCreateDeviceSurface(
  154. DHSURF dhsurf,
  155. SIZEL sizl,
  156. ULONG iFormatCompat
  157. );
  158. HBITMAP APIENTRY VerifierEngCreateDeviceBitmap(
  159. DHSURF dhsurf,
  160. SIZEL sizl,
  161. ULONG iFormatCompat
  162. );
  163. HPALETTE APIENTRY VerifierEngCreatePalette(
  164. ULONG iMode,
  165. ULONG cColors,
  166. ULONG *pulColors,
  167. FLONG flRed,
  168. FLONG flGreen,
  169. FLONG flBlue
  170. );
  171. CLIPOBJ * APIENTRY VerifierEngCreateClip();
  172. PATHOBJ * APIENTRY VerifierEngCreatePath();
  173. WNDOBJ * APIENTRY VerifierEngCreateWnd(
  174. SURFOBJ *pso,
  175. HWND hwnd,
  176. WNDOBJCHANGEPROC pfn,
  177. FLONG fl,
  178. int iPixelFormat
  179. );
  180. HDRVOBJ APIENTRY VerifierEngCreateDriverObj(
  181. PVOID pvObj,
  182. FREEOBJPROC pFreeObjProc,
  183. HDEV hdev
  184. );
  185. PVOID APIENTRY VerifierBRUSHOBJ_pvAllocRbrush(BRUSHOBJ *pbo, ULONG cj);
  186. PATHOBJ* APIENTRY VerifierCLIPOBJ_ppoGetPath(CLIPOBJ* pco);
  187. BOOL VerifierInitialization();
  188. };
  189. extern BOOL FASTCALL VerifierRandomFailure(ULONG ul);
  190. //
  191. // Mask of all the verifier flags interesting to GRE.
  192. //
  193. #define DRIVER_VERIFIER_GRE_MASK \
  194. (DRIVER_VERIFIER_SPECIAL_POOLING | \
  195. DRIVER_VERIFIER_FORCE_IRQL_CHECKING | \
  196. DRIVER_VERIFIER_INJECT_ALLOCATION_FAILURES | \
  197. DRIVER_VERIFIER_TRACK_POOL_ALLOCATIONS)
  198. //
  199. // Debug messages.
  200. //
  201. #if DBG
  202. #define VERIFIERWARNING(l, s) if ((l) <= gvs.ulDebugLevel) { DbgPrint(s); }
  203. #else
  204. #define VERIFIERWARNING(l, s)
  205. #endif
  206. #endif