ddbfeb42d928c81b03e003090e8aec184665fedd
[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 VOID
296 NTAPI
297 ObQueryDeviceMapInformation(
298 IN PEPROCESS Process,
299 OUT PPROCESS_DEVICEMAP_INFORMATION DeviceMapInfo
300 );
301
302 //
303 // Object Lifetime Functions
304 //
305 VOID
306 NTAPI
307 ObpDeleteObject(
308 IN PVOID Object,
309 IN BOOLEAN CalledFromWorkerThread
310 );
311
312 LONG
313 FASTCALL
314 ObDereferenceObjectEx(
315 IN PVOID Object,
316 IN LONG Count
317 );
318
319 LONG
320 FASTCALL
321 ObReferenceObjectEx(
322 IN PVOID Object,
323 IN LONG Count
324 );
325
326 BOOLEAN
327 FASTCALL
328 ObReferenceObjectSafe(
329 IN PVOID Object
330 );
331
332 VOID
333 NTAPI
334 ObpReapObject(
335 IN PVOID Unused
336 );
337
338 VOID
339 FASTCALL
340 ObpSetPermanentObject(
341 IN PVOID ObjectBody,
342 IN BOOLEAN Permanent
343 );
344
345 VOID
346 NTAPI
347 ObpDeleteNameCheck(
348 IN PVOID Object
349 );
350
351 VOID
352 NTAPI
353 ObClearProcessHandleTable(
354 IN PEPROCESS Process
355 );
356
357 NTSTATUS
358 NTAPI
359 ObDuplicateObject(
360 IN PEPROCESS SourceProcess,
361 IN HANDLE SourceHandle,
362 IN PEPROCESS TargetProcess OPTIONAL,
363 IN PHANDLE TargetHandle OPTIONAL,
364 IN ACCESS_MASK DesiredAccess,
365 IN ULONG HandleAttributes,
366 IN ULONG Options,
367 IN KPROCESSOR_MODE PreviousMode
368 );
369
370 VOID
371 NTAPI
372 ObFreeObjectCreateInfoBuffer(
373 IN POBJECT_CREATE_INFORMATION ObjectCreateInfo
374 );
375
376 VOID
377 NTAPI
378 ObpFreeObjectNameBuffer(
379 IN PUNICODE_STRING Name
380 );
381
382 VOID
383 NTAPI
384 ObpDeleteObjectType(
385 IN PVOID Object
386 );
387
388 NTSTATUS
389 NTAPI
390 ObReferenceFileObjectForWrite(
391 IN HANDLE Handle,
392 IN KPROCESSOR_MODE AccessMode,
393 OUT PFILE_OBJECT *FileObject,
394 OUT POBJECT_HANDLE_INFORMATION HandleInformation
395 );
396
397 //
398 // DOS Devices Functions
399 //
400 NTSTATUS
401 NTAPI
402 ObSetDeviceMap(
403 IN PEPROCESS Process,
404 IN HANDLE DirectoryHandle);
405
406 VOID
407 NTAPI
408 ObDereferenceDeviceMap(
409 IN PEPROCESS Process
410 );
411
412 VOID
413 FASTCALL
414 ObfDereferenceDeviceMap(
415 IN PDEVICE_MAP DeviceMap
416 );
417
418 VOID
419 NTAPI
420 ObInheritDeviceMap(
421 IN PEPROCESS Parent,
422 IN PEPROCESS Process
423 );
424
425 INIT_FUNCTION
426 NTSTATUS
427 NTAPI
428 ObpCreateDosDevicesDirectory(
429 VOID
430 );
431
432 //
433 // Security descriptor cache functions
434 //
435 INIT_FUNCTION
436 NTSTATUS
437 NTAPI
438 ObpInitSdCache(
439 VOID
440 );
441
442 PSECURITY_DESCRIPTOR
443 NTAPI
444 ObpReferenceSecurityDescriptor(
445 IN POBJECT_HEADER ObjectHeader
446 );
447
448 //
449 // Object Security Routines
450 //
451 BOOLEAN
452 NTAPI
453 ObCheckObjectAccess(
454 IN PVOID Object,
455 IN OUT PACCESS_STATE AccessState,
456 IN BOOLEAN LockHeld,
457 IN KPROCESSOR_MODE AccessMode,
458 OUT PNTSTATUS ReturnedStatus
459 );
460
461 BOOLEAN
462 NTAPI
463 ObCheckCreateObjectAccess(
464 IN PVOID Object,
465 IN ACCESS_MASK CreateAccess,
466 IN PACCESS_STATE AccessState,
467 IN PUNICODE_STRING ComponentName,
468 IN BOOLEAN LockHeld,
469 IN KPROCESSOR_MODE AccessMode,
470 OUT PNTSTATUS AccessStatus
471 );
472
473 BOOLEAN
474 NTAPI
475 ObpCheckTraverseAccess(
476 IN PVOID Object,
477 IN ACCESS_MASK TraverseAccess,
478 IN PACCESS_STATE AccessState OPTIONAL,
479 IN BOOLEAN LockHeld,
480 IN KPROCESSOR_MODE AccessMode,
481 OUT PNTSTATUS AccessStatus
482 );
483
484 BOOLEAN
485 NTAPI
486 ObpCheckObjectReference(
487 IN PVOID Object,
488 IN OUT PACCESS_STATE AccessState,
489 IN BOOLEAN LockHeld,
490 IN KPROCESSOR_MODE AccessMode,
491 OUT PNTSTATUS AccessStatus
492 );
493
494 //
495 // Default Object Security Callback Routines
496 //
497 NTSTATUS
498 NTAPI
499 ObAssignObjectSecurityDescriptor(
500 IN PVOID Object,
501 IN PSECURITY_DESCRIPTOR SecurityDescriptor OPTIONAL,
502 IN POOL_TYPE PoolType
503 );
504
505 NTSTATUS
506 NTAPI
507 ObDeassignSecurity(
508 IN OUT PSECURITY_DESCRIPTOR *SecurityDescriptor
509 );
510
511 NTSTATUS
512 NTAPI
513 ObQuerySecurityDescriptorInfo(
514 IN PVOID Object,
515 IN PSECURITY_INFORMATION SecurityInformation,
516 OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
517 IN OUT PULONG Length,
518 IN PSECURITY_DESCRIPTOR *OutputSecurityDescriptor
519 );
520
521 NTSTATUS
522 NTAPI
523 ObSetSecurityDescriptorInfo(
524 IN PVOID Object,
525 IN PSECURITY_INFORMATION SecurityInformation,
526 IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
527 IN OUT PSECURITY_DESCRIPTOR *OutputSecurityDescriptor,
528 IN POOL_TYPE PoolType,
529 IN PGENERIC_MAPPING GenericMapping
530 );
531
532 //
533 // Executive Fast Referencing Functions
534 //
535 VOID
536 FASTCALL
537 ObInitializeFastReference(
538 IN PEX_FAST_REF FastRef,
539 IN PVOID Object
540 );
541
542 PVOID
543 FASTCALL
544 ObFastReplaceObject(
545 IN PEX_FAST_REF FastRef,
546 IN PVOID Object
547 );
548
549 PVOID
550 FASTCALL
551 ObFastReferenceObject(
552 IN PEX_FAST_REF FastRef
553 );
554
555 PVOID
556 FASTCALL
557 ObFastReferenceObjectLocked(
558 IN PEX_FAST_REF FastRef
559 );
560
561 VOID
562 FASTCALL
563 ObFastDereferenceObject(
564 IN PEX_FAST_REF FastRef,
565 IN PVOID Object
566 );
567
568 //
569 // Object Create and Object Name Capture Functions
570 //
571 NTSTATUS
572 NTAPI
573 ObpCaptureObjectName(
574 IN PUNICODE_STRING CapturedName,
575 IN PUNICODE_STRING ObjectName,
576 IN KPROCESSOR_MODE AccessMode,
577 IN BOOLEAN AllocateFromLookaside
578 );
579
580 NTSTATUS
581 NTAPI
582 ObpCaptureObjectCreateInformation(
583 IN POBJECT_ATTRIBUTES ObjectAttributes,
584 IN KPROCESSOR_MODE AccessMode,
585 IN KPROCESSOR_MODE CreatorMode,
586 IN BOOLEAN AllocateFromLookaside,
587 IN POBJECT_CREATE_INFORMATION ObjectCreateInfo,
588 OUT PUNICODE_STRING ObjectName
589 );
590
591 //
592 // Miscellanea
593 //
594 ULONG
595 NTAPI
596 ObGetProcessHandleCount(
597 IN PEPROCESS Process
598 );
599
600 //
601 // Global data inside the Object Manager
602 //
603 extern ULONG ObpTraceLevel;
604 extern KEVENT ObpDefaultObject;
605 extern KGUARDED_MUTEX ObpDeviceMapLock;
606 extern POBJECT_TYPE ObpTypeObjectType;
607 extern POBJECT_TYPE ObpDirectoryObjectType;
608 extern POBJECT_TYPE ObpSymbolicLinkObjectType;
609 extern POBJECT_DIRECTORY ObpRootDirectoryObject;
610 extern POBJECT_DIRECTORY ObpTypeDirectoryObject;
611 extern PHANDLE_TABLE ObpKernelHandleTable;
612 extern WORK_QUEUE_ITEM ObpReaperWorkItem;
613 extern volatile PVOID ObpReaperList;
614 extern GENERAL_LOOKASIDE ObpNameBufferLookasideList, ObpCreateInfoLookasideList;
615 extern BOOLEAN IoCountOperations;
616 extern ALIGNEDNAME ObpDosDevicesShortNamePrefix;
617 extern ALIGNEDNAME ObpDosDevicesShortNameRoot;
618 extern UNICODE_STRING ObpDosDevicesShortName;
619 extern WCHAR ObpUnsecureGlobalNamesBuffer[128];
620 extern ULONG ObpUnsecureGlobalNamesLength;
621 extern ULONG ObpObjectSecurityMode;
622 extern ULONG ObpProtectionMode;
623 extern ULONG ObpLUIDDeviceMapsDisabled;
624
625 //
626 // Inlined Functions
627 //
628 #include "ob_x.h"