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.

213 lines
7.0 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name :
  4. randfail.h
  5. Abstract :
  6. This module contains macros used to instrument code for random failures
  7. Author :
  8. Sam Neely
  9. Revision History :
  10. --*/
  11. #if !defined(_WINDOWS_) && !defined(_WINBASE_)
  12. #error This file must be included after other header files
  13. #endif
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. // If this is a debug build, expose the fTimeToFail(g_TestTrace) entry
  18. // and a handful of utility macros
  19. #if defined(DEBUG)
  20. extern int __stdcall g_TestTrace(void);
  21. extern void __stdcall g_TestTraceEnable();
  22. extern void __stdcall g_TestTraceDisable();
  23. #define FAILURE_MACRO0(api,err,ret) \
  24. (g_TestTrace() ? SetLastError(err), ret : api())
  25. #define FAILURE_MACRO1(api,err,ret,arg1) \
  26. (g_TestTrace() ? SetLastError(err), ret : api(arg1))
  27. #define FAILURE_MACRO2(api,err,ret,arg1,arg2) \
  28. (g_TestTrace() ? SetLastError(err), ret : api(arg1,arg2))
  29. #define FAILURE_MACRO3(api,err,ret,arg1,arg2,arg3) \
  30. (g_TestTrace() ? SetLastError(err), ret : api(arg1,arg2,arg3))
  31. #define FAILURE_MACRO4(api,err,ret,arg1,arg2,arg3,arg4) \
  32. (g_TestTrace() ? SetLastError(err), ret : api(arg1,arg2,arg3,arg4))
  33. #define FAILURE_MACRO5(api,err,ret,arg1,arg2,arg3,arg4,arg5) \
  34. (g_TestTrace() ? SetLastError(err), ret : api(arg1,arg2,arg3,arg4,arg5))
  35. #define FAILURE_MACRO6(api,err,ret,arg1,arg2,arg3,arg4,arg5,arg6) \
  36. (g_TestTrace() ? SetLastError(err), ret : api(arg1,arg2,arg3,arg4,arg5,\
  37. arg6))
  38. #define FAILURE_MACRO7(api,err,ret,arg1,arg2,arg3,arg4,arg5, \
  39. arg6,arg7) \
  40. (g_TestTrace() ? SetLastError(err), ret : api(arg1,arg2,arg3,arg4,arg5,\
  41. arg6,arg7))
  42. #define FAILURE_MACRO8(api,err,ret,arg1,arg2,arg3,arg4,arg5, \
  43. arg6,arg7,arg8) \
  44. (g_TestTrace() ? SetLastError(err), ret : api(arg1,arg2,arg3,arg4,arg5,\
  45. arg6,arg7,arg8))
  46. #define FAILURE_MACRO9(api,err,ret,arg1,arg2,arg3,arg4,arg5, \
  47. arg6,arg7,arg8,arg9) \
  48. (g_TestTrace() ? SetLastError(err), ret : api(arg1,arg2,arg3,arg4,arg5,\
  49. arg6,arg7,arg8,arg9))
  50. #define FAILURE_MACRO10(api,err,ret,arg1,arg2,arg3,arg4,arg5, \
  51. arg6,arg7,arg8,arg9,arg10) \
  52. (g_TestTrace() ? SetLastError(err), ret : api(arg1,arg2,arg3,arg4,arg5,\
  53. arg6,arg7,arg8,arg9,arg10))
  54. #define RandFailDisable() g_TestTraceDisable()
  55. #define RandFailEnable() g_TestTraceEnable()
  56. #else // !DEBUG
  57. #define RandFailDisable() (void)0
  58. #define RandFailEnable() (void)0
  59. #endif
  60. #if defined(DEBUG) && !defined(NOFAIL_WIN32API)
  61. #define CreateDirectoryA(arg1,arg2) \
  62. FAILURE_MACRO2(CreateDirectoryA, ERROR_ARENA_TRASHED, 0, arg1, arg2)
  63. #define CreateDirectoryW(arg1,arg2) \
  64. FAILURE_MACRO2(CreateDirectoryW, ERROR_ARENA_TRASHED, 0, arg1, arg2)
  65. #define CreateDirectoryExA(arg1,arg2,arg3) \
  66. FAILURE_MACRO3(CreateDirectoryExA, ERROR_ARENA_TRASHED, 0, \
  67. arg1,arg2,arg3)
  68. #define CreateDirectoryExW(arg1,arg2,arg3) \
  69. FAILURE_MACRO3(CreateDirectoryExW, ERROR_ARENA_TRASHED, 0, \
  70. arg1,arg2,arg3)
  71. #define CreateEventA(arg1,arg2,arg3,arg4) \
  72. FAILURE_MACRO4(CreateEventA, ERROR_ARENA_TRASHED, NULL, \
  73. arg1,arg2,arg3,arg4)
  74. #define CreateEventW(arg1,arg2,arg3,arg4) \
  75. FAILURE_MACRO4(CreateEventW, ERROR_ARENA_TRASHED, NULL, \
  76. arg1,arg2,arg3,arg4)
  77. #define CreateFileA(arg1,arg2,arg3,arg4,arg5,arg6,arg7) \
  78. FAILURE_MACRO7(CreateFileA, ERROR_ARENA_TRASHED, INVALID_HANDLE_VALUE,\
  79. arg1,arg2,arg3,arg4,arg5,arg6,arg7)
  80. #define CreateFileW(arg1,arg2,arg3,arg4,arg5,arg6,arg7) \
  81. FAILURE_MACRO7(CreateFileW, ERROR_ARENA_TRASHED, INVALID_HANDLE_VALUE,\
  82. arg1,arg2,arg3,arg4,arg5,arg6,arg7)
  83. #define CreateFileMappingA(arg1,arg2,arg3,arg4,arg5,arg6) \
  84. FAILURE_MACRO6(CreateFileMappingA, ERROR_ARENA_TRASHED, NULL,\
  85. arg1,arg2,arg3,arg4,arg5,arg6)
  86. #define CreateFileMappingW(arg1,arg2,arg3,arg4,arg5,arg6) \
  87. FAILURE_MACRO6(CreateFileMappingW, ERROR_ARENA_TRASHED, NULL,\
  88. arg1,arg2,arg3,arg4,arg5,arg6)
  89. #define CreateIoCompletionPort(arg1,arg2,arg3,arg4) \
  90. FAILURE_MACRO4(CreateIoCompletionPort, ERROR_ARENA_TRASHED, NULL,\
  91. arg1,arg2,arg3,arg4)
  92. #define CreateMutexA(arg1,arg2,arg3) \
  93. FAILURE_MACRO3(CreateMutexA, ERROR_ARENA_TRASHED, NULL, \
  94. arg1,arg2,arg3)
  95. #define CreateMutexW(arg1,arg2,arg3) \
  96. FAILURE_MACRO3(CreateMutexW, ERROR_ARENA_TRASHED, NULL, \
  97. arg1,arg2,arg3)
  98. #define CreateProcessA(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10) \
  99. FAILURE_MACRO10(CreateProcessA, ERROR_ARENA_TRASHED, 0, \
  100. arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)
  101. #define CreateProcessW(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10) \
  102. FAILURE_MACRO10(CreateProcessW, ERROR_ARENA_TRASHED, 0, \
  103. arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)
  104. #define CreateSemaphoreA(arg1,arg2,arg3,arg4) \
  105. FAILURE_MACRO4(CreateSemaphoreA, ERROR_ARENA_TRASHED, NULL, \
  106. arg1,arg2,arg3,arg4)
  107. #define CreateSemaphoreW(arg1,arg2,arg3,arg4) \
  108. FAILURE_MACRO4(CreateSemaphoreW, ERROR_ARENA_TRASHED, NULL, \
  109. arg1,arg2,arg3,arg4)
  110. #define CreateThread(arg1,arg2,arg3,arg4,arg5,arg6) \
  111. FAILURE_MACRO6(CreateThread, ERROR_ARENA_TRASHED, NULL, \
  112. arg1,arg2,arg3,arg4,arg5,arg6)
  113. #define GetQueuedCompletionStatus(arg1,arg2,arg3,arg4,arg5) \
  114. FAILURE_MACRO5(GetQueuedCompletionStatus, ERROR_ARENA_TRASHED, NULL, \
  115. arg1,arg2,arg3,arg4,arg5)
  116. #define OpenEventA(arg1,arg2,arg3) \
  117. FAILURE_MACRO3(OpenEventA, ERROR_ARENA_TRASHED, NULL, \
  118. arg1,arg2,arg3)
  119. #define OpenEventW(arg1,arg2,arg3) \
  120. FAILURE_MACRO3(OpenEventW, ERROR_ARENA_TRASHED, NULL, \
  121. arg1,arg2,arg3)
  122. #define OpenFileMappingA(arg1,arg2,arg3) \
  123. FAILURE_MACRO3(OpenFileMappingA, ERROR_ARENA_TRASHED, NULL, \
  124. arg1,arg2,arg3)
  125. #define OpenFileMappingW(arg1,arg2,arg3) \
  126. FAILURE_MACRO3(OpenFileMappingW, ERROR_ARENA_TRASHED, NULL, \
  127. arg1,arg2,arg3)
  128. #define OpenMutexA(arg1,arg2,arg3) \
  129. FAILURE_MACRO3(OpenMutexA, ERROR_ARENA_TRASHED, NULL, \
  130. arg1,arg2,arg3)
  131. #define OpenMutexW(arg1,arg2,arg3) \
  132. FAILURE_MACRO3(OpenMutexW, ERROR_ARENA_TRASHED, NULL, \
  133. arg1,arg2,arg3)
  134. #define OpenProcess(arg1,arg2,arg3) \
  135. FAILURE_MACRO3(OpenProcess, ERROR_ARENA_TRASHED, NULL, \
  136. arg1,arg2,arg3)
  137. #define OpenSemaphoreA(arg1,arg2,arg3) \
  138. FAILURE_MACRO3(OpenSemaphoreA, ERROR_ARENA_TRASHED, NULL, \
  139. arg1,arg2,arg3)
  140. #define OpenSemaphoreW(arg1,arg2,arg3) \
  141. FAILURE_MACRO3(OpenSemaphoreW, ERROR_ARENA_TRASHED, NULL, \
  142. arg1,arg2,arg3)
  143. #define PostQueuedCompletionStatus(arg1,arg2,arg3,arg4) \
  144. FAILURE_MACRO4(PostQueuedCompletionStatus, ERROR_ARENA_TRASHED, 0, \
  145. arg1,arg2,arg3,arg4)
  146. #define ReadFile(arg1,arg2,arg3,arg4,arg5) \
  147. FAILURE_MACRO5(ReadFile, ERROR_ARENA_TRASHED, 0, \
  148. arg1,arg2,arg3,arg4,arg5)
  149. #define WriteFile(arg1,arg2,arg3,arg4,arg5) \
  150. FAILURE_MACRO5(WriteFile, ERROR_ARENA_TRASHED, 0, \
  151. arg1,arg2,arg3,arg4,arg5)
  152. #endif
  153. #if defined(DEBUG) && !defined(NOFAIL_RANDOM)
  154. #define fTimeToFail() g_TestTrace()
  155. #else
  156. #define fTimeToFail() (0)
  157. #endif
  158. #ifdef __cplusplus
  159. }
  160. #endif