Commit 7498c15b authored by Derek Lesho's avatar Derek Lesho Committed by Alexandre Julliard

ntoskrnl.exe: Implement PsLookupThreadByThreadId.

parent 2c389667
......@@ -2522,6 +2522,26 @@ PRKTHREAD WINAPI KeGetCurrentThread(void)
return thread;
}
/*****************************************************
* PsLookupThreadByThreadId (NTOSKRNL.EXE.@)
*/
NTSTATUS WINAPI PsLookupThreadByThreadId( HANDLE threadid, PETHREAD *thread )
{
NTSTATUS status;
HANDLE handle;
TRACE( "(%p %p)\n", threadid, thread );
if (!(handle = OpenThread( THREAD_QUERY_INFORMATION, FALSE, HandleToUlong(threadid) )))
return STATUS_INVALID_PARAMETER;
status = ObReferenceObjectByHandle( handle, THREAD_ALL_ACCESS, PsThreadType, KernelMode, (void**)thread, NULL );
NtClose( handle );
return status;
}
/***********************************************************************
* KeInsertQueue (NTOSKRNL.EXE.@)
*/
......
......@@ -914,7 +914,7 @@
@ stub PsJobType
@ stdcall PsLookupProcessByProcessId(ptr ptr)
@ stub PsLookupProcessThreadByCid
@ stub PsLookupThreadByThreadId
@ stdcall PsLookupThreadByThreadId(ptr ptr)
@ extern PsProcessType
@ stub PsReferenceImpersonationToken
@ stub PsReferencePrimaryToken
......
......@@ -29,6 +29,7 @@
#include "winternl.h"
#include "winioctl.h"
#include "ddk/ntddk.h"
#include "ddk/ntifs.h"
#include "ddk/wdm.h"
#include "driver.h"
......@@ -1167,6 +1168,20 @@ static void test_resource(void)
ok(status == STATUS_SUCCESS, "got status %#x\n", status);
}
static void test_lookup_thread(void)
{
NTSTATUS status;
PETHREAD thread = NULL;
status = PsLookupThreadByThreadId(PsGetCurrentThreadId(), &thread);
ok(!status, "PsLookupThreadByThreadId failed: %#x\n", status);
ok((PKTHREAD)thread == KeGetCurrentThread(), "thread != KeGetCurrentThread\n");
if (thread) ObDereferenceObject(thread);
status = PsLookupThreadByThreadId(NULL, &thread);
ok(status == STATUS_INVALID_PARAMETER, "PsLookupThreadByThreadId returned %#x\n", status);
}
static NTSTATUS main_test(DEVICE_OBJECT *device, IRP *irp, IO_STACK_LOCATION *stack, ULONG_PTR *info)
{
ULONG length = stack->Parameters.DeviceIoControl.OutputBufferLength;
......@@ -1210,6 +1225,7 @@ static NTSTATUS main_test(DEVICE_OBJECT *device, IRP *irp, IO_STACK_LOCATION *st
test_lookaside_list();
test_ob_reference(test_input->path);
test_resource();
test_lookup_thread();
/* print process report */
if (winetest_debug)
......
......@@ -131,6 +131,7 @@ typedef struct _FS_FILTER_CALLBACKS
BOOLEAN WINAPI FsRtlIsNameInExpression(PUNICODE_STRING, PUNICODE_STRING, BOOLEAN, PWCH);
NTSTATUS WINAPI ObQueryNameString(PVOID,POBJECT_NAME_INFORMATION,ULONG,PULONG);
NTSTATUS WINAPI PsLookupThreadByThreadId(HANDLE,PETHREAD*);
void WINAPI PsRevertToSelf(void);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment