ke.h 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563
  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. ke.h
  9. Abstract:
  10. This header contains definitions for the Kernel Executive.
  11. Author:
  12. Evan Green 5-Aug-2012
  13. --*/
  14. //
  15. // ------------------------------------------------------------------- Includes
  16. //
  17. #include <minoca/kernel/crash.h>
  18. //
  19. // --------------------------------------------------------------------- Macros
  20. //
  21. //
  22. // Define macros for encoding and decoding system version information. These
  23. // can be revised as needed since this encoded structure is not exposed to
  24. // consumers. They use the SYSTEM_VERSION_INFORMATION structure.
  25. //
  26. #define ENCODE_VERSION_INFORMATION(_Major, _Minor, _Revision, _Release, _Debug)\
  27. (((_Major) << 24) | \
  28. ((_Minor) << 16) | \
  29. ((_Revision) << 8) | \
  30. ((_Release) << 4) | \
  31. (_Debug))
  32. #define DECODE_MAJOR_VERSION(_EncodedVersion) (UCHAR)((_EncodedVersion) >> 24)
  33. #define DECODE_MINOR_VERSION(_EncodedVersion) (UCHAR)((_EncodedVersion) >> 16)
  34. #define DECODE_VERSION_REVISION(_EncodedVersion) (UCHAR)((_EncodedVersion) >> 8)
  35. #define DECODE_VERSION_RELEASE(_EncodedVersion) \
  36. (UCHAR)(((_EncodedVersion) >> 4) & 0x0F)
  37. #define DECODE_VERSION_DEBUG(_EncodedVersion) \
  38. (UCHAR)((_EncodedVersion) & 0x0F)
  39. //
  40. // ---------------------------------------------------------------- Definitions
  41. //
  42. //
  43. // Define the generic catch-all Ke tag: Ke!!
  44. //
  45. #define KE_ALLOCATION_TAG 0x2121654B
  46. //
  47. // Define the scheduler allocation tag: KeSc
  48. //
  49. #define KE_SCHEDULER_ALLOCATION_TAG 0x6353654B
  50. //
  51. // Define the event allocation tag: KeEv
  52. //
  53. #define KE_EVENT_ALLOCATION_TAG 0x7645654B
  54. //
  55. // Define the work item allocation tag: KeWo
  56. //
  57. #define KE_WORK_ITEM_ALLOCATION_TAG 0x6F57654B
  58. //
  59. // Define the Ke system information allocation tag: KInf
  60. //
  61. #define KE_INFORMATION_ALLOCATION_TAG 0x666E494B
  62. //
  63. // Define the maximum number of comma-separated values in a kernel argument.
  64. //
  65. #define KERNEL_MAX_ARGUMENT_VALUES 10
  66. #define KERNEL_MAX_COMMAND_LINE 4096
  67. //
  68. // Work queue flags.
  69. //
  70. //
  71. // Set this bit if the work queue should support adding work items at
  72. // dispatch level.
  73. //
  74. #define WORK_QUEUE_FLAG_SUPPORT_DISPATCH_LEVEL 0x00000001
  75. //
  76. // Define the mask of publicly accessible timer flags.
  77. //
  78. #define KTIMER_FLAG_PUBLIC_MASK 0x0
  79. //
  80. // Define user shared data processor feature flags.
  81. //
  82. //
  83. // This bit is set if the processor supports the sysenter instruction.
  84. //
  85. #define X86_FEATURE_SYSENTER 0x00000001
  86. //
  87. // This bit is set if the processor supports the syscall instruction.
  88. //
  89. #define X86_FEATURE_SYSCALL 0x00000002
  90. //
  91. // This bit is set if the processor conforms to at least the Pentium Pro ISA
  92. // (circa 1995).
  93. //
  94. #define X86_FEATURE_I686 0x00000004
  95. //
  96. // This bit is set if the processor supports fxsave/fxrstor instructions.
  97. //
  98. #define X86_FEATURE_FXSAVE 0x00000008
  99. //
  100. // This bit is set if the kernel is ARMv7.
  101. //
  102. #define ARM_FEATURE_V7 0x00000001
  103. //
  104. // This bit is set if the processor supports VFPv2 or beyond.
  105. //
  106. #define ARM_FEATURE_VFP2 0x00000002
  107. //
  108. // This bit is set if the processor supports VFPv3.
  109. //
  110. #define ARM_FEATURE_VFP3 0x00000004
  111. //
  112. // This bit is set if the processor supports NEON advanced SIMD with 32 64-bit
  113. // registers.
  114. //
  115. #define ARM_FEATURE_NEON32 0x00000008
  116. //
  117. // Define the set of DCP flags.
  118. //
  119. #define DPC_FLAG_QUEUED_ON_PROCESSOR 0x00000001
  120. //
  121. // ------------------------------------------------------ Data Type Definitions
  122. //
  123. typedef enum _RUNLEVEL {
  124. RunLevelLow = 0,
  125. RunLevelDispatch = 2,
  126. RunLevelMaxDevice = 11,
  127. RunLevelClock = 13,
  128. RunLevelIpi = 14,
  129. RunLevelHigh = 15,
  130. RunLevelCount = 16
  131. } RUNLEVEL, *PRUNLEVEL;
  132. typedef enum _WORK_PRIORITY {
  133. WorkPriorityInvalid,
  134. WorkPriorityNormal,
  135. WorkPriorityHigh,
  136. } WORK_PRIORITY, *PWORK_PRIORITY;
  137. typedef enum _PROCESSOR_SET_TARGET {
  138. ProcessorTargetInvalid,
  139. ProcessorTargetNone,
  140. ProcessorTargetAny,
  141. ProcessorTargetAll,
  142. ProcessorTargetAllExcludingSelf,
  143. ProcessorTargetSelf,
  144. ProcessorTargetSingleProcessor
  145. } PROCESSOR_SET_TARGET, *PPROCESSOR_SET_TARGET;
  146. typedef enum _WORK_QUEUE_STATE {
  147. WorkQueueStateInvalid,
  148. WorkQueueStateOpen,
  149. WorkQueueStatePaused,
  150. WorkQueueStateWakingForDestroying,
  151. WorkQueueStateDestroying,
  152. WorkQueueStateDestroyed
  153. } WORK_QUEUE_STATE, *PWORK_QUEUE_STATE;
  154. typedef enum _DPC_CRASH_REASON {
  155. DpcCrashReasonInvalid,
  156. DpcCrashDpcBlocked,
  157. DpcCrashReasonDoubleQueueDpc,
  158. DpcCrashReasonNullRoutine,
  159. DpcCrashReasonCorrupt,
  160. } DPC_CRASH_REASON, *PDPC_CRASH_REASON;
  161. typedef enum _SCHEDULER_REASON {
  162. SchedulerReasonInvalid,
  163. SchedulerReasonDispatchInterrupt,
  164. SchedulerReasonThreadBlocking,
  165. SchedulerReasonThreadYielding,
  166. SchedulerReasonThreadSuspending,
  167. SchedulerReasonThreadExiting
  168. } SCHEDULER_REASON, *PSCHEDULER_REASON;
  169. typedef enum _SYSTEM_INFORMATION_SUBSYSTEM {
  170. SystemInformationInvalid,
  171. SystemInformationKe,
  172. SystemInformationIo,
  173. SystemInformationMm,
  174. SystemInformationPs,
  175. SystemInformationHl,
  176. SystemInformationSp,
  177. SystemInformationPm
  178. } SYSTEM_INFORMATION_SUBSYSTEM, *PSYSTEM_INFORMATION_SUBSYSTEM;
  179. typedef enum _KE_INFORMATION_TYPE {
  180. KeInformationInvalid,
  181. KeInformationSystemVersion,
  182. KeInformationFirmwareTable,
  183. KeInformationFirmwareType,
  184. KeInformationProcessorUsage,
  185. KeInformationProcessorCount,
  186. KeInformationKernelCommandLine,
  187. KeInformationBannerThread,
  188. } KE_INFORMATION_TYPE, *PKE_INFORMATION_TYPE;
  189. typedef enum _SYSTEM_FIRMWARE_TYPE {
  190. SystemFirmwareInvalid,
  191. SystemFirmwareUnknown,
  192. SystemFirmwareEfi,
  193. SystemFirmwarePcat,
  194. } SYSTEM_FIRMWARE_TYPE, *PSYSTEM_FIRMWARE_TYPE;
  195. typedef enum _CYCLE_ACCOUNT {
  196. CycleAccountInvalid,
  197. CycleAccountUser,
  198. CycleAccountKernel,
  199. CycleAccountInterrupt,
  200. CycleAccountIdle,
  201. } CYCLE_ACCOUNT, *PCYCLE_ACCOUNT;
  202. typedef enum _TIMER_QUEUE_TYPE {
  203. TimerQueueSoft,
  204. TimerQueueSoftWake,
  205. TimerQueueHard,
  206. TimerQueueCount,
  207. } TIMER_QUEUE_TYPE, *PTIMER_QUEUE_TYPE;
  208. typedef enum _CLOCK_TIMER_MODE {
  209. ClockTimerInvalid,
  210. ClockTimerPeriodic,
  211. ClockTimerOneShot,
  212. ClockTimerOff
  213. } CLOCK_TIMER_MODE, *PCLOCK_TIMER_MODE;
  214. typedef struct _KTIMER KTIMER, *PKTIMER;
  215. typedef struct _KTIMER_DATA KTIMER_DATA, *PKTIMER_DATA;
  216. typedef struct _WORK_ITEM WORK_ITEM, *PWORK_ITEM;
  217. typedef struct _WORK_QUEUE WORK_QUEUE, *PWORK_QUEUE;
  218. typedef struct _SCHEDULER_DATA SCHEDULER_DATA, *PSCHEDULER_DATA;
  219. typedef struct _SCHEDULER_GROUP_ENTRY
  220. SCHEDULER_GROUP_ENTRY, *PSCHEDULER_GROUP_ENTRY;
  221. typedef struct _SCHEDULER_GROUP SCHEDULER_GROUP, *PSCHEDULER_GROUP;
  222. typedef struct _DPC DPC, *PDPC;
  223. typedef struct _PROCESSOR_START_BLOCK
  224. PROCESSOR_START_BLOCK, *PPROCESSOR_START_BLOCK;
  225. typedef
  226. VOID
  227. (*PIPI_ROUTINE) (
  228. PVOID Context
  229. );
  230. /*++
  231. Routine Description:
  232. This routine executes as part of an Inter-Processor Interrupt request. It
  233. is run simultaneously on the set of processors requested.
  234. Arguments:
  235. Context - Supplies the context pointer supplied when the IPI was requested.
  236. Return Value:
  237. None.
  238. --*/
  239. /*++
  240. Structure Description:
  241. This structure describes a set of zero or more processors.
  242. Members:
  243. Target - Stores the processor target.
  244. Number - Stores the processor number if the target indicates a single
  245. processor.
  246. --*/
  247. typedef struct _PROCESSOR_SET {
  248. PROCESSOR_SET_TARGET Target;
  249. union {
  250. ULONG Number;
  251. } U;
  252. } PROCESSOR_SET, *PPROCESSOR_SET;
  253. /*++
  254. Structure Description:
  255. This structure describes the cycle accounting information for a processor.
  256. Members:
  257. UserCycles - Stores the accumulated number of cycles this processor has
  258. spent in user mode.
  259. KernelCycles - Stores the accumulated number of cycles this processor has
  260. spent in kernel mode (not including interrupt and idle time).
  261. InterruptCycles - Stores the accumulated number of cycles this processor
  262. has spent servicing interrupts and DPCs.
  263. IdleCycles - Stores the accumulated number of cycles this processor has
  264. spent idle.
  265. --*/
  266. typedef struct _PROCESSOR_CYCLE_ACCOUNTING {
  267. ULONGLONG UserCycles;
  268. ULONGLONG KernelCycles;
  269. ULONGLONG InterruptCycles;
  270. ULONGLONG IdleCycles;
  271. } PROCESSOR_CYCLE_ACCOUNTING, *PPROCESSOR_CYCLE_ACCOUNTING;
  272. /*++
  273. Structure Description:
  274. This structure contains the context for a scheduling group.
  275. Members:
  276. ListEntry - Stores pointers to the next and previous groups underneath the
  277. parent of this group.
  278. Parent - Stores a pointer to the parent scheduler group.
  279. Children - Stores the head of the list of child scheduler groups this
  280. group owns.
  281. Entries - Stores a pointer to the array of entries for this group.
  282. EntryCount - Stores the element count of the entries array.
  283. ThreadCount - Stores the number of threads, ready or not, that live in the
  284. group.
  285. --*/
  286. struct _SCHEDULER_GROUP {
  287. LIST_ENTRY ListEntry;
  288. PSCHEDULER_GROUP Parent;
  289. LIST_ENTRY Children;
  290. PSCHEDULER_GROUP_ENTRY Entries;
  291. UINTN EntryCount;
  292. UINTN ThreadCount;
  293. };
  294. /*++
  295. Structure Description:
  296. This structure contains the context for a scheduling group on a particular
  297. scheduler (CPU).
  298. Members:
  299. Entry - Stores the regular scheduling entry data.
  300. Children - Stores the head of the list of scheduling entries that are ready
  301. to be run within this group.
  302. ReadyThreadCount - Stores the number of threads inside this group and all
  303. its children (meaning this includes all ready threads inside child and
  304. grandchild groups).
  305. Scheduler - Stores a pointer to the root CPU this group belongs to.
  306. Group - Stores a pointer to the owning group structure.
  307. --*/
  308. struct _SCHEDULER_GROUP_ENTRY {
  309. SCHEDULER_ENTRY Entry;
  310. LIST_ENTRY Children;
  311. UINTN ReadyThreadCount;
  312. PSCHEDULER_DATA Scheduler;
  313. PSCHEDULER_GROUP Group;
  314. };
  315. /*++
  316. Structure Description:
  317. This structure contains the scheduler context for a specific processor.
  318. Members:
  319. Lock - Stores the spin lock serializing access to the scheduling data.
  320. Group - Stores the fixed head scheduling group for this processor.
  321. --*/
  322. struct _SCHEDULER_DATA {
  323. KSPIN_LOCK Lock;
  324. SCHEDULER_GROUP_ENTRY Group;
  325. };
  326. /*++
  327. Structure Description:
  328. This structure contains the state for a pending interrupt on this processor.
  329. Because new interrupts cause the interrupt controller to block all
  330. interrupts at that priority and lower, there can only be at most one
  331. pending interrupt per run level.
  332. Members:
  333. Vector - Stores the interrupt vector.
  334. MagicCandy - Stores the opaque value returned by the interrupt controller
  335. when the interrupt was acknowledged. This is saved because it needs
  336. to be returned to the interrupt controller in the end of interrupt
  337. routine.
  338. InterruptController - Stores a pointer to the interrupt controller that
  339. generated the interrupt.
  340. --*/
  341. typedef struct _PENDING_INTERRUPT {
  342. ULONG Vector;
  343. ULONG MagicCandy;
  344. PVOID InterruptController;
  345. } PENDING_INTERRUPT, *PPENDING_INTERRUPT;
  346. /*++
  347. Structure Description:
  348. This structure contains the state for this processor's dynamic tick
  349. management.
  350. Members:
  351. Mode - Stores the current clock mode.
  352. NextMode - Stores the next clock mode.
  353. DueTime - Stores the next deadline if the current clock mode is one-shot.
  354. CurrentTime - Stores a relatively recent time counter timestamp.
  355. Hard - Stores a boolean indicating if the given due time is hard (must be
  356. met exactly then) or soft (can be met by the next periodic interrupt).
  357. AnyHard - Stores a boolean indicating if there are any hard timers queued
  358. on this processor.
  359. InterruptCount - Stores the total accumulated number of clock interrupts.
  360. NextDebugEvent - Stores the next deadline after which the processor should
  361. perform debug maintenance, either sending out profiling data or
  362. polling the debugger.
  363. --*/
  364. typedef struct _CLOCK_TIMER_DATA {
  365. CLOCK_TIMER_MODE Mode;
  366. CLOCK_TIMER_MODE NextMode;
  367. ULONGLONG DueTime;
  368. ULONGLONG CurrentTime;
  369. BOOL Hard;
  370. BOOL AnyHard;
  371. UINTN InterruptCount;
  372. ULONGLONG NextDebugEvent;
  373. } CLOCK_TIMER_DATA, *PCLOCK_TIMER_DATA;
  374. /*++
  375. Structure Description:
  376. This structure contains the processor identification information.
  377. Members:
  378. Vendor - Stores the CPU vendor. For x86, this contains the EBX portion of
  379. CPUID, function 1. For ARM, this contains the implementor code.
  380. Family - Stores the CPU family ID.
  381. Model - Stores the CPU model ID.
  382. Stepping - Stores the CPU stepping ID.
  383. --*/
  384. typedef struct _PROCESSOR_IDENTIFICATION {
  385. ULONG Vendor;
  386. USHORT Family;
  387. USHORT Model;
  388. USHORT Stepping;
  389. } PROCESSOR_IDENTIFICATION, *PPROCESSOR_IDENTIFICATION;
  390. /*++
  391. Structure Description:
  392. This structure stores the current running state of a processor.
  393. Members:
  394. Self - Stores a pointer to this structure. This is used to get the actual
  395. memory address when the structure is retrieved through unconventional
  396. means (like a segment register).
  397. ProcessorNumber - Stores the zero-based logical processor number.
  398. RunLevel - Stores the current run level of the processor.
  399. Tss - Stores a pointer to the current Task Segment for this processor. This
  400. only applies to PC processors. This member is accessed directly by
  401. assembly code, so its offset must be manually maintained.
  402. Gdt - Stores a pointer to the GDT for this processor. This only applies to
  403. PC processors. This member is accessed directly by assembly code, so
  404. its offset should be manually maintained.
  405. RunningThread - Stores the current thread scheduled on this processor.
  406. PreviousThread - Stores a pointer to the thread that was just scheduled
  407. out, but has yet to be put back on the ready list.
  408. IdleThread - Stores a pointer to the idle thread for this processor.
  409. Scheduler - Stores the scheduler context for this processor.
  410. Idt - Stores a pointer to the Interrupt Descriptor Table.
  411. InterruptTable - Stores an array of pointers to interrupt objects. The
  412. array is indexed by vector number, where the first index is the
  413. minimum vector.
  414. IpiListHead - Stores the list head for IPI request packets.
  415. IpiListLock - Stores the lock protecting access to the IPI list.
  416. PendingInterruptCount - Stores the number of interrupts that are currently
  417. queued to be replayed.
  418. PendingInterrupts - Stores the queue of interrupts that need to be
  419. replayed. This array is the size of the number of hardware levels that
  420. exist, and will always be sorted. It requires that interrupt
  421. controllers never allow interrupts to get through that are less than
  422. or equal to the priority of the current interrupt in service.
  423. PendingDispatchInterrupt - Stores a boolean indicating whether or not a
  424. dispatch level software interrupt is pending.
  425. DpcInProgress - Stores a pointer to the currently executing DPC.
  426. DpcLock - Stores the spin lock protecting the DPC list.
  427. DpcList - Stores the list head of DPCs pending on this processor.
  428. DpcCount - Stores the total number of DPCS that have occurred on this
  429. processor.
  430. TimerData - Stores a pointer to the timer management context.
  431. Clock - Stores the dynamic tick state.
  432. ClockInterruptCount - Stores the number of clock interrupts for this
  433. processor.
  434. CyclePeriodStart - Stores the beginning of the current cycle accounting
  435. period.
  436. CyclePeriodAccount - Stores the attribution of the current cycle accounting
  437. period.
  438. UserCycles - Stores the accumulated number of cycles this processor has
  439. spent in user mode.
  440. KernelCycles - Stores the accumulated number of cycles this processor has
  441. spent in kernel mode (not including interrupt and idle time).
  442. InterruptCycles - Stores the accumulated number of cycles this processor
  443. has spent servicing interrupts and DPCs.
  444. IdleCycles - Stores the accumulated number of cycles this processor has
  445. spent idle.
  446. SwapPage - Stores a pointer to a virtual address that can be used for
  447. temporary mappings.
  448. NmiCount - Stores a count of nested NMIs this processor has taken.
  449. CpuVersion - Stores the processor identification information for this CPU.
  450. --*/
  451. typedef struct _PROCESSOR_BLOCK PROCESSOR_BLOCK, *PPROCESSOR_BLOCK;
  452. struct _PROCESSOR_BLOCK {
  453. PPROCESSOR_BLOCK Self;
  454. ULONG ProcessorNumber;
  455. RUNLEVEL RunLevel;
  456. PVOID Tss;
  457. PVOID Gdt;
  458. PKTHREAD RunningThread;
  459. PKTHREAD PreviousThread;
  460. PKTHREAD IdleThread;
  461. SCHEDULER_DATA Scheduler;
  462. PVOID Idt;
  463. PVOID *InterruptTable;
  464. LIST_ENTRY IpiListHead;
  465. KSPIN_LOCK IpiListLock;
  466. ULONG PendingInterruptCount;
  467. PENDING_INTERRUPT PendingInterrupts[RunLevelCount];
  468. UCHAR PendingDispatchInterrupt;
  469. PDPC DpcInProgress;
  470. KSPIN_LOCK DpcLock;
  471. LIST_ENTRY DpcList;
  472. UINTN DpcCount;
  473. PKTIMER_DATA TimerData;
  474. CLOCK_TIMER_DATA Clock;
  475. ULONGLONG CyclePeriodStart;
  476. CYCLE_ACCOUNT CyclePeriodAccount;
  477. volatile ULONGLONG UserCycles;
  478. volatile ULONGLONG KernelCycles;
  479. volatile ULONGLONG InterruptCycles;
  480. volatile ULONGLONG IdleCycles;
  481. PVOID SwapPage;
  482. UINTN NmiCount;
  483. PROCESSOR_IDENTIFICATION CpuVersion;
  484. };
  485. /*++
  486. Structure Description:
  487. This structure defines usage information for one or more processors.
  488. Members:
  489. ProcessorNumber - Stores the processor number corresponding to the usage,
  490. or -1 if this data represents all processors.
  491. CycleCounterFrequency - Stores the frequency of the cycle counter. If all
  492. processors are included and processors run at different speeds, then
  493. this value may be zero.
  494. Usage - Stores the cycle counter usage information.
  495. --*/
  496. typedef struct _PROCESSOR_USAGE_INFORMATION {
  497. UINTN ProcessorNumber;
  498. ULONGLONG CycleCounterFrequency;
  499. PROCESSOR_CYCLE_ACCOUNTING Usage;
  500. } PROCESSOR_USAGE_INFORMATION, *PPROCESSOR_USAGE_INFORMATION;
  501. /*++
  502. Structure Description:
  503. This structure provides information about the number of processors in the
  504. system.
  505. Members:
  506. MaxProcessorCount - Stores the maximum number of processors that might
  507. be active in the machine.
  508. ActiveProcessorCount - Stores the number of processors online right now.
  509. --*/
  510. typedef struct _PROCESSOR_COUNT_INFORMATION {
  511. UINTN MaxProcessorCount;
  512. UINTN ActiveProcessorCount;
  513. } PROCESSOR_COUNT_INFORMATION, *PPROCESSOR_COUNT_INFORMATION;
  514. /*++
  515. Structure Description:
  516. This structure defines a queued lock. These locks can be used at or below
  517. dispatch level, or only below if paged memory is used.
  518. Members:
  519. Header - Stores the object header.
  520. OwningThread - Stores a pointer to the thread that is holding the lock.
  521. --*/
  522. typedef struct _QUEUED_LOCK {
  523. OBJECT_HEADER Header;
  524. PKTHREAD OwningThread;
  525. } QUEUED_LOCK, *PQUEUED_LOCK;
  526. /*++
  527. Structure Description:
  528. This structure defines an event.
  529. Members:
  530. Header - Stores the object header.
  531. --*/
  532. typedef struct _KEVENT {
  533. OBJECT_HEADER Header;
  534. } KEVENT, *PKEVENT;
  535. /*++
  536. Structure Description:
  537. This structure defines a shared-exclusive lock.
  538. Members:
  539. State - Stores the current state of the shared-exclusive lock. See
  540. SHARED_EXCLUSIVE_LOCK_* definitions.
  541. Event - Stores a pointer to the event that allows for blocking.
  542. ExclusiveWaiters - Stores the number of thread trying to acquire the lock
  543. exclusively.
  544. SharedWaiters - Stores the number of threads trying to acquire the lock
  545. shared.
  546. --*/
  547. typedef struct _SHARED_EXCLUSIVE_LOCK {
  548. volatile ULONG State;
  549. PKEVENT Event;
  550. volatile ULONG ExclusiveWaiters;
  551. volatile ULONG SharedWaiters;
  552. } SHARED_EXCLUSIVE_LOCK, *PSHARED_EXCLUSIVE_LOCK;
  553. /*++
  554. Structure Description:
  555. This structure defines a single kernel argument. An argument takes the
  556. form component.name=value1,value2,...
  557. Members:
  558. Component - Stores a pointer to the string describing the component
  559. receiving the argument.
  560. Name - Stores a pointer to a string containing the name of the argument.
  561. Values - Stores an array of arguments.
  562. ValueCount - Stores the number of valid elements in the array.
  563. --*/
  564. typedef struct _KERNEL_ARGUMENT {
  565. PSTR Component;
  566. PSTR Name;
  567. PSTR Values[KERNEL_MAX_ARGUMENT_VALUES];
  568. ULONG ValueCount;
  569. } KERNEL_ARGUMENT, *PKERNEL_ARGUMENT;
  570. /*++
  571. Structure Description:
  572. This structure defines the kernel command line information.
  573. Members:
  574. Line - Stores a pointer to the complete command line.
  575. LineSize - Stores the size of the command line, including the null
  576. terminator.
  577. Arguments - Stores the array of command arguments. This will be NULL for
  578. user-mode requests; user-mode is responsible for doing its own
  579. splitting.
  580. ArgumentCount - Stores the number of arguments.
  581. --*/
  582. typedef struct _KERNEL_COMMAND_LINE {
  583. PSTR Line;
  584. ULONG LineSize;
  585. PKERNEL_ARGUMENT Arguments;
  586. ULONG ArgumentCount;
  587. } KERNEL_COMMAND_LINE, *PKERNEL_COMMAND_LINE;
  588. typedef
  589. VOID
  590. (*PWORK_ITEM_ROUTINE) (
  591. PVOID Parameter
  592. );
  593. /*++
  594. Routine Description:
  595. This routine prototype represents a work item.
  596. Arguments:
  597. Parameter - Supplies an optional parameter passed in by the creator of the
  598. work item.
  599. Return Value:
  600. None.
  601. --*/
  602. typedef
  603. VOID
  604. (*PDPC_ROUTINE) (
  605. PDPC Dpc
  606. );
  607. /*++
  608. Routine Description:
  609. This routine prototype represents a function that gets called when a DPC
  610. (Deferred Procedure Call) is executed. When this routine is called, it
  611. is safe to requeue or destroy the DPC.
  612. Arguments:
  613. Dpc - Supplies a pointer to the DPC that is running.
  614. Return Value:
  615. None.
  616. --*/
  617. /*++
  618. Structure Description:
  619. This structure defines a Deferred Procedure Call object.
  620. Members:
  621. ListEntry - Stores pointers to the next and previous DPCs in the queue.
  622. DpcRoutine - Stores a pointer to the routine to call when the DPC fires.
  623. UserData - Stores an opaque pointer that the creator of the DPC can use to
  624. store context.
  625. Processor - Stores the processor number this DPC is queued to.
  626. UseCount - Stores the number of entities actively using this object.
  627. Flags - Stores a bitmask of flags for the DPC. See DPC_FLAG_* for
  628. definitions.
  629. --*/
  630. struct _DPC {
  631. LIST_ENTRY ListEntry;
  632. PDPC_ROUTINE DpcRoutine;
  633. PVOID UserData;
  634. ULONG Processor;
  635. volatile ULONG UseCount;
  636. ULONG Flags;
  637. };
  638. /*++
  639. Structure Description:
  640. This structure defines the contents of the user shared data page, which is
  641. shared between kernel mode and user mode.
  642. Members:
  643. EncodedSystemVersion - Stores the encoded system version information.
  644. SystemVersionSerial - Stores the serial system revision.
  645. BuildTime - Stores the system build time (the seconds portion of a system
  646. time structure).
  647. TimeCounterFrequency - Stores the frequency of the time counter. This value
  648. won't change once the system is booted.
  649. ProcessorCounterFrequency - Stores the frequency of the processor counter
  650. on the boot processor. This is roughly related to the processor speed,
  651. but not exactly. For example, on ARM, it may the the processor speed
  652. divided by 64.
  653. TimeOffset - Stores the system time when the time counter was zero.
  654. TimeCounter - Stores the number of ticks since the system was started. This
  655. value is periodically updated and serves only as a reasonable
  656. approximation of the current time counter.
  657. SystemTime - Stores the current system time.
  658. TickCount - Stores the number of clock interrupts that have occurred since
  659. the system started. Clock interrupts do not necessarily occur at the
  660. same interval and thus cannot be used to accurately measure time. This
  661. member is incremented each time the time counter and system time
  662. members are updated, so it can be used to detect torn reads.
  663. TickCount2 - Stores a copy of the tick count value, updated after all the
  664. other time members are updated (with a memory barrier in between the
  665. updates of all other time variables and this one).
  666. ProcessorFeatures - Stores a bitfield of architecture-specific feature
  667. flags.
  668. --*/
  669. typedef struct _USER_SHARED_DATA {
  670. ULONG EncodedSystemVersion;
  671. ULONG SystemVersionSerial;
  672. ULONGLONG BuildTime;
  673. ULONGLONG TimeCounterFrequency;
  674. ULONGLONG ProcessorCounterFrequency;
  675. volatile SYSTEM_TIME TimeOffset;
  676. volatile ULONGLONG TimeCounter;
  677. volatile SYSTEM_TIME SystemTime;
  678. volatile ULONGLONG TickCount;
  679. volatile ULONGLONG TickCount2;
  680. ULONG ProcessorFeatures;
  681. } USER_SHARED_DATA, *PUSER_SHARED_DATA;
  682. //
  683. // -------------------------------------------------------------------- Globals
  684. //
  685. //
  686. // -------------------------------------------------------- Function Prototypes
  687. //
  688. KERNEL_API
  689. KSTATUS
  690. KeGetSystemVersion (
  691. PSYSTEM_VERSION_INFORMATION VersionInformation,
  692. PVOID Buffer,
  693. PULONG BufferSize
  694. );
  695. /*++
  696. Routine Description:
  697. This routine gets the system version information.
  698. Arguments:
  699. VersionInformation - Supplies a pointer where the system version
  700. information will be returned.
  701. Buffer - Supplies an optional pointer to the buffer to use for the
  702. product name and build string.
  703. BufferSize - Supplies an optional pointer that on input contains the size
  704. of the supplied string buffer in bytes. On output, returns the needed
  705. size of the build string buffer in bytes including the null terminator
  706. characters.
  707. Return Value:
  708. STATUS_SUCCESS on success.
  709. STATUS_BUFFER_TOO_SMALL if the supplied buffer was not big enough to hold
  710. both strings.
  711. --*/
  712. KERNEL_API
  713. PQUEUED_LOCK
  714. KeCreateQueuedLock (
  715. VOID
  716. );
  717. /*++
  718. Routine Description:
  719. This routine creates a new queued lock under the current thread. These locks
  720. can be used at up to dispatch level if non-paged memory is used.
  721. Arguments:
  722. None.
  723. Return Value:
  724. Returns a pointer to the new lock on success.
  725. NULL on failure.
  726. --*/
  727. KERNEL_API
  728. VOID
  729. KeDestroyQueuedLock (
  730. PQUEUED_LOCK Lock
  731. );
  732. /*++
  733. Routine Description:
  734. This routine destroys a queued lock by decrementing its reference count.
  735. Arguments:
  736. Lock - Supplies a pointer to the queued lock to destroy.
  737. Return Value:
  738. None. When the function returns, the lock must not be used again.
  739. --*/
  740. KERNEL_API
  741. VOID
  742. KeAcquireQueuedLock (
  743. PQUEUED_LOCK Lock
  744. );
  745. /*++
  746. Routine Description:
  747. This routine acquires the queued lock. If the lock is held, the thread
  748. blocks until it becomes available.
  749. Arguments:
  750. Lock - Supplies a pointer to the queued lock to acquire.
  751. Return Value:
  752. None. When the function returns, the lock will be held.
  753. --*/
  754. KERNEL_API
  755. KSTATUS
  756. KeAcquireQueuedLockTimed (
  757. PQUEUED_LOCK Lock,
  758. ULONG TimeoutInMilliseconds
  759. );
  760. /*++
  761. Routine Description:
  762. This routine acquires the queued lock. If the lock is held, the thread
  763. blocks until it becomes available or the specified timeout expires.
  764. Arguments:
  765. Lock - Supplies a pointer to the queued lock to acquire.
  766. TimeoutInMilliseconds - Supplies the number of milliseconds that the given
  767. object should be waited on before timing out. Use WAIT_TIME_INDEFINITE
  768. to wait forever on the object.
  769. Return Value:
  770. STATUS_SUCCESS on success.
  771. STATUS_TIMEOUT if the specified amount of time expired and the lock could
  772. not be acquired.
  773. --*/
  774. KERNEL_API
  775. VOID
  776. KeReleaseQueuedLock (
  777. PQUEUED_LOCK Lock
  778. );
  779. /*++
  780. Routine Description:
  781. This routine releases a queued lock that has been previously acquired.
  782. Arguments:
  783. Lock - Supplies a pointer to the queued lock to release.
  784. Return Value:
  785. None.
  786. --*/
  787. KERNEL_API
  788. BOOL
  789. KeTryToAcquireQueuedLock (
  790. PQUEUED_LOCK Lock
  791. );
  792. /*++
  793. Routine Description:
  794. This routine attempts to acquire the queued lock. If the lock is busy, it
  795. does not add this thread to the queue of waiters.
  796. Arguments:
  797. Lock - Supplies a pointer to a queued lock.
  798. Return Value:
  799. Returns TRUE if the lock was acquired, or FALSE otherwise.
  800. --*/
  801. KERNEL_API
  802. BOOL
  803. KeIsQueuedLockHeld (
  804. PQUEUED_LOCK Lock
  805. );
  806. /*++
  807. Routine Description:
  808. This routine determines whether a queued lock is acquired or free.
  809. Arguments:
  810. Lock - Supplies a pointer to the queued lock.
  811. Return Value:
  812. TRUE if the queued lock is held.
  813. FALSE if the queued lock is free.
  814. --*/
  815. KERNEL_API
  816. VOID
  817. KeInitializeSpinLock (
  818. PKSPIN_LOCK Lock
  819. );
  820. /*++
  821. Routine Description:
  822. This routine initializes a spinlock.
  823. Arguments:
  824. Lock - Supplies a pointer to the lock to initialize.
  825. Return Value:
  826. None.
  827. --*/
  828. KERNEL_API
  829. VOID
  830. KeAcquireSpinLock (
  831. PKSPIN_LOCK Lock
  832. );
  833. /*++
  834. Routine Description:
  835. This routine acquires a kernel spinlock. It must be acquired at or below
  836. dispatch level. This routine may yield the processor.
  837. Arguments:
  838. Lock - Supplies a pointer to the lock to acquire.
  839. Return Value:
  840. None.
  841. --*/
  842. KERNEL_API
  843. VOID
  844. KeReleaseSpinLock (
  845. PKSPIN_LOCK Lock
  846. );
  847. /*++
  848. Routine Description:
  849. This routine releases a kernel spinlock.
  850. Arguments:
  851. Lock - Supplies a pointer to the lock to release.
  852. Return Value:
  853. None.
  854. --*/
  855. KERNEL_API
  856. BOOL
  857. KeTryToAcquireSpinLock (
  858. PKSPIN_LOCK Lock
  859. );
  860. /*++
  861. Routine Description:
  862. This routine makes one attempt to acquire a spinlock.
  863. Arguments:
  864. Lock - Supplies a pointer to the lock to attempt to acquire.
  865. Return Value:
  866. TRUE if the lock was acquired.
  867. FALSE if the lock was not acquired.
  868. --*/
  869. KERNEL_API
  870. BOOL
  871. KeIsSpinLockHeld (
  872. PKSPIN_LOCK Lock
  873. );
  874. /*++
  875. Routine Description:
  876. This routine determines whether a spin lock is held or free.
  877. Arguments:
  878. Lock - Supplies a pointer to the lock to check.
  879. Return Value:
  880. TRUE if the lock has been acquired.
  881. FALSE if the lock is free.
  882. --*/
  883. KERNEL_API
  884. PSHARED_EXCLUSIVE_LOCK
  885. KeCreateSharedExclusiveLock (
  886. VOID
  887. );
  888. /*++
  889. Routine Description:
  890. This routine creates a shared-exclusive lock.
  891. Arguments:
  892. None.
  893. Return Value:
  894. Returns a pointer to a shared-exclusive lock on success, or NULL on failure.
  895. --*/
  896. KERNEL_API
  897. VOID
  898. KeDestroySharedExclusiveLock (
  899. PSHARED_EXCLUSIVE_LOCK SharedExclusiveLock
  900. );
  901. /*++
  902. Routine Description:
  903. This routine destroys a shared-exclusive lock.
  904. Arguments:
  905. SharedExclusiveLock - Supplies a pointer to a shared-exclusive lock.
  906. Return Value:
  907. None.
  908. --*/
  909. KERNEL_API
  910. VOID
  911. KeAcquireSharedExclusiveLockShared (
  912. PSHARED_EXCLUSIVE_LOCK SharedExclusiveLock
  913. );
  914. /*++
  915. Routine Description:
  916. This routine acquired the given shared-exclusive lock in shared mode.
  917. Arguments:
  918. SharedExclusiveLock - Supplies a pointer to the shared-exclusive lock.
  919. Return Value:
  920. None.
  921. --*/
  922. KERNEL_API
  923. BOOL
  924. KeTryToAcquireSharedExclusiveLockShared (
  925. PSHARED_EXCLUSIVE_LOCK SharedExclusiveLock
  926. );
  927. /*++
  928. Routine Description:
  929. This routine makes a single attempt to acquire the given shared-exclusive
  930. lock in shared mode.
  931. Arguments:
  932. SharedExclusiveLock - Supplies a pointer to the shared-exclusive lock.
  933. Return Value:
  934. TRUE if the lock was successfully acquired shared.
  935. FALSE if the lock was not successfully acquired shared.
  936. --*/
  937. KERNEL_API
  938. VOID
  939. KeReleaseSharedExclusiveLockShared (
  940. PSHARED_EXCLUSIVE_LOCK SharedExclusiveLock
  941. );
  942. /*++
  943. Routine Description:
  944. This routine releases the given shared-exclusive lock from shared mode.
  945. Arguments:
  946. SharedExclusiveLock - Supplies a pointer to the shared-exclusive lock.
  947. Return Value:
  948. None.
  949. --*/
  950. KERNEL_API
  951. VOID
  952. KeAcquireSharedExclusiveLockExclusive (
  953. PSHARED_EXCLUSIVE_LOCK SharedExclusiveLock
  954. );
  955. /*++
  956. Routine Description:
  957. This routine acquired the given shared-exclusive lock in exclusive mode.
  958. Arguments:
  959. SharedExclusiveLock - Supplies a pointer to the shared-exclusive lock.
  960. Return Value:
  961. None.
  962. --*/
  963. KERNEL_API
  964. BOOL
  965. KeTryToAcquireSharedExclusiveLockExclusive (
  966. PSHARED_EXCLUSIVE_LOCK SharedExclusiveLock
  967. );
  968. /*++
  969. Routine Description:
  970. This routine makes a single attempt to acquire the given shared-exclusive
  971. lock exclusively.
  972. Arguments:
  973. SharedExclusiveLock - Supplies a pointer to the shared-exclusive lock.
  974. Return Value:
  975. TRUE if the lock was successfully acquired exclusively.
  976. FALSE if the lock was not successfully acquired.
  977. --*/
  978. KERNEL_API
  979. VOID
  980. KeReleaseSharedExclusiveLockExclusive (
  981. PSHARED_EXCLUSIVE_LOCK SharedExclusiveLock
  982. );
  983. /*++
  984. Routine Description:
  985. This routine releases the given shared-exclusive lock from exclusive mode.
  986. Arguments:
  987. SharedExclusiveLock - Supplies a pointer to the shared-exclusive lock.
  988. Return Value:
  989. None.
  990. --*/
  991. KERNEL_API
  992. VOID
  993. KeSharedExclusiveLockConvertToExclusive (
  994. PSHARED_EXCLUSIVE_LOCK SharedExclusiveLock
  995. );
  996. /*++
  997. Routine Description:
  998. This routine converts a lock that the caller holds shared into one that
  999. the caller holds exclusive. This routine will most likely fully release
  1000. and reacquire the lock.
  1001. Arguments:
  1002. SharedExclusiveLock - Supplies a pointer to the shared-exclusive lock.
  1003. Return Value:
  1004. None.
  1005. --*/
  1006. KERNEL_API
  1007. BOOL
  1008. KeIsSharedExclusiveLockHeld (
  1009. PSHARED_EXCLUSIVE_LOCK SharedExclusiveLock
  1010. );
  1011. /*++
  1012. Routine Description:
  1013. This routine determines whether a shared-exclusive lock is held or free.
  1014. Arguments:
  1015. SharedExclusiveLock - Supplies a pointer to a shared-exclusive lock.
  1016. Return Value:
  1017. Returns TRUE if the shared-exclusive lock is held, or FALSE if not.
  1018. --*/
  1019. KERNEL_API
  1020. BOOL
  1021. KeIsSharedExclusiveLockHeldExclusive (
  1022. PSHARED_EXCLUSIVE_LOCK SharedExclusiveLock
  1023. );
  1024. /*++
  1025. Routine Description:
  1026. This routine determines whether a shared-exclusive lock is held exclusively
  1027. or not.
  1028. Arguments:
  1029. SharedExclusiveLock - Supplies a pointer to a shared-exclusive lock.
  1030. Return Value:
  1031. Returns TRUE if the shared-exclusive lock is held exclusively, or FALSE
  1032. otherwise.
  1033. --*/
  1034. KERNEL_API
  1035. BOOL
  1036. KeIsSharedExclusiveLockHeldShared (
  1037. PSHARED_EXCLUSIVE_LOCK SharedExclusiveLock
  1038. );
  1039. /*++
  1040. Routine Description:
  1041. This routine determines whether a shared-exclusive lock is held shared or
  1042. not.
  1043. Arguments:
  1044. SharedExclusiveLock - Supplies a pointer to a shared-exclusive lock.
  1045. Return Value:
  1046. Returns TRUE if the shared-exclusive lock is held shared, or FALSE
  1047. otherwise.
  1048. --*/
  1049. KERNEL_API
  1050. BOOL
  1051. KeIsSharedExclusiveLockContended (
  1052. PSHARED_EXCLUSIVE_LOCK SharedExclusiveLock
  1053. );
  1054. /*++
  1055. Routine Description:
  1056. This routine determines whether a shared-exclusive lock is being waited on
  1057. for shared or exclusive access.
  1058. Arguments:
  1059. SharedExclusiveLock - Supplies a pointer to a shared-exclusive lock.
  1060. Return Value:
  1061. Returns TRUE if other threads are waiting to acquire the lock, or FALSE
  1062. if the lock is uncontented.
  1063. --*/
  1064. KERNEL_API
  1065. RUNLEVEL
  1066. KeGetRunLevel (
  1067. VOID
  1068. );
  1069. /*++
  1070. Routine Description:
  1071. This routine gets the running level for the current processor.
  1072. Arguments:
  1073. None.
  1074. Return Value:
  1075. Returns the current run level.
  1076. --*/
  1077. KERNEL_API
  1078. PDPC
  1079. KeCreateDpc (
  1080. PDPC_ROUTINE DpcRoutine,
  1081. PVOID UserData
  1082. );
  1083. /*++
  1084. Routine Description:
  1085. This routine creates a new DPC with the given routine and context data.
  1086. Arguments:
  1087. DpcRoutine - Supplies a pointer to the routine to call when the DPC fires.
  1088. UserData - Supplies a context pointer that can be passed to the routine via
  1089. the DPC when it is called.
  1090. Return Value:
  1091. Returns a pointer to the allocated and initialized (but not queued) DPC.
  1092. --*/
  1093. KERNEL_API
  1094. VOID
  1095. KeDestroyDpc (
  1096. PDPC Dpc
  1097. );
  1098. /*++
  1099. Routine Description:
  1100. This routine destroys a DPC. It will cancel the DPC if it is queued, and
  1101. wait for it to finish if it is running. This routine must be called from
  1102. low level.
  1103. Arguments:
  1104. Dpc - Supplies a pointer to the DPC to destroy.
  1105. Return Value:
  1106. None.
  1107. --*/
  1108. KERNEL_API
  1109. VOID
  1110. KeQueueDpc (
  1111. PDPC Dpc
  1112. );
  1113. /*++
  1114. Routine Description:
  1115. This routine queues a DPC on the current processor.
  1116. Arguments:
  1117. Dpc - Supplies a pointer to the DPC to queue.
  1118. Return Value:
  1119. None.
  1120. --*/
  1121. KERNEL_API
  1122. VOID
  1123. KeQueueDpcOnProcessor (
  1124. PDPC Dpc,
  1125. ULONG ProcessorNumber
  1126. );
  1127. /*++
  1128. Routine Description:
  1129. This routine queues a DPC on the given processor.
  1130. Arguments:
  1131. Dpc - Supplies a pointer to the DPC to queue.
  1132. ProcessorNumber - Supplies the processor number of the processor to queue
  1133. the DPC on.
  1134. Return Value:
  1135. None.
  1136. --*/
  1137. KERNEL_API
  1138. KSTATUS
  1139. KeCancelDpc (
  1140. PDPC Dpc
  1141. );
  1142. /*++
  1143. Routine Description:
  1144. This routine attempts to cancel a DPC that has been queued.
  1145. Arguments:
  1146. Dpc - Supplies a pointer to the DPC to cancel.
  1147. Return Value:
  1148. STATUS_SUCCESS if the DPC was successfully pulled out of a queue.
  1149. STATUS_TOO_LATE if the DPC has already started running.
  1150. --*/
  1151. KERNEL_API
  1152. VOID
  1153. KeFlushDpc (
  1154. PDPC Dpc
  1155. );
  1156. /*++
  1157. Routine Description:
  1158. This routine does not return until the given DPC is out of the system. This
  1159. means that the DPC is neither queued nor running. It's worth noting that
  1160. this routine busy spins at dispatch level, and should therefore be used
  1161. only sparingly. This routine can only be called from low level.
  1162. Arguments:
  1163. Dpc - Supplies a pointer to the DPC to wait for.
  1164. Return Value:
  1165. None.
  1166. --*/
  1167. KERNEL_API
  1168. PKTIMER
  1169. KeCreateTimer (
  1170. ULONG AllocationTag
  1171. );
  1172. /*++
  1173. Routine Description:
  1174. This routine creates a new timer object. Once created, this timer needs to
  1175. be initialized before it can be queued. This routine must be called at or
  1176. below dispatch level.
  1177. Arguments:
  1178. AllocationTag - Supplies a pointer to an identifier to use for the
  1179. allocation that uniquely identifies the driver or module allocating the
  1180. timer.
  1181. Return Value:
  1182. Returns a pointer to the timer on success.
  1183. NULL on resource allocation failure.
  1184. --*/
  1185. KERNEL_API
  1186. VOID
  1187. KeDestroyTimer (
  1188. PKTIMER Timer
  1189. );
  1190. /*++
  1191. Routine Description:
  1192. This routine destroys a timer object. If the timer is currently queued, this
  1193. routine cancels the timer and then destroys it. This routine must be called
  1194. at or below dispatch level.
  1195. Arguments:
  1196. Timer - Supplies a pointer to the timer to destroy.
  1197. Return Value:
  1198. None.
  1199. --*/
  1200. KERNEL_API
  1201. KSTATUS
  1202. KeQueueTimer (
  1203. PKTIMER Timer,
  1204. TIMER_QUEUE_TYPE QueueType,
  1205. ULONGLONG DueTime,
  1206. ULONGLONG Period,
  1207. ULONG Flags,
  1208. PDPC Dpc
  1209. );
  1210. /*++
  1211. Routine Description:
  1212. This routine configures and queues a timer object. The timer must not
  1213. already be queued, otherwise the system will crash. This routine must be
  1214. called at or below dispatch level.
  1215. Arguments:
  1216. Timer - Supplies a pointer to the timer to configure and queue.
  1217. QueueType - Supplies the queue the timer should reside on. Valid values are:
  1218. TimerQueueSoft - The timer will be expired at the first applicable
  1219. clock interrupt, but a clock interrupt will not be scheduled solely
  1220. for this timer. This timer type has the best power management
  1221. profile, but may cause the expiration of the timer to be fairly
  1222. late, as the system will not come out of idle to service this timer.
  1223. The DPC for this timer may run on any processor.
  1224. TimerQueueSoftWake - The timer will be expired at the first applicable
  1225. clock interrupt. If the system was otherwise idle, a clock
  1226. interrupt will be scheduled for this timer. This is a balanced
  1227. choice for timers that can have some slack in their expiration, but
  1228. need to run approximately when scheduled, even if the system is
  1229. idle. The DPC will run on the processor where the timer was queued.
  1230. TimerQueueHard - A clock interrupt will be scheduled for exactly the
  1231. specified deadline. This is the best choice for high performance
  1232. timers that need to expire as close to their deadlines as possible.
  1233. It is the most taxing on power management, as it pulls the system
  1234. out of idle, schedules an extra clock interrupt, and requires
  1235. programming hardware. The DPC will run on the processor where the
  1236. timer was queued.
  1237. DueTime - Supplies the value of the time tick counter when this timer
  1238. should expire (an absolute value in time counter ticks). If this value
  1239. is 0, then an automatic due time of the current time plus the given
  1240. period will be computed.
  1241. Period - Supplies an optional period, in time counter ticks, for periodic
  1242. timers. If this value is non-zero, the period will be added to the
  1243. original due time and the timer will be automatically rearmed.
  1244. Flags - Supplies an optional bitfield of flags. See KTIMER_FLAG_*
  1245. definitions.
  1246. Dpc - Supplies an optional pointer to a DPC that will be queued when this
  1247. timer expires.
  1248. Return Value:
  1249. Status code.
  1250. --*/
  1251. KERNEL_API
  1252. KSTATUS
  1253. KeCancelTimer (
  1254. PKTIMER Timer
  1255. );
  1256. /*++
  1257. Routine Description:
  1258. This routine attempts to cancel a queued timer. This routine must be called
  1259. at or below dispatch level. This routine will ensure that the DPC
  1260. associated with the timer will have either been fully queued or not queued
  1261. by the time this function returns, even if the timer was too late to
  1262. cancel.
  1263. Arguments:
  1264. Timer - Supplies a pointer to the timer to cancel.
  1265. Return Value:
  1266. STATUS_SUCCESS if the timer was successfully cancelled.
  1267. STATUS_TOO_LATE if the timer expired before the timer queue could be
  1268. accessed.
  1269. --*/
  1270. KERNEL_API
  1271. VOID
  1272. KeSignalTimer (
  1273. PKTIMER Timer,
  1274. SIGNAL_OPTION Option
  1275. );
  1276. /*++
  1277. Routine Description:
  1278. This routine sets a timer to the given signal state.
  1279. Arguments:
  1280. Timer - Supplies a pointer to the timer to signal or unsignal.
  1281. Option - Supplies the signaling behavior to apply.
  1282. Return Value:
  1283. None.
  1284. --*/
  1285. KERNEL_API
  1286. SIGNAL_STATE
  1287. KeGetTimerState (
  1288. PKTIMER Timer
  1289. );
  1290. /*++
  1291. Routine Description:
  1292. This routine returns the signal state of a timer.
  1293. Arguments:
  1294. Timer - Supplies a pointer to the timer to get the state of.
  1295. Return Value:
  1296. Returns the signal state of the timer.
  1297. --*/
  1298. KERNEL_API
  1299. ULONGLONG
  1300. KeGetTimerDueTime (
  1301. PKTIMER Timer
  1302. );
  1303. /*++
  1304. Routine Description:
  1305. This routine returns the next due time of the given timer. This could be in
  1306. the past. This routine must be called at or below dispatch level.
  1307. Arguments:
  1308. Timer - Supplies a pointer to the timer to query.
  1309. Return Value:
  1310. Returns the due time of the timer.
  1311. 0 if the timer is not currently queued.
  1312. --*/
  1313. KERNEL_API
  1314. ULONGLONG
  1315. KeConvertMicrosecondsToTimeTicks (
  1316. ULONGLONG Microseconds
  1317. );
  1318. /*++
  1319. Routine Description:
  1320. This routine converts the given number of microseconds into time counter
  1321. ticks.
  1322. Arguments:
  1323. Microseconds - Supplies the microsecond count.
  1324. Return Value:
  1325. Returns the number of time ticks that correspond to the given number of
  1326. microseconds.
  1327. --*/
  1328. KERNEL_API
  1329. ULONGLONG
  1330. KeGetRecentTimeCounter (
  1331. VOID
  1332. );
  1333. /*++
  1334. Routine Description:
  1335. This routine returns a relatively recent snap of the time counter.
  1336. Arguments:
  1337. None.
  1338. Return Value:
  1339. Returns the fairly recent snap of the time counter.
  1340. --*/
  1341. KERNEL_API
  1342. KSTATUS
  1343. KeGetSetSystemInformation (
  1344. SYSTEM_INFORMATION_SUBSYSTEM Subsystem,
  1345. UINTN InformationType,
  1346. PVOID Data,
  1347. PUINTN DataSize,
  1348. BOOL Set
  1349. );
  1350. /*++
  1351. Routine Description:
  1352. This routine gets or sets system information.
  1353. Arguments:
  1354. Subsystem - Supplies the subsystem to query or set information of.
  1355. InformationType - Supplies the information type, which is specific to
  1356. the subsystem. The type of this value is generally
  1357. <subsystem>_INFORMATION_TYPE (eg IO_INFORMATION_TYPE).
  1358. Data - Supplies a pointer to the data buffer where the data is either
  1359. returned for a get operation or given for a set operation.
  1360. DataSize - Supplies a pointer that on input contains the size of the
  1361. data buffer. On output, contains the required size of the data buffer.
  1362. Set - Supplies a boolean indicating if this is a get operation (FALSE) or
  1363. a set operation (TRUE).
  1364. Return Value:
  1365. STATUS_SUCCESS if the information was successfully queried or set.
  1366. STATUS_BUFFER_TOO_SMALL if the buffer size specified was too small. The
  1367. required buffer size will be returned in the data size parameter.
  1368. STATUS_DATA_LENGTH_MISMATCH if the buffer size was not correct. The
  1369. correct buffer size will be returned in the data size parameter.
  1370. STATUS_INVALID_PARAMETER if the given subsystem or information type is
  1371. not known.
  1372. Other status codes on other failures.
  1373. --*/
  1374. KERNEL_API
  1375. PKERNEL_ARGUMENT
  1376. KeGetKernelArgument (
  1377. PKERNEL_ARGUMENT Start,
  1378. PCSTR Component,
  1379. PCSTR Name
  1380. );
  1381. /*++
  1382. Routine Description:
  1383. This routine looks up a kernel command line argument.
  1384. Arguments:
  1385. Start - Supplies an optional pointer to the previous command line argument
  1386. to start from. Supply NULL here initially.
  1387. Component - Supplies a pointer to the component string to look up.
  1388. Name - Supplies a pointer to the argument name to look up.
  1389. Return Value:
  1390. Returns a pointer to a matching kernel argument on success.
  1391. NULL if no argument could be found.
  1392. --*/
  1393. KERNEL_API
  1394. KSTATUS
  1395. KeResetSystem (
  1396. SYSTEM_RESET_TYPE ResetType
  1397. );
  1398. /*++
  1399. Routine Description:
  1400. This routine attempts to reboot the system. This routine must be called
  1401. from low level.
  1402. Arguments:
  1403. ResetType - Supplies the desired system reset type. If the given type is
  1404. not supported and a cold reset is, then a cold reset will be
  1405. performed.
  1406. Return Value:
  1407. Does not return on success, the system is reset.
  1408. STATUS_INVALID_PARAMETER if an invalid reset type was supplied.
  1409. STATUS_NOT_SUPPORTED if the system cannot be reset.
  1410. STATUS_UNSUCCESSFUL if the system did not reset.
  1411. --*/
  1412. INTN
  1413. KeSysGetSetSystemInformation (
  1414. PVOID SystemCallParameter
  1415. );
  1416. /*++
  1417. Routine Description:
  1418. This routine implements the user mode system call for getting and setting
  1419. system information.
  1420. Arguments:
  1421. SystemCallParameter - Supplies a pointer to the parameters supplied with
  1422. the system call. This structure will be a stack-local copy of the
  1423. actual parameters passed from user-mode.
  1424. Return Value:
  1425. STATUS_SUCCESS or positive integer on success.
  1426. Error status code on failure.
  1427. --*/
  1428. INTN
  1429. KeSysResetSystem (
  1430. PVOID SystemCallParameter
  1431. );
  1432. /*++
  1433. Routine Description:
  1434. This routine implements the system call for resetting the system.
  1435. Arguments:
  1436. SystemCallParameter - Supplies a pointer to the parameters supplied with
  1437. the system call. This stores the system reset type. It is passed to the
  1438. kernel in a register.
  1439. Return Value:
  1440. STATUS_SUCCESS or positive integer on success.
  1441. Error status code on failure.
  1442. --*/
  1443. PPROCESSOR_BLOCK
  1444. KeGetCurrentProcessorBlock (
  1445. VOID
  1446. );
  1447. /*++
  1448. Routine Description:
  1449. This routine gets the processor state for the currently executing processor.
  1450. Arguments:
  1451. None.
  1452. Return Value:
  1453. Returns the current processor block.
  1454. --*/
  1455. PPROCESSOR_BLOCK
  1456. KeGetCurrentProcessorBlockForDebugger (
  1457. VOID
  1458. );
  1459. /*++
  1460. Routine Description:
  1461. This routine gets the processor block for the currently executing
  1462. processor. It is intended to be called only by the debugger.
  1463. Arguments:
  1464. None.
  1465. Return Value:
  1466. Returns the current processor block.
  1467. --*/
  1468. ULONG
  1469. KeGetCurrentProcessorNumber (
  1470. VOID
  1471. );
  1472. /*++
  1473. Routine Description:
  1474. This routine gets the processor number for the currently executing
  1475. processor.
  1476. Arguments:
  1477. None.
  1478. Return Value:
  1479. Returns the current zero-indexed processor number.
  1480. --*/
  1481. ULONG
  1482. KeGetActiveProcessorCount (
  1483. VOID
  1484. );
  1485. /*++
  1486. Routine Description:
  1487. This routine gets the number of processors currently running in the
  1488. system.
  1489. Arguments:
  1490. None.
  1491. Return Value:
  1492. Returns the number of active processors currently in the system.
  1493. --*/
  1494. PKTHREAD
  1495. KeGetCurrentThread (
  1496. VOID
  1497. );
  1498. /*++
  1499. Routine Description:
  1500. This routine gets the current thread running on this processor.
  1501. Arguments:
  1502. None.
  1503. Return Value:
  1504. Returns the current run level.
  1505. --*/
  1506. KERNEL_API
  1507. RUNLEVEL
  1508. KeRaiseRunLevel (
  1509. RUNLEVEL RunLevel
  1510. );
  1511. /*++
  1512. Routine Description:
  1513. This routine raises the running level of the current processor to the given
  1514. level.
  1515. Arguments:
  1516. RunLevel - Supplies the new running level of the current processor.
  1517. Return Value:
  1518. Returns the old running level of the processor.
  1519. --*/
  1520. KERNEL_API
  1521. VOID
  1522. KeLowerRunLevel (
  1523. RUNLEVEL RunLevel
  1524. );
  1525. /*++
  1526. Routine Description:
  1527. This routine lowers the running level of the current processor to the given
  1528. level.
  1529. Arguments:
  1530. RunLevel - Supplies the new running level of the current processor.
  1531. Return Value:
  1532. None.
  1533. --*/
  1534. KERNEL_API
  1535. PKEVENT
  1536. KeCreateEvent (
  1537. PVOID ParentObject
  1538. );
  1539. /*++
  1540. Routine Description:
  1541. This routine creates a kernel event. It comes initialized to Not Signaled.
  1542. Arguments:
  1543. ParentObject - Supplies an optional parent object to create the event
  1544. under.
  1545. Return Value:
  1546. Returns a pointer to the event, or NULL if the event could not be created.
  1547. --*/
  1548. KERNEL_API
  1549. VOID
  1550. KeDestroyEvent (
  1551. PKEVENT Event
  1552. );
  1553. /*++
  1554. Routine Description:
  1555. This routine destroys an event created with KeCreateEvent. The event is no
  1556. longer valid after this call.
  1557. Arguments:
  1558. Event - Supplies a pointer to the event to free.
  1559. Return Value:
  1560. None.
  1561. --*/
  1562. KERNEL_API
  1563. KSTATUS
  1564. KeWaitForEvent (
  1565. PKEVENT Event,
  1566. BOOL Interruptible,
  1567. ULONG TimeoutInMilliseconds
  1568. );
  1569. /*++
  1570. Routine Description:
  1571. This routine waits until an event enters a signaled state.
  1572. Arguments:
  1573. Event - Supplies a pointer to the event to wait for.
  1574. Interruptible - Supplies a boolean indicating whether or not the wait can
  1575. be interrupted if a signal is sent to the process on which this thread
  1576. runs. If TRUE is supplied, the caller must check the return status
  1577. code to find out if the wait was really satisfied or just interrupted.
  1578. TimeoutInMilliseconds - Supplies the number of milliseconds that the given
  1579. objects should be waited on before timing out. Use WAIT_TIME_INDEFINITE
  1580. to wait forever on these objects.
  1581. Return Value:
  1582. Status code.
  1583. --*/
  1584. KERNEL_API
  1585. VOID
  1586. KeSignalEvent (
  1587. PKEVENT Event,
  1588. SIGNAL_OPTION Option
  1589. );
  1590. /*++
  1591. Routine Description:
  1592. This routine sets an event to the given signal state.
  1593. Arguments:
  1594. Event - Supplies a pointer to the event to signal or unsignal.
  1595. Option - Supplies the signaling behavior to apply.
  1596. Return Value:
  1597. None.
  1598. --*/
  1599. KERNEL_API
  1600. SIGNAL_STATE
  1601. KeGetEventState (
  1602. PKEVENT Event
  1603. );
  1604. /*++
  1605. Routine Description:
  1606. This routine returns the signal state of an event.
  1607. Arguments:
  1608. Event - Supplies a pointer to the event to get the state of.
  1609. Return Value:
  1610. Returns the signal state of the event.
  1611. --*/
  1612. KERNEL_API
  1613. PWORK_QUEUE
  1614. KeCreateWorkQueue (
  1615. ULONG Flags,
  1616. PCSTR Name
  1617. );
  1618. /*++
  1619. Routine Description:
  1620. This routine creates a new work queue.
  1621. Arguments:
  1622. Flags - Supplies a bitfield of flags governing the behavior of the work
  1623. queue. See WORK_QUEUE_FLAG_* definitions.
  1624. Name - Supplies an optional pointer to the name of the worker threads
  1625. created. A copy of this memory will be made. This should only be used
  1626. for debugging, as text may be added to the end of the name supplied
  1627. here to the actual worker thread names.
  1628. Return Value:
  1629. Returns a pointer to the new work queue on success.
  1630. NULL on failure.
  1631. --*/
  1632. KERNEL_API
  1633. VOID
  1634. KeDestroyWorkQueue (
  1635. PWORK_QUEUE WorkQueue
  1636. );
  1637. /*++
  1638. Routine Description:
  1639. This routine destroys a work queue. If there are items on the work queue,
  1640. they will be completed.
  1641. Arguments:
  1642. WorkQueue - Supplies a pointer to the work queue to destroy.
  1643. Return Value:
  1644. None.
  1645. --*/
  1646. KERNEL_API
  1647. VOID
  1648. KeFlushWorkQueue (
  1649. PWORK_QUEUE WorkQueue
  1650. );
  1651. /*++
  1652. Routine Description:
  1653. This routine flushes a work queue. If there are items on the work queue,
  1654. they will be completed before this routine returns.
  1655. Arguments:
  1656. WorkQueue - Supplies a pointer to the work queue to flush.
  1657. Return Value:
  1658. None.
  1659. --*/
  1660. KERNEL_API
  1661. PWORK_ITEM
  1662. KeCreateWorkItem (
  1663. PWORK_QUEUE WorkQueue,
  1664. WORK_PRIORITY Priority,
  1665. PWORK_ITEM_ROUTINE WorkRoutine,
  1666. PVOID Parameter,
  1667. ULONG AllocationTag
  1668. );
  1669. /*++
  1670. Routine Description:
  1671. This routine creates a new reusable work item.
  1672. Arguments:
  1673. WorkQueue - Supplies a pointer to the queue this work item will
  1674. eventually be queued to. Supply NULL to use the system work queue.
  1675. Priority - Supplies the work priority.
  1676. WorkRoutine - Supplies the routine to execute to does the work. This
  1677. routine should be prepared to take one parameter.
  1678. Parameter - Supplies an optional parameter to pass to the worker routine.
  1679. AllocationTag - Supplies an allocation tag to associate with the work item.
  1680. Return Value:
  1681. Returns a pointer to the new work item on success.
  1682. NULL on failure.
  1683. --*/
  1684. KERNEL_API
  1685. VOID
  1686. KeDestroyWorkItem (
  1687. PWORK_ITEM WorkItem
  1688. );
  1689. /*++
  1690. Routine Description:
  1691. This routine destroys a reusable work item. If this is a work item that
  1692. can re-queue itself, then the caller needs to make sure that that can no
  1693. longer happen before trying to destroy the work item.
  1694. Arguments:
  1695. WorkItem - Supplies a pointer to the work item.
  1696. Return Value:
  1697. None.
  1698. --*/
  1699. KERNEL_API
  1700. KSTATUS
  1701. KeCancelWorkItem (
  1702. PWORK_ITEM WorkItem
  1703. );
  1704. /*++
  1705. Routine Description:
  1706. This routine attempts to cancel the work item. If the work item is still on
  1707. its work queue them this routine will pull it off and return successfully.
  1708. Otherwise the work item may have been selected to run and this routine will
  1709. return that the cancel was too late. Keep in mind that "too late" may also
  1710. mean "too early" if the work item was never queued.
  1711. Arguments:
  1712. WorkItem - Supplies a pointer to the work item to cancel.
  1713. Return Value:
  1714. Status code.
  1715. --*/
  1716. KERNEL_API
  1717. VOID
  1718. KeFlushWorkItem (
  1719. PWORK_ITEM WorkItem
  1720. );
  1721. /*++
  1722. Routine Description:
  1723. This routine does not return until the given work item has completed.
  1724. Arguments:
  1725. WorkItem - Supplies a pointer to the work item.
  1726. Return Value:
  1727. None.
  1728. --*/
  1729. KERNEL_API
  1730. VOID
  1731. KeSetWorkItemParameters (
  1732. PWORK_ITEM WorkItem,
  1733. WORK_PRIORITY Priority,
  1734. PWORK_ITEM_ROUTINE WorkRoutine,
  1735. PVOID Parameter
  1736. );
  1737. /*++
  1738. Routine Description:
  1739. This routine resets the parameters of a work item to the given parameters.
  1740. The work item must not be queued. This routine must be called at or below
  1741. dispatch level.
  1742. Arguments:
  1743. WorkItem - Supplies a pointer to the work item to modify.
  1744. Priority - Supplies the new work priority.
  1745. WorkRoutine - Supplies the routine to execute to does the work. This
  1746. routine should be prepared to take one parameter.
  1747. Parameter - Supplies an optional parameter to pass to the worker routine.
  1748. Return Value:
  1749. None.
  1750. --*/
  1751. KERNEL_API
  1752. KSTATUS
  1753. KeQueueWorkItem (
  1754. PWORK_ITEM WorkItem
  1755. );
  1756. /*++
  1757. Routine Description:
  1758. This routine queues a work item onto the work queue for execution as soon
  1759. as possible. This routine must be called from dispatch level or below.
  1760. Arguments:
  1761. WorkItem - Supplies a pointer to the work item to queue.
  1762. Return Value:
  1763. STATUS_SUCCESS on success.
  1764. STATUS_RESOURCE_IN_USE if the work item is already queued.
  1765. --*/
  1766. KERNEL_API
  1767. KSTATUS
  1768. KeCreateAndQueueWorkItem (
  1769. PWORK_QUEUE WorkQueue,
  1770. WORK_PRIORITY Priority,
  1771. PWORK_ITEM_ROUTINE WorkRoutine,
  1772. PVOID Parameter
  1773. );
  1774. /*++
  1775. Routine Description:
  1776. This routine creates and queues a work item. This work item will get
  1777. executed in a worker thread an arbitrary amount of time later. The work item
  1778. will be automatically freed after the work routine is executed.
  1779. Arguments:
  1780. WorkQueue - Supplies a pointer to the queue this work item will
  1781. eventually be queued to. Supply NULL to use the system work queue.
  1782. Priority - Supplies the work priority.
  1783. WorkRoutine - Supplies the routine to execute to doe the work. This
  1784. routine should be prepared to take one parameter.
  1785. Parameter - Supplies an optional parameter to pass to the worker routine.
  1786. Return Value:
  1787. STATUS_SUCCESS on success.
  1788. STATUS_UNSUCCESSFUL on failure.
  1789. --*/
  1790. KERNEL_API
  1791. KSTATUS
  1792. KeGetRandomBytes (
  1793. PVOID Buffer,
  1794. UINTN Size
  1795. );
  1796. /*++
  1797. Routine Description:
  1798. This routine returns pseudo-random bytes from the system's random source.
  1799. Arguments:
  1800. Buffer - Supplies a pointer where the random bytes will be returned on
  1801. success.
  1802. Size - Supplies the number of bytes of random data to get.
  1803. Return Value:
  1804. STATUS_SUCCESS on success.
  1805. STATUS_NO_SUCH_DEVICE if no pseudo-random interface is present.
  1806. --*/
  1807. INTN
  1808. KeSysDelayExecution (
  1809. PVOID SystemCallParameter
  1810. );
  1811. /*++
  1812. Routine Description:
  1813. This routine implements the system call for delaying execution of the
  1814. current thread by a specified amount of time.
  1815. Arguments:
  1816. SystemCallParameter - Supplies a pointer to the parameters supplied with
  1817. the system call. This structure will be a stack-local copy of the
  1818. actual parameters passed from user-mode.
  1819. Return Value:
  1820. STATUS_SUCCESS or positive integer on success.
  1821. Error status code on failure.
  1822. --*/
  1823. INTN
  1824. KeSysSetSystemTime (
  1825. PVOID SystemCallParameter
  1826. );
  1827. /*++
  1828. Routine Description:
  1829. This routine implements the system call for setting the system time.
  1830. Arguments:
  1831. SystemCallParameter - Supplies a pointer to the parameters supplied with
  1832. the system call. This structure will be a stack-local copy of the
  1833. actual parameters passed from user-mode.
  1834. Return Value:
  1835. STATUS_SUCCESS or positive integer on success.
  1836. Error status code on failure.
  1837. --*/
  1838. VOID
  1839. KeClockInterrupt (
  1840. VOID
  1841. );
  1842. /*++
  1843. Routine Description:
  1844. This routine handles periodic clock interrupts, updating system time and
  1845. providing pre-emptive scheduling.
  1846. Arguments:
  1847. None.
  1848. Return Value:
  1849. None.
  1850. --*/
  1851. ULONG
  1852. KeGetClockInterruptCount (
  1853. ULONG ProcessorNumber
  1854. );
  1855. /*++
  1856. Routine Description:
  1857. This routine returns the clock interrupt count of the given processor.
  1858. Arguments:
  1859. ProcessorNumber - Supplies the number of the processor whose clock
  1860. interrupt count is to be returned.
  1861. Return Value:
  1862. Returns the given processor's clock interrupt count.
  1863. --*/
  1864. VOID
  1865. KeUpdateClockForProfiling (
  1866. BOOL ProfilingEnabled
  1867. );
  1868. /*++
  1869. Routine Description:
  1870. This routine configures the clock interrupt handler for profiling.
  1871. Arguments:
  1872. ProfilingEnabled - Supplies a boolean indicating if profiling is being
  1873. enabled (TRUE) or disabled (FALSE).
  1874. Return Value:
  1875. None.
  1876. --*/
  1877. VOID
  1878. KeDispatchSoftwareInterrupt (
  1879. RUNLEVEL RunLevel,
  1880. PTRAP_FRAME TrapFrame
  1881. );
  1882. /*++
  1883. Routine Description:
  1884. This routine handles a software interrupt. Consider it the ISR for
  1885. software interrupts. On entry, interrupts are disabled. This routine may
  1886. enable interrupts, but must exit with the interrupts disabled.
  1887. Arguments:
  1888. RunLevel - Supplies the run level that that interrupt occurred on.
  1889. TrapFrame - Supplies an optional pointer to the trap frame if this interrupt
  1890. is being dispatched off a hardware interrupt. Supplying this variable
  1891. enables checking for any pending user-mode signals.
  1892. Return Value:
  1893. None.
  1894. --*/
  1895. PPROCESSOR_BLOCK
  1896. KeGetProcessorBlock (
  1897. ULONG ProcessorNumber
  1898. );
  1899. /*++
  1900. Routine Description:
  1901. This routine returns the processor block for the given processor number.
  1902. Arguments:
  1903. ProcessorNumber - Supplies the number of the processor.
  1904. Return Value:
  1905. Returns the processor block for the given processor.
  1906. NULL if the input was not a valid processor number.
  1907. --*/
  1908. KSTATUS
  1909. KeSendIpi (
  1910. PIPI_ROUTINE IpiRoutine,
  1911. PVOID IpiContext,
  1912. PPROCESSOR_SET Processors
  1913. );
  1914. /*++
  1915. Routine Description:
  1916. This routine runs the given routine at IPI level on the specified set of
  1917. processors. This routine runs synchronously: the routine will have completed
  1918. running on all processors by the time this routine returns. This routine
  1919. must be called at or below dispatch level.
  1920. Arguments:
  1921. IpiRoutine - Supplies a pointer to the routine to run at IPI level.
  1922. IpiContext - Supplies the value to pass to the IPI routine as a parameter.
  1923. Processors - Supplies the set of processors to run the IPI on.
  1924. Return Value:
  1925. Status code.
  1926. --*/
  1927. KERNEL_API
  1928. VOID
  1929. KeYield (
  1930. VOID
  1931. );
  1932. /*++
  1933. Routine Description:
  1934. This routine yields the current thread's execution. The thread remains in
  1935. the ready state, and may not actually be scheduled out if no other threads
  1936. are ready.
  1937. Arguments:
  1938. None.
  1939. Return Value:
  1940. None.
  1941. --*/
  1942. KERNEL_API
  1943. VOID
  1944. KeGetSystemTime (
  1945. PSYSTEM_TIME Time
  1946. );
  1947. /*++
  1948. Routine Description:
  1949. This routine returns the current system time.
  1950. Arguments:
  1951. Time - Supplies a pointer where the system time will be returned.
  1952. Return Value:
  1953. None.
  1954. --*/
  1955. VOID
  1956. KeGetHighPrecisionSystemTime (
  1957. PSYSTEM_TIME Time
  1958. );
  1959. /*++
  1960. Routine Description:
  1961. This routine returns a high precision snap of the current system time.
  1962. Arguments:
  1963. Time - Supplies a pointer that receives the precise system time.
  1964. Return Value:
  1965. None.
  1966. --*/
  1967. KSTATUS
  1968. KeSetSystemTime (
  1969. PSYSTEM_TIME NewTime,
  1970. ULONGLONG TimeCounter
  1971. );
  1972. /*++
  1973. Routine Description:
  1974. This routine sets the system time.
  1975. Arguments:
  1976. NewTime - Supplies a pointer to the new system time to set.
  1977. TimeCounter - Supplies the time counter value corresponding with the
  1978. moment the new system time was meant to be set by the caller.
  1979. Return Value:
  1980. Status code.
  1981. --*/
  1982. KERNEL_API
  1983. KSTATUS
  1984. KeDelayExecution (
  1985. BOOL Interruptible,
  1986. BOOL TimeTicks,
  1987. ULONGLONG Interval
  1988. );
  1989. /*++
  1990. Routine Description:
  1991. This routine blocks the current thread for the specified amount of time.
  1992. This routine can only be called at low level.
  1993. Arguments:
  1994. Interruptible - Supplies a boolean indicating if the wait can be
  1995. interrupted by a dispatched signal. If TRUE, the caller must check the
  1996. return status code to see if the wait expired or was interrupted.
  1997. TimeTicks - Supplies a boolean indicating if the interval parameter is
  1998. represented in time counter ticks (TRUE) or microseconds (FALSE).
  1999. Interval - Supplies the interval to wait. If the time ticks parameter is
  2000. TRUE, this parameter represents an absolute time in time counter ticks.
  2001. If the time ticks parameter is FALSE, this parameter represents a
  2002. relative time from now in microseconds. If an interval of 0 is
  2003. supplied, this routine is equivalent to KeYield.
  2004. Return Value:
  2005. STATUS_SUCCESS if the wait completed.
  2006. STATUS_INTERRUPTED if the wait was interrupted.
  2007. --*/
  2008. KERNEL_API
  2009. KSTATUS
  2010. KeGetProcessorCycleAccounting (
  2011. ULONG ProcessorNumber,
  2012. PPROCESSOR_CYCLE_ACCOUNTING Accounting
  2013. );
  2014. /*++
  2015. Routine Description:
  2016. This routine returns a snapshot of the given processor's cycle accounting
  2017. information.
  2018. Arguments:
  2019. ProcessorNumber - Supplies the processor number to query.
  2020. Accounting - Supplies a pointer where the processor accounting information
  2021. will be returned.
  2022. Return Value:
  2023. STATUS_SUCCESS on success.
  2024. STATUS_INVALID_PARAMETER if an invalid processor number was supplied.
  2025. --*/
  2026. KERNEL_API
  2027. VOID
  2028. KeGetTotalProcessorCycleAccounting (
  2029. PPROCESSOR_CYCLE_ACCOUNTING Accounting
  2030. );
  2031. /*++
  2032. Routine Description:
  2033. This routine returns a snapshot of the accumulation of all processors'
  2034. cycle accounting information.
  2035. Arguments:
  2036. Accounting - Supplies a pointer where the processor accounting information
  2037. will be returned.
  2038. Return Value:
  2039. None.
  2040. --*/
  2041. VOID
  2042. KeSchedulerEntry (
  2043. SCHEDULER_REASON Reason
  2044. );
  2045. /*++
  2046. Routine Description:
  2047. This routine serves as the entry point to the thread scheduler. It may
  2048. decide to schedule a new thread or simply return.
  2049. Arguments:
  2050. Reason - Supplies the scheduler with the reason why it's being called (ie
  2051. run-level lowering, the thread is waiting, exiting, etc).
  2052. Return Value:
  2053. None.
  2054. --*/
  2055. VOID
  2056. KeSetThreadReady (
  2057. PKTHREAD Thread
  2058. );
  2059. /*++
  2060. Routine Description:
  2061. This routine unblocks a previously blocked thread and adds it to the
  2062. ready queue.
  2063. Arguments:
  2064. Thread - Supplies a pointer to the blocked thread.
  2065. Return Value:
  2066. None.
  2067. --*/
  2068. VOID
  2069. KeSuspendExecution (
  2070. VOID
  2071. );
  2072. /*++
  2073. Routine Description:
  2074. This routine suspends execution of the current thread until such time as
  2075. another thread wakes it (usually because of a user mode signal).
  2076. Arguments:
  2077. None.
  2078. Return Value:
  2079. None. The function returns when another thread has woken this thread.
  2080. --*/
  2081. VOID
  2082. KeUnlinkSchedulerEntry (
  2083. PSCHEDULER_ENTRY Entry
  2084. );
  2085. /*++
  2086. Routine Description:
  2087. This routine unlinks a scheduler entry from its parent group.
  2088. Arguments:
  2089. Entry - Supplies a pointer to the entry to be unlinked.
  2090. Return Value:
  2091. None.
  2092. --*/
  2093. VOID
  2094. KeIdleLoop (
  2095. VOID
  2096. );
  2097. /*++
  2098. Routine Description:
  2099. This routine executes the idle loop. It does not return. It can be
  2100. executed only from the idle thread.
  2101. Arguments:
  2102. None.
  2103. Return Value:
  2104. None.
  2105. --*/
  2106. CYCLE_ACCOUNT
  2107. KeBeginCycleAccounting (
  2108. CYCLE_ACCOUNT CycleAccount
  2109. );
  2110. /*++
  2111. Routine Description:
  2112. This routine begins a new period of cycle accounting for the current
  2113. processor.
  2114. Arguments:
  2115. CycleAccount - Supplies the type of time to attribute these cycles to.
  2116. Return Value:
  2117. Returns the previous type that cycles were being attributed to.
  2118. --*/
  2119. VOID
  2120. KeRegisterCrashDumpFile (
  2121. HANDLE Handle,
  2122. BOOL Register
  2123. );
  2124. /*++
  2125. Routine Description:
  2126. This routine registers a file for use as a crash dump file.
  2127. Arguments:
  2128. Handle - Supplies a handle to the page file to register.
  2129. Register - Supplies a boolean indicating if the page file is registering
  2130. (TRUE) or de-registering (FALSE).
  2131. Return Value:
  2132. None.
  2133. --*/
  2134. //
  2135. // Video printing routines
  2136. //
  2137. VOID
  2138. KeVideoPrintString (
  2139. ULONG XCoordinate,
  2140. ULONG YCoordinate,
  2141. PCSTR String
  2142. );
  2143. /*++
  2144. Routine Description:
  2145. This routine prints a null-terminated string to the screen at the
  2146. specified location.
  2147. Arguments:
  2148. Context - Supplies a pointer to the initialized base video context.
  2149. XCoordinate - Supplies the X coordinate of the location on the screen
  2150. to write to.
  2151. YCoordinate - Supplies the Y cooordinate of the location on the screen
  2152. to write to.
  2153. String - Supplies the string to print.
  2154. Return Value:
  2155. None.
  2156. --*/
  2157. VOID
  2158. KeVideoPrintHexInteger (
  2159. ULONG XCoordinate,
  2160. ULONG YCoordinate,
  2161. ULONG Number
  2162. );
  2163. /*++
  2164. Routine Description:
  2165. This routine prints an integer to the screen in the specified location.
  2166. Arguments:
  2167. XCoordinate - Supplies the X coordinate of the location on the screen
  2168. to write to.
  2169. YCoordinate - Supplies the Y cooordinate of the location on the screen
  2170. to write to.
  2171. Number - Supplies the signed integer to print.
  2172. Return Value:
  2173. None.
  2174. --*/
  2175. VOID
  2176. KeVideoPrintInteger (
  2177. ULONG XCoordinate,
  2178. ULONG YCoordinate,
  2179. LONG Number
  2180. );
  2181. /*++
  2182. Routine Description:
  2183. This routine prints an integer to the screen in the specified location.
  2184. Arguments:
  2185. Context - Supplies a pointer to the initialized base video context.
  2186. XCoordinate - Supplies the X coordinate of the location on the screen
  2187. to write to.
  2188. YCoordinate - Supplies the Y cooordinate of the location on the screen
  2189. to write to.
  2190. Number - Supplies the signed integer to print.
  2191. Return Value:
  2192. None.
  2193. --*/
  2194. VOID
  2195. KeVideoClearScreen (
  2196. LONG MinimumX,
  2197. LONG MinimumY,
  2198. LONG MaximumX,
  2199. LONG MaximumY
  2200. );
  2201. /*++
  2202. Routine Description:
  2203. This routine clears a portion of the video screen.
  2204. Arguments:
  2205. MinimumX - Supplies the minimum X coordinate of the rectangle to clear,
  2206. inclusive.
  2207. MinimumY - Supplies the minimum Y coordinate of the rectangle to clear,
  2208. inclusive.
  2209. MaximumX - Supplies the maximum X coordinate of the rectangle to clear,
  2210. exclusive.
  2211. MaximumY - Supplies the maximum Y coordinate of the rectangle to clear,
  2212. exclusive.
  2213. Return Value:
  2214. None.
  2215. --*/
  2216. KSTATUS
  2217. KeVideoGetDimensions (
  2218. PULONG Width,
  2219. PULONG Height,
  2220. PULONG CellWidth,
  2221. PULONG CellHeight,
  2222. PULONG Columns,
  2223. PULONG Rows
  2224. );
  2225. /*++
  2226. Routine Description:
  2227. This routine returns the dimensions of the kernel's video frame buffer.
  2228. Arguments:
  2229. Width - Supplies an optional pointer where the width in pixels will be
  2230. returned. For text-based frame buffers, this will be equal to the
  2231. number of text columns.
  2232. Height - Supplies an optional pointer where the height in pixels will be
  2233. returned. For text-based frame buffers, this will be equal to the
  2234. number of text rows.
  2235. CellWidth - Supplies an optional pointer where the width in pixels of a
  2236. text character will be returned on success. For text-based frame
  2237. buffers, 1 will be returned.
  2238. CellHeight - Supplies an optional pointer where the height in pixels of a
  2239. text character will be returned on success. For text-based frame
  2240. buffers, 1 will be returned.
  2241. Columns - Supplies an optional pointer where the number of text columns
  2242. will be returned.
  2243. Rows - Supplies an optional pointer where the number of text rows will be
  2244. returned.
  2245. Return Value:
  2246. STATUS_SUCCESS on success.
  2247. STATUS_NOT_INITIALIZED if there is no frame buffer.
  2248. --*/
  2249. INTN
  2250. KeSystemCallHandler (
  2251. ULONG SystemCallNumber,
  2252. PVOID SystemCallParameter,
  2253. PTRAP_FRAME TrapFrame,
  2254. PUINTN SignalPending
  2255. );
  2256. /*++
  2257. Routine Description:
  2258. This routine responds to requests from user mode entered via a system call.
  2259. It may also be called by the restore system call in order to restart a
  2260. system call. This should not be seen as a general way to invoke system call
  2261. behavior from inside the kernel.
  2262. Arguments:
  2263. SystemCallNumber - Supplies the system call number.
  2264. SystemCallParameter - Supplies a pointer to the parameters supplied with
  2265. the system call.
  2266. TrapFrame - Supplies a pointer to the trap frame generated by this jump
  2267. from user mode to kernel mode.
  2268. SignalPending - Supplies a pointer where a boolean will be returned
  2269. indicating if a signal is pending on the current thread or process that
  2270. needs to be dispatched.
  2271. Return Value:
  2272. STATUS_SUCCESS or positive integer on success.
  2273. Error status code on failure.
  2274. --*/