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