minocaos.h 91 KB

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