Removed trailing whitespace.
[wine] / dlls / psapi / psapi_main.c
1 /*
2  *      PSAPI library
3  *
4  *      Copyright 1998  Patrik Stridvall
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "winbase.h"
22 #include "windef.h"
23 #include "winerror.h"
24 #include "wine/server.h"
25 #include "wine/debug.h"
26 #include "tlhelp32.h"
27 #include "psapi.h"
28
29 WINE_DEFAULT_DEBUG_CHANNEL(psapi);
30
31 #include <string.h>
32
33
34 /***********************************************************************
35  *      get pid from hProcess (internal)
36  */
37 static DWORD get_pid_from_process_handle(HANDLE hProcess)
38 {
39         DWORD ret = 0;
40
41         SERVER_START_REQ( get_process_info )
42         {
43                 req->handle = hProcess;
44                 if ( !wine_server_call_err( req ) )
45                         ret = (DWORD)reply->pid;
46         }
47         SERVER_END_REQ;
48
49         return ret;
50 }
51
52 /***********************************************************************
53  *           EmptyWorkingSet (PSAPI.@)
54  */
55 BOOL WINAPI EmptyWorkingSet(HANDLE hProcess)
56 {
57   return SetProcessWorkingSetSize(hProcess, 0xFFFFFFFF, 0xFFFFFFFF);
58 }
59
60 /***********************************************************************
61  *           EnumDeviceDrivers (PSAPI.@)
62  */
63 BOOL WINAPI EnumDeviceDrivers(
64   LPVOID *lpImageBase, DWORD cb, LPDWORD lpcbNeeded)
65 {
66   FIXME("(%p, %ld, %p): stub\n", lpImageBase, cb, lpcbNeeded);
67
68   if(lpcbNeeded)
69     *lpcbNeeded = 0;
70
71   return TRUE;
72 }
73
74
75 /***********************************************************************
76  *           EnumProcesses (PSAPI.@)
77  */
78 BOOL WINAPI EnumProcesses(DWORD *lpidProcess, DWORD cb, DWORD *lpcbNeeded)
79 {
80         PROCESSENTRY32  pe;
81         HANDLE  hSnapshot;
82         BOOL    res;
83         DWORD   count;
84         DWORD   countMax;
85
86         FIXME("(%p, %ld, %p)\n", lpidProcess,cb, lpcbNeeded);
87
88         if ( lpidProcess == NULL )
89                 cb = 0;
90         if ( lpcbNeeded != NULL )
91                 *lpcbNeeded = 0;
92
93         hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
94         if ( hSnapshot == INVALID_HANDLE_VALUE )
95         {
96                 FIXME("cannot create snapshot\n");
97                 return FALSE;
98         }
99         count = 0;
100         countMax = cb / sizeof(DWORD);
101         while (1)
102         {
103                 ZeroMemory( &pe, sizeof(PROCESSENTRY32) );
104                 pe.dwSize = sizeof(PROCESSENTRY32);
105                 res = (count == 0) ? Process32First( hSnapshot, &pe ) : Process32Next( hSnapshot, &pe );
106                 if ( !res )
107                         break;
108                 TRACE("process 0x%08lx\n",(long)pe.th32ProcessID);
109                 if ( count < countMax )
110                         lpidProcess[count] = pe.th32ProcessID;
111                 count ++;
112         }
113         CloseHandle( hSnapshot );
114
115         if ( lpcbNeeded != NULL )
116                 *lpcbNeeded = sizeof(DWORD) * count;
117
118         TRACE("return %lu processes\n",count);
119
120         return TRUE;
121 }
122
123 /***********************************************************************
124  *           EnumProcessModules (PSAPI.@)
125  */
126 BOOL WINAPI EnumProcessModules(
127   HANDLE hProcess, HMODULE *lphModule, DWORD cb, LPDWORD lpcbNeeded)
128 {
129         MODULEENTRY32   me;
130         HANDLE  hSnapshot;
131         BOOL    res;
132         DWORD   pid;
133         DWORD   count;
134         DWORD   countMax;
135
136         FIXME("(hProcess=0x%08x, %p, %ld, %p)\n",
137                 hProcess, lphModule, cb, lpcbNeeded );
138
139         if ( lphModule == NULL )
140                 cb = 0;
141         if ( lpcbNeeded != NULL )
142                 *lpcbNeeded = 0;
143
144         pid = get_pid_from_process_handle(hProcess);
145         if ( pid == 0 )
146         {
147                 FIXME("no pid for hProcess 0x%08x\n",hProcess);
148                 return FALSE;
149         }
150
151         hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,pid);
152         if ( hSnapshot == INVALID_HANDLE_VALUE )
153         {
154                 FIXME("cannot create snapshot\n");
155                 return FALSE;
156         }
157         count = 0;
158         countMax = cb / sizeof(HMODULE);
159         while (1)
160         {
161                 ZeroMemory( &me, sizeof(MODULEENTRY32) );
162                 me.dwSize = sizeof(MODULEENTRY32);
163                 res = (count == 0) ? Module32First( hSnapshot, &me ) : Module32Next( hSnapshot, &me );
164                 if ( !res )
165                         break;
166                 TRACE("module 0x%08lx\n",(long)me.hModule);
167                 if ( count < countMax )
168                         lphModule[count] = me.hModule;
169                 count ++;
170         }
171         CloseHandle( hSnapshot );
172
173         if ( lpcbNeeded != NULL )
174                 *lpcbNeeded = sizeof(HMODULE) * count;
175
176         TRACE("return %lu modules\n",count);
177
178         return TRUE;
179 }
180
181 /***********************************************************************
182  *          GetDeviceDriverBaseNameA (PSAPI.@)
183  */
184 DWORD WINAPI GetDeviceDriverBaseNameA(
185   LPVOID ImageBase, LPSTR lpBaseName, DWORD nSize)
186 {
187   FIXME("(%p, %s, %ld): stub\n",
188     ImageBase, debugstr_a(lpBaseName), nSize
189   );
190
191   if(lpBaseName && nSize)
192     lpBaseName[0] = '\0';
193
194   return 0;
195 }
196
197 /***********************************************************************
198  *           GetDeviceDriverBaseNameW (PSAPI.@)
199  */
200 DWORD WINAPI GetDeviceDriverBaseNameW(
201   LPVOID ImageBase, LPWSTR lpBaseName, DWORD nSize)
202 {
203   FIXME("(%p, %s, %ld): stub\n",
204     ImageBase, debugstr_w(lpBaseName), nSize
205   );
206
207   if(lpBaseName && nSize)
208     lpBaseName[0] = '\0';
209
210   return 0;
211 }
212
213 /***********************************************************************
214  *           GetDeviceDriverFileNameA (PSAPI.@)
215  */
216 DWORD WINAPI GetDeviceDriverFileNameA(
217   LPVOID ImageBase, LPSTR lpFilename, DWORD nSize)
218 {
219   FIXME("(%p, %s, %ld): stub\n",
220     ImageBase, debugstr_a(lpFilename), nSize
221   );
222
223   if(lpFilename && nSize)
224     lpFilename[0] = '\0';
225
226   return 0;
227 }
228
229 /***********************************************************************
230  *           GetDeviceDriverFileNameW (PSAPI.@)
231  */
232 DWORD WINAPI GetDeviceDriverFileNameW(
233   LPVOID ImageBase, LPWSTR lpFilename, DWORD nSize)
234 {
235   FIXME("(%p, %s, %ld): stub\n",
236     ImageBase, debugstr_w(lpFilename), nSize
237   );
238
239   if(lpFilename && nSize)
240     lpFilename[0] = '\0';
241
242   return 0;
243 }
244
245 /***********************************************************************
246  *           GetMappedFileNameA (PSAPI.@)
247  */
248 DWORD WINAPI GetMappedFileNameA(
249   HANDLE hProcess, LPVOID lpv, LPSTR lpFilename, DWORD nSize)
250 {
251   FIXME("(hProcess=0x%08x, %p, %s, %ld): stub\n",
252     hProcess, lpv, debugstr_a(lpFilename), nSize
253   );
254
255   if(lpFilename && nSize)
256     lpFilename[0] = '\0';
257
258   return 0;
259 }
260
261 /***********************************************************************
262  *           GetMappedFileNameW (PSAPI.@)
263  */
264 DWORD WINAPI GetMappedFileNameW(
265   HANDLE hProcess, LPVOID lpv, LPWSTR lpFilename, DWORD nSize)
266 {
267   FIXME("(hProcess=0x%08x, %p, %s, %ld): stub\n",
268     hProcess, lpv, debugstr_w(lpFilename), nSize
269   );
270
271   if(lpFilename && nSize)
272     lpFilename[0] = '\0';
273
274   return 0;
275 }
276
277 /***********************************************************************
278  *           GetModuleBaseNameA (PSAPI.@)
279  */
280 DWORD WINAPI GetModuleBaseNameA(
281   HANDLE hProcess, HMODULE hModule, LPSTR lpBaseName, DWORD nSize)
282 {
283   FIXME("(hProcess=0x%08x, hModule=0x%08x, %s, %ld): stub\n",
284     hProcess, hModule, debugstr_a(lpBaseName), nSize
285   );
286
287   if(lpBaseName && nSize)
288     lpBaseName[0] = '\0';
289
290   return 0;
291 }
292
293 /***********************************************************************
294  *           GetModuleBaseNameW (PSAPI.@)
295  */
296 DWORD WINAPI GetModuleBaseNameW(
297   HANDLE hProcess, HMODULE hModule, LPWSTR lpBaseName, DWORD nSize)
298 {
299   FIXME("(hProcess=0x%08x, hModule=0x%08x, %s, %ld): stub\n",
300     hProcess, hModule, debugstr_w(lpBaseName), nSize);
301
302   if(lpBaseName && nSize)
303     lpBaseName[0] = '\0';
304
305   return 0;
306 }
307
308 /***********************************************************************
309  *           GetModuleFileNameExA (PSAPI.@)
310  */
311 DWORD WINAPI GetModuleFileNameExA(
312   HANDLE hProcess, HMODULE hModule, LPSTR lpFilename, DWORD nSize)
313 {
314   FIXME("(hProcess=0x%08x,hModule=0x%08x, %s, %ld): stub\n",
315     hProcess, hModule, debugstr_a(lpFilename), nSize
316   );
317
318         if ( get_pid_from_process_handle(hProcess) == GetCurrentProcessId() )
319                 return GetModuleFileNameA( hModule, lpFilename, nSize );
320
321   if(lpFilename&&nSize)
322     lpFilename[0]='\0';
323
324   return 0;
325 }
326
327 /***********************************************************************
328  *           GetModuleFileNameExW (PSAPI.@)
329  */
330 DWORD WINAPI GetModuleFileNameExW(
331   HANDLE hProcess, HMODULE hModule, LPWSTR lpFilename, DWORD nSize)
332 {
333   FIXME("(hProcess=0x%08x,hModule=0x%08x, %s, %ld): stub\n",
334     hProcess, hModule, debugstr_w(lpFilename), nSize
335   );
336
337         if ( get_pid_from_process_handle(hProcess) == GetCurrentProcessId() )
338                 return GetModuleFileNameW( hModule, lpFilename, nSize );
339
340   if(lpFilename && nSize)
341     lpFilename[0] = '\0';
342
343   return 0;
344 }
345
346 /***********************************************************************
347  *           GetModuleInformation (PSAPI.@)
348  */
349 BOOL WINAPI GetModuleInformation(
350   HANDLE hProcess, HMODULE hModule, LPMODULEINFO lpmodinfo, DWORD cb)
351 {
352   FIXME("(hProcess=0x%08x, hModule=0x%08x, %p, %ld): stub\n",
353     hProcess, hModule, lpmodinfo, cb
354   );
355
356   memset(lpmodinfo, 0, cb);
357
358   return TRUE;
359 }
360
361 /***********************************************************************
362  *           GetProcessMemoryInfo (PSAPI.@)
363  */
364 BOOL WINAPI GetProcessMemoryInfo(
365   HANDLE Process, PPROCESS_MEMORY_COUNTERS ppsmemCounters, DWORD cb)
366 {
367   FIXME("(hProcess=0x%08x, %p, %ld): stub\n",
368     Process, ppsmemCounters, cb
369   );
370
371   memset(ppsmemCounters, 0, cb);
372
373   return TRUE;
374 }
375
376 /***********************************************************************
377  *           GetWsChanges (PSAPI.@)
378  */
379 BOOL WINAPI GetWsChanges(
380   HANDLE hProcess, PPSAPI_WS_WATCH_INFORMATION lpWatchInfo, DWORD cb)
381 {
382   FIXME("(hProcess=0x%08x, %p, %ld): stub\n",
383     hProcess, lpWatchInfo, cb
384   );
385
386   memset(lpWatchInfo, 0, cb);
387
388   return TRUE;
389 }
390
391 /***********************************************************************
392  *           InitializeProcessForWsWatch (PSAPI.@)
393  */
394 BOOL WINAPI InitializeProcessForWsWatch(HANDLE hProcess)
395 {
396   FIXME("(hProcess=0x%08x): stub\n", hProcess);
397
398   return TRUE;
399 }
400
401 /***********************************************************************
402  *           QueryWorkingSet (PSAPI.?)
403  * FIXME
404  *     I haven't been able to find the ordinal for this function,
405  *     This means it can't be called from outside the DLL.
406  */
407 BOOL WINAPI QueryWorkingSet(HANDLE hProcess, LPVOID pv, DWORD cb)
408 {
409   FIXME("(hProcess=0x%08x, %p, %ld)\n", hProcess, pv, cb);
410
411   if(pv && cb)
412     ((DWORD *) pv)[0] = 0; /* Empty WorkingSet */
413
414   return TRUE;
415 }
416
417
418
419
420