pal.h 181 KB

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