[PATCH 2/3] ntdll: Fill out thread times in process enumeration.

Zebediah Figura z.figura12 at gmail.com
Tue Jun 2 20:01:18 CDT 2020


From: Michael Müller <michael at fds-team.de>

Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
 dlls/ntdll/nt.c         | 42 +++++++++++++++++++++++++----------------
 dlls/ntdll/ntdll_misc.h |  1 +
 dlls/ntdll/thread.c     |  4 ++--
 server/protocol.def     |  1 +
 server/snapshot.c       |  1 +
 5 files changed, 31 insertions(+), 18 deletions(-)

diff --git a/dlls/ntdll/nt.c b/dlls/ntdll/nt.c
index 7758f19a16..9b5bbd09ee 100644
--- a/dlls/ntdll/nt.c
+++ b/dlls/ntdll/nt.c
@@ -2650,6 +2650,7 @@ NTSTATUS WINAPI NtQuerySystemInformation(
             len = 0;
             while (ret == STATUS_SUCCESS)
             {
+                int unix_pid = -1;
                 SERVER_START_REQ( next_process )
                 {
                     req->handle = wine_server_obj_handle( hSnap );
@@ -2657,6 +2658,8 @@ NTSTATUS WINAPI NtQuerySystemInformation(
                     wine_server_set_reply( req, procname, sizeof(procname)-sizeof(WCHAR) );
                     if (!(ret = wine_server_call( req )))
                     {
+                        unix_pid = reply->unix_pid;
+
                         /* Make sure procname is 0 terminated */
                         procname[wine_server_reply_size(reply) / sizeof(WCHAR)] = 0;
 
@@ -2693,7 +2696,7 @@ NTSTATUS WINAPI NtQuerySystemInformation(
                     }
                 }
                 SERVER_END_REQ;
- 
+
                 if (ret != STATUS_SUCCESS)
                 {
                     if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
@@ -2708,31 +2711,38 @@ NTSTATUS WINAPI NtQuerySystemInformation(
                     i = j = 0;
                     while (ret == STATUS_SUCCESS)
                     {
+                        int unix_tid, pid, tid, base_pri, delta_pri;
                         SERVER_START_REQ( next_thread )
                         {
                             req->handle = wine_server_obj_handle( hSnap );
                             req->reset = (j == 0);
                             if (!(ret = wine_server_call( req )))
                             {
+                                unix_tid = reply->unix_tid;
+                                pid = reply->pid;
+                                tid = reply->tid;
+                                base_pri = reply->base_pri;
+                                delta_pri = reply->delta_pri;
                                 j++;
-                                if (UlongToHandle(reply->pid) == spi->UniqueProcessId)
-                                {
-                                    /* ftKernelTime, ftUserTime, ftCreateTime;
-                                     * dwTickCount, dwStartAddress
-                                     */
-
-                                    memset(&spi->ti[i], 0, sizeof(spi->ti));
-
-                                    spi->ti[i].CreateTime.QuadPart = 0xdeadbeef;
-                                    spi->ti[i].ClientId.UniqueProcess = UlongToHandle(reply->pid);
-                                    spi->ti[i].ClientId.UniqueThread  = UlongToHandle(reply->tid);
-                                    spi->ti[i].dwCurrentPriority = reply->base_pri + reply->delta_pri;
-                                    spi->ti[i].dwBasePriority = reply->base_pri;
-                                    i++;
-                                }
                             }
                         }
                         SERVER_END_REQ;
+
+                        if (!ret)
+                        {
+                            if (UlongToHandle(pid) == spi->UniqueProcessId)
+                            {
+                                memset(&spi->ti[i], 0, sizeof(spi->ti));
+
+                                spi->ti[i].CreateTime.QuadPart = 0xdeadbeef;
+                                spi->ti[i].ClientId.UniqueProcess = UlongToHandle(pid);
+                                spi->ti[i].ClientId.UniqueThread  = UlongToHandle(tid);
+                                spi->ti[i].dwCurrentPriority = base_pri + delta_pri;
+                                spi->ti[i].dwBasePriority = base_pri;
+                                get_thread_times(unix_pid, unix_tid, &spi->ti[i].KernelTime, &spi->ti[i].UserTime);
+                                i++;
+                            }
+                        }
                     }
                     if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
 
diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h
index e9a3230e81..64163a175c 100644
--- a/dlls/ntdll/ntdll_misc.h
+++ b/dlls/ntdll/ntdll_misc.h
@@ -56,6 +56,7 @@ struct drive_info
 
 extern NTSTATUS close_handle( HANDLE ) DECLSPEC_HIDDEN;
 extern ULONG_PTR get_system_affinity_mask(void) DECLSPEC_HIDDEN;
+extern BOOL get_thread_times(int unix_pid, int unix_tid, LARGE_INTEGER *kernel_time, LARGE_INTEGER *user_time) DECLSPEC_HIDDEN;
 
 /* exceptions */
 extern void wait_suspend( CONTEXT *context ) DECLSPEC_HIDDEN;
diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c
index 7ec4a359ec..c0821bcf13 100644
--- a/dlls/ntdll/thread.c
+++ b/dlls/ntdll/thread.c
@@ -768,7 +768,7 @@ NTSTATUS get_thread_context( HANDLE handle, context_t *context, unsigned int fla
 }
 
 #ifdef linux
-static BOOL get_thread_times(int unix_pid, int unix_tid, LARGE_INTEGER *kernel_time, LARGE_INTEGER *user_time)
+BOOL get_thread_times(int unix_pid, int unix_tid, LARGE_INTEGER *kernel_time, LARGE_INTEGER *user_time)
 {
     unsigned long clocks_per_sec = sysconf(_SC_CLK_TCK);
     unsigned long usr, sys;
@@ -813,7 +813,7 @@ static BOOL get_thread_times(int unix_pid, int unix_tid, LARGE_INTEGER *kernel_t
     return FALSE;
 }
 #else
-static BOOL get_thread_times(int unix_pid, int unix_tid, LARGE_INTEGER *kernel_time, LARGE_INTEGER *user_time)
+BOOL get_thread_times(int unix_pid, int unix_tid, LARGE_INTEGER *kernel_time, LARGE_INTEGER *user_time)
 {
     static int once;
     if (!once++) FIXME("not implemented on this platform\n");
diff --git a/server/protocol.def b/server/protocol.def
index 0e4c6e79bc..57fdf862a7 100644
--- a/server/protocol.def
+++ b/server/protocol.def
@@ -1913,6 +1913,7 @@ enum char_info_mode
     thread_id_t  tid;           /* thread id */
     int          base_pri;      /* base priority */
     int          delta_pri;     /* delta priority */
+    int          unix_tid;      /* thread native pid */
 @END
 
 
diff --git a/server/snapshot.c b/server/snapshot.c
index a0f2ea17a3..bdceaef530 100644
--- a/server/snapshot.c
+++ b/server/snapshot.c
@@ -150,6 +150,7 @@ static int snapshot_next_thread( struct snapshot *snapshot, struct next_thread_r
     reply->tid       = get_thread_id( ptr->thread );
     reply->base_pri  = ptr->priority;
     reply->delta_pri = 0;  /* FIXME */
+    reply->unix_tid  = ptr->thread->unix_tid;
     return 1;
 }
 
-- 
2.26.2




More information about the wine-devel mailing list