23f54cefefd4f9b2573d8a21e03d1de3aba9e437
[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/internal/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 INIT_FUNCTION
163 BOOLEAN
164 NTAPI
165 ObInitSystem(
166 VOID
167 );
168
169 VOID
170 NTAPI
171 ObShutdownSystem(
172 VOID
173 );
174
175 //
176 // Directory Namespace Functions
177 //
178 BOOLEAN
179 NTAPI
180 ObpDeleteEntryDirectory(
181 IN POBP_LOOKUP_CONTEXT Context
182 );
183
184 BOOLEAN
185 NTAPI
186 ObpInsertEntryDirectory(
187 IN POBJECT_DIRECTORY Parent,
188 IN POBP_LOOKUP_CONTEXT Context,
189 IN POBJECT_HEADER ObjectHeader
190 );
191
192 PVOID
193 NTAPI
194 ObpLookupEntryDirectory(
195 IN POBJECT_DIRECTORY Directory,
196 IN PUNICODE_STRING Name,
197 IN ULONG Attributes,
198 IN UCHAR SearchShadow,
199 IN POBP_LOOKUP_CONTEXT Context
200 );
201
202 //
203 // Symbolic Link Functions
204 //
205 VOID
206 NTAPI
207 ObpDeleteSymbolicLink(
208 IN PVOID ObjectBody
209 );
210
211 NTSTATUS
212 NTAPI
213 ObpParseSymbolicLink(
214 IN PVOID ParsedObject,
215 IN PVOID ObjectType,
216 IN OUT PACCESS_STATE AccessState,
217 IN KPROCESSOR_MODE AccessMode,
218 IN ULONG Attributes,
219 IN OUT PUNICODE_STRING FullPath,
220 IN OUT PUNICODE_STRING RemainingName,
221 IN OUT PVOID Context OPTIONAL,
222 IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL,
223 OUT PVOID *NextObject
224 );
225
226 VOID
227 NTAPI
228 ObpCreateSymbolicLinkName(
229 IN POBJECT_SYMBOLIC_LINK SymbolicLink
230 );
231
232 VOID
233 NTAPI
234 ObpDeleteSymbolicLinkName(
235 IN POBJECT_SYMBOLIC_LINK SymbolicLink
236 );
237
238 //
239 // Process/Handle Table Init/Rundown
240 //
241 NTSTATUS
242 NTAPI
243 ObInitProcess(
244 IN PEPROCESS Parent OPTIONAL,
245 IN PEPROCESS Process
246 );
247
248 PHANDLE_TABLE
249 NTAPI
250 ObReferenceProcessHandleTable(
251 IN PEPROCESS Process
252 );
253
254 VOID
255 NTAPI
256 ObDereferenceProcessHandleTable(
257 IN PEPROCESS Process
258 );
259
260 VOID
261 NTAPI
262 ObKillProcess(
263 IN PEPROCESS Process
264 );
265
266 //
267 // Object Lookup Functions
268 //
269 NTSTATUS
270 NTAPI
271 ObpLookupObjectName(
272 IN HANDLE RootHandle OPTIONAL,
273 IN OUT PUNICODE_STRING ObjectName,
274 IN ULONG Attributes,
275 IN POBJECT_TYPE ObjectType,
276 IN KPROCESSOR_MODE AccessMode,
277 IN OUT PVOID ParseContext,
278 IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL,
279 IN PVOID InsertObject OPTIONAL,
280 IN OUT PACCESS_STATE AccessState,
281 OUT POBP_LOOKUP_CONTEXT LookupContext,
282 OUT PVOID *FoundObject
283 );
284
285 //
286 // Object Attribute Functions
287 //
288 BOOLEAN
289 NTAPI
290 ObpSetHandleAttributes(
291 IN OUT PHANDLE_TABLE_ENTRY HandleTableEntry,
292 IN ULONG_PTR Context
293 );
294
295 NTSTATUS
296 NTAPI
297 ObQueryDeviceMapInformation(
298 IN PEPROCESS Process,
299 OUT PPROCESS_DEVICEMAP_INFORMATION DeviceMapInfo,
300 IN ULONG Flags
301 );
302
303 //
304 // Object Lifetime Functions
305 //
306 VOID
307 NTAPI
308 ObpDeleteObject(
309 IN PVOID Object,
310 IN BOOLEAN CalledFromWorkerThread
311 );
312
313 LONG
314 FASTCALL
315 ObDereferenceObjectEx(
316 IN PVOID Object,
317 IN LONG Count
318 );
319
320 LONG
321 FASTCALL
322 ObReferenceObjectEx(
323 IN PVOID Object,
324 IN LONG Count
325 );
326
327 BOOLEAN
328 FASTCALL
329 ObReferenceObjectSafe(
330 IN PVOID Object
331 );
332
333 VOID
334 NTAPI
335 ObpReapObject(
336 IN PVOID Unused
337 );
338
339 VOID
340 FASTCALL
341 ObpSetPermanentObject(
342 IN PVOID ObjectBody,
343 IN BOOLEAN Permanent
344 );
345
346 VOID
347 NTAPI
348 ObpDeleteNameCheck(
349 IN PVOID Object
350 );
351
352 VOID
353 NTAPI
354 ObClearProcessHandleTable(
355 IN PEPROCESS Process
356 );
357
358 NTSTATUS
359 NTAPI
360 ObDuplicateObject(
361 IN PEPROCESS SourceProcess,
362 IN HANDLE SourceHandle,
363 IN PEPROCESS TargetProcess OPTIONAL,
364 IN PHANDLE TargetHandle OPTIONAL,
365 IN ACCESS_MASK DesiredAccess,
366 IN ULONG HandleAttributes,
367 IN ULONG Options,
368 IN KPROCESSOR_MODE PreviousMode
369 );
370
371 VOID
372 NTAPI
373 ObFreeObjectCreateInfoBuffer(
374 IN POBJECT_CREATE_INFORMATION ObjectCreateInfo
375 );
376
377 VOID
378 NTAPI
379 ObpFreeObjectNameBuffer(
380 IN PUNICODE_STRING Name
381 );
382
383 VOID
384 NTAPI
385 ObpDeleteObjectType(
386 IN PVOID Object
387 );
388
389 NTSTATUS
390 NTAPI
391 ObReferenceFileObjectForWrite(
392 IN HANDLE Handle,
393 IN KPROCESSOR_MODE AccessMode,
394 OUT PFILE_OBJECT *FileObject,
395 OUT POBJECT_HANDLE_INFORMATION HandleInformation
396 );
397
398 //
399 // DOS Devices Functions
400 //
401 NTSTATUS
402 NTAPI
403 ObSetDeviceMap(
404 IN PEPROCESS Process,
405 IN HANDLE DirectoryHandle);
406
407 VOID
408 NTAPI
409 ObDereferenceDeviceMap(
410 IN PEPROCESS Process
411 );
412
413 VOID
414 FASTCALL
415 ObfDereferenceDeviceMap(
416 IN PDEVICE_MAP DeviceMap
417 );
418
419 VOID
420 NTAPI
421 ObInheritDeviceMap(
422 IN PEPROCESS Parent,
423 IN PEPROCESS Process
424 );
425
426 INIT_FUNCTION
427 NTSTATUS
428 NTAPI
429 ObpCreateDosDevicesDirectory(
430 VOID
431 );
432
433 ULONG
434 NTAPI
435 ObIsLUIDDeviceMapsEnabled(
436 VOID
437 );
438
439 //
440 // Security descriptor cache functions
441 //
442 INIT_FUNCTION
443 NTSTATUS
444 NTAPI
445 ObpInitSdCache(
446 VOID
447 );
448
449 PSECURITY_DESCRIPTOR
450 NTAPI
451 ObpReferenceSecurityDescriptor(
452 IN POBJECT_HEADER ObjectHeader
453 );
454
455 //
456 // Object Security Routines
457 //
458 BOOLEAN
459 NTAPI
460 ObCheckObjectAccess(
461 IN PVOID Object,
462 IN OUT PACCESS_STATE AccessState,
463 IN BOOLEAN LockHeld,
464 IN KPROCESSOR_MODE AccessMode,
465 OUT PNTSTATUS ReturnedStatus
466 );
467
468 BOOLEAN
469 NTAPI
470 ObCheckCreateObjectAccess(
471 IN PVOID Object,
472 IN ACCESS_MASK CreateAccess,
473 IN PACCESS_STATE AccessState,
474 IN PUNICODE_STRING ComponentName,
475 IN BOOLEAN LockHeld,
476 IN KPROCESSOR_MODE AccessMode,
477 OUT PNTSTATUS AccessStatus
478 );
479
480 BOOLEAN
481 NTAPI
482 ObpCheckTraverseAccess(
483 IN PVOID Object,
484 IN ACCESS_MASK TraverseAccess,
485 IN PACCESS_STATE AccessState OPTIONAL,
486 IN BOOLEAN LockHeld,
487 IN KPROCESSOR_MODE AccessMode,
488 OUT PNTSTATUS AccessStatus
489 );
490
491 BOOLEAN
492 NTAPI
493 ObpCheckObjectReference(
494 IN PVOID Object,
495 IN OUT PACCESS_STATE AccessState,
496 IN BOOLEAN LockHeld,
497 IN KPROCESSOR_MODE AccessMode,
498 OUT PNTSTATUS AccessStatus
499 );
500
501 //
502 // Default Object Security Callback Routines
503 //
504 NTSTATUS
505 NTAPI
506 ObAssignObjectSecurityDescriptor(
507 IN PVOID Object,
508 IN PSECURITY_DESCRIPTOR SecurityDescriptor OPTIONAL,
509 IN POOL_TYPE PoolType
510 );
511
512 NTSTATUS
513 NTAPI
514 ObDeassignSecurity(
515 IN OUT PSECURITY_DESCRIPTOR *SecurityDescriptor
516 );
517
518 NTSTATUS
519 NTAPI
520 ObQuerySecurityDescriptorInfo(
521 IN PVOID Object,
522 IN PSECURITY_INFORMATION SecurityInformation,
523 OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
524 IN OUT PULONG Length,
525 IN PSECURITY_DESCRIPTOR *OutputSecurityDescriptor
526 );
527
528 NTSTATUS
529 NTAPI
530 ObSetSecurityDescriptorInfo(
531 IN PVOID Object,
532 IN PSECURITY_INFORMATION SecurityInformation,
533 IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
534 IN OUT PSECURITY_DESCRIPTOR *OutputSecurityDescriptor,
535 IN POOL_TYPE PoolType,
536 IN PGENERIC_MAPPING GenericMapping
537 );
538
539 //
540 // Executive Fast Referencing Functions
541 //
542 VOID
543 FASTCALL
544 ObInitializeFastReference(
545 IN PEX_FAST_REF FastRef,
546 IN PVOID Object
547 );
548
549 PVOID
550 FASTCALL
551 ObFastReplaceObject(
552 IN PEX_FAST_REF FastRef,
553 IN PVOID Object
554 );
555
556 PVOID
557 FASTCALL
558 ObFastReferenceObject(
559 IN PEX_FAST_REF FastRef
560 );
561
562 PVOID
563 FASTCALL
564 ObFastReferenceObjectLocked(
565 IN PEX_FAST_REF FastRef
566 );
567
568 VOID
569 FASTCALL
570 ObFastDereferenceObject(
571 IN PEX_FAST_REF FastRef,
572 IN PVOID Object
573 );
574
575 //
576 // Object Create and Object Name Capture Functions
577 //
578 NTSTATUS
579 NTAPI
580 ObpCaptureObjectName(
581 IN PUNICODE_STRING CapturedName,
582 IN PUNICODE_STRING ObjectName,
583 IN KPROCESSOR_MODE AccessMode,
584 IN BOOLEAN AllocateFromLookaside
585 );
586
587 NTSTATUS
588 NTAPI
589 ObpCaptureObjectCreateInformation(
590 IN POBJECT_ATTRIBUTES ObjectAttributes,
591 IN KPROCESSOR_MODE AccessMode,
592 IN KPROCESSOR_MODE CreatorMode,
593 IN BOOLEAN AllocateFromLookaside,
594 IN POBJECT_CREATE_INFORMATION ObjectCreateInfo,
595 OUT PUNICODE_STRING ObjectName
596 );
597
598 //
599 // Miscellanea
600 //
601 ULONG
602 NTAPI
603 ObGetProcessHandleCount(
604 IN PEPROCESS Process
605 );
606
607 //
608 // Global data inside the Object Manager
609 //
610 extern ULONG ObpTraceLevel;
611 extern KEVENT ObpDefaultObject;
612 extern KGUARDED_MUTEX ObpDeviceMapLock;
613 extern POBJECT_TYPE ObpTypeObjectType;
614 extern POBJECT_TYPE ObpDirectoryObjectType;
615 extern POBJECT_TYPE ObpSymbolicLinkObjectType;
616 extern POBJECT_DIRECTORY ObpRootDirectoryObject;
617 extern POBJECT_DIRECTORY ObpTypeDirectoryObject;
618 extern PHANDLE_TABLE ObpKernelHandleTable;
619 extern WORK_QUEUE_ITEM ObpReaperWorkItem;
620 extern volatile PVOID ObpReaperList;
621 extern GENERAL_LOOKASIDE ObpNameBufferLookasideList, ObpCreateInfoLookasideList;
622 extern BOOLEAN IoCountOperations;
623 extern ALIGNEDNAME ObpDosDevicesShortNamePrefix;
624 extern ALIGNEDNAME ObpDosDevicesShortNameRoot;
625 extern UNICODE_STRING ObpDosDevicesShortName;
626 extern WCHAR ObpUnsecureGlobalNamesBuffer[128];
627 extern ULONG ObpUnsecureGlobalNamesLength;
628 extern ULONG ObpObjectSecurityMode;
629 extern ULONG ObpProtectionMode;
630 extern ULONG ObpLUIDDeviceMapsDisabled;
631 extern ULONG ObpLUIDDeviceMapsEnabled;
632
633 //
634 // Inlined Functions
635 //
636 #include "ob_x.h"