ReactOS 0.4.15-dev-7942-gd23573b
ObReference.c File Reference
#include <kmt_test.h>
#include <debug.h>
Include dependency graph for ObReference.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define CheckObject(Handle, Pointers, Handles)
 

Functions

static VOID TestReference (IN HANDLE Handle, IN PUNICODE_STRING Name OPTIONAL, IN PUNICODE_STRING NameUpper OPTIONAL, IN BOOLEAN CaseSensitive, IN ULONG AdditionalReferences, IN BOOLEAN Permanent)
 
 START_TEST (ObReference)
 

Variables

static POBJECT_TYPE ObDirectoryObjectType
 

Macro Definition Documentation

◆ CheckObject

#define CheckObject (   Handle,
  Pointers,
  Handles 
)
Value:
do \
{ \
Status = ZwQueryObject(Handle, ObjectBasicInformation, \
&ObjectInfo, sizeof ObjectInfo, NULL); \
ok_eq_hex(Status, STATUS_SUCCESS); \
ok_eq_ulong(ObjectInfo.PointerCount, Pointers); \
ok_eq_ulong(ObjectInfo.HandleCount, Handles); \
} while (0)
@ ObjectBasicInformation
Definition: DriverTester.h:54
#define NULL
Definition: types.h:112
ULONG Handle
Definition: gdb_input.c:15
Status
Definition: gdiplustypes.h:25
#define STATUS_SUCCESS
Definition: shellext.h:65

Definition at line 12 of file ObReference.c.

◆ NDEBUG

#define NDEBUG

Definition at line 9 of file ObReference.c.

Function Documentation

◆ START_TEST()

START_TEST ( ObReference  )

Definition at line 142 of file ObReference.c.

143{
148 UNICODE_STRING NameUpper, *pNameUpper;
149 ULONG i;
150 struct
151 {
152 PWSTR Name;
153 ULONG Flags;
154 ULONG AdditionalReferences;
155 } Tests[] =
156 {
157 { NULL, 0, 0 },
159 { NULL, OBJ_KERNEL_HANDLE, 0 },
160 { NULL, OBJ_PERMANENT, 0 },
165 { L"\\YayDirectory0", 0, 1 },
166 { L"\\YayDirectory1", OBJ_CASE_INSENSITIVE, 1 },
167 { L"\\YayDirectory2", OBJ_KERNEL_HANDLE, 1 },
168 { L"\\YayDirectory3", OBJ_PERMANENT, 1 },
169 { L"\\YayDirectory4", OBJ_CASE_INSENSITIVE | OBJ_PERMANENT, 1 },
170 { L"\\YayDirectory5", OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, 1 },
171 { L"\\YayDirectory6", OBJ_KERNEL_HANDLE | OBJ_PERMANENT, 1 },
172 { L"\\YayDirectory7", OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE | OBJ_PERMANENT, 1 },
173 };
174 HANDLE ObjectTypeHandle;
175
176 /* ObReferenceObjectByName needs the object type... so get it... */
177 RtlInitUnicodeString(&Name, L"\\ObjectTypes\\Directory");
179 Status = ObOpenObjectByName(&ObjectAttributes, NULL, KernelMode, NULL, 0, NULL, &ObjectTypeHandle);
181 ok(ObjectTypeHandle != NULL, "ObjectTypeHandle = NULL\n");
182 if (!skip(Status == STATUS_SUCCESS && ObjectTypeHandle, "No handle\n"))
183 {
186 ok(ObDirectoryObjectType != NULL, "ObDirectoryObjectType = NULL\n");
187 Status = ZwClose(ObjectTypeHandle);
189 }
190
191 for (i = 0; i < sizeof Tests / sizeof Tests[0]; ++i)
192 {
193 DPRINT("Run %d\n", i);
194 if (Tests[i].Name)
195 {
197 pName = &Name;
198 Status = RtlUpcaseUnicodeString(&NameUpper, &Name, TRUE);
200 if (skip(Status == STATUS_SUCCESS, "No upper case name\n"))
201 pNameUpper = NULL;
202 else
203 pNameUpper = &NameUpper;
204 }
205 else
206 {
207 pName = NULL;
208 pNameUpper = NULL;
209 }
213 ok(DirectoryHandle != NULL, "DirectoryHandle = NULL\n");
214
215 if (!skip(Status == STATUS_SUCCESS && DirectoryHandle, "Cannot proceed without an object\n"))
216 {
217 TestReference(DirectoryHandle, pName, pNameUpper, FALSE, Tests[i].AdditionalReferences, (Tests[i].Flags & OBJ_PERMANENT) != 0);
218 /* try again for good measure */
219 TestReference(DirectoryHandle, pName, pNameUpper, FALSE, Tests[i].AdditionalReferences, FALSE);
220
224 }
225
226 if (pNameUpper)
227 RtlFreeUnicodeString(pNameUpper);
228 }
229
230 if (DirectoryHandle)
231 {
234 }
235
236 /* parameter tests */
237 /* bugcheck at APC_LEVEL
238 Status = ObReferenceObject(NULL);
239 Status = ObReferenceObjectByPointer(NULL, 0, NULL, UserMode);
240 Status = ObReferenceObjectByPointer(NULL, 0, NULL, KernelMode);*/
241
243 {
246 }
247}
static VOID TestReference(IN HANDLE Handle, IN PUNICODE_STRING Name OPTIONAL, IN PUNICODE_STRING NameUpper OPTIONAL, IN BOOLEAN CaseSensitive, IN ULONG AdditionalReferences, IN BOOLEAN Permanent)
Definition: ObReference.c:26
static POBJECT_TYPE ObDirectoryObjectType
Definition: ObReference.c:22
static HANDLE DirectoryHandle
Definition: ObType.c:48
struct test_data Tests[]
struct NameRec_ * Name
Definition: cdprocs.h:460
#define ok_eq_hex(value, expected)
Definition: apitest.h:77
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
LONG NTSTATUS
Definition: precomp.h:26
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
NTSTATUS RtlUpcaseUnicodeString(PUNICODE_STRING dst, PUNICODE_STRING src, BOOLEAN Alloc)
Definition: string_lib.cpp:46
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
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define OBJ_PERMANENT
Definition: winternl.h:226
static LPSTR pName
Definition: security.c:75
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define KernelMode
Definition: asm.h:34
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSYSAPI NTSTATUS NTAPI ZwCreateDirectoryObject(_Out_ PHANDLE DirectoryHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define DIRECTORY_ALL_ACCESS
Definition: nt_native.h:1259
#define L(x)
Definition: ntvdm.h:50
NTSTATUS NTAPI ObOpenObjectByName(IN POBJECT_ATTRIBUTES ObjectAttributes, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN OUT PVOID ParseContext, OUT PHANDLE Handle)
Definition: obhandle.c:2532
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:494
#define DPRINT
Definition: sndvol32.h:71
uint16_t * PWSTR
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define ObDereferenceObject
Definition: obfuncs.h:203

◆ TestReference()

static VOID TestReference ( IN HANDLE  Handle,
IN PUNICODE_STRING Name  OPTIONAL,
IN PUNICODE_STRING NameUpper  OPTIONAL,
IN BOOLEAN  CaseSensitive,
IN ULONG  AdditionalReferences,
IN BOOLEAN  Permanent 
)
static

Definition at line 26 of file ObReference.c.

33{
35 LONG_PTR Ret;
37 PVOID Object2 = NULL;
38 PVOID Object3 = NULL;
39 PVOID Object4 = NULL;
40
41 CheckObject(Handle, 2LU + AdditionalReferences, 1LU);
42
45 ok(Object != NULL, "ObReferenceObjectByHandle returned NULL object\n");
46 CheckObject(Handle, 3LU + AdditionalReferences, 1LU);
47
50 ok(Object != NULL, "ObReferenceObjectByHandle returned NULL object\n");
51 ok_eq_pointer(Object, Object2);
52 CheckObject(Handle, 4LU + AdditionalReferences, 1LU);
53
54 if (!skip(Object != NULL, "No object to reference!\n"))
55 {
57 ok_eq_longptr(Ret, (LONG_PTR)4 + AdditionalReferences);
58 CheckObject(Handle, 5LU + AdditionalReferences, 1LU);
59
61 ok_eq_longptr(Ret, (LONG_PTR)5 + AdditionalReferences);
62 CheckObject(Handle, 6LU + AdditionalReferences, 1LU);
63
66 CheckObject(Handle, 7LU + AdditionalReferences, 1LU);
67
70 CheckObject(Handle, 8LU + AdditionalReferences, 1LU);
71
73 ok_eq_longptr(Ret, (LONG_PTR)6 + AdditionalReferences);
74 CheckObject(Handle, 7LU + AdditionalReferences, 1LU);
75
77 ok_eq_longptr(Ret, (LONG_PTR)5 + AdditionalReferences);
78 CheckObject(Handle, 6LU + AdditionalReferences, 1LU);
79
81 ok_eq_longptr(Ret, (LONG_PTR)4 + AdditionalReferences);
82 CheckObject(Handle, 5LU + AdditionalReferences, 1LU);
83
85 ok_eq_longptr(Ret, (LONG_PTR)3 + AdditionalReferences);
86 CheckObject(Handle, 4LU + AdditionalReferences, 1LU);
87 }
88
89 if (Name && !skip(ObDirectoryObjectType != NULL, "No directory object type\n"))
90 {
93 CheckObject(Handle, 5LU + AdditionalReferences, 1LU);
94 }
95
96 if (NameUpper && !skip(ObDirectoryObjectType != NULL, "No directory object type\n"))
97 {
100 CheckObject(Handle, 5LU + AdditionalReferences + !CaseSensitive, 1LU);
101 }
102
103 if (NameUpper && !skip(Object4 != NULL, "No object to dereference\n"))
104 {
105 Ret = ObDereferenceObject(Object4);
106 ok_eq_longptr(Ret, (LONG_PTR)4 + AdditionalReferences);
107 CheckObject(Handle, 5LU + AdditionalReferences, 1LU);
108 }
109 if (Name && !skip(Object3 != NULL, "No object to dereference\n"))
110 {
111 Ret = ObDereferenceObject(Object3);
112 ok_eq_longptr(Ret, (LONG_PTR)3 + AdditionalReferences);
113 CheckObject(Handle, 4LU + AdditionalReferences, 1LU);
114 }
115 if (!skip(Object2 != NULL, "No object to dereference\n"))
116 {
117 Ret = ObDereferenceObject(Object2);
118 ok_eq_longptr(Ret, (LONG_PTR)2 + AdditionalReferences);
119 CheckObject(Handle, 3LU + AdditionalReferences, 1LU);
120 }
121 if (!skip(Object != NULL, "No object to dereference\n"))
122 {
124 ok_eq_longptr(Ret, (LONG_PTR)1 + AdditionalReferences);
125 CheckObject(Handle, 2LU + AdditionalReferences, 1LU);
126 }
127
128 CheckObject(Handle, 2LU + AdditionalReferences, 1LU);
129
130 if (Permanent)
131 {
134 CheckObject(Handle, 2LU + AdditionalReferences, 1LU);
135
138 CheckObject(Handle, 2LU + AdditionalReferences, 1LU);
139 }
140}
#define CheckObject(Handle, Pointers, Handles)
Definition: ObReference.c:12
#define ok_eq_pointer(value, expected)
Definition: apitest.h:59
#define ok_eq_longptr(value, expected)
Definition: apitest.h:70
#define U(x)
Definition: wordpad.c:45
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
NTSYSAPI NTSTATUS NTAPI ZwMakeTemporaryObject(_In_ HANDLE Handle)
NTSTATUS NTAPI ObReferenceObjectByName(IN PUNICODE_STRING ObjectPath, IN ULONG Attributes, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, IN OUT PVOID ParseContext, OUT PVOID *ObjectPtr)
Definition: obref.c:409
NTSTATUS NTAPI ObReferenceObjectByPointer(IN PVOID Object, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode)
Definition: obref.c:381
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
#define ObReferenceObject
Definition: obfuncs.h:204

Referenced by START_TEST().

Variable Documentation

◆ ObDirectoryObjectType

POBJECT_TYPE ObDirectoryObjectType
static

Definition at line 22 of file ObReference.c.

Referenced by START_TEST(), and TestReference().