Bernhard Loos : ntoskrnl: Correctly implement PsGetCurrentThread/ProcessId.
Alexandre Julliard
julliard at winehq.org
Fri Oct 28 12:48:38 CDT 2011
Module: wine
Branch: master
Commit: 507d92905174ccef96a33a806bfc383874ff7dcf
URL: http://source.winehq.org/git/wine.git/?a=commit;h=507d92905174ccef96a33a806bfc383874ff7dcf
Author: Bernhard Loos <bernhardloos at googlemail.com>
Date: Thu Oct 27 14:20:19 2011 +0200
ntoskrnl: Correctly implement PsGetCurrentThread/ProcessId.
---
dlls/ntoskrnl.exe/ntoskrnl.c | 29 ++++++++++++++++++++++-------
include/wine/server_protocol.h | 4 +++-
server/device.c | 3 +++
server/protocol.def | 2 ++
server/request.h | 8 +++++---
server/trace.c | 2 ++
6 files changed, 37 insertions(+), 11 deletions(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c
index e5668fd..9c7916e 100644
--- a/dlls/ntoskrnl.exe/ntoskrnl.c
+++ b/dlls/ntoskrnl.exe/ntoskrnl.c
@@ -68,6 +68,13 @@ struct IrpInstance
IRP *irp;
};
+/* tid of the thread running client request */
+static DWORD request_thread;
+
+/* pid/tid of the client thread */
+static DWORD client_tid;
+static DWORD client_pid;
+
#ifdef __i386__
#define DEFINE_FASTCALL1_ENTRYPOINT( name ) \
__ASM_STDCALL_FUNC( name, 4, \
@@ -197,6 +204,8 @@ NTSTATUS CDECL wine_ntoskrnl_main_loop( HANDLE stop_event )
ULONG in_size = 4096, out_size = 0;
HANDLE handles[2];
+ request_thread = GetCurrentThreadId();
+
if (!(in_buff = HeapAlloc( GetProcessHeap(), 0, in_size )))
{
ERR( "failed to allocate buffer\n" );
@@ -217,11 +226,13 @@ NTSTATUS CDECL wine_ntoskrnl_main_loop( HANDLE stop_event )
wine_server_set_reply( req, in_buff, in_size );
if (!(status = wine_server_call( req )))
{
- code = reply->code;
- ioctl = reply->next;
- device = wine_server_get_ptr( reply->user_ptr );
- in_size = reply->in_size;
- out_size = reply->out_size;
+ code = reply->code;
+ ioctl = reply->next;
+ device = wine_server_get_ptr( reply->user_ptr );
+ client_tid = reply->client_pid;
+ client_pid = reply->client_tid;
+ in_size = reply->in_size;
+ out_size = reply->out_size;
}
else
{
@@ -1465,7 +1476,9 @@ NTSTATUS WINAPI PsCreateSystemThread(PHANDLE ThreadHandle, ULONG DesiredAccess,
*/
HANDLE WINAPI PsGetCurrentProcessId(void)
{
- return UlongToHandle(GetCurrentProcessId()); /* FIXME: not quite right... */
+ if (GetCurrentThreadId() == request_thread)
+ return UlongToHandle(client_pid);
+ return UlongToHandle(GetCurrentProcessId());
}
@@ -1474,7 +1487,9 @@ HANDLE WINAPI PsGetCurrentProcessId(void)
*/
HANDLE WINAPI PsGetCurrentThreadId(void)
{
- return UlongToHandle(GetCurrentThreadId()); /* FIXME: not quite right... */
+ if (GetCurrentThreadId() == request_thread)
+ return UlongToHandle(client_tid);
+ return UlongToHandle(GetCurrentThreadId());
}
diff --git a/include/wine/server_protocol.h b/include/wine/server_protocol.h
index e0b0ac8..ab239f3 100644
--- a/include/wine/server_protocol.h
+++ b/include/wine/server_protocol.h
@@ -4613,6 +4613,8 @@ struct get_next_device_request_reply
obj_handle_t next;
ioctl_code_t code;
client_ptr_t user_ptr;
+ process_id_t client_pid;
+ thread_id_t client_tid;
data_size_t in_size;
data_size_t out_size;
/* VARARG(next_data,bytes); */
@@ -5637,6 +5639,6 @@ union generic_reply
struct set_suspend_context_reply set_suspend_context_reply;
};
-#define SERVER_PROTOCOL_VERSION 427
+#define SERVER_PROTOCOL_VERSION 428
#endif /* __WINE_WINE_SERVER_PROTOCOL_H */
diff --git a/server/device.c b/server/device.c
index 4d134a3..49f90e3 100644
--- a/server/device.c
+++ b/server/device.c
@@ -32,6 +32,7 @@
#include "file.h"
#include "handle.h"
#include "request.h"
+#include "process.h"
struct ioctl_call
{
@@ -510,6 +511,8 @@ DECL_HANDLER(get_next_device_request)
ioctl = LIST_ENTRY( ptr, struct ioctl_call, mgr_entry );
reply->code = ioctl->code;
reply->user_ptr = ioctl->device->user_ptr;
+ reply->client_pid = get_process_id( ioctl->thread->process );
+ reply->client_tid = get_thread_id( ioctl->thread );
reply->in_size = ioctl->in_size;
reply->out_size = ioctl->out_size;
if (ioctl->in_size > get_reply_max_size()) set_error( STATUS_BUFFER_OVERFLOW );
diff --git a/server/protocol.def b/server/protocol.def
index bec2e3c..a59bb6e 100644
--- a/server/protocol.def
+++ b/server/protocol.def
@@ -3203,6 +3203,8 @@ enum coords_relative
obj_handle_t next; /* handle to the next ioctl */
ioctl_code_t code; /* ioctl code */
client_ptr_t user_ptr; /* opaque ptr for the device */
+ process_id_t client_pid; /* pid of process calling ioctl */
+ thread_id_t client_tid; /* tid of thread calling ioctl */
data_size_t in_size; /* total needed input size */
data_size_t out_size; /* needed output size */
VARARG(next_data,bytes); /* input data of the next ioctl */
diff --git a/server/request.h b/server/request.h
index b875e30..ac69461 100644
--- a/server/request.h
+++ b/server/request.h
@@ -2046,9 +2046,11 @@ C_ASSERT( sizeof(struct get_next_device_request_request) == 24 );
C_ASSERT( FIELD_OFFSET(struct get_next_device_request_reply, next) == 8 );
C_ASSERT( FIELD_OFFSET(struct get_next_device_request_reply, code) == 12 );
C_ASSERT( FIELD_OFFSET(struct get_next_device_request_reply, user_ptr) == 16 );
-C_ASSERT( FIELD_OFFSET(struct get_next_device_request_reply, in_size) == 24 );
-C_ASSERT( FIELD_OFFSET(struct get_next_device_request_reply, out_size) == 28 );
-C_ASSERT( sizeof(struct get_next_device_request_reply) == 32 );
+C_ASSERT( FIELD_OFFSET(struct get_next_device_request_reply, client_pid) == 24 );
+C_ASSERT( FIELD_OFFSET(struct get_next_device_request_reply, client_tid) == 28 );
+C_ASSERT( FIELD_OFFSET(struct get_next_device_request_reply, in_size) == 32 );
+C_ASSERT( FIELD_OFFSET(struct get_next_device_request_reply, out_size) == 36 );
+C_ASSERT( sizeof(struct get_next_device_request_reply) == 40 );
C_ASSERT( sizeof(struct make_process_system_request) == 16 );
C_ASSERT( FIELD_OFFSET(struct make_process_system_reply, event) == 8 );
C_ASSERT( sizeof(struct make_process_system_reply) == 16 );
diff --git a/server/trace.c b/server/trace.c
index 188eee4..e463229 100644
--- a/server/trace.c
+++ b/server/trace.c
@@ -3731,6 +3731,8 @@ static void dump_get_next_device_request_reply( const struct get_next_device_req
fprintf( stderr, " next=%04x", req->next );
dump_ioctl_code( ", code=", &req->code );
dump_uint64( ", user_ptr=", &req->user_ptr );
+ fprintf( stderr, ", client_pid=%04x", req->client_pid );
+ fprintf( stderr, ", client_tid=%04x", req->client_tid );
fprintf( stderr, ", in_size=%u", req->in_size );
fprintf( stderr, ", out_size=%u", req->out_size );
dump_varargs_bytes( ", next_data=", cur_size );
More information about the wine-cvs
mailing list