ntoskrnl: Correctly implement PsGetCurrentThread/ProcessId.

This commit is contained in:
Bernhard Loos 2011-10-27 14:20:19 +02:00 committed by Alexandre Julliard
parent 8e62e823d6
commit 507d929051
6 changed files with 37 additions and 11 deletions

View File

@ -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());
}

View File

@ -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 */

View File

@ -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 );

View File

@ -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 */

View File

@ -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 );

View File

@ -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 );