From 850fd237bd30969ede93cd409d8c112fdf87a671 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Thu, 16 May 2019 19:50:27 +0200 Subject: [PATCH] ntoskrnl.exe: Implement PsGetProcessInheritedFromUniqueProcessId. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/ntoskrnl.exe/ntoskrnl.c | 9 +++++++++ dlls/ntoskrnl.exe/ntoskrnl.exe.spec | 4 ++-- dlls/ntoskrnl.exe/tests/driver.c | 16 ++++++++++++++++ include/ddk/wdm.h | 1 + 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 49d628d509c..3df7e4e38cd 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -2589,6 +2589,15 @@ HANDLE WINAPI PsGetProcessId(PEPROCESS process) return (HANDLE)process->info.UniqueProcessId; } +/********************************************************************* + * PsGetProcessInheritedFromUniqueProcessId (NTOSKRNL.@) + */ +HANDLE WINAPI PsGetProcessInheritedFromUniqueProcessId( PEPROCESS process ) +{ + HANDLE id = (HANDLE)process->info.InheritedFromUniqueProcessId; + TRACE( "%p -> %p\n", process, id ); + return id; +} static void *create_thread_object( HANDLE handle ) { diff --git a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec index 87ec3979a8d..0105afbe95a 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec +++ b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec @@ -888,7 +888,7 @@ @ stub PsGetProcessExitTime @ stdcall PsGetProcessId(ptr) @ stub PsGetProcessImageFileName -@ stub PsGetProcessInheritedFromUniqueProcessId +@ stdcall PsGetProcessInheritedFromUniqueProcessId(ptr) @ stub PsGetProcessJob @ stub PsGetProcessPeb @ stub PsGetProcessPriorityClass @@ -1374,7 +1374,7 @@ @ stdcall -private ZwQueryFullAttributesFile(ptr ptr) NtQueryFullAttributesFile @ stdcall -private ZwQueryInformationFile(long ptr ptr long long) NtQueryInformationFile @ stdcall -private ZwQueryInformationJobObject(long long ptr long ptr) NtQueryInformationJobObject -@ stdcall -private ZwQueryInformationProcess(long long ptr long ptr) NtQueryInformationProcess +@ stdcall ZwQueryInformationProcess(long long ptr long ptr) NtQueryInformationProcess @ stdcall -private ZwQueryInformationThread(long long ptr long ptr) NtQueryInformationThread @ stdcall -private ZwQueryInformationToken(long long ptr long ptr) NtQueryInformationToken @ stdcall -private ZwQueryInstallUILanguage(ptr) NtQueryInstallUILanguage diff --git a/dlls/ntoskrnl.exe/tests/driver.c b/dlls/ntoskrnl.exe/tests/driver.c index b4624e97340..1ad468e3623 100644 --- a/dlls/ntoskrnl.exe/tests/driver.c +++ b/dlls/ntoskrnl.exe/tests/driver.c @@ -55,6 +55,8 @@ static PEPROCESS *pPsInitialSystemProcess; void WINAPI ObfReferenceObject( void *obj ); +NTSTATUS WINAPI ZwQueryInformationProcess(HANDLE,PROCESSINFOCLASS,void*,ULONG,ULONG*); + extern int CDECL _vsnprintf(char *str, size_t len, const char *format, __ms_va_list argptr); static void kvprintf(const char *format, __ms_va_list ap) @@ -323,7 +325,9 @@ static NTSTATUS wait_single_handle(HANDLE handle, ULONGLONG timeout) static void test_current_thread(BOOL is_system) { + PROCESS_BASIC_INFORMATION info; DISPATCHER_HEADER *header; + HANDLE process_handle, id; PEPROCESS current; PETHREAD thread; NTSTATUS ret; @@ -349,6 +353,18 @@ static void test_current_thread(BOOL is_system) ok(PsGetThreadId((PETHREAD)KeGetCurrentThread()) == PsGetCurrentThreadId(), "thread IDs don't match\n"); ok(PsIsSystemThread((PETHREAD)KeGetCurrentThread()) == is_system, "unexpected system thread\n"); + + ret = ObOpenObjectByPointer(current, OBJ_KERNEL_HANDLE, NULL, PROCESS_QUERY_INFORMATION, NULL, KernelMode, &process_handle); + ok(!ret, "ObOpenObjectByPointer failed: %#x\n", ret); + + ret = ZwQueryInformationProcess(process_handle, ProcessBasicInformation, &info, sizeof(info), NULL); + ok(!ret, "ZwQueryInformationProcess failed: %#x\n", ret); + + id = PsGetProcessInheritedFromUniqueProcessId(current); + ok(id == (HANDLE)info.InheritedFromUniqueProcessId, "unexpected process id %p\n", id); + + ret = ZwClose(process_handle); + ok(!ret, "ZwClose failed: %#x\n", ret); } static void sleep(void) diff --git a/include/ddk/wdm.h b/include/ddk/wdm.h index 4dae97be8db..90a8bae1932 100644 --- a/include/ddk/wdm.h +++ b/include/ddk/wdm.h @@ -1663,6 +1663,7 @@ NTSTATUS WINAPI PsCreateSystemThread(PHANDLE,ULONG,POBJECT_ATTRIBUTES,HANDLE,PC #define PsGetCurrentThread() ((PETHREAD)KeGetCurrentThread()) HANDLE WINAPI PsGetCurrentProcessId(void); HANDLE WINAPI PsGetCurrentThreadId(void); +HANDLE WINAPI PsGetProcessInheritedFromUniqueProcessId(PEPROCESS); BOOLEAN WINAPI PsGetVersion(ULONG*,ULONG*,ULONG*,UNICODE_STRING*); NTSTATUS WINAPI PsTerminateSystemThread(NTSTATUS);