ps.h 91 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741
  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. ps.h
  9. Abstract:
  10. This header contains definitions for the kernel process and thread library.
  11. Author:
  12. Evan Green 6-Aug-2012
  13. --*/
  14. //
  15. // ------------------------------------------------------------------- Includes
  16. //
  17. //
  18. // --------------------------------------------------------------------- Macros
  19. //
  20. //
  21. // This macro creates a mask from the given permission.
  22. //
  23. #define PERMISSION_TO_MASK(_Permission) (1ULL << (_Permission))
  24. //
  25. // This macro adds a permission to a permission set.
  26. //
  27. #define PERMISSION_ADD(_PermissionSet, _Permission) \
  28. ((_PermissionSet) |= PERMISSION_TO_MASK(_Permission))
  29. //
  30. // This macro removes a permission from a permission set.
  31. //
  32. #define PERMISSION_REMOVE(_PermissionSet, _Permission) \
  33. ((_PermissionSet) &= ~PERMISSION_TO_MASK(_Permission))
  34. //
  35. // This macro evaluates to non-zero if the given permission is in the given
  36. // set.
  37. //
  38. #define PERMISSION_CHECK(_PermissionSet, _Permission) \
  39. (((_PermissionSet) & PERMISSION_TO_MASK(_Permission)) != 0)
  40. //
  41. // This macro ORs two permission sets together, writing the result to the
  42. // first set.
  43. //
  44. #define PERMISSION_OR(_DestinationSet, _SetToOr) \
  45. ((_DestinationSet) |= (_SetToOr))
  46. //
  47. // This macro ANDs two permission sets together, writing the result to the
  48. // first set.
  49. //
  50. #define PERMISSION_AND(_DestinationSet, _SetToAnd) \
  51. ((_DestinationSet) &= (_SetToAnd))
  52. //
  53. // This macro removes all signals in the second set from the first set.
  54. //
  55. #define PERMISSION_REMOVE_SET(_DestinationSet, _SetToRemove) \
  56. ((_DestinationSet) &= ~(_SetToRemove))
  57. //
  58. // This macro evaluates to non-zero if the given permission set is the empty
  59. // set.
  60. //
  61. #define PERMISSION_IS_EMPTY(_Set) ((_Set) == PERMISSION_SET_EMPTY)
  62. //
  63. // This macro dispatches pending signals on the given thread if there are any.
  64. //
  65. #define PsDispatchPendingSignals(_Thread, _TrapFrame) \
  66. if ((_Thread)->SignalPending != ThreadNoSignalPending) { \
  67. PsApplyPendingSignals(_TrapFrame); \
  68. }
  69. //
  70. // This macro performs a quick inline check to see if any of the runtime timers
  71. // are armed, and only then calls the real check function.
  72. //
  73. #define PsCheckRuntimeTimers(_Thread) \
  74. (((_Thread)->UserTimer.DueTime | (_Thread)->ProfileTimer.DueTime) ? \
  75. PsEvaluateRuntimeTimers((_Thread)) : 0)
  76. //
  77. // These macros acquire the lock protecting the loaded image list.
  78. //
  79. #define PsAcquireImageListLock(_Process) \
  80. KeAcquireQueuedLock((_Process)->QueuedLock)
  81. #define PsReleaseImageListLock(_Process) \
  82. KeReleaseQueuedLock((_Process)->QueuedLock)
  83. //
  84. // This macro evaluates to non-zero if the given process is a session leader.
  85. //
  86. #define PsIsSessionLeader(_Process) \
  87. ((_Process)->Identifiers.SessionId == (_Process)->Identifiers.ProcessId)
  88. //
  89. // ---------------------------------------------------------------- Definitions
  90. //
  91. //
  92. // Define kernel command line information for the process/thread library.
  93. //
  94. #define PS_KERNEL_ARGUMENT_COMPONENT "ps"
  95. #define PS_KERNEL_ARGUMENT_ENVIRONMENT "env"
  96. //
  97. // Define the standard superuser ID.
  98. //
  99. #define USER_ID_ROOT 0
  100. //
  101. // Define the arbitrary maximum number of supplementary groups a user can
  102. // belong to. Also define a minimum size (just for the allocations) to avoid
  103. // making blocks with silly sizes.
  104. //
  105. #define SUPPLEMENTARY_GROUP_MAX 128
  106. #define SUPPLEMENTARY_GROUP_MIN 8
  107. //
  108. // Define privileged permission bit indices.
  109. //
  110. //
  111. // This permission overrides the restrictions associated with changing file
  112. // ownership and group ownership.
  113. //
  114. #define PERMISSION_CHOWN 0
  115. //
  116. // This permission overrides all discretionary access control.
  117. //
  118. #define PERMISSION_FILE_ACCESS 1
  119. //
  120. // This permission overrides access control restrictions regarding reading
  121. // and searching directories, and reading files.
  122. //
  123. #define PERMISSION_READ_SEARCH 2
  124. //
  125. // This permission overrides restrictions on file operations that assert that
  126. // the file owner must be equal to the user ID, except where the set ID
  127. // permission is applicable.
  128. //
  129. #define PERMISSION_FILE_OWNER 3
  130. //
  131. // This permission overrides restrictions that would otherwise prevent the
  132. // caller from setting the set-user-ID and set-group-ID bits on a file. The
  133. // restrictions are normally that the effective user ID shall match the file
  134. // owner, and that the effective group ID (or a supplementary group ID) shall
  135. // match the file owner ID when setting the set-group-ID bit.
  136. //
  137. #define PERMISSION_FILE_SET_ID 4
  138. //
  139. // This permission overrides the restriction that the real or effective user ID
  140. // of a process sending a signal must match the real or effective user ID of
  141. // the process receiving the signal.
  142. //
  143. #define PERMISSION_KILL 5
  144. //
  145. // This permission allows the thread to change its group IDs and supplementary
  146. // group IDs.
  147. //
  148. #define PERMISSION_SET_GROUP_ID 6
  149. //
  150. // This permission allows the thread to change its user IDs.
  151. //
  152. #define PERMISSION_SET_USER_ID 7
  153. //
  154. // This permission allows any permission within the thread's limit to be added
  155. // to the inheritable set, allows removal of bits from the limit, and allows
  156. // modification of the permission behavior bits.
  157. //
  158. #define PERMISSION_SET_PERMISSIONS 8
  159. //
  160. // This permission allows binding to TCP and UDP ports below 1024.
  161. //
  162. #define PERMISSION_NET_BIND 9
  163. //
  164. // This permission allows broadcasting and listening to multicasts.
  165. //
  166. #define PERMISSION_NET_BROADCAST 10
  167. //
  168. // This permission allows general network administration, including:
  169. // * Interface configuration.
  170. // * Setting debug options on sockets.
  171. // * Modifying routing tables.
  172. // * Setting arbitraty process and process group ownership on sockets.
  173. // * Binding to any address for transparent proxying.
  174. // * Setting promiscuous mode.
  175. // * Clearing statistics.
  176. // * Multicasting.
  177. //
  178. #define PERMISSION_NET_ADMINISTRATOR 11
  179. //
  180. // This permission allows the use of raw sockets.
  181. //
  182. #define PERMISSION_NET_RAW 12
  183. //
  184. // This permission allows locking of memory map segments.
  185. //
  186. #define PERMISSION_LOCK_MEMORY 13
  187. //
  188. // This permission allows loading and unloading of kernel drivers.
  189. //
  190. #define PERMISSION_DRIVER_LOAD 14
  191. //
  192. // This permission allows changing the root directory.
  193. //
  194. #define PERMISSION_CHROOT 15
  195. //
  196. // This permission allows escaping a changed root.
  197. //
  198. #define PERMISSION_ESCAPE_CHROOT 16
  199. //
  200. // This permission allows debugging of other processes.
  201. //
  202. #define PERMISSION_DEBUG 17
  203. //
  204. // This permission allows system-wide administration, including:
  205. // * Setting the host name
  206. // * Configuring paging
  207. // * Configuring storage devices
  208. // * Open any master terminal.
  209. // * Send any process ID in SCM_CREDENTIALS socket control messages.
  210. //
  211. #define PERMISSION_SYSTEM_ADMINISTRATOR 18
  212. //
  213. // This permission allows system shutdown and reboot.
  214. //
  215. #define PERMISSION_REBOOT 19
  216. //
  217. // This permission allows raising the thread's priority, manipulating other
  218. // process' priorities, and adjusting the scheduling algorithms.
  219. //
  220. #define PERMISSION_SCHEDULING 20
  221. //
  222. // This permission allows setting resource and quota limits. It also allows
  223. // changing of the system clock frequency.
  224. //
  225. #define PERMISSION_RESOURCES 21
  226. //
  227. // This permission allows manipulation of the system time and time zone.
  228. //
  229. #define PERMISSION_TIME 22
  230. //
  231. // This permission allows preventing system sleep.
  232. //
  233. #define PERMISSION_PREVENT_SLEEP 23
  234. //
  235. // This permission allows creating timers that will wake the system.
  236. //
  237. #define PERMISSION_WAKE 24
  238. //
  239. // This permission allows mounting and unmounting.
  240. //
  241. #define PERMISSION_MOUNT 25
  242. //
  243. // This permission allows arbitrary control over IPC objects.
  244. //
  245. #define PERMISSION_IPC 26
  246. //
  247. // Define the mask of valid permission. It must be kept up to date if new
  248. // permissions are added.
  249. //
  250. #define PERMISSION_MAX PERMISSION_IPC
  251. #define PERMISSION_MASK (PERMISSION_TO_MASK(PERMISSION_MAX + 1) - 1)
  252. //
  253. // Define some standard permission set values.
  254. //
  255. #define PERMISSION_SET_EMPTY 0ULL
  256. #define PERMISSION_SET_FULL PERMISSION_MASK
  257. //
  258. // Define permission behavior flags.
  259. //
  260. //
  261. // Set this flag to allow a thread that has one or more root (0) user IDs to
  262. // retain its permissions when it switches all of its user IDs to non-zero
  263. // values. Without this bit, the thread loses all its permissions on such a
  264. // change. This flag is always cleared on an exec call.
  265. //
  266. #define PERMISSION_BEHAVIOR_KEEP_PERMISSIONS 0x00000001
  267. #define PERMISSION_BEHAVIOR_KEEP_PERMISSIONS_LOCKED 0x00010000
  268. //
  269. // Set this flag to prevent the kernel from adjusting permission sets when the
  270. // thread's effective user ID is switched between zero and non-zero values.
  271. //
  272. #define PERMISSION_BEHAVIOR_NO_SETUID_FIXUP 0x00000002
  273. #define PERMISSION_BEHAVIOR_NO_SETUID_FIXUP_LOCKED 0x00020000
  274. //
  275. // Set this flag to prevent the kernel from granting capabilities when a
  276. // set-user-ID root program is executed, or when a process with an effective or
  277. // real user ID of root calls exec.
  278. //
  279. #define PERMISSION_BEHAVIOR_NO_ROOT 0x00000004
  280. #define PERMISSION_BEHAVIOR_NO_ROOT_LOCKED 0x00040000
  281. #define PERMISSION_BEHAVIOR_VALID_MASK \
  282. (PERMISSION_BEHAVIOR_KEEP_PERMISSIONS | \
  283. PERMISSION_BEHAVIOR_KEEP_PERMISSIONS_LOCKED | \
  284. PERMISSION_BEHAVIOR_NO_SETUID_FIXUP | \
  285. PERMISSION_BEHAVIOR_NO_SETUID_FIXUP_LOCKED | \
  286. PERMISSION_BEHAVIOR_NO_ROOT | \
  287. PERMISSION_BEHAVIOR_NO_ROOT_LOCKED)
  288. //
  289. // Define thread identity fields that can be set.
  290. //
  291. #define THREAD_IDENTITY_FIELD_REAL_USER_ID 0x00000001
  292. #define THREAD_IDENTITY_FIELD_EFFECTIVE_USER_ID 0x00000002
  293. #define THREAD_IDENTITY_FIELD_SAVED_USER_ID 0x00000004
  294. #define THREAD_IDENTITY_FIELD_REAL_GROUP_ID 0x00000008
  295. #define THREAD_IDENTITY_FIELD_EFFECTIVE_GROUP_ID 0x00000010
  296. #define THREAD_IDENTITY_FIELD_SAVED_GROUP_ID 0x00000020
  297. #define THREAD_IDENTITY_FIELDS_USER \
  298. (THREAD_IDENTITY_FIELD_REAL_USER_ID | \
  299. THREAD_IDENTITY_FIELD_EFFECTIVE_USER_ID | \
  300. THREAD_IDENTITY_FIELD_SAVED_USER_ID)
  301. #define THREAD_IDENTITY_FIELDS_GROUP \
  302. (THREAD_IDENTITY_FIELD_REAL_GROUP_ID | \
  303. THREAD_IDENTITY_FIELD_EFFECTIVE_GROUP_ID | \
  304. THREAD_IDENTITY_FIELD_SAVED_GROUP_ID)
  305. //
  306. // Define thread permission fields that can be set.
  307. //
  308. #define THREAD_PERMISSION_FIELD_BEHAVIOR 0x00000001
  309. #define THREAD_PERMISSION_FIELD_LIMIT 0x00000002
  310. #define THREAD_PERMISSION_FIELD_PERMITTED 0x00000004
  311. #define THREAD_PERMISSION_FIELD_INHERITABLE 0x00000008
  312. #define THREAD_PERMISSION_FIELD_EFFECTIVE 0x00000010
  313. //
  314. // Define thread flags.
  315. //
  316. #define THREAD_FLAG_USER_MODE 0x0001
  317. #define THREAD_FLAG_IN_SYSTEM_CALL 0x0002
  318. #define THREAD_FLAG_FREE_USER_STACK 0x0004
  319. #define THREAD_FLAG_EXITING 0x0008
  320. #define THREAD_FLAG_RESTORE_SIGNALS 0x0010
  321. //
  322. // Define thread FPU flags.
  323. //
  324. #define THREAD_FPU_FLAG_IN_USE 0x0001
  325. #define THREAD_FPU_FLAG_OWNER 0x0002
  326. //
  327. // Define the set of thread flags that can be specified on creation. This is
  328. // also the set of flags that will propagate when a thread is copied.
  329. //
  330. #define THREAD_FLAG_CREATION_MASK (THREAD_FLAG_USER_MODE)
  331. #define DEFAULT_USER_STACK_SIZE (8 * _1MB)
  332. #define DEFAULT_KERNEL_STACK_SIZE 0x3000
  333. #define DEFAULT_KERNEL_STACK_SIZE_ALIGNMENT 0x4000
  334. #define STACK_ALIGNMENT 16
  335. #define MAX_PROCESS_NAME 255
  336. #define PS_ALLOCATION_TAG 0x636F7250 // 'corP'
  337. #define PS_ACCOUNTANT_ALLOCATION_TAG 0x63417350 // 'cAsP'
  338. #define PS_FPU_CONTEXT_ALLOCATION_TAG 0x46637250 // 'FcrP'
  339. #define PS_IMAGE_ALLOCATION_TAG 0x6D497350 // 'mIsP'
  340. #define PS_GROUP_ALLOCATION_TAG 0x70477350 // 'pGsP'
  341. #define PS_UTS_ALLOCATION_TAG 0x74557350 // 'tUsP'
  342. #define PROCESS_INFORMATION_VERSION 1
  343. #define PROCESS_DEBUG_MODULE_CHANGE_VERSION 1
  344. //
  345. // Define the set of process flags.
  346. //
  347. #define PROCESS_FLAG_EXECUTED_IMAGE 0x000000001
  348. //
  349. // Define the user lock operation flags and masks.
  350. //
  351. //
  352. // This mask defines the bits reserved for the operation code.
  353. //
  354. #define USER_LOCK_OPERATION_MASK 0x0000007F
  355. //
  356. // Set this bit if the lock is private to the process, which results in
  357. // slightly faster accesses.
  358. //
  359. #define USER_LOCK_PRIVATE 0x00000080
  360. //
  361. // Define the current version of the process start data structure.
  362. //
  363. #define PROCESS_START_DATA_VERSION 2
  364. //
  365. // Define the number of random bytes of data supplied to new processes.
  366. //
  367. #define PROCESS_START_DATA_RANDOM_SIZE 16
  368. //
  369. // Define the infinite resource limit value.
  370. //
  371. #define RESOURCE_LIMIT_INFINITE MAX_UINTN
  372. //
  373. // Define the largest valid user mode address.
  374. //
  375. #define MAX_USER_ADDRESS ((PVOID)0x7FFFFFFF)
  376. //
  377. // Define the maximum length of a UTS name.
  378. //
  379. #define UTS_NAME_MAX 80
  380. //
  381. // Define flags to the fork call.
  382. //
  383. //
  384. // Set this flag to have the child process fork into an independent UTS
  385. // realm (which stores the host and domain name).
  386. //
  387. #define FORK_FLAG_REALM_UTS 0x00000001
  388. //
  389. // ------------------------------------------------------ Data Type Definitions
  390. //
  391. typedef enum _PROCESS_STATE {
  392. ProcessStateInvalid,
  393. ProcessStateReady,
  394. ProcessStateRunning,
  395. ProcessStateBlocked,
  396. ProcessStateSuspended,
  397. ProcessStateExited,
  398. MaxProcessStates
  399. } PROCESS_STATE, *PPROCESS_STATE;
  400. typedef enum _THREAD_STATE {
  401. ThreadStateInvalid,
  402. ThreadStateFirstTime,
  403. ThreadStateReady,
  404. ThreadStateRunning,
  405. ThreadStateBlocking,
  406. ThreadStateBlocked,
  407. ThreadStateWaking,
  408. ThreadStateSuspending,
  409. ThreadStateSuspended,
  410. ThreadStateExited,
  411. MaxThreadStates
  412. } THREAD_STATE, *PTHREAD_STATE;
  413. typedef enum _DEBUG_COMMAND_TYPE {
  414. DebugCommandInvalid,
  415. DebugCommandEnableDebugging,
  416. DebugCommandPrint,
  417. DebugCommandReportModuleChange,
  418. DebugCommandContinue,
  419. DebugCommandReadMemory,
  420. DebugCommandWriteMemory,
  421. DebugCommandSwitchThread,
  422. DebugCommandGetBreakInformation,
  423. DebugCommandSetBreakInformation,
  424. DebugCommandGetSignalInformation,
  425. DebugCommandSetSignalInformation,
  426. DebugCommandSingleStep,
  427. DebugCommandRangeStep,
  428. DebugCommandGetLoadedModules,
  429. DebugCommandGetThreadList,
  430. } DEBUG_COMMAND_TYPE, *PDEBUG_COMMAND_TYPE;
  431. typedef enum _THREAD_SIGNAL_PENDING_TYPE {
  432. ThreadNoSignalPending,
  433. ThreadChildSignalPending,
  434. ThreadSignalPending,
  435. } THREAD_SIGNAL_PENDING_TYPE, *PTHREAD_SIGNAL_PENDING_TYPE;
  436. typedef enum _PS_INFORMATION_TYPE {
  437. PsInformationInvalid,
  438. PsInformationProcess,
  439. PsInformationProcessIdList,
  440. PsInformationHostName,
  441. PsInformationDomainName,
  442. } PS_INFORMATION_TYPE, *PPS_INFORMATION_TYPE;
  443. typedef enum _PROCESS_ID_TYPE {
  444. ProcessIdInvalid,
  445. ProcessIdProcess,
  446. ProcessIdThread,
  447. ProcessIdParentProcess,
  448. ProcessIdProcessGroup,
  449. ProcessIdSession,
  450. } PROCESS_ID_TYPE, *PPROCESS_ID_TYPE;
  451. typedef enum _SCHEDULER_ENTRY_TYPE {
  452. SchedulerEntryInvalid,
  453. SchedulerEntryThread,
  454. SchedulerEntryGroup,
  455. } SCHEDULER_ENTRY_TYPE, *PSCHEDULER_ENTRY_TYPE;
  456. typedef enum _USER_LOCK_OPERATION {
  457. UserLockInvalid,
  458. UserLockWait,
  459. UserLockWake,
  460. } USER_LOCK_OPERATION, *PUSER_LOCK_OPERATION;
  461. //
  462. // Define the different types of resource limits. These line up with the
  463. // RLIMIT_* definitions.
  464. // TODO: Implement ResourceLimitCore.
  465. // TODO: Implement ResourceLimitCpuTime.
  466. // TODO: Implement ResourceLimitData.
  467. // TODO: Implement ResourceLimitFileSize.
  468. // TODO: Implement ResourceLimitFileCount.
  469. // TODO: Implement ResourceLimitAddressSpace.
  470. // TODO: Implement ResourceLimitProcessCount.
  471. // TODO: Implement ResourceLimitSignals.
  472. // TODO: Implement ResourceLimitNice.
  473. //
  474. typedef enum _RESOURCE_LIMIT_TYPE {
  475. ResourceLimitCore,
  476. ResourceLimitCpuTime,
  477. ResourceLimitData,
  478. ResourceLimitFileSize,
  479. ResourceLimitFileCount,
  480. ResourceLimitStack,
  481. ResourceLimitAddressSpace,
  482. ResourceLimitProcessCount,
  483. ResourceLimitSignals,
  484. ResourceLimitNice,
  485. ResourceLimitCount
  486. } RESOURCE_LIMIT_TYPE, *PRESOURCE_LIMIT_TYPE;
  487. typedef LONG PROCESS_ID, *PPROCESS_ID;
  488. typedef PROCESS_ID THREAD_ID, *PTHREAD_ID;
  489. typedef PROCESS_ID PROCESS_GROUP_ID, *PPROCESS_GROUP_ID;
  490. typedef PROCESS_ID SESSION_ID, *PSESSION_ID;
  491. typedef struct _SIGNAL_QUEUE_ENTRY SIGNAL_QUEUE_ENTRY, *PSIGNAL_QUEUE_ENTRY;
  492. typedef struct _KPROCESS KPROCESS, *PKPROCESS;
  493. typedef struct _KTHREAD KTHREAD, *PKTHREAD;
  494. typedef struct _SUPPLEMENTARY_GROUPS
  495. SUPPLEMENTARY_GROUPS, *PSUPPLEMENTARY_GROUPS;
  496. typedef struct _UTS_REALM UTS_REALM, *PUTS_REALM;
  497. //
  498. // Define the user and group ID types.
  499. //
  500. typedef ULONG USER_ID, *PUSER_ID;
  501. typedef ULONG GROUP_ID, *PGROUP_ID;
  502. typedef ULONGLONG PERMISSION_SET, *PPERMISSION_SET;
  503. /*++
  504. Structure Description:
  505. This structure stores information about a group of processes that
  506. interact with their controlling terminal as a unit.
  507. Members:
  508. ListEntry - Stores pointers to the next and previous process groups in the
  509. global list.
  510. ReferenceCount - Stores the number of outstanding references to this
  511. process group. This structure will be automatically destroyed when the
  512. reference count hits zero.
  513. Identifier - Stores the identifier for this process group, which is usually
  514. the identifier of the process that created the process group.
  515. ProcessListHead - Stores the head of the list of processes in the group.
  516. SessionId - Stores the session identifier the process group belongs to.
  517. OutsideParents - Stores the number of processes with living parents outside
  518. the process group. When the number of processes in a process group with
  519. parents outside the process group (but inside the session) drops to
  520. zero, the process is considered orphaned as there is no one to do job
  521. control on it.
  522. --*/
  523. typedef struct _PROCESS_GROUP {
  524. LIST_ENTRY ListEntry;
  525. volatile ULONG ReferenceCount;
  526. PROCESS_GROUP_ID Identifier;
  527. LIST_ENTRY ProcessListHead;
  528. SESSION_ID SessionId;
  529. ULONG OutsideParents;
  530. } PROCESS_GROUP, *PPROCESS_GROUP;
  531. /*++
  532. Structure Description:
  533. This structure defines the current user and group identity of a thread.
  534. Members:
  535. RealUserId - Stores the user identifier of the user that created the
  536. process.
  537. EffectiveUserId - Stores the user identifier actively used in file and
  538. permission checks.
  539. SavedUserId - Stores the real user ID if the process executed was not a
  540. set-UID program, or the user ID of the executable if the executable had
  541. the set-UID file permission set.
  542. RealGroupId - Stores the group identifier of the user that created the
  543. process.
  544. EffectiveGroupId - Stores the group ID actively used in file and permission
  545. checks.
  546. SavedGroupId - Stores the real group ID if the process executed was not a
  547. sed-GID program, or the group ID of the executable if the executable
  548. had the set-GID file permission set.
  549. --*/
  550. typedef struct _THREAD_IDENTITY {
  551. USER_ID RealUserId;
  552. USER_ID EffectiveUserId;
  553. USER_ID SavedUserId;
  554. GROUP_ID RealGroupId;
  555. GROUP_ID EffectiveGroupId;
  556. GROUP_ID SavedGroupId;
  557. } THREAD_IDENTITY, *PTHREAD_IDENTITY;
  558. /*++
  559. Structure Description:
  560. This structure is passed from the kernel to a newly starting application,
  561. and contains useful values. This structure is provided as a mechanism to
  562. improve performance, as it obviates the need to make various system calls
  563. during program load.
  564. Members:
  565. Version - Stores the structure version. This is set by the kernel to
  566. PROCESS_START_DATA_VERSION. Newer versions will be backwards compatible
  567. with older versions.
  568. PageSize - Stores the system page size.
  569. Identity - Stores the thread identity of the new process.
  570. Base - Stores the base address of the interpreter or executable.
  571. InterpreterBase - Stores the base address of the program interpreter, or
  572. 0 if no intepreter was requested.
  573. OsLibraryBase - Stores the base address of the Minoca OS library, loaded
  574. into every address space.
  575. ExecutableBase - Stores the base address of the executable.
  576. EntryPoint - Stores the initial entry point, either into the interpreter
  577. if there was one or into the executable if not.
  578. StackBase - Stores the base of the stack.
  579. IgnoredSignals - Stores a mask of which signals are ignored.
  580. --*/
  581. typedef struct _PROCESS_START_DATA {
  582. ULONG Version;
  583. UINTN PageSize;
  584. THREAD_IDENTITY Identity;
  585. UCHAR Random[PROCESS_START_DATA_RANDOM_SIZE];
  586. PVOID InterpreterBase;
  587. PVOID OsLibraryBase;
  588. PVOID ExecutableBase;
  589. PVOID EntryPoint;
  590. PVOID StackBase;
  591. SIGNAL_SET IgnoredSignals;
  592. } PROCESS_START_DATA, *PPROCESS_START_DATA;
  593. /*++
  594. Structure Description:
  595. This structure defines the initial environment for a process.
  596. Members:
  597. ImageName - Stores a pointer to a string containing the path to the image
  598. being executed.
  599. ImageNameLength - Stores the length of the image name buffer, in bytes,
  600. including the null terminator.
  601. Arguments - Stores a pointer to an array of pointers to null terminated
  602. strings representing the arguments to be passed to the main function
  603. (in the argv parameter). The first argument will be the same as the
  604. image name pointer.
  605. ArgumentCount - Stores the element count of the arguments array (which
  606. can be passed directly as the argc parameter to the main function).
  607. ArgumentsBuffer - Stores a pointer to the buffer containing the image name
  608. and arguments strings.
  609. ArgumentsBufferLength - Stores the size of the arguments buffer, in bytes.
  610. Environment - Stores a pointer to an array of null terminated strings
  611. representing the execution environment of the process. This array can
  612. be assigned directly to the environ C library variable.
  613. EnvironmentCount - Stores the number of environment variable definitions.
  614. This does not include the null terminating entry.
  615. EnvironmentBuffer - Stores a pointer to the buffer used to hold environment
  616. variable strings.
  617. EnvironmentBufferLength - Stores the length of the environment buffer, in
  618. bytes.
  619. StartData - Stores a pointer to additional data used to help the program
  620. load faster. This is ignored when user mode is passing a process
  621. environment to the kernel.
  622. --*/
  623. typedef struct _PROCESS_ENVIRONMENT {
  624. PSTR ImageName;
  625. ULONG ImageNameLength;
  626. PSTR *Arguments;
  627. ULONG ArgumentCount;
  628. PVOID ArgumentsBuffer;
  629. ULONG ArgumentsBufferLength;
  630. PSTR *Environment;
  631. ULONG EnvironmentCount;
  632. PVOID EnvironmentBuffer;
  633. ULONG EnvironmentBufferLength;
  634. PPROCESS_START_DATA StartData;
  635. } PROCESS_ENVIRONMENT, *PPROCESS_ENVIRONMENT;
  636. typedef
  637. VOID
  638. (*PTHREAD_ENTRY_ROUTINE) (
  639. PVOID Parameter
  640. );
  641. /*++
  642. Routine Description:
  643. This routine is the entry point prototype for a new thread.
  644. Arguments:
  645. Parameter - Supplies a pointer supplied by the creator of the thread.
  646. Return Value:
  647. None.
  648. --*/
  649. typedef
  650. VOID
  651. (*PSIGNAL_COMPLETION_ROUTINE) (
  652. PSIGNAL_QUEUE_ENTRY SignalQueueEntry
  653. );
  654. /*++
  655. Routine Description:
  656. This routine is called when a queued signal was successfully completed
  657. in usermode. It is responsible for doing what it will with the signal queue
  658. entry memory, as the system is done with it.
  659. Arguments:
  660. SignalQueueEntry - Supplies a pointer to the signal queue entry that was
  661. successfully sent to user mode.
  662. Return Value:
  663. None.
  664. --*/
  665. typedef
  666. BOOL
  667. (*PPROCESS_ITERATOR_ROUTINE) (
  668. PVOID Context,
  669. PKPROCESS Process
  670. );
  671. /*++
  672. Routine Description:
  673. This routine describes the prototype for the process list iterator. This
  674. routine is called with the process list lock held.
  675. Arguments:
  676. Context - Supplies a pointer's worth of context passed into the iterate
  677. routine.
  678. Process - Supplies the process to examine.
  679. Return Value:
  680. TRUE if the iteration should stop.
  681. FALSE if the iteration should continue.
  682. --*/
  683. /*++
  684. Structure Description:
  685. This structure defines the signal information structure.
  686. Members:
  687. ListEntry - Stores pointers to the next and previous signals in the process
  688. queue.
  689. Parameters - Stores the parameters of the signal to send.
  690. CompletionRoutine - Stores a pointer to a function that gets called by the
  691. system when the signal is successfully sent to user mode.
  692. --*/
  693. struct _SIGNAL_QUEUE_ENTRY {
  694. LIST_ENTRY ListEntry;
  695. SIGNAL_PARAMETERS Parameters;
  696. PSIGNAL_COMPLETION_ROUTINE CompletionRoutine;
  697. };
  698. /*++
  699. Structure Description:
  700. This structure defines information about a process' paths.
  701. Members:
  702. Root - Stores the root path point for this process.
  703. CurrentDirectory - Stores the current directory path point for this process.
  704. SharedMemoryDirectory - Stores the shared memory directory path point for
  705. this process.
  706. Lock - Stores a pointer to a queued lock synchronizing accesses with
  707. changes.
  708. --*/
  709. typedef struct _PROCESS_PATHS {
  710. struct {
  711. PVOID PathEntry;
  712. PVOID MountPoint;
  713. } Root;
  714. struct {
  715. PVOID PathEntry;
  716. PVOID MountPoint;
  717. } CurrentDirectory;
  718. struct {
  719. PVOID PathEntry;
  720. PVOID MountPoint;
  721. } SharedMemoryDirectory;
  722. PVOID Lock;
  723. } PROCESS_PATHS, *PPROCESS_PATHS;
  724. /*++
  725. Structure Description:
  726. This structure defines the debug request structure.
  727. Members:
  728. Command - Stores the debug command that the application would like to
  729. perform.
  730. PreviousCommand - Stores the previous debug command executed by the
  731. application.
  732. Address - Stores the address parameter of the command, used for commands
  733. like read and write.
  734. Thread - Stores the thread ID for the switch thread command.
  735. Data - Stores a pointer to a buffer containing either the data to write or
  736. the location to return the read data.
  737. Size - Stores the amount of data to be read or written. The data buffer
  738. must be at least that size.
  739. SignalToDeliver - Stores the signal number to deliver to the debugged
  740. process for step or continue operations. Supply zero to not deliver
  741. any signal.
  742. Status - Stores the result of the operation as returned by the kernel.
  743. --*/
  744. typedef struct _PROCESS_DEBUG_COMMAND {
  745. DEBUG_COMMAND_TYPE Command;
  746. DEBUG_COMMAND_TYPE PreviousCommand;
  747. union {
  748. PVOID Address;
  749. THREAD_ID Thread;
  750. } U;
  751. PVOID Data;
  752. ULONG Size;
  753. ULONG SignalToDeliver;
  754. KSTATUS Status;
  755. } PROCESS_DEBUG_COMMAND, *PPROCESS_DEBUG_COMMAND;
  756. /*++
  757. Structure Description:
  758. This structure defines a breakpoint range for a usermode process.
  759. Members:
  760. BreakRangeStart - Stores a pointer to the first byte of memory that
  761. qualifies as being in the break range.
  762. BreakRangeEnd - Stores a pointer to the first byte of memory that does not
  763. qualify as being in the break range.
  764. RangeHoleStart - Stores a pointer to the first byte within the range that
  765. does not generate a break (a "hole" in the break range).
  766. RangeHoleEnd - Stores a pointer to the first byte within the range that does
  767. not fall in the range hole (the first byte that again qualifies as
  768. within the break range).
  769. --*/
  770. typedef struct _PROCESS_DEBUG_BREAK_RANGE {
  771. PVOID BreakRangeStart;
  772. PVOID BreakRangeEnd;
  773. PVOID RangeHoleStart;
  774. PVOID RangeHoleEnd;
  775. } PROCESS_DEBUG_BREAK_RANGE, *PPROCESS_DEBUG_BREAK_RANGE;
  776. /*++
  777. Structure Description:
  778. This structure defines a module change notification for the kernel from
  779. user mode.
  780. Members:
  781. Version - Supplies the version of the module change notification structure.
  782. Set this to PROCESS_DEBUG_MODULE_CHANGE_VERSION.
  783. Load - Supplies a boolean indicating whether this is a module load (TRUE)
  784. or a module unload (FALSE).
  785. Image - Supplies a pointer to the module being loaded or unloaded.
  786. BinaryNameSize - Supplies the length of the binary name string, in bytes,
  787. including the null terminator.
  788. --*/
  789. typedef struct _PROCESS_DEBUG_MODULE_CHANGE {
  790. ULONG Version;
  791. BOOL Load;
  792. PLOADED_IMAGE Image;
  793. UINTN BinaryNameSize;
  794. } PROCESS_DEBUG_MODULE_CHANGE, *PPROCESS_DEBUG_MODULE_CHANGE;
  795. /*++
  796. Structure Description:
  797. This structure defines fields used when a process is being debugged by
  798. another process.
  799. Members:
  800. Process - Stores a pointer back to the process that owns this debug data.
  801. TracingProcess - Stores an optional pointer to the process that is
  802. tracing (debugging) this process. The tracing process will be notified
  803. and this process stopped on every signal and system call. The tracee
  804. does not have a reference on its tracing process. To freely use the
  805. tracer outside of the tracee process' queued lock, the tracee must
  806. acquire its lock, check to make sure the tracing process is not NULL,
  807. take a reference, and then release the lock. This synchronizes with the
  808. tracer's destruction, as it will acquire the tracee's process lock and
  809. NULL this pointer.
  810. TraceeListHead - Stores the list of processes this process traces.
  811. TracerListEntry - Stores pointers to the next and previous entries in the
  812. list of processes that also wait on the same tracer process as this one.
  813. TracerStopRequested - Stores a boolean indicating if the process wants to
  814. stop for a tracer event.
  815. TracerSignalInformation - Stores a pointer to the signal information of the
  816. signal that stopped this process. The tracer process may change this
  817. information.
  818. TracerLock - Stores a lock that serializes access to the tracer stop
  819. requested and tracer signal information members.
  820. AllStoppedEvent - Stores a pointer to the event that is signaled when all
  821. threads have responded to a stop request.
  822. DebugCommand - Stores a the current debug command.
  823. DebugCommandCompleteEvent - Stores a pointer to the event signaled by this
  824. process when the command is complete.
  825. DebugLeaderThread - Stores a pointer to the thread currently acting as the
  826. debug leader.
  827. DebugSingleStepAddress - Stores the address of the single step destination,
  828. or NULL if there is no single step address currently. This is only
  829. used on some architectures (like ARM).
  830. DebugSingleStepOriginalContents - Stores the original contents of the
  831. instruction stream at the given address. This is only used on some
  832. architectures (like ARM).
  833. BreakRange - Stores the range information for a range step, a single step
  834. that is looking to step over one or more instructions.
  835. --*/
  836. typedef struct _PROCESS_DEBUG_DATA {
  837. PKPROCESS Process;
  838. PKPROCESS TracingProcess;
  839. LIST_ENTRY TraceeListHead;
  840. LIST_ENTRY TracerListEntry;
  841. BOOL TracerStopRequested;
  842. SIGNAL_PARAMETERS TracerSignalInformation;
  843. KSPIN_LOCK TracerLock;
  844. PVOID AllStoppedEvent;
  845. PROCESS_DEBUG_COMMAND DebugCommand;
  846. PVOID DebugCommandCompleteEvent;
  847. PVOID DebugLeaderThread;
  848. PVOID DebugSingleStepAddress;
  849. ULONG DebugSingleStepOriginalContents;
  850. PROCESS_DEBUG_BREAK_RANGE BreakRange;
  851. } PROCESS_DEBUG_DATA, *PPROCESS_DEBUG_DATA;
  852. /*++
  853. Structure Description:
  854. This structure maintains system resource usage information for a given
  855. process or thread.
  856. Members:
  857. UserCycles - Stores the number of accumulated cycles in user mode.
  858. KernelCycles - Stores the number of accumulated cycles in kernel mode.
  859. Preemptions - Stores the number of times this thread or process has been
  860. forcibly descheduled.
  861. Yields - Stores the number of times this thread has voluntarily
  862. relinquished control to the scheduler.
  863. PageFaults - Stores the number of page faults that have occurred, including
  864. both page faults that required no I/O, and page faults that required
  865. I/O.
  866. HardPageFaults - Stores the number of hard page faults, which are page
  867. faults that ultimately generated I/O.
  868. BytesRead - Stores the number of bytes read from a device. Reads from
  869. volumes (that don't generate subsequent device reads) do not count here.
  870. BytesWritten - Stores the number of bytes written to a device. Writes to
  871. volumes do not count here.
  872. DeviceReads - Stores the count of device read operations that constituted
  873. the bytes written value.
  874. DeviceWrites - Stores the number of device write operations that
  875. constituted the bytes written value.
  876. MaxResidentSet - Store the maximum number of pages that have ever been
  877. mapped in the process address space. This is zero for threads, as
  878. threads share a single process address space.
  879. --*/
  880. typedef struct _RESOURCE_USAGE {
  881. ULONGLONG UserCycles;
  882. ULONGLONG KernelCycles;
  883. ULONGLONG Preemptions;
  884. ULONGLONG Yields;
  885. ULONGLONG PageFaults;
  886. ULONGLONG HardPageFaults;
  887. ULONGLONG BytesRead;
  888. ULONGLONG BytesWritten;
  889. ULONGLONG DeviceReads;
  890. ULONGLONG DeviceWrites;
  891. UINTN MaxResidentSet;
  892. } RESOURCE_USAGE, *PRESOURCE_USAGE;
  893. /*++
  894. Structure Description:
  895. This structure stores the soft and hard values for a resource limit.
  896. Members:
  897. Current - Stores the currently enforced limit, also known as the soft
  898. limit. Set to RESOURCE_LIMIT_INFINITY if no limit is in effect.
  899. Max - Stores the maximum value the currently enforced limit can be set to.
  900. Set to RESOURCE_LIMIT_INFINITY if no maximum limit is enforced.
  901. --*/
  902. typedef struct _RESOURCE_LIMIT {
  903. UINTN Current;
  904. UINTN Max;
  905. } RESOURCE_LIMIT, *PRESOURCE_LIMIT;
  906. /*++
  907. Structure Description:
  908. This structure defines the set of IDs for a process.
  909. Members:
  910. ProcessId - Stores the process' system-unique identifier.
  911. ParentProcessId - Stores the process identifier of the parent process.
  912. ProcessGroupId - Stores the process group identifier of this process.
  913. SessionId - Stores the process group session identifier of this process.
  914. --*/
  915. typedef struct _PROCESS_IDENTIFIERS {
  916. PROCESS_ID ProcessId;
  917. PROCESS_ID ParentProcessId;
  918. PROCESS_GROUP_ID ProcessGroupId;
  919. SESSION_ID SessionId;
  920. } PROCESS_IDENTIFIERS, *PPROCESS_IDENTIFIERS;
  921. /*++
  922. Structure Description:
  923. This structure defines the set of realms a process can belong to.
  924. Members:
  925. Uts - Stores a pointer to the UTS realm.
  926. --*/
  927. typedef struct _PROCESS_REALMS {
  928. PUTS_REALM Uts;
  929. } PROCESS_REALMS, *PPROCESS_REALMS;
  930. /*++
  931. Structure Description:
  932. This structure defines system or user process.
  933. Members:
  934. Header - Stores the object header.
  935. BinaryName - Stores a pointer to the name of the binary that created this
  936. process.
  937. BinaryNameSize - Stores the size of the binary name buffer in bytes,
  938. including the null terminator.
  939. Flags - Stores a bitmask of flags protected by the process queued lock.
  940. See PROCESS_FLAG_* for definitions.
  941. QueuedLock - Stores a pointer to a queued lock protecting simultaneous
  942. access to this structure. A (potentially partial) list of things
  943. protected by this lock:
  944. * Thread's supplementary groups
  945. * Process group membership
  946. * Child process list
  947. * Environment and binary name
  948. * Process parent pointer and ID
  949. * Signal masks and function pointers
  950. * Exit status
  951. * Debug data creation
  952. * Debug data tracer list and tracing process pointer
  953. * Loaded Image list
  954. * Thread list
  955. * Resource usage
  956. * Timer list
  957. ListEntry - Stores pointers to the next and previous processes in the
  958. system.
  959. ProcessGroupListEntry - Stores pointers to the next and previous processes
  960. in the process group.
  961. ThreadListHead - Stores the head of a list of KTHREAD structures whose
  962. list entries are the member ProcessEntry.
  963. SiblingListEntry - Stores pointers to the next and previous processes that
  964. share the parent process.
  965. ChildListHead - Stores the list of child processes that inherit from this
  966. process.
  967. Parent - Stores a pointer to the parent process if it is still alive. A
  968. child does not have a reference on the parent. To freely use the
  969. parent outside of its queued lock, a child must acquire the lock, check
  970. to see if the parent is not NULL, take a reference, and then release
  971. the lock. This synchronizes with the parent's destruction, as the
  972. parent will acquire the child's lock and NULL the parent point.
  973. ThreadCount - Stores the number of threads that belong to this process.
  974. Identifiers - Stores the ID information for this process, including the
  975. process ID, process group ID, and session ID.
  976. ProcessGroup - Stores a pointer directly to the process group this process
  977. belongs to.
  978. HandleTable - Stores a pointer to the handle table for this process.
  979. Paths - Stores the path root information for this process.
  980. Environment - Stores a pointer to the kernel mode copy of the process
  981. environment.
  982. ImageCount - Stores the number of loaded image elements in the image list.
  983. ImageListHead - Stores the head of list of images loaded for this process.
  984. ImageListSignature - Stores the sum of all the timestamps and loaded
  985. lowest addresses of the loaded images. The debugger uses this as a
  986. heuristic to determine if its list of loaded modules is in sync.
  987. ImageListQueuedLock - Stores a pointer to a queued lock protecting the
  988. image list.
  989. PendingSignals - Stores a bitfield of signals pending for the process as
  990. a whole.
  991. IgnoredSignals - Stores a bitfield of signals that the user has marked
  992. as ignored.
  993. HandledSignals - Stores a bitfield of signals that have a handler
  994. installed. If no handler is installed, the default action is performed.
  995. SignalHandlerRoutine - Stores a pointer to the user mode signal handling
  996. routine.
  997. SignalListHead - Stores the head of the list of signals that are currently
  998. queued for the process. The type of elements on this list will be
  999. SIGNAL_QUEUE_ENTRY structures. This list is protected by the process
  1000. lock.
  1001. UnreapedChildList - Stores the head of the list of child signal entries.
  1002. that have not yet been waited for.
  1003. ChildSignal - Stores the required memory needed for this process to send a
  1004. child signal to the parent and/or tracer process on exits, stops, and
  1005. continues.
  1006. ChildSignalDestination - Stores the destination process where the child
  1007. signal is currently queued.
  1008. ChildSignalLock - Stores the spin lock serializing access to the child
  1009. signal structure.
  1010. ExitStatus - Stores the exit status of the process. This is either the
  1011. code the process exited with or the signal that terminated the process.
  1012. ExitReason - Stores the exit reason. See CHILD_SIGNAL_REASON_* definitions.
  1013. DebugData - Stores a pointer to the debug data if this process is being
  1014. debugged.
  1015. StopEvent - Stores a pointer to the event that stopped threads wait on to
  1016. continue.
  1017. StoppedThreadCount - Stores the number of threads currently waiting on the
  1018. stopped event.
  1019. TimerList - Stores the list of the currently active timers.
  1020. StartTime - Stores the process start time as a system time.
  1021. ResourceUsage - Stores the resource usage for this process. This is
  1022. protected by the queued lock.
  1023. ChildResourceUsage - Stores the resource usage for terminated and waited
  1024. for children of this process. This is protected by the queued lock.
  1025. Umask - Stores the user file creation permission bit mask for the process.
  1026. ControllingTerminal - Stores an opaque pointer to the process' controlling
  1027. terminal. This is a file object, but it's a file object that this
  1028. process doesn't necessarily have a reference to. This pointer should
  1029. not be touched without the terminal list lock held.
  1030. Realm - Stores the set of realms the process belongs to.
  1031. --*/
  1032. struct _KPROCESS {
  1033. OBJECT_HEADER Header;
  1034. PCSTR BinaryName;
  1035. ULONG BinaryNameSize;
  1036. ULONG Flags;
  1037. PVOID QueuedLock;
  1038. LIST_ENTRY ListEntry;
  1039. LIST_ENTRY ProcessGroupListEntry;
  1040. LIST_ENTRY ThreadListHead;
  1041. LIST_ENTRY SiblingListEntry;
  1042. LIST_ENTRY ChildListHead;
  1043. PKPROCESS Parent;
  1044. ULONG ThreadCount;
  1045. PROCESS_IDENTIFIERS Identifiers;
  1046. PPROCESS_GROUP ProcessGroup;
  1047. PADDRESS_SPACE AddressSpace;
  1048. PHANDLE_TABLE HandleTable;
  1049. PROCESS_PATHS Paths;
  1050. PPROCESS_ENVIRONMENT Environment;
  1051. ULONG ImageCount;
  1052. LIST_ENTRY ImageListHead;
  1053. ULONGLONG ImageListSignature;
  1054. PVOID ImageListQueuedLock;
  1055. SIGNAL_SET PendingSignals;
  1056. SIGNAL_SET IgnoredSignals;
  1057. SIGNAL_SET HandledSignals;
  1058. PVOID SignalHandlerRoutine;
  1059. LIST_ENTRY SignalListHead;
  1060. LIST_ENTRY UnreapedChildList;
  1061. SIGNAL_QUEUE_ENTRY ChildSignal;
  1062. PKPROCESS ChildSignalDestination;
  1063. KSPIN_LOCK ChildSignalLock;
  1064. UINTN ExitStatus;
  1065. USHORT ExitReason;
  1066. PPROCESS_DEBUG_DATA DebugData;
  1067. PVOID StopEvent;
  1068. volatile ULONG StoppedThreadCount;
  1069. LIST_ENTRY TimerList;
  1070. ULONGLONG StartTime;
  1071. RESOURCE_USAGE ResourceUsage;
  1072. RESOURCE_USAGE ChildResourceUsage;
  1073. ULONG Umask;
  1074. PVOID ControllingTerminal;
  1075. PROCESS_REALMS Realm;
  1076. };
  1077. /*++
  1078. Structure Description:
  1079. This structure defines the current set of privileged permissions afforded
  1080. to a thread.
  1081. Members:
  1082. Behavior - Stores the bitfield of flags governing the behavior of the
  1083. permission sets when the user ID is manipulated. See the
  1084. PERMISSION_BEHAVIOR_* definitions.
  1085. Limit - Stores the maximum set of permissions this thread and its
  1086. descendents can have, regardless of superuser or file attributes.
  1087. Removing bits from this set is a way of deflating the power of the
  1088. superuser.
  1089. Permitted - Stores the set of permissions that the thread is allowed to
  1090. assume. It is also the maximum set that may be added to the thread's
  1091. inheritable set for a thread that does not have permission to set
  1092. additional permissions.
  1093. Inheritable - Stores the set of permissions preserved across an exec call.
  1094. Effective - Stores the set of the thread's current permissions, used in
  1095. all permission checks.
  1096. --*/
  1097. typedef struct _THREAD_PERMISSIONS {
  1098. ULONG Behavior;
  1099. PERMISSION_SET Limit;
  1100. PERMISSION_SET Permitted;
  1101. PERMISSION_SET Inheritable;
  1102. PERMISSION_SET Effective;
  1103. } THREAD_PERMISSIONS, *PTHREAD_PERMISSIONS;
  1104. /*++
  1105. Structure Description:
  1106. This structure defines a chunk of supplementary group IDs for a thread.
  1107. Members:
  1108. Capacity - Stores the number of elements in this array allocation.
  1109. Count - Stores the number of valid elements in this array allocation.
  1110. Groups - Stores a pointer to the array of supplementary groups this thread
  1111. belongs to.
  1112. Next - Stores a pointer to the next chunk of supplementary group IDs.
  1113. --*/
  1114. struct _SUPPLEMENTARY_GROUPS {
  1115. ULONG Capacity;
  1116. ULONG Count;
  1117. PGROUP_ID Groups;
  1118. PSUPPLEMENTARY_GROUPS Next;
  1119. };
  1120. /*++
  1121. Structure Description:
  1122. This structure defines an entry within the scheduler. This may either be a
  1123. thread or group.
  1124. Members:
  1125. Type - Stores the entry type.
  1126. Parent - Stores the parent group this entry belongs to.
  1127. ListEntry - Stores pointers to the next and previous threads in the
  1128. ready list.
  1129. --*/
  1130. typedef struct _SCHEDULER_ENTRY SCHEDULER_ENTRY, *PSCHEDULER_ENTRY;
  1131. struct _SCHEDULER_ENTRY {
  1132. SCHEDULER_ENTRY_TYPE Type;
  1133. PSCHEDULER_ENTRY Parent;
  1134. LIST_ENTRY ListEntry;
  1135. };
  1136. /*++
  1137. Structure Description:
  1138. This structure defines information about a timer that tracks CPU time.
  1139. Members:
  1140. DueTime - Stores the due time in processor counter ticks.
  1141. Period - Stores the interval in processor counter ticks.
  1142. --*/
  1143. typedef struct _RUNTIME_TIMER {
  1144. ULONGLONG DueTime;
  1145. ULONGLONG Period;
  1146. } RUNTIME_TIMER, *PRUNTIME_TIMER;
  1147. /*++
  1148. Structure Description:
  1149. This structure defines system or user thread of execution.
  1150. Members:
  1151. Header - Stores object manager information about this thread.
  1152. OwningProcess - Stores a pointer to the process that owns this thread.
  1153. KernelStackPointer - Stores a pointer to the current stack location in the
  1154. kernel stack.
  1155. ThreadPointer - Stores the architecture-specific encoding of the thread
  1156. pointer. On x86 this is a GDT_ENTRY, on ARM this is just the pointer
  1157. itself.
  1158. State - Stores the executable state of the thread.
  1159. SignalPending - Stores a value indicating if a signal is pending on this
  1160. thread or perhaps on the process. The synchronization of this variable
  1161. is this: the variable is only ever set to non-zero values with the
  1162. process lock held, but can be reset to zero without the lock held.
  1163. Flags - Stores the bitfield of flags the thread was created with. See
  1164. THREAD_FLAG_* definitions.
  1165. FpuFlags - Stores the bitfield of floating point unit flags governing the
  1166. thread. This is separate from the flags member because it is altered
  1167. during context switch, which can land on top of other kernel level flag
  1168. manipulation.
  1169. SchedulerEntry - Stores the scheduler information for this thread.
  1170. BuiltinTimer - Stores a pointer to the thread's default timeout timer.
  1171. BuiltinWaitBlock - Stores a pointer to the built-in wait block that comes
  1172. with every thread.
  1173. WaitBlock - Stores a pointer to the wait block this thread is currently
  1174. blocking on.
  1175. PendingSignals - Stores a bitfield of signals pending for the current
  1176. thread.
  1177. BlockedSignals - Stores a bitfield of signals that are blocked by the
  1178. thread.
  1179. RestoreSignals - Stores a bitfield of signals that are to be restored to
  1180. the blocked signals set after a signal is dispatched.
  1181. SignalListHead - Stores the head of the list of signals that are currently
  1182. queued for the process. The type of elements on this list will be
  1183. SIGNAL_QUEUE_ENTRY structures. This list is protected by the process
  1184. lock.
  1185. ResourceUsage - Stores the resource usage of the thread.
  1186. FpuContext - Stores a pointer to the saved extended state if user mode
  1187. is currently using the floating point unit.
  1188. Identity - Stores the thread's user and group identity.
  1189. SupplementaryGroups - Stores a pointer to the first block of the thread's
  1190. supplementary groups.
  1191. Permissions - Stores the thread's permission masks.
  1192. ThreadRoutine - Stores the location to jump to on first execution of this
  1193. thread.
  1194. ThreadParameter - Stores the parameter given to the thread routine.
  1195. KernelStack - Stores the base (limit) of the kernel stack for this thread.
  1196. KernelStackSize - Stores the size, in bytes, of the kernel stack.
  1197. UserStack - Stores the base (limit) of the user-mode stack for this thread.
  1198. UserStackSize - Stores the size of the user-mode stack for this thread.
  1199. ThreadId - Stores the thread's system-unique ID.
  1200. ThreadIdPointer - Stores an optional pointer in user mode. If a thread is
  1201. terminated, zero will be written to this value by the kernel and a
  1202. UserLockWake operation will be performed to wake one thread waiting on
  1203. that address. This is used so that threads can reliably wait for
  1204. other threads termination.
  1205. ProcessEntry - Stores pointers to the previous and next threads in the
  1206. process that owns this thread.
  1207. TrapFrame - Stores a pointer to the user mode trap frame saved for this
  1208. thread by the system call handler.
  1209. RealTimer - Stores an optional pointer to the real-time interval timer.
  1210. UserTimer - Stores the per-thread timer that tracks user mode execution
  1211. time.
  1212. ProfileTimer - Stores the per-thread timer that tracks user plus kernel
  1213. execution time.
  1214. Limits - Stores the resource limits associated with the thread.
  1215. --*/
  1216. struct _KTHREAD {
  1217. OBJECT_HEADER Header;
  1218. PKPROCESS OwningProcess;
  1219. PVOID KernelStackPointer;
  1220. ULONGLONG ThreadPointer;
  1221. volatile THREAD_STATE State;
  1222. THREAD_SIGNAL_PENDING_TYPE SignalPending;
  1223. USHORT Flags;
  1224. USHORT FpuFlags;
  1225. SCHEDULER_ENTRY SchedulerEntry;
  1226. PVOID BuiltinTimer;
  1227. PWAIT_BLOCK BuiltinWaitBlock;
  1228. PWAIT_BLOCK WaitBlock;
  1229. SIGNAL_SET PendingSignals;
  1230. SIGNAL_SET BlockedSignals;
  1231. SIGNAL_SET RestoreSignals;
  1232. LIST_ENTRY SignalListHead;
  1233. RESOURCE_USAGE ResourceUsage;
  1234. PFPU_CONTEXT FpuContext;
  1235. THREAD_IDENTITY Identity;
  1236. PSUPPLEMENTARY_GROUPS SupplementaryGroups;
  1237. THREAD_PERMISSIONS Permissions;
  1238. PTHREAD_ENTRY_ROUTINE ThreadRoutine;
  1239. PVOID ThreadParameter;
  1240. PVOID KernelStack;
  1241. ULONG KernelStackSize;
  1242. PVOID UserStack;
  1243. ULONG UserStackSize;
  1244. THREAD_ID ThreadId;
  1245. PTHREAD_ID ThreadIdPointer;
  1246. PTRAP_FRAME TrapFrame;
  1247. LIST_ENTRY ProcessEntry;
  1248. PVOID RealTimer;
  1249. RUNTIME_TIMER UserTimer;
  1250. RUNTIME_TIMER ProfileTimer;
  1251. RESOURCE_LIMIT Limits[ResourceLimitCount];
  1252. };
  1253. /*++
  1254. Structure Description:
  1255. This structure defines information about an active process.
  1256. Members:
  1257. Version - Stores the version of the structure. When querying process
  1258. information, this should be set to PROCESS_INFORMATION_VERSION.
  1259. StructureSize - Stores the size of the structure, in bytes, including the
  1260. name and arguments buffers.
  1261. ProcessId - Stores the process identifier.
  1262. ParentProcessId - Stores the parent process's identifier.
  1263. ProcessGroupId - Stores the process's group identifier.
  1264. SessionId - Stores the process's session identifier.
  1265. RealUserId - Stores the real user ID of the process owner.
  1266. EffectiveUserId - Stores the effective user ID of the process owner.
  1267. RealGroupId - Stores the real group ID of the process owner.
  1268. EffectiveGroupId - Stores the effective group ID of the process owner.
  1269. Priority - Stores the priority of the process.
  1270. NiceValue - Stores the nice value of the process.
  1271. Flags - Stores the process flags.
  1272. State - Stores the process state.
  1273. ImageSize - Stores the size, in bytes, of the process's main image.
  1274. StartTime - Stores the process start time as a system time.
  1275. ResourceUsage - Stores the resource usage of the process.
  1276. ChildResourceUsage - Stores the resource usage of terminated and waited-for
  1277. children of the process.
  1278. Frequency - Stores the frequency of the CPU to be used in conjunction with
  1279. the resource usage data for calculated time.
  1280. NameOffset - Stores the offset, in bytes, to the start of the process name.
  1281. The offset is from the beginning of this structure.
  1282. NameLength - Stores the length of the process name, in characters,
  1283. including the null terminator.
  1284. ArgumentsBufferOffset - Stores the offset, in bytes, to the start of the
  1285. image name and argument strings. The offset is from the beginning of
  1286. this structure.
  1287. ArgumentsBufferSize - Stores the size of the arguments buffer in bytes.
  1288. --*/
  1289. typedef struct _PROCESS_INFORMATION {
  1290. ULONG Version;
  1291. ULONG StructureSize;
  1292. PROCESS_ID ProcessId;
  1293. PROCESS_ID ParentProcessId;
  1294. PROCESS_GROUP_ID ProcessGroupId;
  1295. SESSION_ID SessionId;
  1296. USER_ID RealUserId;
  1297. USER_ID EffectiveUserId;
  1298. GROUP_ID RealGroupId;
  1299. GROUP_ID EffectiveGroupId;
  1300. ULONG Priority;
  1301. ULONG NiceValue;
  1302. ULONG Flags;
  1303. PROCESS_STATE State;
  1304. UINTN ImageSize;
  1305. ULONGLONG StartTime;
  1306. RESOURCE_USAGE ResourceUsage;
  1307. RESOURCE_USAGE ChildResourceUsage;
  1308. ULONGLONG Frequency;
  1309. UINTN NameOffset;
  1310. ULONG NameLength;
  1311. UINTN ArgumentsBufferOffset;
  1312. ULONG ArgumentsBufferSize;
  1313. } PROCESS_INFORMATION, *PPROCESS_INFORMATION;
  1314. /*++
  1315. Structure Description:
  1316. This structure defines information about an active thread.
  1317. Members:
  1318. StructureSize - Stores the size of the structure plus the null terminated
  1319. name.
  1320. ThreadId - Stores the thread identifier.
  1321. ResourceUsage - Stores the resource usage information for the thread.
  1322. Name - Stores the null terminated name of the thread.
  1323. --*/
  1324. typedef struct _THREAD_INFORMATION {
  1325. ULONG StructureSize;
  1326. THREAD_ID ThreadId;
  1327. RESOURCE_USAGE ResourceUsage;
  1328. CHAR Name[ANYSIZE_ARRAY];
  1329. } THREAD_INFORMATION, *PTHREAD_INFORMATION;
  1330. /*++
  1331. Structure Description:
  1332. This structure defines a request to set (or get) the current thread's
  1333. identity.
  1334. Members:
  1335. FieldsToSet - Stores a bitfield of which fields should be changed. See
  1336. THREAD_IDENTITY_FIELD_* definitions. Supply 0 to simply get the current
  1337. thread's identity.
  1338. Identity - Stores the thread identity to set on input. On output,
  1339. contains the new complete thread identity.
  1340. --*/
  1341. typedef struct _SET_THREAD_IDENTITY {
  1342. ULONG FieldsToSet;
  1343. THREAD_IDENTITY Identity;
  1344. } SET_THREAD_IDENTITY, *PSET_THREAD_IDENTITY;
  1345. /*++
  1346. Structure Description:
  1347. This structure defines a request to set (or get) the current thread's
  1348. permissions.
  1349. Members:
  1350. FieldsToSet - Stores a bitfield of which fields should be changed. See
  1351. THREAD_PERMISSION_FIELD_* definitions. Supply 0 to simply get the
  1352. current thread's permission masks.
  1353. Permissions - Stores the thread permissions to set on input. On output,
  1354. contains the new complete thread permission set.
  1355. --*/
  1356. typedef struct _SET_THREAD_PERMISSIONS {
  1357. ULONG FieldsToSet;
  1358. THREAD_PERMISSIONS Permissions;
  1359. } SET_THREAD_PERMISSIONS, *PSET_THREAD_PERMISSIONS;
  1360. /*++
  1361. Structure Description:
  1362. This structure defines the parameters passed to create a new thread.
  1363. Members:
  1364. Process - Stores an optional pointer to the process to create the thread
  1365. in. Supply NULL to create the thread in the current process.
  1366. Name - Stores a pointer to a kernel mode buffer containing the name of
  1367. the thread.
  1368. NameSize - Stores the size of the name buffer in bytes, including the
  1369. null terminator.
  1370. ThreadRoutine - Stores a pointer to the routine to call for the thread.
  1371. Parameter - Stores a pointer's worth of context to pass to the thread
  1372. routine.
  1373. UserStack - Stores an optional pointer to the user stack base to use.
  1374. StackSize - Stores an optional stack size, either the user stack size for a
  1375. user mode thread or a kernel stack size for a kernel mode thread.
  1376. Supply 0 to use a default value.
  1377. Flags - Stores thread flags. See THREAD_FLAG_* definitions.
  1378. ThreadPointer - Stores the value to set as the thread pointer.
  1379. ThreadIdPointer - Stores a pointer where the thread ID will be returned. If
  1380. this is a user mode address, this will also be set as the thread ID
  1381. pointer value for the thread.
  1382. Environment - Stores an optional kernel mode pointer to an environment to
  1383. copy over to the stack of the created thread. This is only used when
  1384. creating a process directly from kernel mode.
  1385. --*/
  1386. typedef struct _THREAD_CREATION_PARAMETERS {
  1387. PKPROCESS Process;
  1388. PCSTR Name;
  1389. UINTN NameSize;
  1390. PTHREAD_ENTRY_ROUTINE ThreadRoutine;
  1391. PVOID Parameter;
  1392. PVOID UserStack;
  1393. ULONG StackSize;
  1394. ULONG Flags;
  1395. PVOID ThreadPointer;
  1396. PTHREAD_ID ThreadIdPointer;
  1397. PPROCESS_ENVIRONMENT Environment;
  1398. } THREAD_CREATION_PARAMETERS, *PTHREAD_CREATION_PARAMETERS;
  1399. //
  1400. // -------------------------------------------------------------------- Globals
  1401. //
  1402. //
  1403. // -------------------------------------------------------- Function Prototypes
  1404. //
  1405. KERNEL_API
  1406. KSTATUS
  1407. PsCreateKernelThread (
  1408. PTHREAD_ENTRY_ROUTINE ThreadRoutine,
  1409. PVOID ThreadParameter,
  1410. PCSTR Name
  1411. );
  1412. /*++
  1413. Routine Description:
  1414. This routine creates and launches a new kernel thread with default
  1415. parameters.
  1416. Arguments:
  1417. ThreadRoutine - Supplies the entry point to the thread.
  1418. ThreadParameter - Supplies the parameter to pass to the entry point
  1419. routine.
  1420. Name - Supplies an optional name to identify the thread.
  1421. Return Value:
  1422. Returns a pointer to the new thread on success, or NULL on failure.
  1423. --*/
  1424. KERNEL_API
  1425. KSTATUS
  1426. PsCreateThread (
  1427. PTHREAD_CREATION_PARAMETERS Parameters
  1428. );
  1429. /*++
  1430. Routine Description:
  1431. This routine creates and initializes a new thread, and adds it to the
  1432. ready list for execution.
  1433. Arguments:
  1434. Parameters - Supplies a pointer to the thread creation parameters.
  1435. Return Value:
  1436. Status code.
  1437. --*/
  1438. KERNEL_API
  1439. KSTATUS
  1440. PsCheckPermission (
  1441. ULONG Permission
  1442. );
  1443. /*++
  1444. Routine Description:
  1445. This routine checks to see if the calling thread currently has the given
  1446. permission.
  1447. Arguments:
  1448. Permission - Supplies the permission number to check. See PERMISSION_*
  1449. definitions.
  1450. Return Value:
  1451. STATUS_SUCCESS if the current thread has the given permission.
  1452. STATUS_PERMISSION_DENIED if the thread does not have the given permission.
  1453. --*/
  1454. BOOL
  1455. PsIsUserInGroup (
  1456. GROUP_ID Group
  1457. );
  1458. /*++
  1459. Routine Description:
  1460. This routine determines if the given group ID matches the effective
  1461. group ID or any of the supplementary group IDs of the calling thread. The
  1462. current thread must not be a kernel thread.
  1463. Arguments:
  1464. Group - Supplies the group ID to check against.
  1465. Return Value:
  1466. TRUE if the calling thread is a member of the given group.
  1467. FALSE if the calling thread is not a member of the given group.
  1468. --*/
  1469. KSTATUS
  1470. PsGetThreadList (
  1471. PROCESS_ID ProcessId,
  1472. ULONG AllocationTag,
  1473. PVOID *Buffer,
  1474. PULONG BufferSize
  1475. );
  1476. /*++
  1477. Routine Description:
  1478. This routine returns information about the active processes in the system.
  1479. Arguments:
  1480. ProcessId - Supplies the identifier of the process to get thread
  1481. information for.
  1482. AllocationTag - Supplies the allocation tag to use for the allocation
  1483. this routine will make on behalf of the caller.
  1484. Buffer - Supplies a pointer where a non-paged pool buffer will be returned
  1485. containing the array of thread information. The caller is responsible
  1486. for freeing this memory from non-paged pool. The type returned here
  1487. will be an array (where each element may be a different size) of
  1488. THREAD_INFORMATION structures.
  1489. BufferSize - Supplies a pointer where the size of the buffer in bytes
  1490. will be returned on success.
  1491. Return Value:
  1492. STATUS_SUCCESS on success.
  1493. STATUS_INSUFFICIENT_RESOURCES if memory could not be allocated for the
  1494. information buffer.
  1495. STATUS_BUFFER_TOO_SMALL if the thread list is so volatile that it cannot
  1496. be sized. This is only returned in extremely rare cases, as this routine
  1497. makes multiple attempts.
  1498. --*/
  1499. KSTATUS
  1500. PsGetThreadInformation (
  1501. PROCESS_ID ProcessId,
  1502. THREAD_ID ThreadId,
  1503. PTHREAD_INFORMATION Buffer,
  1504. PULONG BufferSize
  1505. );
  1506. /*++
  1507. Routine Description:
  1508. This routine returns information about a given thread.
  1509. Arguments:
  1510. ProcessId - Supplies the process ID owning the thread.
  1511. ThreadId - Supplies the ID of the thread to get information about.
  1512. Buffer - Supplies an optional pointer to a buffer to write the data into.
  1513. This must be non-paged memory if the thread requested belongs to the
  1514. kernel process.
  1515. BufferSize - Supplies a pointer that on input contains the size of the
  1516. input buffer. On output, returns the size needed to contain the data.
  1517. Return Value:
  1518. STATUS_SUCCESS on success.
  1519. STATUS_NO_SUCH_PROCESS if no process with the given identifier exists.
  1520. STATUS_NO_SUCH_THREAD if the no thread with the given identifier exists.
  1521. STATUS_BUFFER_TOO_SMALL if a buffer was supplied but was not big enough to
  1522. contain all the information.
  1523. --*/
  1524. VOID
  1525. PsSetSignalMask (
  1526. PSIGNAL_SET NewMask,
  1527. PSIGNAL_SET OriginalMask
  1528. );
  1529. /*++
  1530. Routine Description:
  1531. This routine sets the blocked signal mask for the current thread.
  1532. Arguments:
  1533. NewMask - Supplies a pointer to the new mask to set.
  1534. OriginalMask - Supplies an optional pointer to the previous mask.
  1535. Return Value:
  1536. None.
  1537. --*/
  1538. INTN
  1539. PsSysCreateThread (
  1540. PVOID SystemCallParameter
  1541. );
  1542. /*++
  1543. Routine Description:
  1544. This routine creates a new thread for the current process.
  1545. Arguments:
  1546. SystemCallParameter - Supplies a pointer to the parameters supplied with
  1547. the system call. This structure will be a stack-local copy of the
  1548. actual parameters passed from user-mode.
  1549. Return Value:
  1550. STATUS_SUCCESS or positive integer on success.
  1551. Error status code on failure.
  1552. --*/
  1553. INTN
  1554. PsSysExitThread (
  1555. PVOID SystemCallParameter
  1556. );
  1557. /*++
  1558. Routine Description:
  1559. This routine terminates the current thread.
  1560. Arguments:
  1561. SystemCallParameter - Supplies a pointer to the parameters supplied with
  1562. the system call. This structure will be a stack-local copy of the
  1563. actual parameters passed from user-mode.
  1564. Return Value:
  1565. Does not return. Eventually exits by killing the thread.
  1566. --*/
  1567. INTN
  1568. PsSysSetThreadPointer (
  1569. PVOID SystemCallParameter
  1570. );
  1571. /*++
  1572. Routine Description:
  1573. This routine sets the thread pointer for the current thread.
  1574. Arguments:
  1575. SystemCallParameter - Supplies a pointer to the parameters supplied with
  1576. the system call. This is supplies the thread pointer directly, which is
  1577. passed from user mode via a register.
  1578. Return Value:
  1579. STATUS_SUCCESS or positive integer on success.
  1580. Error status code on failure.
  1581. --*/
  1582. INTN
  1583. PsSysSetThreadIdPointer (
  1584. PVOID SystemCallParameter
  1585. );
  1586. /*++
  1587. Routine Description:
  1588. This routine sets the thread ID pointer for the current thread.
  1589. Arguments:
  1590. SystemCallParameter - Supplies a pointer to the parameters supplied with
  1591. the system call. This is supplies the thread ID pointer directly, which
  1592. is passed from user mode via a register.
  1593. Return Value:
  1594. STATUS_SUCCESS or positive integer on success.
  1595. Error status code on failure.
  1596. --*/
  1597. INTN
  1598. PsSysSetSignalHandler (
  1599. PVOID SystemCallParameter
  1600. );
  1601. /*++
  1602. Routine Description:
  1603. This routine sets the user mode signal handler for the given thread.
  1604. Arguments:
  1605. SystemCallParameter - Supplies a pointer to the parameters supplied with
  1606. the system call. This structure will be a stack-local copy of the
  1607. actual parameters passed from user-mode.
  1608. Return Value:
  1609. STATUS_SUCCESS or positive integer on success.
  1610. Error status code on failure.
  1611. --*/
  1612. INTN
  1613. PsSysRestoreContext (
  1614. PVOID SystemCallParameter
  1615. );
  1616. /*++
  1617. Routine Description:
  1618. This routine restores the original user mode thread context for the thread
  1619. before the signal was invoked.
  1620. Arguments:
  1621. SystemCallParameter - Supplies a pointer to the parameters supplied with
  1622. the system call. The parameter is a user mode pointer to the signal
  1623. context to restore.
  1624. Return Value:
  1625. Returns the architecture-specific return register from the thread context.
  1626. The architecture-specific system call assembly routines do not restore the
  1627. return register out of the trap frame in order to allow a system call to
  1628. return a value via a register. The restore context system call, however,
  1629. must restore the old context, including the return register.
  1630. --*/
  1631. INTN
  1632. PsSysSendSignal (
  1633. PVOID SystemCallParameter
  1634. );
  1635. /*++
  1636. Routine Description:
  1637. This routine implements the system call that allows usermode processes and
  1638. threads to send signals to one another.
  1639. Arguments:
  1640. SystemCallParameter - Supplies a pointer to the parameters supplied with
  1641. the system call. This structure will be a stack-local copy of the
  1642. actual parameters passed from user-mode.
  1643. Return Value:
  1644. STATUS_SUCCESS or positive integer on success.
  1645. Error status code on failure.
  1646. --*/
  1647. INTN
  1648. PsSysSetSignalBehavior (
  1649. PVOID SystemCallParameter
  1650. );
  1651. /*++
  1652. Routine Description:
  1653. This routine implements the system call that allows a thread to set its
  1654. varios signal behavior masks.
  1655. Arguments:
  1656. SystemCallParameter - Supplies a pointer to the parameters supplied with
  1657. the system call. This structure will be a stack-local copy of the
  1658. actual parameters passed from user-mode.
  1659. Return Value:
  1660. STATUS_SUCCESS or positive integer on success.
  1661. Error status code on failure.
  1662. --*/
  1663. INTN
  1664. PsSysWaitForChildProcess (
  1665. PVOID SystemCallParameter
  1666. );
  1667. /*++
  1668. Routine Description:
  1669. This routine implements the system call that suspends the current thread
  1670. until a child process exits.
  1671. Arguments:
  1672. SystemCallParameter - Supplies a pointer to the parameters supplied with
  1673. the system call. This structure will be a stack-local copy of the
  1674. actual parameters passed from user-mode.
  1675. Return Value:
  1676. STATUS_SUCCESS or positive integer on success.
  1677. Error status code on failure.
  1678. --*/
  1679. INTN
  1680. PsSysSuspendExecution (
  1681. PVOID SystemCallParameter
  1682. );
  1683. /*++
  1684. Routine Description:
  1685. This routine implements the system call that suspends the current thread
  1686. until a signal comes in.
  1687. Arguments:
  1688. SystemCallParameter - Supplies a pointer to the parameters supplied with
  1689. the system call. This structure will be a stack-local copy of the
  1690. actual parameters passed from user-mode.
  1691. Return Value:
  1692. STATUS_SUCCESS or positive integer on success.
  1693. Error status code on failure.
  1694. --*/
  1695. INTN
  1696. PsSysQueryTimeCounter (
  1697. PVOID SystemCallParameter
  1698. );
  1699. /*++
  1700. Routine Description:
  1701. This routine implements the system call for getting the current time
  1702. counter value.
  1703. Arguments:
  1704. SystemCallParameter - Supplies a pointer to the parameters supplied with
  1705. the system call. This structure will be a stack-local copy of the
  1706. actual parameters passed from user-mode.
  1707. Return Value:
  1708. STATUS_SUCCESS or positive integer on success.
  1709. Error status code on failure.
  1710. --*/
  1711. INTN
  1712. PsSysTimerControl (
  1713. PVOID SystemCallParameter
  1714. );
  1715. /*++
  1716. Routine Description:
  1717. This routine performs timer control operations.
  1718. Arguments:
  1719. SystemCallParameter - Supplies a pointer to the parameters supplied with
  1720. the system call. This structure will be a stack-local copy of the
  1721. actual parameters passed from user-mode.
  1722. Return Value:
  1723. STATUS_SUCCESS or positive integer on success.
  1724. Error status code on failure.
  1725. --*/
  1726. INTN
  1727. PsSysSetITimer (
  1728. PVOID SystemCallParameter
  1729. );
  1730. /*++
  1731. Routine Description:
  1732. This routine performs gets or sets a thread interval timer.
  1733. Arguments:
  1734. SystemCallParameter - Supplies a pointer to the parameters supplied with
  1735. the system call. This structure will be a stack-local copy of the
  1736. actual parameters passed from user-mode.
  1737. Return Value:
  1738. STATUS_SUCCESS or positive integer on success.
  1739. Error status code on failure.
  1740. --*/
  1741. INTN
  1742. PsSysSetThreadIdentity (
  1743. PVOID SystemCallParameter
  1744. );
  1745. /*++
  1746. Routine Description:
  1747. This routine implements the get/set thread identity system call.
  1748. Arguments:
  1749. SystemCallParameter - Supplies a pointer to the parameters supplied with
  1750. the system call. This structure will be a stack-local copy of the
  1751. actual parameters passed from user-mode.
  1752. Return Value:
  1753. STATUS_SUCCESS or positive integer on success.
  1754. Error status code on failure.
  1755. --*/
  1756. INTN
  1757. PsSysSetThreadPermissions (
  1758. PVOID SystemCallParameter
  1759. );
  1760. /*++
  1761. Routine Description:
  1762. This routine implements the get/set thread permissions system call.
  1763. Arguments:
  1764. SystemCallParameter - Supplies a pointer to the parameters supplied with
  1765. the system call. This structure will be a stack-local copy of the
  1766. actual parameters passed from user-mode.
  1767. Return Value:
  1768. STATUS_SUCCESS or positive integer on success.
  1769. Error status code on failure.
  1770. --*/
  1771. INTN
  1772. PsSysSetSupplementaryGroups (
  1773. PVOID SystemCallParameter
  1774. );
  1775. /*++
  1776. Routine Description:
  1777. This routine implements the get/set supplementary groups system call.
  1778. Arguments:
  1779. SystemCallParameter - Supplies a pointer to the parameters supplied with
  1780. the system call. This structure will be a stack-local copy of the
  1781. actual parameters passed from user-mode.
  1782. Return Value:
  1783. STATUS_SUCCESS or positive integer on success.
  1784. Error status code on failure.
  1785. --*/
  1786. INTN
  1787. PsSysSetResourceLimit (
  1788. PVOID SystemCallParameter
  1789. );
  1790. /*++
  1791. Routine Description:
  1792. This routine implements the system call that gets or sets a resource limit
  1793. for the current thread.
  1794. Arguments:
  1795. SystemCallParameter - Supplies a pointer to the parameters supplied with
  1796. the system call. This structure will be a stack-local copy of the
  1797. actual parameters passed from user-mode.
  1798. Return Value:
  1799. STATUS_SUCCESS or positive integer on success.
  1800. Error status code on failure.
  1801. --*/
  1802. INTN
  1803. PsSysUserLock (
  1804. PVOID SystemCallParameter
  1805. );
  1806. /*++
  1807. Routine Description:
  1808. This routine implements the system call for user mode locking.
  1809. Arguments:
  1810. SystemCallParameter - Supplies a pointer to the parameters supplied with
  1811. the system call. This structure will be a stack-local copy of the
  1812. actual parameters passed from user-mode.
  1813. Return Value:
  1814. STATUS_SUCCESS or positive integer on success.
  1815. Error status code on failure.
  1816. --*/
  1817. VOID
  1818. PsEvaluateRuntimeTimers (
  1819. PKTHREAD Thread
  1820. );
  1821. /*++
  1822. Routine Description:
  1823. This routine checks the runtime timers for expiration on the current thread.
  1824. Arguments:
  1825. Thread - Supplies a pointer to the current thread.
  1826. Return Value:
  1827. None.
  1828. --*/
  1829. VOID
  1830. PsSignalThread (
  1831. PKTHREAD Thread,
  1832. ULONG SignalNumber,
  1833. PSIGNAL_QUEUE_ENTRY SignalQueueEntry,
  1834. BOOL Force
  1835. );
  1836. /*++
  1837. Routine Description:
  1838. This routine sends a signal to the given thread.
  1839. Arguments:
  1840. Thread - Supplies a pointer to the thread to send the signal to.
  1841. SignalNumber - Supplies the signal number to send.
  1842. SignalQueueEntry - Supplies an optional pointer to a queue entry to place
  1843. on the thread's queue.
  1844. Force - Supplies a boolean that if set indicates the thread cannot block
  1845. or ignore this signal.
  1846. Return Value:
  1847. None.
  1848. --*/
  1849. VOID
  1850. PsSignalProcess (
  1851. PKPROCESS Process,
  1852. ULONG SignalNumber,
  1853. PSIGNAL_QUEUE_ENTRY SignalQueueEntry
  1854. );
  1855. /*++
  1856. Routine Description:
  1857. This routine sends a signal to the given process.
  1858. Arguments:
  1859. Process - Supplies a pointer to the process to send the signal to.
  1860. SignalNumber - Supplies the signal number to send.
  1861. SignalQueueEntry - Supplies an optional pointer to a queue entry to place
  1862. on the process' queue.
  1863. Return Value:
  1864. None.
  1865. --*/
  1866. KSTATUS
  1867. PsSignalProcessId (
  1868. PROCESS_ID ProcessId,
  1869. ULONG SignalNumber,
  1870. PSIGNAL_QUEUE_ENTRY SignalQueueEntry
  1871. );
  1872. /*++
  1873. Routine Description:
  1874. This routine sends a signal to the given process.
  1875. Arguments:
  1876. ProcessId - Supplies the identifier of the process to send the signal to.
  1877. SignalNumber - Supplies the signal number to send.
  1878. SignalQueueEntry - Supplies an optional pointer to a queue entry to place
  1879. on the process' queue.
  1880. Return Value:
  1881. None.
  1882. --*/
  1883. KSTATUS
  1884. PsSignalAllProcesses (
  1885. BOOL FromKernel,
  1886. ULONG SignalNumber,
  1887. PSIGNAL_QUEUE_ENTRY QueueEntry
  1888. );
  1889. /*++
  1890. Routine Description:
  1891. This routine sends a signal to every process currently in the system
  1892. (except the kernel process). Processes created during the execution of this
  1893. call may not receive the signal. This routine is used mainly during system
  1894. shutdown.
  1895. Arguments:
  1896. FromKernel - Supplies a boolean indicating whether the origin of the signal
  1897. is the the kernel or not. Permissions are not checked if the origin
  1898. is the kernel.
  1899. SignalNumber - Supplies the signal number to send.
  1900. QueueEntry - Supplies an optional pointer to the queue structure to send.
  1901. A copy of this memory will be made in paged pool for each process a
  1902. signal is sent to.
  1903. Return Value:
  1904. STATUS_SUCCESS if some processes were signaled.
  1905. STATUS_PERMISSION_DENIED if the caller did not have permission to signal
  1906. some of the processes.
  1907. STATUS_INSUFFICIENT_RESOURCES if there was not enough memory to enumerate
  1908. all the processes in the system.
  1909. --*/
  1910. BOOL
  1911. PsIsThreadAcceptingSignal (
  1912. PKTHREAD Thread,
  1913. ULONG SignalNumber
  1914. );
  1915. /*++
  1916. Routine Description:
  1917. This routine determines if the given thread is currently accepting a given
  1918. signal, or if it is being either blocked or ignored.
  1919. Arguments:
  1920. Thread - Supplies a pointer to the process to query. If NULL is supplied
  1921. the current thread will be used.
  1922. SignalNumber - Supplies the signal number to check.
  1923. Return Value:
  1924. TRUE if the process has the signal action set to either default or a
  1925. handler.
  1926. FALSE if the signal is currently blocked or ignored.
  1927. --*/
  1928. VOID
  1929. PsDefaultSignalCompletionRoutine (
  1930. PSIGNAL_QUEUE_ENTRY SignalQueueEntry
  1931. );
  1932. /*++
  1933. Routine Description:
  1934. This routine implements the default signal completion routine, which
  1935. simply frees the signal queue entry from paged pool. The caller should
  1936. not touch the signal queue entry after this routine has returned, as it's
  1937. gone back to the pool.
  1938. Arguments:
  1939. SignalQueueEntry - Supplies a pointer to the signal queue entry that just
  1940. completed.
  1941. Return Value:
  1942. None.
  1943. --*/
  1944. VOID
  1945. PsApplyPendingSignals (
  1946. PTRAP_FRAME TrapFrame
  1947. );
  1948. /*++
  1949. Routine Description:
  1950. This routine dispatches any pending signals that should be run on the
  1951. current thread.
  1952. Arguments:
  1953. TrapFrame - Supplies a pointer to the current trap frame. If this trap frame
  1954. is not destined for user mode, this function exits immediately.
  1955. Return Value:
  1956. None.
  1957. --*/
  1958. VOID
  1959. PsApplyPendingSignalsOrRestart (
  1960. PTRAP_FRAME TrapFrame
  1961. );
  1962. /*++
  1963. Routine Description:
  1964. This routine dispatches any pending signals that should be run on the
  1965. current thread. If no signals were dispatched, it attempts to restart a
  1966. system call.
  1967. Arguments:
  1968. TrapFrame - Supplies a pointer to the current trap frame. If this trap frame
  1969. is not destined for user mode, this function exits immediately.
  1970. Return Value:
  1971. None.
  1972. --*/
  1973. ULONG
  1974. PsDequeuePendingSignal (
  1975. PSIGNAL_PARAMETERS SignalParameters,
  1976. PTRAP_FRAME TrapFrame
  1977. );
  1978. /*++
  1979. Routine Description:
  1980. This routine dequeues the first signal in the thread or process signal mask
  1981. of the current thread that is not handled by any default processing.
  1982. Arguments:
  1983. SignalParameters - Supplies a pointer to a caller-allocated structure where
  1984. the signal parameter information might get returned.
  1985. TrapFrame - Supplies a pointer to the current trap frame. If this trap frame
  1986. is not destined for user mode, this function exits immediately.
  1987. Return Value:
  1988. Returns a signal number if a signal was queued.
  1989. -1 if no signal was dispatched.
  1990. --*/
  1991. VOID
  1992. PsApplySynchronousSignal (
  1993. PTRAP_FRAME TrapFrame,
  1994. PSIGNAL_PARAMETERS SignalParameters,
  1995. BOOL InSystemCall
  1996. );
  1997. /*++
  1998. Routine Description:
  1999. This routine applies the given signal onto the current thread. It is
  2000. required that no signal is already in progress, nor will any other signals
  2001. be applied for the duration of the system call.
  2002. Arguments:
  2003. TrapFrame - Supplies a pointer to the current trap frame. This trap frame
  2004. must be destined for user mode.
  2005. SignalParameters - Supplies a pointer to the signal information to apply.
  2006. InSystemCall - Supplies a boolean indicating if the trap frame came from
  2007. a system call, in which case this routine will look inside to
  2008. potentially prepare restart information.
  2009. Return Value:
  2010. None.
  2011. --*/
  2012. VOID
  2013. PsVolumeArrival (
  2014. PCSTR VolumeName,
  2015. ULONG VolumeNameLength,
  2016. BOOL SystemVolume
  2017. );
  2018. /*++
  2019. Routine Description:
  2020. This routine implements actions that the process library takes in response
  2021. to a new volume arrival.
  2022. Arguments:
  2023. VolumeName - Supplies the full path to the new volume.
  2024. VolumeNameLength - Supplies the length of the volume name buffer, including
  2025. the null terminator, in bytes.
  2026. SystemVolume - Supplies a boolean indicating whether or not this is the
  2027. system volume.
  2028. Return Value:
  2029. None.
  2030. --*/
  2031. VOID
  2032. PsGetProcessGroup (
  2033. PKPROCESS Process,
  2034. PPROCESS_GROUP_ID ProcessGroupId,
  2035. PSESSION_ID SessionId
  2036. );
  2037. /*++
  2038. Routine Description:
  2039. This routine returns the process group and session ID for the given process.
  2040. Arguments:
  2041. Process - Supplies a pointer to the process whose process group and session
  2042. IDs are desired. Supply NULL and the current process will be used.
  2043. ProcessGroupId - Supplies an optional pointer where the process group ID of
  2044. the requested process will be returned.
  2045. SessionId - Supplies an optional pointer where the session ID of the
  2046. requested process will be returned.
  2047. Return Value:
  2048. None.
  2049. --*/
  2050. BOOL
  2051. PsIsProcessGroupOrphaned (
  2052. PROCESS_GROUP_ID ProcessGroupId
  2053. );
  2054. /*++
  2055. Routine Description:
  2056. This routine determines if a process group is orphaned.
  2057. Arguments:
  2058. ProcessGroupId - Supplies the ID of the process group to query.
  2059. Return Value:
  2060. TRUE if the process group is orphaned or does not exist.
  2061. FALSE if the process group has at least one parent within the session but
  2062. outside the process group.
  2063. --*/
  2064. BOOL
  2065. PsIsProcessGroupInSession (
  2066. PROCESS_GROUP_ID ProcessGroupId,
  2067. SESSION_ID SessionId
  2068. );
  2069. /*++
  2070. Routine Description:
  2071. This routine determines whether or not the given process group belongs to
  2072. the given session.
  2073. Arguments:
  2074. ProcessGroupId - Supplies the ID of the process group to be tested.
  2075. SessionId - Supplies the ID of the session to be searched for the given
  2076. process group.
  2077. Return Value:
  2078. Returns TRUE if the process group is in the given session.
  2079. --*/
  2080. KSTATUS
  2081. PsSignalProcessGroup (
  2082. PROCESS_GROUP_ID ProcessGroupId,
  2083. ULONG SignalNumber
  2084. );
  2085. /*++
  2086. Routine Description:
  2087. This routine sends a signal to every process in the given process group.
  2088. Arguments:
  2089. ProcessGroupId - Supplies the ID of the process group to send the signal to.
  2090. SignalNumber - Supplies the signal to send to each process in the group.
  2091. Return Value:
  2092. STATUS_SUCCESS on success.
  2093. STATUS_NOT_FOUND if there was no such process group.
  2094. --*/
  2095. KSTATUS
  2096. PsGetAllProcessInformation (
  2097. ULONG AllocationTag,
  2098. PVOID *Buffer,
  2099. PUINTN BufferSize
  2100. );
  2101. /*++
  2102. Routine Description:
  2103. This routine returns information about the active processes in the system.
  2104. Arguments:
  2105. AllocationTag - Supplies the allocation tag to use for the allocation
  2106. this routine will make on behalf of the caller.
  2107. Buffer - Supplies a pointer where a non-paged pool buffer will be returned
  2108. containing the array of process information. The caller is responsible
  2109. for freeing this memory from non-paged pool. The type returned here
  2110. will be an array (where each element may be a different size) of
  2111. PROCESS_INFORMATION structures.
  2112. BufferSize - Supplies a pointer where the size of the buffer in bytes
  2113. will be returned on success.
  2114. Return Value:
  2115. STATUS_SUCCESS on success.
  2116. STATUS_INSUFFICIENT_RESOURCES if memory could not be allocated for the
  2117. information buffer.
  2118. STATUS_BUFFER_TOO_SMALL if the process list is so volatile that it cannot
  2119. be sized. This is only returned in extremely rare cases, as this routine
  2120. makes multiple attempts.
  2121. --*/
  2122. KSTATUS
  2123. PsGetProcessInformation (
  2124. PROCESS_ID ProcessId,
  2125. PPROCESS_INFORMATION Buffer,
  2126. PUINTN BufferSize
  2127. );
  2128. /*++
  2129. Routine Description:
  2130. This routine returns information about a given process.
  2131. Arguments:
  2132. ProcessId - Supplies the ID of the process to get the information for.
  2133. Buffer - Supplies an optional pointer to a buffer to write the data into.
  2134. This buffer must be non-paged.
  2135. BufferSize - Supplies a pointer that on input contains the size of the
  2136. input buffer. On output, returns the size needed to contain the data.
  2137. Return Value:
  2138. STATUS_SUCCESS on success.
  2139. STATUS_NO_SUCH_PROCESS if the given process ID does not correspond to any
  2140. known process.
  2141. STATUS_BUFFER_TOO_SMALL if a buffer was supplied but was not big enough to
  2142. contain all the information.
  2143. --*/
  2144. KSTATUS
  2145. PsGetProcessIdentity (
  2146. PROCESS_ID ProcessId,
  2147. PTHREAD_IDENTITY Identity
  2148. );
  2149. /*++
  2150. Routine Description:
  2151. This routine gets the identity of the process, which is simply that of
  2152. an arbitrary thread in the process.
  2153. Arguments:
  2154. ProcessId - Supplies the ID of the process to get the information for.
  2155. Identity - Supplies a pointer where the process identity will be returned.
  2156. Return Value:
  2157. STATUS_SUCCESS on success.
  2158. STATUS_NO_SUCH_PROCESS if the given process ID does not correspond to any
  2159. known process.
  2160. --*/
  2161. INTN
  2162. PsSysForkProcess (
  2163. PVOID SystemCallParameter
  2164. );
  2165. /*++
  2166. Routine Description:
  2167. This routine duplicates the current process, including all allocated
  2168. address space and open file handles. Only the current thread's execution
  2169. continues in the new process.
  2170. Arguments:
  2171. SystemCallParameter - Supplies a pointer to the parameters supplied with
  2172. the system call. This structure will be a stack-local copy of the
  2173. actual parameters passed from user-mode.
  2174. Return Value:
  2175. Process ID of the child on success (a positive integer).
  2176. Error status code on failure (a negative integer).
  2177. --*/
  2178. INTN
  2179. PsSysExecuteImage (
  2180. PVOID SystemCallParameter
  2181. );
  2182. /*++
  2183. Routine Description:
  2184. This routine duplicates the current process, including all allocated
  2185. address space and open file handles. Only the current thread's execution
  2186. continues in the new process.
  2187. Arguments:
  2188. SystemCallParameter - Supplies a pointer to the parameters supplied with
  2189. the system call. This structure will be a stack-local copy of the
  2190. actual parameters passed from user-mode.
  2191. Return Value:
  2192. The architecture-specific return register from the reset thread context on
  2193. success. This is necessary because the architecture-specific system call
  2194. assembly routines do not restore the return register out of the trap frame
  2195. in order to allow a system call to return a value via a register. If an
  2196. architecture does not need to pass anything to the new thread in its return
  2197. register, then it should return 0.
  2198. Error status code on failure.
  2199. --*/
  2200. INTN
  2201. PsSysGetSetProcessId (
  2202. PVOID SystemCallParameter
  2203. );
  2204. /*++
  2205. Routine Description:
  2206. This routine gets or sets identifiers associated with the calling process.
  2207. Arguments:
  2208. SystemCallParameter - Supplies a pointer to the parameters supplied with
  2209. the system call. This structure will be a stack-local copy of the
  2210. actual parameters passed from user-mode.
  2211. Return Value:
  2212. STATUS_SUCCESS or the requested process ID on success.
  2213. Error status code on failure.
  2214. --*/
  2215. INTN
  2216. PsSysDebug (
  2217. PVOID SystemCallParameter
  2218. );
  2219. /*++
  2220. Routine Description:
  2221. This routine implements the user mode debug interface.
  2222. Arguments:
  2223. SystemCallParameter - Supplies a pointer to the parameters supplied with
  2224. the system call. This structure will be a stack-local copy of the
  2225. actual parameters passed from user-mode.
  2226. Return Value:
  2227. STATUS_SUCCESS or positive integer on success.
  2228. Error status code on failure.
  2229. --*/
  2230. INTN
  2231. PsSysExitProcess (
  2232. PVOID SystemCallParameter
  2233. );
  2234. /*++
  2235. Routine Description:
  2236. This routine terminates the current process.
  2237. Arguments:
  2238. SystemCallParameter - Supplies a pointer to the parameters supplied with
  2239. the system call. This stores the exit status for the process. It is
  2240. passed to the kernel in a register.
  2241. Return Value:
  2242. STATUS_SUCCESS or positive integer on success.
  2243. Error status code on failure.
  2244. --*/
  2245. INTN
  2246. PsSysGetResourceUsage (
  2247. PVOID SystemCallParameter
  2248. );
  2249. /*++
  2250. Routine Description:
  2251. This routine returns the resource usage for a process or thread.
  2252. Arguments:
  2253. SystemCallParameter - Supplies a pointer to the parameters supplied with
  2254. the system call. This structure will be a stack-local copy of the
  2255. actual parameters passed from user-mode.
  2256. Return Value:
  2257. STATUS_SUCCESS or positive integer on success.
  2258. Error status code on failure.
  2259. --*/
  2260. INTN
  2261. PsSysSetUmask (
  2262. PVOID SystemCallParameter
  2263. );
  2264. /*++
  2265. Routine Description:
  2266. This routine sets the file permission mask for the current process.
  2267. Arguments:
  2268. SystemCallParameter - Supplies a pointer to the parameters supplied with
  2269. the system call. This structure will be a stack-local copy of the
  2270. actual parameters passed from user-mode.
  2271. Return Value:
  2272. STATUS_SUCCESS or positive integer on success.
  2273. Error status code on failure.
  2274. --*/
  2275. PKPROCESS
  2276. PsCreateProcess (
  2277. PCSTR CommandLine,
  2278. ULONG CommandLineSize,
  2279. PVOID RootDirectoryPathPoint,
  2280. PVOID WorkingDirectoryPathPoint,
  2281. PVOID SharedMemoryDirectoryPathPoint
  2282. );
  2283. /*++
  2284. Routine Description:
  2285. This routine creates a new process and executes the given binary image.
  2286. This routine must be called at low level.
  2287. Arguments:
  2288. CommandLine - Supplies a pointer to a string containing the command line to
  2289. invoke (the executable and any arguments).
  2290. CommandLineSize - Supplies the size of the command line in bytes, including
  2291. the null terminator.
  2292. RootDirectoryPathPoint - Supplies an optional pointer to the path point of
  2293. the root directory to set for the new process.
  2294. WorkingDirectoryPathPoint - Supplies an optional pointer to the path point
  2295. of the working directory to set for the process.
  2296. SharedMemoryDirectoryPathPoint - Supplies an optional pointer to the path
  2297. point of the shared memory object directory to set for the process.
  2298. Return Value:
  2299. Returns a pointer to the new process, or NULL if the process could not be
  2300. created. This process will contain a reference that the caller must
  2301. explicitly release.
  2302. --*/
  2303. PKPROCESS
  2304. PsGetCurrentProcess (
  2305. VOID
  2306. );
  2307. /*++
  2308. Routine Description:
  2309. This routine returns the currently running process.
  2310. Arguments:
  2311. None.
  2312. Return Value:
  2313. Returns a pointer to the current process.
  2314. --*/
  2315. PKPROCESS
  2316. PsGetKernelProcess (
  2317. VOID
  2318. );
  2319. /*++
  2320. Routine Description:
  2321. This routine returns a pointer to the system process.
  2322. Arguments:
  2323. None.
  2324. Return Value:
  2325. Returns a pointer to the system process.
  2326. --*/
  2327. ULONG
  2328. PsGetProcessCount (
  2329. VOID
  2330. );
  2331. /*++
  2332. Routine Description:
  2333. This routine returns the number of active processes in the system. This
  2334. count includes the kernel process (and therefore is never zero). This
  2335. information is stale as soon as it is received, and as such is only useful
  2336. in limited scenarios.
  2337. Arguments:
  2338. None.
  2339. Return Value:
  2340. Returns the number of active processes in the system.
  2341. --*/
  2342. VOID
  2343. PsIterateProcess (
  2344. PROCESS_ID_TYPE Type,
  2345. PROCESS_ID Match,
  2346. PPROCESS_ITERATOR_ROUTINE IteratorFunction,
  2347. PVOID Context
  2348. );
  2349. /*++
  2350. Routine Description:
  2351. This routine iterates over all processes in the process ID list.
  2352. Arguments:
  2353. Type - Supplies the type of identifier to match on. Valid values are
  2354. process ID, process group, or session.
  2355. Match - Supplies the process, process group, or session ID to match on.
  2356. Supply -1 to iterate over all processes.
  2357. IteratorFunction - Supplies a pointer to the function to call for each
  2358. matching process.
  2359. Context - Supplies an opaque pointer that will be passed into the iterator
  2360. function on each iteration.
  2361. Return Value:
  2362. None.
  2363. --*/
  2364. VOID
  2365. PsHandleUserModeFault (
  2366. PVOID VirtualAddress,
  2367. ULONG FaultFlags,
  2368. PTRAP_FRAME TrapFrame,
  2369. PKPROCESS Process
  2370. );
  2371. /*++
  2372. Routine Description:
  2373. This routine handles a user mode fault where no image section seems to back
  2374. the faulting address or a write attempt was made to a read-only image
  2375. section.
  2376. Arguments:
  2377. VirtualAddress - Supplies the virtual address that caused the fault.
  2378. FaultFlags - Supplies the fault information.
  2379. TrapFrame - Supplies a pointer to the trap frame.
  2380. Process - Supplies the process that caused the fault.
  2381. Return Value:
  2382. None.
  2383. --*/
  2384. KSTATUS
  2385. PsIncreaseAllThreadIrpCount (
  2386. ULONG OldPagingIrpCount,
  2387. ULONG NewPagingIrpCount
  2388. );
  2389. /*++
  2390. Routine Description:
  2391. This routine allocates more IRPs for each thread to handle a new page file
  2392. coming online whose stack requires additional IRPs to complete page file
  2393. I/O.
  2394. Arguments:
  2395. OldPagingIrpCount - Supplies the number of IRPs previously required to
  2396. complete paging I/O.
  2397. NewPagingIrpCount - Supplies the number of IRPs required to complete paging
  2398. I/O.
  2399. Return Value:
  2400. STATUS_SUCCESS on success.
  2401. STATUS_INSUFFICIENT_RESOURCES if new IRPs could not be allocated.
  2402. --*/
  2403. VOID
  2404. PsQueueThreadCleanup (
  2405. PKTHREAD Thread
  2406. );
  2407. /*++
  2408. Routine Description:
  2409. This routine queues the work item that cleans up a dead thread. This routine
  2410. must not be executed by the thread being destroyed! This routine must be
  2411. called at dispatch level.
  2412. Arguments:
  2413. Thread - Supplies a pointer to the thread to clean up.
  2414. Return Value:
  2415. None.
  2416. --*/
  2417. KSTATUS
  2418. PsCopyEnvironment (
  2419. PPROCESS_ENVIRONMENT Source,
  2420. PPROCESS_ENVIRONMENT *Destination,
  2421. BOOL FromUserMode,
  2422. PKTHREAD DestinationThread,
  2423. PSTR OverrideImageName,
  2424. UINTN OverrideImageNameSize
  2425. );
  2426. /*++
  2427. Routine Description:
  2428. This routine creates a copy of a pre-existing environment.
  2429. Arguments:
  2430. Source - Supplies a pointer to the source environment to copy.
  2431. Destination - Supplies a pointer where a pointer to the newly created
  2432. environment will be returned.
  2433. FromUserMode - Supplies a boolean indicating whether the environment exists
  2434. in user mode or not.
  2435. DestinationThread - Supplies an optional pointer to the user mode thread
  2436. to copy the environment into. Supply NULL to copy the environment to
  2437. a new kernel mode buffer.
  2438. OverrideImageName - Supplies an optional pointer to an image name to use as
  2439. an override of the image name in the source environment.
  2440. OverrideImageNameSize - Supplies the size of the override image name,
  2441. including the null terminator.
  2442. Return Value:
  2443. Status code.
  2444. --*/
  2445. KSTATUS
  2446. PsCreateEnvironment (
  2447. PCSTR CommandLine,
  2448. ULONG CommandLineSize,
  2449. PSTR *EnvironmentVariables,
  2450. ULONG EnvironmentVariableCount,
  2451. PPROCESS_ENVIRONMENT *NewEnvironment
  2452. );
  2453. /*++
  2454. Routine Description:
  2455. This routine creates a new environment based on a command line.
  2456. Arguments:
  2457. CommandLine - Supplies a pointer to a string containing the command line,
  2458. including the image and any arguments.
  2459. CommandLineSize - Supplies the size of the command line buffer in bytes,
  2460. including the null terminator character.
  2461. EnvironmentVariables - Supplies an optional pointer to an array of
  2462. environment variables in the form name=value.
  2463. EnvironmentVariableCount - Supplies the number of valid entries in the
  2464. environment variables array. For example, 1 if there is a single
  2465. environment variable.
  2466. NewEnvironment - Supplies a pointer where a pointer to the newly created
  2467. environment will be returned on success. The caller is responsible
  2468. for freeing this memory from paged pool.
  2469. Return Value:
  2470. Status code.
  2471. --*/
  2472. VOID
  2473. PsDestroyEnvironment (
  2474. PPROCESS_ENVIRONMENT Environment
  2475. );
  2476. /*++
  2477. Routine Description:
  2478. This routine destroys an environment and frees all resources associated with
  2479. it. This routine can only be called on environments created in kernel space.
  2480. Arguments:
  2481. Environment - Supplies a pointer to the environment to tear down.
  2482. Return Value:
  2483. None.
  2484. --*/
  2485. KSTATUS
  2486. PsGetSetSystemInformation (
  2487. BOOL FromKernelMode,
  2488. PS_INFORMATION_TYPE InformationType,
  2489. PVOID Data,
  2490. PUINTN DataSize,
  2491. BOOL Set
  2492. );
  2493. /*++
  2494. Routine Description:
  2495. This routine gets or sets system information.
  2496. Arguments:
  2497. FromKernelMode - Supplies a boolean indicating whether or not this request
  2498. (and the buffer associated with it) originates from user mode (FALSE)
  2499. or kernel mode (TRUE).
  2500. InformationType - Supplies the information type.
  2501. Data - Supplies a pointer to the data buffer where the data is either
  2502. returned for a get operation or given for a set operation.
  2503. DataSize - Supplies a pointer that on input contains the size of the
  2504. data buffer. On output, contains the required size of the data buffer.
  2505. Set - Supplies a boolean indicating if this is a get operation (FALSE) or
  2506. a set operation (TRUE).
  2507. Return Value:
  2508. Status code.
  2509. --*/