From d4c91cc6f99b3f46df142bc92225150a18a2a11f Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Sat, 22 Jun 2019 10:12:31 -0500 Subject: [PATCH] ntoskrnl.exe: Add a stub PnP manager driver. Signed-off-by: Zebediah Figura Signed-off-by: Alexandre Julliard --- dlls/ntoskrnl.exe/ntoskrnl.c | 5 ++++ dlls/ntoskrnl.exe/ntoskrnl_private.h | 3 +++ dlls/ntoskrnl.exe/pnp.c | 36 ++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 209410caeb1..583907262fd 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -850,6 +850,8 @@ NTSTATUS CDECL wine_ntoskrnl_main_loop( HANDLE stop_event ) PsInitialSystemProcess = IoGetCurrentProcess(); request_thread = GetCurrentThreadId(); + pnp_manager_start(); + handles[0] = stop_event; handles[1] = manager; @@ -917,6 +919,9 @@ NTSTATUS CDECL wine_ntoskrnl_main_loop( HANDLE stop_event ) } done: + /* Native PnP drivers expect that all of their devices will be removed when + * their unload routine is called, so we must stop the PnP manager first. */ + pnp_manager_stop(); wine_rb_destroy( &wine_drivers, unload_driver, NULL ); return status; } diff --git a/dlls/ntoskrnl.exe/ntoskrnl_private.h b/dlls/ntoskrnl.exe/ntoskrnl_private.h index 2823a1cd4f1..1c5952f7c10 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl_private.h +++ b/dlls/ntoskrnl.exe/ntoskrnl_private.h @@ -76,6 +76,9 @@ extern POBJECT_TYPE SeTokenObjectType; void ObReferenceObject( void *obj ) DECLSPEC_HIDDEN; +void pnp_manager_start(void) DECLSPEC_HIDDEN; +void pnp_manager_stop(void) DECLSPEC_HIDDEN; + static const WCHAR servicesW[] = {'\\','R','e','g','i','s','t','r','y', '\\','M','a','c','h','i','n','e', '\\','S','y','s','t','e','m', diff --git a/dlls/ntoskrnl.exe/pnp.c b/dlls/ntoskrnl.exe/pnp.c index e1b348b82e3..6f2283bc834 100644 --- a/dlls/ntoskrnl.exe/pnp.c +++ b/dlls/ntoskrnl.exe/pnp.c @@ -3,6 +3,7 @@ * * Copyright 2016 Sebastian Lackner * Copyright 2016 Aric Stewart for CodeWeavers + * Copyright 2019 Zebediah Figura * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -751,3 +752,38 @@ POWER_STATE WINAPI PoSetPowerState( DEVICE_OBJECT *device, POWER_STATE_TYPE type FIXME("device %p, type %u, state %u, stub!\n", device, type, state.DeviceState); return state; } + +static DRIVER_OBJECT *pnp_manager; + +static NTSTATUS WINAPI pnp_manager_device_pnp( DEVICE_OBJECT *device, IRP *irp ) +{ + IO_STACK_LOCATION *stack = IoGetCurrentIrpStackLocation( irp ); + + TRACE("device %p, irp %p, minor function %#x.\n", device, irp, stack->MinorFunction); + + IoCompleteRequest( irp, IO_NO_INCREMENT ); + return irp->IoStatus.u.Status; +} + +static NTSTATUS WINAPI pnp_manager_driver_entry( DRIVER_OBJECT *driver, UNICODE_STRING *keypath ) +{ + pnp_manager = driver; + driver->MajorFunction[IRP_MJ_PNP] = pnp_manager_device_pnp; + return STATUS_SUCCESS; +} + +void pnp_manager_start(void) +{ + static const WCHAR driver_nameW[] = {'\\','D','r','i','v','e','r','\\','P','n','p','M','a','n','a','g','e','r',0}; + UNICODE_STRING driver_nameU; + NTSTATUS status; + + RtlInitUnicodeString( &driver_nameU, driver_nameW ); + if ((status = IoCreateDriver( &driver_nameU, pnp_manager_driver_entry ))) + ERR("Failed to create PnP manager driver, status %#x.\n", status); +} + +void pnp_manager_stop(void) +{ + IoDeleteDriver( pnp_manager ); +}