ob.h 27 KB

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