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/unicode.h"
29 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(psapi);
35 /***********************************************************************
36 * EmptyWorkingSet (PSAPI.@)
38 BOOL WINAPI EmptyWorkingSet(HANDLE hProcess)
40 return SetProcessWorkingSetSize(hProcess, 0xFFFFFFFF, 0xFFFFFFFF);
43 /***********************************************************************
44 * EnumDeviceDrivers (PSAPI.@)
46 BOOL WINAPI EnumDeviceDrivers(LPVOID *lpImageBase, DWORD cb, LPDWORD lpcbNeeded)
48 FIXME("(%p, %ld, %p): stub\n", lpImageBase, cb, lpcbNeeded);
57 /***********************************************************************
58 * EnumProcesses (PSAPI.@)
60 BOOL WINAPI EnumProcesses(DWORD *lpidProcess, DWORD cb, DWORD *lpcbNeeded)
68 TRACE("(%p, %ld, %p)\n", lpidProcess,cb, lpcbNeeded);
70 if ( lpidProcess == NULL )
72 if ( lpcbNeeded != NULL )
75 SERVER_START_REQ( create_snapshot )
77 req->flags = SNAP_PROCESS;
80 wine_server_call_err( req );
81 hSnapshot = reply->handle;
87 FIXME("cannot create snapshot\n");
91 countMax = cb / sizeof(DWORD);
94 SERVER_START_REQ( next_process )
96 req->handle = hSnapshot;
97 req->reset = (count == 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 if ((ret = !wine_server_call_err( req )))
179 hModule = (HMODULE)reply->base;
184 TRACE("module 0x%p\n", hModule);
185 if ( count < countMax )
186 lphModule[count] = hModule;
189 CloseHandle( hSnapshot );
191 if ( lpcbNeeded != NULL )
192 *lpcbNeeded = sizeof(HMODULE) * count;
194 TRACE("return %lu modules\n", count);
199 /***********************************************************************
200 * GetDeviceDriverBaseNameA (PSAPI.@)
202 DWORD WINAPI GetDeviceDriverBaseNameA(LPVOID ImageBase, LPSTR lpBaseName,
205 FIXME("(%p, %s, %ld): stub\n",
206 ImageBase, debugstr_a(lpBaseName), nSize);
208 if (lpBaseName && nSize)
209 lpBaseName[0] = '\0';
214 /***********************************************************************
215 * GetDeviceDriverBaseNameW (PSAPI.@)
217 DWORD WINAPI GetDeviceDriverBaseNameW(LPVOID ImageBase, LPWSTR lpBaseName,
220 FIXME("(%p, %s, %ld): stub\n",
221 ImageBase, debugstr_w(lpBaseName), nSize);
223 if (lpBaseName && nSize)
224 lpBaseName[0] = '\0';
229 /***********************************************************************
230 * GetDeviceDriverFileNameA (PSAPI.@)
232 DWORD WINAPI GetDeviceDriverFileNameA(LPVOID ImageBase, LPSTR lpFilename,
235 FIXME("(%p, %s, %ld): stub\n",
236 ImageBase, debugstr_a(lpFilename), nSize);
238 if (lpFilename && nSize)
239 lpFilename[0] = '\0';
244 /***********************************************************************
245 * GetDeviceDriverFileNameW (PSAPI.@)
247 DWORD WINAPI GetDeviceDriverFileNameW(LPVOID ImageBase, LPWSTR lpFilename,
250 FIXME("(%p, %s, %ld): stub\n",
251 ImageBase, debugstr_w(lpFilename), nSize);
253 if (lpFilename && nSize)
254 lpFilename[0] = '\0';
259 /***********************************************************************
260 * GetMappedFileNameA (PSAPI.@)
262 DWORD WINAPI GetMappedFileNameA(HANDLE hProcess, LPVOID lpv, LPSTR lpFilename,
265 FIXME("(hProcess=%p, %p, %s, %ld): stub\n",
266 hProcess, lpv, debugstr_a(lpFilename), nSize);
268 if (lpFilename && nSize)
269 lpFilename[0] = '\0';
274 /***********************************************************************
275 * GetMappedFileNameW (PSAPI.@)
277 DWORD WINAPI GetMappedFileNameW(HANDLE hProcess, LPVOID lpv, LPWSTR lpFilename,
280 FIXME("(hProcess=%p, %p, %s, %ld): stub\n",
281 hProcess, lpv, debugstr_w(lpFilename), nSize);
283 if (lpFilename && nSize)
284 lpFilename[0] = '\0';
289 /***********************************************************************
290 * GetModuleBaseNameA (PSAPI.@)
292 DWORD WINAPI GetModuleBaseNameA(HANDLE hProcess, HMODULE hModule,
293 LPSTR lpBaseName, DWORD nSize)
296 DWORD buflenW, ret = 0;
298 if(!lpBaseName || !nSize) {
299 SetLastError(ERROR_INVALID_PARAMETER);
302 lpBaseNameW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * nSize);
303 buflenW = GetModuleBaseNameW(hProcess, hModule, lpBaseNameW, nSize);
304 TRACE("%ld, %s\n", buflenW, debugstr_w(lpBaseNameW));
307 ret = WideCharToMultiByte(CP_ACP, 0, lpBaseNameW, buflenW,
308 lpBaseName, nSize, NULL, NULL);
309 if (ret < nSize) lpBaseName[ret] = 0;
311 HeapFree(GetProcessHeap(), 0, lpBaseNameW);
315 /***********************************************************************
316 * GetModuleBaseNameW (PSAPI.@)
318 DWORD WINAPI GetModuleBaseNameW(HANDLE hProcess, HMODULE hModule,
319 LPWSTR lpBaseName, DWORD nSize)
324 if(!lpBaseName || !nSize) {
325 SetLastError(ERROR_INVALID_PARAMETER);
329 if (!GetModuleFileNameExW(hProcess, hModule, tmp,
330 sizeof(tmp)/sizeof(WCHAR)))
332 TRACE("%s\n", debugstr_w(tmp));
333 if ((ptr = strrchrW(tmp, '\\')) != NULL) ptr++; else ptr = tmp;
334 strncpyW(lpBaseName, ptr, nSize);
335 return min(strlenW(ptr), nSize);
338 /***********************************************************************
339 * GetModuleFileNameExA (PSAPI.@)
341 DWORD WINAPI GetModuleFileNameExA(HANDLE hProcess, HMODULE hModule,
342 LPSTR lpFileName, DWORD nSize)
346 TRACE("(hProcess=%p, hModule=%p, %p, %ld)\n",
347 hProcess, hModule, lpFileName, nSize);
349 if (!lpFileName || !nSize) return 0;
351 if ( hProcess == GetCurrentProcess() )
353 DWORD len = GetModuleFileNameA( hModule, lpFileName, nSize );
354 if (nSize) lpFileName[nSize - 1] = '\0';
358 if (!(ptr = HeapAlloc(GetProcessHeap(), 0, nSize * sizeof(WCHAR)))) return 0;
360 if (!GetModuleFileNameExW(hProcess, hModule, ptr, nSize))
362 lpFileName[0] = '\0';
366 if (!WideCharToMultiByte( CP_ACP, 0, ptr, -1, lpFileName, nSize, NULL, NULL ))
367 lpFileName[nSize - 1] = 0;
370 HeapFree(GetProcessHeap(), 0, ptr);
371 return strlen(lpFileName);
374 /***********************************************************************
375 * GetModuleFileNameExW (PSAPI.@)
377 DWORD WINAPI GetModuleFileNameExW(HANDLE hProcess, HMODULE hModule,
378 LPWSTR lpFileName, DWORD nSize)
382 TRACE("(hProcess=%p, hModule=%p, %p, %ld)\n",
383 hProcess, hModule, lpFileName, nSize);
385 if (!lpFileName || !nSize) return 0;
387 if ( hProcess == GetCurrentProcess() )
389 DWORD len = GetModuleFileNameW( hModule, lpFileName, nSize );
390 if (nSize) lpFileName[nSize - 1] = '\0';
391 TRACE("return (cur) %s (%lu)\n", debugstr_w(lpFileName), len);
397 SERVER_START_REQ( get_dll_info )
399 req->handle = hProcess;
400 req->base_address = hModule;
401 wine_server_set_reply( req, lpFileName, (nSize - 1) * sizeof(WCHAR) );
402 if (!wine_server_call_err( req ))
404 len = wine_server_reply_size(reply) / sizeof(WCHAR);
410 TRACE("return %s (%lu)\n", debugstr_w(lpFileName), len);
415 /***********************************************************************
416 * GetModuleInformation (PSAPI.@)
418 BOOL WINAPI GetModuleInformation(HANDLE hProcess, HMODULE hModule,
419 LPMODULEINFO lpmodinfo, DWORD cb)
423 TRACE("(hProcess=%p, hModule=%p, %p, %ld)\n",
424 hProcess, hModule, lpmodinfo, cb);
426 if (cb < sizeof(MODULEINFO)) return FALSE;
428 SERVER_START_REQ( get_dll_info )
430 req->handle = hProcess;
431 req->base_address = (void*)hModule;
432 if (!wine_server_call_err( req ))
435 lpmodinfo->lpBaseOfDll = (void*)hModule;
436 lpmodinfo->SizeOfImage = reply->size;
437 lpmodinfo->EntryPoint = reply->entry_point;
445 /***********************************************************************
446 * GetProcessMemoryInfo (PSAPI.@)
448 BOOL WINAPI GetProcessMemoryInfo(HANDLE Process,
449 PPROCESS_MEMORY_COUNTERS ppsmemCounters, DWORD cb)
451 FIXME("(hProcess=%p, %p, %ld): stub\n",
452 Process, ppsmemCounters, cb);
454 memset(ppsmemCounters, 0, cb);
459 /***********************************************************************
460 * GetWsChanges (PSAPI.@)
462 BOOL WINAPI GetWsChanges(HANDLE hProcess,
463 PPSAPI_WS_WATCH_INFORMATION lpWatchInfo, DWORD cb)
465 FIXME("(hProcess=%p, %p, %ld): stub\n",
466 hProcess, lpWatchInfo, cb);
468 memset(lpWatchInfo, 0, cb);
473 /***********************************************************************
474 * InitializeProcessForWsWatch (PSAPI.@)
476 BOOL WINAPI InitializeProcessForWsWatch(HANDLE hProcess)
478 FIXME("(hProcess=%p): stub\n", hProcess);
483 /***********************************************************************
484 * QueryWorkingSet (PSAPI.@)
486 BOOL WINAPI QueryWorkingSet(HANDLE hProcess, LPVOID pv, DWORD cb)
488 FIXME("(hProcess=%p, %p, %ld)\n", hProcess, pv, cb);
491 ((DWORD *) pv)[0] = 0; /* Empty WorkingSet */