[PATCH] ntdll: Report valid data for ProcessVmCounters on Linux.

Andrew Church achurch at achurch.org
Wed Nov 11 21:03:26 CST 2015


Forwarded by request from https://bugs.winehq.org/show_bug.cgi?id=35563
(please note that I am not subscribed to the list).  This patch modifies
NtQueryInformationProcess() to return valid data for ProcessVmCounters on
Linux by reading /proc/self/status, so that GetProcessMemoryInfo() reports
actual process information rather than all zeros.

  --Andrew Church
    http://achurch.org/

diff -urN wine-git-4a1629c-orig/dlls/ntdll/process.c wine-git-4a1629c/dlls/ntdll/process.c
--- wine-git-4a1629c-orig/dlls/ntdll/process.c	2015-11-11 20:54:45 +0900
+++ wine-git-4a1629c/dlls/ntdll/process.c	2015-11-11 20:55:30 +0900
@@ -243,6 +243,46 @@
                     /* FIXME : real data */
                     memset(&pvmi, 0 , sizeof(VM_COUNTERS));
 
+#ifdef __linux__
+                    FILE *f = fopen("/proc/self/status", "r");
+                    if (f) {
+                        char buf[100];
+                        int at_bol = 1;
+                        while (fgets(buf, sizeof(buf), f)) {
+                            const int has_eol = (buf[strlen(buf)-1] == '\n');
+                            if (at_bol) {
+                                const char *tag = buf;
+                                char *s = strchr(buf, ':');
+                                if (s) {
+                                    *s++ = '\0';
+                                    unsigned long value = strtoul(s, NULL, 10);
+                                    if (strcmp(tag, "VmPeak") == 0) {
+                                        pvmi.PeakVirtualSize = value*1024;
+                                        pvmi.PeakPagefileUsage = value*1024;
+                                        pvmi.QuotaPeakPagedPoolUsage = value*1024;
+                                    } else if (strcmp(tag, "VmSize") == 0) {
+                                        pvmi.VirtualSize = value*1024;
+                                        pvmi.PagefileUsage = value*1024;
+                                        pvmi.QuotaPagedPoolUsage = value*1024;
+                                    } else if (strcmp(tag, "VmHWM") == 0) {
+                                        pvmi.PeakWorkingSetSize = value*1024;
+                                    } else if (strcmp(tag, "VmRSS") == 0) {
+                                        pvmi.WorkingSetSize = value*1024;
+                                    }
+                                    /* We could get QuotaNonPagedPoolUsage from
+                                     * the VmLck line, but Linux doesn't give a
+                                     * peak value for that, so we just ignore
+                                     * it instead of returning a "peak" value
+                                     * that might decrease over time.
+                                     * FIXME: track the peak value ourselves. */
+                                }
+                            }
+                            at_bol = has_eol;
+                        }
+                        fclose(f);
+                    }
+#endif  /* __linux__ */
+
                     len = ProcessInformationLength;
                     if (len != FIELD_OFFSET(VM_COUNTERS,PrivatePageCount)) len = sizeof(VM_COUNTERS);
 



More information about the wine-devel mailing list