minocaos.h 92 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302
  1. /*++
  2. Copyright (c) 2013 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. minocaos.h
  5. Abstract:
  6. This header contains definitions for the Operating System Base library.
  7. Author:
  8. Evan Green 25-Feb-2013
  9. --*/
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. //
  14. // ------------------------------------------------------------------- Includes
  15. //
  16. #include <minoca/kernel/driver.h>
  17. //
  18. // --------------------------------------------------------------------- Macros
  19. //
  20. //
  21. // Use this macro to initialize a spin lock with default values.
  22. //
  23. #define OsInitializeLockDefault(_SpinLock) \
  24. OsInitializeLock((_SpinLock), OS_LOCK_DEFAULT_SPIN_COUNT)
  25. //
  26. // ---------------------------------------------------------------- Definitions
  27. //
  28. #ifndef OS_API
  29. #define OS_API __DLLIMPORT
  30. #endif
  31. //
  32. // Define the allocation tag used by OS thread routines: OsTh
  33. //
  34. #define OS_THREAD_ALLOCATION_TAG 0x6854734F
  35. //
  36. // Define the default system value for number of spins before spin locks start
  37. // sleeping.
  38. //
  39. #define OS_LOCK_DEFAULT_SPIN_COUNT 500
  40. //
  41. // Provide this handle to search for symbols in the executing program's global
  42. // scope.
  43. //
  44. #define OS_LIBRARY_DEFAULT ((HANDLE)NULL)
  45. //
  46. // Provide this handle to search for symbols in the executable after the
  47. // currently executing program. "Next" is defined in terms of load order.
  48. //
  49. #define OS_LIBRARY_NEXT ((HANDLE)-1)
  50. //
  51. // Set this flag when initializing a read-write lock to indicate the lock
  52. // should be shared across processes.
  53. //
  54. #define OS_RWLOCK_SHARED 0x00000001
  55. //
  56. // ------------------------------------------------------ Data Type Definitions
  57. //
  58. typedef enum _OS_ARM_PROCESSOR_FEATURE {
  59. OsArmFeatureInvalid,
  60. OsArmArmv7,
  61. OsArmVfp,
  62. OsArmVfp3,
  63. OsArmNeon32,
  64. OsArmFeatureCount
  65. } OS_ARM_PROCESSOR_FEATURE, *POS_ARM_PROCESSOR_FEATURE;
  66. typedef enum _OS_X86_PROCESSOR_FEATURE {
  67. OsX86FeatureInvalid,
  68. OsX86Sysenter,
  69. OsX86I686,
  70. OsX86FxSave,
  71. OsX86FeatureCount
  72. } OS_X86_PROCESSOR_FEATURE, *POS_X86_PROCESSOR_FEATURE;
  73. typedef
  74. BOOL
  75. (*PSIGNAL_HANDLER_ROUTINE) (
  76. PSIGNAL_PARAMETERS SignalInformation
  77. );
  78. /*++
  79. Routine Description:
  80. This routine is called whenever a signal occurs for the current process or
  81. thread.
  82. Arguments:
  83. SignalInformation - Supplies a pointer to the signal information. This
  84. pointer may be stack allocated, and should not be referenced once the
  85. handler has returned.
  86. Return Value:
  87. TRUE if an interrupted function can restart.
  88. FALSE otherwise.
  89. --*/
  90. typedef
  91. VOID
  92. (*PIMAGE_ITERATOR_ROUTINE) (
  93. PLOADED_IMAGE Image,
  94. PVOID Context
  95. );
  96. /*++
  97. Routine Description:
  98. This routine is called for each loaded image in the process.
  99. Arguments:
  100. Image - Supplies a pointer to the loaded image.
  101. Context - Supplies the context pointer that was passed into the iterate
  102. request function.
  103. Return Value:
  104. None.
  105. --*/
  106. /*++
  107. Structure Description:
  108. This structure defines a basic lock type.
  109. Members:
  110. Value - Stores the current lock state.
  111. SpinCount - Stores the number of times the lock will simply spin and yield
  112. trying to acquire the lock at first.
  113. --*/
  114. typedef struct _OS_LOCK {
  115. ULONG Value;
  116. ULONG SpinCount;
  117. } OS_LOCK, *POS_LOCK;
  118. /*++
  119. Structure Description:
  120. This structure stores the internal structure of a read/write lock.
  121. Members:
  122. State - Stores the state of the lock. 0 is unlocked, -1 is locked for
  123. write, and any other value contains a count of readers.
  124. WriterThreadId - Stores the thread ID of the thread that has this lock for
  125. writing, if any.
  126. PendingReaders - Stores the number of threads waiting to acquire the lock
  127. for read access.
  128. PendingWriters - Stores the number of threads waiting to acquire the lock
  129. for write access.
  130. --*/
  131. typedef struct _OS_RWLOCK {
  132. ULONG State;
  133. UINTN WriterThreadId;
  134. ULONG PendingReaders;
  135. ULONG PendingWriters;
  136. ULONG Attributes;
  137. } OS_RWLOCK, *POS_RWLOCK;
  138. /*++
  139. Structure Description:
  140. This structure defines a thread local storage index entry, the format of
  141. which is defined by the ABI and assumed by the compiler.
  142. Members:
  143. Module - Stores the module ID. Valid module IDs start at 1.
  144. Offset - Stores the offset from the beginning of the thread local storage
  145. section to the desired symbol.
  146. --*/
  147. typedef struct _TLS_INDEX {
  148. UINTN Module;
  149. UINTN Offset;
  150. } TLS_INDEX, *PTLS_INDEX;
  151. /*++
  152. Structure Description:
  153. This structure defines a dynamic library's symbol.
  154. Members:
  155. LibraryName - Stores the name of the library that contains the symbol.
  156. LibraryBaseAddress - Stores the base address of the library that contains
  157. the symbol.
  158. SymbolName - Stores the name of the symbol.
  159. SymbolAddress - Stores the address of the symbol.
  160. --*/
  161. typedef struct _OS_LIBRARY_SYMBOL {
  162. PSTR LibraryName;
  163. PVOID LibraryBaseAddress;
  164. PSTR SymbolName;
  165. PVOID SymbolAddress;
  166. } OS_LIBRARY_SYMBOL, *POS_LIBRARY_SYMBOL;
  167. //
  168. // -------------------------------------------------------------------- Globals
  169. //
  170. //
  171. // Store a pointer to the routine used to get environment variable contents.
  172. //
  173. OS_API extern PIM_GET_ENVIRONMENT_VARIABLE OsImGetEnvironmentVariable;
  174. //
  175. // -------------------------------------------------------- Function Prototypes
  176. //
  177. OS_API
  178. VOID
  179. OsInitializeLibrary (
  180. PPROCESS_ENVIRONMENT Environment
  181. );
  182. /*++
  183. Routine Description:
  184. This routine initializes the base OS library. It needs to be called only
  185. once, when the library is first loaded.
  186. Arguments:
  187. Environment - Supplies a pointer to the environment information.
  188. Return Value:
  189. None.
  190. --*/
  191. OS_API
  192. VOID
  193. OsTestSystemCall (
  194. VOID
  195. );
  196. /*++
  197. Routine Description:
  198. This routine performs a meaningless system call.
  199. Arguments:
  200. None.
  201. Return Value:
  202. None.
  203. --*/
  204. OS_API
  205. KSTATUS
  206. OsOpen (
  207. HANDLE Directory,
  208. PSTR Path,
  209. ULONG PathLength,
  210. ULONG Flags,
  211. FILE_PERMISSIONS CreatePermissions,
  212. PHANDLE Handle
  213. );
  214. /*++
  215. Routine Description:
  216. This routine opens a file or other I/O object.
  217. Arguments:
  218. Directory - Supplies an optional handle to a directory to start the
  219. search from if the supplied path is relative. Supply INVALID_HANDLE
  220. here to to use the current directory for relative paths.
  221. Path - Supplies a pointer to a string containing the path of the object
  222. to open.
  223. PathLength - Supplies the length of the path buffer, in bytes, including
  224. the null terminator.
  225. Flags - Supplies flags associated with the open operation. See
  226. SYS_OPEN_FLAG_* definitions.
  227. CreatePermissions - Supplies the permissions for create operations.
  228. Handle - Supplies a pointer where a handle will be returned on success.
  229. Return Value:
  230. Status code.
  231. --*/
  232. OS_API
  233. KSTATUS
  234. OsOpenDevice (
  235. DEVICE_ID DeviceId,
  236. ULONG Flags,
  237. PHANDLE Handle
  238. );
  239. /*++
  240. Routine Description:
  241. This routine opens a device directly.
  242. Arguments:
  243. DeviceId - Supplies the identifier of the device to open.
  244. Flags - Supplies flags associated with the open operation. See
  245. SYS_OPEN_FLAG_* definitions.
  246. Handle - Supplies a pointer where a handle will be returned on success.
  247. Return Value:
  248. Status code.
  249. --*/
  250. OS_API
  251. KSTATUS
  252. OsClose (
  253. HANDLE Handle
  254. );
  255. /*++
  256. Routine Description:
  257. This routine closes an I/O handle.
  258. Arguments:
  259. Handle - Supplies a pointer to the open handle.
  260. Return Value:
  261. Status code.
  262. --*/
  263. OS_API
  264. KSTATUS
  265. OsPerformIo (
  266. HANDLE Handle,
  267. IO_OFFSET Offset,
  268. UINTN Size,
  269. ULONG Flags,
  270. ULONG TimeoutInMilliseconds,
  271. PVOID Buffer,
  272. PUINTN BytesCompleted
  273. );
  274. /*++
  275. Routine Description:
  276. This routine performs I/O on an open handle.
  277. Arguments:
  278. Handle - Supplies a pointer to the opened I/O handle.
  279. Offset - Supplies the offset into the file to read from or write to. Set
  280. this to IO_OFFSET_NONE to do I/O at the current file position or for
  281. handles that are not seekable.
  282. Size - Supplies the number of bytes to transfer.
  283. Flags - Supplies a bitfield of flags. See SYS_IO_FLAG_* definitions.
  284. TimeoutInMilliseconds - Supplies the number of milliseconds that the I/O
  285. operation should be waited on before timing out. Use
  286. SYS_WAIT_TIME_INDEFINITE to wait forever on the I/O.
  287. Buffer - Supplies a pointer to the buffer containing the data to write or
  288. where the read data should be returned, depending on the operation.
  289. BytesCompleted - Supplies a pointer where the number of bytes completed
  290. will be returned.
  291. Return Value:
  292. Status code.
  293. --*/
  294. OS_API
  295. KSTATUS
  296. OsPerformVectoredIo (
  297. HANDLE Handle,
  298. IO_OFFSET Offset,
  299. UINTN Size,
  300. ULONG Flags,
  301. ULONG TimeoutInMilliseconds,
  302. PIO_VECTOR VectorArray,
  303. UINTN VectorCount,
  304. PUINTN BytesCompleted
  305. );
  306. /*++
  307. Routine Description:
  308. This routine performs I/O on an open handle.
  309. Arguments:
  310. Handle - Supplies a pointer to the opened I/O handle.
  311. Offset - Supplies the offset into the file to read from or write to. Set
  312. this to IO_OFFSET_NONE to do I/O at the current file position or for
  313. handles that are not seekable.
  314. Size - Supplies the number of bytes to transfer.
  315. Flags - Supplies a bitfield of flags. See SYS_IO_FLAG_* definitions.
  316. TimeoutInMilliseconds - Supplies the number of milliseconds that the I/O
  317. operation should be waited on before timing out. Use
  318. SYS_WAIT_TIME_INDEFINITE to wait forever on the I/O.
  319. VectorArray - Supplies an array of I/O vector structures to do I/O to/from.
  320. VectorCount - Supplies the number of elements in the vector array.
  321. BytesCompleted - Supplies a pointer where the number of bytes completed
  322. will be returned.
  323. Return Value:
  324. Status code.
  325. --*/
  326. OS_API
  327. KSTATUS
  328. OsFlush (
  329. HANDLE Handle,
  330. ULONG Flags
  331. );
  332. /*++
  333. Routine Description:
  334. This routine flushes handle data to its backing device. If the flags
  335. specify that all data is to be flushed, then a handle is not required.
  336. Arguments:
  337. Handle - Supplies an open I/O handle. This parameter is not required if
  338. SYS_FLUSH_FLAG_ALL is set.
  339. Flags - Supplies a bitfield of flags. See SYS_FLUSH_FLAG_* definitions.
  340. Return Value:
  341. Status code.
  342. --*/
  343. OS_API
  344. KSTATUS
  345. OsCreatePipe (
  346. HANDLE Directory,
  347. PSTR Path,
  348. ULONG PathLength,
  349. ULONG Flags,
  350. FILE_PERMISSIONS Permissions,
  351. PHANDLE ReadHandle,
  352. PHANDLE WriteHandle
  353. );
  354. /*++
  355. Routine Description:
  356. This routine creates a pipe.
  357. Arguments:
  358. Directory - Supplies an optional handle to a directory to start the
  359. search from if the supplied path is relative. Supply INVALID_HANDLE
  360. here to to use the current directory for relative paths.
  361. Path - Supplies an optional pointer to the path to create the pipe at.
  362. PathLength - Supplies the length of the path buffer in bytes, including
  363. the null terminator character.
  364. Flags - Supplies a bitfield of flags governing the behavior of the new pipe
  365. descriptors. Only SYS_OPEN_FLAG_CLOSE_ON_EXECUTE and
  366. SYS_OPEN_FLAG_NON_BLOCKING are permitted.
  367. Permissions - Supplies the initial permissions to set on the pipe.
  368. ReadHandle - Supplies a pointer where the handle to the read end of the
  369. pipe will be returned on success. Handles are only returned if a
  370. NULL path was passed in.
  371. WriteHandle - Supplies a pointer where the handle to the write end of the
  372. pipe will be returned on success. Handles are only returned in a NULL
  373. path was passed in.
  374. Return Value:
  375. Status code.
  376. --*/
  377. OS_API
  378. VOID
  379. OsExitThread (
  380. PVOID UnmapAddress,
  381. UINTN UnmapSize
  382. );
  383. /*++
  384. Routine Description:
  385. This routine terminates the current thread, and optionally attempts to
  386. unmap a region of memory on its way out. Usually this is the stack of the
  387. thread that is exiting.
  388. Arguments:
  389. UnmapAddress - Supplies an optional pointer to a region of memory to unmap
  390. as the thread exits. Supply NULL to skip unmapping.
  391. UnmapSize - Supplies the size of the region to unmap in bytes. This must be
  392. aligned to the page size. If it is not, the unmap simply won't happen.
  393. Supply 0 to skip the unmap and just exit the thread. If -1 is supplied,
  394. this routine returns. This value can be used to warm up the PLT entry,
  395. since lazy binding cannot take place after the thread's control block
  396. has been destroyed.
  397. Return Value:
  398. This routine does not return, unless the magic size is passed in.
  399. --*/
  400. OS_API
  401. KSTATUS
  402. OsCreateThread (
  403. PSTR ThreadName,
  404. ULONG ThreadNameBufferLength,
  405. PTHREAD_ENTRY_ROUTINE ThreadRoutine,
  406. PVOID Parameter,
  407. PVOID StackBase,
  408. ULONG StackSize,
  409. PVOID ThreadPointer,
  410. PTHREAD_ID ThreadId
  411. );
  412. /*++
  413. Routine Description:
  414. This routine creates a new thread.
  415. Arguments:
  416. ThreadName - Supplies an optional pointer to the thread name.
  417. ThreadNameBufferLength - Supplies the size of the thread name buffer,
  418. including the null terminator.
  419. ThreadRoutine - Supplies a pointer to the funtion that should be run on the
  420. new thread.
  421. Parameter - Supplies a pointer that will be passed directly to the thread
  422. routine.
  423. StackBase - Supplies an optional pointer to the stack base address. If
  424. supplied, the kernel will not add a guard region or automatically
  425. expand the stack.
  426. StackSize - Supplies the size of the new thread's stack. Supply 0 to use
  427. the system default.
  428. ThreadPointer - Supplies the thread pointer to set for the new thread.
  429. ThreadId - Supplies an optional pointer where the ID of the new thread will
  430. be returned on success.
  431. Return Value:
  432. Status code.
  433. --*/
  434. OS_API
  435. KSTATUS
  436. OsForkProcess (
  437. PPROCESS_ID NewProcessId
  438. );
  439. /*++
  440. Routine Description:
  441. This routine forks the current process into two separate processes. The
  442. child process begins executing in the middle of this function.
  443. Arguments:
  444. NewProcessId - Supplies a pointer that on success contains the process ID
  445. of the child process in the parent, and 0 in the child. This value
  446. contains -1 if the new process failed to spawn.
  447. Return Value:
  448. STATUS_SUCCESS in both the parent and child on success.
  449. Other status codes are returned to the parent if the child failed to spawn.
  450. --*/
  451. OS_API
  452. KSTATUS
  453. OsExecuteImage (
  454. PPROCESS_ENVIRONMENT Environment
  455. );
  456. /*++
  457. Routine Description:
  458. This routine replaces the currently running process with the given binary
  459. image.
  460. Arguments:
  461. Environment - Supplies a pointer to the environment to execute, which
  462. includes the image name, parameters, and environment variables.
  463. Return Value:
  464. If this routine succeeds, it will not return, as the process will be
  465. replaced with the new executable. If the process could not be started,
  466. a failing status code will be returned to the caller.
  467. --*/
  468. OS_API
  469. KSTATUS
  470. OsGetSystemVersion (
  471. PSYSTEM_VERSION_INFORMATION VersionInformation,
  472. BOOL WantStrings
  473. );
  474. /*++
  475. Routine Description:
  476. This routine gets the system version information.
  477. Arguments:
  478. VersionInformation - Supplies a pointer where the system version
  479. information will be returned. The caller should not attempt to modify
  480. or free the strings pointed to by members of this structure.
  481. WantStrings - Supplies a boolean indicating if the build strings are
  482. desired or just the major/minor version information.
  483. Return Value:
  484. Status code.
  485. --*/
  486. OS_API
  487. KSTATUS
  488. OsGetCurrentDirectory (
  489. BOOL Root,
  490. PSTR *Buffer,
  491. PUINTN BufferSize
  492. );
  493. /*++
  494. Routine Description:
  495. This routine retrieves a pointer to a null terminated string containing the
  496. path to the current working directory or the current root directory.
  497. Arguments:
  498. Root - Supplies a boolean indicating whether caller would like the current
  499. working directory (FALSE) or the path to the current root directory
  500. (TRUE). If the caller does not have permission to escape roots, or
  501. does not currently have an altered root directory, then / is returned.
  502. Buffer - Supplies a pointer that receives a pointer to a buffer that
  503. contains a null terminated string for the path to the current
  504. directory.
  505. BufferSize - Supplies a pointer that receives the size of the buffer, in
  506. bytes.
  507. Return Value:
  508. Status code.
  509. --*/
  510. OS_API
  511. KSTATUS
  512. OsChangeDirectory (
  513. BOOL Root,
  514. PSTR Path,
  515. ULONG PathSize
  516. );
  517. /*++
  518. Routine Description:
  519. This routine sets the current working directory or current root directory.
  520. Arguments:
  521. Root - Supplies a boolean indicating whether to change the current working
  522. directory (FALSE) or the current root directory (TRUE). If attempting
  523. to change the root, the caller must have permission to change the root,
  524. must be running a single thread, and must not have any other handles
  525. to directories open.
  526. Path - Supplies a pointer to the path of the new working directory. If
  527. trying to escape the root, supply NULL here. The caller must have
  528. sufficient privileges to escape a root.
  529. PathSize - Supplies the size of the path directory string in bytes
  530. including the null terminator.
  531. Return Value:
  532. Status code.
  533. --*/
  534. OS_API
  535. KSTATUS
  536. OsChangeDirectoryHandle (
  537. BOOL Root,
  538. HANDLE Handle
  539. );
  540. /*++
  541. Routine Description:
  542. This routine sets the current working directory or root directory to the
  543. same directory opened with the given file handle.
  544. Arguments:
  545. Root - Supplies a boolean indicating whether to change the current working
  546. directory (FALSE) or the current root directory (TRUE). If attempting
  547. to change the root, the caller must have permission to change the root,
  548. must be running a single thread, and must not have any other handles
  549. to directories open.
  550. Handle - Supplies an open handle to a directory to change the current
  551. working directroy to. Supply INVALID_HANDLE here to escape the root.
  552. The caller must have sufficient privileges to escape a root.
  553. Return Value:
  554. Status code.
  555. --*/
  556. OS_API
  557. KSTATUS
  558. OsPoll (
  559. PSIGNAL_SET SignalMask,
  560. PPOLL_DESCRIPTOR Descriptors,
  561. ULONG DescriptorCount,
  562. ULONG TimeoutInMilliseconds,
  563. PULONG DescriptorsSelected
  564. );
  565. /*++
  566. Routine Description:
  567. This routine polls several I/O handles.
  568. Arguments:
  569. SignalMask - Supplies an optional pointer to a mask to set for the
  570. duration of the wait.
  571. Descriptors - Supplies a pointer to an array of poll descriptor structures
  572. describing the descriptors and events to wait on.
  573. DescriptorCount - Supplies the number of descriptors in the array.
  574. TimeoutInMilliseconds - Supplies the number of milliseconds to wait before
  575. giving up.
  576. DescriptorsSelected - Supplies a pointer where the number of descriptors
  577. that had activity will be returned on success.
  578. Return Value:
  579. STATUS_SUCCESS if one or more descriptors is ready for action.
  580. STATUS_INSUFFICIENT_RESOURCES if memory could not be allocated for the
  581. operation.
  582. STATUS_INTERRUPTED if a signal was caught during the wait.
  583. STATUS_TIMEOUT if no descriptors were ready in the given amount of time.
  584. --*/
  585. OS_API
  586. PSIGNAL_HANDLER_ROUTINE
  587. OsSetSignalHandler (
  588. PSIGNAL_HANDLER_ROUTINE NewHandler
  589. );
  590. /*++
  591. Routine Description:
  592. This routine sets the signal handler routine called whenever a signal is
  593. delivered by the kernel.
  594. Arguments:
  595. NewHandler - Supplies a pointer to the new handler routine to use.
  596. Return Value:
  597. Returns a pointer to the old handler, or NULL if no other signal handlers
  598. were registered.
  599. --*/
  600. OS_API
  601. KSTATUS
  602. OsSendSignal (
  603. SIGNAL_TARGET_TYPE TargetType,
  604. ULONG TargetId,
  605. ULONG SignalNumber,
  606. SHORT SignalCode,
  607. UINTN SignalParameter
  608. );
  609. /*++
  610. Routine Description:
  611. This routine sends a signal to a process, process group or thread.
  612. Arguments:
  613. TargetType - Supplies the target type to which the signal is being sent. It
  614. can be either a process, process group, or thread.
  615. TargetId - Supplies the ID for the signal's target process, process group,
  616. or thread.
  617. SignalNumber - Supplies the signal number to send.
  618. SignalCode - Supplies the signal code to send. See SIGNAL_CODE_*
  619. definitions.
  620. SignalParameter - Supplies a parameter to send with the signal if the
  621. signal is in the real time signal range.
  622. Return Value:
  623. Status code.
  624. --*/
  625. OS_API
  626. KSTATUS
  627. OsGetProcessId (
  628. PROCESS_ID_TYPE ProcessIdType,
  629. PPROCESS_ID ProcessId
  630. );
  631. /*++
  632. Routine Description:
  633. This routine gets an identifier associated with the process, such as the
  634. process ID, thread ID, parent process ID, process group ID, and session ID.
  635. Arguments:
  636. ProcessIdType - Supplies the type of ID to get.
  637. ProcessId - Supplies a pointer that on input contains the process ID
  638. argument if the operation takes a parameter. On successful output,
  639. returns the desired ID. Supply zero to use the calling process ID.
  640. Return Value:
  641. Status code.
  642. --*/
  643. OS_API
  644. KSTATUS
  645. OsSetProcessId (
  646. PROCESS_ID_TYPE ProcessIdType,
  647. PROCESS_ID ProcessId,
  648. PROCESS_ID NewValue
  649. );
  650. /*++
  651. Routine Description:
  652. This routine sets an identifier associated with the process, such as the
  653. process group ID or session ID.
  654. Arguments:
  655. ProcessIdType - Supplies the type of ID to set. Not all types can be set.
  656. ProcessId - Supplies the ID of the process to change. Supply 0 to use the
  657. current process.
  658. NewValue - Supplies the new value to set.
  659. Return Value:
  660. Status code.
  661. --*/
  662. OS_API
  663. SIGNAL_SET
  664. OsSetSignalBehavior (
  665. SIGNAL_MASK_TYPE MaskType,
  666. SIGNAL_MASK_OPERATION Operation,
  667. PSIGNAL_SET NewMask
  668. );
  669. /*++
  670. Routine Description:
  671. This routine sets signal behavior, either for the current thread in the
  672. case of the blocked signals, or for the process for other signal masks.
  673. Arguments:
  674. MaskType - Supplies the type of mask to change.
  675. Operation - Supplies the interaction between the new mask and the previous
  676. signal mask.
  677. NewMask - Supplies a pointer to the mask of signals that are affected by
  678. this operation.
  679. Return Value:
  680. Returns the original signal mask before this function was called.
  681. --*/
  682. OS_API
  683. KSTATUS
  684. OsWaitForChildProcess (
  685. ULONG Flags,
  686. PPROCESS_ID ChildPid,
  687. PULONG Reason,
  688. PUINTN ChildExitValue,
  689. PRESOURCE_USAGE ChildResourceUsage
  690. );
  691. /*++
  692. Routine Description:
  693. This routine is called to suspend execution of the current thread until
  694. a child process completes.
  695. Arguments:
  696. Flags - Supplies a bitfield of flags governing the behavior of the wait.
  697. See SYSTEM_CALL_WAIT_FLAG_* definitions.
  698. ChildPid - Supplies a pointer that on input supplies the child process ID
  699. parameter. This parameter can be one of the following:
  700. If -1 is supplied, any child signal will be pulled off and returned.
  701. If a number greater than 0 is supplied, only the specific process ID
  702. will be pulled off and returned.
  703. If 0 is supplied, any child process whose process group ID is equal to
  704. that of the calling process will be pulled.
  705. If a number less than zero (but not -1) is supplied, then any process
  706. whose process group ID is equal to the absolute value of this parameter
  707. will be dequeued and returned.
  708. On output, this parameter will contain the process ID of the child that
  709. generated the signal activity, and the child signal will be discarded.
  710. If the wait for child parameter is set to FALSE, then this parameter
  711. is ignored. If a non-child signal cause the routine to return, then
  712. the value at this parameter is undefined.
  713. Reason - Supplies a pointer where the reason for the child event will be
  714. returned. See CHILD_SIGNAL_REASON_* definitions.
  715. ChildExitValue - Supplies a pointer where the child exit value (or signal
  716. that caused the event) will be returned.
  717. ChildResourceUsage - Supplies an optional pointer where the resource usage
  718. of the child will be returned on success.
  719. Return Value:
  720. STATUS_SUCCESS if the wait was successfully satisfied. If the
  721. SYSTEM_CALL_WAIT_FLAG_RETURN_IMMEDIATELY flag is set and there are no
  722. children ready to be reaped, then STATUS_SUCCESS is returned and the child
  723. PID is returned as -1.
  724. STATUS_INTERRUPTED if the wait was interrupted by a signal.
  725. STATUS_NO_ELIGIBLE_CHILDREN if no eligible children could be reaped.
  726. --*/
  727. OS_API
  728. KSTATUS
  729. OsSuspendExecution (
  730. SIGNAL_MASK_OPERATION SignalOperation,
  731. PSIGNAL_SET SignalSet,
  732. PSIGNAL_PARAMETERS SignalParameters,
  733. ULONG TimeoutInMilliseconds
  734. );
  735. /*++
  736. Routine Description:
  737. This routine suspends execution of the current thread until a signal comes
  738. in. The current thread's blocked signal mask can be changed for the
  739. duration of the call by providing an operation and a signal set.
  740. Arguments:
  741. SignalOperation - Supplies the operation to perform with the signal set for
  742. the duration of the call: set, clear, overwrite or none.
  743. SignalSet - Supplies a pointer to the signal set to apply for the duration
  744. of this system call as dictated by the signal operation.
  745. SignalParameters - Supplies an optional pointer where the signal
  746. information for the signal that occurred will be returned.
  747. TimeoutInMilliseconds - Supplies the timeout of the operation in
  748. milliseconds.
  749. Return Value:
  750. STATUS_SUCCESS if a signal arrived.
  751. STATUS_INTERRUPTED on a clear signal operation if a signal that is not in
  752. the given set arrived.
  753. STATUS_TIMEOUT if no signal arrived before the given timeout expires.
  754. STATUS_INVALID_PARAMETER if no signal set is supplied for an operation
  755. other than SignalMaskOperationNone.
  756. --*/
  757. OS_API
  758. NO_RETURN
  759. VOID
  760. OsExitProcess (
  761. UINTN Status
  762. );
  763. /*++
  764. Routine Description:
  765. This routine terminates the current process and any threads that may be
  766. running in it.
  767. Arguments:
  768. Status - Supplies the exit status, returned to the parent in the wait
  769. calls. Conventionally 0 indicates success, and non-zero indicates
  770. failure. The C library only recieves the first eight bits of the return
  771. status, portable applications should not set bits beyond that.
  772. Return Value:
  773. This routine does not return.
  774. --*/
  775. OS_API
  776. KSTATUS
  777. OsFileControl (
  778. HANDLE Handle,
  779. FILE_CONTROL_COMMAND Command,
  780. PFILE_CONTROL_PARAMETERS_UNION Parameters
  781. );
  782. /*++
  783. Routine Description:
  784. This routine performs a file control operation on the given handle.
  785. Arguments:
  786. Handle - Supplies the file handle to operate on.
  787. Command - Supplies the command to perform.
  788. Parameters - Supplies an optional pointer to any additional parameters
  789. needed by the command.
  790. Return Value:
  791. Status code.
  792. --*/
  793. OS_API
  794. KSTATUS
  795. OsGetFileInformation (
  796. HANDLE Directory,
  797. PSTR Path,
  798. ULONG PathLength,
  799. BOOL FollowLink,
  800. PFILE_PROPERTIES Properties
  801. );
  802. /*++
  803. Routine Description:
  804. This routine gets the file properties for a given file.
  805. Arguments:
  806. Directory - Supplies an optional handle to a directory to start the
  807. search from if the supplied path is relative. Supply INVALID_HANDLE
  808. here to to use the current directory for relative paths.
  809. Path - Supplies a pointer to the string containing the file path to get
  810. properties for.
  811. PathLength - Supplies the length of the path string in bytes including the
  812. null terminator.
  813. FollowLink - Supplies a boolean indicating what to do if the file path
  814. points to a symbolic link. If set to TRUE, the file information set or
  815. returned will be for the file the link points to. If FALSE, the call
  816. will set or get information for the link itself.
  817. Properties - Supplies a pointer where the file properties will be returned
  818. on success.
  819. Return Value:
  820. Status code.
  821. --*/
  822. OS_API
  823. KSTATUS
  824. OsSetFileInformation (
  825. HANDLE Directory,
  826. PSTR Path,
  827. ULONG PathLength,
  828. BOOL FollowLink,
  829. PSET_FILE_INFORMATION Request
  830. );
  831. /*++
  832. Routine Description:
  833. This routine sets the file properties for a given file.
  834. Arguments:
  835. Directory - Supplies an optional handle to a directory to start the
  836. search from if the supplied path is relative. Supply INVALID_HANDLE
  837. here to to use the current directory for relative paths.
  838. Path - Supplies a pointer to the string containing the file path to set
  839. properties for.
  840. PathLength - Supplies the length of the path string in bytes including the
  841. null terminator.
  842. FollowLink - Supplies a boolean indicating what to do if the file path
  843. points to a symbolic link. If set to TRUE, the file information set or
  844. returned will be for the file the link points to. If FALSE, the call
  845. will set or get information for the link itself.
  846. Request - Supplies a pointer to the set file information request.
  847. Return Value:
  848. Status code.
  849. --*/
  850. OS_API
  851. VOID
  852. OsDebugPrint (
  853. PSTR String,
  854. ULONG StringSize
  855. );
  856. /*++
  857. Routine Description:
  858. This routine prints a message to the debug console. No formatting is
  859. provided.
  860. Arguments:
  861. String - Supplies a pointer to the string to print.
  862. StringSize - Supplies the size of the string in bytes including the null
  863. terminator.
  864. Return Value:
  865. None.
  866. --*/
  867. OS_API
  868. KSTATUS
  869. OsDebug (
  870. DEBUG_COMMAND_TYPE Command,
  871. PROCESS_ID Process,
  872. PVOID Address,
  873. PVOID Data,
  874. ULONG Size,
  875. ULONG SignalToDeliver
  876. );
  877. /*++
  878. Routine Description:
  879. This routine sends a debug command to a process.
  880. Arguments:
  881. Command - Supplies the command to send.
  882. Process - Supplies the process ID to send the command to.
  883. Address - Supplies the address parameter of the command, usually the
  884. address in the target to read from or write to.
  885. Data - Supplies the data parameter, usually the buffer containing the data
  886. to write or the buffer where the read data will be returned.
  887. Size - Supplies the size of the buffer, in bytes.
  888. SignalToDeliver - Supplies the signal number to deliver to the debugged
  889. process for step and continue commands. For other commands, this
  890. parameter is ignored.
  891. Return Value:
  892. Status code.
  893. --*/
  894. OS_API
  895. KSTATUS
  896. OsSeek (
  897. HANDLE Handle,
  898. SEEK_COMMAND SeekCommand,
  899. IO_OFFSET Offset,
  900. PIO_OFFSET NewOffset
  901. );
  902. /*++
  903. Routine Description:
  904. This routine seeks to the given position in a file. This routine is only
  905. relevant for normal file or block based devices.
  906. Arguments:
  907. Handle - Supplies the open file handle.
  908. SeekCommand - Supplies the reference point for the seek offset. Usual
  909. reference points are the beginning of the file, current file position,
  910. and the end of the file.
  911. Offset - Supplies the offset from the reference point to move in bytes.
  912. NewOffset - Supplies an optional pointer where the file position after the
  913. move will be returned on success.
  914. Return Value:
  915. Status code.
  916. --*/
  917. OS_API
  918. KSTATUS
  919. OsCreateSymbolicLink (
  920. HANDLE Directory,
  921. PSTR Path,
  922. ULONG PathSize,
  923. PSTR LinkDestinationBuffer,
  924. ULONG LinkDestinationBufferSize
  925. );
  926. /*++
  927. Routine Description:
  928. This routine creates a symbolic link.
  929. Arguments:
  930. Directory - Supplies an optional handle to a directory to start the
  931. search from if the supplied path is relative. Supply INVALID_HANDLE
  932. here to to use the current directory for relative paths.
  933. Path - Supplies a pointer to the symbolic link path.
  934. PathSize - Supplies the size of the symbolic link pointer in bytes
  935. including the null terminator.
  936. LinkDestinationBuffer - Supplies a pointer to a string containing the link's
  937. target path, the location the link points to.
  938. LinkDestinationBufferSize - Supplies the size of the link destination
  939. buffer in bytes, NOT including the null terminator.
  940. Return Value:
  941. Status code.
  942. --*/
  943. OS_API
  944. KSTATUS
  945. OsReadSymbolicLink (
  946. HANDLE Directory,
  947. PSTR Path,
  948. ULONG PathSize,
  949. PSTR LinkDestinationBuffer,
  950. ULONG LinkDestinationBufferSize,
  951. PULONG LinkDestinationSize
  952. );
  953. /*++
  954. Routine Description:
  955. This routine reads the destination path of a symbolic link.
  956. Arguments:
  957. Directory - Supplies an optional handle to a directory to start the
  958. search from if the supplied path is relative. Supply INVALID_HANDLE
  959. here to to use the current directory for relative paths.
  960. Path - Supplies a pointer to the symbolic link path.
  961. PathSize - Supplies the size of the symbolic link pointer in bytes
  962. including the null terminator.
  963. LinkDestinationBuffer - Supplies a pointer to a buffer where the
  964. destination of the link will be returned.
  965. LinkDestinationBufferSize - Supplies the size of the link destination
  966. buffer in bytes.
  967. LinkDestinationSize - Supplies a pointer where the actual size of the
  968. link destination (including the null terminator) will be returned on
  969. either success or a STATUS_BUFFER_TOO_SMALL case. On failure, 0 will be
  970. returned here.
  971. Return Value:
  972. STATUS_SUCCESS on success.
  973. STATUS_BUFFER_TOO_SMALL if the link destination buffer was not large
  974. enough to store the link destination.
  975. Other errors on other failures.
  976. --*/
  977. OS_API
  978. KSTATUS
  979. OsCreateHardLink (
  980. HANDLE ExistingFileDirectory,
  981. PSTR ExistingFile,
  982. ULONG ExistingFileSize,
  983. HANDLE LinkDirectory,
  984. PSTR LinkPath,
  985. ULONG LinkPathSize,
  986. BOOL FollowExistingFileLinks
  987. );
  988. /*++
  989. Routine Description:
  990. This routine creates a hard link.
  991. Arguments:
  992. ExistingFileDirectory - Supplies an optional handle to the directory to
  993. start path traversal from if the specified existing file path is
  994. relative. Supply INVALID_HANDLE here to use the current directory for
  995. relative paths.
  996. ExistingFile - Supplies a pointer to the path of the existing file to
  997. create the link from.
  998. ExistingFileSize - Supplies the size of the existing file path buffer in
  999. bytes, including the null terminator.
  1000. LinkDirectory - Supplies an optional handle to the directory to start path
  1001. traversal from if the specified new link path is relative. Supply
  1002. INVALID_HANDLE here to use the current directory for relative paths.
  1003. LinkPath - Supplies a pointer to a string containing the destination path
  1004. of the new link.
  1005. LinkPathSize - Supplies the size of the link path buffer in bytes.
  1006. FollowExistingFileLinks - Supplies a boolean indicating that if the
  1007. existing file path exists and is a symbolic link, the new link shall be
  1008. for the target of that link (TRUE) rather than the link itself (FALSE).
  1009. Return Value:
  1010. Status code.
  1011. --*/
  1012. OS_API
  1013. KSTATUS
  1014. OsDelete (
  1015. HANDLE Directory,
  1016. PSTR Path,
  1017. ULONG PathSize,
  1018. ULONG Flags
  1019. );
  1020. /*++
  1021. Routine Description:
  1022. This routine attempts to delete the object at the given path. If the path
  1023. points to a directory, the directory must be empty. If the path points to
  1024. a file, the hard link count on the file is decremented. If the hard link
  1025. count reaches zero and no processes have the file open, the contents of the
  1026. file are destroyed. If processes have open handles to the file, the
  1027. destruction of the file contents are deferred until the last handle to the
  1028. old file is closed. If the path points to a symbolic link, the link itself
  1029. is removed and not the destination. The removal of the entry from the
  1030. directory is immediate.
  1031. Arguments:
  1032. Directory - Supplies an optional handle to a directory to start the
  1033. search from if the supplied path is relative. Supply INVALID_HANDLE
  1034. here to to use the current directory for relative paths.
  1035. Path - Supplies a pointer to the path to delete.
  1036. PathSize - Supplies the length of the path buffer in bytes, including the
  1037. null terminator.
  1038. Flags - Supplies flags associated with the delete operation. See
  1039. SYS_DELETE_FLAG_* definitions.
  1040. Return Value:
  1041. Status code.
  1042. --*/
  1043. OS_API
  1044. KSTATUS
  1045. OsRename (
  1046. HANDLE SourceDirectory,
  1047. PSTR SourcePath,
  1048. ULONG SourcePathSize,
  1049. HANDLE DestinationDirectory,
  1050. PSTR DestinationPath,
  1051. ULONG DestinationPathSize
  1052. );
  1053. /*++
  1054. Routine Description:
  1055. This routine attempts to rename the object at the given path. This routine
  1056. operates on symbolic links themselves, not the destinations of symbolic
  1057. links. If the source and destination paths are equal, this routine will do
  1058. nothing and return successfully. If the source path is not a directory, the
  1059. destination path must not be a directory. If the destination file exists,
  1060. it will be deleted. The caller must have write access in both the old and
  1061. new directories. If the source path is a directory, the destination path
  1062. must not exist or be an empty directory. The destination path must not have
  1063. a path prefix of the source (ie it's illegal to move /my/path into
  1064. /my/path/stuff).
  1065. Arguments:
  1066. SourceDirectory - Supplies an optional handle to the directory to start
  1067. source path searches from. If the source path is absolute, this value
  1068. is ignored. If this is INVALID_HANDLE, then source path searches will
  1069. start from the current working directory.
  1070. SourcePath - Supplies a pointer to the path of the file to rename.
  1071. SourcePathSize - Supplies the length of the source path buffer in bytes,
  1072. including the null terminator.
  1073. DestinationDirectory - Supplies an optional handle to the directory to
  1074. start destination path searches from. If the destination path is
  1075. absolute, this value is ignored. If this is INVALID_HANDLE, then
  1076. destination path searches will start from the current working directory.
  1077. DestinationPath - Supplies a pointer to the path to rename the file to.
  1078. DestinationPathSize - Supplies the size of the destination path buffer in
  1079. bytes, including the null terminator.
  1080. Return Value:
  1081. Status code.
  1082. --*/
  1083. OS_API
  1084. KSTATUS
  1085. OsUserControl (
  1086. HANDLE Handle,
  1087. ULONG RequestCode,
  1088. PVOID Context,
  1089. UINTN ContextSize
  1090. );
  1091. /*++
  1092. Routine Description:
  1093. This routine sends a user I/O request to the given file/device/etc.
  1094. Arguments:
  1095. Handle - Supplies the open file handle to send the request to.
  1096. RequestCode - Supplies the request to send. For device handles, this is the
  1097. minor code of the IRP.
  1098. Context - Supplies a pointer to the context buffer allocated by the
  1099. caller for the request.
  1100. ContextSize - Supplies the size of the supplied context buffer.
  1101. Return Value:
  1102. Status code.
  1103. --*/
  1104. OS_API
  1105. KSTATUS
  1106. OsMount (
  1107. PSTR MountPointPath,
  1108. ULONG MountPointPathSize,
  1109. PSTR TargetPath,
  1110. ULONG TargetPathSize,
  1111. ULONG Flags
  1112. );
  1113. /*++
  1114. Routine Description:
  1115. This routine attempts to mount the given target at the given mount point.
  1116. Arguments:
  1117. MountPointPath - Supplies a pointer to a string containing the path to the
  1118. mount point where the target is to be mounted.
  1119. MountPointPathSize - Supplies the size of the mount point path string in
  1120. bytes, including the null terminator.
  1121. TargetPath - Supplies a pointer to a string containing the path to the
  1122. target file, directory, volume, or device that is to be mounted.
  1123. TargetPathSize - Supplies the size of the target path string in bytes,
  1124. including the null terminator.
  1125. Flags - Supplies the flags associated with the mount operation. See
  1126. SYS_MOUNT_FLAG_* for definitions.
  1127. Return Value:
  1128. Status code.
  1129. --*/
  1130. OS_API
  1131. KSTATUS
  1132. OsUnmount (
  1133. PSTR MountPointPath,
  1134. ULONG MountPointPathSize,
  1135. ULONG Flags
  1136. );
  1137. /*++
  1138. Routine Description:
  1139. This routine attempts to unmount the given target. If the target is not a
  1140. mount point, or the user does not have access to the mount point, then the
  1141. routine will return the appropriate error. Otherwise, it will remove the
  1142. mount point based on the supplied flags.
  1143. Arguments:
  1144. MountPointPath - Supplies a pointer to a string containing the path to the
  1145. mount point that is to be unmounted.
  1146. MountPointPathSize - Supplies the size of the mount point path string in
  1147. bytes, including the null terminator.
  1148. Flags - Supplies the flags associated with the mount operation. See
  1149. SYS_MOUNT_FLAG_* for definitions.
  1150. Return Value:
  1151. Status code.
  1152. --*/
  1153. OS_API
  1154. KSTATUS
  1155. OsGetMountPoints (
  1156. PVOID *Buffer,
  1157. PUINTN BufferSize
  1158. );
  1159. /*++
  1160. Routine Description:
  1161. This routine returns the list of mount points currently in the system. It
  1162. only returns the mounts that are visible to the calling process. The caller
  1163. is responsible for releasing the buffer.
  1164. Arguments:
  1165. Buffer - Supplies a pointer that receives a buffer of mount point data.
  1166. BufferSize - Supplies a pointer that receives the size of the mount point
  1167. data.
  1168. Return Value:
  1169. Status code.
  1170. --*/
  1171. OS_API
  1172. KSTATUS
  1173. OsGetEffectiveAccess (
  1174. HANDLE Directory,
  1175. PSTR Path,
  1176. ULONG PathSize,
  1177. ULONG DesiredFlags,
  1178. BOOL UseRealIds,
  1179. PULONG EffectiveAccess
  1180. );
  1181. /*++
  1182. Routine Description:
  1183. This routine determines the effective access for the given path.
  1184. Arguments:
  1185. Directory - Supplies an optional handle to a directory to start the
  1186. search from if the supplied path is relative. Supply INVALID_HANDLE
  1187. here to to use the current directory for relative paths.
  1188. Path - Supplies a pointer to a string containing the path to the object
  1189. to query access of.
  1190. PathSize - Supplies the size of the supplied path buffer in bytes including
  1191. the null terminator.
  1192. DesiredFlags - Supplies the bitfield of flags the user is interested in.
  1193. See EFFECTIVE_ACCESS_* definitions.
  1194. UseRealIds - Supplies a boolean indicating whether the access check should
  1195. use the real user and group IDs (TRUE) or the effective user and group
  1196. IDs (FALSE).
  1197. EffectiveAccess - Supplies a pointer where the effective access permission
  1198. bits are returned. Only bits set in the desired flags parameter will be
  1199. potentially set. All other bits will be set to 0. See
  1200. EFFECTIVE_ACCESS_* definitions.
  1201. Return Value:
  1202. Status code indicating if the request completed successfully.
  1203. --*/
  1204. OS_API
  1205. KSTATUS
  1206. OsLoadDriver (
  1207. PSTR Path,
  1208. ULONG PathSize
  1209. );
  1210. /*++
  1211. Routine Description:
  1212. This routine loads the given driver into kernel address space.
  1213. Arguments:
  1214. Path - Supplies a pointer to a string containing the path to the driver.
  1215. PathSize - Supplies the size of the supplied path buffer in bytes including
  1216. the null terminator.
  1217. Return Value:
  1218. Status code indicating if the request completed successfully.
  1219. --*/
  1220. OS_API
  1221. KSTATUS
  1222. OsLocateDeviceInformation (
  1223. PUUID Uuid,
  1224. PDEVICE_ID DeviceId,
  1225. PDEVICE_INFORMATION_RESULT Results,
  1226. PULONG ResultCount
  1227. );
  1228. /*++
  1229. Routine Description:
  1230. This routine returns instances of devices enumerating information. Callers
  1231. can get all devices enumerating the given information type, or all
  1232. information types enumerated by a given device. This routine must be called
  1233. at low level.
  1234. Arguments:
  1235. Uuid - Supplies an optional pointer to the information identifier to
  1236. filter on. If NULL, any information type will match.
  1237. DeviceId - Supplies an optional pointer to the device ID to match against.
  1238. If NULL, then any device will match.
  1239. Results - Supplies a pointer to a caller allocated buffer where the
  1240. results will be returned.
  1241. ResultCount - Supplies a pointer that upon input contains the size of the
  1242. buffer in information result elements. On output, returns the number
  1243. of elements in the query, even if the provided buffer was too small.
  1244. Do note however that the number of results can change between two
  1245. successive searches.
  1246. Return Value:
  1247. STATUS_SUCCESS on success.
  1248. STATUS_BUFFER_TOO_SMALL if the provided buffer was not large enough to
  1249. contain all the results. The result count will contain the required number
  1250. of elements to contain the results.
  1251. --*/
  1252. OS_API
  1253. KSTATUS
  1254. OsGetSetDeviceInformation (
  1255. DEVICE_ID DeviceId,
  1256. PUUID Uuid,
  1257. PVOID Data,
  1258. PUINTN DataSize,
  1259. BOOL Set
  1260. );
  1261. /*++
  1262. Routine Description:
  1263. This routine gets or sets device information.
  1264. Arguments:
  1265. DeviceId - Supplies the device ID of the device to get or set information
  1266. for.
  1267. Uuid - Supplies a pointer to the identifier of the device information type
  1268. to get or set.
  1269. Data - Supplies a pointer to the data buffer that either contains the
  1270. information to set or will contain the information to get on success.
  1271. DataSize - Supplies a pointer that on input contains the size of the
  1272. data buffer. On output contains the actual size of the data.
  1273. Set - Supplies a boolean indicating whether to get information (FALSE) or
  1274. set information (TRUE).
  1275. Return Value:
  1276. Status code.
  1277. --*/
  1278. OS_API
  1279. KSTATUS
  1280. OsGetSetSystemInformation (
  1281. SYSTEM_INFORMATION_SUBSYSTEM Subsystem,
  1282. UINTN InformationType,
  1283. PVOID Data,
  1284. PUINTN DataSize,
  1285. BOOL Set
  1286. );
  1287. /*++
  1288. Routine Description:
  1289. This routine gets or sets system information.
  1290. Arguments:
  1291. Subsystem - Supplies the subsystem to query or set information of.
  1292. InformationType - Supplies the information type, which is specific to
  1293. the subsystem. The type of this value is generally
  1294. <subsystem>_INFORMATION_TYPE (eg IO_INFORMATION_TYPE).
  1295. Data - Supplies a pointer to the data buffer where the data is either
  1296. returned for a get operation or given for a set operation.
  1297. DataSize - Supplies a pointer that on input contains the size of the
  1298. data buffer. On output, contains the required size of the data buffer.
  1299. Set - Supplies a boolean indicating if this is a get operation (FALSE) or
  1300. a set operation (TRUE).
  1301. Return Value:
  1302. STATUS_SUCCESS if the information was successfully queried or set.
  1303. STATUS_BUFFER_TOO_SMALL if the buffer size specified was too small. The
  1304. required buffer size will be returned in the data size parameter.
  1305. STATUS_DATA_LENGTH_MISMATCH if the buffer size was not correct. The
  1306. correct buffer size will be returned in the data size parameter.
  1307. STATUS_INVALID_PARAMETER if the given subsystem or information type is
  1308. not known.
  1309. Other status codes on other failures.
  1310. --*/
  1311. OS_API
  1312. KSTATUS
  1313. OsResetSystem (
  1314. SYSTEM_RESET_TYPE ResetType
  1315. );
  1316. /*++
  1317. Routine Description:
  1318. This routine attempts to reboot the system.
  1319. Arguments:
  1320. ResetType - Supplies the desired system reset type. If the given type is
  1321. not supported and a cold reset is, then a cold reset will be
  1322. performed.
  1323. Return Value:
  1324. STATUS_SUCCESS if the reset request was successfully queued. The process
  1325. should expect to receive a termination signal shortly, followed by a
  1326. kill signal shortly after that.
  1327. STATUS_INVALID_PARAMETER if the given reset type is not valid.
  1328. STATUS_INSUFFICIENT_RESOURCES if an allocation failure in the kernel
  1329. prevented queuing of the reset system work item.
  1330. --*/
  1331. OS_API
  1332. PVOID
  1333. OsSetProgramBreak (
  1334. PVOID NewBreak
  1335. );
  1336. /*++
  1337. Routine Description:
  1338. This routine gets or sets the application program break for the process.
  1339. Arguments:
  1340. NewBreak - Supplies an optional pointer to the new break to set. If this
  1341. is less than the original break, then no change is made. Set to NULL
  1342. to simply get the current program break.
  1343. Return Value:
  1344. Returns the current program break, which is either the new value set or
  1345. the previous value.
  1346. --*/
  1347. OS_API
  1348. KSTATUS
  1349. OsMemoryMap (
  1350. HANDLE Handle,
  1351. IO_OFFSET Offset,
  1352. UINTN Size,
  1353. ULONG Flags,
  1354. PVOID *Address
  1355. );
  1356. /*++
  1357. Routine Description:
  1358. This routine maps the specified object starting at the given offset for the
  1359. requested size, in bytes. A suggested address can optionally be supplied.
  1360. Arguments:
  1361. Handle - Supplies a pointer to an opened I/O handle.
  1362. Offset - Supplies the offset into the I/O object where the mapping should
  1363. begin.
  1364. Size - Supplies the size of the mapping region, in bytes.
  1365. Flags - Supplies a bitfield of flags. See SYS_MAP_FLAG_* for definitions.
  1366. Address - Supplies a pointer that receives the address of the mapped
  1367. region. The caller can optionally specify a suggested address using
  1368. this paramter.
  1369. Return Value:
  1370. Status code.
  1371. --*/
  1372. OS_API
  1373. KSTATUS
  1374. OsMemoryUnmap (
  1375. PVOID Address,
  1376. UINTN Size
  1377. );
  1378. /*++
  1379. Routine Description:
  1380. This routine unmaps the specified region from the current process' address
  1381. space.
  1382. Arguments:
  1383. Address - Supplies the starting address of the memory region to unmap.
  1384. Size - Supplies the size of the region to unmap, in bytes.
  1385. Return Value:
  1386. Status code.
  1387. --*/
  1388. OS_API
  1389. KSTATUS
  1390. OsSetMemoryProtection (
  1391. PVOID Address,
  1392. UINTN Size,
  1393. ULONG NewAttributes
  1394. );
  1395. /*++
  1396. Routine Description:
  1397. This routine set the memory protection attributes for the given region.
  1398. Arguments:
  1399. Address - Supplies the starting address (inclusive) to change the memory
  1400. protection for. This must be aligned to a page boundary.
  1401. Size - Supplies the length, in bytes, of the region to change attributes
  1402. for.
  1403. NewAttributes - Supplies the new attributes to set. See SYS_MAP_FLAG_*
  1404. definitions.
  1405. Return Value:
  1406. Status code.
  1407. --*/
  1408. OS_API
  1409. KSTATUS
  1410. OsMemoryFlush (
  1411. PVOID Address,
  1412. ULONGLONG Size,
  1413. ULONG Flags
  1414. );
  1415. /*++
  1416. Routine Description:
  1417. This routine flushes a region of the current process' mapped memory to
  1418. permament storage, if the region has a backing image.
  1419. Arguments:
  1420. Address - Supplies the starting address of the memory region to synchronize.
  1421. Size - Supplies the size of the region to synchronize, in bytes.
  1422. Flags - Supplies a bitfield of flags. See SYS_MAP_SYNC_FLAG_* for
  1423. definitions.
  1424. Return Value:
  1425. Status code.
  1426. --*/
  1427. OS_API
  1428. KSTATUS
  1429. OsSetThreadIdentity (
  1430. ULONG FieldsToSet,
  1431. PTHREAD_IDENTITY Identity
  1432. );
  1433. /*++
  1434. Routine Description:
  1435. This routine gets or sets a thread's identity.
  1436. Arguments:
  1437. FieldsToSet - Supplies a bitfield indicating which identity fields to set.
  1438. Supply zero to simply get the current thread identity. See
  1439. THREAD_IDENTITY_FIELD_* definitions.
  1440. Identity - Supplies a pointer that on input contains the thread identity
  1441. fields to set. On successful output, will contain the complete new
  1442. thread identity.
  1443. Return Value:
  1444. Status code.
  1445. --*/
  1446. OS_API
  1447. KSTATUS
  1448. OsSetThreadPermissions (
  1449. ULONG FieldsToSet,
  1450. PTHREAD_PERMISSIONS Permissions
  1451. );
  1452. /*++
  1453. Routine Description:
  1454. This routine gets or sets a thread's permission masks.
  1455. Arguments:
  1456. FieldsToSet - Supplies a bitfield indicating which permission sets or
  1457. fields to modify. Supply zero to simply get the current thread
  1458. permission sets. See THREAD_PERMISSION_FIELD_* definitions.
  1459. Permissions - Supplies a pointer that on input contains the thread
  1460. permission masks to set. On successful output, will contain the
  1461. complete new set of permission masks.
  1462. Return Value:
  1463. Status code.
  1464. --*/
  1465. OS_API
  1466. KSTATUS
  1467. OsSetSupplementaryGroups (
  1468. BOOL Set,
  1469. PGROUP_ID Groups,
  1470. PUINTN Count
  1471. );
  1472. /*++
  1473. Routine Description:
  1474. This routine gets or sets a thread's set of supplementary groups. To set
  1475. the supplementary groups, the thread must have the set group ID permission.
  1476. Arguments:
  1477. Set - Supplies a boolean indicating whether to set the new groups (TRUE) or
  1478. just get the current list of supplementary groups.
  1479. Groups - Supplies a pointer that recieves the supplementary groups for a
  1480. get operation or contains the new group IDs to set for a set operation.
  1481. Count - Supplies a pointer that on input contains the number of elements
  1482. in the given buffer. On output, contains the number of valid elements.
  1483. If STATUS_BUFFER_TOO_SMALL is returned, the number of elements needed
  1484. will be retunred.
  1485. Return Value:
  1486. STATUS_SUCCESS on success.
  1487. STATUS_ACCESS_VIOLATION if the given groups buffer is invalid.
  1488. STATUS_PERMISSION_DENIED if the caller does not have the set group ID
  1489. permission.
  1490. STATUS_INSUFFICIENT_RESOURCES if an internal kernel allocation failed.
  1491. STATUS_INVALID_PARAMETER if the count was too big.
  1492. STATUS_BUFFER_TOO_SMALL if the given buffer was not big enough to contain
  1493. all the current supplementary groups. In this case, count contains the
  1494. number of elements needed.
  1495. --*/
  1496. OS_API
  1497. KSTATUS
  1498. OsSetResourceLimit (
  1499. RESOURCE_LIMIT_TYPE Type,
  1500. PRESOURCE_LIMIT NewValue,
  1501. PRESOURCE_LIMIT OldValue
  1502. );
  1503. /*++
  1504. Routine Description:
  1505. This routine gets or sets the current resource limit value for a given type.
  1506. Arguments:
  1507. Type - Supplies the resource limit type to get the limit for.
  1508. NewValue - Supplies an optional pointer to the new limit to set. If this is
  1509. NULL, then a new value is not set.
  1510. OldValue - Supplies an optional pointer where the previous limit will be
  1511. returned.
  1512. Return Value:
  1513. STATUS_SUCCESS on success.
  1514. STATUS_INVALID_PARAMETER if the resource type is not valid or the current
  1515. value was greater than the max.
  1516. STATUS_PERMISSION_DENIED if the caller is trying to raise the max/hard
  1517. limit and does not have the resources permission.
  1518. --*/
  1519. OS_API
  1520. KSTATUS
  1521. OsCreateTerminal (
  1522. HANDLE MasterDirectory,
  1523. HANDLE SlaveDirectory,
  1524. PSTR MasterPath,
  1525. UINTN MasterPathLength,
  1526. PSTR SlavePath,
  1527. UINTN SlavePathLength,
  1528. ULONG MasterOpenFlags,
  1529. FILE_PERMISSIONS MasterCreatePermissions,
  1530. FILE_PERMISSIONS SlaveCreatePermissions,
  1531. PHANDLE MasterHandle
  1532. );
  1533. /*++
  1534. Routine Description:
  1535. This routine creates a new pseudo-terminal master and slave at the given
  1536. paths.
  1537. Arguments:
  1538. MasterDirectory - Supplies an optional handle to a directory for relative
  1539. paths when creating the master. Supply INVALID_HANDLE to use the
  1540. current working directory.
  1541. SlaveDirectory - Supplies an optional handle to a directory for relative
  1542. paths when creating the slave. Supply INVALID_HANDLE to use the
  1543. current working directory.
  1544. MasterPath - Supplies an optional pointer to the path to create for the
  1545. master.
  1546. MasterPathLength - Supplies the length of the master side path buffer in
  1547. bytes, including the null terminator.
  1548. SlavePath - Supplies an optional pointer to the path to create for the
  1549. master.
  1550. SlavePathLength - Supplies the length of the slave side path buffer in
  1551. bytes, including the null terminator.
  1552. MasterOpenFlags - Supplies the open flags to use when opening the master.
  1553. Only read, write, and "no controlling terminal" flags are honored.
  1554. MasterCreatePermissions - Supplies the permissions to apply to the created
  1555. master side.
  1556. SlaveCreatePermissions - Supplies the permission to apply to the created
  1557. slave side.
  1558. MasterHandle - Supplies a pointer where the opened handle to the master
  1559. will be returned on success.
  1560. Return Value:
  1561. Status code.
  1562. --*/
  1563. OS_API
  1564. KSTATUS
  1565. OsGetFilePath (
  1566. HANDLE Handle,
  1567. PSTR Path,
  1568. PUINTN PathSize
  1569. );
  1570. /*++
  1571. Routine Description:
  1572. This routine returns the file path for the given handle, if possible.
  1573. Arguments:
  1574. Handle - Supplies the open handle to get the file path of.
  1575. Path - Supplies a pointer where the path will be returned on success.
  1576. PathSize - Supplies a pointer that on input contains the size of the path
  1577. buffer. On output, returns the needed size of the path buffer, even
  1578. if the supplied buffer is too small.
  1579. Return Value:
  1580. STATUS_SUCCESS on success.
  1581. STATUS_INVALID_HANDLE if the given handle is not valid.
  1582. STATUS_PATH_NOT_FOUND if no path exists for the given handle.
  1583. STATUS_BUFFER_TOO_SMALL if the supplied path buffer was not large enough to
  1584. contain the complete path. In this case the path size returned is the size
  1585. needed.
  1586. STATUS_ACCESS_VIOLATION if the path buffer was invalid.
  1587. --*/
  1588. OS_API
  1589. VOID
  1590. OsSetThreadIdPointer (
  1591. PTHREAD_ID Pointer
  1592. );
  1593. /*++
  1594. Routine Description:
  1595. This routine sets the thread ID pointer in the kernel. If this value is
  1596. non-null when the thread exits, then zero will be written to this address,
  1597. and a UserLockWake operation will be performed to wake up one thread.
  1598. Arguments:
  1599. Pointer - Supplies the new user mode pointer to the thread ID that will be
  1600. cleared when the thread exits. Supply NULL to clear the thread ID
  1601. pointer in the kernel.
  1602. Return Value:
  1603. None.
  1604. --*/
  1605. OS_API
  1606. FILE_PERMISSIONS
  1607. OsSetUmask (
  1608. FILE_PERMISSIONS NewMask
  1609. );
  1610. /*++
  1611. Routine Description:
  1612. This routine sets file permission mask for the current process. Bits set
  1613. in this mask will be automatically cleared out of the permissions of any
  1614. file or directory created.
  1615. Arguments:
  1616. NewMask - Supplies the new mask to set.
  1617. Return Value:
  1618. Returns the previously set mask.
  1619. --*/
  1620. OS_API
  1621. KSTATUS
  1622. OsDuplicateHandle (
  1623. HANDLE ExistingHandle,
  1624. PHANDLE NewHandle,
  1625. ULONG Flags
  1626. );
  1627. /*++
  1628. Routine Description:
  1629. This routine duplicates a given handle at a new handle.
  1630. Arguments:
  1631. ExistingHandle - Supplies the handle to duplicate.
  1632. NewHandle - Supplies a pointer that contains the destination handle value
  1633. for the new handle. If this is INVALID_HANDLE, then the duplicated
  1634. handle will be the lowest available handle value, and will be returned
  1635. here. If this is not INVALID_HANDLE, then the previous handle at that
  1636. location will be closed. If the new handle equals the existing handle,
  1637. failure is returned.
  1638. Flags - Supplies open flags to be set on the new handle. Only
  1639. SYS_OPEN_FLAG_CLOSE_ON_EXECUTE is permitted. If not set, the new handle
  1640. will have the close on execute flag cleared.
  1641. Return Value:
  1642. Status code.
  1643. --*/
  1644. OS_API
  1645. PVOID
  1646. OsHeapAllocate (
  1647. UINTN Size,
  1648. UINTN Tag
  1649. );
  1650. /*++
  1651. Routine Description:
  1652. This routine allocates memory from the heap.
  1653. Arguments:
  1654. Size - Supplies the size of the allocation request, in bytes.
  1655. Tag - Supplies an identifier to associate with the allocation, which aides
  1656. in debugging.
  1657. Return Value:
  1658. Returns a pointer to the allocation if successful, or NULL if the
  1659. allocation failed.
  1660. --*/
  1661. OS_API
  1662. VOID
  1663. OsHeapFree (
  1664. PVOID Memory
  1665. );
  1666. /*++
  1667. Routine Description:
  1668. This routine frees memory, making it available for other users of the heap.
  1669. Arguments:
  1670. Memory - Supplies the allocation returned by the allocation routine.
  1671. Return Value:
  1672. None.
  1673. --*/
  1674. OS_API
  1675. PVOID
  1676. OsHeapReallocate (
  1677. PVOID Memory,
  1678. UINTN NewSize,
  1679. UINTN Tag
  1680. );
  1681. /*++
  1682. Routine Description:
  1683. This routine resizes the given allocation, potentially creating a new
  1684. buffer and copying the old contents in.
  1685. Arguments:
  1686. Memory - Supplies the original active allocation. If this parameter is
  1687. NULL, this routine will simply allocate memory.
  1688. NewSize - Supplies the new required size of the allocation. If this is
  1689. 0, then the original allocation will simply be freed.
  1690. Tag - Supplies an identifier to associate with the allocation, which aides
  1691. in debugging.
  1692. Return Value:
  1693. Returns a pointer to a buffer with the new size (and original contents) on
  1694. success. This may be a new buffer or the same one.
  1695. NULL on failure or if the new size supplied was zero.
  1696. --*/
  1697. OS_API
  1698. KSTATUS
  1699. OsHeapAlignedAllocate (
  1700. PVOID *Memory,
  1701. UINTN Alignment,
  1702. UINTN Size,
  1703. UINTN Tag
  1704. );
  1705. /*++
  1706. Routine Description:
  1707. This routine allocates aligned memory from the heap.
  1708. Arguments:
  1709. Memory - Supplies a pointer that receives the pointer to the aligned
  1710. allocation on success.
  1711. Alignment - Supplies the requested alignment for the allocation, in bytes.
  1712. Size - Supplies the size of the allocation request, in bytes.
  1713. Tag - Supplies an identification tag to mark this allocation with.
  1714. Return Value:
  1715. Status code.
  1716. --*/
  1717. OS_API
  1718. VOID
  1719. OsValidateHeap (
  1720. VOID
  1721. );
  1722. /*++
  1723. Routine Description:
  1724. This routine validates the memory heap for consistency, ensuring that no
  1725. corruption or other errors are present in the heap.
  1726. Arguments:
  1727. None.
  1728. Return Value:
  1729. None.
  1730. --*/
  1731. OS_API
  1732. PPROCESS_ENVIRONMENT
  1733. OsCreateEnvironment (
  1734. PSTR ImagePath,
  1735. ULONG ImagePathLength,
  1736. PSTR *ArgumentValues,
  1737. ULONG ArgumentValuesTotalLength,
  1738. ULONG ArgumentCount,
  1739. PSTR *EnvironmentValues,
  1740. ULONG EnvironmentValuesTotalLength,
  1741. ULONG EnvironmentCount
  1742. );
  1743. /*++
  1744. Routine Description:
  1745. This routine creates an environment that can be passed to the kernel for
  1746. execution of an image. This routine will use the heap.
  1747. Arguments:
  1748. ImagePath - Supplies a pointer to the name of the image that will be
  1749. executed.
  1750. ImagePathLength - Supplies the length of the image path buffer in bytes,
  1751. including the null terminator.
  1752. ArgumentValues - Supplies an array of pointers to arguments to pass to the
  1753. image.
  1754. ArgumentValuesTotalLength - Supplies the total length of all arguments, in
  1755. bytes, including their null terminators.
  1756. ArgumentCount - Supplies the number of arguments in the argument values
  1757. array.
  1758. EnvironmentValues - Supplies an array of pointers to environment variables
  1759. to set in the new environment. Environment variables take the form
  1760. "name=value".
  1761. EnvironmentValuesTotalLength - Supplies the total length of all environment
  1762. variables, in bytes, including their null terminators.
  1763. EnvironmentCount - Supplies the number of environment variable strings
  1764. present in the environment values array.
  1765. Return Value:
  1766. Returns a pointer to a heap allocated environment, suitable for sending to
  1767. the execute image system call.
  1768. NULL on failure.
  1769. --*/
  1770. OS_API
  1771. VOID
  1772. OsDestroyEnvironment (
  1773. PPROCESS_ENVIRONMENT Environment
  1774. );
  1775. /*++
  1776. Routine Description:
  1777. This routine destroys an environment created with the create environment
  1778. function.
  1779. Arguments:
  1780. Environment - Supplies a pointer to the environment to destroy.
  1781. Return Value:
  1782. None.
  1783. --*/
  1784. OS_API
  1785. PPROCESS_ENVIRONMENT
  1786. OsGetCurrentEnvironment (
  1787. VOID
  1788. );
  1789. /*++
  1790. Routine Description:
  1791. This routine gets the environment for the current process.
  1792. Arguments:
  1793. None.
  1794. Return Value:
  1795. Returns a pointer to the current environment. This is shared memory, and
  1796. should not be altered by the caller.
  1797. --*/
  1798. OS_API
  1799. KSTATUS
  1800. OsSocketCreatePair (
  1801. NET_DOMAIN_TYPE Domain,
  1802. NET_SOCKET_TYPE Type,
  1803. ULONG Protocol,
  1804. ULONG OpenFlags,
  1805. HANDLE Sockets[2]
  1806. );
  1807. /*++
  1808. Routine Description:
  1809. This routine creates a pair of sockets that are connected to each other.
  1810. Arguments:
  1811. Domain - Supplies the network domain to use on the socket.
  1812. Type - Supplies the socket connection type.
  1813. Protocol - Supplies the raw protocol value used on the network.
  1814. OpenFlags - Supplies an optional bitfield of open flags for the new socket.
  1815. Only SYS_OPEN_FLAG_NON_BLOCKING and SYS_OPEN_FLAG_CLOSE_ON_EXECUTE
  1816. are accepted.
  1817. Sockets - Supplies an array where the two handles to the connected
  1818. sockets will be returned on success.
  1819. Return Value:
  1820. Status code.
  1821. --*/
  1822. OS_API
  1823. KSTATUS
  1824. OsSocketCreate (
  1825. NET_DOMAIN_TYPE Domain,
  1826. NET_SOCKET_TYPE Type,
  1827. ULONG Protocol,
  1828. ULONG OpenFlags,
  1829. PHANDLE Socket
  1830. );
  1831. /*++
  1832. Routine Description:
  1833. This routine creates a new socket for communication.
  1834. Arguments:
  1835. Domain - Supplies the network addressing domain to use for the socket.
  1836. Type - Supplies the socket type.
  1837. Protocol - Supplies the raw protocol value to use for the socket. This is
  1838. network specific.
  1839. OpenFlags - Supplies an optional bitfield of open flags for the new socket.
  1840. Only SYS_OPEN_FLAG_NON_BLOCKING and SYS_OPEN_FLAG_CLOSE_ON_EXECUTE
  1841. are accepted.
  1842. Socket - Supplies a pointer where the new socket handle will be returned on
  1843. success.
  1844. Return Value:
  1845. Status code.
  1846. --*/
  1847. OS_API
  1848. KSTATUS
  1849. OsSocketBind (
  1850. HANDLE Socket,
  1851. PNETWORK_ADDRESS Address,
  1852. PSTR Path,
  1853. UINTN PathSize
  1854. );
  1855. /*++
  1856. Routine Description:
  1857. This routine binds a newly created socket to a local address.
  1858. Arguments:
  1859. Socket - Supplies a handle to the fresh socket.
  1860. Address - Supplies a pointer to the local network address to bind to.
  1861. Path - Supplies a pointer to the path to bind to in the case that this is
  1862. a local (Unix) socket.
  1863. PathSize - Supplies the size of the path in bytes including the null
  1864. terminator.
  1865. Return Value:
  1866. Status code.
  1867. --*/
  1868. OS_API
  1869. KSTATUS
  1870. OsSocketListen (
  1871. HANDLE Socket,
  1872. ULONG SuggestedBacklog
  1873. );
  1874. /*++
  1875. Routine Description:
  1876. This routine activates a socket, making it eligible to accept new
  1877. incoming connections.
  1878. Arguments:
  1879. Socket - Supplies the socket to activate.
  1880. SuggestedBacklog - Supplies a suggestion to the kernel as to the number of
  1881. un-accepted incoming connections to queue up before incoming
  1882. connections are refused.
  1883. Return Value:
  1884. Status code.
  1885. --*/
  1886. OS_API
  1887. KSTATUS
  1888. OsSocketAccept (
  1889. HANDLE Socket,
  1890. PHANDLE NewSocket,
  1891. PNETWORK_ADDRESS Address,
  1892. PSTR RemotePath,
  1893. PUINTN RemotePathSize,
  1894. ULONG OpenFlags
  1895. );
  1896. /*++
  1897. Routine Description:
  1898. This routine accepts an incoming connection on a listening socket and spins
  1899. it off into a new socket. This routine will block until an incoming
  1900. connection request is received.
  1901. Arguments:
  1902. Socket - Supplies the listening socket to accept a new connection from.
  1903. NewSocket - Supplies a pointer where a new socket representing the
  1904. incoming connection will be returned on success.
  1905. Address - Supplies an optional pointer where the address of the remote host
  1906. will be returned.
  1907. RemotePath - Supplies a pointer where the remote path of the client socket
  1908. will be copied on success. This only applies to local sockets.
  1909. RemotePathSize - Supplies a pointer that on input contains the size of the
  1910. remote path buffer. On output, contains the true size of the remote
  1911. path, even if it was bigger than the input.
  1912. OpenFlags - Supplies an optional bitfield of open flags for the new socket.
  1913. Only SYS_OPEN_FLAG_NON_BLOCKING and SYS_OPEN_FLAG_CLOSE_ON_EXECUTE
  1914. are accepted.
  1915. Return Value:
  1916. Status code.
  1917. --*/
  1918. OS_API
  1919. KSTATUS
  1920. OsSocketConnect (
  1921. HANDLE Socket,
  1922. PNETWORK_ADDRESS Address,
  1923. PSTR RemotePath,
  1924. UINTN RemotePathSize
  1925. );
  1926. /*++
  1927. Routine Description:
  1928. This routine attempts to establish a new outgoing connection on a socket.
  1929. Arguments:
  1930. Socket - Supplies a handle to the fresh socket to use to establish the
  1931. connection.
  1932. Address - Supplies a pointer to the destination socket address.
  1933. RemotePath - Supplies a pointer to the path to connect to, if this is a
  1934. local socket.
  1935. RemotePathSize - Supplies the size of the remote path buffer in bytes,
  1936. including the null terminator.
  1937. Return Value:
  1938. Status code.
  1939. --*/
  1940. OS_API
  1941. KSTATUS
  1942. OsSocketPerformIo (
  1943. HANDLE Socket,
  1944. PSOCKET_IO_PARAMETERS Parameters,
  1945. PVOID Buffer
  1946. );
  1947. /*++
  1948. Routine Description:
  1949. This routine performs I/O on an open handle.
  1950. Arguments:
  1951. Socket - Supplies a pointer to the socket.
  1952. Parameters - Supplies a pointer to the socket I/O request details.
  1953. Buffer - Supplies a pointer to the buffer containing the data to write or
  1954. where the read data should be returned, depending on the operation.
  1955. Return Value:
  1956. Status code.
  1957. --*/
  1958. OS_API
  1959. KSTATUS
  1960. OsSocketPerformVectoredIo (
  1961. HANDLE Socket,
  1962. PSOCKET_IO_PARAMETERS Parameters,
  1963. PIO_VECTOR VectorArray,
  1964. UINTN VectorCount
  1965. );
  1966. /*++
  1967. Routine Description:
  1968. This routine performs vectored I/O on an open handle.
  1969. Arguments:
  1970. Socket - Supplies a pointer to the socket.
  1971. Parameters - Supplies a pointer to the socket I/O request details.
  1972. VectorArray - Supplies an array of I/O vector structures to do I/O to/from.
  1973. VectorCount - Supplies the number of elements in the vector array.
  1974. Return Value:
  1975. Status code.
  1976. --*/
  1977. OS_API
  1978. KSTATUS
  1979. OsSocketGetSetInformation (
  1980. HANDLE Socket,
  1981. SOCKET_INFORMATION_TYPE InformationType,
  1982. UINTN Option,
  1983. PVOID Data,
  1984. PUINTN DataSize,
  1985. BOOL Set
  1986. );
  1987. /*++
  1988. Routine Description:
  1989. This routine gets or sets socket information.
  1990. Arguments:
  1991. Socket - Supplies the socket handle.
  1992. InformationType - Supplies the socket information type category to which
  1993. specified option belongs.
  1994. Option - Supplies the option to get or set, which is specific to the
  1995. information type. The type of this value is generally
  1996. SOCKET_<information_type>_OPTION.
  1997. Data - Supplies a pointer to the data buffer where the data is either
  1998. returned for a get operation or given for a set operation. If the
  1999. buffer is too small for a get request, the truncated data will be
  2000. returned and the routine will fail with STATUS_BUFFER_TOO_SMALL.
  2001. DataSize - Supplies a pointer that on input contains the size of the data
  2002. buffer. On output, this contains the required size of the data buffer.
  2003. Set - Supplies a boolean indicating if this is a get operation (FALSE) or
  2004. a set operation (TRUE).
  2005. Return Value:
  2006. Status code.
  2007. --*/
  2008. OS_API
  2009. KSTATUS
  2010. OsSocketShutdown (
  2011. HANDLE Socket,
  2012. ULONG ShutdownType
  2013. );
  2014. /*++
  2015. Routine Description:
  2016. This routine shuts down communication with a given socket.
  2017. Arguments:
  2018. Socket - Supplies the socket handle.
  2019. ShutdownType - Supplies the shutdown type to perform. See the
  2020. SOCKET_SHUTDOWN_* definitions. These are NOT the same as the C library
  2021. definitions.
  2022. Return Value:
  2023. STATUS_SUCCESS on success.
  2024. STATUS_NOT_A_SOCKET if the given handle wasn't a socket.
  2025. Other error codes on failure.
  2026. --*/
  2027. //
  2028. // Timekeeping functions
  2029. //
  2030. OS_API
  2031. ULONGLONG
  2032. OsGetRecentTimeCounter (
  2033. VOID
  2034. );
  2035. /*++
  2036. Routine Description:
  2037. This routine returns a relatively recent snap of the time counter.
  2038. Arguments:
  2039. None.
  2040. Return Value:
  2041. Returns the fairly recent snap of the time counter.
  2042. --*/
  2043. OS_API
  2044. ULONGLONG
  2045. OsQueryTimeCounter (
  2046. VOID
  2047. );
  2048. /*++
  2049. Routine Description:
  2050. This routine returns the current (most up to date) value of the system's
  2051. time counter.
  2052. Arguments:
  2053. None.
  2054. Return Value:
  2055. Returns the time counter value.
  2056. --*/
  2057. OS_API
  2058. ULONGLONG
  2059. OsGetTimeCounterFrequency (
  2060. VOID
  2061. );
  2062. /*++
  2063. Routine Description:
  2064. This routine returns the frequency of the time counter.
  2065. Arguments:
  2066. None.
  2067. Return Value:
  2068. Returns the frequency, in Hertz (ticks per second) of the time counter.
  2069. --*/
  2070. OS_API
  2071. ULONGLONG
  2072. OsGetProcessorCounterFrequency (
  2073. VOID
  2074. );
  2075. /*++
  2076. Routine Description:
  2077. This routine returns the frequency of the boot processor counter.
  2078. Arguments:
  2079. None.
  2080. Return Value:
  2081. Returns the frequency, in Hertz (ticks per second) of the boot processor
  2082. counter.
  2083. --*/
  2084. OS_API
  2085. VOID
  2086. OsConvertSystemTimeToTimeCounter (
  2087. PSYSTEM_TIME SystemTime,
  2088. PULONGLONG TimeCounter
  2089. );
  2090. /*++
  2091. Routine Description:
  2092. This routine converts a system time value into a time counter value.
  2093. Arguments:
  2094. SystemTime - Supplies a pointer to the system time convert to a time
  2095. counter value.
  2096. TimeCounter - Supplies a pointer where the time counter value will be
  2097. returned.
  2098. Return Value:
  2099. None.
  2100. --*/
  2101. OS_API
  2102. VOID
  2103. OsConvertTimeCounterToSystemTime (
  2104. ULONGLONG TimeCounter,
  2105. PSYSTEM_TIME SystemTime
  2106. );
  2107. /*++
  2108. Routine Description:
  2109. This routine converts a time counter value into a system time value.
  2110. Arguments:
  2111. TimeCounter - Supplies the time counter value to convert.
  2112. SystemTime - Supplies a pointer where the converted system time will be
  2113. returned.
  2114. Return Value:
  2115. None.
  2116. --*/
  2117. OS_API
  2118. VOID
  2119. OsGetSystemTime (
  2120. PSYSTEM_TIME Time
  2121. );
  2122. /*++
  2123. Routine Description:
  2124. This routine returns the current system time.
  2125. Arguments:
  2126. Time - Supplies a pointer where the system time will be returned.
  2127. Return Value:
  2128. None.
  2129. --*/
  2130. OS_API
  2131. VOID
  2132. OsGetHighPrecisionSystemTime (
  2133. PSYSTEM_TIME Time
  2134. );
  2135. /*++
  2136. Routine Description:
  2137. This routine returns a high precision snap of the current system time.
  2138. Arguments:
  2139. Time - Supplies a pointer where the system time will be returned.
  2140. Return Value:
  2141. None.
  2142. --*/
  2143. OS_API
  2144. KSTATUS
  2145. OsSetSystemTime (
  2146. PSYSTEM_TIME NewTime,
  2147. ULONGLONG TimeCounter
  2148. );
  2149. /*++
  2150. Routine Description:
  2151. This routine sets the current system time.
  2152. Arguments:
  2153. NewTime - Supplies a pointer to the new system time to set.
  2154. TimeCounter - Supplies the time counter value corresponding with the
  2155. moment the system time was meant to be set by the caller.
  2156. Return Value:
  2157. Status code.
  2158. --*/
  2159. OS_API
  2160. KSTATUS
  2161. OsGetResourceUsage (
  2162. RESOURCE_USAGE_REQUEST Request,
  2163. PROCESS_ID Id,
  2164. PRESOURCE_USAGE Usage,
  2165. PULONGLONG Frequency
  2166. );
  2167. /*++
  2168. Routine Description:
  2169. This routine returns resource usage information for the specified process
  2170. or thread.
  2171. Arguments:
  2172. Request - Supplies the request type, indicating whether to get resource
  2173. usage for a process, a process' children, or a thread.
  2174. Id - Supplies the process or thread ID. Supply -1 to use the current
  2175. process or thread.
  2176. Usage - Supplies a pointer where the resource usage is returned on success.
  2177. Frequency - Supplies a pointer that receives the frequency of the
  2178. processor(s).
  2179. Return Value:
  2180. Status code.
  2181. --*/
  2182. OS_API
  2183. KSTATUS
  2184. OsGetTimeZoneData (
  2185. BOOL AllZones,
  2186. PSTR ZoneName,
  2187. PVOID *ZoneData,
  2188. PULONG ZoneDataSize
  2189. );
  2190. /*++
  2191. Routine Description:
  2192. This routine returns time zone data for the given time zone.
  2193. Arguments:
  2194. AllZones - Supplies a boolean indicating whether data for all time zones
  2195. should be returned (TRUE) or just the specified zone (FALSE). If this
  2196. parameter is TRUE, then the zone name parameter is ignored.
  2197. ZoneName - Supplies an optional pointer to the time zone to get information
  2198. for. If NULL, information for the current system time zone will be
  2199. returned.
  2200. ZoneData - Supplies a pointer where a pointer to the data buffer will be
  2201. returned on success. The caller is responsible for freeing this memory
  2202. from the heap when done.
  2203. ZoneDataSize - Supplies a pointer where the size of the zone data will be
  2204. returned on success.
  2205. Return Value:
  2206. Status code.
  2207. --*/
  2208. OS_API
  2209. KSTATUS
  2210. OsSetSystemTimeZone (
  2211. PSTR Zone,
  2212. PSTR OriginalZoneName,
  2213. PULONG OriginalZoneNameSize
  2214. );
  2215. /*++
  2216. Routine Description:
  2217. This routine attempts to set the system time zone.
  2218. Arguments:
  2219. Zone - Supplies a pointer to the name of the new zone to set.
  2220. OriginalZoneName - Supplies an optional pointer that if supplied will
  2221. return the name of the original time zone. If this buffer is supplied
  2222. but not big enough, the time zone change will not take effect.
  2223. OriginalZoneNameSize - Supplies an optional pointer that on input contains
  2224. the size of the original zone name buffer. On output, returns the
  2225. needed size for the original zone name.
  2226. Return Value:
  2227. Status code.
  2228. --*/
  2229. OS_API
  2230. KSTATUS
  2231. OsCreateTimer (
  2232. ULONG SignalNumber,
  2233. PUINTN SignalValue,
  2234. PTHREAD_ID ThreadId,
  2235. PLONG TimerHandle
  2236. );
  2237. /*++
  2238. Routine Description:
  2239. This routine creates a new timer.
  2240. Arguments:
  2241. SignalNumber - Supplies the signal number to raise when the timer expires.
  2242. SignalValue - Supplies an optional pointer to the signal value to put in
  2243. the signal information structure when the signal is raised. If this is
  2244. NULL, the timer number will be returned as the signal value.
  2245. ThreadId - Supplies an optional ID of the thread to signal when the timer
  2246. expires. If not supplied, the process will be signaled.
  2247. TimerHandle - Supplies a pointer where the timer handle will be returned on
  2248. success.
  2249. Return Value:
  2250. Status code.
  2251. --*/
  2252. OS_API
  2253. KSTATUS
  2254. OsDeleteTimer (
  2255. LONG Timer
  2256. );
  2257. /*++
  2258. Routine Description:
  2259. This routine disarms and deletes a timer.
  2260. Arguments:
  2261. Timer - Supplies the timer to delete.
  2262. Return Value:
  2263. Status code.
  2264. --*/
  2265. OS_API
  2266. KSTATUS
  2267. OsGetTimerInformation (
  2268. LONG Timer,
  2269. PTIMER_INFORMATION Information
  2270. );
  2271. /*++
  2272. Routine Description:
  2273. This routine gets the given timer's information.
  2274. Arguments:
  2275. Timer - Supplies the timer to query.
  2276. Information - Supplies a pointer where the timer information will be
  2277. returned.
  2278. Return Value:
  2279. Status code.
  2280. --*/
  2281. OS_API
  2282. KSTATUS
  2283. OsSetTimerInformation (
  2284. LONG Timer,
  2285. PTIMER_INFORMATION Information
  2286. );
  2287. /*++
  2288. Routine Description:
  2289. This routine sets the given timer's information.
  2290. Arguments:
  2291. Timer - Supplies the timer to set.
  2292. Information - Supplies a pointer to the information to set.
  2293. Return Value:
  2294. Status code.
  2295. --*/
  2296. OS_API
  2297. KSTATUS
  2298. OsGetITimer (
  2299. ITIMER_TYPE Type,
  2300. PULONGLONG DueTime,
  2301. PULONGLONG Period
  2302. );
  2303. /*++
  2304. Routine Description:
  2305. This routine gets the current value of one of the per-thread interval
  2306. timers.
  2307. Arguments:
  2308. Type - Supplies the timer type. Valid values are ITimerReal, which tracks
  2309. wall clock time, ITimerVirtual, which tracks user mode CPU cycles
  2310. spent in this thread, and ITimerProfile, which tracks user and kernel
  2311. CPU cycles spent in this thread.
  2312. DueTime - Supplies a pointer where the relative due time will be returned
  2313. for this timer. Zero will be returned if the timer is not currently
  2314. armed or has already expired. The units here are time counter ticks for
  2315. the real timer, and processor counter ticks for the virtual and profile
  2316. timers.
  2317. Period - Supplies a pointer where the periodic interval of the timer
  2318. will be returned. Zero indicates the timer is not set to rearm itself.
  2319. The units here are time counter ticks for the real timer, and processor
  2320. counter ticks for the firtual and profile timers.
  2321. Return Value:
  2322. Status code.
  2323. --*/
  2324. OS_API
  2325. KSTATUS
  2326. OsSetITimer (
  2327. ITIMER_TYPE Type,
  2328. PULONGLONG DueTime,
  2329. PULONGLONG Period
  2330. );
  2331. /*++
  2332. Routine Description:
  2333. This routine sets the current value of one of the per-thread interval
  2334. timers.
  2335. Arguments:
  2336. Type - Supplies the timer type. Valid values are ITimerReal, which tracks
  2337. wall clock time, ITimerVirtual, which tracks user mode CPU cycles
  2338. spent in this thread, and ITimerProfile, which tracks user and kernel
  2339. CPU cycles spent in this thread.
  2340. DueTime - Supplies a pointer to the relative time to set in the timer.
  2341. Supply zero to disable the timer. The units here are time counter ticks
  2342. for the real timer, and processor counter ticks for the virtual and
  2343. profile timers. On output, this will contain the remaining time left on
  2344. the previously set value for the timer.
  2345. Period - Supplies a pointer to the periodic interval to set. Set zero to
  2346. make the timer only fire once. The units here are time counter ticks
  2347. for the real timer, and processor counter ticks for the firtual and
  2348. profile timers. On output, the previous period will be returned.
  2349. Return Value:
  2350. Status code.
  2351. --*/
  2352. OS_API
  2353. KSTATUS
  2354. OsDelayExecution (
  2355. BOOL TimeTicks,
  2356. ULONGLONG Interval
  2357. );
  2358. /*++
  2359. Routine Description:
  2360. This routine blocks the current thread for the specified amount of time.
  2361. Arguments:
  2362. TimeTicks - Supplies a boolean indicating if the interval parameter is
  2363. represented in time counter ticks (TRUE) or microseconds (FALSE).
  2364. Interval - Supplies the interval to wait. If the time ticks parameter is
  2365. TRUE, this parameter represents an absolute time in time counter ticks.
  2366. If the time ticks parameter is FALSE, this parameter represents a
  2367. relative time from now in microseconds. If an interval of 0 is
  2368. supplied, this routine is equivalent to KeYield.
  2369. Return Value:
  2370. STATUS_SUCCESS if the wait completed.
  2371. STATUS_INTERRUPTED if the wait was interrupted.
  2372. --*/
  2373. OS_API
  2374. KSTATUS
  2375. OsLoadLibrary (
  2376. PSTR LibraryName,
  2377. ULONG Flags,
  2378. PHANDLE Handle
  2379. );
  2380. /*++
  2381. Routine Description:
  2382. This routine loads a dynamic library.
  2383. Arguments:
  2384. LibraryName - Supplies a pointer to the library name to load.
  2385. Flags - Supplies a bitfield of flags associated with the request.
  2386. Handle - Supplies a pointer where a handle to the dynamic library will be
  2387. returned on success. INVALID_HANDLE will be returned on failure.
  2388. Return Value:
  2389. Status code.
  2390. --*/
  2391. OS_API
  2392. VOID
  2393. OsFreeLibrary (
  2394. HANDLE Library
  2395. );
  2396. /*++
  2397. Routine Description:
  2398. This routine indicates a release of the resources associated with a
  2399. previously loaded library. This may or may not actually unload the library
  2400. depending on whether or not there are other references to it.
  2401. Arguments:
  2402. Library - Supplies the library to release.
  2403. Return Value:
  2404. None.
  2405. --*/
  2406. OS_API
  2407. KSTATUS
  2408. OsGetLibrarySymbolAddress (
  2409. HANDLE Library,
  2410. PSTR SymbolName,
  2411. PVOID *Address
  2412. );
  2413. /*++
  2414. Routine Description:
  2415. This routine returns the address of the given symbol in the given library.
  2416. Both the library and all of its imports will be searched.
  2417. Arguments:
  2418. Library - Supplies the library to look up. Use OS_LIBRARY_DEFAULT to search
  2419. the current executable or OS_LIBRARY_NEXT to start the search after the
  2420. current executable.
  2421. SymbolName - Supplies a pointer to a null terminated string containing the
  2422. name of the symbol to look up.
  2423. Address - Supplies a pointer that on success receives the address of the
  2424. symbol, or NULL on failure.
  2425. Return Value:
  2426. STATUS_SUCCESS on success.
  2427. STATUS_INVALID_HANDLE if the library handle is not valid.
  2428. STATUS_NOT_FOUND if the symbol could not be found.
  2429. --*/
  2430. OS_API
  2431. KSTATUS
  2432. OsGetLibrarySymbolForAddress (
  2433. HANDLE Library,
  2434. PVOID Address,
  2435. POS_LIBRARY_SYMBOL Symbol
  2436. );
  2437. /*++
  2438. Routine Description:
  2439. This routine resolves the given address into a symbol by searching the
  2440. given library. Both the library and all its imports will be searched.
  2441. Arguments:
  2442. Library - Supplies the library to look up. Use OS_LIBRARY_DEFAULT to search
  2443. the current executable or OS_LIBRARY_NEXT to start the search after the
  2444. current executable.
  2445. Address - Supplies the address to look up.
  2446. Symbol - Supplies a pointer to a structure that receives the resolved
  2447. symbol information.
  2448. Return Value:
  2449. STATUS_SUCCESS on success.
  2450. STATUS_INVALID_HANDLE if the library handle is not valid.
  2451. STATUS_NOT_FOUND if the address could not be found.
  2452. --*/
  2453. OS_API
  2454. KSTATUS
  2455. OsFlushCache (
  2456. PVOID Address,
  2457. UINTN Size
  2458. );
  2459. /*++
  2460. Routine Description:
  2461. This routine flushes the caches for a region of memory after executable
  2462. code has been modified.
  2463. Arguments:
  2464. Address - Supplies the address of the region to flush.
  2465. Size - Supplies the number of bytes in the region.
  2466. Return Value:
  2467. STATUS_SUCCESS on success.
  2468. STATUS_ACCESS_VIOLATION if the given address was not valid.
  2469. --*/
  2470. OS_API
  2471. KSTATUS
  2472. OsCreateThreadData (
  2473. PVOID *ThreadData
  2474. );
  2475. /*++
  2476. Routine Description:
  2477. This routine creates the OS library data necessary to manage a new thread.
  2478. This function is usually called by the C library.
  2479. Arguments:
  2480. ThreadData - Supplies a pointer where a pointer to the thread data will be
  2481. returned on success. It is the callers responsibility to destroy this
  2482. thread data. The contents of this data are opaque and should not be
  2483. interpreted. The caller should set this returned pointer as the
  2484. thread pointer.
  2485. Return Value:
  2486. Status code.
  2487. --*/
  2488. OS_API
  2489. VOID
  2490. OsDestroyThreadData (
  2491. PVOID ThreadData
  2492. );
  2493. /*++
  2494. Routine Description:
  2495. This routine destroys the previously created OS library thread data.
  2496. Arguments:
  2497. ThreadData - Supplies the previously returned thread data.
  2498. Return Value:
  2499. Status code.
  2500. --*/
  2501. OS_API
  2502. VOID
  2503. OsIterateImages (
  2504. PIMAGE_ITERATOR_ROUTINE IteratorRoutine,
  2505. PVOID Context
  2506. );
  2507. /*++
  2508. Routine Description:
  2509. This routine iterates over all images currently loaded in the process.
  2510. Arguments:
  2511. IteratorRoutine - Supplies a pointer to the routine to call for each image.
  2512. Context - Supplies an opaque context pointer that is passed directly into
  2513. the iterator routine.
  2514. Return Value:
  2515. None.
  2516. --*/
  2517. OS_API
  2518. VOID
  2519. OsInitializeLock (
  2520. POS_LOCK Lock,
  2521. ULONG SpinCount
  2522. );
  2523. /*++
  2524. Routine Description:
  2525. This routine initializes an OS lock.
  2526. Arguments:
  2527. Lock - Supplies a pointer to the lock to initialize.
  2528. SpinCount - Supplies the number of initial consecutive attempts to make
  2529. when acquiring the lock. Larger values here minimize the delay between
  2530. when the lock is freed and subsequently reacquired, but are bad for
  2531. power performance as the thread is burning energy doing nothing. Most
  2532. applications should set this to SPIN_LOCK_DEFAULT_SPIN_COUNT.
  2533. Return Value:
  2534. None.
  2535. --*/
  2536. OS_API
  2537. VOID
  2538. OsAcquireLock (
  2539. POS_LOCK Lock
  2540. );
  2541. /*++
  2542. Routine Description:
  2543. This routine acquires the given OS lock. It is not recursive, meaning
  2544. that if the lock is already held by the current thread this routine will
  2545. never return.
  2546. Arguments:
  2547. Lock - Supplies a pointer to the lock to acquire.
  2548. Return Value:
  2549. None.
  2550. --*/
  2551. OS_API
  2552. BOOL
  2553. OsTryToAcquireLock (
  2554. POS_LOCK Lock
  2555. );
  2556. /*++
  2557. Routine Description:
  2558. This routine performs a single attempt to acquire the given OS lock.
  2559. Arguments:
  2560. Lock - Supplies a pointer to the lock to acquire.
  2561. Return Value:
  2562. TRUE if the lock was successfully acquired.
  2563. FALSE if the lock was already held and could not be acquired.
  2564. --*/
  2565. OS_API
  2566. VOID
  2567. OsReleaseLock (
  2568. POS_LOCK Lock
  2569. );
  2570. /*++
  2571. Routine Description:
  2572. This routine releases the given OS lock. The lock must have been
  2573. previously acquired, obviously.
  2574. Arguments:
  2575. Lock - Supplies a pointer to the lock to release.
  2576. Return Value:
  2577. None.
  2578. --*/
  2579. OS_API
  2580. VOID
  2581. OsRwLockInitialize (
  2582. POS_RWLOCK Lock,
  2583. ULONG Flags
  2584. );
  2585. /*++
  2586. Routine Description:
  2587. This routine initializes a read/write lock.
  2588. Arguments:
  2589. Lock - Supplies a pointer to the read/write lock.
  2590. Flags - Supplies a bitfield of flags governing the lock behavior.
  2591. Return Value:
  2592. None.
  2593. --*/
  2594. OS_API
  2595. KSTATUS
  2596. OsRwLockRead (
  2597. POS_RWLOCK Lock
  2598. );
  2599. /*++
  2600. Routine Description:
  2601. This routine acquires the read/write lock for read access. Multiple readers
  2602. can acquire the lock simultaneously, but any writes that try to acquire
  2603. the lock while it's held for read will block. Readers that try to
  2604. acquire the lock while it's held for write will also block.
  2605. Arguments:
  2606. Lock - Supplies a pointer to the read/write lock.
  2607. Return Value:
  2608. Status code.
  2609. --*/
  2610. OS_API
  2611. KSTATUS
  2612. OsRwLockReadTimed (
  2613. POS_RWLOCK Lock,
  2614. ULONG TimeoutInMilliseconds
  2615. );
  2616. /*++
  2617. Routine Description:
  2618. This routine acquires the read/write lock for read access just like the
  2619. read lock function, except that this function will return after the
  2620. specified deadline if the lock could not be acquired.
  2621. Arguments:
  2622. Lock - Supplies a pointer to the read/write lock.
  2623. TimeoutInMilliseconds - Supplies the duration to wait in milliseconds.
  2624. Return Value:
  2625. Status code.
  2626. --*/
  2627. OS_API
  2628. KSTATUS
  2629. OsRwLockTryRead (
  2630. POS_RWLOCK Lock
  2631. );
  2632. /*++
  2633. Routine Description:
  2634. This routine performs a single attempt at acquiring the lock for read
  2635. access.
  2636. Arguments:
  2637. Lock - Supplies a pointer to the read/write lock.
  2638. Return Value:
  2639. STATUS_SUCCESS on success.
  2640. STATUS_RESOURCE_IN_USE if the lock is already held.
  2641. --*/
  2642. OS_API
  2643. KSTATUS
  2644. OsRwLockWrite (
  2645. POS_RWLOCK Lock
  2646. );
  2647. /*++
  2648. Routine Description:
  2649. This routine acquires the read/write lock for write access. The lock can
  2650. only be acquired for write access if there are no readers and no other
  2651. writers.
  2652. Arguments:
  2653. Lock - Supplies a pointer to the read/write lock.
  2654. Return Value:
  2655. Status code.
  2656. --*/
  2657. OS_API
  2658. KSTATUS
  2659. OsRwLockWriteTimed (
  2660. POS_RWLOCK Lock,
  2661. ULONG TimeoutInMilliseconds
  2662. );
  2663. /*++
  2664. Routine Description:
  2665. This routine acquires the read/write lock for write access just like the
  2666. write lock function, except that this function will return after the
  2667. specified deadline if the lock could not be acquired.
  2668. Arguments:
  2669. Lock - Supplies a pointer to the read/write lock.
  2670. AbsoluteTimeout - Supplies a pointer to the absolute deadline after which
  2671. this function should give up and return failure.
  2672. Return Value:
  2673. Status code.
  2674. --*/
  2675. OS_API
  2676. KSTATUS
  2677. OsRwLockTryWrite (
  2678. POS_RWLOCK Lock
  2679. );
  2680. /*++
  2681. Routine Description:
  2682. This routine performs a single attempt at acquiring the lock for write
  2683. access.
  2684. Arguments:
  2685. Lock - Supplies a pointer to the read/write lock.
  2686. Return Value:
  2687. STATUS_SUCCESS on success.
  2688. STATUS_RESOURCE_IN_USE if the lock is already held.
  2689. --*/
  2690. OS_API
  2691. KSTATUS
  2692. OsRwLockUnlock (
  2693. POS_RWLOCK Lock
  2694. );
  2695. /*++
  2696. Routine Description:
  2697. This routine unlocks a read/write lock that's been acquired by this thread
  2698. for either read or write.
  2699. Arguments:
  2700. Lock - Supplies a pointer to the read/write lock.
  2701. Return Value:
  2702. STATUS_SUCCESS on success.
  2703. STATUS_PERMISSION_DENIED if the lock is not held or was not held by this
  2704. thread.
  2705. --*/
  2706. OS_API
  2707. KSTATUS
  2708. OsUserLock (
  2709. PVOID Address,
  2710. ULONG Operation,
  2711. PULONG Value,
  2712. ULONG TimeoutInMilliseconds
  2713. );
  2714. /*++
  2715. Routine Description:
  2716. This routine performs a cooperative locking operation with the kernel.
  2717. Arguments:
  2718. Address - Supplies a pointer to a 32-bit value representing the lock in
  2719. user mode.
  2720. Operation - Supplies the operation of type USER_LOCK_OPERATION, as well as
  2721. any flags, see USER_LOCK_* definitions. Valid operations are:
  2722. UserLockWait - Puts the current thread to sleep atomically if the value
  2723. at the given address is the same as the value parameter passed in.
  2724. UserLockWake - Wakes the number of threads given in the value that are
  2725. blocked on the given address.
  2726. Value - Supplies a pointer whose value depends on the operation. For wait
  2727. operations, this contains the value to check the address against. This
  2728. is not used on output for wait operations. For wake operations, this
  2729. contains the number of processes to wake on input. On output, contains
  2730. the number of processes woken.
  2731. TimeoutInMilliseconds - Supplies the number of milliseconds for a wait
  2732. operation to complete before timing out. Set to
  2733. SYS_WAIT_TIME_INDEFINITE to wait forever. This is not used on wake
  2734. operations.
  2735. Return Value:
  2736. STATUS_SUCCESS if the wait or wake succeeded.
  2737. STATUS_OPERATION_WOULD_BLOCK if for a wait operation the value at the given
  2738. address was not equal to the supplied value.
  2739. STATUS_TIMEOUT if a wait operation timed out before the wait was satisfied.
  2740. STATUS_INTERRUPTED if a signal arrived before a wait was completed or timed
  2741. out.
  2742. --*/
  2743. OS_API
  2744. PVOID
  2745. OsGetTlsAddress (
  2746. PTLS_INDEX Entry
  2747. );
  2748. /*++
  2749. Routine Description:
  2750. This routine returns the address of the given thread local storage symbol.
  2751. This routine supports a C library call, references to which are emitted
  2752. directly by the compiler.
  2753. Arguments:
  2754. Entry - Supplies a pointer to the TLS entry to get the symbol address for.
  2755. Return Value:
  2756. Returns a pointer to the thread local storage symbol on success.
  2757. --*/
  2758. OS_API
  2759. UINTN
  2760. OsGetThreadId (
  2761. VOID
  2762. );
  2763. /*++
  2764. Routine Description:
  2765. This routine returns the currently running thread's identifier.
  2766. Arguments:
  2767. None.
  2768. Return Value:
  2769. Returns the current thread's ID. This number will be unique to the current
  2770. thread as long as the thread is running.
  2771. --*/
  2772. OS_API
  2773. KSTATUS
  2774. OsSetThreadPointer (
  2775. PVOID Pointer
  2776. );
  2777. /*++
  2778. Routine Description:
  2779. This routine sets the thread control pointer, which points to the thread
  2780. control block. This function should only be called by the C library, not by
  2781. user applications.
  2782. Arguments:
  2783. Pointer - Supplies a pointer to associate with the thread in an
  2784. architecture-specific way.
  2785. Return Value:
  2786. Status code.
  2787. --*/
  2788. OS_API
  2789. BOOL
  2790. OsTestProcessorFeature (
  2791. ULONG Feature
  2792. );
  2793. /*++
  2794. Routine Description:
  2795. This routine determines if a given processor features is supported or not.
  2796. Arguments:
  2797. Feature - Supplies the feature to test, which is an enum of type
  2798. OS_<arch>_PROCESSOR_FEATURE.
  2799. Return Value:
  2800. TRUE if the feature is set.
  2801. FALSE if the feature is not set or not recognized.
  2802. --*/
  2803. #ifdef __cplusplus
  2804. }
  2805. #endif