ReactOS 0.4.16-dev-1946-g52006dd
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 538 of file IoDeviceObject_drv.c.

541{
543 UNICODE_STRING LowerDeviceName;
544
545 RtlInitUnicodeString(&LowerDeviceName, NewDriverRegPath);
548
549 /* TODO: Add more tests */
550}
static PDEVICE_OBJECT AttachDeviceObject
#define ok_eq_hex(value, expected)
Definition: apitest.h:134
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:2061

Referenced by TestEntry().

◆ TestDetachDevice()

static VOID TestDetachDevice ( IN PDEVICE_OBJECT  AttachedDevice)
static

Definition at line 554 of file IoDeviceObject_drv.c.

556{
557 IoDetachDevice(AttachedDevice);
558
559 /* TODO: Add more tests */
560}
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 345 of file IoDeviceObject_drv.c.

348{
350
351 /* Check the device object members */
352 ok(DeviceObject->Type == 3, "Expected Type = 3, got %x\n", DeviceObject->Type);
353#ifdef _M_IX86
354 ok(DeviceObject->Size == 0xb8, "Expected Size = 0xb8, got 0x%x\n", DeviceObject->Size);
355#else
356 ok(DeviceObject->Size == 0x150, "Expected Size = 0x150, got 0x%x\n", DeviceObject->Size);
357#endif
358 ok(DeviceObject->ReferenceCount == 0, "Expected ReferenceCount = 0, got %lu\n",
359 DeviceObject->ReferenceCount);
360 ok(DeviceObject->DriverObject == ThisDriverObject,
361 "Expected DriverObject member to match this DriverObject %p, got %p\n",
362 ThisDriverObject, DeviceObject->DriverObject);
363 ok(DeviceObject->NextDevice == NULL, "Expected NextDevice to be NULL, got %p\n", DeviceObject->NextDevice);
364 ok(DeviceObject->AttachedDevice == NULL, "Expected AttachDevice to be NULL, got %p\n", DeviceObject->AttachedDevice);
365 ok(DeviceObject->Characteristics == 0, "Expected Characteristics to be 0\n");
366 if (ExclusiveAccess)
367 {
369 "Expected Flags DO_DEVICE_HAS_NAME | DO_DEVICE_INITIALIZING | DO_EXCLUSIVE, got %lu\n", DeviceObject->Flags);
370 }
371 else
372 {
374 "Expected Flags DO_DEVICE_HAS_NAME | DO_DEVICE_INITIALIZING, got %lu\n", DeviceObject->Flags);
375 }
376 ok(DeviceObject->DeviceType == FILE_DEVICE_UNKNOWN,
377 "Expected DeviceType to match creation parameter FILE_DEVICE_UNKNWOWN, got %lu\n",
378 DeviceObject->DeviceType);
379 ok(DeviceObject->ActiveThreadCount == 0, "Expected ActiveThreadCount = 0, got %lu\n", DeviceObject->ActiveThreadCount);
380
381 /* Check the extended extension */
382 extdev = (PEXTENDED_DEVOBJ_EXTENSION)DeviceObject->DeviceObjectExtension;
383 ok(extdev->ExtensionFlags == DOE_DEFAULT_SD_PRESENT || // Vista+
384 extdev->ExtensionFlags == 0, // WS03
385 "Expected Extended ExtensionFlags to be DOE_DEFAULT_SD_PRESENT or 0, got %lu\n", extdev->ExtensionFlags);
386 ok(extdev->Type == 13, "Expected Type of 13, got %d\n", extdev->Type);
387 ok(extdev->Size == 0, "Expected Size of 0, got %d\n", extdev->Size);
388 ok(extdev->DeviceObject == DeviceObject, "Expected DeviceOject to match newly created device %p, got %p\n",
389 DeviceObject, extdev->DeviceObject);
390 ok(extdev->AttachedTo == NULL, "Expected AttachTo to be NULL, got %p\n", extdev->AttachedTo);
391 ok(extdev->StartIoCount == 0, "Expected StartIoCount = 0, got %lu\n", extdev->StartIoCount);
392 ok(extdev->StartIoKey == 0, "Expected StartIoKey = 0, got %lu\n", extdev->StartIoKey);
393 ok(extdev->StartIoFlags == 0, "Expected StartIoFlags = 0, got %lu\n", extdev->StartIoFlags);
394}
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 DOE_DEFAULT_SD_PRESENT
Definition: iotypes.h:154
#define FILE_DEVICE_UNKNOWN
Definition: winioctl.h:79
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:1087
PDEVICE_OBJECT AttachedTo
Definition: iotypes.h:1092

Referenced by TestDeviceCreateDelete().

◆ TestDeviceCreateDelete()

static VOID TestDeviceCreateDelete ( IN PDRIVER_OBJECT  DriverObject)
static

Definition at line 463 of file IoDeviceObject_drv.c.

465{
467 UNICODE_STRING DeviceString;
469
470 /* Create using wrong directory */
471 RtlInitUnicodeString(&DeviceString, L"\\Device1\\Kmtest-IoDeviceObject");
473 0,
474 &DeviceString,
476 0,
477 FALSE,
478 &DeviceObject);
479 ok(Status == STATUS_OBJECT_PATH_NOT_FOUND, "Expected STATUS_OBJECT_PATH_NOT_FOUND, got 0x%lX\n", Status);
480
481 /* Create using correct params with exclusice access */
482 RtlInitUnicodeString(&DeviceString, L"\\Device\\Kmtest-IoDeviceObject");
484 0,
485 &DeviceString,
487 0,
488 TRUE,
489 &DeviceObject);
490 ok(Status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got 0x%lX\n", Status);
491
493
494 /* Delete the device */
495 if (NT_SUCCESS(Status))
496 {
498 ok(DriverObject->DeviceObject == 0, "Expected DriverObject->DeviceObject to be NULL, got %p\n",
499 DriverObject->DeviceObject);
500 }
501
502 /* Create using correct params without exclusice access */
504 0,
505 &DeviceString,
507 0,
508 FALSE,
509 &DeviceObject);
510 ok(Status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got 0x%lX\n", Status);
511
513
514 /* Delete the device */
515 if (NT_SUCCESS(Status))
516 {
518 ok(DriverObject->DeviceObject == 0, "Expected DriverObject->DeviceObject to be NULL, got %p\n",
519 DriverObject->DeviceObject);
520 }
521
522 /* Recreate device */
524 0,
525 &DeviceString,
527 0,
528 FALSE,
529 &DeviceObject);
530 ok(Status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got 0x%lX\n", Status);
531
532 if (NT_SUCCESS(Status))
534}
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
#define L(x)
Definition: resources.c:13
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 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 398 of file IoDeviceObject_drv.c.

402{
404
405 /* Check the device object members */
406 ok(DeviceObject->Type == 3, "Expected Type = 3, got %d\n", DeviceObject->Type);
407#ifdef _M_IX86
408 ok(DeviceObject->Size == 0xb8, "Expected Size = 0xb8, got 0x%x\n", DeviceObject->Size);
409#else
410 ok(DeviceObject->Size == 0x150, "Expected Size = 0x150, got 0x%x\n", DeviceObject->Size);
411#endif
412 ok(DeviceObject->ReferenceCount == 0, "Expected ReferenceCount = 0, got %lu\n",
413 DeviceObject->ReferenceCount);
414 if (!Lower)
415 {
416 ok(DeviceObject->DriverObject == ThisDriverObject,
417 "Expected DriverObject member to match this DriverObject %p, got %p\n",
418 ThisDriverObject, DeviceObject->DriverObject);
419 }
420 ok(DeviceObject->NextDevice == NULL, "Expected NextDevice to be NULL, got %p\n", DeviceObject->NextDevice);
421
422 if (Lower)
423 {
424 ok(DeviceObject->AttachedDevice == MainDeviceObject,
425 "Expected AttachDevice to be %p, got %p\n", MainDeviceObject, DeviceObject->AttachedDevice);
426 }
427 else
428 {
429 ok(DeviceObject->AttachedDevice == NULL, "Expected AttachDevice to be NULL, got %p\n", DeviceObject->AttachedDevice);
430 }
431
432 ok(DeviceObject->Flags == (DO_DEVICE_HAS_NAME | (Lower ? DO_EXCLUSIVE : 0)),
433 "Expected Flags DO_DEVICE_HAS_NAME, got %lu\n", DeviceObject->Flags);
434 ok(DeviceObject->DeviceType == FILE_DEVICE_UNKNOWN,
435 "Expected DeviceType to match creation parameter FILE_DEVICE_UNKNWOWN, got %lu\n",
436 DeviceObject->DeviceType);
437 ok(DeviceObject->ActiveThreadCount == 0, "Expected ActiveThreadCount = 0, got %lu\n", DeviceObject->ActiveThreadCount);
438
439 /* Check the extended extension */
440 extdev = (PEXTENDED_DEVOBJ_EXTENSION)DeviceObject->DeviceObjectExtension;
442 extdev->ExtensionFlags & 0x7fffffff) == DOE_UNLOAD_PENDING, // WS03 FIXME: Windows has the MSB set under some conditions, need to find out what this means
443 "Unexpected Extended ExtensionFlags (0x%lx)\n", extdev->ExtensionFlags);
444 ok (extdev->Type == 13, "Expected Type of 13, got %d\n", extdev->Type);
445 ok (extdev->Size == 0, "Expected Size of 0, got %d\n", extdev->Size);
446 ok (extdev->DeviceObject == DeviceObject, "Expected DeviceOject to match newly created device %p, got %p\n",
447 DeviceObject, extdev->DeviceObject);
448 if (Lower || !Attached)
449 {
450 ok(extdev->AttachedTo == NULL, "Expected AttachTo to be NULL, got %p\n", extdev->AttachedTo);
451 }
452 else
453 {
454 ok(extdev->AttachedTo == AttachDeviceObject, "Expected AttachTo to %p, got %p\n", AttachDeviceObject, extdev->AttachedTo);
455 }
456 ok(extdev->StartIoCount == 0, "Expected StartIoCount = 0, got %lu\n", extdev->StartIoCount);
457 ok(extdev->StartIoKey == 0, "Expected StartIoKey = 0, got %lu\n", extdev->StartIoKey);
458 ok(extdev->StartIoFlags == 0, "Expected StartIoFlags = 0, got %lu\n", extdev->StartIoFlags);
459}
#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{
119
120 PAGED_CODE();
121
123
124 DPRINT("TestIrpHandler. Function=%s, DeviceObject=%p, AttachDeviceObject=%p\n",
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
_In_ PIO_STACK_LOCATION IoStackLocation
Definition: usbdlib.h:265
#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);
184 /* Windows 7 doesn't capitalize "Services" like all other versions before and after it. */
186 &RegPath,
188 ok(Equal, "RegistryPath is '%wZ'\n", RegistryPath);
189 ok((ULONG_PTR)RegistryPath % PAGE_SIZE == 0, "RegistryPath %p not page-aligned\n", RegistryPath);
191 ok_eq_uint(RegistryPath->MaximumLength, RegistryPath->Length);
192 Equal = RtlEqualUnicodeString(&DriverObject->DriverExtension->ServiceKeyName,
193 &ServiceKeyName,
194 FALSE);
195 ok(Equal, "ServiceKeyName is '%wZ'\n", &DriverObject->DriverExtension->ServiceKeyName);
196 ok_eq_tag(KmtGetPoolTag(DriverObject->DriverExtension->ServiceKeyName.Buffer), ' oI');
197 if (GetNTVersion() <= _WIN32_WINNT_WS03) // Not guaranteed on Vista+
198 ok_eq_uint((KmtGetPoolType(DriverObject->DriverExtension->ServiceKeyName.Buffer) - 1) & BASE_POOL_TYPE_MASK, NonPagedPool);
199 ok_eq_uint(DriverObject->DriverExtension->ServiceKeyName.MaximumLength, DriverObject->DriverExtension->ServiceKeyName.Length + sizeof(UNICODE_NULL));
200 ok_eq_uint(DriverObject->DriverExtension->ServiceKeyName.Buffer[DriverObject->DriverExtension->ServiceKeyName.Length / sizeof(WCHAR)], UNICODE_NULL);
201 Equal = RtlEqualUnicodeString(&DriverObject->DriverName,
202 &DriverName,
203 FALSE);
204 ok(Equal, "DriverName is '%wZ'\n", &DriverObject->DriverName);
205 ok_eq_tag(KmtGetPoolTag(DriverObject->DriverName.Buffer), ' oI');
207 ok_eq_uint(DriverObject->DriverName.MaximumLength, DriverObject->DriverName.Length);
208 // TODO: show that both string and buffer are constants inside ntos
209 Equal = RtlEqualUnicodeString(DriverObject->HardwareDatabase,
210 &HardwareDatabase,
211 FALSE);
212 ok(Equal, "HardwareDatabase is '%wZ'\n", DriverObject->HardwareDatabase);
213 ok_eq_uint(DriverObject->HardwareDatabase->MaximumLength, DriverObject->HardwareDatabase->Length + sizeof(UNICODE_NULL));
214 ok_eq_uint(DriverObject->HardwareDatabase->Buffer[DriverObject->HardwareDatabase->Length / sizeof(WCHAR)], UNICODE_NULL);
215 ok(DriverObject->DriverInit == DriverEntry,
216 "DriverInit is %p, expected %p\n",
217 (PVOID)DriverObject->DriverInit, (PVOID)DriverEntry);
218 }
219 else if (DriverStatus == DriverStatusIrp)
220 {
221 ok(DriverObject->DeviceObject != NULL, "Expected DeviceObject pointer to non null\n");
223 "Expected Flags to be DRVO_LEGACY_DRIVER | DRVO_INITIALIZED, got %lu\n",
224 DriverObject->Flags);
225 }
226 else if (DriverStatus == DriverStatusUnload)
227 {
228 ok(DriverObject->DeviceObject != NULL, "Expected DeviceObject pointer to non null\n");
230 "Expected Flags to be DRVO_LEGACY_DRIVER | DRVO_INITIALIZED | DRVO_UNLOAD_INVOKED, got %lu\n",
231 DriverObject->Flags);
232 }
233 else
234 ASSERT(FALSE);
235
236 /* Select a routine that was not changed */
237 FirstMajorFunc = DriverObject->MajorFunction[1];
238 ok(FirstMajorFunc != 0, "Expected MajorFunction[1] to be non NULL\n");
239
240 if (!skip(FirstMajorFunc != NULL, "First major function not set!\n"))
241 {
242 for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
243 {
244 if (DriverStatus > 0) CheckThisDispatchRoutine = (i > 3) && (i != 14);
245 else CheckThisDispatchRoutine = TRUE;
246
247 if (CheckThisDispatchRoutine)
248 {
249 ok(DriverObject->MajorFunction[i] == FirstMajorFunc, "Expected MajorFunction[%d] to match %p\n",
250 i, FirstMajorFunc);
251 }
252 }
253 }
254}
#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:116
#define ok_eq_ulong(value, expected)
Definition: apitest.h:120
#define ok_eq_tag(value, expected)
Definition: apitest.h:142
#define GetNTVersion()
Definition: apitest.h:17
#define ok_eq_uint(value, expected)
Definition: apitest.h:118
#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 _WIN32_WINNT_WS03
Definition: sdkddkver.h:23
#define _WIN32_WINNT_WIN7
Definition: sdkddkver.h:28
#define UL
Definition: tui.h:164
#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:2227
#define DRVO_INITIALIZED
Definition: iotypes.h:4473
#define DRVO_LEGACY_DRIVER
Definition: iotypes.h:2228
#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:329
#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:3281
_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 317 of file IoDeviceObject_drv.c.

319{
320 PDEVICE_OBJECT RetObject;
321
323
324 ok(RetObject == AttachDeviceObject,
325 "Expected an Attached DeviceObject %p, got %p\n", AttachDeviceObject, RetObject);
326
327 if (RetObject)
328 {
329 ObDereferenceObject(RetObject);
330 }
331
333 ok(RetObject == AttachDeviceObject,
334 "Expected an Attached DeviceObject %p, got %p\n", AttachDeviceObject, RetObject);
335
336 if (RetObject)
337 {
338 ObDereferenceObject(RetObject);
339 }
340
341}
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 258 of file IoDeviceObject_drv.c.

262{
263 UNICODE_STRING RegPath;
265
266 /* Try to load ourself */
268 ok (Status == STATUS_IMAGE_ALREADY_LOADED, "Expected NTSTATUS STATUS_IMAGE_ALREADY_LOADED, got 0x%lX\n", Status);
269
271 {
272 DbgPrint("WARNING: Loading this a second time will cause BUGCHECK!\n");
273 }
274
275 /* Try to load with a Registry Path that doesnt exist */
276 RtlInitUnicodeString(&RegPath, L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\deadbeef");
277 Status = ZwLoadDriver(&RegPath);
278 ok (Status == STATUS_OBJECT_NAME_NOT_FOUND, "Expected NTSTATUS STATUS_OBJECT_NAME_NOT_FOUND, got 0x%lX\n", Status);
279
280 /* Load the driver */
281 RtlInitUnicodeString(&RegPath, NewDriverRegPath);
282 Status = ZwLoadDriver(&RegPath);
283 ok(Status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got 0x%lX\n", Status);
284
285 return NT_SUCCESS(Status);
286}
#define DbgPrint
Definition: hal.h:12
UNICODE_STRING DriverRegistryPath
Definition: inport.c:17
#define STATUS_IMAGE_ALREADY_LOADED
Definition: ntstatus.h:600
#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 290 of file IoDeviceObject_drv.c.

294{
295 UNICODE_STRING RegPath;
297
298 /* Try to unload ourself, which should fail as our Unload routine hasnt been set yet. */
300 ok (Status == STATUS_INVALID_DEVICE_REQUEST, "Expected NTSTATUS STATUS_INVALID_DEVICE_REQUEST, got 0x%lX\n", Status);
301
302 /* Try to unload with a Registry Path that doesnt exist */
303 RtlInitUnicodeString(&RegPath, L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\deadbeef");
304 Status = ZwUnloadDriver(&RegPath);
305 ok (Status == STATUS_OBJECT_NAME_NOT_FOUND, "Expected NTSTATUS STATUS_OBJECT_NAME_NOT_FOUND, got 0x%lX\n", Status);
306
307 /* Unload the driver */
308 RtlInitUnicodeString(&RegPath, NewDriverRegPath);
309 Status = ZwUnloadDriver(&RegPath);
310 ok(Status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got 0x%lX\n", Status);
311
312 return NT_SUCCESS(Status);
313}
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().