ReactOS  0.4.15-dev-1171-gab82533
IoDeviceInterface.c File Reference
#include <kmt_test.h>
#include <poclass.h>
#include <debug.h>
Include dependency graph for IoDeviceInterface.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

static VOID DeviceInterfaceTest_Func ()
 
static VOID Test_IoRegisterDeviceInterface (VOID)
 
static NTSTATUS NTAPI NotificationCallback (_In_ PVOID NotificationStructure, _Inout_opt_ PVOID Context)
 
static VOID Test_IoRegisterPlugPlayNotification (VOID)
 
static VOID Test_IoSetDeviceInterface (VOID)
 
 START_TEST (IoDeviceInterface)
 

Variables

static UCHAR NotificationContext
 
static DRIVER_NOTIFICATION_CALLBACK_ROUTINE NotificationCallback
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file IoDeviceInterface.c.

Function Documentation

◆ DeviceInterfaceTest_Func()

static VOID DeviceInterfaceTest_Func ( )
static

Definition at line 32 of file IoDeviceInterface.c.

33 {
36  PWSTR SymbolicLinkListPtr;
37  GUID Guid = {0x378de44c, 0x56ef, 0x11d1, {0xbc, 0x8c, 0x00, 0xa0, 0xc9, 0x14, 0x05, 0xdd}};
38 
40  &Guid,
41  NULL,
42  0,
44 
46  "IoGetDeviceInterfaces failed with status 0x%X\n",
47  (unsigned int)Status);
48  if (!NT_SUCCESS(Status))
49  {
50  return;
51  }
52 
53  DPRINT("IoGetDeviceInterfaces results:\n");
54  for (SymbolicLinkListPtr = SymbolicLinkList;
55  SymbolicLinkListPtr[0] != 0 && SymbolicLinkListPtr[1] != 0;
56  SymbolicLinkListPtr += wcslen(SymbolicLinkListPtr) + 1)
57  {
58  DPRINT1("Symbolic Link: %S\n", SymbolicLinkListPtr);
59  }
60 
61 #if 0
62  DPRINT("[PnP Test] Trying to get aliases\n");
63 
64  for (SymbolicLinkListPtr = SymbolicLinkList;
65  SymbolicLinkListPtr[0] != 0 && SymbolicLinkListPtr[1] != 0;
66  SymbolicLinkListPtr += wcslen(SymbolicLinkListPtr) + 1)
67  {
69  UNICODE_STRING AliasSymbolicLink;
70 
71  SymbolicLink.Buffer = SymbolicLinkListPtr;
72  SymbolicLink.Length = SymbolicLink.MaximumLength = wcslen(SymbolicLinkListPtr);
73  RtlInitUnicodeString(&AliasSymbolicLink, NULL);
75  &SymbolicLink,
76  &AliasGuid,
77  &AliasSymbolicLink);
78  if (AliasSymbolicLink.Buffer != NULL)
79  {
80  DPRINT("[PnP Test] Original: %S\n", SymbolicLinkListPtr);
81  DPRINT("[PnP Test] Alias: %S\n", AliasSymbolicLink.Buffer);
82  }
83  }
84 #endif
85 
87 }
_In_opt_ PDEVICE_OBJECT _In_ ULONG _Outptr_result_nullonfailure_ _At_ * SymbolicLinkList(return==0, __drv_allocatesMem(Mem))) PZZWSTR *SymbolicLinkList
uint16_t * PWSTR
Definition: typedefs.h:56
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI IoGetDeviceInterfaces(IN CONST GUID *InterfaceClassGuid, IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL, IN ULONG Flags, OUT PWSTR *SymbolicLinkList)
Definition: deviface.c:454
NTSTATUS NTAPI IoGetDeviceInterfaceAlias(IN PUNICODE_STRING SymbolicLinkName, IN CONST GUID *AliasInterfaceClassGuid, OUT PUNICODE_STRING AliasSymbolicLinkName)
Definition: deviface.c:303
static GUID * Guid
Definition: apphelp.c:93
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
#define ok(value,...)
Definition: atltest.h:57
#define DPRINT1
Definition: precomp.h:8
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
static const WCHAR SymbolicLink[]
Definition: interface.c:31

Referenced by Test_IoRegisterDeviceInterface().

◆ NotificationCallback()

static NTSTATUS NTAPI NotificationCallback ( _In_ PVOID  NotificationStructure,
_Inout_opt_ PVOID  Context 
)
static

Definition at line 131 of file IoDeviceInterface.c.

134 {
138  HANDLE Handle;
139 
140  ok_irql(PASSIVE_LEVEL);
142  ok_eq_uint(Notification->Version, 1);
143  ok_eq_uint(Notification->Size, sizeof(*Notification));
144 
145  /* symbolic link must exist */
146  trace("Interface change: %wZ\n", Notification->SymbolicLinkName);
148  Notification->SymbolicLinkName,
150  NULL,
151  NULL);
154  if (!skip(NT_SUCCESS(Status), "No symbolic link\n"))
155  {
158  }
159  return STATUS_SUCCESS;
160 }
_In_ PVOID NotificationStructure
Definition: iofuncs.h:1203
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define ok_eq_pointer(value, expected)
LONG NTSTATUS
Definition: precomp.h:26
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
smooth NULL
Definition: ftsmooth.c:416
_In_ HANDLE Handle
Definition: extypes.h:390
#define trace
Definition: atltest.h:70
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3376
Status
Definition: gdiplustypes.h:24
#define GENERIC_READ
Definition: compat.h:135
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define skip(...)
Definition: atltest.h:64
static UCHAR NotificationContext
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define ok_eq_hex(value, expected)
#define ok_eq_uint(value, expected)
Definition: kmt_test.h:239
return STATUS_SUCCESS
Definition: btrfs.c:3014
NTSYSAPI NTSTATUS NTAPI ZwOpenSymbolicLinkObject(_Out_ PHANDLE SymbolicLinkHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)

◆ START_TEST()

START_TEST ( IoDeviceInterface  )

Definition at line 286 of file IoDeviceInterface.c.

287 {
288  // FIXME: This test crashes in Windows
292 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
static VOID Test_IoRegisterDeviceInterface(VOID)
static VOID Test_IoRegisterPlugPlayNotification(VOID)
static VOID Test_IoSetDeviceInterface(VOID)

◆ Test_IoRegisterDeviceInterface()

static VOID Test_IoRegisterDeviceInterface ( VOID  )
static

Definition at line 91 of file IoDeviceInterface.c.

92 {
93  GUID Guid = {0x378de44c, 0x56ef, 0x11d1, {0xbc, 0x8c, 0x00, 0xa0, 0xc9, 0x14, 0x05, 0xdd}};
95  EXTENDED_DEVOBJ_EXTENSION DeviceObjectExtension;
97  UNICODE_STRING SymbolicLinkName;
99 
100  RtlInitUnicodeString(&SymbolicLinkName, L"");
101 
102  // Prepare our surrogate of a Device Object
103  DeviceObject.DeviceObjectExtension = (PDEVOBJ_EXTENSION)&DeviceObjectExtension;
104 
105  // 1. DeviceNode = NULL
106  DeviceObjectExtension.DeviceNode = NULL;
108  &SymbolicLinkName);
109 
111  "IoRegisterDeviceInterface returned 0x%08lX\n", Status);
112 
113  // 2. DeviceNode->InstancePath is of a null length
114  DeviceObjectExtension.DeviceNode = &DeviceNode;
115  DeviceNode.InstancePath.Length = 0;
117  &SymbolicLinkName);
118 
120  "IoRegisterDeviceInterface returned 0x%08lX\n", Status);
121 
123 }
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
static VOID DeviceInterfaceTest_Func()
static GUID * Guid
Definition: apphelp.c:93
smooth NULL
Definition: ftsmooth.c:416
struct _DEVICE_NODE * DeviceNode
Definition: iotypes.h:919
Definition: Node.h:9
Status
Definition: gdiplustypes.h:24
static const WCHAR L[]
Definition: oid.c:1250
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
Definition: deviface.c:955
#define ok(value,...)
Definition: atltest.h:57
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
struct _DEVOBJ_EXTENSION * PDEVOBJ_EXTENSION
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)

Referenced by START_TEST().

◆ Test_IoRegisterPlugPlayNotification()

static VOID Test_IoRegisterPlugPlayNotification ( VOID  )
static

Definition at line 164 of file IoDeviceInterface.c.

165 {
168 
171  (PVOID)&GUID_DEVICE_SYS_BUTTON,
172  KmtDriverObject,
177  if (!skip(NT_SUCCESS(Status), "PlugPlayNotification not registered\n"))
178  {
181  }
182 }
NTSTATUS NTAPI IoUnregisterPlugPlayNotification(IN PVOID NotificationEntry)
Definition: pnpnotify.c:371
LONG NTSTATUS
Definition: precomp.h:26
static DRIVER_NOTIFICATION_CALLBACK_ROUTINE NotificationCallback
#define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES
Definition: iotypes.h:1219
_In_ ULONG _In_opt_ PVOID _In_ PDRIVER_OBJECT _In_ PDRIVER_NOTIFICATION_CALLBACK_ROUTINE _Inout_opt_ __drv_aliasesMem PVOID _Outptr_result_nullonfailure_ _At_ * NotificationEntry(return==0, __drv_allocatesMem(Mem))) PVOID *NotificationEntry
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI IoRegisterPlugPlayNotification(IN IO_NOTIFICATION_EVENT_CATEGORY EventCategory, IN ULONG EventCategoryFlags, IN PVOID EventCategoryData OPTIONAL, IN PDRIVER_OBJECT DriverObject, IN PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine, IN PVOID Context, OUT PVOID *NotificationEntry)
Definition: pnpnotify.c:249
#define skip(...)
Definition: atltest.h:64
static UCHAR NotificationContext
#define ok_eq_hex(value, expected)
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by START_TEST().

◆ Test_IoSetDeviceInterface()

static VOID Test_IoSetDeviceInterface ( VOID  )
static

Definition at line 186 of file IoDeviceInterface.c.

187 {
189  UNICODE_STRING SymbolicLinkName;
190  PWCHAR Buffer;
192 
193  /* Invalid prefix or GUID */
194  KmtStartSeh()
198 
199  RtlInitEmptyUnicodeString(&SymbolicLinkName, NULL, 0);
200  KmtStartSeh()
201  Status = IoSetDeviceInterfaceState(&SymbolicLinkName, TRUE);
204 
205  RtlInitUnicodeString(&SymbolicLinkName, L"\\??");
206  KmtStartSeh()
207  Status = IoSetDeviceInterfaceState(&SymbolicLinkName, TRUE);
210 
211  RtlInitUnicodeString(&SymbolicLinkName, L"\\??\\");
212  KmtStartSeh()
213  Status = IoSetDeviceInterfaceState(&SymbolicLinkName, TRUE);
216 
217  RtlInitUnicodeString(&SymbolicLinkName, L"\\??\\\\");
218  KmtStartSeh()
219  Status = IoSetDeviceInterfaceState(&SymbolicLinkName, TRUE);
222 
223  RtlInitUnicodeString(&SymbolicLinkName, L"\\??\\{aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa}");
224  KmtStartSeh()
225  Status = IoSetDeviceInterfaceState(&SymbolicLinkName, TRUE);
226  KmtEndSeh(STATUS_SUCCESS)
227  ok_eq_hex(Status, STATUS_INVALID_PARAMETER);
228 
229  /* Valid prefix & GUID, invalid device node */
230  RtlInitUnicodeString(&SymbolicLinkName, L"\\??\\X{aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa}");
231  KmtStartSeh()
232  Status = IoSetDeviceInterfaceState(&SymbolicLinkName, TRUE);
233  KmtEndSeh(STATUS_SUCCESS)
234  ok_eq_hex(Status, STATUS_OBJECT_NAME_NOT_FOUND);
235 
236  RtlInitUnicodeString(&SymbolicLinkName, L"\\\\?\\X{aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa}");
237  KmtStartSeh()
238  Status = IoSetDeviceInterfaceState(&SymbolicLinkName, TRUE);
239  KmtEndSeh(STATUS_SUCCESS)
240  ok_eq_hex(Status, STATUS_OBJECT_NAME_NOT_FOUND);
241 
242  RtlInitUnicodeString(&SymbolicLinkName, L"\\??\\X{aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa}\\");
243  KmtStartSeh()
244  Status = IoSetDeviceInterfaceState(&SymbolicLinkName, TRUE);
245  KmtEndSeh(STATUS_SUCCESS)
246  ok_eq_hex(Status, STATUS_OBJECT_NAME_NOT_FOUND);
247 
248  RtlInitUnicodeString(&SymbolicLinkName, L"\\??\\#{aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa}");
249  KmtStartSeh()
250  Status = IoSetDeviceInterfaceState(&SymbolicLinkName, TRUE);
251  KmtEndSeh(STATUS_SUCCESS)
252  ok_eq_hex(Status, STATUS_OBJECT_NAME_NOT_FOUND);
253 
254  /* Must not read past the buffer */
255  RtlInitUnicodeString(&SymbolicLinkName, L"\\??\\#{aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa}");
256  BufferSize = SymbolicLinkName.Length;
257  Buffer = KmtAllocateGuarded(BufferSize);
258  if (!skip(Buffer != NULL, "Failed to allocate %lu bytes\n", BufferSize))
259  {
260  RtlCopyMemory(Buffer, SymbolicLinkName.Buffer, BufferSize);
261  SymbolicLinkName.Buffer = Buffer;
262  SymbolicLinkName.MaximumLength = BufferSize;
263  KmtStartSeh()
264  Status = IoSetDeviceInterfaceState(&SymbolicLinkName, TRUE);
265  KmtEndSeh(STATUS_SUCCESS)
266  ok_eq_hex(Status, STATUS_OBJECT_NAME_NOT_FOUND);
267  KmtFreeGuarded(Buffer);
268  }
269 
270  RtlInitUnicodeString(&SymbolicLinkName, L"\\??\\#aaaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa}");
271  BufferSize = SymbolicLinkName.Length;
272  Buffer = KmtAllocateGuarded(BufferSize);
273  if (!skip(Buffer != NULL, "Failed to allocate %lu bytes\n", BufferSize))
274  {
275  RtlCopyMemory(Buffer, SymbolicLinkName.Buffer, BufferSize);
276  SymbolicLinkName.Buffer = Buffer;
277  SymbolicLinkName.MaximumLength = BufferSize;
278  KmtStartSeh()
279  Status = IoSetDeviceInterfaceState(&SymbolicLinkName, TRUE);
280  KmtEndSeh(STATUS_SUCCESS)
281  ok_eq_hex(Status, STATUS_INVALID_PARAMETER);
282  KmtFreeGuarded(Buffer);
283  }
284 }
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
#define KmtEndSeh(ExpectedStatus)
Definition: kmt_test.h:283
GLdouble n
Definition: glext.h:7729
uint16_t * PWCHAR
Definition: typedefs.h:56
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1311
Definition: arc.h:79
#define BufferSize
Definition: mmc.h:75
Status
Definition: gdiplustypes.h:24
static const WCHAR L[]
Definition: oid.c:1250
#define KmtStartSeh()
Definition: kmt_test.h:277
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define ok_eq_hex(value, expected)
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define X(b, s)

Referenced by START_TEST().

Variable Documentation

◆ NotificationCallback

DRIVER_NOTIFICATION_CALLBACK_ROUTINE NotificationCallback
static

Definition at line 127 of file IoDeviceInterface.c.

Referenced by Test_IoRegisterPlugPlayNotification().

◆ NotificationContext

UCHAR NotificationContext
static