Source code of Windows XP (NT5)
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.

333 lines
6.7 KiB

  1. /*++
  2. Copyright (c) 1999-1999 Microsoft Corporation
  3. Module Name:
  4. objtable.h
  5. Abstract:
  6. This module contains public declarations and definitions for the
  7. UL object table package.
  8. Author:
  9. Keith Moore (keithmo) 20-Apr-1999
  10. Revision History:
  11. --*/
  12. #ifndef _OBJTABLE_H_
  13. #define _OBJTABLE_H_
  14. //
  15. // Pointer to an object cleanup routine. This cleanup routine is invoked
  16. // whenever the final reference to an object is removed by a call to
  17. // UlDereferenceObject().
  18. //
  19. // Arguments:
  20. //
  21. // pObjectInfo - Supplies a pointer to the UL_OBJECT_INFO structure
  22. // embedded within the object being destroyed. The destruction
  23. // handler can get to the original object with the
  24. // CONTAINING_RECORD() macro.
  25. //
  26. // Note:
  27. //
  28. // This routine is invoked without the table lock held.
  29. //
  30. // This routine is invoked at the same IRQL as the caller to
  31. // UlDereferenceObject().
  32. //
  33. typedef
  34. VOID
  35. (NTAPI * PUL_DESTROY_HANDLER)(
  36. IN struct _UL_OBJECT_INFO *pObjectInfo
  37. );
  38. //
  39. // An object type definition. One of these must be registered with UL
  40. // for each object type supported.
  41. //
  42. typedef struct _UL_OBJECT_TYPE
  43. {
  44. //
  45. // All object types are kept on a global list.
  46. //
  47. LIST_ENTRY ObjectTypeListEntry;
  48. //
  49. // The cleanup routine for this object type.
  50. //
  51. PUL_DESTROY_HANDLER pDestroyHandler;
  52. //
  53. // The name of this object type.
  54. //
  55. UNICODE_STRING TypeName;
  56. //
  57. // Various statistics.
  58. //
  59. LONG ObjectsCreated;
  60. LONG ObjectsDestroyed;
  61. LONG References;
  62. LONG Dereferences;
  63. } UL_OBJECT_TYPE, *PUL_OBJECT_TYPE;
  64. //
  65. // Per-object info. One of these structures must be present in each
  66. // object managed by the object package.
  67. //
  68. typedef struct _UL_OBJECT_INFO
  69. {
  70. //
  71. // Pointer to the type definition information for this object.
  72. //
  73. PUL_OBJECT_TYPE pType;
  74. //
  75. // The number of outstanding references to this object.
  76. //
  77. LONG ReferenceCount;
  78. } UL_OBJECT_INFO, *PUL_OBJECT_INFO;
  79. //
  80. // Initialize/terminate the object table package.
  81. //
  82. NTSTATUS
  83. UlInitializeObjectTablePackage(
  84. VOID
  85. );
  86. VOID
  87. UlTerminateObjectTablePackage(
  88. VOID
  89. );
  90. //
  91. // Initialize an object type descriptor.
  92. //
  93. // Arguments:
  94. //
  95. // pType - Receives the initialized object type descriptor.
  96. //
  97. // pTypeName - Supplies a human-readable name for the new type.
  98. //
  99. // pDestroyHandler - Supplies the object destruction handler
  100. // for this type.
  101. //
  102. // Note:
  103. //
  104. // The UL_OBJECT_TYPE structure must be in non-paged memory
  105. // and must remain available throughout the life of the driver.
  106. //
  107. VOID
  108. UlInitializeObjectType(
  109. OUT PUL_OBJECT_TYPE pType,
  110. IN PWSTR pTypeName,
  111. IN PUL_DESTROY_HANDLER pDestroyHandler
  112. );
  113. //
  114. // Create a new object table.
  115. //
  116. // Arguments:
  117. //
  118. // pNewObjectTable - Receives a pointer to the new object table
  119. // if successful.
  120. //
  121. // Return Value:
  122. //
  123. // NTSTATUS - Completion status.
  124. //
  125. NTSTATUS
  126. UlCreateObjectTable(
  127. OUT PUL_OBJECT_TABLE *pNewObjectTable
  128. );
  129. //
  130. // Destroys an existing object table.
  131. //
  132. // Arguments:
  133. //
  134. // pObjectTable - Supplies the object table to destroy.
  135. //
  136. // Return Value:
  137. //
  138. // NTSTATUS - Completion status.
  139. //
  140. // Note:
  141. //
  142. // Any outstanding objects in the table are removed (and dereferenced)
  143. // by this routine. This may result in a flood of destruction handler
  144. // invocations.
  145. //
  146. NTSTATUS
  147. UlDestroyObjectTable(
  148. IN PUL_OBJECT_TABLE pObjectTable
  149. );
  150. //
  151. // Creates an table entry for a newly created object.
  152. //
  153. // Arguments:
  154. //
  155. // pObjectTable - Supplies the object table that will contain the
  156. // new object.
  157. //
  158. // pObjectType - Supplies the object type for the new object.
  159. //
  160. // pObjectInfo - Supplies a pointer to the UL_OBJECT_INFO
  161. // struture embedded within the newly created object.
  162. //
  163. // pNewOpaqueId - Receives the new opaque ID for the object
  164. // if successful.
  165. //
  166. // Return Value:
  167. //
  168. // NTSTATUS - Completion status.
  169. //
  170. // Note:
  171. //
  172. // The newly created object (the one containing pObjectInfo) is
  173. // assumed to have been created with a reference count of at least
  174. // one. In other words, the object already accounts for the object
  175. // table's reference. This reference is removed when the object's
  176. // opaque ID is removed from the object table.
  177. //
  178. NTSTATUS
  179. UlCreateObject(
  180. IN PUL_OBJECT_TABLE pObjectTable,
  181. IN PUL_OBJECT_TYPE pObjectType,
  182. IN PUL_OBJECT_INFO pObjectInfo,
  183. OUT PUL_OPAQUE_ID pNewOpaqueId
  184. );
  185. //
  186. // Closes an object by invaliding the opaque ID and dereferenceing the
  187. // associated object.
  188. //
  189. // Arguments:
  190. //
  191. // pObjectTable - Supplies the object table containing the object.
  192. //
  193. // pObjectType - Supplies the object type for the object.
  194. //
  195. // OpaqueId - Supplies the opaque ID of the object to close.
  196. //
  197. // pLastReference - Receives TRUE if the last reference to the
  198. // object was removed.
  199. //
  200. // Return Value:
  201. //
  202. // NTSTATUS - Completion status.
  203. //
  204. NTSTATUS
  205. UlCloseObject(
  206. IN PUL_OBJECT_TABLE pObjectTable,
  207. IN PUL_OBJECT_TYPE pObjectType,
  208. IN UL_OPAQUE_ID OpaqueId,
  209. OUT PBOOLEAN pLastReference
  210. );
  211. //
  212. // Increments the reference count on an object given the object's
  213. // opaque ID.
  214. //
  215. // Arguments:
  216. //
  217. // pObjectTable - Supplies the object table containing the object.
  218. //
  219. // pObjectType - Supplies the object type for the object.
  220. //
  221. // OpaqueId - Supplies the opaque ID of the object to reference.
  222. //
  223. // pObjectInfo - Receives a pointer to the UL_OBJECT_INFO structure
  224. // embedded within the referenced object if successful.
  225. //
  226. // Return Value:
  227. //
  228. // NTSTATUS - Completion status.
  229. //
  230. NTSTATUS
  231. UlReferenceObjectByOpaqueId(
  232. IN PUL_OBJECT_TABLE pObjectTable,
  233. IN PUL_OBJECT_TYPE pObjectType,
  234. IN UL_OPAQUE_ID OpaqueId,
  235. OUT PUL_OBJECT_INFO *pObjectInfo
  236. );
  237. //
  238. // Increments the reference count on an object given a pointer to
  239. // the object.
  240. //
  241. // Arguments:
  242. //
  243. // pObjectInfo - Supplies a pointer to the UL_OBJECT_INFO structure
  244. // embedded within the object to reference.
  245. //
  246. VOID
  247. UlReferenceObjectByPointer(
  248. IN PUL_OBJECT_INFO pObjectInfo
  249. );
  250. //
  251. // Dereferences an object. If this removes the last reference to the
  252. // object, then the destruction handler is invoked.
  253. //
  254. // Arguments:
  255. //
  256. // pObjectInfo - Supplies a pointer to the UL_OBJECT_INFO structure
  257. // embedded within the object to dereference.
  258. //
  259. // Return Value:
  260. //
  261. // BOOLEAN - TRUE if the final reference to the object was removed
  262. // (and therefore the destruction handler was invoked), FALSE
  263. // otherwise.
  264. //
  265. BOOLEAN
  266. UlDereferenceObject(
  267. IN PUL_OBJECT_INFO pObjectInfo
  268. );
  269. #endif // _OBJTABLE_H_