ReactOS 0.4.15-dev-5664-g3bf4ef6
ObTypes.c
Go to the documentation of this file.
1/*
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>
6 */
7
8#include <kmt_test.h>
9
10#define NDEBUG
11#include <debug.h>
12
13static
16 IN PCWSTR TypeName)
17{
23
24 RtlInitUnicodeString(&Name, TypeName);
28 ok(Handle != NULL, "ObjectTypeHandle = NULL\n");
29 if (!skip(Status == STATUS_SUCCESS && Handle, "No handle\n"))
30 {
33 ok(ObjectType != NULL, "ObjectType = NULL\n");
36 }
37 return ObjectType;
38}
39
40#define ok_eq_ustr(value, expected) ok(RtlEqualUnicodeString(value, expected, FALSE), #value " = \"%wZ\", expected \"%%wZ\"\n", value, expected)
41
42#define CheckObjectType(TypeName, Variable, Flags, InvalidAttr, \
43 ReadMapping, WriteMapping, ExecMapping, AllMapping, \
44 ValidMask) do \
45{ \
46 POBJECT_TYPE ObjectType; \
47 UNICODE_STRING Name; \
48 ULONG Key; \
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; \
57 \
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")) \
62 { \
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 */ \
71 if (UseDefault) \
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 */ \
99 /* DumpProcedure */ \
100 /* OpenProcedure */ \
101 /* CloseProcedure */ \
102 /* DeleteProcedure */ \
103 /* ParseProcedure */ \
104 if (CustomSecurityProc) \
105 ok(ObjectType->TypeInfo.SecurityProcedure != NULL, \
106 "No Security Proc\n"); \
107 else \
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; \
116 if (!CustomKey) \
117 ok_eq_hex(ObjectType->Key, Key); \
118 ObDereferenceObject(ObjectType); \
119 } \
120} while (0)
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
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)
151
152static
153VOID
155{
156 ULONG Index;
157
158 ObpTypeObjectType = GetObjectType(L"\\ObjectTypes\\Type");
159 if (skip(ObpTypeObjectType != NULL, "No Type object type\n"))
160 return;
161
163 ok(ObpDefaultObject != NULL, "No ObpDefaultObject\n");
165 ok(SeDefaultObjectMethod != NULL, "No SeDefaultObjectMethod\n");
166
167#ifdef _PROPER_NT_NDK_EXPORTS
168#define ObpTypeObjectType *ObpTypeObjectType
169#define ObpDirectoryObjectType *ObpDirectoryObjectType
170#define ObpSymbolicLinkObjectType *ObpSymbolicLinkObjectType
171#define PsJobType *PsJobType
172#define DbgkDebugObjectType *DbgkDebugObjectType
173#define ExEventPairObjectType *ExEventPairObjectType
174#define ExMutantObjectType *ExMutantObjectType
175#define ExCallbackObjectType *ExCallbackObjectType
176#define ExTimerObjectType *ExTimerObjectType
177#define ExProfileObjectType *ExProfileObjectType
178#define ExpKeyedEventObjectType *ExpKeyedEventObjectType
179#define ExWindowStationObjectType *ExWindowStationObjectType
180#define ExDesktopObjectType *ExDesktopObjectType
181#define MmSectionObjectType *MmSectionObjectType
182#define CmpKeyObjectType *CmpKeyObjectType
183#define LpcPortObjectType *LpcPortObjectType
184#define LpcWaitablePortObjectType *LpcWaitablePortObjectType
185#define IoAdapterObjectType *IoAdapterObjectType
186#define IoControllerObjectType *IoControllerObjectType
187#define IoDeviceObjectType *IoDeviceObjectType
188#define IoDriverObjectType *IoDriverObjectType
189#define IoCompletionObjectType *IoCompletionObjectType
190#define WmipGuidObjectType *WmipGuidObjectType
191#endif
192
193 Index = 1;
194 CheckObjectType(Type, ObpTypeObjectType, OBT_MAINTAIN_TYPE_LIST | OBT_CUSTOM_KEY, 0x100, 0x020000, 0x020000, 0x020000, 0x0f0001, 0x1f0001);
196 CheckObjectType(Directory, ObpDirectoryObjectType, OBT_CASE_INSENSITIVE | OBT_PAGED_POOL, 0x100, 0x020003, 0x02000c, 0x020003, 0x0f000f, 0x0f000f);
197 CheckObjectType(SymbolicLink, ObpSymbolicLinkObjectType, OBT_CASE_INSENSITIVE | OBT_PAGED_POOL, 0x100, 0x020001, 0x020000, 0x020001, 0x0f0001, 0x0f0001);
198 CheckObjectType(Token, *SeTokenObjectType, OBT_SECURITY_REQUIRED | OBT_PAGED_POOL, 0x100, 0x020008, 0x0200e0, 0x020000, 0x0f01ff, 0x1f01ff);
199 CheckObjectType(Process, *PsProcessType, OBT_NO_DEFAULT | OBT_SECURITY_REQUIRED, 0x0b0, 0x020410, 0x020beb, 0x120000, 0x1f0fff, 0x1f0fff);
200 CheckObjectType(Thread, *PsThreadType, OBT_NO_DEFAULT | OBT_SECURITY_REQUIRED, 0x0b0, 0x020048, 0x020037, 0x120000, 0x1f03ff, 0x1f03ff);
201 CheckObjectType(Job, PsJobType, OBT_NO_DEFAULT | OBT_SECURITY_REQUIRED, 0x000, 0x020004, 0x02000b, 0x120000, 0x1f03ff, 0x1f001f);
202 CheckObjectType(DebugObject, DbgkDebugObjectType, OBT_NO_DEFAULT | OBT_SECURITY_REQUIRED, 0x000, 0x020001, 0x020002, 0x120000, 0x1f000f, 0x1f000f);
203 CheckObjectType(Event, *ExEventObjectType, OBT_NO_DEFAULT, 0x100, 0x020001, 0x020002, 0x120000, 0x1f0003, 0x1f0003);
204 CheckObjectType(EventPair, ExEventPairObjectType, 0, 0x100, 0x120000, 0x120000, 0x120000, 0x1f0000, 0x1f0000);
205 CheckObjectType(Mutant, ExMutantObjectType, OBT_NO_DEFAULT, 0x100, 0x020001, 0x020000, 0x120000, 0x1f0001, 0x1f0001);
206 CheckObjectType(Callback, ExCallbackObjectType, OBT_NO_DEFAULT, 0x100, 0x020000, 0x020001, 0x120000, 0x1f0001, 0x1f0001);
207 CheckObjectType(Semaphore, *ExSemaphoreObjectType, OBT_NO_DEFAULT, 0x100, 0x020001, 0x020002, 0x120000, 0x1f0003, 0x1f0003);
208 CheckObjectType(Timer, ExTimerObjectType, OBT_NO_DEFAULT, 0x100, 0x020001, 0x020002, 0x120000, 0x1f0003, 0x1f0003);
209 CheckObjectType(Profile, ExProfileObjectType, OBT_NO_DEFAULT, 0x100, 0x020001, 0x020001, 0x020001, 0x0f0001, 0x0f0001);
210 CheckObjectType(KeyedEvent, ExpKeyedEventObjectType, OBT_PAGED_POOL, 0x000, 0x020001, 0x020002, 0x020000, 0x0f0003, 0x1f0003);
212 0x130, 0x020303, 0x02001c, 0x020060, 0x0f037f, 0x0f037f);
214 0x130, 0x020041, 0x0200be, 0x020100, 0x0f01ff, 0x0f01ff);
215 CheckObjectType(Section, MmSectionObjectType, OBT_PAGED_POOL, 0x100, 0x020005, 0x020002, 0x020008, 0x0f001f, 0x1f001f);
217 0x030, 0x020019, 0x020006, 0x020019, 0x0f003f, 0x1f003f);
218 // 0x7b2 is used for Server 2003 SP2 RTM, it seems it was changed to 0xfb2 in some patch level.
219 CheckObjectType(Port, LpcPortObjectType, OBT_PAGED_POOL, 0xfb2, 0x020001, 0x010001, 0x000000, 0x1f0001, 0x1f0001);
220 // 0x7b2 is used for Server 2003 SP2 RTM, it seems it was changed to 0xfb2 in some patch level.
221 CheckObjectType(WaitablePort, LpcWaitablePortObjectType, OBT_NO_DEFAULT, 0xfb2, 0x020001, 0x010001, 0x000000, 0x1f0001, 0x1f0001);
222 CheckObjectType(Adapter, IoAdapterObjectType, 0, 0x100, 0x120089, 0x120116, 0x1200a0, 0x1f01ff, 0x1f01ff);
223 CheckObjectType(Controller, IoControllerObjectType, 0, 0x100, 0x120089, 0x120116, 0x1200a0, 0x1f01ff, 0x1f01ff);
225 0x100, 0x120089, 0x120116, 0x1200a0, 0x1f01ff, 0x1f01ff);
226 CheckObjectType(Driver, IoDriverObjectType, OBT_CASE_INSENSITIVE, 0x100, 0x120089, 0x120116, 0x1200a0, 0x1f01ff, 0x1f01ff);
227 CheckObjectType(IoCompletion, IoCompletionObjectType, OBT_CASE_INSENSITIVE, 0x110, 0x020001, 0x020002, 0x120000, 0x1f0003, 0x1f0003);
229 0x130, 0x120089, 0x120116, 0x1200a0, 0x1f01ff, 0x1f01ff);
231 0x100, 0x000001, 0x000002, 0x000010, 0x120fff, 0x1f0fff);
232 CheckObjectType(FilterConnectionPort, NULL, OBT_NO_DEFAULT | OBT_SECURITY_REQUIRED, 0x100, 0x020001, 0x010001, 0x000000, 0x1f0001, 0x1f0001);
233 CheckObjectType(FilterCommunicationPort, NULL, OBT_NO_DEFAULT, 0x100, 0x020001, 0x010001, 0x000000, 0x1f0001, 0x1f0001);
234
235 // exported but not created
237
238 // my Win7/x64 additionally has:
239 // ALPC Port
240 // EtwConsumer
241 // EtwRegistration
242 // IoCompletionReserve
243 // PcwObject
244 // PowerRequest
245 // Session
246 // TmEn
247 // TmRm
248 // TmTm
249 // TmTx
250 // TpWorkerFactory
251 // UserApcReserve
252 // ... and does not have:
253 // Port
254 // WaitablePort
255
257}
258
260{
262}
#define ok_eq_hex(value, expected)
Definition: NtContinue.c:18
static POBJECT_TYPE ObTypes[NUM_OBTYPES]
Definition: ObType.c:39
#define ObpDirectoryObjectType
Definition: ObTypes.c:118
#define OBT_CUSTOM_KEY
Definition: ObTypes.c:143
#define IoCompletionObjectType
Definition: ObTypes.c:130
static POBJECT_TYPE ObpDefaultObject
Definition: ObTypes.c:133
static POBJECT_TYPE ObpTypeObjectType
Definition: ObTypes.c:117
#define ExProfileObjectType
Definition: ObTypes.c:125
#define WmipGuidObjectType
Definition: ObTypes.c:131
#define IoControllerObjectType
Definition: ObTypes.c:129
#define OBT_CUSTOM_SECURITY_PROC
Definition: ObTypes.c:137
static OB_SECURITY_METHOD SeDefaultObjectMethod
Definition: ObTypes.c:134
#define ExEventPairObjectType
Definition: ObTypes.c:121
#define OBT_CASE_INSENSITIVE
Definition: ObTypes.c:139
static VOID TestObjectTypes(VOID)
Definition: ObTypes.c:149
#define LpcWaitablePortObjectType
Definition: ObTypes.c:128
#define ExTimerObjectType
Definition: ObTypes.c:124
#define OBT_NO_DEFAULT
Definition: ObTypes.c:136
#define OBT_MAINTAIN_HANDLE_COUNT
Definition: ObTypes.c:141
#define OBT_MAINTAIN_TYPE_LIST
Definition: ObTypes.c:140
#define ObpSymbolicLinkObjectType
Definition: ObTypes.c:119
#define DbgkDebugObjectType
Definition: ObTypes.c:120
#define OBT_SECURITY_REQUIRED
Definition: ObTypes.c:138
#define ExpKeyedEventObjectType
Definition: ObTypes.c:126
#define CmpKeyObjectType
Definition: ObTypes.c:127
#define ExCallbackObjectType
Definition: ObTypes.c:123
#define ExMutantObjectType
Definition: ObTypes.c:122
#define CheckObjectType(TypeName, Variable, Flags, InvalidAttr, ReadMapping, WriteMapping, ExecMapping, AllMapping, ValidMask)
Definition: ObTypes.c:42
#define OBT_PAGED_POOL
Definition: ObTypes.c:142
static POBJECT_TYPE GetObjectType(IN PCWSTR TypeName)
Definition: ObTypes.c:15
#define ok_eq_pointer(value, expected)
Type
Definition: Type.h:7
struct NameRec_ * Name
Definition: cdprocs.h:460
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
LONG NTSTATUS
Definition: precomp.h:26
Definition: File.h:16
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
static const WCHAR SymbolicLink[]
Definition: interface.c:31
NTSTATUS NTAPI IoCompletion(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Ctx)
Definition: control.c:382
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
ULONG Handle
Definition: gdb_input.c:15
Status
Definition: gdiplustypes.h:25
CPPORT Port[4]
Definition: headless.c:35
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
POBJECT_TYPE IoDeviceObjectType
Definition: iomgr.c:35
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
unsigned int ULONG
Definition: retypes.h:1
POBJECT_TYPE LpcPortObjectType
Definition: port.c:17
ObjectType
Definition: metafile.c:81
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define KernelMode
Definition: asm.h:34
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSTATUS(NTAPI * OB_SECURITY_METHOD)(_In_ PVOID Object, _In_ SECURITY_OPERATION_CODE OperationType, _In_ PSECURITY_INFORMATION SecurityInformation, _In_ PSECURITY_DESCRIPTOR SecurityDescriptor, _Inout_ PULONG CapturedLength, _Inout_ PSECURITY_DESCRIPTOR *ObjectSecurityDescriptor, _In_ POOL_TYPE PoolType, _In_ PGENERIC_MAPPING GenericMapping)
Definition: obtypes.h:229
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
POBJECT_TYPE ExEventObjectType
Definition: event.c:18
POBJECT_TYPE IoDeviceHandlerObjectType
Definition: adapter.c:19
POBJECT_TYPE IoAdapterObjectType
Definition: adapter.c:18
POBJECT_TYPE IoDriverObjectType
Definition: driver.c:33
POBJECT_TYPE PsProcessType
Definition: process.c:20
POBJECT_TYPE PsThreadType
Definition: thread.c:20
POBJECT_TYPE SeTokenObjectType
Definition: token.c:17
#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
POBJECT_TYPE PsJobType
Definition: job.c:20
POBJECT_TYPE MmSectionObjectType
Definition: section.c:195
POBJECT_TYPE ExSemaphoreObjectType
Definition: sem.c:22
#define STATUS_SUCCESS
Definition: shellext.h:65
base for all directory entries
Definition: entries.h:138
OB_SECURITY_METHOD SecurityProcedure
Definition: obtypes.h:371
OBJECT_TYPE_INITIALIZER TypeInfo
Definition: obtypes.h:390
ULONG Key
Definition: obtypes.h:391
PVOID DefaultObject
Definition: obtypes.h:384
Definition: fs_rec.h:143
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define IN
Definition: typedefs.h:39
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
_In_ WDFCOLLECTION _In_ ULONG Index
_Must_inspect_result_ _In_ WDFDRIVER Driver
Definition: wdfcontrol.h:83
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:458
POBJECT_TYPE ExDesktopObjectType
Definition: win32k.c:22
POBJECT_TYPE ExWindowStationObjectType
Definition: win32k.c:21
#define ObDereferenceObject
Definition: obfuncs.h:203