[CLT2012]
[reactos.git] / ntoskrnl / include / internal / ob.h
1 /*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/include/ob.h
5 * PURPOSE: Internal header for the Object Manager
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9 //
10 // Define this if you want debugging support
11 //
12 #define _OB_DEBUG_ 0x00
13
14 //
15 // These define the Debug Masks Supported
16 //
17 #define OB_HANDLE_DEBUG 0x01
18 #define OB_NAMESPACE_DEBUG 0x02
19 #define OB_SECURITY_DEBUG 0x04
20 #define OB_REFERENCE_DEBUG 0x08
21 #define OB_CALLBACK_DEBUG 0x10
22
23 //
24 // Debug/Tracing support
25 //
26 #if _OB_DEBUG_
27 #ifdef NEW_DEBUG_SYSTEM_IMPLEMENTED // enable when Debug Filters are implemented
28 #define OBTRACE DbgPrintEx
29 #else
30 #define OBTRACE(x, ...) \
31 if (x & ObpTraceLevel) DbgPrint(__VA_ARGS__)
32 #endif
33 #else
34 #define OBTRACE(x, fmt, ...) DPRINT(fmt, ##__VA_ARGS__)
35 #endif
36
37 //
38 // Mask to detect GENERIC_XXX access masks being used
39 //
40 #define GENERIC_ACCESS \
41 (GENERIC_READ | \
42 GENERIC_WRITE | \
43 GENERIC_EXECUTE | \
44 GENERIC_ALL)
45
46 //
47 // Handle Bit Flags
48 //
49 #define OBJ_PROTECT_CLOSE 0x01
50 //#define OBJ_INHERIT 0x02
51 #define OBJ_AUDIT_OBJECT_CLOSE 0x04
52 #define OBJ_HANDLE_ATTRIBUTES (OBJ_PROTECT_CLOSE |\
53 OBJ_INHERIT | \
54 OBJ_AUDIT_OBJECT_CLOSE)
55
56 //
57 // Identifies a Kernel Handle
58 //
59 #define KERNEL_HANDLE_FLAG \
60 ((ULONG_PTR)1 << ((sizeof(HANDLE) * 8) - 1))
61 #define ObIsKernelHandle(Handle, ProcessorMode) \
62 (((ULONG_PTR)(Handle) & KERNEL_HANDLE_FLAG) && \
63 ((ProcessorMode) == KernelMode))
64
65 //
66 // Converts to and from a Kernel Handle to a normal handle
67 //
68 #define ObKernelHandleToHandle(Handle) \
69 (HANDLE)((ULONG_PTR)(Handle) & ~KERNEL_HANDLE_FLAG)
70 #define ObMarkHandleAsKernelHandle(Handle) \
71 (HANDLE)((ULONG_PTR)(Handle) | KERNEL_HANDLE_FLAG)
72
73 //
74 // Converts from an EXHANDLE object to a POBJECT_HEADER
75 //
76 #define ObpGetHandleObject(x) \
77 ((POBJECT_HEADER)((ULONG_PTR)x->Object & ~OBJ_HANDLE_ATTRIBUTES))
78
79 //
80 // Recovers the security descriptor from a cached security descriptor header
81 //
82 #define ObpGetHeaderForSd(x) \
83 CONTAINING_RECORD((x), SECURITY_DESCRIPTOR_HEADER, SecurityDescriptor)
84
85 //
86 // Recovers the security descriptor from a cached security descriptor list entry
87 //
88 #define ObpGetHeaderForEntry(x) \
89 CONTAINING_RECORD((x), SECURITY_DESCRIPTOR_HEADER, Link)
90
91 //
92 // Context Structures for Ex*Handle Callbacks
93 //
94 typedef struct _OBP_SET_HANDLE_ATTRIBUTES_CONTEXT
95 {
96 KPROCESSOR_MODE PreviousMode;
97 OBJECT_HANDLE_ATTRIBUTE_INFORMATION Information;
98 } OBP_SET_HANDLE_ATTRIBUTES_CONTEXT, *POBP_SET_HANDLE_ATTRIBUTES_CONTEXT;
99
100 typedef struct _OBP_CLOSE_HANDLE_CONTEXT
101 {
102 PHANDLE_TABLE HandleTable;
103 KPROCESSOR_MODE AccessMode;
104 } OBP_CLOSE_HANDLE_CONTEXT, *POBP_CLOSE_HANDLE_CONTEXT;
105
106 typedef struct _OBP_FIND_HANDLE_DATA
107 {
108 POBJECT_HEADER ObjectHeader;
109 POBJECT_TYPE ObjectType;
110 POBJECT_HANDLE_INFORMATION HandleInformation;
111 } OBP_FIND_HANDLE_DATA, *POBP_FIND_HANDLE_DATA;
112
113 //
114 // Cached Security Descriptor Header
115 //
116 typedef struct _SECURITY_DESCRIPTOR_HEADER
117 {
118 LIST_ENTRY Link;
119 ULONG RefCount;
120 ULONG FullHash;
121 QUAD SecurityDescriptor;
122 } SECURITY_DESCRIPTOR_HEADER, *PSECURITY_DESCRIPTOR_HEADER;
123
124 //
125 // Cached Security Descriptor List
126 //
127 typedef struct _OB_SD_CACHE_LIST
128 {
129 EX_PUSH_LOCK PushLock;
130 LIST_ENTRY Head;
131 } OB_SD_CACHE_LIST, *POB_SD_CACHE_LIST;
132
133 //
134 // Structure for quick-compare of a DOS Device path
135 //
136 typedef union
137 {
138 WCHAR Name[sizeof(ULARGE_INTEGER) / sizeof(WCHAR)];
139 ULARGE_INTEGER Alignment;
140 } ALIGNEDNAME;
141
142 //
143 // Private Temporary Buffer for Lookup Routines
144 //
145 #define TAG_OB_TEMP_STORAGE 'tSbO'
146 typedef struct _OB_TEMP_BUFFER
147 {
148 ACCESS_STATE LocalAccessState;
149 OBJECT_CREATE_INFORMATION ObjectCreateInfo;
150 OBP_LOOKUP_CONTEXT LookupContext;
151 AUX_ACCESS_DATA AuxData;
152 } OB_TEMP_BUFFER, *POB_TEMP_BUFFER;
153
154 //
155 // Startup and Shutdown Functions
156 //
157 BOOLEAN
158 NTAPI
159 ObInitSystem(
160 VOID
161 );
162
163 VOID
164 NTAPI
165 ObShutdownSystem(
166 VOID
167 );
168
169 //
170 // Directory Namespace Functions
171 //
172 BOOLEAN
173 NTAPI
174 ObpDeleteEntryDirectory(
175 IN POBP_LOOKUP_CONTEXT Context
176 );
177
178 BOOLEAN
179 NTAPI
180 ObpInsertEntryDirectory(
181 IN POBJECT_DIRECTORY Parent,
182 IN POBP_LOOKUP_CONTEXT Context,
183 IN POBJECT_HEADER ObjectHeader
184 );
185
186 PVOID
187 NTAPI
188 ObpLookupEntryDirectory(
189 IN POBJECT_DIRECTORY Directory,
190 IN PUNICODE_STRING Name,
191 IN ULONG Attributes,
192 IN UCHAR SearchShadow,
193 IN POBP_LOOKUP_CONTEXT Context
194 );
195
196 //
197 // Symbolic Link Functions
198 //
199 VOID
200 NTAPI
201 ObpDeleteSymbolicLink(
202 IN PVOID ObjectBody
203 );
204
205 NTSTATUS
206 NTAPI
207 ObpParseSymbolicLink(
208 IN PVOID ParsedObject,
209 IN PVOID ObjectType,
210 IN OUT PACCESS_STATE AccessState,
211 IN KPROCESSOR_MODE AccessMode,
212 IN ULONG Attributes,
213 IN OUT PUNICODE_STRING FullPath,
214 IN OUT PUNICODE_STRING RemainingName,
215 IN OUT PVOID Context OPTIONAL,
216 IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL,
217 OUT PVOID *NextObject
218 );
219
220 VOID
221 NTAPI
222 ObpCreateSymbolicLinkName(
223 IN POBJECT_SYMBOLIC_LINK SymbolicLink
224 );
225
226 VOID
227 NTAPI
228 ObpDeleteSymbolicLinkName(
229 IN POBJECT_SYMBOLIC_LINK SymbolicLink
230 );
231
232 //
233 // Process/Handle Table Init/Rundown
234 //
235 NTSTATUS
236 NTAPI
237 ObInitProcess(
238 IN PEPROCESS Parent OPTIONAL,
239 IN PEPROCESS Process
240 );
241
242 PHANDLE_TABLE
243 NTAPI
244 ObReferenceProcessHandleTable(
245 IN PEPROCESS Process
246 );
247
248 VOID
249 NTAPI
250 ObDereferenceProcessHandleTable(
251 IN PEPROCESS Process
252 );
253
254 VOID
255 NTAPI
256 ObKillProcess(
257 IN PEPROCESS Process
258 );
259
260 //
261 // Object Lookup Functions
262 //
263 NTSTATUS
264 NTAPI
265 ObpLookupObjectName(
266 IN HANDLE RootHandle,
267 IN PUNICODE_STRING ObjectName,
268 IN ULONG Attributes,
269 IN POBJECT_TYPE ObjectType,
270 IN KPROCESSOR_MODE AccessMode,
271 IN OUT PVOID ParseContext,
272 IN PSECURITY_QUALITY_OF_SERVICE SecurityQos,
273 IN PVOID InsertObject,
274 IN PACCESS_STATE AccessState,
275 IN POBP_LOOKUP_CONTEXT LookupContext,
276 OUT PVOID *FoundObject
277 );
278
279 //
280 // Object Attribute Functions
281 //
282 BOOLEAN
283 NTAPI
284 ObpSetHandleAttributes(
285 IN OUT PHANDLE_TABLE_ENTRY HandleTableEntry,
286 IN ULONG_PTR Context
287 );
288
289 VOID
290 NTAPI
291 ObQueryDeviceMapInformation(
292 IN PEPROCESS Process,
293 OUT PPROCESS_DEVICEMAP_INFORMATION DeviceMapInfo
294 );
295
296 //
297 // Object Lifetime Functions
298 //
299 VOID
300 NTAPI
301 ObpDeleteObject(
302 IN PVOID Object,
303 IN BOOLEAN CalledFromWorkerThread
304 );
305
306 LONG
307 FASTCALL
308 ObDereferenceObjectEx(
309 IN PVOID Object,
310 IN LONG Count
311 );
312
313 LONG
314 FASTCALL
315 ObReferenceObjectEx(
316 IN PVOID Object,
317 IN LONG Count
318 );
319
320 BOOLEAN
321 FASTCALL
322 ObReferenceObjectSafe(
323 IN PVOID Object
324 );
325
326 VOID
327 NTAPI
328 ObpReapObject(
329 IN PVOID Unused
330 );
331
332 VOID
333 FASTCALL
334 ObpSetPermanentObject(
335 IN PVOID ObjectBody,
336 IN BOOLEAN Permanent
337 );
338
339 VOID
340 NTAPI
341 ObpDeleteNameCheck(
342 IN PVOID Object
343 );
344
345 VOID
346 NTAPI
347 ObClearProcessHandleTable(
348 IN PEPROCESS Process
349 );
350
351 NTSTATUS
352 NTAPI
353 ObDuplicateObject(
354 IN PEPROCESS SourceProcess,
355 IN HANDLE SourceHandle,
356 IN PEPROCESS TargetProcess OPTIONAL,
357 IN PHANDLE TargetHandle OPTIONAL,
358 IN ACCESS_MASK DesiredAccess,
359 IN ULONG HandleAttributes,
360 IN ULONG Options,
361 IN KPROCESSOR_MODE PreviousMode
362 );
363
364 VOID
365 NTAPI
366 ObFreeObjectCreateInfoBuffer(
367 IN POBJECT_CREATE_INFORMATION ObjectCreateInfo
368 );
369
370 VOID
371 NTAPI
372 ObpFreeObjectNameBuffer(
373 IN PUNICODE_STRING Name
374 );
375
376 VOID
377 NTAPI
378 ObpDeleteObjectType(
379 IN PVOID Object
380 );
381
382 //
383 // DOS Devices Functions
384 //
385 VOID
386 NTAPI
387 ObDereferenceDeviceMap(
388 IN PEPROCESS Process
389 );
390
391 VOID
392 FASTCALL
393 ObfDereferenceDeviceMap(
394 IN PVOID DeviceMap
395 );
396
397 VOID
398 NTAPI
399 ObInheritDeviceMap(
400 IN PEPROCESS Parent,
401 IN PEPROCESS Process
402 );
403
404 NTSTATUS
405 NTAPI
406 ObpCreateDosDevicesDirectory(
407 VOID
408 );
409
410 //
411 // Security descriptor cache functions
412 //
413 NTSTATUS
414 NTAPI
415 ObpInitSdCache(
416 VOID
417 );
418
419 PSECURITY_DESCRIPTOR
420 NTAPI
421 ObpReferenceSecurityDescriptor(
422 IN POBJECT_HEADER ObjectHeader
423 );
424
425 //
426 // Object Security Routines
427 //
428 BOOLEAN
429 NTAPI
430 ObCheckObjectAccess(
431 IN PVOID Object,
432 IN OUT PACCESS_STATE AccessState,
433 IN BOOLEAN LockHeld,
434 IN KPROCESSOR_MODE AccessMode,
435 OUT PNTSTATUS ReturnedStatus
436 );
437
438 BOOLEAN
439 NTAPI
440 ObCheckCreateObjectAccess(
441 IN PVOID Object,
442 IN ACCESS_MASK CreateAccess,
443 IN PACCESS_STATE AccessState,
444 IN PUNICODE_STRING ComponentName,
445 IN BOOLEAN LockHeld,
446 IN KPROCESSOR_MODE AccessMode,
447 OUT PNTSTATUS AccessStatus
448 );
449
450 BOOLEAN
451 NTAPI
452 ObpCheckTraverseAccess(
453 IN PVOID Object,
454 IN ACCESS_MASK TraverseAccess,
455 IN PACCESS_STATE AccessState OPTIONAL,
456 IN BOOLEAN LockHeld,
457 IN KPROCESSOR_MODE AccessMode,
458 OUT PNTSTATUS AccessStatus
459 );
460
461 BOOLEAN
462 NTAPI
463 ObpCheckObjectReference(
464 IN PVOID Object,
465 IN OUT PACCESS_STATE AccessState,
466 IN BOOLEAN LockHeld,
467 IN KPROCESSOR_MODE AccessMode,
468 OUT PNTSTATUS AccessStatus
469 );
470
471 //
472 // Default Object Security Callback Routines
473 //
474 NTSTATUS
475 NTAPI
476 ObAssignObjectSecurityDescriptor(
477 IN PVOID Object,
478 IN PSECURITY_DESCRIPTOR SecurityDescriptor OPTIONAL,
479 IN POOL_TYPE PoolType
480 );
481
482 NTSTATUS
483 NTAPI
484 ObDeassignSecurity(
485 IN OUT PSECURITY_DESCRIPTOR *SecurityDescriptor
486 );
487
488 NTSTATUS
489 NTAPI
490 ObQuerySecurityDescriptorInfo(
491 IN PVOID Object,
492 IN PSECURITY_INFORMATION SecurityInformation,
493 OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
494 IN OUT PULONG Length,
495 IN PSECURITY_DESCRIPTOR *OutputSecurityDescriptor
496 );
497
498 NTSTATUS
499 NTAPI
500 ObSetSecurityDescriptorInfo(
501 IN PVOID Object,
502 IN PSECURITY_INFORMATION SecurityInformation,
503 IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
504 IN OUT PSECURITY_DESCRIPTOR *OutputSecurityDescriptor,
505 IN POOL_TYPE PoolType,
506 IN PGENERIC_MAPPING GenericMapping
507 );
508
509 //
510 // Executive Fast Referencing Functions
511 //
512 VOID
513 FASTCALL
514 ObInitializeFastReference(
515 IN PEX_FAST_REF FastRef,
516 IN PVOID Object
517 );
518
519 PVOID
520 FASTCALL
521 ObFastReplaceObject(
522 IN PEX_FAST_REF FastRef,
523 IN PVOID Object
524 );
525
526 PVOID
527 FASTCALL
528 ObFastReferenceObject(
529 IN PEX_FAST_REF FastRef
530 );
531
532 PVOID
533 FASTCALL
534 ObFastReferenceObjectLocked(
535 IN PEX_FAST_REF FastRef
536 );
537
538 VOID
539 FASTCALL
540 ObFastDereferenceObject(
541 IN PEX_FAST_REF FastRef,
542 IN PVOID Object
543 );
544
545 //
546 // Object Create and Object Name Capture Functions
547 //
548 NTSTATUS
549 NTAPI
550 ObpCaptureObjectName(
551 IN PUNICODE_STRING CapturedName,
552 IN PUNICODE_STRING ObjectName,
553 IN KPROCESSOR_MODE AccessMode,
554 IN BOOLEAN AllocateFromLookaside
555 );
556
557 NTSTATUS
558 NTAPI
559 ObpCaptureObjectCreateInformation(
560 IN POBJECT_ATTRIBUTES ObjectAttributes,
561 IN KPROCESSOR_MODE AccessMode,
562 IN BOOLEAN AllocateFromLookaside,
563 IN POBJECT_CREATE_INFORMATION ObjectCreateInfo,
564 OUT PUNICODE_STRING ObjectName
565 );
566
567 //
568 // Miscellanea
569 //
570 ULONG
571 NTAPI
572 ObGetProcessHandleCount(
573 IN PEPROCESS Process
574 );
575
576 //
577 // Global data inside the Object Manager
578 //
579 extern ULONG ObpTraceLevel;
580 extern KEVENT ObpDefaultObject;
581 extern KGUARDED_MUTEX ObpDeviceMapLock;
582 extern POBJECT_TYPE ObpTypeObjectType;
583 extern POBJECT_TYPE ObSymbolicLinkType;
584 extern POBJECT_TYPE ObpTypeObjectType;
585 extern POBJECT_DIRECTORY ObpRootDirectoryObject;
586 extern POBJECT_DIRECTORY ObpTypeDirectoryObject;
587 extern PHANDLE_TABLE ObpKernelHandleTable;
588 extern WORK_QUEUE_ITEM ObpReaperWorkItem;
589 extern volatile PVOID ObpReaperList;
590 extern GENERAL_LOOKASIDE ObpNameBufferLookasideList, ObpCreateInfoLookasideList;
591 extern BOOLEAN IoCountOperations;
592 extern ALIGNEDNAME ObpDosDevicesShortNamePrefix;
593 extern ALIGNEDNAME ObpDosDevicesShortNameRoot;
594 extern UNICODE_STRING ObpDosDevicesShortName;
595
596 //
597 // Inlined Functions
598 //
599 #include "ob_x.h"