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.

876 lines
24 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Copyright (c) 1992 Microsoft Corporation
  4. Module Name:
  5. obwait.c
  6. Abstract:
  7. This module implements the generic wait system services.
  8. Author:
  9. Steve Wood (stevewo) 12-May-1989
  10. Revision History:
  11. --*/
  12. #include "obp.h"
  13. #ifdef ALLOC_PRAGMA
  14. #pragma alloc_text(PAGE, NtWaitForSingleObject)
  15. #pragma alloc_text(PAGE, NtWaitForMultipleObjects)
  16. #pragma alloc_text(PAGE, ObWaitForSingleObject)
  17. #endif
  18. //
  19. // We special case these three object types in the wait routine
  20. //
  21. extern POBJECT_TYPE ExEventObjectType;
  22. extern POBJECT_TYPE ExMutantObjectType;
  23. extern POBJECT_TYPE ExSemaphoreObjectType;
  24. NTSTATUS
  25. NtSignalAndWaitForSingleObject (
  26. IN HANDLE SignalHandle,
  27. IN HANDLE WaitHandle,
  28. IN BOOLEAN Alertable,
  29. IN PLARGE_INTEGER Timeout OPTIONAL
  30. )
  31. /*++
  32. Routine Description:
  33. This function atomically signals the specified signal object and then
  34. waits until the specified wait object attains a state of Signaled. An
  35. optional timeout can also be specified. If a timeout is not specified,
  36. then the wait will not be satisfied until the wait object attains a
  37. state of Signaled. If a timeout is specified, and the wait object has
  38. not attained a state of Signaled when the timeout expires, then the
  39. wait is automatically satisfied. If an explicit timeout value of zero
  40. is specified, then no wait will occur if the wait cannot be satisfied
  41. immediately. The wait can also be specified as alertable.
  42. Arguments:
  43. SignalHandle - Supplies the handle of the signal object.
  44. WaitHandle - Supplies the handle for the wait object.
  45. Alertable - Supplies a boolean value that specifies whether the wait
  46. is alertable.
  47. Timeout - Supplies an pointer to an absolute or relative time over
  48. which the wait is to occur.
  49. Return Value:
  50. The wait completion status. A value of STATUS_TIMEOUT is returned if a
  51. timeout occurred. A value of STATUS_SUCCESS is returned if the specified
  52. object satisfied the wait. A value of STATUS_ALERTED is returned if the
  53. wait was aborted to deliver an alert to the current thread. A value of
  54. STATUS_USER_APC is returned if the wait was aborted to deliver a user
  55. APC to the current thread.
  56. --*/
  57. {
  58. OBJECT_HANDLE_INFORMATION HandleInformation;
  59. KPROCESSOR_MODE PreviousMode;
  60. PVOID RealObject;
  61. PVOID SignalObject;
  62. POBJECT_HEADER SignalObjectHeader;
  63. NTSTATUS Status;
  64. LARGE_INTEGER TimeoutValue;
  65. PVOID WaitObject;
  66. POBJECT_HEADER WaitObjectHeader;
  67. //
  68. // Establish an exception handler and probe the specified timeout value
  69. // if necessary. If the probe fails, then return the exception code as
  70. // the service status.
  71. //
  72. PreviousMode = KeGetPreviousMode();
  73. if ((ARGUMENT_PRESENT(Timeout)) && (PreviousMode != KernelMode)) {
  74. try {
  75. TimeoutValue = ProbeAndReadLargeInteger(Timeout);
  76. Timeout = &TimeoutValue;
  77. } except(EXCEPTION_EXECUTE_HANDLER) {
  78. return GetExceptionCode();
  79. }
  80. }
  81. //
  82. // Reference the signal object by handle.
  83. //
  84. Status = ObReferenceObjectByHandle( SignalHandle,
  85. 0,
  86. NULL,
  87. PreviousMode,
  88. &SignalObject,
  89. &HandleInformation );
  90. //
  91. // If the reference was successful, then reference the wait object by
  92. // handle.
  93. //
  94. if (NT_SUCCESS(Status)) {
  95. Status = ObReferenceObjectByHandle( WaitHandle,
  96. SYNCHRONIZE,
  97. NULL,
  98. PreviousMode,
  99. &WaitObject,
  100. NULL );
  101. //
  102. // If the reference was successful, then determine the real wait
  103. // object, check the signal object access, signal the signal object,
  104. // and wait for the real wait object.
  105. //
  106. if (NT_SUCCESS(Status)) {
  107. WaitObjectHeader = OBJECT_TO_OBJECT_HEADER(WaitObject);
  108. RealObject = WaitObjectHeader->Type->DefaultObject;
  109. if ((LONG_PTR)RealObject >= 0) {
  110. RealObject = (PVOID)((PCHAR)WaitObject + (ULONG_PTR)RealObject);
  111. }
  112. //
  113. // If the signal object is an event, then check for modify access
  114. // and set the event. Otherwise, if the signal object is a
  115. // mutant, then attempt to release ownership of the mutant.
  116. // Otherwise, if the object is a semaphore, then check for modify
  117. // access and release the semaphore. Otherwise, the signal objet
  118. // is invalid.
  119. //
  120. SignalObjectHeader = OBJECT_TO_OBJECT_HEADER(SignalObject);
  121. Status = STATUS_ACCESS_DENIED;
  122. if (SignalObjectHeader->Type == ExEventObjectType) {
  123. //
  124. // Check for access to the specified event object,
  125. //
  126. if ((PreviousMode != KernelMode) &&
  127. (SeComputeDeniedAccesses( HandleInformation.GrantedAccess,
  128. EVENT_MODIFY_STATE) != 0 )) {
  129. goto WaitExit;
  130. }
  131. //
  132. // Set the specified event and wait atomically.
  133. //
  134. // N.B. This returns with the dispatcher lock held !!!
  135. //
  136. KeSetEvent((PKEVENT)SignalObject, EVENT_INCREMENT, TRUE);
  137. } else if (SignalObjectHeader->Type == ExMutantObjectType) {
  138. //
  139. // Release the specified mutant and wait atomically.
  140. //
  141. // N.B. The release will only be successful if the current
  142. // thread is the owner of the mutant.
  143. //
  144. try {
  145. KeReleaseMutant( (PKMUTANT)SignalObject,
  146. MUTANT_INCREMENT,
  147. FALSE,
  148. TRUE );
  149. } except(EXCEPTION_EXECUTE_HANDLER) {
  150. Status = GetExceptionCode();
  151. goto WaitExit;
  152. }
  153. } else if (SignalObjectHeader->Type == ExSemaphoreObjectType) {
  154. //
  155. // Check for access to the specified semaphore object,
  156. //
  157. if ((PreviousMode != KernelMode) &&
  158. (SeComputeDeniedAccesses( HandleInformation.GrantedAccess,
  159. SEMAPHORE_MODIFY_STATE) != 0 )) {
  160. goto WaitExit;
  161. }
  162. //
  163. // Release the specified semaphore and wait atomically.
  164. //
  165. try {
  166. //
  167. // Release the specified semaphore and wait atomically.
  168. //
  169. KeReleaseSemaphore( (PKSEMAPHORE)SignalObject,
  170. SEMAPHORE_INCREMENT,
  171. 1,
  172. TRUE );
  173. } except(EXCEPTION_EXECUTE_HANDLER) {
  174. Status = GetExceptionCode();
  175. goto WaitExit;
  176. }
  177. } else {
  178. Status = STATUS_OBJECT_TYPE_MISMATCH;
  179. goto WaitExit;
  180. }
  181. //
  182. // Protect the wait call just in case KeWait decides to raise
  183. // For example, a mutant level is exceeded
  184. //
  185. try {
  186. Status = KeWaitForSingleObject( RealObject,
  187. UserRequest,
  188. PreviousMode,
  189. Alertable,
  190. Timeout );
  191. } except(EXCEPTION_EXECUTE_HANDLER) {
  192. Status = GetExceptionCode();
  193. }
  194. WaitExit:
  195. ObDereferenceObject(WaitObject);
  196. }
  197. ObDereferenceObject(SignalObject);
  198. }
  199. return Status;
  200. }
  201. NTSTATUS
  202. NtWaitForSingleObject (
  203. IN HANDLE Handle,
  204. IN BOOLEAN Alertable,
  205. IN PLARGE_INTEGER Timeout OPTIONAL
  206. )
  207. /*++
  208. Routine Description:
  209. This function waits until the specified object attains a state of
  210. Signaled. An optional timeout can also be specified. If a timeout
  211. is not specified, then the wait will not be satisfied until the
  212. object attains a state of Signaled. If a timeout is specified, and
  213. the object has not attained a state of Signaled when the timeout
  214. expires, then the wait is automatically satisfied. If an explicit
  215. timeout value of zero is specified, then no wait will occur if the
  216. wait cannot be satisfied immediately. The wait can also be specified
  217. as alertable.
  218. Arguments:
  219. Handle - Supplies the handle for the wait object.
  220. Alertable - Supplies a boolean value that specifies whether the wait
  221. is alertable.
  222. Timeout - Supplies an pointer to an absolute or relative time over
  223. which the wait is to occur.
  224. Return Value:
  225. The wait completion status. A value of STATUS_TIMEOUT is returned if a
  226. timeout occurred. A value of STATUS_SUCCESS is returned if the specified
  227. object satisfied the wait. A value of STATUS_ALERTED is returned if the
  228. wait was aborted to deliver an alert to the current thread. A value of
  229. STATUS_USER_APC is returned if the wait was aborted to deliver a user
  230. APC to the current thread.
  231. --*/
  232. {
  233. PVOID Object;
  234. POBJECT_HEADER ObjectHeader;
  235. KPROCESSOR_MODE PreviousMode;
  236. NTSTATUS Status;
  237. LARGE_INTEGER TimeoutValue;
  238. PVOID WaitObject;
  239. PAGED_CODE();
  240. //
  241. // Get previous processor mode and probe and capture timeout argument
  242. // if necessary.
  243. //
  244. PreviousMode = KeGetPreviousMode();
  245. if ((ARGUMENT_PRESENT(Timeout)) && (PreviousMode != KernelMode)) {
  246. try {
  247. TimeoutValue = ProbeAndReadLargeInteger(Timeout);
  248. Timeout = &TimeoutValue;
  249. } except(EXCEPTION_EXECUTE_HANDLER) {
  250. return GetExceptionCode();
  251. }
  252. }
  253. //
  254. // Get a referenced pointer to the specified object with synchronize
  255. // access.
  256. //
  257. Status = ObReferenceObjectByHandle( Handle,
  258. SYNCHRONIZE,
  259. NULL,
  260. PreviousMode,
  261. &Object,
  262. NULL );
  263. //
  264. // If access is granted, then check to determine if the specified object
  265. // can be waited on.
  266. //
  267. if (NT_SUCCESS(Status)) {
  268. ObjectHeader = OBJECT_TO_OBJECT_HEADER( Object );
  269. WaitObject = ObjectHeader->Type->DefaultObject;
  270. if ((LONG_PTR)WaitObject >= 0) {
  271. WaitObject = (PVOID)((PCHAR)Object + (ULONG_PTR)WaitObject);
  272. }
  273. //
  274. // Protect the wait call just in case KeWait decides to raise
  275. // For example, a mutant level is exceeded
  276. //
  277. try {
  278. PERFINFO_DECLARE_OBJECT(Object);
  279. Status = KeWaitForSingleObject( WaitObject,
  280. UserRequest,
  281. PreviousMode,
  282. Alertable,
  283. Timeout );
  284. } except(EXCEPTION_EXECUTE_HANDLER) {
  285. Status = GetExceptionCode();
  286. }
  287. ObDereferenceObject(Object);
  288. }
  289. return Status;
  290. }
  291. NTSTATUS
  292. NtWaitForMultipleObjects (
  293. IN ULONG Count,
  294. IN HANDLE Handles[],
  295. IN WAIT_TYPE WaitType,
  296. IN BOOLEAN Alertable,
  297. IN PLARGE_INTEGER Timeout OPTIONAL
  298. )
  299. /*++
  300. Routine Description:
  301. This function waits until the specified objects attain a state of
  302. Signaled. The wait can be specified to wait until all of the objects
  303. attain a state of Signaled or until one of the objects attains a state
  304. of Signaled. An optional timeout can also be specified. If a timeout
  305. is not specified, then the wait will not be satisfied until the objects
  306. attain a state of Signaled. If a timeout is specified, and the objects
  307. have not attained a state of Signaled when the timeout expires, then
  308. the wait is automatically satisfied. If an explicit timeout value of
  309. zero is specified, then no wait will occur if the wait cannot be satisfied
  310. immediately. The wait can also be specified as alertable.
  311. Arguments:
  312. Count - Supplies a count of the number of objects that are to be waited
  313. on.
  314. Handles[] - Supplies an array of handles to wait objects.
  315. WaitType - Supplies the type of wait to perform (WaitAll, WaitAny).
  316. Alertable - Supplies a boolean value that specifies whether the wait is
  317. alertable.
  318. Timeout - Supplies a pointer to an optional absolute of relative time over
  319. which the wait is to occur.
  320. Return Value:
  321. The wait completion status. A value of STATUS_TIMEOUT is returned if a
  322. timeout occurred. The index of the object (zero based) in the object
  323. pointer array is returned if an object satisfied the wait. A value of
  324. STATUS_ALERTED is returned if the wait was aborted to deliver an alert
  325. to the current thread. A value of STATUS_USER_APC is returned if the
  326. wait was aborted to deliver a user APC to the current thread.
  327. --*/
  328. {
  329. HANDLE CapturedHandles[MAXIMUM_WAIT_OBJECTS];
  330. ULONG i;
  331. ULONG j;
  332. POBJECT_HEADER ObjectHeader;
  333. PVOID Objects[MAXIMUM_WAIT_OBJECTS];
  334. KPROCESSOR_MODE PreviousMode;
  335. ULONG RefCount;
  336. ULONG Size;
  337. NTSTATUS Status;
  338. LARGE_INTEGER TimeoutValue;
  339. PKWAIT_BLOCK WaitBlockArray;
  340. ACCESS_MASK GrantedAccess;
  341. PVOID WaitObjects[MAXIMUM_WAIT_OBJECTS];
  342. PHANDLE_TABLE HandleTable;
  343. PHANDLE_TABLE_ENTRY HandleEntry;
  344. BOOLEAN InCriticalRegion = FALSE;
  345. PETHREAD CurrentThread;
  346. PAGED_CODE();
  347. //
  348. // If the number of objects is zero or greater than the largest number
  349. // that can be waited on, then return and invalid parameter status.
  350. //
  351. if ((Count == 0) || (Count > MAXIMUM_WAIT_OBJECTS)) {
  352. return STATUS_INVALID_PARAMETER_1;
  353. }
  354. //
  355. // If the wait type is not wait any or wait all, then return an invalid
  356. // parameter status.
  357. //
  358. if ((WaitType != WaitAny) && (WaitType != WaitAll)) {
  359. return STATUS_INVALID_PARAMETER_3;
  360. }
  361. //
  362. // Get previous processor mode and probe and capture input arguments if
  363. // necessary.
  364. //
  365. PreviousMode = KeGetPreviousMode();
  366. try {
  367. if (PreviousMode != KernelMode) {
  368. if (ARGUMENT_PRESENT(Timeout)) {
  369. TimeoutValue = ProbeAndReadLargeInteger(Timeout);
  370. Timeout = &TimeoutValue;
  371. }
  372. ProbeForRead( Handles, Count * sizeof(HANDLE), sizeof(HANDLE) );
  373. }
  374. RtlCopyMemory (CapturedHandles, Handles, Count * sizeof(HANDLE));
  375. } except(EXCEPTION_EXECUTE_HANDLER) {
  376. return GetExceptionCode();
  377. }
  378. //
  379. // If the number of objects to be waited on is greater than the number
  380. // of builtin wait blocks, then allocate an array of wait blocks from
  381. // nonpaged pool. If the wait block array cannot be allocated, then
  382. // return insufficient resources.
  383. //
  384. WaitBlockArray = NULL;
  385. if (Count > THREAD_WAIT_OBJECTS) {
  386. Size = Count * sizeof( KWAIT_BLOCK );
  387. WaitBlockArray = ExAllocatePoolWithTag(NonPagedPool, Size, 'tiaW');
  388. if (WaitBlockArray == NULL) {
  389. return STATUS_INSUFFICIENT_RESOURCES;
  390. }
  391. }
  392. //
  393. // Loop through the array of handles and get a referenced pointer to
  394. // each object.
  395. //
  396. i = 0;
  397. RefCount = 0;
  398. Status = STATUS_SUCCESS;
  399. //
  400. // Protect ourselves from being interrupted while we hold a handle table
  401. // entry lock
  402. //
  403. CurrentThread = PsGetCurrentThread ();
  404. KeEnterCriticalRegionThread(&CurrentThread->Tcb);
  405. InCriticalRegion = TRUE;
  406. do {
  407. //
  408. // Get a pointer to the object table entry. Check if this is a kernel
  409. // handle and if so then use the kernel handle table otherwise use the
  410. // processes handle table. If we are going for a kernel handle we'll
  411. // need to attach to the kernel process otherwise we need to ensure
  412. // that we aren't attached.
  413. //
  414. if (IsKernelHandle( CapturedHandles[i], PreviousMode )) {
  415. HANDLE KernelHandle;
  416. //
  417. // Decode the user supplied handle into a regular handle value
  418. // and get its handle table entry
  419. //
  420. KernelHandle = DecodeKernelHandle( CapturedHandles[i] );
  421. HandleTable = ObpKernelHandleTable;
  422. HandleEntry = ExMapHandleToPointerEx ( HandleTable, KernelHandle, PreviousMode );
  423. } else {
  424. //
  425. // Get the handle table entry
  426. //
  427. HandleTable = PsGetCurrentProcessByThread (CurrentThread)->ObjectTable;
  428. HandleEntry = ExMapHandleToPointerEx ( HandleTable, CapturedHandles[ i ], PreviousMode );
  429. }
  430. //
  431. // Make sure the handle really did translate to a valid
  432. // entry
  433. //
  434. if (HandleEntry != NULL) {
  435. //
  436. // Get the granted access for the handle
  437. //
  438. #if i386
  439. if (NtGlobalFlag & FLG_KERNEL_STACK_TRACE_DB) {
  440. if (PreviousMode != KernelMode) {
  441. GrantedAccess = ObpTranslateGrantedAccessIndex( HandleEntry->GrantedAccessIndex );
  442. }
  443. } else {
  444. GrantedAccess = ObpDecodeGrantedAccess(HandleEntry->GrantedAccess);
  445. }
  446. #else
  447. GrantedAccess = ObpDecodeGrantedAccess(HandleEntry->GrantedAccess);
  448. #endif // i386
  449. //
  450. // Make sure the handle as synchronize access to the
  451. // object
  452. //
  453. if ((PreviousMode != KernelMode) &&
  454. (SeComputeDeniedAccesses( GrantedAccess, SYNCHRONIZE ) != 0)) {
  455. Status = STATUS_ACCESS_DENIED;
  456. ExUnlockHandleTableEntry( HandleTable, HandleEntry );
  457. goto ServiceFailed;
  458. } else {
  459. //
  460. // We have a object with proper access so get the header
  461. // and if the default objects points to a real object
  462. // then that is the one we're going to wait on.
  463. // Otherwise we'll find the kernel wait object at an
  464. // offset into the object body
  465. //
  466. ObjectHeader = (POBJECT_HEADER)(((ULONG_PTR)(HandleEntry->Object)) & ~OBJ_HANDLE_ATTRIBUTES);
  467. if ((LONG_PTR)ObjectHeader->Type->DefaultObject < 0) {
  468. RefCount += 1;
  469. Objects[i] = NULL;
  470. WaitObjects[i] = ObjectHeader->Type->DefaultObject;
  471. } else {
  472. ObpIncrPointerCount( ObjectHeader );
  473. RefCount += 1;
  474. Objects[i] = &ObjectHeader->Body;
  475. PERFINFO_DECLARE_OBJECT(Objects[i]);
  476. //
  477. // Compute the address of the kernel wait object.
  478. //
  479. WaitObjects[i] = (PVOID)((PCHAR)&ObjectHeader->Body +
  480. (ULONG_PTR)ObjectHeader->Type->DefaultObject);
  481. }
  482. }
  483. ExUnlockHandleTableEntry( HandleTable, HandleEntry );
  484. } else {
  485. //
  486. // The entry in the handle table isn't in use
  487. //
  488. Status = STATUS_INVALID_HANDLE;
  489. goto ServiceFailed;
  490. }
  491. i += 1;
  492. } while (i < Count);
  493. //
  494. // At this point the WaitObjects[] is set to the kernel wait objects
  495. //
  496. // Now Check to determine if any of the objects are specified more than
  497. // once, but we only need to check this for wait all, with a wait any
  498. // the user can specify the same object multiple times.
  499. //
  500. if (WaitType == WaitAll) {
  501. i = 0;
  502. do {
  503. for (j = i + 1; j < Count; j += 1) {
  504. if (WaitObjects[i] == WaitObjects[j]) {
  505. Status = STATUS_INVALID_PARAMETER_MIX;
  506. goto ServiceFailed;
  507. }
  508. }
  509. i += 1;
  510. } while (i < Count);
  511. }
  512. //
  513. // Wait for the specified objects to attain a state of Signaled or a
  514. // time out to occur. Protect the wait call just in case KeWait decides
  515. // to raise For example, a mutant level is exceeded
  516. //
  517. try {
  518. InCriticalRegion = FALSE;
  519. KeLeaveCriticalRegionThread(&CurrentThread->Tcb);
  520. Status = KeWaitForMultipleObjects( Count,
  521. WaitObjects,
  522. WaitType,
  523. UserRequest,
  524. PreviousMode,
  525. Alertable,
  526. Timeout,
  527. WaitBlockArray );
  528. } except(EXCEPTION_EXECUTE_HANDLER) {
  529. Status = GetExceptionCode();
  530. }
  531. //
  532. // If any objects were referenced, then deference them.
  533. //
  534. ServiceFailed:
  535. while (RefCount > 0) {
  536. RefCount -= 1;
  537. if (Objects[RefCount] != NULL) {
  538. ObDereferenceObject(Objects[RefCount]);
  539. }
  540. }
  541. //
  542. // If a wait block array was allocated, then deallocate it.
  543. //
  544. if (WaitBlockArray != NULL) {
  545. ExFreePool(WaitBlockArray);
  546. }
  547. if (InCriticalRegion) {
  548. KeLeaveCriticalRegionThread(&CurrentThread->Tcb);
  549. }
  550. return Status;
  551. }
  552. NTSTATUS
  553. ObWaitForSingleObject (
  554. IN HANDLE Handle,
  555. IN BOOLEAN Alertable,
  556. IN PLARGE_INTEGER Timeout OPTIONAL
  557. )
  558. /*++
  559. Routine Description:
  560. Please refer to NtWaitForSingleObject
  561. Arguments:
  562. Handle - Supplies the handle for the wait object.
  563. Alertable - Supplies a boolean value that specifies whether the wait
  564. is alertable.
  565. Timeout - Supplies an pointer to an absolute or relative time over
  566. which the wait is to occur.
  567. Return Value:
  568. The wait completion status. A value of STATUS_TIMEOUT is returned if a
  569. timeout occurred. A value of STATUS_SUCCESS is returned if the specified
  570. object satisfied the wait. A value of STATUS_ALERTED is returned if the
  571. wait was aborted to deliver an alert to the current thread. A value of
  572. STATUS_USER_APC is returned if the wait was aborted to deliver a user
  573. APC to the current thread.
  574. --*/
  575. {
  576. POBJECT_HEADER ObjectHeader;
  577. PVOID Object;
  578. NTSTATUS Status;
  579. PVOID WaitObject;
  580. PAGED_CODE();
  581. //
  582. // Get a referenced pointer to the specified object with synchronize
  583. // access.
  584. //
  585. Status = ObReferenceObjectByHandle( Handle,
  586. SYNCHRONIZE,
  587. (POBJECT_TYPE)NULL,
  588. KernelMode,
  589. &Object,
  590. NULL );
  591. //
  592. // If access is granted, then check to determine if the specified object
  593. // can be waited on.
  594. //
  595. if (NT_SUCCESS( Status ) != FALSE) {
  596. ObjectHeader = OBJECT_TO_OBJECT_HEADER( Object );
  597. if ((LONG_PTR)ObjectHeader->Type->DefaultObject < 0) {
  598. WaitObject = (PVOID)ObjectHeader->Type->DefaultObject;
  599. } else {
  600. WaitObject = (PVOID)((PCHAR)Object + (ULONG_PTR)ObjectHeader->Type->DefaultObject);
  601. }
  602. //
  603. // Protect the wait call just in case KeWait decides
  604. // to raise For example, a mutant level is exceeded
  605. //
  606. try {
  607. Status = KeWaitForSingleObject( WaitObject,
  608. UserRequest,
  609. KernelMode,
  610. Alertable,
  611. Timeout );
  612. } except(EXCEPTION_EXECUTE_HANDLER) {
  613. Status = GetExceptionCode();
  614. }
  615. ObDereferenceObject(Object);
  616. }
  617. return Status;
  618. }