ae3c5a7f3d64b2ac90c1f0051c3fb2ae9b8c70a6
[reactos.git] / reactos / ntoskrnl / include / internal / ob.h
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: include/internal/objmgr.h
5 * PURPOSE: Object manager definitions
6 * PROGRAMMER: David Welch (welch@mcmail.com)
7 */
8
9 #ifndef __INCLUDE_INTERNAL_OBJMGR_H
10 #define __INCLUDE_INTERNAL_OBJMGR_H
11
12 struct _EPROCESS;
13
14 #define ICIF_QUERY 0x1
15 #define ICIF_SET 0x2
16 #define ICIF_QUERY_SIZE_VARIABLE 0x4
17 #define ICIF_SET_SIZE_VARIABLE 0x8
18 #define ICIF_SIZE_VARIABLE (ICIF_QUERY_SIZE_VARIABLE | ICIF_SET_SIZE_VARIABLE)
19
20 typedef struct _DIRECTORY_OBJECT
21 {
22 CSHORT Type;
23 CSHORT Size;
24
25 /*
26 * PURPOSE: Head of the list of our subdirectories
27 */
28 LIST_ENTRY head;
29 KSPIN_LOCK Lock;
30 } DIRECTORY_OBJECT, *PDIRECTORY_OBJECT;
31
32 typedef struct _SYMLINK_OBJECT
33 {
34 CSHORT Type;
35 CSHORT Size;
36 UNICODE_STRING TargetName;
37 LARGE_INTEGER CreateTime;
38 } SYMLINK_OBJECT, *PSYMLINK_OBJECT;
39
40 typedef struct _INFORMATION_CLASS_INFO
41 {
42 ULONG RequiredSizeQUERY;
43 ULONG RequiredSizeSET;
44 ULONG AlignmentSET;
45 ULONG AlignmentQUERY;
46 ULONG Flags;
47 } INFORMATION_CLASS_INFO, *PINFORMATION_CLASS_INFO;
48
49 #define BODY_TO_HEADER(objbdy) \
50 CONTAINING_RECORD((objbdy), OBJECT_HEADER, Body)
51
52 #define HEADER_TO_OBJECT_NAME(objhdr) ((POBJECT_HEADER_NAME_INFO) \
53 (!(objhdr)->NameInfoOffset ? NULL: ((PCHAR)(objhdr) - (objhdr)->NameInfoOffset)))
54
55 #define HEADER_TO_HANDLE_INFO(objhdr) ((POBJECT_HEADER_HANDLE_INFO) \
56 (!(objhdr)->HandleInfoOffset ? NULL: ((PCHAR)(objhdr) - (objhdr)->HandleInfoOffset)))
57
58 #define HEADER_TO_CREATOR_INFO(objhdr) ((POBJECT_HEADER_CREATOR_INFO) \
59 (!((objhdr)->Flags & OB_FLAG_CREATOR_INFO) ? NULL: ((PCHAR)(objhdr) - sizeof(OBJECT_HEADER_CREATOR_INFO))))
60
61 #define OBJECT_ALLOC_SIZE(ObjectSize) ((ObjectSize)+sizeof(OBJECT_HEADER))
62
63 #define KERNEL_HANDLE_FLAG (1 << ((sizeof(HANDLE) * 8) - 1))
64 #define ObIsKernelHandle(Handle, ProcessorMode) \
65 (((ULONG_PTR)(Handle) & KERNEL_HANDLE_FLAG) && \
66 ((ProcessorMode) == KernelMode))
67 #define ObKernelHandleToHandle(Handle) \
68 (HANDLE)((ULONG_PTR)(Handle) & ~KERNEL_HANDLE_FLAG)
69
70 extern PDIRECTORY_OBJECT NameSpaceRoot;
71 extern POBJECT_TYPE ObSymbolicLinkType;
72 extern PHANDLE_TABLE ObpKernelHandleTable;
73
74 VOID
75 NTAPI
76 ObpAddEntryDirectory(
77 PDIRECTORY_OBJECT Parent,
78 POBJECT_HEADER Header,
79 PWSTR Name
80 );
81
82 VOID
83 NTAPI
84 ObpRemoveEntryDirectory(POBJECT_HEADER Header);
85
86 VOID
87 NTAPI
88 ObInitSymbolicLinkImplementation(VOID);
89
90 NTSTATUS
91 NTAPI
92 ObpCreateHandle(
93 struct _EPROCESS* Process,
94 PVOID ObjectBody,
95 ACCESS_MASK GrantedAccess,
96 BOOLEAN Inherit,
97 PHANDLE Handle
98 );
99
100 VOID
101 NTAPI
102 ObCreateHandleTable(
103 struct _EPROCESS* Parent,
104 BOOLEAN Inherit,
105 struct _EPROCESS* Process
106 );
107
108 NTSTATUS
109 NTAPI
110 ObFindObject(
111 POBJECT_CREATE_INFORMATION ObjectCreateInfo,
112 PUNICODE_STRING ObjectName,
113 PVOID* ReturnedObject,
114 PUNICODE_STRING RemainingPath,
115 POBJECT_TYPE ObjectType
116 );
117
118 NTSTATUS
119 NTAPI
120 ObpQueryHandleAttributes(
121 HANDLE Handle,
122 POBJECT_HANDLE_ATTRIBUTE_INFORMATION HandleInfo
123 );
124
125 NTSTATUS
126 NTAPI
127 ObpSetHandleAttributes(
128 HANDLE Handle,
129 POBJECT_HANDLE_ATTRIBUTE_INFORMATION HandleInfo
130 );
131
132 NTSTATUS
133 STDCALL
134 ObpCreateTypeObject(
135 struct _OBJECT_TYPE_INITIALIZER *ObjectTypeInitializer,
136 PUNICODE_STRING TypeName,
137 POBJECT_TYPE *ObjectType
138 );
139
140 ULONG
141 NTAPI
142 ObGetObjectHandleCount(PVOID Object);
143
144 NTSTATUS
145 NTAPI
146 ObDuplicateObject(
147 PEPROCESS SourceProcess,
148 PEPROCESS TargetProcess,
149 HANDLE SourceHandle,
150 PHANDLE TargetHandle,
151 ACCESS_MASK DesiredAccess,
152 BOOLEAN InheritHandle,
153 ULONG Options
154 );
155
156 ULONG
157 NTAPI
158 ObpGetHandleCountByHandleTable(PHANDLE_TABLE HandleTable);
159
160 VOID
161 STDCALL
162 ObQueryDeviceMapInformation(
163 PEPROCESS Process,
164 PPROCESS_DEVICEMAP_INFORMATION DeviceMapInfo
165 );
166
167 VOID
168 FASTCALL
169 ObpSetPermanentObject(
170 IN PVOID ObjectBody,
171 IN BOOLEAN Permanent
172 );
173
174 VOID
175 STDCALL
176 ObKillProcess(PEPROCESS Process);
177
178 /* Security descriptor cache functions */
179
180 NTSTATUS
181 NTAPI
182 ObpInitSdCache(VOID);
183
184 NTSTATUS
185 NTAPI
186 ObpAddSecurityDescriptor(
187 IN PSECURITY_DESCRIPTOR SourceSD,
188 OUT PSECURITY_DESCRIPTOR *DestinationSD
189 );
190
191 NTSTATUS
192 NTAPI
193 ObpRemoveSecurityDescriptor(IN PSECURITY_DESCRIPTOR SecurityDescriptor);
194
195 VOID
196 NTAPI
197 ObpReferenceCachedSecurityDescriptor(IN PSECURITY_DESCRIPTOR SecurityDescriptor);
198
199 VOID
200 NTAPI
201 ObpDereferenceCachedSecurityDescriptor(IN PSECURITY_DESCRIPTOR SecurityDescriptor);
202
203 VOID
204 FASTCALL
205 ObInitializeFastReference(
206 IN PEX_FAST_REF FastRef,
207 PVOID Object
208 );
209
210 PVOID
211 FASTCALL
212 ObFastReplaceObject(
213 IN PEX_FAST_REF FastRef,
214 PVOID Object
215 );
216
217 PVOID
218 FASTCALL
219 ObFastReferenceObject(IN PEX_FAST_REF FastRef);
220
221 VOID
222 FASTCALL
223 ObFastDereferenceObject(
224 IN PEX_FAST_REF FastRef,
225 PVOID Object
226 );
227
228 /* Secure object information functions */
229
230 NTSTATUS
231 STDCALL
232 ObpCaptureObjectName(
233 IN PUNICODE_STRING CapturedName,
234 IN PUNICODE_STRING ObjectName,
235 IN KPROCESSOR_MODE AccessMode
236 );
237
238 NTSTATUS
239 STDCALL
240 ObpCaptureObjectAttributes(
241 IN POBJECT_ATTRIBUTES ObjectAttributes,
242 IN KPROCESSOR_MODE AccessMode,
243 IN POBJECT_TYPE ObjectType,
244 IN POBJECT_CREATE_INFORMATION ObjectCreateInfo,
245 OUT PUNICODE_STRING ObjectName
246 );
247
248 VOID
249 STDCALL
250 ObpReleaseCapturedAttributes(IN POBJECT_CREATE_INFORMATION ObjectCreateInfo);
251
252 /* object information classes */
253
254 #define ICI_SQ_SAME(Size, Alignment, Flags) \
255 { Size, Size, Alignment, Alignment, Flags }
256
257 #define ICI_SQ(SizeQuery, SizeSet, AlignmentQuery, AlignmentSet, Flags) \
258 { SizeQuery, SizeSet, AlignmentQuery, AlignmentSet, Flags }
259
260 #define CheckInfoClass(Class, BufferLen, ClassList, StatusVar, Mode) \
261 do { \
262 if((Class) >= 0 && (Class) < sizeof(ClassList) / sizeof(ClassList[0])) \
263 { \
264 if(!(ClassList[Class].Flags & ICIF_##Mode)) \
265 { \
266 *(StatusVar) = STATUS_INVALID_INFO_CLASS; \
267 } \
268 else if(ClassList[Class].RequiredSize##Mode > 0 && \
269 (BufferLen) != ClassList[Class].RequiredSize##Mode) \
270 { \
271 if(!(ClassList[Class].Flags & ICIF_##Mode##_SIZE_VARIABLE) && \
272 (BufferLen) != ClassList[Class].RequiredSize##Mode) \
273 { \
274 *(StatusVar) = STATUS_INFO_LENGTH_MISMATCH; \
275 } \
276 } \
277 } \
278 else \
279 { \
280 *(StatusVar) = STATUS_INVALID_INFO_CLASS; \
281 } \
282 } while(0)
283
284
285 #define GetInfoClassAlignment(Class, ClassList, AlignmentVar, Mode) \
286 do { \
287 if((Class) >= 0 && (Class) < sizeof(ClassList) / sizeof(ClassList[0])) \
288 { \
289 *(AlignmentVar) = ClassList[Class].Alignment##Mode; \
290 } \
291 else \
292 { \
293 *(AlignmentVar) = sizeof(ULONG); \
294 } \
295 } while(0)
296
297 #define ProbeQueryInfoBuffer(Buffer, BufferLen, Alignment, RetLen, PrevMode, StatusVar) \
298 do { \
299 if(PrevMode != KernelMode) \
300 { \
301 _SEH_TRY \
302 { \
303 ProbeForWrite(Buffer, \
304 BufferLen, \
305 Alignment); \
306 if(RetLen != NULL) \
307 { \
308 ProbeForWrite(RetLen, \
309 sizeof(ULONG), \
310 1); \
311 } \
312 } \
313 _SEH_HANDLE \
314 { \
315 *(StatusVar) = _SEH_GetExceptionCode(); \
316 } \
317 _SEH_END; \
318 \
319 if(!NT_SUCCESS(*(StatusVar))) \
320 { \
321 DPRINT1("ProbeQueryInfoBuffer failed: 0x%x\n", *(StatusVar)); \
322 return *(StatusVar); \
323 } \
324 } \
325 } while(0)
326
327 #define ProbeSetInfoBuffer(Buffer, BufferLen, Alignment, PrevMode, StatusVar) \
328 do { \
329 if(PrevMode != KernelMode) \
330 { \
331 _SEH_TRY \
332 { \
333 ProbeForRead(Buffer, \
334 BufferLen, \
335 Alignment); \
336 } \
337 _SEH_HANDLE \
338 { \
339 *(StatusVar) = _SEH_GetExceptionCode(); \
340 } \
341 _SEH_END; \
342 \
343 if(!NT_SUCCESS(*(StatusVar))) \
344 { \
345 DPRINT1("ProbeAllInfoBuffer failed: 0x%x\n", *(StatusVar)); \
346 return *(StatusVar); \
347 } \
348 } \
349 } while(0)
350
351 #define DefaultSetInfoBufferCheck(Class, ClassList, Buffer, BufferLen, PrevMode, StatusVar) \
352 do { \
353 ULONG _Alignment; \
354 /* get the preferred alignment for the information class or return */ \
355 /* default alignment in case the class doesn't exist */ \
356 GetInfoClassAlignment(Class, \
357 ClassList, \
358 &_Alignment, \
359 SET); \
360 \
361 /* probe the ENTIRE buffers and return on failure */ \
362 ProbeSetInfoBuffer(Buffer, \
363 BufferLen, \
364 _Alignment, \
365 PrevMode, \
366 StatusVar); \
367 \
368 /* validate information class index and check buffer size */ \
369 CheckInfoClass(Class, \
370 BufferLen, \
371 ClassList, \
372 StatusVar, \
373 SET); \
374 } while(0)
375
376 #define DefaultQueryInfoBufferCheck(Class, ClassList, Buffer, BufferLen, RetLen, PrevMode, StatusVar) \
377 do { \
378 ULONG _Alignment; \
379 /* get the preferred alignment for the information class or return */ \
380 /* alignment in case the class doesn't exist */ \
381 GetInfoClassAlignment(Class, \
382 ClassList, \
383 &_Alignment, \
384 QUERY); \
385 \
386 /* probe the ENTIRE buffers and return on failure */ \
387 ProbeQueryInfoBuffer(Buffer, \
388 BufferLen, \
389 _Alignment, \
390 RetLen, \
391 PrevMode, \
392 StatusVar); \
393 \
394 /* validate information class index and check buffer size */ \
395 CheckInfoClass(Class, \
396 BufferLen, \
397 ClassList, \
398 StatusVar, \
399 QUERY); \
400 } while(0)
401
402 #endif /* __INCLUDE_INTERNAL_OBJMGR_H */