pal.h 175 KB

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