1 /***********************************************************************\
2 *                                psapi.d                                *
3 *                                                                       *
4 *                       Windows API header module                       *
5 *                                                                       *
6 *                 Translated from MinGW Windows headers                 *
7 *                                                                       *
8 *                       Placed into public domain                       *
9 \***********************************************************************/
10 /* Comment from MinGW
11  *   Process status API (PSAPI)
12  *   http://windowssdk.msdn.microsoft.com/library/ms684884.aspx
13  */
14 
15 module windows.psapi;
16 nothrow:
17 private import windows.w32api;
18 private import windows.winbase;
19 private import windows.windef;
20 
21 struct MODULEINFO {
22 	LPVOID lpBaseOfDll;
23 	DWORD SizeOfImage;
24 	LPVOID EntryPoint;
25 }
26 alias MODULEINFO* LPMODULEINFO;
27 
28 struct PSAPI_WS_WATCH_INFORMATION {
29 	LPVOID FaultingPc;
30 	LPVOID FaultingVa;
31 }
32 alias PSAPI_WS_WATCH_INFORMATION* PPSAPI_WS_WATCH_INFORMATION;
33 
34 struct PSAPI_WS_WATCH_INFORMATION_EX {
35 	PSAPI_WS_WATCH_INFORMATION BasicInfo;
36 	ULONG_PTR FaultingThreadId;
37 	ULONG_PTR Flags;
38 }
39 alias PSAPI_WS_WATCH_INFORMATION_EX* PPSAPI_WS_WATCH_INFORMATION_EX;
40 
41 struct PROCESS_MEMORY_COUNTERS {
42 	DWORD cb = PROCESS_MEMORY_COUNTERS.sizeof;
43 	DWORD PageFaultCount;
44 	SIZE_T PeakWorkingSetSize;
45 	SIZE_T WorkingSetSize;
46 	SIZE_T QuotaPeakPagedPoolUsage;
47 	SIZE_T QuotaPagedPoolUsage;
48 	SIZE_T QuotaPeakNonPagedPoolUsage;
49 	SIZE_T QuotaNonPagedPoolUsage;
50 	SIZE_T PagefileUsage;
51 	SIZE_T PeakPagefileUsage;
52 }
53 alias PROCESS_MEMORY_COUNTERS* PPROCESS_MEMORY_COUNTERS;
54 
55 struct PERFORMANCE_INFORMATION {
56 	DWORD cb;
57 	SIZE_T CommitTotal;
58 	SIZE_T CommitLimit;
59 	SIZE_T CommitPeak;
60 	SIZE_T PhysicalTotal;
61 	SIZE_T PhysicalAvailable;
62 	SIZE_T SystemCache;
63 	SIZE_T KernelTotal;
64 	SIZE_T KernelPaged;
65 	SIZE_T KernelNonpaged;
66 	SIZE_T PageSize;
67 	DWORD HandleCount;
68 	DWORD ProcessCount;
69 	DWORD ThreadCount;
70 }
71 alias PERFORMANCE_INFORMATION* PPERFORMANCE_INFORMATION;
72 
73 struct ENUM_PAGE_FILE_INFORMATION {
74 	DWORD cb;
75 	DWORD Reserved;
76 	SIZE_T TotalSize;
77 	SIZE_T TotalInUse;
78 	SIZE_T PeakUsage;
79 }
80 alias ENUM_PAGE_FILE_INFORMATION* PENUM_PAGE_FILE_INFORMATION;
81 
82 /* application-defined callback function used with the EnumPageFiles()
83  * http://windowssdk.msdn.microsoft.com/library/ms682627.aspx */
84 version (Unicode) {
85 	alias BOOL function(LPVOID, PENUM_PAGE_FILE_INFORMATION, LPCWSTR)
86 	  PENUM_PAGE_FILE_CALLBACK;
87 } else {
88 	alias BOOL function(LPVOID, PENUM_PAGE_FILE_INFORMATION, LPCSTR)
89 	  PENUM_PAGE_FILE_CALLBACK;
90 }
91 
92 // Grouped by application, not in alphabetical order.
93 extern (Windows) {
94 	/* Process Information
95 	 * http://windowssdk.msdn.microsoft.com/library/ms684870.aspx */
96 	BOOL EnumProcesses(DWORD*, DWORD, DWORD*); /* NT/2000/XP/Server2003/Vista/Longhorn */
97 	DWORD GetProcessImageFileNameA(HANDLE, LPSTR, DWORD); /* XP/Server2003/Vista/Longhorn */
98 	DWORD GetProcessImageFileNameW(HANDLE, LPWSTR, DWORD); /* XP/Server2003/Vista/Longhorn */
99 
100 	/* Module Information
101 	 * http://windowssdk.msdn.microsoft.com/library/ms684232.aspx */
102 	BOOL EnumProcessModules(HANDLE, HMODULE*, DWORD, LPDWORD);
103 	BOOL EnumProcessModulesEx(HANDLE, HMODULE*, DWORD, LPDWORD, DWORD); /* Vista/Longhorn */
104 	DWORD GetModuleBaseNameA(HANDLE, HMODULE, LPSTR, DWORD);
105 	DWORD GetModuleBaseNameW(HANDLE, HMODULE, LPWSTR, DWORD);
106 	DWORD GetModuleFileNameExA(HANDLE, HMODULE, LPSTR, DWORD);
107 	DWORD GetModuleFileNameExW(HANDLE, HMODULE, LPWSTR, DWORD);
108 	BOOL GetModuleInformation(HANDLE, HMODULE, LPMODULEINFO, DWORD);
109 
110 	/* Device Driver Information
111 	 * http://windowssdk.msdn.microsoft.com/library/ms682578.aspx */
112 	BOOL EnumDeviceDrivers(LPVOID*, DWORD, LPDWORD);
113 	DWORD GetDeviceDriverBaseNameA(LPVOID, LPSTR, DWORD);
114 	DWORD GetDeviceDriverBaseNameW(LPVOID, LPWSTR, DWORD);
115 	DWORD GetDeviceDriverFileNameA(LPVOID, LPSTR, DWORD);
116 	DWORD GetDeviceDriverFileNameW(LPVOID, LPWSTR, DWORD);
117 
118 	/* Process Memory Usage Information
119 	 * http://windowssdk.msdn.microsoft.com/library/ms684879.aspx */
120 	BOOL GetProcessMemoryInfo(HANDLE, PPROCESS_MEMORY_COUNTERS, DWORD);
121 
122 	/* Working Set Information
123 	 * http://windowssdk.msdn.microsoft.com/library/ms687398.aspx */
124 	BOOL EmptyWorkingSet(HANDLE);
125 	BOOL GetWsChanges(HANDLE, PPSAPI_WS_WATCH_INFORMATION, DWORD);
126 	BOOL GetWsChangesEx(HANDLE, PPSAPI_WS_WATCH_INFORMATION_EX, DWORD); /* Vista/Longhorn */
127 	BOOL InitializeProcessForWsWatch(HANDLE);
128 	BOOL QueryWorkingSet(HANDLE, PVOID, DWORD);
129 	BOOL QueryWorkingSetEx(HANDLE, PVOID, DWORD);
130 
131 	/* Memory-Mapped File Information
132 	 * http://windowssdk.msdn.microsoft.com/library/ms684212.aspx */
133 	DWORD GetMappedFileNameW(HANDLE, LPVOID, LPWSTR, DWORD);
134 	DWORD GetMappedFileNameA(HANDLE, LPVOID, LPSTR, DWORD);
135 
136 	/* Resources Information */
137 	BOOL GetPerformanceInfo(PPERFORMANCE_INFORMATION, DWORD); /* XP/Server2003/Vista/Longhorn */
138 	BOOL EnumPageFilesW(PENUM_PAGE_FILE_CALLBACK, LPVOID); /* 2000/XP/Server2003/Vista/Longhorn */
139 	BOOL EnumPageFilesA(PENUM_PAGE_FILE_CALLBACK, LPVOID); /* 2000/XP/Server2003/Vista/Longhorn */
140 }
141 
142 version (Unicode) {
143 	alias GetModuleBaseNameW GetModuleBaseName;
144 	alias GetModuleFileNameExW GetModuleFileNameEx;
145 	alias GetMappedFileNameW GetMappedFileName;
146 	alias GetDeviceDriverBaseNameW GetDeviceDriverBaseName;
147 	alias GetDeviceDriverFileNameW GetDeviceDriverFileName;
148 	alias EnumPageFilesW EnumPageFiles;
149 	alias GetProcessImageFileNameW GetProcessImageFileName;
150 } else {
151 	alias GetModuleBaseNameA GetModuleBaseName;
152 	alias GetModuleFileNameExA GetModuleFileNameEx;
153 	alias GetMappedFileNameA GetMappedFileName;
154 	alias GetDeviceDriverBaseNameA GetDeviceDriverBaseName;
155 	alias GetDeviceDriverFileNameA GetDeviceDriverFileName;
156 	alias EnumPageFilesA EnumPageFiles;
157 	alias GetProcessImageFileNameA GetProcessImageFileName;
158 }