pal.h 187 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203
  1. //
  2. // Copyright (c) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
  4. //
  5. /*++
  6. Module Name:
  7. pal.h
  8. Abstract:
  9. Rotor Platform Adaptation Layer (PAL) header file. This file
  10. defines all types and API calls required by the Rotor port of
  11. the Microsoft Common Language Runtime.
  12. Defines which control the behavior of this include file:
  13. UNICODE - define it to set the Ansi/Unicode neutral names to
  14. be the ...W names. Otherwise the neutral names default
  15. to be the ...A names.
  16. PAL_IMPLEMENTATION - define it when implementing the PAL. Otherwise
  17. leave it undefined when consuming the PAL.
  18. Note: some fields in structs have been renamed from the original
  19. SDK documentation names, with _PAL_Undefined appended. This leaves
  20. the structure layout identical to its Win32 version, but prevents
  21. PAL consumers from inadvertently referencing undefined fields.
  22. If you want to add a PAL_ wrapper function to a native function in
  23. here, you also need to edit palinternal.h and win32pal.h.
  24. --*/
  25. #ifndef __PAL_H__
  26. #define __PAL_H__
  27. #ifdef PAL_STDCPP_COMPAT
  28. #include <stddef.h>
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <stdarg.h>
  32. #include <string.h>
  33. #include <errno.h>
  34. #include <ctype.h>
  35. #endif
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. #if defined (PLATFORM_UNIX)
  40. // This macro is used to standardize the wide character string literals between UNIX and Windows.
  41. // Unix L"" is UTF32, and on windows it's UTF16. Because of built-in assumptions on the size
  42. // of string literals, it's important to match behaviour between Unix and Windows. Unix will be defined
  43. // as u"" (char16_t)
  44. #define W(str) u##str
  45. // Undefine the QUOTE_MACRO_L helper and redefine it in terms of u.
  46. // The reason that we do this is that quote macro is defined in ndp\common\inc,
  47. // not inside of coreclr sources.
  48. #define QUOTE_MACRO_L(x) QUOTE_MACRO_u(x)
  49. #define QUOTE_MACRO_u_HELPER(x) u###x
  50. #define QUOTE_MACRO_u(x) QUOTE_MACRO_u_HELPER(x)
  51. #endif
  52. #include <pal_char16.h>
  53. #include <pal_error.h>
  54. #include <pal_mstypes.h>
  55. /******************* Processor-specific glue *****************************/
  56. #ifndef _MSC_VER
  57. #if defined(__i686__) && !defined(_M_IX86)
  58. #define _M_IX86 600
  59. #elif defined(__i586__) && !defined(_M_IX86)
  60. #define _M_IX86 500
  61. #elif defined(__i486__) && !defined(_M_IX86)
  62. #define _M_IX86 400
  63. #elif defined(__i386__) && !defined(_M_IX86)
  64. #define _M_IX86 300
  65. #elif defined(__ppc__) && !defined(_M_PPC)
  66. #define _M_PPC 100
  67. #elif defined(_AIX) && defined(_POWER) && !defined(_M_PPC)
  68. #define _M_PPC 100
  69. #elif defined(__sparc__) && !defined(_M_SPARC)
  70. #define _M_SPARC 100
  71. #elif defined(__hppa__) && !defined(_M_PARISC)
  72. #define _M_PARISC 100
  73. #elif defined(__ia64__) && !defined(_M_IA64)
  74. #define _M_IA64 64100
  75. #elif defined(__x86_64__) && !defined(_M_AMD64)
  76. #define _M_AMD64 100
  77. #elif defined(__arm__) && !defined(_M_ARM)
  78. #define _M_ARM 7
  79. #elif defined(__aarch64__) && !defined(_M_ARM64)
  80. #define _M_ARM64 1
  81. #endif
  82. #if defined(_M_IX86) && !defined(_X86_)
  83. #define _X86_
  84. #elif defined(_M_ALPHA) && !defined(_ALPHA_)
  85. #define _ALPHA_
  86. #elif defined(_M_PPC) && !defined(_PPC_)
  87. #define _PPC_
  88. #elif defined(_M_SPARC) && !defined(_SPARC_)
  89. #define _SPARC_
  90. #elif defined(_M_PARISC) && !defined(_PARISC_)
  91. #define _PARISC_
  92. #elif defined(_M_MRX000) && !defined(_MIPS_)
  93. #define _MIPS_
  94. #elif defined(_M_M68K) && !defined(_68K_)
  95. #define _68K_
  96. #elif defined(_M_IA64) && !defined(_IA64_)
  97. #define _IA64_
  98. #elif defined(_M_AMD64) && !defined(_AMD64_)
  99. #define _AMD64_
  100. #elif defined(_M_ARM) && !defined(_ARM_)
  101. #define _ARM_
  102. #elif defined(_M_ARM64) && !defined(_ARM64_)
  103. #define _ARM64_
  104. #endif
  105. #endif // !_MSC_VER
  106. /******************* ABI-specific glue *******************************/
  107. #if defined(_PPC_) || defined(_PPC64_) || defined(_SPARC_) || defined(_PARISC_) || defined(_IA64_)
  108. #define BIGENDIAN 1
  109. #endif
  110. #ifdef __APPLE__
  111. // Both PowerPC, i386 and x86_64 on Mac OS X use 16-byte alignment.
  112. #define STACK_ALIGN_BITS 4
  113. #define STACK_ALIGN_REQ (1 << STACK_ALIGN_BITS)
  114. #endif
  115. #define MAX_PATH 260
  116. #define _MAX_PATH 260
  117. #define _MAX_DRIVE 3 /* max. length of drive component */
  118. #define _MAX_DIR 256 /* max. length of path component */
  119. #define _MAX_FNAME 256 /* max. length of file name component */
  120. #define _MAX_EXT 256 /* max. length of extension component */
  121. // In some Win32 APIs MAX_PATH is used for file names (even though 256 is the normal file system limit)
  122. // use _MAX_PATH_FNAME to indicate these cases
  123. #define MAX_PATH_FNAME MAX_PATH
  124. #define MAX_LONGPATH 1024 /* max. length of full pathname */
  125. #define MAXSHORT 0x7fff
  126. #define MAXLONG 0x7fffffff
  127. #define MAXCHAR 0x7f
  128. #define MAXDWORD 0xffffffff
  129. // Sorting IDs.
  130. //
  131. // Note that the named locale APIs (eg CompareStringExEx) are recommended.
  132. //
  133. #define LANG_CHINESE 0x04
  134. #define LANG_ENGLISH 0x09
  135. #define LANG_JAPANESE 0x11
  136. #define LANG_KOREAN 0x12
  137. #define LANG_THAI 0x1e
  138. /******************* Compiler-specific glue *******************************/
  139. #ifndef _MSC_VER
  140. #define FEATURE_PAL_SXS 1
  141. #endif // !_MSC_VER
  142. #if defined(_MSC_VER) || defined(__llvm__)
  143. #define DECLSPEC_ALIGN(x) __declspec(align(x))
  144. #else
  145. #define DECLSPEC_ALIGN(x)
  146. #endif
  147. #define DECLSPEC_NORETURN PAL_NORETURN
  148. #ifndef _MSC_VER
  149. #define __assume(x) (void)0
  150. #define __annotation(x)
  151. #endif //!MSC_VER
  152. #ifdef _MSC_VER
  153. #if defined(_M_MRX000) || defined(_M_ALPHA) || defined(_M_PPC) || defined(_M_IA64)
  154. #define UNALIGNED __unaligned
  155. #else
  156. #define UNALIGNED
  157. #endif
  158. #else // _MSC_VER
  159. #define UNALIGNED
  160. #endif // _MSC_VER
  161. #ifndef FORCEINLINE
  162. #if _MSC_VER < 1200
  163. #define FORCEINLINE inline
  164. #else
  165. #define FORCEINLINE __forceinline
  166. #endif
  167. #endif
  168. #ifndef PAL_STDCPP_COMPAT
  169. #ifdef _M_ALPHA
  170. typedef struct {
  171. char *a0; /* pointer to first homed integer argument */
  172. int offset; /* byte offset of next parameter */
  173. } va_list;
  174. #define va_start(list, v) __builtin_va_start(list, v, 1)
  175. #define va_end(list)
  176. #elif __GNUC__
  177. #if defined(_AIX)
  178. typedef __builtin_va_list __gnuc_va_list;
  179. typedef __builtin_va_list va_list;
  180. #define va_start(v,l) __builtin_va_start(v,l)
  181. #define va_end __builtin_va_end
  182. #define va_arg __builtin_va_arg
  183. #else // _AIX
  184. #if __GNUC__ == 2
  185. typedef void * va_list;
  186. #else
  187. typedef __builtin_va_list va_list;
  188. #endif // __GNUC__
  189. /* We should consider if the va_arg definition here is actually necessary.
  190. Could we use the standard va_arg definition? */
  191. #if __GNUC__ == 2
  192. #if defined(_SPARC_) || defined(_PARISC_) // ToDo: is this the right thing for PARISC?
  193. #define va_start(list, v) (__builtin_next_arg(v), list = (char *) __builtin_saveregs())
  194. #define __va_rounded_size(TYPE) \
  195. (((sizeof (TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int))
  196. #define __record_type_class 12
  197. #define __real_type_class 8
  198. #define va_arg(pvar,TYPE) \
  199. __extension__ \
  200. (*({((__builtin_classify_type (*(TYPE*) 0) >= __record_type_class \
  201. || (__builtin_classify_type (*(TYPE*) 0) == __real_type_class \
  202. && sizeof (TYPE) == 16)) \
  203. ? ((pvar) = (char *)(pvar) + __va_rounded_size (TYPE *), \
  204. *(TYPE **) (void *) ((char *)(pvar) - __va_rounded_size (TYPE *))) \
  205. : __va_rounded_size (TYPE) == 8 \
  206. ? ({ union {char __d[sizeof (TYPE)]; int __i[2];} __u; \
  207. __u.__i[0] = ((int *) (void *) (pvar))[0]; \
  208. __u.__i[1] = ((int *) (void *) (pvar))[1]; \
  209. (pvar) = (char *)(pvar) + 8; \
  210. (TYPE *) (void *) __u.__d; }) \
  211. : ((pvar) = (char *)(pvar) + __va_rounded_size (TYPE), \
  212. ((TYPE *) (void *) ((char *)(pvar) - __va_rounded_size (TYPE)))));}))
  213. #else // _SPARC_ or _PARISC_
  214. // GCC 2.95.3 on non-SPARC
  215. #define __va_size(type) (((sizeof(type) + sizeof(int) - 1) / sizeof(int)) * sizeof(int))
  216. #define va_start(list, v) ((list) = (va_list) __builtin_next_arg(v))
  217. #define va_arg(ap, type) (*(type *)((ap) += __va_size(type), (ap) - __va_size(type)))
  218. #endif // _SPARC_ or _PARISC_
  219. #else // __GNUC__ == 2
  220. #define va_start __builtin_va_start
  221. #define va_arg __builtin_va_arg
  222. #endif // __GNUC__ == 2
  223. #define va_copy __builtin_va_copy
  224. #define va_end __builtin_va_end
  225. #endif // _AIX
  226. #define VOID void
  227. #define PUB __attribute__((visibility("default")))
  228. #else // __GNUC__
  229. typedef char * va_list;
  230. #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
  231. #if _MSC_VER >= 1400
  232. #ifdef __cplusplus
  233. #define _ADDRESSOF(v) ( &reinterpret_cast<const char &>(v) )
  234. #else
  235. #define _ADDRESSOF(v) ( &(v) )
  236. #endif
  237. #define _crt_va_start(ap,v) ( ap = (va_list)_ADDRESSOF(v) + _INTSIZEOF(v) )
  238. #define _crt_va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
  239. #define _crt_va_end(ap) ( ap = (va_list)0 )
  240. #define va_start _crt_va_start
  241. #define va_arg _crt_va_arg
  242. #define va_end _crt_va_end
  243. #else // _MSC_VER
  244. #define va_start(ap,v) (ap = (va_list) (&(v)) + _INTSIZEOF(v))
  245. #define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
  246. #define va_end(ap)
  247. #endif // _MSC_VER
  248. #define va_copy(dest,src) (dest = src)
  249. #endif // __GNUC__
  250. #endif // !PAL_STDCPP_COMPAT
  251. #if defined(__CLANG__) || defined(__GNUC__)
  252. #define PAL_GLOBAL __attribute__((init_priority(200)))
  253. #else
  254. #define PAL_GLOBAL
  255. #endif
  256. /******************* PAL-Specific Entrypoints *****************************/
  257. #define IsDebuggerPresent PAL_IsDebuggerPresent
  258. PALIMPORT
  259. BOOL
  260. PALAPI
  261. PAL_IsDebuggerPresent();
  262. #define MAXIMUM_SUSPEND_COUNT MAXCHAR
  263. #define CHAR_BIT 8
  264. #define SCHAR_MIN (-128)
  265. #define SCHAR_MAX 127
  266. #define UCHAR_MAX 0xff
  267. #define SHRT_MIN (-32768)
  268. #define SHRT_MAX 32767
  269. #define USHRT_MAX 0xffff
  270. #define INT_MIN (-2147483647 - 1)
  271. #define INT_MAX 2147483647
  272. #define UINT_MAX 0xffffffff
  273. #define LONG_MIN (-2147483647L - 1)
  274. #define LONG_MAX 2147483647L
  275. #define ULONG_MAX 0xffffffffUL
  276. #define FLT_MAX 3.402823466e+38F
  277. #define DBL_MAX 1.7976931348623157e+308
  278. /* minimum signed 64 bit value */
  279. #define _I64_MIN (I64(-9223372036854775807) - 1)
  280. /* maximum signed 64 bit value */
  281. #define _I64_MAX I64(9223372036854775807)
  282. /* maximum unsigned 64 bit value */
  283. #define _UI64_MAX UI64(0xffffffffffffffff)
  284. #define _I8_MAX SCHAR_MAX
  285. #define _I8_MIN SCHAR_MIN
  286. #define _I16_MAX SHRT_MAX
  287. #define _I16_MIN SHRT_MIN
  288. #define _I32_MAX INT_MAX
  289. #define _I32_MIN INT_MIN
  290. #define _UI8_MAX UCHAR_MAX
  291. #define _UI8_MIN UCHAR_MIN
  292. #define _UI16_MAX USHRT_MAX
  293. #define _UI16_MIN USHRT_MIN
  294. #define _UI32_MAX UINT_MAX
  295. #define _UI32_MIN UINT_MIN
  296. #ifdef PAL_STDCPP_COMPAT
  297. #undef NULL
  298. #endif
  299. #ifndef NULL
  300. #if defined(__cplusplus)
  301. #define NULL 0
  302. #else
  303. #define NULL ((void *)0)
  304. #endif
  305. #endif
  306. #if defined(PAL_STDCPP_COMPAT) && !defined(__cplusplus)
  307. #define nullptr NULL
  308. #endif // defined(PAL_STDCPP_COMPAT) && !defined(__cplusplus)
  309. #ifndef PAL_STDCPP_COMPAT
  310. typedef ULONG64 fpos_t;
  311. #if _WIN64 || _MSC_VER >= 1400
  312. typedef __int64 time_t;
  313. #else
  314. typedef long time_t;
  315. #endif
  316. #define _TIME_T_DEFINED
  317. #endif // !PAL_STDCPP_COMPAT
  318. #if ENABLE_DOWNLEVEL_FOR_NLS
  319. #define MAKELCID(lgid, srtid) ((DWORD)((((DWORD)((WORD )(srtid))) << 16) | \
  320. ((DWORD)((WORD )(lgid)))))
  321. #define LANGIDFROMLCID(lcid) ((WORD)(lcid))
  322. #define SORTIDFROMLCID(lcid) ((WORD)((((DWORD)(lcid)) >> 16) & 0xf))
  323. #define LANG_NEUTRAL 0x00
  324. #define LANG_INVARIANT 0x7f
  325. #define SUBLANG_NEUTRAL 0x00 // language neutral
  326. #define SUBLANG_DEFAULT 0x01 // user default
  327. #define SORT_DEFAULT 0x0 // sorting default
  328. #define SUBLANG_SYS_DEFAULT 0x02 // system default
  329. #define MAKELANGID(p, s) ((((WORD )(s)) << 10) | (WORD )(p))
  330. #define PRIMARYLANGID(lgid) ((WORD )(lgid) & 0x3ff)
  331. #define SUBLANGID(lgid) ((WORD )(lgid) >> 10)
  332. #define LANG_SYSTEM_DEFAULT (MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT))
  333. #define LANG_USER_DEFAULT (MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT))
  334. #define LOCALE_SYSTEM_DEFAULT (MAKELCID(LANG_SYSTEM_DEFAULT, SORT_DEFAULT))
  335. #define LOCALE_USER_DEFAULT (MAKELCID(LANG_USER_DEFAULT, SORT_DEFAULT))
  336. #define LOCALE_NEUTRAL (MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), SORT_DEFAULT))
  337. #define LOCALE_US_ENGLISH (MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT))
  338. #define LOCALE_INVARIANT (MAKELCID(MAKELANGID(LANG_INVARIANT, SUBLANG_NEUTRAL), SORT_DEFAULT))
  339. #define SUBLANG_ENGLISH_US 0x01
  340. #define SUBLANG_CHINESE_TRADITIONAL 0x01 /* Chinese (Traditional) */
  341. #endif // ENABLE_DOWNLEVEL_FOR_NLS
  342. #define CT_CTYPE1 0x00000001 /* ctype 1 information */
  343. #define CT_CTYPE2 0x00000002 /* ctype 2 information */
  344. #define CT_CTYPE3 0x00000004 /* ctype 3 information */
  345. #define C1_UPPER 0x0001 /* upper case */
  346. #define C1_LOWER 0x0002 /* lower case */
  347. #define C1_DIGIT 0x0004 /* decimal digits */
  348. #define C1_SPACE 0x0008 /* spacing characters */
  349. #define C1_PUNCT 0x0010 /* punctuation characters */
  350. #define C1_CNTRL 0x0020 /* control characters */
  351. #define C1_BLANK 0x0040 /* blank characters */
  352. #define C1_XDIGIT 0x0080 /* other digits */
  353. #define C1_ALPHA 0x0100 /* any linguistic character */
  354. #define C2_LEFTTORIGHT 0x0001 /* left to right */
  355. #define C2_RIGHTTOLEFT 0x0002 /* right to left */
  356. #define C2_EUROPENUMBER 0x0003 /* European number, digit */
  357. #define C2_EUROPESEPARATOR 0x0004 /* European numeric separator */
  358. #define C2_EUROPETERMINATOR 0x0005 /* European numeric terminator */
  359. #define C2_ARABICNUMBER 0x0006 /* Arabic number */
  360. #define C2_COMMONSEPARATOR 0x0007 /* common numeric separator */
  361. #define C2_BLOCKSEPARATOR 0x0008 /* block separator */
  362. #define C2_SEGMENTSEPARATOR 0x0009 /* segment separator */
  363. #define C2_WHITESPACE 0x000A /* white space */
  364. #define C2_OTHERNEUTRAL 0x000B /* other neutrals */
  365. #define C2_NOTAPPLICABLE 0x0000 /* no implicit directionality */
  366. #define C3_NONSPACING 0x0001 /* nonspacing character */
  367. #define C3_DIACRITIC 0x0002 /* diacritic mark */
  368. #define C3_VOWELMARK 0x0004 /* vowel mark */
  369. #define C3_SYMBOL 0x0008 /* symbols */
  370. #define C3_KATAKANA 0x0010 /* katakana character */
  371. #define C3_HIRAGANA 0x0020 /* hiragana character */
  372. #define C3_HALFWIDTH 0x0040 /* half width character */
  373. #define C3_FULLWIDTH 0x0080 /* full width character */
  374. #define C3_IDEOGRAPH 0x0100 /* ideographic character */
  375. #define C3_KASHIDA 0x0200 /* Arabic kashida character */
  376. #define C3_LEXICAL 0x0400 /* lexical character */
  377. #define C3_ALPHA 0x8000 /* any ling. char (C1_ALPHA) */
  378. #define C3_NOTAPPLICABLE 0x0000 /* ctype 3 is not applicable */
  379. #define DLL_PROCESS_ATTACH 1
  380. #define DLL_THREAD_ATTACH 2
  381. #define DLL_THREAD_DETACH 3
  382. #define DLL_PROCESS_DETACH 0
  383. #define PAL_INITIALIZE_NONE 0x00
  384. #define PAL_INITIALIZE_SYNC_THREAD 0x01
  385. #define PAL_INITIALIZE_EXEC_ALLOCATOR 0x02
  386. // PAL_Initialize() flags
  387. #define PAL_INITIALIZE PAL_INITIALIZE_SYNC_THREAD
  388. // PAL_InitializeDLL() flags - don't start any of the helper threads
  389. #define PAL_INITIALIZE_DLL PAL_INITIALIZE_NONE
  390. // PAL_InitializeChakraCore() flags
  391. #define PAL_INITIALIZE_CHAKRACORE (PAL_INITIALIZE | PAL_INITIALIZE_EXEC_ALLOCATOR)
  392. typedef DWORD (PALAPI *PTHREAD_START_ROUTINE)(LPVOID lpThreadParameter);
  393. typedef PTHREAD_START_ROUTINE LPTHREAD_START_ROUTINE;
  394. /******************* Tracing Initialization *******************************/
  395. #if defined(__LINUX__)
  396. // Constructor priority is set to 200, which allows for constructors to
  397. // guarantee that they run before or after this constructor by setting
  398. // their priority appropriately.
  399. // Priority values must be greater than 100. The lower the value,
  400. // the higher the priority.
  401. static
  402. void
  403. __attribute__((__unused__))
  404. __attribute__((constructor (200)))
  405. PAL_InitializeTracing(void);
  406. #endif
  407. /******************* PAL-Specific Entrypoints *****************************/
  408. PALIMPORT
  409. int
  410. PALAPI
  411. PAL_Initialize(
  412. int argc,
  413. const char * const argv[]);
  414. PALIMPORT
  415. int
  416. PALAPI
  417. PAL_InitializeDLL();
  418. PALIMPORT
  419. DWORD
  420. PALAPI
  421. PAL_InitializeCoreCLR(
  422. const char *szExePath);
  423. PALIMPORT
  424. DWORD
  425. PALAPI
  426. PAL_InitializeChakraCore(
  427. const char *szExePath);
  428. PALIMPORT
  429. DWORD_PTR
  430. PALAPI
  431. PAL_EntryPoint(
  432. IN LPTHREAD_START_ROUTINE lpStartAddress,
  433. IN LPVOID lpParameter);
  434. /// <summary>
  435. /// This function shuts down PAL WITHOUT exiting the current process.
  436. /// </summary>
  437. PALIMPORT
  438. void
  439. PALAPI
  440. PAL_Shutdown(
  441. void);
  442. /// <summary>
  443. /// This function shuts down PAL and exits the current process.
  444. /// </summary>
  445. PALIMPORT
  446. void
  447. PALAPI
  448. PAL_Terminate(
  449. void);
  450. /// <summary>
  451. /// This function shuts down PAL and exits the current process with
  452. /// the specified exit code.
  453. /// </summary>
  454. PALIMPORT
  455. void
  456. PALAPI
  457. PAL_TerminateEx(
  458. int exitCode);
  459. /*++
  460. Function:
  461. PAL_SetShutdownCallback
  462. Abstract:
  463. Sets a callback that is executed when the PAL is shut down because of
  464. ExitProcess, TerminateProcess or PAL_Shutdown but not PAL_Terminate/Ex.
  465. NOTE: Currently only one callback can be set at a time.
  466. --*/
  467. typedef VOID (*PSHUTDOWN_CALLBACK)(void);
  468. PALIMPORT
  469. VOID
  470. PALAPI
  471. PAL_SetShutdownCallback(
  472. IN PSHUTDOWN_CALLBACK callback);
  473. PALIMPORT
  474. void
  475. PALAPI
  476. PAL_InitializeDebug(
  477. void);
  478. PALIMPORT
  479. HINSTANCE
  480. PALAPI
  481. PAL_RegisterModule(
  482. IN LPCSTR lpLibFileName);
  483. PALIMPORT
  484. VOID
  485. PALAPI
  486. PAL_UnregisterModule(
  487. IN HINSTANCE hInstance);
  488. PALIMPORT
  489. BOOL
  490. PALAPI
  491. PAL_GetPALDirectoryW(
  492. OUT LPWSTR lpDirectoryName,
  493. IN UINT cchDirectoryName);
  494. PALIMPORT
  495. BOOL
  496. PALAPI
  497. PAL_GetPALDirectoryA(
  498. OUT LPSTR lpDirectoryName,
  499. IN UINT cchDirectoryName);
  500. #ifdef UNICODE
  501. #define PAL_GetPALDirectory PAL_GetPALDirectoryW
  502. #else
  503. #define PAL_GetPALDirectory PAL_GetPALDirectoryA
  504. #endif
  505. PALIMPORT
  506. BOOL
  507. PALAPI
  508. PAL_Random(
  509. IN BOOL bStrong,
  510. IN OUT LPVOID lpBuffer,
  511. IN DWORD dwLength);
  512. // This helper will be used *only* by the CoreCLR to determine
  513. // if an address lies inside CoreCLR or not.
  514. //
  515. // This shouldnt be used by any other component that links into the PAL.
  516. PALIMPORT
  517. BOOL
  518. PALAPI
  519. PAL_IsIPInCoreCLR(IN PVOID address);
  520. #ifdef PLATFORM_UNIX
  521. PALIMPORT
  522. DWORD
  523. PALAPI
  524. PAL_CreateExecWatchpoint(
  525. HANDLE hThread,
  526. PVOID pvInstruction
  527. );
  528. PALIMPORT
  529. DWORD
  530. PALAPI
  531. PAL_DeleteExecWatchpoint(
  532. HANDLE hThread,
  533. PVOID pvInstruction
  534. );
  535. #endif
  536. /******************* winuser.h Entrypoints *******************************/
  537. PALIMPORT
  538. LPSTR
  539. PALAPI
  540. CharNextA(
  541. IN LPCSTR lpsz);
  542. PALIMPORT
  543. LPSTR
  544. PALAPI
  545. CharNextExA(
  546. IN WORD CodePage,
  547. IN LPCSTR lpCurrentChar,
  548. IN DWORD dwFlags);
  549. #ifndef UNICODE
  550. #define CharNext CharNextA
  551. #define CharNextEx CharNextExA
  552. #endif
  553. PALIMPORT
  554. int
  555. PALAPIV
  556. wsprintfA(
  557. OUT LPSTR,
  558. IN LPCSTR,
  559. ...);
  560. PALIMPORT
  561. int
  562. PALAPIV
  563. wsprintfW(
  564. OUT LPWSTR,
  565. IN LPCWSTR,
  566. ...);
  567. #ifdef UNICODE
  568. #define wsprintf wsprintfW
  569. #else
  570. #define wsprintf wsprintfA
  571. #endif
  572. #define MB_OK 0x00000000L
  573. #define MB_OKCANCEL 0x00000001L
  574. #define MB_ABORTRETRYIGNORE 0x00000002L
  575. #define MB_YESNO 0x00000004L
  576. #define MB_RETRYCANCEL 0x00000005L
  577. #define MB_ICONHAND 0x00000010L
  578. #define MB_ICONQUESTION 0x00000020L
  579. #define MB_ICONEXCLAMATION 0x00000030L
  580. #define MB_ICONASTERISK 0x00000040L
  581. #define MB_ICONINFORMATION MB_ICONASTERISK
  582. #define MB_ICONSTOP MB_ICONHAND
  583. #define MB_ICONERROR MB_ICONHAND
  584. #define MB_DEFBUTTON1 0x00000000L
  585. #define MB_DEFBUTTON2 0x00000100L
  586. #define MB_DEFBUTTON3 0x00000200L
  587. #define MB_SYSTEMMODAL 0x00001000L
  588. #define MB_TASKMODAL 0x00002000L
  589. #define MB_SETFOREGROUND 0x00010000L
  590. #define MB_TOPMOST 0x00040000L
  591. #define MB_NOFOCUS 0x00008000L
  592. #define MB_SETFOREGROUND 0x00010000L
  593. #define MB_DEFAULT_DESKTOP_ONLY 0x00020000L
  594. // Note: this is the NT 4.0 and greater value.
  595. #define MB_SERVICE_NOTIFICATION 0x00200000L
  596. #define MB_TYPEMASK 0x0000000FL
  597. #define MB_ICONMASK 0x000000F0L
  598. #define MB_DEFMASK 0x00000F00L
  599. #define IDOK 1
  600. #define IDCANCEL 2
  601. #define IDABORT 3
  602. #define IDRETRY 4
  603. #define IDIGNORE 5
  604. #define IDYES 6
  605. #define IDNO 7
  606. PALIMPORT
  607. int
  608. PALAPI
  609. MessageBoxW(
  610. IN LPVOID hWnd, // NOTE: diff from winuser.h
  611. IN LPCWSTR lpText,
  612. IN LPCWSTR lpCaption,
  613. IN UINT uType);
  614. PALIMPORT
  615. int
  616. PALAPI
  617. MessageBoxA(
  618. IN LPVOID hWnd, // NOTE: diff from winuser.h
  619. IN LPCSTR lpText,
  620. IN LPCSTR lpCaption,
  621. IN UINT uType);
  622. #ifdef UNICODE
  623. #define MessageBox MessageBoxW
  624. #else
  625. #define MessageBox MessageBoxA
  626. #endif
  627. /***************** wincon.h Entrypoints **********************************/
  628. #define CTRL_C_EVENT 0
  629. #define CTRL_BREAK_EVENT 1
  630. #define CTRL_CLOSE_EVENT 2
  631. // 3 is reserved!
  632. // 4 is reserved!
  633. #define CTRL_LOGOFF_EVENT 5
  634. #define CTRL_SHUTDOWN_EVENT 6
  635. typedef
  636. BOOL
  637. (PALAPI *PHANDLER_ROUTINE)(
  638. DWORD CtrlType
  639. );
  640. //end wincon.h Entrypoints
  641. // From win32.h
  642. #ifndef _CRTIMP
  643. #ifdef __llvm__
  644. #define _CRTIMP
  645. #else // __llvm__
  646. #define _CRTIMP __declspec(dllimport)
  647. #endif // __llvm__
  648. #endif // _CRTIMP
  649. /******************* winbase.h Entrypoints and defines ************************/
  650. PALIMPORT
  651. BOOL
  652. PALAPI
  653. AreFileApisANSI(
  654. VOID);
  655. typedef struct _SECURITY_ATTRIBUTES {
  656. DWORD nLength;
  657. LPVOID lpSecurityDescriptor;
  658. BOOL bInheritHandle;
  659. } SECURITY_ATTRIBUTES, *PSECURITY_ATTRIBUTES, *LPSECURITY_ATTRIBUTES;
  660. #define _SH_DENYWR 0x20 /* deny write mode */
  661. #define FILE_READ_DATA ( 0x0001 ) // file & pipe
  662. #define FILE_APPEND_DATA ( 0x0004 ) // file
  663. #define GENERIC_READ (0x80000000L)
  664. #define GENERIC_WRITE (0x40000000L)
  665. #define FILE_SHARE_READ 0x00000001
  666. #define FILE_SHARE_WRITE 0x00000002
  667. #define FILE_SHARE_DELETE 0x00000004
  668. #define CREATE_NEW 1
  669. #define CREATE_ALWAYS 2
  670. #define OPEN_EXISTING 3
  671. #define OPEN_ALWAYS 4
  672. #define TRUNCATE_EXISTING 5
  673. #define FILE_ATTRIBUTE_READONLY 0x00000001
  674. #define FILE_ATTRIBUTE_HIDDEN 0x00000002
  675. #define FILE_ATTRIBUTE_SYSTEM 0x00000004
  676. #define FILE_ATTRIBUTE_DIRECTORY 0x00000010
  677. #define FILE_ATTRIBUTE_ARCHIVE 0x00000020
  678. #define FILE_ATTRIBUTE_DEVICE 0x00000040
  679. #define FILE_ATTRIBUTE_NORMAL 0x00000080
  680. #define FILE_FLAG_WRITE_THROUGH 0x80000000
  681. #define FILE_FLAG_NO_BUFFERING 0x20000000
  682. #define FILE_FLAG_RANDOM_ACCESS 0x10000000
  683. #define FILE_FLAG_SEQUENTIAL_SCAN 0x08000000
  684. #define FILE_FLAG_BACKUP_SEMANTICS 0x02000000
  685. #define FILE_BEGIN 0
  686. #define FILE_CURRENT 1
  687. #define FILE_END 2
  688. #define STILL_ACTIVE (0x00000103L)
  689. #define INVALID_SET_FILE_POINTER ((DWORD)-1)
  690. PALIMPORT
  691. HANDLE
  692. PALAPI
  693. CreateFileA(
  694. IN LPCSTR lpFileName,
  695. IN DWORD dwDesiredAccess,
  696. IN DWORD dwShareMode,
  697. IN LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  698. IN DWORD dwCreationDisposition,
  699. IN DWORD dwFlagsAndAttributes,
  700. IN HANDLE hTemplateFile);
  701. PALIMPORT
  702. HANDLE
  703. PALAPI
  704. CreateFileW(
  705. IN LPCWSTR lpFileName,
  706. IN DWORD dwDesiredAccess,
  707. IN DWORD dwShareMode,
  708. IN LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  709. IN DWORD dwCreationDisposition,
  710. IN DWORD dwFlagsAndAttributes,
  711. IN HANDLE hTemplateFile);
  712. #ifdef UNICODE
  713. #define CreateFile CreateFileW
  714. #else
  715. #define CreateFile CreateFileA
  716. #endif
  717. PALIMPORT
  718. BOOL
  719. PALAPI
  720. LockFile(
  721. IN HANDLE hFile,
  722. IN DWORD dwFileOffsetLow,
  723. IN DWORD dwFileOffsetHigh,
  724. IN DWORD nNumberOfBytesToLockLow,
  725. IN DWORD nNumberOfBytesToLockHigh
  726. );
  727. PALIMPORT
  728. BOOL
  729. PALAPI
  730. UnlockFile(
  731. IN HANDLE hFile,
  732. IN DWORD dwFileOffsetLow,
  733. IN DWORD dwFileOffsetHigh,
  734. IN DWORD nNumberOfBytesToUnlockLow,
  735. IN DWORD nNumberOfBytesToUnlockHigh
  736. );
  737. PALIMPORT
  738. DWORD
  739. PALAPI
  740. SearchPathA(
  741. IN LPCSTR lpPath,
  742. IN LPCSTR lpFileName,
  743. IN LPCSTR lpExtension,
  744. IN DWORD nBufferLength,
  745. OUT LPSTR lpBuffer,
  746. OUT LPSTR *lpFilePart
  747. );
  748. PALIMPORT
  749. DWORD
  750. PALAPI
  751. SearchPathW(
  752. IN LPCWSTR lpPath,
  753. IN LPCWSTR lpFileName,
  754. IN LPCWSTR lpExtension,
  755. IN DWORD nBufferLength,
  756. OUT LPWSTR lpBuffer,
  757. OUT LPWSTR *lpFilePart
  758. );
  759. #ifdef UNICODE
  760. #define SearchPath SearchPathW
  761. #else
  762. #define SearchPath SearchPathA
  763. #endif // !UNICODE
  764. PALIMPORT
  765. BOOL
  766. PALAPI
  767. CopyFileA(
  768. IN LPCSTR lpExistingFileName,
  769. IN LPCSTR lpNewFileName,
  770. IN BOOL bFailIfExists);
  771. PALIMPORT
  772. BOOL
  773. PALAPI
  774. CopyFileW(
  775. IN LPCWSTR lpExistingFileName,
  776. IN LPCWSTR lpNewFileName,
  777. IN BOOL bFailIfExists);
  778. #ifdef UNICODE
  779. #define CopyFile CopyFileW
  780. #else
  781. #define CopyFile CopyFileA
  782. #endif
  783. PALIMPORT
  784. BOOL
  785. PALAPI
  786. DeleteFileA(
  787. IN LPCSTR lpFileName);
  788. PALIMPORT
  789. BOOL
  790. PALAPI
  791. DeleteFileW(
  792. IN LPCWSTR lpFileName);
  793. #ifdef UNICODE
  794. #define DeleteFile DeleteFileW
  795. #else
  796. #define DeleteFile DeleteFileA
  797. #endif
  798. PALIMPORT
  799. BOOL
  800. PALAPI
  801. MoveFileA(
  802. IN LPCSTR lpExistingFileName,
  803. IN LPCSTR lpNewFileName);
  804. PALIMPORT
  805. BOOL
  806. PALAPI
  807. MoveFileW(
  808. IN LPCWSTR lpExistingFileName,
  809. IN LPCWSTR lpNewFileName);
  810. #ifdef UNICODE
  811. #define MoveFile MoveFileW
  812. #else
  813. #define MoveFile MoveFileA
  814. #endif
  815. #define MOVEFILE_REPLACE_EXISTING 0x00000001
  816. #define MOVEFILE_COPY_ALLOWED 0x00000002
  817. PALIMPORT
  818. BOOL
  819. PALAPI
  820. MoveFileExA(
  821. IN LPCSTR lpExistingFileName,
  822. IN LPCSTR lpNewFileName,
  823. IN DWORD dwFlags);
  824. PALIMPORT
  825. BOOL
  826. PALAPI
  827. MoveFileExW(
  828. IN LPCWSTR lpExistingFileName,
  829. IN LPCWSTR lpNewFileName,
  830. IN DWORD dwFlags);
  831. #ifdef UNICODE
  832. #define MoveFileEx MoveFileExW
  833. #else
  834. #define MoveFileEx MoveFileExA
  835. #endif
  836. PALIMPORT
  837. BOOL
  838. PALAPI
  839. CreateDirectoryA(
  840. IN LPCSTR lpPathName,
  841. IN LPSECURITY_ATTRIBUTES lpSecurityAttributes);
  842. PALIMPORT
  843. BOOL
  844. PALAPI
  845. CreateDirectoryW(
  846. IN LPCWSTR lpPathName,
  847. IN LPSECURITY_ATTRIBUTES lpSecurityAttributes);
  848. #ifdef UNICODE
  849. #define CreateDirectory CreateDirectoryW
  850. #else
  851. #define CreateDirectory CreateDirectoryA
  852. #endif
  853. PALIMPORT
  854. BOOL
  855. PALAPI
  856. RemoveDirectoryW(
  857. IN LPCWSTR lpPathName);
  858. PALIMPORT
  859. BOOL
  860. PALAPI
  861. RemoveDirectoryA(
  862. IN LPCSTR lpPathName);
  863. #ifdef UNICODE
  864. #define RemoveDirectory RemoveDirectoryW
  865. #else
  866. #define RemoveDirectory RemoveDirectoryA
  867. #endif
  868. typedef struct _BY_HANDLE_FILE_INFORMATION {
  869. DWORD dwFileAttributes;
  870. FILETIME ftCreationTime;
  871. FILETIME ftLastAccessTime;
  872. FILETIME ftLastWriteTime;
  873. DWORD dwVolumeSerialNumber;
  874. DWORD nFileSizeHigh;
  875. DWORD nFileSizeLow;
  876. DWORD nNumberOfLinks;
  877. DWORD nFileIndexHigh;
  878. DWORD nFileIndexLow;
  879. } BY_HANDLE_FILE_INFORMATION, *PBY_HANDLE_FILE_INFORMATION, *LPBY_HANDLE_FILE_INFORMATION;
  880. typedef struct _WIN32_FIND_DATAA {
  881. DWORD dwFileAttributes;
  882. FILETIME ftCreationTime;
  883. FILETIME ftLastAccessTime;
  884. FILETIME ftLastWriteTime;
  885. DWORD nFileSizeHigh;
  886. DWORD nFileSizeLow;
  887. DWORD dwReserved0;
  888. DWORD dwReserved1;
  889. CHAR cFileName[ MAX_PATH_FNAME ];
  890. CHAR cAlternateFileName[ 14 ];
  891. } WIN32_FIND_DATAA, *PWIN32_FIND_DATAA, *LPWIN32_FIND_DATAA;
  892. typedef struct _WIN32_FIND_DATAW {
  893. DWORD dwFileAttributes;
  894. FILETIME ftCreationTime;
  895. FILETIME ftLastAccessTime;
  896. FILETIME ftLastWriteTime;
  897. DWORD nFileSizeHigh;
  898. DWORD nFileSizeLow;
  899. DWORD dwReserved0;
  900. DWORD dwReserved1;
  901. WCHAR cFileName[ MAX_PATH_FNAME ];
  902. WCHAR cAlternateFileName[ 14 ];
  903. } WIN32_FIND_DATAW, *PWIN32_FIND_DATAW, *LPWIN32_FIND_DATAW;
  904. #ifdef UNICODE
  905. typedef WIN32_FIND_DATAW WIN32_FIND_DATA;
  906. typedef PWIN32_FIND_DATAW PWIN32_FIND_DATA;
  907. typedef LPWIN32_FIND_DATAW LPWIN32_FIND_DATA;
  908. #else
  909. typedef WIN32_FIND_DATAA WIN32_FIND_DATA;
  910. typedef PWIN32_FIND_DATAA PWIN32_FIND_DATA;
  911. typedef LPWIN32_FIND_DATAA LPWIN32_FIND_DATA;
  912. #endif
  913. PALIMPORT
  914. HANDLE
  915. PALAPI
  916. FindFirstFileA(
  917. IN LPCSTR lpFileName,
  918. OUT LPWIN32_FIND_DATAA lpFindFileData);
  919. PALIMPORT
  920. HANDLE
  921. PALAPI
  922. FindFirstFileW(
  923. IN LPCWSTR lpFileName,
  924. OUT LPWIN32_FIND_DATAW lpFindFileData);
  925. #ifdef UNICODE
  926. #define FindFirstFile FindFirstFileW
  927. #else
  928. #define FindFirstFile FindFirstFileA
  929. #endif
  930. PALIMPORT
  931. BOOL
  932. PALAPI
  933. FindNextFileA(
  934. IN HANDLE hFindFile,
  935. OUT LPWIN32_FIND_DATAA lpFindFileData);
  936. PALIMPORT
  937. BOOL
  938. PALAPI
  939. FindNextFileW(
  940. IN HANDLE hFindFile,
  941. OUT LPWIN32_FIND_DATAW lpFindFileData);
  942. #ifdef UNICODE
  943. #define FindNextFile FindNextFileW
  944. #else
  945. #define FindNextFile FindNextFileA
  946. #endif
  947. PALIMPORT
  948. BOOL
  949. PALAPI
  950. FindClose(
  951. IN OUT HANDLE hFindFile);
  952. PALIMPORT
  953. DWORD
  954. PALAPI
  955. GetFileAttributesA(
  956. IN LPCSTR lpFileName);
  957. PALIMPORT
  958. DWORD
  959. PALAPI
  960. GetFileAttributesW(
  961. IN LPCWSTR lpFileName);
  962. #ifdef UNICODE
  963. #define GetFileAttributes GetFileAttributesW
  964. #else
  965. #define GetFileAttributes GetFileAttributesA
  966. #endif
  967. typedef enum _GET_FILEEX_INFO_LEVELS {
  968. GetFileExInfoStandard
  969. } GET_FILEEX_INFO_LEVELS;
  970. typedef struct _WIN32_FILE_ATTRIBUTE_DATA {
  971. DWORD dwFileAttributes;
  972. FILETIME ftCreationTime;
  973. FILETIME ftLastAccessTime;
  974. FILETIME ftLastWriteTime;
  975. DWORD nFileSizeHigh;
  976. DWORD nFileSizeLow;
  977. } WIN32_FILE_ATTRIBUTE_DATA, *LPWIN32_FILE_ATTRIBUTE_DATA;
  978. PALIMPORT
  979. BOOL
  980. PALAPI
  981. GetFileAttributesExW(
  982. IN LPCWSTR lpFileName,
  983. IN GET_FILEEX_INFO_LEVELS fInfoLevelId,
  984. OUT LPVOID lpFileInformation);
  985. #ifdef UNICODE
  986. #define GetFileAttributesEx GetFileAttributesExW
  987. #endif
  988. PALIMPORT
  989. BOOL
  990. PALAPI
  991. SetFileAttributesA(
  992. IN LPCSTR lpFileName,
  993. IN DWORD dwFileAttributes);
  994. PALIMPORT
  995. BOOL
  996. PALAPI
  997. SetFileAttributesW(
  998. IN LPCWSTR lpFileName,
  999. IN DWORD dwFileAttributes);
  1000. #ifdef UNICODE
  1001. #define SetFileAttributes SetFileAttributesW
  1002. #else
  1003. #define SetFileAttributes SetFileAttributesA
  1004. #endif
  1005. typedef LPVOID LPOVERLAPPED; // diff from winbase.h
  1006. PALIMPORT
  1007. BOOL
  1008. PALAPI
  1009. WriteFile(
  1010. IN HANDLE hFile,
  1011. IN LPCVOID lpBuffer,
  1012. IN DWORD nNumberOfBytesToWrite,
  1013. OUT LPDWORD lpNumberOfBytesWritten,
  1014. IN LPOVERLAPPED lpOverlapped);
  1015. PALIMPORT
  1016. BOOL
  1017. PALAPI
  1018. ReadFile(
  1019. IN HANDLE hFile,
  1020. OUT LPVOID lpBuffer,
  1021. IN DWORD nNumberOfBytesToRead,
  1022. OUT LPDWORD lpNumberOfBytesRead,
  1023. IN LPOVERLAPPED lpOverlapped);
  1024. #define STD_INPUT_HANDLE ((DWORD)-10)
  1025. #define STD_OUTPUT_HANDLE ((DWORD)-11)
  1026. #define STD_ERROR_HANDLE ((DWORD)-12)
  1027. PALIMPORT
  1028. HANDLE
  1029. PALAPI
  1030. GetStdHandle(
  1031. IN DWORD nStdHandle);
  1032. PALIMPORT
  1033. BOOL
  1034. PALAPI
  1035. SetEndOfFile(
  1036. IN HANDLE hFile);
  1037. PALIMPORT
  1038. DWORD
  1039. PALAPI
  1040. SetFilePointer(
  1041. IN HANDLE hFile,
  1042. IN LONG lDistanceToMove,
  1043. IN PLONG lpDistanceToMoveHigh,
  1044. IN DWORD dwMoveMethod);
  1045. PALIMPORT
  1046. BOOL
  1047. PALAPI
  1048. SetFilePointerEx(
  1049. IN HANDLE hFile,
  1050. IN LARGE_INTEGER liDistanceToMove,
  1051. OUT PLARGE_INTEGER lpNewFilePointer,
  1052. IN DWORD dwMoveMethod);
  1053. PALIMPORT
  1054. DWORD
  1055. PALAPI
  1056. GetFileSize(
  1057. IN HANDLE hFile,
  1058. OUT LPDWORD lpFileSizeHigh);
  1059. PALIMPORT
  1060. BOOL
  1061. PALAPI GetFileSizeEx(
  1062. IN HANDLE hFile,
  1063. OUT PLARGE_INTEGER lpFileSize);
  1064. PALIMPORT
  1065. BOOL
  1066. PALAPI
  1067. GetFileInformationByHandle(
  1068. IN HANDLE hFile,
  1069. OUT BY_HANDLE_FILE_INFORMATION* lpFileInformation);
  1070. PALIMPORT
  1071. LONG
  1072. PALAPI
  1073. CompareFileTime(
  1074. IN CONST FILETIME *lpFileTime1,
  1075. IN CONST FILETIME *lpFileTime2);
  1076. PALIMPORT
  1077. BOOL
  1078. PALAPI
  1079. SetFileTime(
  1080. IN HANDLE hFile,
  1081. IN CONST FILETIME *lpCreationTime,
  1082. IN CONST FILETIME *lpLastAccessTime,
  1083. IN CONST FILETIME *lpLastWriteTime);
  1084. PALIMPORT
  1085. BOOL
  1086. PALAPI
  1087. GetFileTime(
  1088. IN HANDLE hFile,
  1089. OUT LPFILETIME lpCreationTime,
  1090. OUT LPFILETIME lpLastAccessTime,
  1091. OUT LPFILETIME lpLastWriteTime);
  1092. PALIMPORT
  1093. VOID
  1094. PALAPI
  1095. GetSystemTimeAsFileTime(
  1096. OUT LPFILETIME lpSystemTimeAsFileTime);
  1097. typedef struct _SYSTEMTIME {
  1098. WORD wYear;
  1099. WORD wMonth;
  1100. WORD wDayOfWeek;
  1101. WORD wDay;
  1102. WORD wHour;
  1103. WORD wMinute;
  1104. WORD wSecond;
  1105. WORD wMilliseconds;
  1106. } SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;
  1107. PALIMPORT
  1108. VOID
  1109. PALAPI
  1110. GetSystemTime(
  1111. OUT LPSYSTEMTIME lpSystemTime);
  1112. PALIMPORT
  1113. BOOL
  1114. PALAPI
  1115. FileTimeToSystemTime(
  1116. IN CONST FILETIME *lpFileTime,
  1117. OUT LPSYSTEMTIME lpSystemTime);
  1118. PALIMPORT
  1119. BOOL
  1120. PALAPI
  1121. FileTimeToDosDateTime(
  1122. IN CONST FILETIME *lpFileTime,
  1123. OUT LPWORD lpFatDate,
  1124. OUT LPWORD lpFatTime
  1125. );
  1126. PALIMPORT
  1127. BOOL
  1128. PALAPI
  1129. FlushFileBuffers(
  1130. IN HANDLE hFile);
  1131. #define FILE_TYPE_UNKNOWN 0x0000
  1132. #define FILE_TYPE_DISK 0x0001
  1133. #define FILE_TYPE_CHAR 0x0002
  1134. #define FILE_TYPE_PIPE 0x0003
  1135. #define FILE_TYPE_REMOTE 0x8000
  1136. PALIMPORT
  1137. DWORD
  1138. PALAPI
  1139. GetFileType(
  1140. IN HANDLE hFile);
  1141. PALIMPORT
  1142. UINT
  1143. PALAPI
  1144. GetConsoleCP(
  1145. VOID);
  1146. PALIMPORT
  1147. UINT
  1148. PALAPI
  1149. GetConsoleOutputCP(
  1150. VOID);
  1151. PALIMPORT
  1152. DWORD
  1153. PALAPI
  1154. GetFullPathNameA(
  1155. IN LPCSTR lpFileName,
  1156. IN DWORD nBufferLength,
  1157. OUT LPSTR lpBuffer,
  1158. OUT LPSTR *lpFilePart);
  1159. PALIMPORT
  1160. DWORD
  1161. PALAPI
  1162. GetFullPathNameW(
  1163. IN LPCWSTR lpFileName,
  1164. IN DWORD nBufferLength,
  1165. OUT LPWSTR lpBuffer,
  1166. OUT LPWSTR *lpFilePart);
  1167. #ifdef UNICODE
  1168. #define GetFullPathName GetFullPathNameW
  1169. #else
  1170. #define GetFullPathName GetFullPathNameA
  1171. #endif
  1172. PALIMPORT
  1173. DWORD
  1174. PALAPI
  1175. GetLongPathNameW(
  1176. IN LPCWSTR lpszShortPath,
  1177. OUT LPWSTR lpszLongPath,
  1178. IN DWORD cchBuffer);
  1179. #ifdef UNICODE
  1180. #define GetLongPathName GetLongPathNameW
  1181. #endif
  1182. PALIMPORT
  1183. DWORD
  1184. PALAPI
  1185. GetShortPathNameW(
  1186. IN LPCWSTR lpszLongPath,
  1187. OUT LPWSTR lpszShortPath,
  1188. IN DWORD cchBuffer);
  1189. #ifdef UNICODE
  1190. #define GetShortPathName GetShortPathNameW
  1191. #endif
  1192. PALIMPORT
  1193. UINT
  1194. PALAPI
  1195. GetTempFileNameA(
  1196. IN LPCSTR lpPathName,
  1197. IN LPCSTR lpPrefixString,
  1198. IN UINT uUnique,
  1199. OUT LPSTR lpTempFileName);
  1200. PALIMPORT
  1201. UINT
  1202. PALAPI
  1203. GetTempFileNameW(
  1204. IN LPCWSTR lpPathName,
  1205. IN LPCWSTR lpPrefixString,
  1206. IN UINT uUnique,
  1207. OUT LPWSTR lpTempFileName);
  1208. #ifdef UNICODE
  1209. #define GetTempFileName GetTempFileNameW
  1210. #else
  1211. #define GetTempFileName GetTempFileNameA
  1212. #endif
  1213. PALIMPORT
  1214. DWORD
  1215. PALAPI
  1216. GetTempPathA(
  1217. IN DWORD nBufferLength,
  1218. OUT LPSTR lpBuffer);
  1219. PALIMPORT
  1220. DWORD
  1221. PALAPI
  1222. GetTempPathW(
  1223. IN DWORD nBufferLength,
  1224. OUT LPWSTR lpBuffer);
  1225. #ifdef UNICODE
  1226. #define GetTempPath GetTempPathW
  1227. #else
  1228. #define GetTempPath GetTempPathA
  1229. #endif
  1230. PALIMPORT
  1231. DWORD
  1232. PALAPI
  1233. GetCurrentDirectoryA(
  1234. IN DWORD nBufferLength,
  1235. OUT LPSTR lpBuffer);
  1236. PALIMPORT
  1237. DWORD
  1238. PALAPI
  1239. GetCurrentDirectoryW(
  1240. IN DWORD nBufferLength,
  1241. OUT LPWSTR lpBuffer);
  1242. #ifdef UNICODE
  1243. #define GetCurrentDirectory GetCurrentDirectoryW
  1244. #else
  1245. #define GetCurrentDirectory GetCurrentDirectoryA
  1246. #endif
  1247. PALIMPORT
  1248. BOOL
  1249. PALAPI
  1250. SetCurrentDirectoryA(
  1251. IN LPCSTR lpPathName);
  1252. PALIMPORT
  1253. BOOL
  1254. PALAPI
  1255. SetCurrentDirectoryW(
  1256. IN LPCWSTR lpPathName);
  1257. #ifdef UNICODE
  1258. #define SetCurrentDirectory SetCurrentDirectoryW
  1259. #else
  1260. #define SetCurrentDirectory SetCurrentDirectoryA
  1261. #endif
  1262. // maximum length of the NETBIOS name (not including NULL)
  1263. #define MAX_COMPUTERNAME_LENGTH 15
  1264. // maximum length of the username (not including NULL)
  1265. #define UNLEN 256
  1266. PALIMPORT
  1267. BOOL
  1268. PALAPI
  1269. GetUserNameW(
  1270. OUT LPWSTR lpBuffer, // address of name buffer
  1271. IN OUT LPDWORD nSize ); // address of size of name buffer
  1272. PALIMPORT
  1273. BOOL
  1274. PALAPI
  1275. GetComputerNameW(
  1276. OUT LPWSTR lpBuffer, // address of name buffer
  1277. IN OUT LPDWORD nSize); // address of size of name buffer
  1278. #ifdef UNICODE
  1279. #define GetUserName GetUserNameW
  1280. #define GetComputerName GetComputerNameW
  1281. #endif // UNICODE
  1282. PALIMPORT
  1283. HANDLE
  1284. PALAPI
  1285. CreateSemaphoreA(
  1286. IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
  1287. IN LONG lInitialCount,
  1288. IN LONG lMaximumCount,
  1289. IN LPCSTR lpName);
  1290. PALIMPORT
  1291. HANDLE
  1292. PALAPI
  1293. CreateSemaphoreExA(
  1294. IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
  1295. IN LONG lInitialCount,
  1296. IN LONG lMaximumCount,
  1297. IN LPCSTR lpName,
  1298. IN /*_Reserved_*/ DWORD dwFlags,
  1299. IN DWORD dwDesiredAccess);
  1300. PALIMPORT
  1301. HANDLE
  1302. PALAPI
  1303. CreateSemaphoreW(
  1304. IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
  1305. IN LONG lInitialCount,
  1306. IN LONG lMaximumCount,
  1307. IN LPCWSTR lpName);
  1308. PALIMPORT
  1309. HANDLE
  1310. PALAPI
  1311. CreateSemaphoreExW(
  1312. IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
  1313. IN LONG lInitialCount,
  1314. IN LONG lMaximumCount,
  1315. IN LPCWSTR lpName,
  1316. IN /*_Reserved_*/ DWORD dwFlags,
  1317. IN DWORD dwDesiredAccess);
  1318. PALIMPORT
  1319. HANDLE
  1320. PALAPI
  1321. OpenSemaphoreW(
  1322. IN DWORD dwDesiredAccess,
  1323. IN BOOL bInheritHandle,
  1324. IN LPCWSTR lpName);
  1325. #ifdef UNICODE
  1326. #define CreateSemaphore CreateSemaphoreW
  1327. #define CreateSemaphoreEx CreateSemaphoreExW
  1328. #else
  1329. #define CreateSemaphore CreateSemaphoreA
  1330. #define CreateSemaphoreEx CreateSemaphoreExA
  1331. #endif
  1332. PALIMPORT
  1333. BOOL
  1334. PALAPI
  1335. ReleaseSemaphore(
  1336. IN HANDLE hSemaphore,
  1337. IN LONG lReleaseCount,
  1338. OUT LPLONG lpPreviousCount);
  1339. PALIMPORT
  1340. HANDLE
  1341. PALAPI
  1342. CreateEventA(
  1343. IN LPSECURITY_ATTRIBUTES lpEventAttributes,
  1344. IN BOOL bManualReset,
  1345. IN BOOL bInitialState,
  1346. IN LPCSTR lpName);
  1347. PALIMPORT
  1348. HANDLE
  1349. PALAPI
  1350. CreateEventW(
  1351. IN LPSECURITY_ATTRIBUTES lpEventAttributes,
  1352. IN BOOL bManualReset,
  1353. IN BOOL bInitialState,
  1354. IN LPCWSTR lpName);
  1355. #ifdef UNICODE
  1356. #define CreateEvent CreateEventW
  1357. #else
  1358. #define CreateEvent CreateEventA
  1359. #endif
  1360. PALIMPORT
  1361. BOOL
  1362. PALAPI
  1363. SetEvent(
  1364. IN HANDLE hEvent);
  1365. PALIMPORT
  1366. BOOL
  1367. PALAPI
  1368. ResetEvent(
  1369. IN HANDLE hEvent);
  1370. PALIMPORT
  1371. HANDLE
  1372. PALAPI
  1373. OpenEventW(
  1374. IN DWORD dwDesiredAccess,
  1375. IN BOOL bInheritHandle,
  1376. IN LPCWSTR lpName);
  1377. #ifdef UNICODE
  1378. #define OpenEvent OpenEventW
  1379. #endif
  1380. PALIMPORT
  1381. HANDLE
  1382. PALAPI
  1383. CreateMutexW(
  1384. IN LPSECURITY_ATTRIBUTES lpMutexAttributes,
  1385. IN BOOL bInitialOwner,
  1386. IN LPCWSTR lpName);
  1387. PALIMPORT
  1388. HANDLE
  1389. PALAPI
  1390. CreateMutexA(
  1391. IN LPSECURITY_ATTRIBUTES lpMutexAttributes,
  1392. IN BOOL bInitialOwner,
  1393. IN LPCSTR lpName);
  1394. #ifdef UNICODE
  1395. #define CreateMutex CreateMutexW
  1396. #else
  1397. #define CreateMutex CreateMutexA
  1398. #endif
  1399. PALIMPORT
  1400. HANDLE
  1401. PALAPI
  1402. OpenMutexW(
  1403. IN DWORD dwDesiredAccess,
  1404. IN BOOL bInheritHandle,
  1405. IN LPCWSTR lpName);
  1406. PALIMPORT
  1407. HANDLE
  1408. PALAPI
  1409. OpenMutexA(
  1410. IN DWORD dwDesiredAccess,
  1411. IN BOOL bInheritHandle,
  1412. IN LPCSTR lpName);
  1413. #ifdef UNICODE
  1414. #define OpenMutex OpenMutexW
  1415. #else
  1416. #define OpenMutex OpenMutexA
  1417. #endif // UNICODE
  1418. PALIMPORT
  1419. BOOL
  1420. PALAPI
  1421. ReleaseMutex(
  1422. IN HANDLE hMutex);
  1423. PALIMPORT
  1424. DWORD
  1425. PALAPI
  1426. GetCurrentProcessId(
  1427. VOID);
  1428. PALIMPORT
  1429. HANDLE
  1430. PALAPI
  1431. GetCurrentProcess(
  1432. VOID);
  1433. PALIMPORT
  1434. DWORD
  1435. PALAPI
  1436. GetCurrentThreadId(
  1437. VOID);
  1438. // To work around multiply-defined symbols in the Carbon framework.
  1439. #define GetCurrentThread PAL_GetCurrentThread
  1440. PALIMPORT
  1441. HANDLE
  1442. PALAPI
  1443. GetCurrentThread(
  1444. VOID);
  1445. #define STARTF_USESTDHANDLES 0x00000100
  1446. typedef struct _STARTUPINFOW {
  1447. DWORD cb;
  1448. LPWSTR lpReserved_PAL_Undefined;
  1449. LPWSTR lpDesktop_PAL_Undefined;
  1450. LPWSTR lpTitle_PAL_Undefined;
  1451. DWORD dwX_PAL_Undefined;
  1452. DWORD dwY_PAL_Undefined;
  1453. DWORD dwXSize_PAL_Undefined;
  1454. DWORD dwYSize_PAL_Undefined;
  1455. DWORD dwXCountChars_PAL_Undefined;
  1456. DWORD dwYCountChars_PAL_Undefined;
  1457. DWORD dwFillAttribute_PAL_Undefined;
  1458. DWORD dwFlags;
  1459. WORD wShowWindow_PAL_Undefined;
  1460. WORD cbReserved2_PAL_Undefined;
  1461. LPBYTE lpReserved2_PAL_Undefined;
  1462. HANDLE hStdInput;
  1463. HANDLE hStdOutput;
  1464. HANDLE hStdError;
  1465. } STARTUPINFOW, *LPSTARTUPINFOW;
  1466. typedef struct _STARTUPINFOA {
  1467. DWORD cb;
  1468. LPSTR lpReserved_PAL_Undefined;
  1469. LPSTR lpDesktop_PAL_Undefined;
  1470. LPSTR lpTitle_PAL_Undefined;
  1471. DWORD dwX_PAL_Undefined;
  1472. DWORD dwY_PAL_Undefined;
  1473. DWORD dwXSize_PAL_Undefined;
  1474. DWORD dwYSize_PAL_Undefined;
  1475. DWORD dwXCountChars_PAL_Undefined;
  1476. DWORD dwYCountChars_PAL_Undefined;
  1477. DWORD dwFillAttribute_PAL_Undefined;
  1478. DWORD dwFlags;
  1479. WORD wShowWindow_PAL_Undefined;
  1480. WORD cbReserved2_PAL_Undefined;
  1481. LPBYTE lpReserved2_PAL_Undefined;
  1482. HANDLE hStdInput;
  1483. HANDLE hStdOutput;
  1484. HANDLE hStdError;
  1485. } STARTUPINFOA, *LPSTARTUPINFOA;
  1486. #ifdef UNICODE
  1487. typedef STARTUPINFOW STARTUPINFO;
  1488. typedef LPSTARTUPINFOW LPSTARTUPINFO;
  1489. #else
  1490. typedef STARTUPINFOA STARTUPINFO;
  1491. typedef LPSTARTUPINFOW LPSTARTUPINFO;
  1492. #endif
  1493. #define CREATE_NEW_CONSOLE 0x00000010
  1494. #define NORMAL_PRIORITY_CLASS 0x00000020
  1495. typedef struct _PROCESS_INFORMATION {
  1496. HANDLE hProcess;
  1497. HANDLE hThread;
  1498. DWORD dwProcessId;
  1499. DWORD dwThreadId_PAL_Undefined;
  1500. } PROCESS_INFORMATION, *PPROCESS_INFORMATION, *LPPROCESS_INFORMATION;
  1501. PALIMPORT
  1502. BOOL
  1503. PALAPI
  1504. CreateProcessA(
  1505. IN LPCSTR lpApplicationName,
  1506. IN LPSTR lpCommandLine,
  1507. IN LPSECURITY_ATTRIBUTES lpProcessAttributes,
  1508. IN LPSECURITY_ATTRIBUTES lpThreadAttributes,
  1509. IN BOOL bInheritHandles,
  1510. IN DWORD dwCreationFlags,
  1511. IN LPVOID lpEnvironment,
  1512. IN LPCSTR lpCurrentDirectory,
  1513. IN LPSTARTUPINFOA lpStartupInfo,
  1514. OUT LPPROCESS_INFORMATION lpProcessInformation);
  1515. PALIMPORT
  1516. BOOL
  1517. PALAPI
  1518. CreateProcessW(
  1519. IN LPCWSTR lpApplicationName,
  1520. IN LPWSTR lpCommandLine,
  1521. IN LPSECURITY_ATTRIBUTES lpProcessAttributes,
  1522. IN LPSECURITY_ATTRIBUTES lpThreadAttributes,
  1523. IN BOOL bInheritHandles,
  1524. IN DWORD dwCreationFlags,
  1525. IN LPVOID lpEnvironment,
  1526. IN LPCWSTR lpCurrentDirectory,
  1527. IN LPSTARTUPINFOW lpStartupInfo,
  1528. OUT LPPROCESS_INFORMATION lpProcessInformation);
  1529. #ifdef UNICODE
  1530. #define CreateProcess CreateProcessW
  1531. #else
  1532. #define CreateProcess CreateProcessA
  1533. #endif
  1534. PALIMPORT
  1535. PAL_NORETURN
  1536. VOID
  1537. PALAPI
  1538. ExitProcess(
  1539. IN UINT uExitCode);
  1540. PALIMPORT
  1541. BOOL
  1542. PALAPI
  1543. TerminateProcess(
  1544. IN HANDLE hProcess,
  1545. IN UINT uExitCode);
  1546. PALIMPORT
  1547. BOOL
  1548. PALAPI
  1549. GetExitCodeProcess(
  1550. IN HANDLE hProcess,
  1551. IN LPDWORD lpExitCode);
  1552. PALIMPORT
  1553. BOOL
  1554. PALAPI
  1555. GetProcessTimes(
  1556. IN HANDLE hProcess,
  1557. OUT LPFILETIME lpCreationTime,
  1558. OUT LPFILETIME lpExitTime,
  1559. OUT LPFILETIME lpKernelTime,
  1560. OUT LPFILETIME lpUserTime);
  1561. #define MAXIMUM_WAIT_OBJECTS 64
  1562. #define WAIT_OBJECT_0 0
  1563. #define WAIT_ABANDONED 0x00000080
  1564. #define WAIT_ABANDONED_0 0x00000080
  1565. #define WAIT_TIMEOUT 258
  1566. #define WAIT_FAILED ((DWORD)0xFFFFFFFF)
  1567. #define INFINITE 0xFFFFFFFF // Infinite timeout
  1568. PALIMPORT
  1569. DWORD
  1570. PALAPI
  1571. WaitForSingleObject(
  1572. IN HANDLE hHandle,
  1573. IN DWORD dwMilliseconds);
  1574. PALIMPORT
  1575. DWORD
  1576. PALAPI
  1577. WaitForSingleObjectEx(
  1578. IN HANDLE hHandle,
  1579. IN DWORD dwMilliseconds,
  1580. IN BOOL bAlertable);
  1581. PALIMPORT
  1582. DWORD
  1583. PALAPI
  1584. WaitForMultipleObjects(
  1585. IN DWORD nCount,
  1586. IN CONST HANDLE *lpHandles,
  1587. IN BOOL bWaitAll,
  1588. IN DWORD dwMilliseconds);
  1589. PALIMPORT
  1590. DWORD
  1591. PALAPI
  1592. WaitForMultipleObjectsEx(
  1593. IN DWORD nCount,
  1594. IN CONST HANDLE *lpHandles,
  1595. IN BOOL bWaitAll,
  1596. IN DWORD dwMilliseconds,
  1597. IN BOOL bAlertable);
  1598. PALIMPORT
  1599. RHANDLE
  1600. PALAPI
  1601. PAL_LocalHandleToRemote(
  1602. IN HANDLE hLocal);
  1603. PALIMPORT
  1604. HANDLE
  1605. PALAPI
  1606. PAL_RemoteHandleToLocal(
  1607. IN RHANDLE hRemote);
  1608. #define DUPLICATE_CLOSE_SOURCE 0x00000001
  1609. #define DUPLICATE_SAME_ACCESS 0x00000002
  1610. PALIMPORT
  1611. BOOL
  1612. PALAPI
  1613. DuplicateHandle(
  1614. IN HANDLE hSourceProcessHandle,
  1615. IN HANDLE hSourceHandle,
  1616. IN HANDLE hTargetProcessHandle,
  1617. OUT LPHANDLE lpTargetHandle,
  1618. IN DWORD dwDesiredAccess,
  1619. IN BOOL bInheritHandle,
  1620. IN DWORD dwOptions);
  1621. PALIMPORT
  1622. VOID
  1623. PALAPI
  1624. Sleep(
  1625. IN DWORD dwMilliseconds);
  1626. PALIMPORT
  1627. DWORD
  1628. PALAPI
  1629. SleepEx(
  1630. IN DWORD dwMilliseconds,
  1631. IN BOOL bAlertable);
  1632. PALIMPORT
  1633. BOOL
  1634. PALAPI
  1635. SwitchToThread(
  1636. VOID);
  1637. #define DEBUG_PROCESS 0x00000001
  1638. #define DEBUG_ONLY_THIS_PROCESS 0x00000002
  1639. #define CREATE_SUSPENDED 0x00000004
  1640. #define STACK_SIZE_PARAM_IS_A_RESERVATION 0x00010000
  1641. PALIMPORT
  1642. HANDLE
  1643. PALAPI
  1644. CreateThread(
  1645. IN LPSECURITY_ATTRIBUTES lpThreadAttributes,
  1646. IN DWORD dwStackSize,
  1647. IN LPTHREAD_START_ROUTINE lpStartAddress,
  1648. IN LPVOID lpParameter,
  1649. IN DWORD dwCreationFlags,
  1650. OUT LPDWORD lpThreadId);
  1651. PALIMPORT
  1652. PAL_NORETURN
  1653. VOID
  1654. PALAPI
  1655. ExitThread(
  1656. IN DWORD dwExitCode);
  1657. PALIMPORT
  1658. BOOL
  1659. PALAPI
  1660. GetExitCodeThread(
  1661. IN HANDLE hThread,
  1662. IN LPDWORD lpExitCode);
  1663. PALIMPORT
  1664. DWORD
  1665. PALAPI
  1666. ResumeThread(
  1667. IN HANDLE hThread);
  1668. typedef VOID (PALAPI *PAPCFUNC)(ULONG_PTR dwParam);
  1669. PALIMPORT
  1670. DWORD
  1671. PALAPI
  1672. QueueUserAPC(
  1673. IN PAPCFUNC pfnAPC,
  1674. IN HANDLE hThread,
  1675. IN ULONG_PTR dwData);
  1676. #ifdef _X86_
  1677. //
  1678. // ***********************************************************************************
  1679. //
  1680. // NOTE: These context definitions are replicated in ndp/clr/src/debug/inc/DbgTargetContext.h (for the
  1681. // purposes manipulating contexts from different platforms during remote debugging). Be sure to keep those
  1682. // definitions in sync if you make any changes here.
  1683. //
  1684. // ***********************************************************************************
  1685. //
  1686. #define SIZE_OF_80387_REGISTERS 80
  1687. #define CONTEXT_i386 0x00010000
  1688. #define CONTEXT_CONTROL (CONTEXT_i386 | 0x00000001L) // SS:SP, CS:IP, FLAGS, BP
  1689. #define CONTEXT_INTEGER (CONTEXT_i386 | 0x00000002L) // AX, BX, CX, DX, SI, DI
  1690. #define CONTEXT_SEGMENTS (CONTEXT_i386 | 0x00000004L)
  1691. #define CONTEXT_FLOATING_POINT (CONTEXT_i386 | 0x00000008L) // 387 state
  1692. #define CONTEXT_DEBUG_REGISTERS (CONTEXT_i386 | 0x00000010L)
  1693. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS)
  1694. #define CONTEXT_EXTENDED_REGISTERS (CONTEXT_i386 | 0x00000020L)
  1695. #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS | CONTEXT_EXTENDED_REGISTERS)
  1696. #define MAXIMUM_SUPPORTED_EXTENSION 512
  1697. typedef struct _FLOATING_SAVE_AREA {
  1698. DWORD ControlWord;
  1699. DWORD StatusWord;
  1700. DWORD TagWord;
  1701. DWORD ErrorOffset;
  1702. DWORD ErrorSelector;
  1703. DWORD DataOffset;
  1704. DWORD DataSelector;
  1705. BYTE RegisterArea[SIZE_OF_80387_REGISTERS];
  1706. DWORD Cr0NpxState;
  1707. } FLOATING_SAVE_AREA;
  1708. typedef FLOATING_SAVE_AREA *PFLOATING_SAVE_AREA;
  1709. typedef struct _CONTEXT {
  1710. ULONG ContextFlags;
  1711. ULONG Dr0_PAL_Undefined;
  1712. ULONG Dr1_PAL_Undefined;
  1713. ULONG Dr2_PAL_Undefined;
  1714. ULONG Dr3_PAL_Undefined;
  1715. ULONG Dr6_PAL_Undefined;
  1716. ULONG Dr7_PAL_Undefined;
  1717. FLOATING_SAVE_AREA FloatSave;
  1718. ULONG SegGs_PAL_Undefined;
  1719. ULONG SegFs_PAL_Undefined;
  1720. ULONG SegEs_PAL_Undefined;
  1721. ULONG SegDs_PAL_Undefined;
  1722. ULONG Edi;
  1723. ULONG Esi;
  1724. ULONG Ebx;
  1725. ULONG Edx;
  1726. ULONG Ecx;
  1727. ULONG Eax;
  1728. ULONG Ebp;
  1729. ULONG Eip;
  1730. ULONG SegCs;
  1731. ULONG EFlags;
  1732. ULONG Esp;
  1733. ULONG SegSs;
  1734. UCHAR ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
  1735. } CONTEXT, *PCONTEXT, *LPCONTEXT;
  1736. // To support saving and loading xmm register context we need to know the offset in the ExtendedRegisters
  1737. // section at which they are stored. This has been determined experimentally since I have found no
  1738. // documentation thus far but it corresponds to the offset we'd expect if a fxsave instruction was used to
  1739. // store the regular FP state along with the XMM registers at the start of the extended registers section.
  1740. // Technically the offset doesn't really matter if no code in the PAL or runtime knows what the offset should
  1741. // be either (as long as we're consistent across GetThreadContext() and SetThreadContext() and we don't
  1742. // support any other values in the ExtendedRegisters) but we might as well be as accurate as we can.
  1743. #define CONTEXT_EXREG_XMM_OFFSET 160
  1744. #elif defined(_PPC_)
  1745. //
  1746. // ***********************************************************************************
  1747. //
  1748. // NOTE: These context definitions are replicated in ndp/clr/src/debug/inc/DbgTargetContext.h (for the
  1749. // purposes manipulating contexts from different platforms during remote debugging). Be sure to keep those
  1750. // definitions in sync if you make any changes here.
  1751. //
  1752. // ***********************************************************************************
  1753. //
  1754. #define CONTEXT_CONTROL 0x00000001L
  1755. #define CONTEXT_FLOATING_POINT 0x00000002L
  1756. #define CONTEXT_INTEGER 0x00000004L
  1757. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
  1758. #define CONTEXT_ALL CONTEXT_FULL
  1759. typedef struct _CONTEXT {
  1760. //
  1761. // This section is specified/returned if the ContextFlags word contains
  1762. // the flag CONTEXT_FLOATING_POINT.
  1763. //
  1764. double Fpr0; // Floating registers 0..31
  1765. double Fpr1;
  1766. double Fpr2;
  1767. double Fpr3;
  1768. double Fpr4;
  1769. double Fpr5;
  1770. double Fpr6;
  1771. double Fpr7;
  1772. double Fpr8;
  1773. double Fpr9;
  1774. double Fpr10;
  1775. double Fpr11;
  1776. double Fpr12;
  1777. double Fpr13;
  1778. double Fpr14;
  1779. double Fpr15;
  1780. double Fpr16;
  1781. double Fpr17;
  1782. double Fpr18;
  1783. double Fpr19;
  1784. double Fpr20;
  1785. double Fpr21;
  1786. double Fpr22;
  1787. double Fpr23;
  1788. double Fpr24;
  1789. double Fpr25;
  1790. double Fpr26;
  1791. double Fpr27;
  1792. double Fpr28;
  1793. double Fpr29;
  1794. double Fpr30;
  1795. double Fpr31;
  1796. double Fpscr; // Floating point status/control reg
  1797. //
  1798. // This section is specified/returned if the ContextFlags word contains
  1799. // the flag CONTEXT_INTEGER.
  1800. //
  1801. ULONG Gpr0; // General registers 0..31
  1802. ULONG Gpr1; // StackPointer
  1803. ULONG Gpr2;
  1804. ULONG Gpr3;
  1805. ULONG Gpr4;
  1806. ULONG Gpr5;
  1807. ULONG Gpr6;
  1808. ULONG Gpr7;
  1809. ULONG Gpr8;
  1810. ULONG Gpr9;
  1811. ULONG Gpr10;
  1812. ULONG Gpr11;
  1813. ULONG Gpr12;
  1814. ULONG Gpr13;
  1815. ULONG Gpr14;
  1816. ULONG Gpr15;
  1817. ULONG Gpr16;
  1818. ULONG Gpr17;
  1819. ULONG Gpr18;
  1820. ULONG Gpr19;
  1821. ULONG Gpr20;
  1822. ULONG Gpr21;
  1823. ULONG Gpr22;
  1824. ULONG Gpr23;
  1825. ULONG Gpr24;
  1826. ULONG Gpr25;
  1827. ULONG Gpr26;
  1828. ULONG Gpr27;
  1829. ULONG Gpr28;
  1830. ULONG Gpr29;
  1831. ULONG Gpr30;
  1832. ULONG Gpr31;
  1833. ULONG Cr; // Condition register
  1834. ULONG Xer; // Fixed point exception register
  1835. //
  1836. // This section is specified/returned if the ContextFlags word contains
  1837. // the flag CONTEXT_CONTROL.
  1838. //
  1839. ULONG Msr; // Machine status register
  1840. ULONG Iar; // Instruction address register
  1841. ULONG Lr; // Link register
  1842. ULONG Ctr; // Count register
  1843. //
  1844. // The flags values within this flag control the contents of
  1845. // a CONTEXT record.
  1846. //
  1847. // If the context record is used as an input parameter, then
  1848. // for each portion of the context record controlled by a flag
  1849. // whose value is set, it is assumed that that portion of the
  1850. // context record contains valid context. If the context record
  1851. // is being used to modify a thread's context, then only that
  1852. // portion of the threads context will be modified.
  1853. //
  1854. // If the context record is used as an IN OUT parameter to capture
  1855. // the context of a thread, then only those portions of the thread's
  1856. // context corresponding to set flags will be returned.
  1857. //
  1858. // The context record is never used as an OUT only parameter.
  1859. //
  1860. ULONG ContextFlags;
  1861. ULONG Fill[3]; // Pad out to multiple of 16 bytes
  1862. //
  1863. // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
  1864. // set in ContextFlags. Note that CONTEXT_DEBUG_REGISTERS is NOT
  1865. // included in CONTEXT_FULL.
  1866. //
  1867. ULONG Dr0; // Breakpoint Register 1
  1868. ULONG Dr1; // Breakpoint Register 2
  1869. ULONG Dr2; // Breakpoint Register 3
  1870. ULONG Dr3; // Breakpoint Register 4
  1871. ULONG Dr4; // Breakpoint Register 5
  1872. ULONG Dr5; // Breakpoint Register 6
  1873. ULONG Dr6; // Debug Status Register
  1874. ULONG Dr7; // Debug Control Register
  1875. } CONTEXT, *PCONTEXT, *LPCONTEXT;
  1876. #elif defined(_SPARC_)
  1877. #define CONTEXT_CONTROL 0x00000001L
  1878. #define CONTEXT_FLOATING_POINT 0x00000002L
  1879. #define CONTEXT_INTEGER 0x00000004L
  1880. #define COUNT_FLOATING_REGISTER 32
  1881. #define COUNT_DOUBLE_REGISTER 16
  1882. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
  1883. #define CONTEXT_ALL CONTEXT_FULL
  1884. typedef struct _CONTEXT {
  1885. //
  1886. // This section is specified/returned if the ContextFlags word contains
  1887. // the flag CONTEXT_INTEGER.
  1888. //
  1889. ULONG g0;
  1890. ULONG g1;
  1891. ULONG g2;
  1892. ULONG g3;
  1893. ULONG g4;
  1894. ULONG g5;
  1895. ULONG g6;
  1896. ULONG g7;
  1897. ULONG o0;
  1898. ULONG o1;
  1899. ULONG o2;
  1900. ULONG o3;
  1901. ULONG o4;
  1902. ULONG o5;
  1903. ULONG sp;
  1904. ULONG o7;
  1905. ULONG l0;
  1906. ULONG l1;
  1907. ULONG l2;
  1908. ULONG l3;
  1909. ULONG l4;
  1910. ULONG l5;
  1911. ULONG l6;
  1912. ULONG l7;
  1913. ULONG i0;
  1914. ULONG i1;
  1915. ULONG i2;
  1916. ULONG i3;
  1917. ULONG i4;
  1918. ULONG i5;
  1919. ULONG fp;
  1920. ULONG i7;
  1921. ULONG y;
  1922. //
  1923. // This section is specified/returned if the ContextFlags word contains
  1924. // the flag CONTEXT_CONTROL.
  1925. //
  1926. #if defined(__sparcv9)
  1927. ULONG ccr;
  1928. #else
  1929. ULONG psr;
  1930. #endif
  1931. ULONG pc; // program counter
  1932. ULONG npc; // next address to be executed
  1933. ULONG ContextFlags;
  1934. //
  1935. // This section is specified/returned if the ContextFlags word contains
  1936. // the flag CONTEXT_FLOATING_POINT.
  1937. //
  1938. ULONGLONG fsr;
  1939. union {
  1940. float f[COUNT_FLOATING_REGISTER];
  1941. double d[COUNT_DOUBLE_REGISTER];
  1942. } fprs;
  1943. } CONTEXT, *PCONTEXT, *LPCONTEXT;
  1944. #elif defined(_PARISC_)
  1945. // ToDo: Get this correct for PARISC architecture
  1946. #define CONTEXT_CONTROL 0x00000001L
  1947. #define CONTEXT_FLOATING_POINT 0x00000002L
  1948. #define CONTEXT_INTEGER 0x00000004L
  1949. #define COUNT_FLOATING_REGISTER 32
  1950. #define COUNT_DOUBLE_REGISTER 16
  1951. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
  1952. #define CONTEXT_ALL CONTEXT_FULL
  1953. typedef struct _CONTEXT {
  1954. //
  1955. // This section is specified/returned if the ContextFlags word contains
  1956. // the flag CONTEXT_INTEGER.
  1957. //
  1958. ULONG g0;
  1959. ULONG g1;
  1960. ULONG g2;
  1961. ULONG g3;
  1962. ULONG g4;
  1963. ULONG g5;
  1964. ULONG g6;
  1965. ULONG g7;
  1966. ULONG o0;
  1967. ULONG o1;
  1968. ULONG o2;
  1969. ULONG o3;
  1970. ULONG o4;
  1971. ULONG o5;
  1972. ULONG sp;
  1973. ULONG o7;
  1974. ULONG l0;
  1975. ULONG l1;
  1976. ULONG l2;
  1977. ULONG l3;
  1978. ULONG l4;
  1979. ULONG l5;
  1980. ULONG l6;
  1981. ULONG l7;
  1982. ULONG i0;
  1983. ULONG i1;
  1984. ULONG i2;
  1985. ULONG i3;
  1986. ULONG i4;
  1987. ULONG i5;
  1988. ULONG fp;
  1989. ULONG i7;
  1990. ULONG y;
  1991. //
  1992. // This section is specified/returned if the ContextFlags word contains
  1993. // the flag CONTEXT_CONTROL.
  1994. //
  1995. ULONG psr;
  1996. ULONG pc; // program counter
  1997. ULONG npc; // next address to be executed
  1998. ULONG ContextFlags;
  1999. //
  2000. // This section is specified/returned if the ContextFlags word contains
  2001. // the flag CONTEXT_FLOATING_POINT.
  2002. //
  2003. ULONGLONG fsr;
  2004. union {
  2005. float f[COUNT_FLOATING_REGISTER];
  2006. double d[COUNT_DOUBLE_REGISTER];
  2007. } fprs;
  2008. } CONTEXT, *PCONTEXT, *LPCONTEXT;
  2009. #elif defined(_IA64_)
  2010. // copied from winnt.h
  2011. typedef struct _FLOAT128 {
  2012. __int64 LowPart;
  2013. __int64 HighPart;
  2014. } FLOAT128;
  2015. typedef FLOAT128 *PFLOAT128;
  2016. // begin_ntddk begin_nthal
  2017. //
  2018. // The following flags control the contents of the CONTEXT structure.
  2019. //
  2020. #if !defined(RC_INVOKED)
  2021. #define CONTEXT_IA64 0x00080000
  2022. #define CONTEXT_CONTROL (CONTEXT_IA64 | 0x00000001L)
  2023. #define CONTEXT_LOWER_FLOATING_POINT (CONTEXT_IA64 | 0x00000002L)
  2024. #define CONTEXT_HIGHER_FLOATING_POINT (CONTEXT_IA64 | 0x00000004L)
  2025. #define CONTEXT_INTEGER (CONTEXT_IA64 | 0x00000008L)
  2026. #define CONTEXT_DEBUG (CONTEXT_IA64 | 0x00000010L)
  2027. #define CONTEXT_IA32_CONTROL (CONTEXT_IA64 | 0x00000020L) // Includes StIPSR
  2028. #define CONTEXT_FLOATING_POINT (CONTEXT_LOWER_FLOATING_POINT | CONTEXT_HIGHER_FLOATING_POINT)
  2029. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER | CONTEXT_IA32_CONTROL)
  2030. #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER | CONTEXT_DEBUG | CONTEXT_IA32_CONTROL)
  2031. #define CONTEXT_EXCEPTION_ACTIVE 0x8000000
  2032. #define CONTEXT_SERVICE_ACTIVE 0x10000000
  2033. #define CONTEXT_EXCEPTION_REQUEST 0x40000000
  2034. #define CONTEXT_EXCEPTION_REPORTING 0x80000000
  2035. #endif // !defined(RC_INVOKED)
  2036. //
  2037. // Context Frame
  2038. //
  2039. // This frame has a several purposes: 1) it is used as an argument to
  2040. // NtContinue, 2) it is used to construct a call frame for APC delivery,
  2041. // 3) it is used to construct a call frame for exception dispatching
  2042. // in user mode, 4) it is used in the user level thread creation
  2043. // routines, and 5) it is used to to pass thread state to debuggers.
  2044. //
  2045. // N.B. Because this record is used as a call frame, it must be EXACTLY
  2046. // a multiple of 16 bytes in length and aligned on a 16-byte boundary.
  2047. //
  2048. typedef struct _CONTEXT {
  2049. //
  2050. // The flags values within this flag control the contents of
  2051. // a CONTEXT record.
  2052. //
  2053. // If the context record is used as an input parameter, then
  2054. // for each portion of the context record controlled by a flag
  2055. // whose value is set, it is assumed that that portion of the
  2056. // context record contains valid context. If the context record
  2057. // is being used to modify a thread's context, then only that
  2058. // portion of the threads context will be modified.
  2059. //
  2060. // If the context record is used as an IN OUT parameter to capture
  2061. // the context of a thread, then only those portions of the thread's
  2062. // context corresponding to set flags will be returned.
  2063. //
  2064. // The context record is never used as an OUT only parameter.
  2065. //
  2066. DWORD ContextFlags;
  2067. DWORD Fill1[3]; // for alignment of following on 16-byte boundary
  2068. //
  2069. // This section is specified/returned if the ContextFlags word contains
  2070. // the flag CONTEXT_DEBUG.
  2071. //
  2072. // N.B. CONTEXT_DEBUG is *not* part of CONTEXT_FULL.
  2073. //
  2074. ULONGLONG DbI0;
  2075. ULONGLONG DbI1;
  2076. ULONGLONG DbI2;
  2077. ULONGLONG DbI3;
  2078. ULONGLONG DbI4;
  2079. ULONGLONG DbI5;
  2080. ULONGLONG DbI6;
  2081. ULONGLONG DbI7;
  2082. ULONGLONG DbD0;
  2083. ULONGLONG DbD1;
  2084. ULONGLONG DbD2;
  2085. ULONGLONG DbD3;
  2086. ULONGLONG DbD4;
  2087. ULONGLONG DbD5;
  2088. ULONGLONG DbD6;
  2089. ULONGLONG DbD7;
  2090. //
  2091. // This section is specified/returned if the ContextFlags word contains
  2092. // the flag CONTEXT_LOWER_FLOATING_POINT.
  2093. //
  2094. FLOAT128 FltS0;
  2095. FLOAT128 FltS1;
  2096. FLOAT128 FltS2;
  2097. FLOAT128 FltS3;
  2098. FLOAT128 FltT0;
  2099. FLOAT128 FltT1;
  2100. FLOAT128 FltT2;
  2101. FLOAT128 FltT3;
  2102. FLOAT128 FltT4;
  2103. FLOAT128 FltT5;
  2104. FLOAT128 FltT6;
  2105. FLOAT128 FltT7;
  2106. FLOAT128 FltT8;
  2107. FLOAT128 FltT9;
  2108. //
  2109. // This section is specified/returned if the ContextFlags word contains
  2110. // the flag CONTEXT_HIGHER_FLOATING_POINT.
  2111. //
  2112. FLOAT128 FltS4;
  2113. FLOAT128 FltS5;
  2114. FLOAT128 FltS6;
  2115. FLOAT128 FltS7;
  2116. FLOAT128 FltS8;
  2117. FLOAT128 FltS9;
  2118. FLOAT128 FltS10;
  2119. FLOAT128 FltS11;
  2120. FLOAT128 FltS12;
  2121. FLOAT128 FltS13;
  2122. FLOAT128 FltS14;
  2123. FLOAT128 FltS15;
  2124. FLOAT128 FltS16;
  2125. FLOAT128 FltS17;
  2126. FLOAT128 FltS18;
  2127. FLOAT128 FltS19;
  2128. FLOAT128 FltF32;
  2129. FLOAT128 FltF33;
  2130. FLOAT128 FltF34;
  2131. FLOAT128 FltF35;
  2132. FLOAT128 FltF36;
  2133. FLOAT128 FltF37;
  2134. FLOAT128 FltF38;
  2135. FLOAT128 FltF39;
  2136. FLOAT128 FltF40;
  2137. FLOAT128 FltF41;
  2138. FLOAT128 FltF42;
  2139. FLOAT128 FltF43;
  2140. FLOAT128 FltF44;
  2141. FLOAT128 FltF45;
  2142. FLOAT128 FltF46;
  2143. FLOAT128 FltF47;
  2144. FLOAT128 FltF48;
  2145. FLOAT128 FltF49;
  2146. FLOAT128 FltF50;
  2147. FLOAT128 FltF51;
  2148. FLOAT128 FltF52;
  2149. FLOAT128 FltF53;
  2150. FLOAT128 FltF54;
  2151. FLOAT128 FltF55;
  2152. FLOAT128 FltF56;
  2153. FLOAT128 FltF57;
  2154. FLOAT128 FltF58;
  2155. FLOAT128 FltF59;
  2156. FLOAT128 FltF60;
  2157. FLOAT128 FltF61;
  2158. FLOAT128 FltF62;
  2159. FLOAT128 FltF63;
  2160. FLOAT128 FltF64;
  2161. FLOAT128 FltF65;
  2162. FLOAT128 FltF66;
  2163. FLOAT128 FltF67;
  2164. FLOAT128 FltF68;
  2165. FLOAT128 FltF69;
  2166. FLOAT128 FltF70;
  2167. FLOAT128 FltF71;
  2168. FLOAT128 FltF72;
  2169. FLOAT128 FltF73;
  2170. FLOAT128 FltF74;
  2171. FLOAT128 FltF75;
  2172. FLOAT128 FltF76;
  2173. FLOAT128 FltF77;
  2174. FLOAT128 FltF78;
  2175. FLOAT128 FltF79;
  2176. FLOAT128 FltF80;
  2177. FLOAT128 FltF81;
  2178. FLOAT128 FltF82;
  2179. FLOAT128 FltF83;
  2180. FLOAT128 FltF84;
  2181. FLOAT128 FltF85;
  2182. FLOAT128 FltF86;
  2183. FLOAT128 FltF87;
  2184. FLOAT128 FltF88;
  2185. FLOAT128 FltF89;
  2186. FLOAT128 FltF90;
  2187. FLOAT128 FltF91;
  2188. FLOAT128 FltF92;
  2189. FLOAT128 FltF93;
  2190. FLOAT128 FltF94;
  2191. FLOAT128 FltF95;
  2192. FLOAT128 FltF96;
  2193. FLOAT128 FltF97;
  2194. FLOAT128 FltF98;
  2195. FLOAT128 FltF99;
  2196. FLOAT128 FltF100;
  2197. FLOAT128 FltF101;
  2198. FLOAT128 FltF102;
  2199. FLOAT128 FltF103;
  2200. FLOAT128 FltF104;
  2201. FLOAT128 FltF105;
  2202. FLOAT128 FltF106;
  2203. FLOAT128 FltF107;
  2204. FLOAT128 FltF108;
  2205. FLOAT128 FltF109;
  2206. FLOAT128 FltF110;
  2207. FLOAT128 FltF111;
  2208. FLOAT128 FltF112;
  2209. FLOAT128 FltF113;
  2210. FLOAT128 FltF114;
  2211. FLOAT128 FltF115;
  2212. FLOAT128 FltF116;
  2213. FLOAT128 FltF117;
  2214. FLOAT128 FltF118;
  2215. FLOAT128 FltF119;
  2216. FLOAT128 FltF120;
  2217. FLOAT128 FltF121;
  2218. FLOAT128 FltF122;
  2219. FLOAT128 FltF123;
  2220. FLOAT128 FltF124;
  2221. FLOAT128 FltF125;
  2222. FLOAT128 FltF126;
  2223. FLOAT128 FltF127;
  2224. //
  2225. // This section is specified/returned if the ContextFlags word contains
  2226. // the flag CONTEXT_LOWER_FLOATING_POINT | CONTEXT_HIGHER_FLOATING_POINT | CONTEXT_CONTROL.
  2227. //
  2228. ULONGLONG StFPSR; // FP status
  2229. //
  2230. // This section is specified/returned if the ContextFlags word contains
  2231. // the flag CONTEXT_INTEGER.
  2232. //
  2233. // N.B. The registers gp, sp, rp are part of the control context
  2234. //
  2235. ULONGLONG IntGp; // r1, volatile
  2236. ULONGLONG IntT0; // r2-r3, volatile
  2237. ULONGLONG IntT1; //
  2238. ULONGLONG IntS0; // r4-r7, preserved
  2239. ULONGLONG IntS1;
  2240. ULONGLONG IntS2;
  2241. ULONGLONG IntS3;
  2242. ULONGLONG IntV0; // r8, volatile
  2243. ULONGLONG IntT2; // r9-r11, volatile
  2244. ULONGLONG IntT3;
  2245. ULONGLONG IntT4;
  2246. ULONGLONG IntSp; // stack pointer (r12), special
  2247. ULONGLONG IntTeb; // teb (r13), special
  2248. ULONGLONG IntT5; // r14-r31, volatile
  2249. ULONGLONG IntT6;
  2250. ULONGLONG IntT7;
  2251. ULONGLONG IntT8;
  2252. ULONGLONG IntT9;
  2253. ULONGLONG IntT10;
  2254. ULONGLONG IntT11;
  2255. ULONGLONG IntT12;
  2256. ULONGLONG IntT13;
  2257. ULONGLONG IntT14;
  2258. ULONGLONG IntT15;
  2259. ULONGLONG IntT16;
  2260. ULONGLONG IntT17;
  2261. ULONGLONG IntT18;
  2262. ULONGLONG IntT19;
  2263. ULONGLONG IntT20;
  2264. ULONGLONG IntT21;
  2265. ULONGLONG IntT22;
  2266. ULONGLONG IntNats; // Nat bits for r1-r31
  2267. // r1-r31 in bits 1 thru 31.
  2268. ULONGLONG Preds; // predicates, preserved
  2269. ULONGLONG BrRp; // return pointer, b0, preserved
  2270. ULONGLONG BrS0; // b1-b5, preserved
  2271. ULONGLONG BrS1;
  2272. ULONGLONG BrS2;
  2273. ULONGLONG BrS3;
  2274. ULONGLONG BrS4;
  2275. ULONGLONG BrT0; // b6-b7, volatile
  2276. ULONGLONG BrT1;
  2277. //
  2278. // This section is specified/returned if the ContextFlags word contains
  2279. // the flag CONTEXT_CONTROL.
  2280. //
  2281. // Other application registers
  2282. ULONGLONG ApUNAT; // User Nat collection register, preserved
  2283. ULONGLONG ApLC; // Loop counter register, preserved
  2284. ULONGLONG ApEC; // Epilog counter register, preserved
  2285. ULONGLONG ApCCV; // CMPXCHG value register, volatile
  2286. ULONGLONG ApDCR; // Default control register (TBD)
  2287. // Register stack info
  2288. ULONGLONG RsPFS; // Previous function state, preserved
  2289. ULONGLONG RsBSP; // Backing store pointer, preserved
  2290. ULONGLONG RsBSPSTORE;
  2291. ULONGLONG RsRSC; // RSE configuration, volatile
  2292. ULONGLONG RsRNAT; // RSE Nat collection register, preserved
  2293. // Trap Status Information
  2294. ULONGLONG StIPSR; // Interruption Processor Status
  2295. ULONGLONG StIIP; // Interruption IP
  2296. ULONGLONG StIFS; // Interruption Function State
  2297. // iA32 related control registers
  2298. ULONGLONG StFCR; // copy of Ar21
  2299. ULONGLONG Eflag; // Eflag copy of Ar24
  2300. ULONGLONG SegCSD; // iA32 CSDescriptor (Ar25)
  2301. ULONGLONG SegSSD; // iA32 SSDescriptor (Ar26)
  2302. ULONGLONG Cflag; // Cr0+Cr4 copy of Ar27
  2303. ULONGLONG StFSR; // x86 FP status (copy of AR28)
  2304. ULONGLONG StFIR; // x86 FP status (copy of AR29)
  2305. ULONGLONG StFDR; // x86 FP status (copy of AR30)
  2306. ULONGLONG UNUSEDPACK; // added to pack StFDR to 16-bytes
  2307. } CONTEXT, *PCONTEXT, *LPCONTEXT;
  2308. #elif defined(_AMD64_)
  2309. // copied from winnt.h
  2310. #define CONTEXT_AMD64 0x100000
  2311. #define CONTEXT_CONTROL (CONTEXT_AMD64 | 0x1L)
  2312. #define CONTEXT_INTEGER (CONTEXT_AMD64 | 0x2L)
  2313. #define CONTEXT_SEGMENTS (CONTEXT_AMD64 | 0x4L)
  2314. #define CONTEXT_FLOATING_POINT (CONTEXT_AMD64 | 0x8L)
  2315. #define CONTEXT_DEBUG_REGISTERS (CONTEXT_AMD64 | 0x10L)
  2316. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
  2317. #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS)
  2318. #define CONTEXT_EXCEPTION_ACTIVE 0x8000000
  2319. #define CONTEXT_SERVICE_ACTIVE 0x10000000
  2320. #define CONTEXT_EXCEPTION_REQUEST 0x40000000
  2321. #define CONTEXT_EXCEPTION_REPORTING 0x80000000
  2322. typedef struct _M128U {
  2323. ULONGLONG Low;
  2324. LONGLONG High;
  2325. } M128U, *PM128U;
  2326. // Same as _M128U but aligned to a 16-byte boundary
  2327. typedef DECLSPEC_ALIGN(16) M128U M128A, *PM128A;
  2328. typedef struct _XMM_SAVE_AREA32 {
  2329. WORD ControlWord;
  2330. WORD StatusWord;
  2331. BYTE TagWord;
  2332. BYTE Reserved1;
  2333. WORD ErrorOpcode;
  2334. DWORD ErrorOffset;
  2335. WORD ErrorSelector;
  2336. WORD Reserved2;
  2337. DWORD DataOffset;
  2338. WORD DataSelector;
  2339. WORD Reserved3;
  2340. DWORD MxCsr;
  2341. DWORD MxCsr_Mask;
  2342. M128A FloatRegisters[8];
  2343. M128A XmmRegisters[16];
  2344. BYTE Reserved4[96];
  2345. } XMM_SAVE_AREA32, *PXMM_SAVE_AREA32;
  2346. #define LEGACY_SAVE_AREA_LENGTH sizeof(XMM_SAVE_AREA32)
  2347. //
  2348. // Context Frame
  2349. //
  2350. // This frame has a several purposes: 1) it is used as an argument to
  2351. // NtContinue, 2) is is used to constuct a call frame for APC delivery,
  2352. // and 3) it is used in the user level thread creation routines.
  2353. //
  2354. //
  2355. // The flags field within this record controls the contents of a CONTEXT
  2356. // record.
  2357. //
  2358. // If the context record is used as an input parameter, then for each
  2359. // portion of the context record controlled by a flag whose value is
  2360. // set, it is assumed that that portion of the context record contains
  2361. // valid context. If the context record is being used to modify a threads
  2362. // context, then only that portion of the threads context is modified.
  2363. //
  2364. // If the context record is used as an output parameter to capture the
  2365. // context of a thread, then only those portions of the thread's context
  2366. // corresponding to set flags will be returned.
  2367. //
  2368. // CONTEXT_CONTROL specifies SegSs, Rsp, SegCs, Rip, and EFlags.
  2369. //
  2370. // CONTEXT_INTEGER specifies Rax, Rcx, Rdx, Rbx, Rbp, Rsi, Rdi, and R8-R15.
  2371. //
  2372. // CONTEXT_SEGMENTS specifies SegDs, SegEs, SegFs, and SegGs.
  2373. //
  2374. // CONTEXT_DEBUG_REGISTERS specifies Dr0-Dr3 and Dr6-Dr7.
  2375. //
  2376. // CONTEXT_MMX_REGISTERS specifies the floating point and extended registers
  2377. // Mm0/St0-Mm7/St7 and Xmm0-Xmm15).
  2378. //
  2379. typedef struct DECLSPEC_ALIGN(16) _CONTEXT {
  2380. //
  2381. // Register parameter home addresses.
  2382. //
  2383. // N.B. These fields are for convience - they could be used to extend the
  2384. // context record in the future.
  2385. //
  2386. DWORD64 P1Home;
  2387. DWORD64 P2Home;
  2388. DWORD64 P3Home;
  2389. DWORD64 P4Home;
  2390. DWORD64 P5Home;
  2391. DWORD64 P6Home;
  2392. //
  2393. // Control flags.
  2394. //
  2395. DWORD ContextFlags;
  2396. DWORD MxCsr;
  2397. //
  2398. // Segment Registers and processor flags.
  2399. //
  2400. WORD SegCs;
  2401. WORD SegDs;
  2402. WORD SegEs;
  2403. WORD SegFs;
  2404. WORD SegGs;
  2405. WORD SegSs;
  2406. DWORD EFlags;
  2407. //
  2408. // Debug registers
  2409. //
  2410. DWORD64 Dr0;
  2411. DWORD64 Dr1;
  2412. DWORD64 Dr2;
  2413. DWORD64 Dr3;
  2414. DWORD64 Dr6;
  2415. DWORD64 Dr7;
  2416. //
  2417. // Integer registers.
  2418. //
  2419. DWORD64 Rax;
  2420. DWORD64 Rcx;
  2421. DWORD64 Rdx;
  2422. DWORD64 Rbx;
  2423. DWORD64 Rsp;
  2424. DWORD64 Rbp;
  2425. DWORD64 Rsi;
  2426. DWORD64 Rdi;
  2427. DWORD64 R8;
  2428. DWORD64 R9;
  2429. DWORD64 R10;
  2430. DWORD64 R11;
  2431. DWORD64 R12;
  2432. DWORD64 R13;
  2433. DWORD64 R14;
  2434. DWORD64 R15;
  2435. //
  2436. // Program counter.
  2437. //
  2438. DWORD64 Rip;
  2439. //
  2440. // Floating point state.
  2441. //
  2442. union {
  2443. XMM_SAVE_AREA32 FltSave;
  2444. struct {
  2445. M128A Header[2];
  2446. M128A Legacy[8];
  2447. M128A Xmm0;
  2448. M128A Xmm1;
  2449. M128A Xmm2;
  2450. M128A Xmm3;
  2451. M128A Xmm4;
  2452. M128A Xmm5;
  2453. M128A Xmm6;
  2454. M128A Xmm7;
  2455. M128A Xmm8;
  2456. M128A Xmm9;
  2457. M128A Xmm10;
  2458. M128A Xmm11;
  2459. M128A Xmm12;
  2460. M128A Xmm13;
  2461. M128A Xmm14;
  2462. M128A Xmm15;
  2463. };
  2464. };
  2465. //
  2466. // Vector registers.
  2467. //
  2468. M128A VectorRegister[26];
  2469. DWORD64 VectorControl;
  2470. //
  2471. // Special debug control registers.
  2472. //
  2473. DWORD64 DebugControl;
  2474. DWORD64 LastBranchToRip;
  2475. DWORD64 LastBranchFromRip;
  2476. DWORD64 LastExceptionToRip;
  2477. DWORD64 LastExceptionFromRip;
  2478. } CONTEXT, *PCONTEXT, *LPCONTEXT;
  2479. //
  2480. // Nonvolatile context pointer record.
  2481. //
  2482. typedef struct _KNONVOLATILE_CONTEXT_POINTERS {
  2483. union {
  2484. PM128A FloatingContext[16];
  2485. struct {
  2486. PM128A Xmm0;
  2487. PM128A Xmm1;
  2488. PM128A Xmm2;
  2489. PM128A Xmm3;
  2490. PM128A Xmm4;
  2491. PM128A Xmm5;
  2492. PM128A Xmm6;
  2493. PM128A Xmm7;
  2494. PM128A Xmm8;
  2495. PM128A Xmm9;
  2496. PM128A Xmm10;
  2497. PM128A Xmm11;
  2498. PM128A Xmm12;
  2499. PM128A Xmm13;
  2500. PM128A Xmm14;
  2501. PM128A Xmm15;
  2502. } ;
  2503. } ;
  2504. union {
  2505. PDWORD64 IntegerContext[16];
  2506. struct {
  2507. PDWORD64 Rax;
  2508. PDWORD64 Rcx;
  2509. PDWORD64 Rdx;
  2510. PDWORD64 Rbx;
  2511. PDWORD64 Rsp;
  2512. PDWORD64 Rbp;
  2513. PDWORD64 Rsi;
  2514. PDWORD64 Rdi;
  2515. PDWORD64 R8;
  2516. PDWORD64 R9;
  2517. PDWORD64 R10;
  2518. PDWORD64 R11;
  2519. PDWORD64 R12;
  2520. PDWORD64 R13;
  2521. PDWORD64 R14;
  2522. PDWORD64 R15;
  2523. } ;
  2524. } ;
  2525. } KNONVOLATILE_CONTEXT_POINTERS, *PKNONVOLATILE_CONTEXT_POINTERS;
  2526. #elif defined(_ARM_)
  2527. #define CONTEXT_ARM 0x00200000L
  2528. // end_wx86
  2529. #define CONTEXT_CONTROL (CONTEXT_ARM | 0x1L)
  2530. #define CONTEXT_INTEGER (CONTEXT_ARM | 0x2L)
  2531. #define CONTEXT_FLOATING_POINT (CONTEXT_ARM | 0x4L)
  2532. #define CONTEXT_DEBUG_REGISTERS (CONTEXT_ARM | 0x8L)
  2533. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
  2534. #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS)
  2535. #define CONTEXT_EXCEPTION_ACTIVE 0x8000000L
  2536. #define CONTEXT_SERVICE_ACTIVE 0x10000000L
  2537. #define CONTEXT_EXCEPTION_REQUEST 0x40000000L
  2538. #define CONTEXT_EXCEPTION_REPORTING 0x80000000L
  2539. //
  2540. // This flag is set by the unwinder if it has unwound to a call
  2541. // site, and cleared whenever it unwinds through a trap frame.
  2542. // It is used by language-specific exception handlers to help
  2543. // differentiate exception scopes during dispatching.
  2544. //
  2545. #define CONTEXT_UNWOUND_TO_CALL 0x20000000
  2546. //
  2547. // Specify the number of breakpoints and watchpoints that the OS
  2548. // will track. Architecturally, ARM supports up to 16. In practice,
  2549. // however, almost no one implements more than 4 of each.
  2550. //
  2551. #define ARM_MAX_BREAKPOINTS 8
  2552. #define ARM_MAX_WATCHPOINTS 1
  2553. typedef struct _NEON128 {
  2554. ULONGLONG Low;
  2555. LONGLONG High;
  2556. } NEON128, *PNEON128;
  2557. //
  2558. // Context Frame
  2559. //
  2560. // This frame has a several purposes: 1) it is used as an argument to
  2561. // NtContinue, 2) it is used to constuct a call frame for APC delivery,
  2562. // and 3) it is used in the user level thread creation routines.
  2563. //
  2564. //
  2565. // The flags field within this record controls the contents of a CONTEXT
  2566. // record.
  2567. //
  2568. // If the context record is used as an input parameter, then for each
  2569. // portion of the context record controlled by a flag whose value is
  2570. // set, it is assumed that that portion of the context record contains
  2571. // valid context. If the context record is being used to modify a threads
  2572. // context, then only that portion of the threads context is modified.
  2573. //
  2574. // If the context record is used as an output parameter to capture the
  2575. // context of a thread, then only those portions of the thread's context
  2576. // corresponding to set flags will be returned.
  2577. //
  2578. // CONTEXT_CONTROL specifies Sp, Lr, Pc, and Cpsr
  2579. //
  2580. // CONTEXT_INTEGER specifies R0-R12
  2581. //
  2582. // CONTEXT_FLOATING_POINT specifies Q0-Q15 / D0-D31 / S0-S31
  2583. //
  2584. // CONTEXT_DEBUG_REGISTERS specifies up to 16 of DBGBVR, DBGBCR, DBGWVR,
  2585. // DBGWCR.
  2586. //
  2587. typedef struct DECLSPEC_ALIGN(8) _CONTEXT {
  2588. //
  2589. // Control flags.
  2590. //
  2591. DWORD ContextFlags;
  2592. //
  2593. // Integer registers
  2594. //
  2595. DWORD R0;
  2596. DWORD R1;
  2597. DWORD R2;
  2598. DWORD R3;
  2599. DWORD R4;
  2600. DWORD R5;
  2601. DWORD R6;
  2602. DWORD R7;
  2603. DWORD R8;
  2604. DWORD R9;
  2605. DWORD R10;
  2606. DWORD R11;
  2607. DWORD R12;
  2608. //
  2609. // Control Registers
  2610. //
  2611. DWORD Sp;
  2612. DWORD Lr;
  2613. DWORD Pc;
  2614. DWORD Cpsr;
  2615. //
  2616. // Floating Point/NEON Registers
  2617. //
  2618. DWORD Fpscr;
  2619. DWORD Padding;
  2620. union {
  2621. NEON128 Q[16];
  2622. ULONGLONG D[32];
  2623. DWORD S[32];
  2624. };
  2625. //
  2626. // Debug registers
  2627. //
  2628. DWORD Bvr[ARM_MAX_BREAKPOINTS];
  2629. DWORD Bcr[ARM_MAX_BREAKPOINTS];
  2630. DWORD Wvr[ARM_MAX_WATCHPOINTS];
  2631. DWORD Wcr[ARM_MAX_WATCHPOINTS];
  2632. DWORD Padding2[2];
  2633. } CONTEXT, *PCONTEXT, *LPCONTEXT;
  2634. //
  2635. // Nonvolatile context pointer record.
  2636. //
  2637. typedef struct _KNONVOLATILE_CONTEXT_POINTERS {
  2638. PDWORD R4;
  2639. PDWORD R5;
  2640. PDWORD R6;
  2641. PDWORD R7;
  2642. PDWORD R8;
  2643. PDWORD R9;
  2644. PDWORD R10;
  2645. PDWORD R11;
  2646. PDWORD Lr;
  2647. PULONGLONG D8;
  2648. PULONGLONG D9;
  2649. PULONGLONG D10;
  2650. PULONGLONG D11;
  2651. PULONGLONG D12;
  2652. PULONGLONG D13;
  2653. PULONGLONG D14;
  2654. PULONGLONG D15;
  2655. } KNONVOLATILE_CONTEXT_POINTERS, *PKNONVOLATILE_CONTEXT_POINTERS;
  2656. typedef struct _IMAGE_ARM_RUNTIME_FUNCTION_ENTRY {
  2657. DWORD BeginAddress;
  2658. union {
  2659. DWORD UnwindData;
  2660. struct {
  2661. DWORD Flag : 2;
  2662. DWORD FunctionLength : 11;
  2663. DWORD Ret : 2;
  2664. DWORD H : 1;
  2665. DWORD Reg : 3;
  2666. DWORD R : 1;
  2667. DWORD L : 1;
  2668. DWORD C : 1;
  2669. DWORD StackAdjust : 10;
  2670. };
  2671. };
  2672. } IMAGE_ARM_RUNTIME_FUNCTION_ENTRY, * PIMAGE_ARM_RUNTIME_FUNCTION_ENTRY;
  2673. #elif defined(_ARM64_)
  2674. #define CONTEXT_ARM64 0x00400000L
  2675. #define CONTEXT_CONTROL (CONTEXT_ARM64 | 0x1L)
  2676. #define CONTEXT_INTEGER (CONTEXT_ARM64 | 0x2L)
  2677. #define CONTEXT_FLOATING_POINT (CONTEXT_ARM64 | 0x4L)
  2678. #define CONTEXT_DEBUG_REGISTERS (CONTEXT_ARM64 | 0x8L)
  2679. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
  2680. #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS)
  2681. #define CONTEXT_EXCEPTION_ACTIVE 0x8000000L
  2682. #define CONTEXT_SERVICE_ACTIVE 0x10000000L
  2683. #define CONTEXT_EXCEPTION_REQUEST 0x40000000L
  2684. #define CONTEXT_EXCEPTION_REPORTING 0x80000000L
  2685. //
  2686. // This flag is set by the unwinder if it has unwound to a call
  2687. // site, and cleared whenever it unwinds through a trap frame.
  2688. // It is used by language-specific exception handlers to help
  2689. // differentiate exception scopes during dispatching.
  2690. //
  2691. #define CONTEXT_UNWOUND_TO_CALL 0x20000000
  2692. //
  2693. // Define initial Cpsr/Fpscr value
  2694. //
  2695. #define INITIAL_CPSR 0x10
  2696. #define INITIAL_FPSCR 0
  2697. // begin_ntoshvp
  2698. //
  2699. // Specify the number of breakpoints and watchpoints that the OS
  2700. // will track. Architecturally, ARM64 supports up to 16. In practice,
  2701. // however, almost no one implements more than 4 of each.
  2702. //
  2703. #define ARM64_MAX_BREAKPOINTS 8
  2704. #define ARM64_MAX_WATCHPOINTS 2
  2705. //
  2706. // Context Frame
  2707. //
  2708. // This frame has a several purposes: 1) it is used as an argument to
  2709. // NtContinue, 2) it is used to constuct a call frame for APC delivery,
  2710. // and 3) it is used in the user level thread creation routines.
  2711. //
  2712. //
  2713. // The flags field within this record controls the contents of a CONTEXT
  2714. // record.
  2715. //
  2716. // If the context record is used as an input parameter, then for each
  2717. // portion of the context record controlled by a flag whose value is
  2718. // set, it is assumed that that portion of the context record contains
  2719. // valid context. If the context record is being used to modify a threads
  2720. // context, then only that portion of the threads context is modified.
  2721. //
  2722. // If the context record is used as an output parameter to capture the
  2723. // context of a thread, then only those portions of the thread's context
  2724. // corresponding to set flags will be returned.
  2725. //
  2726. // CONTEXT_CONTROL specifies Sp, Lr, Pc, and Cpsr
  2727. //
  2728. // CONTEXT_INTEGER specifies R0-R12
  2729. //
  2730. // CONTEXT_FLOATING_POINT specifies Q0-Q15 / D0-D31 / S0-S31
  2731. //
  2732. // CONTEXT_DEBUG_REGISTERS specifies up to 16 of DBGBVR, DBGBCR, DBGWVR,
  2733. // DBGWCR.
  2734. //
  2735. typedef struct _NEON128 {
  2736. ULONGLONG Low;
  2737. LONGLONG High;
  2738. } NEON128, *PNEON128;
  2739. typedef struct DECLSPEC_ALIGN(16) _CONTEXT {
  2740. //
  2741. // Control flags.
  2742. //
  2743. /* +0x000 */ DWORD ContextFlags;
  2744. //
  2745. // Integer registers
  2746. //
  2747. /* +0x004 */ DWORD Cpsr; // NZVF + DAIF + CurrentEL + SPSel
  2748. /* +0x008 */ union {
  2749. struct {
  2750. DWORD64 X0;
  2751. DWORD64 X1;
  2752. DWORD64 X2;
  2753. DWORD64 X3;
  2754. DWORD64 X4;
  2755. DWORD64 X5;
  2756. DWORD64 X6;
  2757. DWORD64 X7;
  2758. DWORD64 X8;
  2759. DWORD64 X9;
  2760. DWORD64 X10;
  2761. DWORD64 X11;
  2762. DWORD64 X12;
  2763. DWORD64 X13;
  2764. DWORD64 X14;
  2765. DWORD64 X15;
  2766. DWORD64 X16;
  2767. DWORD64 X17;
  2768. DWORD64 X18;
  2769. DWORD64 X19;
  2770. DWORD64 X20;
  2771. DWORD64 X21;
  2772. DWORD64 X22;
  2773. DWORD64 X23;
  2774. DWORD64 X24;
  2775. DWORD64 X25;
  2776. DWORD64 X26;
  2777. DWORD64 X27;
  2778. DWORD64 X28;
  2779. };
  2780. DWORD64 X[29];
  2781. };
  2782. /* +0x0f0 */ DWORD64 Fp;
  2783. /* +0x0f8 */ DWORD64 Lr;
  2784. /* +0x100 */ DWORD64 Sp;
  2785. /* +0x108 */ DWORD64 Pc;
  2786. //
  2787. // Floating Point/NEON Registers
  2788. //
  2789. /* +0x110 */ NEON128 V[32];
  2790. /* +0x310 */ DWORD Fpcr;
  2791. /* +0x314 */ DWORD Fpsr;
  2792. //
  2793. // Debug registers
  2794. //
  2795. /* +0x318 */ DWORD Bcr[ARM64_MAX_BREAKPOINTS];
  2796. /* +0x338 */ DWORD64 Bvr[ARM64_MAX_BREAKPOINTS];
  2797. /* +0x378 */ DWORD Wcr[ARM64_MAX_WATCHPOINTS];
  2798. /* +0x380 */ DWORD64 Wvr[ARM64_MAX_WATCHPOINTS];
  2799. /* +0x390 */
  2800. } CONTEXT, *PCONTEXT, *LPCONTEXT;
  2801. //
  2802. // Nonvolatile context pointer record.
  2803. //
  2804. typedef struct _KNONVOLATILE_CONTEXT_POINTERS {
  2805. PDWORD64 X19;
  2806. PDWORD64 X20;
  2807. PDWORD64 X21;
  2808. PDWORD64 X22;
  2809. PDWORD64 X23;
  2810. PDWORD64 X24;
  2811. PDWORD64 X25;
  2812. PDWORD64 X26;
  2813. PDWORD64 X27;
  2814. PDWORD64 X28;
  2815. PDWORD64 Fp;
  2816. PDWORD64 Lr;
  2817. PDWORD64 D8;
  2818. PDWORD64 D9;
  2819. PDWORD64 D10;
  2820. PDWORD64 D11;
  2821. PDWORD64 D12;
  2822. PDWORD64 D13;
  2823. PDWORD64 D14;
  2824. PDWORD64 D15;
  2825. } KNONVOLATILE_CONTEXT_POINTERS, *PKNONVOLATILE_CONTEXT_POINTERS;
  2826. #else
  2827. #error Unknown architecture for defining CONTEXT.
  2828. #endif
  2829. PALIMPORT
  2830. BOOL
  2831. PALAPI
  2832. GetThreadContext(
  2833. IN HANDLE hThread,
  2834. IN OUT LPCONTEXT lpContext);
  2835. PALIMPORT
  2836. BOOL
  2837. PALAPI
  2838. SetThreadContext(
  2839. IN HANDLE hThread,
  2840. IN CONST CONTEXT *lpContext);
  2841. #define THREAD_BASE_PRIORITY_LOWRT 15
  2842. #define THREAD_BASE_PRIORITY_MAX 2
  2843. #define THREAD_BASE_PRIORITY_MIN (-2)
  2844. #define THREAD_BASE_PRIORITY_IDLE (-15)
  2845. #define THREAD_PRIORITY_LOWEST THREAD_BASE_PRIORITY_MIN
  2846. #define THREAD_PRIORITY_BELOW_NORMAL (THREAD_PRIORITY_LOWEST+1)
  2847. #define THREAD_PRIORITY_NORMAL 0
  2848. #define THREAD_PRIORITY_HIGHEST THREAD_BASE_PRIORITY_MAX
  2849. #define THREAD_PRIORITY_ABOVE_NORMAL (THREAD_PRIORITY_HIGHEST-1)
  2850. #define THREAD_PRIORITY_ERROR_RETURN (MAXLONG)
  2851. #define THREAD_PRIORITY_TIME_CRITICAL THREAD_BASE_PRIORITY_LOWRT
  2852. #define THREAD_PRIORITY_IDLE THREAD_BASE_PRIORITY_IDLE
  2853. PALIMPORT
  2854. int
  2855. PALAPI
  2856. GetThreadPriority(
  2857. IN HANDLE hThread);
  2858. PALIMPORT
  2859. BOOL
  2860. PALAPI
  2861. SetThreadPriority(
  2862. IN HANDLE hThread,
  2863. IN int nPriority);
  2864. PALIMPORT
  2865. BOOL
  2866. PALAPI
  2867. GetThreadTimes(
  2868. IN HANDLE hThread,
  2869. OUT LPFILETIME lpCreationTime,
  2870. OUT LPFILETIME lpExitTime,
  2871. OUT LPFILETIME lpKernelTime,
  2872. OUT LPFILETIME lpUserTime);
  2873. #define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF)
  2874. PALIMPORT
  2875. DWORD
  2876. PALAPI
  2877. TlsAlloc(
  2878. VOID);
  2879. PALIMPORT
  2880. LPVOID
  2881. PALAPI
  2882. TlsGetValue(
  2883. IN DWORD dwTlsIndex);
  2884. PALIMPORT
  2885. BOOL
  2886. PALAPI
  2887. TlsSetValue(
  2888. IN DWORD dwTlsIndex,
  2889. IN LPVOID lpTlsValue);
  2890. PALIMPORT
  2891. BOOL
  2892. PALAPI
  2893. TlsFree(
  2894. IN DWORD dwTlsIndex);
  2895. PALIMPORT
  2896. void *
  2897. PALAPI
  2898. PAL_GetStackBase();
  2899. PALIMPORT
  2900. void *
  2901. PALAPI
  2902. PAL_GetStackLimit();
  2903. PALIMPORT
  2904. DWORD
  2905. PALAPI
  2906. PAL_GetLogicalCpuCountFromOS();
  2907. PALIMPORT
  2908. size_t
  2909. PALAPI
  2910. PAL_GetLogicalProcessorCacheSizeFromOS();
  2911. typedef BOOL (*ReadMemoryWordCallback)(SIZE_T address, SIZE_T *value);
  2912. #if defined(_AMD64_) || defined(_ARM_) || defined(_ARM64_)
  2913. PALIMPORT BOOL PALAPI PAL_VirtualUnwind(CONTEXT *context, KNONVOLATILE_CONTEXT_POINTERS *contextPointers);
  2914. PALIMPORT BOOL PALAPI PAL_VirtualUnwindOutOfProc(CONTEXT *context,
  2915. KNONVOLATILE_CONTEXT_POINTERS *contextPointers,
  2916. DWORD pid,
  2917. ReadMemoryWordCallback readMemCallback);
  2918. #endif
  2919. #define GetLogicalProcessorCacheSizeFromOS PAL_GetLogicalProcessorCacheSizeFromOS
  2920. #ifdef PLATFORM_UNIX
  2921. #if defined(__FreeBSD__) && defined(_X86_)
  2922. #define PAL_CS_NATIVE_DATA_SIZE 12
  2923. #elif defined(__FreeBSD__) && defined(__x86_64__)
  2924. #define PAL_CS_NATIVE_DATA_SIZE 24
  2925. #elif defined(__sun__)
  2926. #define PAL_CS_NATIVE_DATA_SIZE 48
  2927. #elif defined(__hpux__) && (defined(__hppa__) || defined (__ia64__))
  2928. #define PAL_CS_NATIVE_DATA_SIZE 148
  2929. #elif defined(_AIX)
  2930. #define PAL_CS_NATIVE_DATA_SIZE 100
  2931. #elif defined(__APPLE__) && defined(__i386__)
  2932. #define PAL_CS_NATIVE_DATA_SIZE 76
  2933. #elif defined(__APPLE__) && defined(__x86_64__)
  2934. #define PAL_CS_NATIVE_DATA_SIZE 120
  2935. #elif defined(__LINUX__) && defined(__x86_64__)
  2936. #define PAL_CS_NATIVE_DATA_SIZE 96
  2937. #elif defined(__LINUX__) && defined(_ARM_)
  2938. #define PAL_CS_NATIVE_DATA_SIZE 80
  2939. #elif defined(__LINUX__) && defined(_ARM64_)
  2940. #define PAL_CS_NATIVE_DATA_SIZE 116
  2941. #else
  2942. #warning
  2943. #error PAL_CS_NATIVE_DATA_SIZE is not defined for this architecture
  2944. #endif
  2945. #endif // PLATFORM_UNIX
  2946. //
  2947. typedef struct _CRITICAL_SECTION {
  2948. PVOID DebugInfo;
  2949. LONG LockCount;
  2950. LONG RecursionCount;
  2951. HANDLE OwningThread;
  2952. HANDLE LockSemaphore;
  2953. ULONG_PTR SpinCount;
  2954. #ifdef PLATFORM_UNIX
  2955. BOOL bInternal;
  2956. volatile DWORD dwInitState;
  2957. union CSNativeDataStorage
  2958. {
  2959. BYTE rgNativeDataStorage[PAL_CS_NATIVE_DATA_SIZE];
  2960. VOID * pvAlign; // make sure the storage is machine-pointer-size aligned
  2961. } csnds;
  2962. #endif // PLATFORM_UNIX
  2963. } CRITICAL_SECTION, *PCRITICAL_SECTION, *LPCRITICAL_SECTION;
  2964. PALIMPORT VOID PALAPI EnterCriticalSection(IN OUT LPCRITICAL_SECTION lpCriticalSection);
  2965. PALIMPORT VOID PALAPI LeaveCriticalSection(IN OUT LPCRITICAL_SECTION lpCriticalSection);
  2966. PALIMPORT VOID PALAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection);
  2967. PALIMPORT BOOL PALAPI InitializeCriticalSectionAndSpinCount(LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount);
  2968. PALIMPORT BOOL PALAPI InitializeCriticalSectionEx(LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount, DWORD Flags);
  2969. PALIMPORT BOOL PALAPI InitializeCriticalSectionAndSpinCount(LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount);
  2970. PALIMPORT VOID PALAPI DeleteCriticalSection(IN OUT LPCRITICAL_SECTION lpCriticalSection);
  2971. PALIMPORT BOOL PALAPI TryEnterCriticalSection(IN OUT LPCRITICAL_SECTION lpCriticalSection);
  2972. #define SEM_FAILCRITICALERRORS 0x0001
  2973. #define SEM_NOOPENFILEERRORBOX 0x8000
  2974. PALIMPORT
  2975. UINT
  2976. PALAPI
  2977. SetErrorMode(
  2978. IN UINT uMode);
  2979. #define PAGE_NOACCESS 0x01
  2980. #define PAGE_READONLY 0x02
  2981. #define PAGE_READWRITE 0x04
  2982. #define PAGE_WRITECOPY 0x08
  2983. #define PAGE_EXECUTE 0x10
  2984. #define PAGE_EXECUTE_READ 0x20
  2985. #define PAGE_EXECUTE_READWRITE 0x40
  2986. #define PAGE_EXECUTE_WRITECOPY 0x80
  2987. #define MEM_COMMIT 0x1000
  2988. #define MEM_RESERVE 0x2000
  2989. #define MEM_DECOMMIT 0x4000
  2990. #define MEM_RELEASE 0x8000
  2991. #define MEM_RESET 0x80000
  2992. #define MEM_FREE 0x10000
  2993. #define MEM_PRIVATE 0x20000
  2994. #define MEM_MAPPED 0x40000
  2995. #define MEM_TOP_DOWN 0x100000
  2996. #define MEM_WRITE_WATCH 0x200000
  2997. #define MEM_RESERVE_EXECUTABLE 0x40000000 // reserve memory using executable memory allocator
  2998. PALIMPORT
  2999. HANDLE
  3000. PALAPI
  3001. CreateFileMappingA(
  3002. IN HANDLE hFile,
  3003. IN LPSECURITY_ATTRIBUTES lpFileMappingAttributes,
  3004. IN DWORD flProtect,
  3005. IN DWORD dwMaximumSizeHigh,
  3006. IN DWORD dwMaximumSizeLow,
  3007. IN LPCSTR lpName);
  3008. PALIMPORT
  3009. HANDLE
  3010. PALAPI
  3011. CreateFileMappingW(
  3012. IN HANDLE hFile,
  3013. IN LPSECURITY_ATTRIBUTES lpFileMappingAttributes,
  3014. IN DWORD flProtect,
  3015. IN DWORD dwMaxmimumSizeHigh,
  3016. IN DWORD dwMaximumSizeLow,
  3017. IN LPCWSTR lpName);
  3018. #ifdef UNICODE
  3019. #define CreateFileMapping CreateFileMappingW
  3020. #else
  3021. #define CreateFileMapping CreateFileMappingA
  3022. #endif
  3023. #define SECTION_QUERY 0x0001
  3024. #define SECTION_MAP_WRITE 0x0002
  3025. #define SECTION_MAP_READ 0x0004
  3026. #define SECTION_ALL_ACCESS (SECTION_MAP_READ | SECTION_MAP_WRITE) // diff from winnt.h
  3027. #define FILE_MAP_WRITE SECTION_MAP_WRITE
  3028. #define FILE_MAP_READ SECTION_MAP_READ
  3029. #define FILE_MAP_ALL_ACCESS SECTION_ALL_ACCESS
  3030. #define FILE_MAP_COPY SECTION_QUERY
  3031. PALIMPORT
  3032. HANDLE
  3033. PALAPI
  3034. OpenFileMappingA(
  3035. IN DWORD dwDesiredAccess,
  3036. IN BOOL bInheritHandle,
  3037. IN LPCSTR lpName);
  3038. PALIMPORT
  3039. HANDLE
  3040. PALAPI
  3041. OpenFileMappingW(
  3042. IN DWORD dwDesiredAccess,
  3043. IN BOOL bInheritHandle,
  3044. IN LPCWSTR lpName);
  3045. #ifdef UNICODE
  3046. #define OpenFileMapping OpenFileMappingW
  3047. #else
  3048. #define OpenFileMapping OpenFileMappingA
  3049. #endif
  3050. PALIMPORT
  3051. LPVOID
  3052. PALAPI
  3053. MapViewOfFile(
  3054. IN HANDLE hFileMappingObject,
  3055. IN DWORD dwDesiredAccess,
  3056. IN DWORD dwFileOffsetHigh,
  3057. IN DWORD dwFileOffsetLow,
  3058. IN SIZE_T dwNumberOfBytesToMap);
  3059. PALIMPORT
  3060. LPVOID
  3061. PALAPI
  3062. MapViewOfFileEx(
  3063. IN HANDLE hFileMappingObject,
  3064. IN DWORD dwDesiredAccess,
  3065. IN DWORD dwFileOffsetHigh,
  3066. IN DWORD dwFileOffsetLow,
  3067. IN SIZE_T dwNumberOfBytesToMap,
  3068. IN LPVOID lpBaseAddress);
  3069. PALIMPORT
  3070. BOOL
  3071. PALAPI
  3072. FlushViewOfFile(
  3073. IN LPVOID lpBaseAddress,
  3074. IN SIZE_T dwNumberOfBytesToFlush);
  3075. PALIMPORT
  3076. BOOL
  3077. PALAPI
  3078. UnmapViewOfFile(
  3079. IN LPCVOID lpBaseAddress);
  3080. PALIMPORT
  3081. HMODULE
  3082. PALAPI
  3083. LoadLibraryA(
  3084. IN LPCSTR lpLibFileName);
  3085. PALIMPORT
  3086. HMODULE
  3087. PALAPI
  3088. LoadLibraryW(
  3089. IN LPCWSTR lpLibFileName);
  3090. PALIMPORT
  3091. HMODULE
  3092. PALAPI
  3093. LoadLibraryExA(
  3094. IN LPCSTR lpLibFileName,
  3095. IN /*Reserved*/ HANDLE hFile,
  3096. IN DWORD dwFlags);
  3097. PALIMPORT
  3098. HMODULE
  3099. PALAPI
  3100. LoadLibraryExW(
  3101. IN LPCWSTR lpLibFileName,
  3102. IN /*Reserved*/ HANDLE hFile,
  3103. IN DWORD dwFlags);
  3104. PALIMPORT
  3105. void *
  3106. PALAPI
  3107. PAL_LoadLibraryDirect(
  3108. IN LPCWSTR lpLibFileName);
  3109. PALIMPORT
  3110. HMODULE
  3111. PALAPI
  3112. PAL_RegisterLibraryDirect(
  3113. IN void *dl_handle,
  3114. IN LPCWSTR lpLibFileName);
  3115. /*++
  3116. Function:
  3117. PAL_LOADLoadPEFile
  3118. Abstract
  3119. Loads a PE file into memory. Properly maps all of the sections in the PE file. Returns a pointer to the
  3120. loaded base.
  3121. Parameters:
  3122. IN hFile - The file to load
  3123. Return value:
  3124. A valid base address if successful.
  3125. 0 if failure
  3126. --*/
  3127. void *
  3128. PALAPI
  3129. PAL_LOADLoadPEFile(HANDLE hFile);
  3130. /*++
  3131. PAL_LOADUnloadPEFile
  3132. Unload a PE file that was loaded by PAL_LOADLoadPEFile().
  3133. Parameters:
  3134. IN ptr - the file pointer returned by PAL_LOADLoadPEFile()
  3135. Return value:
  3136. TRUE - success
  3137. FALSE - failure (incorrect ptr, etc.)
  3138. --*/
  3139. BOOL
  3140. PALAPI
  3141. PAL_LOADUnloadPEFile(void * ptr);
  3142. #ifdef UNICODE
  3143. #define LoadLibrary LoadLibraryW
  3144. #define LoadLibraryEx LoadLibraryExW
  3145. #else
  3146. #define LoadLibrary LoadLibraryA
  3147. #define LoadLibraryEx LoadLibraryExA
  3148. #endif
  3149. typedef INT_PTR (PALAPI *FARPROC)();
  3150. PALIMPORT
  3151. FARPROC
  3152. PALAPI
  3153. GetProcAddress(
  3154. IN HMODULE hModule,
  3155. IN LPCSTR lpProcName);
  3156. PALIMPORT
  3157. BOOL
  3158. PALAPI
  3159. FreeLibrary(
  3160. IN OUT HMODULE hLibModule);
  3161. PALIMPORT
  3162. PAL_NORETURN
  3163. VOID
  3164. PALAPI
  3165. FreeLibraryAndExitThread(
  3166. IN HMODULE hLibModule,
  3167. IN DWORD dwExitCode);
  3168. PALIMPORT
  3169. BOOL
  3170. PALAPI
  3171. DisableThreadLibraryCalls(
  3172. IN HMODULE hLibModule);
  3173. PALIMPORT
  3174. DWORD
  3175. PALAPI
  3176. GetModuleFileNameA(
  3177. IN HMODULE hModule,
  3178. OUT LPSTR lpFileName,
  3179. IN DWORD nSize);
  3180. PALIMPORT
  3181. DWORD
  3182. PALAPI
  3183. GetModuleFileNameW(
  3184. IN HMODULE hModule,
  3185. OUT LPWSTR lpFileName,
  3186. IN DWORD nSize);
  3187. #ifdef UNICODE
  3188. #define GetModuleFileName GetModuleFileNameW
  3189. #else
  3190. #define GetModuleFileName GetModuleFileNameA
  3191. #endif
  3192. PALIMPORT
  3193. DWORD
  3194. PALAPI
  3195. GetModuleFileNameExW(
  3196. IN HANDLE hProcess,
  3197. IN HMODULE hModule,
  3198. OUT LPWSTR lpFilename,
  3199. IN DWORD nSize
  3200. );
  3201. #ifdef UNICODE
  3202. #define GetModuleFileNameEx GetModuleFileNameExW
  3203. #endif
  3204. // Get base address of the module containing a given symbol
  3205. PALAPI
  3206. LPCVOID
  3207. PAL_GetSymbolModuleBase(void *symbol);
  3208. PALIMPORT
  3209. LPVOID
  3210. PALAPI
  3211. VirtualAlloc(
  3212. IN LPVOID lpAddress,
  3213. IN SIZE_T dwSize,
  3214. IN DWORD flAllocationType,
  3215. IN DWORD flProtect);
  3216. PALIMPORT
  3217. BOOL
  3218. PALAPI
  3219. VirtualFree(
  3220. IN LPVOID lpAddress,
  3221. IN SIZE_T dwSize,
  3222. IN DWORD dwFreeType);
  3223. PALIMPORT
  3224. BOOL
  3225. PALAPI
  3226. VirtualProtect(
  3227. IN LPVOID lpAddress,
  3228. IN SIZE_T dwSize,
  3229. IN DWORD flNewProtect,
  3230. OUT PDWORD lpflOldProtect);
  3231. typedef struct _MEMORYSTATUSEX {
  3232. DWORD dwLength;
  3233. DWORD dwMemoryLoad;
  3234. DWORDLONG ullTotalPhys;
  3235. DWORDLONG ullAvailPhys;
  3236. DWORDLONG ullTotalPageFile;
  3237. DWORDLONG ullAvailPageFile;
  3238. DWORDLONG ullTotalVirtual;
  3239. DWORDLONG ullAvailVirtual;
  3240. DWORDLONG ullAvailExtendedVirtual;
  3241. } MEMORYSTATUSEX, *LPMEMORYSTATUSEX;
  3242. PALIMPORT
  3243. BOOL
  3244. PALAPI
  3245. GlobalMemoryStatusEx(
  3246. IN OUT LPMEMORYSTATUSEX lpBuffer);
  3247. typedef struct _MEMORY_BASIC_INFORMATION {
  3248. PVOID BaseAddress;
  3249. PVOID AllocationBase_PAL_Undefined;
  3250. DWORD AllocationProtect;
  3251. SIZE_T RegionSize;
  3252. DWORD State;
  3253. DWORD Protect;
  3254. DWORD Type;
  3255. } MEMORY_BASIC_INFORMATION, *PMEMORY_BASIC_INFORMATION;
  3256. PALIMPORT
  3257. SIZE_T
  3258. PALAPI
  3259. VirtualQuery(
  3260. IN LPCVOID lpAddress,
  3261. OUT PMEMORY_BASIC_INFORMATION lpBuffer,
  3262. IN SIZE_T dwLength);
  3263. PALIMPORT
  3264. BOOL
  3265. PALAPI
  3266. ReadProcessMemory(
  3267. IN HANDLE hProcess,
  3268. IN LPCVOID lpBaseAddress,
  3269. OUT LPVOID lpBuffer,
  3270. IN SIZE_T nSize,
  3271. OUT SIZE_T * lpNumberOfBytesRead);
  3272. PALIMPORT
  3273. VOID
  3274. PALAPI
  3275. RtlMoveMemory(
  3276. IN PVOID Destination,
  3277. IN CONST VOID *Source,
  3278. IN SIZE_T Length);
  3279. PALIMPORT
  3280. VOID
  3281. PALAPI
  3282. RtlZeroMemory(
  3283. IN PVOID Destination,
  3284. IN SIZE_T Length);
  3285. #define MoveMemory memmove
  3286. #define CopyMemory memcpy
  3287. #define FillMemory(Destination,Length,Fill) memset((Destination),(Fill),(Length))
  3288. #define ZeroMemory(Destination,Length) memset((Destination),0,(Length))
  3289. PALIMPORT
  3290. HANDLE
  3291. PALAPI
  3292. GetProcessHeap(
  3293. VOID);
  3294. #define HEAP_ZERO_MEMORY 0x00000008
  3295. PALIMPORT
  3296. HANDLE
  3297. PALAPI
  3298. HeapCreate(
  3299. IN DWORD flOptions,
  3300. IN SIZE_T dwInitialSize,
  3301. IN SIZE_T dwMaximumSize);
  3302. PALIMPORT
  3303. LPVOID
  3304. PALAPI
  3305. HeapAlloc(
  3306. IN HANDLE hHeap,
  3307. IN DWORD dwFlags,
  3308. IN SIZE_T dwBytes);
  3309. PALIMPORT
  3310. LPVOID
  3311. PALAPI
  3312. HeapReAlloc(
  3313. IN HANDLE hHeap,
  3314. IN DWORD dwFlags,
  3315. IN LPVOID lpMem,
  3316. IN SIZE_T dwBytes
  3317. );
  3318. PALIMPORT
  3319. BOOL
  3320. PALAPI
  3321. HeapFree(
  3322. IN HANDLE hHeap,
  3323. IN DWORD dwFlags,
  3324. IN LPVOID lpMem);
  3325. typedef enum _HEAP_INFORMATION_CLASS {
  3326. HeapCompatibilityInformation,
  3327. HeapEnableTerminationOnCorruption
  3328. } HEAP_INFORMATION_CLASS;
  3329. PALIMPORT
  3330. BOOL
  3331. PALAPI
  3332. HeapSetInformation(
  3333. IN OPTIONAL HANDLE HeapHandle,
  3334. IN HEAP_INFORMATION_CLASS HeapInformationClass,
  3335. IN PVOID HeapInformation,
  3336. IN SIZE_T HeapInformationLength);
  3337. #define LMEM_FIXED 0x0000
  3338. #define LMEM_MOVEABLE 0x0002
  3339. #define LMEM_ZEROINIT 0x0040
  3340. #define LPTR (LMEM_FIXED | LMEM_ZEROINIT)
  3341. PALIMPORT
  3342. HLOCAL
  3343. PALAPI
  3344. LocalAlloc(
  3345. IN UINT uFlags,
  3346. IN SIZE_T uBytes);
  3347. PALIMPORT
  3348. HLOCAL
  3349. PALAPI
  3350. LocalReAlloc(
  3351. IN HLOCAL hMem,
  3352. IN SIZE_T uBytes,
  3353. IN UINT uFlags);
  3354. PALIMPORT
  3355. HLOCAL
  3356. PALAPI
  3357. LocalFree(
  3358. IN HLOCAL hMem);
  3359. PALIMPORT
  3360. BOOL
  3361. PALAPI
  3362. FlushInstructionCache(
  3363. IN HANDLE hProcess,
  3364. IN LPCVOID lpBaseAddress,
  3365. IN SIZE_T dwSize);
  3366. #if ENABLE_DOWNLEVEL_FOR_NLS
  3367. PALIMPORT
  3368. BOOL
  3369. PALAPI
  3370. GetStringTypeExW(
  3371. IN LCID Locale,
  3372. IN DWORD dwInfoType,
  3373. IN LPCWSTR lpSrcStr,
  3374. IN int cchSrc,
  3375. OUT LPWORD lpCharType);
  3376. #ifdef UNICODE
  3377. #define GetStringTypeEx GetStringTypeExW
  3378. #endif
  3379. #endif // ENABLE_DOWNLEVEL_FOR_NLS
  3380. #define NORM_IGNORECASE 0x00000001 // ignore case
  3381. #define NORM_IGNOREWIDTH 0x00020000 // ignore width
  3382. #define NORM_LINGUISTIC_CASING 0x08000000 // use linguistic rules for casing
  3383. #ifdef __APPLE__
  3384. #define NORM_IGNORENONSPACE 0x00000002 // ignore nonspacing chars
  3385. #define NORM_IGNORESYMBOLS 0x00000004 // ignore symbols
  3386. #define NORM_IGNOREKANATYPE 0x00010000 // ignore kanatype
  3387. #define SORT_STRINGSORT 0x00001000 // use string sort method
  3388. #endif // __APPLE__
  3389. typedef struct nlsversioninfo {
  3390. DWORD dwNLSVersionInfoSize;
  3391. DWORD dwNLSVersion;
  3392. DWORD dwDefinedVersion;
  3393. } NLSVERSIONINFO, *LPNLSVERSIONINFO;
  3394. #define CSTR_LESS_THAN 1
  3395. #define CSTR_EQUAL 2
  3396. #define CSTR_GREATER_THAN 3
  3397. #if ENABLE_DOWNLEVEL_FOR_NLS
  3398. PALIMPORT
  3399. int
  3400. PALAPI
  3401. CompareStringA(
  3402. IN LCID Locale,
  3403. IN DWORD dwCmpFlags,
  3404. IN LPCSTR lpString1,
  3405. IN int cchCount1,
  3406. IN LPCSTR lpString2,
  3407. IN int cchCount2);
  3408. PALIMPORT
  3409. int
  3410. PALAPI
  3411. CompareStringW(
  3412. IN LCID Locale,
  3413. IN DWORD dwCmpFlags,
  3414. IN LPCWSTR lpString1,
  3415. IN int cchCount1,
  3416. IN LPCWSTR lpString2,
  3417. IN int cchCount2);
  3418. #endif // ENABLE_DOWNLEVEL_FOR_NLS
  3419. PALIMPORT
  3420. int
  3421. PALAPI
  3422. CompareStringEx(
  3423. IN LPCWSTR lpLocaleName,
  3424. IN DWORD dwCmpFlags,
  3425. IN LPCWSTR lpString1,
  3426. IN int cchCount1,
  3427. IN LPCWSTR lpString2,
  3428. IN int cchCount2,
  3429. IN LPNLSVERSIONINFO lpVersionInformation,
  3430. IN LPVOID lpReserved,
  3431. IN LPARAM lParam);
  3432. #ifdef UNICODE
  3433. #define CompareString CompareStringW
  3434. #endif
  3435. #define MAX_LEADBYTES 12
  3436. #define MAX_DEFAULTCHAR 2
  3437. PALIMPORT
  3438. UINT
  3439. PALAPI
  3440. GetACP(void);
  3441. typedef struct _cpinfo {
  3442. UINT MaxCharSize;
  3443. BYTE DefaultChar[MAX_DEFAULTCHAR];
  3444. BYTE LeadByte[MAX_LEADBYTES];
  3445. } CPINFO, *LPCPINFO;
  3446. PALIMPORT
  3447. BOOL
  3448. PALAPI
  3449. GetCPInfo(
  3450. IN UINT CodePage,
  3451. OUT LPCPINFO lpCPInfo);
  3452. PALIMPORT
  3453. BOOL
  3454. PALAPI
  3455. IsDBCSLeadByteEx(
  3456. IN UINT CodePage,
  3457. IN BYTE TestChar);
  3458. PALIMPORT
  3459. BOOL
  3460. PALAPI
  3461. IsDBCSLeadByte(
  3462. IN BYTE TestChar);
  3463. PALIMPORT
  3464. BOOL
  3465. PALAPI
  3466. IsValidCodePage(
  3467. IN UINT CodePage);
  3468. #define MB_PRECOMPOSED 0x00000001
  3469. #define MB_ERR_INVALID_CHARS 0x00000008
  3470. PALIMPORT
  3471. int
  3472. PALAPI
  3473. MultiByteToWideChar(
  3474. IN UINT CodePage,
  3475. IN DWORD dwFlags,
  3476. IN LPCSTR lpMultiByteStr,
  3477. IN int cbMultiByte,
  3478. OUT LPWSTR lpWideCharStr,
  3479. IN int cchWideChar);
  3480. #define WC_NO_BEST_FIT_CHARS 0x00000400
  3481. PALIMPORT
  3482. int
  3483. PALAPI
  3484. WideCharToMultiByte(
  3485. IN UINT CodePage,
  3486. IN DWORD dwFlags,
  3487. IN LPCWSTR lpWideCharStr,
  3488. IN int cchWideChar,
  3489. OUT LPSTR lpMultiByteStr,
  3490. IN int cbMultyByte,
  3491. IN LPCSTR lpDefaultChar,
  3492. OUT LPBOOL lpUsedDefaultChar);
  3493. #if ENABLE_DOWNLEVEL_FOR_NLS
  3494. PALIMPORT
  3495. LANGID
  3496. PALAPI
  3497. GetSystemDefaultLangID(
  3498. void);
  3499. PALIMPORT
  3500. LANGID
  3501. PALAPI
  3502. GetUserDefaultLangID(
  3503. void);
  3504. PALIMPORT
  3505. BOOL
  3506. PALAPI
  3507. SetThreadLocale(
  3508. IN LCID Locale);
  3509. PALIMPORT
  3510. LCID
  3511. PALAPI
  3512. GetThreadLocale(
  3513. void);
  3514. #endif //ENABLE_DOWNLEVEL_FOR_NLS
  3515. //
  3516. // Locale Types.
  3517. //
  3518. // These types are used for the GetLocaleInfo NLS API routine.
  3519. //
  3520. #ifdef __APPLE__
  3521. //
  3522. // The following LCTypes may be used in combination with any other LCTypes.
  3523. //
  3524. // LOCALE_NOUSEROVERRIDE is also used in GetTimeFormat and
  3525. // GetDateFormat.
  3526. //
  3527. // LOCALE_RETURN_NUMBER will return the result from GetLocaleInfo as a
  3528. // number instead of a string. This flag is only valid for the LCTypes
  3529. // beginning with LOCALE_I.
  3530. //
  3531. #define LOCALE_NOUSEROVERRIDE 0x80000000 /* do not use user overrides */
  3532. #define LOCALE_RETURN_NUMBER 0x20000000 /* return number instead of string */
  3533. #define LOCALE_RETURN_GENITIVE_NAMES 0x10000000 //Flag to return the Genitive forms of month names
  3534. #define LOCALE_SLOCALIZEDDISPLAYNAME 0x00000002 // localized name of locale, eg "German (Germany)" in UI language
  3535. #define LOCALE_SENGLISHDISPLAYNAME 0x00000072 // Display name (language + country usually) in English, eg "German (Germany)"
  3536. #define LOCALE_SNATIVEDISPLAYNAME 0x00000073 // Display name in native locale language, eg "Deutsch (Deutschland)
  3537. #define LOCALE_SLOCALIZEDLANGUAGENAME 0x0000006f // Language Display Name for a language, eg "German" in UI language
  3538. #define LOCALE_SENGLISHLANGUAGENAME 0x00001001 // English name of language, eg "German"
  3539. #define LOCALE_SNATIVELANGUAGENAME 0x00000004 // native name of language, eg "Deutsch"
  3540. #define LOCALE_SLOCALIZEDCOUNTRYNAME 0x00000006 // localized name of country, eg "Germany" in UI language
  3541. #define LOCALE_SENGLISHCOUNTRYNAME 0x00001002 // English name of country, eg "Germany"
  3542. #define LOCALE_SNATIVECOUNTRYNAME 0x00000008 // native name of country, eg "Deutschland"
  3543. //
  3544. // The following LCTypes are mutually exclusive in that they may NOT
  3545. // be used in combination with each other.
  3546. //
  3547. #define LOCALE_ILANGUAGE 0x00000001 /* language id */
  3548. #define LOCALE_SLANGUAGE 0x00000002 /* localized name of language */
  3549. #define LOCALE_SENGLANGUAGE 0x00001001 /* English name of language */
  3550. #define LOCALE_SABBREVLANGNAME 0x00000003 /* abbreviated language name */
  3551. #define LOCALE_SNATIVELANGNAME 0x00000004 /* native name of language */
  3552. #define LOCALE_ICOUNTRY 0x00000005 /* country code */
  3553. #define LOCALE_SCOUNTRY 0x00000006 /* localized name of country */
  3554. #define LOCALE_SENGCOUNTRY 0x00001002 /* English name of country */
  3555. #define LOCALE_SABBREVCTRYNAME 0x00000007 /* abbreviated country name */
  3556. #define LOCALE_SNATIVECTRYNAME 0x00000008 /* native name of country */
  3557. #define LOCALE_SLIST 0x0000000C /* list item separator */
  3558. #define LOCALE_IMEASURE 0x0000000D /* 0 = metric, 1 = US */
  3559. #define LOCALE_SDECIMAL 0x0000000E /* decimal separator */
  3560. #define LOCALE_STHOUSAND 0x0000000F /* thousand separator */
  3561. #define LOCALE_SGROUPING 0x00000010 /* digit grouping */
  3562. #define LOCALE_IDIGITS 0x00000011 /* number of fractional digits */
  3563. #define LOCALE_ILZERO 0x00000012 /* leading zeros for decimal */
  3564. #define LOCALE_INEGNUMBER 0x00001010 /* negative number mode */
  3565. #define LOCALE_SNATIVEDIGITS 0x00000013 /* native ascii 0-9 */
  3566. #define LOCALE_SCURRENCY 0x00000014 /* local monetary symbol */
  3567. #define LOCALE_SINTLSYMBOL 0x00000015 /* intl monetary symbol */
  3568. #define LOCALE_SMONDECIMALSEP 0x00000016 /* monetary decimal separator */
  3569. #define LOCALE_SMONTHOUSANDSEP 0x00000017 /* monetary thousand separator */
  3570. #define LOCALE_SMONGROUPING 0x00000018 /* monetary grouping */
  3571. #define LOCALE_ICURRDIGITS 0x00000019 /* # local monetary digits */
  3572. #define LOCALE_IINTLCURRDIGITS 0x0000001A /* # intl monetary digits */
  3573. #define LOCALE_ICURRENCY 0x0000001B /* positive currency mode */
  3574. #define LOCALE_INEGCURR 0x0000001C /* negative currency mode */
  3575. #define LOCALE_SSHORTDATE 0x0000001F /* short date format string */
  3576. #define LOCALE_SLONGDATE 0x00000020 /* long date format string */
  3577. #define LOCALE_STIMEFORMAT 0x00001003 /* time format string */
  3578. #define LOCALE_S1159 0x00000028 /* AM designator */
  3579. #define LOCALE_S2359 0x00000029 /* PM designator */
  3580. #define LOCALE_ICALENDARTYPE 0x00001009 /* type of calendar specifier */
  3581. #define LOCALE_IFIRSTDAYOFWEEK 0x0000100C /* first day of week specifier */
  3582. #define LOCALE_IFIRSTWEEKOFYEAR 0x0000100D /* first week of year specifier */
  3583. #define LOCALE_SDAYNAME1 0x0000002A /* long name for Monday */
  3584. #define LOCALE_SDAYNAME2 0x0000002B /* long name for Tuesday */
  3585. #define LOCALE_SDAYNAME3 0x0000002C /* long name for Wednesday */
  3586. #define LOCALE_SDAYNAME4 0x0000002D /* long name for Thursday */
  3587. #define LOCALE_SDAYNAME5 0x0000002E /* long name for Friday */
  3588. #define LOCALE_SDAYNAME6 0x0000002F /* long name for Saturday */
  3589. #define LOCALE_SDAYNAME7 0x00000030 /* long name for Sunday */
  3590. #define LOCALE_SABBREVDAYNAME1 0x00000031 /* abbreviated name for Monday */
  3591. #define LOCALE_SABBREVDAYNAME2 0x00000032 /* abbreviated name for Tuesday */
  3592. #define LOCALE_SABBREVDAYNAME3 0x00000033 /* abbreviated name for Wednesday */
  3593. #define LOCALE_SABBREVDAYNAME4 0x00000034 /* abbreviated name for Thursday */
  3594. #define LOCALE_SABBREVDAYNAME5 0x00000035 /* abbreviated name for Friday */
  3595. #define LOCALE_SABBREVDAYNAME6 0x00000036 /* abbreviated name for Saturday */
  3596. #define LOCALE_SABBREVDAYNAME7 0x00000037 /* abbreviated name for Sunday */
  3597. #define LOCALE_SMONTHNAME1 0x00000038 /* long name for January */
  3598. #define LOCALE_SMONTHNAME2 0x00000039 /* long name for February */
  3599. #define LOCALE_SMONTHNAME3 0x0000003A /* long name for March */
  3600. #define LOCALE_SMONTHNAME4 0x0000003B /* long name for April */
  3601. #define LOCALE_SMONTHNAME5 0x0000003C /* long name for May */
  3602. #define LOCALE_SMONTHNAME6 0x0000003D /* long name for June */
  3603. #define LOCALE_SMONTHNAME7 0x0000003E /* long name for July */
  3604. #define LOCALE_SMONTHNAME8 0x0000003F /* long name for August */
  3605. #define LOCALE_SMONTHNAME9 0x00000040 /* long name for September */
  3606. #define LOCALE_SMONTHNAME10 0x00000041 /* long name for October */
  3607. #define LOCALE_SMONTHNAME11 0x00000042 /* long name for November */
  3608. #define LOCALE_SMONTHNAME12 0x00000043 /* long name for December */
  3609. #define LOCALE_SMONTHNAME13 0x0000100E /* long name for 13th month (if exists) */
  3610. #define LOCALE_SABBREVMONTHNAME1 0x00000044 /* abbreviated name for January */
  3611. #define LOCALE_SABBREVMONTHNAME2 0x00000045 /* abbreviated name for February */
  3612. #define LOCALE_SABBREVMONTHNAME3 0x00000046 /* abbreviated name for March */
  3613. #define LOCALE_SABBREVMONTHNAME4 0x00000047 /* abbreviated name for April */
  3614. #define LOCALE_SABBREVMONTHNAME5 0x00000048 /* abbreviated name for May */
  3615. #define LOCALE_SABBREVMONTHNAME6 0x00000049 /* abbreviated name for June */
  3616. #define LOCALE_SABBREVMONTHNAME7 0x0000004A /* abbreviated name for July */
  3617. #define LOCALE_SABBREVMONTHNAME8 0x0000004B /* abbreviated name for August */
  3618. #define LOCALE_SABBREVMONTHNAME9 0x0000004C /* abbreviated name for September */
  3619. #define LOCALE_SABBREVMONTHNAME10 0x0000004D /* abbreviated name for October */
  3620. #define LOCALE_SABBREVMONTHNAME11 0x0000004E /* abbreviated name for November */
  3621. #define LOCALE_SABBREVMONTHNAME12 0x0000004F /* abbreviated name for December */
  3622. #define LOCALE_SABBREVMONTHNAME13 0x0000100F /* abbreviated name for 13th month (if exists) */
  3623. #define LOCALE_SPOSITIVESIGN 0x00000050 /* positive sign */
  3624. #define LOCALE_SNEGATIVESIGN 0x00000051 /* negative sign */
  3625. #define LOCALE_FONTSIGNATURE 0x00000058 /* font signature */
  3626. #define LOCALE_SISO639LANGNAME 0x00000059 /* ISO abbreviated language name */
  3627. #define LOCALE_SISO3166CTRYNAME 0x0000005A /* ISO abbreviated country name */
  3628. #define LOCALE_SENGCURRNAME 0x00001007 /* english name of currency */
  3629. #define LOCALE_SNATIVECURRNAME 0x00001008 /* native name of currency */
  3630. #define LOCALE_SYEARMONTH 0x00001006 /* year month format string */
  3631. #define LOCALE_IDIGITSUBSTITUTION 0x00001014 /* 0 = context, 1 = none, 2 = national */
  3632. #define LOCALE_SNAME 0x0000005C /* locale name <language>[-<Script>][-<REGION>[_<sort order>]] */
  3633. #define LOCALE_SDURATION 0x0000005d /* time duration format */
  3634. #define LOCALE_SKEYBOARDSTOINSTALL 0x0000005e /* (windows only) keyboards to install */
  3635. #define LOCALE_SSHORTESTDAYNAME1 0x00000060 /* Shortest day name for Monday */
  3636. #define LOCALE_SSHORTESTDAYNAME2 0x00000061 /* Shortest day name for Tuesday */
  3637. #define LOCALE_SSHORTESTDAYNAME3 0x00000062 /* Shortest day name for Wednesday */
  3638. #define LOCALE_SSHORTESTDAYNAME4 0x00000063 /* Shortest day name for Thursday */
  3639. #define LOCALE_SSHORTESTDAYNAME5 0x00000064 /* Shortest day name for Friday */
  3640. #define LOCALE_SSHORTESTDAYNAME6 0x00000065 /* Shortest day name for Saturday */
  3641. #define LOCALE_SSHORTESTDAYNAME7 0x00000066 /* Shortest day name for Sunday */
  3642. #define LOCALE_SISO639LANGNAME2 0x00000067 /* 3 character ISO abbreviated language name */
  3643. #define LOCALE_SISO3166CTRYNAME2 0x00000068 /* 3 character ISO country name */
  3644. #define LOCALE_SNAN 0x00000069 /* Not a Number */
  3645. #define LOCALE_SPOSINFINITY 0x0000006a /* + Infinity */
  3646. #define LOCALE_SNEGINFINITY 0x0000006b /* - Infinity */
  3647. #define LOCALE_SSCRIPTS 0x0000006c /* Typical scripts in the locale */
  3648. #define LOCALE_SPARENT 0x0000006d /* Fallback name for resources */
  3649. #define LOCALE_SCONSOLEFALLBACKNAME 0x0000006e /* Fallback name for within the console */
  3650. #define LOCALE_SLANGDISPLAYNAME 0x0000006f /* Language Display Name for a language */
  3651. #define LOCALE_IREADINGLAYOUT 0x00000070 // Returns one of the following 4 reading layout values:
  3652. // 0 - Left to right (eg en-US)
  3653. // 1 - Right to left (eg arabic locales)
  3654. // 2 - Vertical top to bottom with columns to the left and also left to right (ja-JP locales)
  3655. // 3 - Vertical top to bottom with columns proceeding to the right
  3656. #define LOCALE_INEUTRAL 0x00000071 // Returns 0 for specific cultures, 1 for neutral cultures.
  3657. #define LOCALE_INEGATIVEPERCENT 0x00000074 // Returns 0-11 for the negative percent format
  3658. #define LOCALE_IPOSITIVEPERCENT 0x00000075 // Returns 0-3 for the positive percent formatIPOSITIVEPERCENT
  3659. #define LOCALE_SPERCENT 0x00000076 // Returns the percent symbol
  3660. #define LOCALE_SPERMILLE 0x00000077 // Returns the permille (U+2030) symbol
  3661. #define LOCALE_SMONTHDAY 0x00000078 // Returns the preferred month/day format
  3662. #define LOCALE_SSHORTTIME 0x00000079 // Returns the preferred short time format (ie: no seconds, just h:mm)
  3663. #define LOCALE_SOPENTYPELANGUAGETAG 0x0000007a // Open type language tag, eg: "latn" or "dflt"
  3664. #define LOCALE_SSORTLOCALE 0x0000007b // Name of locale to use for sorting/collation/casing behavior.
  3665. #define LCMAP_LINGUISTIC_CASING 0x01000000 /* Use linguistic casing */
  3666. #define CAL_RETURN_GENITIVE_NAMES LOCALE_RETURN_GENITIVE_NAMES // return genitive forms of month names
  3667. #define CAL_SSHORTESTDAYNAME1 0x00000031
  3668. #define CAL_SSHORTESTDAYNAME2 0x00000032
  3669. #define CAL_SSHORTESTDAYNAME3 0x00000033
  3670. #define CAL_SSHORTESTDAYNAME4 0x00000034
  3671. #define CAL_SSHORTESTDAYNAME5 0x00000035
  3672. #define CAL_SSHORTESTDAYNAME6 0x00000036
  3673. #define CAL_SSHORTESTDAYNAME7 0x00000037
  3674. #define CAL_SMONTHDAY 0x00000038 // Month/day pattern (reserve for potential inclusion in a future version)
  3675. #define CAL_SERASTRING 0x00000004 // era name for IYearOffsetRanges, eg A.D.
  3676. #define CAL_SABBREVERASTRING 0x00000039 // Abbreviated era string (eg: AD)
  3677. #define CAL_SSHORTDATE 0x00000005 /* short date format string */
  3678. #define CAL_SLONGDATE 0x00000006 /* long date format string */
  3679. #define CAL_SDAYNAME1 0x00000007 /* native name for Monday */
  3680. #define CAL_SDAYNAME2 0x00000008 /* native name for Tuesday */
  3681. #define CAL_SDAYNAME3 0x00000009 /* native name for Wednesday */
  3682. #define CAL_SDAYNAME4 0x0000000a /* native name for Thursday */
  3683. #define CAL_SDAYNAME5 0x0000000b /* native name for Friday */
  3684. #define CAL_SDAYNAME6 0x0000000c /* native name for Saturday */
  3685. #define CAL_SDAYNAME7 0x0000000d /* native name for Sunday */
  3686. #define CAL_SABBREVDAYNAME1 0x0000000e /* abbreviated name for Monday */
  3687. #define CAL_SABBREVDAYNAME2 0x0000000f /* abbreviated name for Tuesday */
  3688. #define CAL_SABBREVDAYNAME3 0x00000010 /* abbreviated name for Wednesday */
  3689. #define CAL_SABBREVDAYNAME4 0x00000011 /* abbreviated name for Thursday */
  3690. #define CAL_SABBREVDAYNAME5 0x00000012 /* abbreviated name for Friday */
  3691. #define CAL_SABBREVDAYNAME6 0x00000013 /* abbreviated name for Saturday */
  3692. #define CAL_SABBREVDAYNAME7 0x00000014 /* abbreviated name for Sunday */
  3693. #define CAL_SMONTHNAME1 0x00000015 /* native name for January */
  3694. #define CAL_SMONTHNAME2 0x00000016 /* native name for February */
  3695. #define CAL_SMONTHNAME3 0x00000017 /* native name for March */
  3696. #define CAL_SMONTHNAME4 0x00000018 /* native name for April */
  3697. #define CAL_SMONTHNAME5 0x00000019 /* native name for May */
  3698. #define CAL_SMONTHNAME6 0x0000001a /* native name for June */
  3699. #define CAL_SMONTHNAME7 0x0000001b /* native name for July */
  3700. #define CAL_SMONTHNAME8 0x0000001c /* native name for August */
  3701. #define CAL_SMONTHNAME9 0x0000001d /* native name for September */
  3702. #define CAL_SMONTHNAME10 0x0000001e /* native name for October */
  3703. #define CAL_SMONTHNAME11 0x0000001f /* native name for November */
  3704. #define CAL_SMONTHNAME12 0x00000020 /* native name for December */
  3705. #define CAL_SMONTHNAME13 0x00000021 /* native name for 13th month (if any) */
  3706. #define CAL_SABBREVMONTHNAME1 0x00000022 /* abbreviated name for January */
  3707. #define CAL_SABBREVMONTHNAME2 0x00000023 /* abbreviated name for February */
  3708. #define CAL_SABBREVMONTHNAME3 0x00000024 /* abbreviated name for March */
  3709. #define CAL_SABBREVMONTHNAME4 0x00000025 /* abbreviated name for April */
  3710. #define CAL_SABBREVMONTHNAME5 0x00000026 /* abbreviated name for May */
  3711. #define CAL_SABBREVMONTHNAME6 0x00000027 /* abbreviated name for June */
  3712. #define CAL_SABBREVMONTHNAME7 0x00000028 /* abbreviated name for July */
  3713. #define CAL_SABBREVMONTHNAME8 0x00000029 /* abbreviated name for August */
  3714. #define CAL_SABBREVMONTHNAME9 0x0000002a /* abbreviated name for September */
  3715. #define CAL_SABBREVMONTHNAME10 0x0000002b /* abbreviated name for October */
  3716. #define CAL_SABBREVMONTHNAME11 0x0000002c /* abbreviated name for November */
  3717. #define CAL_SABBREVMONTHNAME12 0x0000002d /* abbreviated name for December */
  3718. #define CAL_SABBREVMONTHNAME13 0x0000002e /* abbreviated name for 13th month (if any) */
  3719. #define CAL_SYEARMONTH 0x0000002f /* year month format string */
  3720. #else // __APPLE__
  3721. #define LOCALE_SDECIMAL 0x0000000E /* decimal separator */
  3722. #define LOCALE_STHOUSAND 0x0000000F /* thousand separator */
  3723. #define LOCALE_ILZERO 0x00000012 /* leading zeros for decimal */
  3724. #define LOCALE_SCURRENCY 0x00000014 /* local monetary symbol */
  3725. #define LOCALE_SMONDECIMALSEP 0x00000016 /* monetary decimal separator */
  3726. #define LOCALE_SMONTHOUSANDSEP 0x00000017 /* monetary thousand separator */
  3727. #endif // __APPLE__
  3728. #if ENABLE_DOWNLEVEL_FOR_NLS
  3729. PALIMPORT
  3730. int
  3731. PALAPI
  3732. GetLocaleInfoW(
  3733. IN LCID Locale,
  3734. IN LCTYPE LCType,
  3735. OUT LPWSTR lpLCData,
  3736. IN int cchData);
  3737. #endif // ENABLE_DOWNLEVEL_FOR_NLS
  3738. PALIMPORT
  3739. int
  3740. PALAPI
  3741. GetLocaleInfoEx(
  3742. IN LPCWSTR lpLocaleName,
  3743. IN LCTYPE LCType,
  3744. OUT LPWSTR lpLCData,
  3745. IN int cchData);
  3746. PALIMPORT
  3747. int
  3748. PALAPI
  3749. CompareStringOrdinal(
  3750. IN LPCWSTR lpString1,
  3751. IN int cchCount1,
  3752. IN LPCWSTR lpString2,
  3753. IN int cchCount2,
  3754. IN BOOL bIgnoreCase);
  3755. typedef struct _nlsversioninfoex {
  3756. DWORD dwNLSVersionInfoSize;
  3757. DWORD dwNLSVersion;
  3758. DWORD dwDefinedVersion;
  3759. DWORD dwEffectiveId;
  3760. GUID guidCustomVersion;
  3761. } NLSVERSIONINFOEX, *LPNLSVERSIONINFOEX;
  3762. PALIMPORT
  3763. int
  3764. PALAPI
  3765. FindNLSStringEx(
  3766. IN LPCWSTR lpLocaleName,
  3767. IN DWORD dwFindNLSStringFlags,
  3768. IN LPCWSTR lpStringSource,
  3769. IN int cchSource,
  3770. IN LPCWSTR lpStringValue,
  3771. IN int cchValue,
  3772. OUT LPINT pcchFound,
  3773. IN LPNLSVERSIONINFOEX lpVersionInformation,
  3774. IN LPVOID lpReserved,
  3775. IN LPARAM lParam );
  3776. typedef enum {
  3777. COMPARE_STRING = 0x0001,
  3778. } NLS_FUNCTION;
  3779. PALIMPORT
  3780. BOOL
  3781. PALAPI
  3782. IsNLSDefinedString(
  3783. IN NLS_FUNCTION Function,
  3784. IN DWORD dwFlags,
  3785. IN LPNLSVERSIONINFOEX lpVersionInfo,
  3786. IN LPCWSTR lpString,
  3787. IN int cchStr );
  3788. PALIMPORT
  3789. int
  3790. PALAPI
  3791. ResolveLocaleName(
  3792. IN LPCWSTR lpNameToResolve,
  3793. OUT LPWSTR lpLocaleName,
  3794. IN int cchLocaleName );
  3795. PALIMPORT
  3796. BOOL
  3797. PALAPI
  3798. GetThreadPreferredUILanguages(
  3799. IN DWORD dwFlags,
  3800. OUT PULONG pulNumLanguages,
  3801. OUT PWSTR pwszLanguagesBuffer,
  3802. IN OUT PULONG pcchLanguagesBuffer);
  3803. PALIMPORT
  3804. int
  3805. PALAPI
  3806. GetSystemDefaultLocaleName(
  3807. OUT LPWSTR lpLocaleName,
  3808. IN int cchLocaleName);
  3809. #ifdef UNICODE
  3810. #define GetLocaleInfo GetLocaleInfoW
  3811. #endif
  3812. #if ENABLE_DOWNLEVEL_FOR_NLS
  3813. PALIMPORT
  3814. LCID
  3815. PALAPI
  3816. GetUserDefaultLCID(
  3817. void);
  3818. #endif
  3819. PALIMPORT
  3820. int
  3821. PALAPI
  3822. GetUserDefaultLocaleName(
  3823. OUT LPWSTR lpLocaleName,
  3824. IN int cchLocaleName);
  3825. #define LCID_INSTALLED 0x00000001 // installed locale ids
  3826. #define LCID_SUPPORTED 0x00000002 // supported locale ids
  3827. #ifdef __APPLE__
  3828. #define LCID_ALTERNATE_SORTS 0x00000004 // alternate sort locale ids
  3829. #endif // __APPLE__
  3830. #if ENABLE_DOWNLEVEL_FOR_NLS
  3831. PALIMPORT
  3832. BOOL
  3833. PALAPI
  3834. IsValidLocale(
  3835. IN LCID Locale,
  3836. IN DWORD dwFlags);
  3837. #endif // ENABLE_DOWNLEVEL_FOR_NLS
  3838. typedef DWORD CALID;
  3839. typedef DWORD CALTYPE;
  3840. #define CAL_ITWODIGITYEARMAX 0x00000030 // two digit year max
  3841. #define CAL_RETURN_NUMBER 0x20000000 // return number instead of string
  3842. #define CAL_GREGORIAN 1 // Gregorian (localized) calendar
  3843. #define CAL_GREGORIAN_US 2 // Gregorian (U.S.) calendar
  3844. #define CAL_JAPAN 3 // Japanese Emperor Era calendar
  3845. #define CAL_TAIWAN 4 // Taiwan Era calendar
  3846. #define CAL_KOREA 5 // Korean Tangun Era calendar
  3847. #define CAL_HIJRI 6 // Hijri (Arabic Lunar) calendar
  3848. #define CAL_THAI 7 // Thai calendar
  3849. #define CAL_HEBREW 8 // Hebrew (Lunar) calendar
  3850. #define CAL_GREGORIAN_ME_FRENCH 9 // Gregorian Middle East French calendar
  3851. #define CAL_GREGORIAN_ARABIC 10 // Gregorian Arabic calendar
  3852. #define CAL_GREGORIAN_XLIT_ENGLISH 11 // Gregorian Transliterated English calendar
  3853. #define CAL_GREGORIAN_XLIT_FRENCH 12 // Gregorian Transliterated French calendar
  3854. #define CAL_JULIAN 13
  3855. #if ENABLE_DOWNLEVEL_FOR_NLS
  3856. PALIMPORT
  3857. int
  3858. PALAPI
  3859. GetCalendarInfoW(
  3860. IN LCID Locale,
  3861. IN CALID Calendar,
  3862. IN CALTYPE CalType,
  3863. OUT LPWSTR lpCalData,
  3864. IN int cchData,
  3865. OUT LPDWORD lpValue);
  3866. #ifdef UNICODE
  3867. #define GetCalendarInfo GetCalendarInfoW
  3868. #endif
  3869. #endif // ENABLE_DOWNLEVEL_FOR_NLS
  3870. PALIMPORT
  3871. int
  3872. PALAPI
  3873. GetCalendarInfoEx(
  3874. IN LPCWSTR lpLocaleName,
  3875. IN CALID Calendar,
  3876. IN LPCWSTR lpReserved,
  3877. IN CALTYPE CalType,
  3878. OUT LPWSTR lpCalData,
  3879. IN int cchData,
  3880. OUT LPDWORD lpValue);
  3881. #if ENABLE_DOWNLEVEL_FOR_NLS
  3882. typedef BOOL (CALLBACK* LOCALE_ENUMPROCW)(LPWSTR);
  3883. PALIMPORT
  3884. BOOL
  3885. PALAPI
  3886. EnumSystemLocalesW(
  3887. IN LOCALE_ENUMPROCW lpLocaleEnumProc,
  3888. IN DWORD dwFlags);
  3889. #endif // ENABLE_DOWNLEVEL_FOR_NLS
  3890. #define DATE_SHORTDATE 0x00000001 // use short date picture
  3891. #define DATE_LONGDATE 0x00000002 // use long date picture
  3892. #define DATE_YEARMONTH 0x00000008 // use year month picture
  3893. typedef BOOL (CALLBACK* DATEFMT_ENUMPROCEXW)(LPWSTR, CALID);
  3894. #if ENABLE_DOWNLEVEL_FOR_NLS
  3895. PALIMPORT
  3896. BOOL
  3897. PALAPI
  3898. EnumDateFormatsExW(
  3899. IN DATEFMT_ENUMPROCEXW lpDateFmtEnumProcEx,
  3900. IN LCID Locale,
  3901. IN DWORD dwFlags);
  3902. #else // ENABLE_DOWNLEVEL_FOR_NLS
  3903. typedef BOOL (CALLBACK* DATEFMT_ENUMPROCEXEXW)(LPWSTR, CALID, LPARAM);
  3904. PALIMPORT
  3905. BOOL
  3906. PALAPI
  3907. EnumDateFormatsExEx(
  3908. IN DATEFMT_ENUMPROCEXEXW lpDateFmtEnumProcEx,
  3909. IN LPCWSTR lpLocaleName,
  3910. IN DWORD dwFlags,
  3911. IN LPARAM lParam);
  3912. #endif // ENABLE_DOWNLEVEL_FOR_NLS
  3913. typedef BOOL (CALLBACK* TIMEFMT_ENUMPROCW)(LPWSTR);
  3914. #if ENABLE_DOWNLEVEL_FOR_NLS
  3915. PALIMPORT
  3916. BOOL
  3917. PALAPI
  3918. EnumTimeFormatsW(
  3919. IN TIMEFMT_ENUMPROCW lpTimeFmtEnumProc,
  3920. IN LCID Locale,
  3921. IN DWORD dwFlags);
  3922. #else // ENABLE_DOWNLEVEL_FOR_NLS
  3923. typedef BOOL (CALLBACK* TIMEFMT_ENUMPROCEXW)(LPWSTR, LPARAM);
  3924. PALIMPORT
  3925. BOOL
  3926. PALAPI
  3927. EnumTimeFormatsEx(
  3928. IN TIMEFMT_ENUMPROCEXW lpTimeFmtEnumProc,
  3929. IN LPCWSTR lpLocaleName,
  3930. IN DWORD dwFlags,
  3931. IN LPARAM lParam);
  3932. #endif // ENABLE_DOWNLEVEL_FOR_NLS
  3933. #define ENUM_ALL_CALENDARS 0xffffffff // enumerate all calendars
  3934. #define CAL_ICALINTVALUE 0x00000001 // calendar type
  3935. #define CAL_NOUSEROVERRIDE LOCALE_NOUSEROVERRIDE // do not use user overrides
  3936. #define CAL_SCALNAME 0x00000002 // native name of calendar
  3937. typedef BOOL (CALLBACK* CALINFO_ENUMPROCEXW)(LPWSTR,CALID);
  3938. #if ENABLE_DOWNLEVEL_FOR_NLS
  3939. PALIMPORT
  3940. BOOL
  3941. PALAPI
  3942. EnumCalendarInfoExW(
  3943. IN CALINFO_ENUMPROCEXW lpCalInfoEnumProc,
  3944. IN LCID Locale,
  3945. IN CALID Calendar,
  3946. IN CALTYPE CalType);
  3947. #else // ENABLE_DOWNLEVEL_FOR_NLS
  3948. typedef BOOL (CALLBACK* CALINFO_ENUMPROCEXEXW)(LPWSTR, CALID, LPWSTR, LPARAM);
  3949. PALIMPORT
  3950. BOOL
  3951. PALAPI
  3952. EnumCalendarInfoExEx(
  3953. IN CALINFO_ENUMPROCEXEXW lpCalInfoEnumProc,
  3954. IN LPCWSTR lpLocaleName,
  3955. IN CALID Calendar,
  3956. IN LPCWSTR lpReserved,
  3957. IN CALTYPE CalType,
  3958. IN LPARAM lParam);
  3959. #endif // ENABLE_DOWNLEVEL_FOR_NLS
  3960. #define LCMAP_LOWERCASE 0x00000100
  3961. #define LCMAP_UPPERCASE 0x00000200
  3962. #if ENABLE_DOWNLEVEL_FOR_NLS
  3963. PALIMPORT
  3964. int
  3965. PALAPI
  3966. LCMapStringW(
  3967. IN LCID Locale,
  3968. IN DWORD dwMapFlags,
  3969. IN LPCWSTR lpSrcStr,
  3970. IN int cchSrc,
  3971. OUT LPWSTR lpDestStr,
  3972. IN int cchDest);
  3973. #ifdef UNICODE
  3974. #define LCMapString LCMapStringW
  3975. #endif
  3976. #endif // ENABLE_DOWNLEVEL_FOR_NLS
  3977. PALIMPORT
  3978. int
  3979. PALAPI
  3980. LCMapStringEx(
  3981. IN LPCWSTR lpLocaleName,
  3982. IN DWORD dwMapFlags,
  3983. IN LPCWSTR lpSrcStr,
  3984. IN int cchSrc,
  3985. OUT LPWSTR lpDestStr,
  3986. IN int cchDest,
  3987. IN LPNLSVERSIONINFO lpVersionInformation,
  3988. IN LPVOID lpReserved,
  3989. IN LPARAM lParam );
  3990. PALIMPORT
  3991. int
  3992. PALAPI
  3993. PAL_LCMapCharW(
  3994. IN LPCWSTR lpLocaleName,
  3995. IN DWORD dwMapFlags,
  3996. IN WCHAR srcChar,
  3997. OUT WCHAR *destChar,
  3998. LPNLSVERSIONINFO lpVersionInformation,
  3999. LPVOID lpReserved,
  4000. LPARAM lParam );
  4001. PALIMPORT
  4002. int
  4003. PALAPI
  4004. PAL_NormalizeStringExW(
  4005. IN LPCWSTR lpLocaleName,
  4006. IN DWORD dwMapFlags,
  4007. IN LPCWSTR lpSrcStr,
  4008. IN int cchSrc,
  4009. OUT LPWSTR lpDestStr,
  4010. IN int cchDest);
  4011. PALIMPORT
  4012. int
  4013. PALAPI
  4014. PAL_ParseDateW(
  4015. IN LPCWSTR lpLocaleName,
  4016. IN LPCWSTR lpFormat,
  4017. IN LPCWSTR lpString,
  4018. OUT LPSYSTEMTIME lpTime);
  4019. PALIMPORT
  4020. int
  4021. PALAPI
  4022. PAL_GetCalendar(
  4023. IN LPCWSTR lpLocaleName,
  4024. OUT CALID* pCalendar);
  4025. #define GEOID_NOT_AVAILABLE -1
  4026. // "a number", might represent different types
  4027. typedef struct PALNUMBER__* PALNUMBER;
  4028. // return NULL on OOM
  4029. PALIMPORT PALNUMBER PALAPI PAL_DoubleToNumber(double);
  4030. PALIMPORT PALNUMBER PALAPI PAL_Int64ToNumber(INT64);
  4031. PALIMPORT PALNUMBER PALAPI PAL_UInt64ToNumber(UINT64);
  4032. PALIMPORT PALNUMBER PALAPI PAL_IntToNumber(int);
  4033. PALIMPORT PALNUMBER PALAPI PAL_UIntToNumber(unsigned int);
  4034. PALIMPORT void PALAPI PAL_ReleaseNumber(PALNUMBER);
  4035. // return string length if Buffer is NULL or the result fits in cchBuffer, otherwise -1
  4036. PALIMPORT int PALAPI PAL_FormatScientific(LPCWSTR sLocale, LPWSTR pBuffer, SIZE_T cchBuffer, PALNUMBER number, int nMinDigits, int nMaxDigits,
  4037. LPCWSTR sExponent, LPCWSTR sNumberDecimal, LPCWSTR sPositive, LPCWSTR sNegative, LPCWSTR sZero);
  4038. PALIMPORT int PALAPI PAL_FormatCurrency(LPCWSTR sLocale, LPWSTR pBuffer, SIZE_T cchBuffer, PALNUMBER number, int nMinDigits, int nMaxDigits, int iNegativeFormat, int iPositiveFormat,
  4039. int iPrimaryGroup, int iSecondaryGroup, LPCWSTR sCurrencyDecimal, LPCWSTR sCurrencyGroup, LPCWSTR sNegative, LPCWSTR sCurrency, LPCWSTR sZero);
  4040. PALIMPORT int PALAPI PAL_FormatPercent(LPCWSTR sLocale, LPWSTR pBuffer, SIZE_T cchBuffer, PALNUMBER number, int nMinDigits, int nMaxDigits,int iNegativeFormat, int iPositiveFormat,
  4041. int iPrimaryGroup, int iSecondaryGroup, LPCWSTR sPercentDecimal, LPCWSTR sPercentGroup, LPCWSTR sNegative, LPCWSTR sPercent, LPCWSTR sZero);
  4042. PALIMPORT int PALAPI PAL_FormatDecimal(LPCWSTR sLocale, LPWSTR pBuffer, SIZE_T cchBuffer, PALNUMBER number, int nMinDigits, int nMaxDigits, int iNegativeFormat,
  4043. int iPrimaryGroup, int iSecondaryGroup, LPCWSTR sDecimal, LPCWSTR sGroup, LPCWSTR sNegative, LPCWSTR sZero);
  4044. #define DATE_USE_ALT_CALENDAR 0x00000004
  4045. #if ENABLE_DOWNLEVEL_FOR_NLS
  4046. PALIMPORT
  4047. int
  4048. PALAPI
  4049. GetDateFormatW(
  4050. IN LCID Locale,
  4051. IN DWORD dwFlags,
  4052. IN CONST SYSTEMTIME *lpDate,
  4053. IN LPCWSTR lpFormat,
  4054. OUT LPWSTR lpDateStr,
  4055. IN int cchDate);
  4056. #else
  4057. PALIMPORT
  4058. int
  4059. PALAPI
  4060. GetDateFormatEx(
  4061. IN LPCWSTR Locale,
  4062. IN DWORD dwFlags,
  4063. IN CONST SYSTEMTIME *lpDate,
  4064. IN LPCWSTR lpFormat,
  4065. OUT LPWSTR lpDateStr,
  4066. IN int cchDate,
  4067. IN LPCWSTR lpCalendar);
  4068. #endif // ENABLE_DOWNLEVEL_FOR_NLS
  4069. PALIMPORT
  4070. int
  4071. PALAPI
  4072. GetDateFormatEx(
  4073. IN LPCWSTR lpLocaleName,
  4074. IN DWORD dwFlags,
  4075. IN CONST SYSTEMTIME *lpDate,
  4076. IN LPCWSTR lpFormat,
  4077. OUT LPWSTR lpDateStr,
  4078. IN int cchDate,
  4079. LPCWSTR lpCalendar);
  4080. #ifdef UNICODE
  4081. #define GetDateFormat GetDateFormatW
  4082. #endif
  4083. PALIMPORT
  4084. int
  4085. PALAPI
  4086. PAL_GetResourceString(
  4087. IN LPCSTR lpDomain,
  4088. IN LPCSTR lpResourceStr,
  4089. OUT LPWSTR lpWideCharStr,
  4090. IN int cchWideChar);
  4091. PALIMPORT
  4092. BOOL
  4093. PALAPI
  4094. PAL_BindResources(IN LPCSTR lpDomain);
  4095. #define EXCEPTION_NONCONTINUABLE 0x1
  4096. #define EXCEPTION_UNWINDING 0x2
  4097. #ifdef FEATURE_PAL_SXS
  4098. #define EXCEPTION_EXIT_UNWIND 0x4 // Exit unwind is in progress (not used by PAL SEH)
  4099. #define EXCEPTION_NESTED_CALL 0x10 // Nested exception handler call
  4100. #define EXCEPTION_TARGET_UNWIND 0x20 // Target unwind in progress
  4101. #define EXCEPTION_COLLIDED_UNWIND 0x40 // Collided exception handler call
  4102. #define EXCEPTION_SKIP_VEH 0x200
  4103. #define EXCEPTION_UNWIND (EXCEPTION_UNWINDING | EXCEPTION_EXIT_UNWIND | \
  4104. EXCEPTION_TARGET_UNWIND | EXCEPTION_COLLIDED_UNWIND)
  4105. #define IS_DISPATCHING(Flag) ((Flag & EXCEPTION_UNWIND) == 0)
  4106. #define IS_UNWINDING(Flag) ((Flag & EXCEPTION_UNWIND) != 0)
  4107. #define IS_TARGET_UNWIND(Flag) (Flag & EXCEPTION_TARGET_UNWIND)
  4108. #endif // FEATURE_PAL_SXS
  4109. #define EXCEPTION_IS_SIGNAL 0x100
  4110. #define EXCEPTION_MAXIMUM_PARAMETERS 15
  4111. // Index in the ExceptionInformation array where we will keep the reference
  4112. // to the native exception that needs to be deleted when dispatching
  4113. // exception in managed code.
  4114. #define NATIVE_EXCEPTION_ASYNC_SLOT (EXCEPTION_MAXIMUM_PARAMETERS-1)
  4115. typedef struct _EXCEPTION_RECORD {
  4116. DWORD ExceptionCode;
  4117. DWORD ExceptionFlags;
  4118. struct _EXCEPTION_RECORD *ExceptionRecord;
  4119. PVOID ExceptionAddress;
  4120. DWORD NumberParameters;
  4121. ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  4122. } EXCEPTION_RECORD, *PEXCEPTION_RECORD;
  4123. typedef struct _EXCEPTION_POINTERS {
  4124. PEXCEPTION_RECORD ExceptionRecord;
  4125. PCONTEXT ContextRecord;
  4126. } EXCEPTION_POINTERS, *PEXCEPTION_POINTERS, *LPEXCEPTION_POINTERS;
  4127. #ifdef FEATURE_PAL_SXS
  4128. typedef LONG EXCEPTION_DISPOSITION;
  4129. enum {
  4130. ExceptionContinueExecution,
  4131. ExceptionContinueSearch,
  4132. ExceptionNestedException,
  4133. ExceptionCollidedUnwind,
  4134. };
  4135. #endif // FEATURE_PAL_SXS
  4136. //
  4137. // A function table entry is generated for each frame function.
  4138. //
  4139. typedef struct _RUNTIME_FUNCTION {
  4140. DWORD BeginAddress;
  4141. DWORD EndAddress;
  4142. DWORD UnwindData;
  4143. } RUNTIME_FUNCTION, *PRUNTIME_FUNCTION;
  4144. PALIMPORT
  4145. BOOL
  4146. PALAPI
  4147. WriteProcessMemory(IN HANDLE hProcess,
  4148. IN LPVOID lpBaseAddress,
  4149. IN LPCVOID lpBuffer,
  4150. IN SIZE_T nSize,
  4151. OUT SIZE_T * lpNumberOfBytesWritten);
  4152. #define STANDARD_RIGHTS_REQUIRED (0x000F0000L)
  4153. #define SYNCHRONIZE (0x00100000L)
  4154. #define READ_CONTROL (0x00020000L)
  4155. #define EVENT_MODIFY_STATE (0x0002)
  4156. #define EVENT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
  4157. 0x3)
  4158. #define MUTANT_QUERY_STATE (0x0001)
  4159. #define MUTANT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
  4160. MUTANT_QUERY_STATE)
  4161. #define MUTEX_ALL_ACCESS MUTANT_ALL_ACCESS
  4162. #define SEMAPHORE_MODIFY_STATE (0x0002)
  4163. #define SEMAPHORE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
  4164. 0x3)
  4165. #define PROCESS_TERMINATE (0x0001)
  4166. #define PROCESS_CREATE_THREAD (0x0002)
  4167. #define PROCESS_SET_SESSIONID (0x0004)
  4168. #define PROCESS_VM_OPERATION (0x0008)
  4169. #define PROCESS_VM_READ (0x0010)
  4170. #define PROCESS_VM_WRITE (0x0020)
  4171. #define PROCESS_DUP_HANDLE (0x0040)
  4172. #define PROCESS_CREATE_PROCESS (0x0080)
  4173. #define PROCESS_SET_QUOTA (0x0100)
  4174. #define PROCESS_SET_INFORMATION (0x0200)
  4175. #define PROCESS_QUERY_INFORMATION (0x0400)
  4176. #define PROCESS_SUSPEND_RESUME (0x0800)
  4177. #define PROCESS_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
  4178. 0xFFF)
  4179. PALIMPORT
  4180. HANDLE
  4181. PALAPI
  4182. OpenProcess(
  4183. IN DWORD dwDesiredAccess, /* PROCESS_DUP_HANDLE or PROCESS_ALL_ACCESS */
  4184. IN BOOL bInheritHandle,
  4185. IN DWORD dwProcessId
  4186. );
  4187. PALIMPORT
  4188. BOOL
  4189. PALAPI
  4190. EnumProcessModules(
  4191. IN HANDLE hProcess,
  4192. OUT HMODULE *lphModule,
  4193. IN DWORD cb,
  4194. OUT LPDWORD lpcbNeeded
  4195. );
  4196. PALIMPORT
  4197. VOID
  4198. PALAPI
  4199. OutputDebugStringA(
  4200. IN LPCSTR lpOutputString);
  4201. PALIMPORT
  4202. VOID
  4203. PALAPI
  4204. OutputDebugStringW(
  4205. IN LPCWSTR lpOutputStrig);
  4206. #ifdef UNICODE
  4207. #define OutputDebugString OutputDebugStringW
  4208. #else
  4209. #define OutputDebugString OutputDebugStringA
  4210. #endif
  4211. PALIMPORT
  4212. VOID
  4213. PALAPI
  4214. DebugBreak(
  4215. VOID);
  4216. PALIMPORT
  4217. LPWSTR
  4218. PALAPI
  4219. lstrcatW(
  4220. IN OUT LPWSTR lpString1,
  4221. IN LPCWSTR lpString2);
  4222. #ifdef UNICODE
  4223. #define lstrcat lstrcatW
  4224. #endif
  4225. PALIMPORT
  4226. LPWSTR
  4227. PALAPI
  4228. lstrcpyW(
  4229. OUT LPWSTR lpString1,
  4230. IN LPCWSTR lpString2);
  4231. #ifdef UNICODE
  4232. #define lstrcpy lstrcpyW
  4233. #endif
  4234. PALIMPORT
  4235. int
  4236. PALAPI
  4237. lstrlenA(
  4238. IN LPCSTR lpString);
  4239. PALIMPORT
  4240. int
  4241. PALAPI
  4242. lstrlenW(
  4243. IN LPCWSTR lpString);
  4244. #ifdef UNICODE
  4245. #define lstrlen lstrlenW
  4246. #else
  4247. #define lstrlen lstrlenA
  4248. #endif
  4249. PALIMPORT
  4250. LPWSTR
  4251. PALAPI
  4252. lstrcpynW(
  4253. OUT LPWSTR lpString1,
  4254. IN LPCWSTR lpString2,
  4255. IN int iMaxLength);
  4256. #ifdef UNICODE
  4257. #define lstrcpyn lstrcpynW
  4258. #endif
  4259. PALIMPORT
  4260. DWORD
  4261. PALAPI
  4262. GetEnvironmentVariableA(
  4263. IN LPCSTR lpName,
  4264. OUT LPSTR lpBuffer,
  4265. IN DWORD nSize);
  4266. PALIMPORT
  4267. DWORD
  4268. PALAPI
  4269. GetEnvironmentVariableW(
  4270. IN LPCWSTR lpName,
  4271. OUT LPWSTR lpBuffer,
  4272. IN DWORD nSize);
  4273. #ifdef UNICODE
  4274. #define GetEnvironmentVariable GetEnvironmentVariableW
  4275. #else
  4276. #define GetEnvironmentVariable GetEnvironmentVariableA
  4277. #endif
  4278. PALIMPORT
  4279. BOOL
  4280. PALAPI
  4281. SetEnvironmentVariableA(
  4282. IN LPCSTR lpName,
  4283. IN LPCSTR lpValue);
  4284. PALIMPORT
  4285. BOOL
  4286. PALAPI
  4287. SetEnvironmentVariableW(
  4288. IN LPCWSTR lpName,
  4289. IN LPCWSTR lpValue);
  4290. #ifdef UNICODE
  4291. #define SetEnvironmentVariable SetEnvironmentVariableW
  4292. #else
  4293. #define SetEnvironmentVariable SetEnvironmentVariableA
  4294. #endif
  4295. PALIMPORT
  4296. LPSTR
  4297. PALAPI
  4298. GetEnvironmentStringsA(
  4299. VOID);
  4300. PALIMPORT
  4301. LPWSTR
  4302. PALAPI
  4303. GetEnvironmentStringsW(
  4304. VOID);
  4305. #ifdef UNICODE
  4306. #define GetEnvironmentStrings GetEnvironmentStringsW
  4307. #else
  4308. #define GetEnvironmentStrings GetEnvironmentStringsA
  4309. #endif
  4310. PALIMPORT
  4311. BOOL
  4312. PALAPI
  4313. FreeEnvironmentStringsA(
  4314. IN LPSTR);
  4315. PALIMPORT
  4316. BOOL
  4317. PALAPI
  4318. FreeEnvironmentStringsW(
  4319. IN LPWSTR);
  4320. #ifdef UNICODE
  4321. #define FreeEnvironmentStrings FreeEnvironmentStringsW
  4322. #else
  4323. #define FreeEnvironmentStrings FreeEnvironmentStringsA
  4324. #endif
  4325. PALIMPORT
  4326. BOOL
  4327. PALAPI
  4328. CloseHandle(
  4329. IN OUT HANDLE hObject);
  4330. PALIMPORT
  4331. VOID
  4332. PALAPI
  4333. RaiseException(
  4334. IN DWORD dwExceptionCode,
  4335. IN DWORD dwExceptionFlags,
  4336. IN DWORD nNumberOfArguments,
  4337. IN CONST ULONG_PTR *lpArguments);
  4338. #ifdef FEATURE_PAL_SXS
  4339. PALIMPORT
  4340. PAL_NORETURN
  4341. VOID
  4342. PALAPI
  4343. PAL_RaiseException(
  4344. IN PEXCEPTION_POINTERS ExceptionPointers);
  4345. #endif // FEATURE_PAL_SXS
  4346. PALIMPORT
  4347. DWORD
  4348. PALAPI
  4349. GetTickCount(
  4350. VOID);
  4351. PALIMPORT
  4352. ULONGLONG
  4353. PALAPI
  4354. GetTickCount64();
  4355. PALIMPORT
  4356. BOOL
  4357. PALAPI
  4358. QueryPerformanceCounter(
  4359. OUT LARGE_INTEGER *lpPerformanceCount
  4360. );
  4361. PALIMPORT
  4362. BOOL
  4363. PALAPI
  4364. QueryPerformanceFrequency(
  4365. OUT LARGE_INTEGER *lpFrequency
  4366. );
  4367. PALIMPORT
  4368. BOOL
  4369. PALAPI
  4370. QueryThreadCycleTime(
  4371. IN HANDLE ThreadHandle,
  4372. OUT PULONG64 CycleTime);
  4373. #ifndef FEATURE_PAL_SXS
  4374. typedef LONG (PALAPI *PTOP_LEVEL_EXCEPTION_FILTER)(
  4375. struct _EXCEPTION_POINTERS *ExceptionInfo);
  4376. typedef PTOP_LEVEL_EXCEPTION_FILTER LPTOP_LEVEL_EXCEPTION_FILTER;
  4377. PALIMPORT
  4378. LPTOP_LEVEL_EXCEPTION_FILTER
  4379. PALAPI
  4380. SetUnhandledExceptionFilter(
  4381. IN LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter);
  4382. PALIMPORT
  4383. LONG
  4384. UnhandledExceptionFilter(
  4385. IN struct _EXCEPTION_POINTERS *ExceptionInfo);
  4386. PALIMPORT
  4387. LPEXCEPTION_POINTERS
  4388. GetExceptionInformation();
  4389. #else // FEATURE_PAL_SXS
  4390. typedef EXCEPTION_DISPOSITION (PALAPI *PVECTORED_EXCEPTION_HANDLER)(
  4391. struct _EXCEPTION_POINTERS *ExceptionPointers);
  4392. #endif // FEATURE_PAL_SXS
  4393. // Define BitScanForward64 and BitScanForward
  4394. // Per MSDN, BitScanForward64 will search the mask data from LSB to MSB for a set bit.
  4395. // If one is found, its bit position is returned in the out PDWORD argument and 1 is returned.
  4396. // Otherwise, 0 is returned.
  4397. //
  4398. // On GCC, the equivalent function is __builtin_ffsl. It returns 1+index of the least
  4399. // significant set bit, or 0 if if mask is zero.
  4400. //
  4401. // The same is true for BitScanForward, except that the GCC function is __builtin_ffs.
  4402. EXTERN_C
  4403. PALIMPORT
  4404. inline
  4405. unsigned char
  4406. PALAPI
  4407. BitScanForward(
  4408. IN OUT PDWORD Index,
  4409. IN UINT qwMask)
  4410. {
  4411. unsigned char bRet = FALSE;
  4412. int iIndex = __builtin_ffsl(qwMask);
  4413. if (iIndex != 0)
  4414. {
  4415. // Set the Index after deducting unity
  4416. *Index = (DWORD)(iIndex - 1);
  4417. bRet = TRUE;
  4418. }
  4419. return bRet;
  4420. }
  4421. EXTERN_C
  4422. PALIMPORT
  4423. inline
  4424. unsigned char
  4425. PALAPI
  4426. BitScanForward64(
  4427. IN OUT PDWORD Index,
  4428. IN UINT64 qwMask)
  4429. {
  4430. unsigned char bRet = FALSE;
  4431. int iIndex = __builtin_ffsl(qwMask);
  4432. if (iIndex != 0)
  4433. {
  4434. // Set the Index after deducting unity
  4435. *Index = (DWORD)(iIndex - 1);
  4436. bRet = TRUE;
  4437. }
  4438. return bRet;
  4439. }
  4440. // xplat-todo: review this implementation
  4441. EXTERN_C
  4442. PALIMPORT
  4443. inline
  4444. unsigned char
  4445. PALAPI
  4446. BitScanReverse(
  4447. IN OUT PDWORD Index,
  4448. IN UINT qwMask)
  4449. {
  4450. unsigned char bRet = FALSE;
  4451. if (qwMask != 0)
  4452. {
  4453. int countLeadingZero = __builtin_clz(qwMask);
  4454. *Index = (DWORD)(sizeof(qwMask) * 8 - 1 - countLeadingZero);
  4455. bRet = TRUE;
  4456. }
  4457. return bRet;
  4458. }
  4459. // xplat-todo: review this implementation
  4460. EXTERN_C
  4461. PALIMPORT
  4462. inline
  4463. unsigned char
  4464. PALAPI
  4465. BitScanReverse64(
  4466. IN OUT PDWORD Index,
  4467. IN UINT64 qwMask)
  4468. {
  4469. unsigned char bRet = FALSE;
  4470. if (qwMask != 0)
  4471. {
  4472. int countLeadingZero = __builtin_clz(qwMask);
  4473. *Index = (DWORD)(sizeof(qwMask) * 8 - 1 - countLeadingZero);
  4474. bRet = TRUE;
  4475. }
  4476. return bRet;
  4477. }
  4478. /*++
  4479. Function:
  4480. InterlockedIncrement
  4481. The InterlockedIncrement function increments (increases by one) the
  4482. value of the specified variable and checks the resulting value. The
  4483. function prevents more than one thread from using the same variable
  4484. simultaneously.
  4485. Parameters
  4486. lpAddend
  4487. [in/out] Pointer to the variable to increment.
  4488. Return Values
  4489. The return value is the resulting incremented value.
  4490. --*/
  4491. EXTERN_C
  4492. PALIMPORT
  4493. inline
  4494. LONG
  4495. PALAPI
  4496. InterlockedIncrement(
  4497. IN OUT LONG volatile *lpAddend)
  4498. {
  4499. return __sync_add_and_fetch(lpAddend, (LONG)1);
  4500. }
  4501. EXTERN_C
  4502. PALIMPORT
  4503. inline
  4504. LONGLONG
  4505. PALAPI
  4506. InterlockedIncrement16(
  4507. IN OUT SHORT volatile *lpAddend)
  4508. {
  4509. return __sync_add_and_fetch(lpAddend, (SHORT)1);
  4510. }
  4511. EXTERN_C
  4512. PALIMPORT
  4513. inline
  4514. LONGLONG
  4515. PALAPI
  4516. InterlockedIncrement64(
  4517. IN OUT LONGLONG volatile *lpAddend)
  4518. {
  4519. return __sync_add_and_fetch(lpAddend, (LONGLONG)1);
  4520. }
  4521. /*++
  4522. Function:
  4523. InterlockedDecrement
  4524. The InterlockedDecrement function decrements (decreases by one) the
  4525. value of the specified variable and checks the resulting value. The
  4526. function prevents more than one thread from using the same variable
  4527. simultaneously.
  4528. Parameters
  4529. lpAddend
  4530. [in/out] Pointer to the variable to decrement.
  4531. Return Values
  4532. The return value is the resulting decremented value.
  4533. --*/
  4534. EXTERN_C
  4535. PALIMPORT
  4536. inline
  4537. LONG
  4538. PALAPI
  4539. InterlockedDecrement(
  4540. IN OUT LONG volatile *lpAddend)
  4541. {
  4542. return __sync_sub_and_fetch(lpAddend, (LONG)1);
  4543. }
  4544. EXTERN_C
  4545. PALIMPORT
  4546. inline
  4547. LONGLONG
  4548. PALAPI
  4549. InterlockedDecrement64(
  4550. IN OUT LONGLONG volatile *lpAddend)
  4551. {
  4552. return __sync_sub_and_fetch(lpAddend, (LONGLONG)1);
  4553. }
  4554. /*++
  4555. Function:
  4556. InterlockedExchange
  4557. The InterlockedExchange function atomically exchanges a pair of
  4558. values. The function prevents more than one thread from using the same
  4559. variable simultaneously.
  4560. Parameters
  4561. Target
  4562. [in/out] Pointer to the value to exchange. The function sets
  4563. this variable to Value, and returns its prior value.
  4564. Value
  4565. [in] Specifies a new value for the variable pointed to by Target.
  4566. Return Values
  4567. The function returns the initial value pointed to by Target.
  4568. --*/
  4569. EXTERN_C
  4570. PALIMPORT
  4571. inline
  4572. LONG
  4573. PALAPI
  4574. InterlockedExchange(
  4575. IN OUT LONG volatile *Target,
  4576. IN LONG Value)
  4577. {
  4578. return __sync_swap(Target, Value);
  4579. }
  4580. EXTERN_C
  4581. PALIMPORT
  4582. inline
  4583. LONGLONG
  4584. PALAPI
  4585. InterlockedExchange64(
  4586. IN OUT LONGLONG volatile *Target,
  4587. IN LONGLONG Value)
  4588. {
  4589. return __sync_swap(Target, Value);
  4590. }
  4591. /*++
  4592. Function:
  4593. InterlockedCompareExchange
  4594. The InterlockedCompareExchange function performs an atomic comparison
  4595. of the specified values and exchanges the values, based on the outcome
  4596. of the comparison. The function prevents more than one thread from
  4597. using the same variable simultaneously.
  4598. If you are exchanging pointer values, this function has been
  4599. superseded by the InterlockedCompareExchangePointer function.
  4600. Parameters
  4601. Destination [in/out] Specifies the address of the destination value. The sign is ignored.
  4602. Exchange [in] Specifies the exchange value. The sign is ignored.
  4603. Comperand [in] Specifies the value to compare to Destination. The sign is ignored.
  4604. Return Values
  4605. The return value is the initial value of the destination.
  4606. --*/
  4607. EXTERN_C
  4608. PALIMPORT
  4609. inline
  4610. LONG
  4611. PALAPI
  4612. InterlockedCompareExchange(
  4613. IN OUT LONG volatile *Destination,
  4614. IN LONG Exchange,
  4615. IN LONG Comperand)
  4616. {
  4617. return __sync_val_compare_and_swap(
  4618. Destination, /* The pointer to a variable whose value is to be compared with. */
  4619. Comperand, /* The value to be compared */
  4620. Exchange /* The value to be stored */);
  4621. }
  4622. EXTERN_C
  4623. PALIMPORT
  4624. inline
  4625. LONG
  4626. PALAPI
  4627. InterlockedCompareExchangeAcquire(
  4628. IN OUT LONG volatile *Destination,
  4629. IN LONG Exchange,
  4630. IN LONG Comperand)
  4631. {
  4632. // TODO: implement the version with only the acquire semantics
  4633. return __sync_val_compare_and_swap(
  4634. Destination, /* The pointer to a variable whose value is to be compared with. */
  4635. Comperand, /* The value to be compared */
  4636. Exchange /* The value to be stored */);
  4637. }
  4638. EXTERN_C
  4639. PALIMPORT
  4640. inline
  4641. LONG
  4642. PALAPI
  4643. InterlockedCompareExchangeRelease(
  4644. IN OUT LONG volatile *Destination,
  4645. IN LONG Exchange,
  4646. IN LONG Comperand)
  4647. {
  4648. // TODO: implement the version with only the release semantics
  4649. return __sync_val_compare_and_swap(
  4650. Destination, /* The pointer to a variable whose value is to be compared with. */
  4651. Comperand, /* The value to be compared */
  4652. Exchange /* The value to be stored */);
  4653. }
  4654. // See the 32-bit variant in interlock2.s
  4655. EXTERN_C
  4656. PALIMPORT
  4657. inline
  4658. LONGLONG
  4659. PALAPI
  4660. InterlockedCompareExchange64(
  4661. IN OUT LONGLONG volatile *Destination,
  4662. IN LONGLONG Exchange,
  4663. IN LONGLONG Comperand)
  4664. {
  4665. return __sync_val_compare_and_swap(
  4666. Destination, /* The pointer to a variable whose value is to be compared with. */
  4667. Comperand, /* The value to be compared */
  4668. Exchange /* The value to be stored */);
  4669. }
  4670. /*++
  4671. Function:
  4672. InterlockedExchangeAdd
  4673. The InterlockedExchangeAdd function atomically adds the value of 'Value'
  4674. to the variable that 'Addend' points to.
  4675. Parameters
  4676. lpAddend
  4677. [in/out] Pointer to the variable to to added.
  4678. Return Values
  4679. The return value is the original value that 'Addend' pointed to.
  4680. --*/
  4681. EXTERN_C
  4682. PALIMPORT
  4683. inline
  4684. LONG
  4685. PALAPI
  4686. InterlockedExchangeAdd(
  4687. IN OUT LONG volatile *Addend,
  4688. IN LONG Value)
  4689. {
  4690. return __sync_fetch_and_add(Addend, Value);
  4691. }
  4692. EXTERN_C
  4693. PALIMPORT
  4694. inline
  4695. LONG
  4696. PALAPI
  4697. InterlockedAdd(
  4698. IN OUT LONG volatile *Addend,
  4699. IN LONG Value)
  4700. {
  4701. return InterlockedExchangeAdd(Addend, Value) + Value;
  4702. }
  4703. EXTERN_C
  4704. PALIMPORT
  4705. inline
  4706. LONGLONG
  4707. PALAPI
  4708. InterlockedExchangeAdd64(
  4709. IN OUT LONGLONG volatile *Addend,
  4710. IN LONGLONG Value)
  4711. {
  4712. return __sync_fetch_and_add(Addend, Value);
  4713. }
  4714. EXTERN_C
  4715. PALIMPORT
  4716. inline
  4717. LONG
  4718. PALAPI
  4719. InterlockedAnd(
  4720. IN OUT LONG volatile *Destination,
  4721. IN LONG Value)
  4722. {
  4723. return __sync_fetch_and_and(Destination, Value);
  4724. }
  4725. EXTERN_C
  4726. PALIMPORT
  4727. inline
  4728. LONG
  4729. PALAPI
  4730. InterlockedOr(
  4731. IN OUT LONG volatile *Destination,
  4732. IN LONG Value)
  4733. {
  4734. return __sync_fetch_and_or(Destination, Value);
  4735. }
  4736. EXTERN_C
  4737. PALIMPORT
  4738. inline
  4739. UCHAR
  4740. PALAPI
  4741. InterlockedBitTestAndReset(
  4742. IN OUT LONG volatile *Base,
  4743. IN LONG Bit)
  4744. {
  4745. return (InterlockedAnd(Base, ~(1 << Bit)) & (1 << Bit)) != 0;
  4746. }
  4747. EXTERN_C
  4748. PALIMPORT
  4749. inline
  4750. UCHAR
  4751. PALAPI
  4752. InterlockedBitTestAndSet(
  4753. IN OUT LONG volatile *Base,
  4754. IN LONG Bit)
  4755. {
  4756. return (InterlockedOr(Base, (1 << Bit)) & (1 << Bit)) != 0;
  4757. }
  4758. // xplat-todo: review this implementation
  4759. EXTERN_C
  4760. PALIMPORT
  4761. inline
  4762. UCHAR
  4763. PALAPI
  4764. BitTest(
  4765. IN LONG *Base,
  4766. IN LONG Bit)
  4767. {
  4768. return ((*Base) & (1 << Bit)) != 0;
  4769. }
  4770. // xplat-todo: review this implementation
  4771. EXTERN_C
  4772. PALIMPORT
  4773. inline
  4774. UCHAR
  4775. PALAPI
  4776. BitTestAndSet(
  4777. IN OUT LONG *Base,
  4778. IN LONG Bit)
  4779. {
  4780. return (__sync_fetch_and_or(Base, (1 << Bit)) & (1 << Bit)) != 0;
  4781. }
  4782. #if defined(BIT64)
  4783. #define InterlockedExchangePointer(Target, Value) \
  4784. ((PVOID)InterlockedExchange64((PLONG64)(Target), (LONGLONG)(Value)))
  4785. #define InterlockedCompareExchangePointer(Destination, ExChange, Comperand) \
  4786. ((PVOID)InterlockedCompareExchange64((PLONG64)(Destination), (LONGLONG)(ExChange), (LONGLONG)(Comperand)))
  4787. #else
  4788. #define InterlockedExchangePointer(Target, Value) \
  4789. ((PVOID)(UINT_PTR)InterlockedExchange((PLONG)(UINT_PTR)(Target), (LONG)(UINT_PTR)(Value)))
  4790. #define InterlockedCompareExchangePointer(Destination, ExChange, Comperand) \
  4791. ((PVOID)(UINT_PTR)InterlockedCompareExchange((PLONG)(UINT_PTR)(Destination), (LONG)(UINT_PTR)(ExChange), (LONG)(UINT_PTR)(Comperand)))
  4792. #endif
  4793. /*++
  4794. Function:
  4795. MemoryBarrier
  4796. The MemoryBarrier function creates a full memory barrier.
  4797. --*/
  4798. EXTERN_C
  4799. PALIMPORT
  4800. inline
  4801. VOID
  4802. PALAPI
  4803. MemoryBarrier(
  4804. VOID)
  4805. {
  4806. __sync_synchronize();
  4807. }
  4808. PALIMPORT
  4809. VOID
  4810. PALAPI
  4811. YieldProcessor(
  4812. VOID);
  4813. PALIMPORT
  4814. DWORD
  4815. PALAPI
  4816. GetCurrentProcessorNumber();
  4817. /*++
  4818. Function:
  4819. PAL_HasGetCurrentProcessorNumber
  4820. Checks if GetCurrentProcessorNumber is available in the current environment
  4821. --*/
  4822. PALIMPORT
  4823. BOOL
  4824. PALAPI
  4825. PAL_HasGetCurrentProcessorNumber();
  4826. #define FORMAT_MESSAGE_ALLOCATE_BUFFER 0x00000100
  4827. #define FORMAT_MESSAGE_IGNORE_INSERTS 0x00000200
  4828. #define FORMAT_MESSAGE_FROM_STRING 0x00000400
  4829. #define FORMAT_MESSAGE_FROM_SYSTEM 0x00001000
  4830. #define FORMAT_MESSAGE_ARGUMENT_ARRAY 0x00002000
  4831. #define FORMAT_MESSAGE_MAX_WIDTH_MASK 0x000000FF
  4832. PALIMPORT
  4833. DWORD
  4834. PALAPI
  4835. FormatMessageW(
  4836. IN DWORD dwFlags,
  4837. IN LPCVOID lpSource,
  4838. IN DWORD dwMessageId,
  4839. IN DWORD dwLanguageId,
  4840. OUT LPWSTR lpBffer,
  4841. IN DWORD nSize,
  4842. IN va_list *Arguments);
  4843. #ifdef UNICODE
  4844. #define FormatMessage FormatMessageW
  4845. #endif
  4846. PALIMPORT
  4847. DWORD
  4848. PALAPI
  4849. GetLastError(
  4850. VOID);
  4851. PALIMPORT
  4852. VOID
  4853. PALAPI
  4854. SetLastError(
  4855. IN DWORD dwErrCode);
  4856. PALIMPORT
  4857. LPWSTR
  4858. PALAPI
  4859. GetCommandLineW(
  4860. VOID);
  4861. #ifdef UNICODE
  4862. #define GetCommandLine GetCommandLineW
  4863. #endif
  4864. PALIMPORT
  4865. VOID
  4866. PALAPI
  4867. RtlRestoreContext(
  4868. IN PCONTEXT ContextRecord,
  4869. IN PEXCEPTION_RECORD ExceptionRecord
  4870. );
  4871. PALIMPORT
  4872. VOID
  4873. PALAPI
  4874. RtlCaptureContext(
  4875. OUT PCONTEXT ContextRecord
  4876. );
  4877. PALIMPORT
  4878. UINT
  4879. PALAPI
  4880. GetWriteWatch(
  4881. IN DWORD dwFlags,
  4882. IN PVOID lpBaseAddress,
  4883. IN SIZE_T dwRegionSize,
  4884. OUT PVOID *lpAddresses,
  4885. IN OUT PULONG_PTR lpdwCount,
  4886. OUT PULONG lpdwGranularity
  4887. );
  4888. PALIMPORT
  4889. UINT
  4890. PALAPI
  4891. ResetWriteWatch(
  4892. IN LPVOID lpBaseAddress,
  4893. IN SIZE_T dwRegionSize
  4894. );
  4895. PALIMPORT
  4896. VOID
  4897. PALAPI
  4898. FlushProcessWriteBuffers();
  4899. typedef void (*PAL_ActivationFunction)(CONTEXT *context);
  4900. typedef BOOL (*PAL_SafeActivationCheckFunction)(SIZE_T ip);
  4901. PALIMPORT
  4902. VOID
  4903. PALAPI
  4904. PAL_SetActivationFunction(
  4905. IN PAL_ActivationFunction pActivationFunction,
  4906. IN PAL_SafeActivationCheckFunction pSafeActivationCheckFunction);
  4907. PALIMPORT
  4908. BOOL
  4909. PALAPI
  4910. PAL_InjectActivation(
  4911. IN HANDLE hThread
  4912. );
  4913. #define VER_PLATFORM_WIN32_WINDOWS 1
  4914. #define VER_PLATFORM_WIN32_NT 2
  4915. #define VER_PLATFORM_UNIX 10
  4916. #define VER_PLATFORM_MACOSX 11
  4917. typedef struct _OSVERSIONINFOA {
  4918. DWORD dwOSVersionInfoSize;
  4919. DWORD dwMajorVersion;
  4920. DWORD dwMinorVersion;
  4921. DWORD dwBuildNumber;
  4922. DWORD dwPlatformId;
  4923. CHAR szCSDVersion[ 128 ];
  4924. } OSVERSIONINFOA, *POSVERSIONINFOA, *LPOSVERSIONINFOA;
  4925. typedef struct _OSVERSIONINFOW {
  4926. DWORD dwOSVersionInfoSize;
  4927. DWORD dwMajorVersion;
  4928. DWORD dwMinorVersion;
  4929. DWORD dwBuildNumber;
  4930. DWORD dwPlatformId;
  4931. WCHAR szCSDVersion[ 128 ];
  4932. } OSVERSIONINFOW, *POSVERSIONINFOW, *LPOSVERSIONINFOW;
  4933. #ifdef UNICODE
  4934. typedef OSVERSIONINFOW OSVERSIONINFO;
  4935. typedef POSVERSIONINFOW POSVERSIONINFO;
  4936. typedef LPOSVERSIONINFOW LPOSVERSIONINFO;
  4937. #else
  4938. typedef OSVERSIONINFOA OSVERSIONINFO;
  4939. typedef POSVERSIONINFOA POSVERSIONINFO;
  4940. typedef LPOSVERSIONINFOA LPOSVERSIONINFO;
  4941. #endif
  4942. typedef struct _OSVERSIONINFOEXA {
  4943. DWORD dwOSVersionInfoSize;
  4944. DWORD dwMajorVersion;
  4945. DWORD dwMinorVersion;
  4946. DWORD dwBuildNumber;
  4947. DWORD dwPlatformId;
  4948. CHAR szCSDVersion[ 128 ];
  4949. WORD wServicePackMajor;
  4950. WORD wServicePackMinor;
  4951. WORD wSuiteMask;
  4952. BYTE wProductType;
  4953. BYTE wReserved;
  4954. } OSVERSIONINFOEXA, *POSVERSIONINFOEXA, *LPOSVERSIONINFOEXA;
  4955. typedef struct _OSVERSIONINFOEXW {
  4956. DWORD dwOSVersionInfoSize;
  4957. DWORD dwMajorVersion;
  4958. DWORD dwMinorVersion;
  4959. DWORD dwBuildNumber;
  4960. DWORD dwPlatformId;
  4961. WCHAR szCSDVersion[ 128 ];
  4962. WORD wServicePackMajor;
  4963. WORD wServicePackMinor;
  4964. WORD wSuiteMask;
  4965. BYTE wProductType;
  4966. BYTE wReserved;
  4967. } OSVERSIONINFOEXW, *POSVERSIONINFOEXW, *LPOSVERSIONINFOEXW;
  4968. #ifdef UNICODE
  4969. typedef OSVERSIONINFOEXW OSVERSIONINFOEX;
  4970. typedef POSVERSIONINFOEXW POSVERSIONINFOEX;
  4971. typedef LPOSVERSIONINFOEXW LPOSVERSIONINFOEX;
  4972. #else
  4973. typedef OSVERSIONINFOEXA OSVERSIONINFOEX;
  4974. typedef POSVERSIONINFOEXA POSVERSIONINFOEX;
  4975. typedef LPOSVERSIONINFOEXA LPOSVERSIONINFOEX;
  4976. #endif
  4977. PALIMPORT
  4978. BOOL
  4979. PALAPI
  4980. GetVersionExA(
  4981. IN OUT LPOSVERSIONINFOA lpVersionInformation);
  4982. PALIMPORT
  4983. BOOL
  4984. PALAPI
  4985. GetVersionExW(
  4986. IN OUT LPOSVERSIONINFOW lpVersionInformation);
  4987. #ifdef UNICODE
  4988. #define GetVersionEx GetVersionExW
  4989. #else
  4990. #define GetVersionEx GetVersionExA
  4991. #endif
  4992. #define IMAGE_FILE_MACHINE_I386 0x014c
  4993. #define IMAGE_FILE_MACHINE_ARM64 0xAA64 // ARM64 Little-Endian
  4994. typedef struct _SYSTEM_INFO {
  4995. WORD wProcessorArchitecture_PAL_Undefined;
  4996. WORD wReserved_PAL_Undefined; // NOTE: diff from winbase.h - no obsolete dwOemId union
  4997. DWORD dwPageSize;
  4998. LPVOID lpMinimumApplicationAddress;
  4999. LPVOID lpMaximumApplicationAddress;
  5000. DWORD_PTR dwActiveProcessorMask_PAL_Undefined;
  5001. DWORD dwNumberOfProcessors;
  5002. DWORD dwProcessorType_PAL_Undefined;
  5003. DWORD dwAllocationGranularity;
  5004. WORD wProcessorLevel_PAL_Undefined;
  5005. WORD wProcessorRevision_PAL_Undefined;
  5006. } SYSTEM_INFO, *LPSYSTEM_INFO;
  5007. PALIMPORT
  5008. VOID
  5009. PALAPI
  5010. GetSystemInfo(
  5011. OUT LPSYSTEM_INFO lpSystemInfo);
  5012. PALIMPORT
  5013. BOOL
  5014. PALAPI
  5015. GetDiskFreeSpaceW(
  5016. LPCWSTR lpDirectoryName,
  5017. LPDWORD lpSectorsPerCluster,
  5018. LPDWORD lpBytesPerSector,
  5019. LPDWORD lpNumberOfFreeClusters,
  5020. LPDWORD lpTotalNumberOfClusters);
  5021. #ifdef UNICODE
  5022. #define GetDiskFreeSpace GetDiskFreeSpaceW
  5023. #endif
  5024. PALIMPORT
  5025. BOOL
  5026. PALAPI
  5027. CreatePipe(
  5028. OUT PHANDLE hReadPipe,
  5029. OUT PHANDLE hWritePipe,
  5030. IN LPSECURITY_ATTRIBUTES lpPipeAttributes,
  5031. IN DWORD nSize
  5032. );
  5033. PALIMPORT
  5034. BOOL
  5035. PALAPI
  5036. DeregisterEventSource (
  5037. IN HANDLE hEventLog
  5038. );
  5039. PALIMPORT
  5040. HANDLE
  5041. PALAPI
  5042. RegisterEventSourceA (
  5043. IN OPTIONAL LPCSTR lpUNCServerName,
  5044. IN LPCSTR lpSourceName
  5045. );
  5046. PALIMPORT
  5047. HANDLE
  5048. PALAPI
  5049. RegisterEventSourceW (
  5050. IN OPTIONAL LPCWSTR lpUNCServerName,
  5051. IN LPCWSTR lpSourceName
  5052. );
  5053. #ifdef UNICODE
  5054. #define RegisterEventSource RegisterEventSourceW
  5055. #else
  5056. #define RegisterEventSource RegisterEventSourceA
  5057. #endif // !UNICODE
  5058. //
  5059. // The types of events that can be logged.
  5060. //
  5061. #define EVENTLOG_SUCCESS 0x0000
  5062. #define EVENTLOG_ERROR_TYPE 0x0001
  5063. #define EVENTLOG_WARNING_TYPE 0x0002
  5064. #define EVENTLOG_INFORMATION_TYPE 0x0004
  5065. #define EVENTLOG_AUDIT_SUCCESS 0x0008
  5066. #define EVENTLOG_AUDIT_FAILURE 0x0010
  5067. PALIMPORT
  5068. BOOL
  5069. PALAPI
  5070. ReportEventA (
  5071. IN HANDLE hEventLog,
  5072. IN WORD wType,
  5073. IN WORD wCategory,
  5074. IN DWORD dwEventID,
  5075. IN OPTIONAL PSID lpUserSid,
  5076. IN WORD wNumStrings,
  5077. IN DWORD dwDataSize,
  5078. IN OPTIONAL LPCSTR *lpStrings,
  5079. IN OPTIONAL LPVOID lpRawData
  5080. );
  5081. PALIMPORT
  5082. BOOL
  5083. PALAPI
  5084. ReportEventW (
  5085. IN HANDLE hEventLog,
  5086. IN WORD wType,
  5087. IN WORD wCategory,
  5088. IN DWORD dwEventID,
  5089. IN OPTIONAL PSID lpUserSid,
  5090. IN WORD wNumStrings,
  5091. IN DWORD dwDataSize,
  5092. IN OPTIONAL LPCWSTR *lpStrings,
  5093. IN OPTIONAL LPVOID lpRawData
  5094. );
  5095. #ifdef UNICODE
  5096. #define ReportEvent ReportEventW
  5097. #else
  5098. #define ReportEvent ReportEventA
  5099. #endif // !UNICODE
  5100. PALIMPORT
  5101. HRESULT
  5102. PALAPI
  5103. CoCreateGuid(OUT GUID * pguid);
  5104. /******************* C Runtime Entrypoints *******************************/
  5105. /* Some C runtime functions needs to be reimplemented by the PAL.
  5106. To avoid name collisions, those functions have been renamed using
  5107. defines */
  5108. #ifdef PLATFORM_UNIX
  5109. #ifndef PAL_STDCPP_COMPAT
  5110. #define exit PAL_exit
  5111. #define atexit PAL_atexit
  5112. #define printf PAL_printf
  5113. #define vprintf PAL_vprintf
  5114. #define wprintf PAL_wprintf
  5115. #define sprintf PAL_sprintf
  5116. #define swprintf PAL_swprintf
  5117. #define sscanf PAL_sscanf
  5118. #define wcsspn PAL_wcsspn
  5119. #define wcstod PAL_wcstod
  5120. #define wcstol PAL_wcstol
  5121. #define wcstoul PAL_wcstoul
  5122. #define wcscat PAL_wcscat
  5123. #define wcscpy PAL_wcscpy
  5124. #define wcslen PAL_wcslen
  5125. #define wcsncmp PAL_wcsncmp
  5126. #define wcschr PAL_wcschr
  5127. #define wcsrchr PAL_wcsrchr
  5128. #define wcsstr PAL_wcsstr
  5129. #define swscanf PAL_swscanf
  5130. #define wcspbrk PAL_wcspbrk
  5131. #define wcscmp PAL_wcscmp
  5132. #define wcsncat PAL_wcsncat
  5133. #define wcsncpy PAL_wcsncpy
  5134. #define wcstok PAL_wcstok
  5135. #define wcscspn PAL_wcscspn
  5136. #define iswprint PAL_iswprint
  5137. #define iswalpha PAL_iswalpha
  5138. #define iswdigit PAL_iswdigit
  5139. #define iswspace PAL_iswspace
  5140. #define iswupper PAL_iswupper
  5141. #define iswxdigit PAL_iswxdigit
  5142. #define towlower PAL_towlower
  5143. #define towupper PAL_towupper
  5144. #define vsprintf PAL_vsprintf
  5145. #define vswprintf PAL_vswprintf
  5146. #define realloc PAL_realloc
  5147. #define fopen PAL_fopen
  5148. #define strtok PAL_strtok
  5149. #define strtoul PAL_strtoul
  5150. #define fprintf PAL_fprintf
  5151. #define fwprintf PAL_fwprintf
  5152. #define vfprintf PAL_vfprintf
  5153. #define vfwprintf PAL_vfwprintf
  5154. #define ctime PAL_ctime
  5155. #define localtime PAL_localtime
  5156. #define mktime PAL_mktime
  5157. #define rand PAL_rand
  5158. #define getenv PAL_getenv
  5159. #define fgets PAL_fgets
  5160. #define fgetws PAL_fgetws
  5161. #define fputc PAL_fputc
  5162. #define putchar PAL_putchar
  5163. #define qsort PAL_qsort
  5164. #define bsearch PAL_bsearch
  5165. #define ferror PAL_ferror
  5166. #define fread PAL_fread
  5167. #define fwrite PAL_fwrite
  5168. #define feof PAL_feof
  5169. #define ftell PAL_ftell
  5170. #define fclose PAL_fclose
  5171. #define setbuf PAL_setbuf
  5172. #define fflush PAL_fflush
  5173. #define fputs PAL_fputs
  5174. #define fseek PAL_fseek
  5175. #define fgetpos PAL_fgetpos
  5176. #define fsetpos PAL_fsetpos
  5177. #define getc PAL_getc
  5178. #define fgetc PAL_getc // not a typo
  5179. #define ungetc PAL_ungetc
  5180. #define setvbuf PAL_setvbuf
  5181. #define atol PAL_atol
  5182. #define acos PAL_acos
  5183. #define asin PAL_asin
  5184. #define atan2 PAL_atan2
  5185. #define exp PAL_exp
  5186. #define labs PAL_labs
  5187. #define log PAL_log
  5188. #define log10 PAL_log10
  5189. #define pow PAL_pow
  5190. #define malloc PAL_malloc
  5191. #define free PAL_free
  5192. #define mkstemp PAL_mkstemp
  5193. #define rename PAL_rename
  5194. #define unlink PAL_unlink
  5195. #define _strdup PAL__strdup
  5196. #define _getcwd PAL__getcwd
  5197. #define _open PAL__open
  5198. #define _close PAL__close
  5199. #define _wcstoui64 PAL__wcstoui64
  5200. #define _flushall PAL__flushall
  5201. #ifdef _AMD64_
  5202. #define _mm_getcsr PAL__mm_getcsr
  5203. #define _mm_setcsr PAL__mm_setcsr
  5204. #endif // _AMD64_
  5205. #endif // !PAL_STDCPP_COMPAT
  5206. #endif // PLATFORM_UNIX
  5207. #ifndef _CONST_RETURN
  5208. #ifdef __cplusplus
  5209. #define _CONST_RETURN const
  5210. #define _CRT_CONST_CORRECT_OVERLOADS
  5211. #else
  5212. #define _CONST_RETURN
  5213. #endif
  5214. #endif
  5215. /* For backwards compatibility */
  5216. #define _WConst_return _CONST_RETURN
  5217. #define EOF (-1)
  5218. typedef int errno_t;
  5219. #ifndef PAL_STDCPP_COMPAT
  5220. typedef struct {
  5221. int quot;
  5222. int rem;
  5223. } div_t;
  5224. PALIMPORT div_t div(int numer, int denom);
  5225. PALIMPORT void * __cdecl memcpy(void *, const void *, size_t);
  5226. PALIMPORT int __cdecl memcmp(const void *, const void *, size_t);
  5227. PALIMPORT void * __cdecl memset(void *, int, size_t);
  5228. PALIMPORT void * __cdecl memmove(void *, const void *, size_t);
  5229. PALIMPORT void * __cdecl memchr(const void *, int, size_t);
  5230. PALIMPORT size_t __cdecl strlen(const char *);
  5231. PALIMPORT int __cdecl strcmp(const char*, const char *);
  5232. PALIMPORT int __cdecl strncmp(const char*, const char *, size_t);
  5233. PALIMPORT int __cdecl _strnicmp(const char *, const char *, size_t);
  5234. PALIMPORT char * __cdecl strcat(char *, const char *);
  5235. PALIMPORT char * __cdecl strncat(char *, const char *, size_t);
  5236. PALIMPORT char * __cdecl strcpy(char *, const char *);
  5237. PALIMPORT char * __cdecl strncpy(char *, const char *, size_t);
  5238. PALIMPORT char * __cdecl strchr(const char *, int);
  5239. PALIMPORT char * __cdecl strrchr(const char *, int);
  5240. PALIMPORT char * __cdecl strpbrk(const char *, const char *);
  5241. PALIMPORT char * __cdecl strstr(const char *, const char *);
  5242. PALIMPORT char * __cdecl strtok(char *, const char *);
  5243. PALIMPORT size_t __cdecl strspn(const char *, const char *);
  5244. PALIMPORT size_t __cdecl strcspn(const char *, const char *);
  5245. PALIMPORT int __cdecl sprintf(char *, const char *, ...);
  5246. PALIMPORT int __cdecl vsprintf(char *, const char *, va_list);
  5247. PALIMPORT int __cdecl sscanf(const char *, const char *, ...);
  5248. PALIMPORT int __cdecl atoi(const char *);
  5249. PALIMPORT LONG __cdecl atol(const char *);
  5250. PALIMPORT long long int __cdecl atoll(const char *);
  5251. PALIMPORT ULONG __cdecl strtoul(const char *, char **, int);
  5252. PALIMPORT double __cdecl atof(const char *);
  5253. PALIMPORT double __cdecl strtod(const char *, char **);
  5254. PALIMPORT int __cdecl isprint(int);
  5255. PALIMPORT int __cdecl isspace(int);
  5256. PALIMPORT int __cdecl isalpha(int);
  5257. PALIMPORT int __cdecl isalnum(int);
  5258. PALIMPORT int __cdecl isdigit(int);
  5259. PALIMPORT int __cdecl isxdigit(int);
  5260. PALIMPORT int __cdecl isupper(int);
  5261. PALIMPORT int __cdecl islower(int);
  5262. PALIMPORT int __cdecl tolower(int);
  5263. PALIMPORT int __cdecl toupper(int);
  5264. #endif // PAL_STDCPP_COMPAT
  5265. PALIMPORT errno_t __cdecl memcpy_s(void *, size_t, const void *, size_t);
  5266. PALIMPORT errno_t __cdecl memmove_s(void *, size_t, const void *, size_t);
  5267. PALIMPORT char * __cdecl _strlwr(char *);
  5268. PALIMPORT int __cdecl _stricmp(const char *, const char *);
  5269. PALIMPORT int __cdecl _snprintf(char *, size_t, const char *, ...);
  5270. PALIMPORT char * __cdecl _gcvt_s(char *, int, double, int);
  5271. PALIMPORT char * __cdecl _ecvt(double, int, int *, int *);
  5272. PALIMPORT int __cdecl __iscsym(int);
  5273. PALIMPORT size_t __cdecl _mbslen(const unsigned char *);
  5274. PALIMPORT unsigned char * __cdecl _mbsinc(const unsigned char *);
  5275. PALIMPORT unsigned char * __cdecl _mbsninc(const unsigned char *, size_t);
  5276. PALIMPORT unsigned char * __cdecl _mbsdec(const unsigned char *, const unsigned char *);
  5277. PALIMPORT int __cdecl _wcsicmp(const WCHAR *, const WCHAR*);
  5278. PALIMPORT int __cdecl _wcsnicmp(const WCHAR *, const WCHAR *, size_t);
  5279. PALIMPORT int __cdecl _vsnprintf(char *, size_t, const char *, va_list);
  5280. PALIMPORT int __cdecl _vsnwprintf(WCHAR *, size_t, const WCHAR *, va_list);
  5281. PALIMPORT WCHAR * __cdecl _itow(int, WCHAR *, int);
  5282. PALIMPORT size_t __cdecl PAL_wcslen(const WCHAR *);
  5283. PALIMPORT int __cdecl PAL_wcscmp(const WCHAR*, const WCHAR*);
  5284. PALIMPORT int __cdecl PAL_wcsncmp(const WCHAR *, const WCHAR *, size_t);
  5285. PALIMPORT WCHAR * __cdecl PAL_wcscat(WCHAR *, const WCHAR *);
  5286. PALIMPORT WCHAR * __cdecl PAL_wcsncat(WCHAR *, const WCHAR *, size_t);
  5287. PALIMPORT WCHAR * __cdecl PAL_wcscpy(WCHAR *, const WCHAR *);
  5288. PALIMPORT WCHAR * __cdecl PAL_wcsncpy(WCHAR *, const WCHAR *, size_t);
  5289. PALIMPORT const WCHAR * __cdecl PAL_wcschr(const WCHAR *, WCHAR);
  5290. PALIMPORT const WCHAR * __cdecl PAL_wcsrchr(const WCHAR *, WCHAR);
  5291. PALIMPORT WCHAR _WConst_return * __cdecl PAL_wcspbrk(const WCHAR *, const WCHAR *);
  5292. PALIMPORT WCHAR _WConst_return * __cdecl PAL_wcsstr(const WCHAR *, const WCHAR *);
  5293. PALIMPORT WCHAR * __cdecl PAL_wcstok(WCHAR *, const WCHAR *);
  5294. PALIMPORT size_t __cdecl PAL_wcscspn(const WCHAR *, const WCHAR *);
  5295. PALIMPORT int __cdecl PAL_swprintf(WCHAR *, const WCHAR *, ...);
  5296. PALIMPORT int __cdecl PAL_vswprintf(WCHAR *, const WCHAR *, va_list);
  5297. PALIMPORT int __cdecl _snwprintf(WCHAR *, size_t, const WCHAR *, ...);
  5298. PALIMPORT int __cdecl PAL_swscanf(const WCHAR *, const WCHAR *, ...);
  5299. PALIMPORT LONG __cdecl PAL_wcstol(const WCHAR *, WCHAR **, int);
  5300. PALIMPORT ULONG __cdecl PAL_wcstoul(const WCHAR *, WCHAR **, int);
  5301. PALIMPORT size_t __cdecl PAL_wcsspn (const WCHAR *, const WCHAR *);
  5302. PALIMPORT double __cdecl PAL_wcstod(const WCHAR *, WCHAR **);
  5303. PALIMPORT int __cdecl PAL_iswalpha(WCHAR);
  5304. PALIMPORT int __cdecl PAL_iswprint(WCHAR);
  5305. PALIMPORT int __cdecl PAL_iswupper(WCHAR);
  5306. PALIMPORT int __cdecl PAL_iswspace(WCHAR);
  5307. PALIMPORT int __cdecl PAL_iswdigit(WCHAR);
  5308. PALIMPORT int __cdecl PAL_iswxdigit(WCHAR);
  5309. PALIMPORT WCHAR __cdecl PAL_towlower(WCHAR);
  5310. PALIMPORT WCHAR __cdecl PAL_towupper(WCHAR);
  5311. PALIMPORT WCHAR * __cdecl _wcslwr(WCHAR *);
  5312. PALIMPORT ULONGLONG _wcstoui64(const WCHAR *, WCHAR **, int);
  5313. PALIMPORT WCHAR * __cdecl _i64tow(__int64, WCHAR *, int);
  5314. PALIMPORT WCHAR * __cdecl _ui64tow(unsigned __int64, WCHAR *, int);
  5315. PALIMPORT int __cdecl _wtoi(const WCHAR *);
  5316. #ifdef __cplusplus
  5317. extern "C++" {
  5318. inline WCHAR *PAL_wcschr(WCHAR *_S, WCHAR _C)
  5319. {return ((WCHAR *)PAL_wcschr((const WCHAR *)_S, _C)); }
  5320. inline WCHAR *PAL_wcsrchr(WCHAR *_S, WCHAR _C)
  5321. {return ((WCHAR *)PAL_wcsrchr((const WCHAR *)_S, _C)); }
  5322. inline WCHAR *PAL_wcspbrk(WCHAR *_S, const WCHAR *_P)
  5323. {return ((WCHAR *)PAL_wcspbrk((const WCHAR *)_S, _P)); }
  5324. inline WCHAR *PAL_wcsstr(WCHAR *_S, const WCHAR *_P)
  5325. {return ((WCHAR *)PAL_wcsstr((const WCHAR *)_S, _P)); }
  5326. }
  5327. #endif
  5328. /*++
  5329. Function:
  5330. _rotl
  5331. See MSDN doc.
  5332. --*/
  5333. EXTERN_C
  5334. PALIMPORT
  5335. inline
  5336. unsigned int __cdecl _rotl(unsigned int value, int shift)
  5337. {
  5338. unsigned int retval = 0;
  5339. shift &= 0x1f;
  5340. retval = (value << shift) | (value >> (sizeof(int) * CHAR_BIT - shift));
  5341. return retval;
  5342. }
  5343. // On 64 bit unix, make the long an int.
  5344. #ifdef BIT64
  5345. #define _lrotl _rotl
  5346. #endif // BIT64
  5347. /*++
  5348. Function:
  5349. _rotr
  5350. See MSDN doc.
  5351. --*/
  5352. EXTERN_C
  5353. PALIMPORT
  5354. inline
  5355. unsigned int __cdecl _rotr(unsigned int value, int shift)
  5356. {
  5357. unsigned int retval;
  5358. shift &= 0x1f;
  5359. retval = (value >> shift) | (value << (sizeof(int) * CHAR_BIT - shift));
  5360. return retval;
  5361. }
  5362. PALIMPORT int __cdecl abs(int);
  5363. PALIMPORT double __cdecl fabs(double);
  5364. #ifndef PAL_STDCPP_COMPAT
  5365. PALIMPORT LONG __cdecl labs(LONG);
  5366. PALIMPORT double __cdecl fabs(double);
  5367. #endif // !PAL_STDCPP_COMPAT
  5368. // clang complains if this is declared with __int64
  5369. PALIMPORT long long __cdecl llabs(long long);
  5370. PALIMPORT double __cdecl sqrt(double);
  5371. PALIMPORT double __cdecl log(double);
  5372. PALIMPORT double __cdecl log10(double);
  5373. PALIMPORT double __cdecl exp(double);
  5374. PALIMPORT double __cdecl pow(double, double);
  5375. PALIMPORT double __cdecl acos(double);
  5376. PALIMPORT double __cdecl asin(double);
  5377. PALIMPORT double __cdecl atan(double);
  5378. PALIMPORT double __cdecl atan2(double,double);
  5379. PALIMPORT double __cdecl cos(double);
  5380. PALIMPORT double __cdecl sin(double);
  5381. PALIMPORT double __cdecl tan(double);
  5382. PALIMPORT double __cdecl cosh(double);
  5383. PALIMPORT double __cdecl sinh(double);
  5384. PALIMPORT double __cdecl tanh(double);
  5385. PALIMPORT double __cdecl fmod(double, double);
  5386. PALIMPORT float __cdecl fmodf(float, float);
  5387. PALIMPORT double __cdecl floor(double);
  5388. PALIMPORT double __cdecl ceil(double);
  5389. PALIMPORT float __cdecl fabsf(float);
  5390. PALIMPORT double __cdecl modf(double, double *);
  5391. PALIMPORT float __cdecl modff(float, float *);
  5392. PALIMPORT int __cdecl _finite(double);
  5393. PALIMPORT int __cdecl _isnan(double);
  5394. PALIMPORT double __cdecl _copysign(double, double);
  5395. #ifndef PAL_STDCPP_COMPAT
  5396. #ifdef __cplusplus
  5397. extern "C++" {
  5398. inline __int64 abs(__int64 _X) {
  5399. return llabs(_X);
  5400. }
  5401. }
  5402. #endif
  5403. PALIMPORT void * __cdecl malloc(size_t);
  5404. PALIMPORT void __cdecl free(void *);
  5405. PALIMPORT void * __cdecl realloc(void *, size_t);
  5406. PALIMPORT char * __cdecl _strdup(const char *);
  5407. #if defined(_MSC_VER)
  5408. #define alloca _alloca
  5409. #elif defined(PLATFORM_UNIX)
  5410. #define _alloca alloca
  5411. #else
  5412. // MingW
  5413. #define _alloca __builtin_alloca
  5414. #define alloca __builtin_alloca
  5415. #endif //_MSC_VER
  5416. #if defined(__GNUC__) && defined(PLATFORM_UNIX)
  5417. // we set -fno-builtin on the command line. This requires that if
  5418. // we use alloca, with either have to call __builtin_alloca, or
  5419. // ensure that the alloca call doesn't happen in code which is
  5420. // modifying the stack (such as "memset (alloca(x), y, z)"
  5421. #define alloca __builtin_alloca
  5422. #endif // __GNUC__
  5423. #ifndef NO_PAL_MINMAX
  5424. #define max(a, b) (((a) > (b)) ? (a) : (b))
  5425. #define min(a, b) (((a) < (b)) ? (a) : (b))
  5426. #endif
  5427. #define USING_PAL_MINMAX 1
  5428. #endif // !PAL_STDCPP_COMPAT
  5429. PALIMPORT PAL_NORETURN void __cdecl exit(int);
  5430. int __cdecl atexit(void (__cdecl *function)(void));
  5431. PALIMPORT void __cdecl qsort(void *, size_t, size_t, int (__cdecl *)(const void *, const void *));
  5432. PALIMPORT void * __cdecl bsearch(const void *, const void *, size_t, size_t,
  5433. int (__cdecl *)(const void *, const void *));
  5434. PALIMPORT void __cdecl _splitpath(const char *, char *, char *, char *, char *);
  5435. PALIMPORT void __cdecl _wsplitpath(const WCHAR *, WCHAR *, WCHAR *, WCHAR *, WCHAR *);
  5436. PALIMPORT void __cdecl _makepath(char *, const char *, const char *, const char *, const char *);
  5437. PALIMPORT void __cdecl _wmakepath(WCHAR *, const WCHAR *, const WCHAR *, const WCHAR *, const WCHAR *);
  5438. PALIMPORT char * __cdecl _fullpath(char *, const char *, size_t);
  5439. PALIMPORT void __cdecl _swab(char *, char *, int);
  5440. #ifndef PAL_STDCPP_COMPAT
  5441. PALIMPORT time_t __cdecl time(time_t *);
  5442. struct tm {
  5443. int tm_sec; /* seconds after the minute - [0,59] */
  5444. int tm_min; /* minutes after the hour - [0,59] */
  5445. int tm_hour; /* hours since midnight - [0,23] */
  5446. int tm_mday; /* day of the month - [1,31] */
  5447. int tm_mon; /* months since January - [0,11] */
  5448. int tm_year; /* years since 1900 */
  5449. int tm_wday; /* days since Sunday - [0,6] */
  5450. int tm_yday; /* days since January 1 - [0,365] */
  5451. int tm_isdst; /* daylight savings time flag */
  5452. };
  5453. PALIMPORT struct tm * __cdecl localtime(const time_t *);
  5454. PALIMPORT time_t __cdecl mktime(struct tm *);
  5455. PALIMPORT char * __cdecl ctime(const time_t *);
  5456. #endif // !PAL_STDCPP_COMPAT
  5457. PALIMPORT int __cdecl _open_osfhandle(INT_PTR, int);
  5458. PALIMPORT int __cdecl _close(int);
  5459. PALIMPORT int __cdecl _flushall();
  5460. #ifdef PAL_STDCPP_COMPAT
  5461. struct _PAL_FILE;
  5462. typedef struct _PAL_FILE PAL_FILE;
  5463. #else // PAL_STDCPP_COMPAT
  5464. struct _FILE;
  5465. typedef struct _FILE FILE;
  5466. typedef struct _FILE PAL_FILE;
  5467. #define SEEK_SET 0
  5468. #define SEEK_CUR 1
  5469. #define SEEK_END 2
  5470. /* Locale categories */
  5471. #define LC_ALL 0
  5472. #define LC_COLLATE 1
  5473. #define LC_CTYPE 2
  5474. #define LC_MONETARY 3
  5475. #define LC_NUMERIC 4
  5476. #define LC_TIME 5
  5477. #define _IOFBF 0 /* setvbuf should set fully buffered */
  5478. #define _IOLBF 1 /* setvbuf should set line buffered */
  5479. #define _IONBF 2 /* setvbuf should set unbuffered */
  5480. #endif // PAL_STDCPP_COMPAT
  5481. PALIMPORT int __cdecl PAL_fclose(PAL_FILE *);
  5482. PALIMPORT void __cdecl PAL_setbuf(PAL_FILE *, char*);
  5483. PALIMPORT int __cdecl PAL_fflush(PAL_FILE *);
  5484. PALIMPORT size_t __cdecl PAL_fwrite(const void *, size_t, size_t, PAL_FILE *);
  5485. PALIMPORT size_t __cdecl PAL_fread(void *, size_t, size_t, PAL_FILE *);
  5486. PALIMPORT char * __cdecl PAL_fgets(char *, int, PAL_FILE *);
  5487. PALIMPORT int __cdecl PAL_fputs(const char *, PAL_FILE *);
  5488. PALIMPORT int __cdecl PAL_fputc(int c, PAL_FILE *stream);
  5489. PALIMPORT int __cdecl PAL_putchar(int c);
  5490. PALIMPORT int __cdecl PAL_fprintf(PAL_FILE *, const char *, ...);
  5491. PALIMPORT int __cdecl PAL_vfprintf(PAL_FILE *, const char *, va_list);
  5492. PALIMPORT int __cdecl PAL_fseek(PAL_FILE *, LONG, int);
  5493. PALIMPORT int __cdecl PAL_fgetpos(PAL_FILE *, fpos_t *);
  5494. PALIMPORT int __cdecl PAL_fsetpos(PAL_FILE *, const fpos_t *);
  5495. PALIMPORT LONG __cdecl PAL_ftell(PAL_FILE *);
  5496. PALIMPORT int __cdecl PAL_feof(PAL_FILE *);
  5497. PALIMPORT int __cdecl PAL_ferror(PAL_FILE *);
  5498. PALIMPORT PAL_FILE * __cdecl PAL_fopen(const char *, const char *);
  5499. PALIMPORT int __cdecl PAL_getc(PAL_FILE *stream);
  5500. PALIMPORT int __cdecl PAL_fgetc(PAL_FILE *stream);
  5501. PALIMPORT int __cdecl PAL_ungetc(int c, PAL_FILE *stream);
  5502. PALIMPORT int __cdecl PAL_setvbuf(PAL_FILE *stream, char *, int, size_t);
  5503. PALIMPORT WCHAR * __cdecl PAL_fgetws(WCHAR *, int, PAL_FILE *);
  5504. PALIMPORT int __cdecl PAL_fwprintf(PAL_FILE *, const WCHAR *, ...);
  5505. PALIMPORT int __cdecl PAL_vfwprintf(PAL_FILE *, const WCHAR *, va_list);
  5506. PALIMPORT int __cdecl PAL_wprintf(const WCHAR*, ...);
  5507. PALIMPORT int __cdecl _getw(PAL_FILE *);
  5508. PALIMPORT int __cdecl _putw(int, PAL_FILE *);
  5509. PALIMPORT PAL_FILE * __cdecl _fdopen(int, const char *);
  5510. PALIMPORT PAL_FILE * __cdecl _wfopen(const WCHAR *, const WCHAR *);
  5511. PALIMPORT PAL_FILE * __cdecl _wfsopen(const WCHAR *, const WCHAR *, int);
  5512. /* Maximum value that can be returned by the rand function. */
  5513. #ifndef PAL_STDCPP_COMPAT
  5514. #define RAND_MAX 0x7fff
  5515. #endif // !PAL_STDCPP_COMPAT
  5516. PALIMPORT int __cdecl rand(void);
  5517. PALIMPORT void __cdecl srand(unsigned int);
  5518. PALIMPORT errno_t __cdecl rand_s(unsigned int*);
  5519. PALIMPORT int __cdecl printf(const char *, ...);
  5520. PALIMPORT int __cdecl vprintf(const char *, va_list);
  5521. #ifdef _MSC_VER
  5522. #define PAL_get_caller _MSC_VER
  5523. #else
  5524. #define PAL_get_caller 0
  5525. #endif
  5526. PALIMPORT PAL_FILE * __cdecl PAL_get_stdout(int caller);
  5527. PALIMPORT PAL_FILE * __cdecl PAL_get_stdin(int caller);
  5528. PALIMPORT PAL_FILE * __cdecl PAL_get_stderr(int caller);
  5529. PALIMPORT int * __cdecl PAL_errno(int caller);
  5530. #ifdef PAL_STDCPP_COMPAT
  5531. #define PAL_stdout (PAL_get_stdout(PAL_get_caller))
  5532. #define PAL_stdin (PAL_get_stdin(PAL_get_caller))
  5533. #define PAL_stderr (PAL_get_stderr(PAL_get_caller))
  5534. #define PAL_errno (*PAL_errno(PAL_get_caller))
  5535. #else // PAL_STDCPP_COMPAT
  5536. #define stdout (PAL_get_stdout(PAL_get_caller))
  5537. #define stdin (PAL_get_stdin(PAL_get_caller))
  5538. #define stderr (PAL_get_stderr(PAL_get_caller))
  5539. #define errno (*PAL_errno(PAL_get_caller))
  5540. #endif // PAL_STDCPP_COMPAT
  5541. PALIMPORT char * __cdecl getenv(const char *);
  5542. PALIMPORT int __cdecl _putenv(const char *);
  5543. #define ERANGE 34
  5544. /******************* PAL-specific I/O completion port *****************/
  5545. typedef struct _PAL_IOCP_CPU_INFORMATION {
  5546. union {
  5547. FILETIME ftLastRecordedIdleTime;
  5548. FILETIME ftLastRecordedCurrentTime;
  5549. } LastRecordedTime;
  5550. FILETIME ftLastRecordedKernelTime;
  5551. FILETIME ftLastRecordedUserTime;
  5552. } PAL_IOCP_CPU_INFORMATION;
  5553. PALIMPORT
  5554. INT
  5555. PALAPI
  5556. PAL_GetCPUBusyTime(
  5557. IN OUT PAL_IOCP_CPU_INFORMATION *lpPrevCPUInfo);
  5558. /****************PAL Perf functions for PInvoke*********************/
  5559. #if PAL_PERF
  5560. PALIMPORT
  5561. VOID
  5562. PALAPI
  5563. PAL_EnableProcessProfile(VOID);
  5564. PALIMPORT
  5565. VOID
  5566. PALAPI
  5567. PAL_DisableProcessProfile(VOID);
  5568. PALIMPORT
  5569. BOOL
  5570. PALAPI
  5571. PAL_IsProcessProfileEnabled(VOID);
  5572. PALIMPORT
  5573. INT64
  5574. PALAPI
  5575. PAL_GetCpuTickCount(VOID);
  5576. #endif // PAL_PERF
  5577. /******************* PAL functions for SIMD extensions *****************/
  5578. PALIMPORT
  5579. unsigned int _mm_getcsr(void);
  5580. PALIMPORT
  5581. void _mm_setcsr(unsigned int i);
  5582. /******************* PAL side-by-side support ************************/
  5583. #ifdef FEATURE_PAL_SXS
  5584. //
  5585. // Some versions of the PAL support several PALs side-by-side
  5586. // in the process. To avoid those PALs interfering with one
  5587. // another, they need to be told by clients when they are active
  5588. // and when they are not.
  5589. //
  5590. // To avoid performance problems incurred by swapping thread
  5591. // exception ports every time we leave the PAL, there's also
  5592. // the concept of entering/leaving the PAL at its top boundary
  5593. // (entering down/leaving up) or at the bottom boundary
  5594. // (leaving down/entering up).
  5595. typedef enum _PAL_Boundary {
  5596. PAL_BoundaryTop, // closer to main()
  5597. PAL_BoundaryBottom, // closer to execution
  5598. PAL_BoundaryEH, // out-of-band during EH
  5599. PAL_BoundaryMax = PAL_BoundaryEH
  5600. } PAL_Boundary;
  5601. // This function needs to be called on a thread when it enters
  5602. // a region of code that depends on this instance of the PAL
  5603. // in the process, and the current thread may or may not be
  5604. // known to the PAL. This function can fail (for something else
  5605. // than an internal error) if this is the first time that the
  5606. // current thread entered this PAL. Note that PAL_Initialize
  5607. // implies a call to this function. Does not modify LastError.
  5608. PALIMPORT
  5609. DWORD
  5610. PALAPI
  5611. PAL_Enter(PAL_Boundary boundary);
  5612. // Returns TRUE if we this thread has already entered the PAL,
  5613. // returns FALSE if we have not entered the PAL.
  5614. PALIMPORT
  5615. BOOL
  5616. PALAPI
  5617. PAL_HasEntered();
  5618. // Equivalent to PAL_Enter(PAL_BoundaryTop) and is for stub
  5619. // code generation use.
  5620. PALIMPORT
  5621. DWORD
  5622. PALAPI
  5623. PAL_EnterTop();
  5624. // This function needs to be called on a thread when it enters
  5625. // a region of code that depends on this instance of the PAL
  5626. // in the process, and the current thread is already known to
  5627. // the PAL. Does not modify LastError.
  5628. PALIMPORT
  5629. VOID
  5630. PALAPI
  5631. PAL_Reenter(PAL_Boundary boundary);
  5632. // This function needs to be called on a thread when it enters
  5633. // a region of code that depends on this instance of the PAL
  5634. // in the process, and it is unknown whether the current thread
  5635. // is already running in the PAL. Returns TRUE if and only if
  5636. // the thread was not running in the PAL previously. Does not
  5637. // modify LastError.
  5638. PALIMPORT
  5639. BOOL
  5640. PALAPI
  5641. PAL_ReenterForEH(VOID);
  5642. // This function needs to be called on a thread when it leaves
  5643. // a region of code that depends on this instance of the PAL
  5644. // in the process. Does not modify LastError.
  5645. PALIMPORT
  5646. VOID
  5647. PALAPI
  5648. PAL_Leave(PAL_Boundary boundary);
  5649. // This function is equivalent to PAL_Leave(PAL_BoundaryBottom)
  5650. // and is available to limit the creation of stub code.
  5651. PALIMPORT
  5652. VOID
  5653. PALAPI
  5654. PAL_LeaveBottom();
  5655. // This function is equivalent to PAL_Leave(PAL_BoundaryTop)
  5656. // and is available to limit the creation of stub code.
  5657. PALIMPORT
  5658. VOID
  5659. PALAPI
  5660. PAL_LeaveTop();
  5661. #ifdef __cplusplus
  5662. //
  5663. // A holder to enter the PAL for a specific region of code.
  5664. // Previously, we must have been executing outside the PAL
  5665. // (unless fEnter is set to FALSE).
  5666. //
  5667. class PAL_EnterHolder
  5668. {
  5669. private:
  5670. BOOL m_fEntered;
  5671. DWORD m_palError;
  5672. public:
  5673. PAL_EnterHolder(BOOL fEnter = TRUE) : m_palError(ERROR_SUCCESS)
  5674. {
  5675. if (fEnter)
  5676. {
  5677. m_palError = PAL_Enter(PAL_BoundaryTop);
  5678. m_fEntered = m_palError == ERROR_SUCCESS;
  5679. }
  5680. else
  5681. {
  5682. m_fEntered = FALSE;
  5683. }
  5684. }
  5685. ~PAL_EnterHolder()
  5686. {
  5687. if (m_fEntered)
  5688. {
  5689. PAL_Leave(PAL_BoundaryTop);
  5690. }
  5691. }
  5692. DWORD GetError()
  5693. {
  5694. return m_palError;
  5695. }
  5696. void SuppressRelease()
  5697. {
  5698. // Used to avoid calling PAL_Leave() when
  5699. // another code path will explicitly do so.
  5700. m_fEntered = FALSE;
  5701. }
  5702. };
  5703. class PAL_LeaveHolder
  5704. {
  5705. public:
  5706. PAL_LeaveHolder()
  5707. {
  5708. PAL_Leave(PAL_BoundaryBottom);
  5709. }
  5710. ~PAL_LeaveHolder()
  5711. {
  5712. PAL_Reenter(PAL_BoundaryBottom);
  5713. }
  5714. };
  5715. #endif // __cplusplus
  5716. #else // FEATURE_PAL_SXS
  5717. #define PAL_Enter(boundary) ERROR_SUCCESS
  5718. #define PAL_Reenter(boundary)
  5719. #define PAL_Leave(boundary)
  5720. #ifdef __cplusplus
  5721. class PAL_EnterHolder {
  5722. public:
  5723. // using constructor to suppress the "unused variable" warnings
  5724. PAL_EnterHolder() {}
  5725. };
  5726. class PAL_LeaveHolder {
  5727. public:
  5728. // using constructor to suppress the "unused variable" warnings
  5729. PAL_LeaveHolder() {}
  5730. };
  5731. #endif // __cplusplus
  5732. #endif // FEATURE_PAL_SXS
  5733. #ifdef __cplusplus
  5734. #include "pal_unwind.h"
  5735. #define EXCEPTION_CONTINUE_SEARCH 0
  5736. #define EXCEPTION_EXECUTE_HANDLER 1
  5737. #define EXCEPTION_CONTINUE_EXECUTION -1
  5738. struct PAL_SEHException
  5739. {
  5740. private:
  5741. const SIZE_T NoTargetFrameSp = SIZE_MAX;
  5742. public:
  5743. // Note that the following two are actually embedded in this heap-allocated
  5744. // instance - in contrast to Win32, where the exception record would usually
  5745. // be allocated on the stack. This is needed because foreign cleanup handlers
  5746. // partially unwind the stack on the second pass.
  5747. EXCEPTION_POINTERS ExceptionPointers;
  5748. EXCEPTION_RECORD ExceptionRecord;
  5749. CONTEXT ContextRecord;
  5750. // Target frame stack pointer set before the 2nd pass.
  5751. SIZE_T TargetFrameSp;
  5752. PAL_SEHException(EXCEPTION_RECORD *pExceptionRecord, CONTEXT *pContextRecord)
  5753. {
  5754. ExceptionPointers.ExceptionRecord = &ExceptionRecord;
  5755. ExceptionPointers.ContextRecord = &ContextRecord;
  5756. ExceptionRecord = *pExceptionRecord;
  5757. ContextRecord = *pContextRecord;
  5758. TargetFrameSp = NoTargetFrameSp;
  5759. }
  5760. PAL_SEHException()
  5761. {
  5762. }
  5763. PAL_SEHException(const PAL_SEHException& ex)
  5764. {
  5765. *this = ex;
  5766. }
  5767. bool IsFirstPass()
  5768. {
  5769. return (TargetFrameSp == NoTargetFrameSp);
  5770. }
  5771. PAL_SEHException& operator=(const PAL_SEHException& ex)
  5772. {
  5773. ExceptionPointers.ExceptionRecord = &ExceptionRecord;
  5774. ExceptionPointers.ContextRecord = &ContextRecord;
  5775. ExceptionRecord = ex.ExceptionRecord;
  5776. ContextRecord = ex.ContextRecord;
  5777. TargetFrameSp = ex.TargetFrameSp;
  5778. return *this;
  5779. }
  5780. };
  5781. typedef VOID (PALAPI *PHARDWARE_EXCEPTION_HANDLER)(PAL_SEHException* ex);
  5782. PALIMPORT
  5783. VOID
  5784. PALAPI
  5785. PAL_SetHardwareExceptionHandler(
  5786. IN PHARDWARE_EXCEPTION_HANDLER exceptionHandler);
  5787. //
  5788. // This holder is used to indicate that a hardware
  5789. // exception should be raised as a C++ exception
  5790. // to better emulate SEH on the xplat platforms.
  5791. //
  5792. class CatchHardwareExceptionHolder
  5793. {
  5794. public:
  5795. CatchHardwareExceptionHolder();
  5796. ~CatchHardwareExceptionHolder();
  5797. static bool IsEnabled();
  5798. };
  5799. //
  5800. // NOTE: Catching hardware exceptions are only enabled in the DAC and SOS
  5801. // builds. A hardware exception in coreclr code will fail fast/terminate
  5802. // the process.
  5803. //
  5804. #ifdef FEATURE_ENABLE_HARDWARE_EXCEPTIONS
  5805. #define HardwareExceptionHolder CatchHardwareExceptionHolder __catchHardwareException;
  5806. #else
  5807. #define HardwareExceptionHolder
  5808. #endif // FEATURE_ENABLE_HARDWARE_EXCEPTIONS
  5809. #ifdef FEATURE_PAL_SXS
  5810. extern "C++" {
  5811. //
  5812. // This is the base class of native exception holder used to provide
  5813. // the filter function to the exception dispatcher. This allows the
  5814. // filter to be called during the first pass to better emulate SEH
  5815. // the xplat platforms that only have C++ exception support.
  5816. //
  5817. class NativeExceptionHolderBase
  5818. {
  5819. // Save the address of the holder head so the destructor
  5820. // doesn't have access the slow (on Linux) TLS value again.
  5821. NativeExceptionHolderBase **m_head;
  5822. // The next holder on the stack
  5823. NativeExceptionHolderBase *m_next;
  5824. protected:
  5825. NativeExceptionHolderBase();
  5826. ~NativeExceptionHolderBase();
  5827. public:
  5828. // Calls the holder's filter handler.
  5829. virtual EXCEPTION_DISPOSITION InvokeFilter(PAL_SEHException& ex) = 0;
  5830. // Adds the holder to the "stack" of holders. This is done explicitly instead
  5831. // of in the constructor was to avoid the mess of move constructors combined
  5832. // with return value optimization (in CreateHolder).
  5833. void Push();
  5834. // Given the currentHolder and locals stack range find the next holder starting with this one
  5835. // To find the first holder, pass nullptr as the currentHolder.
  5836. static NativeExceptionHolderBase *FindNextHolder(NativeExceptionHolderBase *currentHolder, void *frameLowAddress, void *frameHighAddress);
  5837. };
  5838. //
  5839. // This is the second part of the native exception filter holder. It is
  5840. // templated because the lambda used to wrap the exception filter is a
  5841. // unknown type.
  5842. //
  5843. template<class FilterType>
  5844. class NativeExceptionHolder : public NativeExceptionHolderBase
  5845. {
  5846. FilterType* m_exceptionFilter;
  5847. public:
  5848. NativeExceptionHolder(FilterType* exceptionFilter)
  5849. : NativeExceptionHolderBase()
  5850. {
  5851. m_exceptionFilter = exceptionFilter;
  5852. }
  5853. virtual EXCEPTION_DISPOSITION InvokeFilter(PAL_SEHException& ex)
  5854. {
  5855. return (*m_exceptionFilter)(ex);
  5856. }
  5857. };
  5858. //
  5859. // This is a native exception holder that is used when the catch catches
  5860. // all exceptions.
  5861. //
  5862. class NativeExceptionHolderCatchAll : public NativeExceptionHolderBase
  5863. {
  5864. public:
  5865. NativeExceptionHolderCatchAll()
  5866. : NativeExceptionHolderBase()
  5867. {
  5868. }
  5869. virtual EXCEPTION_DISPOSITION InvokeFilter(PAL_SEHException& ex)
  5870. {
  5871. return EXCEPTION_EXECUTE_HANDLER;
  5872. }
  5873. };
  5874. //
  5875. // This factory class for the native exception holder is necessary because
  5876. // templated functions don't need the explicit type parameter and can infer
  5877. // the template type from the parameter.
  5878. //
  5879. class NativeExceptionHolderFactory
  5880. {
  5881. public:
  5882. template<class FilterType>
  5883. static NativeExceptionHolder<FilterType> CreateHolder(FilterType* exceptionFilter)
  5884. {
  5885. return NativeExceptionHolder<FilterType>(exceptionFilter);
  5886. }
  5887. };
  5888. // Start of a try block for exceptions raised by RaiseException
  5889. #define PAL_TRY(__ParamType, __paramDef, __paramRef) \
  5890. { \
  5891. __ParamType __param = __paramRef; \
  5892. auto tryBlock = [](__ParamType __paramDef) \
  5893. {
  5894. // Start of an exception handler. If an exception raised by the RaiseException
  5895. // occurs in the try block and the disposition is EXCEPTION_EXECUTE_HANDLER,
  5896. // the handler code is executed. If the disposition is EXCEPTION_CONTINUE_SEARCH,
  5897. // the exception is rethrown. The EXCEPTION_CONTINUE_EXECUTION disposition is
  5898. // not supported.
  5899. #define PAL_EXCEPT(dispositionExpression) \
  5900. }; \
  5901. const bool isFinally = false; \
  5902. auto finallyBlock = []() {}; \
  5903. EXCEPTION_DISPOSITION disposition = EXCEPTION_CONTINUE_EXECUTION; \
  5904. auto exceptionFilter = [&disposition, &__param](PAL_SEHException& ex) \
  5905. { \
  5906. disposition = dispositionExpression; \
  5907. _ASSERTE(disposition != EXCEPTION_CONTINUE_EXECUTION); \
  5908. return disposition; \
  5909. }; \
  5910. try \
  5911. { \
  5912. HardwareExceptionHolder \
  5913. auto __exceptionHolder = NativeExceptionHolderFactory::CreateHolder(&exceptionFilter); \
  5914. __exceptionHolder.Push(); \
  5915. tryBlock(__param); \
  5916. } \
  5917. catch (PAL_SEHException& ex) \
  5918. { \
  5919. if (disposition == EXCEPTION_CONTINUE_EXECUTION) \
  5920. { \
  5921. exceptionFilter(ex); \
  5922. } \
  5923. if (disposition == EXCEPTION_CONTINUE_SEARCH) \
  5924. { \
  5925. throw; \
  5926. }
  5927. // Start of an exception handler. It works the same way as the PAL_EXCEPT except
  5928. // that the disposition is obtained by calling the specified filter.
  5929. #define PAL_EXCEPT_FILTER(filter) PAL_EXCEPT(filter(&ex.ExceptionPointers, __param))
  5930. // Start of a finally block. The finally block is executed both when the try block
  5931. // finishes or when an exception is raised using the RaiseException in it.
  5932. #define PAL_FINALLY \
  5933. }; \
  5934. const bool isFinally = true; \
  5935. auto finallyBlock = [&]() \
  5936. {
  5937. // End of an except or a finally block.
  5938. #define PAL_ENDTRY \
  5939. }; \
  5940. if (isFinally) \
  5941. { \
  5942. try \
  5943. { \
  5944. tryBlock(__param); \
  5945. } \
  5946. catch (...) \
  5947. { \
  5948. finallyBlock(); \
  5949. throw; \
  5950. } \
  5951. finallyBlock(); \
  5952. } \
  5953. }
  5954. } // extern "C++"
  5955. #endif // FEATURE_PAL_SXS
  5956. #define PAL_CPP_THROW(type, obj) { throw obj; }
  5957. #define PAL_CPP_RETHROW { throw; }
  5958. #define PAL_CPP_TRY try { HardwareExceptionHolder
  5959. #define PAL_CPP_CATCH_EXCEPTION(ident) } catch (Exception *ident) { PAL_Reenter(PAL_BoundaryBottom);
  5960. #define PAL_CPP_CATCH_EXCEPTION_NOARG } catch (Exception *) { PAL_Reenter(PAL_BoundaryBottom);
  5961. #define PAL_CPP_CATCH_DERIVED(type, ident) } catch (type *ident) { PAL_Reenter(PAL_BoundaryBottom);
  5962. #define PAL_CPP_CATCH_ALL } catch (...) { PAL_Reenter(PAL_BoundaryBottom);
  5963. #define PAL_CPP_ENDTRY }
  5964. #ifdef _MSC_VER
  5965. #pragma warning(disable:4611) // interaction between '_setjmp' and C++ object destruction is non-portable
  5966. #endif
  5967. #ifdef FEATURE_PAL_SXS
  5968. #define PAL_TRY_FOR_DLLMAIN(ParamType, paramDef, paramRef, _reason) PAL_TRY(ParamType, paramDef, paramRef)
  5969. #else // FEATURE_PAL_SXS
  5970. #define PAL_TRY(ParamType, paramDef, paramRef) \
  5971. { \
  5972. ParamType __param = paramRef; \
  5973. ParamType paramDef; paramDef = __param; \
  5974. try { \
  5975. HardwareExceptionHolder
  5976. #define PAL_TRY_FOR_DLLMAIN(ParamType, paramDef, paramRef, _reason) \
  5977. { \
  5978. ParamType __param = paramRef; \
  5979. ParamType paramDef; paramDef = __param; \
  5980. try { \
  5981. HardwareExceptionHolder
  5982. #define PAL_ENDTRY \
  5983. } \
  5984. }
  5985. #endif // FEATURE_PAL_SXS
  5986. #endif // __cplusplus
  5987. // Platform-specific library naming
  5988. //
  5989. #ifdef PLATFORM_UNIX
  5990. #ifdef __APPLE__
  5991. #define MAKEDLLNAME_W(name) u"lib" name u".dylib"
  5992. #define MAKEDLLNAME_A(name) "lib" name ".dylib"
  5993. #elif defined(_AIX)
  5994. #define MAKEDLLNAME_W(name) L"lib" name L".a"
  5995. #define MAKEDLLNAME_A(name) "lib" name ".a"
  5996. #elif defined(__hppa__) || defined(_IA64_)
  5997. #define MAKEDLLNAME_W(name) L"lib" name L".sl"
  5998. #define MAKEDLLNAME_A(name) "lib" name ".sl"
  5999. #else
  6000. #define MAKEDLLNAME_W(name) u"lib" name u".so"
  6001. #define MAKEDLLNAME_A(name) "lib" name ".so"
  6002. #endif
  6003. #else
  6004. #define MAKEDLLNAME_W(name) name L".dll"
  6005. #define MAKEDLLNAME_A(name) name ".dll"
  6006. #endif
  6007. #ifdef UNICODE
  6008. #define MAKEDLLNAME(x) MAKEDLLNAME_W(x)
  6009. #else
  6010. #define MAKEDLLNAME(x) MAKEDLLNAME_A(x)
  6011. #endif
  6012. #define PAL_SHLIB_PREFIX "lib"
  6013. #if __APPLE__
  6014. #define PAL_SHLIB_SUFFIX ".dylib"
  6015. #elif _AIX
  6016. #define PAL_SHLIB_SUFFIX ".a"
  6017. #elif _HPUX_
  6018. #define PAL_SHLIB_SUFFIX ".sl"
  6019. #else
  6020. #define PAL_SHLIB_SUFFIX ".so"
  6021. #endif
  6022. #define DBG_EXCEPTION_HANDLED ((DWORD )0x00010001L)
  6023. #define DBG_CONTINUE ((DWORD )0x00010002L)
  6024. #define DBG_EXCEPTION_NOT_HANDLED ((DWORD )0x80010001L)
  6025. #define DBG_TERMINATE_THREAD ((DWORD )0x40010003L)
  6026. #define DBG_TERMINATE_PROCESS ((DWORD )0x40010004L)
  6027. #define DBG_CONTROL_C ((DWORD )0x40010005L)
  6028. #define DBG_RIPEXCEPTION ((DWORD )0x40010007L)
  6029. #define DBG_CONTROL_BREAK ((DWORD )0x40010008L)
  6030. #define DBG_COMMAND_EXCEPTION ((DWORD )0x40010009L)
  6031. #define STATUS_USER_APC ((DWORD )0x000000C0L)
  6032. #define STATUS_GUARD_PAGE_VIOLATION ((DWORD )0x80000001L)
  6033. #define STATUS_DATATYPE_MISALIGNMENT ((DWORD )0x80000002L)
  6034. #define STATUS_BREAKPOINT ((DWORD )0x80000003L)
  6035. #define STATUS_SINGLE_STEP ((DWORD )0x80000004L)
  6036. #define STATUS_LONGJUMP ((DWORD )0x80000026L)
  6037. #define STATUS_UNWIND_CONSOLIDATE ((DWORD )0x80000029L)
  6038. #define STATUS_ACCESS_VIOLATION ((DWORD )0xC0000005L)
  6039. #define STATUS_IN_PAGE_ERROR ((DWORD )0xC0000006L)
  6040. #define STATUS_INVALID_HANDLE ((DWORD )0xC0000008L)
  6041. #define STATUS_NO_MEMORY ((DWORD )0xC0000017L)
  6042. #define STATUS_ILLEGAL_INSTRUCTION ((DWORD )0xC000001DL)
  6043. #define STATUS_NONCONTINUABLE_EXCEPTION ((DWORD )0xC0000025L)
  6044. #define STATUS_INVALID_DISPOSITION ((DWORD )0xC0000026L)
  6045. #define STATUS_ARRAY_BOUNDS_EXCEEDED ((DWORD )0xC000008CL)
  6046. #define STATUS_FLOAT_DENORMAL_OPERAND ((DWORD )0xC000008DL)
  6047. #define STATUS_FLOAT_DIVIDE_BY_ZERO ((DWORD )0xC000008EL)
  6048. #define STATUS_FLOAT_INEXACT_RESULT ((DWORD )0xC000008FL)
  6049. #define STATUS_FLOAT_INVALID_OPERATION ((DWORD )0xC0000090L)
  6050. #define STATUS_FLOAT_OVERFLOW ((DWORD )0xC0000091L)
  6051. #define STATUS_FLOAT_STACK_CHECK ((DWORD )0xC0000092L)
  6052. #define STATUS_FLOAT_UNDERFLOW ((DWORD )0xC0000093L)
  6053. #define STATUS_INTEGER_DIVIDE_BY_ZERO ((DWORD )0xC0000094L)
  6054. #define STATUS_INTEGER_OVERFLOW ((DWORD )0xC0000095L)
  6055. #define STATUS_PRIVILEGED_INSTRUCTION ((DWORD )0xC0000096L)
  6056. #define STATUS_STACK_OVERFLOW ((DWORD )0xC00000FDL)
  6057. #define STATUS_CONTROL_C_EXIT ((DWORD )0xC000013AL)
  6058. #define WAIT_IO_COMPLETION STATUS_USER_APC
  6059. #define EXCEPTION_ACCESS_VIOLATION STATUS_ACCESS_VIOLATION
  6060. #define EXCEPTION_DATATYPE_MISALIGNMENT STATUS_DATATYPE_MISALIGNMENT
  6061. #define EXCEPTION_BREAKPOINT STATUS_BREAKPOINT
  6062. #define EXCEPTION_SINGLE_STEP STATUS_SINGLE_STEP
  6063. #define EXCEPTION_ARRAY_BOUNDS_EXCEEDED STATUS_ARRAY_BOUNDS_EXCEEDED
  6064. #define EXCEPTION_FLT_DENORMAL_OPERAND STATUS_FLOAT_DENORMAL_OPERAND
  6065. #define EXCEPTION_FLT_DIVIDE_BY_ZERO STATUS_FLOAT_DIVIDE_BY_ZERO
  6066. #define EXCEPTION_FLT_INEXACT_RESULT STATUS_FLOAT_INEXACT_RESULT
  6067. #define EXCEPTION_FLT_INVALID_OPERATION STATUS_FLOAT_INVALID_OPERATION
  6068. #define EXCEPTION_FLT_OVERFLOW STATUS_FLOAT_OVERFLOW
  6069. #define EXCEPTION_FLT_STACK_CHECK STATUS_FLOAT_STACK_CHECK
  6070. #define EXCEPTION_FLT_UNDERFLOW STATUS_FLOAT_UNDERFLOW
  6071. #define EXCEPTION_INT_DIVIDE_BY_ZERO STATUS_INTEGER_DIVIDE_BY_ZERO
  6072. #define EXCEPTION_INT_OVERFLOW STATUS_INTEGER_OVERFLOW
  6073. #define EXCEPTION_PRIV_INSTRUCTION STATUS_PRIVILEGED_INSTRUCTION
  6074. #define EXCEPTION_IN_PAGE_ERROR STATUS_IN_PAGE_ERROR
  6075. #define EXCEPTION_ILLEGAL_INSTRUCTION STATUS_ILLEGAL_INSTRUCTION
  6076. #define EXCEPTION_NONCONTINUABLE_EXCEPTION STATUS_NONCONTINUABLE_EXCEPTION
  6077. #define EXCEPTION_STACK_OVERFLOW STATUS_STACK_OVERFLOW
  6078. #define EXCEPTION_INVALID_DISPOSITION STATUS_INVALID_DISPOSITION
  6079. #define EXCEPTION_GUARD_PAGE STATUS_GUARD_PAGE_VIOLATION
  6080. #define EXCEPTION_INVALID_HANDLE STATUS_INVALID_HANDLE
  6081. #define CONTROL_C_EXIT STATUS_CONTROL_C_EXIT
  6082. /* These are from the <FCNTL.H> file in windows.
  6083. They are needed for _open_osfhandle.*/
  6084. #define _O_RDONLY 0x0000
  6085. #define _O_APPEND 0x0008
  6086. #define _O_TEXT 0x4000
  6087. #define _O_BINARY 0x8000
  6088. #ifdef __cplusplus
  6089. }
  6090. #endif
  6091. #endif // __PAL_H__