UsbDk: Introduce CIrp class
CIrp is a wrapper for WDM IRP data structure and related logic Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
This commit is contained in:
parent
597ca45127
commit
6749f9e714
4 changed files with 108 additions and 0 deletions
67
UsbDk/Irp.cpp
Normal file
67
UsbDk/Irp.cpp
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
#include "Irp.h"
|
||||
|
||||
CIrp::~CIrp()
|
||||
{
|
||||
if (m_Irp != NULL)
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
VOID CIrp::Destroy()
|
||||
{
|
||||
ASSERT(m_Irp != NULL);
|
||||
ASSERT(m_TargetDevice != NULL);
|
||||
|
||||
IoFreeIrp(m_Irp);
|
||||
m_Irp = NULL;
|
||||
|
||||
ObDereferenceObject(m_TargetDevice);
|
||||
m_TargetDevice = NULL;
|
||||
}
|
||||
|
||||
NTSTATUS CIrp::Create(PDEVICE_OBJECT TargetDevice)
|
||||
{
|
||||
m_TargetDevice = TargetDevice;
|
||||
ObReferenceObject(m_TargetDevice);
|
||||
|
||||
m_Irp = IoAllocateIrp(TargetDevice->StackSize, FALSE);
|
||||
|
||||
if (m_Irp != NULL)
|
||||
{
|
||||
m_Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
NTSTATUS CIrp::SynchronousCompletion(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(DeviceObject);
|
||||
UNREFERENCED_PARAMETER(Irp);
|
||||
|
||||
ASSERT(Context != NULL);
|
||||
|
||||
KeSetEvent(static_cast<PKEVENT>(Context), IO_NO_INCREMENT, FALSE);
|
||||
|
||||
return STATUS_MORE_PROCESSING_REQUIRED;
|
||||
}
|
||||
|
||||
NTSTATUS CIrp::SendSynchronously()
|
||||
{
|
||||
KEVENT event;
|
||||
|
||||
KeInitializeEvent(&event, SynchronizationEvent, FALSE);
|
||||
|
||||
IoSetCompletionRoutine(m_Irp, SynchronousCompletion, &event,
|
||||
TRUE, TRUE, TRUE);
|
||||
|
||||
auto status = IoCallDriver(m_TargetDevice, m_Irp);
|
||||
if (status == STATUS_PENDING) {
|
||||
KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
|
||||
status = m_Irp->IoStatus.Status;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
33
UsbDk/Irp.h
Normal file
33
UsbDk/Irp.h
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#pragma once
|
||||
|
||||
#include "ntddk.h"
|
||||
#include "Alloc.h"
|
||||
#include "MemoryBuffer.h"
|
||||
|
||||
class CIrp : public CAllocatable<NonPagedPool, 'RIHR'>
|
||||
{
|
||||
public:
|
||||
CIrp() {};
|
||||
~CIrp();
|
||||
|
||||
NTSTATUS Create(PDEVICE_OBJECT TargetDevice);
|
||||
VOID Destroy();
|
||||
NTSTATUS SendSynchronously();
|
||||
|
||||
template<typename ConfiguratorT>
|
||||
VOID Configure(ConfiguratorT Configurator)
|
||||
{ Configurator(IoGetNextIrpStackLocation(m_Irp)); }
|
||||
|
||||
template<typename ReaderT>
|
||||
VOID ReadResult(ReaderT Reader)
|
||||
{ Reader(m_Irp->IoStatus.Information); }
|
||||
|
||||
CIrp(const CIrp&) = delete;
|
||||
CIrp& operator= (const CIrp&) = delete;
|
||||
|
||||
private:
|
||||
static NTSTATUS SynchronousCompletion(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context);
|
||||
|
||||
PIRP m_Irp = NULL;
|
||||
PDEVICE_OBJECT m_TargetDevice = NULL;
|
||||
};
|
||||
|
|
@ -55,6 +55,7 @@
|
|||
<ClCompile Include="DeviceAccess.cpp" />
|
||||
<ClCompile Include="Driver.cpp" />
|
||||
<ClCompile Include="Filter.cpp" />
|
||||
<ClCompile Include="Irp.cpp" />
|
||||
<ClCompile Include="MemoryBuffer.cpp" />
|
||||
<ClCompile Include="WdfWorkitem.cpp" />
|
||||
</ItemGroup>
|
||||
|
|
@ -64,6 +65,7 @@
|
|||
<ClInclude Include="DeviceAccess.h" />
|
||||
<ClInclude Include="Driver.h" />
|
||||
<ClInclude Include="Filter.h" />
|
||||
<ClInclude Include="Irp.h" />
|
||||
<ClInclude Include="MemoryBuffer.h" />
|
||||
<ClInclude Include="Public.h" />
|
||||
<ClInclude Include="Trace.h" />
|
||||
|
|
|
|||
|
|
@ -46,6 +46,9 @@
|
|||
<ClInclude Include="MemoryBuffer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Irp.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Filter.cpp">
|
||||
|
|
@ -66,5 +69,8 @@
|
|||
<ClCompile Include="MemoryBuffer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Irp.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Loading…
Add table
Add a link
Reference in a new issue