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.

304 lines
8.8 KiB

  1. /*** asrt.h - Definitions for Assertion Manager
  2. *
  3. * Microsoft Confidential
  4. * Copyright (C) Microsoft Corporation 1993-1994
  5. * All Rights Reserved.
  6. *
  7. * Author:
  8. * Benjamin W. Slivka
  9. *
  10. * History:
  11. * 10-Aug-1993 bens Initial version
  12. * 11-Aug-1993 bens Lifted old code from 1988 PSCHAR.EXE
  13. * 14-Aug-1993 bens Added Get/Set functions
  14. * 01-Sep-1993 bens Added AssertSub function
  15. * 10-Feb-1994 bens Added Set/ClearAssertSignature
  16. * 15-Mar-1994 bens Put back AssertMessage macro
  17. *
  18. * Notes:
  19. * o Every data structure must have a signature as first member.
  20. * o Signatures MUST be unique over all structures.
  21. * o sigBAD is a reserved signature.
  22. * o When freeing a structure, blast the signature field with sigBAD.
  23. * o Put an AssertXXX prior to dereferencing any pointer.
  24. * o Signatures in structures and private Assert definitions should only
  25. * be generated if ASSERT is defined.
  26. *
  27. * Functions available in ASSERT build:
  28. * AssertRegisterFunc - Register assertion failure call back function
  29. * AssertGetFunc - Get registered call back function
  30. *
  31. * AssertSetFlags - Set Assertion Manager flags
  32. * AssertGetFlags - Get Assertion Manager flags
  33. *
  34. * Assert - Check that parameter is TRUE
  35. * AssertSub - Check that parameter is TRUE, take explicit filename & line number
  36. * AssertStrucure - Check that pointer points to specified structure
  37. * AssertForce - Force an assertion failure
  38. * AssertErrPath - Error Path assertion failure
  39. *
  40. * SetAssertSignature - Set the signature for a structure
  41. * ClearAssertSignature - Clear the signature for a structure
  42. *
  43. * Other definitions available in ASSERT build:
  44. * PFNASSERTFAILURE - Assertion failure call back function type
  45. * FNASSERTFAILURE - Macro to simplify declaration of call back function
  46. * SIGNATURE - Structure signature type
  47. */
  48. #ifndef INCLUDED_ASSERT
  49. #define INCLUDED_ASSERT 1
  50. #ifdef DIAMOND_DEBUG
  51. #ifndef ASSERT
  52. #define ASSERT 1
  53. #endif // !ASSERT
  54. #endif // _DEBUG
  55. #ifdef ASSERT
  56. typedef unsigned long ASSERTFLAGS; /* asf - Assertion Manager Flags */
  57. #define asfNONE 0x00
  58. #define asfSKIP_ERROR_PATH_ASSERTS 0x01 /* Some clients may wish to set
  59. * assertions in error paths, to
  60. * ensure that the problem is
  61. * noticed in a debug build. But,
  62. * in order to support automated
  63. * testing of error paths, these
  64. * assertions must be disabled.
  65. * This flag allows a test program
  66. * to disable these informational
  67. * asserts!
  68. */
  69. typedef unsigned long SIGNATURE; /* sig - structure signature */
  70. typedef SIGNATURE *PSIGNATURE; /* psig */
  71. #define sigBAD 0 // Invalid signature for ALL structs
  72. /*** MAKESIG - construct a structure signature
  73. *
  74. * Entry:
  75. * ch1,ch2,ch3,ch4 - four characters
  76. *
  77. * Exit:
  78. * returns SIGNATURE
  79. */
  80. #define MAKESIG(ch1,ch2,ch3,ch4) \
  81. ( ((SIGNATURE)ch1) + \
  82. (((SIGNATURE)ch2)<< 8) + \
  83. (((SIGNATURE)ch3)<<16) + \
  84. (((SIGNATURE)ch4)<<24) )
  85. /*** AssertMessage -- Force an Assertion with supplied message
  86. *
  87. * Entry:
  88. * pszMsg -- message to display
  89. *
  90. * Exit:
  91. * none
  92. */
  93. #define AssertMessage(pszMsg) AssertForce(pszMsg,__FILE__,__LINE__)
  94. /*** PFNASSERTFAILURE - Assertion Failure call back function
  95. *** FNASSERTFAILURE - Define Assertion Failure call back function
  96. *
  97. * Entry:
  98. * pszMsg - Description of failure
  99. * pszFile - File where assertion failed
  100. * iLine - Line number in file where assertion failed
  101. *
  102. * Exit-Success:
  103. * Returns; ignore failure and continue
  104. *
  105. * Exit-Failure:
  106. * Function does not return, but cleans up and exits program.
  107. */
  108. typedef void (*PFNASSERTFAILURE)(char *pszMsg, char *pszFile, int iLine);
  109. #define FNASSERTFAILURE(fn) void fn(char *pszMsg, char *pszFile, int iLine)
  110. /*** AssertRegisterFunc - Register assertion failure call back function
  111. *
  112. * Entry:
  113. * pfnaf - Call back function
  114. *
  115. * Exit-Success:
  116. * Returns; pfnaf is stored in the Assertion Manager
  117. *
  118. * NOTES:
  119. * (1) This function *must* be called prior to executing an assertion
  120. * checks. If not, and an assertion check fails, then the Assertion
  121. * Manager will sit in a spin loop to catch the developer's attention.
  122. */
  123. void AssertRegisterFunc(PFNASSERTFAILURE pfnaf);
  124. /*** AssertGetFunc - Get current assertion failure call back function
  125. *
  126. * Entry:
  127. * none
  128. *
  129. * Exit-Success:
  130. * Returns current call back function registerd in Assertion Manager.
  131. */
  132. PFNASSERTFAILURE AssertGetFunc(void);
  133. /*** AssertSetFlags - Set special assertion control flags
  134. *
  135. * Entry:
  136. * flags - Set with combination of asfXXXX flags
  137. *
  138. * Exit-Success:
  139. * Returns; Flags are modified in Assertion Manager.
  140. */
  141. void AssertSetFlags(ASSERTFLAGS asf);
  142. /*** AssertGetFlags - Get special assertion control flags
  143. *
  144. * Entry:
  145. * none
  146. *
  147. * Exit-Success:
  148. * Returns current Assertion Manager flags.
  149. */
  150. ASSERTFLAGS AssertGetFlags(void);
  151. /*** Assert - Check assertion that argument is true
  152. *
  153. * Entry:
  154. * b - Boolean value to check
  155. *
  156. * Exit-Success:
  157. * Returns; b was TRUE
  158. *
  159. * Exit-Failure:
  160. * Calls assertion failure callback function; b was FALSE
  161. */
  162. #define Assert(b) AsrtCheck(b,__FILE__,__LINE__)
  163. /*** AssertSub - Check assertion, use passed in filename and line number
  164. *
  165. * Entry:
  166. * b - Boolean value to check
  167. * pszFile - File where assertion occurred
  168. * iLine - Line in file where assertion occurred
  169. *
  170. * Exit-Success:
  171. * Returns; b was TRUE
  172. *
  173. * Exit-Failure:
  174. * Calls assertion failure callback function; b was FALSE
  175. */
  176. #define AssertSub(b,pszFile,iLine) AsrtCheck(b,pszFile,iLine)
  177. /*** AssertStructure - Check assertion that pointer is of correct type
  178. *
  179. * Entry:
  180. * pv - Pointer to structure
  181. * sig - Expected signature
  182. *
  183. * Exit-Success:
  184. * Returns; pv != NULL, and pv->sig == sig.
  185. *
  186. * Exit-Failure:
  187. * Calls assertion failure callback function; pv was bad.
  188. */
  189. #define AssertStructure(pv,sig) AsrtStruct(pv, sig, __FILE__, __LINE__)
  190. /*** AssertForce - Force an assertion failure
  191. *
  192. * Entry:
  193. * pszMsg - Message to display
  194. * pszFile - File where assertion occurred
  195. * iLine - Line in file where assertion occurred
  196. *
  197. * Exit-Success:
  198. * Returns; client wanted to ignore assertion.
  199. *
  200. * Exit-Failure:
  201. * Does not return.
  202. */
  203. void AssertForce(char *pszMsg, char *pszFile, int iLine);
  204. /*** AssertErrorPath - Report an internal error path
  205. *
  206. * Entry:
  207. * pszMsg - Message to display
  208. * pszFile - File where assertion occurred
  209. * iLine - Line in file where assertion occurred
  210. *
  211. * Exit-Success:
  212. * Returns; client wanted to ignore assertion.
  213. *
  214. * Exit-Failure:
  215. * Does not return.
  216. */
  217. void AssertErrPath(char *pszMsg, char *pszFile, int iLine);
  218. /*** SetAssertSignature - Set the signature for a structure
  219. *
  220. * Entry:
  221. * p - Structure with member "sigValue"
  222. * sig - Signature to set
  223. *
  224. * Exit:
  225. * p->sig = sig
  226. */
  227. #define SetAssertSignature(p,sigValue) p->sig = sigValue
  228. /*** ClearAssertSignature - Clear the signature for a structure
  229. *
  230. * Entry:
  231. * p - Structure with member "sig"
  232. *
  233. * Exit:
  234. * p->sig = sigBAD
  235. */
  236. #define ClearAssertSignature(p) p->sig = sigBAD
  237. //** Internal assertion manager worker routines
  238. void AsrtCheck(BOOL f, char *pszFile, int iLine);
  239. void AsrtStruct(void *pv, SIGNATURE sig, char *pszFile, int iLine);
  240. #else // !ASSERT
  241. //** Assertion checking is turned off, so it all evaporates!
  242. #define FNASSERTFAILURE(fn)
  243. #define AssertRegisterFunc(pfnaf)
  244. #define Assert(b)
  245. #define AssertSub(b,pszFile,iLine)
  246. #define AssertStructure(pv,sig)
  247. #define AssertMessage(pszMsg)
  248. #define AssertForce(pszMsg,pszFile,iLine)
  249. #define AssertErrPath(pszMsg,pszFile,iLine)
  250. #define SetAssertSignature(p,sig)
  251. #define ClearAssertSignature(p)
  252. /** The following functions are not defined away, because any valid use
  253. * of them requires a typedef'd variable or function that is not available
  254. * in a non-ASSERT build. So we don't define them so that if a client
  255. * has used these outside of an #ifdef ASSERT, a compiler error/warning
  256. * will be generated:
  257. *
  258. * AssertGetFunc
  259. * AssertSetFlags
  260. * AssertGetFlags
  261. */
  262. #endif // ASSERT
  263. #endif // !INCLUDED_ASSERT