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 | 11 ++++++----- dlls/ntoskrnl.exe/tests/driver.c | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 80dee34b75..b873c9b770 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -1539,10 +1539,15 @@ NTSTATUS WINAPI IoCreateDriver( UNICODE_STRING *name, PDRIVER_INITIALIZE init ) for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++) driver->driver_obj.MajorFunction[i] = unhandled_irp;
+ EnterCriticalSection( &drivers_cs ); + if (wine_rb_put( &wine_drivers, &driver->driver_obj.DriverName, &driver->entry )) + ERR( "failed to insert driver %s in tree\n", debugstr_us(name) ); + LeaveCriticalSection( &drivers_cs ); + status = driver->driver_obj.DriverInit( &driver->driver_obj, &driver->driver_extension.ServiceKeyName ); if (status) { - ObDereferenceObject( driver ); + IoDeleteDriver( &driver->driver_obj ); return status; }
@@ -1552,10 +1557,6 @@ NTSTATUS WINAPI IoCreateDriver( UNICODE_STRING *name, PDRIVER_INITIALIZE init ) driver->driver_obj.MajorFunction[i] = unhandled_irp; }
- EnterCriticalSection( &drivers_cs ); - if (wine_rb_put( &wine_drivers, &driver->driver_obj.DriverName, &driver->entry )) - ERR( "failed to insert driver %s in tree\n", debugstr_us(name) ); - LeaveCriticalSection( &drivers_cs ); return STATUS_SUCCESS; }
diff --git a/dlls/ntoskrnl.exe/tests/driver.c b/dlls/ntoskrnl.exe/tests/driver.c index 3333b3939d..0f333dd25b 100644 --- a/dlls/ntoskrnl.exe/tests/driver.c +++ b/dlls/ntoskrnl.exe/tests/driver.c @@ -56,7 +56,7 @@ static int running_under_wine; static int winetest_debug; static int winetest_report_success;
-static POBJECT_TYPE *pExEventObjectType, *pIoFileObjectType, *pPsThreadType; +static POBJECT_TYPE *pExEventObjectType, *pIoFileObjectType, *pPsThreadType, *pIoDriverObjectType; static PEPROCESS *pPsInitialSystemProcess; static void *create_caller_thread;
@@ -1921,8 +1921,12 @@ static VOID WINAPI driver_Unload(DRIVER_OBJECT *driver)
NTSTATUS WINAPI DriverEntry(DRIVER_OBJECT *driver, PUNICODE_STRING registry) { + static const WCHAR IoDriverObjectTypeW[] = {'I','o','D','r','i','v','e','r','O','b','j','e','c','t','T','y','p','e',0}; + static const WCHAR driver_nameW[] = {'\','D','r','i','v','e','r', + '\','W','i','n','e','T','e','s','t','D','r','i','v','e','r',0}; UNICODE_STRING nameW, linkW; NTSTATUS status; + void *obj;
DbgPrint("loading driver\n");
@@ -1937,6 +1941,19 @@ NTSTATUS WINAPI DriverEntry(DRIVER_OBJECT *driver, PUNICODE_STRING registry) driver->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = driver_FlushBuffers; driver->MajorFunction[IRP_MJ_CLOSE] = driver_Close;
+ RtlInitUnicodeString(&nameW, IoDriverObjectTypeW); + pIoDriverObjectType = MmGetSystemRoutineAddress(&nameW); + + RtlInitUnicodeString(&nameW, driver_nameW); + if ((status = ObReferenceObjectByName(&nameW, 0, NULL, 0, *pIoDriverObjectType, KernelMode, NULL, &obj))) + return status; + if (obj != driver) + { + ObDereferenceObject(obj); + return STATUS_UNSUCCESSFUL; + } + ObDereferenceObject(obj); + RtlInitUnicodeString(&nameW, device_name); RtlInitUnicodeString(&linkW, driver_link);