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
25 #include "wine/server.h"
26 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(psapi
);
32 /***********************************************************************
33 * EmptyWorkingSet (PSAPI.@)
35 BOOL WINAPI
EmptyWorkingSet(HANDLE hProcess
)
37 return SetProcessWorkingSetSize(hProcess
, 0xFFFFFFFF, 0xFFFFFFFF);
40 /***********************************************************************
41 * EnumDeviceDrivers (PSAPI.@)
43 BOOL WINAPI
EnumDeviceDrivers(LPVOID
*lpImageBase
, DWORD cb
, LPDWORD lpcbNeeded
)
45 FIXME("(%p, %ld, %p): stub\n", lpImageBase
, cb
, lpcbNeeded
);
54 /***********************************************************************
55 * EnumProcesses (PSAPI.@)
57 BOOL WINAPI
EnumProcesses(DWORD
*lpidProcess
, DWORD cb
, DWORD
*lpcbNeeded
)
65 TRACE("(%p, %ld, %p)\n", lpidProcess
,cb
, lpcbNeeded
);
67 if ( lpidProcess
== NULL
)
69 if ( lpcbNeeded
!= NULL
)
72 SERVER_START_REQ( create_snapshot
)
74 req
->flags
= SNAP_PROCESS
;
77 wine_server_call_err( req
);
78 hSnapshot
= reply
->handle
;
84 FIXME("cannot create snapshot\n");
88 countMax
= cb
/ sizeof(DWORD
);
91 SERVER_START_REQ( next_process
)
93 req
->handle
= hSnapshot
;
94 req
->reset
= (count
== 0);
95 wine_server_set_reply( req
, NULL
, 0);
96 if ((ret
= !wine_server_call_err( req
)))
101 TRACE("process 0x%08lx\n", pid
);
102 if ( count
< countMax
)
103 lpidProcess
[count
] = pid
;
106 CloseHandle( hSnapshot
);
108 if ( lpcbNeeded
!= NULL
)
109 *lpcbNeeded
= sizeof(DWORD
) * count
;
111 TRACE("return %lu processes\n", count
);
116 /***********************************************************************
117 * EnumProcessModules (PSAPI.@)
119 BOOL WINAPI
EnumProcessModules(HANDLE hProcess
, HMODULE
*lphModule
,
120 DWORD cb
, LPDWORD lpcbNeeded
)
129 TRACE("(hProcess=%p, %p, %ld, %p)\n",
130 hProcess
, lphModule
, cb
, lpcbNeeded
);
132 if ( lphModule
== NULL
)
134 if ( lpcbNeeded
!= NULL
)
137 SERVER_START_REQ( get_process_info
)
139 req
->handle
= hProcess
;
140 if ( !wine_server_call_err( req
) )
141 pid
= (DWORD
)reply
->pid
;
149 FIXME("no pid for hProcess %p\n" ,hProcess
);
153 SERVER_START_REQ( create_snapshot
)
155 req
->flags
= SNAP_MODULE
;
156 req
->inherit
= FALSE
;
158 wine_server_call_err( req
);
159 hSnapshot
= reply
->handle
;
162 if ( hSnapshot
== 0 )
164 FIXME("cannot create snapshot\n");
168 countMax
= cb
/ sizeof(HMODULE
);
171 SERVER_START_REQ( next_module
)
173 req
->handle
= hSnapshot
;
174 req
->reset
= (count
== 0);
175 wine_server_set_reply( req
, NULL
, 0 );
176 if ((ret
= !wine_server_call_err( req
)))
178 hModule
= (HMODULE
)reply
->base
;
183 TRACE("module 0x%p\n", hModule
);
184 if ( count
< countMax
)
185 lphModule
[count
] = hModule
;
188 CloseHandle( hSnapshot
);
190 if ( lpcbNeeded
!= NULL
)
191 *lpcbNeeded
= sizeof(HMODULE
) * count
;
193 TRACE("return %lu modules\n", count
);
198 /***********************************************************************
199 * GetDeviceDriverBaseNameA (PSAPI.@)
201 DWORD WINAPI
GetDeviceDriverBaseNameA(LPVOID ImageBase
, LPSTR lpBaseName
,
204 FIXME("(%p, %s, %ld): stub\n",
205 ImageBase
, debugstr_a(lpBaseName
), nSize
);
207 if (lpBaseName
&& nSize
)
208 lpBaseName
[0] = '\0';
213 /***********************************************************************
214 * GetDeviceDriverBaseNameW (PSAPI.@)
216 DWORD WINAPI
GetDeviceDriverBaseNameW(LPVOID ImageBase
, LPWSTR lpBaseName
,
219 FIXME("(%p, %s, %ld): stub\n",
220 ImageBase
, debugstr_w(lpBaseName
), nSize
);
222 if (lpBaseName
&& nSize
)
223 lpBaseName
[0] = '\0';
228 /***********************************************************************
229 * GetDeviceDriverFileNameA (PSAPI.@)
231 DWORD WINAPI
GetDeviceDriverFileNameA(LPVOID ImageBase
, LPSTR lpFilename
,
234 FIXME("(%p, %s, %ld): stub\n",
235 ImageBase
, debugstr_a(lpFilename
), nSize
);
237 if (lpFilename
&& nSize
)
238 lpFilename
[0] = '\0';
243 /***********************************************************************
244 * GetDeviceDriverFileNameW (PSAPI.@)
246 DWORD WINAPI
GetDeviceDriverFileNameW(LPVOID ImageBase
, LPWSTR lpFilename
,
249 FIXME("(%p, %s, %ld): stub\n",
250 ImageBase
, debugstr_w(lpFilename
), nSize
);
252 if (lpFilename
&& nSize
)
253 lpFilename
[0] = '\0';
258 /***********************************************************************
259 * GetMappedFileNameA (PSAPI.@)
261 DWORD WINAPI
GetMappedFileNameA(HANDLE hProcess
, LPVOID lpv
, LPSTR lpFilename
,
264 FIXME("(hProcess=%p, %p, %s, %ld): stub\n",
265 hProcess
, lpv
, debugstr_a(lpFilename
), nSize
);
267 if (lpFilename
&& nSize
)
268 lpFilename
[0] = '\0';
273 /***********************************************************************
274 * GetMappedFileNameW (PSAPI.@)
276 DWORD WINAPI
GetMappedFileNameW(HANDLE hProcess
, LPVOID lpv
, LPWSTR lpFilename
,
279 FIXME("(hProcess=%p, %p, %s, %ld): stub\n",
280 hProcess
, lpv
, debugstr_w(lpFilename
), nSize
);
282 if (lpFilename
&& nSize
)
283 lpFilename
[0] = '\0';
288 /***********************************************************************
289 * GetModuleBaseNameA (PSAPI.@)
291 DWORD WINAPI
GetModuleBaseNameA(HANDLE hProcess
, HMODULE hModule
,
292 LPSTR lpBaseName
, DWORD nSize
)
297 if (!GetModuleFileNameExA(hProcess
, hModule
, tmp
, sizeof(tmp
)))
299 if ((ptr
= strrchr(tmp
, '\\')) != NULL
) ptr
++; else ptr
= tmp
;
300 strncpy(lpBaseName
, ptr
, nSize
);
301 lpBaseName
[nSize
- 1] = '\0';
302 return strlen(lpBaseName
);
305 /***********************************************************************
306 * GetModuleBaseNameW (PSAPI.@)
308 DWORD WINAPI
GetModuleBaseNameW(HANDLE hProcess
, HMODULE hModule
,
309 LPWSTR lpBaseName
, DWORD nSize
)
314 TRACE("(hProcess=%p, hModule=%p, %p, %ld)\n",
315 hProcess
, hModule
, lpBaseName
, nSize
);
317 if (!lpBaseName
|| !nSize
) return 0;
319 ptr
= HeapAlloc(GetProcessHeap(), 0, nSize
/ 2);
322 len
= GetModuleBaseNameA(hProcess
, hModule
, ptr
, nSize
/ 2);
325 lpBaseName
[0] = '\0';
329 if (!MultiByteToWideChar( CP_ACP
, 0, ptr
, -1, lpBaseName
, nSize
/ 2 ))
330 lpBaseName
[nSize
/ 2 - 1] = 0;
333 HeapFree(GetProcessHeap(), 0, ptr
);
337 /***********************************************************************
338 * GetModuleFileNameExA (PSAPI.@)
340 DWORD WINAPI
GetModuleFileNameExA(HANDLE hProcess
, HMODULE hModule
,
341 LPSTR lpFileName
, DWORD nSize
)
345 TRACE("(hProcess=%p, hModule=%p, %p, %ld)\n",
346 hProcess
, hModule
, lpFileName
, nSize
);
348 if (!lpFileName
|| !nSize
) return 0;
350 if ( hProcess
== GetCurrentProcess() )
351 return GetModuleFileNameA( hModule
, lpFileName
, nSize
);
355 SERVER_START_REQ( get_dll_info
)
357 req
->handle
= hProcess
;
358 req
->base_address
= (void*)hModule
;
359 wine_server_set_reply( req
, lpFileName
, nSize
- 1);
360 if (!wine_server_call_err( req
))
362 len
= wine_server_reply_size(reply
);
368 TRACE("return %s (%lu)\n", lpFileName
, len
);
373 /***********************************************************************
374 * GetModuleFileNameExW (PSAPI.@)
376 DWORD WINAPI
GetModuleFileNameExW(HANDLE hProcess
, HMODULE hModule
,
377 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() )
388 return GetModuleFileNameW( hModule
, lpFileName
, nSize
);
390 ptr
= HeapAlloc(GetProcessHeap(), 0, nSize
/ 2);
393 len
= GetModuleFileNameExA(hProcess
, hModule
, ptr
, nSize
/ 2);
396 lpFileName
[0] = '\0';
400 if (!MultiByteToWideChar( CP_ACP
, 0, ptr
, -1, lpFileName
, nSize
/ 2 ))
401 lpFileName
[nSize
/ 2 - 1] = 0;
404 HeapFree(GetProcessHeap(), 0, ptr
);
408 /***********************************************************************
409 * GetModuleInformation (PSAPI.@)
411 BOOL WINAPI
GetModuleInformation(HANDLE hProcess
, HMODULE hModule
,
412 LPMODULEINFO lpmodinfo
, DWORD cb
)
416 TRACE("(hProcess=%p, hModule=%p, %p, %ld)\n",
417 hProcess
, hModule
, lpmodinfo
, cb
);
419 if (cb
< sizeof(MODULEINFO
)) return FALSE
;
421 SERVER_START_REQ( get_dll_info
)
423 req
->handle
= hProcess
;
424 req
->base_address
= (void*)hModule
;
425 if (!wine_server_call_err( req
))
428 lpmodinfo
->lpBaseOfDll
= (void*)hModule
;
429 lpmodinfo
->SizeOfImage
= reply
->size
;
430 lpmodinfo
->EntryPoint
= reply
->entry_point
;
438 /***********************************************************************
439 * GetProcessMemoryInfo (PSAPI.@)
441 BOOL WINAPI
GetProcessMemoryInfo(HANDLE Process
,
442 PPROCESS_MEMORY_COUNTERS ppsmemCounters
, DWORD cb
)
444 FIXME("(hProcess=%p, %p, %ld): stub\n",
445 Process
, ppsmemCounters
, cb
);
447 memset(ppsmemCounters
, 0, cb
);
452 /***********************************************************************
453 * GetWsChanges (PSAPI.@)
455 BOOL WINAPI
GetWsChanges(HANDLE hProcess
,
456 PPSAPI_WS_WATCH_INFORMATION lpWatchInfo
, DWORD cb
)
458 FIXME("(hProcess=%p, %p, %ld): stub\n",
459 hProcess
, lpWatchInfo
, cb
);
461 memset(lpWatchInfo
, 0, cb
);
466 /***********************************************************************
467 * InitializeProcessForWsWatch (PSAPI.@)
469 BOOL WINAPI
InitializeProcessForWsWatch(HANDLE hProcess
)
471 FIXME("(hProcess=%p): stub\n", hProcess
);
476 /***********************************************************************
477 * QueryWorkingSet (PSAPI.?)
479 * I haven't been able to find the ordinal for this function,
480 * This means it can't be called from outside the DLL.
482 BOOL WINAPI
QueryWorkingSet(HANDLE hProcess
, LPVOID pv
, DWORD cb
)
484 FIXME("(hProcess=%p, %p, %ld)\n", hProcess
, pv
, cb
);
487 ((DWORD
*) pv
)[0] = 0; /* Empty WorkingSet */