ntoskrnl.exe: Make the driver object accessible by name while in its entry point.

Signed-off-by: Zebediah Figura <z.figura12@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2019-08-18 20:02:39 -05:00 committed by Alexandre Julliard
parent 32b2497645
commit 92d8ec7954
2 changed files with 24 additions and 6 deletions

View File

@ -1413,10 +1413,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;
}
@ -1426,10 +1431,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;
}

View File

@ -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;
@ -1887,8 +1887,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");
@ -1903,6 +1907,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);