Module: wine Branch: master Commit: f680eda832bdbd910f8916ea657bc2934669c8e3 URL: https://source.winehq.org/git/wine.git/?a=commit;h=f680eda832bdbd910f8916ea6...
Author: Jacek Caban jacek@codeweavers.com Date: Mon Apr 8 14:04:07 2019 +0200
ntoskrnl.exe: Implement KeGetCurrentThread.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=45844 Signed-off-by: Jacek Caban jacek@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/ntoskrnl.exe/ntoskrnl.c | 19 +++++++++++++++++-- dlls/ntoskrnl.exe/tests/driver.c | 24 +++++++++++++++--------- 2 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index a02dc1c..403c398 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -961,6 +961,7 @@ NTSTATUS CDECL wine_ntoskrnl_main_loop( HANDLE stop_event )
for (;;) { + NtCurrentTeb()->Reserved5[1] = NULL; if (!in_buff && !(in_buff = HeapAlloc( GetProcessHeap(), 0, in_size ))) { ERR( "failed to allocate buffer\n" ); @@ -2506,8 +2507,22 @@ POBJECT_TYPE PsThreadType = &thread_type; */ PRKTHREAD WINAPI KeGetCurrentThread(void) { - FIXME("() stub\n"); - return NULL; + struct _KTHREAD *thread = NtCurrentTeb()->Reserved5[1]; + + if (!thread) + { + HANDLE handle = GetCurrentThread(); + + /* FIXME: we shouldn't need it, GetCurrentThread() should be client thread already */ + if (GetCurrentThreadId() == request_thread) handle = OpenThread( 0, FALSE, client_tid ); + + kernel_object_from_handle( handle, PsThreadType, (void**)&thread ); + if (handle != GetCurrentThread()) NtClose( handle ); + + NtCurrentTeb()->Reserved5[1] = thread; + } + + return thread; }
/*********************************************************************** diff --git a/dlls/ntoskrnl.exe/tests/driver.c b/dlls/ntoskrnl.exe/tests/driver.c index ac6568f..81baffa 100644 --- a/dlls/ntoskrnl.exe/tests/driver.c +++ b/dlls/ntoskrnl.exe/tests/driver.c @@ -210,15 +210,6 @@ static void *get_proc_address(const char *name) return ret; }
-static void test_currentprocess(void) -{ - PEPROCESS current; - - current = IoGetCurrentProcess(); -todo_wine - ok(current != NULL, "Expected current process to be non-NULL\n"); -} - static FILE_OBJECT *last_created_file;
static void test_irp_struct(IRP *irp, DEVICE_OBJECT *device) @@ -316,6 +307,21 @@ static NTSTATUS wait_single_handle(HANDLE handle, ULONGLONG timeout) return ZwWaitForSingleObject(handle, FALSE, &integer); }
+static void test_currentprocess(void) +{ + PEPROCESS current; + PETHREAD thread; + NTSTATUS ret; + + current = IoGetCurrentProcess(); +todo_wine + ok(current != NULL, "Expected current process to be non-NULL\n"); + + thread = PsGetCurrentThread(); + ret = wait_single( thread, 0 ); + ok(ret == STATUS_TIMEOUT, "got %#x\n", ret); +} + static void run_thread(PKSTART_ROUTINE proc, void *arg) { OBJECT_ATTRIBUTES attr = {0};