Added patch to fill process virtual memory counters in NtQuerySystemInformation.

This commit is contained in:
Sebastian Lackner 2017-03-20 17:26:23 +01:00
parent a47000e41c
commit 3f05773e20
3 changed files with 124 additions and 2 deletions

View File

@ -0,0 +1,119 @@
From 16d6f502dc86d2356b476ef0449b38353e3abc73 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
Date: Thu, 9 Mar 2017 22:56:45 +0100
Subject: ntdll: Fill process virtual memory counters in
NtQuerySystemInformation.
---
dlls/ntdll/nt.c | 3 +++
dlls/ntdll/ntdll_misc.h | 1 +
dlls/ntdll/process.c | 2 +-
dlls/ntdll/tests/info.c | 5 +----
dlls/ntdll/thread.c | 36 ++++++++++++++++++++++++++++++++++++
5 files changed, 42 insertions(+), 5 deletions(-)
diff --git a/dlls/ntdll/nt.c b/dlls/ntdll/nt.c
index 1dd890c4bd..a793b57221 100644
--- a/dlls/ntdll/nt.c
+++ b/dlls/ntdll/nt.c
@@ -2077,8 +2077,11 @@ NTSTATUS WINAPI NtQuerySystemInformation(
/* spi->ti will be set later on */
if (reply->unix_pid != -1)
+ {
read_process_time(reply->unix_pid, -1, clk_tck,
&spi->KernelTime, &spi->UserTime);
+ read_process_memory_stats(reply->unix_pid, &spi->vmCounters);
+ }
unix_pid = reply->unix_pid;
}
len += procstructlen;
diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h
index 0ecc099133..d556a21ee6 100644
--- a/dlls/ntdll/ntdll_misc.h
+++ b/dlls/ntdll/ntdll_misc.h
@@ -289,4 +289,5 @@ extern void CDECL NTDLL_wine_get_host_version( const char **sysname, const char
/* process / thread time */
extern BOOL read_process_time(int unix_pid, int unix_tid, unsigned long clk_tck,
LARGE_INTEGER *kernel, LARGE_INTEGER *user) DECLSPEC_HIDDEN;
+extern BOOL read_process_memory_stats(int unix_pid, VM_COUNTERS *pvmi) DECLSPEC_HIDDEN;
#endif
diff --git a/dlls/ntdll/process.c b/dlls/ntdll/process.c
index 39cd8be601..993d90290d 100644
--- a/dlls/ntdll/process.c
+++ b/dlls/ntdll/process.c
@@ -135,7 +135,7 @@ static void fill_VM_COUNTERS(VM_COUNTERS* pvmi)
static void fill_VM_COUNTERS(VM_COUNTERS* pvmi)
{
- /* FIXME : real data */
+ read_process_memory_stats(getpid(), pvmi);
}
#endif
diff --git a/dlls/ntdll/tests/info.c b/dlls/ntdll/tests/info.c
index c65a74bf5e..b9c44267a9 100644
--- a/dlls/ntdll/tests/info.c
+++ b/dlls/ntdll/tests/info.c
@@ -1134,10 +1134,7 @@ static void test_query_process_vm(void)
/* Check if we have some return values */
trace("WorkingSetSize : %ld\n", pvi.WorkingSetSize);
- todo_wine
- {
- ok( pvi.WorkingSetSize > 0, "Expected a WorkingSetSize > 0\n");
- }
+ ok( pvi.WorkingSetSize > 0, "Expected a WorkingSetSize > 0\n");
}
static void test_query_process_io(void)
diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c
index 28ce2a1362..ccbc41d6ac 100644
--- a/dlls/ntdll/thread.c
+++ b/dlls/ntdll/thread.c
@@ -117,6 +117,42 @@ BOOL read_process_time(int unix_pid, int unix_tid, unsigned long clk_tck,
return FALSE;
}
+BOOL read_process_memory_stats(int unix_pid, VM_COUNTERS *pvmi)
+{
+ BOOL ret = FALSE;
+#ifdef __linux__
+ unsigned long size, resident, shared, trs, drs, lrs, dt;
+ char buf[512];
+ FILE *fp;
+
+ sprintf( buf, "/proc/%u/statm", unix_pid );
+ if ((fp = fopen( buf, "r" )))
+ {
+ if (fscanf( fp, "%lu %lu %lu %lu %lu %lu %lu",
+ &size, &resident, &shared, &trs, &drs, &lrs, &dt ) == 7)
+ {
+ pvmi->VirtualSize = size * page_size;
+ pvmi->WorkingSetSize = resident * page_size;
+ pvmi->PrivatePageCount = size - shared;
+
+ /* these values are not available through /proc/pid/statm */
+ pvmi->PeakVirtualSize = pvmi->VirtualSize;
+ pvmi->PageFaultCount = 0;
+ pvmi->PeakWorkingSetSize = pvmi->WorkingSetSize;
+ pvmi->QuotaPagedPoolUsage = pvmi->VirtualSize;
+ pvmi->QuotaPeakPagedPoolUsage = pvmi->QuotaPagedPoolUsage;
+ pvmi->QuotaPeakNonPagedPoolUsage = 0;
+ pvmi->QuotaNonPagedPoolUsage = 0;
+ pvmi->PagefileUsage = 0;
+ pvmi->PeakPagefileUsage = 0;
+
+ ret = TRUE;
+ }
+ fclose( fp );
+ }
+#endif
+ return ret;
+}
/***********************************************************************
* get_unicode_string
--
2.11.0

View File

@ -1,2 +1,3 @@
Fixes: [20230] Return correct values for GetThreadTimes function
Fixes: Return correct thread creation time in SystemProcessInformation
Fixes: Fill process virtual memory counters in NtQuerySystemInformation

View File

@ -5419,8 +5419,8 @@ fi
# | * [#20230] Return correct values for GetThreadTimes function
# |
# | Modified files:
# | * dlls/ntdll/nt.c, dlls/ntdll/ntdll_misc.h, dlls/ntdll/thread.c, server/protocol.def, server/snapshot.c, server/thread.c,
# | server/thread.h
# | * dlls/ntdll/nt.c, dlls/ntdll/ntdll_misc.h, dlls/ntdll/process.c, dlls/ntdll/tests/info.c, dlls/ntdll/thread.c,
# | server/protocol.def, server/snapshot.c, server/thread.c, server/thread.h
# |
if test "$enable_ntdll_ThreadTime" -eq 1; then
patch_apply ntdll-ThreadTime/0001-ntdll-Return-correct-values-in-GetThreadTimes-for-al.patch
@ -5428,12 +5428,14 @@ if test "$enable_ntdll_ThreadTime" -eq 1; then
patch_apply ntdll-ThreadTime/0003-ntdll-Fill-process-kernel-and-user-time.patch
patch_apply ntdll-ThreadTime/0004-ntdll-Set-process-start-time.patch
patch_apply ntdll-ThreadTime/0005-ntdll-Fill-out-thread-times-in-process-enumeration.patch
patch_apply ntdll-ThreadTime/0006-ntdll-Fill-process-virtual-memory-counters-in-NtQuer.patch
(
printf '%s\n' '+ { "Sebastian Lackner", "ntdll: Return correct values in GetThreadTimes() for all threads.", 1 },';
printf '%s\n' '+ { "Michael Müller", "ntdll: Set correct thread creation time for SystemProcessInformation in NtQuerySystemInformation.", 1 },';
printf '%s\n' '+ { "Michael Müller", "ntdll: Fill process kernel and user time.", 1 },';
printf '%s\n' '+ { "Michael Müller", "ntdll: Set process start time.", 1 },';
printf '%s\n' '+ { "Michael Müller", "ntdll: Fill out thread times in process enumeration.", 1 },';
printf '%s\n' '+ { "Michael Müller", "ntdll: Fill process virtual memory counters in NtQuerySystemInformation.", 1 },';
) >> "$patchlist"
fi