From 69e9651c1ae0542e52f5ea924b9e286584446607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=BCller?= Date: Sun, 28 Jun 2020 20:43:18 -0500 Subject: [PATCH] ntdll: Return thread times in NtQuerySystemInformation(SystemProcessInformation). Signed-off-by: Zebediah Figura Signed-off-by: Alexandre Julliard --- dlls/ntdll/unix/system.c | 40 +++++++++++++++++++++------------- dlls/ntdll/unix/thread.c | 4 ++-- dlls/ntdll/unix/unix_private.h | 2 ++ include/wine/server_protocol.h | 4 ++-- server/protocol.def | 1 + server/request.h | 1 + server/snapshot.c | 1 + server/trace.c | 1 + 8 files changed, 35 insertions(+), 19 deletions(-) diff --git a/dlls/ntdll/unix/system.c b/dlls/ntdll/unix/system.c index 5e2e763445c..fd86ab874ab 100644 --- a/dlls/ntdll/unix/system.c +++ b/dlls/ntdll/unix/system.c @@ -2101,6 +2101,7 @@ NTSTATUS WINAPI NtQuerySystemInformation( SYSTEM_INFORMATION_CLASS class, len = 0; while (ret == STATUS_SUCCESS) { + int unix_pid = -1; SERVER_START_REQ( next_process ) { req->handle = wine_server_obj_handle( handle ); @@ -2108,6 +2109,8 @@ NTSTATUS WINAPI NtQuerySystemInformation( SYSTEM_INFORMATION_CLASS class, 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; @@ -2156,31 +2159,38 @@ NTSTATUS WINAPI NtQuerySystemInformation( SYSTEM_INFORMATION_CLASS class, 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( handle ); 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/unix/thread.c b/dlls/ntdll/unix/thread.c index 54483e1f994..3655adf2db9 100644 --- a/dlls/ntdll/unix/thread.c +++ b/dlls/ntdll/unix/thread.c @@ -824,7 +824,7 @@ static void wow64_context_to_server( context_t *to, const WOW64_CONTEXT *from ) #endif /* __x86_64__ */ #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; @@ -869,7 +869,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/dlls/ntdll/unix/unix_private.h b/dlls/ntdll/unix/unix_private.h index ee6caaec8f5..fe63606ed83 100644 --- a/dlls/ntdll/unix/unix_private.h +++ b/dlls/ntdll/unix/unix_private.h @@ -209,6 +209,8 @@ extern void virtual_fill_image_information( const pe_image_info_t *pe_info, SECTION_IMAGE_INFORMATION *info ) DECLSPEC_HIDDEN; extern NTSTATUS get_thread_ldt_entry( HANDLE handle, void *data, ULONG len, ULONG *ret_len ) DECLSPEC_HIDDEN; +extern BOOL get_thread_times( int unix_pid, int unix_tid, LARGE_INTEGER *kernel_time, + LARGE_INTEGER *user_time ) DECLSPEC_HIDDEN; extern void signal_init_threading(void) DECLSPEC_HIDDEN; extern NTSTATUS signal_alloc_thread( TEB *teb ) DECLSPEC_HIDDEN; extern void signal_free_thread( TEB *teb ) DECLSPEC_HIDDEN; diff --git a/include/wine/server_protocol.h b/include/wine/server_protocol.h index 0473c6a64a9..13da55adedb 100644 --- a/include/wine/server_protocol.h +++ b/include/wine/server_protocol.h @@ -2493,7 +2493,7 @@ struct next_thread_reply thread_id_t tid; int base_pri; int delta_pri; - char __pad_28[4]; + int unix_tid; }; @@ -6702,7 +6702,7 @@ union generic_reply /* ### protocol_version begin ### */ -#define SERVER_PROTOCOL_VERSION 610 +#define SERVER_PROTOCOL_VERSION 611 /* ### protocol_version end ### */ diff --git a/server/protocol.def b/server/protocol.def index ed8ca3c478d..38079f23daf 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/request.h b/server/request.h index 2a646438488..3b7db3997b5 100644 --- a/server/request.h +++ b/server/request.h @@ -1362,6 +1362,7 @@ C_ASSERT( FIELD_OFFSET(struct next_thread_reply, pid) == 12 ); C_ASSERT( FIELD_OFFSET(struct next_thread_reply, tid) == 16 ); C_ASSERT( FIELD_OFFSET(struct next_thread_reply, base_pri) == 20 ); C_ASSERT( FIELD_OFFSET(struct next_thread_reply, delta_pri) == 24 ); +C_ASSERT( FIELD_OFFSET(struct next_thread_reply, unix_tid) == 28 ); C_ASSERT( sizeof(struct next_thread_reply) == 32 ); C_ASSERT( FIELD_OFFSET(struct wait_debug_event_request, get_handle) == 12 ); C_ASSERT( sizeof(struct wait_debug_event_request) == 16 ); diff --git a/server/snapshot.c b/server/snapshot.c index a0f2ea17a3e..bdceaef5302 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; } diff --git a/server/trace.c b/server/trace.c index 2b22dc52075..951ac44d9d2 100644 --- a/server/trace.c +++ b/server/trace.c @@ -2412,6 +2412,7 @@ static void dump_next_thread_reply( const struct next_thread_reply *req ) fprintf( stderr, ", tid=%04x", req->tid ); fprintf( stderr, ", base_pri=%d", req->base_pri ); fprintf( stderr, ", delta_pri=%d", req->delta_pri ); + fprintf( stderr, ", unix_tid=%d", req->unix_tid ); } static void dump_wait_debug_event_request( const struct wait_debug_event_request *req )