4 * Copyright 1998 Patrik Stridvall
5 * Copyright 2003 Eric Pouech
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "wine/server.h"
28 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(psapi);
34 /***********************************************************************
35 * EmptyWorkingSet (PSAPI.@)
37 BOOL WINAPI EmptyWorkingSet(HANDLE hProcess)
39 return SetProcessWorkingSetSize(hProcess, 0xFFFFFFFF, 0xFFFFFFFF);
42 /***********************************************************************
43 * EnumDeviceDrivers (PSAPI.@)
45 BOOL WINAPI EnumDeviceDrivers(LPVOID *lpImageBase, DWORD cb, LPDWORD lpcbNeeded)
47 FIXME("(%p, %ld, %p): stub\n", lpImageBase, cb, lpcbNeeded);
56 /***********************************************************************
57 * EnumProcesses (PSAPI.@)
59 BOOL WINAPI EnumProcesses(DWORD *lpidProcess, DWORD cb, DWORD *lpcbNeeded)
67 TRACE("(%p, %ld, %p)\n", lpidProcess,cb, lpcbNeeded);
69 if ( lpidProcess == NULL )
71 if ( lpcbNeeded != NULL )
74 SERVER_START_REQ( create_snapshot )
76 req->flags = SNAP_PROCESS;
79 wine_server_call_err( req );
80 hSnapshot = reply->handle;
86 FIXME("cannot create snapshot\n");
90 countMax = cb / sizeof(DWORD);
93 SERVER_START_REQ( next_process )
95 req->handle = hSnapshot;
96 req->reset = (count == 0);
97 wine_server_set_reply( req, NULL, 0);
98 if ((ret = !wine_server_call_err( req )))
103 TRACE("process 0x%08lx\n", pid);
104 if ( count < countMax )
105 lpidProcess[count] = pid;
108 CloseHandle( hSnapshot );
110 if ( lpcbNeeded != NULL )
111 *lpcbNeeded = sizeof(DWORD) * count;
113 TRACE("return %lu processes\n", count);
118 /***********************************************************************
119 * EnumProcessModules (PSAPI.@)
121 BOOL WINAPI EnumProcessModules(HANDLE hProcess, HMODULE *lphModule,
122 DWORD cb, LPDWORD lpcbNeeded)
131 TRACE("(hProcess=%p, %p, %ld, %p)\n",
132 hProcess, lphModule, cb, lpcbNeeded );
134 if ( lphModule == NULL )
136 if ( lpcbNeeded != NULL )
139 SERVER_START_REQ( get_process_info )
141 req->handle = hProcess;
142 if ( !wine_server_call_err( req ) )
143 pid = (DWORD)reply->pid;
151 FIXME("no pid for hProcess %p\n" ,hProcess);
155 SERVER_START_REQ( create_snapshot )
157 req->flags = SNAP_MODULE;
158 req->inherit = FALSE;
160 wine_server_call_err( req );
161 hSnapshot = reply->handle;
164 if ( hSnapshot == 0 )
166 FIXME("cannot create snapshot\n");
170 countMax = cb / sizeof(HMODULE);
173 SERVER_START_REQ( next_module )
175 req->handle = hSnapshot;
176 req->reset = (count == 0);
177 wine_server_set_reply( req, NULL, 0 );
178 if ((ret = !wine_server_call_err( req )))
180 hModule = (HMODULE)reply->base;
185 TRACE("module 0x%p\n", hModule);
186 if ( count < countMax )
187 lphModule[count] = hModule;
190 CloseHandle( hSnapshot );
192 if ( lpcbNeeded != NULL )
193 *lpcbNeeded = sizeof(HMODULE) * count;
195 TRACE("return %lu modules\n", count);
200 /***********************************************************************
201 * GetDeviceDriverBaseNameA (PSAPI.@)
203 DWORD WINAPI GetDeviceDriverBaseNameA(LPVOID ImageBase, LPSTR lpBaseName,
206 FIXME("(%p, %s, %ld): stub\n",
207 ImageBase, debugstr_a(lpBaseName), nSize);
209 if (lpBaseName && nSize)
210 lpBaseName[0] = '\0';
215 /***********************************************************************
216 * GetDeviceDriverBaseNameW (PSAPI.@)
218 DWORD WINAPI GetDeviceDriverBaseNameW(LPVOID ImageBase, LPWSTR lpBaseName,
221 FIXME("(%p, %s, %ld): stub\n",
222 ImageBase, debugstr_w(lpBaseName), nSize);
224 if (lpBaseName && nSize)
225 lpBaseName[0] = '\0';
230 /***********************************************************************
231 * GetDeviceDriverFileNameA (PSAPI.@)
233 DWORD WINAPI GetDeviceDriverFileNameA(LPVOID ImageBase, LPSTR lpFilename,
236 FIXME("(%p, %s, %ld): stub\n",
237 ImageBase, debugstr_a(lpFilename), nSize);
239 if (lpFilename && nSize)
240 lpFilename[0] = '\0';
245 /***********************************************************************
246 * GetDeviceDriverFileNameW (PSAPI.@)
248 DWORD WINAPI GetDeviceDriverFileNameW(LPVOID ImageBase, LPWSTR lpFilename,
251 FIXME("(%p, %s, %ld): stub\n",
252 ImageBase, debugstr_w(lpFilename), nSize);
254 if (lpFilename && nSize)
255 lpFilename[0] = '\0';
260 /***********************************************************************
261 * GetMappedFileNameA (PSAPI.@)
263 DWORD WINAPI GetMappedFileNameA(HANDLE hProcess, LPVOID lpv, LPSTR lpFilename,
266 FIXME("(hProcess=%p, %p, %s, %ld): stub\n",
267 hProcess, lpv, debugstr_a(lpFilename), nSize);
269 if (lpFilename && nSize)
270 lpFilename[0] = '\0';
275 /***********************************************************************
276 * GetMappedFileNameW (PSAPI.@)
278 DWORD WINAPI GetMappedFileNameW(HANDLE hProcess, LPVOID lpv, LPWSTR lpFilename,
281 FIXME("(hProcess=%p, %p, %s, %ld): stub\n",
282 hProcess, lpv, debugstr_w(lpFilename), nSize);
284 if (lpFilename && nSize)
285 lpFilename[0] = '\0';
290 /***********************************************************************
291 * GetModuleBaseNameA (PSAPI.@)
293 DWORD WINAPI GetModuleBaseNameA(HANDLE hProcess, HMODULE hModule,
294 LPSTR lpBaseName, DWORD nSize)
299 if (!GetModuleFileNameExA(hProcess, hModule, tmp, sizeof(tmp)))
301 if ((ptr = strrchr(tmp, '\\')) != NULL) ptr++; else ptr = tmp;
302 strncpy(lpBaseName, ptr, nSize);
303 lpBaseName[nSize - 1] = '\0';
304 return strlen(lpBaseName);
307 /***********************************************************************
308 * GetModuleBaseNameW (PSAPI.@)
310 DWORD WINAPI GetModuleBaseNameW(HANDLE hProcess, HMODULE hModule,
311 LPWSTR lpBaseName, DWORD nSize)
316 TRACE("(hProcess=%p, hModule=%p, %p, %ld)\n",
317 hProcess, hModule, lpBaseName, nSize);
319 if (!lpBaseName || !nSize) return 0;
321 ptr = HeapAlloc(GetProcessHeap(), 0, nSize / 2);
324 len = GetModuleBaseNameA(hProcess, hModule, ptr, nSize / 2);
327 lpBaseName[0] = '\0';
331 if (!MultiByteToWideChar( CP_ACP, 0, ptr, -1, lpBaseName, nSize / 2 ))
332 lpBaseName[nSize / 2 - 1] = 0;
335 HeapFree(GetProcessHeap(), 0, ptr);
339 /***********************************************************************
340 * GetModuleFileNameExA (PSAPI.@)
342 DWORD WINAPI GetModuleFileNameExA(HANDLE hProcess, HMODULE hModule,
343 LPSTR lpFileName, DWORD nSize)
347 TRACE("(hProcess=%p, hModule=%p, %p, %ld)\n",
348 hProcess, hModule, lpFileName, nSize);
350 if (!lpFileName || !nSize) return 0;
352 if ( hProcess == GetCurrentProcess() )
353 return GetModuleFileNameA( hModule, lpFileName, nSize );
357 SERVER_START_REQ( get_dll_info )
359 req->handle = hProcess;
360 req->base_address = (void*)hModule;
361 wine_server_set_reply( req, lpFileName, nSize - 1);
362 if (!wine_server_call_err( req ))
364 len = wine_server_reply_size(reply);
370 TRACE("return %s (%lu)\n", lpFileName, len);
375 /***********************************************************************
376 * GetModuleFileNameExW (PSAPI.@)
378 DWORD WINAPI GetModuleFileNameExW(HANDLE hProcess, HMODULE hModule,
379 LPWSTR lpFileName, DWORD nSize)
384 TRACE("(hProcess=%p,hModule=%p, %p, %ld)\n",
385 hProcess, hModule, lpFileName, nSize);
387 if (!lpFileName || !nSize) return 0;
389 if ( hProcess == GetCurrentProcess() )
390 return GetModuleFileNameW( hModule, lpFileName, nSize );
392 ptr = HeapAlloc(GetProcessHeap(), 0, nSize / 2);
395 len = GetModuleFileNameExA(hProcess, hModule, ptr, nSize / 2);
398 lpFileName[0] = '\0';
402 if (!MultiByteToWideChar( CP_ACP, 0, ptr, -1, lpFileName, nSize / 2 ))
403 lpFileName[nSize / 2 - 1] = 0;
406 HeapFree(GetProcessHeap(), 0, ptr);
410 /***********************************************************************
411 * GetModuleInformation (PSAPI.@)
413 BOOL WINAPI GetModuleInformation(HANDLE hProcess, HMODULE hModule,
414 LPMODULEINFO lpmodinfo, DWORD cb)
418 TRACE("(hProcess=%p, hModule=%p, %p, %ld)\n",
419 hProcess, hModule, lpmodinfo, cb);
421 if (cb < sizeof(MODULEINFO)) return FALSE;
423 SERVER_START_REQ( get_dll_info )
425 req->handle = hProcess;
426 req->base_address = (void*)hModule;
427 if (!wine_server_call_err( req ))
430 lpmodinfo->lpBaseOfDll = (void*)hModule;
431 lpmodinfo->SizeOfImage = reply->size;
432 lpmodinfo->EntryPoint = reply->entry_point;
440 /***********************************************************************
441 * GetProcessMemoryInfo (PSAPI.@)
443 BOOL WINAPI GetProcessMemoryInfo(HANDLE Process,
444 PPROCESS_MEMORY_COUNTERS ppsmemCounters, DWORD cb)
446 FIXME("(hProcess=%p, %p, %ld): stub\n",
447 Process, ppsmemCounters, cb);
449 memset(ppsmemCounters, 0, cb);
454 /***********************************************************************
455 * GetWsChanges (PSAPI.@)
457 BOOL WINAPI GetWsChanges(HANDLE hProcess,
458 PPSAPI_WS_WATCH_INFORMATION lpWatchInfo, DWORD cb)
460 FIXME("(hProcess=%p, %p, %ld): stub\n",
461 hProcess, lpWatchInfo, cb);
463 memset(lpWatchInfo, 0, cb);
468 /***********************************************************************
469 * InitializeProcessForWsWatch (PSAPI.@)
471 BOOL WINAPI InitializeProcessForWsWatch(HANDLE hProcess)
473 FIXME("(hProcess=%p): stub\n", hProcess);
478 /***********************************************************************
479 * QueryWorkingSet (PSAPI.?)
481 * I haven't been able to find the ordinal for this function,
482 * This means it can't be called from outside the DLL.
484 BOOL WINAPI QueryWorkingSet(HANDLE hProcess, LPVOID pv, DWORD cb)
486 FIXME("(hProcess=%p, %p, %ld)\n", hProcess, pv, cb);
489 ((DWORD *) pv)[0] = 0; /* Empty WorkingSet */