pal.h 175 KB

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