ReactOS 0.4.15-dev-7958-gcd0bb1a
PoIrp_drv.c File Reference
#include <kmt_test.h>
#include "PoIrp.h"
Include dependency graph for PoIrp_drv.c:

Go to the source code of this file.

Functions

static NTSTATUS CreateTestDevices (_In_ PDRIVER_OBJECT DriverObject)
 
NTSTATUS TestEntry (_In_ PDRIVER_OBJECT DriverObject, _In_ PCUNICODE_STRING RegistryPath, _Out_ PCWSTR *DeviceName, _Inout_ INT *Flags)
 
VOID TestUnload (IN PDRIVER_OBJECT DriverObject)
 
static VOID NTAPI RequestedPowerCompletion (_In_ PDEVICE_OBJECT DeviceObject, _In_ UCHAR MinorFunction, _In_ POWER_STATE PowerState, _In_opt_ PVOID Context, _In_ PIO_STATUS_BLOCK IoStatus)
 
static NTSTATUS RequestedPowerIrpHandler (_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp, _In_ PIO_STACK_LOCATION IoStackLocation)
 
static VOID TestPoRequestPowerIrp (VOID)
 
static NTSTATUS TestMessageHandler (_In_ PDEVICE_OBJECT DeviceObject, _In_ ULONG ControlCode, _In_ PVOID Buffer OPTIONAL, _In_ SIZE_T InLength, _Inout_ PSIZE_T OutLength)
 

Variables

static PDRIVER_OBJECT TestDriverObject
 
static KMT_MESSAGE_HANDLER TestMessageHandler
 
static PDEVICE_OBJECT DeviceObject1
 
static PDEVICE_OBJECT DeviceObject2
 
static PDEVICE_OBJECT DeviceObject3
 
static KEVENT TestDoneEvent
 
static PIRP RequestedPowerIrp
 
static PIRP RequestedPowerIrpReturned
 

Function Documentation

◆ CreateTestDevices()

static NTSTATUS CreateTestDevices ( _In_ PDRIVER_OBJECT  DriverObject)
static

Definition at line 20 of file PoIrp_drv.c.

22{
24 PDEVICE_OBJECT AttachedDevice;
25
27 if (!NT_SUCCESS(Status))
28 return Status;
29
30 DeviceObject1->Flags &= ~DO_DEVICE_INITIALIZING;
31
33 if (!NT_SUCCESS(Status))
34 {
36 return Status;
37 }
38
40 ok(AttachedDevice == DeviceObject1, "Device attached to %p is %p, expected %p\n", DeviceObject2, AttachedDevice, DeviceObject1);
41 if (AttachedDevice == NULL)
42 {
46 }
47
48 DeviceObject2->Flags &= ~DO_DEVICE_INITIALIZING;
49
51 if (!NT_SUCCESS(Status))
52 {
56 return Status;
57 }
58
60 ok(AttachedDevice == DeviceObject2, "Device attached to %p is %p, expected %p\n", DeviceObject2, AttachedDevice, DeviceObject2);
61 if (AttachedDevice == NULL)
62 {
68 }
69
70 DeviceObject3->Flags &= ~DO_DEVICE_INITIALIZING;
71
72 return Status;
73}
static PDEVICE_OBJECT DeviceObject1
Definition: PoIrp_drv.c:14
static PDEVICE_OBJECT DeviceObject3
Definition: PoIrp_drv.c:16
static PDEVICE_OBJECT DeviceObject2
Definition: PoIrp_drv.c:15
#define ok(value,...)
Definition: atltest.h:57
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:25
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1296
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define FILE_DEVICE_UNKNOWN
Definition: winioctl.h:140
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213

Referenced by TestMessageHandler().

◆ RequestedPowerCompletion()

static VOID NTAPI RequestedPowerCompletion ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ UCHAR  MinorFunction,
_In_ POWER_STATE  PowerState,
_In_opt_ PVOID  Context,
_In_ PIO_STATUS_BLOCK  IoStatus 
)
static

Definition at line 117 of file PoIrp_drv.c.

123{
124 PIRP Irp;
125 PIO_STACK_LOCATION IoStackLocation;
126
129 ok_eq_uint(PowerState.DeviceState, PowerDeviceD0);
133 ok_eq_ulongptr(IoStatus->Information, 7);
136
137 ok_eq_uint(Irp->StackCount, 5);
138 ok_eq_uint(Irp->CurrentLocation, 4);
139 ok_eq_pointer(Irp->Tail.Overlay.Thread, NULL);
140 IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
141 ok_eq_uint(IoStackLocation->MajorFunction, 0);
142 ok_eq_uint(IoStackLocation->MinorFunction, 0);
143 ok_eq_pointer(IoStackLocation->CompletionRoutine, NULL);
144 ok_eq_pointer(IoStackLocation->Context, NULL);
145 ok_eq_pointer(IoStackLocation->Parameters.Others.Argument1, DeviceObject);
146 ok_eq_pointer(IoStackLocation->Parameters.Others.Argument2, (PVOID)(ULONG_PTR)MinorFunction);
147 ok_eq_pointer(IoStackLocation->Parameters.Others.Argument3, (PVOID)(ULONG_PTR)PowerState.SystemState);
148 ok_eq_pointer(IoStackLocation->Parameters.Others.Argument4, Context);
149}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
static PIRP RequestedPowerIrp
Definition: PoIrp_drv.c:111
static KEVENT TestDoneEvent
Definition: PoIrp_drv.c:110
#define ok_eq_pointer(value, expected)
Definition: apitest.h:59
#define ok_eq_hex(value, expected)
Definition: apitest.h:77
#define ok_eq_uint(value, expected)
Definition: apitest.h:61
#define ok_eq_ulongptr(value, expected)
Definition: apitest.h:71
_In_ PIRP Irp
Definition: csq.h:116
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159
@ PowerDeviceD0
Definition: ntpoapi.h:49
#define STATUS_WAIT_3
Definition: ntstatus.h:73
struct _IO_STACK_LOCATION::@3978::@4017 Others
union _IO_STACK_LOCATION::@1564 Parameters
PIO_COMPLETION_ROUTINE CompletionRoutine
Definition: iotypes.h:3314
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ WDF_DEVICE_POWER_STATE PowerState
Definition: wdfdevice.h:3034
_In_ UCHAR _In_ UCHAR MinorFunction
Definition: wdfdevice.h:1699
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IRP_MN_SET_POWER

Referenced by RequestedPowerIrpHandler(), and TestPoRequestPowerIrp().

◆ RequestedPowerIrpHandler()

static NTSTATUS RequestedPowerIrpHandler ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ PIRP  Irp,
_In_ PIO_STACK_LOCATION  IoStackLocation 
)
static

Definition at line 153 of file PoIrp_drv.c.

157{
158 if (RequestedPowerIrp == NULL)
160 else
162
163 ok_eq_uint(Irp->StackCount, 5);
164 ok_eq_ulongptr(Irp->IoStatus.Information, 0);
165 ok_eq_hex(Irp->IoStatus.Status, STATUS_NOT_SUPPORTED);
166 ok_eq_pointer(Irp->Tail.Overlay.Thread, NULL);
167 ok_eq_uint(IoStackLocation->MajorFunction, IRP_MJ_POWER);
168 ok_eq_uint(IoStackLocation->MinorFunction, IRP_MN_SET_POWER);
169 ok_eq_pointer(IoStackLocation->Context, RequestedPowerCompletion);
170 ok_eq_uint(IoStackLocation->Parameters.Power.Type, DevicePowerState);
171 ok_eq_uint(IoStackLocation->Parameters.Power.State.DeviceState, PowerDeviceD0);
172
174 {
175 ok_eq_uint(Irp->CurrentLocation, 3);
176 Irp->IoStatus.Information = 7;
177 Irp->IoStatus.Status = STATUS_WAIT_3;
180 return STATUS_SUCCESS;
181 }
182 else if (DeviceObject == DeviceObject2)
183 {
184 ok_eq_uint(Irp->CurrentLocation, 3);
187 return PoCallDriver(DeviceObject1, Irp);
188 }
189 else if (DeviceObject == DeviceObject3)
190 {
191 ok_eq_uint(Irp->CurrentLocation, 3);
194 return PoCallDriver(DeviceObject2, Irp);
195 }
196 else
197 {
198 ok(0, "\n");
202 }
203}
static VOID NTAPI RequestedPowerCompletion(_In_ PDEVICE_OBJECT DeviceObject, _In_ UCHAR MinorFunction, _In_ POWER_STATE PowerState, _In_opt_ PVOID Context, _In_ PIO_STATUS_BLOCK IoStatus)
Definition: PoIrp_drv.c:117
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IoCompleteRequest
Definition: irp.c:1240
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:758
@ DevicePowerState
Definition: ntpoapi.h:63
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
#define STATUS_SUCCESS
Definition: shellext.h:65
#define IRP_MJ_POWER

Referenced by TestPoRequestPowerIrp().

◆ TestEntry()

NTSTATUS TestEntry ( _In_ PDRIVER_OBJECT  DriverObject,
_In_ PCUNICODE_STRING  RegistryPath,
_Out_ PCWSTR DeviceName,
_Inout_ INT Flags 
)

Definition at line 76 of file PoIrp_drv.c.

81{
83
84 PAGED_CODE();
85
87
89
90 *DeviceName = L"PoIrp";
91 *Flags = TESTENTRY_NO_EXCLUSIVE_DEVICE;
92
94
95 return Status;
96}
#define PAGED_CODE()
static KMT_MESSAGE_HANDLER TestMessageHandler
Definition: PoIrp_drv.c:12
static PDRIVER_OBJECT TestDriverObject
Definition: PoIrp_drv.c:11
NTSTATUS KmtRegisterMessageHandler(IN ULONG ControlCode OPTIONAL, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PKMT_MESSAGE_HANDLER MessageHandler)
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define L(x)
Definition: ntvdm.h:50
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

◆ TestMessageHandler()

static NTSTATUS TestMessageHandler ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ ULONG  ControlCode,
_In_ PVOID Buffer  OPTIONAL,
_In_ SIZE_T  InLength,
_Inout_ PSIZE_T  OutLength 
)
static

Definition at line 237 of file PoIrp_drv.c.

243{
245
246 PAGED_CODE();
247
248 switch (ControlCode)
249 {
250 case IOCTL_RUN_TEST:
251 {
254 if (!NT_SUCCESS(Status))
255 return Status;
256
258
264
265 break;
266 }
267 default:
269 }
270
271 return Status;
272}
#define IOCTL_RUN_TEST
Definition: PoIrp.h:11
static NTSTATUS CreateTestDevices(_In_ PDRIVER_OBJECT DriverObject)
Definition: PoIrp_drv.c:20
static VOID TestPoRequestPowerIrp(VOID)
Definition: PoIrp_drv.c:207
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55

◆ TestPoRequestPowerIrp()

static VOID TestPoRequestPowerIrp ( VOID  )
static

Definition at line 207 of file PoIrp_drv.c.

208{
211
213
215
216 PowerState.DeviceState = PowerDeviceD0;
223 ok(Status == STATUS_PENDING, "PoRequestPowerIrp returned %lx\n", Status);
225
227 ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
229}
static NTSTATUS RequestedPowerIrpHandler(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp, _In_ PIO_STACK_LOCATION IoStackLocation)
Definition: PoIrp_drv.c:153
static PIRP RequestedPowerIrpReturned
Definition: PoIrp_drv.c:112
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS KmtUnregisterIrpHandler(IN UCHAR MajorFunction, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PKMT_IRP_HANDLER IrpHandler)
NTSTATUS KmtRegisterIrpHandler(IN UCHAR MajorFunction, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PKMT_IRP_HANDLER IrpHandler)
#define KernelMode
Definition: asm.h:34
@ NotificationEvent
NTSTATUS NTAPI PoRequestPowerIrp(_In_ PDEVICE_OBJECT DeviceObject, _In_ UCHAR MinorFunction, _In_ POWER_STATE PowerState, _In_opt_ PREQUEST_POWER_COMPLETE CompletionFunction, _In_opt_ __drv_aliasesMem PVOID Context, _Outptr_opt_ PIRP *pIrp)
Definition: power.c:659
#define STATUS_PENDING
Definition: ntstatus.h:82
@ Executive
Definition: ketypes.h:415

Referenced by TestMessageHandler().

◆ TestUnload()

VOID TestUnload ( IN PDRIVER_OBJECT  DriverObject)

Definition at line 99 of file PoIrp_drv.c.

101{
103
104 PAGED_CODE();
105}

Variable Documentation

◆ DeviceObject1

PDEVICE_OBJECT DeviceObject1
static

Definition at line 14 of file PoIrp_drv.c.

Referenced by CreateTestDevices(), RequestedPowerIrpHandler(), and TestMessageHandler().

◆ DeviceObject2

◆ DeviceObject3

PDEVICE_OBJECT DeviceObject3
static

Definition at line 16 of file PoIrp_drv.c.

Referenced by CreateTestDevices(), RequestedPowerIrpHandler(), and TestMessageHandler().

◆ RequestedPowerIrp

PIRP RequestedPowerIrp
static

◆ RequestedPowerIrpReturned

PIRP RequestedPowerIrpReturned
static

Definition at line 112 of file PoIrp_drv.c.

Referenced by TestPoRequestPowerIrp().

◆ TestDoneEvent

KEVENT TestDoneEvent
static

Definition at line 110 of file PoIrp_drv.c.

Referenced by RequestedPowerCompletion(), and TestPoRequestPowerIrp().

◆ TestDriverObject

PDRIVER_OBJECT TestDriverObject
static

Definition at line 11 of file PoIrp_drv.c.

Referenced by TestEntry(), and TestMessageHandler().

◆ TestMessageHandler

KMT_MESSAGE_HANDLER TestMessageHandler
static

Definition at line 12 of file PoIrp_drv.c.

Referenced by TestEntry().