pal.h 175 KB

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