implemented GetProcessMemoryInfo()

svn path=/trunk/; revision=13051
This commit is contained in:
Thomas Bluemel 2005-01-15 02:33:06 +00:00
parent dd0186b047
commit 3e133f3384
4 changed files with 66 additions and 18 deletions

View file

@ -6,14 +6,14 @@ TARGET_TYPE = dynlink
TARGET_NAME = psapi
TARGET_SDKLIBS = epsapi.a ntdll.a kernel32.a
TARGET_SDKLIBS = pseh.a epsapi.a ntdll.a kernel32.a
TARGET_CFLAGS = -I./include -Wall -Werror
# require os code to explicitly request A/W version of structs/functions
TARGET_CFLAGS += -D_DISABLE_TIDENTS
TARGET_LFLAGS = -nostartfiles -nostdlib
TARGET_LFLAGS = -nostartfiles
TARGET_BASE = $(TARGET_BASE_LIB_PSAPI)

View file

@ -5,21 +5,6 @@
#include <debug.h>
/*
* @unimplemented
*/
BOOL
STDCALL
GetProcessMemoryInfo(HANDLE Process,
PPROCESS_MEMORY_COUNTERS ppsmemCounters,
DWORD cb)
{
DPRINT1("PSAPI: GetProcessMemoryInfo is UNIMPLEMENTED!\n");
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
}
/*
* @unimplemented
*/

View file

@ -1302,4 +1302,67 @@ GetPerformanceInfo(PPERFORMANCE_INFORMATION pPerformanceInformation,
return TRUE;
}
/*
* @implemented
*/
BOOL
STDCALL
GetProcessMemoryInfo(HANDLE Process,
PPROCESS_MEMORY_COUNTERS ppsmemCounters,
DWORD cb)
{
NTSTATUS Status;
VM_COUNTERS vmc;
BOOL Ret = FALSE;
/* XP's implementation secures access to ppsmemCounters in SEH, we should behave
similar so we can return the proper error codes when bad pointers are passed
to this function! */
_SEH_TRY
{
if(cb < sizeof(PROCESS_MEMORY_COUNTERS))
{
SetLastError(ERROR_INSUFFICIENT_BUFFER);
_SEH_LEAVE;
}
/* ppsmemCounters->cb isn't checked at all! */
Status = NtQueryInformationProcess(Process,
ProcessVmCounters,
&vmc,
sizeof(vmc),
NULL);
if(!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
_SEH_LEAVE;
}
/* fill the structure with the collected information, in case of bad pointers
SEH will catch the exception and set the appropriate error code */
ppsmemCounters->cb = sizeof(PROCESS_MEMORY_COUNTERS);
ppsmemCounters->PageFaultCount = vmc.PageFaultCount;
ppsmemCounters->PeakWorkingSetSize = vmc.PeakWorkingSetSize;
ppsmemCounters->WorkingSetSize = vmc.WorkingSetSize;
ppsmemCounters->QuotaPeakPagedPoolUsage = vmc.QuotaPeakPagedPoolUsage;
ppsmemCounters->QuotaPagedPoolUsage = vmc.QuotaPagedPoolUsage;
ppsmemCounters->QuotaPeakNonPagedPoolUsage = vmc.QuotaPeakNonPagedPoolUsage;
ppsmemCounters->QuotaNonPagedPoolUsage = vmc.QuotaNonPagedPoolUsage;
ppsmemCounters->PagefileUsage = vmc.PagefileUsage;
ppsmemCounters->PeakPagefileUsage = vmc.PeakPagefileUsage;
Ret = TRUE;
}
_SEH_HANDLE
{
SetLastErrorByStatus(_SEH_GetExceptionCode());
}
_SEH_END;
return Ret;
}
/* EOF */

View file

@ -11,4 +11,4 @@
#include <napi/teb.h>
#include <ntos/heap.h>
#include <ntdll/ldr.h>
#include <pseh.h>