2
0

pal.h 176 KB

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