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.

188 lines
8.0 KiB

  1. #if DBG==1 && defined(WIN32) && !defined(_CHICAGO_)
  2. #define VDATEHEAP() if( !HeapValidate(GetProcessHeap(),0,0)){ DebugBreak();}
  3. #else
  4. #define VDATEHEAP()
  5. #endif // DBG==1 && defined(WIN32) && !defined(_CHICAGO_)
  6. #define IsValidPtrIn(pv,cb) ((pv == NULL) || !IsBadReadPtr ((pv),(cb)))
  7. #define IsValidPtrOut(pv,cb) (!IsBadWritePtr((pv),(cb)))
  8. STDAPI_(BOOL) IsValidInterface( void FAR* pv );
  9. #if DBG==1
  10. // for performance, do not do in retail builds
  11. STDAPI_(BOOL) IsValidIid( REFIID riid );
  12. #else
  13. #define IsValidIid(x) (TRUE)
  14. #endif
  15. #ifdef _DEBUG
  16. //** POINTER IN validation macros:
  17. #define VDATEPTRIN( pv, TYPE ) \
  18. if (!IsValidPtrIn( (pv), sizeof(TYPE))) \
  19. return (FnAssert(#pv,"Invalid in ptr", __FILE__, __LINE__),ResultFromScode(E_INVALIDARG))
  20. #define GEN_VDATEPTRIN( pv, TYPE, retval) \
  21. if (!IsValidPtrIn( (pv), sizeof(TYPE))) \
  22. return (FnAssert(#pv,"Invalid in ptr", __FILE__, __LINE__), retval)
  23. #define VOID_VDATEPTRIN( pv, TYPE ) \
  24. if (!IsValidPtrIn( (pv), sizeof(TYPE))) {\
  25. FnAssert(#pv,"Invalid in ptr", __FILE__, __LINE__); return; }
  26. //** POINTER IN validation macros for single entry/single exit functions
  27. //** uses a goto instead of return
  28. #define VDATEPTRIN_LABEL(pv, TYPE, label, retVar) \
  29. if (!IsValidPtrIn((pv), sizeof(TYPE))) \
  30. { retVar = (FnAssert(#pv, "Invalid in ptr", __FILE__, __LINE__), ResultFromScode(E_INVALIDARG)); \
  31. goto label; }
  32. #define GEN_VDATEPTRIN_LABEL(pv, TYPE, retval, label, retVar) \
  33. if (!IsValidPtrIn((pv), sizeof(TYPE))) \
  34. { retVar = (FnAssert(#pv, "Invalid in ptr", __FILE__, __LINE__), retval); \
  35. goto label; }
  36. #define VOID_VDATEPTRIN_LABEL(pv, TYPE, label) \
  37. if (!IsValidPtrIn((pv), sizeof(TYPE))) \
  38. { FnAssert(#pv, "Invalid in ptr", __FILE__, __LINE__); goto label; }
  39. //** POINTER OUT validation macros:
  40. #define VDATEPTROUT( pv, TYPE ) \
  41. if (!IsValidPtrOut( (pv), sizeof(TYPE))) \
  42. return (FnAssert(#pv,"Invalid out ptr", __FILE__, __LINE__),ResultFromScode(E_INVALIDARG))
  43. #define GEN_VDATEPTROUT( pv, TYPE, retval ) \
  44. if (!IsValidPtrOut( (pv), sizeof(TYPE))) \
  45. return (FnAssert(#pv,"Invalid out ptr", __FILE__, __LINE__), retval)
  46. //** POINTER OUT validation macros for single entry/single exit functions
  47. //** uses a goto instead of return
  48. #define VDATEPTROUT_LABEL( pv, TYPE, label, retVar ) \
  49. if (!IsValidPtrOut( (pv), sizeof(TYPE))) \
  50. { retVar = (FnAssert(#pv,"Invalid out ptr", __FILE__, __LINE__),ResultFromScode(E_INVALIDARG)); \
  51. goto label; }
  52. #define GEN_VDATEPTROUT_LABEL( pv, TYPE, retval, label, retVar ) \
  53. if (!IsValidPtrOut( (pv), sizeof(TYPE))) \
  54. { retVar = (FnAssert(#pv,"Invalid out ptr", __FILE__, __LINE__),retval); \
  55. goto label; }
  56. //** INTERFACE validation macro:
  57. #define GEN_VDATEIFACE( pv, retval ) \
  58. if (!IsValidInterface(pv)) \
  59. return (FnAssert(#pv,"Invalid interface", __FILE__, __LINE__), retval)
  60. #define VDATEIFACE( pv ) \
  61. if (!IsValidInterface(pv)) \
  62. return (FnAssert(#pv,"Invalid interface", __FILE__, __LINE__),ResultFromScode(E_INVALIDARG))
  63. #define VOID_VDATEIFACE( pv ) \
  64. if (!IsValidInterface(pv)) {\
  65. FnAssert(#pv,"Invalid interface", __FILE__, __LINE__); return; }
  66. //** INTERFACE validation macros for single entry/single exit functions
  67. //** uses a goto instead of return
  68. #define GEN_VDATEIFACE_LABEL( pv, retval, label, retVar ) \
  69. if (!IsValidInterface(pv)) \
  70. { retVar = (FnAssert(#pv,"Invalid interface", __FILE__, __LINE__),retval); \
  71. goto label; }
  72. #define VDATEIFACE_LABEL( pv, label, retVar ) \
  73. if (!IsValidInterface(pv)) \
  74. { retVar = (FnAssert(#pv,"Invalid interface", __FILE__, __LINE__),ResultFromScode(E_INVALIDARG)); \
  75. goto label; }
  76. #define VOID_VDATEIFACE_LABEL( pv, label ) \
  77. if (!IsValidInterface(pv)) {\
  78. FnAssert(#pv,"Invalid interface", __FILE__, __LINE__); goto label; }
  79. //** INTERFACE ID validation macro:
  80. // Only do this in debug build
  81. #define VDATEIID( iid ) if (!IsValidIid( iid )) \
  82. return (FnAssert(#iid,"Invalid iid", __FILE__, __LINE__),ResultFromScode(E_INVALIDARG))
  83. #define GEN_VDATEIID( iid, retval ) if (!IsValidIid( iid )) {\
  84. FnAssert(#iid,"Invalid iid", __FILE__, __LINE__); return retval; }
  85. //** INTERFACE ID validation macros for single entry/single exit functions
  86. //** uses a goto instead of return
  87. #define VDATEIID_LABEL( iid, label, retVar ) if (!IsValidIid( iid )) \
  88. {retVar = (FnAssert(#iid,"Invalid iid", __FILE__, __LINE__),ResultFromScode(E_INVALIDARG)); \
  89. goto label; }
  90. #define GEN_VDATEIID_LABEL( iid, retval, label, retVar ) if (!IsValidIid( iid )) {\
  91. FnAssert(#iid,"Invalid iid", __FILE__, __LINE__); retVar = retval; goto label; }
  92. #else
  93. // --assertless macros for non-debug case
  94. //** POINTER IN validation macros:
  95. #define VDATEPTRIN( pv, TYPE ) if (!IsValidPtrIn( (pv), sizeof(TYPE))) \
  96. return (ResultFromScode(E_INVALIDARG))
  97. #define GEN_VDATEPTRIN( pv, TYPE, retval ) if (!IsValidPtrIn( (pv), sizeof(TYPE))) \
  98. return (retval)
  99. #define VOID_VDATEPTRIN( pv, TYPE ) if (!IsValidPtrIn( (pv), sizeof(TYPE))) {\
  100. return; }
  101. //** POINTER IN validation macros for single entry/single exit functions
  102. //** uses a goto instead of return
  103. #define VDATEPTRIN_LABEL(pv, TYPE, label, retVar) \
  104. if (!IsValidPtrIn((pv), sizeof(TYPE))) \
  105. { retVar = ResultFromScode(E_INVALIDARG); \
  106. goto label; }
  107. #define GEN_VDATEPTRIN_LABEL(pv, TYPE, retval, label, retVar) \
  108. if (!IsValidPtrIn((pv), sizeof(TYPE))) \
  109. { retVar = retval; \
  110. goto label; }
  111. #define VOID_VDATEPTRIN_LABEL(pv, TYPE, label) \
  112. if (!IsValidPtrIn((pv), sizeof(TYPE))) \
  113. { goto label; }
  114. //** POINTER OUT validation macros:
  115. #define VDATEPTROUT( pv, TYPE ) if (!IsValidPtrOut( (pv), sizeof(TYPE))) \
  116. return (ResultFromScode(E_INVALIDARG))
  117. #define GEN_VDATEPTROUT( pv, TYPE, retval ) if (!IsValidPtrOut( (pv), sizeof(TYPE))) \
  118. return (retval)
  119. //** POINTER OUT validation macros for single entry/single exit functions
  120. //** uses a goto instead of return
  121. #define VDATEPTROUT_LABEL( pv, TYPE, label, retVar ) \
  122. if (!IsValidPtrOut( (pv), sizeof(TYPE))) \
  123. { retVar = ResultFromScode(E_INVALIDARG); \
  124. goto label; }
  125. #define GEN_VDATEPTROUT_LABEL( pv, TYPE, retval, label, retVar ) \
  126. if (!IsValidPtrOut( (pv), sizeof(TYPE))) \
  127. { retVar = retval; \
  128. goto label; }
  129. //** INTERFACE validation macro:
  130. #define VDATEIFACE( pv ) if (!IsValidInterface(pv)) \
  131. return (ResultFromScode(E_INVALIDARG))
  132. #define VOID_VDATEIFACE( pv ) if (!IsValidInterface(pv)) \
  133. return;
  134. #define GEN_VDATEIFACE( pv, retval ) if (!IsValidInterface(pv)) \
  135. return (retval)
  136. //** INTERFACE validation macros for single entry/single exit functions
  137. //** uses a goto instead of return
  138. #define GEN_VDATEIFACE_LABEL( pv, retval, label, retVar ) \
  139. if (!IsValidInterface(pv)) \
  140. { retVar = retval; \
  141. goto label; }
  142. #define VDATEIFACE_LABEL( pv, label, retVar ) \
  143. if (!IsValidInterface(pv)) \
  144. { retVar = ResultFromScode(E_INVALIDARG); \
  145. goto label; }
  146. #define VOID_VDATEIFACE_LABEL( pv, label ) \
  147. if (!IsValidInterface(pv)) {\
  148. goto label; }
  149. //** INTERFACE ID validation macro:
  150. // do not do in retail build. This code USED to call a bogus version of
  151. // IsValidIID that did no work. Now we are faster and no less stable than before.
  152. #define VDATEIID( iid ) ((void)0)
  153. #define GEN_VDATEIID( iid, retval ) ((void)0);
  154. //** INTERFACE ID validation macros for single entry/single exit functions
  155. //** uses a goto instead of return
  156. #define VDATEIID_LABEL( iid, label, retVar ) if (!IsValidIid( iid )) \
  157. {retVar = ResultFromScode(E_INVALIDARG); \
  158. goto label; }
  159. #define GEN_VDATEIID_LABEL( iid, retval, label, retVar ) if (!IsValidIid( iid )) {\
  160. retVar = retval; goto label; }
  161. #endif