Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=47623 Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/ntoskrnl.exe/ntoskrnl.c | 15 +++++-- dlls/ntoskrnl.exe/tests/driver.c | 77 ++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 3 deletions(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index c989b3a684..80dee34b75 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -3260,10 +3260,19 @@ VOID WINAPI IoStartNextPacket(PDEVICE_OBJECT deviceobject, BOOLEAN cancelable) /***************************************************** * ObQueryNameString (NTOSKRNL.EXE.@) */ -NTSTATUS WINAPI ObQueryNameString(PVOID object, POBJECT_NAME_INFORMATION name, ULONG maxlength, PULONG returnlength) +NTSTATUS WINAPI ObQueryNameString( void *object, OBJECT_NAME_INFORMATION *name, ULONG size, ULONG *ret_size ) { - FIXME("(%p %p %u %p) stub\n", object, name, maxlength, returnlength); - return STATUS_NOT_IMPLEMENTED; + HANDLE handle; + NTSTATUS ret; + + TRACE("object %p, name %p, size %u, ret_size %p.\n", object, name, size, ret_size); + + if ((ret = ObOpenObjectByPointer( object, 0, NULL, 0, NULL, KernelMode, &handle ))) + return ret; + ret = NtQueryObject( handle, ObjectNameInformation, name, size, ret_size ); + + NtClose( handle ); + return ret; }
/***************************************************** diff --git a/dlls/ntoskrnl.exe/tests/driver.c b/dlls/ntoskrnl.exe/tests/driver.c index 94b62b05fe..3333b3939d 100644 --- a/dlls/ntoskrnl.exe/tests/driver.c +++ b/dlls/ntoskrnl.exe/tests/driver.c @@ -1524,6 +1524,82 @@ static void test_IoAttachDeviceToDeviceStack(void) IoDeleteDevice(dev3); }
+static void test_object_name(void) +{ + static const WCHAR event_nameW[] = L"\wine_test_event"; + static const WCHAR device_nameW[] = L"\Device\WineTestDriver"; + char buffer[1024]; + OBJECT_NAME_INFORMATION *name = (OBJECT_NAME_INFORMATION *)buffer; + OBJECT_ATTRIBUTES attr; + UNICODE_STRING string; + ULONG ret_size; + HANDLE handle; + KEVENT *event; + NTSTATUS ret; + + ret_size = 0; + ret = ObQueryNameString(lower_device, name, 0, &ret_size); + ok(ret == STATUS_INFO_LENGTH_MISMATCH, "got status %#x\n", ret); + ok(ret_size == sizeof(*name) + sizeof(device_nameW), "got size %u\n", ret_size); + + ret_size = 0; + ret = ObQueryNameString(lower_device, name, sizeof(buffer), &ret_size); + ok(!ret, "got status %#x\n", ret); + ok(!wcscmp(name->Name.Buffer, device_nameW), "got name %ls\n", name->Name.Buffer); + ok(ret_size == sizeof(*name) + sizeof(device_nameW), "got size %u\n", ret_size); + ok(name->Name.Length == wcslen(device_nameW) * sizeof(WCHAR), "got length %u\n", name->Name.Length); + ok(name->Name.MaximumLength == sizeof(device_nameW), "got maximum length %u\n", name->Name.MaximumLength); + + event = IoCreateSynchronizationEvent(NULL, &handle); + ok(!!event, "failed to create event\n"); + + ret_size = 0; + ret = ObQueryNameString(event, name, sizeof(buffer), &ret_size); + ok(!ret, "got status %#x\n", ret); + ok(!name->Name.Buffer, "got name %ls\n", name->Name.Buffer); + ok(ret_size == sizeof(*name), "got size %u\n", ret_size); + ok(!name->Name.Length, "got length %u\n", name->Name.Length); + ok(!name->Name.MaximumLength, "got maximum length %u\n", name->Name.MaximumLength); + + ret = ZwClose(handle); + ok(!ret, "got status %#x\n", ret); + + RtlInitUnicodeString(&string, event_nameW); + InitializeObjectAttributes(&attr, &string, OBJ_KERNEL_HANDLE, NULL, NULL); + ret = ZwCreateEvent(&handle, 0, &attr, NotificationEvent, TRUE); + ok(!ret, "got status %#x\n", ret); + ret = ObReferenceObjectByHandle(handle, 0, *pExEventObjectType, KernelMode, (void **)&event, NULL); + ok(!ret, "got status %#x\n", ret); + + ret_size = 0; + ret = ObQueryNameString(event, name, sizeof(buffer), &ret_size); + ok(!ret, "got status %#x\n", ret); + ok(!wcscmp(name->Name.Buffer, event_nameW), "got name %ls\n", name->Name.Buffer); + ok(ret_size == sizeof(*name) + sizeof(event_nameW), "got size %u\n", ret_size); + ok(name->Name.Length == wcslen(event_nameW) * sizeof(WCHAR), "got length %u\n", name->Name.Length); + ok(name->Name.MaximumLength == sizeof(event_nameW), "got maximum length %u\n", name->Name.MaximumLength); + + ObDereferenceObject(event); + ret = ZwClose(handle); + ok(!ret, "got status %#x\n", ret); + + ret_size = 0; + ret = ObQueryNameString(KeGetCurrentThread(), name, sizeof(buffer), &ret_size); + ok(!ret, "got status %#x\n", ret); + ok(!name->Name.Buffer, "got name %ls\n", name->Name.Buffer); + ok(ret_size == sizeof(*name), "got size %u\n", ret_size); + ok(!name->Name.Length, "got length %u\n", name->Name.Length); + ok(!name->Name.MaximumLength, "got maximum length %u\n", name->Name.MaximumLength); + + ret_size = 0; + ret = ObQueryNameString(IoGetCurrentProcess(), name, sizeof(buffer), &ret_size); + ok(!ret, "got status %#x\n", ret); + ok(!name->Name.Buffer, "got name %ls\n", name->Name.Buffer); + ok(ret_size == sizeof(*name), "got size %u\n", ret_size); + ok(!name->Name.Length, "got length %u\n", name->Name.Length); + ok(!name->Name.MaximumLength, "got maximum length %u\n", name->Name.MaximumLength); +} + static PIO_WORKITEM main_test_work_item;
static void WINAPI main_test_task(DEVICE_OBJECT *device, void *context) @@ -1633,6 +1709,7 @@ static NTSTATUS main_test(DEVICE_OBJECT *device, IRP *irp, IO_STACK_LOCATION *st test_resource(); test_lookup_thread(); test_IoAttachDeviceToDeviceStack(); + test_object_name(); #if defined(__i386__) || defined(__x86_64__) test_executable_pool(); #endif