[CDROM] Forcibly declare our CD devices to the MountMgr
[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
408 NTSTATUS
409 NTAPI
410 ObSetDirectoryDeviceMap(OUT PDEVICE_MAP * DeviceMap,
411 IN HANDLE DirectoryHandle
412 );
413
414 VOID
415 NTAPI
416 ObDereferenceDeviceMap(
417 IN PEPROCESS Process
418 );
419
420 VOID
421 FASTCALL
422 ObfDereferenceDeviceMap(
423 IN PDEVICE_MAP DeviceMap
424 );
425
426 VOID
427 NTAPI
428 ObInheritDeviceMap(
429 IN PEPROCESS Parent,
430 IN PEPROCESS Process
431 );
432
433 INIT_FUNCTION
434 NTSTATUS
435 NTAPI
436 ObpCreateDosDevicesDirectory(
437 VOID
438 );
439
440 ULONG
441 NTAPI
442 ObIsLUIDDeviceMapsEnabled(
443 VOID
444 );
445
446 PDEVICE_MAP
447 NTAPI
448 ObpReferenceDeviceMap(
449 VOID
450 );
451
452 //
453 // Security descriptor cache functions
454 //
455 INIT_FUNCTION
456 NTSTATUS
457 NTAPI
458 ObpInitSdCache(
459 VOID
460 );
461
462 PSECURITY_DESCRIPTOR
463 NTAPI
464 ObpReferenceSecurityDescriptor(
465 IN POBJECT_HEADER ObjectHeader
466 );
467
468 //
469 // Object Security Routines
470 //
471 BOOLEAN
472 NTAPI
473 ObCheckObjectAccess(
474 IN PVOID Object,
475 IN OUT PACCESS_STATE AccessState,
476 IN BOOLEAN LockHeld,
477 IN KPROCESSOR_MODE AccessMode,
478 OUT PNTSTATUS ReturnedStatus
479 );
480
481 BOOLEAN
482 NTAPI
483 ObCheckCreateObjectAccess(
484 IN PVOID Object,
485 IN ACCESS_MASK CreateAccess,
486 IN PACCESS_STATE AccessState,
487 IN PUNICODE_STRING ComponentName,
488 IN BOOLEAN LockHeld,
489 IN KPROCESSOR_MODE AccessMode,
490 OUT PNTSTATUS AccessStatus
491 );
492
493 BOOLEAN
494 NTAPI
495 ObpCheckTraverseAccess(
496 IN PVOID Object,
497 IN ACCESS_MASK TraverseAccess,
498 IN PACCESS_STATE AccessState OPTIONAL,
499 IN BOOLEAN LockHeld,
500 IN KPROCESSOR_MODE AccessMode,
501 OUT PNTSTATUS AccessStatus
502 );
503
504 BOOLEAN
505 NTAPI
506 ObpCheckObjectReference(
507 IN PVOID Object,
508 IN OUT PACCESS_STATE AccessState,
509 IN BOOLEAN LockHeld,
510 IN KPROCESSOR_MODE AccessMode,
511 OUT PNTSTATUS AccessStatus
512 );
513
514 //
515 // Default Object Security Callback Routines
516 //
517 NTSTATUS
518 NTAPI
519 ObAssignObjectSecurityDescriptor(
520 IN PVOID Object,
521 IN PSECURITY_DESCRIPTOR SecurityDescriptor OPTIONAL,
522 IN POOL_TYPE PoolType
523 );
524
525 NTSTATUS
526 NTAPI
527 ObDeassignSecurity(
528 IN OUT PSECURITY_DESCRIPTOR *SecurityDescriptor
529 );
530
531 NTSTATUS
532 NTAPI
533 ObQuerySecurityDescriptorInfo(
534 IN PVOID Object,
535 IN PSECURITY_INFORMATION SecurityInformation,
536 OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
537 IN OUT PULONG Length,
538 IN PSECURITY_DESCRIPTOR *OutputSecurityDescriptor
539 );
540
541 NTSTATUS
542 NTAPI
543 ObSetSecurityDescriptorInfo(
544 IN PVOID Object,
545 IN PSECURITY_INFORMATION SecurityInformation,
546 IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
547 IN OUT PSECURITY_DESCRIPTOR *OutputSecurityDescriptor,
548 IN POOL_TYPE PoolType,
549 IN PGENERIC_MAPPING GenericMapping
550 );
551
552 //
553 // Executive Fast Referencing Functions
554 //
555 VOID
556 FASTCALL
557 ObInitializeFastReference(
558 IN PEX_FAST_REF FastRef,
559 IN PVOID Object
560 );
561
562 PVOID
563 FASTCALL
564 ObFastReplaceObject(
565 IN PEX_FAST_REF FastRef,
566 IN PVOID Object
567 );
568
569 PVOID
570 FASTCALL
571 ObFastReferenceObject(
572 IN PEX_FAST_REF FastRef
573 );
574
575 PVOID
576 FASTCALL
577 ObFastReferenceObjectLocked(
578 IN PEX_FAST_REF FastRef
579 );
580
581 VOID
582 FASTCALL
583 ObFastDereferenceObject(
584 IN PEX_FAST_REF FastRef,
585 IN PVOID Object
586 );
587
588 //
589 // Object Create and Object Name Capture Functions
590 //
591 NTSTATUS
592 NTAPI
593 ObpCaptureObjectName(
594 IN PUNICODE_STRING CapturedName,
595 IN PUNICODE_STRING ObjectName,
596 IN KPROCESSOR_MODE AccessMode,
597 IN BOOLEAN AllocateFromLookaside
598 );
599
600 NTSTATUS
601 NTAPI
602 ObpCaptureObjectCreateInformation(
603 IN POBJECT_ATTRIBUTES ObjectAttributes,
604 IN KPROCESSOR_MODE AccessMode,
605 IN KPROCESSOR_MODE CreatorMode,
606 IN BOOLEAN AllocateFromLookaside,
607 IN POBJECT_CREATE_INFORMATION ObjectCreateInfo,
608 OUT PUNICODE_STRING ObjectName
609 );
610
611 //
612 // Miscellanea
613 //
614 ULONG
615 NTAPI
616 ObGetProcessHandleCount(
617 IN PEPROCESS Process
618 );
619
620 //
621 // Global data inside the Object Manager
622 //
623 extern ULONG ObpTraceLevel;
624 extern KEVENT ObpDefaultObject;
625 extern KGUARDED_MUTEX ObpDeviceMapLock;
626 extern POBJECT_TYPE ObpTypeObjectType;
627 extern POBJECT_TYPE ObpDirectoryObjectType;
628 extern POBJECT_TYPE ObpSymbolicLinkObjectType;
629 extern POBJECT_DIRECTORY ObpRootDirectoryObject;
630 extern POBJECT_DIRECTORY ObpTypeDirectoryObject;
631 extern PHANDLE_TABLE ObpKernelHandleTable;
632 extern WORK_QUEUE_ITEM ObpReaperWorkItem;
633 extern volatile PVOID ObpReaperList;
634 extern GENERAL_LOOKASIDE ObpNameBufferLookasideList, ObpCreateInfoLookasideList;
635 extern BOOLEAN IoCountOperations;
636 extern ALIGNEDNAME ObpDosDevicesShortNamePrefix;
637 extern ALIGNEDNAME ObpDosDevicesShortNameRoot;
638 extern UNICODE_STRING ObpDosDevicesShortName;
639 extern WCHAR ObpUnsecureGlobalNamesBuffer[128];
640 extern ULONG ObpUnsecureGlobalNamesLength;
641 extern ULONG ObpObjectSecurityMode;
642 extern ULONG ObpProtectionMode;
643 extern ULONG ObpLUIDDeviceMapsDisabled;
644 extern ULONG ObpLUIDDeviceMapsEnabled;
645
646 //
647 // Inlined Functions
648 //
649 #include "ob_x.h"