fspr_dbg_win32_handles.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef APR_DBG_WIN32_HANDLES_H
  17. #define APR_DBG_WIN32_HANDLES_H
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. /* USAGE:
  22. *
  23. * Add the following include to fspr_private.h for internal debugging,
  24. * or copy this header into apr/include add the include below to apr.h
  25. * for really global debugging;
  26. *
  27. * #include "fspr_dbg_win32_handles.h"
  28. *
  29. * fspr_dbg_log is the crux of this function ... it uses Win32 API and
  30. * no apr calls itself to log all activity to a file named for the
  31. * executing application with a .pid suffix. Ergo several instances
  32. * may be executing and logged at once.
  33. *
  34. * HANDLE fspr_dbg_log(char* fn, HANDLE ha, char* fl, int ln, int nh
  35. * [, HANDLE *hv, char *dsc...])
  36. *
  37. * returns: the handle passed in ha, which is cast back to the real return type.
  38. *
  39. * formats one line into the debug log file if nh is zero;
  40. * ha (hex) seq(hex) tid(hex) fn fl ln
  41. * xxxxxxxx xxxxxxxx xxxxxxxx func() sourcefile:lineno
  42. * The macro fspr_dbg_rv makes this simple to implement for many APIs
  43. * that simply take args that don't interest us, and return a handle.
  44. *
  45. * formats multiple lines (nh) into the debug log file for each hv/dsc pair
  46. * (nh must correspond to the number of pairs);
  47. * hv (hex) seq(hex) tid(hex) fn dsc fl ln
  48. * xxxxxxxx xxxxxxxx xxxxxxxx func(arg) sourcefile:lineno
  49. * In this later usage, hv is the still the return value but is not
  50. * treated as a handle.
  51. */
  52. APR_DECLARE_NONSTD(HANDLE) fspr_dbg_log(char* fn, HANDLE ha, char* fl, int ln,
  53. int nh,/* HANDLE *hv, char *dsc */...);
  54. #define fspr_dbg_rv(fn, args) (fspr_dbg_log(#fn,(fn) args,__FILE__,__LINE__,0))
  55. #define CloseHandle(h) \
  56. ((BOOL)fspr_dbg_log("CloseHandle", \
  57. (HANDLE)(CloseHandle)(h), \
  58. __FILE__,__LINE__,1, \
  59. &(h),""))
  60. #define CreateEventA(sd,b1,b2,nm) fspr_dbg_rv(CreateEventA,(sd,b1,b2,nm))
  61. #define CreateEventW(sd,b1,b2,nm) fspr_dbg_rv(CreateEventW,(sd,b1,b2,nm))
  62. #define CreateFileA(nm,d1,d2,sd,d3,d4,h) fspr_dbg_rv(CreateFileA,(nm,d1,d2,sd,d3,d4,h))
  63. #define CreateFileW(nm,d1,d2,sd,d3,d4,h) fspr_dbg_rv(CreateFileW,(nm,d1,d2,sd,d3,d4,h))
  64. #define CreateFileMappingA(fh,sd,d1,d2,d3,nm) fspr_dbg_rv(CreateFileMappingA,(fh,sd,d1,d2,d3,nm))
  65. #define CreateFileMappingW(fh,sd,d1,d2,d3,nm) fspr_dbg_rv(CreateFileMappingW,(fh,sd,d1,d2,d3,nm))
  66. #define CreateMutexA(sd,b,nm) fspr_dbg_rv(CreateMutexA,(sd,b,nm))
  67. #define CreateMutexW(sd,b,nm) fspr_dbg_rv(CreateMutexW,(sd,b,nm))
  68. #define CreateIoCompletionPort(h1,h2,pd1,d2) fspr_dbg_rv(CreateIoCompletionPort,(h1,h2,pd1,d2))
  69. #define CreateNamedPipeA(nm,d1,d2,d3,d4,d5,d6,sd) fspr_dbg_rv(CreateNamedPipeA,(nm,d1,d2,d3,d4,d5,d6,sd))
  70. #define CreateNamedPipeW(nm,d1,d2,d3,d4,d5,d6,sd) fspr_dbg_rv(CreateNamedPipeW,(nm,d1,d2,d3,d4,d5,d6,sd))
  71. #define CreatePipe(ph1,ph2,sd,d) \
  72. ((BOOL)fspr_dbg_log("CreatePipe", \
  73. (HANDLE)(CreatePipe)(ph1,ph2,sd,d), \
  74. __FILE__,__LINE__,2, \
  75. (ph1),"hRead", \
  76. (ph2),"hWrite"))
  77. #define CreateProcessA(s1,s2,sd1,sd2,b,d1,s3,s4,pd2,hr) \
  78. ((BOOL)fspr_dbg_log("CreateProcessA", \
  79. (HANDLE)(CreateProcessA)(s1,s2,sd1,sd2,b,d1,s3,s4,pd2,hr), \
  80. __FILE__,__LINE__,2, \
  81. &((hr)->hProcess),"hProcess", \
  82. &((hr)->hThread),"hThread"))
  83. #define CreateProcessW(s1,s2,sd1,sd2,b,d1,s3,s4,pd2,hr) \
  84. ((BOOL)fspr_dbg_log("CreateProcessW", \
  85. (HANDLE)(CreateProcessW)(s1,s2,sd1,sd2,b,d1,s3,s4,pd2,hr), \
  86. __FILE__,__LINE__,2, \
  87. &((hr)->hProcess),"hProcess", \
  88. &((hr)->hThread),"hThread"))
  89. #define CreateSemaphoreA(sd,d1,d2,nm) fspr_dbg_rv(CreateSemaphoreA,(sd,d1,d2,nm))
  90. #define CreateSemaphoreW(sd,d1,d2,nm) fspr_dbg_rv(CreateSemaphoreW,(sd,d1,d2,nm))
  91. #define CreateThread(sd,d1,fn,pv,d2,pd3) fspr_dbg_rv(CreateThread,(sd,d1,fn,pv,d2,pd3))
  92. #define DeregisterEventSource(h) \
  93. ((BOOL)fspr_dbg_log("DeregisterEventSource", \
  94. (HANDLE)(DeregisterEventSource)(h), \
  95. __FILE__,__LINE__,1, \
  96. &(h),""))
  97. #define DuplicateHandle(h1,h2,h3,ph4,d1,b,d2) \
  98. ((BOOL)fspr_dbg_log("DuplicateHandle", \
  99. (HANDLE)(DuplicateHandle)(h1,h2,h3,ph4,d1,b,d2), \
  100. __FILE__,__LINE__,2, \
  101. (ph4),((h3)==GetCurrentProcess()) \
  102. ? "Target" : "EXTERN Target", \
  103. &(h2),((h1)==GetCurrentProcess()) \
  104. ? "Source" : "EXTERN Source"))
  105. #define GetCurrentProcess() \
  106. (fspr_dbg_log("GetCurrentProcess", \
  107. (GetCurrentProcess)(),__FILE__,__LINE__,0))
  108. #define GetCurrentThread() \
  109. (fspr_dbg_log("GetCurrentThread", \
  110. (GetCurrentThread)(),__FILE__,__LINE__,0))
  111. #define GetModuleHandleA(nm) fspr_dbg_rv(GetModuleHandleA,(nm))
  112. #define GetModuleHandleW(nm) fspr_dbg_rv(GetModuleHandleW,(nm))
  113. #define GetStdHandle(d) fspr_dbg_rv(GetStdHandle,(d))
  114. #define LoadLibraryA(nm) fspr_dbg_rv(LoadLibraryA,(nm))
  115. #define LoadLibraryW(nm) fspr_dbg_rv(LoadLibraryW,(nm))
  116. #define LoadLibraryExA(nm,h,d) fspr_dbg_rv(LoadLibraryExA,(nm,h,d))
  117. #define LoadLibraryExW(nm,h,d) fspr_dbg_rv(LoadLibraryExW,(nm,h,d))
  118. #define OpenEventA(d,b,nm) fspr_dbg_rv(OpenEventA,(d,b,nm))
  119. #define OpenEventW(d,b,nm) fspr_dbg_rv(OpenEventW,(d,b,nm))
  120. #define OpenFileMappingA(d,b,nm) fspr_dbg_rv(OpenFileMappingA,(d,b,nm))
  121. #define OpenFileMappingW(d,b,nm) fspr_dbg_rv(OpenFileMappingW,(d,b,nm))
  122. #define RegisterEventSourceA(s1,s2) fspr_dbg_rv(RegisterEventSourceA,(s1,s2))
  123. #define RegisterEventSourceW(s1,s2) fspr_dbg_rv(RegisterEventSourceW,(s1,s2))
  124. #define SetEvent(h) \
  125. ((BOOL)fspr_dbg_log("SetEvent", \
  126. (HANDLE)(SetEvent)(h), \
  127. __FILE__,__LINE__,1, \
  128. &(h),""))
  129. #define SetStdHandle(d,h) \
  130. ((BOOL)fspr_dbg_log("SetStdHandle", \
  131. (HANDLE)(SetStdHandle)(d,h), \
  132. __FILE__,__LINE__,1,&(h),""))
  133. #define socket(i1,i2,i3) \
  134. ((SOCKET)fspr_dbg_log("socket", \
  135. (HANDLE)(socket)(i1,i2,i3), \
  136. __FILE__,__LINE__,0))
  137. #define WaitForSingleObject(h,d) \
  138. ((DWORD)fspr_dbg_log("WaitForSingleObject", \
  139. (HANDLE)(WaitForSingleObject)(h,d), \
  140. __FILE__,__LINE__,1,&(h),"Signaled"))
  141. #define WaitForSingleObjectEx(h,d,b) \
  142. ((DWORD)fspr_dbg_log("WaitForSingleObjectEx", \
  143. (HANDLE)(WaitForSingleObjectEx)(h,d,b), \
  144. __FILE__,__LINE__,1,&(h),"Signaled"))
  145. #define WaitForMultipleObjects(d1,ah,b,d2) \
  146. ((DWORD)fspr_dbg_log("WaitForMultipleObjects", \
  147. (HANDLE)(WaitForMultipleObjects)(d1,ah,b,d2), \
  148. __FILE__,__LINE__,1,ah,"Signaled"))
  149. #define WaitForMultipleObjectsEx(d1,ah,b1,d2,b2) \
  150. ((DWORD)fspr_dbg_log("WaitForMultipleObjectsEx", \
  151. (HANDLE)(WaitForMultipleObjectsEx)(d1,ah,b1,d2,b2), \
  152. __FILE__,__LINE__,1,ah,"Signaled"))
  153. #define WSASocketA(i1,i2,i3,pi,g,dw) \
  154. ((SOCKET)fspr_dbg_log("WSASocketA", \
  155. (HANDLE)(WSASocketA)(i1,i2,i3,pi,g,dw), \
  156. __FILE__,__LINE__,0))
  157. #define WSASocketW(i1,i2,i3,pi,g,dw) \
  158. ((SOCKET)fspr_dbg_log("WSASocketW", \
  159. (HANDLE)(WSASocketW)(i1,i2,i3,pi,g,dw), \
  160. __FILE__,__LINE__,0))
  161. #define closesocket(sh) \
  162. ((int)fspr_dbg_log("closesocket", \
  163. (HANDLE)(closesocket)(sh), \
  164. __FILE__,__LINE__,1,&(sh),""))
  165. #define _beginthread(fn,d,pv) \
  166. ((unsigned long)fspr_dbg_log("_beginthread", \
  167. (HANDLE)(_beginthread)(fn,d,pv), \
  168. __FILE__,__LINE__,0))
  169. #define _beginthreadex(sd,d1,fn,pv,d2,pd3) \
  170. ((unsigned long)fspr_dbg_log("_beginthreadex", \
  171. (HANDLE)(_beginthreadex)(sd,d1,fn,pv,d2,pd3), \
  172. __FILE__,__LINE__,0))
  173. #ifdef __cplusplus
  174. }
  175. #endif
  176. #endif /* !defined(APR_DBG_WIN32_HANDLES_H) */