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.

187 lines
7.2 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 2001 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: HandleTracking.h
  6. * Content: Handle Tracking Header File
  7. *
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 10/31/2001 masonb Created
  12. *
  13. ***************************************************************************/
  14. #ifndef __HANDLETRACKING_H__
  15. #define __HANDLETRACKING_H__
  16. #ifdef DBG
  17. BOOL DNHandleTrackInitialize();
  18. VOID DNHandleTrackDeinitialize();
  19. BOOL DNHandleTrackDumpLeaks();
  20. enum HandleType
  21. {
  22. TypeEvent,
  23. TypeMutex,
  24. TypeSemaphore,
  25. TypeFile,
  26. TypeFileMap, // not used when DPNBUILD_SINGLEPROCESS defined
  27. TypeThread,
  28. TypeProcess, // not used when DPNBUILD_SINGLEPROCESS defined
  29. TypeSpecial
  30. };
  31. struct TRACKED_HANDLE
  32. {
  33. HANDLE handle;
  34. HandleType type;
  35. CBilink blHandle;
  36. CCallStack AllocCallStack;
  37. };
  38. typedef TRACKED_HANDLE* DNHANDLE;
  39. #define DNINVALID_HANDLE_VALUE ((DNHANDLE)INVALID_HANDLE_VALUE)
  40. #ifndef DPNBUILD_SINGLEPROCESS
  41. struct DNPROCESS_INFORMATION
  42. {
  43. DNHANDLE hProcess;
  44. DNHANDLE hThread;
  45. DWORD dwProcessId;
  46. DWORD dwThreadId;
  47. };
  48. #endif // ! DPNBUILD_SINGLEPROCESS
  49. DNHANDLE DNHandleTrackMakeDNHANDLE(HANDLE h);
  50. VOID DNHandleTrackRemoveDNHANDLE(DNHANDLE dnh);
  51. HANDLE DNHandleTrackHandleFromDNHANDLE(DNHANDLE h);
  52. #ifndef DPNBUILD_SINGLEPROCESS
  53. BOOL DNHandleTrackCreateProcess(LPCTSTR lpApplicationName, LPTSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCTSTR lpCurrentDirectory, LPSTARTUPINFO lpStartupInfo, DNPROCESS_INFORMATION* lpProcessInformation);
  54. DNHANDLE DNHandleTrackOpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId);
  55. #endif // ! DPNBUILD_SINGLEPROCESS
  56. DNHANDLE DNHandleTrackCreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes, DWORD dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId);
  57. DNHANDLE DNHandleTrackCreateEvent(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPCTSTR lpName);
  58. DNHANDLE DNHandleTrackOpenEvent(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCTSTR lpName);
  59. BOOL DNHandleTrackSetEvent(DNHANDLE hHandle);
  60. BOOL DNHandleTrackResetEvent(DNHANDLE hHandle);
  61. DNHANDLE DNHandleTrackCreateMutex(LPSECURITY_ATTRIBUTES lpMutexAttributes, BOOL bInitialOwner, LPCTSTR lpName);
  62. DNHANDLE DNHandleTrackOpenMutex(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCTSTR lpName);
  63. BOOL DNHandleTrackReleaseMutex(DNHANDLE hHandle);
  64. DNHANDLE DNHandleTrackCreateSemaphore(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, LONG lInitialCount, LONG lMaximumCount, LPCTSTR lpName);
  65. BOOL DNHandleTrackReleaseSemaphore(DNHANDLE hSemaphore, LONG lReleaseCount, LPLONG lpPreviousCount);
  66. DNHANDLE DNHandleTrackCreateFile(LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
  67. #ifndef DPNBUILD_SINGLEPROCESS
  68. DNHANDLE DNHandleTrackCreateFileMapping(HANDLE hFile, LPSECURITY_ATTRIBUTES lpAttributes, DWORD flProtect, DWORD dwMaximumSizeHigh, DWORD dwMaximumSizeLow, LPCTSTR lpName);
  69. DNHANDLE DNHandleTrackOpenFileMapping(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCTSTR lpName);
  70. BOOL DNHandleTrackGetExitCodeProcess(DNHANDLE hHandle, LPDWORD lpExitCode);
  71. #endif // ! DPNBUILD_SINGLEPROCESS
  72. DWORD DNHandleTrackWaitForSingleObject(DNHANDLE hHandle, DWORD dwMilliseconds);
  73. DWORD DNHandleTrackWaitForSingleObjectEx(DNHANDLE hHandle, DWORD dwMilliseconds, BOOL bAlertable);
  74. DWORD DNHandleTrackWaitForMultipleObjects(DWORD nCount, CONST DNHANDLE *lpHandles, BOOL fWaitAll, DWORD dwMilliseconds);
  75. DWORD DNHandleTrackWaitForMultipleObjectsEx(DWORD nCount, CONST DNHANDLE *lpHandles, BOOL fWaitAll, DWORD dwMilliseconds, BOOL bAlertable);
  76. DWORD DNHandleTrackSignalObjectAndWait(DNHANDLE hObjectToSignal, DNHANDLE hObjectToWaitOn, DWORD dwMilliseconds, BOOL bAlertable);
  77. BOOL DNHandleTrackCloseHandle(DNHANDLE hHandle);
  78. #define MAKE_DNHANDLE(x) DNHandleTrackMakeDNHANDLE(x)
  79. #define REMOVE_DNHANDLE(x) DNHandleTrackRemoveDNHANDLE(x)
  80. #define HANDLE_FROM_DNHANDLE(x) DNHandleTrackHandleFromDNHANDLE(x)
  81. #define DNCreateProcess DNHandleTrackCreateProcess
  82. #define DNOpenProcess DNHandleTrackOpenProcess
  83. #define DNCreateThread DNHandleTrackCreateThread
  84. #define DNCreateEvent DNHandleTrackCreateEvent
  85. #define DNOpenEvent DNHandleTrackOpenEvent
  86. #define DNSetEvent DNHandleTrackSetEvent
  87. #define DNResetEvent DNHandleTrackResetEvent
  88. #define DNCreateMutex DNHandleTrackCreateMutex
  89. #define DNOpenMutex DNHandleTrackOpenMutex
  90. #define DNReleaseMutex DNHandleTrackReleaseMutex
  91. #define DNCreateSemaphore DNHandleTrackCreateSemaphore
  92. #define DNReleaseSemaphore DNHandleTrackReleaseSemaphore
  93. #define DNGetExitCodeProcess DNHandleTrackGetExitCodeProcess
  94. #define DNCreateFile DNHandleTrackCreateFile
  95. #define DNCreateFileMapping DNHandleTrackCreateFileMapping
  96. #define DNOpenFileMapping DNHandleTrackOpenFileMapping
  97. #define DNWaitForSingleObject DNHandleTrackWaitForSingleObject
  98. #define DNWaitForSingleObjectEx DNHandleTrackWaitForSingleObjectEx
  99. #define DNWaitForMultipleObjects DNHandleTrackWaitForMultipleObjects
  100. #define DNWaitForMultipleObjectsEx DNHandleTrackWaitForMultipleObjectsEx
  101. #define DNSignalObjectAndWait DNHandleTrackSignalObjectAndWait
  102. #define DNCloseHandle DNHandleTrackCloseHandle
  103. #else // !DBG
  104. #define DNInitializeHandleTracking() TRUE
  105. #define DNDeinitializeHandleTracking()
  106. #define DNDumpLeakedHandles() FALSE
  107. #define DNHANDLE HANDLE
  108. #define DNINVALID_HANDLE_VALUE INVALID_HANDLE_VALUE
  109. #define MAKE_DNHANDLE(x) x
  110. #define REMOVE_DNHANDLE(x)
  111. #define HANDLE_FROM_DNHANDLE(x) x
  112. #ifndef DPNBUILD_SINGLEPROCESS
  113. #define DNPROCESS_INFORMATION PROCESS_INFORMATION
  114. #define DNCreateProcess CreateProcess
  115. #define DNOpenProcess OpenProcess
  116. #endif // ! DPNBUILD_SINGLEPROCESS
  117. #define DNCreateThread CreateThread
  118. #define DNCreateEvent CreateEvent
  119. #define DNOpenEvent OpenEvent
  120. #define DNSetEvent SetEvent
  121. #define DNResetEvent ResetEvent
  122. #define DNCreateMutex CreateMutex
  123. #define DNOpenMutex OpenMutex
  124. #define DNReleaseMutex ReleaseMutex
  125. #define DNCreateSemaphore CreateSemaphore
  126. #define DNReleaseSemaphore ReleaseSemaphore
  127. #define DNCreateFile CreateFile
  128. #ifndef DPNBUILD_SINGLEPROCESS
  129. #define DNCreateFileMapping CreateFileMapping
  130. #define DNOpenFileMapping OpenFileMapping
  131. #define DNGetExitCodeProcess GetExitCodeProcess
  132. #endif // ! DPNBUILD_SINGLEPROCESS
  133. #define DNWaitForSingleObject WaitForSingleObject
  134. #define DNWaitForSingleObjectEx WaitForSingleObjectEx
  135. #define DNWaitForMultipleObjects WaitForMultipleObjects
  136. #define DNWaitForMultipleObjectsEx WaitForMultipleObjectsEx
  137. #ifdef WINNT
  138. #define DNSignalObjectAndWait SignalObjectAndWait
  139. #else // ! WINNT
  140. #define DNSignalObjectAndWait(hObjectToSignal, hObjectToWaitOn, dwMilliseconds, bAlertable) SetEvent(hObjectToSignal),WaitForSingleObjectEx(hObjectToWaitOn, dwMilliseconds, bAlertable)
  141. #endif // ! WINNT
  142. #define DNCloseHandle CloseHandle
  143. #endif // DBG
  144. #endif // __HANDLETRACKING_H__