diagnostics_win.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // This file is part of BOINC.
  2. // http://boinc.berkeley.edu
  3. // Copyright (C) 2008 University of California
  4. //
  5. // BOINC is free software; you can redistribute it and/or modify it
  6. // under the terms of the GNU Lesser General Public License
  7. // as published by the Free Software Foundation,
  8. // either version 3 of the License, or (at your option) any later version.
  9. //
  10. // BOINC is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. // See the GNU Lesser General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Lesser General Public License
  16. // along with BOINC. If not, see <http://www.gnu.org/licenses/>.
  17. #ifndef BOINC_DIAGNOSTICS_WIN_H
  18. #define BOINC_DIAGNOSTICS_WIN_H
  19. #include "boinc_win.h"
  20. #define STATUS_INFO_LENGTH_MISMATCH ((NTSTATUS)0xC0000004L)
  21. typedef LONG NTSTATUS;
  22. typedef LONG KPRIORITY;
  23. //MinGW-W64 defines this struct in its own header
  24. #if !defined(HAVE_CLIENT_ID) && !defined(__MINGW32__)
  25. typedef struct _CLIENT_ID {
  26. DWORD UniqueProcess;
  27. DWORD UniqueThread;
  28. } CLIENT_ID;
  29. #endif
  30. //MinGW-W64 defines this struct in its own header
  31. #if !defined(HAVE_VM_COUNTERS) && !defined(__MINGW32__)
  32. typedef struct _VM_COUNTERS {
  33. #ifdef _WIN64
  34. // the following was inferred by painful reverse engineering
  35. SIZE_T PeakVirtualSize; // not actually
  36. SIZE_T PageFaultCount;
  37. SIZE_T PeakWorkingSetSize;
  38. SIZE_T WorkingSetSize;
  39. SIZE_T QuotaPeakPagedPoolUsage;
  40. SIZE_T QuotaPagedPoolUsage;
  41. SIZE_T QuotaPeakNonPagedPoolUsage;
  42. SIZE_T QuotaNonPagedPoolUsage;
  43. SIZE_T PagefileUsage;
  44. SIZE_T PeakPagefileUsage;
  45. SIZE_T VirtualSize; // not actually
  46. #else
  47. SIZE_T PeakVirtualSize;
  48. SIZE_T VirtualSize;
  49. ULONG PageFaultCount;
  50. SIZE_T PeakWorkingSetSize;
  51. SIZE_T WorkingSetSize;
  52. SIZE_T QuotaPeakPagedPoolUsage;
  53. SIZE_T QuotaPagedPoolUsage;
  54. SIZE_T QuotaPeakNonPagedPoolUsage;
  55. SIZE_T QuotaNonPagedPoolUsage;
  56. SIZE_T PagefileUsage;
  57. SIZE_T PeakPagefileUsage;
  58. #endif
  59. } VM_COUNTERS;
  60. #endif
  61. //MinGW-W64 defines this struct in its own header
  62. #if !defined(HAVE_SYSTEM_THREADS) && !defined(__MINGW32__)
  63. typedef struct _SYSTEM_THREADS {
  64. LARGE_INTEGER KernelTime;
  65. LARGE_INTEGER UserTime;
  66. LARGE_INTEGER CreateTime;
  67. ULONG WaitTime;
  68. PVOID StartAddress;
  69. CLIENT_ID ClientId;
  70. KPRIORITY Priority;
  71. KPRIORITY BasePriority;
  72. ULONG ContextSwitchCount;
  73. LONG State;
  74. LONG WaitReason;
  75. } SYSTEM_THREADS, * PSYSTEM_THREADS;
  76. #endif
  77. #ifndef HAVE_SYSTEM_PROCESSES
  78. typedef struct _SYSTEM_PROCESSES {
  79. ULONG NextEntryDelta;
  80. ULONG ThreadCount;
  81. ULONG Reserved1[6];
  82. LARGE_INTEGER CreateTime;
  83. LARGE_INTEGER UserTime;
  84. LARGE_INTEGER KernelTime;
  85. UNICODE_STRING ProcessName;
  86. KPRIORITY BasePriority;
  87. #ifdef _WIN64
  88. ULONG pad1;
  89. ULONG ProcessId;
  90. ULONG pad2;
  91. ULONG InheritedFromProcessId;
  92. ULONG pad3, pad4, pad5;
  93. #else
  94. ULONG ProcessId;
  95. ULONG InheritedFromProcessId;
  96. #endif
  97. ULONG HandleCount;
  98. ULONG Reserved2[2];
  99. VM_COUNTERS VmCounters;
  100. IO_COUNTERS IoCounters;
  101. SYSTEM_THREADS Threads[1];
  102. } SYSTEM_PROCESSES, * PSYSTEM_PROCESSES;
  103. #endif
  104. //MinGW-W64 defines this struct in its own header
  105. #if !defined(HAVE_THREAD_STATE) && !defined(__MINGW32__)
  106. typedef enum _THREAD_STATE {
  107. StateInitialized,
  108. StateReady,
  109. StateRunning,
  110. StateStandby,
  111. StateTerminated,
  112. StateWait,
  113. StateTransition
  114. } THREAD_STATE, *PTHREAD_STATE;
  115. #endif
  116. #ifndef HAVE_THREAD_WAIT_REASON
  117. typedef enum _THREAD_WAIT_REASON {
  118. ThreadWaitReasonExecutive,
  119. ThreadWaitReasonFreePage,
  120. ThreadWaitReasonPageIn,
  121. ThreadWaitReasonPoolAllocation,
  122. ThreadWaitReasonDelayExecution,
  123. ThreadWaitReasonSuspended,
  124. ThreadWaitReasonUserRequest,
  125. ThreadWaitReasonWrExecutive,
  126. ThreadWaitReasonWrFreePage,
  127. ThreadWaitReasonWrPageIn,
  128. ThreadWaitReasonWrPoolAllocation,
  129. ThreadWaitReasonWrDelayExecution,
  130. ThreadWaitReasonWrSuspended,
  131. ThreadWaitReasonWrUserRequest,
  132. ThreadWaitReasonWrEventPairHigh,
  133. ThreadWaitReasonWrEventPairLow,
  134. ThreadWaitReasonWrLpcReceive,
  135. ThreadWaitReasonWrLpcReply,
  136. ThreadWaitReasonWrVirtualMemory,
  137. ThreadWaitReasonWrPageOut,
  138. ThreadWaitReasonMaximumWaitReason
  139. } THREAD_WAIT_REASON;
  140. #endif
  141. // older mingw versions (before 2012-07-12) do not define this in winternl.h
  142. #if defined(__MINGW32__)
  143. #ifndef NT_SUCCESS
  144. #define NT_SUCCESS(status) ((NTSTATUS) (status) >= 0)
  145. #endif
  146. #endif
  147. #endif