[PATCH v4] ntoskrnl.exe: Send PnP and Power IRPs to plug and play devices

Sebastian Lackner sebastian at fds-team.de
Thu Sep 15 03:50:39 CDT 2016


On 14.09.2016 20:58, Aric Stewart wrote:
> v2: use same helper function as get_device_id
>     Suggestions from Sebastian Lackner
> v3: shift code to ntoskrnl.c
> v4: Suggestions from Sebastian Lackner
> 
> The drivers AddDevice function will be well behaved and call
> IoAttachDeviceToDeviceStack. The Plug and Play manager will then
> proceed to call IRP_MN_START_DEVICE on the top device of the device
> stack. Then a IRP_MJ_POWER/IRP_MN_SET_POWER to PowerDeviceD0.
> 
> Signed-off-by: Aric Stewart <aric at codeweavers.com>
> ---
>  dlls/ntoskrnl.exe/ntoskrnl.c | 42 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 42 insertions(+)
> 
> 
> 
> v4-0001-ntoskrnl.exe-Send-PnP-and-Power-IRPs-to-plug-and-pl.txt
> 
> 
> diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c
> index aebb3de..6c4c984 100644
> --- a/dlls/ntoskrnl.exe/ntoskrnl.c
> +++ b/dlls/ntoskrnl.exe/ntoskrnl.c
> @@ -2927,6 +2927,42 @@ static BOOL get_driver_for_id( const WCHAR *id, WCHAR *driver )
>  }
>  
>  
> +static NTSTATUS send_pnp_irp( DEVICE_OBJECT *device, UCHAR minor )
> +{
> +    IO_STACK_LOCATION *irpsp;
> +    IO_STATUS_BLOCK irp_status;

Did you forget to declare irp here and in the function below?

> +
> +    if (!(irp = IoBuildSynchronousFsdRequest( IRP_MJ_PNP, device, NULL, 0, NULL, NULL, &irp_status )))
> +        return STATUS_NO_MEMORY;
> +
> +    irpsp = IoGetNextIrpStackLocation( irp );
> +    irpsp->MinorFunction = minor;
> +
> +    irpsp->Parameters.StartDevice.AllocatedResources = NULL;
> +    irpsp->Parameters.StartDevice.AllocatedResourcesTranslated = NULL;
> +
> +    return send_device_irp( device, irp, NULL );
> +}
> +
> +
> +static NTSTATUS send_power_irp( DEVICE_OBJECT *device, DEVICE_POWER_STATE power )
> +{
> +    IO_STATUS_BLOCK irp_status;
> +    IO_STACK_LOCATION *irpsp;
> +
> +    if (!(irp = IoBuildSynchronousFsdRequest( IRP_MJ_POWER, device, NULL, 0, NULL, NULL, &irp_status )))
> +        return STATUS_NO_MEMORY;
> +
> +    irpsp = IoGetNextIrpStackLocation( irp );
> +    irpsp->MinorFunction = IRP_MN_SET_POWER;
> +
> +    irpsp->Parameters.Power.Type = DevicePowerState;
> +    irpsp->Parameters.Power.State.DeviceState = power;
> +
> +    return send_device_irp( device, irp, NULL );
> +}
> +
> +
>  static void handle_bus_relations( DEVICE_OBJECT *device )
>  {
>      static const WCHAR driverW[] = {'\\','D','r','i','v','e','r','\\',0};
> @@ -2990,7 +3026,13 @@ static void handle_bus_relations( DEVICE_OBJECT *device )
>      ObDereferenceObject( driver_obj );
>  
>      if (status != STATUS_SUCCESS)
> +    {
>          ERR_(plugplay)( "AddDevice failed for driver %s\n", debugstr_w(driver) );
> +        return;
> +    }
> +
> +    send_pnp_irp( device, IRP_MN_START_DEVICE );
> +    send_power_irp( device, PowerDeviceD0 );
>  }
>  
>  
> 
> 
> 




More information about the wine-devel mailing list