Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1119 lines
28 KiB

  1. /*++ BUILD Version: 0002 // Increment this if a change has global effects
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. ob.h
  5. Abstract:
  6. This module contains the object manager structure public data
  7. structures and procedure prototypes to be used within the NT
  8. system.
  9. Author:
  10. Steve Wood (stevewo) 28-Mar-1989
  11. Revision History:
  12. --*/
  13. #ifndef _OB_
  14. #define _OB_
  15. //
  16. // System Initialization procedure for OB subcomponent of NTOS
  17. //
  18. BOOLEAN
  19. ObInitSystem( VOID );
  20. VOID
  21. ObShutdownSystem(
  22. IN ULONG Phase
  23. );
  24. NTSTATUS
  25. ObInitProcess(
  26. PEPROCESS ParentProcess OPTIONAL,
  27. PEPROCESS NewProcess
  28. );
  29. VOID
  30. ObInitProcess2(
  31. PEPROCESS NewProcess
  32. );
  33. VOID
  34. ObKillProcess(
  35. PEPROCESS Process
  36. );
  37. VOID
  38. ObClearProcessHandleTable (
  39. PEPROCESS Process
  40. );
  41. VOID
  42. ObDereferenceProcessHandleTable (
  43. PEPROCESS SourceProcess
  44. );
  45. PHANDLE_TABLE
  46. ObReferenceProcessHandleTable (
  47. PEPROCESS SourceProcess
  48. );
  49. ULONG
  50. ObGetProcessHandleCount (
  51. PEPROCESS Process
  52. );
  53. NTSTATUS
  54. ObDuplicateObject (
  55. IN PEPROCESS SourceProcess,
  56. IN HANDLE SourceHandle,
  57. IN PEPROCESS TargetProcess OPTIONAL,
  58. OUT PHANDLE TargetHandle OPTIONAL,
  59. IN ACCESS_MASK DesiredAccess,
  60. IN ULONG HandleAttributes,
  61. IN ULONG Options,
  62. IN KPROCESSOR_MODE PreviousMode
  63. );
  64. // begin_ntddk begin_wdm begin_nthal begin_ntosp begin_ntifs
  65. //
  66. // Object Manager types
  67. //
  68. typedef struct _OBJECT_HANDLE_INFORMATION {
  69. ULONG HandleAttributes;
  70. ACCESS_MASK GrantedAccess;
  71. } OBJECT_HANDLE_INFORMATION, *POBJECT_HANDLE_INFORMATION;
  72. // end_ntddk end_wdm end_nthal end_ntifs
  73. typedef struct _OBJECT_DUMP_CONTROL {
  74. PVOID Stream;
  75. ULONG Detail;
  76. } OB_DUMP_CONTROL, *POB_DUMP_CONTROL;
  77. typedef VOID (*OB_DUMP_METHOD)(
  78. IN PVOID Object,
  79. IN POB_DUMP_CONTROL Control OPTIONAL
  80. );
  81. typedef enum _OB_OPEN_REASON {
  82. ObCreateHandle,
  83. ObOpenHandle,
  84. ObDuplicateHandle,
  85. ObInheritHandle,
  86. ObMaxOpenReason
  87. } OB_OPEN_REASON;
  88. typedef NTSTATUS (*OB_OPEN_METHOD)(
  89. IN OB_OPEN_REASON OpenReason,
  90. IN PEPROCESS Process OPTIONAL,
  91. IN PVOID Object,
  92. IN ACCESS_MASK GrantedAccess,
  93. IN ULONG HandleCount
  94. );
  95. typedef BOOLEAN (*OB_OKAYTOCLOSE_METHOD)(
  96. IN PEPROCESS Process OPTIONAL,
  97. IN PVOID Object,
  98. IN HANDLE Handle,
  99. IN KPROCESSOR_MODE PreviousMode
  100. );
  101. typedef VOID (*OB_CLOSE_METHOD)(
  102. IN PEPROCESS Process OPTIONAL,
  103. IN PVOID Object,
  104. IN ACCESS_MASK GrantedAccess,
  105. IN ULONG_PTR ProcessHandleCount,
  106. IN ULONG_PTR SystemHandleCount
  107. );
  108. typedef VOID (*OB_DELETE_METHOD)(
  109. IN PVOID Object
  110. );
  111. typedef NTSTATUS (*OB_PARSE_METHOD)(
  112. IN PVOID ParseObject,
  113. IN PVOID ObjectType,
  114. IN OUT PACCESS_STATE AccessState,
  115. IN KPROCESSOR_MODE AccessMode,
  116. IN ULONG Attributes,
  117. IN OUT PUNICODE_STRING CompleteName,
  118. IN OUT PUNICODE_STRING RemainingName,
  119. IN OUT PVOID Context OPTIONAL,
  120. IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL,
  121. OUT PVOID *Object
  122. );
  123. typedef NTSTATUS (*OB_SECURITY_METHOD)(
  124. IN PVOID Object,
  125. IN SECURITY_OPERATION_CODE OperationCode,
  126. IN PSECURITY_INFORMATION SecurityInformation,
  127. IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
  128. IN OUT PULONG CapturedLength,
  129. IN OUT PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor,
  130. IN POOL_TYPE PoolType,
  131. IN PGENERIC_MAPPING GenericMapping
  132. );
  133. typedef NTSTATUS (*OB_QUERYNAME_METHOD)(
  134. IN PVOID Object,
  135. IN BOOLEAN HasObjectName,
  136. OUT POBJECT_NAME_INFORMATION ObjectNameInfo,
  137. IN ULONG Length,
  138. OUT PULONG ReturnLength,
  139. IN KPROCESSOR_MODE Mode
  140. );
  141. /*
  142. A security method and its caller must obey the following w.r.t.
  143. capturing and probing parameters:
  144. For a query operation, the caller must pass a kernel space address for
  145. CapturedLength. The caller should be able to assume that it points to
  146. valid data that will not change. In addition, the SecurityDescriptor
  147. parameter (which will receive the result of the query operation) must
  148. be probed for write up to the length given in CapturedLength. The
  149. security method itself must always write to the SecurityDescriptor
  150. buffer in a try clause in case the caller de-allocates it.
  151. For a set operation, the SecurityDescriptor parameter must have
  152. been captured via SeCaptureSecurityDescriptor. This parameter is
  153. not optional, and therefore may not be NULL.
  154. */
  155. //
  156. // Prototypes for Win32 WindowStation and Desktop object callout routines
  157. //
  158. typedef struct _WIN32_OPENMETHOD_PARAMETERS {
  159. OB_OPEN_REASON OpenReason;
  160. PEPROCESS Process;
  161. PVOID Object;
  162. ACCESS_MASK GrantedAccess;
  163. ULONG HandleCount;
  164. } WIN32_OPENMETHOD_PARAMETERS, *PKWIN32_OPENMETHOD_PARAMETERS;
  165. typedef
  166. NTSTATUS
  167. (*PKWIN32_OPENMETHOD_CALLOUT) ( PKWIN32_OPENMETHOD_PARAMETERS );
  168. extern PKWIN32_OPENMETHOD_CALLOUT ExDesktopOpenProcedureCallout;
  169. extern PKWIN32_OPENMETHOD_CALLOUT ExWindowStationOpenProcedureCallout;
  170. typedef struct _WIN32_OKAYTOCLOSEMETHOD_PARAMETERS {
  171. PEPROCESS Process;
  172. PVOID Object;
  173. HANDLE Handle;
  174. KPROCESSOR_MODE PreviousMode;
  175. } WIN32_OKAYTOCLOSEMETHOD_PARAMETERS, *PKWIN32_OKAYTOCLOSEMETHOD_PARAMETERS;
  176. typedef
  177. NTSTATUS
  178. (*PKWIN32_OKTOCLOSEMETHOD_CALLOUT) ( PKWIN32_OKAYTOCLOSEMETHOD_PARAMETERS );
  179. extern PKWIN32_OKTOCLOSEMETHOD_CALLOUT ExDesktopOkToCloseProcedureCallout;
  180. extern PKWIN32_OKTOCLOSEMETHOD_CALLOUT ExWindowStationOkToCloseProcedureCallout;
  181. typedef struct _WIN32_CLOSEMETHOD_PARAMETERS {
  182. PEPROCESS Process;
  183. PVOID Object;
  184. ACCESS_MASK GrantedAccess;
  185. ULONG ProcessHandleCount;
  186. ULONG SystemHandleCount;
  187. } WIN32_CLOSEMETHOD_PARAMETERS, *PKWIN32_CLOSEMETHOD_PARAMETERS;
  188. typedef
  189. NTSTATUS
  190. (*PKWIN32_CLOSEMETHOD_CALLOUT) ( PKWIN32_CLOSEMETHOD_PARAMETERS );
  191. extern PKWIN32_CLOSEMETHOD_CALLOUT ExDesktopCloseProcedureCallout;
  192. extern PKWIN32_CLOSEMETHOD_CALLOUT ExWindowStationCloseProcedureCallout;
  193. typedef struct _WIN32_DELETEMETHOD_PARAMETERS {
  194. PVOID Object;
  195. } WIN32_DELETEMETHOD_PARAMETERS, *PKWIN32_DELETEMETHOD_PARAMETERS;
  196. typedef
  197. NTSTATUS
  198. (*PKWIN32_DELETEMETHOD_CALLOUT) ( PKWIN32_DELETEMETHOD_PARAMETERS );
  199. extern PKWIN32_DELETEMETHOD_CALLOUT ExDesktopDeleteProcedureCallout;
  200. extern PKWIN32_DELETEMETHOD_CALLOUT ExWindowStationDeleteProcedureCallout;
  201. typedef struct _WIN32_PARSEMETHOD_PARAMETERS {
  202. PVOID ParseObject;
  203. PVOID ObjectType;
  204. PACCESS_STATE AccessState;
  205. KPROCESSOR_MODE AccessMode;
  206. ULONG Attributes;
  207. PUNICODE_STRING CompleteName;
  208. PUNICODE_STRING RemainingName;
  209. PVOID Context OPTIONAL;
  210. PSECURITY_QUALITY_OF_SERVICE SecurityQos;
  211. PVOID *Object;
  212. } WIN32_PARSEMETHOD_PARAMETERS, *PKWIN32_PARSEMETHOD_PARAMETERS;
  213. typedef
  214. NTSTATUS
  215. (*PKWIN32_PARSEMETHOD_CALLOUT) ( PKWIN32_PARSEMETHOD_PARAMETERS );
  216. extern PKWIN32_PARSEMETHOD_CALLOUT ExWindowStationParseProcedureCallout;
  217. //
  218. // Object Type Structure
  219. //
  220. typedef struct _OBJECT_TYPE_INITIALIZER {
  221. USHORT Length;
  222. BOOLEAN UseDefaultObject;
  223. BOOLEAN CaseInsensitive;
  224. ULONG InvalidAttributes;
  225. GENERIC_MAPPING GenericMapping;
  226. ULONG ValidAccessMask;
  227. BOOLEAN SecurityRequired;
  228. BOOLEAN MaintainHandleCount;
  229. BOOLEAN MaintainTypeList;
  230. POOL_TYPE PoolType;
  231. ULONG DefaultPagedPoolCharge;
  232. ULONG DefaultNonPagedPoolCharge;
  233. OB_DUMP_METHOD DumpProcedure;
  234. OB_OPEN_METHOD OpenProcedure;
  235. OB_CLOSE_METHOD CloseProcedure;
  236. OB_DELETE_METHOD DeleteProcedure;
  237. OB_PARSE_METHOD ParseProcedure;
  238. OB_SECURITY_METHOD SecurityProcedure;
  239. OB_QUERYNAME_METHOD QueryNameProcedure;
  240. OB_OKAYTOCLOSE_METHOD OkayToCloseProcedure;
  241. } OBJECT_TYPE_INITIALIZER, *POBJECT_TYPE_INITIALIZER;
  242. #define OBJECT_LOCK_COUNT 4
  243. typedef struct _OBJECT_TYPE {
  244. ERESOURCE Mutex;
  245. LIST_ENTRY TypeList;
  246. UNICODE_STRING Name; // Copy from object header for convenience
  247. PVOID DefaultObject;
  248. ULONG Index;
  249. ULONG TotalNumberOfObjects;
  250. ULONG TotalNumberOfHandles;
  251. ULONG HighWaterNumberOfObjects;
  252. ULONG HighWaterNumberOfHandles;
  253. OBJECT_TYPE_INITIALIZER TypeInfo;
  254. #ifdef POOL_TAGGING
  255. ULONG Key;
  256. #endif //POOL_TAGGING
  257. ERESOURCE ObjectLocks[ OBJECT_LOCK_COUNT ];
  258. } OBJECT_TYPE, *POBJECT_TYPE;
  259. //
  260. // Object Directory Structure
  261. //
  262. #define NUMBER_HASH_BUCKETS 37
  263. #define OBJ_INVALID_SESSION_ID 0xFFFFFFFF
  264. typedef struct _OBJECT_DIRECTORY {
  265. struct _OBJECT_DIRECTORY_ENTRY *HashBuckets[ NUMBER_HASH_BUCKETS ];
  266. EX_PUSH_LOCK Lock;
  267. struct _DEVICE_MAP *DeviceMap;
  268. ULONG SessionId;
  269. #if 0
  270. USHORT Reserved;
  271. USHORT SymbolicLinkUsageCount;
  272. #endif
  273. } OBJECT_DIRECTORY, *POBJECT_DIRECTORY;
  274. // end_ntosp
  275. //
  276. // Object Directory Entry Structure
  277. //
  278. typedef struct _OBJECT_DIRECTORY_ENTRY {
  279. struct _OBJECT_DIRECTORY_ENTRY *ChainLink;
  280. PVOID Object;
  281. } OBJECT_DIRECTORY_ENTRY, *POBJECT_DIRECTORY_ENTRY;
  282. //
  283. // Symbolic Link Object Structure
  284. //
  285. typedef struct _OBJECT_SYMBOLIC_LINK {
  286. LARGE_INTEGER CreationTime;
  287. UNICODE_STRING LinkTarget;
  288. UNICODE_STRING LinkTargetRemaining;
  289. PVOID LinkTargetObject;
  290. ULONG DosDeviceDriveIndex; // 1-based index into KUSER_SHARED_DATA.DosDeviceDriveType
  291. } OBJECT_SYMBOLIC_LINK, *POBJECT_SYMBOLIC_LINK;
  292. //
  293. // Device Map Structure
  294. //
  295. typedef struct _DEVICE_MAP {
  296. POBJECT_DIRECTORY DosDevicesDirectory;
  297. POBJECT_DIRECTORY GlobalDosDevicesDirectory;
  298. ULONG ReferenceCount;
  299. ULONG DriveMap;
  300. UCHAR DriveType[ 32 ];
  301. } DEVICE_MAP, *PDEVICE_MAP;
  302. extern PDEVICE_MAP ObSystemDeviceMap;
  303. //
  304. // Object Handle Count Database
  305. //
  306. typedef struct _OBJECT_HANDLE_COUNT_ENTRY {
  307. PEPROCESS Process;
  308. ULONG HandleCount;
  309. } OBJECT_HANDLE_COUNT_ENTRY, *POBJECT_HANDLE_COUNT_ENTRY;
  310. typedef struct _OBJECT_HANDLE_COUNT_DATABASE {
  311. ULONG CountEntries;
  312. OBJECT_HANDLE_COUNT_ENTRY HandleCountEntries[ 1 ];
  313. } OBJECT_HANDLE_COUNT_DATABASE, *POBJECT_HANDLE_COUNT_DATABASE;
  314. //
  315. // Object Header Structure
  316. //
  317. // The SecurityQuotaCharged is the amount of quota charged to cover
  318. // the GROUP and DISCRETIONARY ACL fields of the security descriptor
  319. // only. The OWNER and SYSTEM ACL fields get charged for at a fixed
  320. // rate that may be less than or greater than the amount actually used.
  321. //
  322. // If the object has no security, then the SecurityQuotaCharged and the
  323. // SecurityQuotaInUse fields are set to zero.
  324. //
  325. // Modification of the OWNER and SYSTEM ACL fields should never fail
  326. // due to quota exceeded problems. Modifications to the GROUP and
  327. // DISCRETIONARY ACL fields may fail due to quota exceeded problems.
  328. //
  329. //
  330. typedef struct _OBJECT_CREATE_INFORMATION {
  331. ULONG Attributes;
  332. HANDLE RootDirectory;
  333. PVOID ParseContext;
  334. KPROCESSOR_MODE ProbeMode;
  335. ULONG PagedPoolCharge;
  336. ULONG NonPagedPoolCharge;
  337. ULONG SecurityDescriptorCharge;
  338. PSECURITY_DESCRIPTOR SecurityDescriptor;
  339. PSECURITY_QUALITY_OF_SERVICE SecurityQos;
  340. SECURITY_QUALITY_OF_SERVICE SecurityQualityOfService;
  341. } OBJECT_CREATE_INFORMATION;
  342. // begin_ntosp
  343. typedef struct _OBJECT_CREATE_INFORMATION *POBJECT_CREATE_INFORMATION;;
  344. typedef struct _OBJECT_HEADER {
  345. LONG_PTR PointerCount;
  346. union {
  347. LONG_PTR HandleCount;
  348. PVOID NextToFree;
  349. };
  350. POBJECT_TYPE Type;
  351. UCHAR NameInfoOffset;
  352. UCHAR HandleInfoOffset;
  353. UCHAR QuotaInfoOffset;
  354. UCHAR Flags;
  355. union {
  356. POBJECT_CREATE_INFORMATION ObjectCreateInfo;
  357. PVOID QuotaBlockCharged;
  358. };
  359. PSECURITY_DESCRIPTOR SecurityDescriptor;
  360. QUAD Body;
  361. } OBJECT_HEADER, *POBJECT_HEADER;
  362. // end_ntosp
  363. typedef struct _OBJECT_HEADER_QUOTA_INFO {
  364. ULONG PagedPoolCharge;
  365. ULONG NonPagedPoolCharge;
  366. ULONG SecurityDescriptorCharge;
  367. PEPROCESS ExclusiveProcess;
  368. #ifdef _WIN64
  369. ULONG64 Reserved; // Win64 requires these structures to be 16 byte aligned.
  370. #endif
  371. } OBJECT_HEADER_QUOTA_INFO, *POBJECT_HEADER_QUOTA_INFO;
  372. typedef struct _OBJECT_HEADER_HANDLE_INFO {
  373. union {
  374. POBJECT_HANDLE_COUNT_DATABASE HandleCountDataBase;
  375. OBJECT_HANDLE_COUNT_ENTRY SingleEntry;
  376. };
  377. } OBJECT_HEADER_HANDLE_INFO, *POBJECT_HEADER_HANDLE_INFO;
  378. // begin_ntosp
  379. typedef struct _OBJECT_HEADER_NAME_INFO {
  380. POBJECT_DIRECTORY Directory;
  381. UNICODE_STRING Name;
  382. ULONG QueryReferences;
  383. #if DBG
  384. ULONG Reserved2;
  385. LONG DbgDereferenceCount;
  386. #ifdef _WIN64
  387. ULONG64 Reserved3; // Win64 requires these structures to be 16 byte aligned.
  388. #endif
  389. #endif
  390. } OBJECT_HEADER_NAME_INFO, *POBJECT_HEADER_NAME_INFO;
  391. // end_ntosp
  392. typedef struct _OBJECT_HEADER_CREATOR_INFO {
  393. LIST_ENTRY TypeList;
  394. HANDLE CreatorUniqueProcess;
  395. USHORT CreatorBackTraceIndex;
  396. USHORT Reserved;
  397. } OBJECT_HEADER_CREATOR_INFO, *POBJECT_HEADER_CREATOR_INFO;
  398. #define OB_FLAG_NEW_OBJECT 0x01
  399. #define OB_FLAG_KERNEL_OBJECT 0x02
  400. #define OB_FLAG_CREATOR_INFO 0x04
  401. #define OB_FLAG_EXCLUSIVE_OBJECT 0x08
  402. #define OB_FLAG_PERMANENT_OBJECT 0x10
  403. #define OB_FLAG_DEFAULT_SECURITY_QUOTA 0x20
  404. #define OB_FLAG_SINGLE_HANDLE_ENTRY 0x40
  405. #define OB_FLAG_DELETED_INLINE 0x80
  406. // begin_ntosp
  407. #define OBJECT_TO_OBJECT_HEADER( o ) \
  408. CONTAINING_RECORD( (o), OBJECT_HEADER, Body )
  409. // end_ntosp
  410. #define OBJECT_HEADER_TO_EXCLUSIVE_PROCESS( oh ) ((oh->Flags & OB_FLAG_EXCLUSIVE_OBJECT) == 0 ? \
  411. NULL : (((POBJECT_HEADER_QUOTA_INFO)((PCHAR)(oh) - (oh)->QuotaInfoOffset))->ExclusiveProcess))
  412. #define OBJECT_HEADER_TO_QUOTA_INFO( oh ) ((POBJECT_HEADER_QUOTA_INFO) \
  413. ((oh)->QuotaInfoOffset == 0 ? NULL : ((PCHAR)(oh) - (oh)->QuotaInfoOffset)))
  414. #define OBJECT_HEADER_TO_HANDLE_INFO( oh ) ((POBJECT_HEADER_HANDLE_INFO) \
  415. ((oh)->HandleInfoOffset == 0 ? NULL : ((PCHAR)(oh) - (oh)->HandleInfoOffset)))
  416. // begin_ntosp
  417. #define OBJECT_HEADER_TO_NAME_INFO( oh ) ((POBJECT_HEADER_NAME_INFO) \
  418. ((oh)->NameInfoOffset == 0 ? NULL : ((PCHAR)(oh) - (oh)->NameInfoOffset)))
  419. #define OBJECT_HEADER_TO_CREATOR_INFO( oh ) ((POBJECT_HEADER_CREATOR_INFO) \
  420. (((oh)->Flags & OB_FLAG_CREATOR_INFO) == 0 ? NULL : ((PCHAR)(oh) - sizeof(OBJECT_HEADER_CREATOR_INFO))))
  421. NTKERNELAPI
  422. NTSTATUS
  423. ObCreateObjectType(
  424. IN PUNICODE_STRING TypeName,
  425. IN POBJECT_TYPE_INITIALIZER ObjectTypeInitializer,
  426. IN PSECURITY_DESCRIPTOR SecurityDescriptor OPTIONAL,
  427. OUT POBJECT_TYPE *ObjectType
  428. );
  429. #define OBJ_PROTECT_CLOSE 0x00000001L
  430. // end_ntosp
  431. VOID
  432. FASTCALL
  433. ObFreeObjectCreateInfoBuffer(
  434. IN POBJECT_CREATE_INFORMATION ObjectCreateInfo
  435. );
  436. NTSTATUS
  437. ObSetDirectoryDeviceMap (
  438. OUT PDEVICE_MAP *ppDeviceMap OPTIONAL,
  439. IN HANDLE DirectoryHandle
  440. );
  441. ULONG
  442. ObIsLUIDDeviceMapsEnabled (
  443. );
  444. ULONG
  445. ObGetSecurityMode (
  446. );
  447. BOOLEAN
  448. ObIsObjectDeletionInline(
  449. IN PVOID Object
  450. );
  451. FORCEINLINE
  452. ULONG
  453. ObSanitizeHandleAttributes (
  454. IN ULONG HandleAttributes,
  455. IN KPROCESSOR_MODE Mode
  456. )
  457. {
  458. if (Mode == KernelMode) {
  459. return HandleAttributes & OBJ_VALID_ATTRIBUTES;
  460. } else {
  461. return HandleAttributes & (OBJ_VALID_ATTRIBUTES&~OBJ_KERNEL_HANDLE);
  462. }
  463. }
  464. // begin_nthal
  465. // begin_ntosp
  466. NTKERNELAPI
  467. VOID
  468. ObDeleteCapturedInsertInfo(
  469. IN PVOID Object
  470. );
  471. NTKERNELAPI
  472. NTSTATUS
  473. ObCreateObject(
  474. IN KPROCESSOR_MODE ProbeMode,
  475. IN POBJECT_TYPE ObjectType,
  476. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  477. IN KPROCESSOR_MODE OwnershipMode,
  478. IN OUT PVOID ParseContext OPTIONAL,
  479. IN ULONG ObjectBodySize,
  480. IN ULONG PagedPoolCharge,
  481. IN ULONG NonPagedPoolCharge,
  482. OUT PVOID *Object
  483. );
  484. //
  485. // These inlines correct an issue where the compiler refetches
  486. // the output object over and over again because it thinks its
  487. // a possible alias for other stores.
  488. //
  489. FORCEINLINE
  490. NTSTATUS
  491. _ObCreateObject(
  492. IN KPROCESSOR_MODE ProbeMode,
  493. IN POBJECT_TYPE ObjectType,
  494. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  495. IN KPROCESSOR_MODE OwnershipMode,
  496. IN OUT PVOID ParseContext OPTIONAL,
  497. IN ULONG ObjectBodySize,
  498. IN ULONG PagedPoolCharge,
  499. IN ULONG NonPagedPoolCharge,
  500. OUT PVOID *pObject
  501. )
  502. {
  503. PVOID Object;
  504. NTSTATUS Status;
  505. Status = ObCreateObject (ProbeMode,
  506. ObjectType,
  507. ObjectAttributes,
  508. OwnershipMode,
  509. ParseContext,
  510. ObjectBodySize,
  511. PagedPoolCharge,
  512. NonPagedPoolCharge,
  513. &Object);
  514. *pObject = Object;
  515. return Status;
  516. }
  517. #define ObCreateObject _ObCreateObject
  518. NTKERNELAPI
  519. NTSTATUS
  520. ObInsertObject(
  521. IN PVOID Object,
  522. IN PACCESS_STATE PassedAccessState OPTIONAL,
  523. IN ACCESS_MASK DesiredAccess OPTIONAL,
  524. IN ULONG ObjectPointerBias,
  525. OUT PVOID *NewObject OPTIONAL,
  526. OUT PHANDLE Handle OPTIONAL
  527. );
  528. // end_nthal
  529. NTKERNELAPI // ntddk wdm nthal ntifs
  530. NTSTATUS // ntddk wdm nthal ntifs
  531. ObReferenceObjectByHandle( // ntddk wdm nthal ntifs
  532. IN HANDLE Handle, // ntddk wdm nthal ntifs
  533. IN ACCESS_MASK DesiredAccess, // ntddk wdm nthal ntifs
  534. IN POBJECT_TYPE ObjectType OPTIONAL, // ntddk wdm nthal ntifs
  535. IN KPROCESSOR_MODE AccessMode, // ntddk wdm nthal ntifs
  536. OUT PVOID *Object, // ntddk wdm nthal ntifs
  537. OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL // ntddk wdm nthal ntifs
  538. ); // ntddk wdm nthal ntifs
  539. FORCEINLINE
  540. NTSTATUS
  541. _ObReferenceObjectByHandle(
  542. IN HANDLE Handle,
  543. IN ACCESS_MASK DesiredAccess,
  544. IN POBJECT_TYPE ObjectType OPTIONAL,
  545. IN KPROCESSOR_MODE AccessMode,
  546. OUT PVOID *pObject,
  547. OUT POBJECT_HANDLE_INFORMATION pHandleInformation OPTIONAL
  548. )
  549. {
  550. PVOID Object;
  551. NTSTATUS Status;
  552. Status = ObReferenceObjectByHandle (Handle,
  553. DesiredAccess,
  554. ObjectType,
  555. AccessMode,
  556. &Object,
  557. pHandleInformation);
  558. *pObject = Object;
  559. return Status;
  560. }
  561. #define ObReferenceObjectByHandle _ObReferenceObjectByHandle
  562. NTKERNELAPI
  563. NTSTATUS
  564. ObReferenceFileObjectForWrite(
  565. IN HANDLE Handle,
  566. IN KPROCESSOR_MODE AccessMode,
  567. OUT PVOID *FileObject,
  568. OUT POBJECT_HANDLE_INFORMATION HandleInformation
  569. );
  570. NTKERNELAPI
  571. NTSTATUS
  572. ObOpenObjectByName(
  573. IN POBJECT_ATTRIBUTES ObjectAttributes,
  574. IN POBJECT_TYPE ObjectType,
  575. IN KPROCESSOR_MODE AccessMode,
  576. IN OUT PACCESS_STATE PassedAccessState OPTIONAL,
  577. IN ACCESS_MASK DesiredAccess OPTIONAL,
  578. IN OUT PVOID ParseContext OPTIONAL,
  579. OUT PHANDLE Handle
  580. );
  581. NTKERNELAPI // ntifs
  582. NTSTATUS // ntifs
  583. ObOpenObjectByPointer( // ntifs
  584. IN PVOID Object, // ntifs
  585. IN ULONG HandleAttributes, // ntifs
  586. IN PACCESS_STATE PassedAccessState OPTIONAL, // ntifs
  587. IN ACCESS_MASK DesiredAccess OPTIONAL, // ntifs
  588. IN POBJECT_TYPE ObjectType OPTIONAL, // ntifs
  589. IN KPROCESSOR_MODE AccessMode, // ntifs
  590. OUT PHANDLE Handle // ntifs
  591. ); // ntifs
  592. NTSTATUS
  593. ObReferenceObjectByName(
  594. IN PUNICODE_STRING ObjectName,
  595. IN ULONG Attributes,
  596. IN PACCESS_STATE PassedAccessState OPTIONAL,
  597. IN ACCESS_MASK DesiredAccess OPTIONAL,
  598. IN POBJECT_TYPE ObjectType,
  599. IN KPROCESSOR_MODE AccessMode,
  600. IN OUT PVOID ParseContext OPTIONAL,
  601. OUT PVOID *Object
  602. );
  603. // end_ntosp
  604. NTKERNELAPI // ntifs
  605. VOID // ntifs
  606. ObMakeTemporaryObject( // ntifs
  607. IN PVOID Object // ntifs
  608. ); // ntifs
  609. // begin_ntosp
  610. NTKERNELAPI
  611. BOOLEAN
  612. ObFindHandleForObject(
  613. IN PEPROCESS Process,
  614. IN PVOID Object,
  615. IN POBJECT_TYPE ObjectType OPTIONAL,
  616. IN POBJECT_HANDLE_INFORMATION MatchCriteria OPTIONAL,
  617. OUT PHANDLE Handle
  618. );
  619. // begin_ntddk begin_wdm begin_nthal begin_ntifs
  620. #define ObDereferenceObject(a) \
  621. ObfDereferenceObject(a)
  622. #define ObReferenceObject(Object) ObfReferenceObject(Object)
  623. NTKERNELAPI
  624. LONG_PTR
  625. FASTCALL
  626. ObfReferenceObject(
  627. IN PVOID Object
  628. );
  629. NTKERNELAPI
  630. NTSTATUS
  631. ObReferenceObjectByPointer(
  632. IN PVOID Object,
  633. IN ACCESS_MASK DesiredAccess,
  634. IN POBJECT_TYPE ObjectType,
  635. IN KPROCESSOR_MODE AccessMode
  636. );
  637. NTKERNELAPI
  638. LONG_PTR
  639. FASTCALL
  640. ObfDereferenceObject(
  641. IN PVOID Object
  642. );
  643. // end_ntddk end_wdm end_nthal end_ntifs end_ntosp
  644. NTKERNELAPI
  645. BOOLEAN
  646. FASTCALL
  647. ObReferenceObjectSafe (
  648. IN PVOID Object
  649. );
  650. NTKERNELAPI
  651. LONG_PTR
  652. FASTCALL
  653. ObReferenceObjectEx (
  654. IN PVOID Object,
  655. IN ULONG Count
  656. );
  657. LONG_PTR
  658. FASTCALL
  659. ObDereferenceObjectEx (
  660. IN PVOID Object,
  661. IN ULONG Count
  662. );
  663. NTSTATUS
  664. ObWaitForSingleObject(
  665. IN HANDLE Handle,
  666. IN BOOLEAN Alertable,
  667. IN PLARGE_INTEGER Timeout OPTIONAL
  668. );
  669. VOID
  670. ObDereferenceObjectDeferDelete (
  671. IN PVOID Object
  672. );
  673. // begin_ntifs begin_ntosp
  674. NTKERNELAPI
  675. NTSTATUS
  676. ObQueryNameString(
  677. IN PVOID Object,
  678. OUT POBJECT_NAME_INFORMATION ObjectNameInfo,
  679. IN ULONG Length,
  680. OUT PULONG ReturnLength
  681. );
  682. // end_ntifs end_ntosp
  683. #if DBG
  684. PUNICODE_STRING
  685. ObGetObjectName(
  686. IN PVOID Object
  687. );
  688. #endif // DBG
  689. NTSTATUS
  690. ObQueryTypeName(
  691. IN PVOID Object,
  692. PUNICODE_STRING ObjectTypeName,
  693. IN ULONG Length,
  694. OUT PULONG ReturnLength
  695. );
  696. NTSTATUS
  697. ObQueryTypeInfo(
  698. IN POBJECT_TYPE ObjectType,
  699. OUT POBJECT_TYPE_INFORMATION ObjectTypeInfo,
  700. IN ULONG Length,
  701. OUT PULONG ReturnLength
  702. );
  703. NTSTATUS
  704. ObDumpObjectByHandle(
  705. IN HANDLE Handle,
  706. IN POB_DUMP_CONTROL Control OPTIONAL
  707. );
  708. NTSTATUS
  709. ObDumpObjectByPointer(
  710. IN PVOID Object,
  711. IN POB_DUMP_CONTROL Control OPTIONAL
  712. );
  713. NTSTATUS
  714. ObSetDeviceMap(
  715. IN PEPROCESS TargetProcess,
  716. IN HANDLE DirectoryHandle
  717. );
  718. NTSTATUS
  719. ObQueryDeviceMapInformation(
  720. IN PEPROCESS TargetProcess,
  721. OUT PPROCESS_DEVICEMAP_INFORMATION DeviceMapInformation,
  722. IN ULONG Flags
  723. );
  724. VOID
  725. ObInheritDeviceMap(
  726. IN PEPROCESS NewProcess,
  727. IN PEPROCESS ParentProcess
  728. );
  729. VOID
  730. ObDereferenceDeviceMap(
  731. IN PEPROCESS Process
  732. );
  733. // begin_ntifs begin_ntddk begin_wdm begin_ntosp
  734. NTSTATUS
  735. ObGetObjectSecurity(
  736. IN PVOID Object,
  737. OUT PSECURITY_DESCRIPTOR *SecurityDescriptor,
  738. OUT PBOOLEAN MemoryAllocated
  739. );
  740. VOID
  741. ObReleaseObjectSecurity(
  742. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  743. IN BOOLEAN MemoryAllocated
  744. );
  745. // end_ntifs end_ntddk end_wdm
  746. NTSTATUS
  747. ObLogSecurityDescriptor (
  748. IN PSECURITY_DESCRIPTOR InputSecurityDescriptor,
  749. OUT PSECURITY_DESCRIPTOR *OutputSecurityDescriptor,
  750. ULONG RefBias
  751. );
  752. VOID
  753. ObDereferenceSecurityDescriptor (
  754. PSECURITY_DESCRIPTOR SecurityDescriptor,
  755. ULONG Count
  756. );
  757. VOID
  758. ObReferenceSecurityDescriptor (
  759. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  760. IN ULONG Count
  761. );
  762. // end_ntosp
  763. NTSTATUS
  764. ObAssignObjectSecurityDescriptor(
  765. IN PVOID Object,
  766. IN PSECURITY_DESCRIPTOR SecurityDescriptor OPTIONAL,
  767. IN POOL_TYPE PoolType
  768. );
  769. NTSTATUS
  770. ObValidateSecurityQuota(
  771. IN PVOID Object,
  772. IN ULONG NewSize
  773. );
  774. // begin_ntosp
  775. NTKERNELAPI
  776. BOOLEAN
  777. ObCheckCreateObjectAccess(
  778. IN PVOID DirectoryObject,
  779. IN ACCESS_MASK CreateAccess,
  780. IN PACCESS_STATE AccessState OPTIONAL,
  781. IN PUNICODE_STRING ComponentName,
  782. IN BOOLEAN TypeMutexLocked,
  783. IN KPROCESSOR_MODE PreviousMode,
  784. OUT PNTSTATUS AccessStatus
  785. );
  786. NTKERNELAPI
  787. BOOLEAN
  788. ObCheckObjectAccess(
  789. IN PVOID Object,
  790. IN PACCESS_STATE AccessState,
  791. IN BOOLEAN TypeMutexLocked,
  792. IN KPROCESSOR_MODE AccessMode,
  793. OUT PNTSTATUS AccessStatus
  794. );
  795. NTKERNELAPI
  796. NTSTATUS
  797. ObAssignSecurity(
  798. IN PACCESS_STATE AccessState,
  799. IN PSECURITY_DESCRIPTOR ParentDescriptor OPTIONAL,
  800. IN PVOID Object,
  801. IN POBJECT_TYPE ObjectType
  802. );
  803. // end_ntosp
  804. NTSTATUS // ntifs
  805. ObQueryObjectAuditingByHandle( // ntifs
  806. IN HANDLE Handle, // ntifs
  807. OUT PBOOLEAN GenerateOnClose // ntifs
  808. ); // ntifs
  809. // begin_ntosp
  810. NTSTATUS
  811. ObSetSecurityObjectByPointer (
  812. IN PVOID Object,
  813. IN SECURITY_INFORMATION SecurityInformation,
  814. IN PSECURITY_DESCRIPTOR SecurityDescriptor
  815. );
  816. NTSTATUS
  817. ObSetHandleAttributes (
  818. IN HANDLE Handle,
  819. IN POBJECT_HANDLE_FLAG_INFORMATION HandleFlags,
  820. IN KPROCESSOR_MODE PreviousMode
  821. );
  822. NTSTATUS
  823. ObCloseHandle (
  824. IN HANDLE Handle,
  825. IN KPROCESSOR_MODE PreviousMode
  826. );
  827. NTSTATUS
  828. ObSwapObjectNames (
  829. IN HANDLE DirectoryHandle,
  830. IN HANDLE Handle1,
  831. IN HANDLE Handle2,
  832. IN ULONG Flags
  833. );
  834. // end_ntosp
  835. #if DEVL
  836. typedef BOOLEAN (*OB_ENUM_OBJECT_TYPE_ROUTINE)(
  837. IN PVOID Object,
  838. IN PUNICODE_STRING ObjectName,
  839. IN ULONG_PTR HandleCount,
  840. IN ULONG_PTR PointerCount,
  841. IN PVOID Parameter
  842. );
  843. NTSTATUS
  844. ObEnumerateObjectsByType(
  845. IN POBJECT_TYPE ObjectType,
  846. IN OB_ENUM_OBJECT_TYPE_ROUTINE EnumerationRoutine,
  847. IN PVOID Parameter
  848. );
  849. NTSTATUS
  850. ObGetHandleInformation(
  851. OUT PSYSTEM_HANDLE_INFORMATION HandleInformation,
  852. IN ULONG Length,
  853. OUT PULONG ReturnLength OPTIONAL
  854. );
  855. NTSTATUS
  856. ObGetHandleInformationEx (
  857. OUT PSYSTEM_HANDLE_INFORMATION_EX HandleInformation,
  858. IN ULONG Length,
  859. OUT PULONG ReturnLength OPTIONAL
  860. );
  861. NTSTATUS
  862. ObGetObjectInformation(
  863. IN PCHAR UserModeBufferAddress,
  864. OUT PSYSTEM_OBJECTTYPE_INFORMATION ObjectInformation,
  865. IN ULONG Length,
  866. OUT PULONG ReturnLength OPTIONAL
  867. );
  868. // begin_ntosp
  869. NTKERNELAPI
  870. NTSTATUS
  871. ObSetSecurityDescriptorInfo(
  872. IN PVOID Object,
  873. IN PSECURITY_INFORMATION SecurityInformation,
  874. IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
  875. IN OUT PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor,
  876. IN POOL_TYPE PoolType,
  877. IN PGENERIC_MAPPING GenericMapping
  878. );
  879. // end_ntosp
  880. NTKERNELAPI
  881. NTSTATUS
  882. ObQuerySecurityDescriptorInfo(
  883. IN PVOID Object,
  884. IN PSECURITY_INFORMATION SecurityInformation,
  885. OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
  886. IN OUT PULONG Length,
  887. IN PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor
  888. );
  889. NTSTATUS
  890. ObDeassignSecurity (
  891. IN OUT PSECURITY_DESCRIPTOR *SecurityDescriptor
  892. );
  893. VOID
  894. ObAuditObjectAccess(
  895. IN HANDLE Handle,
  896. IN POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL,
  897. IN KPROCESSOR_MODE AccessMode,
  898. IN ACCESS_MASK DesiredAccess
  899. );
  900. NTKERNELAPI
  901. VOID
  902. FASTCALL
  903. ObInitializeFastReference (
  904. IN PEX_FAST_REF FastRef,
  905. IN PVOID Object
  906. );
  907. NTKERNELAPI
  908. PVOID
  909. FASTCALL
  910. ObFastReferenceObject (
  911. IN PEX_FAST_REF FastRef
  912. );
  913. NTKERNELAPI
  914. PVOID
  915. FASTCALL
  916. ObFastReferenceObjectLocked (
  917. IN PEX_FAST_REF FastRef
  918. );
  919. NTKERNELAPI
  920. VOID
  921. FASTCALL
  922. ObFastDereferenceObject (
  923. IN PEX_FAST_REF FastRef,
  924. IN PVOID Object
  925. );
  926. NTKERNELAPI
  927. PVOID
  928. FASTCALL
  929. ObFastReplaceObject (
  930. IN PEX_FAST_REF FastRef,
  931. IN PVOID Object
  932. );
  933. #endif // DEVL
  934. #endif // _OB_