2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Kernel-Mode Test Suite Object types test
5 * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
20 OBJECT_ATTRIBUTES ObjectAttributes
;
22 PVOID ObjectType
= NULL
;
24 RtlInitUnicodeString(&Name
, TypeName
);
25 InitializeObjectAttributes(&ObjectAttributes
, &Name
, OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
, NULL
, NULL
);
26 Status
= ObOpenObjectByName(&ObjectAttributes
, NULL
, KernelMode
, NULL
, 0, NULL
, &Handle
);
27 ok_eq_hex(Status
, STATUS_SUCCESS
);
28 ok(Handle
!= NULL
, "ObjectTypeHandle = NULL\n");
29 if (!skip(Status
== STATUS_SUCCESS
&& Handle
, "No handle\n"))
31 Status
= ObReferenceObjectByHandle(Handle
, 0, NULL
, KernelMode
, &ObjectType
, NULL
);
32 ok_eq_hex(Status
, STATUS_SUCCESS
);
33 ok(ObjectType
!= NULL
, "ObjectType = NULL\n");
34 Status
= ZwClose(Handle
);
35 ok_eq_hex(Status
, STATUS_SUCCESS
);
40 #define ok_eq_ustr(value, expected) ok(RtlEqualUnicodeString(value, expected, FALSE), #value " = \"%wZ\", expected \"%%wZ\"\n", value, expected)
42 #define CheckObjectType(TypeName, Variable, Flags, InvalidAttr, \
43 ReadMapping, WriteMapping, ExecMapping, AllMapping, \
46 POBJECT_TYPE ObjectType; \
47 UNICODE_STRING Name; \
49 BOOLEAN UseDefault = ((Flags) & OBT_NO_DEFAULT) == 0; \
50 BOOLEAN CustomSecurityProc = ((Flags) & OBT_CUSTOM_SECURITY_PROC) != 0; \
51 BOOLEAN SecurityRequired = ((Flags) & OBT_SECURITY_REQUIRED) != 0; \
52 BOOLEAN CaseInsensitive = ((Flags) & OBT_CASE_INSENSITIVE) != 0; \
53 BOOLEAN MaintainTypeList = ((Flags) & OBT_MAINTAIN_TYPE_LIST) != 0; \
54 BOOLEAN MaintainHandleCount = ((Flags) & OBT_MAINTAIN_HANDLE_COUNT) != 0; \
55 POOL_TYPE PoolType = ((Flags) & OBT_PAGED_POOL) ? PagedPool : NonPagedPool; \
56 BOOLEAN CustomKey = ((Flags) & OBT_CUSTOM_KEY) != 0; \
58 trace(#TypeName "\n"); \
59 ObjectType = GetObjectType(L"\\ObjectTypes\\" L ## #TypeName); \
60 ok(ObjectType != NULL, "ObjectType = NULL\n"); \
61 if (!skip(ObjectType != NULL, "No ObjectType\n")) \
63 ok(!Variable || Variable == ObjectType, \
64 #Variable "is %p, expected %p\n", Variable, ObjectType); \
65 RtlInitUnicodeString(&Name, L ## #TypeName); \
66 ok_eq_ustr(&ObjectType->Name, &Name); \
67 ok_eq_ulong(ObjectType->Index, Index); \
68 Index = ObjectType->Index + 1; \
69 /* apparently, File and WaitablePort are evil and have other stuff \
70 * in DefaultObject. All others are NULL */ \
72 ok_eq_pointer(ObjectType->DefaultObject, ObpDefaultObject); \
73 /*ok(ObjectType->TotalNumberOfObjects >= 1, \
74 "Number of objects = %lu\n", ObjectType->TotalNumberOfObjects); \
75 ok(ObjectType->TotalNumberOfHandles >= ObjectType->TotalNumberOfObjects, \
76 "%lu objects, but %lu handles\n", \
77 ObjectType->TotalNumberOfObjects, ObjectType->TotalNumberOfHandles);*/ \
78 ok(ObjectType->HighWaterNumberOfObjects >= ObjectType->TotalNumberOfObjects,\
79 "%lu objects, but high water %lu\n", \
80 ObjectType->TotalNumberOfObjects, ObjectType->HighWaterNumberOfObjects); \
81 ok(ObjectType->HighWaterNumberOfHandles >= ObjectType->TotalNumberOfHandles,\
82 "%lu handles, but high water %lu\n", \
83 ObjectType->TotalNumberOfHandles, ObjectType->HighWaterNumberOfHandles); \
84 ok_eq_ulong(ObjectType->TypeInfo.Length, sizeof(OBJECT_TYPE_INITIALIZER)); \
85 ok_eq_bool(ObjectType->TypeInfo.UseDefaultObject, UseDefault); \
86 ok_eq_bool(ObjectType->TypeInfo.CaseInsensitive, CaseInsensitive); \
87 ok_eq_hex(ObjectType->TypeInfo.InvalidAttributes, InvalidAttr); \
88 ok_eq_hex(ObjectType->TypeInfo.GenericMapping.GenericRead, ReadMapping); \
89 ok_eq_hex(ObjectType->TypeInfo.GenericMapping.GenericWrite, WriteMapping); \
90 ok_eq_hex(ObjectType->TypeInfo.GenericMapping.GenericExecute, ExecMapping); \
91 ok_eq_hex(ObjectType->TypeInfo.GenericMapping.GenericAll, AllMapping); \
92 ok_eq_hex(ObjectType->TypeInfo.ValidAccessMask, ValidMask); \
93 ok_eq_bool(ObjectType->TypeInfo.SecurityRequired, SecurityRequired); \
94 ok_eq_bool(ObjectType->TypeInfo.MaintainHandleCount, MaintainHandleCount); \
95 ok_eq_bool(ObjectType->TypeInfo.MaintainTypeList, MaintainTypeList); \
96 ok_eq_ulong(ObjectType->TypeInfo.PoolType, PoolType); \
97 /* DefaultPagedPoolCharge */ \
98 /* DefaultNonPagedPoolCharge */ \
100 /* OpenProcedure */ \
101 /* CloseProcedure */ \
102 /* DeleteProcedure */ \
103 /* ParseProcedure */ \
104 if (CustomSecurityProc) \
105 ok(ObjectType->TypeInfo.SecurityProcedure != NULL, \
106 "No Security Proc\n"); \
108 ok_eq_pointer(ObjectType->TypeInfo.SecurityProcedure, \
109 SeDefaultObjectMethod); \
110 /* QueryNameProcedure */ \
111 /* OkayToCloseProcedure */ \
112 Key = *(PULONG)#TypeName; \
113 if (sizeof(#TypeName) <= 4) Key |= ' ' << 24; \
114 if (sizeof(#TypeName) <= 3) Key |= ' ' << 16; \
115 if (sizeof(#TypeName) <= 2) Key |= ' ' << 8; \
117 ok_eq_hex(ObjectType->Key, Key); \
118 ObDereferenceObject(ObjectType); \
122 static POBJECT_TYPE ObpTypeObjectType
;
123 #define ObpDirectoryObjectType NULL
124 #define ObpSymbolicLinkObjectType NULL
125 #define DbgkDebugObjectType NULL
126 #define ExEventPairObjectType NULL
127 #define ExMutantObjectType NULL
128 #define ExCallbackObjectType NULL
129 #define ExTimerObjectType NULL
130 #define ExProfileObjectType NULL
131 #define ExpKeyedEventObjectType NULL
132 #define CmpKeyObjectType NULL
133 #define LpcWaitablePortObjectType NULL
134 #define IoControllerObjectType NULL
135 #define IoCompletionObjectType NULL
136 #define WmipGuidObjectType NULL
138 static POBJECT_TYPE ObpDefaultObject
;
139 static OB_SECURITY_METHOD SeDefaultObjectMethod
;
141 #define OBT_NO_DEFAULT 0x01
142 #define OBT_CUSTOM_SECURITY_PROC 0x02
143 #define OBT_SECURITY_REQUIRED 0x04
144 #define OBT_CASE_INSENSITIVE 0x08
145 #define OBT_MAINTAIN_TYPE_LIST 0x10
146 #define OBT_MAINTAIN_HANDLE_COUNT 0x20
147 #define OBT_PAGED_POOL 0x40
148 #define OBT_CUSTOM_KEY 0x80
150 #define TAG(x) RtlUlongByteSwap(x)
154 TestObjectTypes(VOID
)
158 ObpTypeObjectType
= GetObjectType(L
"\\ObjectTypes\\Type");
159 if (skip(ObpTypeObjectType
!= NULL
, "No Type object type\n"))
162 ObpDefaultObject
= ObpTypeObjectType
->DefaultObject
;
163 ok(ObpDefaultObject
!= NULL
, "No ObpDefaultObject\n");
164 SeDefaultObjectMethod
= ObpTypeObjectType
->TypeInfo
.SecurityProcedure
;
165 ok(SeDefaultObjectMethod
!= NULL
, "No SeDefaultObjectMethod\n");
168 CheckObjectType(Type
, ObpTypeObjectType
, OBT_MAINTAIN_TYPE_LIST
| OBT_CUSTOM_KEY
, 0x100, 0x020000, 0x020000, 0x020000, 0x0f0001, 0x1f0001);
169 ok_eq_hex(ObpTypeObjectType
->Key
, TAG('ObjT'));
170 CheckObjectType(Directory
, ObpDirectoryObjectType
, OBT_CASE_INSENSITIVE
| OBT_PAGED_POOL
, 0x100, 0x020003, 0x02000c, 0x020003, 0x0f000f, 0x0f000f);
171 CheckObjectType(SymbolicLink
, ObpSymbolicLinkObjectType
, OBT_CASE_INSENSITIVE
| OBT_PAGED_POOL
, 0x100, 0x020001, 0x020000, 0x020001, 0x0f0001, 0x0f0001);
172 CheckObjectType(Token
, SeTokenObjectType
, OBT_SECURITY_REQUIRED
| OBT_PAGED_POOL
, 0x100, 0x020008, 0x0200e0, 0x020000, 0x0f01ff, 0x1f01ff);
173 CheckObjectType(Process
, PsProcessType
, OBT_NO_DEFAULT
| OBT_SECURITY_REQUIRED
, 0x0b0, 0x020410, 0x020beb, 0x120000, 0x1f0fff, 0x1f0fff);
174 CheckObjectType(Thread
, PsThreadType
, OBT_NO_DEFAULT
| OBT_SECURITY_REQUIRED
, 0x0b0, 0x020048, 0x020037, 0x120000, 0x1f03ff, 0x1f03ff);
175 CheckObjectType(Job
, PsJobType
, OBT_NO_DEFAULT
| OBT_SECURITY_REQUIRED
, 0x000, 0x020004, 0x02000b, 0x120000, 0x1f03ff, 0x1f001f);
176 CheckObjectType(DebugObject
, DbgkDebugObjectType
, OBT_NO_DEFAULT
| OBT_SECURITY_REQUIRED
, 0x000, 0x020001, 0x020002, 0x120000, 0x1f000f, 0x1f000f);
177 CheckObjectType(Event
, ExEventObjectType
, OBT_NO_DEFAULT
, 0x100, 0x020001, 0x020002, 0x120000, 0x1f0003, 0x1f0003);
178 CheckObjectType(EventPair
, ExEventPairObjectType
, 0, 0x100, 0x120000, 0x120000, 0x120000, 0x1f0000, 0x1f0000);
179 CheckObjectType(Mutant
, ExMutantObjectType
, OBT_NO_DEFAULT
, 0x100, 0x020001, 0x020000, 0x120000, 0x1f0001, 0x1f0001);
180 CheckObjectType(Callback
, ExCallbackObjectType
, OBT_NO_DEFAULT
, 0x100, 0x020000, 0x020001, 0x120000, 0x1f0001, 0x1f0001);
181 CheckObjectType(Semaphore
, ExSemaphoreObjectType
, OBT_NO_DEFAULT
, 0x100, 0x020001, 0x020002, 0x120000, 0x1f0003, 0x1f0003);
182 CheckObjectType(Timer
, ExTimerObjectType
, OBT_NO_DEFAULT
, 0x100, 0x020001, 0x020002, 0x120000, 0x1f0003, 0x1f0003);
183 CheckObjectType(Profile
, ExProfileObjectType
, OBT_NO_DEFAULT
, 0x100, 0x020001, 0x020001, 0x020001, 0x0f0001, 0x0f0001);
184 CheckObjectType(KeyedEvent
, ExpKeyedEventObjectType
, OBT_PAGED_POOL
, 0x000, 0x020001, 0x020002, 0x020000, 0x0f0003, 0x1f0003);
185 CheckObjectType(WindowStation
, ExWindowStationObjectType
, OBT_NO_DEFAULT
| OBT_SECURITY_REQUIRED
| OBT_MAINTAIN_HANDLE_COUNT
,
186 0x130, 0x020303, 0x02001c, 0x020060, 0x0f037f, 0x0f037f);
187 CheckObjectType(Desktop
, ExDesktopObjectType
, OBT_NO_DEFAULT
| OBT_SECURITY_REQUIRED
| OBT_MAINTAIN_HANDLE_COUNT
,
188 0x130, 0x020041, 0x0200be, 0x020100, 0x0f01ff, 0x0f01ff);
189 CheckObjectType(Section
, MmSectionObjectType
, OBT_PAGED_POOL
, 0x100, 0x020005, 0x020002, 0x020008, 0x0f001f, 0x1f001f);
190 CheckObjectType(Key
, CmpKeyObjectType
, OBT_CUSTOM_SECURITY_PROC
| OBT_SECURITY_REQUIRED
| OBT_PAGED_POOL
,
191 0x030, 0x020019, 0x020006, 0x020019, 0x0f003f, 0x1f003f);
192 CheckObjectType(Port
, LpcPortObjectType
, OBT_PAGED_POOL
, 0x7b2, 0x020001, 0x010001, 0x000000, 0x1f0001, 0x1f0001);
193 CheckObjectType(WaitablePort
, LpcWaitablePortObjectType
, OBT_NO_DEFAULT
, 0x7b2, 0x020001, 0x010001, 0x000000, 0x1f0001, 0x1f0001);
194 CheckObjectType(Adapter
, IoAdapterObjectType
, 0, 0x100, 0x120089, 0x120116, 0x1200a0, 0x1f01ff, 0x1f01ff);
195 CheckObjectType(Controller
, IoControllerObjectType
, 0, 0x100, 0x120089, 0x120116, 0x1200a0, 0x1f01ff, 0x1f01ff);
196 CheckObjectType(Device
, IoDeviceObjectType
, OBT_CUSTOM_SECURITY_PROC
| OBT_CASE_INSENSITIVE
,
197 0x100, 0x120089, 0x120116, 0x1200a0, 0x1f01ff, 0x1f01ff);
198 CheckObjectType(Driver
, IoDriverObjectType
, OBT_CASE_INSENSITIVE
, 0x100, 0x120089, 0x120116, 0x1200a0, 0x1f01ff, 0x1f01ff);
199 CheckObjectType(IoCompletion
, IoCompletionObjectType
, OBT_CASE_INSENSITIVE
, 0x110, 0x020001, 0x020002, 0x120000, 0x1f0003, 0x1f0003);
200 CheckObjectType(File
, IoFileObjectType
, OBT_NO_DEFAULT
| OBT_CUSTOM_SECURITY_PROC
| OBT_CASE_INSENSITIVE
| OBT_MAINTAIN_HANDLE_COUNT
,
201 0x130, 0x120089, 0x120116, 0x1200a0, 0x1f01ff, 0x1f01ff);
202 CheckObjectType(WmiGuid
, WmipGuidObjectType
, OBT_NO_DEFAULT
| OBT_CUSTOM_SECURITY_PROC
| OBT_SECURITY_REQUIRED
,
203 0x100, 0x000001, 0x000002, 0x000010, 0x120fff, 0x1f0fff);
204 CheckObjectType(FilterConnectionPort
, NULL
, OBT_NO_DEFAULT
| OBT_SECURITY_REQUIRED
, 0x100, 0x020001, 0x010001, 0x000000, 0x1f0001, 0x1f0001);
205 CheckObjectType(FilterCommunicationPort
, NULL
, OBT_NO_DEFAULT
, 0x100, 0x020001, 0x010001, 0x000000, 0x1f0001, 0x1f0001);
207 // exported but not created
208 ok_eq_pointer(IoDeviceHandlerObjectType
, NULL
);
210 // my Win7/x64 additionally has:
214 // IoCompletionReserve
224 // ... and does not have:
228 ObDereferenceObject(ObpTypeObjectType
);