ReactOS  0.4.14-dev-833-g5f692ed
IoDeviceInterface.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS kernel-mode tests
3  * LICENSE: LGPLv2+ - See COPYING.LIB in the top level directory
4  * PURPOSE: Kernel-Mode Test Suite Device Interface functions test
5  * PROGRAMMER: Filip Navara <xnavara@volny.cz>
6  */
7 
8 /* TODO: what's with the prototypes at the top, what's with the if-ed out part? Doesn't process most results */
9 
10 #include <kmt_test.h>
11 #include <poclass.h>
12 
13 #define NDEBUG
14 #include <debug.h>
15 
16 #if 0
18 (NTAPI *IoGetDeviceInterfaces_Func)(
21  IN ULONG Flags,
23 
25 ReactOS_IoGetDeviceInterfaces(
28  IN ULONG Flags,
30 #endif /* 0 */
31 
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 }
88 
89 static
90 VOID
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 }
124 
126 
127 static DRIVER_NOTIFICATION_CALLBACK_ROUTINE NotificationCallback;
128 static
129 NTSTATUS
130 NTAPI
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 }
161 
162 static
163 VOID
165 {
168 
171  (PVOID)&GUID_DEVICE_SYS_BUTTON,
172  KmtDriverObject,
177  if (!skip(NT_SUCCESS(Status), "PlugPlayNotification not registered\n"))
178  {
181  }
182 }
183 
184 static
185 VOID
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);
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);
235 
236  RtlInitUnicodeString(&SymbolicLinkName, L"\\\\?\\X{aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa}");
237  KmtStartSeh()
238  Status = IoSetDeviceInterfaceState(&SymbolicLinkName, TRUE);
241 
242  RtlInitUnicodeString(&SymbolicLinkName, L"\\??\\X{aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa}\\");
243  KmtStartSeh()
244  Status = IoSetDeviceInterfaceState(&SymbolicLinkName, TRUE);
247 
248  RtlInitUnicodeString(&SymbolicLinkName, L"\\??\\#{aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa}");
249  KmtStartSeh()
250  Status = IoSetDeviceInterfaceState(&SymbolicLinkName, TRUE);
253 
254  /* Must not read past the buffer */
255  RtlInitUnicodeString(&SymbolicLinkName, L"\\??\\#{aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa}");
256  BufferSize = SymbolicLinkName.Length;
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);
268  }
269 
270  RtlInitUnicodeString(&SymbolicLinkName, L"\\??\\#aaaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa}");
271  BufferSize = SymbolicLinkName.Length;
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);
283  }
284 }
285 
286 START_TEST(IoDeviceInterface)
287 {
288  // FIXME: This test crashes in Windows
292 }
BOOLEAN BOOLEAN VOID VOID BOOLEAN BOOLEAN PVOID KmtAllocateGuarded(SIZE_T SizeRequested)
_In_ PVOID NotificationStructure
Definition: iofuncs.h:1203
NTSTATUS NTAPI IoUnregisterPlugPlayNotification(IN PVOID NotificationEntry)
Definition: pnpnotify.c:371
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_In_opt_ PDEVICE_OBJECT _In_ ULONG _Outptr_result_nullonfailure_ _At_ * SymbolicLinkList(return==0, __drv_allocatesMem(Mem))) PZZWSTR *SymbolicLinkList
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
uint16_t * PWSTR
Definition: typedefs.h:54
#define ok_eq_pointer(value, expected)
LONG NTSTATUS
Definition: precomp.h:26
#define KmtEndSeh(ExpectedStatus)
Definition: kmt_test.h:283
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
NTSTATUS NTAPI IoGetDeviceInterfaces(IN CONST GUID *InterfaceClassGuid, IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL, IN ULONG Flags, OUT PWSTR *SymbolicLinkList)
Definition: deviface.c:454
static DRIVER_NOTIFICATION_CALLBACK_ROUTINE NotificationCallback
#define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES
Definition: iotypes.h:1196
uint16_t * PWCHAR
Definition: typedefs.h:54
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1122
static VOID DeviceInterfaceTest_Func()
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
_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
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
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
Definition: bufpool.h:45
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1311
START_TEST(IoDeviceInterface)
struct _DEVICE_NODE * DeviceNode
Definition: iotypes.h:919
static VOID Test_IoRegisterDeviceInterface(VOID)
_In_ HANDLE Handle
Definition: extypes.h:390
#define trace
Definition: atltest.h:70
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define BufferSize
Definition: classpnp.h:419
Definition: Node.h:9
unsigned char UCHAR
Definition: xmlstorage.h:181
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3376
static const WCHAR L[]
Definition: oid.c:1250
#define NTSTATUS
Definition: precomp.h:20
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 GENERIC_READ
Definition: compat.h:124
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define KmtStartSeh()
Definition: kmt_test.h:277
Status
Definition: gdiplustypes.h:24
#define _In_
Definition: no_sal2.h:204
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
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 STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
#define ok(value,...)
Definition: atltest.h:57
#define OPTIONAL
Definition: typedefs.h:40
_In_ CONST GUID * InterfaceClassGuid
Definition: iofuncs.h:1134
struct _DEVOBJ_EXTENSION * PDEVOBJ_EXTENSION
#define DPRINT1
Definition: precomp.h:8
#define skip(...)
Definition: atltest.h:64
#define OUT
Definition: typedefs.h:39
static VOID Test_IoRegisterPlugPlayNotification(VOID)
unsigned int ULONG
Definition: retypes.h:1
VOID KmtFreeGuarded(PVOID Pointer)
static VOID Test_IoSetDeviceInterface(VOID)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
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
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define CONST
Definition: pedump.c:81
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
NTSYSAPI NTSTATUS NTAPI ZwOpenSymbolicLinkObject(_Out_ PHANDLE SymbolicLinkHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
static const WCHAR SymbolicLink[]
Definition: interface.c:31
#define _Inout_opt_
Definition: no_sal2.h:258
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68