Source code of Windows XP (NT5)
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.

326 lines
13 KiB

  1. #ifndef __IH_VALID__H__
  2. #define __IH_VALID__H__
  3. #include "apcompat.hxx"
  4. #if DBG==1 && defined(WIN32) && !defined(_CHICAGO_)
  5. #define VDATEHEAP() if( !HeapValidate(GetProcessHeap(),0,0)){ DebugBreak();}
  6. #else
  7. #define VDATEHEAP()
  8. #endif // DBG==1 && defined(WIN32) && !defined(_CHICAGO_)
  9. #define IsValidPtrIn(pv,cb) ((pv == NULL) || !ValidateInPointers() || !IsBadReadPtr ((pv),(cb)))
  10. #define IsValidReadPtrIn(pv,cb) ((cb == 0 || pv) && (!ValidateInPointers() || !IsBadReadPtr ((pv),(cb))))
  11. #define IsValidPtrOut(pv,cb) ((cb == 0 || pv) && (!ValidateOutPointers() || !IsBadWritePtr((pv),(cb))))
  12. #define IsValidCodePtr(pv) (pv && (!ValidateCodePointers() || !IsBadCodePtr ((pv))))
  13. STDAPI_(BOOL) IsValidInterface( void FAR* pv );
  14. #if DBG==1
  15. // for performance, do not do in retail builds
  16. STDAPI_(BOOL) IsValidIid( REFIID riid );
  17. #else
  18. #define IsValidIid(x) (TRUE)
  19. #endif
  20. #ifdef _DEBUG
  21. DECLARE_DEBUG(VDATE);
  22. #define VdateAssert(exp, msg) \
  23. VDATEInlineDebugOut( DEB_FORCE, "%s:%s; File: %s Line: %d\n", #exp, msg, __FILE__, __LINE__ )
  24. //** POINTER IN validation macros:
  25. #define VDATEPTRIN( pv, TYPE ) \
  26. if (!IsValidPtrIn( (pv), sizeof(TYPE))) \
  27. return (VdateAssert(pv, "Invalid in ptr"),ResultFromScode(E_INVALIDARG))
  28. #define GEN_VDATEPTRIN( pv, TYPE, retval) \
  29. if (!IsValidPtrIn( (pv), sizeof(TYPE))) \
  30. return (VdateAssert(pv, "Invalid in ptr"), retval)
  31. #define VOID_VDATEPTRIN( pv, TYPE ) \
  32. if (!IsValidPtrIn( (pv), sizeof(TYPE))) {\
  33. VdateAssert(pv, "Invalid in ptr"); return; }
  34. //** POINTER IN validation macros for single entry/single exit functions
  35. //** uses a goto instead of return
  36. #define VDATEPTRIN_LABEL(pv, TYPE, label, retVar) \
  37. if (!IsValidPtrIn((pv), sizeof(TYPE))) \
  38. { retVar = (VdateAssert(pv, "Invalid in ptr"), ResultFromScode(E_INVALIDARG)); \
  39. goto label; }
  40. #define GEN_VDATEPTRIN_LABEL(pv, TYPE, retval, label, retVar) \
  41. if (!IsValidPtrIn((pv), sizeof(TYPE))) \
  42. { retVar = (VdateAssert(pv, "Invalid in ptr"), retval); \
  43. goto label; }
  44. #define VOID_VDATEPTRIN_LABEL(pv, TYPE, label) \
  45. if (!IsValidPtrIn((pv), sizeof(TYPE))) \
  46. { VdateAssert(pv, "Invalid in ptr"); goto label; }
  47. //** READ POINTER IN validation macros:
  48. #define VDATEREADPTRIN( pv, TYPE ) \
  49. if (!IsValidReadPtrIn( (pv), sizeof(TYPE))) \
  50. return (VdateAssert(pv,"Invalid in read ptr"),ResultFromScode(E_INVALIDARG))
  51. #define GEN_VDATEREADPTRIN( pv, TYPE, retval) \
  52. if (!IsValidReadPtrIn( (pv), sizeof(TYPE))) \
  53. return (VdateAssert(pv,"Invalid in read ptr"), retval)
  54. #define VOID_VDATEREADPTRIN( pv, TYPE ) \
  55. if (!IsValidReadPtrIn( (pv), sizeof(TYPE))) {\
  56. VdateAssert(pv,"Invalid in read ptr"); return; }
  57. //** READ POINTER IN validation macros for single entry/single exit functions
  58. //** uses a goto instead of return
  59. #define VDATEREADPTRIN_LABEL(pv, TYPE, label, retVar) \
  60. if (!IsValidReadPtrIn((pv), sizeof(TYPE))) \
  61. { retVar = (VdateAssert(pv, "Invalid in read ptr"), ResultFromScode(E_INVALIDARG)); \
  62. goto label; }
  63. #define GEN_VDATEREADPTRIN_LABEL(pv, TYPE, retval, label, retVar) \
  64. if (!IsValidReadPtrIn((pv), sizeof(TYPE))) \
  65. { retVar = (VdateAssert(pv, "Invalid in read ptr"), retval); \
  66. goto label; }
  67. #define VOID_VDATEREADPTRIN_LABEL(pv, TYPE, label) \
  68. if (!IsValidReadPtrIn((pv), sizeof(TYPE))) \
  69. { VdateAssert(pv, "Invalid in read ptr"); goto label; }
  70. //** READ POINTER IN validation macros for single entry/single exit functions
  71. //** uses a goto instead of return and a byte count instead of a TYPE
  72. #define VDATESIZEREADPTRIN_LABEL(pv, cb, label, retVar) \
  73. if (!IsValidReadPtrIn((pv), cb)) \
  74. { retVar = (VdateAssert(pv, "Invalid in read ptr"), ResultFromScode(E_INVALIDARG)); \
  75. goto label; }
  76. #define GEN_VDATESIZEREADPTRIN_LABEL(pv, cb, retval, label, retVar) \
  77. if (!IsValidReadPtrIn((pv), cb)) \
  78. { retVar = (VdateAssert(pv, "Invalid in read ptr"), retval); \
  79. goto label; }
  80. #define VOID_VDATESIZEREADPTRIN_LABEL(pv, cb, label) \
  81. if (!IsValidReadPtrIn((pv), cb)) \
  82. { VdateAssert(pv, "Invalid in read ptr"); goto label; }
  83. //** POINTER OUT validation macros:
  84. #define VDATEPTROUT( pv, TYPE ) \
  85. if (!IsValidPtrOut( (pv), sizeof(TYPE))) \
  86. return (VdateAssert(pv,"Invalid out ptr"),ResultFromScode(E_INVALIDARG))
  87. #define GEN_VDATEPTROUT( pv, TYPE, retval ) \
  88. if (!IsValidPtrOut( (pv), sizeof(TYPE))) \
  89. return (VdateAssert(pv,"Invalid out ptr"), retval)
  90. //** POINTER OUT validation macros for single entry/single exit functions
  91. //** uses a goto instead of return
  92. #define VDATEPTROUT_LABEL( pv, TYPE, label, retVar ) \
  93. if (!IsValidPtrOut( (pv), sizeof(TYPE))) \
  94. { retVar = (VdateAssert(pv,"Invalid out ptr"),ResultFromScode(E_INVALIDARG)); \
  95. goto label; }
  96. #define GEN_VDATEPTROUT_LABEL( pv, TYPE, retval, label, retVar ) \
  97. if (!IsValidPtrOut( (pv), sizeof(TYPE))) \
  98. { retVar = (VdateAssert(pv,"Invalid out ptr"),retval); \
  99. goto label; }
  100. //** POINTER OUT validation macros for single entry/single exit functions
  101. //** uses a goto instead of return and a byte count instead of a TYPE
  102. #define VDATESIZEPTROUT_LABEL(pv, cb, label, retVar) \
  103. if (!IsValidPtrOut((pv), cb)) \
  104. { retVar = (VdateAssert(pv, "Invalid out ptr"), ResultFromScode(E_INVALIDARG)); \
  105. goto label; }
  106. #define GEN_VDATESIZEPTROUT_LABEL(pv, cb, retval, label, retVar) \
  107. if (!IsValidPtrOut((pv), cb)) \
  108. { retVar = (VdateAssert(pv, "Invalid out ptr"), retval); \
  109. goto label; }
  110. //** POINTER is NULL validation macros
  111. #define VDATEPTRNULL_LABEL(pv, label, retVar) \
  112. if ((pv) != NULL) \
  113. { retVar = (VdateAssert(pv, "Ptr should be NULL"), ResultFromScode(E_INVALIDARG)); \
  114. goto label; }
  115. #define GEN_VDATEPTRNULL_LABEL(pv, retval, label, retVar) \
  116. if ((pv) != NULL) \
  117. { retVar = (VdateAssert(pv, "Ptr should be NULL"), retval); \
  118. goto label; }
  119. //** INTERFACE validation macro:
  120. #define GEN_VDATEIFACE( pv, retval ) \
  121. if (!IsValidInterface(pv)) \
  122. return (VdateAssert(pv,"Invalid interface"), retval)
  123. #define VDATEIFACE( pv ) \
  124. if (!IsValidInterface(pv)) \
  125. return (VdateAssert(pv,"Invalid interface"),ResultFromScode(E_INVALIDARG))
  126. #define VOID_VDATEIFACE( pv ) \
  127. if (!IsValidInterface(pv)) {\
  128. VdateAssert(pv,"Invalid interface"); return; }
  129. //** INTERFACE validation macros for single entry/single exit functions
  130. //** uses a goto instead of return
  131. #define GEN_VDATEIFACE_LABEL( pv, retval, label, retVar ) \
  132. if (!IsValidInterface(pv)) \
  133. { retVar = (VdateAssert(pv,"Invalid interface"),retval); \
  134. goto label; }
  135. #define VDATEIFACE_LABEL( pv, label, retVar ) \
  136. if (!IsValidInterface(pv)) \
  137. { retVar = (VdateAssert(pv,"Invalid interface"),ResultFromScode(E_INVALIDARG)); \
  138. goto label; }
  139. #define VOID_VDATEIFACE_LABEL( pv, label ) \
  140. if (!IsValidInterface(pv)) {\
  141. VdateAssert(pv,"Invalid interface"); goto label; }
  142. //** INTERFACE ID validation macro:
  143. // Only do this in debug build
  144. #define VDATEIID( iid ) if (!IsValidIid( iid )) \
  145. return (VdateAssert(iid,"Invalid iid"),ResultFromScode(E_INVALIDARG))
  146. #define GEN_VDATEIID( iid, retval ) if (!IsValidIid( iid )) {\
  147. VdateAssert(iid,"Invalid iid"); return retval; }
  148. //** INTERFACE ID validation macros for single entry/single exit functions
  149. //** uses a goto instead of return
  150. #define VDATEIID_LABEL( iid, label, retVar ) if (!IsValidIid( iid )) \
  151. {retVar = (VdateAssert(iid,"Invalid iid"),ResultFromScode(E_INVALIDARG)); \
  152. goto label; }
  153. #define GEN_VDATEIID_LABEL( iid, retval, label, retVar ) if (!IsValidIid( iid )) {\
  154. VdateAssert(iid,"Invalid iid"); retVar = retval; goto label; }
  155. #else // _DEBUG
  156. #define VdateAssert(exp, msg) ((void)0)
  157. // --assertless macros for non-debug case
  158. //** POINTER IN validation macros:
  159. #define VDATEPTRIN( pv, TYPE ) if (!IsValidPtrIn( (pv), sizeof(TYPE))) \
  160. return (ResultFromScode(E_INVALIDARG))
  161. #define GEN_VDATEPTRIN( pv, TYPE, retval ) if (!IsValidPtrIn( (pv), sizeof(TYPE))) \
  162. return (retval)
  163. #define VOID_VDATEPTRIN( pv, TYPE ) if (!IsValidPtrIn( (pv), sizeof(TYPE))) {\
  164. return; }
  165. //** POINTER IN validation macros for single entry/single exit functions
  166. //** uses a goto instead of return
  167. #define VDATEPTRIN_LABEL(pv, TYPE, label, retVar) \
  168. if (!IsValidPtrIn((pv), sizeof(TYPE))) \
  169. { retVar = ResultFromScode(E_INVALIDARG); \
  170. goto label; }
  171. #define GEN_VDATEPTRIN_LABEL(pv, TYPE, retval, label, retVar) \
  172. if (!IsValidPtrIn((pv), sizeof(TYPE))) \
  173. { retVar = retval; \
  174. goto label; }
  175. #define VOID_VDATEPTRIN_LABEL(pv, TYPE, label) \
  176. if (!IsValidPtrIn((pv), sizeof(TYPE))) \
  177. { goto label; }
  178. //** POINTER IN validation macros:
  179. #define VDATEREADPTRIN( pv, TYPE ) if (!IsValidReadPtrIn( (pv), sizeof(TYPE))) \
  180. return (ResultFromScode(E_INVALIDARG))
  181. #define GEN_VDATEREADPTRIN( pv, TYPE, retval ) if (!IsValidReadPtrIn( (pv), sizeof(TYPE))) \
  182. return (retval)
  183. #define VOID_VDATEREADPTRIN( pv, TYPE ) if (!IsValidReadPtrIn( (pv), sizeof(TYPE))) {\
  184. return; }
  185. //** POINTER IN validation macros for single entry/single exit functions
  186. //** uses a goto instead of return
  187. #define VDATEREADPTRIN_LABEL(pv, TYPE, label, retVar) \
  188. if (!IsValidReadPtrIn((pv), sizeof(TYPE))) \
  189. { retVar = ResultFromScode(E_INVALIDARG); \
  190. goto label; }
  191. #define GEN_VDATEREADPTRIN_LABEL(pv, TYPE, retval, label, retVar) \
  192. if (!IsValidReadPtrIn((pv), sizeof(TYPE))) \
  193. { retVar = retval; \
  194. goto label; }
  195. #define VOID_VDATEREADPTRIN_LABEL(pv, TYPE, label) \
  196. if (!IsValidReadPtrIn((pv), sizeof(TYPE))) \
  197. { goto label; }
  198. //** READ POINTER IN validation macros for single entry/single exit functions
  199. //** uses a goto instead of return and a byte count instead of a TYPE
  200. #define VDATESIZEREADPTRIN_LABEL(pv, cb, label, retVar) \
  201. if (!IsValidReadPtrIn((pv), cb)) \
  202. { retVar = ResultFromScode(E_INVALIDARG); \
  203. goto label; }
  204. #define GEN_VDATESIZEREADPTRIN_LABEL(pv, cb, retval, label, retVar) \
  205. if (!IsValidReadPtrIn((pv), cb)) \
  206. { retVar = retval; \
  207. goto label; }
  208. #define VOID_VDATESIZEREADPTRIN_LABEL(pv, cb, label) \
  209. if (!IsValidReadPtrIn((pv), cb)) \
  210. { goto label; }
  211. //** POINTER OUT validation macros:
  212. #define VDATEPTROUT( pv, TYPE ) if (!IsValidPtrOut( (pv), sizeof(TYPE))) \
  213. return (ResultFromScode(E_INVALIDARG))
  214. #define GEN_VDATEPTROUT( pv, TYPE, retval ) if (!IsValidPtrOut( (pv), sizeof(TYPE))) \
  215. return (retval)
  216. //** POINTER OUT validation macros for single entry/single exit functions
  217. //** uses a goto instead of return
  218. #define VDATEPTROUT_LABEL( pv, TYPE, label, retVar ) \
  219. if (!IsValidPtrOut( (pv), sizeof(TYPE))) \
  220. { retVar = ResultFromScode(E_INVALIDARG); \
  221. goto label; }
  222. #define GEN_VDATEPTROUT_LABEL( pv, TYPE, retval, label, retVar ) \
  223. if (!IsValidPtrOut( (pv), sizeof(TYPE))) \
  224. { retVar = retval; \
  225. goto label; }
  226. //** POINTER OUT validation macros for single entry/single exit functions
  227. //** uses a goto instead of return and a byte count instead of a TYPE
  228. #define VDATESIZEPTROUT_LABEL(pv, cb, label, retVar) \
  229. if (!IsValidPtrOut((pv), cb)) \
  230. { retVar = ResultFromScode(E_INVALIDARG); \
  231. goto label; }
  232. #define GEN_VDATESIZEPTROUT_LABEL(pv, cb, retval, label, retVar) \
  233. if (!IsValidPtrOut((pv), cb)) \
  234. { retVar = retval; \
  235. goto label; }
  236. //** POINTER is NULL validation macros
  237. #define VDATEPTRNULL_LABEL(pv, label, retVar) \
  238. if ((pv) != NULL) \
  239. { retVar = ResultFromScode(E_INVALIDARG); \
  240. goto label; }
  241. #define GEN_VDATEPTRNULL_LABEL(pv, retval, label, retVar) \
  242. if ((pv) != NULL) \
  243. { retVar = retval; \
  244. goto label; }
  245. //** INTERFACE validation macro:
  246. #define VDATEIFACE( pv ) if (!IsValidInterface(pv)) \
  247. return (ResultFromScode(E_INVALIDARG))
  248. #define VOID_VDATEIFACE( pv ) if (!IsValidInterface(pv)) \
  249. return;
  250. #define GEN_VDATEIFACE( pv, retval ) if (!IsValidInterface(pv)) \
  251. return (retval)
  252. //** INTERFACE validation macros for single entry/single exit functions
  253. //** uses a goto instead of return
  254. #define GEN_VDATEIFACE_LABEL( pv, retval, label, retVar ) \
  255. if (!IsValidInterface(pv)) \
  256. { retVar = retval; \
  257. goto label; }
  258. #define VDATEIFACE_LABEL( pv, label, retVar ) \
  259. if (!IsValidInterface(pv)) \
  260. { retVar = ResultFromScode(E_INVALIDARG); \
  261. goto label; }
  262. #define VOID_VDATEIFACE_LABEL( pv, label ) \
  263. if (!IsValidInterface(pv)) {\
  264. goto label; }
  265. //** INTERFACE ID validation macro:
  266. // do not do in retail build. This code USED to call a bogus version of
  267. // IsValidIID that did no work. Now we are faster and no less stable than before.
  268. #define VDATEIID( iid ) ((void)0)
  269. #define GEN_VDATEIID( iid, retval ) ((void)0);
  270. //** INTERFACE ID validation macros for single entry/single exit functions
  271. //** uses a goto instead of return
  272. #define VDATEIID_LABEL( iid, label, retVar ) if (!IsValidIid( iid )) \
  273. {retVar = ResultFromScode(E_INVALIDARG); \
  274. goto label; }
  275. #define GEN_VDATEIID_LABEL( iid, retval, label, retVar ) if (!IsValidIid( iid )) {\
  276. retVar = retval; goto label; }
  277. #endif
  278. #endif // __IH_VALID_H__
  279.