ReactOS 0.4.15-dev-7924-g5949c20
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);
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}
#define ok(value,...)
Definition: atltest.h:57
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const WCHAR SymbolicLink[]
Definition: interface.c:31
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
Status
Definition: gdiplustypes.h:25
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
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
#define DPRINT
Definition: sndvol32.h:71
uint16_t * PWSTR
Definition: typedefs.h:56
_Must_inspect_result_ _In_ WDFOBJECT _In_ CONST GUID * Guid
Definition: wdfobject.h:762
_In_opt_ PDEVICE_OBJECT _In_ ULONG _Outptr_result_nullonfailure_ _At_ * SymbolicLinkList(return==0, __drv_allocatesMem(Mem))) PZZWSTR *SymbolicLinkList

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{
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}
static UCHAR NotificationContext
#define ok_eq_pointer(value, expected)
Definition: apitest.h:59
#define ok_eq_hex(value, expected)
Definition: apitest.h:77
#define ok_eq_uint(value, expected)
Definition: apitest.h:61
#define trace
Definition: atltest.h:70
#define skip(...)
Definition: atltest.h:64
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define GENERIC_READ
Definition: compat.h:135
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
ULONG Handle
Definition: gdb_input.c:15
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define KernelMode
Definition: asm.h:34
NTSYSAPI NTSTATUS NTAPI ZwOpenSymbolicLinkObject(_Out_ PHANDLE SymbolicLinkHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3379
#define STATUS_SUCCESS
Definition: shellext.h:65
_In_ PWDFDEVICE_INIT _In_ PFN_WDF_DEVICE_SHUTDOWN_NOTIFICATION Notification
Definition: wdfcontrol.h:115
_In_ PVOID NotificationStructure
Definition: iofuncs.h:1206

◆ START_TEST()

START_TEST ( IoDeviceInterface  )

Definition at line 286 of file IoDeviceInterface.c.

287{
288 // FIXME: This test crashes in Windows
292}
static VOID Test_IoRegisterPlugPlayNotification(VOID)
static VOID Test_IoRegisterDeviceInterface(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;
99
101
102 // Prepare our surrogate of a Device Object
103 DeviceObject.DeviceObjectExtension = (PDEVOBJ_EXTENSION)&DeviceObjectExtension;
104
105 // 1. DeviceNode = NULL
106 DeviceObjectExtension.DeviceNode = NULL;
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;
118
120 "IoRegisterDeviceInterface returned 0x%08lX\n", Status);
121
123}
static VOID DeviceInterfaceTest_Func()
@ DeviceNode
Definition: Node.h:9
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 L(x)
Definition: ntvdm.h:50
struct _DEVICE_NODE * DeviceNode
Definition: iotypes.h:972
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING SymbolicLinkName
Definition: wdfdevice.h:3739
struct _DEVOBJ_EXTENSION * PDEVOBJ_EXTENSION

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}
static DRIVER_NOTIFICATION_CALLBACK_ROUTINE NotificationCallback
NTSTATUS NTAPI IoRegisterPlugPlayNotification(_In_ IO_NOTIFICATION_EVENT_CATEGORY EventCategory, _In_ ULONG EventCategoryFlags, _In_opt_ PVOID EventCategoryData, _In_ PDRIVER_OBJECT DriverObject, _In_ PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine, _Inout_opt_ PVOID Context, _Out_ PVOID *NotificationEntry)
Definition: pnpnotify.c:345
NTSTATUS NTAPI IoUnregisterPlugPlayNotification(_In_ PVOID NotificationEntry)
Definition: pnpnotify.c:479
_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
@ EventCategoryDeviceInterfaceChange
Definition: iotypes.h:1226
#define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES
Definition: iotypes.h:1239

Referenced by START_TEST().

◆ Test_IoSetDeviceInterface()

static VOID Test_IoSetDeviceInterface ( VOID  )
static

Definition at line 186 of file IoDeviceInterface.c.

187{
192
193 /* Invalid prefix or GUID */
198
199 RtlInitEmptyUnicodeString(&SymbolicLinkName, NULL, 0);
204
210
216
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}
Definition: bufpool.h:45
#define BufferSize
Definition: mmc.h:75
#define TRUE
Definition: types.h:120
#define KmtStartSeh()
Definition: kmt_test.h:282
#define KmtEndSeh(ExpectedStatus)
Definition: kmt_test.h:288
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1311
@ Failed
Definition: arc.h:79
uint16_t * PWCHAR
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135

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