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