[PATCH 3/3] Kernel32: Fix getting remote process times in GetProcessTimes

brock at polynubstudios.com brock at polynubstudios.com
Wed Feb 19 03:50:29 CST 2020


From: Brock York <twunknown at gmail.com>

-GetProcessTimes would return the current processes cpu and kernel times
 even if the handle was for a different remote process.
-Read the user and kernel times using get_process_times from wineserver
 if the requested process to read from is not the current process. If the
 requested process is the current process then the times(7) syscall
 is used instead.
---
 dlls/kernel32/time.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/dlls/kernel32/time.c b/dlls/kernel32/time.c
index 4ebdabf18c..050c8b6b5c 100644
--- a/dlls/kernel32/time.c
+++ b/dlls/kernel32/time.c
@@ -180,7 +180,8 @@ static void TIME_ClockTimeToFileTime(clock_t unix_time, LPFILETIME filetime)
  *  Also, there is a need to separate times used by different applications.
  *
  * BUGS
- *  KernelTime and UserTime are always for the current process
+ *  twunknown at gmail.com:
+ *  Cannot get process time if hprocess handle is for another process and not on Linux
  */
 BOOL WINAPI GetProcessTimes( HANDLE hprocess, LPFILETIME lpCreationTime,
     LPFILETIME lpExitTime, LPFILETIME lpKernelTime, LPFILETIME lpUserTime )
@@ -188,7 +189,34 @@ BOOL WINAPI GetProcessTimes( HANDLE hprocess, LPFILETIME lpCreationTime,
     struct tms tms;
     KERNEL_USER_TIMES pti;
 
-    times(&tms);
+    //CompareObjectHandles is a Window 10 thing so this should suffice
+    //If process is current process then just use times syscall
+    if (hprocess == GetCurrentProcess())
+        times(&tms);
+#ifdef linux
+    else
+    {
+        SERVER_START_REQ( get_process_time )
+        {
+            req->handle = wine_server_obj_handle( hprocess );
+            if (wine_server_call( req ) == STATUS_SUCCESS)
+            {
+                tms.tms_utime = reply->utime;
+                tms.tms_stime = reply->stime;
+            }
+            else
+                return FALSE;
+        }
+        SERVER_END_REQ;
+    }
+#else //If not on linux we can't get another processes time, so return failure
+    else
+    {
+        FIXME("Cannot get process time for another process on non linux OS\n");
+        return FALSE;
+    }
+#endif
+
     TIME_ClockTimeToFileTime(tms.tms_utime,lpUserTime);
     TIME_ClockTimeToFileTime(tms.tms_stime,lpKernelTime);
     if (NtQueryInformationProcess( hprocess, ProcessTimes, &pti, sizeof(pti), NULL))
-- 
2.25.0




More information about the wine-devel mailing list