diff --git a/reactos/lib/psapi/makefile b/reactos/lib/psapi/makefile index e6a14634e6e..db62edba3f4 100644 --- a/reactos/lib/psapi/makefile +++ b/reactos/lib/psapi/makefile @@ -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) diff --git a/reactos/lib/psapi/misc/stubs.c b/reactos/lib/psapi/misc/stubs.c index 0d7abd97d7a..a27bae87945 100644 --- a/reactos/lib/psapi/misc/stubs.c +++ b/reactos/lib/psapi/misc/stubs.c @@ -5,21 +5,6 @@ #include -/* - * @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 */ diff --git a/reactos/lib/psapi/misc/win32.c b/reactos/lib/psapi/misc/win32.c index 34a2c085f1e..a1870db1ffe 100644 --- a/reactos/lib/psapi/misc/win32.c +++ b/reactos/lib/psapi/misc/win32.c @@ -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 */ diff --git a/reactos/lib/psapi/precomp.h b/reactos/lib/psapi/precomp.h index 551dc305239..f0f87b357f2 100644 --- a/reactos/lib/psapi/precomp.h +++ b/reactos/lib/psapi/precomp.h @@ -11,4 +11,4 @@ #include #include #include - +#include