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.

1153 lines
23 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. ki.h
  5. Abstract:
  6. This module contains the private (internal) header file for the
  7. kernel.
  8. Author:
  9. David N. Cutler (davec) 28-Feb-1989
  10. Revision History:
  11. --*/
  12. #ifndef _KI_
  13. #define _KI_
  14. #include "ntos.h"
  15. #include "stdio.h"
  16. #include "stdlib.h"
  17. #include "zwapi.h"
  18. //
  19. // Private (internal) constant definitions.
  20. //
  21. // Priority increment value definitions
  22. //
  23. #define ALERT_INCREMENT 2 // Alerted unwait priority increment
  24. #define BALANCE_INCREMENT 10 // Balance set priority increment
  25. #define RESUME_INCREMENT 0 // Resume thread priority increment
  26. #define TIMER_EXPIRE_INCREMENT 0 // Timer expiration priority increment
  27. //
  28. // Define time critical priority class base.
  29. //
  30. #define TIME_CRITICAL_PRIORITY_BOUND 14
  31. //
  32. // Define NIL pointer value.
  33. //
  34. #define NIL (PVOID)NULL // Null pointer to void
  35. //
  36. // Define macros which are used in the kernel only
  37. //
  38. // Clear member in set
  39. //
  40. #define ClearMember(Member, Set) \
  41. Set = Set & (~(1 << (Member)))
  42. //
  43. // Set member in set
  44. //
  45. #define SetMember(Member, Set) \
  46. Set = Set | (1 << (Member))
  47. //
  48. // Lock and unlock context swap lock.
  49. //
  50. #define KiLockContextSwap(OldIrql) \
  51. *(OldIrql) = KeAcquireQueuedSpinLockRaiseToSynch(LockQueueContextSwapLock)
  52. #define KiUnlockContextSwap(OldIrql) \
  53. KeReleaseQueuedSpinLock(LockQueueContextSwapLock, OldIrql)
  54. VOID
  55. FASTCALL
  56. KiUnlockDispatcherDatabase (
  57. IN KIRQL OldIrql
  58. );
  59. // VOID
  60. // KiBoostPriorityThread (
  61. // IN PKTHREAD Thread,
  62. // IN KPRIORITY Increment
  63. // )
  64. //
  65. //*++
  66. //
  67. // Routine Description:
  68. //
  69. // This function boosts the priority of the specified thread using
  70. // the same algorithm used when a thread gets a boost from a wait
  71. // operation.
  72. //
  73. // Arguments:
  74. //
  75. // Thread - Supplies a pointer to a dispatcher object of type thread.
  76. //
  77. // Increment - Supplies the priority increment that is to be applied to
  78. // the thread's priority.
  79. //
  80. // Return Value:
  81. //
  82. // None.
  83. //
  84. //--*
  85. #define KiBoostPriorityThread(Thread, Increment) { \
  86. KPRIORITY NewPriority; \
  87. PKPROCESS Process; \
  88. \
  89. if ((Thread)->Priority < LOW_REALTIME_PRIORITY) { \
  90. if ((Thread)->PriorityDecrement == 0) { \
  91. NewPriority = (Thread)->BasePriority + (Increment); \
  92. if (NewPriority > (Thread)->Priority) { \
  93. if (NewPriority >= LOW_REALTIME_PRIORITY) { \
  94. NewPriority = LOW_REALTIME_PRIORITY - 1; \
  95. } \
  96. \
  97. Process = (Thread)->ApcState.Process; \
  98. (Thread)->Quantum = Process->ThreadQuantum; \
  99. KiSetPriorityThread((Thread), NewPriority); \
  100. } \
  101. } \
  102. } \
  103. }
  104. FORCEINLINE
  105. LOGICAL
  106. KiIsKernelStackSwappable (
  107. IN KPROCESSOR_MODE WaitMode,
  108. IN PKTHREAD Thread
  109. )
  110. /*++
  111. Routine Description:
  112. This function determines whether the kernel stack is swappabel for the
  113. the specified thread in a wait operation.
  114. Arguments:
  115. WaitMode - Supplies the processor mode of the wait operation.
  116. Thread - Supplies a pointer to a dispatcher object of type thread.
  117. Return Value:
  118. If the kernel stack for the specified thread is swappable, then TRUE is
  119. returned. Otherwise, FALSE is returned.
  120. --*/
  121. {
  122. return ((WaitMode != KernelMode) &&
  123. (Thread->EnableStackSwap != FALSE) &&
  124. (Thread->Priority < (LOW_REALTIME_PRIORITY + 9)));
  125. }
  126. //
  127. // Private (internal) structure definitions.
  128. //
  129. // APC Parameter structure.
  130. //
  131. typedef struct _KAPC_RECORD {
  132. PKNORMAL_ROUTINE NormalRoutine;
  133. PVOID NormalContext;
  134. PVOID SystemArgument1;
  135. PVOID SystemArgument2;
  136. } KAPC_RECORD, *PKAPC_RECORD;
  137. //
  138. // Executive initialization.
  139. //
  140. VOID
  141. ExpInitializeExecutive (
  142. IN ULONG Number,
  143. IN PLOADER_PARAMETER_BLOCK LoaderBlock
  144. );
  145. //
  146. // Interprocessor interrupt function definitions.
  147. //
  148. // Define immediate interprocessor commands.
  149. //
  150. #define IPI_APC 1 // APC interrupt request
  151. #define IPI_DPC 2 // DPC interrupt request
  152. #define IPI_FREEZE 4 // freeze execution request
  153. #define IPI_PACKET_READY 8 // packet ready request
  154. #define IPI_SYNCH_REQUEST 16 // reverse stall packet request
  155. //
  156. // Define interprocess interrupt types.
  157. //
  158. typedef ULONG KIPI_REQUEST;
  159. typedef
  160. ULONG_PTR
  161. (*PKIPI_BROADCAST_WORKER)(
  162. IN ULONG_PTR Argument
  163. );
  164. #if NT_INST
  165. #define IPI_INSTRUMENT_COUNT(a,b) KiIpiCounts[a].b++;
  166. #else
  167. #define IPI_INSTRUMENT_COUNT(a,b)
  168. #endif
  169. //
  170. // Define interprocessor interrupt function prototypes.
  171. //
  172. ULONG_PTR
  173. KiIpiGenericCall (
  174. IN PKIPI_BROADCAST_WORKER BroadcastFunction,
  175. IN ULONG_PTR Context
  176. );
  177. #if defined(_AMD64_) || defined(_IA64_)
  178. ULONG
  179. KiIpiProcessRequests (
  180. VOID
  181. );
  182. #endif // defined(_AMD64_) || defined(_IA64_)
  183. VOID
  184. FASTCALL
  185. KiIpiSend (
  186. IN KAFFINITY TargetProcessors,
  187. IN KIPI_REQUEST Request
  188. );
  189. VOID
  190. KiIpiSendPacket (
  191. IN KAFFINITY TargetProcessors,
  192. IN PKIPI_WORKER WorkerFunction,
  193. IN PVOID Parameter1,
  194. IN PVOID Parameter2,
  195. IN PVOID Parameter3
  196. );
  197. VOID
  198. FASTCALL
  199. KiIpiSignalPacketDone (
  200. IN PKIPI_CONTEXT SignalDone
  201. );
  202. VOID
  203. KiIpiStallOnPacketTargets (
  204. KAFFINITY TargetSet
  205. );
  206. //
  207. // Private (internal) function definitions.
  208. //
  209. VOID
  210. FASTCALL
  211. KiActivateWaiterQueue (
  212. IN PKQUEUE Queue
  213. );
  214. BOOLEAN
  215. KiAdjustInterruptTime (
  216. IN LONGLONG TimeDelta
  217. );
  218. VOID
  219. KiAllProcessorsStarted (
  220. VOID
  221. );
  222. VOID
  223. KiApcInterrupt (
  224. VOID
  225. );
  226. NTSTATUS
  227. KiCallUserMode (
  228. IN PVOID *OutputBuffer,
  229. IN PULONG OutputLength
  230. );
  231. typedef struct {
  232. ULONGLONG Adjustment;
  233. LARGE_INTEGER NewCount;
  234. volatile LONG KiNumber;
  235. volatile LONG HalNumber;
  236. volatile LONG Barrier;
  237. } ADJUST_INTERRUPT_TIME_CONTEXT, *PADJUST_INTERRUPT_TIME_CONTEXT;
  238. VOID
  239. KiCalibrateTimeAdjustment (
  240. PADJUST_INTERRUPT_TIME_CONTEXT Adjust
  241. );
  242. VOID
  243. KiChainedDispatch (
  244. VOID
  245. );
  246. #if DBG
  247. VOID
  248. KiCheckTimerTable (
  249. IN ULARGE_INTEGER SystemTime
  250. );
  251. #endif
  252. LARGE_INTEGER
  253. KiComputeReciprocal (
  254. IN LONG Divisor,
  255. OUT PCCHAR Shift
  256. );
  257. ULONG
  258. KiComputeTimerTableIndex (
  259. IN LARGE_INTEGER Interval,
  260. IN LARGE_INTEGER CurrentCount,
  261. IN PKTIMER Timer
  262. );
  263. PLARGE_INTEGER
  264. FASTCALL
  265. KiComputeWaitInterval (
  266. IN PLARGE_INTEGER OriginalTime,
  267. IN PLARGE_INTEGER DueTime,
  268. IN OUT PLARGE_INTEGER NewTime
  269. );
  270. NTSTATUS
  271. KiContinue (
  272. IN PCONTEXT ContextRecord,
  273. IN PKEXCEPTION_FRAME ExceptionFrame,
  274. IN PKTRAP_FRAME TrapFrame
  275. );
  276. VOID
  277. KiDeliverApc (
  278. IN KPROCESSOR_MODE PreviousMode,
  279. IN PKEXCEPTION_FRAME ExceptionFrame,
  280. IN PKTRAP_FRAME TrapFrame
  281. );
  282. VOID
  283. KiDispatchException (
  284. IN PEXCEPTION_RECORD ExceptionRecord,
  285. IN PKEXCEPTION_FRAME ExceptionFrame,
  286. IN PKTRAP_FRAME TrapFrame,
  287. IN KPROCESSOR_MODE PreviousMode,
  288. IN BOOLEAN FirstChance
  289. );
  290. KCONTINUE_STATUS
  291. KiSetDebugProcessor (
  292. IN PKTRAP_FRAME TrapFrame,
  293. IN PKEXCEPTION_FRAME ExceptionFrame,
  294. IN KPROCESSOR_MODE PreviousMode
  295. );
  296. ULONG
  297. KiCopyInformation (
  298. IN OUT PEXCEPTION_RECORD ExceptionRecord1,
  299. IN PEXCEPTION_RECORD ExceptionRecord2
  300. );
  301. VOID
  302. KiDispatchInterrupt (
  303. VOID
  304. );
  305. PKTHREAD
  306. FASTCALL
  307. KiFindReadyThread (
  308. IN ULONG Processor,
  309. KPRIORITY LowPriority
  310. );
  311. VOID
  312. KiFloatingDispatch (
  313. VOID
  314. );
  315. #if !defined(_IA64_) && !defined(_AMD64_)
  316. VOID
  317. FASTCALL
  318. KiFlushSingleTb (
  319. IN BOOLEAN Invalid,
  320. IN PVOID Virtual
  321. );
  322. #endif // !_IA64_ && !_AMD64_
  323. VOID
  324. KiFlushMultipleTb (
  325. IN BOOLEAN Invalid,
  326. IN PVOID *Virtual,
  327. IN ULONG Count
  328. );
  329. //
  330. // VOID
  331. // KiSetTbFlushTimeStampBusy (
  332. // VOID
  333. // )
  334. //
  335. //*++
  336. //
  337. // Routine Description:
  338. //
  339. // This function sets the TB flush time stamp busy by setting the high
  340. // order bit of the TB flush time stamp. All readers of the time stamp
  341. // value will spin until the bit is cleared.
  342. //
  343. // Arguments:
  344. //
  345. // None.
  346. //
  347. // Return Value:
  348. //
  349. // None.
  350. //
  351. //--*
  352. __inline
  353. VOID
  354. KiSetTbFlushTimeStampBusy (
  355. VOID
  356. )
  357. {
  358. LONG Value;
  359. //
  360. // While the TB flush time stamp counter is being updated the high
  361. // order bit of the time stamp value is set. Otherwise, the bit is
  362. // clear.
  363. //
  364. do {
  365. do {
  366. } while ((Value = KiTbFlushTimeStamp) < 0);
  367. //
  368. // Attempt to set the high order bit.
  369. //
  370. } while (InterlockedCompareExchange((PLONG)&KiTbFlushTimeStamp,
  371. Value | 0x80000000,
  372. Value) != Value);
  373. return;
  374. }
  375. // VOID
  376. // KiClearTbFlushTimeStampBusy (
  377. // VOID
  378. // )
  379. //
  380. //*++
  381. //
  382. // Routine Description:
  383. //
  384. // This function ckears the TB flush time stamp busy by clearing the high
  385. // order bit of the TB flush time stamp and incrementing the low 32-bit
  386. // value.
  387. //
  388. // N.B. It is assumed that the high order bit of the time stamp value
  389. // is set on entry to this routine.
  390. //
  391. // Arguments:
  392. //
  393. // None.
  394. //
  395. // Return Value:
  396. //
  397. // None.
  398. //
  399. //--*
  400. __inline
  401. VOID
  402. KiClearTbFlushTimeStampBusy (
  403. VOID
  404. )
  405. {
  406. LONG Value;
  407. //
  408. // Get the current TB flush time stamp value, compute the next value,
  409. // and store the result clearing the busy bit.
  410. //
  411. Value = (KiTbFlushTimeStamp + 1) & 0x7fffffff;
  412. InterlockedExchange((PLONG)&KiTbFlushTimeStamp, Value);
  413. return;
  414. }
  415. PULONG
  416. KiGetUserModeStackAddress (
  417. VOID
  418. );
  419. VOID
  420. KiInitializeContextThread (
  421. IN PKTHREAD Thread,
  422. IN PKSYSTEM_ROUTINE SystemRoutine,
  423. IN PKSTART_ROUTINE StartRoutine OPTIONAL,
  424. IN PVOID StartContext OPTIONAL,
  425. IN PCONTEXT ContextFrame OPTIONAL
  426. );
  427. VOID
  428. KiInitializeKernel (
  429. IN PKPROCESS Process,
  430. IN PKTHREAD Thread,
  431. IN PVOID IdleStack,
  432. IN PKPRCB Prcb,
  433. IN CCHAR Number,
  434. IN PLOADER_PARAMETER_BLOCK LoaderBlock
  435. );
  436. VOID
  437. KiInitQueuedSpinLocks (
  438. PKPRCB Prcb,
  439. ULONG Number
  440. );
  441. VOID
  442. KiInitSystem (
  443. VOID
  444. );
  445. BOOLEAN
  446. KiInitMachineDependent (
  447. VOID
  448. );
  449. VOID
  450. KiInitializeUserApc (
  451. IN PKEXCEPTION_FRAME ExceptionFrame,
  452. IN PKTRAP_FRAME TrapFrame,
  453. IN PKNORMAL_ROUTINE NormalRoutine,
  454. IN PVOID NormalContext,
  455. IN PVOID SystemArgument1,
  456. IN PVOID SystemArgument2
  457. );
  458. LONG
  459. FASTCALL
  460. KiInsertQueue (
  461. IN PKQUEUE Queue,
  462. IN PLIST_ENTRY Entry,
  463. IN BOOLEAN Head
  464. );
  465. BOOLEAN
  466. FASTCALL
  467. KiInsertQueueApc (
  468. IN PKAPC Apc,
  469. IN KPRIORITY Increment
  470. );
  471. LOGICAL
  472. FASTCALL
  473. KiInsertTreeTimer (
  474. IN PKTIMER Timer,
  475. IN LARGE_INTEGER Interval
  476. );
  477. VOID
  478. KiInterruptDispatch (
  479. VOID
  480. );
  481. VOID
  482. KiInterruptDispatchRaise (
  483. IN PKINTERRUPT Interrupt
  484. );
  485. VOID
  486. KiInterruptDispatchSame (
  487. IN PKINTERRUPT Interrupt
  488. );
  489. VOID
  490. KiPassiveRelease (
  491. VOID
  492. );
  493. PKTHREAD
  494. KiQuantumEnd (
  495. VOID
  496. );
  497. NTSTATUS
  498. KiRaiseException (
  499. IN PEXCEPTION_RECORD ExceptionRecord,
  500. IN PCONTEXT ContextRecord,
  501. IN PKEXCEPTION_FRAME ExceptionFrame,
  502. IN PKTRAP_FRAME TrapFrame,
  503. IN BOOLEAN FirstChance
  504. );
  505. VOID
  506. FASTCALL
  507. KiReadyThread (
  508. IN PKTHREAD Thread
  509. );
  510. LOGICAL
  511. FASTCALL
  512. KiReinsertTreeTimer (
  513. IN PKTIMER Timer,
  514. IN ULARGE_INTEGER DueTime
  515. );
  516. #if DBG
  517. #define KiRemoveTreeTimer(Timer) \
  518. (Timer)->Header.Inserted = FALSE; \
  519. RemoveEntryList(&(Timer)->TimerListEntry); \
  520. (Timer)->TimerListEntry.Flink = NULL; \
  521. (Timer)->TimerListEntry.Blink = NULL
  522. #else
  523. #define KiRemoveTreeTimer(Timer) \
  524. (Timer)->Header.Inserted = FALSE; \
  525. RemoveEntryList(&(Timer)->TimerListEntry)
  526. #endif
  527. #if defined(NT_UP)
  528. #define KiRequestApcInterrupt(Processor) KiRequestSoftwareInterrupt(APC_LEVEL)
  529. #else
  530. #define KiRequestApcInterrupt(Processor) \
  531. if (KeGetCurrentPrcb()->Number == (CCHAR)Processor) { \
  532. KiRequestSoftwareInterrupt(APC_LEVEL); \
  533. } else { \
  534. KiIpiSend(AFFINITY_MASK(Processor), IPI_APC); \
  535. }
  536. #endif
  537. #if defined(NT_UP)
  538. #define KiRequestDispatchInterrupt(Processor)
  539. #else
  540. #define KiRequestDispatchInterrupt(Processor) \
  541. if (KeGetCurrentPrcb()->Number != (CCHAR)Processor) { \
  542. KiIpiSend(AFFINITY_MASK(Processor), IPI_DPC); \
  543. }
  544. #endif
  545. PKTHREAD
  546. FASTCALL
  547. KiSelectNextThread (
  548. IN ULONG Processor
  549. );
  550. KAFFINITY
  551. FASTCALL
  552. KiSetAffinityThread (
  553. IN PKTHREAD Thread,
  554. IN KAFFINITY Affinity
  555. );
  556. VOID
  557. KiSetSystemTime (
  558. IN PLARGE_INTEGER NewTime,
  559. OUT PLARGE_INTEGER OldTime
  560. );
  561. VOID
  562. KiSuspendNop (
  563. IN struct _KAPC *Apc,
  564. IN OUT PKNORMAL_ROUTINE *NormalRoutine,
  565. IN OUT PVOID *NormalContext,
  566. IN OUT PVOID *SystemArgument1,
  567. IN OUT PVOID *SystemArgument2
  568. );
  569. VOID
  570. KiSuspendRundown (
  571. IN PKAPC Apc
  572. );
  573. VOID
  574. KiSuspendThread (
  575. IN PVOID NormalContext,
  576. IN PVOID SystemArgument1,
  577. IN PVOID SystemArgument2
  578. );
  579. BOOLEAN
  580. KiSwapProcess (
  581. IN PKPROCESS NewProcess,
  582. IN PKPROCESS OldProcess
  583. );
  584. LONG_PTR
  585. FASTCALL
  586. KiSwapThread (
  587. VOID
  588. );
  589. VOID
  590. KiThreadStartup (
  591. IN PVOID StartContext
  592. );
  593. VOID
  594. KiTimerExpiration (
  595. IN PKDPC Dpc,
  596. IN PVOID DeferredContext,
  597. IN PVOID SystemArgument1,
  598. IN PVOID SystemArgument2
  599. );
  600. VOID
  601. FASTCALL
  602. KiTimerListExpire (
  603. IN PLIST_ENTRY ExpiredListHead,
  604. IN KIRQL OldIrql
  605. );
  606. VOID
  607. KiUnexpectedInterrupt (
  608. VOID
  609. );
  610. VOID
  611. FASTCALL
  612. KiUnlinkThread (
  613. IN PKTHREAD Thread,
  614. IN LONG_PTR WaitStatus
  615. );
  616. VOID
  617. FASTCALL
  618. KiUnwaitThread (
  619. IN PKTHREAD Thread,
  620. IN LONG_PTR WaitStatus,
  621. IN KPRIORITY Increment,
  622. IN PLIST_ENTRY ThreadList OPTIONAL
  623. );
  624. VOID
  625. KiUserApcDispatcher (
  626. IN PVOID NormalContext,
  627. IN PVOID SystemArgument1,
  628. IN PVOID SystemArgument2,
  629. IN PKNORMAL_ROUTINE NormalRoutine
  630. );
  631. VOID
  632. KiUserExceptionDispatcher (
  633. IN PEXCEPTION_RECORD ExceptionRecord,
  634. IN PCONTEXT ContextFrame
  635. );
  636. BOOLEAN
  637. FASTCALL
  638. KiSwapContext (
  639. IN PKTHREAD Thread
  640. );
  641. VOID
  642. FASTCALL
  643. KiWaitSatisfyAll (
  644. IN PKWAIT_BLOCK WaitBlock
  645. );
  646. //
  647. // VOID
  648. // FASTCALL
  649. // KiWaitSatisfyAny (
  650. // IN PKMUTANT Object,
  651. // IN PKTHREAD Thread
  652. // )
  653. //
  654. //
  655. // Routine Description:
  656. //
  657. // This function satisfies a wait for any type of object and performs
  658. // any side effects that are necessary.
  659. //
  660. // Arguments:
  661. //
  662. // Object - Supplies a pointer to a dispatcher object.
  663. //
  664. // Thread - Supplies a pointer to a dispatcher object of type thread.
  665. //
  666. // Return Value:
  667. //
  668. // None.
  669. //
  670. #define KiWaitSatisfyAny(_Object_, _Thread_) { \
  671. if (((_Object_)->Header.Type & DISPATCHER_OBJECT_TYPE_MASK) == EventSynchronizationObject) { \
  672. (_Object_)->Header.SignalState = 0; \
  673. \
  674. } else if ((_Object_)->Header.Type == SemaphoreObject) { \
  675. (_Object_)->Header.SignalState -= 1; \
  676. \
  677. } else if ((_Object_)->Header.Type == MutantObject) { \
  678. (_Object_)->Header.SignalState -= 1; \
  679. if ((_Object_)->Header.SignalState == 0) { \
  680. (_Thread_)->KernelApcDisable -= (_Object_)->ApcDisable; \
  681. (_Object_)->OwnerThread = (_Thread_); \
  682. if ((_Object_)->Abandoned == TRUE) { \
  683. (_Object_)->Abandoned = FALSE; \
  684. (_Thread_)->WaitStatus = STATUS_ABANDONED; \
  685. } \
  686. \
  687. InsertHeadList((_Thread_)->MutantListHead.Blink, \
  688. &(_Object_)->MutantListEntry); \
  689. } \
  690. } \
  691. }
  692. //
  693. // VOID
  694. // FASTCALL
  695. // KiWaitSatisfyMutant (
  696. // IN PKMUTANT Object,
  697. // IN PKTHREAD Thread
  698. // )
  699. //
  700. //
  701. // Routine Description:
  702. //
  703. // This function satisfies a wait for a mutant object.
  704. //
  705. // Arguments:
  706. //
  707. // Object - Supplies a pointer to a dispatcher object.
  708. //
  709. // Thread - Supplies a pointer to a dispatcher object of type thread.
  710. //
  711. // Return Value:
  712. //
  713. // None.
  714. //
  715. #define KiWaitSatisfyMutant(_Object_, _Thread_) { \
  716. (_Object_)->Header.SignalState -= 1; \
  717. if ((_Object_)->Header.SignalState == 0) { \
  718. (_Thread_)->KernelApcDisable -= (_Object_)->ApcDisable; \
  719. (_Object_)->OwnerThread = (_Thread_); \
  720. if ((_Object_)->Abandoned == TRUE) { \
  721. (_Object_)->Abandoned = FALSE; \
  722. (_Thread_)->WaitStatus = STATUS_ABANDONED; \
  723. } \
  724. \
  725. InsertHeadList((_Thread_)->MutantListHead.Blink, \
  726. &(_Object_)->MutantListEntry); \
  727. } \
  728. }
  729. //
  730. // VOID
  731. // FASTCALL
  732. // KiWaitSatisfyOther (
  733. // IN PKMUTANT Object
  734. // )
  735. //
  736. //
  737. // Routine Description:
  738. //
  739. // This function satisfies a wait for any type of object except a mutant
  740. // and performs any side effects that are necessary.
  741. //
  742. // Arguments:
  743. //
  744. // Object - Supplies a pointer to a dispatcher object.
  745. //
  746. // Return Value:
  747. //
  748. // None.
  749. //
  750. #define KiWaitSatisfyOther(_Object_) { \
  751. if (((_Object_)->Header.Type & DISPATCHER_OBJECT_TYPE_MASK) == EventSynchronizationObject) { \
  752. (_Object_)->Header.SignalState = 0; \
  753. \
  754. } else if ((_Object_)->Header.Type == SemaphoreObject) { \
  755. (_Object_)->Header.SignalState -= 1; \
  756. \
  757. } \
  758. }
  759. VOID
  760. FASTCALL
  761. KiWaitTest (
  762. IN PVOID Object,
  763. IN KPRIORITY Increment
  764. );
  765. VOID
  766. KiFreezeTargetExecution (
  767. IN PKTRAP_FRAME TrapFrame,
  768. IN PKEXCEPTION_FRAME ExceptionFrame
  769. );
  770. VOID
  771. KiPollFreezeExecution (
  772. VOID
  773. );
  774. VOID
  775. KiSaveProcessorState (
  776. IN PKTRAP_FRAME TrapFrame,
  777. IN PKEXCEPTION_FRAME ExceptionFrame
  778. );
  779. VOID
  780. KiSaveProcessorControlState (
  781. IN PKPROCESSOR_STATE ProcessorState
  782. );
  783. VOID
  784. KiRestoreProcessorState (
  785. IN PKTRAP_FRAME TrapFrame,
  786. IN PKEXCEPTION_FRAME ExceptionFrame
  787. );
  788. VOID
  789. KiRestoreProcessorControlState (
  790. IN PKPROCESSOR_STATE ProcessorState
  791. );
  792. #define KiEnableAlignmentExceptions()
  793. #define KiDisableAlignmentExceptions()
  794. BOOLEAN
  795. KiHandleAlignmentFault(
  796. IN PEXCEPTION_RECORD ExceptionRecord,
  797. IN PKEXCEPTION_FRAME ExceptionFrame,
  798. IN PKTRAP_FRAME TrapFrame,
  799. IN KPROCESSOR_MODE PreviousMode,
  800. IN BOOLEAN FirstChance,
  801. OUT BOOLEAN *ExceptionForwarded
  802. );
  803. //
  804. // External references to private kernel data structures
  805. //
  806. extern PMESSAGE_RESOURCE_DATA KiBugCodeMessages;
  807. extern ULONG KiDmaIoCoherency;
  808. extern ULONG KiMaximumDpcQueueDepth;
  809. extern ULONG KiMinimumDpcRate;
  810. extern ULONG KiAdjustDpcThreshold;
  811. extern PKDEBUG_ROUTINE KiDebugRoutine;
  812. extern PKDEBUG_SWITCH_ROUTINE KiDebugSwitchRoutine;
  813. extern LIST_ENTRY KiDispatcherReadyListHead[MAXIMUM_PRIORITY];
  814. extern const CCHAR KiFindFirstSetLeft[256];
  815. extern CALL_PERFORMANCE_DATA KiFlushSingleCallData;
  816. extern ULONG_PTR KiHardwareTrigger;
  817. extern KAFFINITY KiIdleSummary;
  818. extern KAFFINITY KiIdleSMTSummary;
  819. extern KEVENT KiSwapEvent;
  820. extern PKTHREAD KiSwappingThread;
  821. extern KNODE KiNode0;
  822. extern KNODE KiNodeInit[];
  823. extern SINGLE_LIST_ENTRY KiProcessInSwapListHead;
  824. extern SINGLE_LIST_ENTRY KiProcessOutSwapListHead;
  825. extern SINGLE_LIST_ENTRY KiStackInSwapListHead;
  826. extern LIST_ENTRY KiProfileSourceListHead;
  827. extern BOOLEAN KiProfileAlignmentFixup;
  828. extern ULONG KiProfileAlignmentFixupInterval;
  829. extern ULONG KiProfileAlignmentFixupCount;
  830. #if defined(_IA64_)
  831. // KiProfileInterval value should be replaced by a call:
  832. // HalQuerySystemInformation(HalProfileSourceInformation)
  833. #else // !_IA64_
  834. extern ULONG KiProfileInterval;
  835. #endif // !_IA64_
  836. extern LIST_ENTRY KiProfileListHead;
  837. extern KSPIN_LOCK KiProfileLock;
  838. extern ULONG KiReadySummary;
  839. extern UCHAR KiArgumentTable[];
  840. extern ULONG KiServiceLimit;
  841. extern ULONG_PTR KiServiceTable[];
  842. extern CALL_PERFORMANCE_DATA KiSetEventCallData;
  843. extern ULONG KiTickOffset;
  844. extern LARGE_INTEGER KiTimeIncrementReciprocal;
  845. extern CCHAR KiTimeIncrementShiftCount;
  846. extern LIST_ENTRY KiTimerTableListHead[TIMER_TABLE_SIZE];
  847. extern KAFFINITY KiTimeProcessor;
  848. extern KDPC KiTimerExpireDpc;
  849. extern KSPIN_LOCK KiFreezeExecutionLock;
  850. extern BOOLEAN KiSlavesStartExecution;
  851. extern PTIME_UPDATE_NOTIFY_ROUTINE KiTimeUpdateNotifyRoutine;
  852. extern LIST_ENTRY KiWaitListHead;
  853. extern CALL_PERFORMANCE_DATA KiWaitSingleCallData;
  854. extern ULONG KiEnableTimerWatchdog;
  855. #if defined(_IA64_)
  856. extern ULONG KiMasterRid;
  857. extern ULONGLONG KiMasterSequence;
  858. extern ULONG KiIdealDpcRate;
  859. #if !defined(UP_NT)
  860. extern KSPIN_LOCK KiMasterRidLock;
  861. #endif
  862. VOID
  863. KiSaveEmDebugContext (
  864. IN OUT PCONTEXT Context
  865. );
  866. VOID
  867. KiLoadEmDebugContext (
  868. IN PCONTEXT Context
  869. );
  870. VOID
  871. KiFlushRse (
  872. VOID
  873. );
  874. VOID
  875. KiInvalidateStackedRegisters (
  876. VOID
  877. );
  878. NTSTATUS
  879. Ki386CheckDivideByZeroTrap(
  880. IN PKTRAP_FRAME Frame
  881. );
  882. #endif // defined(_IA64_)
  883. #if defined(_IA64_)
  884. extern KINTERRUPT KxUnexpectedInterrupt;
  885. #endif
  886. #if NT_INST
  887. extern KIPI_COUNTS KiIpiCounts[MAXIMUM_PROCESSORS];
  888. #endif
  889. extern KSPIN_LOCK KiFreezeLockBackup;
  890. extern ULONG KiFreezeFlag;
  891. extern volatile ULONG KiSuspendState;
  892. #if DBG
  893. extern ULONG KiMaximumSearchCount;
  894. #endif
  895. // VOID
  896. // KiSetSwapEvent (
  897. // VOID
  898. // )
  899. //
  900. //*++
  901. //
  902. // Routine Description:
  903. //
  904. // This function sets the swap event or unwaits the swap thread.
  905. //
  906. // N.B. The dispatcher lock must be held to call this routine.
  907. //
  908. // Arguments:
  909. //
  910. // None.
  911. //
  912. // Return Value:
  913. //
  914. // None.
  915. //
  916. //--*
  917. __inline
  918. VOID
  919. KiSetSwapEvent (
  920. VOID
  921. )
  922. {
  923. PLIST_ENTRY WaitEntry;
  924. //
  925. // If the swap event wait queue is not empty, then unwait the swap
  926. // thread (there is only one swap thread). Otherwise, set the swap
  927. // event.
  928. //
  929. WaitEntry = KiSwapEvent.Header.WaitListHead.Flink;
  930. if (WaitEntry != &KiSwapEvent.Header.WaitListHead) {
  931. KiUnwaitThread(KiSwappingThread, 0, BALANCE_INCREMENT, NULL);
  932. } else {
  933. KiSwapEvent.Header.SignalState = 1;
  934. }
  935. return;
  936. }
  937. //
  938. // Include platform specific internal kernel header file.
  939. //
  940. #if defined(_AMD64_)
  941. #include "amd64\kiamd64.h"
  942. #elif defined(_X86_)
  943. #include "i386\kix86.h"
  944. #endif // defined(_AMD64_)
  945. #endif // defined(_KI_)