1
0

kep.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  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. kep.h
  9. Abstract:
  10. This header contains private definitions for the Kernel Executive.
  11. Author:
  12. Evan Green 6-Aug-2012
  13. --*/
  14. //
  15. // ------------------------------------------------------------------- Includes
  16. //
  17. //
  18. // ---------------------------------------------------------------- Definitions
  19. //
  20. //
  21. // ------------------------------------------------------ Data Type Definitions
  22. //
  23. /*++
  24. Structure Description:
  25. This structure stores an IPI request packet.
  26. Members:
  27. ListEntry - Stores pointers to the previous and next list entries.
  28. IpiRoutine - Stores a pointer to the routine to execute on each processor.
  29. Context - Stores a pointer to the parameter passed to the IPI routine.
  30. ProcessorsRemaining - Stores a pointer where the number of processors that
  31. have yet to complete the IPI is stored.
  32. --*/
  33. typedef struct _IPI_REQUEST {
  34. LIST_ENTRY ListEntry;
  35. PIPI_ROUTINE IpiRoutine;
  36. PVOID Context;
  37. volatile ULONG *ProcessorsRemaining;
  38. } IPI_REQUEST, *PIPI_REQUEST;
  39. //
  40. // -------------------------------------------------------------------- Globals
  41. //
  42. //
  43. // Structures that store the processor blocks and total number of processors.
  44. //
  45. extern PPROCESSOR_BLOCK *KeProcessorBlocks;
  46. extern volatile ULONG KeActiveProcessorCount;
  47. //
  48. // Store the version information jammed into a packed format.
  49. //
  50. extern ULONG KeEncodedVersion;
  51. extern ULONG KeVersionSerial;
  52. extern ULONG KeBuildTime;
  53. extern PSTR KeBuildString;
  54. extern PSTR KeProductName;
  55. extern SYSTEM_FIRMWARE_TYPE KeSystemFirmwareType;
  56. extern PKERNEL_COMMAND_LINE KeCommandLine;
  57. //
  58. // Store the current periodic clock rate, in time counter ticks.
  59. //
  60. extern ULONGLONG KeClockRate;
  61. //
  62. // Set this to true to disable dynamic tick. This reverts back to a periodic
  63. // timer tick that's always running.
  64. //
  65. extern BOOL KeDisableDynamicTick;
  66. //
  67. // -------------------------------------------------------- Function Prototypes
  68. //
  69. VOID
  70. KepArchPrepareForContextSwap (
  71. PPROCESSOR_BLOCK ProcessorBlock,
  72. PKTHREAD CurrentThread,
  73. PKTHREAD NewThread
  74. );
  75. /*++
  76. Routine Description:
  77. This routine performs any architecture specific work before context swapping
  78. between threads. This must be called at dispatch level.
  79. Arguments:
  80. ProcessorBlock - Supplies a pointer to the processor block of the current
  81. processor.
  82. CurrentThread - Supplies a pointer to the current (old) thread.
  83. NewThread - Supplies a pointer to the thread that's about to be switched to.
  84. Return Value:
  85. None.
  86. --*/
  87. VOID
  88. KepContextSwap (
  89. PVOID *SavedStackLocation,
  90. PVOID NewStack,
  91. ULONGLONG NewThreadPointer,
  92. BOOL FirstTime
  93. );
  94. /*++
  95. Routine Description:
  96. This routine switches context to the given thread.
  97. Arguments:
  98. SavedStackLocation - Supplies a pointer where the old stack pointer will
  99. be saved.
  100. NewStack - Supplies the new stack address.
  101. NewThreadPointer - Supplies the new thread pointer data.
  102. FirstTime - Supplies a boolean indicating whether the thread has never been
  103. run before.
  104. Return Value:
  105. None.
  106. --*/
  107. KSTATUS
  108. KepInitializeSystemWorkQueue (
  109. VOID
  110. );
  111. /*++
  112. Routine Description:
  113. This routine initializes the system work queue. This must happen after the
  114. Object Manager initializes.
  115. Arguments:
  116. None.
  117. Return Value:
  118. Status code.
  119. --*/
  120. VOID
  121. KepExecutePendingDpcs (
  122. VOID
  123. );
  124. /*++
  125. Routine Description:
  126. This routine executes any pending DPCs on the current processor. This
  127. routine should only be executed internally by the scheduler. It must be
  128. called at dispatch level. Interrupts must be disabled upon entry, but will
  129. be enabled on exit.
  130. Arguments:
  131. None.
  132. Return Value:
  133. None.
  134. --*/
  135. PKTIMER_DATA
  136. KepCreateTimerData (
  137. VOID
  138. );
  139. /*++
  140. Routine Description:
  141. This routine is called upon system initialization to create a timer
  142. management context for a new processor.
  143. Arguments:
  144. None.
  145. Return Value:
  146. Returns a pointer to the timer data on success.
  147. NULL on resource allocation failure.
  148. --*/
  149. VOID
  150. KepDestroyTimerData (
  151. PKTIMER_DATA Data
  152. );
  153. /*++
  154. Routine Description:
  155. This routine tears down a processor's timer management context.
  156. Arguments:
  157. Data - Supplies a pointer to the data to destroy.
  158. Return Value:
  159. None.
  160. --*/
  161. VOID
  162. KepDispatchTimers (
  163. ULONGLONG CurrentTime
  164. );
  165. /*++
  166. Routine Description:
  167. This routine is called at regular intervals to check for and expire timers
  168. whose time has come. This routine must only be called internally, and must
  169. be called at dispatch level.
  170. Arguments:
  171. Queue - Supplies a pointer to the timer queue for the current processor.
  172. CurrentTime - Supplies the current time counter value. Any timers with this
  173. due time or earlier will be expired.
  174. Return Value:
  175. None.
  176. --*/
  177. ULONGLONG
  178. KepGetNextTimerDeadline (
  179. PPROCESSOR_BLOCK Processor,
  180. PBOOL Hard
  181. );
  182. /*++
  183. Routine Description:
  184. This routine returns the next waking deadline of timers on the given
  185. processor. This routine must be called at or above dispatch level.
  186. Arguments:
  187. Processor - Supplies a pointer to the processor.
  188. Hard - Supplies a pointer where a boolean will be returned indicating if
  189. this is a hard deadline or a soft deadline.
  190. Return Value:
  191. Returns the next waking timer deadline.
  192. -1 if there are no waking timers.
  193. --*/
  194. VOID
  195. KepGetTimeOffset (
  196. PSYSTEM_TIME TimeOffset
  197. );
  198. /*++
  199. Routine Description:
  200. This routine reads the time offset from the shared user data page.
  201. Arguments:
  202. TimeOffset - Supplies a pointer that receives the time offset from the
  203. shared user data page.
  204. Return Value:
  205. None.
  206. --*/
  207. KSTATUS
  208. KepSetTimeOffset (
  209. PSYSTEM_TIME NewTimeOffset,
  210. PDPC Dpc
  211. );
  212. /*++
  213. Routine Description:
  214. This routine sets the time offset in the shared user data page. For
  215. synchronization purposes, the time offset can only be updated by the clock
  216. owner at the clock run level. If the caller requires this routine to
  217. succeed, then a DPC can be supplied, otherwise the DPC will be allocated if
  218. necessary and said allocation could fail.
  219. Arguments:
  220. NewTimeOffset - Supplies a pointer to the new time offset. This cannot be
  221. a pointer to paged pool as it may be used at dispatch level by the DPC.
  222. Dpc - Supplies a pointer to an optional DPC to use when tracking down the
  223. clock owner.
  224. Return Value:
  225. Status code.
  226. --*/
  227. VOID
  228. KepInitializeClock (
  229. PPROCESSOR_BLOCK Processor
  230. );
  231. /*++
  232. Routine Description:
  233. This routine initializes system clock information.
  234. Arguments:
  235. Processor - Supplies a pointer to the processor block being initialized.
  236. Return Value:
  237. None.
  238. --*/
  239. VOID
  240. KepUpdateClockDeadline (
  241. VOID
  242. );
  243. /*++
  244. Routine Description:
  245. This routine is called when the next clock deadline is potentially changed.
  246. Arguments:
  247. None.
  248. Return Value:
  249. None.
  250. --*/
  251. VOID
  252. KepClockIdle (
  253. PPROCESSOR_BLOCK Processor
  254. );
  255. /*++
  256. Routine Description:
  257. This routine is called when the processor goes idle. It potentially
  258. requests a clock transition to disable the clock.
  259. Arguments:
  260. Processor - Supplies a pointer to the current processor block.
  261. Return Value:
  262. None.
  263. --*/
  264. VOID
  265. KepSetClockToPeriodic (
  266. PPROCESSOR_BLOCK Processor
  267. );
  268. /*++
  269. Routine Description:
  270. This routine sets the clock to be periodic on the given processor. This
  271. routine must be called at or above dispatch level.
  272. Arguments:
  273. Processor - Supplies a pointer to the processor block for the processor
  274. whose clock should be switched to periodic.
  275. Return Value:
  276. None.
  277. --*/
  278. VOID
  279. KepAddTimePointEntropy (
  280. VOID
  281. );
  282. /*++
  283. Routine Description:
  284. This routine adds entropy in the form of a timestamp to the pseudo random
  285. interface, if one exists.
  286. Arguments:
  287. None.
  288. Return Value:
  289. None.
  290. --*/
  291. VOID
  292. KepInitializeScheduler (
  293. PPROCESSOR_BLOCK ProcessorBlock
  294. );
  295. /*++
  296. Routine Description:
  297. This routine initializes the scheduler for a processor.
  298. Arguments:
  299. ProcessorBlock - Supplies a pointer to the processor block.
  300. Return Value:
  301. None.
  302. --*/
  303. KSTATUS
  304. KepWriteCrashDump (
  305. ULONG CrashCode,
  306. ULONGLONG Parameter1,
  307. ULONGLONG Parameter2,
  308. ULONGLONG Parameter3,
  309. ULONGLONG Parameter4
  310. );
  311. /*++
  312. Routine Description:
  313. This routine writes crash dump data to disk.
  314. Arguments:
  315. CrashCode - Supplies the reason for the system crash.
  316. Parameter1 - Supplies an optional parameter regarding the crash.
  317. Parameter2 - Supplies an optional parameter regarding the crash.
  318. Parameter3 - Supplies an optional parameter regarding the crash.
  319. Parameter4 - Supplies an optional parameter regarding the crash.
  320. Return Value:
  321. Status code.
  322. --*/
  323. KSTATUS
  324. KepSetBannerThread (
  325. PVOID Data,
  326. PUINTN DataSize,
  327. BOOL Set
  328. );
  329. /*++
  330. Routine Description:
  331. This routine enables or disables the banner thread.
  332. Arguments:
  333. Data - Supplies a pointer to the data buffer where the data is either
  334. returned for a get operation or given for a set operation.
  335. DataSize - Supplies a pointer that on input contains the size of the
  336. data buffer. On output, contains the required size of the data buffer.
  337. Set - Supplies a boolean indicating if this is a get operation (FALSE) or
  338. a set operation (TRUE).
  339. Return Value:
  340. Status code.
  341. --*/