ReactOS  0.4.15-dev-1386-g5cb9f87
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.

Function Documentation

◆ TestAttachDevice()

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

Definition at line 525 of file IoDeviceObject_drv.c.

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

Referenced by TestEntry().

◆ TestDetachDevice()

static VOID TestDetachDevice ( IN PDEVICE_OBJECT  AttachedDevice)
static

Definition at line 541 of file IoDeviceObject_drv.c.

543 {
544  IoDetachDevice(AttachedDevice);
545 
546  /* TODO: Add more tests */
547 }
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 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
static PDRIVER_OBJECT ThisDriverObject
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:915
struct _EXTENDED_DEVOBJ_EXTENSION * PEXTENDED_DEVOBJ_EXTENSION
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
PDEVICE_OBJECT AttachedTo
Definition: iotypes.h:920
#define DO_DEVICE_HAS_NAME
Definition: env_spec_w32.h:398
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
#define FILE_DEVICE_UNKNOWN
Definition: winioctl.h:139
#define DO_EXCLUSIVE
Definition: env_spec_w32.h:395

Referenced by TestDeviceCreateDelete().

◆ TestDeviceCreateDelete()

static VOID TestDeviceCreateDelete ( IN PDRIVER_OBJECT  DriverObject)
static

Definition at line 450 of file IoDeviceObject_drv.c.

452 {
454  UNICODE_STRING DeviceString;
456 
457  /* Create using wrong directory */
458  RtlInitUnicodeString(&DeviceString, L"\\Device1\\Kmtest-IoDeviceObject");
460  0,
461  &DeviceString,
463  0,
464  FALSE,
465  &DeviceObject);
466  ok(Status == STATUS_OBJECT_PATH_NOT_FOUND, "Expected STATUS_OBJECT_PATH_NOT_FOUND, got 0x%lX\n", Status);
467 
468  /* Create using correct params with exclusice access */
469  RtlInitUnicodeString(&DeviceString, L"\\Device\\Kmtest-IoDeviceObject");
471  0,
472  &DeviceString,
474  0,
475  TRUE,
476  &DeviceObject);
477  ok(Status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got 0x%lX\n", Status);
478 
480 
481  /* Delete the device */
482  if (NT_SUCCESS(Status))
483  {
485  ok(DriverObject->DeviceObject == 0, "Expected DriverObject->DeviceObject to be NULL, got %p\n",
486  DriverObject->DeviceObject);
487  }
488 
489  /* Create using correct params without exclusice access */
491  0,
492  &DeviceString,
494  0,
495  FALSE,
496  &DeviceObject);
497  ok(Status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got 0x%lX\n", Status);
498 
500 
501  /* Delete the device */
502  if (NT_SUCCESS(Status))
503  {
505  ok(DriverObject->DeviceObject == 0, "Expected DriverObject->DeviceObject to be NULL, got %p\n",
506  DriverObject->DeviceObject);
507  }
508 
509  /* Recreate device */
511  0,
512  &DeviceString,
514  0,
515  FALSE,
516  &DeviceObject);
517  ok(Status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got 0x%lX\n", Status);
518 
519  if (NT_SUCCESS(Status))
521 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_OBJECT_PATH_NOT_FOUND
Definition: udferr_usr.h:151
static const WCHAR L[]
Definition: oid.c:1250
static VOID TestDeviceCreated(IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN ExclusiveAccess)
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define ok(value,...)
Definition: atltest.h:57
static PDEVICE_OBJECT MainDeviceObject
#define FILE_DEVICE_UNKNOWN
Definition: winioctl.h:139
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
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define STATUS_SUCCESS
Definition: shellext.h:65

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;
430  "Expected Extended ExtensionFlags to be DOE_UNLOAD_PENDING, got %lu\n", extdev->ExtensionFlags);
431  ok (extdev->Type == 13, "Expected Type of 13, got %d\n", extdev->Type);
432  ok (extdev->Size == 0, "Expected Size of 0, got %d\n", extdev->Size);
433  ok (extdev->DeviceObject == DeviceObject, "Expected DeviceOject to match newly created device %p, got %p\n",
434  DeviceObject, extdev->DeviceObject);
435  if (Lower || !Attached)
436  {
437  ok(extdev->AttachedTo == NULL, "Expected AttachTo to be NULL, got %p\n", extdev->AttachedTo);
438  }
439  else
440  {
441  ok(extdev->AttachedTo == AttachDeviceObject, "Expected AttachTo to %p, got %p\n", AttachDeviceObject, extdev->AttachedTo);
442  }
443  ok(extdev->StartIoCount == 0, "Expected StartIoCount = 0, got %lu\n", extdev->StartIoCount);
444  ok(extdev->StartIoKey == 0, "Expected StartIoKey = 0, got %lu\n", extdev->StartIoKey);
445  ok(extdev->StartIoFlags == 0, "Expected StartIoFlags = 0, got %lu\n", extdev->StartIoFlags);
446 }
static PDRIVER_OBJECT ThisDriverObject
static PDEVICE_OBJECT AttachDeviceObject
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:915
struct _EXTENDED_DEVOBJ_EXTENSION * PEXTENDED_DEVOBJ_EXTENSION
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
static BOOL Attached
Definition: vidbios.c:3905
PDEVICE_OBJECT AttachedTo
Definition: iotypes.h:920
#define DOE_UNLOAD_PENDING
Definition: iotypes.h:149
#define DO_DEVICE_HAS_NAME
Definition: env_spec_w32.h:398
#define ok(value,...)
Definition: atltest.h:57
static PDEVICE_OBJECT MainDeviceObject
#define NULL
Definition: types.h:112
#define FILE_DEVICE_UNKNOWN
Definition: winioctl.h:139
#define DO_EXCLUSIVE
Definition: env_spec_w32.h:395

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],
126  DeviceObject,
128 
129  if (AttachDeviceObject)
130  {
133  return Status;
134  }
135 
137 
138  Irp->IoStatus.Status = Status;
139  Irp->IoStatus.Information = 0;
140 
142 
143  return Status;
144 }
PCSTR KmtMajorFunctionNames[]
static PDEVICE_OBJECT AttachDeviceObject
LONG NTSTATUS
Definition: precomp.h:26
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
Status
Definition: gdiplustypes.h:24
static VOID TestDriverObject(IN PDRIVER_OBJECT DriverObject, IN PCUNICODE_STRING RegistryPath OPTIONAL, IN DRIVER_STATUS DriverStatus)
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IO_NO_INCREMENT
Definition: iotypes.h:581
#define STATUS_SUCCESS
Definition: shellext.h:65
#define PAGED_CODE()

◆ 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);
180  ok_eq_pointer(DriverObject->DriverExtension, (PDRIVER_EXTENSION)(DriverObject + 1));
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 ok_eq_ulong(value, expected)
#define DRVO_LEGACY_DRIVER
Definition: iotypes.h:2206
#define TRUE
Definition: types.h:120
#define ok_eq_pointer(value, expected)
#define IRP_MJ_MAXIMUM_FUNCTION
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:213
uint16_t * PWCHAR
Definition: typedefs.h:56
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define FALSE
Definition: types.h:117
#define UNICODE_NULL
unsigned char BOOLEAN
#define ok_eq_tag(value, expected)
Definition: kmt_test.h:263
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
#define DRVO_UNLOAD_INVOKED
Definition: iotypes.h:2205
DRIVER_INITIALIZE DriverEntry
Definition: condrv.c:21
#define ASSERT(a)
Definition: mode.c:45
#define DRVO_INITIALIZED
Definition: iotypes.h:4449
__wchar_t WCHAR
Definition: xmlstorage.h:180
NTSTATUS TestEntry(IN PDRIVER_OBJECT DriverObject, IN PCUNICODE_STRING RegistryPath, OUT PCWSTR *DeviceName, IN OUT INT *Flags)
USHORT KmtGetPoolType(PVOID Memory)
static const WCHAR L[]
Definition: oid.c:1250
#define PAGE_SIZE
Definition: env_spec_w32.h:49
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
ULONG KmtGetPoolTag(PVOID Memory)
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
#define skip(...)
Definition: atltest.h:64
#define BASE_POOL_TYPE_MASK
#define ok_eq_uint(value, expected)
Definition: kmt_test.h:239
#define UL
Definition: tui.h:82
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by TestDispatch(), TestEntry(), and TestUnload().

◆ 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 PDRIVER_OBJECT ThisDriverObject
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
static PDEVICE_OBJECT AttachDeviceObject
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define IRP_MJ_MAXIMUM_FUNCTION
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:213
static BOOLEAN TestZwUnload(IN PDRIVER_OBJECT DriverObject, IN PCUNICODE_STRING DriverRegistryPath, IN PWCHAR NewDriverRegPath)
static DRIVER_DISPATCH TestDispatch
uint16_t * PWCHAR
Definition: typedefs.h:56
int32_t INT
Definition: typedefs.h:58
static VOID TestAttachDevice(IN PDEVICE_OBJECT DeviceObject, IN PWCHAR NewDriverRegPath)
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3272
static BOOLEAN TestZwLoad(IN PDRIVER_OBJECT DriverObject, IN PCUNICODE_STRING DriverRegistryPath, IN PWCHAR NewDriverRegPath)
unsigned char BOOLEAN
static VOID TestDeviceCreateDelete(IN PDRIVER_OBJECT DriverObject)
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
Status
Definition: gdiplustypes.h:24
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
static VOID TestDriverObject(IN PDRIVER_OBJECT DriverObject, IN PCUNICODE_STRING RegistryPath OPTIONAL, IN DRIVER_STATUS DriverStatus)
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
static const WCHAR L[]
Definition: oid.c:1250
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
static PDEVICE_OBJECT MainDeviceObject
#define NULL
Definition: types.h:112
#define skip(...)
Definition: atltest.h:64
#define STATUS_SUCCESS
Definition: shellext.h:65
static VOID TestLowerDeviceKernelAPI(IN PDEVICE_OBJECT DeviceObject)
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define PAGED_CODE()

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 }
static PDEVICE_OBJECT AttachDeviceObject
PDEVICE_OBJECT NTAPI IoGetDeviceAttachmentBaseRef(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1419
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
PDEVICE_OBJECT NTAPI IoGetLowerDeviceObject(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1507
#define ObDereferenceObject
Definition: obfuncs.h:203
#define ok(value,...)
Definition: atltest.h:57

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 
106  if (MainDeviceObject)
108 }
static PDEVICE_OBJECT AttachDeviceObject
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static VOID TestDetachDevice(IN PDEVICE_OBJECT AttachedDevice)
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
static VOID TestDeviceDeletion(IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN Lower, IN BOOLEAN Attached)
static VOID TestDriverObject(IN PDRIVER_OBJECT DriverObject, IN PCUNICODE_STRING RegistryPath OPTIONAL, IN DRIVER_STATUS DriverStatus)
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
static PDEVICE_OBJECT MainDeviceObject
#define NULL
Definition: types.h:112
#define skip(...)
Definition: atltest.h:64
#define PAGED_CODE()

◆ 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 */
265  Status = ZwLoadDriver((PUNICODE_STRING)DriverRegistryPath);
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: loader.c:25
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const WCHAR L[]
Definition: oid.c:1250
UNICODE_STRING DriverRegistryPath
Definition: inport.c:24
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
#define ok(value,...)
Definition: atltest.h:57
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_IMAGE_ALREADY_LOADED
Definition: ntstatus.h:506

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 }
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
NTSYSAPI NTSTATUS NTAPI ZwUnloadDriver(_In_ PUNICODE_STRING DriverServiceName)
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const WCHAR L[]
Definition: oid.c:1250
UNICODE_STRING DriverRegistryPath
Definition: inport.c:24
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
#define ok(value,...)
Definition: atltest.h:57
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by TestEntry().

Variable Documentation

◆ AttachDeviceObject

◆ DriverEntry

DRIVER_INITIALIZE 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().