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