ob.h 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249
  1. /*++
  2. Copyright (c) 2012 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. ob.h
  5. Abstract:
  6. This header contains definitions for the kernel Object Manager.
  7. Author:
  8. Evan Green 4-Sep-2012
  9. --*/
  10. //
  11. // ------------------------------------------------------------------- Includes
  12. //
  13. //
  14. // --------------------------------------------------------------------- Macros
  15. //
  16. //
  17. // This macro signals the given object. The first parameter is a pointer to an
  18. // object (which always begins with an OBJECT_HEADER), and the second parameter
  19. // is a SIGNAL_OPTION. See the signal queue function.
  20. //
  21. #define ObSignalObject(_Object, _SignalOption) \
  22. ObSignalQueue(&(((POBJECT_HEADER)(_Object))->WaitQueue), (_SignalOption))
  23. //
  24. // This macro waits on the given object. The first parameter is a pointer to
  25. // an object header. The other parameters follow the "wait on queue" function
  26. // parameters.
  27. //
  28. #define ObWaitOnObject(_Object, _Flags, _TimeoutInMilliseconds) \
  29. ObWaitOnQueue(&(((POBJECT_HEADER)(_Object))->WaitQueue), \
  30. (_Flags), \
  31. (_TimeoutInMilliseconds))
  32. //
  33. // ---------------------------------------------------------------- Definitions
  34. //
  35. #define OBJECT_MANAGER_POOL_TAG 0x216A624F // '!jbO'
  36. //
  37. // This character represents the object directory separator.
  38. //
  39. #define OBJECT_PATH_SEPARATOR '/'
  40. //
  41. // Set this flag if the object manager should use the name parameter passed in
  42. // directly as the object's name buffer rather than allocating a copy. This
  43. // saves some memory for hardcoded strings.
  44. //
  45. #define OBJECT_FLAG_USE_NAME_DIRECTLY 0x00000001
  46. //
  47. // Set this flag if all queues must be signaled before the wait is satisfied.
  48. //
  49. #define WAIT_FLAG_ALL 0x00000001
  50. //
  51. // Set this flag if the wait can be interrupted by an asynchronous signal.
  52. //
  53. #define WAIT_FLAG_INTERRUPTIBLE 0x00000002
  54. //
  55. // Define the number of built in wait block entries.
  56. //
  57. #define BUILTIN_WAIT_BLOCK_ENTRY_COUNT 8
  58. //
  59. // Define a constant that can be passed to wait routines to indicate that the
  60. // wait should never time out.
  61. //
  62. #define WAIT_TIME_INDEFINITE MAX_ULONG
  63. //
  64. // Define the bitmask of usable flags in each handle table entry.
  65. //
  66. #define HANDLE_FLAG_MASK 0x7FFFFFFF
  67. //
  68. // Define the maximum number of handles. This is fairly arbitrary, and it should
  69. // be possible to raise this so long as it doesn't collide with INVALID_HANDLE.
  70. //
  71. #define OB_MAX_HANDLES 0x1000
  72. typedef enum _OBJECT_TYPE {
  73. ObjectInvalid,
  74. ObjectDirectory,
  75. ObjectQueuedLock,
  76. ObjectEvent,
  77. ObjectProcess,
  78. ObjectThread,
  79. ObjectDriver,
  80. ObjectDevice,
  81. ObjectIrp,
  82. ObjectInterface,
  83. ObjectInterfaceInstance,
  84. ObjectInterfaceListener,
  85. ObjectVolume,
  86. ObjectImageSection,
  87. ObjectPipe,
  88. ObjectTimer,
  89. ObjectTerminalMaster,
  90. ObjectTerminalSlave,
  91. ObjectSharedMemoryObject,
  92. ObjectMaxTypes
  93. } OBJECT_TYPE, *POBJECT_TYPE;
  94. typedef enum _SIGNAL_STATE {
  95. InvalidSignalState,
  96. NotSignaledWithWaiters,
  97. NotSignaled,
  98. SignaledForOne,
  99. Signaled,
  100. } SIGNAL_STATE, *PSIGNAL_STATE;
  101. typedef enum _SIGNAL_OPTION {
  102. SignalOptionInvalid,
  103. SignalOptionSignalAll,
  104. SignalOptionSignalOne,
  105. SignalOptionPulse,
  106. SignalOptionUnsignal
  107. } SIGNAL_OPTION, *PSIGNAL_OPTION;
  108. //
  109. // ------------------------------------------------------ Data Type Definitions
  110. //
  111. typedef struct _HANDLE_TABLE HANDLE_TABLE, *PHANDLE_TABLE;
  112. typedef
  113. VOID
  114. (*PDESTROY_OBJECT_ROUTINE) (
  115. PVOID Object
  116. );
  117. /*++
  118. Routine Description:
  119. This routine is called when an object's reference count drops to zero. It
  120. is responsible for cleaning up any auxiliary state inside the object. The
  121. object itself will be freed by the object manager.
  122. Arguments:
  123. Object - Supplies a pointer to the object being destroyed.
  124. Return Value:
  125. None.
  126. --*/
  127. typedef
  128. VOID
  129. (*PHANDLE_TABLE_ITERATE_ROUTINE) (
  130. PHANDLE_TABLE HandleTable,
  131. HANDLE Descriptor,
  132. ULONG Flags,
  133. PVOID HandleValue,
  134. PVOID Context
  135. );
  136. /*++
  137. Routine Description:
  138. This routine is called on each handle in the handle table for which it was
  139. invoked. The handle table will be locked during this call, so this call
  140. must not make any calls that would require accessing the handle table.
  141. Arguments:
  142. HandleTable - Supplies a pointer to the handle table being iterated through.
  143. Descriptor - Supplies the handle descriptor for the current handle.
  144. Flags - Supplies the flags associated with this handle.
  145. HandleValue - Supplies the handle value for the current handle.
  146. Context - Supplies an opaque pointer of context that was provided when the
  147. iteration was requested.
  148. Return Value:
  149. None.
  150. --*/
  151. typedef
  152. VOID
  153. (*PHANDLE_TABLE_LOOKUP_CALLBACK) (
  154. PHANDLE_TABLE HandleTable,
  155. HANDLE Descriptor,
  156. PVOID HandleValue
  157. );
  158. /*++
  159. Routine Description:
  160. This routine is called whenever a handle is looked up. It is called with
  161. the handle table lock still held.
  162. Arguments:
  163. HandleTable - Supplies a pointer to the handle table being iterated through.
  164. Descriptor - Supplies the handle descriptor for the current handle.
  165. HandleValue - Supplies the handle value for the current handle.
  166. Return Value:
  167. None.
  168. --*/
  169. /*++
  170. Structure Description:
  171. This structure defines a scheduler wait queue, upon which threads can
  172. block.
  173. Members:
  174. Lock - Stores the spin lock used to synchronize access to the structure.
  175. State - Stores the signaling state of the object. This is of type
  176. SIGNAL_STATE.
  177. Waiters - Stores a list of wait blocks waiting on this object.
  178. --*/
  179. typedef struct _WAIT_QUEUE {
  180. KSPIN_LOCK Lock;
  181. volatile ULONG State;
  182. LIST_ENTRY Waiters;
  183. } WAIT_QUEUE, *PWAIT_QUEUE;
  184. /*++
  185. Structure Description:
  186. This structure defines a generic kernel object.
  187. Members:
  188. Type - Stores the object type.
  189. NameLength - Stores the length of the name buffer in bytes, including the
  190. null terminator.
  191. Name - Stores an optional pointer to the pool allocated name.
  192. Parent - Stores a pointer to the parent object.
  193. SiblingEntry - Stores the list entry for its sibling objects.
  194. ChildListHead - Stores the list head for its child objects.
  195. Flags - Stores state flags regarding the object.
  196. ReferenceCount - Stores the reference count of the object, managed by the
  197. Object Manager.
  198. DestroyRoutine - Stores an optional pointer to a function to be called when
  199. the reference count drops to zero immediately before the object is
  200. deallocated.
  201. --*/
  202. typedef struct _OBJECT_HEADER OBJECT_HEADER, *POBJECT_HEADER;
  203. struct _OBJECT_HEADER {
  204. OBJECT_TYPE Type;
  205. ULONG NameLength;
  206. PSTR Name;
  207. POBJECT_HEADER Parent;
  208. LIST_ENTRY SiblingEntry;
  209. LIST_ENTRY ChildListHead;
  210. ULONG Flags;
  211. WAIT_QUEUE WaitQueue;
  212. volatile ULONG ReferenceCount;
  213. PDESTROY_OBJECT_ROUTINE DestroyRoutine;
  214. };
  215. typedef struct _WAIT_BLOCK WAIT_BLOCK, *PWAIT_BLOCK;
  216. //
  217. // -------------------------------------------------------------------- Globals
  218. //
  219. //
  220. // -------------------------------------------------------- Function Prototypes
  221. //
  222. KSTATUS
  223. ObInitialize (
  224. VOID
  225. );
  226. /*++
  227. Routine Description:
  228. This routine initializes the Object Manager. It requires that the MM pools
  229. are online.
  230. Arguments:
  231. None.
  232. Return Value:
  233. Status code.
  234. --*/
  235. PVOID
  236. ObGetRootObject (
  237. VOID
  238. );
  239. /*++
  240. Routine Description:
  241. This routine returns the root object of the system.
  242. Arguments:
  243. None.
  244. Return Value:
  245. Returns a pointer to the root object.
  246. --*/
  247. VOID
  248. ObInitializeWaitQueue (
  249. PWAIT_QUEUE WaitQueue,
  250. SIGNAL_STATE InitialState
  251. );
  252. /*++
  253. Routine Description:
  254. This routine initializes a wait queue structure.
  255. Arguments:
  256. WaitQueue - Supplies a pointer to the wait queue to initialize.
  257. InitialState - Supplies the initial state to set the queue to.
  258. Return Value:
  259. None.
  260. --*/
  261. PVOID
  262. ObCreateObject (
  263. OBJECT_TYPE Type,
  264. PVOID Parent,
  265. PSTR ObjectName,
  266. ULONG NameLength,
  267. ULONG DataSize,
  268. PDESTROY_OBJECT_ROUTINE DestroyRoutine,
  269. ULONG Flags,
  270. ULONG Tag
  271. );
  272. /*++
  273. Routine Description:
  274. This routine creates a new system object.
  275. Arguments:
  276. Type - Supplies the type of object being created.
  277. Parent - Supplies a pointer to the object that this object is a child under.
  278. Supply NULL to create an object off the root node.
  279. ObjectName - Supplies an optional name for the object. A copy of this
  280. string will be made unless the flags specify otherwise.
  281. NameLength - Supplies the length of the name string in bytes, including
  282. the null terminator.
  283. DataSize - Supplies the size of the object body, *including* the object
  284. header.
  285. DestroyRoutine - Supplies an optional pointer to a function to be called
  286. when the reference count of the object drops to zero (immediately before
  287. the object is deallocated).
  288. Flags - Supplies optional flags indicating various properties of the object.
  289. See OBJECT_FLAG_* definitions.
  290. Tag - Supplies the pool tag that should be used for the memory allocation.
  291. Return Value:
  292. Returns a pointer to the new object, on success. The returned structure is
  293. assumed to start with an OBJECT_HEADER structure.
  294. NULL if the object could not be allocated, the object already exists, or
  295. an invalid parameter was passed in.
  296. --*/
  297. KERNEL_API
  298. VOID
  299. ObAddReference (
  300. PVOID Object
  301. );
  302. /*++
  303. Routine Description:
  304. This routine increases the reference count on an object by 1.
  305. Arguments:
  306. Object - Supplies a pointer to the object to add a reference to.
  307. Return Value:
  308. None.
  309. --*/
  310. KERNEL_API
  311. VOID
  312. ObReleaseReference (
  313. PVOID Object
  314. );
  315. /*++
  316. Routine Description:
  317. This routine decreases the reference count of an object by 1. If this
  318. causes the reference count of the object to drop to 0, the object will be
  319. freed. This may cascade up the tree.
  320. Arguments:
  321. Object - Supplies a pointer to the object to subtract a reference from.
  322. This structure is presumed to begin with an OBJECT_HEADER structure.
  323. Return Value:
  324. None.
  325. --*/
  326. KSTATUS
  327. ObUnlinkObject (
  328. PVOID Object
  329. );
  330. /*++
  331. Routine Description:
  332. This routine unlinks an object.
  333. Arguments:
  334. Object - Supplies a pointer to the object to unlink.
  335. Return Value:
  336. Status code.
  337. --*/
  338. KSTATUS
  339. ObNameObject (
  340. PVOID Object,
  341. PSTR Name,
  342. ULONG NameLength,
  343. ULONG Tag,
  344. BOOL UseNameDirectly
  345. );
  346. /*++
  347. Routine Description:
  348. This routine names an object.
  349. Arguments:
  350. Object - Supplies a pointer to the object to name.
  351. Name - Supplies a pointer to the object name.
  352. NameLength - Supplies the new name's length.
  353. Tag - Supplies the pool tag to use to allocate the name.
  354. UseNameDirectly - Supplies the new value of the "Use name directly" flag
  355. in the object.
  356. Return Value:
  357. Status code.
  358. --*/
  359. PWAIT_BLOCK
  360. ObCreateWaitBlock (
  361. ULONG Capacity
  362. );
  363. /*++
  364. Routine Description:
  365. This routine creates a wait block. While this can be done on the fly,
  366. creating a wait block ahead of time is potentially faster if the number of
  367. elements being waited on is fairly large (greater than approximately 7).
  368. Arguments:
  369. Capacity - Supplies the maximum number of queues that will be waited on
  370. with this wait block.
  371. Return Value:
  372. Returns a pointer to the wait block on success.
  373. NULL on allocation failure.
  374. --*/
  375. VOID
  376. ObDestroyWaitBlock (
  377. PWAIT_BLOCK WaitBlock
  378. );
  379. /*++
  380. Routine Description:
  381. This routine destroys an explicitly created wait block. The wait block must
  382. not be actively waiting on anything.
  383. Arguments:
  384. WaitBlock - Supplies a pointer to the wait block.
  385. Return Value:
  386. None.
  387. --*/
  388. KSTATUS
  389. ObWait (
  390. PWAIT_BLOCK WaitBlock,
  391. ULONG TimeoutInMilliseconds
  392. );
  393. /*++
  394. Routine Description:
  395. This routine executes a wait block, waiting on the given list of wait
  396. queues for the specified amount of time.
  397. Arguments:
  398. WaitBlock - Supplies a pointer to the wait block to wait for.
  399. TimeoutInMilliseconds - Supplies the number of milliseconds that the given
  400. queues should be waited on before timing out. Use WAIT_TIME_INDEFINITE
  401. to wait forever.
  402. Return Value:
  403. STATUS_SUCCESS if the wait completed successfully.
  404. STATUS_TIMEOUT if the wait timed out.
  405. STATUS_INTERRUPTED if the wait timed out early due to a signal.
  406. --*/
  407. KERNEL_API
  408. KSTATUS
  409. ObWaitOnQueue (
  410. PWAIT_QUEUE Queue,
  411. ULONG Flags,
  412. ULONG TimeoutInMilliseconds
  413. );
  414. /*++
  415. Routine Description:
  416. This routine waits on a given wait queue. It is assumed that the caller can
  417. ensure externally that the wait queue will remain allocated.
  418. Arguments:
  419. Queue - Supplies a pointer to the queue to wait on.
  420. Flags - Supplies a bitfield of flags governing the behavior of the wait.
  421. See WAIT_FLAG_* definitions.
  422. TimeoutInMilliseconds - Supplies the number of milliseconds that the given
  423. queues should be waited on before timing out. Use WAIT_TIME_INDEFINITE
  424. to wait forever.
  425. Return Value:
  426. Status code.
  427. --*/
  428. KERNEL_API
  429. KSTATUS
  430. ObWaitOnObjects (
  431. PVOID *ObjectArray,
  432. ULONG ObjectCount,
  433. ULONG Flags,
  434. ULONG TimeoutInMilliseconds,
  435. PWAIT_BLOCK PreallocatedWaitBlock,
  436. PVOID *SignalingObject
  437. );
  438. /*++
  439. Routine Description:
  440. This routine waits on multiple objects until one (or all in some cases) is
  441. signaled. The caller is responsible for maintaining references to these
  442. objects.
  443. Arguments:
  444. ObjectArray - Supplies an array of object pointers containing the objects
  445. to wait on. Each object must only be on the list once.
  446. ObjectCount - Supplies the number of elements in the array.
  447. Flags - Supplies a bitfield of flags governing the behavior of the wait.
  448. See WAIT_FLAG_* definitions.
  449. TimeoutInMilliseconds - Supplies the number of milliseconds that the given
  450. objects should be waited on before timing out. Use WAIT_TIME_INDEFINITE
  451. to wait forever on these objects.
  452. PreallocatedWaitBlock - Supplies an optional pointer to a pre-allocated
  453. wait block to use for the wait. This is optional, however if there are
  454. a large number of objects to wait on and this is a common operation, it
  455. is a little faster to pre-allocate a wait block and reuse it.
  456. SignalingObject - Supplies an optional pointer where the object that
  457. satisfied the wait will be returned on success. If the wait was
  458. interrupted, this returns NULL. If the WAIT_FLAG_ALL_OBJECTS flag was
  459. not specified, the first object to be signaled will be returned. If the
  460. WAIT_FLAG_ALL_OBJECTS was specified, the caller should not depend on
  461. a particular object being returned here.
  462. Return Value:
  463. Status code.
  464. --*/
  465. KERNEL_API
  466. KSTATUS
  467. ObWaitOnQueues (
  468. PWAIT_QUEUE *QueueArray,
  469. ULONG Count,
  470. ULONG Flags,
  471. ULONG TimeoutInMilliseconds,
  472. PWAIT_BLOCK PreallocatedWaitBlock,
  473. PWAIT_QUEUE *SignalingQueue
  474. );
  475. /*++
  476. Routine Description:
  477. This routine waits on multiple wait queues until one (or all in some cases)
  478. is signaled. The caller is responsible for ensuring externally that these
  479. wait queues will not somehow be deallocated over the course of the wait.
  480. Arguments:
  481. QueueArray - Supplies an array of wait queue pointers containing the queues
  482. to wait on. Each queue must only be on the list once.
  483. Count - Supplies the number of elements in the array.
  484. Flags - Supplies a bitfield of flags governing the behavior of the wait.
  485. See WAIT_FLAG_* definitions.
  486. TimeoutInMilliseconds - Supplies the number of milliseconds that the given
  487. queues should be waited on before timing out. Use WAIT_TIME_INDEFINITE
  488. to wait forever.
  489. PreallocatedWaitBlock - Supplies an optional pointer to a pre-allocated
  490. wait block to use for the wait. This is optional, however if there are
  491. a large number of queues to wait on and this is a common operation, it
  492. is a little faster to pre-allocate a wait block and reuse it.
  493. SignalingQueue - Supplies an optional pointer where the queue that
  494. satisfied the wait will be returned on success. If the wait was
  495. interrupted, this returns NULL. If the WAIT_FLAG_ALL_OBJECTS flag was
  496. not specified, the first queue to be signaled will be returned. If the
  497. WAIT_FLAG_ALL_OBJECTS was specified, the caller should not depend on
  498. a particular queue being returned here.
  499. Return Value:
  500. Status code.
  501. --*/
  502. VOID
  503. ObSignalQueue (
  504. PWAIT_QUEUE Queue,
  505. SIGNAL_OPTION Signal
  506. );
  507. /*++
  508. Routine Description:
  509. This routine signals (or unsignals) a wait queue, potentially releasing
  510. threads blocking on this object.
  511. Arguments:
  512. Queue - Supplies a pointer to the wait queue to signal.
  513. Signal - Supplies the type of signaling to provide on the queue. Valid
  514. values are:
  515. SignalOptionSignalAll - Sets the queue to a signaled state and leaves
  516. it that way. All threads waiting on this queue will continue.
  517. SignalOptionSignalOne - Wakes up one thread waiting on the queue.
  518. If no threads are waiting on the queue, the state will be
  519. signaled until one thread waits on the queue, at which point it
  520. will go back to being unsignaled.
  521. SignalOptionPulse - Satisfies all waiters currently waiting on the
  522. queue, but does not set the state to signaled.
  523. SignalOptionUnsignal - Sets the queue's state to unsignaled.
  524. Return Value:
  525. None.
  526. --*/
  527. BOOL
  528. ObWakeBlockedThread (
  529. PVOID ThreadToWake,
  530. BOOL OnlyWakeSuspendedThreads
  531. );
  532. /*++
  533. Routine Description:
  534. This routine wakes up a blocked or suspended thread, interrupting any wait
  535. it may have been performing. If the thread was not blocked or suspended or
  536. the wait is not interruptible, then this routine does nothing.
  537. Arguments:
  538. ThreadToWake - Supplies a pointer to the thread to poke.
  539. OnlyWakeSuspendedThreads - Supplies a boolean indicating that the thread
  540. should only be poked if it's in the suspended state (not if it's in
  541. the blocked state).
  542. Return Value:
  543. TRUE if the thread was actually pulled out of a blocked or suspended state.
  544. FALSE if no action was performed because the thread was not stopped.
  545. --*/
  546. BOOL
  547. ObWakeBlockingThread (
  548. PVOID ThreadToWake
  549. );
  550. /*++
  551. Routine Description:
  552. This routine wakes up a blocking or suspending thread, interrupting any
  553. wait it may have been performing. This routine assumes that the thread is
  554. either blocking or suspending. It should not be in another state.
  555. Arguments:
  556. ThreadToWake - Supplies a pointer to the thread to poke.
  557. Return Value:
  558. TRUE if the thread was actually pulled out of a blocking or suspending
  559. state.
  560. FALSE if no action was performed because the thread had already been awoken.
  561. --*/
  562. PVOID
  563. ObFindObject (
  564. PSTR ObjectName,
  565. ULONG BufferLength,
  566. POBJECT_HEADER ParentObject
  567. );
  568. /*++
  569. Routine Description:
  570. This routine locates an object by name. The found object will be returned
  571. with an incremented reference count as to ensure it does not disappear
  572. while the caller is handling it. It is the caller's responsibility to
  573. release this reference.
  574. Arguments:
  575. ObjectName - Supplies the name of the object to find, either
  576. fully-specified or relative. Fully specified names begin with a /.
  577. BufferLength - Supplies the length of the name buffer.
  578. ParentObject - Supplies the parent object for relative names.
  579. Return Value:
  580. Returns a pointer to the object with the specified name, or NULL if the
  581. object could not be found.
  582. --*/
  583. PSTR
  584. ObGetFullPath (
  585. PVOID Object,
  586. ULONG AllocationTag
  587. );
  588. /*++
  589. Routine Description:
  590. This routine returns the full path of the given object. The return value
  591. will be allocated from paged pool, and it is the caller's responsibility
  592. to free it. The object path must not have any unnamed objects anywhere in
  593. its parent chain.
  594. Arguments:
  595. Object - Supplies a pointer to the object whose path to return.
  596. AllocationTag - Supplies the allocation tag to use when allocating memory
  597. for the return value.
  598. Return Value:
  599. Returns a pointer to the full path of the object, allocated from paged
  600. pool. It is the caller's responsibility to free this memory.
  601. NULL on failure, usually a memory allocation failure or an unnamed object
  602. somewhere in the path.
  603. --*/
  604. PWAIT_QUEUE
  605. ObGetBlockingQueue (
  606. PVOID Thread
  607. );
  608. /*++
  609. Routine Description:
  610. This routine returns one of the wait queues the given thread is blocking on.
  611. The caller is not guaranteed that the queue returned has a reference on it
  612. and won't disappear before being accessed. Generally this routine is only
  613. used by the scheduler for profiling.
  614. Arguments:
  615. Thread - Supplies a pointer to the thread.
  616. Return Value:
  617. Returns a pointer to the first wait queue the thread is blocking on, if any.
  618. The built-in thread timer does not count.
  619. NULL if the thread's wait block is empty.
  620. --*/
  621. //
  622. // Handle Table routines.
  623. //
  624. PHANDLE_TABLE
  625. ObCreateHandleTable (
  626. PVOID Process,
  627. PHANDLE_TABLE_LOOKUP_CALLBACK LookupCallbackRoutine
  628. );
  629. /*++
  630. Routine Description:
  631. This routine creates a new handle table. This routine must be called at low
  632. level.
  633. Arguments:
  634. Process - Supplies an optional pointer to the process that owns the handle
  635. table. When in doubt, supply NULL.
  636. LookupCallbackRoutine - Supplies an optional pointer that if supplied
  637. points to a function that will get called whenever a handle value is
  638. looked up (but not on iterates).
  639. Return Value:
  640. Returns a pointer to the new handle table on success.
  641. NULL on insufficient resource conditions.
  642. --*/
  643. VOID
  644. ObDestroyHandleTable (
  645. PHANDLE_TABLE HandleTable
  646. );
  647. /*++
  648. Routine Description:
  649. This routine destroys a handle table. This routine must be called at low
  650. level.
  651. Arguments:
  652. HandleTable - Supplies a pointer to the handle table to destroy.
  653. Return Value:
  654. None.
  655. --*/
  656. KSTATUS
  657. ObEnableHandleTableLocking (
  658. PHANDLE_TABLE HandleTable
  659. );
  660. /*++
  661. Routine Description:
  662. This routine enables locking on the given handle table.
  663. Arguments:
  664. HandleTable - Supplies a pointer to the handle table to enable locking for.
  665. Return Value:
  666. Status code.
  667. --*/
  668. KSTATUS
  669. ObCreateHandle (
  670. PHANDLE_TABLE Table,
  671. PVOID HandleValue,
  672. ULONG Flags,
  673. PHANDLE NewHandle
  674. );
  675. /*++
  676. Routine Description:
  677. This routine creates a new handle table entry. This routine must be called
  678. at low level.
  679. Arguments:
  680. Table - Supplies a pointer to the handle table.
  681. HandleValue - Supplies the value to be associated with the handle.
  682. Flags - Supplies a bitfield of flags to set with the handle. This value
  683. will be ANDed with HANDLE_FLAG_MASK, so bits set outside of that range
  684. will not stick.
  685. NewHandle - Supplies a pointer where the handle will be returned. On input,
  686. contains the minimum required value for the handle. Supply
  687. INVALID_HANDLE as the initial contents to let the system decide (which
  688. should be almost always).
  689. Return Value:
  690. STATUS_SUCCESS on success.
  691. STATUS_INSUFFICIENT_RESOURCES if memory could not be allocated for the
  692. handle table entry.
  693. --*/
  694. VOID
  695. ObDestroyHandle (
  696. PHANDLE_TABLE Table,
  697. HANDLE Handle
  698. );
  699. /*++
  700. Routine Description:
  701. This routine destroys a handle.
  702. Arguments:
  703. Table - Supplies a pointer to the handle table.
  704. Handle - Supplies the handle returned when the handle was created.
  705. Return Value:
  706. None.
  707. --*/
  708. KSTATUS
  709. ObReplaceHandleValue (
  710. PHANDLE_TABLE Table,
  711. HANDLE Handle,
  712. PVOID NewHandleValue,
  713. ULONG NewFlags,
  714. PVOID *OldHandleValue,
  715. PULONG OldFlags
  716. );
  717. /*++
  718. Routine Description:
  719. This routine replaces a handle table entry, or creates a handle if none was
  720. there before. This routine must be called at low level.
  721. Arguments:
  722. Table - Supplies a pointer to the handle table.
  723. Handle - Supplies the handle to replace or create.
  724. NewHandleValue - Supplies the value to be associated with the handle.
  725. NewFlags - Supplies the new handle flags to set.
  726. OldHandleValue - Supplies an optional pointer where the original handle
  727. value will be returned.
  728. OldFlags - Supplies an optional pointer where the original handle flags
  729. will be returned.
  730. Return Value:
  731. STATUS_SUCCESS on success.
  732. STATUS_INSUFFICIENT_RESOURCES if memory could not be allocated for the
  733. handle table entry.
  734. STATUS_TOO_MANY_HANDLES if the given minimum handle value was too high.
  735. --*/
  736. PVOID
  737. ObGetHandleValue (
  738. PHANDLE_TABLE Table,
  739. HANDLE Handle,
  740. PULONG Flags
  741. );
  742. /*++
  743. Routine Description:
  744. This routine looks up the given handle and returns the value associated
  745. with that handle.
  746. Arguments:
  747. Table - Supplies a pointer to the handle table.
  748. Handle - Supplies the handle returned when the handle was created.
  749. Flags - Supplies an optional pointer that receives value of the handle's
  750. flags.
  751. Return Value:
  752. Returns the value associated with that handle upon success.
  753. NULL if the given handle is invalid.
  754. --*/
  755. KSTATUS
  756. ObGetSetHandleFlags (
  757. PHANDLE_TABLE Table,
  758. HANDLE Handle,
  759. BOOL Set,
  760. PULONG Flags
  761. );
  762. /*++
  763. Routine Description:
  764. This routine sets and/or returns the flags associated with a handle. The
  765. lookup callback routine initialized with the handle table is not called
  766. during this operation.
  767. Arguments:
  768. Table - Supplies a pointer to the handle table.
  769. Handle - Supplies the handle whose flags should be retrieved.
  770. Set - Supplies a boolean indicating if the value in the flags parameter
  771. should be set as the new value.
  772. Flags - Supplies a pointer that on input contains the value of the flags
  773. to set if the set parameter is TRUE. This value will be ANDed with
  774. HANDLE_FLAG_MASK, so bits set outside of that mask will not stick.
  775. On output, contains the original value of the flags before the set was
  776. performed.
  777. Return Value:
  778. STATUS_SUCCESS on success.
  779. STATUS_INVALID_HANDLE if no such handle could be found.
  780. --*/
  781. HANDLE
  782. ObGetHighestHandle (
  783. PHANDLE_TABLE Table
  784. );
  785. /*++
  786. Routine Description:
  787. This routine returns the highest allocated handle.
  788. Arguments:
  789. Table - Supplies a pointer to the handle table.
  790. Return Value:
  791. Returns the highest handle number (not the handle value).
  792. INVALID_HANDLE if the table is empty.
  793. --*/
  794. VOID
  795. ObHandleTableIterate (
  796. PHANDLE_TABLE Table,
  797. PHANDLE_TABLE_ITERATE_ROUTINE IterateRoutine,
  798. PVOID IterateRoutineContext
  799. );
  800. /*++
  801. Routine Description:
  802. This routine iterates through all handles in the given handle table, and
  803. calls the given handle table for each one. The table will be locked when the
  804. iterate routine is called, so the iterate routine must not make any calls
  805. that would require use of the handle table.
  806. Arguments:
  807. Table - Supplies a pointer to the handle table to iterate through.
  808. IterateRoutine - Supplies a pointer to the routine to be called for each
  809. handle in the table.
  810. IterateRoutineContext - Supplies an opaque context pointer that will get
  811. passed to the iterate routine each time it is called.
  812. Return Value:
  813. None.
  814. --*/