You've already forked wine-staging
mirror of
https://gitlab.winehq.org/wine/wine-staging.git
synced 2025-09-12 18:50:20 -07:00
Added patch to return user/kernel times for threads and processes in NtQuerySystemInformation.
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
From e6832d1b0f923e7589424ade7571cc67dc768c4d Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
|
||||
Date: Thu, 9 Mar 2017 00:00:46 +0100
|
||||
Subject: ntdll: Set correct thread creation time for SystemProcessInformation
|
||||
in NtQuerySystemInformation.
|
||||
|
||||
---
|
||||
dlls/ntdll/nt.c | 2 +-
|
||||
server/protocol.def | 1 +
|
||||
server/snapshot.c | 11 ++++++-----
|
||||
server/thread.h | 1 +
|
||||
4 files changed, 9 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/dlls/ntdll/nt.c b/dlls/ntdll/nt.c
|
||||
index 86beb031e9c..fc8e3b1eb4e 100644
|
||||
--- a/dlls/ntdll/nt.c
|
||||
+++ b/dlls/ntdll/nt.c
|
||||
@@ -2012,7 +2012,7 @@ NTSTATUS WINAPI NtQuerySystemInformation(
|
||||
|
||||
memset(&spi->ti[i], 0, sizeof(spi->ti));
|
||||
|
||||
- spi->ti[i].CreateTime.QuadPart = 0xdeadbeef;
|
||||
+ spi->ti[i].CreateTime.QuadPart = reply->creation_time;
|
||||
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;
|
||||
diff --git a/server/protocol.def b/server/protocol.def
|
||||
index 60865a6ffc2..15adc51462f 100644
|
||||
--- a/server/protocol.def
|
||||
+++ b/server/protocol.def
|
||||
@@ -1783,6 +1783,7 @@ enum char_info_mode
|
||||
int count; /* thread usage count */
|
||||
process_id_t pid; /* process id */
|
||||
thread_id_t tid; /* thread id */
|
||||
+ timeout_t creation_time; /* thread creation time */
|
||||
int base_pri; /* base priority */
|
||||
int delta_pri; /* delta priority */
|
||||
@END
|
||||
diff --git a/server/snapshot.c b/server/snapshot.c
|
||||
index e35588a136c..858fca898a7 100644
|
||||
--- a/server/snapshot.c
|
||||
+++ b/server/snapshot.c
|
||||
@@ -144,11 +144,12 @@ static int snapshot_next_thread( struct snapshot *snapshot, struct next_thread_r
|
||||
return 0;
|
||||
}
|
||||
ptr = &snapshot->threads[snapshot->thread_pos++];
|
||||
- reply->count = ptr->count;
|
||||
- reply->pid = get_process_id( ptr->thread->process );
|
||||
- reply->tid = get_thread_id( ptr->thread );
|
||||
- reply->base_pri = ptr->priority;
|
||||
- reply->delta_pri = 0; /* FIXME */
|
||||
+ reply->count = ptr->count;
|
||||
+ reply->pid = get_process_id( ptr->thread->process );
|
||||
+ reply->tid = get_thread_id( ptr->thread );
|
||||
+ reply->creation_time = get_thread_creation_time( ptr->thread );
|
||||
+ reply->base_pri = ptr->priority;
|
||||
+ reply->delta_pri = 0; /* FIXME */
|
||||
return 1;
|
||||
}
|
||||
|
||||
diff --git a/server/thread.h b/server/thread.h
|
||||
index 282199149e6..2098c76a472 100644
|
||||
--- a/server/thread.h
|
||||
+++ b/server/thread.h
|
||||
@@ -145,5 +145,6 @@ static inline void clear_error(void) { set_error(0); }
|
||||
static inline void set_win32_error( unsigned int err ) { set_error( 0xc0010000 | err ); }
|
||||
|
||||
static inline thread_id_t get_thread_id( struct thread *thread ) { return thread->id; }
|
||||
+static inline timeout_t get_thread_creation_time( struct thread *thread ) { return thread->creation_time; }
|
||||
|
||||
#endif /* __WINE_SERVER_THREAD_H */
|
||||
--
|
||||
2.11.0
|
||||
|
@@ -0,0 +1,159 @@
|
||||
From 2578dfb02f0a8781970f5c7d967b1d07ae433e2f Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
|
||||
Date: Thu, 9 Mar 2017 16:27:23 +0100
|
||||
Subject: ntdll: Fill process kernel and user time.
|
||||
|
||||
---
|
||||
dlls/ntdll/nt.c | 6 +++-
|
||||
dlls/ntdll/ntdll_misc.h | 3 ++
|
||||
dlls/ntdll/thread.c | 84 ++++++++++++++++++++++++++++---------------------
|
||||
3 files changed, 56 insertions(+), 37 deletions(-)
|
||||
|
||||
diff --git a/dlls/ntdll/nt.c b/dlls/ntdll/nt.c
|
||||
index fc8e3b1eb4..6b67397471 100644
|
||||
--- a/dlls/ntdll/nt.c
|
||||
+++ b/dlls/ntdll/nt.c
|
||||
@@ -1922,6 +1922,7 @@ NTSTATUS WINAPI NtQuerySystemInformation(
|
||||
{
|
||||
SYSTEM_PROCESS_INFORMATION* spi = SystemInformation;
|
||||
SYSTEM_PROCESS_INFORMATION* last = NULL;
|
||||
+ unsigned long clk_tck = sysconf(_SC_CLK_TCK);
|
||||
HANDLE hSnap = 0;
|
||||
WCHAR procname[1024];
|
||||
WCHAR* exename;
|
||||
@@ -1959,7 +1960,7 @@ NTSTATUS WINAPI NtQuerySystemInformation(
|
||||
|
||||
if (Length >= len + procstructlen)
|
||||
{
|
||||
- /* ftCreationTime, ftUserTime, ftKernelTime;
|
||||
+ /* ftCreationTime;
|
||||
* vmCounters, ioCounters
|
||||
*/
|
||||
|
||||
@@ -1977,6 +1978,9 @@ 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);
|
||||
}
|
||||
len += procstructlen;
|
||||
}
|
||||
diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h
|
||||
index 5e4c39e8bd..443c86000d 100644
|
||||
--- a/dlls/ntdll/ntdll_misc.h
|
||||
+++ b/dlls/ntdll/ntdll_misc.h
|
||||
@@ -266,4 +266,7 @@ extern HANDLE keyed_event DECLSPEC_HIDDEN;
|
||||
|
||||
NTSTATUS WINAPI RtlHashUnicodeString(PCUNICODE_STRING,BOOLEAN,ULONG,ULONG*);
|
||||
|
||||
+/* 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;
|
||||
#endif
|
||||
diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c
|
||||
index 91a59517b3..29b6513f38 100644
|
||||
--- a/dlls/ntdll/thread.c
|
||||
+++ b/dlls/ntdll/thread.c
|
||||
@@ -71,6 +71,53 @@ static RTL_BITMAP tls_expansion_bitmap;
|
||||
static RTL_BITMAP fls_bitmap;
|
||||
static int nb_threads = 1;
|
||||
|
||||
+
|
||||
+BOOL read_process_time(int unix_pid, int unix_tid, unsigned long clk_tck,
|
||||
+ LARGE_INTEGER *kernel, LARGE_INTEGER *user)
|
||||
+{
|
||||
+#ifdef __linux__
|
||||
+ unsigned long usr, sys;
|
||||
+ char buf[512], *pos;
|
||||
+ FILE *fp;
|
||||
+ int i;
|
||||
+
|
||||
+ /* based on https://github.com/torvalds/linux/blob/master/fs/proc/array.c */
|
||||
+ if (unix_tid != -1)
|
||||
+ sprintf( buf, "/proc/%u/task/%u/stat", unix_pid, unix_tid );
|
||||
+ else
|
||||
+ sprintf( buf, "/proc/%u/stat", unix_pid );
|
||||
+ if ((fp = fopen( buf, "r" )))
|
||||
+ {
|
||||
+ pos = fgets( buf, sizeof(buf), fp );
|
||||
+ fclose( fp );
|
||||
+
|
||||
+ /* format of first chunk is "%d (%s) %c" - we have to skip to the last ')'
|
||||
+ * to avoid misinterpreting the string. */
|
||||
+ if (pos) pos = strrchr( pos, ')' );
|
||||
+ if (pos) pos = strchr( pos + 1, ' ' );
|
||||
+ if (pos) pos++;
|
||||
+
|
||||
+ /* skip over the following fields: state, ppid, pgid, sid, tty_nr, tty_pgrp,
|
||||
+ * task->flags, min_flt, cmin_flt, maj_flt, cmaj_flt */
|
||||
+ for (i = 0; (i < 11) && pos; i++)
|
||||
+ {
|
||||
+ pos = strchr( pos + 1, ' ' );
|
||||
+ if (pos) pos++;
|
||||
+ }
|
||||
+
|
||||
+ /* the next two values are user and system time */
|
||||
+ if (pos && (sscanf( pos, "%lu %lu", &usr, &sys ) == 2))
|
||||
+ {
|
||||
+ kernel->QuadPart = (ULONGLONG)sys * 10000000 / clk_tck;
|
||||
+ user->QuadPart = (ULONGLONG)usr * 10000000 / clk_tck;
|
||||
+ return TRUE;
|
||||
+ }
|
||||
+ }
|
||||
+#endif
|
||||
+ return FALSE;
|
||||
+}
|
||||
+
|
||||
+
|
||||
/***********************************************************************
|
||||
* get_unicode_string
|
||||
*
|
||||
@@ -1009,42 +1056,7 @@ NTSTATUS WINAPI NtQueryInformationThread( HANDLE handle, THREADINFOCLASS class,
|
||||
#ifdef __linux__
|
||||
/* only /proc provides exact values for a specific thread */
|
||||
if (unix_pid != -1 && unix_tid != -1)
|
||||
- {
|
||||
- unsigned long usr, sys;
|
||||
- char buf[512], *pos;
|
||||
- FILE *fp;
|
||||
- int i;
|
||||
-
|
||||
- /* based on https://github.com/torvalds/linux/blob/master/fs/proc/array.c */
|
||||
- sprintf( buf, "/proc/%u/task/%u/stat", unix_pid, unix_tid );
|
||||
- if ((fp = fopen( buf, "r" )))
|
||||
- {
|
||||
- pos = fgets( buf, sizeof(buf), fp );
|
||||
- fclose( fp );
|
||||
-
|
||||
- /* format of first chunk is "%d (%s) %c" - we have to skip to the last ')'
|
||||
- * to avoid misinterpreting the string. */
|
||||
- if (pos) pos = strrchr( pos, ')' );
|
||||
- if (pos) pos = strchr( pos + 1, ' ' );
|
||||
- if (pos) pos++;
|
||||
-
|
||||
- /* skip over the following fields: state, ppid, pgid, sid, tty_nr, tty_pgrp,
|
||||
- * task->flags, min_flt, cmin_flt, maj_flt, cmaj_flt */
|
||||
- for (i = 0; (i < 11) && pos; i++)
|
||||
- {
|
||||
- pos = strchr( pos + 1, ' ' );
|
||||
- if (pos) pos++;
|
||||
- }
|
||||
-
|
||||
- /* the next two values are user and system time */
|
||||
- if (pos && (sscanf( pos, "%lu %lu", &usr, &sys ) == 2))
|
||||
- {
|
||||
- kusrt.KernelTime.QuadPart = (ULONGLONG)sys * 10000000 / clk_tck;
|
||||
- kusrt.UserTime.QuadPart = (ULONGLONG)usr * 10000000 / clk_tck;
|
||||
- filled_times = TRUE;
|
||||
- }
|
||||
- }
|
||||
- }
|
||||
+ filled_times = read_process_time(unix_pid, unix_tid, clk_tck, &kusrt.KernelTime, &kusrt.UserTime);
|
||||
#endif
|
||||
|
||||
/* get values for current process instead */
|
||||
--
|
||||
2.11.0
|
||||
|
@@ -0,0 +1,64 @@
|
||||
From e048ad0cd3879fb8f752af7e2eeda770864f9982 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
|
||||
Date: Thu, 9 Mar 2017 16:32:59 +0100
|
||||
Subject: ntdll: Set process start time.
|
||||
|
||||
---
|
||||
dlls/ntdll/nt.c | 1 +
|
||||
server/protocol.def | 1 +
|
||||
server/snapshot.c | 15 ++++++++-------
|
||||
3 files changed, 10 insertions(+), 7 deletions(-)
|
||||
|
||||
diff --git a/dlls/ntdll/nt.c b/dlls/ntdll/nt.c
|
||||
index 03cfd032bc..45572cb393 100644
|
||||
--- a/dlls/ntdll/nt.c
|
||||
+++ b/dlls/ntdll/nt.c
|
||||
@@ -2058,6 +2058,7 @@ NTSTATUS WINAPI NtQuerySystemInformation(
|
||||
spi->UniqueProcessId = UlongToHandle(reply->pid);
|
||||
spi->ParentProcessId = UlongToHandle(reply->ppid);
|
||||
spi->HandleCount = reply->handles;
|
||||
+ spi->CreationTime.QuadPart = reply->start_time;
|
||||
|
||||
/* spi->ti will be set later on */
|
||||
|
||||
diff --git a/server/protocol.def b/server/protocol.def
|
||||
index 320e34384a..1347defe70 100644
|
||||
--- a/server/protocol.def
|
||||
+++ b/server/protocol.def
|
||||
@@ -1808,6 +1808,7 @@ enum char_info_mode
|
||||
int priority; /* process priority */
|
||||
int handles; /* number of handles */
|
||||
int unix_pid; /* Unix pid */
|
||||
+ timeout_t start_time; /* start time */
|
||||
VARARG(filename,unicode_str); /* file name of main exe */
|
||||
@END
|
||||
|
||||
diff --git a/server/snapshot.c b/server/snapshot.c
|
||||
index f2903d522e..e509e0aca9 100644
|
||||
--- a/server/snapshot.c
|
||||
+++ b/server/snapshot.c
|
||||
@@ -114,13 +114,14 @@ static int snapshot_next_process( struct snapshot *snapshot, struct next_process
|
||||
return 0;
|
||||
}
|
||||
ptr = &snapshot->processes[snapshot->process_pos++];
|
||||
- reply->count = ptr->count;
|
||||
- reply->pid = get_process_id( ptr->process );
|
||||
- reply->ppid = ptr->process->parent_id;
|
||||
- reply->threads = ptr->threads;
|
||||
- reply->priority = ptr->priority;
|
||||
- reply->handles = ptr->handles;
|
||||
- reply->unix_pid = ptr->process->unix_pid;
|
||||
+ reply->count = ptr->count;
|
||||
+ reply->pid = get_process_id( ptr->process );
|
||||
+ reply->ppid = ptr->process->parent_id;
|
||||
+ reply->threads = ptr->threads;
|
||||
+ reply->priority = ptr->priority;
|
||||
+ reply->handles = ptr->handles;
|
||||
+ reply->unix_pid = ptr->process->unix_pid;
|
||||
+ reply->start_time = ptr->process->start_time;
|
||||
if ((exe_module = get_process_exe_module( ptr->process )) && exe_module->filename)
|
||||
{
|
||||
data_size_t len = min( exe_module->namelen, get_reply_max_size() );
|
||||
--
|
||||
2.11.0
|
||||
|
@@ -0,0 +1,82 @@
|
||||
From 6c3b7e0065c239b488bb224c1c67ff971562fdca Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
|
||||
Date: Thu, 9 Mar 2017 21:14:13 +0100
|
||||
Subject: ntdll: Fill out thread times in process enumeration.
|
||||
|
||||
---
|
||||
dlls/ntdll/nt.c | 6 ++++++
|
||||
server/protocol.def | 1 +
|
||||
server/snapshot.c | 1 +
|
||||
server/thread.h | 1 +
|
||||
4 files changed, 9 insertions(+)
|
||||
|
||||
diff --git a/dlls/ntdll/nt.c b/dlls/ntdll/nt.c
|
||||
index 8c54e7edfb..8b84cd865b 100644
|
||||
--- a/dlls/ntdll/nt.c
|
||||
+++ b/dlls/ntdll/nt.c
|
||||
@@ -1928,6 +1928,7 @@ NTSTATUS WINAPI NtQuerySystemInformation(
|
||||
WCHAR* exename;
|
||||
DWORD wlen = 0;
|
||||
DWORD procstructlen = 0;
|
||||
+ int unix_pid = -1;
|
||||
|
||||
SERVER_START_REQ( create_snapshot )
|
||||
{
|
||||
@@ -1982,6 +1983,7 @@ NTSTATUS WINAPI NtQuerySystemInformation(
|
||||
if (reply->unix_pid != -1)
|
||||
read_process_time(reply->unix_pid, -1, clk_tck,
|
||||
&spi->KernelTime, &spi->UserTime);
|
||||
+ unix_pid = reply->unix_pid;
|
||||
}
|
||||
len += procstructlen;
|
||||
}
|
||||
@@ -2022,6 +2024,10 @@ NTSTATUS WINAPI NtQuerySystemInformation(
|
||||
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;
|
||||
+
|
||||
+ if (unix_pid != -1 && reply->unix_tid != -1)
|
||||
+ read_process_time(unix_pid, reply->unix_tid, clk_tck,
|
||||
+ &spi->ti[i].KernelTime, &spi->ti[i].UserTime);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
diff --git a/server/protocol.def b/server/protocol.def
|
||||
index b0b837cb93..542060decd 100644
|
||||
--- a/server/protocol.def
|
||||
+++ b/server/protocol.def
|
||||
@@ -1789,6 +1789,7 @@ enum char_info_mode
|
||||
timeout_t creation_time; /* thread creation time */
|
||||
int base_pri; /* base priority */
|
||||
int delta_pri; /* delta priority */
|
||||
+ int unix_tid; /* Unix tid */
|
||||
@END
|
||||
|
||||
|
||||
diff --git a/server/snapshot.c b/server/snapshot.c
|
||||
index cc8a9be1b5..a32207c720 100644
|
||||
--- a/server/snapshot.c
|
||||
+++ b/server/snapshot.c
|
||||
@@ -151,6 +151,7 @@ static int snapshot_next_thread( struct snapshot *snapshot, struct next_thread_r
|
||||
reply->creation_time = get_thread_creation_time( ptr->thread );
|
||||
reply->base_pri = ptr->priority;
|
||||
reply->delta_pri = 0; /* FIXME */
|
||||
+ reply->unix_tid = get_thread_unix_tid( ptr->thread );
|
||||
return 1;
|
||||
}
|
||||
|
||||
diff --git a/server/thread.h b/server/thread.h
|
||||
index 2098c76a47..9614e2140d 100644
|
||||
--- a/server/thread.h
|
||||
+++ b/server/thread.h
|
||||
@@ -145,6 +145,7 @@ static inline void clear_error(void) { set_error(0); }
|
||||
static inline void set_win32_error( unsigned int err ) { set_error( 0xc0010000 | err ); }
|
||||
|
||||
static inline thread_id_t get_thread_id( struct thread *thread ) { return thread->id; }
|
||||
+static inline int get_thread_unix_tid( struct thread *thread ) { return thread->unix_tid; }
|
||||
static inline timeout_t get_thread_creation_time( struct thread *thread ) { return thread->creation_time; }
|
||||
|
||||
#endif /* __WINE_SERVER_THREAD_H */
|
||||
--
|
||||
2.11.0
|
||||
|
@@ -1 +1,2 @@
|
||||
Fixes: [20230] Return correct values for GetThreadTimes function
|
||||
Fixes: Return correct thread creation time in SystemProcessInformation
|
||||
|
Reference in New Issue
Block a user