ReactOS 0.4.16-dev-112-g52265ae
IoDeviceObject_drv.c File Reference
#include <kmt_test.h>
#include <debug.h>
Include dependency graph for IoDeviceObject_drv.c:

Go to the source code of this file.

Macros

#define BASE_POOL_TYPE_MASK   1
 

Enumerations

enum  DRIVER_STATUS { DriverStatusEntry , DriverStatusIrp , DriverStatusUnload }
 

Functions

static VOID TestDriverObject (IN PDRIVER_OBJECT DriverObject, IN PCUNICODE_STRING RegistryPath OPTIONAL, IN DRIVER_STATUS DriverStatus)
 
static BOOLEAN TestZwLoad (IN PDRIVER_OBJECT DriverObject, IN PCUNICODE_STRING DriverRegistryPath, IN PWCHAR NewDriverRegPath)
 
static BOOLEAN TestZwUnload (IN PDRIVER_OBJECT DriverObject, IN PCUNICODE_STRING DriverRegistryPath, IN PWCHAR NewDriverRegPath)
 
static VOID TestLowerDeviceKernelAPI (IN PDEVICE_OBJECT DeviceObject)
 
static VOID TestDeviceCreated (IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN ExclusiveAccess)
 
static VOID TestDeviceDeletion (IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN Lower, IN BOOLEAN Attached)
 
static VOID TestDeviceCreateDelete (IN PDRIVER_OBJECT DriverObject)
 
static VOID TestAttachDevice (IN PDEVICE_OBJECT DeviceObject, IN PWCHAR NewDriverRegPath)
 
static VOID TestDetachDevice (IN PDEVICE_OBJECT AttachedDevice)
 
NTSTATUS TestEntry (IN PDRIVER_OBJECT DriverObject, IN PCUNICODE_STRING RegistryPath, OUT PCWSTR *DeviceName, IN OUT INT *Flags)
 
VOID TestUnload (IN PDRIVER_OBJECT DriverObject)
 
static NTSTATUS NTAPI TestDispatch (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 

Variables

static DRIVER_DISPATCH TestDispatch
 
static PDEVICE_OBJECT MainDeviceObject
 
static PDEVICE_OBJECT AttachDeviceObject
 
static PDRIVER_OBJECT ThisDriverObject
 
DRIVER_INITIALIZE DriverEntry
 

Macro Definition Documentation

◆ BASE_POOL_TYPE_MASK

#define BASE_POOL_TYPE_MASK   1

Definition at line 14 of file IoDeviceObject_drv.c.

Enumeration Type Documentation

◆ DRIVER_STATUS

Enumerator
DriverStatusEntry 
DriverStatusIrp 
DriverStatusUnload 

Definition at line 16 of file IoDeviceObject_drv.c.

17{
DRIVER_STATUS
@ DriverStatusUnload
@ DriverStatusEntry
@ DriverStatusIrp

Function Documentation

◆ TestAttachDevice()

static VOID TestAttachDevice ( IN PDEVICE_OBJECT  DeviceObject,
IN PWCHAR  NewDriverRegPath 
)
static

Definition at line 526 of file IoDeviceObject_drv.c.

529{
531 UNICODE_STRING LowerDeviceName;
532
533 RtlInitUnicodeString(&LowerDeviceName, NewDriverRegPath);
536
537 /* TODO: Add more tests */
538}
static PDEVICE_OBJECT AttachDeviceObject
#define ok_eq_hex(value, expected)
Definition: apitest.h:77
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: gdiplustypes.h:25
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSTATUS NTAPI IoAttachDevice(PDEVICE_OBJECT SourceDevice, PUNICODE_STRING TargetDeviceName, PDEVICE_OBJECT *AttachedDevice)
Definition: device.c:913
#define STATUS_SUCCESS
Definition: shellext.h:65
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055

Referenced by TestEntry().

◆ TestDetachDevice()

static VOID TestDetachDevice ( IN PDEVICE_OBJECT  AttachedDevice)
static

Definition at line 542 of file IoDeviceObject_drv.c.

544{
545 IoDetachDevice(AttachedDevice);
546
547 /* TODO: Add more tests */
548}
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1296

Referenced by TestUnload().

◆ TestDeviceCreated()

static VOID TestDeviceCreated ( IN PDEVICE_OBJECT  DeviceObject,
IN BOOLEAN  ExclusiveAccess 
)
static

Definition at line 343 of file IoDeviceObject_drv.c.

346{
348
349 /* Check the device object members */
350 ok(DeviceObject->Type == 3, "Expected Type = 3, got %x\n", DeviceObject->Type);
351 ok(DeviceObject->Size == 0xb8, "Expected Size = 0xb8, got %x\n", DeviceObject->Size);
352 ok(DeviceObject->ReferenceCount == 0, "Expected ReferenceCount = 0, got %lu\n",
353 DeviceObject->ReferenceCount);
354 ok(DeviceObject->DriverObject == ThisDriverObject,
355 "Expected DriverObject member to match this DriverObject %p, got %p\n",
356 ThisDriverObject, DeviceObject->DriverObject);
357 ok(DeviceObject->NextDevice == NULL, "Expected NextDevice to be NULL, got %p\n", DeviceObject->NextDevice);
358 ok(DeviceObject->AttachedDevice == NULL, "Expected AttachDevice to be NULL, got %p\n", DeviceObject->AttachedDevice);
359 ok(DeviceObject->Characteristics == 0, "Expected Characteristics to be 0\n");
360 if (ExclusiveAccess)
361 {
363 "Expected Flags DO_DEVICE_HAS_NAME | DO_DEVICE_INITIALIZING | DO_EXCLUSIVE, got %lu\n", DeviceObject->Flags);
364 }
365 else
366 {
368 "Expected Flags DO_DEVICE_HAS_NAME | DO_DEVICE_INITIALIZING, got %lu\n", DeviceObject->Flags);
369 }
370 ok(DeviceObject->DeviceType == FILE_DEVICE_UNKNOWN,
371 "Expected DeviceType to match creation parameter FILE_DEVICE_UNKNWOWN, got %lu\n",
372 DeviceObject->DeviceType);
373 ok(DeviceObject->ActiveThreadCount == 0, "Expected ActiveThreadCount = 0, got %lu\n", DeviceObject->ActiveThreadCount);
374
375 /* Check the extended extension */
376 extdev = (PEXTENDED_DEVOBJ_EXTENSION)DeviceObject->DeviceObjectExtension;
377 ok(extdev->ExtensionFlags == 0, "Expected Extended ExtensionFlags to be 0, got %lu\n", extdev->ExtensionFlags);
378 ok (extdev->Type == 13, "Expected Type of 13, got %d\n", extdev->Type);
379 ok (extdev->Size == 0, "Expected Size of 0, got %d\n", extdev->Size);
380 ok (extdev->DeviceObject == DeviceObject, "Expected DeviceOject to match newly created device %p, got %p\n",
381 DeviceObject, extdev->DeviceObject);
382 ok(extdev->AttachedTo == NULL, "Expected AttachTo to be NULL, got %p\n", extdev->AttachedTo);
383 ok(extdev->StartIoCount == 0, "Expected StartIoCount = 0, got %lu\n", extdev->StartIoCount);
384 ok(extdev->StartIoKey == 0, "Expected StartIoKey = 0, got %lu\n", extdev->StartIoKey);
385 ok(extdev->StartIoFlags == 0, "Expected StartIoFlags = 0, got %lu\n", extdev->StartIoFlags);
386}
static PDRIVER_OBJECT ThisDriverObject
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
#define DO_EXCLUSIVE
Definition: env_spec_w32.h:395
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define DO_DEVICE_HAS_NAME
Definition: env_spec_w32.h:398
struct _EXTENDED_DEVOBJ_EXTENSION * PEXTENDED_DEVOBJ_EXTENSION
#define FILE_DEVICE_UNKNOWN
Definition: winioctl.h:79
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:1081
PDEVICE_OBJECT AttachedTo
Definition: iotypes.h:1086

Referenced by TestDeviceCreateDelete().

◆ TestDeviceCreateDelete()

static VOID TestDeviceCreateDelete ( IN PDRIVER_OBJECT  DriverObject)
static

Definition at line 451 of file IoDeviceObject_drv.c.

453{
455 UNICODE_STRING DeviceString;
457
458 /* Create using wrong directory */
459 RtlInitUnicodeString(&DeviceString, L"\\Device1\\Kmtest-IoDeviceObject");
461 0,
462 &DeviceString,
464 0,
465 FALSE,
466 &DeviceObject);
467 ok(Status == STATUS_OBJECT_PATH_NOT_FOUND, "Expected STATUS_OBJECT_PATH_NOT_FOUND, got 0x%lX\n", Status);
468
469 /* Create using correct params with exclusice access */
470 RtlInitUnicodeString(&DeviceString, L"\\Device\\Kmtest-IoDeviceObject");
472 0,
473 &DeviceString,
475 0,
476 TRUE,
477 &DeviceObject);
478 ok(Status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got 0x%lX\n", Status);
479
481
482 /* Delete the device */
483 if (NT_SUCCESS(Status))
484 {
486 ok(DriverObject->DeviceObject == 0, "Expected DriverObject->DeviceObject to be NULL, got %p\n",
487 DriverObject->DeviceObject);
488 }
489
490 /* Create using correct params without exclusice access */
492 0,
493 &DeviceString,
495 0,
496 FALSE,
497 &DeviceObject);
498 ok(Status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got 0x%lX\n", Status);
499
501
502 /* Delete the device */
503 if (NT_SUCCESS(Status))
504 {
506 ok(DriverObject->DeviceObject == 0, "Expected DriverObject->DeviceObject to be NULL, got %p\n",
507 DriverObject->DeviceObject);
508 }
509
510 /* Recreate device */
512 0,
513 &DeviceString,
515 0,
516 FALSE,
517 &DeviceObject);
518 ok(Status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got 0x%lX\n", Status);
519
520 if (NT_SUCCESS(Status))
522}
static PDEVICE_OBJECT MainDeviceObject
static VOID TestDeviceCreated(IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN ExclusiveAccess)
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
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 IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define L(x)
Definition: ntvdm.h:50
#define STATUS_OBJECT_PATH_NOT_FOUND
Definition: udferr_usr.h:151
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213

Referenced by TestEntry().

◆ TestDeviceDeletion()

static VOID TestDeviceDeletion ( IN PDEVICE_OBJECT  DeviceObject,
IN BOOLEAN  Lower,
IN BOOLEAN  Attached 
)
static

Definition at line 390 of file IoDeviceObject_drv.c.

394{
396
397 /* Check the device object members */
398 ok(DeviceObject->Type == 3, "Expected Type = 3, got %d\n", DeviceObject->Type);
399 ok(DeviceObject->Size == 0xb8, "Expected Size = 0xb8, got %d\n", DeviceObject->Size);
400 ok(DeviceObject->ReferenceCount == 0, "Expected ReferenceCount = 0, got %lu\n",
401 DeviceObject->ReferenceCount);
402 if (!Lower)
403 {
404 ok(DeviceObject->DriverObject == ThisDriverObject,
405 "Expected DriverObject member to match this DriverObject %p, got %p\n",
406 ThisDriverObject, DeviceObject->DriverObject);
407 }
408 ok(DeviceObject->NextDevice == NULL, "Expected NextDevice to be NULL, got %p\n", DeviceObject->NextDevice);
409
410 if (Lower)
411 {
412 ok(DeviceObject->AttachedDevice == MainDeviceObject,
413 "Expected AttachDevice to be %p, got %p\n", MainDeviceObject, DeviceObject->AttachedDevice);
414 }
415 else
416 {
417 ok(DeviceObject->AttachedDevice == NULL, "Expected AttachDevice to be NULL, got %p\n", DeviceObject->AttachedDevice);
418 }
419
420 ok(DeviceObject->Flags == (DO_DEVICE_HAS_NAME | (Lower ? DO_EXCLUSIVE : 0)),
421 "Expected Flags DO_DEVICE_HAS_NAME, got %lu\n", DeviceObject->Flags);
422 ok(DeviceObject->DeviceType == FILE_DEVICE_UNKNOWN,
423 "Expected DeviceType to match creation parameter FILE_DEVICE_UNKNWOWN, got %lu\n",
424 DeviceObject->DeviceType);
425 ok(DeviceObject->ActiveThreadCount == 0, "Expected ActiveThreadCount = 0, got %lu\n", DeviceObject->ActiveThreadCount);
426
427 /* Check the extended extension */
428 extdev = (PEXTENDED_DEVOBJ_EXTENSION)DeviceObject->DeviceObjectExtension;
429 /* FIXME: Windows has the MSB set under some conditions, need to find out what this means */
430 ok((extdev->ExtensionFlags & 0x7fffffff) == DOE_UNLOAD_PENDING,
431 "Expected Extended ExtensionFlags to be DOE_UNLOAD_PENDING, got 0x%lx\n", extdev->ExtensionFlags);
432 ok (extdev->Type == 13, "Expected Type of 13, got %d\n", extdev->Type);
433 ok (extdev->Size == 0, "Expected Size of 0, got %d\n", extdev->Size);
434 ok (extdev->DeviceObject == DeviceObject, "Expected DeviceOject to match newly created device %p, got %p\n",
435 DeviceObject, extdev->DeviceObject);
436 if (Lower || !Attached)
437 {
438 ok(extdev->AttachedTo == NULL, "Expected AttachTo to be NULL, got %p\n", extdev->AttachedTo);
439 }
440 else
441 {
442 ok(extdev->AttachedTo == AttachDeviceObject, "Expected AttachTo to %p, got %p\n", AttachDeviceObject, extdev->AttachedTo);
443 }
444 ok(extdev->StartIoCount == 0, "Expected StartIoCount = 0, got %lu\n", extdev->StartIoCount);
445 ok(extdev->StartIoKey == 0, "Expected StartIoKey = 0, got %lu\n", extdev->StartIoKey);
446 ok(extdev->StartIoFlags == 0, "Expected StartIoFlags = 0, got %lu\n", extdev->StartIoFlags);
447}
#define DOE_UNLOAD_PENDING
Definition: iotypes.h:149
static BOOL Attached
Definition: vidbios.c:3905

Referenced by TestUnload().

◆ TestDispatch()

static NTSTATUS NTAPI TestDispatch ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)
static

Definition at line 113 of file IoDeviceObject_drv.c.

116{
118 PIO_STACK_LOCATION IoStackLocation;
119
120 PAGED_CODE();
121
122 IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
123
124 DPRINT("TestIrpHandler. Function=%s, DeviceObject=%p, AttachDeviceObject=%p\n",
125 KmtMajorFunctionNames[IoStackLocation->MajorFunction],
128
130 {
133 return Status;
134 }
135
137
138 Irp->IoStatus.Status = Status;
139 Irp->IoStatus.Information = 0;
140
142
143 return Status;
144}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define PAGED_CODE()
static PDRIVER_OBJECT TestDriverObject
Definition: Example_drv.c:20
_In_ PIRP Irp
Definition: csq.h:116
PCSTR KmtMajorFunctionNames[]
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IoCompleteRequest
Definition: irp.c:1240
#define IoCallDriver
Definition: irp.c:1225
#define DPRINT
Definition: sndvol32.h:73
#define IO_NO_INCREMENT
Definition: iotypes.h:598

◆ TestDriverObject()

static VOID TestDriverObject ( IN PDRIVER_OBJECT  DriverObject,
IN PCUNICODE_STRING RegistryPath  OPTIONAL,
IN DRIVER_STATUS  DriverStatus 
)
static

Definition at line 150 of file IoDeviceObject_drv.c.

154{
155 BOOLEAN CheckThisDispatchRoutine;
156 PVOID FirstMajorFunc;
157 int i;
158 UNICODE_STRING HardwareDatabase = RTL_CONSTANT_STRING(L"\\REGISTRY\\MACHINE\\HARDWARE\\DESCRIPTION\\SYSTEM");
159 UNICODE_STRING RegPath = RTL_CONSTANT_STRING(L"\\REGISTRY\\MACHINE\\SYSTEM\\ControlSet001\\Services\\Kmtest-IoDeviceObject");
160 UNICODE_STRING DriverName = RTL_CONSTANT_STRING(L"\\Driver\\Kmtest-IoDeviceObject");
161 UNICODE_STRING ServiceKeyName = RTL_CONSTANT_STRING(L"Kmtest-IoDeviceObject");
162 BOOLEAN Equal;
163
164 ok(DriverObject->Size == sizeof(DRIVER_OBJECT), "Size does not match, got %x\n",DriverObject->Size);
165 ok(DriverObject->Type == 4, "Type does not match 4. got %d\n", DriverObject->Type);
166
167 if (DriverStatus == DriverStatusEntry)
168 {
169 ok(DriverObject->DeviceObject == NULL, "Expected DeviceObject pointer to be 0, got %p\n",
170 DriverObject->DeviceObject);
172 "Expected Flags to be DRVO_LEGACY_DRIVER, got %lu\n",
173 DriverObject->Flags);
174
175 ok(DriverObject->DriverStart < (PVOID)TestEntry,
176 "DriverStart is %p, expected < %p\n",
177 DriverObject->DriverStart, (PVOID)TestEntry);
178 ok(DriverObject->DriverSize > 0x2000,
179 "DriverSize 0x%lx\n", DriverObject->DriverSize);
181 ok_eq_pointer(DriverObject->DriverExtension->DriverObject, DriverObject);
182 ok_eq_pointer(DriverObject->DriverExtension->AddDevice, NULL);
183 ok_eq_ulong(DriverObject->DriverExtension->Count, 0UL);
185 &RegPath,
186 FALSE);
187 ok(Equal, "RegistryPath is '%wZ'\n", RegistryPath);
188 ok((ULONG_PTR)RegistryPath % PAGE_SIZE == 0, "RegistryPath %p not page-aligned\n", RegistryPath);
190 ok_eq_uint(RegistryPath->MaximumLength, RegistryPath->Length);
191 Equal = RtlEqualUnicodeString(&DriverObject->DriverExtension->ServiceKeyName,
192 &ServiceKeyName,
193 FALSE);
194 ok(Equal, "ServiceKeyName is '%wZ'\n", &DriverObject->DriverExtension->ServiceKeyName);
195 ok_eq_tag(KmtGetPoolTag(DriverObject->DriverExtension->ServiceKeyName.Buffer), ' oI');
196 ok_eq_uint((KmtGetPoolType(DriverObject->DriverExtension->ServiceKeyName.Buffer) - 1) & BASE_POOL_TYPE_MASK, NonPagedPool);
197 ok_eq_uint(DriverObject->DriverExtension->ServiceKeyName.MaximumLength, DriverObject->DriverExtension->ServiceKeyName.Length + sizeof(UNICODE_NULL));
198 ok_eq_uint(DriverObject->DriverExtension->ServiceKeyName.Buffer[DriverObject->DriverExtension->ServiceKeyName.Length / sizeof(WCHAR)], UNICODE_NULL);
199 Equal = RtlEqualUnicodeString(&DriverObject->DriverName,
200 &DriverName,
201 FALSE);
202 ok(Equal, "DriverName is '%wZ'\n", &DriverObject->DriverName);
203 ok_eq_tag(KmtGetPoolTag(DriverObject->DriverName.Buffer), ' oI');
205 ok_eq_uint(DriverObject->DriverName.MaximumLength, DriverObject->DriverName.Length);
206 // TODO: show that both string and buffer are constants inside ntos
207 Equal = RtlEqualUnicodeString(DriverObject->HardwareDatabase,
208 &HardwareDatabase,
209 FALSE);
210 ok(Equal, "HardwareDatabase is '%wZ'\n", DriverObject->HardwareDatabase);
211 ok_eq_uint(DriverObject->HardwareDatabase->MaximumLength, DriverObject->HardwareDatabase->Length + sizeof(UNICODE_NULL));
212 ok_eq_uint(DriverObject->HardwareDatabase->Buffer[DriverObject->HardwareDatabase->Length / sizeof(WCHAR)], UNICODE_NULL);
213 ok(DriverObject->DriverInit == DriverEntry,
214 "DriverInit is %p, expected %p\n",
215 (PVOID)DriverObject->DriverInit, (PVOID)DriverEntry);
216 }
217 else if (DriverStatus == DriverStatusIrp)
218 {
219 ok(DriverObject->DeviceObject != NULL, "Expected DeviceObject pointer to non null\n");
221 "Expected Flags to be DRVO_LEGACY_DRIVER | DRVO_INITIALIZED, got %lu\n",
222 DriverObject->Flags);
223 }
224 else if (DriverStatus == DriverStatusUnload)
225 {
226 ok(DriverObject->DeviceObject != NULL, "Expected DeviceObject pointer to non null\n");
228 "Expected Flags to be DRVO_LEGACY_DRIVER | DRVO_INITIALIZED | DRVO_UNLOAD_INVOKED, got %lu\n",
229 DriverObject->Flags);
230 }
231 else
232 ASSERT(FALSE);
233
234 /* Select a routine that was not changed */
235 FirstMajorFunc = DriverObject->MajorFunction[1];
236 ok(FirstMajorFunc != 0, "Expected MajorFunction[1] to be non NULL\n");
237
238 if (!skip(FirstMajorFunc != NULL, "First major function not set!\n"))
239 {
240 for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
241 {
242 if (DriverStatus > 0) CheckThisDispatchRoutine = (i > 3) && (i != 14);
243 else CheckThisDispatchRoutine = TRUE;
244
245 if (CheckThisDispatchRoutine)
246 {
247 ok(DriverObject->MajorFunction[i] == FirstMajorFunc, "Expected MajorFunction[%d] to match %p\n",
248 i, FirstMajorFunc);
249 }
250 }
251 }
252}
#define BASE_POOL_TYPE_MASK
DRIVER_INITIALIZE DriverEntry
Definition: condrv.c:21
NTSTATUS TestEntry(IN PDRIVER_OBJECT DriverObject, IN PCUNICODE_STRING RegistryPath, OUT PCWSTR *DeviceName, IN OUT INT *Flags)
unsigned char BOOLEAN
#define ok_eq_pointer(value, expected)
Definition: apitest.h:59
#define ok_eq_ulong(value, expected)
Definition: apitest.h:63
#define ok_eq_tag(value, expected)
Definition: apitest.h:85
#define ok_eq_uint(value, expected)
Definition: apitest.h:61
#define skip(...)
Definition: atltest.h:64
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define NonPagedPool
Definition: env_spec_w32.h:307
#define PagedPool
Definition: env_spec_w32.h:308
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
USHORT KmtGetPoolType(PVOID Memory)
ULONG KmtGetPoolTag(PVOID Memory)
#define ASSERT(a)
Definition: mode.c:44
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
#define UNICODE_NULL
#define UL
Definition: tui.h:165
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint16_t * PWCHAR
Definition: typedefs.h:56
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
#define DRVO_UNLOAD_INVOKED
Definition: iotypes.h:2225
#define DRVO_INITIALIZED
Definition: iotypes.h:4470
#define DRVO_LEGACY_DRIVER
Definition: iotypes.h:2226
#define IRP_MJ_MAXIMUM_FUNCTION
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ TestEntry()

NTSTATUS TestEntry ( IN PDRIVER_OBJECT  DriverObject,
IN PCUNICODE_STRING  RegistryPath,
OUT PCWSTR DeviceName,
IN OUT INT Flags 
)

Definition at line 39 of file IoDeviceObject_drv.c.

44{
46 BOOLEAN Ret;
47 INT i;
48
49 PAGED_CODE();
50
52
53 *Flags = TESTENTRY_NO_CREATE_DEVICE | TESTENTRY_NO_REGISTER_DISPATCH;
54
56
58
59 /* Create and delete device, on return MainDeviceObject has been created */
61
62 /* Make sure a device object was created */
63 if (!skip(MainDeviceObject != NULL, "Device object creation failed\n"))
64 {
65 PWCHAR LowerDriverRegPath = L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\Kmtest-IoHelper";
66
67 /* Load driver test and load the lower driver */
68 Ret = TestZwLoad(DriverObject, RegistryPath, LowerDriverRegPath);
69 if (!skip(Ret, "Failed to load helper driver\n"))
70 {
71 TestAttachDevice(MainDeviceObject, L"\\Device\\Kmtest-IoHelper");
72 if (!skip(AttachDeviceObject != NULL, "No attached device object\n"))
74
75 /* Unload lower driver without detaching from its device */
76 TestZwUnload(DriverObject, RegistryPath, LowerDriverRegPath);
78 }
79 }
80
81 for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; ++i)
82 DriverObject->MajorFunction[i] = NULL;
83 DriverObject->MajorFunction[IRP_MJ_CREATE] = TestDispatch;
84 DriverObject->MajorFunction[IRP_MJ_CLOSE] = TestDispatch;
86
87 return Status;
88}
static BOOLEAN TestZwUnload(IN PDRIVER_OBJECT DriverObject, IN PCUNICODE_STRING DriverRegistryPath, IN PWCHAR NewDriverRegPath)
static BOOLEAN TestZwLoad(IN PDRIVER_OBJECT DriverObject, IN PCUNICODE_STRING DriverRegistryPath, IN PWCHAR NewDriverRegPath)
static VOID TestLowerDeviceKernelAPI(IN PDEVICE_OBJECT DeviceObject)
static DRIVER_DISPATCH TestDispatch
static VOID TestDeviceCreateDelete(IN PDRIVER_OBJECT DriverObject)
static VOID TestAttachDevice(IN PDEVICE_OBJECT DeviceObject, IN PWCHAR NewDriverRegPath)
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
int32_t INT
Definition: typedefs.h:58
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Referenced by TestDriverObject().

◆ TestLowerDeviceKernelAPI()

static VOID TestLowerDeviceKernelAPI ( IN PDEVICE_OBJECT  DeviceObject)
static

Definition at line 315 of file IoDeviceObject_drv.c.

317{
318 PDEVICE_OBJECT RetObject;
319
321
322 ok(RetObject == AttachDeviceObject,
323 "Expected an Attached DeviceObject %p, got %p\n", AttachDeviceObject, RetObject);
324
325 if (RetObject)
326 {
327 ObDereferenceObject(RetObject);
328 }
329
331 ok(RetObject == AttachDeviceObject,
332 "Expected an Attached DeviceObject %p, got %p\n", AttachDeviceObject, RetObject);
333
334 if (RetObject)
335 {
336 ObDereferenceObject(RetObject);
337 }
338
339}
PDEVICE_OBJECT NTAPI IoGetLowerDeviceObject(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1507
PDEVICE_OBJECT NTAPI IoGetDeviceAttachmentBaseRef(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1419
#define ObDereferenceObject
Definition: obfuncs.h:203

Referenced by TestEntry().

◆ TestUnload()

VOID TestUnload ( IN PDRIVER_OBJECT  DriverObject)

Definition at line 91 of file IoDeviceObject_drv.c.

93{
94 PAGED_CODE();
95
96 if (!skip(AttachDeviceObject != NULL, "no attached device object\n"))
97 {
101 }
102
105
108}
static VOID TestDetachDevice(IN PDEVICE_OBJECT AttachedDevice)
static VOID TestDeviceDeletion(IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN Lower, IN BOOLEAN Attached)

◆ TestZwLoad()

static BOOLEAN TestZwLoad ( IN PDRIVER_OBJECT  DriverObject,
IN PCUNICODE_STRING  DriverRegistryPath,
IN PWCHAR  NewDriverRegPath 
)
static

Definition at line 256 of file IoDeviceObject_drv.c.

260{
261 UNICODE_STRING RegPath;
263
264 /* Try to load ourself */
266 ok (Status == STATUS_IMAGE_ALREADY_LOADED, "Expected NTSTATUS STATUS_IMAGE_ALREADY_LOADED, got 0x%lX\n", Status);
267
269 {
270 DbgPrint("WARNING: Loading this a second time will cause BUGCHECK!\n");
271 }
272
273 /* Try to load with a Registry Path that doesnt exist */
274 RtlInitUnicodeString(&RegPath, L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\deadbeef");
275 Status = ZwLoadDriver(&RegPath);
276 ok (Status == STATUS_OBJECT_NAME_NOT_FOUND, "Expected NTSTATUS STATUS_OBJECT_NAME_NOT_FOUND, got 0x%lX\n", Status);
277
278 /* Load the driver */
279 RtlInitUnicodeString(&RegPath, NewDriverRegPath);
280 Status = ZwLoadDriver(&RegPath);
281 ok(Status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got 0x%lX\n", Status);
282
283 return NT_SUCCESS(Status);
284}
#define DbgPrint
Definition: hal.h:12
UNICODE_STRING DriverRegistryPath
Definition: inport.c:17
#define STATUS_IMAGE_ALREADY_LOADED
Definition: ntstatus.h:506
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149

Referenced by TestEntry().

◆ TestZwUnload()

static BOOLEAN TestZwUnload ( IN PDRIVER_OBJECT  DriverObject,
IN PCUNICODE_STRING  DriverRegistryPath,
IN PWCHAR  NewDriverRegPath 
)
static

Definition at line 288 of file IoDeviceObject_drv.c.

292{
293 UNICODE_STRING RegPath;
295
296 /* Try to unload ourself, which should fail as our Unload routine hasnt been set yet. */
298 ok (Status == STATUS_INVALID_DEVICE_REQUEST, "Expected NTSTATUS STATUS_INVALID_DEVICE_REQUEST, got 0x%lX\n", Status);
299
300 /* Try to unload with a Registry Path that doesnt exist */
301 RtlInitUnicodeString(&RegPath, L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\deadbeef");
302 Status = ZwUnloadDriver(&RegPath);
303 ok (Status == STATUS_OBJECT_NAME_NOT_FOUND, "Expected NTSTATUS STATUS_OBJECT_NAME_NOT_FOUND, got 0x%lX\n", Status);
304
305 /* Unload the driver */
306 RtlInitUnicodeString(&RegPath, NewDriverRegPath);
307 Status = ZwUnloadDriver(&RegPath);
308 ok(Status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got 0x%lX\n", Status);
309
310 return NT_SUCCESS(Status);
311}
NTSYSAPI NTSTATUS NTAPI ZwUnloadDriver(_In_ PUNICODE_STRING DriverServiceName)
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138

Referenced by TestEntry().

Variable Documentation

◆ AttachDeviceObject

◆ DriverEntry

◆ MainDeviceObject

◆ TestDispatch

DRIVER_DISPATCH TestDispatch
static

Definition at line 23 of file IoDeviceObject_drv.c.

Referenced by TestEntry().

◆ ThisDriverObject

PDRIVER_OBJECT ThisDriverObject
static

Definition at line 36 of file IoDeviceObject_drv.c.

Referenced by TestDeviceCreated(), TestDeviceDeletion(), and TestEntry().