000-update-to-git-2016-01-30.patch 436 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863
  1. --- a/.gitignore
  2. +++ b/.gitignore
  3. @@ -5,9 +5,6 @@
  4. *.so.1
  5. arch/*/bits/alltypes.h
  6. config.mak
  7. -include/bits
  8. -tools/musl-gcc
  9. -tools/musl-clang
  10. -tools/ld.musl-clang
  11. lib/musl-gcc.specs
  12. src/internal/version.h
  13. +/obj/
  14. --- a/Makefile
  15. +++ b/Makefile
  16. @@ -8,6 +8,7 @@
  17. # Do not make changes here.
  18. #
  19. +srcdir = .
  20. exec_prefix = /usr/local
  21. bindir = $(exec_prefix)/bin
  22. @@ -16,31 +17,42 @@ includedir = $(prefix)/include
  23. libdir = $(prefix)/lib
  24. syslibdir = /lib
  25. -SRCS = $(sort $(wildcard src/*/*.c arch/$(ARCH)/src/*.c))
  26. -OBJS = $(SRCS:.c=.o)
  27. +BASE_SRCS = $(sort $(wildcard $(srcdir)/src/*/*.c))
  28. +BASE_OBJS = $(patsubst $(srcdir)/%,%.o,$(basename $(BASE_SRCS)))
  29. +ARCH_SRCS = $(wildcard $(srcdir)/src/*/$(ARCH)/*.[csS])
  30. +ARCH_OBJS = $(patsubst $(srcdir)/%,%.o,$(basename $(ARCH_SRCS)))
  31. +REPLACED_OBJS = $(sort $(subst /$(ARCH)/,/,$(ARCH_OBJS)))
  32. +LDSO_SRCS = $(sort $(wildcard $(srcdir)/ldso/*.c))
  33. +LDSO_OBJS = $(patsubst $(srcdir)/%,obj/%.lo,$(basename $(LDSO_SRCS)))
  34. +OBJS = $(addprefix obj/, $(filter-out $(REPLACED_OBJS), $(sort $(BASE_OBJS) $(ARCH_OBJS))))
  35. +AOBJS = $(OBJS)
  36. LOBJS = $(OBJS:.o=.lo)
  37. -GENH = include/bits/alltypes.h
  38. -GENH_INT = src/internal/version.h
  39. -IMPH = src/internal/stdio_impl.h src/internal/pthread_impl.h src/internal/libc.h
  40. +GENH = obj/include/bits/alltypes.h
  41. +GENH_INT = obj/src/internal/version.h
  42. +IMPH = $(addprefix $(srcdir)/, src/internal/stdio_impl.h src/internal/pthread_impl.h src/internal/libc.h)
  43. -LDFLAGS =
  44. +LDFLAGS =
  45. +LDFLAGS_AUTO =
  46. LIBCC = -lgcc
  47. CPPFLAGS =
  48. -CFLAGS = -Os -pipe
  49. +CFLAGS =
  50. +CFLAGS_AUTO = -Os -pipe
  51. CFLAGS_C99FSE = -std=c99 -ffreestanding -nostdinc
  52. CFLAGS_ALL = $(CFLAGS_C99FSE)
  53. -CFLAGS_ALL += -D_XOPEN_SOURCE=700 -I./arch/$(ARCH) -I./src/internal -I./include
  54. -CFLAGS_ALL += $(CPPFLAGS) $(CFLAGS)
  55. -CFLAGS_ALL_STATIC = $(CFLAGS_ALL)
  56. -CFLAGS_ALL_SHARED = $(CFLAGS_ALL) -fPIC -DSHARED
  57. +CFLAGS_ALL += -D_XOPEN_SOURCE=700 -I$(srcdir)/arch/$(ARCH) -I$(srcdir)/arch/generic -Iobj/src/internal -I$(srcdir)/src/internal -Iobj/include -I$(srcdir)/include
  58. +CFLAGS_ALL += $(CPPFLAGS) $(CFLAGS_AUTO) $(CFLAGS)
  59. +
  60. +LDFLAGS_ALL = $(LDFLAGS_AUTO) $(LDFLAGS)
  61. AR = $(CROSS_COMPILE)ar
  62. RANLIB = $(CROSS_COMPILE)ranlib
  63. -INSTALL = ./tools/install.sh
  64. +INSTALL = $(srcdir)/tools/install.sh
  65. -ARCH_INCLUDES = $(wildcard arch/$(ARCH)/bits/*.h)
  66. -ALL_INCLUDES = $(sort $(wildcard include/*.h include/*/*.h) $(GENH) $(ARCH_INCLUDES:arch/$(ARCH)/%=include/%))
  67. +ARCH_INCLUDES = $(wildcard $(srcdir)/arch/$(ARCH)/bits/*.h)
  68. +GENERIC_INCLUDES = $(wildcard $(srcdir)/arch/generic/bits/*.h)
  69. +INCLUDES = $(wildcard $(srcdir)/include/*.h $(srcdir)/include/*/*.h)
  70. +ALL_INCLUDES = $(sort $(INCLUDES:$(srcdir)/%=%) $(GENH:obj/%=%) $(ARCH_INCLUDES:$(srcdir)/arch/$(ARCH)/%=include/%) $(GENERIC_INCLUDES:$(srcdir)/arch/generic/%=include/%))
  71. EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv dl
  72. EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a)
  73. @@ -49,7 +61,7 @@ STATIC_LIBS = lib/libc.a
  74. SHARED_LIBS = lib/libc.so
  75. TOOL_LIBS = lib/musl-gcc.specs
  76. ALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS) $(EMPTY_LIBS) $(TOOL_LIBS)
  77. -ALL_TOOLS = tools/musl-gcc
  78. +ALL_TOOLS = obj/musl-gcc
  79. WRAPCC_GCC = gcc
  80. WRAPCC_CLANG = clang
  81. @@ -58,122 +70,128 @@ LDSO_PATHNAME = $(syslibdir)/ld-musl-$(A
  82. -include config.mak
  83. +ifeq ($(ARCH),)
  84. +$(error Please set ARCH in config.mak before running make.)
  85. +endif
  86. +
  87. all: $(ALL_LIBS) $(ALL_TOOLS)
  88. +OBJ_DIRS = $(sort $(patsubst %/,%,$(dir $(ALL_LIBS) $(ALL_TOOLS) $(OBJS) $(LDSO_OBJS) $(GENH) $(GENH_INT))) $(addprefix obj/, crt crt/$(ARCH) include))
  89. +
  90. +$(ALL_LIBS) $(ALL_TOOLS) $(CRT_LIBS:lib/%=obj/crt/%) $(OBJS) $(LOBJS) $(GENH) $(GENH_INT): | $(OBJ_DIRS)
  91. +
  92. +$(OBJ_DIRS):
  93. + mkdir -p $@
  94. +
  95. install: install-libs install-headers install-tools
  96. clean:
  97. - rm -f crt/*.o
  98. - rm -f $(OBJS)
  99. - rm -f $(LOBJS)
  100. - rm -f $(ALL_LIBS) lib/*.[ao] lib/*.so
  101. - rm -f $(ALL_TOOLS)
  102. - rm -f $(GENH) $(GENH_INT)
  103. - rm -f include/bits
  104. + rm -rf obj lib
  105. distclean: clean
  106. rm -f config.mak
  107. -include/bits:
  108. - @test "$(ARCH)" || { echo "Please set ARCH in config.mak before running make." ; exit 1 ; }
  109. - ln -sf ../arch/$(ARCH)/bits $@
  110. +obj/include/bits/alltypes.h: $(srcdir)/arch/$(ARCH)/bits/alltypes.h.in $(srcdir)/include/alltypes.h.in $(srcdir)/tools/mkalltypes.sed
  111. + sed -f $(srcdir)/tools/mkalltypes.sed $(srcdir)/arch/$(ARCH)/bits/alltypes.h.in $(srcdir)/include/alltypes.h.in > $@
  112. -include/bits/alltypes.h.in: include/bits
  113. +obj/src/internal/version.h: $(wildcard $(srcdir)/VERSION $(srcdir)/.git)
  114. + printf '#define VERSION "%s"\n' "$$(cd $(srcdir); sh tools/version.sh)" > $@
  115. -include/bits/alltypes.h: include/bits/alltypes.h.in include/alltypes.h.in tools/mkalltypes.sed
  116. - sed -f tools/mkalltypes.sed include/bits/alltypes.h.in include/alltypes.h.in > $@
  117. +obj/src/internal/version.o obj/src/internal/version.lo: obj/src/internal/version.h
  118. -src/internal/version.h: $(wildcard VERSION .git)
  119. - printf '#define VERSION "%s"\n' "$$(sh tools/version.sh)" > $@
  120. +obj/crt/rcrt1.o obj/ldso/dlstart.lo obj/ldso/dynlink.lo: $(srcdir)/src/internal/dynlink.h $(srcdir)/arch/$(ARCH)/reloc.h
  121. -src/internal/version.lo: src/internal/version.h
  122. +obj/crt/crt1.o obj/crt/scrt1.o obj/crt/rcrt1.o obj/ldso/dlstart.lo: $(srcdir)/arch/$(ARCH)/crt_arch.h
  123. -crt/rcrt1.o src/ldso/dlstart.lo src/ldso/dynlink.lo: src/internal/dynlink.h arch/$(ARCH)/reloc.h
  124. +obj/crt/rcrt1.o: $(srcdir)/ldso/dlstart.c
  125. -crt/crt1.o crt/Scrt1.o crt/rcrt1.o src/ldso/dlstart.lo: $(wildcard arch/$(ARCH)/crt_arch.h)
  126. +obj/crt/Scrt1.o obj/crt/rcrt1.o: CFLAGS_ALL += -fPIC
  127. -crt/rcrt1.o: src/ldso/dlstart.c
  128. +obj/crt/$(ARCH)/crti.o: $(srcdir)/crt/$(ARCH)/crti.s
  129. -crt/Scrt1.o crt/rcrt1.o: CFLAGS += -fPIC
  130. +obj/crt/$(ARCH)/crtn.o: $(srcdir)/crt/$(ARCH)/crtn.s
  131. -OPTIMIZE_SRCS = $(wildcard $(OPTIMIZE_GLOBS:%=src/%))
  132. -$(OPTIMIZE_SRCS:%.c=%.o) $(OPTIMIZE_SRCS:%.c=%.lo): CFLAGS += -O3
  133. +OPTIMIZE_SRCS = $(wildcard $(OPTIMIZE_GLOBS:%=$(srcdir)/src/%))
  134. +$(OPTIMIZE_SRCS:$(srcdir)/%.c=obj/%.o) $(OPTIMIZE_SRCS:$(srcdir)/%.c=obj/%.lo): CFLAGS += -O3
  135. MEMOPS_SRCS = src/string/memcpy.c src/string/memmove.c src/string/memcmp.c src/string/memset.c
  136. -$(MEMOPS_SRCS:%.c=%.o) $(MEMOPS_SRCS:%.c=%.lo): CFLAGS += $(CFLAGS_MEMOPS)
  137. +$(MEMOPS_SRCS:%.c=obj/%.o) $(MEMOPS_SRCS:%.c=obj/%.lo): CFLAGS_ALL += $(CFLAGS_MEMOPS)
  138. NOSSP_SRCS = $(wildcard crt/*.c) \
  139. src/env/__libc_start_main.c src/env/__init_tls.c \
  140. - src/thread/__set_thread_area.c src/env/__stack_chk_fail.c \
  141. - src/string/memset.c src/string/memcpy.c \
  142. - src/ldso/dlstart.c src/ldso/dynlink.c
  143. -$(NOSSP_SRCS:%.c=%.o) $(NOSSP_SRCS:%.c=%.lo): CFLAGS += $(CFLAGS_NOSSP)
  144. + src/env/__stack_chk_fail.c \
  145. + src/thread/__set_thread_area.c src/thread/$(ARCH)/__set_thread_area.c \
  146. + src/string/memset.c src/string/$(ARCH)/memset.c \
  147. + src/string/memcpy.c src/string/$(ARCH)/memcpy.c \
  148. + ldso/dlstart.c ldso/dynlink.c
  149. +$(NOSSP_SRCS:%.c=obj/%.o) $(NOSSP_SRCS:%.c=obj/%.lo): CFLAGS_ALL += $(CFLAGS_NOSSP)
  150. -$(CRT_LIBS:lib/%=crt/%): CFLAGS += -DCRT
  151. +$(CRT_LIBS:lib/%=obj/crt/%): CFLAGS_ALL += -DCRT
  152. -# This incantation ensures that changes to any subarch asm files will
  153. -# force the corresponding object file to be rebuilt, even if the implicit
  154. -# rule below goes indirectly through a .sub file.
  155. -define mkasmdep
  156. -$(dir $(patsubst %/,%,$(dir $(1))))$(notdir $(1:.s=.o)): $(1)
  157. -endef
  158. -$(foreach s,$(wildcard src/*/$(ARCH)*/*.s),$(eval $(call mkasmdep,$(s))))
  159. +$(LOBJS) $(LDSO_OBJS): CFLAGS_ALL += -fPIC
  160. +
  161. +CC_CMD = $(CC) $(CFLAGS_ALL) -c -o $@ $<
  162. # Choose invocation of assembler to be used
  163. -# $(1) is input file, $(2) is output file, $(3) is assembler flags
  164. ifeq ($(ADD_CFI),yes)
  165. - AS_CMD = LC_ALL=C awk -f tools/add-cfi.common.awk -f tools/add-cfi.$(ARCH).awk $< | $(CC) -x assembler -c -o $@ -
  166. + AS_CMD = LC_ALL=C awk -f $(srcdir)/tools/add-cfi.common.awk -f $(srcdir)/tools/add-cfi.$(ARCH).awk $< | $(CC) $(CFLAGS_ALL) -x assembler -c -o $@ -
  167. else
  168. - AS_CMD = $(CC) -c -o $@ $<
  169. + AS_CMD = $(CC_CMD)
  170. endif
  171. -%.o: $(ARCH)$(ASMSUBARCH)/%.sub
  172. - $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $(dir $<)$(shell cat $<)
  173. +obj/%.o: $(srcdir)/%.s
  174. + $(AS_CMD)
  175. -%.o: $(ARCH)/%.s
  176. - $(AS_CMD) $(CFLAGS_ALL_STATIC)
  177. +obj/%.o: $(srcdir)/%.S
  178. + $(CC_CMD)
  179. -%.o: %.c $(GENH) $(IMPH)
  180. - $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
  181. +obj/%.o: $(srcdir)/%.c $(GENH) $(IMPH)
  182. + $(CC_CMD)
  183. -%.lo: $(ARCH)$(ASMSUBARCH)/%.sub
  184. - $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $(dir $<)$(shell cat $<)
  185. +obj/%.lo: $(srcdir)/%.s
  186. + $(AS_CMD)
  187. -%.lo: $(ARCH)/%.s
  188. - $(AS_CMD) $(CFLAGS_ALL_SHARED)
  189. +obj/%.lo: $(srcdir)/%.S
  190. + $(CC_CMD)
  191. -%.lo: %.c $(GENH) $(IMPH)
  192. - $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
  193. +obj/%.lo: $(srcdir)/%.c $(GENH) $(IMPH)
  194. + $(CC_CMD)
  195. -lib/libc.so: $(LOBJS)
  196. - $(CC) $(CFLAGS_ALL_SHARED) $(LDFLAGS) -nostdlib -shared \
  197. +lib/libc.so: $(LOBJS) $(LDSO_OBJS)
  198. + $(CC) $(CFLAGS_ALL) $(LDFLAGS_ALL) -nostdlib -shared \
  199. -Wl,-e,_dlstart -Wl,-Bsymbolic-functions \
  200. - -o $@ $(LOBJS) $(LIBCC)
  201. + -o $@ $(LOBJS) $(LDSO_OBJS) $(LIBCC)
  202. -lib/libc.a: $(OBJS)
  203. +lib/libc.a: $(AOBJS)
  204. rm -f $@
  205. - $(AR) rc $@ $(OBJS)
  206. + $(AR) rc $@ $(AOBJS)
  207. $(RANLIB) $@
  208. $(EMPTY_LIBS):
  209. rm -f $@
  210. $(AR) rc $@
  211. -lib/%.o: crt/%.o
  212. +lib/%.o: obj/crt/%.o
  213. cp $< $@
  214. -lib/musl-gcc.specs: tools/musl-gcc.specs.sh config.mak
  215. +lib/crti.o: obj/crt/$(ARCH)/crti.o
  216. + cp $< $@
  217. +
  218. +lib/crtn.o: obj/crt/$(ARCH)/crtn.o
  219. + cp $< $@
  220. +
  221. +lib/musl-gcc.specs: $(srcdir)/tools/musl-gcc.specs.sh config.mak
  222. sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@
  223. -tools/musl-gcc: config.mak
  224. +obj/musl-gcc: config.mak
  225. printf '#!/bin/sh\nexec "$${REALGCC:-$(WRAPCC_GCC)}" "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@
  226. chmod +x $@
  227. -tools/%-clang: tools/%-clang.in config.mak
  228. +obj/%-clang: $(srcdir)/tools/%-clang.in config.mak
  229. sed -e 's!@CC@!$(WRAPCC_CLANG)!g' -e 's!@PREFIX@!$(prefix)!g' -e 's!@INCDIR@!$(includedir)!g' -e 's!@LIBDIR@!$(libdir)!g' -e 's!@LDSO@!$(LDSO_PATHNAME)!g' $< > $@
  230. chmod +x $@
  231. -$(DESTDIR)$(bindir)/%: tools/%
  232. +$(DESTDIR)$(bindir)/%: obj/%
  233. $(INSTALL) -D $< $@
  234. $(DESTDIR)$(libdir)/%.so: lib/%.so
  235. @@ -182,10 +200,16 @@ $(DESTDIR)$(libdir)/%.so: lib/%.so
  236. $(DESTDIR)$(libdir)/%: lib/%
  237. $(INSTALL) -D -m 644 $< $@
  238. -$(DESTDIR)$(includedir)/bits/%: arch/$(ARCH)/bits/%
  239. +$(DESTDIR)$(includedir)/bits/%: $(srcdir)/arch/$(ARCH)/bits/%
  240. $(INSTALL) -D -m 644 $< $@
  241. -$(DESTDIR)$(includedir)/%: include/%
  242. +$(DESTDIR)$(includedir)/bits/%: $(srcdir)/arch/generic/bits/%
  243. + $(INSTALL) -D -m 644 $< $@
  244. +
  245. +$(DESTDIR)$(includedir)/bits/%: obj/include/bits/%
  246. + $(INSTALL) -D -m 644 $< $@
  247. +
  248. +$(DESTDIR)$(includedir)/%: $(srcdir)/include/%
  249. $(INSTALL) -D -m 644 $< $@
  250. $(DESTDIR)$(LDSO_PATHNAME): $(DESTDIR)$(libdir)/libc.so
  251. @@ -195,12 +219,12 @@ install-libs: $(ALL_LIBS:lib/%=$(DESTDIR
  252. install-headers: $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%)
  253. -install-tools: $(ALL_TOOLS:tools/%=$(DESTDIR)$(bindir)/%)
  254. +install-tools: $(ALL_TOOLS:obj/%=$(DESTDIR)$(bindir)/%)
  255. musl-git-%.tar.gz: .git
  256. - git archive --format=tar.gz --prefix=$(patsubst %.tar.gz,%,$@)/ -o $@ $(patsubst musl-git-%.tar.gz,%,$@)
  257. + git --git-dir=$(srcdir)/.git archive --format=tar.gz --prefix=$(patsubst %.tar.gz,%,$@)/ -o $@ $(patsubst musl-git-%.tar.gz,%,$@)
  258. musl-%.tar.gz: .git
  259. - git archive --format=tar.gz --prefix=$(patsubst %.tar.gz,%,$@)/ -o $@ v$(patsubst musl-%.tar.gz,%,$@)
  260. + git --git-dir=$(srcdir)/.git archive --format=tar.gz --prefix=$(patsubst %.tar.gz,%,$@)/ -o $@ v$(patsubst musl-%.tar.gz,%,$@)
  261. .PHONY: all clean install install-libs install-headers install-tools
  262. --- a/arch/aarch64/atomic.h
  263. +++ /dev/null
  264. @@ -1,206 +0,0 @@
  265. -#ifndef _INTERNAL_ATOMIC_H
  266. -#define _INTERNAL_ATOMIC_H
  267. -
  268. -#include <stdint.h>
  269. -
  270. -static inline int a_ctz_64(uint64_t x)
  271. -{
  272. - __asm__(
  273. - " rbit %0, %1\n"
  274. - " clz %0, %0\n"
  275. - : "=r"(x) : "r"(x));
  276. - return x;
  277. -}
  278. -
  279. -static inline int a_ctz_l(unsigned long x)
  280. -{
  281. - return a_ctz_64(x);
  282. -}
  283. -
  284. -static inline void a_barrier()
  285. -{
  286. - __asm__ __volatile__("dmb ish");
  287. -}
  288. -
  289. -static inline void *a_cas_p(volatile void *p, void *t, void *s)
  290. -{
  291. - void *old;
  292. - __asm__ __volatile__(
  293. - " dmb ish\n"
  294. - "1: ldxr %0,%3\n"
  295. - " cmp %0,%1\n"
  296. - " b.ne 1f\n"
  297. - " stxr %w0,%2,%3\n"
  298. - " cbnz %w0,1b\n"
  299. - " mov %0,%1\n"
  300. - "1: dmb ish\n"
  301. - : "=&r"(old)
  302. - : "r"(t), "r"(s), "Q"(*(long*)p)
  303. - : "memory", "cc");
  304. - return old;
  305. -}
  306. -
  307. -static inline int a_cas(volatile int *p, int t, int s)
  308. -{
  309. - int old;
  310. - __asm__ __volatile__(
  311. - " dmb ish\n"
  312. - "1: ldxr %w0,%3\n"
  313. - " cmp %w0,%w1\n"
  314. - " b.ne 1f\n"
  315. - " stxr %w0,%w2,%3\n"
  316. - " cbnz %w0,1b\n"
  317. - " mov %w0,%w1\n"
  318. - "1: dmb ish\n"
  319. - : "=&r"(old)
  320. - : "r"(t), "r"(s), "Q"(*p)
  321. - : "memory", "cc");
  322. - return old;
  323. -}
  324. -
  325. -static inline int a_swap(volatile int *x, int v)
  326. -{
  327. - int old, tmp;
  328. - __asm__ __volatile__(
  329. - " dmb ish\n"
  330. - "1: ldxr %w0,%3\n"
  331. - " stxr %w1,%w2,%3\n"
  332. - " cbnz %w1,1b\n"
  333. - " dmb ish\n"
  334. - : "=&r"(old), "=&r"(tmp)
  335. - : "r"(v), "Q"(*x)
  336. - : "memory", "cc" );
  337. - return old;
  338. -}
  339. -
  340. -static inline int a_fetch_add(volatile int *x, int v)
  341. -{
  342. - int old, tmp;
  343. - __asm__ __volatile__(
  344. - " dmb ish\n"
  345. - "1: ldxr %w0,%3\n"
  346. - " add %w0,%w0,%w2\n"
  347. - " stxr %w1,%w0,%3\n"
  348. - " cbnz %w1,1b\n"
  349. - " dmb ish\n"
  350. - : "=&r"(old), "=&r"(tmp)
  351. - : "r"(v), "Q"(*x)
  352. - : "memory", "cc" );
  353. - return old-v;
  354. -}
  355. -
  356. -static inline void a_inc(volatile int *x)
  357. -{
  358. - int tmp, tmp2;
  359. - __asm__ __volatile__(
  360. - " dmb ish\n"
  361. - "1: ldxr %w0,%2\n"
  362. - " add %w0,%w0,#1\n"
  363. - " stxr %w1,%w0,%2\n"
  364. - " cbnz %w1,1b\n"
  365. - " dmb ish\n"
  366. - : "=&r"(tmp), "=&r"(tmp2)
  367. - : "Q"(*x)
  368. - : "memory", "cc" );
  369. -}
  370. -
  371. -static inline void a_dec(volatile int *x)
  372. -{
  373. - int tmp, tmp2;
  374. - __asm__ __volatile__(
  375. - " dmb ish\n"
  376. - "1: ldxr %w0,%2\n"
  377. - " sub %w0,%w0,#1\n"
  378. - " stxr %w1,%w0,%2\n"
  379. - " cbnz %w1,1b\n"
  380. - " dmb ish\n"
  381. - : "=&r"(tmp), "=&r"(tmp2)
  382. - : "Q"(*x)
  383. - : "memory", "cc" );
  384. -}
  385. -
  386. -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
  387. -{
  388. - int tmp, tmp2;
  389. - __asm__ __volatile__(
  390. - " dmb ish\n"
  391. - "1: ldxr %0,%3\n"
  392. - " and %0,%0,%2\n"
  393. - " stxr %w1,%0,%3\n"
  394. - " cbnz %w1,1b\n"
  395. - " dmb ish\n"
  396. - : "=&r"(tmp), "=&r"(tmp2)
  397. - : "r"(v), "Q"(*p)
  398. - : "memory", "cc" );
  399. -}
  400. -
  401. -static inline void a_and(volatile int *p, int v)
  402. -{
  403. - int tmp, tmp2;
  404. - __asm__ __volatile__(
  405. - " dmb ish\n"
  406. - "1: ldxr %w0,%3\n"
  407. - " and %w0,%w0,%w2\n"
  408. - " stxr %w1,%w0,%3\n"
  409. - " cbnz %w1,1b\n"
  410. - " dmb ish\n"
  411. - : "=&r"(tmp), "=&r"(tmp2)
  412. - : "r"(v), "Q"(*p)
  413. - : "memory", "cc" );
  414. -}
  415. -
  416. -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
  417. -{
  418. - int tmp, tmp2;
  419. - __asm__ __volatile__(
  420. - " dmb ish\n"
  421. - "1: ldxr %0,%3\n"
  422. - " orr %0,%0,%2\n"
  423. - " stxr %w1,%0,%3\n"
  424. - " cbnz %w1,1b\n"
  425. - " dmb ish\n"
  426. - : "=&r"(tmp), "=&r"(tmp2)
  427. - : "r"(v), "Q"(*p)
  428. - : "memory", "cc" );
  429. -}
  430. -
  431. -static inline void a_or_l(volatile void *p, long v)
  432. -{
  433. - return a_or_64(p, v);
  434. -}
  435. -
  436. -static inline void a_or(volatile int *p, int v)
  437. -{
  438. - int tmp, tmp2;
  439. - __asm__ __volatile__(
  440. - " dmb ish\n"
  441. - "1: ldxr %w0,%3\n"
  442. - " orr %w0,%w0,%w2\n"
  443. - " stxr %w1,%w0,%3\n"
  444. - " cbnz %w1,1b\n"
  445. - " dmb ish\n"
  446. - : "=&r"(tmp), "=&r"(tmp2)
  447. - : "r"(v), "Q"(*p)
  448. - : "memory", "cc" );
  449. -}
  450. -
  451. -static inline void a_store(volatile int *p, int x)
  452. -{
  453. - __asm__ __volatile__(
  454. - " dmb ish\n"
  455. - " str %w1,%0\n"
  456. - " dmb ish\n"
  457. - : "=m"(*p)
  458. - : "r"(x)
  459. - : "memory", "cc" );
  460. -}
  461. -
  462. -#define a_spin a_barrier
  463. -
  464. -static inline void a_crash()
  465. -{
  466. - *(volatile char *)0=0;
  467. -}
  468. -
  469. -
  470. -#endif
  471. --- /dev/null
  472. +++ b/arch/aarch64/atomic_arch.h
  473. @@ -0,0 +1,73 @@
  474. +#define a_ll a_ll
  475. +static inline int a_ll(volatile int *p)
  476. +{
  477. + int v;
  478. + __asm__ __volatile__ ("ldaxr %w0,%1" : "=r"(v) : "Q"(*p));
  479. + return v;
  480. +}
  481. +
  482. +#define a_sc a_sc
  483. +static inline int a_sc(volatile int *p, int v)
  484. +{
  485. + int r;
  486. + __asm__ __volatile__ ("stlxr %w0,%w1,%2" : "=&r"(r) : "r"(v), "Q"(*p) : "memory");
  487. + return !r;
  488. +}
  489. +
  490. +#define a_barrier a_barrier
  491. +static inline void a_barrier()
  492. +{
  493. + __asm__ __volatile__ ("dmb ish" : : : "memory");
  494. +}
  495. +
  496. +#define a_cas a_cas
  497. +static inline int a_cas(volatile int *p, int t, int s)
  498. +{
  499. + int old;
  500. + do {
  501. + old = a_ll(p);
  502. + if (old != t) {
  503. + a_barrier();
  504. + break;
  505. + }
  506. + } while (!a_sc(p, s));
  507. + return old;
  508. +}
  509. +
  510. +static inline void *a_ll_p(volatile void *p)
  511. +{
  512. + void *v;
  513. + __asm__ __volatile__ ("ldaxr %0, %1" : "=r"(v) : "Q"(*(void *volatile *)p));
  514. + return v;
  515. +}
  516. +
  517. +static inline int a_sc_p(volatile int *p, void *v)
  518. +{
  519. + int r;
  520. + __asm__ __volatile__ ("stlxr %w0,%1,%2" : "=&r"(r) : "r"(v), "Q"(*(void *volatile *)p) : "memory");
  521. + return !r;
  522. +}
  523. +
  524. +#define a_cas_p a_cas_p
  525. +static inline void *a_cas_p(volatile void *p, void *t, void *s)
  526. +{
  527. + void *old;
  528. + do {
  529. + old = a_ll_p(p);
  530. + if (old != t) {
  531. + a_barrier();
  532. + break;
  533. + }
  534. + } while (!a_sc_p(p, s));
  535. + return old;
  536. +}
  537. +
  538. +#define a_ctz_64 a_ctz_64
  539. +static inline int a_ctz_64(uint64_t x)
  540. +{
  541. + __asm__(
  542. + " rbit %0, %1\n"
  543. + " clz %0, %0\n"
  544. + : "=r"(x) : "r"(x));
  545. + return x;
  546. +}
  547. --- a/arch/aarch64/bits/errno.h
  548. +++ /dev/null
  549. @@ -1,134 +0,0 @@
  550. -#define EPERM 1
  551. -#define ENOENT 2
  552. -#define ESRCH 3
  553. -#define EINTR 4
  554. -#define EIO 5
  555. -#define ENXIO 6
  556. -#define E2BIG 7
  557. -#define ENOEXEC 8
  558. -#define EBADF 9
  559. -#define ECHILD 10
  560. -#define EAGAIN 11
  561. -#define ENOMEM 12
  562. -#define EACCES 13
  563. -#define EFAULT 14
  564. -#define ENOTBLK 15
  565. -#define EBUSY 16
  566. -#define EEXIST 17
  567. -#define EXDEV 18
  568. -#define ENODEV 19
  569. -#define ENOTDIR 20
  570. -#define EISDIR 21
  571. -#define EINVAL 22
  572. -#define ENFILE 23
  573. -#define EMFILE 24
  574. -#define ENOTTY 25
  575. -#define ETXTBSY 26
  576. -#define EFBIG 27
  577. -#define ENOSPC 28
  578. -#define ESPIPE 29
  579. -#define EROFS 30
  580. -#define EMLINK 31
  581. -#define EPIPE 32
  582. -#define EDOM 33
  583. -#define ERANGE 34
  584. -#define EDEADLK 35
  585. -#define ENAMETOOLONG 36
  586. -#define ENOLCK 37
  587. -#define ENOSYS 38
  588. -#define ENOTEMPTY 39
  589. -#define ELOOP 40
  590. -#define EWOULDBLOCK EAGAIN
  591. -#define ENOMSG 42
  592. -#define EIDRM 43
  593. -#define ECHRNG 44
  594. -#define EL2NSYNC 45
  595. -#define EL3HLT 46
  596. -#define EL3RST 47
  597. -#define ELNRNG 48
  598. -#define EUNATCH 49
  599. -#define ENOCSI 50
  600. -#define EL2HLT 51
  601. -#define EBADE 52
  602. -#define EBADR 53
  603. -#define EXFULL 54
  604. -#define ENOANO 55
  605. -#define EBADRQC 56
  606. -#define EBADSLT 57
  607. -#define EDEADLOCK EDEADLK
  608. -#define EBFONT 59
  609. -#define ENOSTR 60
  610. -#define ENODATA 61
  611. -#define ETIME 62
  612. -#define ENOSR 63
  613. -#define ENONET 64
  614. -#define ENOPKG 65
  615. -#define EREMOTE 66
  616. -#define ENOLINK 67
  617. -#define EADV 68
  618. -#define ESRMNT 69
  619. -#define ECOMM 70
  620. -#define EPROTO 71
  621. -#define EMULTIHOP 72
  622. -#define EDOTDOT 73
  623. -#define EBADMSG 74
  624. -#define EOVERFLOW 75
  625. -#define ENOTUNIQ 76
  626. -#define EBADFD 77
  627. -#define EREMCHG 78
  628. -#define ELIBACC 79
  629. -#define ELIBBAD 80
  630. -#define ELIBSCN 81
  631. -#define ELIBMAX 82
  632. -#define ELIBEXEC 83
  633. -#define EILSEQ 84
  634. -#define ERESTART 85
  635. -#define ESTRPIPE 86
  636. -#define EUSERS 87
  637. -#define ENOTSOCK 88
  638. -#define EDESTADDRREQ 89
  639. -#define EMSGSIZE 90
  640. -#define EPROTOTYPE 91
  641. -#define ENOPROTOOPT 92
  642. -#define EPROTONOSUPPORT 93
  643. -#define ESOCKTNOSUPPORT 94
  644. -#define EOPNOTSUPP 95
  645. -#define ENOTSUP EOPNOTSUPP
  646. -#define EPFNOSUPPORT 96
  647. -#define EAFNOSUPPORT 97
  648. -#define EADDRINUSE 98
  649. -#define EADDRNOTAVAIL 99
  650. -#define ENETDOWN 100
  651. -#define ENETUNREACH 101
  652. -#define ENETRESET 102
  653. -#define ECONNABORTED 103
  654. -#define ECONNRESET 104
  655. -#define ENOBUFS 105
  656. -#define EISCONN 106
  657. -#define ENOTCONN 107
  658. -#define ESHUTDOWN 108
  659. -#define ETOOMANYREFS 109
  660. -#define ETIMEDOUT 110
  661. -#define ECONNREFUSED 111
  662. -#define EHOSTDOWN 112
  663. -#define EHOSTUNREACH 113
  664. -#define EALREADY 114
  665. -#define EINPROGRESS 115
  666. -#define ESTALE 116
  667. -#define EUCLEAN 117
  668. -#define ENOTNAM 118
  669. -#define ENAVAIL 119
  670. -#define EISNAM 120
  671. -#define EREMOTEIO 121
  672. -#define EDQUOT 122
  673. -#define ENOMEDIUM 123
  674. -#define EMEDIUMTYPE 124
  675. -#define ECANCELED 125
  676. -#define ENOKEY 126
  677. -#define EKEYEXPIRED 127
  678. -#define EKEYREVOKED 128
  679. -#define EKEYREJECTED 129
  680. -#define EOWNERDEAD 130
  681. -#define ENOTRECOVERABLE 131
  682. -#define ERFKILL 132
  683. -#define EHWPOISON 133
  684. --- a/arch/aarch64/bits/mman.h
  685. +++ b/arch/aarch64/bits/mman.h
  686. @@ -36,6 +36,7 @@
  687. #define MCL_CURRENT 1
  688. #define MCL_FUTURE 2
  689. +#define MCL_ONFAULT 4
  690. #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  691. #define MADV_NORMAL 0
  692. --- a/arch/aarch64/bits/statfs.h
  693. +++ /dev/null
  694. @@ -1,7 +0,0 @@
  695. -struct statfs {
  696. - unsigned long f_type, f_bsize;
  697. - fsblkcnt_t f_blocks, f_bfree, f_bavail;
  698. - fsfilcnt_t f_files, f_ffree;
  699. - fsid_t f_fsid;
  700. - unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
  701. -};
  702. --- a/arch/aarch64/bits/stdarg.h
  703. +++ /dev/null
  704. @@ -1,4 +0,0 @@
  705. -#define va_start(v,l) __builtin_va_start(v,l)
  706. -#define va_end(v) __builtin_va_end(v)
  707. -#define va_arg(v,l) __builtin_va_arg(v,l)
  708. -#define va_copy(d,s) __builtin_va_copy(d,s)
  709. --- a/arch/aarch64/bits/syscall.h
  710. +++ b/arch/aarch64/bits/syscall.h
  711. @@ -265,6 +265,9 @@
  712. #define __NR_memfd_create 279
  713. #define __NR_bpf 280
  714. #define __NR_execveat 281
  715. +#define __NR_userfaultfd 282
  716. +#define __NR_membarrier 283
  717. +#define __NR_mlock2 284
  718. #define SYS_io_setup __NR_io_setup
  719. #define SYS_io_destroy __NR_io_destroy
  720. @@ -533,3 +536,6 @@
  721. #define SYS_memfd_create __NR_memfd_create
  722. #define SYS_bpf __NR_bpf
  723. #define SYS_execveat __NR_execveat
  724. +#define SYS_userfaultfd __NR_userfaultfd
  725. +#define SYS_membarrier __NR_membarrier
  726. +#define SYS_mlock2 __NR_mlock2
  727. --- a/arch/aarch64/bits/termios.h
  728. +++ /dev/null
  729. @@ -1,160 +0,0 @@
  730. -struct termios
  731. -{
  732. - tcflag_t c_iflag;
  733. - tcflag_t c_oflag;
  734. - tcflag_t c_cflag;
  735. - tcflag_t c_lflag;
  736. - cc_t c_line;
  737. - cc_t c_cc[NCCS];
  738. - speed_t __c_ispeed;
  739. - speed_t __c_ospeed;
  740. -};
  741. -
  742. -#define VINTR 0
  743. -#define VQUIT 1
  744. -#define VERASE 2
  745. -#define VKILL 3
  746. -#define VEOF 4
  747. -#define VTIME 5
  748. -#define VMIN 6
  749. -#define VSWTC 7
  750. -#define VSTART 8
  751. -#define VSTOP 9
  752. -#define VSUSP 10
  753. -#define VEOL 11
  754. -#define VREPRINT 12
  755. -#define VDISCARD 13
  756. -#define VWERASE 14
  757. -#define VLNEXT 15
  758. -#define VEOL2 16
  759. -
  760. -#define IGNBRK 0000001
  761. -#define BRKINT 0000002
  762. -#define IGNPAR 0000004
  763. -#define PARMRK 0000010
  764. -#define INPCK 0000020
  765. -#define ISTRIP 0000040
  766. -#define INLCR 0000100
  767. -#define IGNCR 0000200
  768. -#define ICRNL 0000400
  769. -#define IUCLC 0001000
  770. -#define IXON 0002000
  771. -#define IXANY 0004000
  772. -#define IXOFF 0010000
  773. -#define IMAXBEL 0020000
  774. -#define IUTF8 0040000
  775. -
  776. -#define OPOST 0000001
  777. -#define OLCUC 0000002
  778. -#define ONLCR 0000004
  779. -#define OCRNL 0000010
  780. -#define ONOCR 0000020
  781. -#define ONLRET 0000040
  782. -#define OFILL 0000100
  783. -#define OFDEL 0000200
  784. -#define NLDLY 0000400
  785. -#define NL0 0000000
  786. -#define NL1 0000400
  787. -#define CRDLY 0003000
  788. -#define CR0 0000000
  789. -#define CR1 0001000
  790. -#define CR2 0002000
  791. -#define CR3 0003000
  792. -#define TABDLY 0014000
  793. -#define TAB0 0000000
  794. -#define TAB1 0004000
  795. -#define TAB2 0010000
  796. -#define TAB3 0014000
  797. -#define BSDLY 0020000
  798. -#define BS0 0000000
  799. -#define BS1 0020000
  800. -#define FFDLY 0100000
  801. -#define FF0 0000000
  802. -#define FF1 0100000
  803. -
  804. -#define VTDLY 0040000
  805. -#define VT0 0000000
  806. -#define VT1 0040000
  807. -
  808. -#define B0 0000000
  809. -#define B50 0000001
  810. -#define B75 0000002
  811. -#define B110 0000003
  812. -#define B134 0000004
  813. -#define B150 0000005
  814. -#define B200 0000006
  815. -#define B300 0000007
  816. -#define B600 0000010
  817. -#define B1200 0000011
  818. -#define B1800 0000012
  819. -#define B2400 0000013
  820. -#define B4800 0000014
  821. -#define B9600 0000015
  822. -#define B19200 0000016
  823. -#define B38400 0000017
  824. -
  825. -#define B57600 0010001
  826. -#define B115200 0010002
  827. -#define B230400 0010003
  828. -#define B460800 0010004
  829. -#define B500000 0010005
  830. -#define B576000 0010006
  831. -#define B921600 0010007
  832. -#define B1000000 0010010
  833. -#define B1152000 0010011
  834. -#define B1500000 0010012
  835. -#define B2000000 0010013
  836. -#define B2500000 0010014
  837. -#define B3000000 0010015
  838. -#define B3500000 0010016
  839. -#define B4000000 0010017
  840. -
  841. -#define CBAUD 0010017
  842. -
  843. -#define CSIZE 0000060
  844. -#define CS5 0000000
  845. -#define CS6 0000020
  846. -#define CS7 0000040
  847. -#define CS8 0000060
  848. -#define CSTOPB 0000100
  849. -#define CREAD 0000200
  850. -#define PARENB 0000400
  851. -#define PARODD 0001000
  852. -#define HUPCL 0002000
  853. -#define CLOCAL 0004000
  854. -
  855. -#define ISIG 0000001
  856. -#define ICANON 0000002
  857. -#define ECHO 0000010
  858. -#define ECHOE 0000020
  859. -#define ECHOK 0000040
  860. -#define ECHONL 0000100
  861. -#define NOFLSH 0000200
  862. -#define TOSTOP 0000400
  863. -#define IEXTEN 0100000
  864. -
  865. -#define ECHOCTL 0001000
  866. -#define ECHOPRT 0002000
  867. -#define ECHOKE 0004000
  868. -#define FLUSHO 0010000
  869. -#define PENDIN 0040000
  870. -
  871. -#define TCOOFF 0
  872. -#define TCOON 1
  873. -#define TCIOFF 2
  874. -#define TCION 3
  875. -
  876. -#define TCIFLUSH 0
  877. -#define TCOFLUSH 1
  878. -#define TCIOFLUSH 2
  879. -
  880. -#define TCSANOW 0
  881. -#define TCSADRAIN 1
  882. -#define TCSAFLUSH 2
  883. -
  884. -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  885. -#define CBAUDEX 0010000
  886. -#define CRTSCTS 020000000000
  887. -#define EXTPROC 0200000
  888. -#define XTABS 0014000
  889. -#endif
  890. --- a/arch/aarch64/pthread_arch.h
  891. +++ b/arch/aarch64/pthread_arch.h
  892. @@ -8,4 +8,4 @@ static inline struct pthread *__pthread_
  893. #define TLS_ABOVE_TP
  894. #define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) - 16)
  895. -#define CANCEL_REG_IP 33
  896. +#define MC_PC pc
  897. --- a/arch/arm/atomic.h
  898. +++ /dev/null
  899. @@ -1,261 +0,0 @@
  900. -#ifndef _INTERNAL_ATOMIC_H
  901. -#define _INTERNAL_ATOMIC_H
  902. -
  903. -#include <stdint.h>
  904. -
  905. -static inline int a_ctz_l(unsigned long x)
  906. -{
  907. - static const char debruijn32[32] = {
  908. - 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13,
  909. - 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14
  910. - };
  911. - return debruijn32[(x&-x)*0x076be629 >> 27];
  912. -}
  913. -
  914. -static inline int a_ctz_64(uint64_t x)
  915. -{
  916. - uint32_t y = x;
  917. - if (!y) {
  918. - y = x>>32;
  919. - return 32 + a_ctz_l(y);
  920. - }
  921. - return a_ctz_l(y);
  922. -}
  923. -
  924. -#if __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7
  925. -
  926. -static inline void a_barrier()
  927. -{
  928. - __asm__ __volatile__("dmb ish");
  929. -}
  930. -
  931. -static inline int a_cas(volatile int *p, int t, int s)
  932. -{
  933. - int old;
  934. - __asm__ __volatile__(
  935. - " dmb ish\n"
  936. - "1: ldrex %0,%3\n"
  937. - " cmp %0,%1\n"
  938. - " bne 1f\n"
  939. - " strex %0,%2,%3\n"
  940. - " cmp %0, #0\n"
  941. - " bne 1b\n"
  942. - " mov %0, %1\n"
  943. - "1: dmb ish\n"
  944. - : "=&r"(old)
  945. - : "r"(t), "r"(s), "Q"(*p)
  946. - : "memory", "cc" );
  947. - return old;
  948. -}
  949. -
  950. -static inline int a_swap(volatile int *x, int v)
  951. -{
  952. - int old, tmp;
  953. - __asm__ __volatile__(
  954. - " dmb ish\n"
  955. - "1: ldrex %0,%3\n"
  956. - " strex %1,%2,%3\n"
  957. - " cmp %1, #0\n"
  958. - " bne 1b\n"
  959. - " dmb ish\n"
  960. - : "=&r"(old), "=&r"(tmp)
  961. - : "r"(v), "Q"(*x)
  962. - : "memory", "cc" );
  963. - return old;
  964. -}
  965. -
  966. -static inline int a_fetch_add(volatile int *x, int v)
  967. -{
  968. - int old, tmp;
  969. - __asm__ __volatile__(
  970. - " dmb ish\n"
  971. - "1: ldrex %0,%3\n"
  972. - " add %0,%0,%2\n"
  973. - " strex %1,%0,%3\n"
  974. - " cmp %1, #0\n"
  975. - " bne 1b\n"
  976. - " dmb ish\n"
  977. - : "=&r"(old), "=&r"(tmp)
  978. - : "r"(v), "Q"(*x)
  979. - : "memory", "cc" );
  980. - return old-v;
  981. -}
  982. -
  983. -static inline void a_inc(volatile int *x)
  984. -{
  985. - int tmp, tmp2;
  986. - __asm__ __volatile__(
  987. - " dmb ish\n"
  988. - "1: ldrex %0,%2\n"
  989. - " add %0,%0,#1\n"
  990. - " strex %1,%0,%2\n"
  991. - " cmp %1, #0\n"
  992. - " bne 1b\n"
  993. - " dmb ish\n"
  994. - : "=&r"(tmp), "=&r"(tmp2)
  995. - : "Q"(*x)
  996. - : "memory", "cc" );
  997. -}
  998. -
  999. -static inline void a_dec(volatile int *x)
  1000. -{
  1001. - int tmp, tmp2;
  1002. - __asm__ __volatile__(
  1003. - " dmb ish\n"
  1004. - "1: ldrex %0,%2\n"
  1005. - " sub %0,%0,#1\n"
  1006. - " strex %1,%0,%2\n"
  1007. - " cmp %1, #0\n"
  1008. - " bne 1b\n"
  1009. - " dmb ish\n"
  1010. - : "=&r"(tmp), "=&r"(tmp2)
  1011. - : "Q"(*x)
  1012. - : "memory", "cc" );
  1013. -}
  1014. -
  1015. -static inline void a_and(volatile int *x, int v)
  1016. -{
  1017. - int tmp, tmp2;
  1018. - __asm__ __volatile__(
  1019. - " dmb ish\n"
  1020. - "1: ldrex %0,%3\n"
  1021. - " and %0,%0,%2\n"
  1022. - " strex %1,%0,%3\n"
  1023. - " cmp %1, #0\n"
  1024. - " bne 1b\n"
  1025. - " dmb ish\n"
  1026. - : "=&r"(tmp), "=&r"(tmp2)
  1027. - : "r"(v), "Q"(*x)
  1028. - : "memory", "cc" );
  1029. -}
  1030. -
  1031. -static inline void a_or(volatile int *x, int v)
  1032. -{
  1033. - int tmp, tmp2;
  1034. - __asm__ __volatile__(
  1035. - " dmb ish\n"
  1036. - "1: ldrex %0,%3\n"
  1037. - " orr %0,%0,%2\n"
  1038. - " strex %1,%0,%3\n"
  1039. - " cmp %1, #0\n"
  1040. - " bne 1b\n"
  1041. - " dmb ish\n"
  1042. - : "=&r"(tmp), "=&r"(tmp2)
  1043. - : "r"(v), "Q"(*x)
  1044. - : "memory", "cc" );
  1045. -}
  1046. -
  1047. -static inline void a_store(volatile int *p, int x)
  1048. -{
  1049. - __asm__ __volatile__(
  1050. - " dmb ish\n"
  1051. - " str %1,%0\n"
  1052. - " dmb ish\n"
  1053. - : "=m"(*p)
  1054. - : "r"(x)
  1055. - : "memory", "cc" );
  1056. -}
  1057. -
  1058. -#else
  1059. -
  1060. -int __a_cas(int, int, volatile int *) __attribute__((__visibility__("hidden")));
  1061. -#define __k_cas __a_cas
  1062. -
  1063. -static inline void a_barrier()
  1064. -{
  1065. - __asm__ __volatile__("bl __a_barrier"
  1066. - : : : "memory", "cc", "ip", "lr" );
  1067. -}
  1068. -
  1069. -static inline int a_cas(volatile int *p, int t, int s)
  1070. -{
  1071. - int old;
  1072. - for (;;) {
  1073. - if (!__k_cas(t, s, p))
  1074. - return t;
  1075. - if ((old=*p) != t)
  1076. - return old;
  1077. - }
  1078. -}
  1079. -
  1080. -static inline int a_swap(volatile int *x, int v)
  1081. -{
  1082. - int old;
  1083. - do old = *x;
  1084. - while (__k_cas(old, v, x));
  1085. - return old;
  1086. -}
  1087. -
  1088. -static inline int a_fetch_add(volatile int *x, int v)
  1089. -{
  1090. - int old;
  1091. - do old = *x;
  1092. - while (__k_cas(old, old+v, x));
  1093. - return old;
  1094. -}
  1095. -
  1096. -static inline void a_inc(volatile int *x)
  1097. -{
  1098. - a_fetch_add(x, 1);
  1099. -}
  1100. -
  1101. -static inline void a_dec(volatile int *x)
  1102. -{
  1103. - a_fetch_add(x, -1);
  1104. -}
  1105. -
  1106. -static inline void a_store(volatile int *p, int x)
  1107. -{
  1108. - a_barrier();
  1109. - *p = x;
  1110. - a_barrier();
  1111. -}
  1112. -
  1113. -static inline void a_and(volatile int *p, int v)
  1114. -{
  1115. - int old;
  1116. - do old = *p;
  1117. - while (__k_cas(old, old&v, p));
  1118. -}
  1119. -
  1120. -static inline void a_or(volatile int *p, int v)
  1121. -{
  1122. - int old;
  1123. - do old = *p;
  1124. - while (__k_cas(old, old|v, p));
  1125. -}
  1126. -
  1127. -#endif
  1128. -
  1129. -static inline void *a_cas_p(volatile void *p, void *t, void *s)
  1130. -{
  1131. - return (void *)a_cas(p, (int)t, (int)s);
  1132. -}
  1133. -
  1134. -#define a_spin a_barrier
  1135. -
  1136. -static inline void a_crash()
  1137. -{
  1138. - *(volatile char *)0=0;
  1139. -}
  1140. -
  1141. -static inline void a_or_l(volatile void *p, long v)
  1142. -{
  1143. - a_or(p, v);
  1144. -}
  1145. -
  1146. -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
  1147. -{
  1148. - union { uint64_t v; uint32_t r[2]; } u = { v };
  1149. - a_and((int *)p, u.r[0]);
  1150. - a_and((int *)p+1, u.r[1]);
  1151. -}
  1152. -
  1153. -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
  1154. -{
  1155. - union { uint64_t v; uint32_t r[2]; } u = { v };
  1156. - a_or((int *)p, u.r[0]);
  1157. - a_or((int *)p+1, u.r[1]);
  1158. -}
  1159. -
  1160. -#endif
  1161. --- /dev/null
  1162. +++ b/arch/arm/atomic_arch.h
  1163. @@ -0,0 +1,76 @@
  1164. +__attribute__((__visibility__("hidden")))
  1165. +extern const void *__arm_atomics[3]; /* gettp, cas, barrier */
  1166. +
  1167. +#if ((__ARM_ARCH_6__ || __ARM_ARCH_6K__ || __ARM_ARCH_6ZK__) && !__thumb__) \
  1168. + || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7
  1169. +
  1170. +#define a_ll a_ll
  1171. +static inline int a_ll(volatile int *p)
  1172. +{
  1173. + int v;
  1174. + __asm__ __volatile__ ("ldrex %0, %1" : "=r"(v) : "Q"(*p));
  1175. + return v;
  1176. +}
  1177. +
  1178. +#define a_sc a_sc
  1179. +static inline int a_sc(volatile int *p, int v)
  1180. +{
  1181. + int r;
  1182. + __asm__ __volatile__ ("strex %0,%1,%2" : "=&r"(r) : "r"(v), "Q"(*p) : "memory");
  1183. + return !r;
  1184. +}
  1185. +
  1186. +#if __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7
  1187. +
  1188. +#define a_barrier a_barrier
  1189. +static inline void a_barrier()
  1190. +{
  1191. + __asm__ __volatile__ ("dmb ish" : : : "memory");
  1192. +}
  1193. +
  1194. +#endif
  1195. +
  1196. +#define a_pre_llsc a_barrier
  1197. +#define a_post_llsc a_barrier
  1198. +
  1199. +#else
  1200. +
  1201. +#define a_cas a_cas
  1202. +static inline int a_cas(volatile int *p, int t, int s)
  1203. +{
  1204. + for (;;) {
  1205. + register int r0 __asm__("r0") = t;
  1206. + register int r1 __asm__("r1") = s;
  1207. + register volatile int *r2 __asm__("r2") = p;
  1208. + int old;
  1209. + __asm__ __volatile__ (
  1210. + "bl __a_cas"
  1211. + : "+r"(r0) : "r"(r1), "r"(r2)
  1212. + : "memory", "r3", "lr", "ip", "cc" );
  1213. + if (!r0) return t;
  1214. + if ((old=*p)!=t) return old;
  1215. + }
  1216. +}
  1217. +
  1218. +#endif
  1219. +
  1220. +#ifndef a_barrier
  1221. +#define a_barrier a_barrier
  1222. +static inline void a_barrier()
  1223. +{
  1224. + __asm__ __volatile__("bl __a_barrier"
  1225. + : : : "memory", "cc", "ip", "lr" );
  1226. +}
  1227. +#endif
  1228. +
  1229. +#define a_crash a_crash
  1230. +static inline void a_crash()
  1231. +{
  1232. + __asm__ __volatile__(
  1233. +#ifndef __thumb__
  1234. + ".word 0xe7f000f0"
  1235. +#else
  1236. + ".short 0xdeff"
  1237. +#endif
  1238. + : : : "memory");
  1239. +}
  1240. --- a/arch/arm/bits/errno.h
  1241. +++ /dev/null
  1242. @@ -1,134 +0,0 @@
  1243. -#define EPERM 1
  1244. -#define ENOENT 2
  1245. -#define ESRCH 3
  1246. -#define EINTR 4
  1247. -#define EIO 5
  1248. -#define ENXIO 6
  1249. -#define E2BIG 7
  1250. -#define ENOEXEC 8
  1251. -#define EBADF 9
  1252. -#define ECHILD 10
  1253. -#define EAGAIN 11
  1254. -#define ENOMEM 12
  1255. -#define EACCES 13
  1256. -#define EFAULT 14
  1257. -#define ENOTBLK 15
  1258. -#define EBUSY 16
  1259. -#define EEXIST 17
  1260. -#define EXDEV 18
  1261. -#define ENODEV 19
  1262. -#define ENOTDIR 20
  1263. -#define EISDIR 21
  1264. -#define EINVAL 22
  1265. -#define ENFILE 23
  1266. -#define EMFILE 24
  1267. -#define ENOTTY 25
  1268. -#define ETXTBSY 26
  1269. -#define EFBIG 27
  1270. -#define ENOSPC 28
  1271. -#define ESPIPE 29
  1272. -#define EROFS 30
  1273. -#define EMLINK 31
  1274. -#define EPIPE 32
  1275. -#define EDOM 33
  1276. -#define ERANGE 34
  1277. -#define EDEADLK 35
  1278. -#define ENAMETOOLONG 36
  1279. -#define ENOLCK 37
  1280. -#define ENOSYS 38
  1281. -#define ENOTEMPTY 39
  1282. -#define ELOOP 40
  1283. -#define EWOULDBLOCK EAGAIN
  1284. -#define ENOMSG 42
  1285. -#define EIDRM 43
  1286. -#define ECHRNG 44
  1287. -#define EL2NSYNC 45
  1288. -#define EL3HLT 46
  1289. -#define EL3RST 47
  1290. -#define ELNRNG 48
  1291. -#define EUNATCH 49
  1292. -#define ENOCSI 50
  1293. -#define EL2HLT 51
  1294. -#define EBADE 52
  1295. -#define EBADR 53
  1296. -#define EXFULL 54
  1297. -#define ENOANO 55
  1298. -#define EBADRQC 56
  1299. -#define EBADSLT 57
  1300. -#define EDEADLOCK EDEADLK
  1301. -#define EBFONT 59
  1302. -#define ENOSTR 60
  1303. -#define ENODATA 61
  1304. -#define ETIME 62
  1305. -#define ENOSR 63
  1306. -#define ENONET 64
  1307. -#define ENOPKG 65
  1308. -#define EREMOTE 66
  1309. -#define ENOLINK 67
  1310. -#define EADV 68
  1311. -#define ESRMNT 69
  1312. -#define ECOMM 70
  1313. -#define EPROTO 71
  1314. -#define EMULTIHOP 72
  1315. -#define EDOTDOT 73
  1316. -#define EBADMSG 74
  1317. -#define EOVERFLOW 75
  1318. -#define ENOTUNIQ 76
  1319. -#define EBADFD 77
  1320. -#define EREMCHG 78
  1321. -#define ELIBACC 79
  1322. -#define ELIBBAD 80
  1323. -#define ELIBSCN 81
  1324. -#define ELIBMAX 82
  1325. -#define ELIBEXEC 83
  1326. -#define EILSEQ 84
  1327. -#define ERESTART 85
  1328. -#define ESTRPIPE 86
  1329. -#define EUSERS 87
  1330. -#define ENOTSOCK 88
  1331. -#define EDESTADDRREQ 89
  1332. -#define EMSGSIZE 90
  1333. -#define EPROTOTYPE 91
  1334. -#define ENOPROTOOPT 92
  1335. -#define EPROTONOSUPPORT 93
  1336. -#define ESOCKTNOSUPPORT 94
  1337. -#define EOPNOTSUPP 95
  1338. -#define ENOTSUP EOPNOTSUPP
  1339. -#define EPFNOSUPPORT 96
  1340. -#define EAFNOSUPPORT 97
  1341. -#define EADDRINUSE 98
  1342. -#define EADDRNOTAVAIL 99
  1343. -#define ENETDOWN 100
  1344. -#define ENETUNREACH 101
  1345. -#define ENETRESET 102
  1346. -#define ECONNABORTED 103
  1347. -#define ECONNRESET 104
  1348. -#define ENOBUFS 105
  1349. -#define EISCONN 106
  1350. -#define ENOTCONN 107
  1351. -#define ESHUTDOWN 108
  1352. -#define ETOOMANYREFS 109
  1353. -#define ETIMEDOUT 110
  1354. -#define ECONNREFUSED 111
  1355. -#define EHOSTDOWN 112
  1356. -#define EHOSTUNREACH 113
  1357. -#define EALREADY 114
  1358. -#define EINPROGRESS 115
  1359. -#define ESTALE 116
  1360. -#define EUCLEAN 117
  1361. -#define ENOTNAM 118
  1362. -#define ENAVAIL 119
  1363. -#define EISNAM 120
  1364. -#define EREMOTEIO 121
  1365. -#define EDQUOT 122
  1366. -#define ENOMEDIUM 123
  1367. -#define EMEDIUMTYPE 124
  1368. -#define ECANCELED 125
  1369. -#define ENOKEY 126
  1370. -#define EKEYEXPIRED 127
  1371. -#define EKEYREVOKED 128
  1372. -#define EKEYREJECTED 129
  1373. -#define EOWNERDEAD 130
  1374. -#define ENOTRECOVERABLE 131
  1375. -#define ERFKILL 132
  1376. -#define EHWPOISON 133
  1377. --- a/arch/arm/bits/ioctl.h
  1378. +++ /dev/null
  1379. @@ -1,197 +0,0 @@
  1380. -#define _IOC(a,b,c,d) ( ((a)<<30) | ((b)<<8) | (c) | ((d)<<16) )
  1381. -#define _IOC_NONE 0U
  1382. -#define _IOC_WRITE 1U
  1383. -#define _IOC_READ 2U
  1384. -
  1385. -#define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0)
  1386. -#define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),sizeof(c))
  1387. -#define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),sizeof(c))
  1388. -#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE,(a),(b),sizeof(c))
  1389. -
  1390. -#define TCGETS 0x5401
  1391. -#define TCSETS 0x5402
  1392. -#define TCSETSW 0x5403
  1393. -#define TCSETSF 0x5404
  1394. -#define TCGETA 0x5405
  1395. -#define TCSETA 0x5406
  1396. -#define TCSETAW 0x5407
  1397. -#define TCSETAF 0x5408
  1398. -#define TCSBRK 0x5409
  1399. -#define TCXONC 0x540A
  1400. -#define TCFLSH 0x540B
  1401. -#define TIOCEXCL 0x540C
  1402. -#define TIOCNXCL 0x540D
  1403. -#define TIOCSCTTY 0x540E
  1404. -#define TIOCGPGRP 0x540F
  1405. -#define TIOCSPGRP 0x5410
  1406. -#define TIOCOUTQ 0x5411
  1407. -#define TIOCSTI 0x5412
  1408. -#define TIOCGWINSZ 0x5413
  1409. -#define TIOCSWINSZ 0x5414
  1410. -#define TIOCMGET 0x5415
  1411. -#define TIOCMBIS 0x5416
  1412. -#define TIOCMBIC 0x5417
  1413. -#define TIOCMSET 0x5418
  1414. -#define TIOCGSOFTCAR 0x5419
  1415. -#define TIOCSSOFTCAR 0x541A
  1416. -#define FIONREAD 0x541B
  1417. -#define TIOCINQ FIONREAD
  1418. -#define TIOCLINUX 0x541C
  1419. -#define TIOCCONS 0x541D
  1420. -#define TIOCGSERIAL 0x541E
  1421. -#define TIOCSSERIAL 0x541F
  1422. -#define TIOCPKT 0x5420
  1423. -#define FIONBIO 0x5421
  1424. -#define TIOCNOTTY 0x5422
  1425. -#define TIOCSETD 0x5423
  1426. -#define TIOCGETD 0x5424
  1427. -#define TCSBRKP 0x5425
  1428. -#define TIOCTTYGSTRUCT 0x5426
  1429. -#define TIOCSBRK 0x5427
  1430. -#define TIOCCBRK 0x5428
  1431. -#define TIOCGSID 0x5429
  1432. -#define TIOCGPTN 0x80045430
  1433. -#define TIOCSPTLCK 0x40045431
  1434. -#define TCGETX 0x5432
  1435. -#define TCSETX 0x5433
  1436. -#define TCSETXF 0x5434
  1437. -#define TCSETXW 0x5435
  1438. -
  1439. -#define FIONCLEX 0x5450
  1440. -#define FIOCLEX 0x5451
  1441. -#define FIOASYNC 0x5452
  1442. -#define TIOCSERCONFIG 0x5453
  1443. -#define TIOCSERGWILD 0x5454
  1444. -#define TIOCSERSWILD 0x5455
  1445. -#define TIOCGLCKTRMIOS 0x5456
  1446. -#define TIOCSLCKTRMIOS 0x5457
  1447. -#define TIOCSERGSTRUCT 0x5458
  1448. -#define TIOCSERGETLSR 0x5459
  1449. -#define TIOCSERGETMULTI 0x545A
  1450. -#define TIOCSERSETMULTI 0x545B
  1451. -
  1452. -#define TIOCMIWAIT 0x545C
  1453. -#define TIOCGICOUNT 0x545D
  1454. -#define TIOCGHAYESESP 0x545E
  1455. -#define TIOCSHAYESESP 0x545F
  1456. -#define FIOQSIZE 0x5460
  1457. -
  1458. -#define TIOCPKT_DATA 0
  1459. -#define TIOCPKT_FLUSHREAD 1
  1460. -#define TIOCPKT_FLUSHWRITE 2
  1461. -#define TIOCPKT_STOP 4
  1462. -#define TIOCPKT_START 8
  1463. -#define TIOCPKT_NOSTOP 16
  1464. -#define TIOCPKT_DOSTOP 32
  1465. -#define TIOCPKT_IOCTL 64
  1466. -
  1467. -#define TIOCSER_TEMT 0x01
  1468. -
  1469. -struct winsize {
  1470. - unsigned short ws_row;
  1471. - unsigned short ws_col;
  1472. - unsigned short ws_xpixel;
  1473. - unsigned short ws_ypixel;
  1474. -};
  1475. -
  1476. -#define TIOCM_LE 0x001
  1477. -#define TIOCM_DTR 0x002
  1478. -#define TIOCM_RTS 0x004
  1479. -#define TIOCM_ST 0x008
  1480. -#define TIOCM_SR 0x010
  1481. -#define TIOCM_CTS 0x020
  1482. -#define TIOCM_CAR 0x040
  1483. -#define TIOCM_RNG 0x080
  1484. -#define TIOCM_DSR 0x100
  1485. -#define TIOCM_CD TIOCM_CAR
  1486. -#define TIOCM_RI TIOCM_RNG
  1487. -#define TIOCM_OUT1 0x2000
  1488. -#define TIOCM_OUT2 0x4000
  1489. -#define TIOCM_LOOP 0x8000
  1490. -#define TIOCM_MODEM_BITS TIOCM_OUT2
  1491. -
  1492. -#define N_TTY 0
  1493. -#define N_SLIP 1
  1494. -#define N_MOUSE 2
  1495. -#define N_PPP 3
  1496. -#define N_STRIP 4
  1497. -#define N_AX25 5
  1498. -#define N_X25 6
  1499. -#define N_6PACK 7
  1500. -#define N_MASC 8
  1501. -#define N_R3964 9
  1502. -#define N_PROFIBUS_FDL 10
  1503. -#define N_IRDA 11
  1504. -#define N_SMSBLOCK 12
  1505. -#define N_HDLC 13
  1506. -#define N_SYNC_PPP 14
  1507. -#define N_HCI 15
  1508. -
  1509. -#define FIOSETOWN 0x8901
  1510. -#define SIOCSPGRP 0x8902
  1511. -#define FIOGETOWN 0x8903
  1512. -#define SIOCGPGRP 0x8904
  1513. -#define SIOCATMARK 0x8905
  1514. -#define SIOCGSTAMP 0x8906
  1515. -
  1516. -#define SIOCADDRT 0x890B
  1517. -#define SIOCDELRT 0x890C
  1518. -#define SIOCRTMSG 0x890D
  1519. -
  1520. -#define SIOCGIFNAME 0x8910
  1521. -#define SIOCSIFLINK 0x8911
  1522. -#define SIOCGIFCONF 0x8912
  1523. -#define SIOCGIFFLAGS 0x8913
  1524. -#define SIOCSIFFLAGS 0x8914
  1525. -#define SIOCGIFADDR 0x8915
  1526. -#define SIOCSIFADDR 0x8916
  1527. -#define SIOCGIFDSTADDR 0x8917
  1528. -#define SIOCSIFDSTADDR 0x8918
  1529. -#define SIOCGIFBRDADDR 0x8919
  1530. -#define SIOCSIFBRDADDR 0x891a
  1531. -#define SIOCGIFNETMASK 0x891b
  1532. -#define SIOCSIFNETMASK 0x891c
  1533. -#define SIOCGIFMETRIC 0x891d
  1534. -#define SIOCSIFMETRIC 0x891e
  1535. -#define SIOCGIFMEM 0x891f
  1536. -#define SIOCSIFMEM 0x8920
  1537. -#define SIOCGIFMTU 0x8921
  1538. -#define SIOCSIFMTU 0x8922
  1539. -#define SIOCSIFHWADDR 0x8924
  1540. -#define SIOCGIFENCAP 0x8925
  1541. -#define SIOCSIFENCAP 0x8926
  1542. -#define SIOCGIFHWADDR 0x8927
  1543. -#define SIOCGIFSLAVE 0x8929
  1544. -#define SIOCSIFSLAVE 0x8930
  1545. -#define SIOCADDMULTI 0x8931
  1546. -#define SIOCDELMULTI 0x8932
  1547. -#define SIOCGIFINDEX 0x8933
  1548. -#define SIOGIFINDEX SIOCGIFINDEX
  1549. -#define SIOCSIFPFLAGS 0x8934
  1550. -#define SIOCGIFPFLAGS 0x8935
  1551. -#define SIOCDIFADDR 0x8936
  1552. -#define SIOCSIFHWBROADCAST 0x8937
  1553. -#define SIOCGIFCOUNT 0x8938
  1554. -
  1555. -#define SIOCGIFBR 0x8940
  1556. -#define SIOCSIFBR 0x8941
  1557. -
  1558. -#define SIOCGIFTXQLEN 0x8942
  1559. -#define SIOCSIFTXQLEN 0x8943
  1560. -
  1561. -#define SIOCDARP 0x8953
  1562. -#define SIOCGARP 0x8954
  1563. -#define SIOCSARP 0x8955
  1564. -
  1565. -#define SIOCDRARP 0x8960
  1566. -#define SIOCGRARP 0x8961
  1567. -#define SIOCSRARP 0x8962
  1568. -
  1569. -#define SIOCGIFMAP 0x8970
  1570. -#define SIOCSIFMAP 0x8971
  1571. -
  1572. -#define SIOCADDDLCI 0x8980
  1573. -#define SIOCDELDLCI 0x8981
  1574. -
  1575. -#define SIOCDEVPRIVATE 0x89F0
  1576. -#define SIOCPROTOPRIVATE 0x89E0
  1577. --- a/arch/arm/bits/ipc.h
  1578. +++ /dev/null
  1579. @@ -1,14 +0,0 @@
  1580. -struct ipc_perm
  1581. -{
  1582. - key_t __ipc_perm_key;
  1583. - uid_t uid;
  1584. - gid_t gid;
  1585. - uid_t cuid;
  1586. - gid_t cgid;
  1587. - mode_t mode;
  1588. - int __ipc_perm_seq;
  1589. - long __pad1;
  1590. - long __pad2;
  1591. -};
  1592. -
  1593. -#define IPC_64 0x100
  1594. --- a/arch/arm/bits/mman.h
  1595. +++ b/arch/arm/bits/mman.h
  1596. @@ -37,6 +37,7 @@
  1597. #define MCL_CURRENT 1
  1598. #define MCL_FUTURE 2
  1599. +#define MCL_ONFAULT 4
  1600. #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  1601. #define MADV_NORMAL 0
  1602. --- a/arch/arm/bits/msg.h
  1603. +++ /dev/null
  1604. @@ -1,16 +0,0 @@
  1605. -struct msqid_ds
  1606. -{
  1607. - struct ipc_perm msg_perm;
  1608. - time_t msg_stime;
  1609. - int __unused1;
  1610. - time_t msg_rtime;
  1611. - int __unused2;
  1612. - time_t msg_ctime;
  1613. - int __unused3;
  1614. - unsigned long msg_cbytes;
  1615. - msgqnum_t msg_qnum;
  1616. - msglen_t msg_qbytes;
  1617. - pid_t msg_lspid;
  1618. - pid_t msg_lrpid;
  1619. - unsigned long __unused[2];
  1620. -};
  1621. --- a/arch/arm/bits/sem.h
  1622. +++ /dev/null
  1623. @@ -1,16 +0,0 @@
  1624. -struct semid_ds {
  1625. - struct ipc_perm sem_perm;
  1626. - time_t sem_otime;
  1627. - time_t __unused1;
  1628. - time_t sem_ctime;
  1629. - time_t __unused2;
  1630. -#if __BYTE_ORDER == __LITTLE_ENDIAN
  1631. - unsigned short sem_nsems;
  1632. - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
  1633. -#else
  1634. - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
  1635. - unsigned short sem_nsems;
  1636. -#endif
  1637. - time_t __unused3;
  1638. - time_t __unused4;
  1639. -};
  1640. --- a/arch/arm/bits/shm.h
  1641. +++ /dev/null
  1642. @@ -1,29 +0,0 @@
  1643. -#define SHMLBA 4096
  1644. -
  1645. -struct shmid_ds
  1646. -{
  1647. - struct ipc_perm shm_perm;
  1648. - size_t shm_segsz;
  1649. - time_t shm_atime;
  1650. - int __unused1;
  1651. - time_t shm_dtime;
  1652. - int __unused2;
  1653. - time_t shm_ctime;
  1654. - int __unused3;
  1655. - pid_t shm_cpid;
  1656. - pid_t shm_lpid;
  1657. - unsigned long shm_nattch;
  1658. - unsigned long __pad1;
  1659. - unsigned long __pad2;
  1660. -};
  1661. -
  1662. -struct shminfo {
  1663. - unsigned long shmmax, shmmin, shmmni, shmseg, shmall, __unused[4];
  1664. -};
  1665. -
  1666. -struct shm_info {
  1667. - int __used_ids;
  1668. - unsigned long shm_tot, shm_rss, shm_swp;
  1669. - unsigned long __swap_attempts, __swap_successes;
  1670. -};
  1671. -
  1672. --- a/arch/arm/bits/socket.h
  1673. +++ /dev/null
  1674. @@ -1,17 +0,0 @@
  1675. -struct msghdr
  1676. -{
  1677. - void *msg_name;
  1678. - socklen_t msg_namelen;
  1679. - struct iovec *msg_iov;
  1680. - int msg_iovlen;
  1681. - void *msg_control;
  1682. - socklen_t msg_controllen;
  1683. - int msg_flags;
  1684. -};
  1685. -
  1686. -struct cmsghdr
  1687. -{
  1688. - socklen_t cmsg_len;
  1689. - int cmsg_level;
  1690. - int cmsg_type;
  1691. -};
  1692. --- a/arch/arm/bits/statfs.h
  1693. +++ /dev/null
  1694. @@ -1,7 +0,0 @@
  1695. -struct statfs {
  1696. - unsigned long f_type, f_bsize;
  1697. - fsblkcnt_t f_blocks, f_bfree, f_bavail;
  1698. - fsfilcnt_t f_files, f_ffree;
  1699. - fsid_t f_fsid;
  1700. - unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
  1701. -};
  1702. --- a/arch/arm/bits/stdarg.h
  1703. +++ /dev/null
  1704. @@ -1,4 +0,0 @@
  1705. -#define va_start(v,l) __builtin_va_start(v,l)
  1706. -#define va_end(v) __builtin_va_end(v)
  1707. -#define va_arg(v,l) __builtin_va_arg(v,l)
  1708. -#define va_copy(d,s) __builtin_va_copy(d,s)
  1709. --- a/arch/arm/bits/syscall.h
  1710. +++ b/arch/arm/bits/syscall.h
  1711. @@ -341,6 +341,9 @@
  1712. #define __NR_memfd_create 385
  1713. #define __NR_bpf 386
  1714. #define __NR_execveat 387
  1715. +#define __NR_userfaultfd 388
  1716. +#define __NR_membarrier 389
  1717. +#define __NR_mlock2 390
  1718. #define __ARM_NR_breakpoint 0x0f0001
  1719. #define __ARM_NR_cacheflush 0x0f0002
  1720. @@ -693,3 +696,6 @@
  1721. #define SYS_memfd_create 385
  1722. #define SYS_bpf 386
  1723. #define SYS_execveat 387
  1724. +#define SYS_userfaultfd 388
  1725. +#define SYS_membarrier 389
  1726. +#define SYS_mlock2 390
  1727. --- a/arch/arm/bits/termios.h
  1728. +++ /dev/null
  1729. @@ -1,160 +0,0 @@
  1730. -struct termios
  1731. -{
  1732. - tcflag_t c_iflag;
  1733. - tcflag_t c_oflag;
  1734. - tcflag_t c_cflag;
  1735. - tcflag_t c_lflag;
  1736. - cc_t c_line;
  1737. - cc_t c_cc[NCCS];
  1738. - speed_t __c_ispeed;
  1739. - speed_t __c_ospeed;
  1740. -};
  1741. -
  1742. -#define VINTR 0
  1743. -#define VQUIT 1
  1744. -#define VERASE 2
  1745. -#define VKILL 3
  1746. -#define VEOF 4
  1747. -#define VTIME 5
  1748. -#define VMIN 6
  1749. -#define VSWTC 7
  1750. -#define VSTART 8
  1751. -#define VSTOP 9
  1752. -#define VSUSP 10
  1753. -#define VEOL 11
  1754. -#define VREPRINT 12
  1755. -#define VDISCARD 13
  1756. -#define VWERASE 14
  1757. -#define VLNEXT 15
  1758. -#define VEOL2 16
  1759. -
  1760. -#define IGNBRK 0000001
  1761. -#define BRKINT 0000002
  1762. -#define IGNPAR 0000004
  1763. -#define PARMRK 0000010
  1764. -#define INPCK 0000020
  1765. -#define ISTRIP 0000040
  1766. -#define INLCR 0000100
  1767. -#define IGNCR 0000200
  1768. -#define ICRNL 0000400
  1769. -#define IUCLC 0001000
  1770. -#define IXON 0002000
  1771. -#define IXANY 0004000
  1772. -#define IXOFF 0010000
  1773. -#define IMAXBEL 0020000
  1774. -#define IUTF8 0040000
  1775. -
  1776. -#define OPOST 0000001
  1777. -#define OLCUC 0000002
  1778. -#define ONLCR 0000004
  1779. -#define OCRNL 0000010
  1780. -#define ONOCR 0000020
  1781. -#define ONLRET 0000040
  1782. -#define OFILL 0000100
  1783. -#define OFDEL 0000200
  1784. -#define NLDLY 0000400
  1785. -#define NL0 0000000
  1786. -#define NL1 0000400
  1787. -#define CRDLY 0003000
  1788. -#define CR0 0000000
  1789. -#define CR1 0001000
  1790. -#define CR2 0002000
  1791. -#define CR3 0003000
  1792. -#define TABDLY 0014000
  1793. -#define TAB0 0000000
  1794. -#define TAB1 0004000
  1795. -#define TAB2 0010000
  1796. -#define TAB3 0014000
  1797. -#define BSDLY 0020000
  1798. -#define BS0 0000000
  1799. -#define BS1 0020000
  1800. -#define FFDLY 0100000
  1801. -#define FF0 0000000
  1802. -#define FF1 0100000
  1803. -
  1804. -#define VTDLY 0040000
  1805. -#define VT0 0000000
  1806. -#define VT1 0040000
  1807. -
  1808. -#define B0 0000000
  1809. -#define B50 0000001
  1810. -#define B75 0000002
  1811. -#define B110 0000003
  1812. -#define B134 0000004
  1813. -#define B150 0000005
  1814. -#define B200 0000006
  1815. -#define B300 0000007
  1816. -#define B600 0000010
  1817. -#define B1200 0000011
  1818. -#define B1800 0000012
  1819. -#define B2400 0000013
  1820. -#define B4800 0000014
  1821. -#define B9600 0000015
  1822. -#define B19200 0000016
  1823. -#define B38400 0000017
  1824. -
  1825. -#define B57600 0010001
  1826. -#define B115200 0010002
  1827. -#define B230400 0010003
  1828. -#define B460800 0010004
  1829. -#define B500000 0010005
  1830. -#define B576000 0010006
  1831. -#define B921600 0010007
  1832. -#define B1000000 0010010
  1833. -#define B1152000 0010011
  1834. -#define B1500000 0010012
  1835. -#define B2000000 0010013
  1836. -#define B2500000 0010014
  1837. -#define B3000000 0010015
  1838. -#define B3500000 0010016
  1839. -#define B4000000 0010017
  1840. -
  1841. -#define CBAUD 0010017
  1842. -
  1843. -#define CSIZE 0000060
  1844. -#define CS5 0000000
  1845. -#define CS6 0000020
  1846. -#define CS7 0000040
  1847. -#define CS8 0000060
  1848. -#define CSTOPB 0000100
  1849. -#define CREAD 0000200
  1850. -#define PARENB 0000400
  1851. -#define PARODD 0001000
  1852. -#define HUPCL 0002000
  1853. -#define CLOCAL 0004000
  1854. -
  1855. -#define ISIG 0000001
  1856. -#define ICANON 0000002
  1857. -#define ECHO 0000010
  1858. -#define ECHOE 0000020
  1859. -#define ECHOK 0000040
  1860. -#define ECHONL 0000100
  1861. -#define NOFLSH 0000200
  1862. -#define TOSTOP 0000400
  1863. -#define IEXTEN 0100000
  1864. -
  1865. -#define ECHOCTL 0001000
  1866. -#define ECHOPRT 0002000
  1867. -#define ECHOKE 0004000
  1868. -#define FLUSHO 0010000
  1869. -#define PENDIN 0040000
  1870. -
  1871. -#define TCOOFF 0
  1872. -#define TCOON 1
  1873. -#define TCIOFF 2
  1874. -#define TCION 3
  1875. -
  1876. -#define TCIFLUSH 0
  1877. -#define TCOFLUSH 1
  1878. -#define TCIOFLUSH 2
  1879. -
  1880. -#define TCSANOW 0
  1881. -#define TCSADRAIN 1
  1882. -#define TCSAFLUSH 2
  1883. -
  1884. -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  1885. -#define CBAUDEX 0010000
  1886. -#define CRTSCTS 020000000000
  1887. -#define EXTPROC 0200000
  1888. -#define XTABS 0014000
  1889. -#endif
  1890. --- a/arch/arm/pthread_arch.h
  1891. +++ b/arch/arm/pthread_arch.h
  1892. @@ -27,4 +27,4 @@ static inline pthread_t __pthread_self()
  1893. #define TLS_ABOVE_TP
  1894. #define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) - 8)
  1895. -#define CANCEL_REG_IP 18
  1896. +#define MC_PC arm_pc
  1897. --- a/arch/arm/reloc.h
  1898. +++ b/arch/arm/reloc.h
  1899. @@ -6,10 +6,10 @@
  1900. #define ENDIAN_SUFFIX ""
  1901. #endif
  1902. -#if __SOFTFP__
  1903. -#define FP_SUFFIX ""
  1904. -#else
  1905. +#if __ARM_PCS_VFP
  1906. #define FP_SUFFIX "hf"
  1907. +#else
  1908. +#define FP_SUFFIX ""
  1909. #endif
  1910. #define LDSO_ARCH "arm" ENDIAN_SUFFIX FP_SUFFIX
  1911. @@ -28,10 +28,5 @@
  1912. #define REL_TPOFF R_ARM_TLS_TPOFF32
  1913. //#define REL_TLSDESC R_ARM_TLS_DESC
  1914. -#ifdef __thumb__
  1915. #define CRTJMP(pc,sp) __asm__ __volatile__( \
  1916. "mov sp,%1 ; bx %0" : : "r"(pc), "r"(sp) : "memory" )
  1917. -#else
  1918. -#define CRTJMP(pc,sp) __asm__ __volatile__( \
  1919. - "mov sp,%1 ; tst %0,#1 ; moveq pc,%0 ; bx %0" : : "r"(pc), "r"(sp) : "memory" )
  1920. -#endif
  1921. --- a/arch/arm/src/__aeabi_atexit.c
  1922. +++ /dev/null
  1923. @@ -1,6 +0,0 @@
  1924. -int __cxa_atexit(void (*func)(void *), void *arg, void *dso);
  1925. -
  1926. -int __aeabi_atexit (void *obj, void (*func) (void *), void *d)
  1927. -{
  1928. - return __cxa_atexit (func, obj, d);
  1929. -}
  1930. --- a/arch/arm/src/__aeabi_memclr.c
  1931. +++ /dev/null
  1932. @@ -1,9 +0,0 @@
  1933. -#include <string.h>
  1934. -#include "libc.h"
  1935. -
  1936. -void __aeabi_memclr(void *dest, size_t n)
  1937. -{
  1938. - memset(dest, 0, n);
  1939. -}
  1940. -weak_alias(__aeabi_memclr, __aeabi_memclr4);
  1941. -weak_alias(__aeabi_memclr, __aeabi_memclr8);
  1942. --- a/arch/arm/src/__aeabi_memcpy.c
  1943. +++ /dev/null
  1944. @@ -1,9 +0,0 @@
  1945. -#include <string.h>
  1946. -#include "libc.h"
  1947. -
  1948. -void __aeabi_memcpy(void *restrict dest, const void *restrict src, size_t n)
  1949. -{
  1950. - memcpy(dest, src, n);
  1951. -}
  1952. -weak_alias(__aeabi_memcpy, __aeabi_memcpy4);
  1953. -weak_alias(__aeabi_memcpy, __aeabi_memcpy8);
  1954. --- a/arch/arm/src/__aeabi_memmove.c
  1955. +++ /dev/null
  1956. @@ -1,9 +0,0 @@
  1957. -#include <string.h>
  1958. -#include "libc.h"
  1959. -
  1960. -void __aeabi_memmove(void *dest, const void *src, size_t n)
  1961. -{
  1962. - memmove(dest, src, n);
  1963. -}
  1964. -weak_alias(__aeabi_memmove, __aeabi_memmove4);
  1965. -weak_alias(__aeabi_memmove, __aeabi_memmove8);
  1966. --- a/arch/arm/src/__aeabi_memset.c
  1967. +++ /dev/null
  1968. @@ -1,9 +0,0 @@
  1969. -#include <string.h>
  1970. -#include "libc.h"
  1971. -
  1972. -void __aeabi_memset(void *dest, size_t n, int c)
  1973. -{
  1974. - memset(dest, c, n);
  1975. -}
  1976. -weak_alias(__aeabi_memset, __aeabi_memset4);
  1977. -weak_alias(__aeabi_memset, __aeabi_memset8);
  1978. --- a/arch/arm/src/__set_thread_area.c
  1979. +++ /dev/null
  1980. @@ -1,49 +0,0 @@
  1981. -#include <stdint.h>
  1982. -#include <elf.h>
  1983. -#include "pthread_impl.h"
  1984. -#include "libc.h"
  1985. -
  1986. -#define HWCAP_TLS (1 << 15)
  1987. -
  1988. -extern const unsigned char __attribute__((__visibility__("hidden")))
  1989. - __a_barrier_dummy[], __a_barrier_oldkuser[],
  1990. - __a_barrier_v6[], __a_barrier_v7[],
  1991. - __a_cas_dummy[], __a_cas_v6[], __a_cas_v7[],
  1992. - __a_gettp_dummy[];
  1993. -
  1994. -#define __a_barrier_kuser 0xffff0fa0
  1995. -#define __a_cas_kuser 0xffff0fc0
  1996. -#define __a_gettp_kuser 0xffff0fe0
  1997. -
  1998. -extern uintptr_t __attribute__((__visibility__("hidden")))
  1999. - __a_barrier_ptr, __a_cas_ptr, __a_gettp_ptr;
  2000. -
  2001. -#define SET(op,ver) (__a_##op##_ptr = \
  2002. - (uintptr_t)__a_##op##_##ver - (uintptr_t)__a_##op##_dummy)
  2003. -
  2004. -int __set_thread_area(void *p)
  2005. -{
  2006. -#if !__ARM_ARCH_7A__ && !__ARM_ARCH_7R__ && __ARM_ARCH < 7
  2007. - if (__hwcap & HWCAP_TLS) {
  2008. - size_t *aux;
  2009. - SET(cas, v7);
  2010. - SET(barrier, v7);
  2011. - for (aux=libc.auxv; *aux; aux+=2) {
  2012. - if (*aux != AT_PLATFORM) continue;
  2013. - const char *s = (void *)aux[1];
  2014. - if (s[0]!='v' || s[1]!='6' || s[2]-'0'<10u) break;
  2015. - SET(cas, v6);
  2016. - SET(barrier, v6);
  2017. - break;
  2018. - }
  2019. - } else {
  2020. - int ver = *(int *)0xffff0ffc;
  2021. - SET(gettp, kuser);
  2022. - SET(cas, kuser);
  2023. - SET(barrier, kuser);
  2024. - if (ver < 2) a_crash();
  2025. - if (ver < 3) SET(barrier, oldkuser);
  2026. - }
  2027. -#endif
  2028. - return __syscall(0xf0005, p);
  2029. -}
  2030. --- a/arch/arm/src/arm/atomics.s
  2031. +++ /dev/null
  2032. @@ -1,116 +0,0 @@
  2033. -.text
  2034. -
  2035. -.global __a_barrier
  2036. -.hidden __a_barrier
  2037. -.type __a_barrier,%function
  2038. -__a_barrier:
  2039. - ldr ip,1f
  2040. - ldr ip,[pc,ip]
  2041. - add pc,pc,ip
  2042. -1: .word __a_barrier_ptr-1b
  2043. -.global __a_barrier_dummy
  2044. -.hidden __a_barrier_dummy
  2045. -__a_barrier_dummy:
  2046. - tst lr,#1
  2047. - moveq pc,lr
  2048. - bx lr
  2049. -.global __a_barrier_oldkuser
  2050. -.hidden __a_barrier_oldkuser
  2051. -__a_barrier_oldkuser:
  2052. - push {r0,r1,r2,r3,ip,lr}
  2053. - mov r1,r0
  2054. - mov r2,sp
  2055. - ldr ip,=0xffff0fc0
  2056. - mov lr,pc
  2057. - mov pc,ip
  2058. - pop {r0,r1,r2,r3,ip,lr}
  2059. - tst lr,#1
  2060. - moveq pc,lr
  2061. - bx lr
  2062. -.global __a_barrier_v6
  2063. -.hidden __a_barrier_v6
  2064. -__a_barrier_v6:
  2065. - mcr p15,0,r0,c7,c10,5
  2066. - bx lr
  2067. -.global __a_barrier_v7
  2068. -.hidden __a_barrier_v7
  2069. -__a_barrier_v7:
  2070. - .word 0xf57ff05b /* dmb ish */
  2071. - bx lr
  2072. -
  2073. -.global __a_cas
  2074. -.hidden __a_cas
  2075. -.type __a_cas,%function
  2076. -__a_cas:
  2077. - ldr ip,1f
  2078. - ldr ip,[pc,ip]
  2079. - add pc,pc,ip
  2080. -1: .word __a_cas_ptr-1b
  2081. -.global __a_cas_dummy
  2082. -.hidden __a_cas_dummy
  2083. -__a_cas_dummy:
  2084. - mov r3,r0
  2085. - ldr r0,[r2]
  2086. - subs r0,r3,r0
  2087. - streq r1,[r2]
  2088. - tst lr,#1
  2089. - moveq pc,lr
  2090. - bx lr
  2091. -.global __a_cas_v6
  2092. -.hidden __a_cas_v6
  2093. -__a_cas_v6:
  2094. - mov r3,r0
  2095. - mcr p15,0,r0,c7,c10,5
  2096. -1: .word 0xe1920f9f /* ldrex r0,[r2] */
  2097. - subs r0,r3,r0
  2098. - .word 0x01820f91 /* strexeq r0,r1,[r2] */
  2099. - teqeq r0,#1
  2100. - beq 1b
  2101. - mcr p15,0,r0,c7,c10,5
  2102. - bx lr
  2103. -.global __a_cas_v7
  2104. -.hidden __a_cas_v7
  2105. -__a_cas_v7:
  2106. - mov r3,r0
  2107. - .word 0xf57ff05b /* dmb ish */
  2108. -1: .word 0xe1920f9f /* ldrex r0,[r2] */
  2109. - subs r0,r3,r0
  2110. - .word 0x01820f91 /* strexeq r0,r1,[r2] */
  2111. - teqeq r0,#1
  2112. - beq 1b
  2113. - .word 0xf57ff05b /* dmb ish */
  2114. - bx lr
  2115. -
  2116. -.global __aeabi_read_tp
  2117. -.type __aeabi_read_tp,%function
  2118. -__aeabi_read_tp:
  2119. -
  2120. -.global __a_gettp
  2121. -.hidden __a_gettp
  2122. -.type __a_gettp,%function
  2123. -__a_gettp:
  2124. - ldr r0,1f
  2125. - ldr r0,[pc,r0]
  2126. - add pc,pc,r0
  2127. -1: .word __a_gettp_ptr-1b
  2128. -.global __a_gettp_dummy
  2129. -.hidden __a_gettp_dummy
  2130. -__a_gettp_dummy:
  2131. - mrc p15,0,r0,c13,c0,3
  2132. - bx lr
  2133. -
  2134. -.data
  2135. -.global __a_barrier_ptr
  2136. -.hidden __a_barrier_ptr
  2137. -__a_barrier_ptr:
  2138. - .word 0
  2139. -
  2140. -.global __a_cas_ptr
  2141. -.hidden __a_cas_ptr
  2142. -__a_cas_ptr:
  2143. - .word 0
  2144. -
  2145. -.global __a_gettp_ptr
  2146. -.hidden __a_gettp_ptr
  2147. -__a_gettp_ptr:
  2148. - .word 0
  2149. --- a/arch/arm/src/find_exidx.c
  2150. +++ /dev/null
  2151. @@ -1,42 +0,0 @@
  2152. -#define _GNU_SOURCE
  2153. -#include <link.h>
  2154. -#include <stdint.h>
  2155. -
  2156. -struct find_exidx_data {
  2157. - uintptr_t pc, exidx_start;
  2158. - int exidx_len;
  2159. -};
  2160. -
  2161. -static int find_exidx(struct dl_phdr_info *info, size_t size, void *ptr)
  2162. -{
  2163. - struct find_exidx_data *data = ptr;
  2164. - const ElfW(Phdr) *phdr = info->dlpi_phdr;
  2165. - uintptr_t addr, exidx_start = 0;
  2166. - int i, match = 0, exidx_len = 0;
  2167. -
  2168. - for (i = info->dlpi_phnum; i > 0; i--, phdr++) {
  2169. - addr = info->dlpi_addr + phdr->p_vaddr;
  2170. - switch (phdr->p_type) {
  2171. - case PT_LOAD:
  2172. - match |= data->pc >= addr && data->pc < addr + phdr->p_memsz;
  2173. - break;
  2174. - case PT_ARM_EXIDX:
  2175. - exidx_start = addr;
  2176. - exidx_len = phdr->p_memsz;
  2177. - break;
  2178. - }
  2179. - }
  2180. - data->exidx_start = exidx_start;
  2181. - data->exidx_len = exidx_len;
  2182. - return match;
  2183. -}
  2184. -
  2185. -uintptr_t __gnu_Unwind_Find_exidx(uintptr_t pc, int *pcount)
  2186. -{
  2187. - struct find_exidx_data data;
  2188. - data.pc = pc;
  2189. - if (dl_iterate_phdr(find_exidx, &data) <= 0)
  2190. - return 0;
  2191. - *pcount = data.exidx_len / 8;
  2192. - return data.exidx_start;
  2193. -}
  2194. --- /dev/null
  2195. +++ b/arch/generic/bits/errno.h
  2196. @@ -0,0 +1,134 @@
  2197. +#define EPERM 1
  2198. +#define ENOENT 2
  2199. +#define ESRCH 3
  2200. +#define EINTR 4
  2201. +#define EIO 5
  2202. +#define ENXIO 6
  2203. +#define E2BIG 7
  2204. +#define ENOEXEC 8
  2205. +#define EBADF 9
  2206. +#define ECHILD 10
  2207. +#define EAGAIN 11
  2208. +#define ENOMEM 12
  2209. +#define EACCES 13
  2210. +#define EFAULT 14
  2211. +#define ENOTBLK 15
  2212. +#define EBUSY 16
  2213. +#define EEXIST 17
  2214. +#define EXDEV 18
  2215. +#define ENODEV 19
  2216. +#define ENOTDIR 20
  2217. +#define EISDIR 21
  2218. +#define EINVAL 22
  2219. +#define ENFILE 23
  2220. +#define EMFILE 24
  2221. +#define ENOTTY 25
  2222. +#define ETXTBSY 26
  2223. +#define EFBIG 27
  2224. +#define ENOSPC 28
  2225. +#define ESPIPE 29
  2226. +#define EROFS 30
  2227. +#define EMLINK 31
  2228. +#define EPIPE 32
  2229. +#define EDOM 33
  2230. +#define ERANGE 34
  2231. +#define EDEADLK 35
  2232. +#define ENAMETOOLONG 36
  2233. +#define ENOLCK 37
  2234. +#define ENOSYS 38
  2235. +#define ENOTEMPTY 39
  2236. +#define ELOOP 40
  2237. +#define EWOULDBLOCK EAGAIN
  2238. +#define ENOMSG 42
  2239. +#define EIDRM 43
  2240. +#define ECHRNG 44
  2241. +#define EL2NSYNC 45
  2242. +#define EL3HLT 46
  2243. +#define EL3RST 47
  2244. +#define ELNRNG 48
  2245. +#define EUNATCH 49
  2246. +#define ENOCSI 50
  2247. +#define EL2HLT 51
  2248. +#define EBADE 52
  2249. +#define EBADR 53
  2250. +#define EXFULL 54
  2251. +#define ENOANO 55
  2252. +#define EBADRQC 56
  2253. +#define EBADSLT 57
  2254. +#define EDEADLOCK EDEADLK
  2255. +#define EBFONT 59
  2256. +#define ENOSTR 60
  2257. +#define ENODATA 61
  2258. +#define ETIME 62
  2259. +#define ENOSR 63
  2260. +#define ENONET 64
  2261. +#define ENOPKG 65
  2262. +#define EREMOTE 66
  2263. +#define ENOLINK 67
  2264. +#define EADV 68
  2265. +#define ESRMNT 69
  2266. +#define ECOMM 70
  2267. +#define EPROTO 71
  2268. +#define EMULTIHOP 72
  2269. +#define EDOTDOT 73
  2270. +#define EBADMSG 74
  2271. +#define EOVERFLOW 75
  2272. +#define ENOTUNIQ 76
  2273. +#define EBADFD 77
  2274. +#define EREMCHG 78
  2275. +#define ELIBACC 79
  2276. +#define ELIBBAD 80
  2277. +#define ELIBSCN 81
  2278. +#define ELIBMAX 82
  2279. +#define ELIBEXEC 83
  2280. +#define EILSEQ 84
  2281. +#define ERESTART 85
  2282. +#define ESTRPIPE 86
  2283. +#define EUSERS 87
  2284. +#define ENOTSOCK 88
  2285. +#define EDESTADDRREQ 89
  2286. +#define EMSGSIZE 90
  2287. +#define EPROTOTYPE 91
  2288. +#define ENOPROTOOPT 92
  2289. +#define EPROTONOSUPPORT 93
  2290. +#define ESOCKTNOSUPPORT 94
  2291. +#define EOPNOTSUPP 95
  2292. +#define ENOTSUP EOPNOTSUPP
  2293. +#define EPFNOSUPPORT 96
  2294. +#define EAFNOSUPPORT 97
  2295. +#define EADDRINUSE 98
  2296. +#define EADDRNOTAVAIL 99
  2297. +#define ENETDOWN 100
  2298. +#define ENETUNREACH 101
  2299. +#define ENETRESET 102
  2300. +#define ECONNABORTED 103
  2301. +#define ECONNRESET 104
  2302. +#define ENOBUFS 105
  2303. +#define EISCONN 106
  2304. +#define ENOTCONN 107
  2305. +#define ESHUTDOWN 108
  2306. +#define ETOOMANYREFS 109
  2307. +#define ETIMEDOUT 110
  2308. +#define ECONNREFUSED 111
  2309. +#define EHOSTDOWN 112
  2310. +#define EHOSTUNREACH 113
  2311. +#define EALREADY 114
  2312. +#define EINPROGRESS 115
  2313. +#define ESTALE 116
  2314. +#define EUCLEAN 117
  2315. +#define ENOTNAM 118
  2316. +#define ENAVAIL 119
  2317. +#define EISNAM 120
  2318. +#define EREMOTEIO 121
  2319. +#define EDQUOT 122
  2320. +#define ENOMEDIUM 123
  2321. +#define EMEDIUMTYPE 124
  2322. +#define ECANCELED 125
  2323. +#define ENOKEY 126
  2324. +#define EKEYEXPIRED 127
  2325. +#define EKEYREVOKED 128
  2326. +#define EKEYREJECTED 129
  2327. +#define EOWNERDEAD 130
  2328. +#define ENOTRECOVERABLE 131
  2329. +#define ERFKILL 132
  2330. +#define EHWPOISON 133
  2331. --- /dev/null
  2332. +++ b/arch/generic/bits/fcntl.h
  2333. @@ -0,0 +1,40 @@
  2334. +#define O_CREAT 0100
  2335. +#define O_EXCL 0200
  2336. +#define O_NOCTTY 0400
  2337. +#define O_TRUNC 01000
  2338. +#define O_APPEND 02000
  2339. +#define O_NONBLOCK 04000
  2340. +#define O_DSYNC 010000
  2341. +#define O_SYNC 04010000
  2342. +#define O_RSYNC 04010000
  2343. +#define O_DIRECTORY 0200000
  2344. +#define O_NOFOLLOW 0400000
  2345. +#define O_CLOEXEC 02000000
  2346. +
  2347. +#define O_ASYNC 020000
  2348. +#define O_DIRECT 040000
  2349. +#define O_LARGEFILE 0100000
  2350. +#define O_NOATIME 01000000
  2351. +#define O_PATH 010000000
  2352. +#define O_TMPFILE 020200000
  2353. +#define O_NDELAY O_NONBLOCK
  2354. +
  2355. +#define F_DUPFD 0
  2356. +#define F_GETFD 1
  2357. +#define F_SETFD 2
  2358. +#define F_GETFL 3
  2359. +#define F_SETFL 4
  2360. +
  2361. +#define F_SETOWN 8
  2362. +#define F_GETOWN 9
  2363. +#define F_SETSIG 10
  2364. +#define F_GETSIG 11
  2365. +
  2366. +#define F_GETLK 12
  2367. +#define F_SETLK 13
  2368. +#define F_SETLKW 14
  2369. +
  2370. +#define F_SETOWN_EX 15
  2371. +#define F_GETOWN_EX 16
  2372. +
  2373. +#define F_GETOWNER_UIDS 17
  2374. --- /dev/null
  2375. +++ b/arch/generic/bits/fenv.h
  2376. @@ -0,0 +1,10 @@
  2377. +#define FE_ALL_EXCEPT 0
  2378. +#define FE_TONEAREST 0
  2379. +
  2380. +typedef unsigned long fexcept_t;
  2381. +
  2382. +typedef struct {
  2383. + unsigned long __cw;
  2384. +} fenv_t;
  2385. +
  2386. +#define FE_DFL_ENV ((const fenv_t *) -1)
  2387. --- /dev/null
  2388. +++ b/arch/generic/bits/ioctl.h
  2389. @@ -0,0 +1,197 @@
  2390. +#define _IOC(a,b,c,d) ( ((a)<<30) | ((b)<<8) | (c) | ((d)<<16) )
  2391. +#define _IOC_NONE 0U
  2392. +#define _IOC_WRITE 1U
  2393. +#define _IOC_READ 2U
  2394. +
  2395. +#define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0)
  2396. +#define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),sizeof(c))
  2397. +#define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),sizeof(c))
  2398. +#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE,(a),(b),sizeof(c))
  2399. +
  2400. +#define TCGETS 0x5401
  2401. +#define TCSETS 0x5402
  2402. +#define TCSETSW 0x5403
  2403. +#define TCSETSF 0x5404
  2404. +#define TCGETA 0x5405
  2405. +#define TCSETA 0x5406
  2406. +#define TCSETAW 0x5407
  2407. +#define TCSETAF 0x5408
  2408. +#define TCSBRK 0x5409
  2409. +#define TCXONC 0x540A
  2410. +#define TCFLSH 0x540B
  2411. +#define TIOCEXCL 0x540C
  2412. +#define TIOCNXCL 0x540D
  2413. +#define TIOCSCTTY 0x540E
  2414. +#define TIOCGPGRP 0x540F
  2415. +#define TIOCSPGRP 0x5410
  2416. +#define TIOCOUTQ 0x5411
  2417. +#define TIOCSTI 0x5412
  2418. +#define TIOCGWINSZ 0x5413
  2419. +#define TIOCSWINSZ 0x5414
  2420. +#define TIOCMGET 0x5415
  2421. +#define TIOCMBIS 0x5416
  2422. +#define TIOCMBIC 0x5417
  2423. +#define TIOCMSET 0x5418
  2424. +#define TIOCGSOFTCAR 0x5419
  2425. +#define TIOCSSOFTCAR 0x541A
  2426. +#define FIONREAD 0x541B
  2427. +#define TIOCINQ FIONREAD
  2428. +#define TIOCLINUX 0x541C
  2429. +#define TIOCCONS 0x541D
  2430. +#define TIOCGSERIAL 0x541E
  2431. +#define TIOCSSERIAL 0x541F
  2432. +#define TIOCPKT 0x5420
  2433. +#define FIONBIO 0x5421
  2434. +#define TIOCNOTTY 0x5422
  2435. +#define TIOCSETD 0x5423
  2436. +#define TIOCGETD 0x5424
  2437. +#define TCSBRKP 0x5425
  2438. +#define TIOCTTYGSTRUCT 0x5426
  2439. +#define TIOCSBRK 0x5427
  2440. +#define TIOCCBRK 0x5428
  2441. +#define TIOCGSID 0x5429
  2442. +#define TIOCGPTN 0x80045430
  2443. +#define TIOCSPTLCK 0x40045431
  2444. +#define TCGETX 0x5432
  2445. +#define TCSETX 0x5433
  2446. +#define TCSETXF 0x5434
  2447. +#define TCSETXW 0x5435
  2448. +
  2449. +#define FIONCLEX 0x5450
  2450. +#define FIOCLEX 0x5451
  2451. +#define FIOASYNC 0x5452
  2452. +#define TIOCSERCONFIG 0x5453
  2453. +#define TIOCSERGWILD 0x5454
  2454. +#define TIOCSERSWILD 0x5455
  2455. +#define TIOCGLCKTRMIOS 0x5456
  2456. +#define TIOCSLCKTRMIOS 0x5457
  2457. +#define TIOCSERGSTRUCT 0x5458
  2458. +#define TIOCSERGETLSR 0x5459
  2459. +#define TIOCSERGETMULTI 0x545A
  2460. +#define TIOCSERSETMULTI 0x545B
  2461. +
  2462. +#define TIOCMIWAIT 0x545C
  2463. +#define TIOCGICOUNT 0x545D
  2464. +#define TIOCGHAYESESP 0x545E
  2465. +#define TIOCSHAYESESP 0x545F
  2466. +#define FIOQSIZE 0x5460
  2467. +
  2468. +#define TIOCPKT_DATA 0
  2469. +#define TIOCPKT_FLUSHREAD 1
  2470. +#define TIOCPKT_FLUSHWRITE 2
  2471. +#define TIOCPKT_STOP 4
  2472. +#define TIOCPKT_START 8
  2473. +#define TIOCPKT_NOSTOP 16
  2474. +#define TIOCPKT_DOSTOP 32
  2475. +#define TIOCPKT_IOCTL 64
  2476. +
  2477. +#define TIOCSER_TEMT 0x01
  2478. +
  2479. +struct winsize {
  2480. + unsigned short ws_row;
  2481. + unsigned short ws_col;
  2482. + unsigned short ws_xpixel;
  2483. + unsigned short ws_ypixel;
  2484. +};
  2485. +
  2486. +#define TIOCM_LE 0x001
  2487. +#define TIOCM_DTR 0x002
  2488. +#define TIOCM_RTS 0x004
  2489. +#define TIOCM_ST 0x008
  2490. +#define TIOCM_SR 0x010
  2491. +#define TIOCM_CTS 0x020
  2492. +#define TIOCM_CAR 0x040
  2493. +#define TIOCM_RNG 0x080
  2494. +#define TIOCM_DSR 0x100
  2495. +#define TIOCM_CD TIOCM_CAR
  2496. +#define TIOCM_RI TIOCM_RNG
  2497. +#define TIOCM_OUT1 0x2000
  2498. +#define TIOCM_OUT2 0x4000
  2499. +#define TIOCM_LOOP 0x8000
  2500. +#define TIOCM_MODEM_BITS TIOCM_OUT2
  2501. +
  2502. +#define N_TTY 0
  2503. +#define N_SLIP 1
  2504. +#define N_MOUSE 2
  2505. +#define N_PPP 3
  2506. +#define N_STRIP 4
  2507. +#define N_AX25 5
  2508. +#define N_X25 6
  2509. +#define N_6PACK 7
  2510. +#define N_MASC 8
  2511. +#define N_R3964 9
  2512. +#define N_PROFIBUS_FDL 10
  2513. +#define N_IRDA 11
  2514. +#define N_SMSBLOCK 12
  2515. +#define N_HDLC 13
  2516. +#define N_SYNC_PPP 14
  2517. +#define N_HCI 15
  2518. +
  2519. +#define FIOSETOWN 0x8901
  2520. +#define SIOCSPGRP 0x8902
  2521. +#define FIOGETOWN 0x8903
  2522. +#define SIOCGPGRP 0x8904
  2523. +#define SIOCATMARK 0x8905
  2524. +#define SIOCGSTAMP 0x8906
  2525. +
  2526. +#define SIOCADDRT 0x890B
  2527. +#define SIOCDELRT 0x890C
  2528. +#define SIOCRTMSG 0x890D
  2529. +
  2530. +#define SIOCGIFNAME 0x8910
  2531. +#define SIOCSIFLINK 0x8911
  2532. +#define SIOCGIFCONF 0x8912
  2533. +#define SIOCGIFFLAGS 0x8913
  2534. +#define SIOCSIFFLAGS 0x8914
  2535. +#define SIOCGIFADDR 0x8915
  2536. +#define SIOCSIFADDR 0x8916
  2537. +#define SIOCGIFDSTADDR 0x8917
  2538. +#define SIOCSIFDSTADDR 0x8918
  2539. +#define SIOCGIFBRDADDR 0x8919
  2540. +#define SIOCSIFBRDADDR 0x891a
  2541. +#define SIOCGIFNETMASK 0x891b
  2542. +#define SIOCSIFNETMASK 0x891c
  2543. +#define SIOCGIFMETRIC 0x891d
  2544. +#define SIOCSIFMETRIC 0x891e
  2545. +#define SIOCGIFMEM 0x891f
  2546. +#define SIOCSIFMEM 0x8920
  2547. +#define SIOCGIFMTU 0x8921
  2548. +#define SIOCSIFMTU 0x8922
  2549. +#define SIOCSIFHWADDR 0x8924
  2550. +#define SIOCGIFENCAP 0x8925
  2551. +#define SIOCSIFENCAP 0x8926
  2552. +#define SIOCGIFHWADDR 0x8927
  2553. +#define SIOCGIFSLAVE 0x8929
  2554. +#define SIOCSIFSLAVE 0x8930
  2555. +#define SIOCADDMULTI 0x8931
  2556. +#define SIOCDELMULTI 0x8932
  2557. +#define SIOCGIFINDEX 0x8933
  2558. +#define SIOGIFINDEX SIOCGIFINDEX
  2559. +#define SIOCSIFPFLAGS 0x8934
  2560. +#define SIOCGIFPFLAGS 0x8935
  2561. +#define SIOCDIFADDR 0x8936
  2562. +#define SIOCSIFHWBROADCAST 0x8937
  2563. +#define SIOCGIFCOUNT 0x8938
  2564. +
  2565. +#define SIOCGIFBR 0x8940
  2566. +#define SIOCSIFBR 0x8941
  2567. +
  2568. +#define SIOCGIFTXQLEN 0x8942
  2569. +#define SIOCSIFTXQLEN 0x8943
  2570. +
  2571. +#define SIOCDARP 0x8953
  2572. +#define SIOCGARP 0x8954
  2573. +#define SIOCSARP 0x8955
  2574. +
  2575. +#define SIOCDRARP 0x8960
  2576. +#define SIOCGRARP 0x8961
  2577. +#define SIOCSRARP 0x8962
  2578. +
  2579. +#define SIOCGIFMAP 0x8970
  2580. +#define SIOCSIFMAP 0x8971
  2581. +
  2582. +#define SIOCADDDLCI 0x8980
  2583. +#define SIOCDELDLCI 0x8981
  2584. +
  2585. +#define SIOCDEVPRIVATE 0x89F0
  2586. +#define SIOCPROTOPRIVATE 0x89E0
  2587. --- /dev/null
  2588. +++ b/arch/generic/bits/ipc.h
  2589. @@ -0,0 +1,14 @@
  2590. +struct ipc_perm
  2591. +{
  2592. + key_t __ipc_perm_key;
  2593. + uid_t uid;
  2594. + gid_t gid;
  2595. + uid_t cuid;
  2596. + gid_t cgid;
  2597. + mode_t mode;
  2598. + int __ipc_perm_seq;
  2599. + long __pad1;
  2600. + long __pad2;
  2601. +};
  2602. +
  2603. +#define IPC_64 0x100
  2604. --- /dev/null
  2605. +++ b/arch/generic/bits/msg.h
  2606. @@ -0,0 +1,16 @@
  2607. +struct msqid_ds
  2608. +{
  2609. + struct ipc_perm msg_perm;
  2610. + time_t msg_stime;
  2611. + int __unused1;
  2612. + time_t msg_rtime;
  2613. + int __unused2;
  2614. + time_t msg_ctime;
  2615. + int __unused3;
  2616. + unsigned long msg_cbytes;
  2617. + msgqnum_t msg_qnum;
  2618. + msglen_t msg_qbytes;
  2619. + pid_t msg_lspid;
  2620. + pid_t msg_lrpid;
  2621. + unsigned long __unused[2];
  2622. +};
  2623. --- /dev/null
  2624. +++ b/arch/generic/bits/sem.h
  2625. @@ -0,0 +1,16 @@
  2626. +struct semid_ds {
  2627. + struct ipc_perm sem_perm;
  2628. + time_t sem_otime;
  2629. + time_t __unused1;
  2630. + time_t sem_ctime;
  2631. + time_t __unused2;
  2632. +#if __BYTE_ORDER == __LITTLE_ENDIAN
  2633. + unsigned short sem_nsems;
  2634. + char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
  2635. +#else
  2636. + char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
  2637. + unsigned short sem_nsems;
  2638. +#endif
  2639. + time_t __unused3;
  2640. + time_t __unused4;
  2641. +};
  2642. --- /dev/null
  2643. +++ b/arch/generic/bits/shm.h
  2644. @@ -0,0 +1,29 @@
  2645. +#define SHMLBA 4096
  2646. +
  2647. +struct shmid_ds
  2648. +{
  2649. + struct ipc_perm shm_perm;
  2650. + size_t shm_segsz;
  2651. + time_t shm_atime;
  2652. + int __unused1;
  2653. + time_t shm_dtime;
  2654. + int __unused2;
  2655. + time_t shm_ctime;
  2656. + int __unused3;
  2657. + pid_t shm_cpid;
  2658. + pid_t shm_lpid;
  2659. + unsigned long shm_nattch;
  2660. + unsigned long __pad1;
  2661. + unsigned long __pad2;
  2662. +};
  2663. +
  2664. +struct shminfo {
  2665. + unsigned long shmmax, shmmin, shmmni, shmseg, shmall, __unused[4];
  2666. +};
  2667. +
  2668. +struct shm_info {
  2669. + int __used_ids;
  2670. + unsigned long shm_tot, shm_rss, shm_swp;
  2671. + unsigned long __swap_attempts, __swap_successes;
  2672. +};
  2673. +
  2674. --- /dev/null
  2675. +++ b/arch/generic/bits/socket.h
  2676. @@ -0,0 +1,17 @@
  2677. +struct msghdr
  2678. +{
  2679. + void *msg_name;
  2680. + socklen_t msg_namelen;
  2681. + struct iovec *msg_iov;
  2682. + int msg_iovlen;
  2683. + void *msg_control;
  2684. + socklen_t msg_controllen;
  2685. + int msg_flags;
  2686. +};
  2687. +
  2688. +struct cmsghdr
  2689. +{
  2690. + socklen_t cmsg_len;
  2691. + int cmsg_level;
  2692. + int cmsg_type;
  2693. +};
  2694. --- /dev/null
  2695. +++ b/arch/generic/bits/statfs.h
  2696. @@ -0,0 +1,7 @@
  2697. +struct statfs {
  2698. + unsigned long f_type, f_bsize;
  2699. + fsblkcnt_t f_blocks, f_bfree, f_bavail;
  2700. + fsfilcnt_t f_files, f_ffree;
  2701. + fsid_t f_fsid;
  2702. + unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
  2703. +};
  2704. --- /dev/null
  2705. +++ b/arch/generic/bits/stdarg.h
  2706. @@ -0,0 +1,4 @@
  2707. +#define va_start(v,l) __builtin_va_start(v,l)
  2708. +#define va_end(v) __builtin_va_end(v)
  2709. +#define va_arg(v,l) __builtin_va_arg(v,l)
  2710. +#define va_copy(d,s) __builtin_va_copy(d,s)
  2711. --- /dev/null
  2712. +++ b/arch/generic/bits/termios.h
  2713. @@ -0,0 +1,160 @@
  2714. +struct termios
  2715. +{
  2716. + tcflag_t c_iflag;
  2717. + tcflag_t c_oflag;
  2718. + tcflag_t c_cflag;
  2719. + tcflag_t c_lflag;
  2720. + cc_t c_line;
  2721. + cc_t c_cc[NCCS];
  2722. + speed_t __c_ispeed;
  2723. + speed_t __c_ospeed;
  2724. +};
  2725. +
  2726. +#define VINTR 0
  2727. +#define VQUIT 1
  2728. +#define VERASE 2
  2729. +#define VKILL 3
  2730. +#define VEOF 4
  2731. +#define VTIME 5
  2732. +#define VMIN 6
  2733. +#define VSWTC 7
  2734. +#define VSTART 8
  2735. +#define VSTOP 9
  2736. +#define VSUSP 10
  2737. +#define VEOL 11
  2738. +#define VREPRINT 12
  2739. +#define VDISCARD 13
  2740. +#define VWERASE 14
  2741. +#define VLNEXT 15
  2742. +#define VEOL2 16
  2743. +
  2744. +#define IGNBRK 0000001
  2745. +#define BRKINT 0000002
  2746. +#define IGNPAR 0000004
  2747. +#define PARMRK 0000010
  2748. +#define INPCK 0000020
  2749. +#define ISTRIP 0000040
  2750. +#define INLCR 0000100
  2751. +#define IGNCR 0000200
  2752. +#define ICRNL 0000400
  2753. +#define IUCLC 0001000
  2754. +#define IXON 0002000
  2755. +#define IXANY 0004000
  2756. +#define IXOFF 0010000
  2757. +#define IMAXBEL 0020000
  2758. +#define IUTF8 0040000
  2759. +
  2760. +#define OPOST 0000001
  2761. +#define OLCUC 0000002
  2762. +#define ONLCR 0000004
  2763. +#define OCRNL 0000010
  2764. +#define ONOCR 0000020
  2765. +#define ONLRET 0000040
  2766. +#define OFILL 0000100
  2767. +#define OFDEL 0000200
  2768. +#define NLDLY 0000400
  2769. +#define NL0 0000000
  2770. +#define NL1 0000400
  2771. +#define CRDLY 0003000
  2772. +#define CR0 0000000
  2773. +#define CR1 0001000
  2774. +#define CR2 0002000
  2775. +#define CR3 0003000
  2776. +#define TABDLY 0014000
  2777. +#define TAB0 0000000
  2778. +#define TAB1 0004000
  2779. +#define TAB2 0010000
  2780. +#define TAB3 0014000
  2781. +#define BSDLY 0020000
  2782. +#define BS0 0000000
  2783. +#define BS1 0020000
  2784. +#define FFDLY 0100000
  2785. +#define FF0 0000000
  2786. +#define FF1 0100000
  2787. +
  2788. +#define VTDLY 0040000
  2789. +#define VT0 0000000
  2790. +#define VT1 0040000
  2791. +
  2792. +#define B0 0000000
  2793. +#define B50 0000001
  2794. +#define B75 0000002
  2795. +#define B110 0000003
  2796. +#define B134 0000004
  2797. +#define B150 0000005
  2798. +#define B200 0000006
  2799. +#define B300 0000007
  2800. +#define B600 0000010
  2801. +#define B1200 0000011
  2802. +#define B1800 0000012
  2803. +#define B2400 0000013
  2804. +#define B4800 0000014
  2805. +#define B9600 0000015
  2806. +#define B19200 0000016
  2807. +#define B38400 0000017
  2808. +
  2809. +#define B57600 0010001
  2810. +#define B115200 0010002
  2811. +#define B230400 0010003
  2812. +#define B460800 0010004
  2813. +#define B500000 0010005
  2814. +#define B576000 0010006
  2815. +#define B921600 0010007
  2816. +#define B1000000 0010010
  2817. +#define B1152000 0010011
  2818. +#define B1500000 0010012
  2819. +#define B2000000 0010013
  2820. +#define B2500000 0010014
  2821. +#define B3000000 0010015
  2822. +#define B3500000 0010016
  2823. +#define B4000000 0010017
  2824. +
  2825. +#define CBAUD 0010017
  2826. +
  2827. +#define CSIZE 0000060
  2828. +#define CS5 0000000
  2829. +#define CS6 0000020
  2830. +#define CS7 0000040
  2831. +#define CS8 0000060
  2832. +#define CSTOPB 0000100
  2833. +#define CREAD 0000200
  2834. +#define PARENB 0000400
  2835. +#define PARODD 0001000
  2836. +#define HUPCL 0002000
  2837. +#define CLOCAL 0004000
  2838. +
  2839. +#define ISIG 0000001
  2840. +#define ICANON 0000002
  2841. +#define ECHO 0000010
  2842. +#define ECHOE 0000020
  2843. +#define ECHOK 0000040
  2844. +#define ECHONL 0000100
  2845. +#define NOFLSH 0000200
  2846. +#define TOSTOP 0000400
  2847. +#define IEXTEN 0100000
  2848. +
  2849. +#define ECHOCTL 0001000
  2850. +#define ECHOPRT 0002000
  2851. +#define ECHOKE 0004000
  2852. +#define FLUSHO 0010000
  2853. +#define PENDIN 0040000
  2854. +
  2855. +#define TCOOFF 0
  2856. +#define TCOON 1
  2857. +#define TCIOFF 2
  2858. +#define TCION 3
  2859. +
  2860. +#define TCIFLUSH 0
  2861. +#define TCOFLUSH 1
  2862. +#define TCIOFLUSH 2
  2863. +
  2864. +#define TCSANOW 0
  2865. +#define TCSADRAIN 1
  2866. +#define TCSAFLUSH 2
  2867. +
  2868. +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  2869. +#define CBAUDEX 0010000
  2870. +#define CRTSCTS 020000000000
  2871. +#define EXTPROC 0200000
  2872. +#define XTABS 0014000
  2873. +#endif
  2874. --- a/arch/i386/atomic.h
  2875. +++ /dev/null
  2876. @@ -1,110 +0,0 @@
  2877. -#ifndef _INTERNAL_ATOMIC_H
  2878. -#define _INTERNAL_ATOMIC_H
  2879. -
  2880. -#include <stdint.h>
  2881. -
  2882. -static inline int a_ctz_64(uint64_t x)
  2883. -{
  2884. - int r;
  2885. - __asm__( "bsf %1,%0 ; jnz 1f ; bsf %2,%0 ; addl $32,%0\n1:"
  2886. - : "=&r"(r) : "r"((unsigned)x), "r"((unsigned)(x>>32)) );
  2887. - return r;
  2888. -}
  2889. -
  2890. -static inline int a_ctz_l(unsigned long x)
  2891. -{
  2892. - long r;
  2893. - __asm__( "bsf %1,%0" : "=r"(r) : "r"(x) );
  2894. - return r;
  2895. -}
  2896. -
  2897. -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
  2898. -{
  2899. - __asm__( "lock ; andl %1, (%0) ; lock ; andl %2, 4(%0)"
  2900. - : : "r"((long *)p), "r"((unsigned)v), "r"((unsigned)(v>>32)) : "memory" );
  2901. -}
  2902. -
  2903. -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
  2904. -{
  2905. - __asm__( "lock ; orl %1, (%0) ; lock ; orl %2, 4(%0)"
  2906. - : : "r"((long *)p), "r"((unsigned)v), "r"((unsigned)(v>>32)) : "memory" );
  2907. -}
  2908. -
  2909. -static inline void a_or_l(volatile void *p, long v)
  2910. -{
  2911. - __asm__( "lock ; orl %1, %0"
  2912. - : "=m"(*(long *)p) : "r"(v) : "memory" );
  2913. -}
  2914. -
  2915. -static inline void *a_cas_p(volatile void *p, void *t, void *s)
  2916. -{
  2917. - __asm__( "lock ; cmpxchg %3, %1"
  2918. - : "=a"(t), "=m"(*(long *)p) : "a"(t), "r"(s) : "memory" );
  2919. - return t;
  2920. -}
  2921. -
  2922. -static inline int a_cas(volatile int *p, int t, int s)
  2923. -{
  2924. - __asm__( "lock ; cmpxchg %3, %1"
  2925. - : "=a"(t), "=m"(*p) : "a"(t), "r"(s) : "memory" );
  2926. - return t;
  2927. -}
  2928. -
  2929. -static inline void a_or(volatile int *p, int v)
  2930. -{
  2931. - __asm__( "lock ; orl %1, %0"
  2932. - : "=m"(*p) : "r"(v) : "memory" );
  2933. -}
  2934. -
  2935. -static inline void a_and(volatile int *p, int v)
  2936. -{
  2937. - __asm__( "lock ; andl %1, %0"
  2938. - : "=m"(*p) : "r"(v) : "memory" );
  2939. -}
  2940. -
  2941. -static inline int a_swap(volatile int *x, int v)
  2942. -{
  2943. - __asm__( "xchg %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" );
  2944. - return v;
  2945. -}
  2946. -
  2947. -#define a_xchg a_swap
  2948. -
  2949. -static inline int a_fetch_add(volatile int *x, int v)
  2950. -{
  2951. - __asm__( "lock ; xadd %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" );
  2952. - return v;
  2953. -}
  2954. -
  2955. -static inline void a_inc(volatile int *x)
  2956. -{
  2957. - __asm__( "lock ; incl %0" : "=m"(*x) : "m"(*x) : "memory" );
  2958. -}
  2959. -
  2960. -static inline void a_dec(volatile int *x)
  2961. -{
  2962. - __asm__( "lock ; decl %0" : "=m"(*x) : "m"(*x) : "memory" );
  2963. -}
  2964. -
  2965. -static inline void a_store(volatile int *p, int x)
  2966. -{
  2967. - __asm__( "movl %1, %0 ; lock ; orl $0,(%%esp)" : "=m"(*p) : "r"(x) : "memory" );
  2968. -}
  2969. -
  2970. -static inline void a_spin()
  2971. -{
  2972. - __asm__ __volatile__( "pause" : : : "memory" );
  2973. -}
  2974. -
  2975. -static inline void a_barrier()
  2976. -{
  2977. - __asm__ __volatile__( "" : : : "memory" );
  2978. -}
  2979. -
  2980. -static inline void a_crash()
  2981. -{
  2982. - __asm__ __volatile__( "hlt" : : : "memory" );
  2983. -}
  2984. -
  2985. -
  2986. -#endif
  2987. --- /dev/null
  2988. +++ b/arch/i386/atomic_arch.h
  2989. @@ -0,0 +1,101 @@
  2990. +#define a_cas a_cas
  2991. +static inline int a_cas(volatile int *p, int t, int s)
  2992. +{
  2993. + __asm__ __volatile__ (
  2994. + "lock ; cmpxchg %3, %1"
  2995. + : "=a"(t), "=m"(*p) : "a"(t), "r"(s) : "memory" );
  2996. + return t;
  2997. +}
  2998. +
  2999. +#define a_swap a_swap
  3000. +static inline int a_swap(volatile int *p, int v)
  3001. +{
  3002. + __asm__ __volatile__(
  3003. + "xchg %0, %1"
  3004. + : "=r"(v), "=m"(*p) : "0"(v) : "memory" );
  3005. + return v;
  3006. +}
  3007. +
  3008. +#define a_fetch_add a_fetch_add
  3009. +static inline int a_fetch_add(volatile int *p, int v)
  3010. +{
  3011. + __asm__ __volatile__(
  3012. + "lock ; xadd %0, %1"
  3013. + : "=r"(v), "=m"(*p) : "0"(v) : "memory" );
  3014. + return v;
  3015. +}
  3016. +
  3017. +#define a_and a_and
  3018. +static inline void a_and(volatile int *p, int v)
  3019. +{
  3020. + __asm__ __volatile__(
  3021. + "lock ; and %1, %0"
  3022. + : "=m"(*p) : "r"(v) : "memory" );
  3023. +}
  3024. +
  3025. +#define a_or a_or
  3026. +static inline void a_or(volatile int *p, int v)
  3027. +{
  3028. + __asm__ __volatile__(
  3029. + "lock ; or %1, %0"
  3030. + : "=m"(*p) : "r"(v) : "memory" );
  3031. +}
  3032. +
  3033. +#define a_inc a_inc
  3034. +static inline void a_inc(volatile int *p)
  3035. +{
  3036. + __asm__ __volatile__(
  3037. + "lock ; incl %0"
  3038. + : "=m"(*p) : "m"(*p) : "memory" );
  3039. +}
  3040. +
  3041. +#define a_dec a_dec
  3042. +static inline void a_dec(volatile int *p)
  3043. +{
  3044. + __asm__ __volatile__(
  3045. + "lock ; decl %0"
  3046. + : "=m"(*p) : "m"(*p) : "memory" );
  3047. +}
  3048. +
  3049. +#define a_store a_store
  3050. +static inline void a_store(volatile int *p, int x)
  3051. +{
  3052. + __asm__ __volatile__(
  3053. + "mov %1, %0 ; lock ; orl $0,(%%esp)"
  3054. + : "=m"(*p) : "r"(x) : "memory" );
  3055. +}
  3056. +
  3057. +#define a_barrier a_barrier
  3058. +static inline void a_barrier()
  3059. +{
  3060. + __asm__ __volatile__( "" : : : "memory" );
  3061. +}
  3062. +
  3063. +#define a_pause a_pause
  3064. +static inline void a_spin()
  3065. +{
  3066. + __asm__ __volatile__( "pause" : : : "memory" );
  3067. +}
  3068. +
  3069. +#define a_crash a_crash
  3070. +static inline void a_crash()
  3071. +{
  3072. + __asm__ __volatile__( "hlt" : : : "memory" );
  3073. +}
  3074. +
  3075. +#define a_ctz_64 a_ctz_64
  3076. +static inline int a_ctz_64(uint64_t x)
  3077. +{
  3078. + int r;
  3079. + __asm__( "bsf %1,%0 ; jnz 1f ; bsf %2,%0 ; add $32,%0\n1:"
  3080. + : "=&r"(r) : "r"((unsigned)x), "r"((unsigned)(x>>32)) );
  3081. + return r;
  3082. +}
  3083. +
  3084. +#define a_ctz_l a_ctz_l
  3085. +static inline int a_ctz_l(unsigned long x)
  3086. +{
  3087. + long r;
  3088. + __asm__( "bsf %1,%0" : "=r"(r) : "r"(x) );
  3089. + return r;
  3090. +}
  3091. --- a/arch/i386/bits/alltypes.h.in
  3092. +++ b/arch/i386/bits/alltypes.h.in
  3093. @@ -26,10 +26,12 @@ TYPEDEF long double float_t;
  3094. TYPEDEF long double double_t;
  3095. #endif
  3096. -#ifdef __cplusplus
  3097. -TYPEDEF struct { alignas(8) long long __ll; long double __ld; } max_align_t;
  3098. -#else
  3099. +#if !defined(__cplusplus)
  3100. TYPEDEF struct { _Alignas(8) long long __ll; long double __ld; } max_align_t;
  3101. +#elif defined(__GNUC__)
  3102. +TYPEDEF struct { __attribute__((__aligned__(8))) long long __ll; long double __ld; } max_align_t;
  3103. +#else
  3104. +TYPEDEF struct { alignas(8) long long __ll; long double __ld; } max_align_t;
  3105. #endif
  3106. TYPEDEF long time_t;
  3107. --- a/arch/i386/bits/errno.h
  3108. +++ /dev/null
  3109. @@ -1,134 +0,0 @@
  3110. -#define EPERM 1
  3111. -#define ENOENT 2
  3112. -#define ESRCH 3
  3113. -#define EINTR 4
  3114. -#define EIO 5
  3115. -#define ENXIO 6
  3116. -#define E2BIG 7
  3117. -#define ENOEXEC 8
  3118. -#define EBADF 9
  3119. -#define ECHILD 10
  3120. -#define EAGAIN 11
  3121. -#define ENOMEM 12
  3122. -#define EACCES 13
  3123. -#define EFAULT 14
  3124. -#define ENOTBLK 15
  3125. -#define EBUSY 16
  3126. -#define EEXIST 17
  3127. -#define EXDEV 18
  3128. -#define ENODEV 19
  3129. -#define ENOTDIR 20
  3130. -#define EISDIR 21
  3131. -#define EINVAL 22
  3132. -#define ENFILE 23
  3133. -#define EMFILE 24
  3134. -#define ENOTTY 25
  3135. -#define ETXTBSY 26
  3136. -#define EFBIG 27
  3137. -#define ENOSPC 28
  3138. -#define ESPIPE 29
  3139. -#define EROFS 30
  3140. -#define EMLINK 31
  3141. -#define EPIPE 32
  3142. -#define EDOM 33
  3143. -#define ERANGE 34
  3144. -#define EDEADLK 35
  3145. -#define ENAMETOOLONG 36
  3146. -#define ENOLCK 37
  3147. -#define ENOSYS 38
  3148. -#define ENOTEMPTY 39
  3149. -#define ELOOP 40
  3150. -#define EWOULDBLOCK EAGAIN
  3151. -#define ENOMSG 42
  3152. -#define EIDRM 43
  3153. -#define ECHRNG 44
  3154. -#define EL2NSYNC 45
  3155. -#define EL3HLT 46
  3156. -#define EL3RST 47
  3157. -#define ELNRNG 48
  3158. -#define EUNATCH 49
  3159. -#define ENOCSI 50
  3160. -#define EL2HLT 51
  3161. -#define EBADE 52
  3162. -#define EBADR 53
  3163. -#define EXFULL 54
  3164. -#define ENOANO 55
  3165. -#define EBADRQC 56
  3166. -#define EBADSLT 57
  3167. -#define EDEADLOCK EDEADLK
  3168. -#define EBFONT 59
  3169. -#define ENOSTR 60
  3170. -#define ENODATA 61
  3171. -#define ETIME 62
  3172. -#define ENOSR 63
  3173. -#define ENONET 64
  3174. -#define ENOPKG 65
  3175. -#define EREMOTE 66
  3176. -#define ENOLINK 67
  3177. -#define EADV 68
  3178. -#define ESRMNT 69
  3179. -#define ECOMM 70
  3180. -#define EPROTO 71
  3181. -#define EMULTIHOP 72
  3182. -#define EDOTDOT 73
  3183. -#define EBADMSG 74
  3184. -#define EOVERFLOW 75
  3185. -#define ENOTUNIQ 76
  3186. -#define EBADFD 77
  3187. -#define EREMCHG 78
  3188. -#define ELIBACC 79
  3189. -#define ELIBBAD 80
  3190. -#define ELIBSCN 81
  3191. -#define ELIBMAX 82
  3192. -#define ELIBEXEC 83
  3193. -#define EILSEQ 84
  3194. -#define ERESTART 85
  3195. -#define ESTRPIPE 86
  3196. -#define EUSERS 87
  3197. -#define ENOTSOCK 88
  3198. -#define EDESTADDRREQ 89
  3199. -#define EMSGSIZE 90
  3200. -#define EPROTOTYPE 91
  3201. -#define ENOPROTOOPT 92
  3202. -#define EPROTONOSUPPORT 93
  3203. -#define ESOCKTNOSUPPORT 94
  3204. -#define EOPNOTSUPP 95
  3205. -#define ENOTSUP EOPNOTSUPP
  3206. -#define EPFNOSUPPORT 96
  3207. -#define EAFNOSUPPORT 97
  3208. -#define EADDRINUSE 98
  3209. -#define EADDRNOTAVAIL 99
  3210. -#define ENETDOWN 100
  3211. -#define ENETUNREACH 101
  3212. -#define ENETRESET 102
  3213. -#define ECONNABORTED 103
  3214. -#define ECONNRESET 104
  3215. -#define ENOBUFS 105
  3216. -#define EISCONN 106
  3217. -#define ENOTCONN 107
  3218. -#define ESHUTDOWN 108
  3219. -#define ETOOMANYREFS 109
  3220. -#define ETIMEDOUT 110
  3221. -#define ECONNREFUSED 111
  3222. -#define EHOSTDOWN 112
  3223. -#define EHOSTUNREACH 113
  3224. -#define EALREADY 114
  3225. -#define EINPROGRESS 115
  3226. -#define ESTALE 116
  3227. -#define EUCLEAN 117
  3228. -#define ENOTNAM 118
  3229. -#define ENAVAIL 119
  3230. -#define EISNAM 120
  3231. -#define EREMOTEIO 121
  3232. -#define EDQUOT 122
  3233. -#define ENOMEDIUM 123
  3234. -#define EMEDIUMTYPE 124
  3235. -#define ECANCELED 125
  3236. -#define ENOKEY 126
  3237. -#define EKEYEXPIRED 127
  3238. -#define EKEYREVOKED 128
  3239. -#define EKEYREJECTED 129
  3240. -#define EOWNERDEAD 130
  3241. -#define ENOTRECOVERABLE 131
  3242. -#define ERFKILL 132
  3243. -#define EHWPOISON 133
  3244. --- a/arch/i386/bits/fcntl.h
  3245. +++ /dev/null
  3246. @@ -1,40 +0,0 @@
  3247. -#define O_CREAT 0100
  3248. -#define O_EXCL 0200
  3249. -#define O_NOCTTY 0400
  3250. -#define O_TRUNC 01000
  3251. -#define O_APPEND 02000
  3252. -#define O_NONBLOCK 04000
  3253. -#define O_DSYNC 010000
  3254. -#define O_SYNC 04010000
  3255. -#define O_RSYNC 04010000
  3256. -#define O_DIRECTORY 0200000
  3257. -#define O_NOFOLLOW 0400000
  3258. -#define O_CLOEXEC 02000000
  3259. -
  3260. -#define O_ASYNC 020000
  3261. -#define O_DIRECT 040000
  3262. -#define O_LARGEFILE 0100000
  3263. -#define O_NOATIME 01000000
  3264. -#define O_PATH 010000000
  3265. -#define O_TMPFILE 020200000
  3266. -#define O_NDELAY O_NONBLOCK
  3267. -
  3268. -#define F_DUPFD 0
  3269. -#define F_GETFD 1
  3270. -#define F_SETFD 2
  3271. -#define F_GETFL 3
  3272. -#define F_SETFL 4
  3273. -
  3274. -#define F_SETOWN 8
  3275. -#define F_GETOWN 9
  3276. -#define F_SETSIG 10
  3277. -#define F_GETSIG 11
  3278. -
  3279. -#define F_GETLK 12
  3280. -#define F_SETLK 13
  3281. -#define F_SETLKW 14
  3282. -
  3283. -#define F_SETOWN_EX 15
  3284. -#define F_GETOWN_EX 16
  3285. -
  3286. -#define F_GETOWNER_UIDS 17
  3287. --- a/arch/i386/bits/ioctl.h
  3288. +++ /dev/null
  3289. @@ -1,197 +0,0 @@
  3290. -#define _IOC(a,b,c,d) ( ((a)<<30) | ((b)<<8) | (c) | ((d)<<16) )
  3291. -#define _IOC_NONE 0U
  3292. -#define _IOC_WRITE 1U
  3293. -#define _IOC_READ 2U
  3294. -
  3295. -#define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0)
  3296. -#define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),sizeof(c))
  3297. -#define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),sizeof(c))
  3298. -#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE,(a),(b),sizeof(c))
  3299. -
  3300. -#define TCGETS 0x5401
  3301. -#define TCSETS 0x5402
  3302. -#define TCSETSW 0x5403
  3303. -#define TCSETSF 0x5404
  3304. -#define TCGETA 0x5405
  3305. -#define TCSETA 0x5406
  3306. -#define TCSETAW 0x5407
  3307. -#define TCSETAF 0x5408
  3308. -#define TCSBRK 0x5409
  3309. -#define TCXONC 0x540A
  3310. -#define TCFLSH 0x540B
  3311. -#define TIOCEXCL 0x540C
  3312. -#define TIOCNXCL 0x540D
  3313. -#define TIOCSCTTY 0x540E
  3314. -#define TIOCGPGRP 0x540F
  3315. -#define TIOCSPGRP 0x5410
  3316. -#define TIOCOUTQ 0x5411
  3317. -#define TIOCSTI 0x5412
  3318. -#define TIOCGWINSZ 0x5413
  3319. -#define TIOCSWINSZ 0x5414
  3320. -#define TIOCMGET 0x5415
  3321. -#define TIOCMBIS 0x5416
  3322. -#define TIOCMBIC 0x5417
  3323. -#define TIOCMSET 0x5418
  3324. -#define TIOCGSOFTCAR 0x5419
  3325. -#define TIOCSSOFTCAR 0x541A
  3326. -#define FIONREAD 0x541B
  3327. -#define TIOCINQ FIONREAD
  3328. -#define TIOCLINUX 0x541C
  3329. -#define TIOCCONS 0x541D
  3330. -#define TIOCGSERIAL 0x541E
  3331. -#define TIOCSSERIAL 0x541F
  3332. -#define TIOCPKT 0x5420
  3333. -#define FIONBIO 0x5421
  3334. -#define TIOCNOTTY 0x5422
  3335. -#define TIOCSETD 0x5423
  3336. -#define TIOCGETD 0x5424
  3337. -#define TCSBRKP 0x5425
  3338. -#define TIOCTTYGSTRUCT 0x5426
  3339. -#define TIOCSBRK 0x5427
  3340. -#define TIOCCBRK 0x5428
  3341. -#define TIOCGSID 0x5429
  3342. -#define TIOCGPTN 0x80045430
  3343. -#define TIOCSPTLCK 0x40045431
  3344. -#define TCGETX 0x5432
  3345. -#define TCSETX 0x5433
  3346. -#define TCSETXF 0x5434
  3347. -#define TCSETXW 0x5435
  3348. -
  3349. -#define FIONCLEX 0x5450
  3350. -#define FIOCLEX 0x5451
  3351. -#define FIOASYNC 0x5452
  3352. -#define TIOCSERCONFIG 0x5453
  3353. -#define TIOCSERGWILD 0x5454
  3354. -#define TIOCSERSWILD 0x5455
  3355. -#define TIOCGLCKTRMIOS 0x5456
  3356. -#define TIOCSLCKTRMIOS 0x5457
  3357. -#define TIOCSERGSTRUCT 0x5458
  3358. -#define TIOCSERGETLSR 0x5459
  3359. -#define TIOCSERGETMULTI 0x545A
  3360. -#define TIOCSERSETMULTI 0x545B
  3361. -
  3362. -#define TIOCMIWAIT 0x545C
  3363. -#define TIOCGICOUNT 0x545D
  3364. -#define TIOCGHAYESESP 0x545E
  3365. -#define TIOCSHAYESESP 0x545F
  3366. -#define FIOQSIZE 0x5460
  3367. -
  3368. -#define TIOCPKT_DATA 0
  3369. -#define TIOCPKT_FLUSHREAD 1
  3370. -#define TIOCPKT_FLUSHWRITE 2
  3371. -#define TIOCPKT_STOP 4
  3372. -#define TIOCPKT_START 8
  3373. -#define TIOCPKT_NOSTOP 16
  3374. -#define TIOCPKT_DOSTOP 32
  3375. -#define TIOCPKT_IOCTL 64
  3376. -
  3377. -#define TIOCSER_TEMT 0x01
  3378. -
  3379. -struct winsize {
  3380. - unsigned short ws_row;
  3381. - unsigned short ws_col;
  3382. - unsigned short ws_xpixel;
  3383. - unsigned short ws_ypixel;
  3384. -};
  3385. -
  3386. -#define TIOCM_LE 0x001
  3387. -#define TIOCM_DTR 0x002
  3388. -#define TIOCM_RTS 0x004
  3389. -#define TIOCM_ST 0x008
  3390. -#define TIOCM_SR 0x010
  3391. -#define TIOCM_CTS 0x020
  3392. -#define TIOCM_CAR 0x040
  3393. -#define TIOCM_RNG 0x080
  3394. -#define TIOCM_DSR 0x100
  3395. -#define TIOCM_CD TIOCM_CAR
  3396. -#define TIOCM_RI TIOCM_RNG
  3397. -#define TIOCM_OUT1 0x2000
  3398. -#define TIOCM_OUT2 0x4000
  3399. -#define TIOCM_LOOP 0x8000
  3400. -#define TIOCM_MODEM_BITS TIOCM_OUT2
  3401. -
  3402. -#define N_TTY 0
  3403. -#define N_SLIP 1
  3404. -#define N_MOUSE 2
  3405. -#define N_PPP 3
  3406. -#define N_STRIP 4
  3407. -#define N_AX25 5
  3408. -#define N_X25 6
  3409. -#define N_6PACK 7
  3410. -#define N_MASC 8
  3411. -#define N_R3964 9
  3412. -#define N_PROFIBUS_FDL 10
  3413. -#define N_IRDA 11
  3414. -#define N_SMSBLOCK 12
  3415. -#define N_HDLC 13
  3416. -#define N_SYNC_PPP 14
  3417. -#define N_HCI 15
  3418. -
  3419. -#define FIOSETOWN 0x8901
  3420. -#define SIOCSPGRP 0x8902
  3421. -#define FIOGETOWN 0x8903
  3422. -#define SIOCGPGRP 0x8904
  3423. -#define SIOCATMARK 0x8905
  3424. -#define SIOCGSTAMP 0x8906
  3425. -
  3426. -#define SIOCADDRT 0x890B
  3427. -#define SIOCDELRT 0x890C
  3428. -#define SIOCRTMSG 0x890D
  3429. -
  3430. -#define SIOCGIFNAME 0x8910
  3431. -#define SIOCSIFLINK 0x8911
  3432. -#define SIOCGIFCONF 0x8912
  3433. -#define SIOCGIFFLAGS 0x8913
  3434. -#define SIOCSIFFLAGS 0x8914
  3435. -#define SIOCGIFADDR 0x8915
  3436. -#define SIOCSIFADDR 0x8916
  3437. -#define SIOCGIFDSTADDR 0x8917
  3438. -#define SIOCSIFDSTADDR 0x8918
  3439. -#define SIOCGIFBRDADDR 0x8919
  3440. -#define SIOCSIFBRDADDR 0x891a
  3441. -#define SIOCGIFNETMASK 0x891b
  3442. -#define SIOCSIFNETMASK 0x891c
  3443. -#define SIOCGIFMETRIC 0x891d
  3444. -#define SIOCSIFMETRIC 0x891e
  3445. -#define SIOCGIFMEM 0x891f
  3446. -#define SIOCSIFMEM 0x8920
  3447. -#define SIOCGIFMTU 0x8921
  3448. -#define SIOCSIFMTU 0x8922
  3449. -#define SIOCSIFHWADDR 0x8924
  3450. -#define SIOCGIFENCAP 0x8925
  3451. -#define SIOCSIFENCAP 0x8926
  3452. -#define SIOCGIFHWADDR 0x8927
  3453. -#define SIOCGIFSLAVE 0x8929
  3454. -#define SIOCSIFSLAVE 0x8930
  3455. -#define SIOCADDMULTI 0x8931
  3456. -#define SIOCDELMULTI 0x8932
  3457. -#define SIOCGIFINDEX 0x8933
  3458. -#define SIOGIFINDEX SIOCGIFINDEX
  3459. -#define SIOCSIFPFLAGS 0x8934
  3460. -#define SIOCGIFPFLAGS 0x8935
  3461. -#define SIOCDIFADDR 0x8936
  3462. -#define SIOCSIFHWBROADCAST 0x8937
  3463. -#define SIOCGIFCOUNT 0x8938
  3464. -
  3465. -#define SIOCGIFBR 0x8940
  3466. -#define SIOCSIFBR 0x8941
  3467. -
  3468. -#define SIOCGIFTXQLEN 0x8942
  3469. -#define SIOCSIFTXQLEN 0x8943
  3470. -
  3471. -#define SIOCDARP 0x8953
  3472. -#define SIOCGARP 0x8954
  3473. -#define SIOCSARP 0x8955
  3474. -
  3475. -#define SIOCDRARP 0x8960
  3476. -#define SIOCGRARP 0x8961
  3477. -#define SIOCSRARP 0x8962
  3478. -
  3479. -#define SIOCGIFMAP 0x8970
  3480. -#define SIOCSIFMAP 0x8971
  3481. -
  3482. -#define SIOCADDDLCI 0x8980
  3483. -#define SIOCDELDLCI 0x8981
  3484. -
  3485. -#define SIOCDEVPRIVATE 0x89F0
  3486. -#define SIOCPROTOPRIVATE 0x89E0
  3487. --- a/arch/i386/bits/ipc.h
  3488. +++ /dev/null
  3489. @@ -1,14 +0,0 @@
  3490. -struct ipc_perm
  3491. -{
  3492. - key_t __ipc_perm_key;
  3493. - uid_t uid;
  3494. - gid_t gid;
  3495. - uid_t cuid;
  3496. - gid_t cgid;
  3497. - mode_t mode;
  3498. - int __ipc_perm_seq;
  3499. - long __pad1;
  3500. - long __pad2;
  3501. -};
  3502. -
  3503. -#define IPC_64 0x100
  3504. --- a/arch/i386/bits/mman.h
  3505. +++ b/arch/i386/bits/mman.h
  3506. @@ -38,6 +38,7 @@
  3507. #define MCL_CURRENT 1
  3508. #define MCL_FUTURE 2
  3509. +#define MCL_ONFAULT 4
  3510. #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  3511. #define MADV_NORMAL 0
  3512. --- a/arch/i386/bits/msg.h
  3513. +++ /dev/null
  3514. @@ -1,16 +0,0 @@
  3515. -struct msqid_ds
  3516. -{
  3517. - struct ipc_perm msg_perm;
  3518. - time_t msg_stime;
  3519. - int __unused1;
  3520. - time_t msg_rtime;
  3521. - int __unused2;
  3522. - time_t msg_ctime;
  3523. - int __unused3;
  3524. - unsigned long msg_cbytes;
  3525. - msgqnum_t msg_qnum;
  3526. - msglen_t msg_qbytes;
  3527. - pid_t msg_lspid;
  3528. - pid_t msg_lrpid;
  3529. - unsigned long __unused[2];
  3530. -};
  3531. --- a/arch/i386/bits/sem.h
  3532. +++ /dev/null
  3533. @@ -1,16 +0,0 @@
  3534. -struct semid_ds {
  3535. - struct ipc_perm sem_perm;
  3536. - time_t sem_otime;
  3537. - time_t __unused1;
  3538. - time_t sem_ctime;
  3539. - time_t __unused2;
  3540. -#if __BYTE_ORDER == __LITTLE_ENDIAN
  3541. - unsigned short sem_nsems;
  3542. - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
  3543. -#else
  3544. - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
  3545. - unsigned short sem_nsems;
  3546. -#endif
  3547. - time_t __unused3;
  3548. - time_t __unused4;
  3549. -};
  3550. --- a/arch/i386/bits/shm.h
  3551. +++ /dev/null
  3552. @@ -1,29 +0,0 @@
  3553. -#define SHMLBA 4096
  3554. -
  3555. -struct shmid_ds
  3556. -{
  3557. - struct ipc_perm shm_perm;
  3558. - size_t shm_segsz;
  3559. - time_t shm_atime;
  3560. - int __unused1;
  3561. - time_t shm_dtime;
  3562. - int __unused2;
  3563. - time_t shm_ctime;
  3564. - int __unused3;
  3565. - pid_t shm_cpid;
  3566. - pid_t shm_lpid;
  3567. - unsigned long shm_nattch;
  3568. - unsigned long __pad1;
  3569. - unsigned long __pad2;
  3570. -};
  3571. -
  3572. -struct shminfo {
  3573. - unsigned long shmmax, shmmin, shmmni, shmseg, shmall, __unused[4];
  3574. -};
  3575. -
  3576. -struct shm_info {
  3577. - int __used_ids;
  3578. - unsigned long shm_tot, shm_rss, shm_swp;
  3579. - unsigned long __swap_attempts, __swap_successes;
  3580. -};
  3581. -
  3582. --- a/arch/i386/bits/socket.h
  3583. +++ /dev/null
  3584. @@ -1,17 +0,0 @@
  3585. -struct msghdr
  3586. -{
  3587. - void *msg_name;
  3588. - socklen_t msg_namelen;
  3589. - struct iovec *msg_iov;
  3590. - int msg_iovlen;
  3591. - void *msg_control;
  3592. - socklen_t msg_controllen;
  3593. - int msg_flags;
  3594. -};
  3595. -
  3596. -struct cmsghdr
  3597. -{
  3598. - socklen_t cmsg_len;
  3599. - int cmsg_level;
  3600. - int cmsg_type;
  3601. -};
  3602. --- a/arch/i386/bits/statfs.h
  3603. +++ /dev/null
  3604. @@ -1,7 +0,0 @@
  3605. -struct statfs {
  3606. - unsigned long f_type, f_bsize;
  3607. - fsblkcnt_t f_blocks, f_bfree, f_bavail;
  3608. - fsfilcnt_t f_files, f_ffree;
  3609. - fsid_t f_fsid;
  3610. - unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
  3611. -};
  3612. --- a/arch/i386/bits/syscall.h
  3613. +++ b/arch/i386/bits/syscall.h
  3614. @@ -357,6 +357,24 @@
  3615. #define __NR_memfd_create 356
  3616. #define __NR_bpf 357
  3617. #define __NR_execveat 358
  3618. +#define __NR_socket 359
  3619. +#define __NR_socketpair 360
  3620. +#define __NR_bind 361
  3621. +#define __NR_connect 362
  3622. +#define __NR_listen 363
  3623. +#define __NR_accept4 364
  3624. +#define __NR_getsockopt 365
  3625. +#define __NR_setsockopt 366
  3626. +#define __NR_getsockname 367
  3627. +#define __NR_getpeername 368
  3628. +#define __NR_sendto 369
  3629. +#define __NR_sendmsg 370
  3630. +#define __NR_recvfrom 371
  3631. +#define __NR_recvmsg 372
  3632. +#define __NR_shutdown 373
  3633. +#define __NR_userfaultfd 374
  3634. +#define __NR_membarrier 375
  3635. +#define __NR_mlock2 376
  3636. /* Repeated with SYS_ prefix */
  3637. @@ -720,3 +738,21 @@
  3638. #define SYS_memfd_create 356
  3639. #define SYS_bpf 357
  3640. #define SYS_execveat 358
  3641. +#define SYS_socket 359
  3642. +#define SYS_socketpair 360
  3643. +#define SYS_bind 361
  3644. +#define SYS_connect 362
  3645. +#define SYS_listen 363
  3646. +#define SYS_accept4 364
  3647. +#define SYS_getsockopt 365
  3648. +#define SYS_setsockopt 366
  3649. +#define SYS_getsockname 367
  3650. +#define SYS_getpeername 368
  3651. +#define SYS_sendto 369
  3652. +#define SYS_sendmsg 370
  3653. +#define SYS_recvfrom 371
  3654. +#define SYS_recvmsg 372
  3655. +#define SYS_shutdown 373
  3656. +#define SYS_userfaultfd 374
  3657. +#define SYS_membarrier 375
  3658. +#define SYS_mlock2 376
  3659. --- a/arch/i386/bits/termios.h
  3660. +++ /dev/null
  3661. @@ -1,160 +0,0 @@
  3662. -struct termios
  3663. -{
  3664. - tcflag_t c_iflag;
  3665. - tcflag_t c_oflag;
  3666. - tcflag_t c_cflag;
  3667. - tcflag_t c_lflag;
  3668. - cc_t c_line;
  3669. - cc_t c_cc[NCCS];
  3670. - speed_t __c_ispeed;
  3671. - speed_t __c_ospeed;
  3672. -};
  3673. -
  3674. -#define VINTR 0
  3675. -#define VQUIT 1
  3676. -#define VERASE 2
  3677. -#define VKILL 3
  3678. -#define VEOF 4
  3679. -#define VTIME 5
  3680. -#define VMIN 6
  3681. -#define VSWTC 7
  3682. -#define VSTART 8
  3683. -#define VSTOP 9
  3684. -#define VSUSP 10
  3685. -#define VEOL 11
  3686. -#define VREPRINT 12
  3687. -#define VDISCARD 13
  3688. -#define VWERASE 14
  3689. -#define VLNEXT 15
  3690. -#define VEOL2 16
  3691. -
  3692. -#define IGNBRK 0000001
  3693. -#define BRKINT 0000002
  3694. -#define IGNPAR 0000004
  3695. -#define PARMRK 0000010
  3696. -#define INPCK 0000020
  3697. -#define ISTRIP 0000040
  3698. -#define INLCR 0000100
  3699. -#define IGNCR 0000200
  3700. -#define ICRNL 0000400
  3701. -#define IUCLC 0001000
  3702. -#define IXON 0002000
  3703. -#define IXANY 0004000
  3704. -#define IXOFF 0010000
  3705. -#define IMAXBEL 0020000
  3706. -#define IUTF8 0040000
  3707. -
  3708. -#define OPOST 0000001
  3709. -#define OLCUC 0000002
  3710. -#define ONLCR 0000004
  3711. -#define OCRNL 0000010
  3712. -#define ONOCR 0000020
  3713. -#define ONLRET 0000040
  3714. -#define OFILL 0000100
  3715. -#define OFDEL 0000200
  3716. -#define NLDLY 0000400
  3717. -#define NL0 0000000
  3718. -#define NL1 0000400
  3719. -#define CRDLY 0003000
  3720. -#define CR0 0000000
  3721. -#define CR1 0001000
  3722. -#define CR2 0002000
  3723. -#define CR3 0003000
  3724. -#define TABDLY 0014000
  3725. -#define TAB0 0000000
  3726. -#define TAB1 0004000
  3727. -#define TAB2 0010000
  3728. -#define TAB3 0014000
  3729. -#define BSDLY 0020000
  3730. -#define BS0 0000000
  3731. -#define BS1 0020000
  3732. -#define FFDLY 0100000
  3733. -#define FF0 0000000
  3734. -#define FF1 0100000
  3735. -
  3736. -#define VTDLY 0040000
  3737. -#define VT0 0000000
  3738. -#define VT1 0040000
  3739. -
  3740. -#define B0 0000000
  3741. -#define B50 0000001
  3742. -#define B75 0000002
  3743. -#define B110 0000003
  3744. -#define B134 0000004
  3745. -#define B150 0000005
  3746. -#define B200 0000006
  3747. -#define B300 0000007
  3748. -#define B600 0000010
  3749. -#define B1200 0000011
  3750. -#define B1800 0000012
  3751. -#define B2400 0000013
  3752. -#define B4800 0000014
  3753. -#define B9600 0000015
  3754. -#define B19200 0000016
  3755. -#define B38400 0000017
  3756. -
  3757. -#define B57600 0010001
  3758. -#define B115200 0010002
  3759. -#define B230400 0010003
  3760. -#define B460800 0010004
  3761. -#define B500000 0010005
  3762. -#define B576000 0010006
  3763. -#define B921600 0010007
  3764. -#define B1000000 0010010
  3765. -#define B1152000 0010011
  3766. -#define B1500000 0010012
  3767. -#define B2000000 0010013
  3768. -#define B2500000 0010014
  3769. -#define B3000000 0010015
  3770. -#define B3500000 0010016
  3771. -#define B4000000 0010017
  3772. -
  3773. -#define CBAUD 0010017
  3774. -
  3775. -#define CSIZE 0000060
  3776. -#define CS5 0000000
  3777. -#define CS6 0000020
  3778. -#define CS7 0000040
  3779. -#define CS8 0000060
  3780. -#define CSTOPB 0000100
  3781. -#define CREAD 0000200
  3782. -#define PARENB 0000400
  3783. -#define PARODD 0001000
  3784. -#define HUPCL 0002000
  3785. -#define CLOCAL 0004000
  3786. -
  3787. -#define ISIG 0000001
  3788. -#define ICANON 0000002
  3789. -#define ECHO 0000010
  3790. -#define ECHOE 0000020
  3791. -#define ECHOK 0000040
  3792. -#define ECHONL 0000100
  3793. -#define NOFLSH 0000200
  3794. -#define TOSTOP 0000400
  3795. -#define IEXTEN 0100000
  3796. -
  3797. -#define ECHOCTL 0001000
  3798. -#define ECHOPRT 0002000
  3799. -#define ECHOKE 0004000
  3800. -#define FLUSHO 0010000
  3801. -#define PENDIN 0040000
  3802. -
  3803. -#define TCOOFF 0
  3804. -#define TCOON 1
  3805. -#define TCIOFF 2
  3806. -#define TCION 3
  3807. -
  3808. -#define TCIFLUSH 0
  3809. -#define TCOFLUSH 1
  3810. -#define TCIOFLUSH 2
  3811. -
  3812. -#define TCSANOW 0
  3813. -#define TCSADRAIN 1
  3814. -#define TCSAFLUSH 2
  3815. -
  3816. -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  3817. -#define CBAUDEX 0010000
  3818. -#define CRTSCTS 020000000000
  3819. -#define EXTPROC 0200000
  3820. -#define XTABS 0014000
  3821. -#endif
  3822. --- a/arch/i386/pthread_arch.h
  3823. +++ b/arch/i386/pthread_arch.h
  3824. @@ -7,4 +7,4 @@ static inline struct pthread *__pthread_
  3825. #define TP_ADJ(p) (p)
  3826. -#define CANCEL_REG_IP 14
  3827. +#define MC_PC gregs[REG_EIP]
  3828. --- a/arch/i386/syscall_arch.h
  3829. +++ b/arch/i386/syscall_arch.h
  3830. @@ -55,3 +55,5 @@ static inline long __syscall6(long n, lo
  3831. #define VDSO_USEFUL
  3832. #define VDSO_CGT_SYM "__vdso_clock_gettime"
  3833. #define VDSO_CGT_VER "LINUX_2.6"
  3834. +
  3835. +#define SYSCALL_USE_SOCKETCALL
  3836. --- a/arch/microblaze/atomic.h
  3837. +++ /dev/null
  3838. @@ -1,143 +0,0 @@
  3839. -#ifndef _INTERNAL_ATOMIC_H
  3840. -#define _INTERNAL_ATOMIC_H
  3841. -
  3842. -#include <stdint.h>
  3843. -
  3844. -static inline int a_ctz_l(unsigned long x)
  3845. -{
  3846. - static const char debruijn32[32] = {
  3847. - 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13,
  3848. - 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14
  3849. - };
  3850. - return debruijn32[(x&-x)*0x076be629 >> 27];
  3851. -}
  3852. -
  3853. -static inline int a_ctz_64(uint64_t x)
  3854. -{
  3855. - uint32_t y = x;
  3856. - if (!y) {
  3857. - y = x>>32;
  3858. - return 32 + a_ctz_l(y);
  3859. - }
  3860. - return a_ctz_l(y);
  3861. -}
  3862. -
  3863. -static inline int a_cas(volatile int *p, int t, int s)
  3864. -{
  3865. - register int old, tmp;
  3866. - __asm__ __volatile__ (
  3867. - " addi %0, r0, 0\n"
  3868. - "1: lwx %0, %2, r0\n"
  3869. - " rsubk %1, %0, %3\n"
  3870. - " bnei %1, 1f\n"
  3871. - " swx %4, %2, r0\n"
  3872. - " addic %1, r0, 0\n"
  3873. - " bnei %1, 1b\n"
  3874. - "1: "
  3875. - : "=&r"(old), "=&r"(tmp)
  3876. - : "r"(p), "r"(t), "r"(s)
  3877. - : "cc", "memory" );
  3878. - return old;
  3879. -}
  3880. -
  3881. -static inline void *a_cas_p(volatile void *p, void *t, void *s)
  3882. -{
  3883. - return (void *)a_cas(p, (int)t, (int)s);
  3884. -}
  3885. -
  3886. -static inline int a_swap(volatile int *x, int v)
  3887. -{
  3888. - register int old, tmp;
  3889. - __asm__ __volatile__ (
  3890. - " addi %0, r0, 0\n"
  3891. - "1: lwx %0, %2, r0\n"
  3892. - " swx %3, %2, r0\n"
  3893. - " addic %1, r0, 0\n"
  3894. - " bnei %1, 1b\n"
  3895. - "1: "
  3896. - : "=&r"(old), "=&r"(tmp)
  3897. - : "r"(x), "r"(v)
  3898. - : "cc", "memory" );
  3899. - return old;
  3900. -}
  3901. -
  3902. -static inline int a_fetch_add(volatile int *x, int v)
  3903. -{
  3904. - register int new, tmp;
  3905. - __asm__ __volatile__ (
  3906. - " addi %0, r0, 0\n"
  3907. - "1: lwx %0, %2, r0\n"
  3908. - " addk %0, %0, %3\n"
  3909. - " swx %0, %2, r0\n"
  3910. - " addic %1, r0, 0\n"
  3911. - " bnei %1, 1b\n"
  3912. - "1: "
  3913. - : "=&r"(new), "=&r"(tmp)
  3914. - : "r"(x), "r"(v)
  3915. - : "cc", "memory" );
  3916. - return new-v;
  3917. -}
  3918. -
  3919. -static inline void a_inc(volatile int *x)
  3920. -{
  3921. - a_fetch_add(x, 1);
  3922. -}
  3923. -
  3924. -static inline void a_dec(volatile int *x)
  3925. -{
  3926. - a_fetch_add(x, -1);
  3927. -}
  3928. -
  3929. -static inline void a_store(volatile int *p, int x)
  3930. -{
  3931. - __asm__ __volatile__ (
  3932. - "swi %1, %0"
  3933. - : "=m"(*p) : "r"(x) : "memory" );
  3934. -}
  3935. -
  3936. -#define a_spin a_barrier
  3937. -
  3938. -static inline void a_barrier()
  3939. -{
  3940. - a_cas(&(int){0}, 0, 0);
  3941. -}
  3942. -
  3943. -static inline void a_crash()
  3944. -{
  3945. - *(volatile char *)0=0;
  3946. -}
  3947. -
  3948. -static inline void a_and(volatile int *p, int v)
  3949. -{
  3950. - int old;
  3951. - do old = *p;
  3952. - while (a_cas(p, old, old&v) != old);
  3953. -}
  3954. -
  3955. -static inline void a_or(volatile int *p, int v)
  3956. -{
  3957. - int old;
  3958. - do old = *p;
  3959. - while (a_cas(p, old, old|v) != old);
  3960. -}
  3961. -
  3962. -static inline void a_or_l(volatile void *p, long v)
  3963. -{
  3964. - a_or(p, v);
  3965. -}
  3966. -
  3967. -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
  3968. -{
  3969. - union { uint64_t v; uint32_t r[2]; } u = { v };
  3970. - a_and((int *)p, u.r[0]);
  3971. - a_and((int *)p+1, u.r[1]);
  3972. -}
  3973. -
  3974. -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
  3975. -{
  3976. - union { uint64_t v; uint32_t r[2]; } u = { v };
  3977. - a_or((int *)p, u.r[0]);
  3978. - a_or((int *)p+1, u.r[1]);
  3979. -}
  3980. -
  3981. -#endif
  3982. --- /dev/null
  3983. +++ b/arch/microblaze/atomic_arch.h
  3984. @@ -0,0 +1,53 @@
  3985. +#define a_cas a_cas
  3986. +static inline int a_cas(volatile int *p, int t, int s)
  3987. +{
  3988. + register int old, tmp;
  3989. + __asm__ __volatile__ (
  3990. + " addi %0, r0, 0\n"
  3991. + "1: lwx %0, %2, r0\n"
  3992. + " rsubk %1, %0, %3\n"
  3993. + " bnei %1, 1f\n"
  3994. + " swx %4, %2, r0\n"
  3995. + " addic %1, r0, 0\n"
  3996. + " bnei %1, 1b\n"
  3997. + "1: "
  3998. + : "=&r"(old), "=&r"(tmp)
  3999. + : "r"(p), "r"(t), "r"(s)
  4000. + : "cc", "memory" );
  4001. + return old;
  4002. +}
  4003. +
  4004. +#define a_swap a_swap
  4005. +static inline int a_swap(volatile int *x, int v)
  4006. +{
  4007. + register int old, tmp;
  4008. + __asm__ __volatile__ (
  4009. + " addi %0, r0, 0\n"
  4010. + "1: lwx %0, %2, r0\n"
  4011. + " swx %3, %2, r0\n"
  4012. + " addic %1, r0, 0\n"
  4013. + " bnei %1, 1b\n"
  4014. + "1: "
  4015. + : "=&r"(old), "=&r"(tmp)
  4016. + : "r"(x), "r"(v)
  4017. + : "cc", "memory" );
  4018. + return old;
  4019. +}
  4020. +
  4021. +#define a_fetch_add a_fetch_add
  4022. +static inline int a_fetch_add(volatile int *x, int v)
  4023. +{
  4024. + register int new, tmp;
  4025. + __asm__ __volatile__ (
  4026. + " addi %0, r0, 0\n"
  4027. + "1: lwx %0, %2, r0\n"
  4028. + " addk %0, %0, %3\n"
  4029. + " swx %0, %2, r0\n"
  4030. + " addic %1, r0, 0\n"
  4031. + " bnei %1, 1b\n"
  4032. + "1: "
  4033. + : "=&r"(new), "=&r"(tmp)
  4034. + : "r"(x), "r"(v)
  4035. + : "cc", "memory" );
  4036. + return new-v;
  4037. +}
  4038. --- a/arch/microblaze/bits/errno.h
  4039. +++ /dev/null
  4040. @@ -1,134 +0,0 @@
  4041. -#define EPERM 1
  4042. -#define ENOENT 2
  4043. -#define ESRCH 3
  4044. -#define EINTR 4
  4045. -#define EIO 5
  4046. -#define ENXIO 6
  4047. -#define E2BIG 7
  4048. -#define ENOEXEC 8
  4049. -#define EBADF 9
  4050. -#define ECHILD 10
  4051. -#define EAGAIN 11
  4052. -#define ENOMEM 12
  4053. -#define EACCES 13
  4054. -#define EFAULT 14
  4055. -#define ENOTBLK 15
  4056. -#define EBUSY 16
  4057. -#define EEXIST 17
  4058. -#define EXDEV 18
  4059. -#define ENODEV 19
  4060. -#define ENOTDIR 20
  4061. -#define EISDIR 21
  4062. -#define EINVAL 22
  4063. -#define ENFILE 23
  4064. -#define EMFILE 24
  4065. -#define ENOTTY 25
  4066. -#define ETXTBSY 26
  4067. -#define EFBIG 27
  4068. -#define ENOSPC 28
  4069. -#define ESPIPE 29
  4070. -#define EROFS 30
  4071. -#define EMLINK 31
  4072. -#define EPIPE 32
  4073. -#define EDOM 33
  4074. -#define ERANGE 34
  4075. -#define EDEADLK 35
  4076. -#define ENAMETOOLONG 36
  4077. -#define ENOLCK 37
  4078. -#define ENOSYS 38
  4079. -#define ENOTEMPTY 39
  4080. -#define ELOOP 40
  4081. -#define EWOULDBLOCK EAGAIN
  4082. -#define ENOMSG 42
  4083. -#define EIDRM 43
  4084. -#define ECHRNG 44
  4085. -#define EL2NSYNC 45
  4086. -#define EL3HLT 46
  4087. -#define EL3RST 47
  4088. -#define ELNRNG 48
  4089. -#define EUNATCH 49
  4090. -#define ENOCSI 50
  4091. -#define EL2HLT 51
  4092. -#define EBADE 52
  4093. -#define EBADR 53
  4094. -#define EXFULL 54
  4095. -#define ENOANO 55
  4096. -#define EBADRQC 56
  4097. -#define EBADSLT 57
  4098. -#define EDEADLOCK EDEADLK
  4099. -#define EBFONT 59
  4100. -#define ENOSTR 60
  4101. -#define ENODATA 61
  4102. -#define ETIME 62
  4103. -#define ENOSR 63
  4104. -#define ENONET 64
  4105. -#define ENOPKG 65
  4106. -#define EREMOTE 66
  4107. -#define ENOLINK 67
  4108. -#define EADV 68
  4109. -#define ESRMNT 69
  4110. -#define ECOMM 70
  4111. -#define EPROTO 71
  4112. -#define EMULTIHOP 72
  4113. -#define EDOTDOT 73
  4114. -#define EBADMSG 74
  4115. -#define EOVERFLOW 75
  4116. -#define ENOTUNIQ 76
  4117. -#define EBADFD 77
  4118. -#define EREMCHG 78
  4119. -#define ELIBACC 79
  4120. -#define ELIBBAD 80
  4121. -#define ELIBSCN 81
  4122. -#define ELIBMAX 82
  4123. -#define ELIBEXEC 83
  4124. -#define EILSEQ 84
  4125. -#define ERESTART 85
  4126. -#define ESTRPIPE 86
  4127. -#define EUSERS 87
  4128. -#define ENOTSOCK 88
  4129. -#define EDESTADDRREQ 89
  4130. -#define EMSGSIZE 90
  4131. -#define EPROTOTYPE 91
  4132. -#define ENOPROTOOPT 92
  4133. -#define EPROTONOSUPPORT 93
  4134. -#define ESOCKTNOSUPPORT 94
  4135. -#define EOPNOTSUPP 95
  4136. -#define ENOTSUP EOPNOTSUPP
  4137. -#define EPFNOSUPPORT 96
  4138. -#define EAFNOSUPPORT 97
  4139. -#define EADDRINUSE 98
  4140. -#define EADDRNOTAVAIL 99
  4141. -#define ENETDOWN 100
  4142. -#define ENETUNREACH 101
  4143. -#define ENETRESET 102
  4144. -#define ECONNABORTED 103
  4145. -#define ECONNRESET 104
  4146. -#define ENOBUFS 105
  4147. -#define EISCONN 106
  4148. -#define ENOTCONN 107
  4149. -#define ESHUTDOWN 108
  4150. -#define ETOOMANYREFS 109
  4151. -#define ETIMEDOUT 110
  4152. -#define ECONNREFUSED 111
  4153. -#define EHOSTDOWN 112
  4154. -#define EHOSTUNREACH 113
  4155. -#define EALREADY 114
  4156. -#define EINPROGRESS 115
  4157. -#define ESTALE 116
  4158. -#define EUCLEAN 117
  4159. -#define ENOTNAM 118
  4160. -#define ENAVAIL 119
  4161. -#define EISNAM 120
  4162. -#define EREMOTEIO 121
  4163. -#define EDQUOT 122
  4164. -#define ENOMEDIUM 123
  4165. -#define EMEDIUMTYPE 124
  4166. -#define ECANCELED 125
  4167. -#define ENOKEY 126
  4168. -#define EKEYEXPIRED 127
  4169. -#define EKEYREVOKED 128
  4170. -#define EKEYREJECTED 129
  4171. -#define EOWNERDEAD 130
  4172. -#define ENOTRECOVERABLE 131
  4173. -#define ERFKILL 132
  4174. -#define EHWPOISON 133
  4175. --- a/arch/microblaze/bits/fcntl.h
  4176. +++ /dev/null
  4177. @@ -1,40 +0,0 @@
  4178. -#define O_CREAT 0100
  4179. -#define O_EXCL 0200
  4180. -#define O_NOCTTY 0400
  4181. -#define O_TRUNC 01000
  4182. -#define O_APPEND 02000
  4183. -#define O_NONBLOCK 04000
  4184. -#define O_DSYNC 010000
  4185. -#define O_SYNC 04010000
  4186. -#define O_RSYNC 04010000
  4187. -#define O_DIRECTORY 0200000
  4188. -#define O_NOFOLLOW 0400000
  4189. -#define O_CLOEXEC 02000000
  4190. -
  4191. -#define O_ASYNC 020000
  4192. -#define O_DIRECT 040000
  4193. -#define O_LARGEFILE 0100000
  4194. -#define O_NOATIME 01000000
  4195. -#define O_PATH 010000000
  4196. -#define O_TMPFILE 020200000
  4197. -#define O_NDELAY O_NONBLOCK
  4198. -
  4199. -#define F_DUPFD 0
  4200. -#define F_GETFD 1
  4201. -#define F_SETFD 2
  4202. -#define F_GETFL 3
  4203. -#define F_SETFL 4
  4204. -
  4205. -#define F_SETOWN 8
  4206. -#define F_GETOWN 9
  4207. -#define F_SETSIG 10
  4208. -#define F_GETSIG 11
  4209. -
  4210. -#define F_GETLK 12
  4211. -#define F_SETLK 13
  4212. -#define F_SETLKW 14
  4213. -
  4214. -#define F_SETOWN_EX 15
  4215. -#define F_GETOWN_EX 16
  4216. -
  4217. -#define F_GETOWNER_UIDS 17
  4218. --- a/arch/microblaze/bits/fenv.h
  4219. +++ /dev/null
  4220. @@ -1,10 +0,0 @@
  4221. -#define FE_ALL_EXCEPT 0
  4222. -#define FE_TONEAREST 0
  4223. -
  4224. -typedef unsigned long fexcept_t;
  4225. -
  4226. -typedef struct {
  4227. - unsigned long __cw;
  4228. -} fenv_t;
  4229. -
  4230. -#define FE_DFL_ENV ((const fenv_t *) -1)
  4231. --- a/arch/microblaze/bits/ioctl.h
  4232. +++ /dev/null
  4233. @@ -1,197 +0,0 @@
  4234. -#define _IOC(a,b,c,d) ( ((a)<<30) | ((b)<<8) | (c) | ((d)<<16) )
  4235. -#define _IOC_NONE 0U
  4236. -#define _IOC_WRITE 1U
  4237. -#define _IOC_READ 2U
  4238. -
  4239. -#define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0)
  4240. -#define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),sizeof(c))
  4241. -#define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),sizeof(c))
  4242. -#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE,(a),(b),sizeof(c))
  4243. -
  4244. -#define TCGETS 0x5401
  4245. -#define TCSETS 0x5402
  4246. -#define TCSETSW 0x5403
  4247. -#define TCSETSF 0x5404
  4248. -#define TCGETA 0x5405
  4249. -#define TCSETA 0x5406
  4250. -#define TCSETAW 0x5407
  4251. -#define TCSETAF 0x5408
  4252. -#define TCSBRK 0x5409
  4253. -#define TCXONC 0x540A
  4254. -#define TCFLSH 0x540B
  4255. -#define TIOCEXCL 0x540C
  4256. -#define TIOCNXCL 0x540D
  4257. -#define TIOCSCTTY 0x540E
  4258. -#define TIOCGPGRP 0x540F
  4259. -#define TIOCSPGRP 0x5410
  4260. -#define TIOCOUTQ 0x5411
  4261. -#define TIOCSTI 0x5412
  4262. -#define TIOCGWINSZ 0x5413
  4263. -#define TIOCSWINSZ 0x5414
  4264. -#define TIOCMGET 0x5415
  4265. -#define TIOCMBIS 0x5416
  4266. -#define TIOCMBIC 0x5417
  4267. -#define TIOCMSET 0x5418
  4268. -#define TIOCGSOFTCAR 0x5419
  4269. -#define TIOCSSOFTCAR 0x541A
  4270. -#define FIONREAD 0x541B
  4271. -#define TIOCINQ FIONREAD
  4272. -#define TIOCLINUX 0x541C
  4273. -#define TIOCCONS 0x541D
  4274. -#define TIOCGSERIAL 0x541E
  4275. -#define TIOCSSERIAL 0x541F
  4276. -#define TIOCPKT 0x5420
  4277. -#define FIONBIO 0x5421
  4278. -#define TIOCNOTTY 0x5422
  4279. -#define TIOCSETD 0x5423
  4280. -#define TIOCGETD 0x5424
  4281. -#define TCSBRKP 0x5425
  4282. -#define TIOCTTYGSTRUCT 0x5426
  4283. -#define TIOCSBRK 0x5427
  4284. -#define TIOCCBRK 0x5428
  4285. -#define TIOCGSID 0x5429
  4286. -#define TIOCGPTN 0x80045430
  4287. -#define TIOCSPTLCK 0x40045431
  4288. -#define TCGETX 0x5432
  4289. -#define TCSETX 0x5433
  4290. -#define TCSETXF 0x5434
  4291. -#define TCSETXW 0x5435
  4292. -
  4293. -#define FIONCLEX 0x5450
  4294. -#define FIOCLEX 0x5451
  4295. -#define FIOASYNC 0x5452
  4296. -#define TIOCSERCONFIG 0x5453
  4297. -#define TIOCSERGWILD 0x5454
  4298. -#define TIOCSERSWILD 0x5455
  4299. -#define TIOCGLCKTRMIOS 0x5456
  4300. -#define TIOCSLCKTRMIOS 0x5457
  4301. -#define TIOCSERGSTRUCT 0x5458
  4302. -#define TIOCSERGETLSR 0x5459
  4303. -#define TIOCSERGETMULTI 0x545A
  4304. -#define TIOCSERSETMULTI 0x545B
  4305. -
  4306. -#define TIOCMIWAIT 0x545C
  4307. -#define TIOCGICOUNT 0x545D
  4308. -#define TIOCGHAYESESP 0x545E
  4309. -#define TIOCSHAYESESP 0x545F
  4310. -#define FIOQSIZE 0x5460
  4311. -
  4312. -#define TIOCPKT_DATA 0
  4313. -#define TIOCPKT_FLUSHREAD 1
  4314. -#define TIOCPKT_FLUSHWRITE 2
  4315. -#define TIOCPKT_STOP 4
  4316. -#define TIOCPKT_START 8
  4317. -#define TIOCPKT_NOSTOP 16
  4318. -#define TIOCPKT_DOSTOP 32
  4319. -#define TIOCPKT_IOCTL 64
  4320. -
  4321. -#define TIOCSER_TEMT 0x01
  4322. -
  4323. -struct winsize {
  4324. - unsigned short ws_row;
  4325. - unsigned short ws_col;
  4326. - unsigned short ws_xpixel;
  4327. - unsigned short ws_ypixel;
  4328. -};
  4329. -
  4330. -#define TIOCM_LE 0x001
  4331. -#define TIOCM_DTR 0x002
  4332. -#define TIOCM_RTS 0x004
  4333. -#define TIOCM_ST 0x008
  4334. -#define TIOCM_SR 0x010
  4335. -#define TIOCM_CTS 0x020
  4336. -#define TIOCM_CAR 0x040
  4337. -#define TIOCM_RNG 0x080
  4338. -#define TIOCM_DSR 0x100
  4339. -#define TIOCM_CD TIOCM_CAR
  4340. -#define TIOCM_RI TIOCM_RNG
  4341. -#define TIOCM_OUT1 0x2000
  4342. -#define TIOCM_OUT2 0x4000
  4343. -#define TIOCM_LOOP 0x8000
  4344. -#define TIOCM_MODEM_BITS TIOCM_OUT2
  4345. -
  4346. -#define N_TTY 0
  4347. -#define N_SLIP 1
  4348. -#define N_MOUSE 2
  4349. -#define N_PPP 3
  4350. -#define N_STRIP 4
  4351. -#define N_AX25 5
  4352. -#define N_X25 6
  4353. -#define N_6PACK 7
  4354. -#define N_MASC 8
  4355. -#define N_R3964 9
  4356. -#define N_PROFIBUS_FDL 10
  4357. -#define N_IRDA 11
  4358. -#define N_SMSBLOCK 12
  4359. -#define N_HDLC 13
  4360. -#define N_SYNC_PPP 14
  4361. -#define N_HCI 15
  4362. -
  4363. -#define FIOSETOWN 0x8901
  4364. -#define SIOCSPGRP 0x8902
  4365. -#define FIOGETOWN 0x8903
  4366. -#define SIOCGPGRP 0x8904
  4367. -#define SIOCATMARK 0x8905
  4368. -#define SIOCGSTAMP 0x8906
  4369. -
  4370. -#define SIOCADDRT 0x890B
  4371. -#define SIOCDELRT 0x890C
  4372. -#define SIOCRTMSG 0x890D
  4373. -
  4374. -#define SIOCGIFNAME 0x8910
  4375. -#define SIOCSIFLINK 0x8911
  4376. -#define SIOCGIFCONF 0x8912
  4377. -#define SIOCGIFFLAGS 0x8913
  4378. -#define SIOCSIFFLAGS 0x8914
  4379. -#define SIOCGIFADDR 0x8915
  4380. -#define SIOCSIFADDR 0x8916
  4381. -#define SIOCGIFDSTADDR 0x8917
  4382. -#define SIOCSIFDSTADDR 0x8918
  4383. -#define SIOCGIFBRDADDR 0x8919
  4384. -#define SIOCSIFBRDADDR 0x891a
  4385. -#define SIOCGIFNETMASK 0x891b
  4386. -#define SIOCSIFNETMASK 0x891c
  4387. -#define SIOCGIFMETRIC 0x891d
  4388. -#define SIOCSIFMETRIC 0x891e
  4389. -#define SIOCGIFMEM 0x891f
  4390. -#define SIOCSIFMEM 0x8920
  4391. -#define SIOCGIFMTU 0x8921
  4392. -#define SIOCSIFMTU 0x8922
  4393. -#define SIOCSIFHWADDR 0x8924
  4394. -#define SIOCGIFENCAP 0x8925
  4395. -#define SIOCSIFENCAP 0x8926
  4396. -#define SIOCGIFHWADDR 0x8927
  4397. -#define SIOCGIFSLAVE 0x8929
  4398. -#define SIOCSIFSLAVE 0x8930
  4399. -#define SIOCADDMULTI 0x8931
  4400. -#define SIOCDELMULTI 0x8932
  4401. -#define SIOCGIFINDEX 0x8933
  4402. -#define SIOGIFINDEX SIOCGIFINDEX
  4403. -#define SIOCSIFPFLAGS 0x8934
  4404. -#define SIOCGIFPFLAGS 0x8935
  4405. -#define SIOCDIFADDR 0x8936
  4406. -#define SIOCSIFHWBROADCAST 0x8937
  4407. -#define SIOCGIFCOUNT 0x8938
  4408. -
  4409. -#define SIOCGIFBR 0x8940
  4410. -#define SIOCSIFBR 0x8941
  4411. -
  4412. -#define SIOCGIFTXQLEN 0x8942
  4413. -#define SIOCSIFTXQLEN 0x8943
  4414. -
  4415. -#define SIOCDARP 0x8953
  4416. -#define SIOCGARP 0x8954
  4417. -#define SIOCSARP 0x8955
  4418. -
  4419. -#define SIOCDRARP 0x8960
  4420. -#define SIOCGRARP 0x8961
  4421. -#define SIOCSRARP 0x8962
  4422. -
  4423. -#define SIOCGIFMAP 0x8970
  4424. -#define SIOCSIFMAP 0x8971
  4425. -
  4426. -#define SIOCADDDLCI 0x8980
  4427. -#define SIOCDELDLCI 0x8981
  4428. -
  4429. -#define SIOCDEVPRIVATE 0x89F0
  4430. -#define SIOCPROTOPRIVATE 0x89E0
  4431. --- a/arch/microblaze/bits/ipc.h
  4432. +++ /dev/null
  4433. @@ -1,14 +0,0 @@
  4434. -struct ipc_perm
  4435. -{
  4436. - key_t __ipc_perm_key;
  4437. - uid_t uid;
  4438. - gid_t gid;
  4439. - uid_t cuid;
  4440. - gid_t cgid;
  4441. - mode_t mode;
  4442. - int __ipc_perm_seq;
  4443. - long __pad1;
  4444. - long __pad2;
  4445. -};
  4446. -
  4447. -#define IPC_64 0x100
  4448. --- a/arch/microblaze/bits/mman.h
  4449. +++ b/arch/microblaze/bits/mman.h
  4450. @@ -37,6 +37,7 @@
  4451. #define MCL_CURRENT 1
  4452. #define MCL_FUTURE 2
  4453. +#define MCL_ONFAULT 4
  4454. #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  4455. #define MADV_NORMAL 0
  4456. --- a/arch/microblaze/bits/msg.h
  4457. +++ /dev/null
  4458. @@ -1,16 +0,0 @@
  4459. -struct msqid_ds
  4460. -{
  4461. - struct ipc_perm msg_perm;
  4462. - time_t msg_stime;
  4463. - int __unused1;
  4464. - time_t msg_rtime;
  4465. - int __unused2;
  4466. - time_t msg_ctime;
  4467. - int __unused3;
  4468. - unsigned long msg_cbytes;
  4469. - msgqnum_t msg_qnum;
  4470. - msglen_t msg_qbytes;
  4471. - pid_t msg_lspid;
  4472. - pid_t msg_lrpid;
  4473. - unsigned long __unused[2];
  4474. -};
  4475. --- a/arch/microblaze/bits/sem.h
  4476. +++ /dev/null
  4477. @@ -1,16 +0,0 @@
  4478. -struct semid_ds {
  4479. - struct ipc_perm sem_perm;
  4480. - time_t sem_otime;
  4481. - time_t __unused1;
  4482. - time_t sem_ctime;
  4483. - time_t __unused2;
  4484. -#if __BYTE_ORDER == __LITTLE_ENDIAN
  4485. - unsigned short sem_nsems;
  4486. - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
  4487. -#else
  4488. - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
  4489. - unsigned short sem_nsems;
  4490. -#endif
  4491. - time_t __unused3;
  4492. - time_t __unused4;
  4493. -};
  4494. --- a/arch/microblaze/bits/shm.h
  4495. +++ /dev/null
  4496. @@ -1,29 +0,0 @@
  4497. -#define SHMLBA 4096
  4498. -
  4499. -struct shmid_ds
  4500. -{
  4501. - struct ipc_perm shm_perm;
  4502. - size_t shm_segsz;
  4503. - time_t shm_atime;
  4504. - int __unused1;
  4505. - time_t shm_dtime;
  4506. - int __unused2;
  4507. - time_t shm_ctime;
  4508. - int __unused3;
  4509. - pid_t shm_cpid;
  4510. - pid_t shm_lpid;
  4511. - unsigned long shm_nattch;
  4512. - unsigned long __pad1;
  4513. - unsigned long __pad2;
  4514. -};
  4515. -
  4516. -struct shminfo {
  4517. - unsigned long shmmax, shmmin, shmmni, shmseg, shmall, __unused[4];
  4518. -};
  4519. -
  4520. -struct shm_info {
  4521. - int __used_ids;
  4522. - unsigned long shm_tot, shm_rss, shm_swp;
  4523. - unsigned long __swap_attempts, __swap_successes;
  4524. -};
  4525. -
  4526. --- a/arch/microblaze/bits/socket.h
  4527. +++ /dev/null
  4528. @@ -1,17 +0,0 @@
  4529. -struct msghdr
  4530. -{
  4531. - void *msg_name;
  4532. - socklen_t msg_namelen;
  4533. - struct iovec *msg_iov;
  4534. - int msg_iovlen;
  4535. - void *msg_control;
  4536. - socklen_t msg_controllen;
  4537. - int msg_flags;
  4538. -};
  4539. -
  4540. -struct cmsghdr
  4541. -{
  4542. - socklen_t cmsg_len;
  4543. - int cmsg_level;
  4544. - int cmsg_type;
  4545. -};
  4546. --- a/arch/microblaze/bits/statfs.h
  4547. +++ /dev/null
  4548. @@ -1,7 +0,0 @@
  4549. -struct statfs {
  4550. - unsigned long f_type, f_bsize;
  4551. - fsblkcnt_t f_blocks, f_bfree, f_bavail;
  4552. - fsfilcnt_t f_files, f_ffree;
  4553. - fsid_t f_fsid;
  4554. - unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
  4555. -};
  4556. --- a/arch/microblaze/bits/stdarg.h
  4557. +++ /dev/null
  4558. @@ -1,4 +0,0 @@
  4559. -#define va_start(v,l) __builtin_va_start(v,l)
  4560. -#define va_end(v) __builtin_va_end(v)
  4561. -#define va_arg(v,l) __builtin_va_arg(v,l)
  4562. -#define va_copy(d,s) __builtin_va_copy(d,s)
  4563. --- a/arch/microblaze/bits/termios.h
  4564. +++ /dev/null
  4565. @@ -1,160 +0,0 @@
  4566. -struct termios
  4567. -{
  4568. - tcflag_t c_iflag;
  4569. - tcflag_t c_oflag;
  4570. - tcflag_t c_cflag;
  4571. - tcflag_t c_lflag;
  4572. - cc_t c_line;
  4573. - cc_t c_cc[NCCS];
  4574. - speed_t __c_ispeed;
  4575. - speed_t __c_ospeed;
  4576. -};
  4577. -
  4578. -#define VINTR 0
  4579. -#define VQUIT 1
  4580. -#define VERASE 2
  4581. -#define VKILL 3
  4582. -#define VEOF 4
  4583. -#define VTIME 5
  4584. -#define VMIN 6
  4585. -#define VSWTC 7
  4586. -#define VSTART 8
  4587. -#define VSTOP 9
  4588. -#define VSUSP 10
  4589. -#define VEOL 11
  4590. -#define VREPRINT 12
  4591. -#define VDISCARD 13
  4592. -#define VWERASE 14
  4593. -#define VLNEXT 15
  4594. -#define VEOL2 16
  4595. -
  4596. -#define IGNBRK 0000001
  4597. -#define BRKINT 0000002
  4598. -#define IGNPAR 0000004
  4599. -#define PARMRK 0000010
  4600. -#define INPCK 0000020
  4601. -#define ISTRIP 0000040
  4602. -#define INLCR 0000100
  4603. -#define IGNCR 0000200
  4604. -#define ICRNL 0000400
  4605. -#define IUCLC 0001000
  4606. -#define IXON 0002000
  4607. -#define IXANY 0004000
  4608. -#define IXOFF 0010000
  4609. -#define IMAXBEL 0020000
  4610. -#define IUTF8 0040000
  4611. -
  4612. -#define OPOST 0000001
  4613. -#define OLCUC 0000002
  4614. -#define ONLCR 0000004
  4615. -#define OCRNL 0000010
  4616. -#define ONOCR 0000020
  4617. -#define ONLRET 0000040
  4618. -#define OFILL 0000100
  4619. -#define OFDEL 0000200
  4620. -#define NLDLY 0000400
  4621. -#define NL0 0000000
  4622. -#define NL1 0000400
  4623. -#define CRDLY 0003000
  4624. -#define CR0 0000000
  4625. -#define CR1 0001000
  4626. -#define CR2 0002000
  4627. -#define CR3 0003000
  4628. -#define TABDLY 0014000
  4629. -#define TAB0 0000000
  4630. -#define TAB1 0004000
  4631. -#define TAB2 0010000
  4632. -#define TAB3 0014000
  4633. -#define BSDLY 0020000
  4634. -#define BS0 0000000
  4635. -#define BS1 0020000
  4636. -#define FFDLY 0100000
  4637. -#define FF0 0000000
  4638. -#define FF1 0100000
  4639. -
  4640. -#define VTDLY 0040000
  4641. -#define VT0 0000000
  4642. -#define VT1 0040000
  4643. -
  4644. -#define B0 0000000
  4645. -#define B50 0000001
  4646. -#define B75 0000002
  4647. -#define B110 0000003
  4648. -#define B134 0000004
  4649. -#define B150 0000005
  4650. -#define B200 0000006
  4651. -#define B300 0000007
  4652. -#define B600 0000010
  4653. -#define B1200 0000011
  4654. -#define B1800 0000012
  4655. -#define B2400 0000013
  4656. -#define B4800 0000014
  4657. -#define B9600 0000015
  4658. -#define B19200 0000016
  4659. -#define B38400 0000017
  4660. -
  4661. -#define B57600 0010001
  4662. -#define B115200 0010002
  4663. -#define B230400 0010003
  4664. -#define B460800 0010004
  4665. -#define B500000 0010005
  4666. -#define B576000 0010006
  4667. -#define B921600 0010007
  4668. -#define B1000000 0010010
  4669. -#define B1152000 0010011
  4670. -#define B1500000 0010012
  4671. -#define B2000000 0010013
  4672. -#define B2500000 0010014
  4673. -#define B3000000 0010015
  4674. -#define B3500000 0010016
  4675. -#define B4000000 0010017
  4676. -
  4677. -#define CBAUD 0010017
  4678. -
  4679. -#define CSIZE 0000060
  4680. -#define CS5 0000000
  4681. -#define CS6 0000020
  4682. -#define CS7 0000040
  4683. -#define CS8 0000060
  4684. -#define CSTOPB 0000100
  4685. -#define CREAD 0000200
  4686. -#define PARENB 0000400
  4687. -#define PARODD 0001000
  4688. -#define HUPCL 0002000
  4689. -#define CLOCAL 0004000
  4690. -
  4691. -#define ISIG 0000001
  4692. -#define ICANON 0000002
  4693. -#define ECHO 0000010
  4694. -#define ECHOE 0000020
  4695. -#define ECHOK 0000040
  4696. -#define ECHONL 0000100
  4697. -#define NOFLSH 0000200
  4698. -#define TOSTOP 0000400
  4699. -#define IEXTEN 0100000
  4700. -
  4701. -#define ECHOCTL 0001000
  4702. -#define ECHOPRT 0002000
  4703. -#define ECHOKE 0004000
  4704. -#define FLUSHO 0010000
  4705. -#define PENDIN 0040000
  4706. -
  4707. -#define TCOOFF 0
  4708. -#define TCOON 1
  4709. -#define TCIOFF 2
  4710. -#define TCION 3
  4711. -
  4712. -#define TCIFLUSH 0
  4713. -#define TCOFLUSH 1
  4714. -#define TCIOFLUSH 2
  4715. -
  4716. -#define TCSANOW 0
  4717. -#define TCSADRAIN 1
  4718. -#define TCSAFLUSH 2
  4719. -
  4720. -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  4721. -#define CBAUDEX 0010000
  4722. -#define CRTSCTS 020000000000
  4723. -#define EXTPROC 0200000
  4724. -#define XTABS 0014000
  4725. -#endif
  4726. --- a/arch/microblaze/pthread_arch.h
  4727. +++ b/arch/microblaze/pthread_arch.h
  4728. @@ -7,4 +7,4 @@ static inline struct pthread *__pthread_
  4729. #define TP_ADJ(p) (p)
  4730. -#define CANCEL_REG_IP 32
  4731. +#define MC_PC regs.pc
  4732. --- a/arch/mips/atomic.h
  4733. +++ /dev/null
  4734. @@ -1,205 +0,0 @@
  4735. -#ifndef _INTERNAL_ATOMIC_H
  4736. -#define _INTERNAL_ATOMIC_H
  4737. -
  4738. -#include <stdint.h>
  4739. -
  4740. -static inline int a_ctz_l(unsigned long x)
  4741. -{
  4742. - static const char debruijn32[32] = {
  4743. - 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13,
  4744. - 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14
  4745. - };
  4746. - return debruijn32[(x&-x)*0x076be629 >> 27];
  4747. -}
  4748. -
  4749. -static inline int a_ctz_64(uint64_t x)
  4750. -{
  4751. - uint32_t y = x;
  4752. - if (!y) {
  4753. - y = x>>32;
  4754. - return 32 + a_ctz_l(y);
  4755. - }
  4756. - return a_ctz_l(y);
  4757. -}
  4758. -
  4759. -static inline int a_cas(volatile int *p, int t, int s)
  4760. -{
  4761. - int dummy;
  4762. - __asm__ __volatile__(
  4763. - ".set push\n"
  4764. - ".set mips2\n"
  4765. - ".set noreorder\n"
  4766. - " sync\n"
  4767. - "1: ll %0, %2\n"
  4768. - " bne %0, %3, 1f\n"
  4769. - " addu %1, %4, $0\n"
  4770. - " sc %1, %2\n"
  4771. - " beq %1, $0, 1b\n"
  4772. - " nop\n"
  4773. - " sync\n"
  4774. - "1: \n"
  4775. - ".set pop\n"
  4776. - : "=&r"(t), "=&r"(dummy), "+m"(*p) : "r"(t), "r"(s) : "memory" );
  4777. - return t;
  4778. -}
  4779. -
  4780. -static inline void *a_cas_p(volatile void *p, void *t, void *s)
  4781. -{
  4782. - return (void *)a_cas(p, (int)t, (int)s);
  4783. -}
  4784. -
  4785. -static inline int a_swap(volatile int *x, int v)
  4786. -{
  4787. - int old, dummy;
  4788. - __asm__ __volatile__(
  4789. - ".set push\n"
  4790. - ".set mips2\n"
  4791. - ".set noreorder\n"
  4792. - " sync\n"
  4793. - "1: ll %0, %2\n"
  4794. - " addu %1, %3, $0\n"
  4795. - " sc %1, %2\n"
  4796. - " beq %1, $0, 1b\n"
  4797. - " nop\n"
  4798. - " sync\n"
  4799. - ".set pop\n"
  4800. - : "=&r"(old), "=&r"(dummy), "+m"(*x) : "r"(v) : "memory" );
  4801. - return old;
  4802. -}
  4803. -
  4804. -static inline int a_fetch_add(volatile int *x, int v)
  4805. -{
  4806. - int old, dummy;
  4807. - __asm__ __volatile__(
  4808. - ".set push\n"
  4809. - ".set mips2\n"
  4810. - ".set noreorder\n"
  4811. - " sync\n"
  4812. - "1: ll %0, %2\n"
  4813. - " addu %1, %0, %3\n"
  4814. - " sc %1, %2\n"
  4815. - " beq %1, $0, 1b\n"
  4816. - " nop\n"
  4817. - " sync\n"
  4818. - ".set pop\n"
  4819. - : "=&r"(old), "=&r"(dummy), "+m"(*x) : "r"(v) : "memory" );
  4820. - return old;
  4821. -}
  4822. -
  4823. -static inline void a_inc(volatile int *x)
  4824. -{
  4825. - int dummy;
  4826. - __asm__ __volatile__(
  4827. - ".set push\n"
  4828. - ".set mips2\n"
  4829. - ".set noreorder\n"
  4830. - " sync\n"
  4831. - "1: ll %0, %1\n"
  4832. - " addu %0, %0, 1\n"
  4833. - " sc %0, %1\n"
  4834. - " beq %0, $0, 1b\n"
  4835. - " nop\n"
  4836. - " sync\n"
  4837. - ".set pop\n"
  4838. - : "=&r"(dummy), "+m"(*x) : : "memory" );
  4839. -}
  4840. -
  4841. -static inline void a_dec(volatile int *x)
  4842. -{
  4843. - int dummy;
  4844. - __asm__ __volatile__(
  4845. - ".set push\n"
  4846. - ".set mips2\n"
  4847. - ".set noreorder\n"
  4848. - " sync\n"
  4849. - "1: ll %0, %1\n"
  4850. - " subu %0, %0, 1\n"
  4851. - " sc %0, %1\n"
  4852. - " beq %0, $0, 1b\n"
  4853. - " nop\n"
  4854. - " sync\n"
  4855. - ".set pop\n"
  4856. - : "=&r"(dummy), "+m"(*x) : : "memory" );
  4857. -}
  4858. -
  4859. -static inline void a_store(volatile int *p, int x)
  4860. -{
  4861. - __asm__ __volatile__(
  4862. - ".set push\n"
  4863. - ".set mips2\n"
  4864. - ".set noreorder\n"
  4865. - " sync\n"
  4866. - " sw %1, %0\n"
  4867. - " sync\n"
  4868. - ".set pop\n"
  4869. - : "+m"(*p) : "r"(x) : "memory" );
  4870. -}
  4871. -
  4872. -#define a_spin a_barrier
  4873. -
  4874. -static inline void a_barrier()
  4875. -{
  4876. - a_cas(&(int){0}, 0, 0);
  4877. -}
  4878. -
  4879. -static inline void a_crash()
  4880. -{
  4881. - *(volatile char *)0=0;
  4882. -}
  4883. -
  4884. -static inline void a_and(volatile int *p, int v)
  4885. -{
  4886. - int dummy;
  4887. - __asm__ __volatile__(
  4888. - ".set push\n"
  4889. - ".set mips2\n"
  4890. - ".set noreorder\n"
  4891. - " sync\n"
  4892. - "1: ll %0, %1\n"
  4893. - " and %0, %0, %2\n"
  4894. - " sc %0, %1\n"
  4895. - " beq %0, $0, 1b\n"
  4896. - " nop\n"
  4897. - " sync\n"
  4898. - ".set pop\n"
  4899. - : "=&r"(dummy), "+m"(*p) : "r"(v) : "memory" );
  4900. -}
  4901. -
  4902. -static inline void a_or(volatile int *p, int v)
  4903. -{
  4904. - int dummy;
  4905. - __asm__ __volatile__(
  4906. - ".set push\n"
  4907. - ".set mips2\n"
  4908. - ".set noreorder\n"
  4909. - " sync\n"
  4910. - "1: ll %0, %1\n"
  4911. - " or %0, %0, %2\n"
  4912. - " sc %0, %1\n"
  4913. - " beq %0, $0, 1b\n"
  4914. - " nop\n"
  4915. - " sync\n"
  4916. - ".set pop\n"
  4917. - : "=&r"(dummy), "+m"(*p) : "r"(v) : "memory" );
  4918. -}
  4919. -
  4920. -static inline void a_or_l(volatile void *p, long v)
  4921. -{
  4922. - a_or(p, v);
  4923. -}
  4924. -
  4925. -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
  4926. -{
  4927. - union { uint64_t v; uint32_t r[2]; } u = { v };
  4928. - a_and((int *)p, u.r[0]);
  4929. - a_and((int *)p+1, u.r[1]);
  4930. -}
  4931. -
  4932. -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
  4933. -{
  4934. - union { uint64_t v; uint32_t r[2]; } u = { v };
  4935. - a_or((int *)p, u.r[0]);
  4936. - a_or((int *)p+1, u.r[1]);
  4937. -}
  4938. -
  4939. -#endif
  4940. --- /dev/null
  4941. +++ b/arch/mips/atomic_arch.h
  4942. @@ -0,0 +1,39 @@
  4943. +#define a_ll a_ll
  4944. +static inline int a_ll(volatile int *p)
  4945. +{
  4946. + int v;
  4947. + __asm__ __volatile__ (
  4948. + ".set push ; .set mips2\n\t"
  4949. + "ll %0, %1"
  4950. + "\n\t.set pop"
  4951. + : "=r"(v) : "m"(*p));
  4952. + return v;
  4953. +}
  4954. +
  4955. +#define a_sc a_sc
  4956. +static inline int a_sc(volatile int *p, int v)
  4957. +{
  4958. + int r;
  4959. + __asm__ __volatile__ (
  4960. + ".set push ; .set mips2\n\t"
  4961. + "sc %0, %1"
  4962. + "\n\t.set pop"
  4963. + : "=r"(r), "=m"(*p) : "0"(v) : "memory");
  4964. + return r;
  4965. +}
  4966. +
  4967. +#define a_barrier a_barrier
  4968. +static inline void a_barrier()
  4969. +{
  4970. + /* mips2 sync, but using too many directives causes
  4971. + * gcc not to inline it, so encode with .long instead. */
  4972. + __asm__ __volatile__ (".long 0xf" : : : "memory");
  4973. +#if 0
  4974. + __asm__ __volatile__ (
  4975. + ".set push ; .set mips2 ; sync ; .set pop"
  4976. + : : : "memory");
  4977. +#endif
  4978. +}
  4979. +
  4980. +#define a_pre_llsc a_barrier
  4981. +#define a_post_llsc a_barrier
  4982. --- a/arch/mips/bits/ipc.h
  4983. +++ /dev/null
  4984. @@ -1,14 +0,0 @@
  4985. -struct ipc_perm
  4986. -{
  4987. - key_t __ipc_perm_key;
  4988. - uid_t uid;
  4989. - gid_t gid;
  4990. - uid_t cuid;
  4991. - gid_t cgid;
  4992. - mode_t mode;
  4993. - int __ipc_perm_seq;
  4994. - long __pad1;
  4995. - long __pad2;
  4996. -};
  4997. -
  4998. -#define IPC_64 0x100
  4999. --- a/arch/mips/bits/mman.h
  5000. +++ b/arch/mips/bits/mman.h
  5001. @@ -37,6 +37,7 @@
  5002. #define MCL_CURRENT 1
  5003. #define MCL_FUTURE 2
  5004. +#define MCL_ONFAULT 4
  5005. #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  5006. #define MADV_NORMAL 0
  5007. --- a/arch/mips/bits/signal.h
  5008. +++ b/arch/mips/bits/signal.h
  5009. @@ -73,6 +73,15 @@ typedef struct __ucontext {
  5010. #define SIG_UNBLOCK 2
  5011. #define SIG_SETMASK 3
  5012. +#undef SI_ASYNCIO
  5013. +#undef SI_MESGQ
  5014. +#undef SI_TIMER
  5015. +#define SI_ASYNCIO (-2)
  5016. +#define SI_MESGQ (-4)
  5017. +#define SI_TIMER (-3)
  5018. +
  5019. +#define __SI_SWAP_ERRNO_CODE
  5020. +
  5021. #endif
  5022. #define SIGHUP 1
  5023. --- a/arch/mips/bits/stdarg.h
  5024. +++ /dev/null
  5025. @@ -1,4 +0,0 @@
  5026. -#define va_start(v,l) __builtin_va_start(v,l)
  5027. -#define va_end(v) __builtin_va_end(v)
  5028. -#define va_arg(v,l) __builtin_va_arg(v,l)
  5029. -#define va_copy(d,s) __builtin_va_copy(d,s)
  5030. --- a/arch/mips/bits/syscall.h
  5031. +++ b/arch/mips/bits/syscall.h
  5032. @@ -354,6 +354,9 @@
  5033. #define __NR_memfd_create 4354
  5034. #define __NR_bpf 4355
  5035. #define __NR_execveat 4356
  5036. +#define __NR_userfaultfd 4357
  5037. +#define __NR_membarrier 4358
  5038. +#define __NR_mlock2 4359
  5039. /* Repeated with SYS_ prefix */
  5040. @@ -713,3 +716,6 @@
  5041. #define SYS_memfd_create 4354
  5042. #define SYS_bpf 4355
  5043. #define SYS_execveat 4356
  5044. +#define SYS_userfaultfd 4357
  5045. +#define SYS_membarrier 4358
  5046. +#define SYS_mlock2 4359
  5047. --- a/arch/mips/crt_arch.h
  5048. +++ b/arch/mips/crt_arch.h
  5049. @@ -4,13 +4,16 @@ __asm__(
  5050. ".text \n"
  5051. ".global _" START "\n"
  5052. ".global " START "\n"
  5053. +".global " START "_data\n"
  5054. ".type _" START ", @function\n"
  5055. ".type " START ", @function\n"
  5056. +".type " START "_data, @function\n"
  5057. "_" START ":\n"
  5058. "" START ":\n"
  5059. " bal 1f \n"
  5060. " move $fp, $0 \n"
  5061. -"2: .gpword 2b \n"
  5062. +"" START "_data: \n"
  5063. +" .gpword " START "_data \n"
  5064. " .gpword " START "_c \n"
  5065. ".weak _DYNAMIC \n"
  5066. ".hidden _DYNAMIC \n"
  5067. --- a/arch/mips/pthread_arch.h
  5068. +++ b/arch/mips/pthread_arch.h
  5069. @@ -16,4 +16,4 @@ static inline struct pthread *__pthread_
  5070. #define DTP_OFFSET 0x8000
  5071. -#define CANCEL_REG_IP (3-(union {int __i; char __b;}){1}.__b)
  5072. +#define MC_PC pc
  5073. --- a/arch/mips/syscall_arch.h
  5074. +++ b/arch/mips/syscall_arch.h
  5075. @@ -3,9 +3,7 @@
  5076. ((union { long long ll; long l[2]; }){ .ll = x }).l[1]
  5077. #define __SYSCALL_LL_O(x) 0, __SYSCALL_LL_E((x))
  5078. -#ifdef SHARED
  5079. __attribute__((visibility("hidden")))
  5080. -#endif
  5081. long (__syscall)(long, ...);
  5082. #define SYSCALL_RLIM_INFINITY (-1UL/2)
  5083. @@ -163,3 +161,7 @@ static inline long __syscall6(long n, lo
  5084. if (n == SYS_fstatat) __stat_fix(c);
  5085. return r2;
  5086. }
  5087. +
  5088. +#define VDSO_USEFUL
  5089. +#define VDSO_CGT_SYM "__vdso_clock_gettime"
  5090. +#define VDSO_CGT_VER "LINUX_2.6"
  5091. --- a/arch/or1k/atomic.h
  5092. +++ /dev/null
  5093. @@ -1,120 +0,0 @@
  5094. -#ifndef _INTERNAL_ATOMIC_H
  5095. -#define _INTERNAL_ATOMIC_H
  5096. -
  5097. -#include <stdint.h>
  5098. -
  5099. -static inline int a_ctz_l(unsigned long x)
  5100. -{
  5101. - static const char debruijn32[32] = {
  5102. - 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13,
  5103. - 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14
  5104. - };
  5105. - return debruijn32[(x&-x)*0x076be629 >> 27];
  5106. -}
  5107. -
  5108. -static inline int a_ctz_64(uint64_t x)
  5109. -{
  5110. - uint32_t y = x;
  5111. - if (!y) {
  5112. - y = x>>32;
  5113. - return 32 + a_ctz_l(y);
  5114. - }
  5115. - return a_ctz_l(y);
  5116. -}
  5117. -
  5118. -static inline int a_cas(volatile int *p, int t, int s)
  5119. -{
  5120. - __asm__("1: l.lwa %0, %1\n"
  5121. - " l.sfeq %0, %2\n"
  5122. - " l.bnf 1f\n"
  5123. - " l.nop\n"
  5124. - " l.swa %1, %3\n"
  5125. - " l.bnf 1b\n"
  5126. - " l.nop\n"
  5127. - "1: \n"
  5128. - : "=&r"(t), "+m"(*p) : "r"(t), "r"(s) : "cc", "memory" );
  5129. - return t;
  5130. -}
  5131. -
  5132. -static inline void *a_cas_p(volatile void *p, void *t, void *s)
  5133. -{
  5134. - return (void *)a_cas(p, (int)t, (int)s);
  5135. -}
  5136. -
  5137. -static inline int a_swap(volatile int *x, int v)
  5138. -{
  5139. - int old;
  5140. - do old = *x;
  5141. - while (a_cas(x, old, v) != old);
  5142. - return old;
  5143. -}
  5144. -
  5145. -static inline int a_fetch_add(volatile int *x, int v)
  5146. -{
  5147. - int old;
  5148. - do old = *x;
  5149. - while (a_cas(x, old, old+v) != old);
  5150. - return old;
  5151. -}
  5152. -
  5153. -static inline void a_inc(volatile int *x)
  5154. -{
  5155. - a_fetch_add(x, 1);
  5156. -}
  5157. -
  5158. -static inline void a_dec(volatile int *x)
  5159. -{
  5160. - a_fetch_add(x, -1);
  5161. -}
  5162. -
  5163. -static inline void a_store(volatile int *p, int x)
  5164. -{
  5165. - a_swap(p, x);
  5166. -}
  5167. -
  5168. -#define a_spin a_barrier
  5169. -
  5170. -static inline void a_barrier()
  5171. -{
  5172. - a_cas(&(int){0}, 0, 0);
  5173. -}
  5174. -
  5175. -static inline void a_crash()
  5176. -{
  5177. - *(volatile char *)0=0;
  5178. -}
  5179. -
  5180. -static inline void a_and(volatile int *p, int v)
  5181. -{
  5182. - int old;
  5183. - do old = *p;
  5184. - while (a_cas(p, old, old&v) != old);
  5185. -}
  5186. -
  5187. -static inline void a_or(volatile int *p, int v)
  5188. -{
  5189. - int old;
  5190. - do old = *p;
  5191. - while (a_cas(p, old, old|v) != old);
  5192. -}
  5193. -
  5194. -static inline void a_or_l(volatile void *p, long v)
  5195. -{
  5196. - a_or(p, v);
  5197. -}
  5198. -
  5199. -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
  5200. -{
  5201. - union { uint64_t v; uint32_t r[2]; } u = { v };
  5202. - a_and((int *)p, u.r[0]);
  5203. - a_and((int *)p+1, u.r[1]);
  5204. -}
  5205. -
  5206. -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
  5207. -{
  5208. - union { uint64_t v; uint32_t r[2]; } u = { v };
  5209. - a_or((int *)p, u.r[0]);
  5210. - a_or((int *)p+1, u.r[1]);
  5211. -}
  5212. -
  5213. -#endif
  5214. --- /dev/null
  5215. +++ b/arch/or1k/atomic_arch.h
  5216. @@ -0,0 +1,14 @@
  5217. +#define a_cas a_cas
  5218. +static inline int a_cas(volatile int *p, int t, int s)
  5219. +{
  5220. + __asm__("1: l.lwa %0, %1\n"
  5221. + " l.sfeq %0, %2\n"
  5222. + " l.bnf 1f\n"
  5223. + " l.nop\n"
  5224. + " l.swa %1, %3\n"
  5225. + " l.bnf 1b\n"
  5226. + " l.nop\n"
  5227. + "1: \n"
  5228. + : "=&r"(t), "+m"(*p) : "r"(t), "r"(s) : "cc", "memory" );
  5229. + return t;
  5230. +}
  5231. --- a/arch/or1k/bits/errno.h
  5232. +++ /dev/null
  5233. @@ -1,134 +0,0 @@
  5234. -#define EPERM 1
  5235. -#define ENOENT 2
  5236. -#define ESRCH 3
  5237. -#define EINTR 4
  5238. -#define EIO 5
  5239. -#define ENXIO 6
  5240. -#define E2BIG 7
  5241. -#define ENOEXEC 8
  5242. -#define EBADF 9
  5243. -#define ECHILD 10
  5244. -#define EAGAIN 11
  5245. -#define ENOMEM 12
  5246. -#define EACCES 13
  5247. -#define EFAULT 14
  5248. -#define ENOTBLK 15
  5249. -#define EBUSY 16
  5250. -#define EEXIST 17
  5251. -#define EXDEV 18
  5252. -#define ENODEV 19
  5253. -#define ENOTDIR 20
  5254. -#define EISDIR 21
  5255. -#define EINVAL 22
  5256. -#define ENFILE 23
  5257. -#define EMFILE 24
  5258. -#define ENOTTY 25
  5259. -#define ETXTBSY 26
  5260. -#define EFBIG 27
  5261. -#define ENOSPC 28
  5262. -#define ESPIPE 29
  5263. -#define EROFS 30
  5264. -#define EMLINK 31
  5265. -#define EPIPE 32
  5266. -#define EDOM 33
  5267. -#define ERANGE 34
  5268. -#define EDEADLK 35
  5269. -#define ENAMETOOLONG 36
  5270. -#define ENOLCK 37
  5271. -#define ENOSYS 38
  5272. -#define ENOTEMPTY 39
  5273. -#define ELOOP 40
  5274. -#define EWOULDBLOCK EAGAIN
  5275. -#define ENOMSG 42
  5276. -#define EIDRM 43
  5277. -#define ECHRNG 44
  5278. -#define EL2NSYNC 45
  5279. -#define EL3HLT 46
  5280. -#define EL3RST 47
  5281. -#define ELNRNG 48
  5282. -#define EUNATCH 49
  5283. -#define ENOCSI 50
  5284. -#define EL2HLT 51
  5285. -#define EBADE 52
  5286. -#define EBADR 53
  5287. -#define EXFULL 54
  5288. -#define ENOANO 55
  5289. -#define EBADRQC 56
  5290. -#define EBADSLT 57
  5291. -#define EDEADLOCK EDEADLK
  5292. -#define EBFONT 59
  5293. -#define ENOSTR 60
  5294. -#define ENODATA 61
  5295. -#define ETIME 62
  5296. -#define ENOSR 63
  5297. -#define ENONET 64
  5298. -#define ENOPKG 65
  5299. -#define EREMOTE 66
  5300. -#define ENOLINK 67
  5301. -#define EADV 68
  5302. -#define ESRMNT 69
  5303. -#define ECOMM 70
  5304. -#define EPROTO 71
  5305. -#define EMULTIHOP 72
  5306. -#define EDOTDOT 73
  5307. -#define EBADMSG 74
  5308. -#define EOVERFLOW 75
  5309. -#define ENOTUNIQ 76
  5310. -#define EBADFD 77
  5311. -#define EREMCHG 78
  5312. -#define ELIBACC 79
  5313. -#define ELIBBAD 80
  5314. -#define ELIBSCN 81
  5315. -#define ELIBMAX 82
  5316. -#define ELIBEXEC 83
  5317. -#define EILSEQ 84
  5318. -#define ERESTART 85
  5319. -#define ESTRPIPE 86
  5320. -#define EUSERS 87
  5321. -#define ENOTSOCK 88
  5322. -#define EDESTADDRREQ 89
  5323. -#define EMSGSIZE 90
  5324. -#define EPROTOTYPE 91
  5325. -#define ENOPROTOOPT 92
  5326. -#define EPROTONOSUPPORT 93
  5327. -#define ESOCKTNOSUPPORT 94
  5328. -#define EOPNOTSUPP 95
  5329. -#define ENOTSUP EOPNOTSUPP
  5330. -#define EPFNOSUPPORT 96
  5331. -#define EAFNOSUPPORT 97
  5332. -#define EADDRINUSE 98
  5333. -#define EADDRNOTAVAIL 99
  5334. -#define ENETDOWN 100
  5335. -#define ENETUNREACH 101
  5336. -#define ENETRESET 102
  5337. -#define ECONNABORTED 103
  5338. -#define ECONNRESET 104
  5339. -#define ENOBUFS 105
  5340. -#define EISCONN 106
  5341. -#define ENOTCONN 107
  5342. -#define ESHUTDOWN 108
  5343. -#define ETOOMANYREFS 109
  5344. -#define ETIMEDOUT 110
  5345. -#define ECONNREFUSED 111
  5346. -#define EHOSTDOWN 112
  5347. -#define EHOSTUNREACH 113
  5348. -#define EALREADY 114
  5349. -#define EINPROGRESS 115
  5350. -#define ESTALE 116
  5351. -#define EUCLEAN 117
  5352. -#define ENOTNAM 118
  5353. -#define ENAVAIL 119
  5354. -#define EISNAM 120
  5355. -#define EREMOTEIO 121
  5356. -#define EDQUOT 122
  5357. -#define ENOMEDIUM 123
  5358. -#define EMEDIUMTYPE 124
  5359. -#define ECANCELED 125
  5360. -#define ENOKEY 126
  5361. -#define EKEYEXPIRED 127
  5362. -#define EKEYREVOKED 128
  5363. -#define EKEYREJECTED 129
  5364. -#define EOWNERDEAD 130
  5365. -#define ENOTRECOVERABLE 131
  5366. -#define ERFKILL 132
  5367. -#define EHWPOISON 133
  5368. --- a/arch/or1k/bits/fcntl.h
  5369. +++ /dev/null
  5370. @@ -1,40 +0,0 @@
  5371. -#define O_CREAT 0100
  5372. -#define O_EXCL 0200
  5373. -#define O_NOCTTY 0400
  5374. -#define O_TRUNC 01000
  5375. -#define O_APPEND 02000
  5376. -#define O_NONBLOCK 04000
  5377. -#define O_DSYNC 010000
  5378. -#define O_SYNC 04010000
  5379. -#define O_RSYNC 04010000
  5380. -#define O_DIRECTORY 0200000
  5381. -#define O_NOFOLLOW 0400000
  5382. -#define O_CLOEXEC 02000000
  5383. -
  5384. -#define O_ASYNC 020000
  5385. -#define O_DIRECT 040000
  5386. -#define O_LARGEFILE 0100000
  5387. -#define O_NOATIME 01000000
  5388. -#define O_PATH 010000000
  5389. -#define O_TMPFILE 020200000
  5390. -#define O_NDELAY O_NONBLOCK
  5391. -
  5392. -#define F_DUPFD 0
  5393. -#define F_GETFD 1
  5394. -#define F_SETFD 2
  5395. -#define F_GETFL 3
  5396. -#define F_SETFL 4
  5397. -
  5398. -#define F_SETOWN 8
  5399. -#define F_GETOWN 9
  5400. -#define F_SETSIG 10
  5401. -#define F_GETSIG 11
  5402. -
  5403. -#define F_GETLK 12
  5404. -#define F_SETLK 13
  5405. -#define F_SETLKW 14
  5406. -
  5407. -#define F_SETOWN_EX 15
  5408. -#define F_GETOWN_EX 16
  5409. -
  5410. -#define F_GETOWNER_UIDS 17
  5411. --- a/arch/or1k/bits/fenv.h
  5412. +++ /dev/null
  5413. @@ -1,10 +0,0 @@
  5414. -#define FE_ALL_EXCEPT 0
  5415. -#define FE_TONEAREST 0
  5416. -
  5417. -typedef unsigned long fexcept_t;
  5418. -
  5419. -typedef struct {
  5420. - unsigned long __cw;
  5421. -} fenv_t;
  5422. -
  5423. -#define FE_DFL_ENV ((const fenv_t *) -1)
  5424. --- a/arch/or1k/bits/ioctl.h
  5425. +++ /dev/null
  5426. @@ -1,197 +0,0 @@
  5427. -#define _IOC(a,b,c,d) ( ((a)<<30) | ((b)<<8) | (c) | ((d)<<16) )
  5428. -#define _IOC_NONE 0U
  5429. -#define _IOC_WRITE 1U
  5430. -#define _IOC_READ 2U
  5431. -
  5432. -#define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0)
  5433. -#define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),sizeof(c))
  5434. -#define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),sizeof(c))
  5435. -#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE,(a),(b),sizeof(c))
  5436. -
  5437. -#define TCGETS 0x5401
  5438. -#define TCSETS 0x5402
  5439. -#define TCSETSW 0x5403
  5440. -#define TCSETSF 0x5404
  5441. -#define TCGETA 0x5405
  5442. -#define TCSETA 0x5406
  5443. -#define TCSETAW 0x5407
  5444. -#define TCSETAF 0x5408
  5445. -#define TCSBRK 0x5409
  5446. -#define TCXONC 0x540A
  5447. -#define TCFLSH 0x540B
  5448. -#define TIOCEXCL 0x540C
  5449. -#define TIOCNXCL 0x540D
  5450. -#define TIOCSCTTY 0x540E
  5451. -#define TIOCGPGRP 0x540F
  5452. -#define TIOCSPGRP 0x5410
  5453. -#define TIOCOUTQ 0x5411
  5454. -#define TIOCSTI 0x5412
  5455. -#define TIOCGWINSZ 0x5413
  5456. -#define TIOCSWINSZ 0x5414
  5457. -#define TIOCMGET 0x5415
  5458. -#define TIOCMBIS 0x5416
  5459. -#define TIOCMBIC 0x5417
  5460. -#define TIOCMSET 0x5418
  5461. -#define TIOCGSOFTCAR 0x5419
  5462. -#define TIOCSSOFTCAR 0x541A
  5463. -#define FIONREAD 0x541B
  5464. -#define TIOCINQ FIONREAD
  5465. -#define TIOCLINUX 0x541C
  5466. -#define TIOCCONS 0x541D
  5467. -#define TIOCGSERIAL 0x541E
  5468. -#define TIOCSSERIAL 0x541F
  5469. -#define TIOCPKT 0x5420
  5470. -#define FIONBIO 0x5421
  5471. -#define TIOCNOTTY 0x5422
  5472. -#define TIOCSETD 0x5423
  5473. -#define TIOCGETD 0x5424
  5474. -#define TCSBRKP 0x5425
  5475. -#define TIOCTTYGSTRUCT 0x5426
  5476. -#define TIOCSBRK 0x5427
  5477. -#define TIOCCBRK 0x5428
  5478. -#define TIOCGSID 0x5429
  5479. -#define TIOCGPTN 0x80045430
  5480. -#define TIOCSPTLCK 0x40045431
  5481. -#define TCGETX 0x5432
  5482. -#define TCSETX 0x5433
  5483. -#define TCSETXF 0x5434
  5484. -#define TCSETXW 0x5435
  5485. -
  5486. -#define FIONCLEX 0x5450
  5487. -#define FIOCLEX 0x5451
  5488. -#define FIOASYNC 0x5452
  5489. -#define TIOCSERCONFIG 0x5453
  5490. -#define TIOCSERGWILD 0x5454
  5491. -#define TIOCSERSWILD 0x5455
  5492. -#define TIOCGLCKTRMIOS 0x5456
  5493. -#define TIOCSLCKTRMIOS 0x5457
  5494. -#define TIOCSERGSTRUCT 0x5458
  5495. -#define TIOCSERGETLSR 0x5459
  5496. -#define TIOCSERGETMULTI 0x545A
  5497. -#define TIOCSERSETMULTI 0x545B
  5498. -
  5499. -#define TIOCMIWAIT 0x545C
  5500. -#define TIOCGICOUNT 0x545D
  5501. -#define TIOCGHAYESESP 0x545E
  5502. -#define TIOCSHAYESESP 0x545F
  5503. -#define FIOQSIZE 0x5460
  5504. -
  5505. -#define TIOCPKT_DATA 0
  5506. -#define TIOCPKT_FLUSHREAD 1
  5507. -#define TIOCPKT_FLUSHWRITE 2
  5508. -#define TIOCPKT_STOP 4
  5509. -#define TIOCPKT_START 8
  5510. -#define TIOCPKT_NOSTOP 16
  5511. -#define TIOCPKT_DOSTOP 32
  5512. -#define TIOCPKT_IOCTL 64
  5513. -
  5514. -#define TIOCSER_TEMT 0x01
  5515. -
  5516. -struct winsize {
  5517. - unsigned short ws_row;
  5518. - unsigned short ws_col;
  5519. - unsigned short ws_xpixel;
  5520. - unsigned short ws_ypixel;
  5521. -};
  5522. -
  5523. -#define TIOCM_LE 0x001
  5524. -#define TIOCM_DTR 0x002
  5525. -#define TIOCM_RTS 0x004
  5526. -#define TIOCM_ST 0x008
  5527. -#define TIOCM_SR 0x010
  5528. -#define TIOCM_CTS 0x020
  5529. -#define TIOCM_CAR 0x040
  5530. -#define TIOCM_RNG 0x080
  5531. -#define TIOCM_DSR 0x100
  5532. -#define TIOCM_CD TIOCM_CAR
  5533. -#define TIOCM_RI TIOCM_RNG
  5534. -#define TIOCM_OUT1 0x2000
  5535. -#define TIOCM_OUT2 0x4000
  5536. -#define TIOCM_LOOP 0x8000
  5537. -#define TIOCM_MODEM_BITS TIOCM_OUT2
  5538. -
  5539. -#define N_TTY 0
  5540. -#define N_SLIP 1
  5541. -#define N_MOUSE 2
  5542. -#define N_PPP 3
  5543. -#define N_STRIP 4
  5544. -#define N_AX25 5
  5545. -#define N_X25 6
  5546. -#define N_6PACK 7
  5547. -#define N_MASC 8
  5548. -#define N_R3964 9
  5549. -#define N_PROFIBUS_FDL 10
  5550. -#define N_IRDA 11
  5551. -#define N_SMSBLOCK 12
  5552. -#define N_HDLC 13
  5553. -#define N_SYNC_PPP 14
  5554. -#define N_HCI 15
  5555. -
  5556. -#define FIOSETOWN 0x8901
  5557. -#define SIOCSPGRP 0x8902
  5558. -#define FIOGETOWN 0x8903
  5559. -#define SIOCGPGRP 0x8904
  5560. -#define SIOCATMARK 0x8905
  5561. -#define SIOCGSTAMP 0x8906
  5562. -
  5563. -#define SIOCADDRT 0x890B
  5564. -#define SIOCDELRT 0x890C
  5565. -#define SIOCRTMSG 0x890D
  5566. -
  5567. -#define SIOCGIFNAME 0x8910
  5568. -#define SIOCSIFLINK 0x8911
  5569. -#define SIOCGIFCONF 0x8912
  5570. -#define SIOCGIFFLAGS 0x8913
  5571. -#define SIOCSIFFLAGS 0x8914
  5572. -#define SIOCGIFADDR 0x8915
  5573. -#define SIOCSIFADDR 0x8916
  5574. -#define SIOCGIFDSTADDR 0x8917
  5575. -#define SIOCSIFDSTADDR 0x8918
  5576. -#define SIOCGIFBRDADDR 0x8919
  5577. -#define SIOCSIFBRDADDR 0x891a
  5578. -#define SIOCGIFNETMASK 0x891b
  5579. -#define SIOCSIFNETMASK 0x891c
  5580. -#define SIOCGIFMETRIC 0x891d
  5581. -#define SIOCSIFMETRIC 0x891e
  5582. -#define SIOCGIFMEM 0x891f
  5583. -#define SIOCSIFMEM 0x8920
  5584. -#define SIOCGIFMTU 0x8921
  5585. -#define SIOCSIFMTU 0x8922
  5586. -#define SIOCSIFHWADDR 0x8924
  5587. -#define SIOCGIFENCAP 0x8925
  5588. -#define SIOCSIFENCAP 0x8926
  5589. -#define SIOCGIFHWADDR 0x8927
  5590. -#define SIOCGIFSLAVE 0x8929
  5591. -#define SIOCSIFSLAVE 0x8930
  5592. -#define SIOCADDMULTI 0x8931
  5593. -#define SIOCDELMULTI 0x8932
  5594. -#define SIOCGIFINDEX 0x8933
  5595. -#define SIOGIFINDEX SIOCGIFINDEX
  5596. -#define SIOCSIFPFLAGS 0x8934
  5597. -#define SIOCGIFPFLAGS 0x8935
  5598. -#define SIOCDIFADDR 0x8936
  5599. -#define SIOCSIFHWBROADCAST 0x8937
  5600. -#define SIOCGIFCOUNT 0x8938
  5601. -
  5602. -#define SIOCGIFBR 0x8940
  5603. -#define SIOCSIFBR 0x8941
  5604. -
  5605. -#define SIOCGIFTXQLEN 0x8942
  5606. -#define SIOCSIFTXQLEN 0x8943
  5607. -
  5608. -#define SIOCDARP 0x8953
  5609. -#define SIOCGARP 0x8954
  5610. -#define SIOCSARP 0x8955
  5611. -
  5612. -#define SIOCDRARP 0x8960
  5613. -#define SIOCGRARP 0x8961
  5614. -#define SIOCSRARP 0x8962
  5615. -
  5616. -#define SIOCGIFMAP 0x8970
  5617. -#define SIOCSIFMAP 0x8971
  5618. -
  5619. -#define SIOCADDDLCI 0x8980
  5620. -#define SIOCDELDLCI 0x8981
  5621. -
  5622. -#define SIOCDEVPRIVATE 0x89F0
  5623. -#define SIOCPROTOPRIVATE 0x89E0
  5624. --- a/arch/or1k/bits/mman.h
  5625. +++ b/arch/or1k/bits/mman.h
  5626. @@ -37,6 +37,7 @@
  5627. #define MCL_CURRENT 1
  5628. #define MCL_FUTURE 2
  5629. +#define MCL_ONFAULT 4
  5630. #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  5631. #define MADV_NORMAL 0
  5632. --- a/arch/or1k/bits/shm.h
  5633. +++ /dev/null
  5634. @@ -1,27 +0,0 @@
  5635. -#define SHMLBA 4096
  5636. -
  5637. -struct shmid_ds {
  5638. - struct ipc_perm shm_perm;
  5639. - size_t shm_segsz;
  5640. - time_t shm_atime;
  5641. - int __unused1;
  5642. - time_t shm_dtime;
  5643. - int __unused2;
  5644. - time_t shm_ctime;
  5645. - int __unused3;
  5646. - pid_t shm_cpid;
  5647. - pid_t shm_lpid;
  5648. - unsigned long shm_nattch;
  5649. - unsigned long __pad1;
  5650. - unsigned long __pad2;
  5651. -};
  5652. -
  5653. -struct shminfo {
  5654. - unsigned long shmmax, shmmin, shmmni, shmseg, shmall, __unused[4];
  5655. -};
  5656. -
  5657. -struct shm_info {
  5658. - int __used_ids;
  5659. - unsigned long shm_tot, shm_rss, shm_swp;
  5660. - unsigned long __swap_attempts, __swap_successes;
  5661. -};
  5662. --- a/arch/or1k/bits/socket.h
  5663. +++ /dev/null
  5664. @@ -1,15 +0,0 @@
  5665. -struct msghdr {
  5666. - void *msg_name;
  5667. - socklen_t msg_namelen;
  5668. - struct iovec *msg_iov;
  5669. - int msg_iovlen;
  5670. - void *msg_control;
  5671. - socklen_t msg_controllen;
  5672. - int msg_flags;
  5673. -};
  5674. -
  5675. -struct cmsghdr {
  5676. - socklen_t cmsg_len;
  5677. - int cmsg_level;
  5678. - int cmsg_type;
  5679. -};
  5680. --- a/arch/or1k/bits/statfs.h
  5681. +++ /dev/null
  5682. @@ -1,7 +0,0 @@
  5683. -struct statfs {
  5684. - unsigned long f_type, f_bsize;
  5685. - fsblkcnt_t f_blocks, f_bfree, f_bavail;
  5686. - fsfilcnt_t f_files, f_ffree;
  5687. - fsid_t f_fsid;
  5688. - unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
  5689. -};
  5690. --- a/arch/or1k/bits/stdarg.h
  5691. +++ /dev/null
  5692. @@ -1,4 +0,0 @@
  5693. -#define va_start(v,l) __builtin_va_start(v,l)
  5694. -#define va_end(v) __builtin_va_end(v)
  5695. -#define va_arg(v,l) __builtin_va_arg(v,l)
  5696. -#define va_copy(d,s) __builtin_va_copy(d,s)
  5697. --- a/arch/or1k/bits/syscall.h
  5698. +++ b/arch/or1k/bits/syscall.h
  5699. @@ -265,6 +265,9 @@
  5700. #define __NR_memfd_create 279
  5701. #define __NR_bpf 280
  5702. #define __NR_execveat 281
  5703. +#define __NR_userfaultfd 282
  5704. +#define __NR_membarrier 283
  5705. +#define __NR_mlock2 284
  5706. #define SYS_io_setup __NR_io_setup
  5707. #define SYS_io_destroy __NR_io_destroy
  5708. @@ -533,3 +536,6 @@
  5709. #define SYS_memfd_create __NR_memfd_create
  5710. #define SYS_bpf __NR_bpf
  5711. #define SYS_execveat __NR_execveat
  5712. +#define SYS_userfaultfd __NR_userfaultfd
  5713. +#define SYS_membarrier __NR_membarrier
  5714. +#define SYS_mlock2 __NR_mlock2
  5715. --- a/arch/or1k/bits/termios.h
  5716. +++ /dev/null
  5717. @@ -1,159 +0,0 @@
  5718. -struct termios {
  5719. - tcflag_t c_iflag;
  5720. - tcflag_t c_oflag;
  5721. - tcflag_t c_cflag;
  5722. - tcflag_t c_lflag;
  5723. - cc_t c_line;
  5724. - cc_t c_cc[NCCS];
  5725. - speed_t __c_ispeed;
  5726. - speed_t __c_ospeed;
  5727. -};
  5728. -
  5729. -#define VINTR 0
  5730. -#define VQUIT 1
  5731. -#define VERASE 2
  5732. -#define VKILL 3
  5733. -#define VEOF 4
  5734. -#define VTIME 5
  5735. -#define VMIN 6
  5736. -#define VSWTC 7
  5737. -#define VSTART 8
  5738. -#define VSTOP 9
  5739. -#define VSUSP 10
  5740. -#define VEOL 11
  5741. -#define VREPRINT 12
  5742. -#define VDISCARD 13
  5743. -#define VWERASE 14
  5744. -#define VLNEXT 15
  5745. -#define VEOL2 16
  5746. -
  5747. -#define IGNBRK 0000001
  5748. -#define BRKINT 0000002
  5749. -#define IGNPAR 0000004
  5750. -#define PARMRK 0000010
  5751. -#define INPCK 0000020
  5752. -#define ISTRIP 0000040
  5753. -#define INLCR 0000100
  5754. -#define IGNCR 0000200
  5755. -#define ICRNL 0000400
  5756. -#define IUCLC 0001000
  5757. -#define IXON 0002000
  5758. -#define IXANY 0004000
  5759. -#define IXOFF 0010000
  5760. -#define IMAXBEL 0020000
  5761. -#define IUTF8 0040000
  5762. -
  5763. -#define OPOST 0000001
  5764. -#define OLCUC 0000002
  5765. -#define ONLCR 0000004
  5766. -#define OCRNL 0000010
  5767. -#define ONOCR 0000020
  5768. -#define ONLRET 0000040
  5769. -#define OFILL 0000100
  5770. -#define OFDEL 0000200
  5771. -#define NLDLY 0000400
  5772. -#define NL0 0000000
  5773. -#define NL1 0000400
  5774. -#define CRDLY 0003000
  5775. -#define CR0 0000000
  5776. -#define CR1 0001000
  5777. -#define CR2 0002000
  5778. -#define CR3 0003000
  5779. -#define TABDLY 0014000
  5780. -#define TAB0 0000000
  5781. -#define TAB1 0004000
  5782. -#define TAB2 0010000
  5783. -#define TAB3 0014000
  5784. -#define BSDLY 0020000
  5785. -#define BS0 0000000
  5786. -#define BS1 0020000
  5787. -#define FFDLY 0100000
  5788. -#define FF0 0000000
  5789. -#define FF1 0100000
  5790. -
  5791. -#define VTDLY 0040000
  5792. -#define VT0 0000000
  5793. -#define VT1 0040000
  5794. -
  5795. -#define B0 0000000
  5796. -#define B50 0000001
  5797. -#define B75 0000002
  5798. -#define B110 0000003
  5799. -#define B134 0000004
  5800. -#define B150 0000005
  5801. -#define B200 0000006
  5802. -#define B300 0000007
  5803. -#define B600 0000010
  5804. -#define B1200 0000011
  5805. -#define B1800 0000012
  5806. -#define B2400 0000013
  5807. -#define B4800 0000014
  5808. -#define B9600 0000015
  5809. -#define B19200 0000016
  5810. -#define B38400 0000017
  5811. -
  5812. -#define B57600 0010001
  5813. -#define B115200 0010002
  5814. -#define B230400 0010003
  5815. -#define B460800 0010004
  5816. -#define B500000 0010005
  5817. -#define B576000 0010006
  5818. -#define B921600 0010007
  5819. -#define B1000000 0010010
  5820. -#define B1152000 0010011
  5821. -#define B1500000 0010012
  5822. -#define B2000000 0010013
  5823. -#define B2500000 0010014
  5824. -#define B3000000 0010015
  5825. -#define B3500000 0010016
  5826. -#define B4000000 0010017
  5827. -
  5828. -#define CBAUD 0010017
  5829. -
  5830. -#define CSIZE 0000060
  5831. -#define CS5 0000000
  5832. -#define CS6 0000020
  5833. -#define CS7 0000040
  5834. -#define CS8 0000060
  5835. -#define CSTOPB 0000100
  5836. -#define CREAD 0000200
  5837. -#define PARENB 0000400
  5838. -#define PARODD 0001000
  5839. -#define HUPCL 0002000
  5840. -#define CLOCAL 0004000
  5841. -
  5842. -#define ISIG 0000001
  5843. -#define ICANON 0000002
  5844. -#define ECHO 0000010
  5845. -#define ECHOE 0000020
  5846. -#define ECHOK 0000040
  5847. -#define ECHONL 0000100
  5848. -#define NOFLSH 0000200
  5849. -#define TOSTOP 0000400
  5850. -#define IEXTEN 0100000
  5851. -
  5852. -#define ECHOCTL 0001000
  5853. -#define ECHOPRT 0002000
  5854. -#define ECHOKE 0004000
  5855. -#define FLUSHO 0010000
  5856. -#define PENDIN 0040000
  5857. -
  5858. -#define TCOOFF 0
  5859. -#define TCOON 1
  5860. -#define TCIOFF 2
  5861. -#define TCION 3
  5862. -
  5863. -#define TCIFLUSH 0
  5864. -#define TCOFLUSH 1
  5865. -#define TCIOFLUSH 2
  5866. -
  5867. -#define TCSANOW 0
  5868. -#define TCSADRAIN 1
  5869. -#define TCSAFLUSH 2
  5870. -
  5871. -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  5872. -#define CBAUDEX 0010000
  5873. -#define CRTSCTS 020000000000
  5874. -#define EXTPROC 0200000
  5875. -#define XTABS 0014000
  5876. -#endif
  5877. --- a/arch/or1k/pthread_arch.h
  5878. +++ b/arch/or1k/pthread_arch.h
  5879. @@ -14,5 +14,4 @@ static inline struct pthread *__pthread_
  5880. #define TLS_ABOVE_TP
  5881. #define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread))
  5882. -/* word-offset to 'pc' in mcontext_t */
  5883. -#define CANCEL_REG_IP 32
  5884. +#define MC_PC regs.pc
  5885. --- a/arch/powerpc/atomic.h
  5886. +++ /dev/null
  5887. @@ -1,126 +0,0 @@
  5888. -#ifndef _INTERNAL_ATOMIC_H
  5889. -#define _INTERNAL_ATOMIC_H
  5890. -
  5891. -#include <stdint.h>
  5892. -#include <endian.h>
  5893. -
  5894. -static inline int a_ctz_l(unsigned long x)
  5895. -{
  5896. - static const char debruijn32[32] = {
  5897. - 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13,
  5898. - 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14
  5899. - };
  5900. - return debruijn32[(x&-x)*0x076be629 >> 27];
  5901. -}
  5902. -
  5903. -static inline int a_ctz_64(uint64_t x)
  5904. -{
  5905. - uint32_t y = x;
  5906. - if (!y) {
  5907. - y = x>>32;
  5908. - return 32 + a_ctz_l(y);
  5909. - }
  5910. - return a_ctz_l(y);
  5911. -}
  5912. -
  5913. -static inline int a_cas(volatile int *p, int t, int s)
  5914. -{
  5915. - __asm__("\n"
  5916. - " sync\n"
  5917. - "1: lwarx %0, 0, %4\n"
  5918. - " cmpw %0, %2\n"
  5919. - " bne 1f\n"
  5920. - " stwcx. %3, 0, %4\n"
  5921. - " bne- 1b\n"
  5922. - " isync\n"
  5923. - "1: \n"
  5924. - : "=&r"(t), "+m"(*p) : "r"(t), "r"(s), "r"(p) : "cc", "memory" );
  5925. - return t;
  5926. -}
  5927. -
  5928. -static inline void *a_cas_p(volatile void *p, void *t, void *s)
  5929. -{
  5930. - return (void *)a_cas(p, (int)t, (int)s);
  5931. -}
  5932. -
  5933. -static inline int a_swap(volatile int *x, int v)
  5934. -{
  5935. - int old;
  5936. - do old = *x;
  5937. - while (a_cas(x, old, v) != old);
  5938. - return old;
  5939. -}
  5940. -
  5941. -static inline int a_fetch_add(volatile int *x, int v)
  5942. -{
  5943. - int old;
  5944. - do old = *x;
  5945. - while (a_cas(x, old, old+v) != old);
  5946. - return old;
  5947. -}
  5948. -
  5949. -static inline void a_inc(volatile int *x)
  5950. -{
  5951. - a_fetch_add(x, 1);
  5952. -}
  5953. -
  5954. -static inline void a_dec(volatile int *x)
  5955. -{
  5956. - a_fetch_add(x, -1);
  5957. -}
  5958. -
  5959. -static inline void a_store(volatile int *p, int x)
  5960. -{
  5961. - __asm__ __volatile__ ("\n"
  5962. - " sync\n"
  5963. - " stw %1, %0\n"
  5964. - " isync\n"
  5965. - : "=m"(*p) : "r"(x) : "memory" );
  5966. -}
  5967. -
  5968. -#define a_spin a_barrier
  5969. -
  5970. -static inline void a_barrier()
  5971. -{
  5972. - a_cas(&(int){0}, 0, 0);
  5973. -}
  5974. -
  5975. -static inline void a_crash()
  5976. -{
  5977. - *(volatile char *)0=0;
  5978. -}
  5979. -
  5980. -static inline void a_and(volatile int *p, int v)
  5981. -{
  5982. - int old;
  5983. - do old = *p;
  5984. - while (a_cas(p, old, old&v) != old);
  5985. -}
  5986. -
  5987. -static inline void a_or(volatile int *p, int v)
  5988. -{
  5989. - int old;
  5990. - do old = *p;
  5991. - while (a_cas(p, old, old|v) != old);
  5992. -}
  5993. -
  5994. -static inline void a_or_l(volatile void *p, long v)
  5995. -{
  5996. - a_or(p, v);
  5997. -}
  5998. -
  5999. -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
  6000. -{
  6001. - union { uint64_t v; uint32_t r[2]; } u = { v };
  6002. - a_and((int *)p, u.r[0]);
  6003. - a_and((int *)p+1, u.r[1]);
  6004. -}
  6005. -
  6006. -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
  6007. -{
  6008. - union { uint64_t v; uint32_t r[2]; } u = { v };
  6009. - a_or((int *)p, u.r[0]);
  6010. - a_or((int *)p+1, u.r[1]);
  6011. -}
  6012. -
  6013. -#endif
  6014. --- /dev/null
  6015. +++ b/arch/powerpc/atomic_arch.h
  6016. @@ -0,0 +1,39 @@
  6017. +#define a_ll a_ll
  6018. +static inline int a_ll(volatile int *p)
  6019. +{
  6020. + int v;
  6021. + __asm__ __volatile__ ("lwarx %0, 0, %2" : "=r"(v) : "m"(*p), "r"(p));
  6022. + return v;
  6023. +}
  6024. +
  6025. +#define a_sc a_sc
  6026. +static inline int a_sc(volatile int *p, int v)
  6027. +{
  6028. + int r;
  6029. + __asm__ __volatile__ (
  6030. + "stwcx. %2, 0, %3 ; mfcr %0"
  6031. + : "=r"(r), "=m"(*p) : "r"(v), "r"(p) : "memory", "cc");
  6032. + return r & 0x20000000; /* "bit 2" of "cr0" (backwards bit order) */
  6033. +}
  6034. +
  6035. +#define a_barrier a_barrier
  6036. +static inline void a_barrier()
  6037. +{
  6038. + __asm__ __volatile__ ("sync" : : : "memory");
  6039. +}
  6040. +
  6041. +#define a_pre_llsc a_barrier
  6042. +
  6043. +#define a_post_llsc a_post_llsc
  6044. +static inline void a_post_llsc()
  6045. +{
  6046. + __asm__ __volatile__ ("isync" : : : "memory");
  6047. +}
  6048. +
  6049. +#define a_store a_store
  6050. +static inline void a_store(volatile int *p, int v)
  6051. +{
  6052. + a_pre_llsc();
  6053. + *p = v;
  6054. + a_post_llsc();
  6055. +}
  6056. --- a/arch/powerpc/bits/mman.h
  6057. +++ b/arch/powerpc/bits/mman.h
  6058. @@ -4,6 +4,7 @@
  6059. #define PROT_READ 1
  6060. #define PROT_WRITE 2
  6061. #define PROT_EXEC 4
  6062. +#define PROT_SAO 0x10
  6063. #define PROT_GROWSDOWN 0x01000000
  6064. #define PROT_GROWSUP 0x02000000
  6065. @@ -35,8 +36,9 @@
  6066. #define MS_INVALIDATE 2
  6067. #define MS_SYNC 4
  6068. -#define MCL_CURRENT 1
  6069. -#define MCL_FUTURE 2
  6070. +#define MCL_CURRENT 0x2000
  6071. +#define MCL_FUTURE 0x4000
  6072. +#define MCL_ONFAULT 0x8000
  6073. #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  6074. #define MADV_NORMAL 0
  6075. --- a/arch/powerpc/bits/statfs.h
  6076. +++ /dev/null
  6077. @@ -1,7 +0,0 @@
  6078. -struct statfs {
  6079. - unsigned long f_type, f_bsize;
  6080. - fsblkcnt_t f_blocks, f_bfree, f_bavail;
  6081. - fsfilcnt_t f_files, f_ffree;
  6082. - fsid_t f_fsid;
  6083. - unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
  6084. -};
  6085. --- a/arch/powerpc/bits/stdarg.h
  6086. +++ /dev/null
  6087. @@ -1,4 +0,0 @@
  6088. -#define va_start(v,l) __builtin_va_start(v,l)
  6089. -#define va_end(v) __builtin_va_end(v)
  6090. -#define va_arg(v,l) __builtin_va_arg(v,l)
  6091. -#define va_copy(d,s) __builtin_va_copy(d,s)
  6092. --- a/arch/powerpc/bits/syscall.h
  6093. +++ b/arch/powerpc/bits/syscall.h
  6094. @@ -194,23 +194,19 @@
  6095. #define __NR_vfork 189
  6096. #define __NR_ugetrlimit 190
  6097. #define __NR_readahead 191
  6098. -#if !defined(__PPC64) || defined(__ABI32)
  6099. #define __NR_mmap2 192
  6100. #define __NR_truncate64 193
  6101. #define __NR_ftruncate64 194
  6102. #define __NR_stat64 195
  6103. #define __NR_lstat64 196
  6104. #define __NR_fstat64 197
  6105. -#endif
  6106. #define __NR_pciconfig_read 198
  6107. #define __NR_pciconfig_write 199
  6108. #define __NR_pciconfig_iobase 200
  6109. #define __NR_multiplexer 201
  6110. #define __NR_getdents64 202
  6111. #define __NR_pivot_root 203
  6112. -#if !defined(__PPC64) || defined(__ABI32)
  6113. #define __NR_fcntl64 204
  6114. -#endif
  6115. #define __NR_madvise 205
  6116. #define __NR_mincore 206
  6117. #define __NR_gettid 207
  6118. @@ -231,9 +227,7 @@
  6119. #define __NR_sched_setaffinity 222
  6120. #define __NR_sched_getaffinity 223
  6121. #define __NR_tuxcall 225
  6122. -#if !defined(__PPC64) || defined(__ABI32)
  6123. #define __NR_sendfile64 226
  6124. -#endif
  6125. #define __NR_io_setup 227
  6126. #define __NR_io_destroy 228
  6127. #define __NR_io_getevents 229
  6128. @@ -261,9 +255,7 @@
  6129. #define __NR_utimes 251
  6130. #define __NR_statfs64 252
  6131. #define __NR_fstatfs64 253
  6132. -#if !defined(__PPC64) || defined(__ABI32)
  6133. #define __NR_fadvise64_64 254
  6134. -#endif
  6135. #define __NR_rtas 255
  6136. #define __NR_sys_debug_setcontext 256
  6137. #define __NR_migrate_pages 258
  6138. @@ -299,11 +291,7 @@
  6139. #define __NR_mknodat 288
  6140. #define __NR_fchownat 289
  6141. #define __NR_futimesat 290
  6142. -#if defined(__PPC64) && !defined(__ABI32)
  6143. -#define __NR_newfstatat 291
  6144. -#else
  6145. #define __NR_fstatat64 291
  6146. -#endif
  6147. #define __NR_unlinkat 292
  6148. #define __NR_renameat 293
  6149. #define __NR_linkat 294
  6150. @@ -376,6 +364,10 @@
  6151. #define __NR_memfd_create 360
  6152. #define __NR_bpf 361
  6153. #define __NR_execveat 362
  6154. +#define __NR_switch_endian 363
  6155. +#define __NR_userfaultfd 364
  6156. +#define __NR_membarrier 365
  6157. +#define __NR_mlock2 378
  6158. /*
  6159. * repeated with SYS prefix
  6160. @@ -576,23 +568,19 @@
  6161. #define SYS_vfork 189
  6162. #define SYS_ugetrlimit 190
  6163. #define SYS_readahead 191
  6164. -#if !defined(__PPC64) || defined(__ABI32)
  6165. #define SYS_mmap2 192
  6166. #define SYS_truncate64 193
  6167. #define SYS_ftruncate64 194
  6168. #define SYS_stat64 195
  6169. #define SYS_lstat64 196
  6170. #define SYS_fstat64 197
  6171. -#endif
  6172. #define SYS_pciconfig_read 198
  6173. #define SYS_pciconfig_write 199
  6174. #define SYS_pciconfig_iobase 200
  6175. #define SYS_multiplexer 201
  6176. #define SYS_getdents64 202
  6177. #define SYS_pivot_root 203
  6178. -#if !defined(__PPC64) || defined(__ABI32)
  6179. #define SYS_fcntl64 204
  6180. -#endif
  6181. #define SYS_madvise 205
  6182. #define SYS_mincore 206
  6183. #define SYS_gettid 207
  6184. @@ -613,9 +601,7 @@
  6185. #define SYS_sched_setaffinity 222
  6186. #define SYS_sched_getaffinity 223
  6187. #define SYS_tuxcall 225
  6188. -#if !defined(__PPC64) || defined(__ABI32)
  6189. #define SYS_sendfile64 226
  6190. -#endif
  6191. #define SYS_io_setup 227
  6192. #define SYS_io_destroy 228
  6193. #define SYS_io_getevents 229
  6194. @@ -643,9 +629,7 @@
  6195. #define SYS_utimes 251
  6196. #define SYS_statfs64 252
  6197. #define SYS_fstatfs64 253
  6198. -#if !defined(__PPC64) || defined(__ABI32)
  6199. #define SYS_fadvise64_64 254
  6200. -#endif
  6201. #define SYS_rtas 255
  6202. #define SYS_sys_debug_setcontext 256
  6203. #define SYS_migrate_pages 258
  6204. @@ -681,11 +665,7 @@
  6205. #define SYS_mknodat 288
  6206. #define SYS_fchownat 289
  6207. #define SYS_futimesat 290
  6208. -#if defined(__PPC64) && !defined(__ABI32)
  6209. -#define SYS_newfstatat 291
  6210. -#else
  6211. #define SYS_fstatat64 291
  6212. -#endif
  6213. #define SYS_unlinkat 292
  6214. #define SYS_renameat 293
  6215. #define SYS_linkat 294
  6216. @@ -758,3 +738,7 @@
  6217. #define SYS_memfd_create 360
  6218. #define SYS_bpf 361
  6219. #define SYS_execveat 362
  6220. +#define SYS_switch_endian 363
  6221. +#define SYS_userfaultfd 364
  6222. +#define SYS_membarrier 365
  6223. +#define SYS_mlock2 378
  6224. --- a/arch/powerpc/pthread_arch.h
  6225. +++ b/arch/powerpc/pthread_arch.h
  6226. @@ -15,9 +15,8 @@ static inline struct pthread *__pthread_
  6227. #define DTP_OFFSET 0x8000
  6228. -// offset of the PC register in mcontext_t, divided by the system wordsize
  6229. // the kernel calls the ip "nip", it's the first saved value after the 32
  6230. // GPRs.
  6231. -#define CANCEL_REG_IP 32
  6232. +#define MC_PC gregs[32]
  6233. #define CANARY canary_at_end
  6234. --- a/arch/sh/atomic.h
  6235. +++ /dev/null
  6236. @@ -1,168 +0,0 @@
  6237. -#ifndef _INTERNAL_ATOMIC_H
  6238. -#define _INTERNAL_ATOMIC_H
  6239. -
  6240. -#include <stdint.h>
  6241. -
  6242. -static inline int a_ctz_l(unsigned long x)
  6243. -{
  6244. - static const char debruijn32[32] = {
  6245. - 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13,
  6246. - 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14
  6247. - };
  6248. - return debruijn32[(x&-x)*0x076be629 >> 27];
  6249. -}
  6250. -
  6251. -static inline int a_ctz_64(uint64_t x)
  6252. -{
  6253. - uint32_t y = x;
  6254. - if (!y) {
  6255. - y = x>>32;
  6256. - return 32 + a_ctz_l(y);
  6257. - }
  6258. - return a_ctz_l(y);
  6259. -}
  6260. -
  6261. -#define LLSC_CLOBBERS "r0", "t", "memory"
  6262. -#define LLSC_START(mem) "synco\n" \
  6263. - "0: movli.l @" mem ", r0\n"
  6264. -#define LLSC_END(mem) \
  6265. - "1: movco.l r0, @" mem "\n" \
  6266. - " bf 0b\n" \
  6267. - " synco\n"
  6268. -
  6269. -static inline int __sh_cas_llsc(volatile int *p, int t, int s)
  6270. -{
  6271. - int old;
  6272. - __asm__ __volatile__(
  6273. - LLSC_START("%1")
  6274. - " mov r0, %0\n"
  6275. - " cmp/eq %0, %2\n"
  6276. - " bf 1f\n"
  6277. - " mov %3, r0\n"
  6278. - LLSC_END("%1")
  6279. - : "=&r"(old) : "r"(p), "r"(t), "r"(s) : LLSC_CLOBBERS);
  6280. - return old;
  6281. -}
  6282. -
  6283. -static inline int __sh_swap_llsc(volatile int *x, int v)
  6284. -{
  6285. - int old;
  6286. - __asm__ __volatile__(
  6287. - LLSC_START("%1")
  6288. - " mov r0, %0\n"
  6289. - " mov %2, r0\n"
  6290. - LLSC_END("%1")
  6291. - : "=&r"(old) : "r"(x), "r"(v) : LLSC_CLOBBERS);
  6292. - return old;
  6293. -}
  6294. -
  6295. -static inline int __sh_fetch_add_llsc(volatile int *x, int v)
  6296. -{
  6297. - int old;
  6298. - __asm__ __volatile__(
  6299. - LLSC_START("%1")
  6300. - " mov r0, %0\n"
  6301. - " add %2, r0\n"
  6302. - LLSC_END("%1")
  6303. - : "=&r"(old) : "r"(x), "r"(v) : LLSC_CLOBBERS);
  6304. - return old;
  6305. -}
  6306. -
  6307. -static inline void __sh_store_llsc(volatile int *p, int x)
  6308. -{
  6309. - __asm__ __volatile__(
  6310. - " synco\n"
  6311. - " mov.l %1, @%0\n"
  6312. - " synco\n"
  6313. - : : "r"(p), "r"(x) : "memory");
  6314. -}
  6315. -
  6316. -static inline void __sh_and_llsc(volatile int *x, int v)
  6317. -{
  6318. - __asm__ __volatile__(
  6319. - LLSC_START("%0")
  6320. - " and %1, r0\n"
  6321. - LLSC_END("%0")
  6322. - : : "r"(x), "r"(v) : LLSC_CLOBBERS);
  6323. -}
  6324. -
  6325. -static inline void __sh_or_llsc(volatile int *x, int v)
  6326. -{
  6327. - __asm__ __volatile__(
  6328. - LLSC_START("%0")
  6329. - " or %1, r0\n"
  6330. - LLSC_END("%0")
  6331. - : : "r"(x), "r"(v) : LLSC_CLOBBERS);
  6332. -}
  6333. -
  6334. -#ifdef __SH4A__
  6335. -#define a_cas(p,t,s) __sh_cas_llsc(p,t,s)
  6336. -#define a_swap(x,v) __sh_swap_llsc(x,v)
  6337. -#define a_fetch_add(x,v) __sh_fetch_add_llsc(x, v)
  6338. -#define a_store(x,v) __sh_store_llsc(x, v)
  6339. -#define a_and(x,v) __sh_and_llsc(x, v)
  6340. -#define a_or(x,v) __sh_or_llsc(x, v)
  6341. -#else
  6342. -
  6343. -int __sh_cas(volatile int *, int, int);
  6344. -int __sh_swap(volatile int *, int);
  6345. -int __sh_fetch_add(volatile int *, int);
  6346. -void __sh_store(volatile int *, int);
  6347. -void __sh_and(volatile int *, int);
  6348. -void __sh_or(volatile int *, int);
  6349. -
  6350. -#define a_cas(p,t,s) __sh_cas(p,t,s)
  6351. -#define a_swap(x,v) __sh_swap(x,v)
  6352. -#define a_fetch_add(x,v) __sh_fetch_add(x, v)
  6353. -#define a_store(x,v) __sh_store(x, v)
  6354. -#define a_and(x,v) __sh_and(x, v)
  6355. -#define a_or(x,v) __sh_or(x, v)
  6356. -#endif
  6357. -
  6358. -static inline void *a_cas_p(volatile void *p, void *t, void *s)
  6359. -{
  6360. - return (void *)a_cas(p, (int)t, (int)s);
  6361. -}
  6362. -
  6363. -static inline void a_inc(volatile int *x)
  6364. -{
  6365. - a_fetch_add(x, 1);
  6366. -}
  6367. -
  6368. -static inline void a_dec(volatile int *x)
  6369. -{
  6370. - a_fetch_add(x, -1);
  6371. -}
  6372. -
  6373. -#define a_spin a_barrier
  6374. -
  6375. -static inline void a_barrier()
  6376. -{
  6377. - a_cas(&(int){0}, 0, 0);
  6378. -}
  6379. -
  6380. -static inline void a_crash()
  6381. -{
  6382. - *(volatile char *)0=0;
  6383. -}
  6384. -
  6385. -static inline void a_or_l(volatile void *p, long v)
  6386. -{
  6387. - a_or(p, v);
  6388. -}
  6389. -
  6390. -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
  6391. -{
  6392. - union { uint64_t v; uint32_t r[2]; } u = { v };
  6393. - a_and((int *)p, u.r[0]);
  6394. - a_and((int *)p+1, u.r[1]);
  6395. -}
  6396. -
  6397. -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
  6398. -{
  6399. - union { uint64_t v; uint32_t r[2]; } u = { v };
  6400. - a_or((int *)p, u.r[0]);
  6401. - a_or((int *)p+1, u.r[1]);
  6402. -}
  6403. -
  6404. -#endif
  6405. --- /dev/null
  6406. +++ b/arch/sh/atomic_arch.h
  6407. @@ -0,0 +1,46 @@
  6408. +#if defined(__SH4A__)
  6409. +
  6410. +#define a_ll a_ll
  6411. +static inline int a_ll(volatile int *p)
  6412. +{
  6413. + int v;
  6414. + __asm__ __volatile__ ("movli.l @%1, %0" : "=z"(v) : "r"(p), "m"(*p));
  6415. + return v;
  6416. +}
  6417. +
  6418. +#define a_sc a_sc
  6419. +static inline int a_sc(volatile int *p, int v)
  6420. +{
  6421. + int r;
  6422. + __asm__ __volatile__ (
  6423. + "movco.l %2, @%3 ; movt %0"
  6424. + : "=r"(r), "=m"(*p) : "z"(v), "r"(p) : "memory", "cc");
  6425. + return r;
  6426. +}
  6427. +
  6428. +#define a_barrier a_barrier
  6429. +static inline void a_barrier()
  6430. +{
  6431. + __asm__ __volatile__ ("synco" : : "memory");
  6432. +}
  6433. +
  6434. +#define a_pre_llsc a_barrier
  6435. +#define a_post_llsc a_barrier
  6436. +
  6437. +#else
  6438. +
  6439. +#define a_cas a_cas
  6440. +__attribute__((__visibility__("hidden"))) extern const void *__sh_cas_ptr;
  6441. +static inline int a_cas(volatile int *p, int t, int s)
  6442. +{
  6443. + register int r1 __asm__("r1");
  6444. + register int r2 __asm__("r2") = t;
  6445. + register int r3 __asm__("r3") = s;
  6446. + __asm__ __volatile__ (
  6447. + "jsr @%4 ; nop"
  6448. + : "=r"(r1), "+r"(r3) : "z"(p), "r"(r2), "r"(__sh_cas_ptr)
  6449. + : "memory", "pr", "cc");
  6450. + return r3;
  6451. +}
  6452. +
  6453. +#endif
  6454. --- a/arch/sh/bits/errno.h
  6455. +++ /dev/null
  6456. @@ -1,134 +0,0 @@
  6457. -#define EPERM 1
  6458. -#define ENOENT 2
  6459. -#define ESRCH 3
  6460. -#define EINTR 4
  6461. -#define EIO 5
  6462. -#define ENXIO 6
  6463. -#define E2BIG 7
  6464. -#define ENOEXEC 8
  6465. -#define EBADF 9
  6466. -#define ECHILD 10
  6467. -#define EAGAIN 11
  6468. -#define ENOMEM 12
  6469. -#define EACCES 13
  6470. -#define EFAULT 14
  6471. -#define ENOTBLK 15
  6472. -#define EBUSY 16
  6473. -#define EEXIST 17
  6474. -#define EXDEV 18
  6475. -#define ENODEV 19
  6476. -#define ENOTDIR 20
  6477. -#define EISDIR 21
  6478. -#define EINVAL 22
  6479. -#define ENFILE 23
  6480. -#define EMFILE 24
  6481. -#define ENOTTY 25
  6482. -#define ETXTBSY 26
  6483. -#define EFBIG 27
  6484. -#define ENOSPC 28
  6485. -#define ESPIPE 29
  6486. -#define EROFS 30
  6487. -#define EMLINK 31
  6488. -#define EPIPE 32
  6489. -#define EDOM 33
  6490. -#define ERANGE 34
  6491. -#define EDEADLK 35
  6492. -#define ENAMETOOLONG 36
  6493. -#define ENOLCK 37
  6494. -#define ENOSYS 38
  6495. -#define ENOTEMPTY 39
  6496. -#define ELOOP 40
  6497. -#define EWOULDBLOCK EAGAIN
  6498. -#define ENOMSG 42
  6499. -#define EIDRM 43
  6500. -#define ECHRNG 44
  6501. -#define EL2NSYNC 45
  6502. -#define EL3HLT 46
  6503. -#define EL3RST 47
  6504. -#define ELNRNG 48
  6505. -#define EUNATCH 49
  6506. -#define ENOCSI 50
  6507. -#define EL2HLT 51
  6508. -#define EBADE 52
  6509. -#define EBADR 53
  6510. -#define EXFULL 54
  6511. -#define ENOANO 55
  6512. -#define EBADRQC 56
  6513. -#define EBADSLT 57
  6514. -#define EDEADLOCK EDEADLK
  6515. -#define EBFONT 59
  6516. -#define ENOSTR 60
  6517. -#define ENODATA 61
  6518. -#define ETIME 62
  6519. -#define ENOSR 63
  6520. -#define ENONET 64
  6521. -#define ENOPKG 65
  6522. -#define EREMOTE 66
  6523. -#define ENOLINK 67
  6524. -#define EADV 68
  6525. -#define ESRMNT 69
  6526. -#define ECOMM 70
  6527. -#define EPROTO 71
  6528. -#define EMULTIHOP 72
  6529. -#define EDOTDOT 73
  6530. -#define EBADMSG 74
  6531. -#define EOVERFLOW 75
  6532. -#define ENOTUNIQ 76
  6533. -#define EBADFD 77
  6534. -#define EREMCHG 78
  6535. -#define ELIBACC 79
  6536. -#define ELIBBAD 80
  6537. -#define ELIBSCN 81
  6538. -#define ELIBMAX 82
  6539. -#define ELIBEXEC 83
  6540. -#define EILSEQ 84
  6541. -#define ERESTART 85
  6542. -#define ESTRPIPE 86
  6543. -#define EUSERS 87
  6544. -#define ENOTSOCK 88
  6545. -#define EDESTADDRREQ 89
  6546. -#define EMSGSIZE 90
  6547. -#define EPROTOTYPE 91
  6548. -#define ENOPROTOOPT 92
  6549. -#define EPROTONOSUPPORT 93
  6550. -#define ESOCKTNOSUPPORT 94
  6551. -#define EOPNOTSUPP 95
  6552. -#define ENOTSUP EOPNOTSUPP
  6553. -#define EPFNOSUPPORT 96
  6554. -#define EAFNOSUPPORT 97
  6555. -#define EADDRINUSE 98
  6556. -#define EADDRNOTAVAIL 99
  6557. -#define ENETDOWN 100
  6558. -#define ENETUNREACH 101
  6559. -#define ENETRESET 102
  6560. -#define ECONNABORTED 103
  6561. -#define ECONNRESET 104
  6562. -#define ENOBUFS 105
  6563. -#define EISCONN 106
  6564. -#define ENOTCONN 107
  6565. -#define ESHUTDOWN 108
  6566. -#define ETOOMANYREFS 109
  6567. -#define ETIMEDOUT 110
  6568. -#define ECONNREFUSED 111
  6569. -#define EHOSTDOWN 112
  6570. -#define EHOSTUNREACH 113
  6571. -#define EALREADY 114
  6572. -#define EINPROGRESS 115
  6573. -#define ESTALE 116
  6574. -#define EUCLEAN 117
  6575. -#define ENOTNAM 118
  6576. -#define ENAVAIL 119
  6577. -#define EISNAM 120
  6578. -#define EREMOTEIO 121
  6579. -#define EDQUOT 122
  6580. -#define ENOMEDIUM 123
  6581. -#define EMEDIUMTYPE 124
  6582. -#define ECANCELED 125
  6583. -#define ENOKEY 126
  6584. -#define EKEYEXPIRED 127
  6585. -#define EKEYREVOKED 128
  6586. -#define EKEYREJECTED 129
  6587. -#define EOWNERDEAD 130
  6588. -#define ENOTRECOVERABLE 131
  6589. -#define ERFKILL 132
  6590. -#define EHWPOISON 133
  6591. --- a/arch/sh/bits/fcntl.h
  6592. +++ /dev/null
  6593. @@ -1,40 +0,0 @@
  6594. -#define O_CREAT 0100
  6595. -#define O_EXCL 0200
  6596. -#define O_NOCTTY 0400
  6597. -#define O_TRUNC 01000
  6598. -#define O_APPEND 02000
  6599. -#define O_NONBLOCK 04000
  6600. -#define O_DSYNC 010000
  6601. -#define O_SYNC 04010000
  6602. -#define O_RSYNC 04010000
  6603. -#define O_DIRECTORY 0200000
  6604. -#define O_NOFOLLOW 0400000
  6605. -#define O_CLOEXEC 02000000
  6606. -
  6607. -#define O_ASYNC 020000
  6608. -#define O_DIRECT 040000
  6609. -#define O_LARGEFILE 0100000
  6610. -#define O_NOATIME 01000000
  6611. -#define O_PATH 010000000
  6612. -#define O_TMPFILE 020200000
  6613. -#define O_NDELAY O_NONBLOCK
  6614. -
  6615. -#define F_DUPFD 0
  6616. -#define F_GETFD 1
  6617. -#define F_SETFD 2
  6618. -#define F_GETFL 3
  6619. -#define F_SETFL 4
  6620. -
  6621. -#define F_SETOWN 8
  6622. -#define F_GETOWN 9
  6623. -#define F_SETSIG 10
  6624. -#define F_GETSIG 11
  6625. -
  6626. -#define F_GETLK 12
  6627. -#define F_SETLK 13
  6628. -#define F_SETLKW 14
  6629. -
  6630. -#define F_SETOWN_EX 15
  6631. -#define F_GETOWN_EX 16
  6632. -
  6633. -#define F_GETOWNER_UIDS 17
  6634. --- a/arch/sh/bits/ipc.h
  6635. +++ /dev/null
  6636. @@ -1,14 +0,0 @@
  6637. -struct ipc_perm
  6638. -{
  6639. - key_t __ipc_perm_key;
  6640. - uid_t uid;
  6641. - gid_t gid;
  6642. - uid_t cuid;
  6643. - gid_t cgid;
  6644. - mode_t mode;
  6645. - int __ipc_perm_seq;
  6646. - long __pad1;
  6647. - long __pad2;
  6648. -};
  6649. -
  6650. -#define IPC_64 0x100
  6651. --- a/arch/sh/bits/mman.h
  6652. +++ b/arch/sh/bits/mman.h
  6653. @@ -38,6 +38,7 @@
  6654. #define MCL_CURRENT 1
  6655. #define MCL_FUTURE 2
  6656. +#define MCL_ONFAULT 4
  6657. #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  6658. #define MADV_NORMAL 0
  6659. --- a/arch/sh/bits/msg.h
  6660. +++ /dev/null
  6661. @@ -1,16 +0,0 @@
  6662. -struct msqid_ds
  6663. -{
  6664. - struct ipc_perm msg_perm;
  6665. - time_t msg_stime;
  6666. - int __unused1;
  6667. - time_t msg_rtime;
  6668. - int __unused2;
  6669. - time_t msg_ctime;
  6670. - int __unused3;
  6671. - unsigned long msg_cbytes;
  6672. - msgqnum_t msg_qnum;
  6673. - msglen_t msg_qbytes;
  6674. - pid_t msg_lspid;
  6675. - pid_t msg_lrpid;
  6676. - unsigned long __unused[2];
  6677. -};
  6678. --- a/arch/sh/bits/sem.h
  6679. +++ /dev/null
  6680. @@ -1,16 +0,0 @@
  6681. -struct semid_ds {
  6682. - struct ipc_perm sem_perm;
  6683. - time_t sem_otime;
  6684. - time_t __unused1;
  6685. - time_t sem_ctime;
  6686. - time_t __unused2;
  6687. -#if __BYTE_ORDER == __LITTLE_ENDIAN
  6688. - unsigned short sem_nsems;
  6689. - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
  6690. -#else
  6691. - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
  6692. - unsigned short sem_nsems;
  6693. -#endif
  6694. - time_t __unused3;
  6695. - time_t __unused4;
  6696. -};
  6697. --- a/arch/sh/bits/socket.h
  6698. +++ /dev/null
  6699. @@ -1,17 +0,0 @@
  6700. -struct msghdr
  6701. -{
  6702. - void *msg_name;
  6703. - socklen_t msg_namelen;
  6704. - struct iovec *msg_iov;
  6705. - int msg_iovlen;
  6706. - void *msg_control;
  6707. - socklen_t msg_controllen;
  6708. - int msg_flags;
  6709. -};
  6710. -
  6711. -struct cmsghdr
  6712. -{
  6713. - socklen_t cmsg_len;
  6714. - int cmsg_level;
  6715. - int cmsg_type;
  6716. -};
  6717. --- a/arch/sh/bits/statfs.h
  6718. +++ /dev/null
  6719. @@ -1,7 +0,0 @@
  6720. -struct statfs {
  6721. - unsigned long f_type, f_bsize;
  6722. - fsblkcnt_t f_blocks, f_bfree, f_bavail;
  6723. - fsfilcnt_t f_files, f_ffree;
  6724. - fsid_t f_fsid;
  6725. - unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
  6726. -};
  6727. --- a/arch/sh/bits/stdarg.h
  6728. +++ /dev/null
  6729. @@ -1,4 +0,0 @@
  6730. -#define va_start(v,l) __builtin_va_start(v,l)
  6731. -#define va_end(v) __builtin_va_end(v)
  6732. -#define va_arg(v,l) __builtin_va_arg(v,l)
  6733. -#define va_copy(d,s) __builtin_va_copy(d,s)
  6734. --- a/arch/sh/bits/termios.h
  6735. +++ /dev/null
  6736. @@ -1,160 +0,0 @@
  6737. -struct termios
  6738. -{
  6739. - tcflag_t c_iflag;
  6740. - tcflag_t c_oflag;
  6741. - tcflag_t c_cflag;
  6742. - tcflag_t c_lflag;
  6743. - cc_t c_line;
  6744. - cc_t c_cc[NCCS];
  6745. - speed_t __c_ispeed;
  6746. - speed_t __c_ospeed;
  6747. -};
  6748. -
  6749. -#define VINTR 0
  6750. -#define VQUIT 1
  6751. -#define VERASE 2
  6752. -#define VKILL 3
  6753. -#define VEOF 4
  6754. -#define VTIME 5
  6755. -#define VMIN 6
  6756. -#define VSWTC 7
  6757. -#define VSTART 8
  6758. -#define VSTOP 9
  6759. -#define VSUSP 10
  6760. -#define VEOL 11
  6761. -#define VREPRINT 12
  6762. -#define VDISCARD 13
  6763. -#define VWERASE 14
  6764. -#define VLNEXT 15
  6765. -#define VEOL2 16
  6766. -
  6767. -#define IGNBRK 0000001
  6768. -#define BRKINT 0000002
  6769. -#define IGNPAR 0000004
  6770. -#define PARMRK 0000010
  6771. -#define INPCK 0000020
  6772. -#define ISTRIP 0000040
  6773. -#define INLCR 0000100
  6774. -#define IGNCR 0000200
  6775. -#define ICRNL 0000400
  6776. -#define IUCLC 0001000
  6777. -#define IXON 0002000
  6778. -#define IXANY 0004000
  6779. -#define IXOFF 0010000
  6780. -#define IMAXBEL 0020000
  6781. -#define IUTF8 0040000
  6782. -
  6783. -#define OPOST 0000001
  6784. -#define OLCUC 0000002
  6785. -#define ONLCR 0000004
  6786. -#define OCRNL 0000010
  6787. -#define ONOCR 0000020
  6788. -#define ONLRET 0000040
  6789. -#define OFILL 0000100
  6790. -#define OFDEL 0000200
  6791. -#define NLDLY 0000400
  6792. -#define NL0 0000000
  6793. -#define NL1 0000400
  6794. -#define CRDLY 0003000
  6795. -#define CR0 0000000
  6796. -#define CR1 0001000
  6797. -#define CR2 0002000
  6798. -#define CR3 0003000
  6799. -#define TABDLY 0014000
  6800. -#define TAB0 0000000
  6801. -#define TAB1 0004000
  6802. -#define TAB2 0010000
  6803. -#define TAB3 0014000
  6804. -#define BSDLY 0020000
  6805. -#define BS0 0000000
  6806. -#define BS1 0020000
  6807. -#define FFDLY 0100000
  6808. -#define FF0 0000000
  6809. -#define FF1 0100000
  6810. -
  6811. -#define VTDLY 0040000
  6812. -#define VT0 0000000
  6813. -#define VT1 0040000
  6814. -
  6815. -#define B0 0000000
  6816. -#define B50 0000001
  6817. -#define B75 0000002
  6818. -#define B110 0000003
  6819. -#define B134 0000004
  6820. -#define B150 0000005
  6821. -#define B200 0000006
  6822. -#define B300 0000007
  6823. -#define B600 0000010
  6824. -#define B1200 0000011
  6825. -#define B1800 0000012
  6826. -#define B2400 0000013
  6827. -#define B4800 0000014
  6828. -#define B9600 0000015
  6829. -#define B19200 0000016
  6830. -#define B38400 0000017
  6831. -
  6832. -#define B57600 0010001
  6833. -#define B115200 0010002
  6834. -#define B230400 0010003
  6835. -#define B460800 0010004
  6836. -#define B500000 0010005
  6837. -#define B576000 0010006
  6838. -#define B921600 0010007
  6839. -#define B1000000 0010010
  6840. -#define B1152000 0010011
  6841. -#define B1500000 0010012
  6842. -#define B2000000 0010013
  6843. -#define B2500000 0010014
  6844. -#define B3000000 0010015
  6845. -#define B3500000 0010016
  6846. -#define B4000000 0010017
  6847. -
  6848. -#define CBAUD 0010017
  6849. -
  6850. -#define CSIZE 0000060
  6851. -#define CS5 0000000
  6852. -#define CS6 0000020
  6853. -#define CS7 0000040
  6854. -#define CS8 0000060
  6855. -#define CSTOPB 0000100
  6856. -#define CREAD 0000200
  6857. -#define PARENB 0000400
  6858. -#define PARODD 0001000
  6859. -#define HUPCL 0002000
  6860. -#define CLOCAL 0004000
  6861. -
  6862. -#define ISIG 0000001
  6863. -#define ICANON 0000002
  6864. -#define ECHO 0000010
  6865. -#define ECHOE 0000020
  6866. -#define ECHOK 0000040
  6867. -#define ECHONL 0000100
  6868. -#define NOFLSH 0000200
  6869. -#define TOSTOP 0000400
  6870. -#define IEXTEN 0100000
  6871. -
  6872. -#define ECHOCTL 0001000
  6873. -#define ECHOPRT 0002000
  6874. -#define ECHOKE 0004000
  6875. -#define FLUSHO 0010000
  6876. -#define PENDIN 0040000
  6877. -
  6878. -#define TCOOFF 0
  6879. -#define TCOON 1
  6880. -#define TCIOFF 2
  6881. -#define TCION 3
  6882. -
  6883. -#define TCIFLUSH 0
  6884. -#define TCOFLUSH 1
  6885. -#define TCIOFLUSH 2
  6886. -
  6887. -#define TCSANOW 0
  6888. -#define TCSADRAIN 1
  6889. -#define TCSAFLUSH 2
  6890. -
  6891. -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  6892. -#define CBAUDEX 0010000
  6893. -#define CRTSCTS 020000000000
  6894. -#define EXTPROC 0200000
  6895. -#define XTABS 0014000
  6896. -#endif
  6897. --- a/arch/sh/crt_arch.h
  6898. +++ b/arch/sh/crt_arch.h
  6899. @@ -22,7 +22,8 @@ START ": \n"
  6900. " mov.l 1f, r5 \n"
  6901. " mov.l 1f+4, r6 \n"
  6902. " add r0, r5 \n"
  6903. -" bsr __fdpic_fixup \n"
  6904. +" mov.l 4f, r1 \n"
  6905. +"5: bsrf r1 \n"
  6906. " add r0, r6 \n"
  6907. " mov r0, r12 \n"
  6908. #endif
  6909. @@ -31,11 +32,16 @@ START ": \n"
  6910. " mov.l r9, @-r15 \n"
  6911. " mov.l r8, @-r15 \n"
  6912. " mov #-16, r0 \n"
  6913. -" bsr " START "_c \n"
  6914. +" mov.l 2f, r1 \n"
  6915. +"3: bsrf r1 \n"
  6916. " and r0, r15 \n"
  6917. ".align 2 \n"
  6918. "1: .long __ROFIXUP_LIST__@PCREL \n"
  6919. " .long __ROFIXUP_END__@PCREL + 4 \n"
  6920. +"2: .long " START "_c@PCREL - (3b+4-.) \n"
  6921. +#ifndef SHARED
  6922. +"4: .long __fdpic_fixup@PCREL - (5b+4-.) \n"
  6923. +#endif
  6924. );
  6925. #ifndef SHARED
  6926. @@ -53,13 +59,14 @@ START ": \n"
  6927. " add r0, r5 \n"
  6928. " mov r15, r4 \n"
  6929. " mov #-16, r0 \n"
  6930. -" and r0, r15 \n"
  6931. -" bsr " START "_c \n"
  6932. -" nop \n"
  6933. +" mov.l 2f, r1 \n"
  6934. +"3: bsrf r1 \n"
  6935. +" and r0, r15 \n"
  6936. ".align 2 \n"
  6937. ".weak _DYNAMIC \n"
  6938. ".hidden _DYNAMIC \n"
  6939. "1: .long _DYNAMIC-. \n"
  6940. +"2: .long " START "_c@PCREL - (3b+4-.) \n"
  6941. );
  6942. #endif
  6943. --- a/arch/sh/pthread_arch.h
  6944. +++ b/arch/sh/pthread_arch.h
  6945. @@ -8,4 +8,4 @@ static inline struct pthread *__pthread_
  6946. #define TLS_ABOVE_TP
  6947. #define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) - 8)
  6948. -#define CANCEL_REG_IP 17
  6949. +#define MC_PC sc_pc
  6950. --- a/arch/sh/reloc.h
  6951. +++ b/arch/sh/reloc.h
  6952. @@ -32,6 +32,8 @@
  6953. #define REL_DTPOFF R_SH_TLS_DTPOFF32
  6954. #define REL_TPOFF R_SH_TLS_TPOFF32
  6955. +#define DL_NOMMU_SUPPORT 1
  6956. +
  6957. #if __SH_FDPIC__
  6958. #define REL_FUNCDESC R_SH_FUNCDESC
  6959. #define REL_FUNCDESC_VAL R_SH_FUNCDESC_VALUE
  6960. --- a/arch/sh/src/__fpscr_values.c
  6961. +++ /dev/null
  6962. @@ -1,5 +0,0 @@
  6963. -#include "libc.h"
  6964. -
  6965. -/* used by gcc for switching the FPU between single and double precision */
  6966. -//const unsigned long __fpscr_values[2] ATTR_LIBC_VISIBILITY = { 0, 0x80000 };
  6967. -
  6968. --- a/arch/sh/src/__set_thread_area.c
  6969. +++ /dev/null
  6970. @@ -1,34 +0,0 @@
  6971. -#include "pthread_impl.h"
  6972. -#include "libc.h"
  6973. -#include "sh_atomic.h"
  6974. -#include <elf.h>
  6975. -
  6976. -/* Also perform sh-specific init */
  6977. -
  6978. -#define CPU_HAS_LLSC 0x0040
  6979. -
  6980. -__attribute__((__visibility__("hidden"))) unsigned __sh_atomic_model, __sh_nommu;
  6981. -
  6982. -int __set_thread_area(void *p)
  6983. -{
  6984. - size_t *aux;
  6985. - __asm__ __volatile__ ( "ldc %0, gbr" : : "r"(p) : "memory" );
  6986. -#ifndef __SH4A__
  6987. - if (__hwcap & CPU_HAS_LLSC) {
  6988. - __sh_atomic_model = SH_A_LLSC;
  6989. - return 0;
  6990. - }
  6991. -#if !defined(__SH3__) && !defined(__SH4__)
  6992. - for (aux=libc.auxv; *aux; aux+=2) {
  6993. - if (*aux != AT_PLATFORM) continue;
  6994. - const char *s = (void *)aux[1];
  6995. - if (s[0]!='s' || s[1]!='h' || s[2]!='2' || s[3]-'0'<10u) break;
  6996. - __sh_atomic_model = SH_A_IMASK;
  6997. - __sh_nommu = 1;
  6998. - return 0;
  6999. - }
  7000. -#endif
  7001. - /* __sh_atomic_model = SH_A_GUSA; */ /* 0, default */
  7002. -#endif
  7003. - return 0;
  7004. -}
  7005. --- a/arch/sh/src/__shcall.c
  7006. +++ /dev/null
  7007. @@ -1,5 +0,0 @@
  7008. -__attribute__((__visibility__("hidden")))
  7009. -int __shcall(void *arg, int (*func)(void *))
  7010. -{
  7011. - return func(arg);
  7012. -}
  7013. --- a/arch/sh/src/__unmapself.c
  7014. +++ /dev/null
  7015. @@ -1,24 +0,0 @@
  7016. -#include "pthread_impl.h"
  7017. -
  7018. -void __unmapself_sh_mmu(void *, size_t);
  7019. -void __unmapself_sh_nommu(void *, size_t);
  7020. -
  7021. -#if !defined(__SH3__) && !defined(__SH4__)
  7022. -#define __unmapself __unmapself_sh_nommu
  7023. -#include "dynlink.h"
  7024. -#undef CRTJMP
  7025. -#define CRTJMP(pc,sp) __asm__ __volatile__( \
  7026. - "mov.l @%0+,r0 ; mov.l @%0,r12 ; jmp @r0 ; mov %1,r15" \
  7027. - : : "r"(pc), "r"(sp) : "r0", "memory" )
  7028. -#include "../../../src/thread/__unmapself.c"
  7029. -#undef __unmapself
  7030. -extern __attribute__((__visibility__("hidden"))) unsigned __sh_nommu;
  7031. -#else
  7032. -#define __sh_nommu 0
  7033. -#endif
  7034. -
  7035. -void __unmapself(void *base, size_t size)
  7036. -{
  7037. - if (__sh_nommu) __unmapself_sh_nommu(base, size);
  7038. - else __unmapself_sh_mmu(base, size);
  7039. -}
  7040. --- a/arch/sh/src/atomic.c
  7041. +++ /dev/null
  7042. @@ -1,158 +0,0 @@
  7043. -#ifndef __SH4A__
  7044. -
  7045. -#include "sh_atomic.h"
  7046. -#include "atomic.h"
  7047. -#include "libc.h"
  7048. -
  7049. -static inline unsigned mask()
  7050. -{
  7051. - unsigned sr;
  7052. - __asm__ __volatile__ ( "\n"
  7053. - " stc sr,r0 \n"
  7054. - " mov r0,%0 \n"
  7055. - " or #0xf0,r0 \n"
  7056. - " ldc r0,sr \n"
  7057. - : "=&r"(sr) : : "memory", "r0" );
  7058. - return sr;
  7059. -}
  7060. -
  7061. -static inline void unmask(unsigned sr)
  7062. -{
  7063. - __asm__ __volatile__ ( "ldc %0,sr" : : "r"(sr) : "memory" );
  7064. -}
  7065. -
  7066. -/* gusa is a hack in the kernel which lets you create a sequence of instructions
  7067. - * which will be restarted if the process is preempted in the middle of the
  7068. - * sequence. It will do for implementing atomics on non-smp systems. ABI is:
  7069. - * r0 = address of first instruction after the atomic sequence
  7070. - * r1 = original stack pointer
  7071. - * r15 = -1 * length of atomic sequence in bytes
  7072. - */
  7073. -#define GUSA_CLOBBERS "r0", "r1", "memory"
  7074. -#define GUSA_START(mem,old,nop) \
  7075. - " .align 2\n" \
  7076. - " mova 1f, r0\n" \
  7077. - nop \
  7078. - " mov r15, r1\n" \
  7079. - " mov #(0f-1f), r15\n" \
  7080. - "0: mov.l @" mem ", " old "\n"
  7081. -/* the target of mova must be 4 byte aligned, so we may need a nop */
  7082. -#define GUSA_START_ODD(mem,old) GUSA_START(mem,old,"")
  7083. -#define GUSA_START_EVEN(mem,old) GUSA_START(mem,old,"\tnop\n")
  7084. -#define GUSA_END(mem,new) \
  7085. - " mov.l " new ", @" mem "\n" \
  7086. - "1: mov r1, r15\n"
  7087. -
  7088. -int __sh_cas(volatile int *p, int t, int s)
  7089. -{
  7090. - if (__sh_atomic_model == SH_A_LLSC) return __sh_cas_llsc(p, t, s);
  7091. -
  7092. - if (__sh_atomic_model == SH_A_IMASK) {
  7093. - unsigned sr = mask();
  7094. - int old = *p;
  7095. - if (old==t) *p = s;
  7096. - unmask(sr);
  7097. - return old;
  7098. - }
  7099. -
  7100. - int old;
  7101. - __asm__ __volatile__(
  7102. - GUSA_START_EVEN("%1", "%0")
  7103. - " cmp/eq %0, %2\n"
  7104. - " bf 1f\n"
  7105. - GUSA_END("%1", "%3")
  7106. - : "=&r"(old) : "r"(p), "r"(t), "r"(s) : GUSA_CLOBBERS, "t");
  7107. - return old;
  7108. -}
  7109. -
  7110. -int __sh_swap(volatile int *x, int v)
  7111. -{
  7112. - if (__sh_atomic_model == SH_A_LLSC) return __sh_swap_llsc(x, v);
  7113. -
  7114. - if (__sh_atomic_model == SH_A_IMASK) {
  7115. - unsigned sr = mask();
  7116. - int old = *x;
  7117. - *x = v;
  7118. - unmask(sr);
  7119. - return old;
  7120. - }
  7121. -
  7122. - int old;
  7123. - __asm__ __volatile__(
  7124. - GUSA_START_EVEN("%1", "%0")
  7125. - GUSA_END("%1", "%2")
  7126. - : "=&r"(old) : "r"(x), "r"(v) : GUSA_CLOBBERS);
  7127. - return old;
  7128. -}
  7129. -
  7130. -int __sh_fetch_add(volatile int *x, int v)
  7131. -{
  7132. - if (__sh_atomic_model == SH_A_LLSC) return __sh_fetch_add_llsc(x, v);
  7133. -
  7134. - if (__sh_atomic_model == SH_A_IMASK) {
  7135. - unsigned sr = mask();
  7136. - int old = *x;
  7137. - *x = old + v;
  7138. - unmask(sr);
  7139. - return old;
  7140. - }
  7141. -
  7142. - int old, dummy;
  7143. - __asm__ __volatile__(
  7144. - GUSA_START_EVEN("%2", "%0")
  7145. - " mov %0, %1\n"
  7146. - " add %3, %1\n"
  7147. - GUSA_END("%2", "%1")
  7148. - : "=&r"(old), "=&r"(dummy) : "r"(x), "r"(v) : GUSA_CLOBBERS);
  7149. - return old;
  7150. -}
  7151. -
  7152. -void __sh_store(volatile int *p, int x)
  7153. -{
  7154. - if (__sh_atomic_model == SH_A_LLSC) return __sh_store_llsc(p, x);
  7155. - __asm__ __volatile__(
  7156. - " mov.l %1, @%0\n"
  7157. - : : "r"(p), "r"(x) : "memory");
  7158. -}
  7159. -
  7160. -void __sh_and(volatile int *x, int v)
  7161. -{
  7162. - if (__sh_atomic_model == SH_A_LLSC) return __sh_and_llsc(x, v);
  7163. -
  7164. - if (__sh_atomic_model == SH_A_IMASK) {
  7165. - unsigned sr = mask();
  7166. - int old = *x;
  7167. - *x = old & v;
  7168. - unmask(sr);
  7169. - return;
  7170. - }
  7171. -
  7172. - int dummy;
  7173. - __asm__ __volatile__(
  7174. - GUSA_START_ODD("%1", "%0")
  7175. - " and %2, %0\n"
  7176. - GUSA_END("%1", "%0")
  7177. - : "=&r"(dummy) : "r"(x), "r"(v) : GUSA_CLOBBERS);
  7178. -}
  7179. -
  7180. -void __sh_or(volatile int *x, int v)
  7181. -{
  7182. - if (__sh_atomic_model == SH_A_LLSC) return __sh_or_llsc(x, v);
  7183. -
  7184. - if (__sh_atomic_model == SH_A_IMASK) {
  7185. - unsigned sr = mask();
  7186. - int old = *x;
  7187. - *x = old | v;
  7188. - unmask(sr);
  7189. - return;
  7190. - }
  7191. -
  7192. - int dummy;
  7193. - __asm__ __volatile__(
  7194. - GUSA_START_ODD("%1", "%0")
  7195. - " or %2, %0\n"
  7196. - GUSA_END("%1", "%0")
  7197. - : "=&r"(dummy) : "r"(x), "r"(v) : GUSA_CLOBBERS);
  7198. -}
  7199. -
  7200. -#endif
  7201. --- a/arch/sh/src/sh_atomic.h
  7202. +++ /dev/null
  7203. @@ -1,15 +0,0 @@
  7204. -#ifndef _SH_ATOMIC_H
  7205. -#define _SH_ATOMIC_H
  7206. -
  7207. -#define SH_A_GUSA 0
  7208. -#define SH_A_LLSC 1
  7209. -#define SH_A_CAS 2
  7210. -#if !defined(__SH3__) && !defined(__SH4__)
  7211. -#define SH_A_IMASK 3
  7212. -#else
  7213. -#define SH_A_IMASK -1LL /* unmatchable by unsigned int */
  7214. -#endif
  7215. -
  7216. -extern __attribute__((__visibility__("hidden"))) unsigned __sh_atomic_model;
  7217. -
  7218. -#endif
  7219. --- a/arch/x32/atomic.h
  7220. +++ /dev/null
  7221. @@ -1,105 +0,0 @@
  7222. -#ifndef _INTERNAL_ATOMIC_H
  7223. -#define _INTERNAL_ATOMIC_H
  7224. -
  7225. -#include <stdint.h>
  7226. -
  7227. -static inline int a_ctz_64(uint64_t x)
  7228. -{
  7229. - __asm__( "bsf %1,%0" : "=r"(x) : "r"(x) );
  7230. - return x;
  7231. -}
  7232. -
  7233. -static inline int a_ctz_l(unsigned long x)
  7234. -{
  7235. - __asm__( "bsf %1,%0" : "=r"(x) : "r"(x) );
  7236. - return x;
  7237. -}
  7238. -
  7239. -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
  7240. -{
  7241. - __asm__( "lock ; and %1, %0"
  7242. - : "=m"(*p) : "r"(v) : "memory" );
  7243. -}
  7244. -
  7245. -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
  7246. -{
  7247. - __asm__( "lock ; or %1, %0"
  7248. - : "=m"(*p) : "r"(v) : "memory" );
  7249. -}
  7250. -
  7251. -static inline void a_or_l(volatile void *p, long v)
  7252. -{
  7253. - __asm__( "lock ; or %1, %0"
  7254. - : "=m"(*(long *)p) : "r"(v) : "memory" );
  7255. -}
  7256. -
  7257. -static inline void *a_cas_p(volatile void *p, void *t, void *s)
  7258. -{
  7259. - __asm__( "lock ; cmpxchg %3, %1"
  7260. - : "=a"(t), "=m"(*(long *)p) : "a"(t), "r"(s) : "memory" );
  7261. - return t;
  7262. -}
  7263. -
  7264. -static inline int a_cas(volatile int *p, int t, int s)
  7265. -{
  7266. - __asm__( "lock ; cmpxchg %3, %1"
  7267. - : "=a"(t), "=m"(*p) : "a"(t), "r"(s) : "memory" );
  7268. - return t;
  7269. -}
  7270. -
  7271. -static inline void a_or(volatile int *p, int v)
  7272. -{
  7273. - __asm__( "lock ; or %1, %0"
  7274. - : "=m"(*p) : "r"(v) : "memory" );
  7275. -}
  7276. -
  7277. -static inline void a_and(volatile int *p, int v)
  7278. -{
  7279. - __asm__( "lock ; and %1, %0"
  7280. - : "=m"(*p) : "r"(v) : "memory" );
  7281. -}
  7282. -
  7283. -static inline int a_swap(volatile int *x, int v)
  7284. -{
  7285. - __asm__( "xchg %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" );
  7286. - return v;
  7287. -}
  7288. -
  7289. -static inline int a_fetch_add(volatile int *x, int v)
  7290. -{
  7291. - __asm__( "lock ; xadd %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" );
  7292. - return v;
  7293. -}
  7294. -
  7295. -static inline void a_inc(volatile int *x)
  7296. -{
  7297. - __asm__( "lock ; incl %0" : "=m"(*x) : "m"(*x) : "memory" );
  7298. -}
  7299. -
  7300. -static inline void a_dec(volatile int *x)
  7301. -{
  7302. - __asm__( "lock ; decl %0" : "=m"(*x) : "m"(*x) : "memory" );
  7303. -}
  7304. -
  7305. -static inline void a_store(volatile int *p, int x)
  7306. -{
  7307. - __asm__( "mov %1, %0 ; lock ; orl $0,(%%rsp)" : "=m"(*p) : "r"(x) : "memory" );
  7308. -}
  7309. -
  7310. -static inline void a_spin()
  7311. -{
  7312. - __asm__ __volatile__( "pause" : : : "memory" );
  7313. -}
  7314. -
  7315. -static inline void a_barrier()
  7316. -{
  7317. - __asm__ __volatile__( "" : : : "memory" );
  7318. -}
  7319. -
  7320. -static inline void a_crash()
  7321. -{
  7322. - __asm__ __volatile__( "hlt" : : : "memory" );
  7323. -}
  7324. -
  7325. -
  7326. -#endif
  7327. --- /dev/null
  7328. +++ b/arch/x32/atomic_arch.h
  7329. @@ -0,0 +1,114 @@
  7330. +#define a_cas a_cas
  7331. +static inline int a_cas(volatile int *p, int t, int s)
  7332. +{
  7333. + __asm__ __volatile__ (
  7334. + "lock ; cmpxchg %3, %1"
  7335. + : "=a"(t), "=m"(*p) : "a"(t), "r"(s) : "memory" );
  7336. + return t;
  7337. +}
  7338. +
  7339. +#define a_swap a_swap
  7340. +static inline int a_swap(volatile int *p, int v)
  7341. +{
  7342. + __asm__ __volatile__(
  7343. + "xchg %0, %1"
  7344. + : "=r"(v), "=m"(*p) : "0"(v) : "memory" );
  7345. + return v;
  7346. +}
  7347. +
  7348. +#define a_fetch_add a_fetch_add
  7349. +static inline int a_fetch_add(volatile int *p, int v)
  7350. +{
  7351. + __asm__ __volatile__(
  7352. + "lock ; xadd %0, %1"
  7353. + : "=r"(v), "=m"(*p) : "0"(v) : "memory" );
  7354. + return v;
  7355. +}
  7356. +
  7357. +#define a_and a_and
  7358. +static inline void a_and(volatile int *p, int v)
  7359. +{
  7360. + __asm__ __volatile__(
  7361. + "lock ; and %1, %0"
  7362. + : "=m"(*p) : "r"(v) : "memory" );
  7363. +}
  7364. +
  7365. +#define a_or a_or
  7366. +static inline void a_or(volatile int *p, int v)
  7367. +{
  7368. + __asm__ __volatile__(
  7369. + "lock ; or %1, %0"
  7370. + : "=m"(*p) : "r"(v) : "memory" );
  7371. +}
  7372. +
  7373. +#define a_and_64 a_and_64
  7374. +static inline void a_and_64(volatile uint64_t *p, uint64_t v)
  7375. +{
  7376. + __asm__ __volatile(
  7377. + "lock ; and %1, %0"
  7378. + : "=m"(*p) : "r"(v) : "memory" );
  7379. +}
  7380. +
  7381. +#define a_or_64 a_or_64
  7382. +static inline void a_or_64(volatile uint64_t *p, uint64_t v)
  7383. +{
  7384. + __asm__ __volatile__(
  7385. + "lock ; or %1, %0"
  7386. + : "=m"(*p) : "r"(v) : "memory" );
  7387. +}
  7388. +
  7389. +#define a_inc a_inc
  7390. +static inline void a_inc(volatile int *p)
  7391. +{
  7392. + __asm__ __volatile__(
  7393. + "lock ; incl %0"
  7394. + : "=m"(*p) : "m"(*p) : "memory" );
  7395. +}
  7396. +
  7397. +#define a_dec a_dec
  7398. +static inline void a_dec(volatile int *p)
  7399. +{
  7400. + __asm__ __volatile__(
  7401. + "lock ; decl %0"
  7402. + : "=m"(*p) : "m"(*p) : "memory" );
  7403. +}
  7404. +
  7405. +#define a_store a_store
  7406. +static inline void a_store(volatile int *p, int x)
  7407. +{
  7408. + __asm__ __volatile__(
  7409. + "mov %1, %0 ; lock ; orl $0,(%%rsp)"
  7410. + : "=m"(*p) : "r"(x) : "memory" );
  7411. +}
  7412. +
  7413. +#define a_barrier a_barrier
  7414. +static inline void a_barrier()
  7415. +{
  7416. + __asm__ __volatile__( "" : : : "memory" );
  7417. +}
  7418. +
  7419. +#define a_pause a_pause
  7420. +static inline void a_spin()
  7421. +{
  7422. + __asm__ __volatile__( "pause" : : : "memory" );
  7423. +}
  7424. +
  7425. +#define a_crash a_crash
  7426. +static inline void a_crash()
  7427. +{
  7428. + __asm__ __volatile__( "hlt" : : : "memory" );
  7429. +}
  7430. +
  7431. +#define a_ctz_64 a_ctz_64
  7432. +static inline int a_ctz_64(uint64_t x)
  7433. +{
  7434. + __asm__( "bsf %1,%0" : "=r"(x) : "r"(x) );
  7435. + return x;
  7436. +}
  7437. +
  7438. +#define a_ctz_l a_ctz_l
  7439. +static inline int a_ctz_l(unsigned long x)
  7440. +{
  7441. + __asm__( "bsf %1,%0" : "=r"(x) : "r"(x) );
  7442. + return x;
  7443. +}
  7444. --- a/arch/x32/bits/errno.h
  7445. +++ /dev/null
  7446. @@ -1,134 +0,0 @@
  7447. -#define EPERM 1
  7448. -#define ENOENT 2
  7449. -#define ESRCH 3
  7450. -#define EINTR 4
  7451. -#define EIO 5
  7452. -#define ENXIO 6
  7453. -#define E2BIG 7
  7454. -#define ENOEXEC 8
  7455. -#define EBADF 9
  7456. -#define ECHILD 10
  7457. -#define EAGAIN 11
  7458. -#define ENOMEM 12
  7459. -#define EACCES 13
  7460. -#define EFAULT 14
  7461. -#define ENOTBLK 15
  7462. -#define EBUSY 16
  7463. -#define EEXIST 17
  7464. -#define EXDEV 18
  7465. -#define ENODEV 19
  7466. -#define ENOTDIR 20
  7467. -#define EISDIR 21
  7468. -#define EINVAL 22
  7469. -#define ENFILE 23
  7470. -#define EMFILE 24
  7471. -#define ENOTTY 25
  7472. -#define ETXTBSY 26
  7473. -#define EFBIG 27
  7474. -#define ENOSPC 28
  7475. -#define ESPIPE 29
  7476. -#define EROFS 30
  7477. -#define EMLINK 31
  7478. -#define EPIPE 32
  7479. -#define EDOM 33
  7480. -#define ERANGE 34
  7481. -#define EDEADLK 35
  7482. -#define ENAMETOOLONG 36
  7483. -#define ENOLCK 37
  7484. -#define ENOSYS 38
  7485. -#define ENOTEMPTY 39
  7486. -#define ELOOP 40
  7487. -#define EWOULDBLOCK EAGAIN
  7488. -#define ENOMSG 42
  7489. -#define EIDRM 43
  7490. -#define ECHRNG 44
  7491. -#define EL2NSYNC 45
  7492. -#define EL3HLT 46
  7493. -#define EL3RST 47
  7494. -#define ELNRNG 48
  7495. -#define EUNATCH 49
  7496. -#define ENOCSI 50
  7497. -#define EL2HLT 51
  7498. -#define EBADE 52
  7499. -#define EBADR 53
  7500. -#define EXFULL 54
  7501. -#define ENOANO 55
  7502. -#define EBADRQC 56
  7503. -#define EBADSLT 57
  7504. -#define EDEADLOCK EDEADLK
  7505. -#define EBFONT 59
  7506. -#define ENOSTR 60
  7507. -#define ENODATA 61
  7508. -#define ETIME 62
  7509. -#define ENOSR 63
  7510. -#define ENONET 64
  7511. -#define ENOPKG 65
  7512. -#define EREMOTE 66
  7513. -#define ENOLINK 67
  7514. -#define EADV 68
  7515. -#define ESRMNT 69
  7516. -#define ECOMM 70
  7517. -#define EPROTO 71
  7518. -#define EMULTIHOP 72
  7519. -#define EDOTDOT 73
  7520. -#define EBADMSG 74
  7521. -#define EOVERFLOW 75
  7522. -#define ENOTUNIQ 76
  7523. -#define EBADFD 77
  7524. -#define EREMCHG 78
  7525. -#define ELIBACC 79
  7526. -#define ELIBBAD 80
  7527. -#define ELIBSCN 81
  7528. -#define ELIBMAX 82
  7529. -#define ELIBEXEC 83
  7530. -#define EILSEQ 84
  7531. -#define ERESTART 85
  7532. -#define ESTRPIPE 86
  7533. -#define EUSERS 87
  7534. -#define ENOTSOCK 88
  7535. -#define EDESTADDRREQ 89
  7536. -#define EMSGSIZE 90
  7537. -#define EPROTOTYPE 91
  7538. -#define ENOPROTOOPT 92
  7539. -#define EPROTONOSUPPORT 93
  7540. -#define ESOCKTNOSUPPORT 94
  7541. -#define EOPNOTSUPP 95
  7542. -#define ENOTSUP EOPNOTSUPP
  7543. -#define EPFNOSUPPORT 96
  7544. -#define EAFNOSUPPORT 97
  7545. -#define EADDRINUSE 98
  7546. -#define EADDRNOTAVAIL 99
  7547. -#define ENETDOWN 100
  7548. -#define ENETUNREACH 101
  7549. -#define ENETRESET 102
  7550. -#define ECONNABORTED 103
  7551. -#define ECONNRESET 104
  7552. -#define ENOBUFS 105
  7553. -#define EISCONN 106
  7554. -#define ENOTCONN 107
  7555. -#define ESHUTDOWN 108
  7556. -#define ETOOMANYREFS 109
  7557. -#define ETIMEDOUT 110
  7558. -#define ECONNREFUSED 111
  7559. -#define EHOSTDOWN 112
  7560. -#define EHOSTUNREACH 113
  7561. -#define EALREADY 114
  7562. -#define EINPROGRESS 115
  7563. -#define ESTALE 116
  7564. -#define EUCLEAN 117
  7565. -#define ENOTNAM 118
  7566. -#define ENAVAIL 119
  7567. -#define EISNAM 120
  7568. -#define EREMOTEIO 121
  7569. -#define EDQUOT 122
  7570. -#define ENOMEDIUM 123
  7571. -#define EMEDIUMTYPE 124
  7572. -#define ECANCELED 125
  7573. -#define ENOKEY 126
  7574. -#define EKEYEXPIRED 127
  7575. -#define EKEYREVOKED 128
  7576. -#define EKEYREJECTED 129
  7577. -#define EOWNERDEAD 130
  7578. -#define ENOTRECOVERABLE 131
  7579. -#define ERFKILL 132
  7580. -#define EHWPOISON 133
  7581. --- a/arch/x32/bits/mman.h
  7582. +++ b/arch/x32/bits/mman.h
  7583. @@ -38,6 +38,7 @@
  7584. #define MCL_CURRENT 1
  7585. #define MCL_FUTURE 2
  7586. +#define MCL_ONFAULT 4
  7587. #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  7588. #define MADV_NORMAL 0
  7589. --- a/arch/x32/bits/sem.h
  7590. +++ /dev/null
  7591. @@ -1,16 +0,0 @@
  7592. -struct semid_ds {
  7593. - struct ipc_perm sem_perm;
  7594. - time_t sem_otime;
  7595. - time_t __unused1;
  7596. - time_t sem_ctime;
  7597. - time_t __unused2;
  7598. -#if __BYTE_ORDER == __LITTLE_ENDIAN
  7599. - unsigned short sem_nsems;
  7600. - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
  7601. -#else
  7602. - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
  7603. - unsigned short sem_nsems;
  7604. -#endif
  7605. - time_t __unused3;
  7606. - time_t __unused4;
  7607. -};
  7608. --- a/arch/x32/bits/stdarg.h
  7609. +++ /dev/null
  7610. @@ -1,4 +0,0 @@
  7611. -#define va_start(v,l) __builtin_va_start(v,l)
  7612. -#define va_end(v) __builtin_va_end(v)
  7613. -#define va_arg(v,l) __builtin_va_arg(v,l)
  7614. -#define va_copy(d,s) __builtin_va_copy(d,s)
  7615. --- a/arch/x32/bits/syscall.h
  7616. +++ b/arch/x32/bits/syscall.h
  7617. @@ -277,6 +277,9 @@
  7618. #define __NR_memfd_create (__X32_SYSCALL_BIT + 319)
  7619. #define __NR_kexec_file_load (__X32_SYSCALL_BIT + 320)
  7620. #define __NR_bpf (__X32_SYSCALL_BIT + 321)
  7621. +#define __NR_userfaultfd (__X32_SYSCALL_BIT + 323)
  7622. +#define __NR_membarrier (__X32_SYSCALL_BIT + 324)
  7623. +#define __NR_mlock2 (__X32_SYSCALL_BIT + 325)
  7624. #define __NR_rt_sigaction (__X32_SYSCALL_BIT + 512)
  7625. #define __NR_rt_sigreturn (__X32_SYSCALL_BIT + 513)
  7626. @@ -607,6 +610,9 @@
  7627. #define SYS_memfd_create __NR_memfd_create
  7628. #define SYS_kexec_file_load __NR_kexec_file_load
  7629. #define SYS_bpf __NR_bpf
  7630. +#define SYS_userfaultfd __NR_userfaultfd
  7631. +#define SYS_membarrier __NR_membarrier
  7632. +#define SYS_mlock2 __NR_mlock2
  7633. #define SYS_rt_sigaction __NR_rt_sigaction
  7634. --- a/arch/x32/bits/termios.h
  7635. +++ /dev/null
  7636. @@ -1,160 +0,0 @@
  7637. -struct termios
  7638. -{
  7639. - tcflag_t c_iflag;
  7640. - tcflag_t c_oflag;
  7641. - tcflag_t c_cflag;
  7642. - tcflag_t c_lflag;
  7643. - cc_t c_line;
  7644. - cc_t c_cc[NCCS];
  7645. - speed_t __c_ispeed;
  7646. - speed_t __c_ospeed;
  7647. -};
  7648. -
  7649. -#define VINTR 0
  7650. -#define VQUIT 1
  7651. -#define VERASE 2
  7652. -#define VKILL 3
  7653. -#define VEOF 4
  7654. -#define VTIME 5
  7655. -#define VMIN 6
  7656. -#define VSWTC 7
  7657. -#define VSTART 8
  7658. -#define VSTOP 9
  7659. -#define VSUSP 10
  7660. -#define VEOL 11
  7661. -#define VREPRINT 12
  7662. -#define VDISCARD 13
  7663. -#define VWERASE 14
  7664. -#define VLNEXT 15
  7665. -#define VEOL2 16
  7666. -
  7667. -#define IGNBRK 0000001
  7668. -#define BRKINT 0000002
  7669. -#define IGNPAR 0000004
  7670. -#define PARMRK 0000010
  7671. -#define INPCK 0000020
  7672. -#define ISTRIP 0000040
  7673. -#define INLCR 0000100
  7674. -#define IGNCR 0000200
  7675. -#define ICRNL 0000400
  7676. -#define IUCLC 0001000
  7677. -#define IXON 0002000
  7678. -#define IXANY 0004000
  7679. -#define IXOFF 0010000
  7680. -#define IMAXBEL 0020000
  7681. -#define IUTF8 0040000
  7682. -
  7683. -#define OPOST 0000001
  7684. -#define OLCUC 0000002
  7685. -#define ONLCR 0000004
  7686. -#define OCRNL 0000010
  7687. -#define ONOCR 0000020
  7688. -#define ONLRET 0000040
  7689. -#define OFILL 0000100
  7690. -#define OFDEL 0000200
  7691. -#define NLDLY 0000400
  7692. -#define NL0 0000000
  7693. -#define NL1 0000400
  7694. -#define CRDLY 0003000
  7695. -#define CR0 0000000
  7696. -#define CR1 0001000
  7697. -#define CR2 0002000
  7698. -#define CR3 0003000
  7699. -#define TABDLY 0014000
  7700. -#define TAB0 0000000
  7701. -#define TAB1 0004000
  7702. -#define TAB2 0010000
  7703. -#define TAB3 0014000
  7704. -#define BSDLY 0020000
  7705. -#define BS0 0000000
  7706. -#define BS1 0020000
  7707. -#define FFDLY 0100000
  7708. -#define FF0 0000000
  7709. -#define FF1 0100000
  7710. -
  7711. -#define VTDLY 0040000
  7712. -#define VT0 0000000
  7713. -#define VT1 0040000
  7714. -
  7715. -#define B0 0000000
  7716. -#define B50 0000001
  7717. -#define B75 0000002
  7718. -#define B110 0000003
  7719. -#define B134 0000004
  7720. -#define B150 0000005
  7721. -#define B200 0000006
  7722. -#define B300 0000007
  7723. -#define B600 0000010
  7724. -#define B1200 0000011
  7725. -#define B1800 0000012
  7726. -#define B2400 0000013
  7727. -#define B4800 0000014
  7728. -#define B9600 0000015
  7729. -#define B19200 0000016
  7730. -#define B38400 0000017
  7731. -
  7732. -#define B57600 0010001
  7733. -#define B115200 0010002
  7734. -#define B230400 0010003
  7735. -#define B460800 0010004
  7736. -#define B500000 0010005
  7737. -#define B576000 0010006
  7738. -#define B921600 0010007
  7739. -#define B1000000 0010010
  7740. -#define B1152000 0010011
  7741. -#define B1500000 0010012
  7742. -#define B2000000 0010013
  7743. -#define B2500000 0010014
  7744. -#define B3000000 0010015
  7745. -#define B3500000 0010016
  7746. -#define B4000000 0010017
  7747. -
  7748. -#define CBAUD 0010017
  7749. -
  7750. -#define CSIZE 0000060
  7751. -#define CS5 0000000
  7752. -#define CS6 0000020
  7753. -#define CS7 0000040
  7754. -#define CS8 0000060
  7755. -#define CSTOPB 0000100
  7756. -#define CREAD 0000200
  7757. -#define PARENB 0000400
  7758. -#define PARODD 0001000
  7759. -#define HUPCL 0002000
  7760. -#define CLOCAL 0004000
  7761. -
  7762. -#define ISIG 0000001
  7763. -#define ICANON 0000002
  7764. -#define ECHO 0000010
  7765. -#define ECHOE 0000020
  7766. -#define ECHOK 0000040
  7767. -#define ECHONL 0000100
  7768. -#define NOFLSH 0000200
  7769. -#define TOSTOP 0000400
  7770. -#define IEXTEN 0100000
  7771. -
  7772. -#define ECHOCTL 0001000
  7773. -#define ECHOPRT 0002000
  7774. -#define ECHOKE 0004000
  7775. -#define FLUSHO 0010000
  7776. -#define PENDIN 0040000
  7777. -
  7778. -#define TCOOFF 0
  7779. -#define TCOON 1
  7780. -#define TCIOFF 2
  7781. -#define TCION 3
  7782. -
  7783. -#define TCIFLUSH 0
  7784. -#define TCOFLUSH 1
  7785. -#define TCIOFLUSH 2
  7786. -
  7787. -#define TCSANOW 0
  7788. -#define TCSADRAIN 1
  7789. -#define TCSAFLUSH 2
  7790. -
  7791. -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  7792. -#define CBAUDEX 0010000
  7793. -#define CRTSCTS 020000000000
  7794. -#define EXTPROC 0200000
  7795. -#define XTABS 0014000
  7796. -#endif
  7797. --- a/arch/x32/pthread_arch.h
  7798. +++ b/arch/x32/pthread_arch.h
  7799. @@ -7,6 +7,6 @@ static inline struct pthread *__pthread_
  7800. #define TP_ADJ(p) (p)
  7801. -#define CANCEL_REG_IP 32
  7802. +#define MC_PC gregs[REG_RIP]
  7803. #define CANARY canary2
  7804. --- a/arch/x32/src/syscall_cp_fixup.c
  7805. +++ /dev/null
  7806. @@ -1,42 +0,0 @@
  7807. -#include <sys/syscall.h>
  7808. -
  7809. -#ifdef SHARED
  7810. -__attribute__((__visibility__("hidden")))
  7811. -#endif
  7812. -long __syscall_cp_internal(volatile void*, long long, long long, long long, long long,
  7813. - long long, long long, long long);
  7814. -
  7815. -struct __timespec { long long tv_sec; long tv_nsec; };
  7816. -struct __timespec_kernel { long long tv_sec; long long tv_nsec; };
  7817. -#define __tsc(X) ((struct __timespec*)(unsigned long)(X))
  7818. -#define __fixup(X) do { if(X) { \
  7819. - ts->tv_sec = __tsc(X)->tv_sec; \
  7820. - ts->tv_nsec = __tsc(X)->tv_nsec; \
  7821. - (X) = (unsigned long)ts; } } while(0)
  7822. -
  7823. -#ifdef SHARED
  7824. -__attribute__((__visibility__("hidden")))
  7825. -#endif
  7826. -long __syscall_cp_asm (volatile void * foo, long long n, long long a1, long long a2, long long a3,
  7827. - long long a4, long long a5, long long a6)
  7828. -{
  7829. - struct __timespec_kernel ts[1];
  7830. - switch (n) {
  7831. - case SYS_mq_timedsend: case SYS_mq_timedreceive: case SYS_pselect6:
  7832. - __fixup(a5);
  7833. - break;
  7834. - case SYS_futex:
  7835. - if((a2 & (~128 /* FUTEX_PRIVATE_FLAG */)) == 0 /* FUTEX_WAIT */)
  7836. - __fixup(a4);
  7837. - break;
  7838. - case SYS_clock_nanosleep:
  7839. - case SYS_rt_sigtimedwait: case SYS_ppoll:
  7840. - __fixup(a3);
  7841. - break;
  7842. - case SYS_nanosleep:
  7843. - __fixup(a1);
  7844. - break;
  7845. - }
  7846. - return __syscall_cp_internal(foo, n, a1, a2, a3, a4, a5, a6);
  7847. -}
  7848. -
  7849. --- a/arch/x32/src/sysinfo.c
  7850. +++ /dev/null
  7851. @@ -1,50 +0,0 @@
  7852. -#include <sys/sysinfo.h>
  7853. -#include "syscall.h"
  7854. -#include "libc.h"
  7855. -
  7856. -#define klong long long
  7857. -#define kulong unsigned long long
  7858. -
  7859. -struct kernel_sysinfo {
  7860. - klong uptime;
  7861. - kulong loads[3];
  7862. - kulong totalram;
  7863. - kulong freeram;
  7864. - kulong sharedram;
  7865. - kulong bufferram;
  7866. - kulong totalswap;
  7867. - kulong freeswap;
  7868. - short procs;
  7869. - short pad;
  7870. - kulong totalhigh;
  7871. - kulong freehigh;
  7872. - unsigned mem_unit;
  7873. -};
  7874. -
  7875. -int __lsysinfo(struct sysinfo *info)
  7876. -{
  7877. - struct kernel_sysinfo tmp;
  7878. - int ret = syscall(SYS_sysinfo, &tmp);
  7879. - if(ret == -1) return ret;
  7880. - info->uptime = tmp.uptime;
  7881. - info->loads[0] = tmp.loads[0];
  7882. - info->loads[1] = tmp.loads[1];
  7883. - info->loads[2] = tmp.loads[2];
  7884. - kulong shifts;
  7885. - kulong max = tmp.totalram | tmp.totalswap;
  7886. - __asm__("bsr %1,%0" : "=r"(shifts) : "r"(max));
  7887. - shifts = shifts >= 32 ? shifts - 31 : 0;
  7888. - info->totalram = tmp.totalram >> shifts;
  7889. - info->freeram = tmp.freeram >> shifts;
  7890. - info->sharedram = tmp.sharedram >> shifts;
  7891. - info->bufferram = tmp.bufferram >> shifts;
  7892. - info->totalswap = tmp.totalswap >> shifts;
  7893. - info->freeswap = tmp.freeswap >> shifts;
  7894. - info->procs = tmp.procs ;
  7895. - info->totalhigh = tmp.totalhigh >> shifts;
  7896. - info->freehigh = tmp.freehigh >> shifts;
  7897. - info->mem_unit = (tmp.mem_unit ? tmp.mem_unit : 1) << shifts;
  7898. - return ret;
  7899. -}
  7900. -
  7901. -weak_alias(__lsysinfo, sysinfo);
  7902. --- a/arch/x86_64/atomic.h
  7903. +++ /dev/null
  7904. @@ -1,105 +0,0 @@
  7905. -#ifndef _INTERNAL_ATOMIC_H
  7906. -#define _INTERNAL_ATOMIC_H
  7907. -
  7908. -#include <stdint.h>
  7909. -
  7910. -static inline int a_ctz_64(uint64_t x)
  7911. -{
  7912. - __asm__( "bsf %1,%0" : "=r"(x) : "r"(x) );
  7913. - return x;
  7914. -}
  7915. -
  7916. -static inline int a_ctz_l(unsigned long x)
  7917. -{
  7918. - __asm__( "bsf %1,%0" : "=r"(x) : "r"(x) );
  7919. - return x;
  7920. -}
  7921. -
  7922. -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
  7923. -{
  7924. - __asm__( "lock ; and %1, %0"
  7925. - : "=m"(*p) : "r"(v) : "memory" );
  7926. -}
  7927. -
  7928. -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
  7929. -{
  7930. - __asm__( "lock ; or %1, %0"
  7931. - : "=m"(*p) : "r"(v) : "memory" );
  7932. -}
  7933. -
  7934. -static inline void a_or_l(volatile void *p, long v)
  7935. -{
  7936. - __asm__( "lock ; or %1, %0"
  7937. - : "=m"(*(long *)p) : "r"(v) : "memory" );
  7938. -}
  7939. -
  7940. -static inline void *a_cas_p(volatile void *p, void *t, void *s)
  7941. -{
  7942. - __asm__( "lock ; cmpxchg %3, %1"
  7943. - : "=a"(t), "=m"(*(long *)p) : "a"(t), "r"(s) : "memory" );
  7944. - return t;
  7945. -}
  7946. -
  7947. -static inline int a_cas(volatile int *p, int t, int s)
  7948. -{
  7949. - __asm__( "lock ; cmpxchg %3, %1"
  7950. - : "=a"(t), "=m"(*p) : "a"(t), "r"(s) : "memory" );
  7951. - return t;
  7952. -}
  7953. -
  7954. -static inline void a_or(volatile int *p, int v)
  7955. -{
  7956. - __asm__( "lock ; or %1, %0"
  7957. - : "=m"(*p) : "r"(v) : "memory" );
  7958. -}
  7959. -
  7960. -static inline void a_and(volatile int *p, int v)
  7961. -{
  7962. - __asm__( "lock ; and %1, %0"
  7963. - : "=m"(*p) : "r"(v) : "memory" );
  7964. -}
  7965. -
  7966. -static inline int a_swap(volatile int *x, int v)
  7967. -{
  7968. - __asm__( "xchg %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" );
  7969. - return v;
  7970. -}
  7971. -
  7972. -static inline int a_fetch_add(volatile int *x, int v)
  7973. -{
  7974. - __asm__( "lock ; xadd %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" );
  7975. - return v;
  7976. -}
  7977. -
  7978. -static inline void a_inc(volatile int *x)
  7979. -{
  7980. - __asm__( "lock ; incl %0" : "=m"(*x) : "m"(*x) : "memory" );
  7981. -}
  7982. -
  7983. -static inline void a_dec(volatile int *x)
  7984. -{
  7985. - __asm__( "lock ; decl %0" : "=m"(*x) : "m"(*x) : "memory" );
  7986. -}
  7987. -
  7988. -static inline void a_store(volatile int *p, int x)
  7989. -{
  7990. - __asm__( "mov %1, %0 ; lock ; orl $0,(%%rsp)" : "=m"(*p) : "r"(x) : "memory" );
  7991. -}
  7992. -
  7993. -static inline void a_spin()
  7994. -{
  7995. - __asm__ __volatile__( "pause" : : : "memory" );
  7996. -}
  7997. -
  7998. -static inline void a_barrier()
  7999. -{
  8000. - __asm__ __volatile__( "" : : : "memory" );
  8001. -}
  8002. -
  8003. -static inline void a_crash()
  8004. -{
  8005. - __asm__ __volatile__( "hlt" : : : "memory" );
  8006. -}
  8007. -
  8008. -
  8009. -#endif
  8010. --- /dev/null
  8011. +++ b/arch/x86_64/atomic_arch.h
  8012. @@ -0,0 +1,116 @@
  8013. +#define a_cas a_cas
  8014. +static inline int a_cas(volatile int *p, int t, int s)
  8015. +{
  8016. + __asm__ __volatile__ (
  8017. + "lock ; cmpxchg %3, %1"
  8018. + : "=a"(t), "=m"(*p) : "a"(t), "r"(s) : "memory" );
  8019. + return t;
  8020. +}
  8021. +
  8022. +#define a_cas_p a_cas_p
  8023. +static inline void *a_cas_p(volatile void *p, void *t, void *s)
  8024. +{
  8025. + __asm__( "lock ; cmpxchg %3, %1"
  8026. + : "=a"(t), "=m"(*(void *volatile *)p)
  8027. + : "a"(t), "r"(s) : "memory" );
  8028. + return t;
  8029. +}
  8030. +
  8031. +#define a_swap a_swap
  8032. +static inline int a_swap(volatile int *p, int v)
  8033. +{
  8034. + __asm__ __volatile__(
  8035. + "xchg %0, %1"
  8036. + : "=r"(v), "=m"(*p) : "0"(v) : "memory" );
  8037. + return v;
  8038. +}
  8039. +
  8040. +#define a_fetch_add a_fetch_add
  8041. +static inline int a_fetch_add(volatile int *p, int v)
  8042. +{
  8043. + __asm__ __volatile__(
  8044. + "lock ; xadd %0, %1"
  8045. + : "=r"(v), "=m"(*p) : "0"(v) : "memory" );
  8046. + return v;
  8047. +}
  8048. +
  8049. +#define a_and a_and
  8050. +static inline void a_and(volatile int *p, int v)
  8051. +{
  8052. + __asm__ __volatile__(
  8053. + "lock ; and %1, %0"
  8054. + : "=m"(*p) : "r"(v) : "memory" );
  8055. +}
  8056. +
  8057. +#define a_or a_or
  8058. +static inline void a_or(volatile int *p, int v)
  8059. +{
  8060. + __asm__ __volatile__(
  8061. + "lock ; or %1, %0"
  8062. + : "=m"(*p) : "r"(v) : "memory" );
  8063. +}
  8064. +
  8065. +#define a_and_64 a_and_64
  8066. +static inline void a_and_64(volatile uint64_t *p, uint64_t v)
  8067. +{
  8068. + __asm__ __volatile(
  8069. + "lock ; and %1, %0"
  8070. + : "=m"(*p) : "r"(v) : "memory" );
  8071. +}
  8072. +
  8073. +#define a_or_64 a_or_64
  8074. +static inline void a_or_64(volatile uint64_t *p, uint64_t v)
  8075. +{
  8076. + __asm__ __volatile__(
  8077. + "lock ; or %1, %0"
  8078. + : "=m"(*p) : "r"(v) : "memory" );
  8079. +}
  8080. +
  8081. +#define a_inc a_inc
  8082. +static inline void a_inc(volatile int *p)
  8083. +{
  8084. + __asm__ __volatile__(
  8085. + "lock ; incl %0"
  8086. + : "=m"(*p) : "m"(*p) : "memory" );
  8087. +}
  8088. +
  8089. +#define a_dec a_dec
  8090. +static inline void a_dec(volatile int *p)
  8091. +{
  8092. + __asm__ __volatile__(
  8093. + "lock ; decl %0"
  8094. + : "=m"(*p) : "m"(*p) : "memory" );
  8095. +}
  8096. +
  8097. +#define a_store a_store
  8098. +static inline void a_store(volatile int *p, int x)
  8099. +{
  8100. + __asm__ __volatile__(
  8101. + "mov %1, %0 ; lock ; orl $0,(%%rsp)"
  8102. + : "=m"(*p) : "r"(x) : "memory" );
  8103. +}
  8104. +
  8105. +#define a_barrier a_barrier
  8106. +static inline void a_barrier()
  8107. +{
  8108. + __asm__ __volatile__( "" : : : "memory" );
  8109. +}
  8110. +
  8111. +#define a_pause a_pause
  8112. +static inline void a_spin()
  8113. +{
  8114. + __asm__ __volatile__( "pause" : : : "memory" );
  8115. +}
  8116. +
  8117. +#define a_crash a_crash
  8118. +static inline void a_crash()
  8119. +{
  8120. + __asm__ __volatile__( "hlt" : : : "memory" );
  8121. +}
  8122. +
  8123. +#define a_ctz_64 a_ctz_64
  8124. +static inline int a_ctz_64(uint64_t x)
  8125. +{
  8126. + __asm__( "bsf %1,%0" : "=r"(x) : "r"(x) );
  8127. + return x;
  8128. +}
  8129. --- a/arch/x86_64/bits/errno.h
  8130. +++ /dev/null
  8131. @@ -1,134 +0,0 @@
  8132. -#define EPERM 1
  8133. -#define ENOENT 2
  8134. -#define ESRCH 3
  8135. -#define EINTR 4
  8136. -#define EIO 5
  8137. -#define ENXIO 6
  8138. -#define E2BIG 7
  8139. -#define ENOEXEC 8
  8140. -#define EBADF 9
  8141. -#define ECHILD 10
  8142. -#define EAGAIN 11
  8143. -#define ENOMEM 12
  8144. -#define EACCES 13
  8145. -#define EFAULT 14
  8146. -#define ENOTBLK 15
  8147. -#define EBUSY 16
  8148. -#define EEXIST 17
  8149. -#define EXDEV 18
  8150. -#define ENODEV 19
  8151. -#define ENOTDIR 20
  8152. -#define EISDIR 21
  8153. -#define EINVAL 22
  8154. -#define ENFILE 23
  8155. -#define EMFILE 24
  8156. -#define ENOTTY 25
  8157. -#define ETXTBSY 26
  8158. -#define EFBIG 27
  8159. -#define ENOSPC 28
  8160. -#define ESPIPE 29
  8161. -#define EROFS 30
  8162. -#define EMLINK 31
  8163. -#define EPIPE 32
  8164. -#define EDOM 33
  8165. -#define ERANGE 34
  8166. -#define EDEADLK 35
  8167. -#define ENAMETOOLONG 36
  8168. -#define ENOLCK 37
  8169. -#define ENOSYS 38
  8170. -#define ENOTEMPTY 39
  8171. -#define ELOOP 40
  8172. -#define EWOULDBLOCK EAGAIN
  8173. -#define ENOMSG 42
  8174. -#define EIDRM 43
  8175. -#define ECHRNG 44
  8176. -#define EL2NSYNC 45
  8177. -#define EL3HLT 46
  8178. -#define EL3RST 47
  8179. -#define ELNRNG 48
  8180. -#define EUNATCH 49
  8181. -#define ENOCSI 50
  8182. -#define EL2HLT 51
  8183. -#define EBADE 52
  8184. -#define EBADR 53
  8185. -#define EXFULL 54
  8186. -#define ENOANO 55
  8187. -#define EBADRQC 56
  8188. -#define EBADSLT 57
  8189. -#define EDEADLOCK EDEADLK
  8190. -#define EBFONT 59
  8191. -#define ENOSTR 60
  8192. -#define ENODATA 61
  8193. -#define ETIME 62
  8194. -#define ENOSR 63
  8195. -#define ENONET 64
  8196. -#define ENOPKG 65
  8197. -#define EREMOTE 66
  8198. -#define ENOLINK 67
  8199. -#define EADV 68
  8200. -#define ESRMNT 69
  8201. -#define ECOMM 70
  8202. -#define EPROTO 71
  8203. -#define EMULTIHOP 72
  8204. -#define EDOTDOT 73
  8205. -#define EBADMSG 74
  8206. -#define EOVERFLOW 75
  8207. -#define ENOTUNIQ 76
  8208. -#define EBADFD 77
  8209. -#define EREMCHG 78
  8210. -#define ELIBACC 79
  8211. -#define ELIBBAD 80
  8212. -#define ELIBSCN 81
  8213. -#define ELIBMAX 82
  8214. -#define ELIBEXEC 83
  8215. -#define EILSEQ 84
  8216. -#define ERESTART 85
  8217. -#define ESTRPIPE 86
  8218. -#define EUSERS 87
  8219. -#define ENOTSOCK 88
  8220. -#define EDESTADDRREQ 89
  8221. -#define EMSGSIZE 90
  8222. -#define EPROTOTYPE 91
  8223. -#define ENOPROTOOPT 92
  8224. -#define EPROTONOSUPPORT 93
  8225. -#define ESOCKTNOSUPPORT 94
  8226. -#define EOPNOTSUPP 95
  8227. -#define ENOTSUP EOPNOTSUPP
  8228. -#define EPFNOSUPPORT 96
  8229. -#define EAFNOSUPPORT 97
  8230. -#define EADDRINUSE 98
  8231. -#define EADDRNOTAVAIL 99
  8232. -#define ENETDOWN 100
  8233. -#define ENETUNREACH 101
  8234. -#define ENETRESET 102
  8235. -#define ECONNABORTED 103
  8236. -#define ECONNRESET 104
  8237. -#define ENOBUFS 105
  8238. -#define EISCONN 106
  8239. -#define ENOTCONN 107
  8240. -#define ESHUTDOWN 108
  8241. -#define ETOOMANYREFS 109
  8242. -#define ETIMEDOUT 110
  8243. -#define ECONNREFUSED 111
  8244. -#define EHOSTDOWN 112
  8245. -#define EHOSTUNREACH 113
  8246. -#define EALREADY 114
  8247. -#define EINPROGRESS 115
  8248. -#define ESTALE 116
  8249. -#define EUCLEAN 117
  8250. -#define ENOTNAM 118
  8251. -#define ENAVAIL 119
  8252. -#define EISNAM 120
  8253. -#define EREMOTEIO 121
  8254. -#define EDQUOT 122
  8255. -#define ENOMEDIUM 123
  8256. -#define EMEDIUMTYPE 124
  8257. -#define ECANCELED 125
  8258. -#define ENOKEY 126
  8259. -#define EKEYEXPIRED 127
  8260. -#define EKEYREVOKED 128
  8261. -#define EKEYREJECTED 129
  8262. -#define EOWNERDEAD 130
  8263. -#define ENOTRECOVERABLE 131
  8264. -#define ERFKILL 132
  8265. -#define EHWPOISON 133
  8266. --- a/arch/x86_64/bits/mman.h
  8267. +++ b/arch/x86_64/bits/mman.h
  8268. @@ -38,6 +38,7 @@
  8269. #define MCL_CURRENT 1
  8270. #define MCL_FUTURE 2
  8271. +#define MCL_ONFAULT 4
  8272. #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  8273. #define MADV_NORMAL 0
  8274. --- a/arch/x86_64/bits/sem.h
  8275. +++ /dev/null
  8276. @@ -1,16 +0,0 @@
  8277. -struct semid_ds {
  8278. - struct ipc_perm sem_perm;
  8279. - time_t sem_otime;
  8280. - time_t __unused1;
  8281. - time_t sem_ctime;
  8282. - time_t __unused2;
  8283. -#if __BYTE_ORDER == __LITTLE_ENDIAN
  8284. - unsigned short sem_nsems;
  8285. - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
  8286. -#else
  8287. - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
  8288. - unsigned short sem_nsems;
  8289. -#endif
  8290. - time_t __unused3;
  8291. - time_t __unused4;
  8292. -};
  8293. --- a/arch/x86_64/bits/statfs.h
  8294. +++ /dev/null
  8295. @@ -1,7 +0,0 @@
  8296. -struct statfs {
  8297. - unsigned long f_type, f_bsize;
  8298. - fsblkcnt_t f_blocks, f_bfree, f_bavail;
  8299. - fsfilcnt_t f_files, f_ffree;
  8300. - fsid_t f_fsid;
  8301. - unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
  8302. -};
  8303. --- a/arch/x86_64/bits/stdarg.h
  8304. +++ /dev/null
  8305. @@ -1,4 +0,0 @@
  8306. -#define va_start(v,l) __builtin_va_start(v,l)
  8307. -#define va_end(v) __builtin_va_end(v)
  8308. -#define va_arg(v,l) __builtin_va_arg(v,l)
  8309. -#define va_copy(d,s) __builtin_va_copy(d,s)
  8310. --- a/arch/x86_64/bits/syscall.h
  8311. +++ b/arch/x86_64/bits/syscall.h
  8312. @@ -321,6 +321,9 @@
  8313. #define __NR_kexec_file_load 320
  8314. #define __NR_bpf 321
  8315. #define __NR_execveat 322
  8316. +#define __NR_userfaultfd 323
  8317. +#define __NR_membarrier 324
  8318. +#define __NR_mlock2 325
  8319. @@ -649,3 +652,6 @@
  8320. #define SYS_kexec_file_load 320
  8321. #define SYS_bpf 321
  8322. #define SYS_execveat 322
  8323. +#define SYS_userfaultfd 323
  8324. +#define SYS_membarrier 324
  8325. +#define SYS_mlock2 325
  8326. --- a/arch/x86_64/bits/termios.h
  8327. +++ /dev/null
  8328. @@ -1,160 +0,0 @@
  8329. -struct termios
  8330. -{
  8331. - tcflag_t c_iflag;
  8332. - tcflag_t c_oflag;
  8333. - tcflag_t c_cflag;
  8334. - tcflag_t c_lflag;
  8335. - cc_t c_line;
  8336. - cc_t c_cc[NCCS];
  8337. - speed_t __c_ispeed;
  8338. - speed_t __c_ospeed;
  8339. -};
  8340. -
  8341. -#define VINTR 0
  8342. -#define VQUIT 1
  8343. -#define VERASE 2
  8344. -#define VKILL 3
  8345. -#define VEOF 4
  8346. -#define VTIME 5
  8347. -#define VMIN 6
  8348. -#define VSWTC 7
  8349. -#define VSTART 8
  8350. -#define VSTOP 9
  8351. -#define VSUSP 10
  8352. -#define VEOL 11
  8353. -#define VREPRINT 12
  8354. -#define VDISCARD 13
  8355. -#define VWERASE 14
  8356. -#define VLNEXT 15
  8357. -#define VEOL2 16
  8358. -
  8359. -#define IGNBRK 0000001
  8360. -#define BRKINT 0000002
  8361. -#define IGNPAR 0000004
  8362. -#define PARMRK 0000010
  8363. -#define INPCK 0000020
  8364. -#define ISTRIP 0000040
  8365. -#define INLCR 0000100
  8366. -#define IGNCR 0000200
  8367. -#define ICRNL 0000400
  8368. -#define IUCLC 0001000
  8369. -#define IXON 0002000
  8370. -#define IXANY 0004000
  8371. -#define IXOFF 0010000
  8372. -#define IMAXBEL 0020000
  8373. -#define IUTF8 0040000
  8374. -
  8375. -#define OPOST 0000001
  8376. -#define OLCUC 0000002
  8377. -#define ONLCR 0000004
  8378. -#define OCRNL 0000010
  8379. -#define ONOCR 0000020
  8380. -#define ONLRET 0000040
  8381. -#define OFILL 0000100
  8382. -#define OFDEL 0000200
  8383. -#define NLDLY 0000400
  8384. -#define NL0 0000000
  8385. -#define NL1 0000400
  8386. -#define CRDLY 0003000
  8387. -#define CR0 0000000
  8388. -#define CR1 0001000
  8389. -#define CR2 0002000
  8390. -#define CR3 0003000
  8391. -#define TABDLY 0014000
  8392. -#define TAB0 0000000
  8393. -#define TAB1 0004000
  8394. -#define TAB2 0010000
  8395. -#define TAB3 0014000
  8396. -#define BSDLY 0020000
  8397. -#define BS0 0000000
  8398. -#define BS1 0020000
  8399. -#define FFDLY 0100000
  8400. -#define FF0 0000000
  8401. -#define FF1 0100000
  8402. -
  8403. -#define VTDLY 0040000
  8404. -#define VT0 0000000
  8405. -#define VT1 0040000
  8406. -
  8407. -#define B0 0000000
  8408. -#define B50 0000001
  8409. -#define B75 0000002
  8410. -#define B110 0000003
  8411. -#define B134 0000004
  8412. -#define B150 0000005
  8413. -#define B200 0000006
  8414. -#define B300 0000007
  8415. -#define B600 0000010
  8416. -#define B1200 0000011
  8417. -#define B1800 0000012
  8418. -#define B2400 0000013
  8419. -#define B4800 0000014
  8420. -#define B9600 0000015
  8421. -#define B19200 0000016
  8422. -#define B38400 0000017
  8423. -
  8424. -#define B57600 0010001
  8425. -#define B115200 0010002
  8426. -#define B230400 0010003
  8427. -#define B460800 0010004
  8428. -#define B500000 0010005
  8429. -#define B576000 0010006
  8430. -#define B921600 0010007
  8431. -#define B1000000 0010010
  8432. -#define B1152000 0010011
  8433. -#define B1500000 0010012
  8434. -#define B2000000 0010013
  8435. -#define B2500000 0010014
  8436. -#define B3000000 0010015
  8437. -#define B3500000 0010016
  8438. -#define B4000000 0010017
  8439. -
  8440. -#define CBAUD 0010017
  8441. -
  8442. -#define CSIZE 0000060
  8443. -#define CS5 0000000
  8444. -#define CS6 0000020
  8445. -#define CS7 0000040
  8446. -#define CS8 0000060
  8447. -#define CSTOPB 0000100
  8448. -#define CREAD 0000200
  8449. -#define PARENB 0000400
  8450. -#define PARODD 0001000
  8451. -#define HUPCL 0002000
  8452. -#define CLOCAL 0004000
  8453. -
  8454. -#define ISIG 0000001
  8455. -#define ICANON 0000002
  8456. -#define ECHO 0000010
  8457. -#define ECHOE 0000020
  8458. -#define ECHOK 0000040
  8459. -#define ECHONL 0000100
  8460. -#define NOFLSH 0000200
  8461. -#define TOSTOP 0000400
  8462. -#define IEXTEN 0100000
  8463. -
  8464. -#define ECHOCTL 0001000
  8465. -#define ECHOPRT 0002000
  8466. -#define ECHOKE 0004000
  8467. -#define FLUSHO 0010000
  8468. -#define PENDIN 0040000
  8469. -
  8470. -#define TCOOFF 0
  8471. -#define TCOON 1
  8472. -#define TCIOFF 2
  8473. -#define TCION 3
  8474. -
  8475. -#define TCIFLUSH 0
  8476. -#define TCOFLUSH 1
  8477. -#define TCIOFLUSH 2
  8478. -
  8479. -#define TCSANOW 0
  8480. -#define TCSADRAIN 1
  8481. -#define TCSAFLUSH 2
  8482. -
  8483. -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  8484. -#define CBAUDEX 0010000
  8485. -#define CRTSCTS 020000000000
  8486. -#define EXTPROC 0200000
  8487. -#define XTABS 0014000
  8488. -#endif
  8489. --- a/arch/x86_64/pthread_arch.h
  8490. +++ b/arch/x86_64/pthread_arch.h
  8491. @@ -7,4 +7,4 @@ static inline struct pthread *__pthread_
  8492. #define TP_ADJ(p) (p)
  8493. -#define CANCEL_REG_IP 16
  8494. +#define MC_PC gregs[REG_RIP]
  8495. --- a/configure
  8496. +++ b/configure
  8497. @@ -9,6 +9,9 @@ VAR=VALUE. See below for descriptions o
  8498. Defaults for the options are specified in brackets.
  8499. +Configuration:
  8500. + --srcdir=DIR source directory [detected]
  8501. +
  8502. Installation directories:
  8503. --prefix=PREFIX main installation prefix [/usr/local/musl]
  8504. --exec-prefix=EPREFIX installation prefix for executable files [PREFIX]
  8505. @@ -117,6 +120,7 @@ CFLAGS_TRY=
  8506. LDFLAGS_AUTO=
  8507. LDFLAGS_TRY=
  8508. OPTIMIZE_GLOBS=
  8509. +srcdir=
  8510. prefix=/usr/local/musl
  8511. exec_prefix='$(prefix)'
  8512. bindir='$(exec_prefix)/bin'
  8513. @@ -139,6 +143,7 @@ clang_wrapper=no
  8514. for arg ; do
  8515. case "$arg" in
  8516. --help) usage ;;
  8517. +--srcdir=*) srcdir=${arg#*=} ;;
  8518. --prefix=*) prefix=${arg#*=} ;;
  8519. --exec-prefix=*) exec_prefix=${arg#*=} ;;
  8520. --bindir=*) bindir=${arg#*=} ;;
  8521. @@ -179,11 +184,23 @@ LIBCC=*) LIBCC=${arg#*=} ;;
  8522. esac
  8523. done
  8524. -for i in prefix exec_prefix bindir libdir includedir syslibdir ; do
  8525. +for i in srcdir prefix exec_prefix bindir libdir includedir syslibdir ; do
  8526. stripdir $i
  8527. done
  8528. #
  8529. +# Get the source dir for out-of-tree builds
  8530. +#
  8531. +if test -z "$srcdir" ; then
  8532. +srcdir="${0%/configure}"
  8533. +stripdir srcdir
  8534. +fi
  8535. +abs_builddir="$(pwd)" || fail "$0: cannot determine working directory"
  8536. +abs_srcdir="$(cd $srcdir && pwd)" || fail "$0: invalid source directory $srcdir"
  8537. +test "$abs_srcdir" = "$abs_builddir" && srcdir=.
  8538. +test "$srcdir" != "." -a -f Makefile -a ! -h Makefile && fail "$0: Makefile already exists in the working directory"
  8539. +
  8540. +#
  8541. # Get a temp filename we can use
  8542. #
  8543. i=0
  8544. @@ -263,11 +280,11 @@ fi
  8545. fi
  8546. if test "$gcc_wrapper" = yes ; then
  8547. -tools="$tools tools/musl-gcc"
  8548. +tools="$tools obj/musl-gcc"
  8549. tool_libs="$tool_libs lib/musl-gcc.specs"
  8550. fi
  8551. if test "$clang_wrapper" = yes ; then
  8552. -tools="$tools tools/musl-clang tools/ld.musl-clang"
  8553. +tools="$tools obj/musl-clang obj/ld.musl-clang"
  8554. fi
  8555. #
  8556. @@ -321,7 +338,7 @@ __attribute__((__may_alias__))
  8557. #endif
  8558. x;
  8559. EOF
  8560. -if $CC $CFLAGS_C99FSE -I./arch/$ARCH -I./include $CPPFLAGS $CFLAGS \
  8561. +if $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS \
  8562. -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
  8563. printf "no\n"
  8564. else
  8565. @@ -330,6 +347,13 @@ CFLAGS_C99FSE="$CFLAGS_C99FSE -D__may_al
  8566. fi
  8567. #
  8568. +# The GNU toolchain defaults to assuming unmarked files need an
  8569. +# executable stack, potentially exposing vulnerabilities in programs
  8570. +# linked with such object files. Fix this.
  8571. +#
  8572. +tryflag CFLAGS_C99FSE -Wa,--noexecstack
  8573. +
  8574. +#
  8575. # Check for options to disable stack protector, which needs to be
  8576. # disabled for a few early-bootstrap translation units. If not found,
  8577. # this is not an error; we assume the toolchain does not do ssp.
  8578. @@ -430,11 +454,15 @@ tryflag CFLAGS_AUTO -fno-unwind-tables
  8579. tryflag CFLAGS_AUTO -fno-asynchronous-unwind-tables
  8580. #
  8581. -# The GNU toolchain defaults to assuming unmarked files need an
  8582. -# executable stack, potentially exposing vulnerabilities in programs
  8583. -# linked with such object files. Fix this.
  8584. +# Attempt to put each function and each data object in its own
  8585. +# section. This both allows additional size optimizations at link
  8586. +# time and works around a dangerous class of compiler/assembler bugs
  8587. +# whereby relative address expressions are constant-folded by the
  8588. +# assembler even when one or more of the symbols involved is
  8589. +# replaceable. See gas pr 18561 and gcc pr 66609, 68178, etc.
  8590. #
  8591. -tryflag CFLAGS_AUTO -Wa,--noexecstack
  8592. +tryflag CFLAGS_AUTO -ffunction-sections
  8593. +tryflag CFLAGS_AUTO -fdata-sections
  8594. #
  8595. # On x86, make sure we don't have incompatible instruction set
  8596. @@ -489,7 +517,7 @@ int foo(void) { }
  8597. int bar(void) { fp = foo; return foo(); }
  8598. EOF
  8599. if $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS \
  8600. - -DSHARED -fPIC -I./src/internal -include vis.h \
  8601. + -DSHARED -fPIC -I$srcdir/src/internal -include vis.h \
  8602. -nostdlib -shared -Wl,-Bsymbolic-functions \
  8603. -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
  8604. visibility=yes
  8605. @@ -504,6 +532,25 @@ CFLAGS_AUTO="$CFLAGS_AUTO -include vis.h
  8606. CFLAGS_AUTO="${CFLAGS_AUTO# }"
  8607. fi
  8608. +# Determine if the compiler produces position-independent code (PIC)
  8609. +# by default. If so, we don't need to compile separate object files
  8610. +# for libc.a and libc.so.
  8611. +if trycppif __PIC__ "$CFLAGS_C99FSE $CPPFLAGS $CFLAGS" ; then
  8612. +pic_default=yes
  8613. +else
  8614. +pic_default=no
  8615. +fi
  8616. +
  8617. +# Reduce space lost to padding for alignment purposes by sorting data
  8618. +# objects according to their alignment reqirements. This approximates
  8619. +# optimal packing.
  8620. +tryldflag LDFLAGS_AUTO -Wl,--sort-section,alignment
  8621. +tryldflag LDFLAGS_AUTO -Wl,--sort-common
  8622. +
  8623. +# When linking shared library, drop dummy weak definitions that were
  8624. +# replaced by strong definitions from other translation units.
  8625. +tryldflag LDFLAGS_AUTO -Wl,--gc-sections
  8626. +
  8627. # Some patched GCC builds have these defaults messed up...
  8628. tryldflag LDFLAGS_AUTO -Wl,--hash-style=both
  8629. @@ -513,6 +560,11 @@ tryldflag LDFLAGS_AUTO -Wl,--hash-style=
  8630. # runtime library; implementation error is also a possibility.
  8631. tryldflag LDFLAGS_AUTO -Wl,--no-undefined
  8632. +# Avoid exporting symbols from compiler runtime libraries. They
  8633. +# should be hidden anyway, but some toolchains including old gcc
  8634. +# versions built without shared library support and pcc are broken.
  8635. +tryldflag LDFLAGS_AUTO -Wl,--exclude-libs=ALL
  8636. +
  8637. test "$shared" = "no" || {
  8638. # Disable dynamic linking if ld is broken and can't do -Bsymbolic-functions
  8639. LDFLAGS_DUMMY=
  8640. @@ -599,8 +651,9 @@ echo '#include <float.h>' > "$tmpc"
  8641. echo '#if LDBL_MANT_DIG == 53' >> "$tmpc"
  8642. echo 'typedef char ldcheck[9-(int)sizeof(long double)];' >> "$tmpc"
  8643. echo '#endif' >> "$tmpc"
  8644. -if $CC $CFLAGS_C99FSE -I./arch/$ARCH -I./include $CPPFLAGS $CFLAGS \
  8645. - -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
  8646. +if $CC $CFLAGS_C99FSE \
  8647. + -I$srcdir/arch/$ARCH -I$srcdir/arch/generic -I$srcdir/include \
  8648. + $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
  8649. printf "yes\n"
  8650. else
  8651. printf "no\n"
  8652. @@ -622,6 +675,7 @@ cat << EOF
  8653. ARCH = $ARCH
  8654. SUBARCH = $SUBARCH
  8655. ASMSUBARCH = $ASMSUBARCH
  8656. +srcdir = $srcdir
  8657. prefix = $prefix
  8658. exec_prefix = $exec_prefix
  8659. bindir = $bindir
  8660. @@ -629,12 +683,14 @@ libdir = $libdir
  8661. includedir = $includedir
  8662. syslibdir = $syslibdir
  8663. CC = $CC
  8664. -CFLAGS = $CFLAGS_AUTO $CFLAGS
  8665. +CFLAGS = $CFLAGS
  8666. +CFLAGS_AUTO = $CFLAGS_AUTO
  8667. CFLAGS_C99FSE = $CFLAGS_C99FSE
  8668. CFLAGS_MEMOPS = $CFLAGS_MEMOPS
  8669. CFLAGS_NOSSP = $CFLAGS_NOSSP
  8670. CPPFLAGS = $CPPFLAGS
  8671. -LDFLAGS = $LDFLAGS_AUTO $LDFLAGS
  8672. +LDFLAGS = $LDFLAGS
  8673. +LDFLAGS_AUTO = $LDFLAGS_AUTO
  8674. CROSS_COMPILE = $CROSS_COMPILE
  8675. LIBCC = $LIBCC
  8676. OPTIMIZE_GLOBS = $OPTIMIZE_GLOBS
  8677. @@ -646,6 +702,9 @@ test "x$static" = xno && echo "STATIC_LI
  8678. test "x$shared" = xno && echo "SHARED_LIBS ="
  8679. test "x$cc_family" = xgcc && echo 'WRAPCC_GCC = $(CC)'
  8680. test "x$cc_family" = xclang && echo 'WRAPCC_CLANG = $(CC)'
  8681. +test "x$pic_default" = xyes && echo 'AOBJS = $(LOBJS)'
  8682. exec 1>&3 3>&-
  8683. +test "$srcdir" = "." || ln -sf $srcdir/Makefile .
  8684. +
  8685. printf "done\n"
  8686. --- a/crt/arm/crti.s
  8687. +++ b/crt/arm/crti.s
  8688. @@ -1,3 +1,5 @@
  8689. +.syntax unified
  8690. +
  8691. .section .init
  8692. .global _init
  8693. .type _init,%function
  8694. --- a/crt/arm/crtn.s
  8695. +++ b/crt/arm/crtn.s
  8696. @@ -1,11 +1,9 @@
  8697. +.syntax unified
  8698. +
  8699. .section .init
  8700. pop {r0,lr}
  8701. - tst lr,#1
  8702. - moveq pc,lr
  8703. bx lr
  8704. .section .fini
  8705. pop {r0,lr}
  8706. - tst lr,#1
  8707. - moveq pc,lr
  8708. bx lr
  8709. --- a/crt/rcrt1.c
  8710. +++ b/crt/rcrt1.c
  8711. @@ -1,7 +1,7 @@
  8712. #define SHARED
  8713. #define START "_start"
  8714. #define _dlstart_c _start_c
  8715. -#include "../src/ldso/dlstart.c"
  8716. +#include "../ldso/dlstart.c"
  8717. int main();
  8718. void _init() __attribute__((weak));
  8719. --- a/include/complex.h
  8720. +++ b/include/complex.h
  8721. @@ -116,7 +116,7 @@ long double creall(long double complex);
  8722. #if __STDC_VERSION__ >= 201112L
  8723. #if defined(_Imaginary_I)
  8724. -#define __CMPLX(x, y, t) ((t)(x) + _Imaginary_I*(t)(y)))
  8725. +#define __CMPLX(x, y, t) ((t)(x) + _Imaginary_I*(t)(y))
  8726. #elif defined(__clang__)
  8727. #define __CMPLX(x, y, t) (+(_Complex t){ (t)(x), (t)(y) })
  8728. #else
  8729. --- a/include/netinet/in.h
  8730. +++ b/include/netinet/in.h
  8731. @@ -103,6 +103,7 @@ uint16_t ntohs(uint16_t);
  8732. #define IPPROTO_SCTP 132
  8733. #define IPPROTO_MH 135
  8734. #define IPPROTO_UDPLITE 136
  8735. +#define IPPROTO_MPLS 137
  8736. #define IPPROTO_RAW 255
  8737. #define IPPROTO_MAX 256
  8738. @@ -200,6 +201,7 @@ uint16_t ntohs(uint16_t);
  8739. #define IP_MINTTL 21
  8740. #define IP_NODEFRAG 22
  8741. #define IP_CHECKSUM 23
  8742. +#define IP_BIND_ADDRESS_NO_PORT 24
  8743. #define IP_MULTICAST_IF 32
  8744. #define IP_MULTICAST_TTL 33
  8745. #define IP_MULTICAST_LOOP 34
  8746. --- a/include/netinet/tcp.h
  8747. +++ b/include/netinet/tcp.h
  8748. @@ -27,6 +27,9 @@
  8749. #define TCP_FASTOPEN 23
  8750. #define TCP_TIMESTAMP 24
  8751. #define TCP_NOTSENT_LOWAT 25
  8752. +#define TCP_CC_INFO 26
  8753. +#define TCP_SAVE_SYN 27
  8754. +#define TCP_SAVED_SYN 28
  8755. #define TCP_ESTABLISHED 1
  8756. #define TCP_SYN_SENT 2
  8757. @@ -41,7 +44,20 @@
  8758. #define TCP_CLOSING 11
  8759. #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  8760. +#define TCPOPT_EOL 0
  8761. +#define TCPOPT_NOP 1
  8762. +#define TCPOPT_MAXSEG 2
  8763. +#define TCPOPT_WINDOW 3
  8764. +#define TCPOPT_SACK_PERMITTED 4
  8765. +#define TCPOPT_SACK 5
  8766. +#define TCPOPT_TIMESTAMP 8
  8767. +#define TCPOLEN_SACK_PERMITTED 2
  8768. +#define TCPOLEN_WINDOW 3
  8769. +#define TCPOLEN_MAXSEG 4
  8770. +#define TCPOLEN_TIMESTAMP 10
  8771. +
  8772. #define SOL_TCP 6
  8773. +
  8774. #include <sys/types.h>
  8775. #include <sys/socket.h>
  8776. #include <stdint.h>
  8777. @@ -164,6 +180,10 @@ struct tcp_info
  8778. uint32_t tcpi_total_retrans;
  8779. uint64_t tcpi_pacing_rate;
  8780. uint64_t tcpi_max_pacing_rate;
  8781. + uint64_t tcpi_bytes_acked;
  8782. + uint64_t tcpi_bytes_received;
  8783. + uint32_t tcpi_segs_out;
  8784. + uint32_t tcpi_segs_in;
  8785. };
  8786. #define TCP_MD5SIG_MAXKEYLEN 80
  8787. --- a/include/netpacket/packet.h
  8788. +++ b/include/netpacket/packet.h
  8789. @@ -32,10 +32,27 @@ struct packet_mreq {
  8790. #define PACKET_RECV_OUTPUT 3
  8791. #define PACKET_RX_RING 5
  8792. #define PACKET_STATISTICS 6
  8793. +#define PACKET_COPY_THRESH 7
  8794. +#define PACKET_AUXDATA 8
  8795. +#define PACKET_ORIGDEV 9
  8796. +#define PACKET_VERSION 10
  8797. +#define PACKET_HDRLEN 11
  8798. +#define PACKET_RESERVE 12
  8799. +#define PACKET_TX_RING 13
  8800. +#define PACKET_LOSS 14
  8801. +#define PACKET_VNET_HDR 15
  8802. +#define PACKET_TX_TIMESTAMP 16
  8803. +#define PACKET_TIMESTAMP 17
  8804. +#define PACKET_FANOUT 18
  8805. +#define PACKET_TX_HAS_OFF 19
  8806. +#define PACKET_QDISC_BYPASS 20
  8807. +#define PACKET_ROLLOVER_STATS 21
  8808. +#define PACKET_FANOUT_DATA 22
  8809. #define PACKET_MR_MULTICAST 0
  8810. #define PACKET_MR_PROMISC 1
  8811. #define PACKET_MR_ALLMULTI 2
  8812. +#define PACKET_MR_UNICAST 3
  8813. #ifdef __cplusplus
  8814. }
  8815. --- a/include/signal.h
  8816. +++ b/include/signal.h
  8817. @@ -27,8 +27,6 @@ extern "C" {
  8818. #include <bits/alltypes.h>
  8819. -#define SIG_HOLD ((void (*)(int)) 2)
  8820. -
  8821. #define SIG_BLOCK 0
  8822. #define SIG_UNBLOCK 1
  8823. #define SIG_SETMASK 2
  8824. @@ -43,6 +41,18 @@ extern "C" {
  8825. #define SI_USER 0
  8826. #define SI_KERNEL 128
  8827. +typedef struct sigaltstack stack_t;
  8828. +
  8829. +#endif
  8830. +
  8831. +#include <bits/signal.h>
  8832. +
  8833. +#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
  8834. + || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
  8835. + || defined(_BSD_SOURCE)
  8836. +
  8837. +#define SIG_HOLD ((void (*)(int)) 2)
  8838. +
  8839. #define FPE_INTDIV 1
  8840. #define FPE_INTOVF 2
  8841. #define FPE_FLTDIV 3
  8842. @@ -78,15 +88,17 @@ extern "C" {
  8843. #define CLD_STOPPED 5
  8844. #define CLD_CONTINUED 6
  8845. -typedef struct sigaltstack stack_t;
  8846. -
  8847. union sigval {
  8848. int sival_int;
  8849. void *sival_ptr;
  8850. };
  8851. typedef struct {
  8852. +#ifdef __SI_SWAP_ERRNO_CODE
  8853. + int si_signo, si_code, si_errno;
  8854. +#else
  8855. int si_signo, si_errno, si_code;
  8856. +#endif
  8857. union {
  8858. char __pad[128 - 2*sizeof(int) - sizeof(long)];
  8859. struct {
  8860. @@ -240,8 +252,6 @@ int sigandset(sigset_t *, const sigset_t
  8861. #define SA_ONESHOT SA_RESETHAND
  8862. #endif
  8863. -#include <bits/signal.h>
  8864. -
  8865. #define SIG_ERR ((void (*)(int))-1)
  8866. #define SIG_DFL ((void (*)(int)) 0)
  8867. #define SIG_IGN ((void (*)(int)) 1)
  8868. --- a/include/sys/mman.h
  8869. +++ b/include/sys/mman.h
  8870. @@ -39,6 +39,7 @@ int remap_file_pages (void *, size_t, in
  8871. #endif
  8872. #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  8873. +#define MLOCK_ONFAULT 0x01
  8874. int madvise (void *, size_t, int);
  8875. int mincore (void *, size_t, unsigned char *);
  8876. #endif
  8877. --- a/include/sys/mount.h
  8878. +++ b/include/sys/mount.h
  8879. @@ -46,12 +46,13 @@ extern "C" {
  8880. #define MS_KERNMOUNT (1<<22)
  8881. #define MS_I_VERSION (1<<23)
  8882. #define MS_STRICTATIME (1<<24)
  8883. +#define MS_LAZYTIME (1<<25)
  8884. #define MS_NOSEC (1<<28)
  8885. #define MS_BORN (1<<29)
  8886. #define MS_ACTIVE (1<<30)
  8887. #define MS_NOUSER (1U<<31)
  8888. -#define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_I_VERSION)
  8889. +#define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_I_VERSION|MS_LAZYTIME)
  8890. #define MS_MGC_VAL 0xc0ed0000
  8891. #define MS_MGC_MSK 0xffff0000
  8892. --- a/include/sys/prctl.h
  8893. +++ b/include/sys/prctl.h
  8894. @@ -124,6 +124,12 @@ struct prctl_mm_map {
  8895. #define PR_FP_MODE_FR (1 << 0)
  8896. #define PR_FP_MODE_FRE (1 << 1)
  8897. +#define PR_CAP_AMBIENT 47
  8898. +#define PR_CAP_AMBIENT_IS_SET 1
  8899. +#define PR_CAP_AMBIENT_RAISE 2
  8900. +#define PR_CAP_AMBIENT_LOWER 3
  8901. +#define PR_CAP_AMBIENT_CLEAR_ALL 4
  8902. +
  8903. int prctl (int, ...);
  8904. #ifdef __cplusplus
  8905. --- a/include/sys/ptrace.h
  8906. +++ b/include/sys/ptrace.h
  8907. @@ -39,6 +39,7 @@ extern "C" {
  8908. #define PTRACE_PEEKSIGINFO 0x4209
  8909. #define PTRACE_GETSIGMASK 0x420a
  8910. #define PTRACE_SETSIGMASK 0x420b
  8911. +#define PTRACE_SECCOMP_GET_FILTER 0x420c
  8912. #define PT_READ_I PTRACE_PEEKTEXT
  8913. #define PT_READ_D PTRACE_PEEKDATA
  8914. @@ -72,7 +73,8 @@ extern "C" {
  8915. #define PTRACE_O_TRACEEXIT 0x00000040
  8916. #define PTRACE_O_TRACESECCOMP 0x00000080
  8917. #define PTRACE_O_EXITKILL 0x00100000
  8918. -#define PTRACE_O_MASK 0x001000ff
  8919. +#define PTRACE_O_SUSPEND_SECCOMP 0x00200000
  8920. +#define PTRACE_O_MASK 0x003000ff
  8921. #define PTRACE_EVENT_FORK 1
  8922. #define PTRACE_EVENT_VFORK 2
  8923. --- a/include/sys/socket.h
  8924. +++ b/include/sys/socket.h
  8925. @@ -96,6 +96,7 @@ struct linger
  8926. #define PF_WANPIPE 25
  8927. #define PF_LLC 26
  8928. #define PF_IB 27
  8929. +#define PF_MPLS 28
  8930. #define PF_CAN 29
  8931. #define PF_TIPC 30
  8932. #define PF_BLUETOOTH 31
  8933. @@ -141,6 +142,7 @@ struct linger
  8934. #define AF_WANPIPE PF_WANPIPE
  8935. #define AF_LLC PF_LLC
  8936. #define AF_IB PF_IB
  8937. +#define AF_MPLS PF_MPLS
  8938. #define AF_CAN PF_CAN
  8939. #define AF_TIPC PF_TIPC
  8940. #define AF_BLUETOOTH PF_BLUETOOTH
  8941. @@ -255,6 +257,7 @@ struct linger
  8942. #define MSG_NOSIGNAL 0x4000
  8943. #define MSG_MORE 0x8000
  8944. #define MSG_WAITFORONE 0x10000
  8945. +#define MSG_FASTOPEN 0x20000000
  8946. #define MSG_CMSG_CLOEXEC 0x40000000
  8947. #define __CMSG_LEN(cmsg) (((cmsg)->cmsg_len + sizeof(long) - 1) & ~(long)(sizeof(long) - 1))
  8948. --- /dev/null
  8949. +++ b/ldso/dlstart.c
  8950. @@ -0,0 +1,146 @@
  8951. +#include <stddef.h>
  8952. +#include "dynlink.h"
  8953. +
  8954. +#ifndef START
  8955. +#define START "_dlstart"
  8956. +#endif
  8957. +
  8958. +#include "crt_arch.h"
  8959. +
  8960. +#ifndef GETFUNCSYM
  8961. +#define GETFUNCSYM(fp, sym, got) do { \
  8962. + __attribute__((__visibility__("hidden"))) void sym(); \
  8963. + static void (*static_func_ptr)() = sym; \
  8964. + __asm__ __volatile__ ( "" : "+m"(static_func_ptr) : : "memory"); \
  8965. + *(fp) = static_func_ptr; } while(0)
  8966. +#endif
  8967. +
  8968. +__attribute__((__visibility__("hidden")))
  8969. +void _dlstart_c(size_t *sp, size_t *dynv)
  8970. +{
  8971. + size_t i, aux[AUX_CNT], dyn[DYN_CNT];
  8972. + size_t *rel, rel_size, base;
  8973. +
  8974. + int argc = *sp;
  8975. + char **argv = (void *)(sp+1);
  8976. +
  8977. + for (i=argc+1; argv[i]; i++);
  8978. + size_t *auxv = (void *)(argv+i+1);
  8979. +
  8980. + for (i=0; i<AUX_CNT; i++) aux[i] = 0;
  8981. + for (i=0; auxv[i]; i+=2) if (auxv[i]<AUX_CNT)
  8982. + aux[auxv[i]] = auxv[i+1];
  8983. +
  8984. +#if DL_FDPIC
  8985. + struct fdpic_loadseg *segs, fakeseg;
  8986. + size_t j;
  8987. + if (dynv) {
  8988. + /* crt_arch.h entry point asm is responsible for reserving
  8989. + * space and moving the extra fdpic arguments to the stack
  8990. + * vector where they are easily accessible from C. */
  8991. + segs = ((struct fdpic_loadmap *)(sp[-1] ? sp[-1] : sp[-2]))->segs;
  8992. + } else {
  8993. + /* If dynv is null, the entry point was started from loader
  8994. + * that is not fdpic-aware. We can assume normal fixed-
  8995. + * displacement ELF loading was performed, but when ldso was
  8996. + * run as a command, finding the Ehdr is a heursitic: we
  8997. + * have to assume Phdrs start in the first 4k of the file. */
  8998. + base = aux[AT_BASE];
  8999. + if (!base) base = aux[AT_PHDR] & -4096;
  9000. + segs = &fakeseg;
  9001. + segs[0].addr = base;
  9002. + segs[0].p_vaddr = 0;
  9003. + segs[0].p_memsz = -1;
  9004. + Ehdr *eh = (void *)base;
  9005. + Phdr *ph = (void *)(base + eh->e_phoff);
  9006. + size_t phnum = eh->e_phnum;
  9007. + size_t phent = eh->e_phentsize;
  9008. + while (phnum-- && ph->p_type != PT_DYNAMIC)
  9009. + ph = (void *)((size_t)ph + phent);
  9010. + dynv = (void *)(base + ph->p_vaddr);
  9011. + }
  9012. +#endif
  9013. +
  9014. + for (i=0; i<DYN_CNT; i++) dyn[i] = 0;
  9015. + for (i=0; dynv[i]; i+=2) if (dynv[i]<DYN_CNT)
  9016. + dyn[dynv[i]] = dynv[i+1];
  9017. +
  9018. +#if DL_FDPIC
  9019. + for (i=0; i<DYN_CNT; i++) {
  9020. + if (i==DT_RELASZ || i==DT_RELSZ) continue;
  9021. + if (!dyn[i]) continue;
  9022. + for (j=0; dyn[i]-segs[j].p_vaddr >= segs[j].p_memsz; j++);
  9023. + dyn[i] += segs[j].addr - segs[j].p_vaddr;
  9024. + }
  9025. + base = 0;
  9026. +
  9027. + const Sym *syms = (void *)dyn[DT_SYMTAB];
  9028. +
  9029. + rel = (void *)dyn[DT_RELA];
  9030. + rel_size = dyn[DT_RELASZ];
  9031. + for (; rel_size; rel+=3, rel_size-=3*sizeof(size_t)) {
  9032. + if (!IS_RELATIVE(rel[1], syms)) continue;
  9033. + for (j=0; rel[0]-segs[j].p_vaddr >= segs[j].p_memsz; j++);
  9034. + size_t *rel_addr = (void *)
  9035. + (rel[0] + segs[j].addr - segs[j].p_vaddr);
  9036. + if (R_TYPE(rel[1]) == REL_FUNCDESC_VAL) {
  9037. + *rel_addr += segs[rel_addr[1]].addr
  9038. + - segs[rel_addr[1]].p_vaddr
  9039. + + syms[R_SYM(rel[1])].st_value;
  9040. + rel_addr[1] = dyn[DT_PLTGOT];
  9041. + } else {
  9042. + size_t val = syms[R_SYM(rel[1])].st_value;
  9043. + for (j=0; val-segs[j].p_vaddr >= segs[j].p_memsz; j++);
  9044. + *rel_addr = rel[2] + segs[j].addr - segs[j].p_vaddr + val;
  9045. + }
  9046. + }
  9047. +#else
  9048. + /* If the dynamic linker is invoked as a command, its load
  9049. + * address is not available in the aux vector. Instead, compute
  9050. + * the load address as the difference between &_DYNAMIC and the
  9051. + * virtual address in the PT_DYNAMIC program header. */
  9052. + base = aux[AT_BASE];
  9053. + if (!base) {
  9054. + size_t phnum = aux[AT_PHNUM];
  9055. + size_t phentsize = aux[AT_PHENT];
  9056. + Phdr *ph = (void *)aux[AT_PHDR];
  9057. + for (i=phnum; i--; ph = (void *)((char *)ph + phentsize)) {
  9058. + if (ph->p_type == PT_DYNAMIC) {
  9059. + base = (size_t)dynv - ph->p_vaddr;
  9060. + break;
  9061. + }
  9062. + }
  9063. + }
  9064. +
  9065. + /* MIPS uses an ugly packed form for GOT relocations. Since we
  9066. + * can't make function calls yet and the code is tiny anyway,
  9067. + * it's simply inlined here. */
  9068. + if (NEED_MIPS_GOT_RELOCS) {
  9069. + size_t local_cnt = 0;
  9070. + size_t *got = (void *)(base + dyn[DT_PLTGOT]);
  9071. + for (i=0; dynv[i]; i+=2) if (dynv[i]==DT_MIPS_LOCAL_GOTNO)
  9072. + local_cnt = dynv[i+1];
  9073. + for (i=0; i<local_cnt; i++) got[i] += base;
  9074. + }
  9075. +
  9076. + rel = (void *)(base+dyn[DT_REL]);
  9077. + rel_size = dyn[DT_RELSZ];
  9078. + for (; rel_size; rel+=2, rel_size-=2*sizeof(size_t)) {
  9079. + if (!IS_RELATIVE(rel[1], 0)) continue;
  9080. + size_t *rel_addr = (void *)(base + rel[0]);
  9081. + *rel_addr += base;
  9082. + }
  9083. +
  9084. + rel = (void *)(base+dyn[DT_RELA]);
  9085. + rel_size = dyn[DT_RELASZ];
  9086. + for (; rel_size; rel+=3, rel_size-=3*sizeof(size_t)) {
  9087. + if (!IS_RELATIVE(rel[1], 0)) continue;
  9088. + size_t *rel_addr = (void *)(base + rel[0]);
  9089. + *rel_addr = base + rel[2];
  9090. + }
  9091. +#endif
  9092. +
  9093. + stage2_func dls2;
  9094. + GETFUNCSYM(&dls2, __dls2, base+dyn[DT_PLTGOT]);
  9095. + dls2((void *)base, sp);
  9096. +}
  9097. --- /dev/null
  9098. +++ b/ldso/dynlink.c
  9099. @@ -0,0 +1,1931 @@
  9100. +#define _GNU_SOURCE
  9101. +#include <stdio.h>
  9102. +#include <stdlib.h>
  9103. +#include <stdarg.h>
  9104. +#include <stddef.h>
  9105. +#include <string.h>
  9106. +#include <unistd.h>
  9107. +#include <stdint.h>
  9108. +#include <elf.h>
  9109. +#include <sys/mman.h>
  9110. +#include <limits.h>
  9111. +#include <fcntl.h>
  9112. +#include <sys/stat.h>
  9113. +#include <errno.h>
  9114. +#include <link.h>
  9115. +#include <setjmp.h>
  9116. +#include <pthread.h>
  9117. +#include <ctype.h>
  9118. +#include <dlfcn.h>
  9119. +#include "pthread_impl.h"
  9120. +#include "libc.h"
  9121. +#include "dynlink.h"
  9122. +
  9123. +static void error(const char *, ...);
  9124. +
  9125. +#define MAXP2(a,b) (-(-(a)&-(b)))
  9126. +#define ALIGN(x,y) ((x)+(y)-1 & -(y))
  9127. +
  9128. +struct debug {
  9129. + int ver;
  9130. + void *head;
  9131. + void (*bp)(void);
  9132. + int state;
  9133. + void *base;
  9134. +};
  9135. +
  9136. +struct td_index {
  9137. + size_t args[2];
  9138. + struct td_index *next;
  9139. +};
  9140. +
  9141. +struct dso {
  9142. +#if DL_FDPIC
  9143. + struct fdpic_loadmap *loadmap;
  9144. +#else
  9145. + unsigned char *base;
  9146. +#endif
  9147. + char *name;
  9148. + size_t *dynv;
  9149. + struct dso *next, *prev;
  9150. +
  9151. + Phdr *phdr;
  9152. + int phnum;
  9153. + size_t phentsize;
  9154. + int refcnt;
  9155. + Sym *syms;
  9156. + uint32_t *hashtab;
  9157. + uint32_t *ghashtab;
  9158. + int16_t *versym;
  9159. + char *strings;
  9160. + unsigned char *map;
  9161. + size_t map_len;
  9162. + dev_t dev;
  9163. + ino_t ino;
  9164. + signed char global;
  9165. + char relocated;
  9166. + char constructed;
  9167. + char kernel_mapped;
  9168. + struct dso **deps, *needed_by;
  9169. + char *rpath_orig, *rpath;
  9170. + struct tls_module tls;
  9171. + size_t tls_id;
  9172. + size_t relro_start, relro_end;
  9173. + void **new_dtv;
  9174. + unsigned char *new_tls;
  9175. + volatile int new_dtv_idx, new_tls_idx;
  9176. + struct td_index *td_index;
  9177. + struct dso *fini_next;
  9178. + char *shortname;
  9179. +#if DL_FDPIC
  9180. + unsigned char *base;
  9181. +#else
  9182. + struct fdpic_loadmap *loadmap;
  9183. +#endif
  9184. + struct funcdesc {
  9185. + void *addr;
  9186. + size_t *got;
  9187. + } *funcdescs;
  9188. + size_t *got;
  9189. + char buf[];
  9190. +};
  9191. +
  9192. +struct symdef {
  9193. + Sym *sym;
  9194. + struct dso *dso;
  9195. +};
  9196. +
  9197. +int __init_tp(void *);
  9198. +void __init_libc(char **, char *);
  9199. +void *__copy_tls(unsigned char *);
  9200. +
  9201. +__attribute__((__visibility__("hidden")))
  9202. +const char *__libc_get_version(void);
  9203. +
  9204. +static struct builtin_tls {
  9205. + char c;
  9206. + struct pthread pt;
  9207. + void *space[16];
  9208. +} builtin_tls[1];
  9209. +#define MIN_TLS_ALIGN offsetof(struct builtin_tls, pt)
  9210. +
  9211. +#define ADDEND_LIMIT 4096
  9212. +static size_t *saved_addends, *apply_addends_to;
  9213. +
  9214. +static struct dso ldso;
  9215. +static struct dso *head, *tail, *fini_head;
  9216. +static char *env_path, *sys_path;
  9217. +static unsigned long long gencnt;
  9218. +static int runtime;
  9219. +static int ldd_mode;
  9220. +static int ldso_fail;
  9221. +static int noload;
  9222. +static jmp_buf *rtld_fail;
  9223. +static pthread_rwlock_t lock;
  9224. +static struct debug debug;
  9225. +static struct tls_module *tls_tail;
  9226. +static size_t tls_cnt, tls_offset, tls_align = MIN_TLS_ALIGN;
  9227. +static size_t static_tls_cnt;
  9228. +static pthread_mutex_t init_fini_lock = { ._m_type = PTHREAD_MUTEX_RECURSIVE };
  9229. +static struct fdpic_loadmap *app_loadmap;
  9230. +static struct fdpic_dummy_loadmap app_dummy_loadmap;
  9231. +
  9232. +struct debug *_dl_debug_addr = &debug;
  9233. +
  9234. +__attribute__((__visibility__("hidden")))
  9235. +void (*const __init_array_start)(void)=0, (*const __fini_array_start)(void)=0;
  9236. +
  9237. +__attribute__((__visibility__("hidden")))
  9238. +extern void (*const __init_array_end)(void), (*const __fini_array_end)(void);
  9239. +
  9240. +weak_alias(__init_array_start, __init_array_end);
  9241. +weak_alias(__fini_array_start, __fini_array_end);
  9242. +
  9243. +static int dl_strcmp(const char *l, const char *r)
  9244. +{
  9245. + for (; *l==*r && *l; l++, r++);
  9246. + return *(unsigned char *)l - *(unsigned char *)r;
  9247. +}
  9248. +#define strcmp(l,r) dl_strcmp(l,r)
  9249. +
  9250. +/* Compute load address for a virtual address in a given dso. */
  9251. +#if DL_FDPIC
  9252. +static void *laddr(const struct dso *p, size_t v)
  9253. +{
  9254. + size_t j=0;
  9255. + if (!p->loadmap) return p->base + v;
  9256. + for (j=0; v-p->loadmap->segs[j].p_vaddr >= p->loadmap->segs[j].p_memsz; j++);
  9257. + return (void *)(v - p->loadmap->segs[j].p_vaddr + p->loadmap->segs[j].addr);
  9258. +}
  9259. +#define fpaddr(p, v) ((void (*)())&(struct funcdesc){ \
  9260. + laddr(p, v), (p)->got })
  9261. +#else
  9262. +#define laddr(p, v) (void *)((p)->base + (v))
  9263. +#define fpaddr(p, v) ((void (*)())laddr(p, v))
  9264. +#endif
  9265. +
  9266. +static void decode_vec(size_t *v, size_t *a, size_t cnt)
  9267. +{
  9268. + size_t i;
  9269. + for (i=0; i<cnt; i++) a[i] = 0;
  9270. + for (; v[0]; v+=2) if (v[0]-1<cnt-1) {
  9271. + a[0] |= 1UL<<v[0];
  9272. + a[v[0]] = v[1];
  9273. + }
  9274. +}
  9275. +
  9276. +static int search_vec(size_t *v, size_t *r, size_t key)
  9277. +{
  9278. + for (; v[0]!=key; v+=2)
  9279. + if (!v[0]) return 0;
  9280. + *r = v[1];
  9281. + return 1;
  9282. +}
  9283. +
  9284. +static uint32_t sysv_hash(const char *s0)
  9285. +{
  9286. + const unsigned char *s = (void *)s0;
  9287. + uint_fast32_t h = 0;
  9288. + while (*s) {
  9289. + h = 16*h + *s++;
  9290. + h ^= h>>24 & 0xf0;
  9291. + }
  9292. + return h & 0xfffffff;
  9293. +}
  9294. +
  9295. +static uint32_t gnu_hash(const char *s0)
  9296. +{
  9297. + const unsigned char *s = (void *)s0;
  9298. + uint_fast32_t h = 5381;
  9299. + for (; *s; s++)
  9300. + h += h*32 + *s;
  9301. + return h;
  9302. +}
  9303. +
  9304. +static Sym *sysv_lookup(const char *s, uint32_t h, struct dso *dso)
  9305. +{
  9306. + size_t i;
  9307. + Sym *syms = dso->syms;
  9308. + uint32_t *hashtab = dso->hashtab;
  9309. + char *strings = dso->strings;
  9310. + for (i=hashtab[2+h%hashtab[0]]; i; i=hashtab[2+hashtab[0]+i]) {
  9311. + if ((!dso->versym || dso->versym[i] >= 0)
  9312. + && (!strcmp(s, strings+syms[i].st_name)))
  9313. + return syms+i;
  9314. + }
  9315. + return 0;
  9316. +}
  9317. +
  9318. +static Sym *gnu_lookup(uint32_t h1, uint32_t *hashtab, struct dso *dso, const char *s)
  9319. +{
  9320. + uint32_t nbuckets = hashtab[0];
  9321. + uint32_t *buckets = hashtab + 4 + hashtab[2]*(sizeof(size_t)/4);
  9322. + uint32_t i = buckets[h1 % nbuckets];
  9323. +
  9324. + if (!i) return 0;
  9325. +
  9326. + uint32_t *hashval = buckets + nbuckets + (i - hashtab[1]);
  9327. +
  9328. + for (h1 |= 1; ; i++) {
  9329. + uint32_t h2 = *hashval++;
  9330. + if ((h1 == (h2|1)) && (!dso->versym || dso->versym[i] >= 0)
  9331. + && !strcmp(s, dso->strings + dso->syms[i].st_name))
  9332. + return dso->syms+i;
  9333. + if (h2 & 1) break;
  9334. + }
  9335. +
  9336. + return 0;
  9337. +}
  9338. +
  9339. +static Sym *gnu_lookup_filtered(uint32_t h1, uint32_t *hashtab, struct dso *dso, const char *s, uint32_t fofs, size_t fmask)
  9340. +{
  9341. + const size_t *bloomwords = (const void *)(hashtab+4);
  9342. + size_t f = bloomwords[fofs & (hashtab[2]-1)];
  9343. + if (!(f & fmask)) return 0;
  9344. +
  9345. + f >>= (h1 >> hashtab[3]) % (8 * sizeof f);
  9346. + if (!(f & 1)) return 0;
  9347. +
  9348. + return gnu_lookup(h1, hashtab, dso, s);
  9349. +}
  9350. +
  9351. +#define OK_TYPES (1<<STT_NOTYPE | 1<<STT_OBJECT | 1<<STT_FUNC | 1<<STT_COMMON | 1<<STT_TLS)
  9352. +#define OK_BINDS (1<<STB_GLOBAL | 1<<STB_WEAK | 1<<STB_GNU_UNIQUE)
  9353. +
  9354. +#ifndef ARCH_SYM_REJECT_UND
  9355. +#define ARCH_SYM_REJECT_UND(s) 0
  9356. +#endif
  9357. +
  9358. +static struct symdef find_sym(struct dso *dso, const char *s, int need_def)
  9359. +{
  9360. + uint32_t h = 0, gh, gho, *ght;
  9361. + size_t ghm = 0;
  9362. + struct symdef def = {0};
  9363. + for (; dso; dso=dso->next) {
  9364. + Sym *sym;
  9365. + if (!dso->global) continue;
  9366. + if ((ght = dso->ghashtab)) {
  9367. + if (!ghm) {
  9368. + gh = gnu_hash(s);
  9369. + int maskbits = 8 * sizeof ghm;
  9370. + gho = gh / maskbits;
  9371. + ghm = 1ul << gh % maskbits;
  9372. + }
  9373. + sym = gnu_lookup_filtered(gh, ght, dso, s, gho, ghm);
  9374. + } else {
  9375. + if (!h) h = sysv_hash(s);
  9376. + sym = sysv_lookup(s, h, dso);
  9377. + }
  9378. + if (!sym) continue;
  9379. + if (!sym->st_shndx)
  9380. + if (need_def || (sym->st_info&0xf) == STT_TLS
  9381. + || ARCH_SYM_REJECT_UND(sym))
  9382. + continue;
  9383. + if (!sym->st_value)
  9384. + if ((sym->st_info&0xf) != STT_TLS)
  9385. + continue;
  9386. + if (!(1<<(sym->st_info&0xf) & OK_TYPES)) continue;
  9387. + if (!(1<<(sym->st_info>>4) & OK_BINDS)) continue;
  9388. +
  9389. + if (def.sym && sym->st_info>>4 == STB_WEAK) continue;
  9390. + def.sym = sym;
  9391. + def.dso = dso;
  9392. + if (sym->st_info>>4 == STB_GLOBAL) break;
  9393. + }
  9394. + return def;
  9395. +}
  9396. +
  9397. +__attribute__((__visibility__("hidden")))
  9398. +ptrdiff_t __tlsdesc_static(), __tlsdesc_dynamic();
  9399. +
  9400. +static void do_relocs(struct dso *dso, size_t *rel, size_t rel_size, size_t stride)
  9401. +{
  9402. + unsigned char *base = dso->base;
  9403. + Sym *syms = dso->syms;
  9404. + char *strings = dso->strings;
  9405. + Sym *sym;
  9406. + const char *name;
  9407. + void *ctx;
  9408. + int type;
  9409. + int sym_index;
  9410. + struct symdef def;
  9411. + size_t *reloc_addr;
  9412. + size_t sym_val;
  9413. + size_t tls_val;
  9414. + size_t addend;
  9415. + int skip_relative = 0, reuse_addends = 0, save_slot = 0;
  9416. +
  9417. + if (dso == &ldso) {
  9418. + /* Only ldso's REL table needs addend saving/reuse. */
  9419. + if (rel == apply_addends_to)
  9420. + reuse_addends = 1;
  9421. + skip_relative = 1;
  9422. + }
  9423. +
  9424. + for (; rel_size; rel+=stride, rel_size-=stride*sizeof(size_t)) {
  9425. + if (skip_relative && IS_RELATIVE(rel[1], dso->syms)) continue;
  9426. + type = R_TYPE(rel[1]);
  9427. + if (type == REL_NONE) continue;
  9428. + sym_index = R_SYM(rel[1]);
  9429. + reloc_addr = laddr(dso, rel[0]);
  9430. + if (sym_index) {
  9431. + sym = syms + sym_index;
  9432. + name = strings + sym->st_name;
  9433. + ctx = type==REL_COPY ? head->next : head;
  9434. + def = (sym->st_info&0xf) == STT_SECTION
  9435. + ? (struct symdef){ .dso = dso, .sym = sym }
  9436. + : find_sym(ctx, name, type==REL_PLT);
  9437. + if (!def.sym && (sym->st_shndx != SHN_UNDEF
  9438. + || sym->st_info>>4 != STB_WEAK)) {
  9439. + error("Error relocating %s: %s: symbol not found",
  9440. + dso->name, name);
  9441. + if (runtime) longjmp(*rtld_fail, 1);
  9442. + continue;
  9443. + }
  9444. + } else {
  9445. + sym = 0;
  9446. + def.sym = 0;
  9447. + def.dso = dso;
  9448. + }
  9449. +
  9450. + if (stride > 2) {
  9451. + addend = rel[2];
  9452. + } else if (type==REL_GOT || type==REL_PLT|| type==REL_COPY) {
  9453. + addend = 0;
  9454. + } else if (reuse_addends) {
  9455. + /* Save original addend in stage 2 where the dso
  9456. + * chain consists of just ldso; otherwise read back
  9457. + * saved addend since the inline one was clobbered. */
  9458. + if (head==&ldso)
  9459. + saved_addends[save_slot] = *reloc_addr;
  9460. + addend = saved_addends[save_slot++];
  9461. + } else {
  9462. + addend = *reloc_addr;
  9463. + }
  9464. +
  9465. + sym_val = def.sym ? (size_t)laddr(def.dso, def.sym->st_value) : 0;
  9466. + tls_val = def.sym ? def.sym->st_value : 0;
  9467. +
  9468. + switch(type) {
  9469. + case REL_NONE:
  9470. + break;
  9471. + case REL_OFFSET:
  9472. + addend -= (size_t)reloc_addr;
  9473. + case REL_SYMBOLIC:
  9474. + case REL_GOT:
  9475. + case REL_PLT:
  9476. + *reloc_addr = sym_val + addend;
  9477. + break;
  9478. + case REL_RELATIVE:
  9479. + *reloc_addr = (size_t)base + addend;
  9480. + break;
  9481. + case REL_SYM_OR_REL:
  9482. + if (sym) *reloc_addr = sym_val + addend;
  9483. + else *reloc_addr = (size_t)base + addend;
  9484. + break;
  9485. + case REL_COPY:
  9486. + memcpy(reloc_addr, (void *)sym_val, sym->st_size);
  9487. + break;
  9488. + case REL_OFFSET32:
  9489. + *(uint32_t *)reloc_addr = sym_val + addend
  9490. + - (size_t)reloc_addr;
  9491. + break;
  9492. + case REL_FUNCDESC:
  9493. + *reloc_addr = def.sym ? (size_t)(def.dso->funcdescs
  9494. + + (def.sym - def.dso->syms)) : 0;
  9495. + break;
  9496. + case REL_FUNCDESC_VAL:
  9497. + if ((sym->st_info&0xf) == STT_SECTION) *reloc_addr += sym_val;
  9498. + else *reloc_addr = sym_val;
  9499. + reloc_addr[1] = def.sym ? (size_t)def.dso->got : 0;
  9500. + break;
  9501. + case REL_DTPMOD:
  9502. + *reloc_addr = def.dso->tls_id;
  9503. + break;
  9504. + case REL_DTPOFF:
  9505. + *reloc_addr = tls_val + addend - DTP_OFFSET;
  9506. + break;
  9507. +#ifdef TLS_ABOVE_TP
  9508. + case REL_TPOFF:
  9509. + *reloc_addr = tls_val + def.dso->tls.offset + TPOFF_K + addend;
  9510. + break;
  9511. +#else
  9512. + case REL_TPOFF:
  9513. + *reloc_addr = tls_val - def.dso->tls.offset + addend;
  9514. + break;
  9515. + case REL_TPOFF_NEG:
  9516. + *reloc_addr = def.dso->tls.offset - tls_val + addend;
  9517. + break;
  9518. +#endif
  9519. + case REL_TLSDESC:
  9520. + if (stride<3) addend = reloc_addr[1];
  9521. + if (runtime && def.dso->tls_id >= static_tls_cnt) {
  9522. + struct td_index *new = malloc(sizeof *new);
  9523. + if (!new) {
  9524. + error(
  9525. + "Error relocating %s: cannot allocate TLSDESC for %s",
  9526. + dso->name, sym ? name : "(local)" );
  9527. + longjmp(*rtld_fail, 1);
  9528. + }
  9529. + new->next = dso->td_index;
  9530. + dso->td_index = new;
  9531. + new->args[0] = def.dso->tls_id;
  9532. + new->args[1] = tls_val + addend;
  9533. + reloc_addr[0] = (size_t)__tlsdesc_dynamic;
  9534. + reloc_addr[1] = (size_t)new;
  9535. + } else {
  9536. + reloc_addr[0] = (size_t)__tlsdesc_static;
  9537. +#ifdef TLS_ABOVE_TP
  9538. + reloc_addr[1] = tls_val + def.dso->tls.offset
  9539. + + TPOFF_K + addend;
  9540. +#else
  9541. + reloc_addr[1] = tls_val - def.dso->tls.offset
  9542. + + addend;
  9543. +#endif
  9544. + }
  9545. + break;
  9546. + default:
  9547. + error("Error relocating %s: unsupported relocation type %d",
  9548. + dso->name, type);
  9549. + if (runtime) longjmp(*rtld_fail, 1);
  9550. + continue;
  9551. + }
  9552. + }
  9553. +}
  9554. +
  9555. +/* A huge hack: to make up for the wastefulness of shared libraries
  9556. + * needing at least a page of dirty memory even if they have no global
  9557. + * data, we reclaim the gaps at the beginning and end of writable maps
  9558. + * and "donate" them to the heap by setting up minimal malloc
  9559. + * structures and then freeing them. */
  9560. +
  9561. +static void reclaim(struct dso *dso, size_t start, size_t end)
  9562. +{
  9563. + size_t *a, *z;
  9564. + if (start >= dso->relro_start && start < dso->relro_end) start = dso->relro_end;
  9565. + if (end >= dso->relro_start && end < dso->relro_end) end = dso->relro_start;
  9566. + start = start + 6*sizeof(size_t)-1 & -4*sizeof(size_t);
  9567. + end = (end & -4*sizeof(size_t)) - 2*sizeof(size_t);
  9568. + if (start>end || end-start < 4*sizeof(size_t)) return;
  9569. + a = laddr(dso, start);
  9570. + z = laddr(dso, end);
  9571. + a[-2] = 1;
  9572. + a[-1] = z[0] = end-start + 2*sizeof(size_t) | 1;
  9573. + z[1] = 1;
  9574. + free(a);
  9575. +}
  9576. +
  9577. +static void reclaim_gaps(struct dso *dso)
  9578. +{
  9579. + Phdr *ph = dso->phdr;
  9580. + size_t phcnt = dso->phnum;
  9581. +
  9582. + if (DL_FDPIC) return; // FIXME
  9583. + for (; phcnt--; ph=(void *)((char *)ph+dso->phentsize)) {
  9584. + if (ph->p_type!=PT_LOAD) continue;
  9585. + if ((ph->p_flags&(PF_R|PF_W))!=(PF_R|PF_W)) continue;
  9586. + reclaim(dso, ph->p_vaddr & -PAGE_SIZE, ph->p_vaddr);
  9587. + reclaim(dso, ph->p_vaddr+ph->p_memsz,
  9588. + ph->p_vaddr+ph->p_memsz+PAGE_SIZE-1 & -PAGE_SIZE);
  9589. + }
  9590. +}
  9591. +
  9592. +static void *mmap_fixed(void *p, size_t n, int prot, int flags, int fd, off_t off)
  9593. +{
  9594. + static int no_map_fixed;
  9595. + char *q;
  9596. + if (!no_map_fixed) {
  9597. + q = mmap(p, n, prot, flags|MAP_FIXED, fd, off);
  9598. + if (!DL_NOMMU_SUPPORT || q != MAP_FAILED || errno != EINVAL)
  9599. + return q;
  9600. + no_map_fixed = 1;
  9601. + }
  9602. + /* Fallbacks for MAP_FIXED failure on NOMMU kernels. */
  9603. + if (flags & MAP_ANONYMOUS) {
  9604. + memset(p, 0, n);
  9605. + return p;
  9606. + }
  9607. + ssize_t r;
  9608. + if (lseek(fd, off, SEEK_SET) < 0) return MAP_FAILED;
  9609. + for (q=p; n; q+=r, off+=r, n-=r) {
  9610. + r = read(fd, q, n);
  9611. + if (r < 0 && errno != EINTR) return MAP_FAILED;
  9612. + if (!r) {
  9613. + memset(q, 0, n);
  9614. + break;
  9615. + }
  9616. + }
  9617. + return p;
  9618. +}
  9619. +
  9620. +static void unmap_library(struct dso *dso)
  9621. +{
  9622. + if (dso->loadmap) {
  9623. + size_t i;
  9624. + for (i=0; i<dso->loadmap->nsegs; i++) {
  9625. + if (!dso->loadmap->segs[i].p_memsz)
  9626. + continue;
  9627. + munmap((void *)dso->loadmap->segs[i].addr,
  9628. + dso->loadmap->segs[i].p_memsz);
  9629. + }
  9630. + free(dso->loadmap);
  9631. + } else if (dso->map && dso->map_len) {
  9632. + munmap(dso->map, dso->map_len);
  9633. + }
  9634. +}
  9635. +
  9636. +static void *map_library(int fd, struct dso *dso)
  9637. +{
  9638. + Ehdr buf[(896+sizeof(Ehdr))/sizeof(Ehdr)];
  9639. + void *allocated_buf=0;
  9640. + size_t phsize;
  9641. + size_t addr_min=SIZE_MAX, addr_max=0, map_len;
  9642. + size_t this_min, this_max;
  9643. + size_t nsegs = 0;
  9644. + off_t off_start;
  9645. + Ehdr *eh;
  9646. + Phdr *ph, *ph0;
  9647. + unsigned prot;
  9648. + unsigned char *map=MAP_FAILED, *base;
  9649. + size_t dyn=0;
  9650. + size_t tls_image=0;
  9651. + size_t i;
  9652. +
  9653. + ssize_t l = read(fd, buf, sizeof buf);
  9654. + eh = buf;
  9655. + if (l<0) return 0;
  9656. + if (l<sizeof *eh || (eh->e_type != ET_DYN && eh->e_type != ET_EXEC))
  9657. + goto noexec;
  9658. + phsize = eh->e_phentsize * eh->e_phnum;
  9659. + if (phsize > sizeof buf - sizeof *eh) {
  9660. + allocated_buf = malloc(phsize);
  9661. + if (!allocated_buf) return 0;
  9662. + l = pread(fd, allocated_buf, phsize, eh->e_phoff);
  9663. + if (l < 0) goto error;
  9664. + if (l != phsize) goto noexec;
  9665. + ph = ph0 = allocated_buf;
  9666. + } else if (eh->e_phoff + phsize > l) {
  9667. + l = pread(fd, buf+1, phsize, eh->e_phoff);
  9668. + if (l < 0) goto error;
  9669. + if (l != phsize) goto noexec;
  9670. + ph = ph0 = (void *)(buf + 1);
  9671. + } else {
  9672. + ph = ph0 = (void *)((char *)buf + eh->e_phoff);
  9673. + }
  9674. + for (i=eh->e_phnum; i; i--, ph=(void *)((char *)ph+eh->e_phentsize)) {
  9675. + if (ph->p_type == PT_DYNAMIC) {
  9676. + dyn = ph->p_vaddr;
  9677. + } else if (ph->p_type == PT_TLS) {
  9678. + tls_image = ph->p_vaddr;
  9679. + dso->tls.align = ph->p_align;
  9680. + dso->tls.len = ph->p_filesz;
  9681. + dso->tls.size = ph->p_memsz;
  9682. + } else if (ph->p_type == PT_GNU_RELRO) {
  9683. + dso->relro_start = ph->p_vaddr & -PAGE_SIZE;
  9684. + dso->relro_end = (ph->p_vaddr + ph->p_memsz) & -PAGE_SIZE;
  9685. + }
  9686. + if (ph->p_type != PT_LOAD) continue;
  9687. + nsegs++;
  9688. + if (ph->p_vaddr < addr_min) {
  9689. + addr_min = ph->p_vaddr;
  9690. + off_start = ph->p_offset;
  9691. + prot = (((ph->p_flags&PF_R) ? PROT_READ : 0) |
  9692. + ((ph->p_flags&PF_W) ? PROT_WRITE: 0) |
  9693. + ((ph->p_flags&PF_X) ? PROT_EXEC : 0));
  9694. + }
  9695. + if (ph->p_vaddr+ph->p_memsz > addr_max) {
  9696. + addr_max = ph->p_vaddr+ph->p_memsz;
  9697. + }
  9698. + }
  9699. + if (!dyn) goto noexec;
  9700. + if (DL_FDPIC && !(eh->e_flags & FDPIC_CONSTDISP_FLAG)) {
  9701. + dso->loadmap = calloc(1, sizeof *dso->loadmap
  9702. + + nsegs * sizeof *dso->loadmap->segs);
  9703. + if (!dso->loadmap) goto error;
  9704. + dso->loadmap->nsegs = nsegs;
  9705. + for (ph=ph0, i=0; i<nsegs; ph=(void *)((char *)ph+eh->e_phentsize)) {
  9706. + if (ph->p_type != PT_LOAD) continue;
  9707. + prot = (((ph->p_flags&PF_R) ? PROT_READ : 0) |
  9708. + ((ph->p_flags&PF_W) ? PROT_WRITE: 0) |
  9709. + ((ph->p_flags&PF_X) ? PROT_EXEC : 0));
  9710. + map = mmap(0, ph->p_memsz + (ph->p_vaddr & PAGE_SIZE-1),
  9711. + prot, MAP_PRIVATE,
  9712. + fd, ph->p_offset & -PAGE_SIZE);
  9713. + if (map == MAP_FAILED) {
  9714. + unmap_library(dso);
  9715. + goto error;
  9716. + }
  9717. + dso->loadmap->segs[i].addr = (size_t)map +
  9718. + (ph->p_vaddr & PAGE_SIZE-1);
  9719. + dso->loadmap->segs[i].p_vaddr = ph->p_vaddr;
  9720. + dso->loadmap->segs[i].p_memsz = ph->p_memsz;
  9721. + i++;
  9722. + if (prot & PROT_WRITE) {
  9723. + size_t brk = (ph->p_vaddr & PAGE_SIZE-1)
  9724. + + ph->p_filesz;
  9725. + size_t pgbrk = brk + PAGE_SIZE-1 & -PAGE_SIZE;
  9726. + size_t pgend = brk + ph->p_memsz - ph->p_filesz
  9727. + + PAGE_SIZE-1 & -PAGE_SIZE;
  9728. + if (pgend > pgbrk && mmap_fixed(map+pgbrk,
  9729. + pgend-pgbrk, prot,
  9730. + MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS,
  9731. + -1, off_start) == MAP_FAILED)
  9732. + goto error;
  9733. + memset(map + brk, 0, pgbrk-brk);
  9734. + }
  9735. + }
  9736. + map = (void *)dso->loadmap->segs[0].addr;
  9737. + map_len = 0;
  9738. + goto done_mapping;
  9739. + }
  9740. + addr_max += PAGE_SIZE-1;
  9741. + addr_max &= -PAGE_SIZE;
  9742. + addr_min &= -PAGE_SIZE;
  9743. + off_start &= -PAGE_SIZE;
  9744. + map_len = addr_max - addr_min + off_start;
  9745. + /* The first time, we map too much, possibly even more than
  9746. + * the length of the file. This is okay because we will not
  9747. + * use the invalid part; we just need to reserve the right
  9748. + * amount of virtual address space to map over later. */
  9749. + map = DL_NOMMU_SUPPORT
  9750. + ? mmap((void *)addr_min, map_len, PROT_READ|PROT_WRITE|PROT_EXEC,
  9751. + MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
  9752. + : mmap((void *)addr_min, map_len, prot,
  9753. + MAP_PRIVATE, fd, off_start);
  9754. + if (map==MAP_FAILED) goto error;
  9755. + dso->map = map;
  9756. + dso->map_len = map_len;
  9757. + /* If the loaded file is not relocatable and the requested address is
  9758. + * not available, then the load operation must fail. */
  9759. + if (eh->e_type != ET_DYN && addr_min && map!=(void *)addr_min) {
  9760. + errno = EBUSY;
  9761. + goto error;
  9762. + }
  9763. + base = map - addr_min;
  9764. + dso->phdr = 0;
  9765. + dso->phnum = 0;
  9766. + for (ph=ph0, i=eh->e_phnum; i; i--, ph=(void *)((char *)ph+eh->e_phentsize)) {
  9767. + if (ph->p_type != PT_LOAD) continue;
  9768. + /* Check if the programs headers are in this load segment, and
  9769. + * if so, record the address for use by dl_iterate_phdr. */
  9770. + if (!dso->phdr && eh->e_phoff >= ph->p_offset
  9771. + && eh->e_phoff+phsize <= ph->p_offset+ph->p_filesz) {
  9772. + dso->phdr = (void *)(base + ph->p_vaddr
  9773. + + (eh->e_phoff-ph->p_offset));
  9774. + dso->phnum = eh->e_phnum;
  9775. + dso->phentsize = eh->e_phentsize;
  9776. + }
  9777. + /* Reuse the existing mapping for the lowest-address LOAD */
  9778. + if ((ph->p_vaddr & -PAGE_SIZE) == addr_min && !DL_NOMMU_SUPPORT)
  9779. + continue;
  9780. + this_min = ph->p_vaddr & -PAGE_SIZE;
  9781. + this_max = ph->p_vaddr+ph->p_memsz+PAGE_SIZE-1 & -PAGE_SIZE;
  9782. + off_start = ph->p_offset & -PAGE_SIZE;
  9783. + prot = (((ph->p_flags&PF_R) ? PROT_READ : 0) |
  9784. + ((ph->p_flags&PF_W) ? PROT_WRITE: 0) |
  9785. + ((ph->p_flags&PF_X) ? PROT_EXEC : 0));
  9786. + if (mmap_fixed(base+this_min, this_max-this_min, prot, MAP_PRIVATE|MAP_FIXED, fd, off_start) == MAP_FAILED)
  9787. + goto error;
  9788. + if (ph->p_memsz > ph->p_filesz) {
  9789. + size_t brk = (size_t)base+ph->p_vaddr+ph->p_filesz;
  9790. + size_t pgbrk = brk+PAGE_SIZE-1 & -PAGE_SIZE;
  9791. + memset((void *)brk, 0, pgbrk-brk & PAGE_SIZE-1);
  9792. + if (pgbrk-(size_t)base < this_max && mmap_fixed((void *)pgbrk, (size_t)base+this_max-pgbrk, prot, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) == MAP_FAILED)
  9793. + goto error;
  9794. + }
  9795. + }
  9796. + for (i=0; ((size_t *)(base+dyn))[i]; i+=2)
  9797. + if (((size_t *)(base+dyn))[i]==DT_TEXTREL) {
  9798. + if (mprotect(map, map_len, PROT_READ|PROT_WRITE|PROT_EXEC)
  9799. + && errno != ENOSYS)
  9800. + goto error;
  9801. + break;
  9802. + }
  9803. +done_mapping:
  9804. + dso->base = base;
  9805. + dso->dynv = laddr(dso, dyn);
  9806. + if (dso->tls.size) dso->tls.image = laddr(dso, tls_image);
  9807. + if (!runtime) reclaim_gaps(dso);
  9808. + free(allocated_buf);
  9809. + return map;
  9810. +noexec:
  9811. + errno = ENOEXEC;
  9812. +error:
  9813. + if (map!=MAP_FAILED) unmap_library(dso);
  9814. + free(allocated_buf);
  9815. + return 0;
  9816. +}
  9817. +
  9818. +static int path_open(const char *name, const char *s, char *buf, size_t buf_size)
  9819. +{
  9820. + size_t l;
  9821. + int fd;
  9822. + for (;;) {
  9823. + s += strspn(s, ":\n");
  9824. + l = strcspn(s, ":\n");
  9825. + if (l-1 >= INT_MAX) return -1;
  9826. + if (snprintf(buf, buf_size, "%.*s/%s", (int)l, s, name) < buf_size) {
  9827. + if ((fd = open(buf, O_RDONLY|O_CLOEXEC))>=0) return fd;
  9828. + switch (errno) {
  9829. + case ENOENT:
  9830. + case ENOTDIR:
  9831. + case EACCES:
  9832. + case ENAMETOOLONG:
  9833. + break;
  9834. + default:
  9835. + /* Any negative value but -1 will inhibit
  9836. + * futher path search. */
  9837. + return -2;
  9838. + }
  9839. + }
  9840. + s += l;
  9841. + }
  9842. +}
  9843. +
  9844. +static int fixup_rpath(struct dso *p, char *buf, size_t buf_size)
  9845. +{
  9846. + size_t n, l;
  9847. + const char *s, *t, *origin;
  9848. + char *d;
  9849. + if (p->rpath || !p->rpath_orig) return 0;
  9850. + if (!strchr(p->rpath_orig, '$')) {
  9851. + p->rpath = p->rpath_orig;
  9852. + return 0;
  9853. + }
  9854. + n = 0;
  9855. + s = p->rpath_orig;
  9856. + while ((t=strchr(s, '$'))) {
  9857. + if (strncmp(t, "$ORIGIN", 7) && strncmp(t, "${ORIGIN}", 9))
  9858. + return 0;
  9859. + s = t+1;
  9860. + n++;
  9861. + }
  9862. + if (n > SSIZE_MAX/PATH_MAX) return 0;
  9863. +
  9864. + if (p->kernel_mapped) {
  9865. + /* $ORIGIN searches cannot be performed for the main program
  9866. + * when it is suid/sgid/AT_SECURE. This is because the
  9867. + * pathname is under the control of the caller of execve.
  9868. + * For libraries, however, $ORIGIN can be processed safely
  9869. + * since the library's pathname came from a trusted source
  9870. + * (either system paths or a call to dlopen). */
  9871. + if (libc.secure)
  9872. + return 0;
  9873. + l = readlink("/proc/self/exe", buf, buf_size);
  9874. + if (l == -1) switch (errno) {
  9875. + case ENOENT:
  9876. + case ENOTDIR:
  9877. + case EACCES:
  9878. + break;
  9879. + default:
  9880. + return -1;
  9881. + }
  9882. + if (l >= buf_size)
  9883. + return 0;
  9884. + buf[l] = 0;
  9885. + origin = buf;
  9886. + } else {
  9887. + origin = p->name;
  9888. + }
  9889. + t = strrchr(origin, '/');
  9890. + l = t ? t-origin : 0;
  9891. + p->rpath = malloc(strlen(p->rpath_orig) + n*l + 1);
  9892. + if (!p->rpath) return -1;
  9893. +
  9894. + d = p->rpath;
  9895. + s = p->rpath_orig;
  9896. + while ((t=strchr(s, '$'))) {
  9897. + memcpy(d, s, t-s);
  9898. + d += t-s;
  9899. + memcpy(d, origin, l);
  9900. + d += l;
  9901. + /* It was determined previously that the '$' is followed
  9902. + * either by "ORIGIN" or "{ORIGIN}". */
  9903. + s = t + 7 + 2*(t[1]=='{');
  9904. + }
  9905. + strcpy(d, s);
  9906. + return 0;
  9907. +}
  9908. +
  9909. +static void decode_dyn(struct dso *p)
  9910. +{
  9911. + size_t dyn[DYN_CNT];
  9912. + decode_vec(p->dynv, dyn, DYN_CNT);
  9913. + p->syms = laddr(p, dyn[DT_SYMTAB]);
  9914. + p->strings = laddr(p, dyn[DT_STRTAB]);
  9915. + if (dyn[0]&(1<<DT_HASH))
  9916. + p->hashtab = laddr(p, dyn[DT_HASH]);
  9917. + if (dyn[0]&(1<<DT_RPATH))
  9918. + p->rpath_orig = p->strings + dyn[DT_RPATH];
  9919. + if (dyn[0]&(1<<DT_RUNPATH))
  9920. + p->rpath_orig = p->strings + dyn[DT_RUNPATH];
  9921. + if (dyn[0]&(1<<DT_PLTGOT))
  9922. + p->got = laddr(p, dyn[DT_PLTGOT]);
  9923. + if (search_vec(p->dynv, dyn, DT_GNU_HASH))
  9924. + p->ghashtab = laddr(p, *dyn);
  9925. + if (search_vec(p->dynv, dyn, DT_VERSYM))
  9926. + p->versym = laddr(p, *dyn);
  9927. +}
  9928. +
  9929. +static size_t count_syms(struct dso *p)
  9930. +{
  9931. + if (p->hashtab) return p->hashtab[1];
  9932. +
  9933. + size_t nsym, i;
  9934. + uint32_t *buckets = p->ghashtab + 4 + (p->ghashtab[2]*sizeof(size_t)/4);
  9935. + uint32_t *hashval;
  9936. + for (i = nsym = 0; i < p->ghashtab[0]; i++) {
  9937. + if (buckets[i] > nsym)
  9938. + nsym = buckets[i];
  9939. + }
  9940. + if (nsym) {
  9941. + hashval = buckets + p->ghashtab[0] + (nsym - p->ghashtab[1]);
  9942. + do nsym++;
  9943. + while (!(*hashval++ & 1));
  9944. + }
  9945. + return nsym;
  9946. +}
  9947. +
  9948. +static void *dl_mmap(size_t n)
  9949. +{
  9950. + void *p;
  9951. + int prot = PROT_READ|PROT_WRITE, flags = MAP_ANONYMOUS|MAP_PRIVATE;
  9952. +#ifdef SYS_mmap2
  9953. + p = (void *)__syscall(SYS_mmap2, 0, n, prot, flags, -1, 0);
  9954. +#else
  9955. + p = (void *)__syscall(SYS_mmap, 0, n, prot, flags, -1, 0);
  9956. +#endif
  9957. + return p == MAP_FAILED ? 0 : p;
  9958. +}
  9959. +
  9960. +static void makefuncdescs(struct dso *p)
  9961. +{
  9962. + static int self_done;
  9963. + size_t nsym = count_syms(p);
  9964. + size_t i, size = nsym * sizeof(*p->funcdescs);
  9965. +
  9966. + if (!self_done) {
  9967. + p->funcdescs = dl_mmap(size);
  9968. + self_done = 1;
  9969. + } else {
  9970. + p->funcdescs = malloc(size);
  9971. + }
  9972. + if (!p->funcdescs) {
  9973. + if (!runtime) a_crash();
  9974. + error("Error allocating function descriptors for %s", p->name);
  9975. + longjmp(*rtld_fail, 1);
  9976. + }
  9977. + for (i=0; i<nsym; i++) {
  9978. + if ((p->syms[i].st_info&0xf)==STT_FUNC && p->syms[i].st_shndx) {
  9979. + p->funcdescs[i].addr = laddr(p, p->syms[i].st_value);
  9980. + p->funcdescs[i].got = p->got;
  9981. + } else {
  9982. + p->funcdescs[i].addr = 0;
  9983. + p->funcdescs[i].got = 0;
  9984. + }
  9985. + }
  9986. +}
  9987. +
  9988. +static struct dso *load_library(const char *name, struct dso *needed_by)
  9989. +{
  9990. + char buf[2*NAME_MAX+2];
  9991. + const char *pathname;
  9992. + unsigned char *map;
  9993. + struct dso *p, temp_dso = {0};
  9994. + int fd;
  9995. + struct stat st;
  9996. + size_t alloc_size;
  9997. + int n_th = 0;
  9998. + int is_self = 0;
  9999. +
  10000. + if (!*name) {
  10001. + errno = EINVAL;
  10002. + return 0;
  10003. + }
  10004. +
  10005. + /* Catch and block attempts to reload the implementation itself */
  10006. + if (name[0]=='l' && name[1]=='i' && name[2]=='b') {
  10007. + static const char *rp, reserved[] =
  10008. + "c\0pthread\0rt\0m\0dl\0util\0xnet\0";
  10009. + char *z = strchr(name, '.');
  10010. + if (z) {
  10011. + size_t l = z-name;
  10012. + for (rp=reserved; *rp && strncmp(name+3, rp, l-3); rp+=strlen(rp)+1);
  10013. + if (*rp) {
  10014. + if (ldd_mode) {
  10015. + /* Track which names have been resolved
  10016. + * and only report each one once. */
  10017. + static unsigned reported;
  10018. + unsigned mask = 1U<<(rp-reserved);
  10019. + if (!(reported & mask)) {
  10020. + reported |= mask;
  10021. + dprintf(1, "\t%s => %s (%p)\n",
  10022. + name, ldso.name,
  10023. + ldso.base);
  10024. + }
  10025. + }
  10026. + is_self = 1;
  10027. + }
  10028. + }
  10029. + }
  10030. + if (!strcmp(name, ldso.name)) is_self = 1;
  10031. + if (is_self) {
  10032. + if (!ldso.prev) {
  10033. + tail->next = &ldso;
  10034. + ldso.prev = tail;
  10035. + tail = ldso.next ? ldso.next : &ldso;
  10036. + }
  10037. + return &ldso;
  10038. + }
  10039. + if (strchr(name, '/')) {
  10040. + pathname = name;
  10041. + fd = open(name, O_RDONLY|O_CLOEXEC);
  10042. + } else {
  10043. + /* Search for the name to see if it's already loaded */
  10044. + for (p=head->next; p; p=p->next) {
  10045. + if (p->shortname && !strcmp(p->shortname, name)) {
  10046. + p->refcnt++;
  10047. + return p;
  10048. + }
  10049. + }
  10050. + if (strlen(name) > NAME_MAX) return 0;
  10051. + fd = -1;
  10052. + if (env_path) fd = path_open(name, env_path, buf, sizeof buf);
  10053. + for (p=needed_by; fd == -1 && p; p=p->needed_by) {
  10054. + if (fixup_rpath(p, buf, sizeof buf) < 0)
  10055. + fd = -2; /* Inhibit further search. */
  10056. + if (p->rpath)
  10057. + fd = path_open(name, p->rpath, buf, sizeof buf);
  10058. + }
  10059. + if (fd == -1) {
  10060. + if (!sys_path) {
  10061. + char *prefix = 0;
  10062. + size_t prefix_len;
  10063. + if (ldso.name[0]=='/') {
  10064. + char *s, *t, *z;
  10065. + for (s=t=z=ldso.name; *s; s++)
  10066. + if (*s=='/') z=t, t=s;
  10067. + prefix_len = z-ldso.name;
  10068. + if (prefix_len < PATH_MAX)
  10069. + prefix = ldso.name;
  10070. + }
  10071. + if (!prefix) {
  10072. + prefix = "";
  10073. + prefix_len = 0;
  10074. + }
  10075. + char etc_ldso_path[prefix_len + 1
  10076. + + sizeof "/etc/ld-musl-" LDSO_ARCH ".path"];
  10077. + snprintf(etc_ldso_path, sizeof etc_ldso_path,
  10078. + "%.*s/etc/ld-musl-" LDSO_ARCH ".path",
  10079. + (int)prefix_len, prefix);
  10080. + FILE *f = fopen(etc_ldso_path, "rbe");
  10081. + if (f) {
  10082. + if (getdelim(&sys_path, (size_t[1]){0}, 0, f) <= 0) {
  10083. + free(sys_path);
  10084. + sys_path = "";
  10085. + }
  10086. + fclose(f);
  10087. + } else if (errno != ENOENT) {
  10088. + sys_path = "";
  10089. + }
  10090. + }
  10091. + if (!sys_path) sys_path = "/lib:/usr/local/lib:/usr/lib";
  10092. + fd = path_open(name, sys_path, buf, sizeof buf);
  10093. + }
  10094. + pathname = buf;
  10095. + }
  10096. + if (fd < 0) return 0;
  10097. + if (fstat(fd, &st) < 0) {
  10098. + close(fd);
  10099. + return 0;
  10100. + }
  10101. + for (p=head->next; p; p=p->next) {
  10102. + if (p->dev == st.st_dev && p->ino == st.st_ino) {
  10103. + /* If this library was previously loaded with a
  10104. + * pathname but a search found the same inode,
  10105. + * setup its shortname so it can be found by name. */
  10106. + if (!p->shortname && pathname != name)
  10107. + p->shortname = strrchr(p->name, '/')+1;
  10108. + close(fd);
  10109. + p->refcnt++;
  10110. + return p;
  10111. + }
  10112. + }
  10113. + map = noload ? 0 : map_library(fd, &temp_dso);
  10114. + close(fd);
  10115. + if (!map) return 0;
  10116. +
  10117. + /* Allocate storage for the new DSO. When there is TLS, this
  10118. + * storage must include a reservation for all pre-existing
  10119. + * threads to obtain copies of both the new TLS, and an
  10120. + * extended DTV capable of storing an additional slot for
  10121. + * the newly-loaded DSO. */
  10122. + alloc_size = sizeof *p + strlen(pathname) + 1;
  10123. + if (runtime && temp_dso.tls.image) {
  10124. + size_t per_th = temp_dso.tls.size + temp_dso.tls.align
  10125. + + sizeof(void *) * (tls_cnt+3);
  10126. + n_th = libc.threads_minus_1 + 1;
  10127. + if (n_th > SSIZE_MAX / per_th) alloc_size = SIZE_MAX;
  10128. + else alloc_size += n_th * per_th;
  10129. + }
  10130. + p = calloc(1, alloc_size);
  10131. + if (!p) {
  10132. + unmap_library(&temp_dso);
  10133. + return 0;
  10134. + }
  10135. + memcpy(p, &temp_dso, sizeof temp_dso);
  10136. + decode_dyn(p);
  10137. + p->dev = st.st_dev;
  10138. + p->ino = st.st_ino;
  10139. + p->refcnt = 1;
  10140. + p->needed_by = needed_by;
  10141. + p->name = p->buf;
  10142. + strcpy(p->name, pathname);
  10143. + /* Add a shortname only if name arg was not an explicit pathname. */
  10144. + if (pathname != name) p->shortname = strrchr(p->name, '/')+1;
  10145. + if (p->tls.image) {
  10146. + p->tls_id = ++tls_cnt;
  10147. + tls_align = MAXP2(tls_align, p->tls.align);
  10148. +#ifdef TLS_ABOVE_TP
  10149. + p->tls.offset = tls_offset + ( (tls_align-1) &
  10150. + -(tls_offset + (uintptr_t)p->tls.image) );
  10151. + tls_offset += p->tls.size;
  10152. +#else
  10153. + tls_offset += p->tls.size + p->tls.align - 1;
  10154. + tls_offset -= (tls_offset + (uintptr_t)p->tls.image)
  10155. + & (p->tls.align-1);
  10156. + p->tls.offset = tls_offset;
  10157. +#endif
  10158. + p->new_dtv = (void *)(-sizeof(size_t) &
  10159. + (uintptr_t)(p->name+strlen(p->name)+sizeof(size_t)));
  10160. + p->new_tls = (void *)(p->new_dtv + n_th*(tls_cnt+1));
  10161. + if (tls_tail) tls_tail->next = &p->tls;
  10162. + else libc.tls_head = &p->tls;
  10163. + tls_tail = &p->tls;
  10164. + }
  10165. +
  10166. + tail->next = p;
  10167. + p->prev = tail;
  10168. + tail = p;
  10169. +
  10170. + if (DL_FDPIC) makefuncdescs(p);
  10171. +
  10172. + if (ldd_mode) dprintf(1, "\t%s => %s (%p)\n", name, pathname, p->base);
  10173. +
  10174. + return p;
  10175. +}
  10176. +
  10177. +static void load_deps(struct dso *p)
  10178. +{
  10179. + size_t i, ndeps=0;
  10180. + struct dso ***deps = &p->deps, **tmp, *dep;
  10181. + for (; p; p=p->next) {
  10182. + for (i=0; p->dynv[i]; i+=2) {
  10183. + if (p->dynv[i] != DT_NEEDED) continue;
  10184. + dep = load_library(p->strings + p->dynv[i+1], p);
  10185. + if (!dep) {
  10186. + error("Error loading shared library %s: %m (needed by %s)",
  10187. + p->strings + p->dynv[i+1], p->name);
  10188. + if (runtime) longjmp(*rtld_fail, 1);
  10189. + continue;
  10190. + }
  10191. + if (runtime) {
  10192. + tmp = realloc(*deps, sizeof(*tmp)*(ndeps+2));
  10193. + if (!tmp) longjmp(*rtld_fail, 1);
  10194. + tmp[ndeps++] = dep;
  10195. + tmp[ndeps] = 0;
  10196. + *deps = tmp;
  10197. + }
  10198. + }
  10199. + }
  10200. +}
  10201. +
  10202. +static void load_preload(char *s)
  10203. +{
  10204. + int tmp;
  10205. + char *z;
  10206. + for (z=s; *z; s=z) {
  10207. + for ( ; *s && (isspace(*s) || *s==':'); s++);
  10208. + for (z=s; *z && !isspace(*z) && *z!=':'; z++);
  10209. + tmp = *z;
  10210. + *z = 0;
  10211. + load_library(s, 0);
  10212. + *z = tmp;
  10213. + }
  10214. +}
  10215. +
  10216. +static void make_global(struct dso *p)
  10217. +{
  10218. + for (; p; p=p->next) p->global = 1;
  10219. +}
  10220. +
  10221. +static void do_mips_relocs(struct dso *p, size_t *got)
  10222. +{
  10223. + size_t i, j, rel[2];
  10224. + unsigned char *base = p->base;
  10225. + i=0; search_vec(p->dynv, &i, DT_MIPS_LOCAL_GOTNO);
  10226. + if (p==&ldso) {
  10227. + got += i;
  10228. + } else {
  10229. + while (i--) *got++ += (size_t)base;
  10230. + }
  10231. + j=0; search_vec(p->dynv, &j, DT_MIPS_GOTSYM);
  10232. + i=0; search_vec(p->dynv, &i, DT_MIPS_SYMTABNO);
  10233. + Sym *sym = p->syms + j;
  10234. + rel[0] = (unsigned char *)got - base;
  10235. + for (i-=j; i; i--, sym++, rel[0]+=sizeof(size_t)) {
  10236. + rel[1] = sym-p->syms << 8 | R_MIPS_JUMP_SLOT;
  10237. + do_relocs(p, rel, sizeof rel, 2);
  10238. + }
  10239. +}
  10240. +
  10241. +static void reloc_all(struct dso *p)
  10242. +{
  10243. + size_t dyn[DYN_CNT];
  10244. + for (; p; p=p->next) {
  10245. + if (p->relocated) continue;
  10246. + decode_vec(p->dynv, dyn, DYN_CNT);
  10247. + if (NEED_MIPS_GOT_RELOCS)
  10248. + do_mips_relocs(p, laddr(p, dyn[DT_PLTGOT]));
  10249. + do_relocs(p, laddr(p, dyn[DT_JMPREL]), dyn[DT_PLTRELSZ],
  10250. + 2+(dyn[DT_PLTREL]==DT_RELA));
  10251. + do_relocs(p, laddr(p, dyn[DT_REL]), dyn[DT_RELSZ], 2);
  10252. + do_relocs(p, laddr(p, dyn[DT_RELA]), dyn[DT_RELASZ], 3);
  10253. +
  10254. + if (head != &ldso && p->relro_start != p->relro_end &&
  10255. + mprotect(laddr(p, p->relro_start), p->relro_end-p->relro_start, PROT_READ)
  10256. + && errno != ENOSYS) {
  10257. + error("Error relocating %s: RELRO protection failed: %m",
  10258. + p->name);
  10259. + if (runtime) longjmp(*rtld_fail, 1);
  10260. + }
  10261. +
  10262. + p->relocated = 1;
  10263. + }
  10264. +}
  10265. +
  10266. +static void kernel_mapped_dso(struct dso *p)
  10267. +{
  10268. + size_t min_addr = -1, max_addr = 0, cnt;
  10269. + Phdr *ph = p->phdr;
  10270. + for (cnt = p->phnum; cnt--; ph = (void *)((char *)ph + p->phentsize)) {
  10271. + if (ph->p_type == PT_DYNAMIC) {
  10272. + p->dynv = laddr(p, ph->p_vaddr);
  10273. + } else if (ph->p_type == PT_GNU_RELRO) {
  10274. + p->relro_start = ph->p_vaddr & -PAGE_SIZE;
  10275. + p->relro_end = (ph->p_vaddr + ph->p_memsz) & -PAGE_SIZE;
  10276. + }
  10277. + if (ph->p_type != PT_LOAD) continue;
  10278. + if (ph->p_vaddr < min_addr)
  10279. + min_addr = ph->p_vaddr;
  10280. + if (ph->p_vaddr+ph->p_memsz > max_addr)
  10281. + max_addr = ph->p_vaddr+ph->p_memsz;
  10282. + }
  10283. + min_addr &= -PAGE_SIZE;
  10284. + max_addr = (max_addr + PAGE_SIZE-1) & -PAGE_SIZE;
  10285. + p->map = p->base + min_addr;
  10286. + p->map_len = max_addr - min_addr;
  10287. + p->kernel_mapped = 1;
  10288. +}
  10289. +
  10290. +void __libc_exit_fini()
  10291. +{
  10292. + struct dso *p;
  10293. + size_t dyn[DYN_CNT];
  10294. + for (p=fini_head; p; p=p->fini_next) {
  10295. + if (!p->constructed) continue;
  10296. + decode_vec(p->dynv, dyn, DYN_CNT);
  10297. + if (dyn[0] & (1<<DT_FINI_ARRAY)) {
  10298. + size_t n = dyn[DT_FINI_ARRAYSZ]/sizeof(size_t);
  10299. + size_t *fn = (size_t *)laddr(p, dyn[DT_FINI_ARRAY])+n;
  10300. + while (n--) ((void (*)(void))*--fn)();
  10301. + }
  10302. +#ifndef NO_LEGACY_INITFINI
  10303. + if ((dyn[0] & (1<<DT_FINI)) && dyn[DT_FINI])
  10304. + fpaddr(p, dyn[DT_FINI])();
  10305. +#endif
  10306. + }
  10307. +}
  10308. +
  10309. +static void do_init_fini(struct dso *p)
  10310. +{
  10311. + size_t dyn[DYN_CNT];
  10312. + int need_locking = libc.threads_minus_1;
  10313. + /* Allow recursive calls that arise when a library calls
  10314. + * dlopen from one of its constructors, but block any
  10315. + * other threads until all ctors have finished. */
  10316. + if (need_locking) pthread_mutex_lock(&init_fini_lock);
  10317. + for (; p; p=p->prev) {
  10318. + if (p->constructed) continue;
  10319. + p->constructed = 1;
  10320. + decode_vec(p->dynv, dyn, DYN_CNT);
  10321. + if (dyn[0] & ((1<<DT_FINI) | (1<<DT_FINI_ARRAY))) {
  10322. + p->fini_next = fini_head;
  10323. + fini_head = p;
  10324. + }
  10325. +#ifndef NO_LEGACY_INITFINI
  10326. + if ((dyn[0] & (1<<DT_INIT)) && dyn[DT_INIT])
  10327. + fpaddr(p, dyn[DT_INIT])();
  10328. +#endif
  10329. + if (dyn[0] & (1<<DT_INIT_ARRAY)) {
  10330. + size_t n = dyn[DT_INIT_ARRAYSZ]/sizeof(size_t);
  10331. + size_t *fn = laddr(p, dyn[DT_INIT_ARRAY]);
  10332. + while (n--) ((void (*)(void))*fn++)();
  10333. + }
  10334. + if (!need_locking && libc.threads_minus_1) {
  10335. + need_locking = 1;
  10336. + pthread_mutex_lock(&init_fini_lock);
  10337. + }
  10338. + }
  10339. + if (need_locking) pthread_mutex_unlock(&init_fini_lock);
  10340. +}
  10341. +
  10342. +void __libc_start_init(void)
  10343. +{
  10344. + do_init_fini(tail);
  10345. +}
  10346. +
  10347. +static void dl_debug_state(void)
  10348. +{
  10349. +}
  10350. +
  10351. +weak_alias(dl_debug_state, _dl_debug_state);
  10352. +
  10353. +void __init_tls(size_t *auxv)
  10354. +{
  10355. +}
  10356. +
  10357. +__attribute__((__visibility__("hidden")))
  10358. +void *__tls_get_new(size_t *v)
  10359. +{
  10360. + pthread_t self = __pthread_self();
  10361. +
  10362. + /* Block signals to make accessing new TLS async-signal-safe */
  10363. + sigset_t set;
  10364. + __block_all_sigs(&set);
  10365. + if (v[0]<=(size_t)self->dtv[0]) {
  10366. + __restore_sigs(&set);
  10367. + return (char *)self->dtv[v[0]]+v[1]+DTP_OFFSET;
  10368. + }
  10369. +
  10370. + /* This is safe without any locks held because, if the caller
  10371. + * is able to request the Nth entry of the DTV, the DSO list
  10372. + * must be valid at least that far out and it was synchronized
  10373. + * at program startup or by an already-completed call to dlopen. */
  10374. + struct dso *p;
  10375. + for (p=head; p->tls_id != v[0]; p=p->next);
  10376. +
  10377. + /* Get new DTV space from new DSO if needed */
  10378. + if (v[0] > (size_t)self->dtv[0]) {
  10379. + void **newdtv = p->new_dtv +
  10380. + (v[0]+1)*a_fetch_add(&p->new_dtv_idx,1);
  10381. + memcpy(newdtv, self->dtv,
  10382. + ((size_t)self->dtv[0]+1) * sizeof(void *));
  10383. + newdtv[0] = (void *)v[0];
  10384. + self->dtv = self->dtv_copy = newdtv;
  10385. + }
  10386. +
  10387. + /* Get new TLS memory from all new DSOs up to the requested one */
  10388. + unsigned char *mem;
  10389. + for (p=head; ; p=p->next) {
  10390. + if (!p->tls_id || self->dtv[p->tls_id]) continue;
  10391. + mem = p->new_tls + (p->tls.size + p->tls.align)
  10392. + * a_fetch_add(&p->new_tls_idx,1);
  10393. + mem += ((uintptr_t)p->tls.image - (uintptr_t)mem)
  10394. + & (p->tls.align-1);
  10395. + self->dtv[p->tls_id] = mem;
  10396. + memcpy(mem, p->tls.image, p->tls.len);
  10397. + if (p->tls_id == v[0]) break;
  10398. + }
  10399. + __restore_sigs(&set);
  10400. + return mem + v[1] + DTP_OFFSET;
  10401. +}
  10402. +
  10403. +static void update_tls_size()
  10404. +{
  10405. + libc.tls_cnt = tls_cnt;
  10406. + libc.tls_align = tls_align;
  10407. + libc.tls_size = ALIGN(
  10408. + (1+tls_cnt) * sizeof(void *) +
  10409. + tls_offset +
  10410. + sizeof(struct pthread) +
  10411. + tls_align * 2,
  10412. + tls_align);
  10413. +}
  10414. +
  10415. +/* Stage 1 of the dynamic linker is defined in dlstart.c. It calls the
  10416. + * following stage 2 and stage 3 functions via primitive symbolic lookup
  10417. + * since it does not have access to their addresses to begin with. */
  10418. +
  10419. +/* Stage 2 of the dynamic linker is called after relative relocations
  10420. + * have been processed. It can make function calls to static functions
  10421. + * and access string literals and static data, but cannot use extern
  10422. + * symbols. Its job is to perform symbolic relocations on the dynamic
  10423. + * linker itself, but some of the relocations performed may need to be
  10424. + * replaced later due to copy relocations in the main program. */
  10425. +
  10426. +__attribute__((__visibility__("hidden")))
  10427. +void __dls2(unsigned char *base, size_t *sp)
  10428. +{
  10429. + if (DL_FDPIC) {
  10430. + void *p1 = (void *)sp[-2];
  10431. + void *p2 = (void *)sp[-1];
  10432. + if (!p1) {
  10433. + size_t *auxv, aux[AUX_CNT];
  10434. + for (auxv=sp+1+*sp+1; *auxv; auxv++); auxv++;
  10435. + decode_vec(auxv, aux, AUX_CNT);
  10436. + if (aux[AT_BASE]) ldso.base = (void *)aux[AT_BASE];
  10437. + else ldso.base = (void *)(aux[AT_PHDR] & -4096);
  10438. + }
  10439. + app_loadmap = p2 ? p1 : 0;
  10440. + ldso.loadmap = p2 ? p2 : p1;
  10441. + ldso.base = laddr(&ldso, 0);
  10442. + } else {
  10443. + ldso.base = base;
  10444. + }
  10445. + Ehdr *ehdr = (void *)ldso.base;
  10446. + ldso.name = ldso.shortname = "libc.so";
  10447. + ldso.global = 1;
  10448. + ldso.phnum = ehdr->e_phnum;
  10449. + ldso.phdr = laddr(&ldso, ehdr->e_phoff);
  10450. + ldso.phentsize = ehdr->e_phentsize;
  10451. + kernel_mapped_dso(&ldso);
  10452. + decode_dyn(&ldso);
  10453. +
  10454. + if (DL_FDPIC) makefuncdescs(&ldso);
  10455. +
  10456. + /* Prepare storage for to save clobbered REL addends so they
  10457. + * can be reused in stage 3. There should be very few. If
  10458. + * something goes wrong and there are a huge number, abort
  10459. + * instead of risking stack overflow. */
  10460. + size_t dyn[DYN_CNT];
  10461. + decode_vec(ldso.dynv, dyn, DYN_CNT);
  10462. + size_t *rel = laddr(&ldso, dyn[DT_REL]);
  10463. + size_t rel_size = dyn[DT_RELSZ];
  10464. + size_t symbolic_rel_cnt = 0;
  10465. + apply_addends_to = rel;
  10466. + for (; rel_size; rel+=2, rel_size-=2*sizeof(size_t))
  10467. + if (!IS_RELATIVE(rel[1], ldso.syms)) symbolic_rel_cnt++;
  10468. + if (symbolic_rel_cnt >= ADDEND_LIMIT) a_crash();
  10469. + size_t addends[symbolic_rel_cnt+1];
  10470. + saved_addends = addends;
  10471. +
  10472. + head = &ldso;
  10473. + reloc_all(&ldso);
  10474. +
  10475. + ldso.relocated = 0;
  10476. +
  10477. + /* Call dynamic linker stage-3, __dls3, looking it up
  10478. + * symbolically as a barrier against moving the address
  10479. + * load across the above relocation processing. */
  10480. + struct symdef dls3_def = find_sym(&ldso, "__dls3", 0);
  10481. + if (DL_FDPIC) ((stage3_func)&ldso.funcdescs[dls3_def.sym-ldso.syms])(sp);
  10482. + else ((stage3_func)laddr(&ldso, dls3_def.sym->st_value))(sp);
  10483. +}
  10484. +
  10485. +/* Stage 3 of the dynamic linker is called with the dynamic linker/libc
  10486. + * fully functional. Its job is to load (if not already loaded) and
  10487. + * process dependencies and relocations for the main application and
  10488. + * transfer control to its entry point. */
  10489. +
  10490. +_Noreturn void __dls3(size_t *sp)
  10491. +{
  10492. + static struct dso app, vdso;
  10493. + size_t aux[AUX_CNT], *auxv;
  10494. + size_t i;
  10495. + char *env_preload=0;
  10496. + size_t vdso_base;
  10497. + int argc = *sp;
  10498. + char **argv = (void *)(sp+1);
  10499. + char **argv_orig = argv;
  10500. + char **envp = argv+argc+1;
  10501. +
  10502. + /* Find aux vector just past environ[] and use it to initialize
  10503. + * global data that may be needed before we can make syscalls. */
  10504. + __environ = envp;
  10505. + for (i=argc+1; argv[i]; i++);
  10506. + libc.auxv = auxv = (void *)(argv+i+1);
  10507. + decode_vec(auxv, aux, AUX_CNT);
  10508. + __hwcap = aux[AT_HWCAP];
  10509. + libc.page_size = aux[AT_PAGESZ];
  10510. + libc.secure = ((aux[0]&0x7800)!=0x7800 || aux[AT_UID]!=aux[AT_EUID]
  10511. + || aux[AT_GID]!=aux[AT_EGID] || aux[AT_SECURE]);
  10512. +
  10513. + /* Setup early thread pointer in builtin_tls for ldso/libc itself to
  10514. + * use during dynamic linking. If possible it will also serve as the
  10515. + * thread pointer at runtime. */
  10516. + libc.tls_size = sizeof builtin_tls;
  10517. + libc.tls_align = tls_align;
  10518. + if (__init_tp(__copy_tls((void *)builtin_tls)) < 0) {
  10519. + a_crash();
  10520. + }
  10521. +
  10522. + /* Only trust user/env if kernel says we're not suid/sgid */
  10523. + if (!libc.secure) {
  10524. + env_path = getenv("LD_LIBRARY_PATH");
  10525. + env_preload = getenv("LD_PRELOAD");
  10526. + }
  10527. +
  10528. + /* If the main program was already loaded by the kernel,
  10529. + * AT_PHDR will point to some location other than the dynamic
  10530. + * linker's program headers. */
  10531. + if (aux[AT_PHDR] != (size_t)ldso.phdr) {
  10532. + size_t interp_off = 0;
  10533. + size_t tls_image = 0;
  10534. + /* Find load address of the main program, via AT_PHDR vs PT_PHDR. */
  10535. + Phdr *phdr = app.phdr = (void *)aux[AT_PHDR];
  10536. + app.phnum = aux[AT_PHNUM];
  10537. + app.phentsize = aux[AT_PHENT];
  10538. + for (i=aux[AT_PHNUM]; i; i--, phdr=(void *)((char *)phdr + aux[AT_PHENT])) {
  10539. + if (phdr->p_type == PT_PHDR)
  10540. + app.base = (void *)(aux[AT_PHDR] - phdr->p_vaddr);
  10541. + else if (phdr->p_type == PT_INTERP)
  10542. + interp_off = (size_t)phdr->p_vaddr;
  10543. + else if (phdr->p_type == PT_TLS) {
  10544. + tls_image = phdr->p_vaddr;
  10545. + app.tls.len = phdr->p_filesz;
  10546. + app.tls.size = phdr->p_memsz;
  10547. + app.tls.align = phdr->p_align;
  10548. + }
  10549. + }
  10550. + if (DL_FDPIC) app.loadmap = app_loadmap;
  10551. + if (app.tls.size) app.tls.image = laddr(&app, tls_image);
  10552. + if (interp_off) ldso.name = laddr(&app, interp_off);
  10553. + if ((aux[0] & (1UL<<AT_EXECFN))
  10554. + && strncmp((char *)aux[AT_EXECFN], "/proc/", 6))
  10555. + app.name = (char *)aux[AT_EXECFN];
  10556. + else
  10557. + app.name = argv[0];
  10558. + kernel_mapped_dso(&app);
  10559. + } else {
  10560. + int fd;
  10561. + char *ldname = argv[0];
  10562. + size_t l = strlen(ldname);
  10563. + if (l >= 3 && !strcmp(ldname+l-3, "ldd")) ldd_mode = 1;
  10564. + argv++;
  10565. + while (argv[0] && argv[0][0]=='-' && argv[0][1]=='-') {
  10566. + char *opt = argv[0]+2;
  10567. + *argv++ = (void *)-1;
  10568. + if (!*opt) {
  10569. + break;
  10570. + } else if (!memcmp(opt, "list", 5)) {
  10571. + ldd_mode = 1;
  10572. + } else if (!memcmp(opt, "library-path", 12)) {
  10573. + if (opt[12]=='=') env_path = opt+13;
  10574. + else if (opt[12]) *argv = 0;
  10575. + else if (*argv) env_path = *argv++;
  10576. + } else if (!memcmp(opt, "preload", 7)) {
  10577. + if (opt[7]=='=') env_preload = opt+8;
  10578. + else if (opt[7]) *argv = 0;
  10579. + else if (*argv) env_preload = *argv++;
  10580. + } else {
  10581. + argv[0] = 0;
  10582. + }
  10583. + }
  10584. + argv[-1] = (void *)(argc - (argv-argv_orig));
  10585. + if (!argv[0]) {
  10586. + dprintf(2, "musl libc (" LDSO_ARCH ")\n"
  10587. + "Version %s\n"
  10588. + "Dynamic Program Loader\n"
  10589. + "Usage: %s [options] [--] pathname%s\n",
  10590. + __libc_get_version(), ldname,
  10591. + ldd_mode ? "" : " [args]");
  10592. + _exit(1);
  10593. + }
  10594. + fd = open(argv[0], O_RDONLY);
  10595. + if (fd < 0) {
  10596. + dprintf(2, "%s: cannot load %s: %s\n", ldname, argv[0], strerror(errno));
  10597. + _exit(1);
  10598. + }
  10599. + runtime = 1;
  10600. + Ehdr *ehdr = (void *)map_library(fd, &app);
  10601. + if (!ehdr) {
  10602. + dprintf(2, "%s: %s: Not a valid dynamic program\n", ldname, argv[0]);
  10603. + _exit(1);
  10604. + }
  10605. + runtime = 0;
  10606. + close(fd);
  10607. + ldso.name = ldname;
  10608. + app.name = argv[0];
  10609. + aux[AT_ENTRY] = (size_t)laddr(&app, ehdr->e_entry);
  10610. + /* Find the name that would have been used for the dynamic
  10611. + * linker had ldd not taken its place. */
  10612. + if (ldd_mode) {
  10613. + for (i=0; i<app.phnum; i++) {
  10614. + if (app.phdr[i].p_type == PT_INTERP)
  10615. + ldso.name = laddr(&app, app.phdr[i].p_vaddr);
  10616. + }
  10617. + dprintf(1, "\t%s (%p)\n", ldso.name, ldso.base);
  10618. + }
  10619. + }
  10620. + if (app.tls.size) {
  10621. + libc.tls_head = tls_tail = &app.tls;
  10622. + app.tls_id = tls_cnt = 1;
  10623. +#ifdef TLS_ABOVE_TP
  10624. + app.tls.offset = 0;
  10625. + tls_offset = app.tls.size
  10626. + + ( -((uintptr_t)app.tls.image + app.tls.size)
  10627. + & (app.tls.align-1) );
  10628. +#else
  10629. + tls_offset = app.tls.offset = app.tls.size
  10630. + + ( -((uintptr_t)app.tls.image + app.tls.size)
  10631. + & (app.tls.align-1) );
  10632. +#endif
  10633. + tls_align = MAXP2(tls_align, app.tls.align);
  10634. + }
  10635. + app.global = 1;
  10636. + decode_dyn(&app);
  10637. + if (DL_FDPIC) {
  10638. + makefuncdescs(&app);
  10639. + if (!app.loadmap) {
  10640. + app.loadmap = (void *)&app_dummy_loadmap;
  10641. + app.loadmap->nsegs = 1;
  10642. + app.loadmap->segs[0].addr = (size_t)app.map;
  10643. + app.loadmap->segs[0].p_vaddr = (size_t)app.map
  10644. + - (size_t)app.base;
  10645. + app.loadmap->segs[0].p_memsz = app.map_len;
  10646. + }
  10647. + argv[-3] = (void *)app.loadmap;
  10648. + }
  10649. +
  10650. + /* Attach to vdso, if provided by the kernel */
  10651. + if (search_vec(auxv, &vdso_base, AT_SYSINFO_EHDR)) {
  10652. + Ehdr *ehdr = (void *)vdso_base;
  10653. + Phdr *phdr = vdso.phdr = (void *)(vdso_base + ehdr->e_phoff);
  10654. + vdso.phnum = ehdr->e_phnum;
  10655. + vdso.phentsize = ehdr->e_phentsize;
  10656. + for (i=ehdr->e_phnum; i; i--, phdr=(void *)((char *)phdr + ehdr->e_phentsize)) {
  10657. + if (phdr->p_type == PT_DYNAMIC)
  10658. + vdso.dynv = (void *)(vdso_base + phdr->p_offset);
  10659. + if (phdr->p_type == PT_LOAD)
  10660. + vdso.base = (void *)(vdso_base - phdr->p_vaddr + phdr->p_offset);
  10661. + }
  10662. + vdso.name = "";
  10663. + vdso.shortname = "linux-gate.so.1";
  10664. + vdso.global = 1;
  10665. + vdso.relocated = 1;
  10666. + decode_dyn(&vdso);
  10667. + vdso.prev = &ldso;
  10668. + ldso.next = &vdso;
  10669. + }
  10670. +
  10671. + /* Initial dso chain consists only of the app. */
  10672. + head = tail = &app;
  10673. +
  10674. + /* Donate unused parts of app and library mapping to malloc */
  10675. + reclaim_gaps(&app);
  10676. + reclaim_gaps(&ldso);
  10677. +
  10678. + /* Load preload/needed libraries, add their symbols to the global
  10679. + * namespace, and perform all remaining relocations. */
  10680. + if (env_preload) load_preload(env_preload);
  10681. + load_deps(&app);
  10682. + make_global(&app);
  10683. +
  10684. +#ifndef DYNAMIC_IS_RO
  10685. + for (i=0; app.dynv[i]; i+=2)
  10686. + if (app.dynv[i]==DT_DEBUG)
  10687. + app.dynv[i+1] = (size_t)&debug;
  10688. +#endif
  10689. +
  10690. + /* The main program must be relocated LAST since it may contin
  10691. + * copy relocations which depend on libraries' relocations. */
  10692. + reloc_all(app.next);
  10693. + reloc_all(&app);
  10694. +
  10695. + update_tls_size();
  10696. + if (libc.tls_size > sizeof builtin_tls || tls_align > MIN_TLS_ALIGN) {
  10697. + void *initial_tls = calloc(libc.tls_size, 1);
  10698. + if (!initial_tls) {
  10699. + dprintf(2, "%s: Error getting %zu bytes thread-local storage: %m\n",
  10700. + argv[0], libc.tls_size);
  10701. + _exit(127);
  10702. + }
  10703. + if (__init_tp(__copy_tls(initial_tls)) < 0) {
  10704. + a_crash();
  10705. + }
  10706. + } else {
  10707. + size_t tmp_tls_size = libc.tls_size;
  10708. + pthread_t self = __pthread_self();
  10709. + /* Temporarily set the tls size to the full size of
  10710. + * builtin_tls so that __copy_tls will use the same layout
  10711. + * as it did for before. Then check, just to be safe. */
  10712. + libc.tls_size = sizeof builtin_tls;
  10713. + if (__copy_tls((void*)builtin_tls) != self) a_crash();
  10714. + libc.tls_size = tmp_tls_size;
  10715. + }
  10716. + static_tls_cnt = tls_cnt;
  10717. +
  10718. + if (ldso_fail) _exit(127);
  10719. + if (ldd_mode) _exit(0);
  10720. +
  10721. + /* Switch to runtime mode: any further failures in the dynamic
  10722. + * linker are a reportable failure rather than a fatal startup
  10723. + * error. */
  10724. + runtime = 1;
  10725. +
  10726. + debug.ver = 1;
  10727. + debug.bp = dl_debug_state;
  10728. + debug.head = head;
  10729. + debug.base = ldso.base;
  10730. + debug.state = 0;
  10731. + _dl_debug_state();
  10732. +
  10733. + errno = 0;
  10734. +
  10735. + CRTJMP((void *)aux[AT_ENTRY], argv-1);
  10736. + for(;;);
  10737. +}
  10738. +
  10739. +void *dlopen(const char *file, int mode)
  10740. +{
  10741. + struct dso *volatile p, *orig_tail, *next;
  10742. + struct tls_module *orig_tls_tail;
  10743. + size_t orig_tls_cnt, orig_tls_offset, orig_tls_align;
  10744. + size_t i;
  10745. + int cs;
  10746. + jmp_buf jb;
  10747. +
  10748. + if (!file) return head;
  10749. +
  10750. + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
  10751. + pthread_rwlock_wrlock(&lock);
  10752. + __inhibit_ptc();
  10753. +
  10754. + p = 0;
  10755. + orig_tls_tail = tls_tail;
  10756. + orig_tls_cnt = tls_cnt;
  10757. + orig_tls_offset = tls_offset;
  10758. + orig_tls_align = tls_align;
  10759. + orig_tail = tail;
  10760. + noload = mode & RTLD_NOLOAD;
  10761. +
  10762. + rtld_fail = &jb;
  10763. + if (setjmp(*rtld_fail)) {
  10764. + /* Clean up anything new that was (partially) loaded */
  10765. + if (p && p->deps) for (i=0; p->deps[i]; i++)
  10766. + if (p->deps[i]->global < 0)
  10767. + p->deps[i]->global = 0;
  10768. + for (p=orig_tail->next; p; p=next) {
  10769. + next = p->next;
  10770. + while (p->td_index) {
  10771. + void *tmp = p->td_index->next;
  10772. + free(p->td_index);
  10773. + p->td_index = tmp;
  10774. + }
  10775. + free(p->funcdescs);
  10776. + if (p->rpath != p->rpath_orig)
  10777. + free(p->rpath);
  10778. + free(p->deps);
  10779. + unmap_library(p);
  10780. + free(p);
  10781. + }
  10782. + if (!orig_tls_tail) libc.tls_head = 0;
  10783. + tls_tail = orig_tls_tail;
  10784. + tls_cnt = orig_tls_cnt;
  10785. + tls_offset = orig_tls_offset;
  10786. + tls_align = orig_tls_align;
  10787. + tail = orig_tail;
  10788. + tail->next = 0;
  10789. + p = 0;
  10790. + goto end;
  10791. + } else p = load_library(file, head);
  10792. +
  10793. + if (!p) {
  10794. + error(noload ?
  10795. + "Library %s is not already loaded" :
  10796. + "Error loading shared library %s: %m",
  10797. + file);
  10798. + goto end;
  10799. + }
  10800. +
  10801. + /* First load handling */
  10802. + if (!p->deps) {
  10803. + load_deps(p);
  10804. + if (p->deps) for (i=0; p->deps[i]; i++)
  10805. + if (!p->deps[i]->global)
  10806. + p->deps[i]->global = -1;
  10807. + if (!p->global) p->global = -1;
  10808. + reloc_all(p);
  10809. + if (p->deps) for (i=0; p->deps[i]; i++)
  10810. + if (p->deps[i]->global < 0)
  10811. + p->deps[i]->global = 0;
  10812. + if (p->global < 0) p->global = 0;
  10813. + }
  10814. +
  10815. + if (mode & RTLD_GLOBAL) {
  10816. + if (p->deps) for (i=0; p->deps[i]; i++)
  10817. + p->deps[i]->global = 1;
  10818. + p->global = 1;
  10819. + }
  10820. +
  10821. + update_tls_size();
  10822. + _dl_debug_state();
  10823. + orig_tail = tail;
  10824. +end:
  10825. + __release_ptc();
  10826. + if (p) gencnt++;
  10827. + pthread_rwlock_unlock(&lock);
  10828. + if (p) do_init_fini(orig_tail);
  10829. + pthread_setcancelstate(cs, 0);
  10830. + return p;
  10831. +}
  10832. +
  10833. +__attribute__((__visibility__("hidden")))
  10834. +int __dl_invalid_handle(void *h)
  10835. +{
  10836. + struct dso *p;
  10837. + for (p=head; p; p=p->next) if (h==p) return 0;
  10838. + error("Invalid library handle %p", (void *)h);
  10839. + return 1;
  10840. +}
  10841. +
  10842. +static void *addr2dso(size_t a)
  10843. +{
  10844. + struct dso *p;
  10845. + size_t i;
  10846. + if (DL_FDPIC) for (p=head; p; p=p->next) {
  10847. + i = count_syms(p);
  10848. + if (a-(size_t)p->funcdescs < i*sizeof(*p->funcdescs))
  10849. + return p;
  10850. + }
  10851. + for (p=head; p; p=p->next) {
  10852. + if (DL_FDPIC && p->loadmap) {
  10853. + for (i=0; i<p->loadmap->nsegs; i++) {
  10854. + if (a-p->loadmap->segs[i].p_vaddr
  10855. + < p->loadmap->segs[i].p_memsz)
  10856. + return p;
  10857. + }
  10858. + } else {
  10859. + if (a-(size_t)p->map < p->map_len)
  10860. + return p;
  10861. + }
  10862. + }
  10863. + return 0;
  10864. +}
  10865. +
  10866. +void *__tls_get_addr(size_t *);
  10867. +
  10868. +static void *do_dlsym(struct dso *p, const char *s, void *ra)
  10869. +{
  10870. + size_t i;
  10871. + uint32_t h = 0, gh = 0, *ght;
  10872. + Sym *sym;
  10873. + if (p == head || p == RTLD_DEFAULT || p == RTLD_NEXT) {
  10874. + if (p == RTLD_DEFAULT) {
  10875. + p = head;
  10876. + } else if (p == RTLD_NEXT) {
  10877. + p = addr2dso((size_t)ra);
  10878. + if (!p) p=head;
  10879. + p = p->next;
  10880. + }
  10881. + struct symdef def = find_sym(p, s, 0);
  10882. + if (!def.sym) goto failed;
  10883. + if ((def.sym->st_info&0xf) == STT_TLS)
  10884. + return __tls_get_addr((size_t []){def.dso->tls_id, def.sym->st_value});
  10885. + if (DL_FDPIC && (def.sym->st_info&0xf) == STT_FUNC)
  10886. + return def.dso->funcdescs + (def.sym - def.dso->syms);
  10887. + return laddr(def.dso, def.sym->st_value);
  10888. + }
  10889. + if (__dl_invalid_handle(p))
  10890. + return 0;
  10891. + if ((ght = p->ghashtab)) {
  10892. + gh = gnu_hash(s);
  10893. + sym = gnu_lookup(gh, ght, p, s);
  10894. + } else {
  10895. + h = sysv_hash(s);
  10896. + sym = sysv_lookup(s, h, p);
  10897. + }
  10898. + if (sym && (sym->st_info&0xf) == STT_TLS)
  10899. + return __tls_get_addr((size_t []){p->tls_id, sym->st_value});
  10900. + if (DL_FDPIC && sym && sym->st_shndx && (sym->st_info&0xf) == STT_FUNC)
  10901. + return p->funcdescs + (sym - p->syms);
  10902. + if (sym && sym->st_value && (1<<(sym->st_info&0xf) & OK_TYPES))
  10903. + return laddr(p, sym->st_value);
  10904. + if (p->deps) for (i=0; p->deps[i]; i++) {
  10905. + if ((ght = p->deps[i]->ghashtab)) {
  10906. + if (!gh) gh = gnu_hash(s);
  10907. + sym = gnu_lookup(gh, ght, p->deps[i], s);
  10908. + } else {
  10909. + if (!h) h = sysv_hash(s);
  10910. + sym = sysv_lookup(s, h, p->deps[i]);
  10911. + }
  10912. + if (sym && (sym->st_info&0xf) == STT_TLS)
  10913. + return __tls_get_addr((size_t []){p->deps[i]->tls_id, sym->st_value});
  10914. + if (DL_FDPIC && sym && sym->st_shndx && (sym->st_info&0xf) == STT_FUNC)
  10915. + return p->deps[i]->funcdescs + (sym - p->deps[i]->syms);
  10916. + if (sym && sym->st_value && (1<<(sym->st_info&0xf) & OK_TYPES))
  10917. + return laddr(p->deps[i], sym->st_value);
  10918. + }
  10919. +failed:
  10920. + error("Symbol not found: %s", s);
  10921. + return 0;
  10922. +}
  10923. +
  10924. +int dladdr(const void *addr, Dl_info *info)
  10925. +{
  10926. + struct dso *p;
  10927. + Sym *sym, *bestsym;
  10928. + uint32_t nsym;
  10929. + char *strings;
  10930. + void *best = 0;
  10931. +
  10932. + pthread_rwlock_rdlock(&lock);
  10933. + p = addr2dso((size_t)addr);
  10934. + pthread_rwlock_unlock(&lock);
  10935. +
  10936. + if (!p) return 0;
  10937. +
  10938. + sym = p->syms;
  10939. + strings = p->strings;
  10940. + nsym = count_syms(p);
  10941. +
  10942. + if (DL_FDPIC) {
  10943. + size_t idx = ((size_t)addr-(size_t)p->funcdescs)
  10944. + / sizeof(*p->funcdescs);
  10945. + if (idx < nsym && (sym[idx].st_info&0xf) == STT_FUNC) {
  10946. + best = p->funcdescs + idx;
  10947. + bestsym = sym + idx;
  10948. + }
  10949. + }
  10950. +
  10951. + if (!best) for (; nsym; nsym--, sym++) {
  10952. + if (sym->st_value
  10953. + && (1<<(sym->st_info&0xf) & OK_TYPES)
  10954. + && (1<<(sym->st_info>>4) & OK_BINDS)) {
  10955. + void *symaddr = laddr(p, sym->st_value);
  10956. + if (symaddr > addr || symaddr < best)
  10957. + continue;
  10958. + best = symaddr;
  10959. + bestsym = sym;
  10960. + if (addr == symaddr)
  10961. + break;
  10962. + }
  10963. + }
  10964. +
  10965. + if (!best) return 0;
  10966. +
  10967. + if (DL_FDPIC && (bestsym->st_info&0xf) == STT_FUNC)
  10968. + best = p->funcdescs + (bestsym - p->syms);
  10969. +
  10970. + info->dli_fname = p->name;
  10971. + info->dli_fbase = p->base;
  10972. + info->dli_sname = strings + bestsym->st_name;
  10973. + info->dli_saddr = best;
  10974. +
  10975. + return 1;
  10976. +}
  10977. +
  10978. +__attribute__((__visibility__("hidden")))
  10979. +void *__dlsym(void *restrict p, const char *restrict s, void *restrict ra)
  10980. +{
  10981. + void *res;
  10982. + pthread_rwlock_rdlock(&lock);
  10983. + res = do_dlsym(p, s, ra);
  10984. + pthread_rwlock_unlock(&lock);
  10985. + return res;
  10986. +}
  10987. +
  10988. +int dl_iterate_phdr(int(*callback)(struct dl_phdr_info *info, size_t size, void *data), void *data)
  10989. +{
  10990. + struct dso *current;
  10991. + struct dl_phdr_info info;
  10992. + int ret = 0;
  10993. + for(current = head; current;) {
  10994. + info.dlpi_addr = (uintptr_t)current->base;
  10995. + info.dlpi_name = current->name;
  10996. + info.dlpi_phdr = current->phdr;
  10997. + info.dlpi_phnum = current->phnum;
  10998. + info.dlpi_adds = gencnt;
  10999. + info.dlpi_subs = 0;
  11000. + info.dlpi_tls_modid = current->tls_id;
  11001. + info.dlpi_tls_data = current->tls.image;
  11002. +
  11003. + ret = (callback)(&info, sizeof (info), data);
  11004. +
  11005. + if (ret != 0) break;
  11006. +
  11007. + pthread_rwlock_rdlock(&lock);
  11008. + current = current->next;
  11009. + pthread_rwlock_unlock(&lock);
  11010. + }
  11011. + return ret;
  11012. +}
  11013. +
  11014. +__attribute__((__visibility__("hidden")))
  11015. +void __dl_vseterr(const char *, va_list);
  11016. +
  11017. +static void error(const char *fmt, ...)
  11018. +{
  11019. + va_list ap;
  11020. + va_start(ap, fmt);
  11021. + if (!runtime) {
  11022. + vdprintf(2, fmt, ap);
  11023. + dprintf(2, "\n");
  11024. + ldso_fail = 1;
  11025. + va_end(ap);
  11026. + return;
  11027. + }
  11028. + __dl_vseterr(fmt, ap);
  11029. + va_end(ap);
  11030. +}
  11031. --- a/src/env/__init_tls.c
  11032. +++ b/src/env/__init_tls.c
  11033. @@ -8,9 +8,6 @@
  11034. #include "atomic.h"
  11035. #include "syscall.h"
  11036. -#ifndef SHARED
  11037. -static
  11038. -#endif
  11039. int __init_tp(void *p)
  11040. {
  11041. pthread_t td = p;
  11042. @@ -24,8 +21,6 @@ int __init_tp(void *p)
  11043. return 0;
  11044. }
  11045. -#ifndef SHARED
  11046. -
  11047. static struct builtin_tls {
  11048. char c;
  11049. struct pthread pt;
  11050. @@ -33,33 +28,40 @@ static struct builtin_tls {
  11051. } builtin_tls[1];
  11052. #define MIN_TLS_ALIGN offsetof(struct builtin_tls, pt)
  11053. -struct tls_image {
  11054. - void *image;
  11055. - size_t len, size, align;
  11056. -} __static_tls;
  11057. -
  11058. -#define T __static_tls
  11059. +static struct tls_module main_tls;
  11060. void *__copy_tls(unsigned char *mem)
  11061. {
  11062. pthread_t td;
  11063. - if (!T.image) return mem;
  11064. - void **dtv = (void *)mem;
  11065. - dtv[0] = (void *)1;
  11066. + struct tls_module *p;
  11067. + size_t i;
  11068. + void **dtv;
  11069. +
  11070. #ifdef TLS_ABOVE_TP
  11071. - mem += sizeof(void *) * 2;
  11072. - mem += -((uintptr_t)mem + sizeof(struct pthread)) & (T.align-1);
  11073. + dtv = (void **)(mem + libc.tls_size) - (libc.tls_cnt + 1);
  11074. +
  11075. + mem += -((uintptr_t)mem + sizeof(struct pthread)) & (libc.tls_align-1);
  11076. td = (pthread_t)mem;
  11077. mem += sizeof(struct pthread);
  11078. +
  11079. + for (i=1, p=libc.tls_head; p; i++, p=p->next) {
  11080. + dtv[i] = mem + p->offset;
  11081. + memcpy(dtv[i], p->image, p->len);
  11082. + }
  11083. #else
  11084. + dtv = (void **)mem;
  11085. +
  11086. mem += libc.tls_size - sizeof(struct pthread);
  11087. - mem -= (uintptr_t)mem & (T.align-1);
  11088. + mem -= (uintptr_t)mem & (libc.tls_align-1);
  11089. td = (pthread_t)mem;
  11090. - mem -= T.size;
  11091. +
  11092. + for (i=1, p=libc.tls_head; p; i++, p=p->next) {
  11093. + dtv[i] = mem - p->offset;
  11094. + memcpy(dtv[i], p->image, p->len);
  11095. + }
  11096. #endif
  11097. + dtv[0] = (void *)libc.tls_cnt;
  11098. td->dtv = td->dtv_copy = dtv;
  11099. - dtv[1] = mem;
  11100. - memcpy(mem, T.image, T.len);
  11101. return td;
  11102. }
  11103. @@ -69,7 +71,7 @@ typedef Elf32_Phdr Phdr;
  11104. typedef Elf64_Phdr Phdr;
  11105. #endif
  11106. -void __init_tls(size_t *aux)
  11107. +static void static_init_tls(size_t *aux)
  11108. {
  11109. unsigned char *p;
  11110. size_t n;
  11111. @@ -86,16 +88,24 @@ void __init_tls(size_t *aux)
  11112. }
  11113. if (tls_phdr) {
  11114. - T.image = (void *)(base + tls_phdr->p_vaddr);
  11115. - T.len = tls_phdr->p_filesz;
  11116. - T.size = tls_phdr->p_memsz;
  11117. - T.align = tls_phdr->p_align;
  11118. + main_tls.image = (void *)(base + tls_phdr->p_vaddr);
  11119. + main_tls.len = tls_phdr->p_filesz;
  11120. + main_tls.size = tls_phdr->p_memsz;
  11121. + main_tls.align = tls_phdr->p_align;
  11122. + libc.tls_cnt = 1;
  11123. + libc.tls_head = &main_tls;
  11124. }
  11125. - T.size += (-T.size - (uintptr_t)T.image) & (T.align-1);
  11126. - if (T.align < MIN_TLS_ALIGN) T.align = MIN_TLS_ALIGN;
  11127. + main_tls.size += (-main_tls.size - (uintptr_t)main_tls.image)
  11128. + & (main_tls.align-1);
  11129. + if (main_tls.align < MIN_TLS_ALIGN) main_tls.align = MIN_TLS_ALIGN;
  11130. +#ifndef TLS_ABOVE_TP
  11131. + main_tls.offset = main_tls.size;
  11132. +#endif
  11133. - libc.tls_size = 2*sizeof(void *)+T.size+T.align+sizeof(struct pthread)
  11134. + libc.tls_align = main_tls.align;
  11135. + libc.tls_size = 2*sizeof(void *) + sizeof(struct pthread)
  11136. + + main_tls.size + main_tls.align
  11137. + MIN_TLS_ALIGN-1 & -MIN_TLS_ALIGN;
  11138. if (libc.tls_size > sizeof builtin_tls) {
  11139. @@ -117,6 +127,5 @@ void __init_tls(size_t *aux)
  11140. if (__init_tp(__copy_tls(mem)) < 0)
  11141. a_crash();
  11142. }
  11143. -#else
  11144. -void __init_tls(size_t *auxv) { }
  11145. -#endif
  11146. +
  11147. +weak_alias(static_init_tls, __init_tls);
  11148. --- a/src/env/__libc_start_main.c
  11149. +++ b/src/env/__libc_start_main.c
  11150. @@ -8,21 +8,17 @@
  11151. void __init_tls(size_t *);
  11152. -#ifndef SHARED
  11153. -static void dummy() {}
  11154. +static void dummy(void) {}
  11155. weak_alias(dummy, _init);
  11156. -extern void (*const __init_array_start)() __attribute__((weak));
  11157. -extern void (*const __init_array_end)() __attribute__((weak));
  11158. -#endif
  11159. +
  11160. +__attribute__((__weak__, __visibility__("hidden")))
  11161. +extern void (*const __init_array_start)(void), (*const __init_array_end)(void);
  11162. static void dummy1(void *p) {}
  11163. weak_alias(dummy1, __init_ssp);
  11164. #define AUX_CNT 38
  11165. -#ifndef SHARED
  11166. -static
  11167. -#endif
  11168. void __init_libc(char **envp, char *pn)
  11169. {
  11170. size_t i, *auxv, aux[AUX_CNT] = { 0 };
  11171. @@ -57,20 +53,22 @@ void __init_libc(char **envp, char *pn)
  11172. libc.secure = 1;
  11173. }
  11174. -int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv)
  11175. +static void libc_start_init(void)
  11176. {
  11177. - char **envp = argv+argc+1;
  11178. -
  11179. -#ifndef SHARED
  11180. - __init_libc(envp, argv[0]);
  11181. _init();
  11182. uintptr_t a = (uintptr_t)&__init_array_start;
  11183. for (; a<(uintptr_t)&__init_array_end; a+=sizeof(void(*)()))
  11184. (*(void (**)())a)();
  11185. -#else
  11186. - void __libc_start_init(void);
  11187. +}
  11188. +
  11189. +weak_alias(libc_start_init, __libc_start_init);
  11190. +
  11191. +int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv)
  11192. +{
  11193. + char **envp = argv+argc+1;
  11194. +
  11195. + __init_libc(envp, argv[0]);
  11196. __libc_start_init();
  11197. -#endif
  11198. /* Pass control to the application */
  11199. exit(main(argc, argv, envp));
  11200. --- a/src/env/__reset_tls.c
  11201. +++ b/src/env/__reset_tls.c
  11202. @@ -1,21 +1,16 @@
  11203. -#ifndef SHARED
  11204. -
  11205. #include <string.h>
  11206. #include "pthread_impl.h"
  11207. -
  11208. -extern struct tls_image {
  11209. - void *image;
  11210. - size_t len, size, align;
  11211. -} __static_tls;
  11212. -
  11213. -#define T __static_tls
  11214. +#include "libc.h"
  11215. void __reset_tls()
  11216. {
  11217. - if (!T.size) return;
  11218. pthread_t self = __pthread_self();
  11219. - memcpy(self->dtv[1], T.image, T.len);
  11220. - memset((char *)self->dtv[1]+T.len, 0, T.size-T.len);
  11221. + struct tls_module *p;
  11222. + size_t i, n = (size_t)self->dtv[0];
  11223. + if (n) for (p=libc.tls_head, i=1; i<=n; i++, p=p->next) {
  11224. + if (!self->dtv[i]) continue;
  11225. + memcpy(self->dtv[i], p->image, p->len);
  11226. + memset((char *)self->dtv[i]+p->len, 0,
  11227. + p->size - p->len);
  11228. + }
  11229. }
  11230. -
  11231. -#endif
  11232. --- a/src/env/__stack_chk_fail.c
  11233. +++ b/src/env/__stack_chk_fail.c
  11234. @@ -17,16 +17,7 @@ void __stack_chk_fail(void)
  11235. a_crash();
  11236. }
  11237. -#ifdef SHARED
  11238. -
  11239. __attribute__((__visibility__("hidden")))
  11240. -void __stack_chk_fail_local(void)
  11241. -{
  11242. - a_crash();
  11243. -}
  11244. -
  11245. -#else
  11246. +void __stack_chk_fail_local(void);
  11247. weak_alias(__stack_chk_fail, __stack_chk_fail_local);
  11248. -
  11249. -#endif
  11250. --- /dev/null
  11251. +++ b/src/exit/arm/__aeabi_atexit.c
  11252. @@ -0,0 +1,6 @@
  11253. +int __cxa_atexit(void (*func)(void *), void *arg, void *dso);
  11254. +
  11255. +int __aeabi_atexit (void *obj, void (*func) (void *), void *d)
  11256. +{
  11257. + return __cxa_atexit (func, obj, d);
  11258. +}
  11259. --- a/src/exit/exit.c
  11260. +++ b/src/exit/exit.c
  11261. @@ -10,25 +10,25 @@ static void dummy()
  11262. * as a consequence of linking either __toread.c or __towrite.c. */
  11263. weak_alias(dummy, __funcs_on_exit);
  11264. weak_alias(dummy, __stdio_exit);
  11265. -
  11266. -#ifndef SHARED
  11267. weak_alias(dummy, _fini);
  11268. -extern void (*const __fini_array_start)() __attribute__((weak));
  11269. -extern void (*const __fini_array_end)() __attribute__((weak));
  11270. -#endif
  11271. -_Noreturn void exit(int code)
  11272. -{
  11273. - __funcs_on_exit();
  11274. +__attribute__((__weak__, __visibility__("hidden")))
  11275. +extern void (*const __fini_array_start)(void), (*const __fini_array_end)(void);
  11276. -#ifndef SHARED
  11277. +static void libc_exit_fini(void)
  11278. +{
  11279. uintptr_t a = (uintptr_t)&__fini_array_end;
  11280. for (; a>(uintptr_t)&__fini_array_start; a-=sizeof(void(*)()))
  11281. (*(void (**)())(a-sizeof(void(*)())))();
  11282. _fini();
  11283. -#endif
  11284. +}
  11285. - __stdio_exit();
  11286. +weak_alias(libc_exit_fini, __libc_exit_fini);
  11287. +_Noreturn void exit(int code)
  11288. +{
  11289. + __funcs_on_exit();
  11290. + __libc_exit_fini();
  11291. + __stdio_exit();
  11292. _Exit(code);
  11293. }
  11294. --- /dev/null
  11295. +++ b/src/fenv/arm/fenv-hf.S
  11296. @@ -0,0 +1,69 @@
  11297. +#if __ARM_PCS_VFP
  11298. +
  11299. +.syntax unified
  11300. +.fpu vfp
  11301. +
  11302. +.global fegetround
  11303. +.type fegetround,%function
  11304. +fegetround:
  11305. + fmrx r0, fpscr
  11306. + and r0, r0, #0xc00000
  11307. + bx lr
  11308. +
  11309. +.global __fesetround
  11310. +.type __fesetround,%function
  11311. +__fesetround:
  11312. + fmrx r3, fpscr
  11313. + bic r3, r3, #0xc00000
  11314. + orr r3, r3, r0
  11315. + fmxr fpscr, r3
  11316. + mov r0, #0
  11317. + bx lr
  11318. +
  11319. +.global fetestexcept
  11320. +.type fetestexcept,%function
  11321. +fetestexcept:
  11322. + and r0, r0, #0x1f
  11323. + fmrx r3, fpscr
  11324. + and r0, r0, r3
  11325. + bx lr
  11326. +
  11327. +.global feclearexcept
  11328. +.type feclearexcept,%function
  11329. +feclearexcept:
  11330. + and r0, r0, #0x1f
  11331. + fmrx r3, fpscr
  11332. + bic r3, r3, r0
  11333. + fmxr fpscr, r3
  11334. + mov r0, #0
  11335. + bx lr
  11336. +
  11337. +.global feraiseexcept
  11338. +.type feraiseexcept,%function
  11339. +feraiseexcept:
  11340. + and r0, r0, #0x1f
  11341. + fmrx r3, fpscr
  11342. + orr r3, r3, r0
  11343. + fmxr fpscr, r3
  11344. + mov r0, #0
  11345. + bx lr
  11346. +
  11347. +.global fegetenv
  11348. +.type fegetenv,%function
  11349. +fegetenv:
  11350. + fmrx r3, fpscr
  11351. + str r3, [r0]
  11352. + mov r0, #0
  11353. + bx lr
  11354. +
  11355. +.global fesetenv
  11356. +.type fesetenv,%function
  11357. +fesetenv:
  11358. + cmn r0, #1
  11359. + moveq r3, #0
  11360. + ldrne r3, [r0]
  11361. + fmxr fpscr, r3
  11362. + mov r0, #0
  11363. + bx lr
  11364. +
  11365. +#endif
  11366. --- /dev/null
  11367. +++ b/src/fenv/arm/fenv.c
  11368. @@ -0,0 +1,3 @@
  11369. +#if !__ARM_PCS_VFP
  11370. +#include "../fenv.c"
  11371. +#endif
  11372. --- a/src/fenv/armebhf/fenv.sub
  11373. +++ /dev/null
  11374. @@ -1 +0,0 @@
  11375. -../armhf/fenv.s
  11376. --- a/src/fenv/armhf/fenv.s
  11377. +++ /dev/null
  11378. @@ -1,64 +0,0 @@
  11379. -.fpu vfp
  11380. -
  11381. -.global fegetround
  11382. -.type fegetround,%function
  11383. -fegetround:
  11384. - mrc p10, 7, r0, cr1, cr0, 0
  11385. - and r0, r0, #0xc00000
  11386. - bx lr
  11387. -
  11388. -.global __fesetround
  11389. -.type __fesetround,%function
  11390. -__fesetround:
  11391. - mrc p10, 7, r3, cr1, cr0, 0
  11392. - bic r3, r3, #0xc00000
  11393. - orr r3, r3, r0
  11394. - mcr p10, 7, r3, cr1, cr0, 0
  11395. - mov r0, #0
  11396. - bx lr
  11397. -
  11398. -.global fetestexcept
  11399. -.type fetestexcept,%function
  11400. -fetestexcept:
  11401. - and r0, r0, #0x1f
  11402. - mrc p10, 7, r3, cr1, cr0, 0
  11403. - and r0, r0, r3
  11404. - bx lr
  11405. -
  11406. -.global feclearexcept
  11407. -.type feclearexcept,%function
  11408. -feclearexcept:
  11409. - and r0, r0, #0x1f
  11410. - mrc p10, 7, r3, cr1, cr0, 0
  11411. - bic r3, r3, r0
  11412. - mcr p10, 7, r3, cr1, cr0, 0
  11413. - mov r0, #0
  11414. - bx lr
  11415. -
  11416. -.global feraiseexcept
  11417. -.type feraiseexcept,%function
  11418. -feraiseexcept:
  11419. - and r0, r0, #0x1f
  11420. - mrc p10, 7, r3, cr1, cr0, 0
  11421. - orr r3, r3, r0
  11422. - mcr p10, 7, r3, cr1, cr0, 0
  11423. - mov r0, #0
  11424. - bx lr
  11425. -
  11426. -.global fegetenv
  11427. -.type fegetenv,%function
  11428. -fegetenv:
  11429. - mrc p10, 7, r3, cr1, cr0, 0
  11430. - str r3, [r0]
  11431. - mov r0, #0
  11432. - bx lr
  11433. -
  11434. -.global fesetenv
  11435. -.type fesetenv,%function
  11436. -fesetenv:
  11437. - cmn r0, #1
  11438. - moveq r3, #0
  11439. - ldrne r3, [r0]
  11440. - mcr p10, 7, r3, cr1, cr0, 0
  11441. - mov r0, #0
  11442. - bx lr
  11443. --- a/src/fenv/armhf/fenv.sub
  11444. +++ /dev/null
  11445. @@ -1 +0,0 @@
  11446. -fenv.s
  11447. --- a/src/fenv/mips-sf/fenv.sub
  11448. +++ /dev/null
  11449. @@ -1 +0,0 @@
  11450. -../fenv.c
  11451. --- /dev/null
  11452. +++ b/src/fenv/mips/fenv-sf.c
  11453. @@ -0,0 +1,3 @@
  11454. +#ifdef __mips_soft_float
  11455. +#include "../fenv.c"
  11456. +#endif
  11457. --- /dev/null
  11458. +++ b/src/fenv/mips/fenv.S
  11459. @@ -0,0 +1,71 @@
  11460. +#ifndef __mips_soft_float
  11461. +
  11462. +.set noreorder
  11463. +
  11464. +.global feclearexcept
  11465. +.type feclearexcept,@function
  11466. +feclearexcept:
  11467. + and $4, $4, 0x7c
  11468. + cfc1 $5, $31
  11469. + or $5, $5, $4
  11470. + xor $5, $5, $4
  11471. + ctc1 $5, $31
  11472. + jr $ra
  11473. + li $2, 0
  11474. +
  11475. +.global feraiseexcept
  11476. +.type feraiseexcept,@function
  11477. +feraiseexcept:
  11478. + and $4, $4, 0x7c
  11479. + cfc1 $5, $31
  11480. + or $5, $5, $4
  11481. + ctc1 $5, $31
  11482. + jr $ra
  11483. + li $2, 0
  11484. +
  11485. +.global fetestexcept
  11486. +.type fetestexcept,@function
  11487. +fetestexcept:
  11488. + and $4, $4, 0x7c
  11489. + cfc1 $2, $31
  11490. + jr $ra
  11491. + and $2, $2, $4
  11492. +
  11493. +.global fegetround
  11494. +.type fegetround,@function
  11495. +fegetround:
  11496. + cfc1 $2, $31
  11497. + jr $ra
  11498. + andi $2, $2, 3
  11499. +
  11500. +.global __fesetround
  11501. +.type __fesetround,@function
  11502. +__fesetround:
  11503. + cfc1 $5, $31
  11504. + li $6, -4
  11505. + and $5, $5, $6
  11506. + or $5, $5, $4
  11507. + ctc1 $5, $31
  11508. + jr $ra
  11509. + li $2, 0
  11510. +
  11511. +.global fegetenv
  11512. +.type fegetenv,@function
  11513. +fegetenv:
  11514. + cfc1 $5, $31
  11515. + sw $5, 0($4)
  11516. + jr $ra
  11517. + li $2, 0
  11518. +
  11519. +.global fesetenv
  11520. +.type fesetenv,@function
  11521. +fesetenv:
  11522. + addiu $5, $4, 1
  11523. + beq $5, $0, 1f
  11524. + nop
  11525. + lw $5, 0($4)
  11526. +1: ctc1 $5, $31
  11527. + jr $ra
  11528. + li $2, 0
  11529. +
  11530. +#endif
  11531. --- a/src/fenv/mips/fenv.s
  11532. +++ /dev/null
  11533. @@ -1,67 +0,0 @@
  11534. -.set noreorder
  11535. -
  11536. -.global feclearexcept
  11537. -.type feclearexcept,@function
  11538. -feclearexcept:
  11539. - and $4, $4, 0x7c
  11540. - cfc1 $5, $31
  11541. - or $5, $5, $4
  11542. - xor $5, $5, $4
  11543. - ctc1 $5, $31
  11544. - jr $ra
  11545. - li $2, 0
  11546. -
  11547. -.global feraiseexcept
  11548. -.type feraiseexcept,@function
  11549. -feraiseexcept:
  11550. - and $4, $4, 0x7c
  11551. - cfc1 $5, $31
  11552. - or $5, $5, $4
  11553. - ctc1 $5, $31
  11554. - jr $ra
  11555. - li $2, 0
  11556. -
  11557. -.global fetestexcept
  11558. -.type fetestexcept,@function
  11559. -fetestexcept:
  11560. - and $4, $4, 0x7c
  11561. - cfc1 $2, $31
  11562. - jr $ra
  11563. - and $2, $2, $4
  11564. -
  11565. -.global fegetround
  11566. -.type fegetround,@function
  11567. -fegetround:
  11568. - cfc1 $2, $31
  11569. - jr $ra
  11570. - andi $2, $2, 3
  11571. -
  11572. -.global __fesetround
  11573. -.type __fesetround,@function
  11574. -__fesetround:
  11575. - cfc1 $5, $31
  11576. - li $6, -4
  11577. - and $5, $5, $6
  11578. - or $5, $5, $4
  11579. - ctc1 $5, $31
  11580. - jr $ra
  11581. - li $2, 0
  11582. -
  11583. -.global fegetenv
  11584. -.type fegetenv,@function
  11585. -fegetenv:
  11586. - cfc1 $5, $31
  11587. - sw $5, 0($4)
  11588. - jr $ra
  11589. - li $2, 0
  11590. -
  11591. -.global fesetenv
  11592. -.type fesetenv,@function
  11593. -fesetenv:
  11594. - addiu $5, $4, 1
  11595. - beq $5, $0, 1f
  11596. - nop
  11597. - lw $5, 0($4)
  11598. -1: ctc1 $5, $31
  11599. - jr $ra
  11600. - li $2, 0
  11601. --- a/src/fenv/mipsel-sf/fenv.sub
  11602. +++ /dev/null
  11603. @@ -1 +0,0 @@
  11604. -../fenv.c
  11605. --- a/src/fenv/sh-nofpu/fenv.sub
  11606. +++ /dev/null
  11607. @@ -1 +0,0 @@
  11608. -../fenv.c
  11609. --- /dev/null
  11610. +++ b/src/fenv/sh/fenv-nofpu.c
  11611. @@ -0,0 +1,3 @@
  11612. +#if !__SH_FPU_ANY__ && !__SH4__
  11613. +#include "../fenv.c"
  11614. +#endif
  11615. --- /dev/null
  11616. +++ b/src/fenv/sh/fenv.S
  11617. @@ -0,0 +1,78 @@
  11618. +#if __SH_FPU_ANY__ || __SH4__
  11619. +
  11620. +.global fegetround
  11621. +.type fegetround, @function
  11622. +fegetround:
  11623. + sts fpscr, r0
  11624. + rts
  11625. + and #3, r0
  11626. +
  11627. +.global __fesetround
  11628. +.type __fesetround, @function
  11629. +__fesetround:
  11630. + sts fpscr, r0
  11631. + or r4, r0
  11632. + lds r0, fpscr
  11633. + rts
  11634. + mov #0, r0
  11635. +
  11636. +.global fetestexcept
  11637. +.type fetestexcept, @function
  11638. +fetestexcept:
  11639. + sts fpscr, r0
  11640. + and r4, r0
  11641. + rts
  11642. + and #0x7c, r0
  11643. +
  11644. +.global feclearexcept
  11645. +.type feclearexcept, @function
  11646. +feclearexcept:
  11647. + mov r4, r0
  11648. + and #0x7c, r0
  11649. + not r0, r4
  11650. + sts fpscr, r0
  11651. + and r4, r0
  11652. + lds r0, fpscr
  11653. + rts
  11654. + mov #0, r0
  11655. +
  11656. +.global feraiseexcept
  11657. +.type feraiseexcept, @function
  11658. +feraiseexcept:
  11659. + mov r4, r0
  11660. + and #0x7c, r0
  11661. + sts fpscr, r4
  11662. + or r4, r0
  11663. + lds r0, fpscr
  11664. + rts
  11665. + mov #0, r0
  11666. +
  11667. +.global fegetenv
  11668. +.type fegetenv, @function
  11669. +fegetenv:
  11670. + sts fpscr, r0
  11671. + mov.l r0, @r4
  11672. + rts
  11673. + mov #0, r0
  11674. +
  11675. +.global fesetenv
  11676. +.type fesetenv, @function
  11677. +fesetenv:
  11678. + mov r4, r0
  11679. + cmp/eq #-1, r0
  11680. + bf 1f
  11681. +
  11682. + ! the default environment is complicated by the fact that we need to
  11683. + ! preserve the current precision bit, which we do not know a priori
  11684. + sts fpscr, r0
  11685. + mov #8, r1
  11686. + swap.w r1, r1
  11687. + bra 2f
  11688. + and r1, r0
  11689. +
  11690. +1: mov.l @r4, r0 ! non-default environment
  11691. +2: lds r0, fpscr
  11692. + rts
  11693. + mov #0, r0
  11694. +
  11695. +#endif
  11696. --- a/src/fenv/sh/fenv.s
  11697. +++ /dev/null
  11698. @@ -1,74 +0,0 @@
  11699. -.global fegetround
  11700. -.type fegetround, @function
  11701. -fegetround:
  11702. - sts fpscr, r0
  11703. - rts
  11704. - and #3, r0
  11705. -
  11706. -.global __fesetround
  11707. -.type __fesetround, @function
  11708. -__fesetround:
  11709. - sts fpscr, r0
  11710. - or r4, r0
  11711. - lds r0, fpscr
  11712. - rts
  11713. - mov #0, r0
  11714. -
  11715. -.global fetestexcept
  11716. -.type fetestexcept, @function
  11717. -fetestexcept:
  11718. - sts fpscr, r0
  11719. - and r4, r0
  11720. - rts
  11721. - and #0x7c, r0
  11722. -
  11723. -.global feclearexcept
  11724. -.type feclearexcept, @function
  11725. -feclearexcept:
  11726. - mov r4, r0
  11727. - and #0x7c, r0
  11728. - not r0, r4
  11729. - sts fpscr, r0
  11730. - and r4, r0
  11731. - lds r0, fpscr
  11732. - rts
  11733. - mov #0, r0
  11734. -
  11735. -.global feraiseexcept
  11736. -.type feraiseexcept, @function
  11737. -feraiseexcept:
  11738. - mov r4, r0
  11739. - and #0x7c, r0
  11740. - sts fpscr, r4
  11741. - or r4, r0
  11742. - lds r0, fpscr
  11743. - rts
  11744. - mov #0, r0
  11745. -
  11746. -.global fegetenv
  11747. -.type fegetenv, @function
  11748. -fegetenv:
  11749. - sts fpscr, r0
  11750. - mov.l r0, @r4
  11751. - rts
  11752. - mov #0, r0
  11753. -
  11754. -.global fesetenv
  11755. -.type fesetenv, @function
  11756. -fesetenv:
  11757. - mov r4, r0
  11758. - cmp/eq #-1, r0
  11759. - bf 1f
  11760. -
  11761. - ! the default environment is complicated by the fact that we need to
  11762. - ! preserve the current precision bit, which we do not know a priori
  11763. - sts fpscr, r0
  11764. - mov #8, r1
  11765. - swap.w r1, r1
  11766. - bra 2f
  11767. - and r1, r0
  11768. -
  11769. -1: mov.l @r4, r0 ! non-default environment
  11770. -2: lds r0, fpscr
  11771. - rts
  11772. - mov #0, r0
  11773. --- a/src/fenv/sheb-nofpu/fenv.sub
  11774. +++ /dev/null
  11775. @@ -1 +0,0 @@
  11776. -../fenv.c
  11777. --- a/src/internal/arm/syscall.s
  11778. +++ b/src/internal/arm/syscall.s
  11779. @@ -1,3 +1,4 @@
  11780. +.syntax unified
  11781. .global __syscall
  11782. .hidden __syscall
  11783. .type __syscall,%function
  11784. @@ -11,6 +12,4 @@ __syscall:
  11785. ldmfd ip,{r3,r4,r5,r6}
  11786. svc 0
  11787. ldmfd sp!,{r4,r5,r6,r7}
  11788. - tst lr,#1
  11789. - moveq pc,lr
  11790. bx lr
  11791. --- /dev/null
  11792. +++ b/src/internal/atomic.h
  11793. @@ -0,0 +1,275 @@
  11794. +#ifndef _ATOMIC_H
  11795. +#define _ATOMIC_H
  11796. +
  11797. +#include <stdint.h>
  11798. +
  11799. +#include "atomic_arch.h"
  11800. +
  11801. +#ifdef a_ll
  11802. +
  11803. +#ifndef a_pre_llsc
  11804. +#define a_pre_llsc()
  11805. +#endif
  11806. +
  11807. +#ifndef a_post_llsc
  11808. +#define a_post_llsc()
  11809. +#endif
  11810. +
  11811. +#ifndef a_cas
  11812. +#define a_cas a_cas
  11813. +static inline int a_cas(volatile int *p, int t, int s)
  11814. +{
  11815. + int old;
  11816. + a_pre_llsc();
  11817. + do old = a_ll(p);
  11818. + while (old==t && !a_sc(p, s));
  11819. + a_post_llsc();
  11820. + return old;
  11821. +}
  11822. +#endif
  11823. +
  11824. +#ifndef a_swap
  11825. +#define a_swap a_swap
  11826. +static inline int a_swap(volatile int *p, int v)
  11827. +{
  11828. + int old;
  11829. + a_pre_llsc();
  11830. + do old = a_ll(p);
  11831. + while (!a_sc(p, v));
  11832. + a_post_llsc();
  11833. + return old;
  11834. +}
  11835. +#endif
  11836. +
  11837. +#ifndef a_fetch_add
  11838. +#define a_fetch_add a_fetch_add
  11839. +static inline int a_fetch_add(volatile int *p, int v)
  11840. +{
  11841. + int old;
  11842. + a_pre_llsc();
  11843. + do old = a_ll(p);
  11844. + while (!a_sc(p, (unsigned)old + v));
  11845. + a_post_llsc();
  11846. + return old;
  11847. +}
  11848. +#endif
  11849. +
  11850. +#ifndef a_fetch_and
  11851. +#define a_fetch_and a_fetch_and
  11852. +static inline int a_fetch_and(volatile int *p, int v)
  11853. +{
  11854. + int old;
  11855. + a_pre_llsc();
  11856. + do old = a_ll(p);
  11857. + while (!a_sc(p, old & v));
  11858. + a_post_llsc();
  11859. + return old;
  11860. +}
  11861. +#endif
  11862. +
  11863. +#ifndef a_fetch_or
  11864. +#define a_fetch_or a_fetch_or
  11865. +static inline int a_fetch_or(volatile int *p, int v)
  11866. +{
  11867. + int old;
  11868. + a_pre_llsc();
  11869. + do old = a_ll(p);
  11870. + while (!a_sc(p, old | v));
  11871. + a_post_llsc();
  11872. + return old;
  11873. +}
  11874. +#endif
  11875. +
  11876. +#endif
  11877. +
  11878. +#ifndef a_cas
  11879. +#error missing definition of a_cas
  11880. +#endif
  11881. +
  11882. +#ifndef a_swap
  11883. +#define a_swap a_swap
  11884. +static inline int a_swap(volatile int *p, int v)
  11885. +{
  11886. + int old;
  11887. + do old = *p;
  11888. + while (a_cas(p, old, v) != old);
  11889. + return old;
  11890. +}
  11891. +#endif
  11892. +
  11893. +#ifndef a_fetch_add
  11894. +#define a_fetch_add a_fetch_add
  11895. +static inline int a_fetch_add(volatile int *p, int v)
  11896. +{
  11897. + int old;
  11898. + do old = *p;
  11899. + while (a_cas(p, old, (unsigned)old+v) != old);
  11900. + return old;
  11901. +}
  11902. +#endif
  11903. +
  11904. +#ifndef a_fetch_and
  11905. +#define a_fetch_and a_fetch_and
  11906. +static inline int a_fetch_and(volatile int *p, int v)
  11907. +{
  11908. + int old;
  11909. + do old = *p;
  11910. + while (a_cas(p, old, old&v) != old);
  11911. + return old;
  11912. +}
  11913. +#endif
  11914. +#ifndef a_fetch_or
  11915. +#define a_fetch_or a_fetch_or
  11916. +static inline int a_fetch_or(volatile int *p, int v)
  11917. +{
  11918. + int old;
  11919. + do old = *p;
  11920. + while (a_cas(p, old, old|v) != old);
  11921. + return old;
  11922. +}
  11923. +#endif
  11924. +
  11925. +#ifndef a_and
  11926. +#define a_and a_and
  11927. +static inline void a_and(volatile int *p, int v)
  11928. +{
  11929. + a_fetch_and(p, v);
  11930. +}
  11931. +#endif
  11932. +
  11933. +#ifndef a_or
  11934. +#define a_or a_or
  11935. +static inline void a_or(volatile int *p, int v)
  11936. +{
  11937. + a_fetch_or(p, v);
  11938. +}
  11939. +#endif
  11940. +
  11941. +#ifndef a_inc
  11942. +#define a_inc a_inc
  11943. +static inline void a_inc(volatile int *p)
  11944. +{
  11945. + a_fetch_add(p, 1);
  11946. +}
  11947. +#endif
  11948. +
  11949. +#ifndef a_dec
  11950. +#define a_dec a_dec
  11951. +static inline void a_dec(volatile int *p)
  11952. +{
  11953. + a_fetch_add(p, -1);
  11954. +}
  11955. +#endif
  11956. +
  11957. +#ifndef a_store
  11958. +#define a_store a_store
  11959. +static inline void a_store(volatile int *p, int v)
  11960. +{
  11961. +#ifdef a_barrier
  11962. + a_barrier();
  11963. + *p = v;
  11964. + a_barrier();
  11965. +#else
  11966. + a_swap(p, v);
  11967. +#endif
  11968. +}
  11969. +#endif
  11970. +
  11971. +#ifndef a_barrier
  11972. +#define a_barrier a_barrier
  11973. +static void a_barrier()
  11974. +{
  11975. + volatile int tmp = 0;
  11976. + a_cas(&tmp, 0, 0);
  11977. +}
  11978. +#endif
  11979. +
  11980. +#ifndef a_spin
  11981. +#define a_spin a_barrier
  11982. +#endif
  11983. +
  11984. +#ifndef a_and_64
  11985. +#define a_and_64 a_and_64
  11986. +static inline void a_and_64(volatile uint64_t *p, uint64_t v)
  11987. +{
  11988. + union { uint64_t v; uint32_t r[2]; } u = { v };
  11989. + if (u.r[0]+1) a_and((int *)p, u.r[0]);
  11990. + if (u.r[1]+1) a_and((int *)p+1, u.r[1]);
  11991. +}
  11992. +#endif
  11993. +
  11994. +#ifndef a_or_64
  11995. +#define a_or_64 a_or_64
  11996. +static inline void a_or_64(volatile uint64_t *p, uint64_t v)
  11997. +{
  11998. + union { uint64_t v; uint32_t r[2]; } u = { v };
  11999. + if (u.r[0]) a_or((int *)p, u.r[0]);
  12000. + if (u.r[1]) a_or((int *)p+1, u.r[1]);
  12001. +}
  12002. +#endif
  12003. +
  12004. +#ifndef a_cas_p
  12005. +#define a_cas_p a_cas_p
  12006. +static inline void *a_cas_p(volatile void *p, void *t, void *s)
  12007. +{
  12008. + return (void *)a_cas((volatile int *)p, (int)t, (int)s);
  12009. +}
  12010. +#endif
  12011. +
  12012. +#ifndef a_or_l
  12013. +#define a_or_l a_or_l
  12014. +static inline void a_or_l(volatile void *p, long v)
  12015. +{
  12016. + if (sizeof(long) == sizeof(int)) a_or(p, v);
  12017. + else a_or_64(p, v);
  12018. +}
  12019. +#endif
  12020. +
  12021. +#ifndef a_crash
  12022. +#define a_crash a_crash
  12023. +static inline void a_crash()
  12024. +{
  12025. + *(volatile char *)0=0;
  12026. +}
  12027. +#endif
  12028. +
  12029. +#ifndef a_ctz_64
  12030. +#define a_ctz_64 a_ctz_64
  12031. +static inline int a_ctz_64(uint64_t x)
  12032. +{
  12033. + static const char debruijn64[64] = {
  12034. + 0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28,
  12035. + 62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11,
  12036. + 63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10,
  12037. + 51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12
  12038. + };
  12039. + static const char debruijn32[32] = {
  12040. + 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13,
  12041. + 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14
  12042. + };
  12043. + if (sizeof(long) < 8) {
  12044. + uint32_t y = x;
  12045. + if (!y) {
  12046. + y = x>>32;
  12047. + return 32 + debruijn32[(y&-y)*0x076be629 >> 27];
  12048. + }
  12049. + return debruijn32[(y&-y)*0x076be629 >> 27];
  12050. + }
  12051. + return debruijn64[(x&-x)*0x022fdd63cc95386dull >> 58];
  12052. +}
  12053. +#endif
  12054. +
  12055. +#ifndef a_ctz_l
  12056. +#define a_ctz_l a_ctz_l
  12057. +static inline int a_ctz_l(unsigned long x)
  12058. +{
  12059. + static const char debruijn32[32] = {
  12060. + 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13,
  12061. + 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14
  12062. + };
  12063. + if (sizeof(long) == 8) return a_ctz_64(x);
  12064. + return debruijn32[(x&-x)*0x076be629 >> 27];
  12065. +}
  12066. +#endif
  12067. +
  12068. +#endif
  12069. --- a/src/internal/dynlink.h
  12070. +++ b/src/internal/dynlink.h
  12071. @@ -64,6 +64,10 @@ struct fdpic_dummy_loadmap {
  12072. #define DL_FDPIC 0
  12073. #endif
  12074. +#ifndef DL_NOMMU_SUPPORT
  12075. +#define DL_NOMMU_SUPPORT 0
  12076. +#endif
  12077. +
  12078. #if !DL_FDPIC
  12079. #define IS_RELATIVE(x,s) ( \
  12080. (R_TYPE(x) == REL_RELATIVE) || \
  12081. --- a/src/internal/libc.h
  12082. +++ b/src/internal/libc.h
  12083. @@ -11,13 +11,20 @@ struct __locale_struct {
  12084. const struct __locale_map *volatile cat[6];
  12085. };
  12086. +struct tls_module {
  12087. + struct tls_module *next;
  12088. + void *image;
  12089. + size_t len, size, align, offset;
  12090. +};
  12091. +
  12092. struct __libc {
  12093. int can_do_threads;
  12094. int threaded;
  12095. int secure;
  12096. volatile int threads_minus_1;
  12097. size_t *auxv;
  12098. - size_t tls_size;
  12099. + struct tls_module *tls_head;
  12100. + size_t tls_size, tls_align, tls_cnt;
  12101. size_t page_size;
  12102. struct __locale_struct global_locale;
  12103. };
  12104. --- /dev/null
  12105. +++ b/src/internal/sh/__shcall.c
  12106. @@ -0,0 +1,5 @@
  12107. +__attribute__((__visibility__("hidden")))
  12108. +int __shcall(void *arg, int (*func)(void *))
  12109. +{
  12110. + return func(arg);
  12111. +}
  12112. --- a/src/internal/syscall.h
  12113. +++ b/src/internal/syscall.h
  12114. @@ -17,9 +17,7 @@
  12115. typedef long syscall_arg_t;
  12116. #endif
  12117. -#ifdef SHARED
  12118. __attribute__((visibility("hidden")))
  12119. -#endif
  12120. long __syscall_ret(unsigned long), __syscall(syscall_arg_t, ...),
  12121. __syscall_cp(syscall_arg_t, syscall_arg_t, syscall_arg_t, syscall_arg_t,
  12122. syscall_arg_t, syscall_arg_t, syscall_arg_t);
  12123. @@ -65,7 +63,7 @@ long __syscall_ret(unsigned long), __sys
  12124. #define __syscall_cp(...) __SYSCALL_DISP(__syscall_cp,__VA_ARGS__)
  12125. #define syscall_cp(...) __syscall_ret(__syscall_cp(__VA_ARGS__))
  12126. -#ifdef SYS_socket
  12127. +#ifndef SYSCALL_USE_SOCKETCALL
  12128. #define __socketcall(nm,a,b,c,d,e,f) syscall(SYS_##nm, a, b, c, d, e, f)
  12129. #define __socketcall_cp(nm,a,b,c,d,e,f) syscall_cp(SYS_##nm, a, b, c, d, e, f)
  12130. #else
  12131. --- a/src/internal/version.c
  12132. +++ b/src/internal/version.c
  12133. @@ -1,12 +1,9 @@
  12134. -#ifdef SHARED
  12135. -
  12136. #include "version.h"
  12137. static const char version[] = VERSION;
  12138. +__attribute__((__visibility__("hidden")))
  12139. const char *__libc_get_version()
  12140. {
  12141. return version;
  12142. }
  12143. -
  12144. -#endif
  12145. --- a/src/internal/vis.h
  12146. +++ b/src/internal/vis.h
  12147. @@ -4,10 +4,9 @@
  12148. * override default visibilities to reduce the size and performance costs
  12149. * of position-independent code. */
  12150. -#ifndef CRT
  12151. -#ifdef SHARED
  12152. +#if !defined(CRT) && !defined(__ASSEMBLER__)
  12153. -/* For shared libc.so, all symbols should be protected, but some toolchains
  12154. +/* Conceptually, all symbols should be protected, but some toolchains
  12155. * fail to support copy relocations for protected data, so exclude all
  12156. * exported data symbols. */
  12157. @@ -25,16 +24,4 @@ extern char *optarg, **environ, **__envi
  12158. #pragma GCC visibility push(protected)
  12159. -#elif defined(__PIC__)
  12160. -
  12161. -/* If building static libc.a as position-independent code, try to make
  12162. - * everything hidden except possibly-undefined weak references. */
  12163. -
  12164. -__attribute__((__visibility__("default")))
  12165. -extern void (*const __init_array_start)(), (*const __init_array_end)(),
  12166. - (*const __fini_array_start)(), (*const __fini_array_end)();
  12167. -
  12168. -#pragma GCC visibility push(hidden)
  12169. -
  12170. -#endif
  12171. #endif
  12172. --- /dev/null
  12173. +++ b/src/ldso/__dlsym.c
  12174. @@ -0,0 +1,13 @@
  12175. +#include <dlfcn.h>
  12176. +#include "libc.h"
  12177. +
  12178. +__attribute__((__visibility__("hidden")))
  12179. +void __dl_seterr(const char *, ...);
  12180. +
  12181. +static void *stub_dlsym(void *restrict p, const char *restrict s, void *restrict ra)
  12182. +{
  12183. + __dl_seterr("Symbol not found: %s", s);
  12184. + return 0;
  12185. +}
  12186. +
  12187. +weak_alias(stub_dlsym, __dlsym);
  12188. --- a/src/ldso/arm/dlsym.s
  12189. +++ b/src/ldso/arm/dlsym.s
  12190. @@ -1,3 +1,4 @@
  12191. +.syntax unified
  12192. .text
  12193. .global dlsym
  12194. .hidden __dlsym
  12195. --- /dev/null
  12196. +++ b/src/ldso/arm/find_exidx.c
  12197. @@ -0,0 +1,42 @@
  12198. +#define _GNU_SOURCE
  12199. +#include <link.h>
  12200. +#include <stdint.h>
  12201. +
  12202. +struct find_exidx_data {
  12203. + uintptr_t pc, exidx_start;
  12204. + int exidx_len;
  12205. +};
  12206. +
  12207. +static int find_exidx(struct dl_phdr_info *info, size_t size, void *ptr)
  12208. +{
  12209. + struct find_exidx_data *data = ptr;
  12210. + const ElfW(Phdr) *phdr = info->dlpi_phdr;
  12211. + uintptr_t addr, exidx_start = 0;
  12212. + int i, match = 0, exidx_len = 0;
  12213. +
  12214. + for (i = info->dlpi_phnum; i > 0; i--, phdr++) {
  12215. + addr = info->dlpi_addr + phdr->p_vaddr;
  12216. + switch (phdr->p_type) {
  12217. + case PT_LOAD:
  12218. + match |= data->pc >= addr && data->pc < addr + phdr->p_memsz;
  12219. + break;
  12220. + case PT_ARM_EXIDX:
  12221. + exidx_start = addr;
  12222. + exidx_len = phdr->p_memsz;
  12223. + break;
  12224. + }
  12225. + }
  12226. + data->exidx_start = exidx_start;
  12227. + data->exidx_len = exidx_len;
  12228. + return match;
  12229. +}
  12230. +
  12231. +uintptr_t __gnu_Unwind_Find_exidx(uintptr_t pc, int *pcount)
  12232. +{
  12233. + struct find_exidx_data data;
  12234. + data.pc = pc;
  12235. + if (dl_iterate_phdr(find_exidx, &data) <= 0)
  12236. + return 0;
  12237. + *pcount = data.exidx_len / 8;
  12238. + return data.exidx_start;
  12239. +}
  12240. --- a/src/ldso/dl_iterate_phdr.c
  12241. +++ b/src/ldso/dl_iterate_phdr.c
  12242. @@ -1,12 +1,10 @@
  12243. -#ifndef SHARED
  12244. -
  12245. #include <elf.h>
  12246. #include <link.h>
  12247. #include "libc.h"
  12248. #define AUX_CNT 38
  12249. -int dl_iterate_phdr(int(*callback)(struct dl_phdr_info *info, size_t size, void *data), void *data)
  12250. +static int static_dl_iterate_phdr(int(*callback)(struct dl_phdr_info *info, size_t size, void *data), void *data)
  12251. {
  12252. unsigned char *p;
  12253. ElfW(Phdr) *phdr, *tls_phdr=0;
  12254. @@ -40,4 +38,5 @@ int dl_iterate_phdr(int(*callback)(struc
  12255. }
  12256. return (callback)(&info, sizeof (info), data);
  12257. }
  12258. -#endif
  12259. +
  12260. +weak_alias(static_dl_iterate_phdr, dl_iterate_phdr);
  12261. --- a/src/ldso/dladdr.c
  12262. +++ b/src/ldso/dladdr.c
  12263. @@ -1,9 +1,10 @@
  12264. #define _GNU_SOURCE
  12265. #include <dlfcn.h>
  12266. +#include "libc.h"
  12267. -int __dladdr(const void *, Dl_info *);
  12268. -
  12269. -int dladdr(const void *addr, Dl_info *info)
  12270. +static int stub_dladdr(const void *addr, Dl_info *info)
  12271. {
  12272. - return __dladdr(addr, info);
  12273. + return 0;
  12274. }
  12275. +
  12276. +weak_alias(stub_dladdr, dladdr);
  12277. --- /dev/null
  12278. +++ b/src/ldso/dlclose.c
  12279. @@ -0,0 +1,9 @@
  12280. +#include <dlfcn.h>
  12281. +
  12282. +__attribute__((__visibility__("hidden")))
  12283. +int __dl_invalid_handle(void *);
  12284. +
  12285. +int dlclose(void *p)
  12286. +{
  12287. + return __dl_invalid_handle(p);
  12288. +}
  12289. --- /dev/null
  12290. +++ b/src/ldso/dlerror.c
  12291. @@ -0,0 +1,64 @@
  12292. +#include <dlfcn.h>
  12293. +#include <stdlib.h>
  12294. +#include <stdarg.h>
  12295. +#include "pthread_impl.h"
  12296. +#include "libc.h"
  12297. +
  12298. +char *dlerror()
  12299. +{
  12300. + pthread_t self = __pthread_self();
  12301. + if (!self->dlerror_flag) return 0;
  12302. + self->dlerror_flag = 0;
  12303. + char *s = self->dlerror_buf;
  12304. + if (s == (void *)-1)
  12305. + return "Dynamic linker failed to allocate memory for error message";
  12306. + else
  12307. + return s;
  12308. +}
  12309. +
  12310. +void __dl_thread_cleanup(void)
  12311. +{
  12312. + pthread_t self = __pthread_self();
  12313. + if (self->dlerror_buf != (void *)-1)
  12314. + free(self->dlerror_buf);
  12315. +}
  12316. +
  12317. +__attribute__((__visibility__("hidden")))
  12318. +void __dl_vseterr(const char *fmt, va_list ap)
  12319. +{
  12320. + va_list ap2;
  12321. + va_copy(ap2, ap);
  12322. + pthread_t self = __pthread_self();
  12323. + if (self->dlerror_buf != (void *)-1)
  12324. + free(self->dlerror_buf);
  12325. + size_t len = vsnprintf(0, 0, fmt, ap2);
  12326. + va_end(ap2);
  12327. + char *buf = malloc(len+1);
  12328. + if (buf) {
  12329. + vsnprintf(buf, len+1, fmt, ap);
  12330. + } else {
  12331. + buf = (void *)-1;
  12332. + }
  12333. + self->dlerror_buf = buf;
  12334. + self->dlerror_flag = 1;
  12335. +}
  12336. +
  12337. +__attribute__((__visibility__("hidden")))
  12338. +void __dl_seterr(const char *fmt, ...)
  12339. +{
  12340. + va_list ap;
  12341. + va_start(ap, fmt);
  12342. + __dl_vseterr(fmt, ap);
  12343. + va_end(ap);
  12344. +}
  12345. +
  12346. +__attribute__((__visibility__("hidden")))
  12347. +int __dl_invalid_handle(void *);
  12348. +
  12349. +static int stub_invalid_handle(void *h)
  12350. +{
  12351. + __dl_seterr("Invalid library handle %p", (void *)h);
  12352. + return 1;
  12353. +}
  12354. +
  12355. +weak_alias(stub_invalid_handle, __dl_invalid_handle);
  12356. --- a/src/ldso/dlinfo.c
  12357. +++ b/src/ldso/dlinfo.c
  12358. @@ -1,9 +1,19 @@
  12359. #define _GNU_SOURCE
  12360. #include <dlfcn.h>
  12361. -int __dlinfo(void *, int, void *);
  12362. +__attribute__((__visibility__("hidden")))
  12363. +int __dl_invalid_handle(void *);
  12364. +
  12365. +__attribute__((__visibility__("hidden")))
  12366. +void __dl_seterr(const char *, ...);
  12367. int dlinfo(void *dso, int req, void *res)
  12368. {
  12369. - return __dlinfo(dso, req, res);
  12370. + if (__dl_invalid_handle(dso)) return -1;
  12371. + if (req != RTLD_DI_LINKMAP) {
  12372. + __dl_seterr("Unsupported request %d", req);
  12373. + return -1;
  12374. + }
  12375. + *(struct link_map **)res = dso;
  12376. + return 0;
  12377. }
  12378. --- /dev/null
  12379. +++ b/src/ldso/dlopen.c
  12380. @@ -0,0 +1,13 @@
  12381. +#include <dlfcn.h>
  12382. +#include "libc.h"
  12383. +
  12384. +__attribute__((__visibility__("hidden")))
  12385. +void __dl_seterr(const char *, ...);
  12386. +
  12387. +static void *stub_dlopen(const char *file, int mode)
  12388. +{
  12389. + __dl_seterr("Dynamic loading not supported");
  12390. + return 0;
  12391. +}
  12392. +
  12393. +weak_alias(stub_dlopen, dlopen);
  12394. --- a/src/ldso/dlstart.c
  12395. +++ /dev/null
  12396. @@ -1,150 +0,0 @@
  12397. -#include <stddef.h>
  12398. -#include "dynlink.h"
  12399. -
  12400. -#ifdef SHARED
  12401. -
  12402. -#ifndef START
  12403. -#define START "_dlstart"
  12404. -#endif
  12405. -
  12406. -#include "crt_arch.h"
  12407. -
  12408. -#ifndef GETFUNCSYM
  12409. -#define GETFUNCSYM(fp, sym, got) do { \
  12410. - __attribute__((__visibility__("hidden"))) void sym(); \
  12411. - static void (*static_func_ptr)() = sym; \
  12412. - __asm__ __volatile__ ( "" : "+m"(static_func_ptr) : : "memory"); \
  12413. - *(fp) = static_func_ptr; } while(0)
  12414. -#endif
  12415. -
  12416. -__attribute__((__visibility__("hidden")))
  12417. -void _dlstart_c(size_t *sp, size_t *dynv)
  12418. -{
  12419. - size_t i, aux[AUX_CNT], dyn[DYN_CNT];
  12420. - size_t *rel, rel_size, base;
  12421. -
  12422. - int argc = *sp;
  12423. - char **argv = (void *)(sp+1);
  12424. -
  12425. - for (i=argc+1; argv[i]; i++);
  12426. - size_t *auxv = (void *)(argv+i+1);
  12427. -
  12428. - for (i=0; i<AUX_CNT; i++) aux[i] = 0;
  12429. - for (i=0; auxv[i]; i+=2) if (auxv[i]<AUX_CNT)
  12430. - aux[auxv[i]] = auxv[i+1];
  12431. -
  12432. -#if DL_FDPIC
  12433. - struct fdpic_loadseg *segs, fakeseg;
  12434. - size_t j;
  12435. - if (dynv) {
  12436. - /* crt_arch.h entry point asm is responsible for reserving
  12437. - * space and moving the extra fdpic arguments to the stack
  12438. - * vector where they are easily accessible from C. */
  12439. - segs = ((struct fdpic_loadmap *)(sp[-1] ? sp[-1] : sp[-2]))->segs;
  12440. - } else {
  12441. - /* If dynv is null, the entry point was started from loader
  12442. - * that is not fdpic-aware. We can assume normal fixed-
  12443. - * displacement ELF loading was performed, but when ldso was
  12444. - * run as a command, finding the Ehdr is a heursitic: we
  12445. - * have to assume Phdrs start in the first 4k of the file. */
  12446. - base = aux[AT_BASE];
  12447. - if (!base) base = aux[AT_PHDR] & -4096;
  12448. - segs = &fakeseg;
  12449. - segs[0].addr = base;
  12450. - segs[0].p_vaddr = 0;
  12451. - segs[0].p_memsz = -1;
  12452. - Ehdr *eh = (void *)base;
  12453. - Phdr *ph = (void *)(base + eh->e_phoff);
  12454. - size_t phnum = eh->e_phnum;
  12455. - size_t phent = eh->e_phentsize;
  12456. - while (phnum-- && ph->p_type != PT_DYNAMIC)
  12457. - ph = (void *)((size_t)ph + phent);
  12458. - dynv = (void *)(base + ph->p_vaddr);
  12459. - }
  12460. -#endif
  12461. -
  12462. - for (i=0; i<DYN_CNT; i++) dyn[i] = 0;
  12463. - for (i=0; dynv[i]; i+=2) if (dynv[i]<DYN_CNT)
  12464. - dyn[dynv[i]] = dynv[i+1];
  12465. -
  12466. -#if DL_FDPIC
  12467. - for (i=0; i<DYN_CNT; i++) {
  12468. - if (i==DT_RELASZ || i==DT_RELSZ) continue;
  12469. - if (!dyn[i]) continue;
  12470. - for (j=0; dyn[i]-segs[j].p_vaddr >= segs[j].p_memsz; j++);
  12471. - dyn[i] += segs[j].addr - segs[j].p_vaddr;
  12472. - }
  12473. - base = 0;
  12474. -
  12475. - const Sym *syms = (void *)dyn[DT_SYMTAB];
  12476. -
  12477. - rel = (void *)dyn[DT_RELA];
  12478. - rel_size = dyn[DT_RELASZ];
  12479. - for (; rel_size; rel+=3, rel_size-=3*sizeof(size_t)) {
  12480. - if (!IS_RELATIVE(rel[1], syms)) continue;
  12481. - for (j=0; rel[0]-segs[j].p_vaddr >= segs[j].p_memsz; j++);
  12482. - size_t *rel_addr = (void *)
  12483. - (rel[0] + segs[j].addr - segs[j].p_vaddr);
  12484. - if (R_TYPE(rel[1]) == REL_FUNCDESC_VAL) {
  12485. - *rel_addr += segs[rel_addr[1]].addr
  12486. - - segs[rel_addr[1]].p_vaddr
  12487. - + syms[R_SYM(rel[1])].st_value;
  12488. - rel_addr[1] = dyn[DT_PLTGOT];
  12489. - } else {
  12490. - size_t val = syms[R_SYM(rel[1])].st_value;
  12491. - for (j=0; val-segs[j].p_vaddr >= segs[j].p_memsz; j++);
  12492. - *rel_addr = rel[2] + segs[j].addr - segs[j].p_vaddr + val;
  12493. - }
  12494. - }
  12495. -#else
  12496. - /* If the dynamic linker is invoked as a command, its load
  12497. - * address is not available in the aux vector. Instead, compute
  12498. - * the load address as the difference between &_DYNAMIC and the
  12499. - * virtual address in the PT_DYNAMIC program header. */
  12500. - base = aux[AT_BASE];
  12501. - if (!base) {
  12502. - size_t phnum = aux[AT_PHNUM];
  12503. - size_t phentsize = aux[AT_PHENT];
  12504. - Phdr *ph = (void *)aux[AT_PHDR];
  12505. - for (i=phnum; i--; ph = (void *)((char *)ph + phentsize)) {
  12506. - if (ph->p_type == PT_DYNAMIC) {
  12507. - base = (size_t)dynv - ph->p_vaddr;
  12508. - break;
  12509. - }
  12510. - }
  12511. - }
  12512. -
  12513. - /* MIPS uses an ugly packed form for GOT relocations. Since we
  12514. - * can't make function calls yet and the code is tiny anyway,
  12515. - * it's simply inlined here. */
  12516. - if (NEED_MIPS_GOT_RELOCS) {
  12517. - size_t local_cnt = 0;
  12518. - size_t *got = (void *)(base + dyn[DT_PLTGOT]);
  12519. - for (i=0; dynv[i]; i+=2) if (dynv[i]==DT_MIPS_LOCAL_GOTNO)
  12520. - local_cnt = dynv[i+1];
  12521. - for (i=0; i<local_cnt; i++) got[i] += base;
  12522. - }
  12523. -
  12524. - rel = (void *)(base+dyn[DT_REL]);
  12525. - rel_size = dyn[DT_RELSZ];
  12526. - for (; rel_size; rel+=2, rel_size-=2*sizeof(size_t)) {
  12527. - if (!IS_RELATIVE(rel[1], 0)) continue;
  12528. - size_t *rel_addr = (void *)(base + rel[0]);
  12529. - *rel_addr += base;
  12530. - }
  12531. -
  12532. - rel = (void *)(base+dyn[DT_RELA]);
  12533. - rel_size = dyn[DT_RELASZ];
  12534. - for (; rel_size; rel+=3, rel_size-=3*sizeof(size_t)) {
  12535. - if (!IS_RELATIVE(rel[1], 0)) continue;
  12536. - size_t *rel_addr = (void *)(base + rel[0]);
  12537. - *rel_addr = base + rel[2];
  12538. - }
  12539. -#endif
  12540. -
  12541. - stage2_func dls2;
  12542. - GETFUNCSYM(&dls2, __dls2, base+dyn[DT_PLTGOT]);
  12543. - dls2((void *)base, sp);
  12544. -}
  12545. -
  12546. -#endif
  12547. --- a/src/ldso/dynlink.c
  12548. +++ /dev/null
  12549. @@ -1,2000 +0,0 @@
  12550. -#define _GNU_SOURCE
  12551. -#include <stdio.h>
  12552. -#include <stdlib.h>
  12553. -#include <stdarg.h>
  12554. -#include <stddef.h>
  12555. -#include <string.h>
  12556. -#include <unistd.h>
  12557. -#include <stdint.h>
  12558. -#include <elf.h>
  12559. -#include <sys/mman.h>
  12560. -#include <limits.h>
  12561. -#include <fcntl.h>
  12562. -#include <sys/stat.h>
  12563. -#include <errno.h>
  12564. -#include <link.h>
  12565. -#include <setjmp.h>
  12566. -#include <pthread.h>
  12567. -#include <ctype.h>
  12568. -#include <dlfcn.h>
  12569. -#include "pthread_impl.h"
  12570. -#include "libc.h"
  12571. -#include "dynlink.h"
  12572. -
  12573. -static void error(const char *, ...);
  12574. -
  12575. -#ifdef SHARED
  12576. -
  12577. -#define MAXP2(a,b) (-(-(a)&-(b)))
  12578. -#define ALIGN(x,y) ((x)+(y)-1 & -(y))
  12579. -
  12580. -struct debug {
  12581. - int ver;
  12582. - void *head;
  12583. - void (*bp)(void);
  12584. - int state;
  12585. - void *base;
  12586. -};
  12587. -
  12588. -struct td_index {
  12589. - size_t args[2];
  12590. - struct td_index *next;
  12591. -};
  12592. -
  12593. -struct dso {
  12594. -#if DL_FDPIC
  12595. - struct fdpic_loadmap *loadmap;
  12596. -#else
  12597. - unsigned char *base;
  12598. -#endif
  12599. - char *name;
  12600. - size_t *dynv;
  12601. - struct dso *next, *prev;
  12602. -
  12603. - Phdr *phdr;
  12604. - int phnum;
  12605. - size_t phentsize;
  12606. - int refcnt;
  12607. - Sym *syms;
  12608. - uint32_t *hashtab;
  12609. - uint32_t *ghashtab;
  12610. - int16_t *versym;
  12611. - char *strings;
  12612. - unsigned char *map;
  12613. - size_t map_len;
  12614. - dev_t dev;
  12615. - ino_t ino;
  12616. - signed char global;
  12617. - char relocated;
  12618. - char constructed;
  12619. - char kernel_mapped;
  12620. - struct dso **deps, *needed_by;
  12621. - char *rpath_orig, *rpath;
  12622. - void *tls_image;
  12623. - size_t tls_len, tls_size, tls_align, tls_id, tls_offset;
  12624. - size_t relro_start, relro_end;
  12625. - void **new_dtv;
  12626. - unsigned char *new_tls;
  12627. - volatile int new_dtv_idx, new_tls_idx;
  12628. - struct td_index *td_index;
  12629. - struct dso *fini_next;
  12630. - char *shortname;
  12631. -#if DL_FDPIC
  12632. - unsigned char *base;
  12633. -#else
  12634. - struct fdpic_loadmap *loadmap;
  12635. -#endif
  12636. - struct funcdesc {
  12637. - void *addr;
  12638. - size_t *got;
  12639. - } *funcdescs;
  12640. - size_t *got;
  12641. - char buf[];
  12642. -};
  12643. -
  12644. -struct symdef {
  12645. - Sym *sym;
  12646. - struct dso *dso;
  12647. -};
  12648. -
  12649. -int __init_tp(void *);
  12650. -void __init_libc(char **, char *);
  12651. -
  12652. -const char *__libc_get_version(void);
  12653. -
  12654. -static struct builtin_tls {
  12655. - char c;
  12656. - struct pthread pt;
  12657. - void *space[16];
  12658. -} builtin_tls[1];
  12659. -#define MIN_TLS_ALIGN offsetof(struct builtin_tls, pt)
  12660. -
  12661. -#define ADDEND_LIMIT 4096
  12662. -static size_t *saved_addends, *apply_addends_to;
  12663. -
  12664. -static struct dso ldso;
  12665. -static struct dso *head, *tail, *fini_head;
  12666. -static char *env_path, *sys_path;
  12667. -static unsigned long long gencnt;
  12668. -static int runtime;
  12669. -static int ldd_mode;
  12670. -static int ldso_fail;
  12671. -static int noload;
  12672. -static jmp_buf *rtld_fail;
  12673. -static pthread_rwlock_t lock;
  12674. -static struct debug debug;
  12675. -static size_t tls_cnt, tls_offset, tls_align = MIN_TLS_ALIGN;
  12676. -static size_t static_tls_cnt;
  12677. -static pthread_mutex_t init_fini_lock = { ._m_type = PTHREAD_MUTEX_RECURSIVE };
  12678. -static struct fdpic_loadmap *app_loadmap;
  12679. -static struct fdpic_dummy_loadmap app_dummy_loadmap;
  12680. -
  12681. -struct debug *_dl_debug_addr = &debug;
  12682. -
  12683. -static int dl_strcmp(const char *l, const char *r)
  12684. -{
  12685. - for (; *l==*r && *l; l++, r++);
  12686. - return *(unsigned char *)l - *(unsigned char *)r;
  12687. -}
  12688. -#define strcmp(l,r) dl_strcmp(l,r)
  12689. -
  12690. -/* Compute load address for a virtual address in a given dso. */
  12691. -#if DL_FDPIC
  12692. -static void *laddr(const struct dso *p, size_t v)
  12693. -{
  12694. - size_t j=0;
  12695. - if (!p->loadmap) return p->base + v;
  12696. - for (j=0; v-p->loadmap->segs[j].p_vaddr >= p->loadmap->segs[j].p_memsz; j++);
  12697. - return (void *)(v - p->loadmap->segs[j].p_vaddr + p->loadmap->segs[j].addr);
  12698. -}
  12699. -#define fpaddr(p, v) ((void (*)())&(struct funcdesc){ \
  12700. - laddr(p, v), (p)->got })
  12701. -#else
  12702. -#define laddr(p, v) (void *)((p)->base + (v))
  12703. -#define fpaddr(p, v) ((void (*)())laddr(p, v))
  12704. -#endif
  12705. -
  12706. -static void decode_vec(size_t *v, size_t *a, size_t cnt)
  12707. -{
  12708. - size_t i;
  12709. - for (i=0; i<cnt; i++) a[i] = 0;
  12710. - for (; v[0]; v+=2) if (v[0]-1<cnt-1) {
  12711. - a[0] |= 1UL<<v[0];
  12712. - a[v[0]] = v[1];
  12713. - }
  12714. -}
  12715. -
  12716. -static int search_vec(size_t *v, size_t *r, size_t key)
  12717. -{
  12718. - for (; v[0]!=key; v+=2)
  12719. - if (!v[0]) return 0;
  12720. - *r = v[1];
  12721. - return 1;
  12722. -}
  12723. -
  12724. -static uint32_t sysv_hash(const char *s0)
  12725. -{
  12726. - const unsigned char *s = (void *)s0;
  12727. - uint_fast32_t h = 0;
  12728. - while (*s) {
  12729. - h = 16*h + *s++;
  12730. - h ^= h>>24 & 0xf0;
  12731. - }
  12732. - return h & 0xfffffff;
  12733. -}
  12734. -
  12735. -static uint32_t gnu_hash(const char *s0)
  12736. -{
  12737. - const unsigned char *s = (void *)s0;
  12738. - uint_fast32_t h = 5381;
  12739. - for (; *s; s++)
  12740. - h += h*32 + *s;
  12741. - return h;
  12742. -}
  12743. -
  12744. -static Sym *sysv_lookup(const char *s, uint32_t h, struct dso *dso)
  12745. -{
  12746. - size_t i;
  12747. - Sym *syms = dso->syms;
  12748. - uint32_t *hashtab = dso->hashtab;
  12749. - char *strings = dso->strings;
  12750. - for (i=hashtab[2+h%hashtab[0]]; i; i=hashtab[2+hashtab[0]+i]) {
  12751. - if ((!dso->versym || dso->versym[i] >= 0)
  12752. - && (!strcmp(s, strings+syms[i].st_name)))
  12753. - return syms+i;
  12754. - }
  12755. - return 0;
  12756. -}
  12757. -
  12758. -static Sym *gnu_lookup(uint32_t h1, uint32_t *hashtab, struct dso *dso, const char *s)
  12759. -{
  12760. - uint32_t nbuckets = hashtab[0];
  12761. - uint32_t *buckets = hashtab + 4 + hashtab[2]*(sizeof(size_t)/4);
  12762. - uint32_t i = buckets[h1 % nbuckets];
  12763. -
  12764. - if (!i) return 0;
  12765. -
  12766. - uint32_t *hashval = buckets + nbuckets + (i - hashtab[1]);
  12767. -
  12768. - for (h1 |= 1; ; i++) {
  12769. - uint32_t h2 = *hashval++;
  12770. - if ((h1 == (h2|1)) && (!dso->versym || dso->versym[i] >= 0)
  12771. - && !strcmp(s, dso->strings + dso->syms[i].st_name))
  12772. - return dso->syms+i;
  12773. - if (h2 & 1) break;
  12774. - }
  12775. -
  12776. - return 0;
  12777. -}
  12778. -
  12779. -static Sym *gnu_lookup_filtered(uint32_t h1, uint32_t *hashtab, struct dso *dso, const char *s, uint32_t fofs, size_t fmask)
  12780. -{
  12781. - const size_t *bloomwords = (const void *)(hashtab+4);
  12782. - size_t f = bloomwords[fofs & (hashtab[2]-1)];
  12783. - if (!(f & fmask)) return 0;
  12784. -
  12785. - f >>= (h1 >> hashtab[3]) % (8 * sizeof f);
  12786. - if (!(f & 1)) return 0;
  12787. -
  12788. - return gnu_lookup(h1, hashtab, dso, s);
  12789. -}
  12790. -
  12791. -#define OK_TYPES (1<<STT_NOTYPE | 1<<STT_OBJECT | 1<<STT_FUNC | 1<<STT_COMMON | 1<<STT_TLS)
  12792. -#define OK_BINDS (1<<STB_GLOBAL | 1<<STB_WEAK | 1<<STB_GNU_UNIQUE)
  12793. -
  12794. -#ifndef ARCH_SYM_REJECT_UND
  12795. -#define ARCH_SYM_REJECT_UND(s) 0
  12796. -#endif
  12797. -
  12798. -static struct symdef find_sym(struct dso *dso, const char *s, int need_def)
  12799. -{
  12800. - uint32_t h = 0, gh, gho, *ght;
  12801. - size_t ghm = 0;
  12802. - struct symdef def = {0};
  12803. - for (; dso; dso=dso->next) {
  12804. - Sym *sym;
  12805. - if (!dso->global) continue;
  12806. - if ((ght = dso->ghashtab)) {
  12807. - if (!ghm) {
  12808. - gh = gnu_hash(s);
  12809. - int maskbits = 8 * sizeof ghm;
  12810. - gho = gh / maskbits;
  12811. - ghm = 1ul << gh % maskbits;
  12812. - }
  12813. - sym = gnu_lookup_filtered(gh, ght, dso, s, gho, ghm);
  12814. - } else {
  12815. - if (!h) h = sysv_hash(s);
  12816. - sym = sysv_lookup(s, h, dso);
  12817. - }
  12818. - if (!sym) continue;
  12819. - if (!sym->st_shndx)
  12820. - if (need_def || (sym->st_info&0xf) == STT_TLS
  12821. - || ARCH_SYM_REJECT_UND(sym))
  12822. - continue;
  12823. - if (!sym->st_value)
  12824. - if ((sym->st_info&0xf) != STT_TLS)
  12825. - continue;
  12826. - if (!(1<<(sym->st_info&0xf) & OK_TYPES)) continue;
  12827. - if (!(1<<(sym->st_info>>4) & OK_BINDS)) continue;
  12828. -
  12829. - if (def.sym && sym->st_info>>4 == STB_WEAK) continue;
  12830. - def.sym = sym;
  12831. - def.dso = dso;
  12832. - if (sym->st_info>>4 == STB_GLOBAL) break;
  12833. - }
  12834. - return def;
  12835. -}
  12836. -
  12837. -__attribute__((__visibility__("hidden")))
  12838. -ptrdiff_t __tlsdesc_static(), __tlsdesc_dynamic();
  12839. -
  12840. -static void do_relocs(struct dso *dso, size_t *rel, size_t rel_size, size_t stride)
  12841. -{
  12842. - unsigned char *base = dso->base;
  12843. - Sym *syms = dso->syms;
  12844. - char *strings = dso->strings;
  12845. - Sym *sym;
  12846. - const char *name;
  12847. - void *ctx;
  12848. - int type;
  12849. - int sym_index;
  12850. - struct symdef def;
  12851. - size_t *reloc_addr;
  12852. - size_t sym_val;
  12853. - size_t tls_val;
  12854. - size_t addend;
  12855. - int skip_relative = 0, reuse_addends = 0, save_slot = 0;
  12856. -
  12857. - if (dso == &ldso) {
  12858. - /* Only ldso's REL table needs addend saving/reuse. */
  12859. - if (rel == apply_addends_to)
  12860. - reuse_addends = 1;
  12861. - skip_relative = 1;
  12862. - }
  12863. -
  12864. - for (; rel_size; rel+=stride, rel_size-=stride*sizeof(size_t)) {
  12865. - if (skip_relative && IS_RELATIVE(rel[1], dso->syms)) continue;
  12866. - type = R_TYPE(rel[1]);
  12867. - if (type == REL_NONE) continue;
  12868. - sym_index = R_SYM(rel[1]);
  12869. - reloc_addr = laddr(dso, rel[0]);
  12870. - if (sym_index) {
  12871. - sym = syms + sym_index;
  12872. - name = strings + sym->st_name;
  12873. - ctx = type==REL_COPY ? head->next : head;
  12874. - def = (sym->st_info&0xf) == STT_SECTION
  12875. - ? (struct symdef){ .dso = dso, .sym = sym }
  12876. - : find_sym(ctx, name, type==REL_PLT);
  12877. - if (!def.sym && (sym->st_shndx != SHN_UNDEF
  12878. - || sym->st_info>>4 != STB_WEAK)) {
  12879. - error("Error relocating %s: %s: symbol not found",
  12880. - dso->name, name);
  12881. - if (runtime) longjmp(*rtld_fail, 1);
  12882. - continue;
  12883. - }
  12884. - } else {
  12885. - sym = 0;
  12886. - def.sym = 0;
  12887. - def.dso = dso;
  12888. - }
  12889. -
  12890. - if (stride > 2) {
  12891. - addend = rel[2];
  12892. - } else if (type==REL_GOT || type==REL_PLT|| type==REL_COPY) {
  12893. - addend = 0;
  12894. - } else if (reuse_addends) {
  12895. - /* Save original addend in stage 2 where the dso
  12896. - * chain consists of just ldso; otherwise read back
  12897. - * saved addend since the inline one was clobbered. */
  12898. - if (head==&ldso)
  12899. - saved_addends[save_slot] = *reloc_addr;
  12900. - addend = saved_addends[save_slot++];
  12901. - } else {
  12902. - addend = *reloc_addr;
  12903. - }
  12904. -
  12905. - sym_val = def.sym ? (size_t)laddr(def.dso, def.sym->st_value) : 0;
  12906. - tls_val = def.sym ? def.sym->st_value : 0;
  12907. -
  12908. - switch(type) {
  12909. - case REL_NONE:
  12910. - break;
  12911. - case REL_OFFSET:
  12912. - addend -= (size_t)reloc_addr;
  12913. - case REL_SYMBOLIC:
  12914. - case REL_GOT:
  12915. - case REL_PLT:
  12916. - *reloc_addr = sym_val + addend;
  12917. - break;
  12918. - case REL_RELATIVE:
  12919. - *reloc_addr = (size_t)base + addend;
  12920. - break;
  12921. - case REL_SYM_OR_REL:
  12922. - if (sym) *reloc_addr = sym_val + addend;
  12923. - else *reloc_addr = (size_t)base + addend;
  12924. - break;
  12925. - case REL_COPY:
  12926. - memcpy(reloc_addr, (void *)sym_val, sym->st_size);
  12927. - break;
  12928. - case REL_OFFSET32:
  12929. - *(uint32_t *)reloc_addr = sym_val + addend
  12930. - - (size_t)reloc_addr;
  12931. - break;
  12932. - case REL_FUNCDESC:
  12933. - *reloc_addr = def.sym ? (size_t)(def.dso->funcdescs
  12934. - + (def.sym - def.dso->syms)) : 0;
  12935. - break;
  12936. - case REL_FUNCDESC_VAL:
  12937. - if ((sym->st_info&0xf) == STT_SECTION) *reloc_addr += sym_val;
  12938. - else *reloc_addr = sym_val;
  12939. - reloc_addr[1] = def.sym ? (size_t)def.dso->got : 0;
  12940. - break;
  12941. - case REL_DTPMOD:
  12942. - *reloc_addr = def.dso->tls_id;
  12943. - break;
  12944. - case REL_DTPOFF:
  12945. - *reloc_addr = tls_val + addend - DTP_OFFSET;
  12946. - break;
  12947. -#ifdef TLS_ABOVE_TP
  12948. - case REL_TPOFF:
  12949. - *reloc_addr = tls_val + def.dso->tls_offset + TPOFF_K + addend;
  12950. - break;
  12951. -#else
  12952. - case REL_TPOFF:
  12953. - *reloc_addr = tls_val - def.dso->tls_offset + addend;
  12954. - break;
  12955. - case REL_TPOFF_NEG:
  12956. - *reloc_addr = def.dso->tls_offset - tls_val + addend;
  12957. - break;
  12958. -#endif
  12959. - case REL_TLSDESC:
  12960. - if (stride<3) addend = reloc_addr[1];
  12961. - if (runtime && def.dso->tls_id >= static_tls_cnt) {
  12962. - struct td_index *new = malloc(sizeof *new);
  12963. - if (!new) {
  12964. - error(
  12965. - "Error relocating %s: cannot allocate TLSDESC for %s",
  12966. - dso->name, sym ? name : "(local)" );
  12967. - longjmp(*rtld_fail, 1);
  12968. - }
  12969. - new->next = dso->td_index;
  12970. - dso->td_index = new;
  12971. - new->args[0] = def.dso->tls_id;
  12972. - new->args[1] = tls_val + addend;
  12973. - reloc_addr[0] = (size_t)__tlsdesc_dynamic;
  12974. - reloc_addr[1] = (size_t)new;
  12975. - } else {
  12976. - reloc_addr[0] = (size_t)__tlsdesc_static;
  12977. -#ifdef TLS_ABOVE_TP
  12978. - reloc_addr[1] = tls_val + def.dso->tls_offset
  12979. - + TPOFF_K + addend;
  12980. -#else
  12981. - reloc_addr[1] = tls_val - def.dso->tls_offset
  12982. - + addend;
  12983. -#endif
  12984. - }
  12985. - break;
  12986. - default:
  12987. - error("Error relocating %s: unsupported relocation type %d",
  12988. - dso->name, type);
  12989. - if (runtime) longjmp(*rtld_fail, 1);
  12990. - continue;
  12991. - }
  12992. - }
  12993. -}
  12994. -
  12995. -/* A huge hack: to make up for the wastefulness of shared libraries
  12996. - * needing at least a page of dirty memory even if they have no global
  12997. - * data, we reclaim the gaps at the beginning and end of writable maps
  12998. - * and "donate" them to the heap by setting up minimal malloc
  12999. - * structures and then freeing them. */
  13000. -
  13001. -static void reclaim(struct dso *dso, size_t start, size_t end)
  13002. -{
  13003. - size_t *a, *z;
  13004. - if (start >= dso->relro_start && start < dso->relro_end) start = dso->relro_end;
  13005. - if (end >= dso->relro_start && end < dso->relro_end) end = dso->relro_start;
  13006. - start = start + 6*sizeof(size_t)-1 & -4*sizeof(size_t);
  13007. - end = (end & -4*sizeof(size_t)) - 2*sizeof(size_t);
  13008. - if (start>end || end-start < 4*sizeof(size_t)) return;
  13009. - a = laddr(dso, start);
  13010. - z = laddr(dso, end);
  13011. - a[-2] = 1;
  13012. - a[-1] = z[0] = end-start + 2*sizeof(size_t) | 1;
  13013. - z[1] = 1;
  13014. - free(a);
  13015. -}
  13016. -
  13017. -static void reclaim_gaps(struct dso *dso)
  13018. -{
  13019. - Phdr *ph = dso->phdr;
  13020. - size_t phcnt = dso->phnum;
  13021. -
  13022. - if (DL_FDPIC) return; // FIXME
  13023. - for (; phcnt--; ph=(void *)((char *)ph+dso->phentsize)) {
  13024. - if (ph->p_type!=PT_LOAD) continue;
  13025. - if ((ph->p_flags&(PF_R|PF_W))!=(PF_R|PF_W)) continue;
  13026. - reclaim(dso, ph->p_vaddr & -PAGE_SIZE, ph->p_vaddr);
  13027. - reclaim(dso, ph->p_vaddr+ph->p_memsz,
  13028. - ph->p_vaddr+ph->p_memsz+PAGE_SIZE-1 & -PAGE_SIZE);
  13029. - }
  13030. -}
  13031. -
  13032. -static void *mmap_fixed(void *p, size_t n, int prot, int flags, int fd, off_t off)
  13033. -{
  13034. - char *q = mmap(p, n, prot, flags, fd, off);
  13035. - if (q != MAP_FAILED || errno != EINVAL) return q;
  13036. - /* Fallbacks for MAP_FIXED failure on NOMMU kernels. */
  13037. - if (flags & MAP_ANONYMOUS) {
  13038. - memset(p, 0, n);
  13039. - return p;
  13040. - }
  13041. - ssize_t r;
  13042. - if (lseek(fd, off, SEEK_SET) < 0) return MAP_FAILED;
  13043. - for (q=p; n; q+=r, off+=r, n-=r) {
  13044. - r = read(fd, q, n);
  13045. - if (r < 0 && errno != EINTR) return MAP_FAILED;
  13046. - if (!r) {
  13047. - memset(q, 0, n);
  13048. - break;
  13049. - }
  13050. - }
  13051. - return p;
  13052. -}
  13053. -
  13054. -static void unmap_library(struct dso *dso)
  13055. -{
  13056. - if (dso->loadmap) {
  13057. - size_t i;
  13058. - for (i=0; i<dso->loadmap->nsegs; i++) {
  13059. - if (!dso->loadmap->segs[i].p_memsz)
  13060. - continue;
  13061. - munmap((void *)dso->loadmap->segs[i].addr,
  13062. - dso->loadmap->segs[i].p_memsz);
  13063. - }
  13064. - free(dso->loadmap);
  13065. - } else if (dso->map && dso->map_len) {
  13066. - munmap(dso->map, dso->map_len);
  13067. - }
  13068. -}
  13069. -
  13070. -static void *map_library(int fd, struct dso *dso)
  13071. -{
  13072. - Ehdr buf[(896+sizeof(Ehdr))/sizeof(Ehdr)];
  13073. - void *allocated_buf=0;
  13074. - size_t phsize;
  13075. - size_t addr_min=SIZE_MAX, addr_max=0, map_len;
  13076. - size_t this_min, this_max;
  13077. - size_t nsegs = 0;
  13078. - off_t off_start;
  13079. - Ehdr *eh;
  13080. - Phdr *ph, *ph0;
  13081. - unsigned prot;
  13082. - unsigned char *map=MAP_FAILED, *base;
  13083. - size_t dyn=0;
  13084. - size_t tls_image=0;
  13085. - size_t i;
  13086. -
  13087. - ssize_t l = read(fd, buf, sizeof buf);
  13088. - eh = buf;
  13089. - if (l<0) return 0;
  13090. - if (l<sizeof *eh || (eh->e_type != ET_DYN && eh->e_type != ET_EXEC))
  13091. - goto noexec;
  13092. - phsize = eh->e_phentsize * eh->e_phnum;
  13093. - if (phsize > sizeof buf - sizeof *eh) {
  13094. - allocated_buf = malloc(phsize);
  13095. - if (!allocated_buf) return 0;
  13096. - l = pread(fd, allocated_buf, phsize, eh->e_phoff);
  13097. - if (l < 0) goto error;
  13098. - if (l != phsize) goto noexec;
  13099. - ph = ph0 = allocated_buf;
  13100. - } else if (eh->e_phoff + phsize > l) {
  13101. - l = pread(fd, buf+1, phsize, eh->e_phoff);
  13102. - if (l < 0) goto error;
  13103. - if (l != phsize) goto noexec;
  13104. - ph = ph0 = (void *)(buf + 1);
  13105. - } else {
  13106. - ph = ph0 = (void *)((char *)buf + eh->e_phoff);
  13107. - }
  13108. - for (i=eh->e_phnum; i; i--, ph=(void *)((char *)ph+eh->e_phentsize)) {
  13109. - if (ph->p_type == PT_DYNAMIC) {
  13110. - dyn = ph->p_vaddr;
  13111. - } else if (ph->p_type == PT_TLS) {
  13112. - tls_image = ph->p_vaddr;
  13113. - dso->tls_align = ph->p_align;
  13114. - dso->tls_len = ph->p_filesz;
  13115. - dso->tls_size = ph->p_memsz;
  13116. - } else if (ph->p_type == PT_GNU_RELRO) {
  13117. - dso->relro_start = ph->p_vaddr & -PAGE_SIZE;
  13118. - dso->relro_end = (ph->p_vaddr + ph->p_memsz) & -PAGE_SIZE;
  13119. - }
  13120. - if (ph->p_type != PT_LOAD) continue;
  13121. - nsegs++;
  13122. - if (ph->p_vaddr < addr_min) {
  13123. - addr_min = ph->p_vaddr;
  13124. - off_start = ph->p_offset;
  13125. - prot = (((ph->p_flags&PF_R) ? PROT_READ : 0) |
  13126. - ((ph->p_flags&PF_W) ? PROT_WRITE: 0) |
  13127. - ((ph->p_flags&PF_X) ? PROT_EXEC : 0));
  13128. - }
  13129. - if (ph->p_vaddr+ph->p_memsz > addr_max) {
  13130. - addr_max = ph->p_vaddr+ph->p_memsz;
  13131. - }
  13132. - }
  13133. - if (!dyn) goto noexec;
  13134. - if (DL_FDPIC && !(eh->e_flags & FDPIC_CONSTDISP_FLAG)) {
  13135. - dso->loadmap = calloc(1, sizeof *dso->loadmap
  13136. - + nsegs * sizeof *dso->loadmap->segs);
  13137. - if (!dso->loadmap) goto error;
  13138. - dso->loadmap->nsegs = nsegs;
  13139. - for (ph=ph0, i=0; i<nsegs; ph=(void *)((char *)ph+eh->e_phentsize)) {
  13140. - if (ph->p_type != PT_LOAD) continue;
  13141. - prot = (((ph->p_flags&PF_R) ? PROT_READ : 0) |
  13142. - ((ph->p_flags&PF_W) ? PROT_WRITE: 0) |
  13143. - ((ph->p_flags&PF_X) ? PROT_EXEC : 0));
  13144. - map = mmap(0, ph->p_memsz + (ph->p_vaddr & PAGE_SIZE-1),
  13145. - prot, (prot&PROT_WRITE) ? MAP_PRIVATE : MAP_SHARED,
  13146. - fd, ph->p_offset & -PAGE_SIZE);
  13147. - if (map == MAP_FAILED) {
  13148. - unmap_library(dso);
  13149. - goto error;
  13150. - }
  13151. - dso->loadmap->segs[i].addr = (size_t)map +
  13152. - (ph->p_vaddr & PAGE_SIZE-1);
  13153. - dso->loadmap->segs[i].p_vaddr = ph->p_vaddr;
  13154. - dso->loadmap->segs[i].p_memsz = ph->p_memsz;
  13155. - i++;
  13156. - }
  13157. - map = (void *)dso->loadmap->segs[0].addr;
  13158. - map_len = 0;
  13159. - goto done_mapping;
  13160. - }
  13161. - addr_max += PAGE_SIZE-1;
  13162. - addr_max &= -PAGE_SIZE;
  13163. - addr_min &= -PAGE_SIZE;
  13164. - off_start &= -PAGE_SIZE;
  13165. - map_len = addr_max - addr_min + off_start;
  13166. - /* The first time, we map too much, possibly even more than
  13167. - * the length of the file. This is okay because we will not
  13168. - * use the invalid part; we just need to reserve the right
  13169. - * amount of virtual address space to map over later. */
  13170. - map = mmap((void *)addr_min, map_len, prot, MAP_PRIVATE, fd, off_start);
  13171. - if (map==MAP_FAILED) goto error;
  13172. - dso->map = map;
  13173. - dso->map_len = map_len;
  13174. - /* If the loaded file is not relocatable and the requested address is
  13175. - * not available, then the load operation must fail. */
  13176. - if (eh->e_type != ET_DYN && addr_min && map!=(void *)addr_min) {
  13177. - errno = EBUSY;
  13178. - goto error;
  13179. - }
  13180. - base = map - addr_min;
  13181. - dso->phdr = 0;
  13182. - dso->phnum = 0;
  13183. - for (ph=ph0, i=eh->e_phnum; i; i--, ph=(void *)((char *)ph+eh->e_phentsize)) {
  13184. - if (ph->p_type != PT_LOAD) continue;
  13185. - /* Check if the programs headers are in this load segment, and
  13186. - * if so, record the address for use by dl_iterate_phdr. */
  13187. - if (!dso->phdr && eh->e_phoff >= ph->p_offset
  13188. - && eh->e_phoff+phsize <= ph->p_offset+ph->p_filesz) {
  13189. - dso->phdr = (void *)(base + ph->p_vaddr
  13190. - + (eh->e_phoff-ph->p_offset));
  13191. - dso->phnum = eh->e_phnum;
  13192. - dso->phentsize = eh->e_phentsize;
  13193. - }
  13194. - /* Reuse the existing mapping for the lowest-address LOAD */
  13195. - if ((ph->p_vaddr & -PAGE_SIZE) == addr_min) continue;
  13196. - this_min = ph->p_vaddr & -PAGE_SIZE;
  13197. - this_max = ph->p_vaddr+ph->p_memsz+PAGE_SIZE-1 & -PAGE_SIZE;
  13198. - off_start = ph->p_offset & -PAGE_SIZE;
  13199. - prot = (((ph->p_flags&PF_R) ? PROT_READ : 0) |
  13200. - ((ph->p_flags&PF_W) ? PROT_WRITE: 0) |
  13201. - ((ph->p_flags&PF_X) ? PROT_EXEC : 0));
  13202. - if (mmap_fixed(base+this_min, this_max-this_min, prot, MAP_PRIVATE|MAP_FIXED, fd, off_start) == MAP_FAILED)
  13203. - goto error;
  13204. - if (ph->p_memsz > ph->p_filesz) {
  13205. - size_t brk = (size_t)base+ph->p_vaddr+ph->p_filesz;
  13206. - size_t pgbrk = brk+PAGE_SIZE-1 & -PAGE_SIZE;
  13207. - memset((void *)brk, 0, pgbrk-brk & PAGE_SIZE-1);
  13208. - if (pgbrk-(size_t)base < this_max && mmap_fixed((void *)pgbrk, (size_t)base+this_max-pgbrk, prot, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) == MAP_FAILED)
  13209. - goto error;
  13210. - }
  13211. - }
  13212. - for (i=0; ((size_t *)(base+dyn))[i]; i+=2)
  13213. - if (((size_t *)(base+dyn))[i]==DT_TEXTREL) {
  13214. - if (mprotect(map, map_len, PROT_READ|PROT_WRITE|PROT_EXEC)
  13215. - && errno != ENOSYS)
  13216. - goto error;
  13217. - break;
  13218. - }
  13219. -done_mapping:
  13220. - dso->base = base;
  13221. - dso->dynv = laddr(dso, dyn);
  13222. - if (dso->tls_size) dso->tls_image = laddr(dso, tls_image);
  13223. - if (!runtime) reclaim_gaps(dso);
  13224. - free(allocated_buf);
  13225. - return map;
  13226. -noexec:
  13227. - errno = ENOEXEC;
  13228. -error:
  13229. - if (map!=MAP_FAILED) unmap_library(dso);
  13230. - free(allocated_buf);
  13231. - return 0;
  13232. -}
  13233. -
  13234. -static int path_open(const char *name, const char *s, char *buf, size_t buf_size)
  13235. -{
  13236. - size_t l;
  13237. - int fd;
  13238. - for (;;) {
  13239. - s += strspn(s, ":\n");
  13240. - l = strcspn(s, ":\n");
  13241. - if (l-1 >= INT_MAX) return -1;
  13242. - if (snprintf(buf, buf_size, "%.*s/%s", (int)l, s, name) < buf_size) {
  13243. - if ((fd = open(buf, O_RDONLY|O_CLOEXEC))>=0) return fd;
  13244. - switch (errno) {
  13245. - case ENOENT:
  13246. - case ENOTDIR:
  13247. - case EACCES:
  13248. - case ENAMETOOLONG:
  13249. - break;
  13250. - default:
  13251. - /* Any negative value but -1 will inhibit
  13252. - * futher path search. */
  13253. - return -2;
  13254. - }
  13255. - }
  13256. - s += l;
  13257. - }
  13258. -}
  13259. -
  13260. -static int fixup_rpath(struct dso *p, char *buf, size_t buf_size)
  13261. -{
  13262. - size_t n, l;
  13263. - const char *s, *t, *origin;
  13264. - char *d;
  13265. - if (p->rpath || !p->rpath_orig) return 0;
  13266. - if (!strchr(p->rpath_orig, '$')) {
  13267. - p->rpath = p->rpath_orig;
  13268. - return 0;
  13269. - }
  13270. - n = 0;
  13271. - s = p->rpath_orig;
  13272. - while ((t=strchr(s, '$'))) {
  13273. - if (strncmp(t, "$ORIGIN", 7) && strncmp(t, "${ORIGIN}", 9))
  13274. - return 0;
  13275. - s = t+1;
  13276. - n++;
  13277. - }
  13278. - if (n > SSIZE_MAX/PATH_MAX) return 0;
  13279. -
  13280. - if (p->kernel_mapped) {
  13281. - /* $ORIGIN searches cannot be performed for the main program
  13282. - * when it is suid/sgid/AT_SECURE. This is because the
  13283. - * pathname is under the control of the caller of execve.
  13284. - * For libraries, however, $ORIGIN can be processed safely
  13285. - * since the library's pathname came from a trusted source
  13286. - * (either system paths or a call to dlopen). */
  13287. - if (libc.secure)
  13288. - return 0;
  13289. - l = readlink("/proc/self/exe", buf, buf_size);
  13290. - if (l == -1) switch (errno) {
  13291. - case ENOENT:
  13292. - case ENOTDIR:
  13293. - case EACCES:
  13294. - break;
  13295. - default:
  13296. - return -1;
  13297. - }
  13298. - if (l >= buf_size)
  13299. - return 0;
  13300. - buf[l] = 0;
  13301. - origin = buf;
  13302. - } else {
  13303. - origin = p->name;
  13304. - }
  13305. - t = strrchr(origin, '/');
  13306. - l = t ? t-origin : 0;
  13307. - p->rpath = malloc(strlen(p->rpath_orig) + n*l + 1);
  13308. - if (!p->rpath) return -1;
  13309. -
  13310. - d = p->rpath;
  13311. - s = p->rpath_orig;
  13312. - while ((t=strchr(s, '$'))) {
  13313. - memcpy(d, s, t-s);
  13314. - d += t-s;
  13315. - memcpy(d, origin, l);
  13316. - d += l;
  13317. - /* It was determined previously that the '$' is followed
  13318. - * either by "ORIGIN" or "{ORIGIN}". */
  13319. - s = t + 7 + 2*(t[1]=='{');
  13320. - }
  13321. - strcpy(d, s);
  13322. - return 0;
  13323. -}
  13324. -
  13325. -static void decode_dyn(struct dso *p)
  13326. -{
  13327. - size_t dyn[DYN_CNT];
  13328. - decode_vec(p->dynv, dyn, DYN_CNT);
  13329. - p->syms = laddr(p, dyn[DT_SYMTAB]);
  13330. - p->strings = laddr(p, dyn[DT_STRTAB]);
  13331. - if (dyn[0]&(1<<DT_HASH))
  13332. - p->hashtab = laddr(p, dyn[DT_HASH]);
  13333. - if (dyn[0]&(1<<DT_RPATH))
  13334. - p->rpath_orig = p->strings + dyn[DT_RPATH];
  13335. - if (dyn[0]&(1<<DT_RUNPATH))
  13336. - p->rpath_orig = p->strings + dyn[DT_RUNPATH];
  13337. - if (dyn[0]&(1<<DT_PLTGOT))
  13338. - p->got = laddr(p, dyn[DT_PLTGOT]);
  13339. - if (search_vec(p->dynv, dyn, DT_GNU_HASH))
  13340. - p->ghashtab = laddr(p, *dyn);
  13341. - if (search_vec(p->dynv, dyn, DT_VERSYM))
  13342. - p->versym = laddr(p, *dyn);
  13343. -}
  13344. -
  13345. -static size_t count_syms(struct dso *p)
  13346. -{
  13347. - if (p->hashtab) return p->hashtab[1];
  13348. -
  13349. - size_t nsym, i;
  13350. - uint32_t *buckets = p->ghashtab + 4 + (p->ghashtab[2]*sizeof(size_t)/4);
  13351. - uint32_t *hashval;
  13352. - for (i = nsym = 0; i < p->ghashtab[0]; i++) {
  13353. - if (buckets[i] > nsym)
  13354. - nsym = buckets[i];
  13355. - }
  13356. - if (nsym) {
  13357. - hashval = buckets + p->ghashtab[0] + (nsym - p->ghashtab[1]);
  13358. - do nsym++;
  13359. - while (!(*hashval++ & 1));
  13360. - }
  13361. - return nsym;
  13362. -}
  13363. -
  13364. -static void *dl_mmap(size_t n)
  13365. -{
  13366. - void *p;
  13367. - int prot = PROT_READ|PROT_WRITE, flags = MAP_ANONYMOUS|MAP_PRIVATE;
  13368. -#ifdef SYS_mmap2
  13369. - p = (void *)__syscall(SYS_mmap2, 0, n, prot, flags, -1, 0);
  13370. -#else
  13371. - p = (void *)__syscall(SYS_mmap, 0, n, prot, flags, -1, 0);
  13372. -#endif
  13373. - return p == MAP_FAILED ? 0 : p;
  13374. -}
  13375. -
  13376. -static void makefuncdescs(struct dso *p)
  13377. -{
  13378. - static int self_done;
  13379. - size_t nsym = count_syms(p);
  13380. - size_t i, size = nsym * sizeof(*p->funcdescs);
  13381. -
  13382. - if (!self_done) {
  13383. - p->funcdescs = dl_mmap(size);
  13384. - self_done = 1;
  13385. - } else {
  13386. - p->funcdescs = malloc(size);
  13387. - }
  13388. - if (!p->funcdescs) {
  13389. - if (!runtime) a_crash();
  13390. - error("Error allocating function descriptors for %s", p->name);
  13391. - longjmp(*rtld_fail, 1);
  13392. - }
  13393. - for (i=0; i<nsym; i++) {
  13394. - if ((p->syms[i].st_info&0xf)==STT_FUNC && p->syms[i].st_shndx) {
  13395. - p->funcdescs[i].addr = laddr(p, p->syms[i].st_value);
  13396. - p->funcdescs[i].got = p->got;
  13397. - } else {
  13398. - p->funcdescs[i].addr = 0;
  13399. - p->funcdescs[i].got = 0;
  13400. - }
  13401. - }
  13402. -}
  13403. -
  13404. -static struct dso *load_library(const char *name, struct dso *needed_by)
  13405. -{
  13406. - char buf[2*NAME_MAX+2];
  13407. - const char *pathname;
  13408. - unsigned char *map;
  13409. - struct dso *p, temp_dso = {0};
  13410. - int fd;
  13411. - struct stat st;
  13412. - size_t alloc_size;
  13413. - int n_th = 0;
  13414. - int is_self = 0;
  13415. -
  13416. - if (!*name) {
  13417. - errno = EINVAL;
  13418. - return 0;
  13419. - }
  13420. -
  13421. - /* Catch and block attempts to reload the implementation itself */
  13422. - if (name[0]=='l' && name[1]=='i' && name[2]=='b') {
  13423. - static const char *rp, reserved[] =
  13424. - "c\0pthread\0rt\0m\0dl\0util\0xnet\0";
  13425. - char *z = strchr(name, '.');
  13426. - if (z) {
  13427. - size_t l = z-name;
  13428. - for (rp=reserved; *rp && strncmp(name+3, rp, l-3); rp+=strlen(rp)+1);
  13429. - if (*rp) {
  13430. - if (ldd_mode) {
  13431. - /* Track which names have been resolved
  13432. - * and only report each one once. */
  13433. - static unsigned reported;
  13434. - unsigned mask = 1U<<(rp-reserved);
  13435. - if (!(reported & mask)) {
  13436. - reported |= mask;
  13437. - dprintf(1, "\t%s => %s (%p)\n",
  13438. - name, ldso.name,
  13439. - ldso.base);
  13440. - }
  13441. - }
  13442. - is_self = 1;
  13443. - }
  13444. - }
  13445. - }
  13446. - if (!strcmp(name, ldso.name)) is_self = 1;
  13447. - if (is_self) {
  13448. - if (!ldso.prev) {
  13449. - tail->next = &ldso;
  13450. - ldso.prev = tail;
  13451. - tail = ldso.next ? ldso.next : &ldso;
  13452. - }
  13453. - return &ldso;
  13454. - }
  13455. - if (strchr(name, '/')) {
  13456. - pathname = name;
  13457. - fd = open(name, O_RDONLY|O_CLOEXEC);
  13458. - } else {
  13459. - /* Search for the name to see if it's already loaded */
  13460. - for (p=head->next; p; p=p->next) {
  13461. - if (p->shortname && !strcmp(p->shortname, name)) {
  13462. - p->refcnt++;
  13463. - return p;
  13464. - }
  13465. - }
  13466. - if (strlen(name) > NAME_MAX) return 0;
  13467. - fd = -1;
  13468. - if (env_path) fd = path_open(name, env_path, buf, sizeof buf);
  13469. - for (p=needed_by; fd == -1 && p; p=p->needed_by) {
  13470. - if (fixup_rpath(p, buf, sizeof buf) < 0)
  13471. - fd = -2; /* Inhibit further search. */
  13472. - if (p->rpath)
  13473. - fd = path_open(name, p->rpath, buf, sizeof buf);
  13474. - }
  13475. - if (fd == -1) {
  13476. - if (!sys_path) {
  13477. - char *prefix = 0;
  13478. - size_t prefix_len;
  13479. - if (ldso.name[0]=='/') {
  13480. - char *s, *t, *z;
  13481. - for (s=t=z=ldso.name; *s; s++)
  13482. - if (*s=='/') z=t, t=s;
  13483. - prefix_len = z-ldso.name;
  13484. - if (prefix_len < PATH_MAX)
  13485. - prefix = ldso.name;
  13486. - }
  13487. - if (!prefix) {
  13488. - prefix = "";
  13489. - prefix_len = 0;
  13490. - }
  13491. - char etc_ldso_path[prefix_len + 1
  13492. - + sizeof "/etc/ld-musl-" LDSO_ARCH ".path"];
  13493. - snprintf(etc_ldso_path, sizeof etc_ldso_path,
  13494. - "%.*s/etc/ld-musl-" LDSO_ARCH ".path",
  13495. - (int)prefix_len, prefix);
  13496. - FILE *f = fopen(etc_ldso_path, "rbe");
  13497. - if (f) {
  13498. - if (getdelim(&sys_path, (size_t[1]){0}, 0, f) <= 0) {
  13499. - free(sys_path);
  13500. - sys_path = "";
  13501. - }
  13502. - fclose(f);
  13503. - } else if (errno != ENOENT) {
  13504. - sys_path = "";
  13505. - }
  13506. - }
  13507. - if (!sys_path) sys_path = "/lib:/usr/local/lib:/usr/lib";
  13508. - fd = path_open(name, sys_path, buf, sizeof buf);
  13509. - }
  13510. - pathname = buf;
  13511. - }
  13512. - if (fd < 0) return 0;
  13513. - if (fstat(fd, &st) < 0) {
  13514. - close(fd);
  13515. - return 0;
  13516. - }
  13517. - for (p=head->next; p; p=p->next) {
  13518. - if (p->dev == st.st_dev && p->ino == st.st_ino) {
  13519. - /* If this library was previously loaded with a
  13520. - * pathname but a search found the same inode,
  13521. - * setup its shortname so it can be found by name. */
  13522. - if (!p->shortname && pathname != name)
  13523. - p->shortname = strrchr(p->name, '/')+1;
  13524. - close(fd);
  13525. - p->refcnt++;
  13526. - return p;
  13527. - }
  13528. - }
  13529. - map = noload ? 0 : map_library(fd, &temp_dso);
  13530. - close(fd);
  13531. - if (!map) return 0;
  13532. -
  13533. - /* Allocate storage for the new DSO. When there is TLS, this
  13534. - * storage must include a reservation for all pre-existing
  13535. - * threads to obtain copies of both the new TLS, and an
  13536. - * extended DTV capable of storing an additional slot for
  13537. - * the newly-loaded DSO. */
  13538. - alloc_size = sizeof *p + strlen(pathname) + 1;
  13539. - if (runtime && temp_dso.tls_image) {
  13540. - size_t per_th = temp_dso.tls_size + temp_dso.tls_align
  13541. - + sizeof(void *) * (tls_cnt+3);
  13542. - n_th = libc.threads_minus_1 + 1;
  13543. - if (n_th > SSIZE_MAX / per_th) alloc_size = SIZE_MAX;
  13544. - else alloc_size += n_th * per_th;
  13545. - }
  13546. - p = calloc(1, alloc_size);
  13547. - if (!p) {
  13548. - unmap_library(&temp_dso);
  13549. - return 0;
  13550. - }
  13551. - memcpy(p, &temp_dso, sizeof temp_dso);
  13552. - decode_dyn(p);
  13553. - p->dev = st.st_dev;
  13554. - p->ino = st.st_ino;
  13555. - p->refcnt = 1;
  13556. - p->needed_by = needed_by;
  13557. - p->name = p->buf;
  13558. - strcpy(p->name, pathname);
  13559. - /* Add a shortname only if name arg was not an explicit pathname. */
  13560. - if (pathname != name) p->shortname = strrchr(p->name, '/')+1;
  13561. - if (p->tls_image) {
  13562. - p->tls_id = ++tls_cnt;
  13563. - tls_align = MAXP2(tls_align, p->tls_align);
  13564. -#ifdef TLS_ABOVE_TP
  13565. - p->tls_offset = tls_offset + ( (tls_align-1) &
  13566. - -(tls_offset + (uintptr_t)p->tls_image) );
  13567. - tls_offset += p->tls_size;
  13568. -#else
  13569. - tls_offset += p->tls_size + p->tls_align - 1;
  13570. - tls_offset -= (tls_offset + (uintptr_t)p->tls_image)
  13571. - & (p->tls_align-1);
  13572. - p->tls_offset = tls_offset;
  13573. -#endif
  13574. - p->new_dtv = (void *)(-sizeof(size_t) &
  13575. - (uintptr_t)(p->name+strlen(p->name)+sizeof(size_t)));
  13576. - p->new_tls = (void *)(p->new_dtv + n_th*(tls_cnt+1));
  13577. - }
  13578. -
  13579. - tail->next = p;
  13580. - p->prev = tail;
  13581. - tail = p;
  13582. -
  13583. - if (DL_FDPIC) makefuncdescs(p);
  13584. -
  13585. - if (ldd_mode) dprintf(1, "\t%s => %s (%p)\n", name, pathname, p->base);
  13586. -
  13587. - return p;
  13588. -}
  13589. -
  13590. -static void load_deps(struct dso *p)
  13591. -{
  13592. - size_t i, ndeps=0;
  13593. - struct dso ***deps = &p->deps, **tmp, *dep;
  13594. - for (; p; p=p->next) {
  13595. - for (i=0; p->dynv[i]; i+=2) {
  13596. - if (p->dynv[i] != DT_NEEDED) continue;
  13597. - dep = load_library(p->strings + p->dynv[i+1], p);
  13598. - if (!dep) {
  13599. - error("Error loading shared library %s: %m (needed by %s)",
  13600. - p->strings + p->dynv[i+1], p->name);
  13601. - if (runtime) longjmp(*rtld_fail, 1);
  13602. - continue;
  13603. - }
  13604. - if (runtime) {
  13605. - tmp = realloc(*deps, sizeof(*tmp)*(ndeps+2));
  13606. - if (!tmp) longjmp(*rtld_fail, 1);
  13607. - tmp[ndeps++] = dep;
  13608. - tmp[ndeps] = 0;
  13609. - *deps = tmp;
  13610. - }
  13611. - }
  13612. - }
  13613. -}
  13614. -
  13615. -static void load_preload(char *s)
  13616. -{
  13617. - int tmp;
  13618. - char *z;
  13619. - for (z=s; *z; s=z) {
  13620. - for ( ; *s && (isspace(*s) || *s==':'); s++);
  13621. - for (z=s; *z && !isspace(*z) && *z!=':'; z++);
  13622. - tmp = *z;
  13623. - *z = 0;
  13624. - load_library(s, 0);
  13625. - *z = tmp;
  13626. - }
  13627. -}
  13628. -
  13629. -static void make_global(struct dso *p)
  13630. -{
  13631. - for (; p; p=p->next) p->global = 1;
  13632. -}
  13633. -
  13634. -static void do_mips_relocs(struct dso *p, size_t *got)
  13635. -{
  13636. - size_t i, j, rel[2];
  13637. - unsigned char *base = p->base;
  13638. - i=0; search_vec(p->dynv, &i, DT_MIPS_LOCAL_GOTNO);
  13639. - if (p==&ldso) {
  13640. - got += i;
  13641. - } else {
  13642. - while (i--) *got++ += (size_t)base;
  13643. - }
  13644. - j=0; search_vec(p->dynv, &j, DT_MIPS_GOTSYM);
  13645. - i=0; search_vec(p->dynv, &i, DT_MIPS_SYMTABNO);
  13646. - Sym *sym = p->syms + j;
  13647. - rel[0] = (unsigned char *)got - base;
  13648. - for (i-=j; i; i--, sym++, rel[0]+=sizeof(size_t)) {
  13649. - rel[1] = sym-p->syms << 8 | R_MIPS_JUMP_SLOT;
  13650. - do_relocs(p, rel, sizeof rel, 2);
  13651. - }
  13652. -}
  13653. -
  13654. -static void reloc_all(struct dso *p)
  13655. -{
  13656. - size_t dyn[DYN_CNT];
  13657. - for (; p; p=p->next) {
  13658. - if (p->relocated) continue;
  13659. - decode_vec(p->dynv, dyn, DYN_CNT);
  13660. - if (NEED_MIPS_GOT_RELOCS)
  13661. - do_mips_relocs(p, laddr(p, dyn[DT_PLTGOT]));
  13662. - do_relocs(p, laddr(p, dyn[DT_JMPREL]), dyn[DT_PLTRELSZ],
  13663. - 2+(dyn[DT_PLTREL]==DT_RELA));
  13664. - do_relocs(p, laddr(p, dyn[DT_REL]), dyn[DT_RELSZ], 2);
  13665. - do_relocs(p, laddr(p, dyn[DT_RELA]), dyn[DT_RELASZ], 3);
  13666. -
  13667. - if (head != &ldso && p->relro_start != p->relro_end &&
  13668. - mprotect(laddr(p, p->relro_start), p->relro_end-p->relro_start, PROT_READ)
  13669. - && errno != ENOSYS) {
  13670. - error("Error relocating %s: RELRO protection failed: %m",
  13671. - p->name);
  13672. - if (runtime) longjmp(*rtld_fail, 1);
  13673. - }
  13674. -
  13675. - p->relocated = 1;
  13676. - }
  13677. -}
  13678. -
  13679. -static void kernel_mapped_dso(struct dso *p)
  13680. -{
  13681. - size_t min_addr = -1, max_addr = 0, cnt;
  13682. - Phdr *ph = p->phdr;
  13683. - for (cnt = p->phnum; cnt--; ph = (void *)((char *)ph + p->phentsize)) {
  13684. - if (ph->p_type == PT_DYNAMIC) {
  13685. - p->dynv = laddr(p, ph->p_vaddr);
  13686. - } else if (ph->p_type == PT_GNU_RELRO) {
  13687. - p->relro_start = ph->p_vaddr & -PAGE_SIZE;
  13688. - p->relro_end = (ph->p_vaddr + ph->p_memsz) & -PAGE_SIZE;
  13689. - }
  13690. - if (ph->p_type != PT_LOAD) continue;
  13691. - if (ph->p_vaddr < min_addr)
  13692. - min_addr = ph->p_vaddr;
  13693. - if (ph->p_vaddr+ph->p_memsz > max_addr)
  13694. - max_addr = ph->p_vaddr+ph->p_memsz;
  13695. - }
  13696. - min_addr &= -PAGE_SIZE;
  13697. - max_addr = (max_addr + PAGE_SIZE-1) & -PAGE_SIZE;
  13698. - p->map = p->base + min_addr;
  13699. - p->map_len = max_addr - min_addr;
  13700. - p->kernel_mapped = 1;
  13701. -}
  13702. -
  13703. -static void do_fini()
  13704. -{
  13705. - struct dso *p;
  13706. - size_t dyn[DYN_CNT];
  13707. - for (p=fini_head; p; p=p->fini_next) {
  13708. - if (!p->constructed) continue;
  13709. - decode_vec(p->dynv, dyn, DYN_CNT);
  13710. - if (dyn[0] & (1<<DT_FINI_ARRAY)) {
  13711. - size_t n = dyn[DT_FINI_ARRAYSZ]/sizeof(size_t);
  13712. - size_t *fn = (size_t *)laddr(p, dyn[DT_FINI_ARRAY])+n;
  13713. - while (n--) ((void (*)(void))*--fn)();
  13714. - }
  13715. -#ifndef NO_LEGACY_INITFINI
  13716. - if ((dyn[0] & (1<<DT_FINI)) && dyn[DT_FINI])
  13717. - fpaddr(p, dyn[DT_FINI])();
  13718. -#endif
  13719. - }
  13720. -}
  13721. -
  13722. -static void do_init_fini(struct dso *p)
  13723. -{
  13724. - size_t dyn[DYN_CNT];
  13725. - int need_locking = libc.threads_minus_1;
  13726. - /* Allow recursive calls that arise when a library calls
  13727. - * dlopen from one of its constructors, but block any
  13728. - * other threads until all ctors have finished. */
  13729. - if (need_locking) pthread_mutex_lock(&init_fini_lock);
  13730. - for (; p; p=p->prev) {
  13731. - if (p->constructed) continue;
  13732. - p->constructed = 1;
  13733. - decode_vec(p->dynv, dyn, DYN_CNT);
  13734. - if (dyn[0] & ((1<<DT_FINI) | (1<<DT_FINI_ARRAY))) {
  13735. - p->fini_next = fini_head;
  13736. - fini_head = p;
  13737. - }
  13738. -#ifndef NO_LEGACY_INITFINI
  13739. - if ((dyn[0] & (1<<DT_INIT)) && dyn[DT_INIT])
  13740. - fpaddr(p, dyn[DT_INIT])();
  13741. -#endif
  13742. - if (dyn[0] & (1<<DT_INIT_ARRAY)) {
  13743. - size_t n = dyn[DT_INIT_ARRAYSZ]/sizeof(size_t);
  13744. - size_t *fn = laddr(p, dyn[DT_INIT_ARRAY]);
  13745. - while (n--) ((void (*)(void))*fn++)();
  13746. - }
  13747. - if (!need_locking && libc.threads_minus_1) {
  13748. - need_locking = 1;
  13749. - pthread_mutex_lock(&init_fini_lock);
  13750. - }
  13751. - }
  13752. - if (need_locking) pthread_mutex_unlock(&init_fini_lock);
  13753. -}
  13754. -
  13755. -void __libc_start_init(void)
  13756. -{
  13757. - do_init_fini(tail);
  13758. -}
  13759. -
  13760. -static void dl_debug_state(void)
  13761. -{
  13762. -}
  13763. -
  13764. -weak_alias(dl_debug_state, _dl_debug_state);
  13765. -
  13766. -void __reset_tls()
  13767. -{
  13768. - pthread_t self = __pthread_self();
  13769. - struct dso *p;
  13770. - for (p=head; p; p=p->next) {
  13771. - if (!p->tls_id || !self->dtv[p->tls_id]) continue;
  13772. - memcpy(self->dtv[p->tls_id], p->tls_image, p->tls_len);
  13773. - memset((char *)self->dtv[p->tls_id]+p->tls_len, 0,
  13774. - p->tls_size - p->tls_len);
  13775. - if (p->tls_id == (size_t)self->dtv[0]) break;
  13776. - }
  13777. -}
  13778. -
  13779. -void *__copy_tls(unsigned char *mem)
  13780. -{
  13781. - pthread_t td;
  13782. - struct dso *p;
  13783. - void **dtv;
  13784. -
  13785. -#ifdef TLS_ABOVE_TP
  13786. - dtv = (void **)(mem + libc.tls_size) - (tls_cnt + 1);
  13787. -
  13788. - mem += -((uintptr_t)mem + sizeof(struct pthread)) & (tls_align-1);
  13789. - td = (pthread_t)mem;
  13790. - mem += sizeof(struct pthread);
  13791. -
  13792. - for (p=head; p; p=p->next) {
  13793. - if (!p->tls_id) continue;
  13794. - dtv[p->tls_id] = mem + p->tls_offset;
  13795. - memcpy(dtv[p->tls_id], p->tls_image, p->tls_len);
  13796. - }
  13797. -#else
  13798. - dtv = (void **)mem;
  13799. -
  13800. - mem += libc.tls_size - sizeof(struct pthread);
  13801. - mem -= (uintptr_t)mem & (tls_align-1);
  13802. - td = (pthread_t)mem;
  13803. -
  13804. - for (p=head; p; p=p->next) {
  13805. - if (!p->tls_id) continue;
  13806. - dtv[p->tls_id] = mem - p->tls_offset;
  13807. - memcpy(dtv[p->tls_id], p->tls_image, p->tls_len);
  13808. - }
  13809. -#endif
  13810. - dtv[0] = (void *)tls_cnt;
  13811. - td->dtv = td->dtv_copy = dtv;
  13812. - return td;
  13813. -}
  13814. -
  13815. -__attribute__((__visibility__("hidden")))
  13816. -void *__tls_get_new(size_t *v)
  13817. -{
  13818. - pthread_t self = __pthread_self();
  13819. -
  13820. - /* Block signals to make accessing new TLS async-signal-safe */
  13821. - sigset_t set;
  13822. - __block_all_sigs(&set);
  13823. - if (v[0]<=(size_t)self->dtv[0]) {
  13824. - __restore_sigs(&set);
  13825. - return (char *)self->dtv[v[0]]+v[1]+DTP_OFFSET;
  13826. - }
  13827. -
  13828. - /* This is safe without any locks held because, if the caller
  13829. - * is able to request the Nth entry of the DTV, the DSO list
  13830. - * must be valid at least that far out and it was synchronized
  13831. - * at program startup or by an already-completed call to dlopen. */
  13832. - struct dso *p;
  13833. - for (p=head; p->tls_id != v[0]; p=p->next);
  13834. -
  13835. - /* Get new DTV space from new DSO if needed */
  13836. - if (v[0] > (size_t)self->dtv[0]) {
  13837. - void **newdtv = p->new_dtv +
  13838. - (v[0]+1)*sizeof(void *)*a_fetch_add(&p->new_dtv_idx,1);
  13839. - memcpy(newdtv, self->dtv,
  13840. - ((size_t)self->dtv[0]+1) * sizeof(void *));
  13841. - newdtv[0] = (void *)v[0];
  13842. - self->dtv = self->dtv_copy = newdtv;
  13843. - }
  13844. -
  13845. - /* Get new TLS memory from all new DSOs up to the requested one */
  13846. - unsigned char *mem;
  13847. - for (p=head; ; p=p->next) {
  13848. - if (!p->tls_id || self->dtv[p->tls_id]) continue;
  13849. - mem = p->new_tls + (p->tls_size + p->tls_align)
  13850. - * a_fetch_add(&p->new_tls_idx,1);
  13851. - mem += ((uintptr_t)p->tls_image - (uintptr_t)mem)
  13852. - & (p->tls_align-1);
  13853. - self->dtv[p->tls_id] = mem;
  13854. - memcpy(mem, p->tls_image, p->tls_len);
  13855. - if (p->tls_id == v[0]) break;
  13856. - }
  13857. - __restore_sigs(&set);
  13858. - return mem + v[1] + DTP_OFFSET;
  13859. -}
  13860. -
  13861. -static void update_tls_size()
  13862. -{
  13863. - libc.tls_size = ALIGN(
  13864. - (1+tls_cnt) * sizeof(void *) +
  13865. - tls_offset +
  13866. - sizeof(struct pthread) +
  13867. - tls_align * 2,
  13868. - tls_align);
  13869. -}
  13870. -
  13871. -/* Stage 1 of the dynamic linker is defined in dlstart.c. It calls the
  13872. - * following stage 2 and stage 3 functions via primitive symbolic lookup
  13873. - * since it does not have access to their addresses to begin with. */
  13874. -
  13875. -/* Stage 2 of the dynamic linker is called after relative relocations
  13876. - * have been processed. It can make function calls to static functions
  13877. - * and access string literals and static data, but cannot use extern
  13878. - * symbols. Its job is to perform symbolic relocations on the dynamic
  13879. - * linker itself, but some of the relocations performed may need to be
  13880. - * replaced later due to copy relocations in the main program. */
  13881. -
  13882. -__attribute__((__visibility__("hidden")))
  13883. -void __dls2(unsigned char *base, size_t *sp)
  13884. -{
  13885. - if (DL_FDPIC) {
  13886. - void *p1 = (void *)sp[-2];
  13887. - void *p2 = (void *)sp[-1];
  13888. - if (!p1) {
  13889. - size_t *auxv, aux[AUX_CNT];
  13890. - for (auxv=sp+1+*sp+1; *auxv; auxv++); auxv++;
  13891. - decode_vec(auxv, aux, AUX_CNT);
  13892. - if (aux[AT_BASE]) ldso.base = (void *)aux[AT_BASE];
  13893. - else ldso.base = (void *)(aux[AT_PHDR] & -4096);
  13894. - }
  13895. - app_loadmap = p2 ? p1 : 0;
  13896. - ldso.loadmap = p2 ? p2 : p1;
  13897. - ldso.base = laddr(&ldso, 0);
  13898. - } else {
  13899. - ldso.base = base;
  13900. - }
  13901. - Ehdr *ehdr = (void *)ldso.base;
  13902. - ldso.name = ldso.shortname = "libc.so";
  13903. - ldso.global = 1;
  13904. - ldso.phnum = ehdr->e_phnum;
  13905. - ldso.phdr = laddr(&ldso, ehdr->e_phoff);
  13906. - ldso.phentsize = ehdr->e_phentsize;
  13907. - kernel_mapped_dso(&ldso);
  13908. - decode_dyn(&ldso);
  13909. -
  13910. - if (DL_FDPIC) makefuncdescs(&ldso);
  13911. -
  13912. - /* Prepare storage for to save clobbered REL addends so they
  13913. - * can be reused in stage 3. There should be very few. If
  13914. - * something goes wrong and there are a huge number, abort
  13915. - * instead of risking stack overflow. */
  13916. - size_t dyn[DYN_CNT];
  13917. - decode_vec(ldso.dynv, dyn, DYN_CNT);
  13918. - size_t *rel = laddr(&ldso, dyn[DT_REL]);
  13919. - size_t rel_size = dyn[DT_RELSZ];
  13920. - size_t symbolic_rel_cnt = 0;
  13921. - apply_addends_to = rel;
  13922. - for (; rel_size; rel+=2, rel_size-=2*sizeof(size_t))
  13923. - if (!IS_RELATIVE(rel[1], ldso.syms)) symbolic_rel_cnt++;
  13924. - if (symbolic_rel_cnt >= ADDEND_LIMIT) a_crash();
  13925. - size_t addends[symbolic_rel_cnt+1];
  13926. - saved_addends = addends;
  13927. -
  13928. - head = &ldso;
  13929. - reloc_all(&ldso);
  13930. -
  13931. - ldso.relocated = 0;
  13932. -
  13933. - /* Call dynamic linker stage-3, __dls3, looking it up
  13934. - * symbolically as a barrier against moving the address
  13935. - * load across the above relocation processing. */
  13936. - struct symdef dls3_def = find_sym(&ldso, "__dls3", 0);
  13937. - if (DL_FDPIC) ((stage3_func)&ldso.funcdescs[dls3_def.sym-ldso.syms])(sp);
  13938. - else ((stage3_func)laddr(&ldso, dls3_def.sym->st_value))(sp);
  13939. -}
  13940. -
  13941. -/* Stage 3 of the dynamic linker is called with the dynamic linker/libc
  13942. - * fully functional. Its job is to load (if not already loaded) and
  13943. - * process dependencies and relocations for the main application and
  13944. - * transfer control to its entry point. */
  13945. -
  13946. -_Noreturn void __dls3(size_t *sp)
  13947. -{
  13948. - static struct dso app, vdso;
  13949. - size_t aux[AUX_CNT], *auxv;
  13950. - size_t i;
  13951. - char *env_preload=0;
  13952. - size_t vdso_base;
  13953. - int argc = *sp;
  13954. - char **argv = (void *)(sp+1);
  13955. - char **argv_orig = argv;
  13956. - char **envp = argv+argc+1;
  13957. -
  13958. - /* Find aux vector just past environ[] and use it to initialize
  13959. - * global data that may be needed before we can make syscalls. */
  13960. - __environ = envp;
  13961. - for (i=argc+1; argv[i]; i++);
  13962. - libc.auxv = auxv = (void *)(argv+i+1);
  13963. - decode_vec(auxv, aux, AUX_CNT);
  13964. - __hwcap = aux[AT_HWCAP];
  13965. - libc.page_size = aux[AT_PAGESZ];
  13966. - libc.secure = ((aux[0]&0x7800)!=0x7800 || aux[AT_UID]!=aux[AT_EUID]
  13967. - || aux[AT_GID]!=aux[AT_EGID] || aux[AT_SECURE]);
  13968. -
  13969. - /* Setup early thread pointer in builtin_tls for ldso/libc itself to
  13970. - * use during dynamic linking. If possible it will also serve as the
  13971. - * thread pointer at runtime. */
  13972. - libc.tls_size = sizeof builtin_tls;
  13973. - if (__init_tp(__copy_tls((void *)builtin_tls)) < 0) {
  13974. - a_crash();
  13975. - }
  13976. -
  13977. - /* Only trust user/env if kernel says we're not suid/sgid */
  13978. - if (!libc.secure) {
  13979. - env_path = getenv("LD_LIBRARY_PATH");
  13980. - env_preload = getenv("LD_PRELOAD");
  13981. - }
  13982. -
  13983. - /* If the main program was already loaded by the kernel,
  13984. - * AT_PHDR will point to some location other than the dynamic
  13985. - * linker's program headers. */
  13986. - if (aux[AT_PHDR] != (size_t)ldso.phdr) {
  13987. - size_t interp_off = 0;
  13988. - size_t tls_image = 0;
  13989. - /* Find load address of the main program, via AT_PHDR vs PT_PHDR. */
  13990. - Phdr *phdr = app.phdr = (void *)aux[AT_PHDR];
  13991. - app.phnum = aux[AT_PHNUM];
  13992. - app.phentsize = aux[AT_PHENT];
  13993. - for (i=aux[AT_PHNUM]; i; i--, phdr=(void *)((char *)phdr + aux[AT_PHENT])) {
  13994. - if (phdr->p_type == PT_PHDR)
  13995. - app.base = (void *)(aux[AT_PHDR] - phdr->p_vaddr);
  13996. - else if (phdr->p_type == PT_INTERP)
  13997. - interp_off = (size_t)phdr->p_vaddr;
  13998. - else if (phdr->p_type == PT_TLS) {
  13999. - tls_image = phdr->p_vaddr;
  14000. - app.tls_len = phdr->p_filesz;
  14001. - app.tls_size = phdr->p_memsz;
  14002. - app.tls_align = phdr->p_align;
  14003. - }
  14004. - }
  14005. - if (DL_FDPIC) app.loadmap = app_loadmap;
  14006. - if (app.tls_size) app.tls_image = laddr(&app, tls_image);
  14007. - if (interp_off) ldso.name = laddr(&app, interp_off);
  14008. - if ((aux[0] & (1UL<<AT_EXECFN))
  14009. - && strncmp((char *)aux[AT_EXECFN], "/proc/", 6))
  14010. - app.name = (char *)aux[AT_EXECFN];
  14011. - else
  14012. - app.name = argv[0];
  14013. - kernel_mapped_dso(&app);
  14014. - } else {
  14015. - int fd;
  14016. - char *ldname = argv[0];
  14017. - size_t l = strlen(ldname);
  14018. - if (l >= 3 && !strcmp(ldname+l-3, "ldd")) ldd_mode = 1;
  14019. - argv++;
  14020. - while (argv[0] && argv[0][0]=='-' && argv[0][1]=='-') {
  14021. - char *opt = argv[0]+2;
  14022. - *argv++ = (void *)-1;
  14023. - if (!*opt) {
  14024. - break;
  14025. - } else if (!memcmp(opt, "list", 5)) {
  14026. - ldd_mode = 1;
  14027. - } else if (!memcmp(opt, "library-path", 12)) {
  14028. - if (opt[12]=='=') env_path = opt+13;
  14029. - else if (opt[12]) *argv = 0;
  14030. - else if (*argv) env_path = *argv++;
  14031. - } else if (!memcmp(opt, "preload", 7)) {
  14032. - if (opt[7]=='=') env_preload = opt+8;
  14033. - else if (opt[7]) *argv = 0;
  14034. - else if (*argv) env_preload = *argv++;
  14035. - } else {
  14036. - argv[0] = 0;
  14037. - }
  14038. - }
  14039. - argv[-1] = (void *)(argc - (argv-argv_orig));
  14040. - if (!argv[0]) {
  14041. - dprintf(2, "musl libc\n"
  14042. - "Version %s\n"
  14043. - "Dynamic Program Loader\n"
  14044. - "Usage: %s [options] [--] pathname%s\n",
  14045. - __libc_get_version(), ldname,
  14046. - ldd_mode ? "" : " [args]");
  14047. - _exit(1);
  14048. - }
  14049. - fd = open(argv[0], O_RDONLY);
  14050. - if (fd < 0) {
  14051. - dprintf(2, "%s: cannot load %s: %s\n", ldname, argv[0], strerror(errno));
  14052. - _exit(1);
  14053. - }
  14054. - runtime = 1;
  14055. - Ehdr *ehdr = (void *)map_library(fd, &app);
  14056. - if (!ehdr) {
  14057. - dprintf(2, "%s: %s: Not a valid dynamic program\n", ldname, argv[0]);
  14058. - _exit(1);
  14059. - }
  14060. - runtime = 0;
  14061. - close(fd);
  14062. - ldso.name = ldname;
  14063. - app.name = argv[0];
  14064. - aux[AT_ENTRY] = (size_t)laddr(&app, ehdr->e_entry);
  14065. - /* Find the name that would have been used for the dynamic
  14066. - * linker had ldd not taken its place. */
  14067. - if (ldd_mode) {
  14068. - for (i=0; i<app.phnum; i++) {
  14069. - if (app.phdr[i].p_type == PT_INTERP)
  14070. - ldso.name = laddr(&app, app.phdr[i].p_vaddr);
  14071. - }
  14072. - dprintf(1, "\t%s (%p)\n", ldso.name, ldso.base);
  14073. - }
  14074. - }
  14075. - if (app.tls_size) {
  14076. - app.tls_id = tls_cnt = 1;
  14077. -#ifdef TLS_ABOVE_TP
  14078. - app.tls_offset = 0;
  14079. - tls_offset = app.tls_size
  14080. - + ( -((uintptr_t)app.tls_image + app.tls_size)
  14081. - & (app.tls_align-1) );
  14082. -#else
  14083. - tls_offset = app.tls_offset = app.tls_size
  14084. - + ( -((uintptr_t)app.tls_image + app.tls_size)
  14085. - & (app.tls_align-1) );
  14086. -#endif
  14087. - tls_align = MAXP2(tls_align, app.tls_align);
  14088. - }
  14089. - app.global = 1;
  14090. - decode_dyn(&app);
  14091. - if (DL_FDPIC) {
  14092. - makefuncdescs(&app);
  14093. - if (!app.loadmap) {
  14094. - app.loadmap = (void *)&app_dummy_loadmap;
  14095. - app.loadmap->nsegs = 1;
  14096. - app.loadmap->segs[0].addr = (size_t)app.map;
  14097. - app.loadmap->segs[0].p_vaddr = (size_t)app.map
  14098. - - (size_t)app.base;
  14099. - app.loadmap->segs[0].p_memsz = app.map_len;
  14100. - }
  14101. - argv[-3] = (void *)app.loadmap;
  14102. - }
  14103. -
  14104. - /* Attach to vdso, if provided by the kernel */
  14105. - if (search_vec(auxv, &vdso_base, AT_SYSINFO_EHDR)) {
  14106. - Ehdr *ehdr = (void *)vdso_base;
  14107. - Phdr *phdr = vdso.phdr = (void *)(vdso_base + ehdr->e_phoff);
  14108. - vdso.phnum = ehdr->e_phnum;
  14109. - vdso.phentsize = ehdr->e_phentsize;
  14110. - for (i=ehdr->e_phnum; i; i--, phdr=(void *)((char *)phdr + ehdr->e_phentsize)) {
  14111. - if (phdr->p_type == PT_DYNAMIC)
  14112. - vdso.dynv = (void *)(vdso_base + phdr->p_offset);
  14113. - if (phdr->p_type == PT_LOAD)
  14114. - vdso.base = (void *)(vdso_base - phdr->p_vaddr + phdr->p_offset);
  14115. - }
  14116. - vdso.name = "";
  14117. - vdso.shortname = "linux-gate.so.1";
  14118. - vdso.global = 1;
  14119. - vdso.relocated = 1;
  14120. - decode_dyn(&vdso);
  14121. - vdso.prev = &ldso;
  14122. - ldso.next = &vdso;
  14123. - }
  14124. -
  14125. - /* Initial dso chain consists only of the app. */
  14126. - head = tail = &app;
  14127. -
  14128. - /* Donate unused parts of app and library mapping to malloc */
  14129. - reclaim_gaps(&app);
  14130. - reclaim_gaps(&ldso);
  14131. -
  14132. - /* Load preload/needed libraries, add their symbols to the global
  14133. - * namespace, and perform all remaining relocations. */
  14134. - if (env_preload) load_preload(env_preload);
  14135. - load_deps(&app);
  14136. - make_global(&app);
  14137. -
  14138. -#ifndef DYNAMIC_IS_RO
  14139. - for (i=0; app.dynv[i]; i+=2)
  14140. - if (app.dynv[i]==DT_DEBUG)
  14141. - app.dynv[i+1] = (size_t)&debug;
  14142. -#endif
  14143. -
  14144. - /* The main program must be relocated LAST since it may contin
  14145. - * copy relocations which depend on libraries' relocations. */
  14146. - reloc_all(app.next);
  14147. - reloc_all(&app);
  14148. -
  14149. - update_tls_size();
  14150. - if (libc.tls_size > sizeof builtin_tls || tls_align > MIN_TLS_ALIGN) {
  14151. - void *initial_tls = calloc(libc.tls_size, 1);
  14152. - if (!initial_tls) {
  14153. - dprintf(2, "%s: Error getting %zu bytes thread-local storage: %m\n",
  14154. - argv[0], libc.tls_size);
  14155. - _exit(127);
  14156. - }
  14157. - if (__init_tp(__copy_tls(initial_tls)) < 0) {
  14158. - a_crash();
  14159. - }
  14160. - } else {
  14161. - size_t tmp_tls_size = libc.tls_size;
  14162. - pthread_t self = __pthread_self();
  14163. - /* Temporarily set the tls size to the full size of
  14164. - * builtin_tls so that __copy_tls will use the same layout
  14165. - * as it did for before. Then check, just to be safe. */
  14166. - libc.tls_size = sizeof builtin_tls;
  14167. - if (__copy_tls((void*)builtin_tls) != self) a_crash();
  14168. - libc.tls_size = tmp_tls_size;
  14169. - }
  14170. - static_tls_cnt = tls_cnt;
  14171. -
  14172. - if (ldso_fail) _exit(127);
  14173. - if (ldd_mode) _exit(0);
  14174. -
  14175. - /* Switch to runtime mode: any further failures in the dynamic
  14176. - * linker are a reportable failure rather than a fatal startup
  14177. - * error. */
  14178. - runtime = 1;
  14179. -
  14180. - debug.ver = 1;
  14181. - debug.bp = dl_debug_state;
  14182. - debug.head = head;
  14183. - debug.base = ldso.base;
  14184. - debug.state = 0;
  14185. - _dl_debug_state();
  14186. -
  14187. - __init_libc(envp, argv[0]);
  14188. - atexit(do_fini);
  14189. - errno = 0;
  14190. -
  14191. - CRTJMP((void *)aux[AT_ENTRY], argv-1);
  14192. - for(;;);
  14193. -}
  14194. -
  14195. -void *dlopen(const char *file, int mode)
  14196. -{
  14197. - struct dso *volatile p, *orig_tail, *next;
  14198. - size_t orig_tls_cnt, orig_tls_offset, orig_tls_align;
  14199. - size_t i;
  14200. - int cs;
  14201. - jmp_buf jb;
  14202. -
  14203. - if (!file) return head;
  14204. -
  14205. - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
  14206. - pthread_rwlock_wrlock(&lock);
  14207. - __inhibit_ptc();
  14208. -
  14209. - p = 0;
  14210. - orig_tls_cnt = tls_cnt;
  14211. - orig_tls_offset = tls_offset;
  14212. - orig_tls_align = tls_align;
  14213. - orig_tail = tail;
  14214. - noload = mode & RTLD_NOLOAD;
  14215. -
  14216. - rtld_fail = &jb;
  14217. - if (setjmp(*rtld_fail)) {
  14218. - /* Clean up anything new that was (partially) loaded */
  14219. - if (p && p->deps) for (i=0; p->deps[i]; i++)
  14220. - if (p->deps[i]->global < 0)
  14221. - p->deps[i]->global = 0;
  14222. - for (p=orig_tail->next; p; p=next) {
  14223. - next = p->next;
  14224. - while (p->td_index) {
  14225. - void *tmp = p->td_index->next;
  14226. - free(p->td_index);
  14227. - p->td_index = tmp;
  14228. - }
  14229. - free(p->funcdescs);
  14230. - if (p->rpath != p->rpath_orig)
  14231. - free(p->rpath);
  14232. - free(p->deps);
  14233. - unmap_library(p);
  14234. - free(p);
  14235. - }
  14236. - tls_cnt = orig_tls_cnt;
  14237. - tls_offset = orig_tls_offset;
  14238. - tls_align = orig_tls_align;
  14239. - tail = orig_tail;
  14240. - tail->next = 0;
  14241. - p = 0;
  14242. - goto end;
  14243. - } else p = load_library(file, head);
  14244. -
  14245. - if (!p) {
  14246. - error(noload ?
  14247. - "Library %s is not already loaded" :
  14248. - "Error loading shared library %s: %m",
  14249. - file);
  14250. - goto end;
  14251. - }
  14252. -
  14253. - /* First load handling */
  14254. - if (!p->deps) {
  14255. - load_deps(p);
  14256. - if (p->deps) for (i=0; p->deps[i]; i++)
  14257. - if (!p->deps[i]->global)
  14258. - p->deps[i]->global = -1;
  14259. - if (!p->global) p->global = -1;
  14260. - reloc_all(p);
  14261. - if (p->deps) for (i=0; p->deps[i]; i++)
  14262. - if (p->deps[i]->global < 0)
  14263. - p->deps[i]->global = 0;
  14264. - if (p->global < 0) p->global = 0;
  14265. - }
  14266. -
  14267. - if (mode & RTLD_GLOBAL) {
  14268. - if (p->deps) for (i=0; p->deps[i]; i++)
  14269. - p->deps[i]->global = 1;
  14270. - p->global = 1;
  14271. - }
  14272. -
  14273. - update_tls_size();
  14274. - _dl_debug_state();
  14275. - orig_tail = tail;
  14276. -end:
  14277. - __release_ptc();
  14278. - if (p) gencnt++;
  14279. - pthread_rwlock_unlock(&lock);
  14280. - if (p) do_init_fini(orig_tail);
  14281. - pthread_setcancelstate(cs, 0);
  14282. - return p;
  14283. -}
  14284. -
  14285. -static int invalid_dso_handle(void *h)
  14286. -{
  14287. - struct dso *p;
  14288. - for (p=head; p; p=p->next) if (h==p) return 0;
  14289. - error("Invalid library handle %p", (void *)h);
  14290. - return 1;
  14291. -}
  14292. -
  14293. -static void *addr2dso(size_t a)
  14294. -{
  14295. - struct dso *p;
  14296. - size_t i;
  14297. - if (DL_FDPIC) for (p=head; p; p=p->next) {
  14298. - i = count_syms(p);
  14299. - if (a-(size_t)p->funcdescs < i*sizeof(*p->funcdescs))
  14300. - return p;
  14301. - }
  14302. - for (p=head; p; p=p->next) {
  14303. - if (DL_FDPIC && p->loadmap) {
  14304. - for (i=0; i<p->loadmap->nsegs; i++) {
  14305. - if (a-p->loadmap->segs[i].p_vaddr
  14306. - < p->loadmap->segs[i].p_memsz)
  14307. - return p;
  14308. - }
  14309. - } else {
  14310. - if (a-(size_t)p->map < p->map_len)
  14311. - return p;
  14312. - }
  14313. - }
  14314. - return 0;
  14315. -}
  14316. -
  14317. -void *__tls_get_addr(size_t *);
  14318. -
  14319. -static void *do_dlsym(struct dso *p, const char *s, void *ra)
  14320. -{
  14321. - size_t i;
  14322. - uint32_t h = 0, gh = 0, *ght;
  14323. - Sym *sym;
  14324. - if (p == head || p == RTLD_DEFAULT || p == RTLD_NEXT) {
  14325. - if (p == RTLD_DEFAULT) {
  14326. - p = head;
  14327. - } else if (p == RTLD_NEXT) {
  14328. - p = addr2dso((size_t)ra);
  14329. - if (!p) p=head;
  14330. - p = p->next;
  14331. - }
  14332. - struct symdef def = find_sym(p, s, 0);
  14333. - if (!def.sym) goto failed;
  14334. - if ((def.sym->st_info&0xf) == STT_TLS)
  14335. - return __tls_get_addr((size_t []){def.dso->tls_id, def.sym->st_value});
  14336. - if (DL_FDPIC && (def.sym->st_info&0xf) == STT_FUNC)
  14337. - return def.dso->funcdescs + (def.sym - def.dso->syms);
  14338. - return laddr(def.dso, def.sym->st_value);
  14339. - }
  14340. - if (invalid_dso_handle(p))
  14341. - return 0;
  14342. - if ((ght = p->ghashtab)) {
  14343. - gh = gnu_hash(s);
  14344. - sym = gnu_lookup(gh, ght, p, s);
  14345. - } else {
  14346. - h = sysv_hash(s);
  14347. - sym = sysv_lookup(s, h, p);
  14348. - }
  14349. - if (sym && (sym->st_info&0xf) == STT_TLS)
  14350. - return __tls_get_addr((size_t []){p->tls_id, sym->st_value});
  14351. - if (DL_FDPIC && sym && sym->st_shndx && (sym->st_info&0xf) == STT_FUNC)
  14352. - return p->funcdescs + (sym - p->syms);
  14353. - if (sym && sym->st_value && (1<<(sym->st_info&0xf) & OK_TYPES))
  14354. - return laddr(p, sym->st_value);
  14355. - if (p->deps) for (i=0; p->deps[i]; i++) {
  14356. - if ((ght = p->deps[i]->ghashtab)) {
  14357. - if (!gh) gh = gnu_hash(s);
  14358. - sym = gnu_lookup(gh, ght, p->deps[i], s);
  14359. - } else {
  14360. - if (!h) h = sysv_hash(s);
  14361. - sym = sysv_lookup(s, h, p->deps[i]);
  14362. - }
  14363. - if (sym && (sym->st_info&0xf) == STT_TLS)
  14364. - return __tls_get_addr((size_t []){p->deps[i]->tls_id, sym->st_value});
  14365. - if (DL_FDPIC && sym && sym->st_shndx && (sym->st_info&0xf) == STT_FUNC)
  14366. - return p->deps[i]->funcdescs + (sym - p->deps[i]->syms);
  14367. - if (sym && sym->st_value && (1<<(sym->st_info&0xf) & OK_TYPES))
  14368. - return laddr(p->deps[i], sym->st_value);
  14369. - }
  14370. -failed:
  14371. - error("Symbol not found: %s", s);
  14372. - return 0;
  14373. -}
  14374. -
  14375. -int __dladdr(const void *addr, Dl_info *info)
  14376. -{
  14377. - struct dso *p;
  14378. - Sym *sym, *bestsym;
  14379. - uint32_t nsym;
  14380. - char *strings;
  14381. - void *best = 0;
  14382. -
  14383. - pthread_rwlock_rdlock(&lock);
  14384. - p = addr2dso((size_t)addr);
  14385. - pthread_rwlock_unlock(&lock);
  14386. -
  14387. - if (!p) return 0;
  14388. -
  14389. - sym = p->syms;
  14390. - strings = p->strings;
  14391. - nsym = count_syms(p);
  14392. -
  14393. - if (DL_FDPIC) {
  14394. - size_t idx = ((size_t)addr-(size_t)p->funcdescs)
  14395. - / sizeof(*p->funcdescs);
  14396. - if (idx < nsym && (sym[idx].st_info&0xf) == STT_FUNC) {
  14397. - best = p->funcdescs + idx;
  14398. - bestsym = sym + idx;
  14399. - }
  14400. - }
  14401. -
  14402. - if (!best) for (; nsym; nsym--, sym++) {
  14403. - if (sym->st_value
  14404. - && (1<<(sym->st_info&0xf) & OK_TYPES)
  14405. - && (1<<(sym->st_info>>4) & OK_BINDS)) {
  14406. - void *symaddr = laddr(p, sym->st_value);
  14407. - if (symaddr > addr || symaddr < best)
  14408. - continue;
  14409. - best = symaddr;
  14410. - bestsym = sym;
  14411. - if (addr == symaddr)
  14412. - break;
  14413. - }
  14414. - }
  14415. -
  14416. - if (!best) return 0;
  14417. -
  14418. - if (DL_FDPIC && (bestsym->st_info&0xf) == STT_FUNC)
  14419. - best = p->funcdescs + (bestsym - p->syms);
  14420. -
  14421. - info->dli_fname = p->name;
  14422. - info->dli_fbase = p->base;
  14423. - info->dli_sname = strings + bestsym->st_name;
  14424. - info->dli_saddr = best;
  14425. -
  14426. - return 1;
  14427. -}
  14428. -
  14429. -__attribute__((__visibility__("hidden")))
  14430. -void *__dlsym(void *restrict p, const char *restrict s, void *restrict ra)
  14431. -{
  14432. - void *res;
  14433. - pthread_rwlock_rdlock(&lock);
  14434. - res = do_dlsym(p, s, ra);
  14435. - pthread_rwlock_unlock(&lock);
  14436. - return res;
  14437. -}
  14438. -
  14439. -int dl_iterate_phdr(int(*callback)(struct dl_phdr_info *info, size_t size, void *data), void *data)
  14440. -{
  14441. - struct dso *current;
  14442. - struct dl_phdr_info info;
  14443. - int ret = 0;
  14444. - for(current = head; current;) {
  14445. - info.dlpi_addr = (uintptr_t)current->base;
  14446. - info.dlpi_name = current->name;
  14447. - info.dlpi_phdr = current->phdr;
  14448. - info.dlpi_phnum = current->phnum;
  14449. - info.dlpi_adds = gencnt;
  14450. - info.dlpi_subs = 0;
  14451. - info.dlpi_tls_modid = current->tls_id;
  14452. - info.dlpi_tls_data = current->tls_image;
  14453. -
  14454. - ret = (callback)(&info, sizeof (info), data);
  14455. -
  14456. - if (ret != 0) break;
  14457. -
  14458. - pthread_rwlock_rdlock(&lock);
  14459. - current = current->next;
  14460. - pthread_rwlock_unlock(&lock);
  14461. - }
  14462. - return ret;
  14463. -}
  14464. -#else
  14465. -static int invalid_dso_handle(void *h)
  14466. -{
  14467. - error("Invalid library handle %p", (void *)h);
  14468. - return 1;
  14469. -}
  14470. -void *dlopen(const char *file, int mode)
  14471. -{
  14472. - error("Dynamic loading not supported");
  14473. - return 0;
  14474. -}
  14475. -void *__dlsym(void *restrict p, const char *restrict s, void *restrict ra)
  14476. -{
  14477. - error("Symbol not found: %s", s);
  14478. - return 0;
  14479. -}
  14480. -int __dladdr (const void *addr, Dl_info *info)
  14481. -{
  14482. - return 0;
  14483. -}
  14484. -#endif
  14485. -
  14486. -int __dlinfo(void *dso, int req, void *res)
  14487. -{
  14488. - if (invalid_dso_handle(dso)) return -1;
  14489. - if (req != RTLD_DI_LINKMAP) {
  14490. - error("Unsupported request %d", req);
  14491. - return -1;
  14492. - }
  14493. - *(struct link_map **)res = dso;
  14494. - return 0;
  14495. -}
  14496. -
  14497. -char *dlerror()
  14498. -{
  14499. - pthread_t self = __pthread_self();
  14500. - if (!self->dlerror_flag) return 0;
  14501. - self->dlerror_flag = 0;
  14502. - char *s = self->dlerror_buf;
  14503. - if (s == (void *)-1)
  14504. - return "Dynamic linker failed to allocate memory for error message";
  14505. - else
  14506. - return s;
  14507. -}
  14508. -
  14509. -int dlclose(void *p)
  14510. -{
  14511. - return invalid_dso_handle(p);
  14512. -}
  14513. -
  14514. -void __dl_thread_cleanup(void)
  14515. -{
  14516. - pthread_t self = __pthread_self();
  14517. - if (self->dlerror_buf != (void *)-1)
  14518. - free(self->dlerror_buf);
  14519. -}
  14520. -
  14521. -static void error(const char *fmt, ...)
  14522. -{
  14523. - va_list ap;
  14524. - va_start(ap, fmt);
  14525. -#ifdef SHARED
  14526. - if (!runtime) {
  14527. - vdprintf(2, fmt, ap);
  14528. - dprintf(2, "\n");
  14529. - ldso_fail = 1;
  14530. - va_end(ap);
  14531. - return;
  14532. - }
  14533. -#endif
  14534. - pthread_t self = __pthread_self();
  14535. - if (self->dlerror_buf != (void *)-1)
  14536. - free(self->dlerror_buf);
  14537. - size_t len = vsnprintf(0, 0, fmt, ap);
  14538. - va_end(ap);
  14539. - char *buf = malloc(len+1);
  14540. - if (buf) {
  14541. - va_start(ap, fmt);
  14542. - vsnprintf(buf, len+1, fmt, ap);
  14543. - va_end(ap);
  14544. - } else {
  14545. - buf = (void *)-1;
  14546. - }
  14547. - self->dlerror_buf = buf;
  14548. - self->dlerror_flag = 1;
  14549. -}
  14550. --- a/src/ldso/tlsdesc.c
  14551. +++ b/src/ldso/tlsdesc.c
  14552. @@ -1,5 +1,3 @@
  14553. -#ifdef SHARED
  14554. -
  14555. #include <stddef.h>
  14556. #include "libc.h"
  14557. @@ -12,5 +10,3 @@ ptrdiff_t __tlsdesc_static()
  14558. }
  14559. weak_alias(__tlsdesc_static, __tlsdesc_dynamic);
  14560. -
  14561. -#endif
  14562. --- a/src/legacy/utmpx.c
  14563. +++ b/src/legacy/utmpx.c
  14564. @@ -1,5 +1,6 @@
  14565. #include <utmpx.h>
  14566. #include <stddef.h>
  14567. +#include <errno.h>
  14568. #include "libc.h"
  14569. void endutxent(void)
  14570. @@ -34,6 +35,12 @@ void updwtmpx(const char *f, const struc
  14571. {
  14572. }
  14573. +int __utmpxname(const char *f)
  14574. +{
  14575. + errno = ENOTSUP;
  14576. + return -1;
  14577. +}
  14578. +
  14579. weak_alias(endutxent, endutent);
  14580. weak_alias(setutxent, setutent);
  14581. weak_alias(getutxent, getutent);
  14582. @@ -41,3 +48,5 @@ weak_alias(getutxid, getutid);
  14583. weak_alias(getutxline, getutline);
  14584. weak_alias(pututxline, pututline);
  14585. weak_alias(updwtmpx, updwtmp);
  14586. +weak_alias(__utmpxname, utmpname);
  14587. +weak_alias(__utmpxname, utmpxname);
  14588. --- /dev/null
  14589. +++ b/src/linux/x32/sysinfo.c
  14590. @@ -0,0 +1,50 @@
  14591. +#include <sys/sysinfo.h>
  14592. +#include "syscall.h"
  14593. +#include "libc.h"
  14594. +
  14595. +#define klong long long
  14596. +#define kulong unsigned long long
  14597. +
  14598. +struct kernel_sysinfo {
  14599. + klong uptime;
  14600. + kulong loads[3];
  14601. + kulong totalram;
  14602. + kulong freeram;
  14603. + kulong sharedram;
  14604. + kulong bufferram;
  14605. + kulong totalswap;
  14606. + kulong freeswap;
  14607. + short procs;
  14608. + short pad;
  14609. + kulong totalhigh;
  14610. + kulong freehigh;
  14611. + unsigned mem_unit;
  14612. +};
  14613. +
  14614. +int __lsysinfo(struct sysinfo *info)
  14615. +{
  14616. + struct kernel_sysinfo tmp;
  14617. + int ret = syscall(SYS_sysinfo, &tmp);
  14618. + if(ret == -1) return ret;
  14619. + info->uptime = tmp.uptime;
  14620. + info->loads[0] = tmp.loads[0];
  14621. + info->loads[1] = tmp.loads[1];
  14622. + info->loads[2] = tmp.loads[2];
  14623. + kulong shifts;
  14624. + kulong max = tmp.totalram | tmp.totalswap;
  14625. + __asm__("bsr %1,%0" : "=r"(shifts) : "r"(max));
  14626. + shifts = shifts >= 32 ? shifts - 31 : 0;
  14627. + info->totalram = tmp.totalram >> shifts;
  14628. + info->freeram = tmp.freeram >> shifts;
  14629. + info->sharedram = tmp.sharedram >> shifts;
  14630. + info->bufferram = tmp.bufferram >> shifts;
  14631. + info->totalswap = tmp.totalswap >> shifts;
  14632. + info->freeswap = tmp.freeswap >> shifts;
  14633. + info->procs = tmp.procs ;
  14634. + info->totalhigh = tmp.totalhigh >> shifts;
  14635. + info->freehigh = tmp.freehigh >> shifts;
  14636. + info->mem_unit = (tmp.mem_unit ? tmp.mem_unit : 1) << shifts;
  14637. + return ret;
  14638. +}
  14639. +
  14640. +weak_alias(__lsysinfo, sysinfo);
  14641. --- a/src/linux/x32/sysinfo.s
  14642. +++ /dev/null
  14643. @@ -1 +0,0 @@
  14644. -# see arch/x32/src/sysinfo.c
  14645. --- a/src/locale/langinfo.c
  14646. +++ b/src/locale/langinfo.c
  14647. @@ -37,23 +37,23 @@ char *__nl_langinfo_l(nl_item item, loca
  14648. switch (cat) {
  14649. case LC_NUMERIC:
  14650. - if (idx > 1) return NULL;
  14651. + if (idx > 1) return "";
  14652. str = c_numeric;
  14653. break;
  14654. case LC_TIME:
  14655. - if (idx > 0x31) return NULL;
  14656. + if (idx > 0x31) return "";
  14657. str = c_time;
  14658. break;
  14659. case LC_MONETARY:
  14660. - if (idx > 0) return NULL;
  14661. + if (idx > 0) return "";
  14662. str = "";
  14663. break;
  14664. case LC_MESSAGES:
  14665. - if (idx > 3) return NULL;
  14666. + if (idx > 3) return "";
  14667. str = c_messages;
  14668. break;
  14669. default:
  14670. - return NULL;
  14671. + return "";
  14672. }
  14673. for (; idx; idx--, str++) for (; *str; str++);
  14674. --- a/src/malloc/lite_malloc.c
  14675. +++ b/src/malloc/lite_malloc.c
  14676. @@ -8,7 +8,7 @@
  14677. void *__expand_heap(size_t *);
  14678. -void *__simple_malloc(size_t n)
  14679. +static void *__simple_malloc(size_t n)
  14680. {
  14681. static char *cur, *end;
  14682. static volatile int lock[2];
  14683. --- a/src/math/__rem_pio2.c
  14684. +++ b/src/math/__rem_pio2.c
  14685. @@ -118,7 +118,7 @@ int __rem_pio2(double x, double *y)
  14686. if (ix < 0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */
  14687. medium:
  14688. /* rint(x/(pi/2)), Assume round-to-nearest. */
  14689. - fn = x*invpio2 + toint - toint;
  14690. + fn = (double_t)x*invpio2 + toint - toint;
  14691. n = (int32_t)fn;
  14692. r = x - fn*pio2_1;
  14693. w = fn*pio2_1t; /* 1st round, good to 85 bits */
  14694. --- a/src/math/__rem_pio2f.c
  14695. +++ b/src/math/__rem_pio2f.c
  14696. @@ -51,7 +51,7 @@ int __rem_pio2f(float x, double *y)
  14697. /* 25+53 bit pi is good enough for medium size */
  14698. if (ix < 0x4dc90fdb) { /* |x| ~< 2^28*(pi/2), medium size */
  14699. /* Use a specialized rint() to get fn. Assume round-to-nearest. */
  14700. - fn = x*invpio2 + toint - toint;
  14701. + fn = (double_t)x*invpio2 + toint - toint;
  14702. n = (int32_t)fn;
  14703. *y = x - fn*pio2_1 - fn*pio2_1t;
  14704. return n;
  14705. --- /dev/null
  14706. +++ b/src/math/arm/fabs.c
  14707. @@ -0,0 +1,15 @@
  14708. +#include <math.h>
  14709. +
  14710. +#if __ARM_PCS_VFP
  14711. +
  14712. +double fabs(double x)
  14713. +{
  14714. + __asm__ ("vabs.f64 %P0, %P1" : "=w"(x) : "w"(x));
  14715. + return x;
  14716. +}
  14717. +
  14718. +#else
  14719. +
  14720. +#include "../fabs.c"
  14721. +
  14722. +#endif
  14723. --- /dev/null
  14724. +++ b/src/math/arm/fabsf.c
  14725. @@ -0,0 +1,15 @@
  14726. +#include <math.h>
  14727. +
  14728. +#if __ARM_PCS_VFP
  14729. +
  14730. +float fabsf(float x)
  14731. +{
  14732. + __asm__ ("vabs.f32 %0, %1" : "=t"(x) : "t"(x));
  14733. + return x;
  14734. +}
  14735. +
  14736. +#else
  14737. +
  14738. +#include "../fabsf.c"
  14739. +
  14740. +#endif
  14741. --- /dev/null
  14742. +++ b/src/math/arm/sqrt.c
  14743. @@ -0,0 +1,15 @@
  14744. +#include <math.h>
  14745. +
  14746. +#if __VFP_FP__ && !__SOFTFP__
  14747. +
  14748. +double sqrt(double x)
  14749. +{
  14750. + __asm__ ("vsqrt.f64 %P0, %P1" : "=w"(x) : "w"(x));
  14751. + return x;
  14752. +}
  14753. +
  14754. +#else
  14755. +
  14756. +#include "../sqrt.c"
  14757. +
  14758. +#endif
  14759. --- /dev/null
  14760. +++ b/src/math/arm/sqrtf.c
  14761. @@ -0,0 +1,15 @@
  14762. +#include <math.h>
  14763. +
  14764. +#if __VFP_FP__ && !__SOFTFP__
  14765. +
  14766. +float sqrtf(float x)
  14767. +{
  14768. + __asm__ ("vsqrt.f32 %0, %1" : "=t"(x) : "t"(x));
  14769. + return x;
  14770. +}
  14771. +
  14772. +#else
  14773. +
  14774. +#include "../sqrtf.c"
  14775. +
  14776. +#endif
  14777. --- a/src/math/armebhf/fabs.sub
  14778. +++ /dev/null
  14779. @@ -1 +0,0 @@
  14780. -../armhf/fabs.s
  14781. --- a/src/math/armebhf/fabsf.sub
  14782. +++ /dev/null
  14783. @@ -1 +0,0 @@
  14784. -../armhf/fabsf.s
  14785. --- a/src/math/armebhf/sqrt.sub
  14786. +++ /dev/null
  14787. @@ -1 +0,0 @@
  14788. -../armhf/sqrt.s
  14789. --- a/src/math/armebhf/sqrtf.sub
  14790. +++ /dev/null
  14791. @@ -1 +0,0 @@
  14792. -../armhf/sqrtf.s
  14793. --- a/src/math/armhf/fabs.s
  14794. +++ /dev/null
  14795. @@ -1,7 +0,0 @@
  14796. -.fpu vfp
  14797. -.text
  14798. -.global fabs
  14799. -.type fabs,%function
  14800. -fabs:
  14801. - vabs.f64 d0, d0
  14802. - bx lr
  14803. --- a/src/math/armhf/fabs.sub
  14804. +++ /dev/null
  14805. @@ -1 +0,0 @@
  14806. -fabs.s
  14807. --- a/src/math/armhf/fabsf.s
  14808. +++ /dev/null
  14809. @@ -1,7 +0,0 @@
  14810. -.fpu vfp
  14811. -.text
  14812. -.global fabsf
  14813. -.type fabsf,%function
  14814. -fabsf:
  14815. - vabs.f32 s0, s0
  14816. - bx lr
  14817. --- a/src/math/armhf/fabsf.sub
  14818. +++ /dev/null
  14819. @@ -1 +0,0 @@
  14820. -fabsf.s
  14821. --- a/src/math/armhf/sqrt.s
  14822. +++ /dev/null
  14823. @@ -1,7 +0,0 @@
  14824. -.fpu vfp
  14825. -.text
  14826. -.global sqrt
  14827. -.type sqrt,%function
  14828. -sqrt:
  14829. - vsqrt.f64 d0, d0
  14830. - bx lr
  14831. --- a/src/math/armhf/sqrt.sub
  14832. +++ /dev/null
  14833. @@ -1 +0,0 @@
  14834. -sqrt.s
  14835. --- a/src/math/armhf/sqrtf.s
  14836. +++ /dev/null
  14837. @@ -1,7 +0,0 @@
  14838. -.fpu vfp
  14839. -.text
  14840. -.global sqrtf
  14841. -.type sqrtf,%function
  14842. -sqrtf:
  14843. - vsqrt.f32 s0, s0
  14844. - bx lr
  14845. --- a/src/math/armhf/sqrtf.sub
  14846. +++ /dev/null
  14847. @@ -1 +0,0 @@
  14848. -sqrtf.s
  14849. --- a/src/math/hypot.c
  14850. +++ b/src/math/hypot.c
  14851. @@ -12,10 +12,10 @@ static void sq(double_t *hi, double_t *l
  14852. {
  14853. double_t xh, xl, xc;
  14854. - xc = x*SPLIT;
  14855. + xc = (double_t)x*SPLIT;
  14856. xh = x - xc + xc;
  14857. xl = x - xh;
  14858. - *hi = x*x;
  14859. + *hi = (double_t)x*x;
  14860. *lo = xh*xh - *hi + 2*xh*xl + xl*xl;
  14861. }
  14862. --- a/src/mman/mremap.c
  14863. +++ b/src/mman/mremap.c
  14864. @@ -1,17 +1,31 @@
  14865. +#define _GNU_SOURCE
  14866. #include <unistd.h>
  14867. #include <sys/mman.h>
  14868. +#include <errno.h>
  14869. +#include <stdint.h>
  14870. #include <stdarg.h>
  14871. #include "syscall.h"
  14872. #include "libc.h"
  14873. +static void dummy(void) { }
  14874. +weak_alias(dummy, __vm_wait);
  14875. +
  14876. void *__mremap(void *old_addr, size_t old_len, size_t new_len, int flags, ...)
  14877. {
  14878. va_list ap;
  14879. - void *new_addr;
  14880. -
  14881. - va_start(ap, flags);
  14882. - new_addr = va_arg(ap, void *);
  14883. - va_end(ap);
  14884. + void *new_addr = 0;
  14885. +
  14886. + if (new_len >= PTRDIFF_MAX) {
  14887. + errno = ENOMEM;
  14888. + return MAP_FAILED;
  14889. + }
  14890. +
  14891. + if (flags & MREMAP_FIXED) {
  14892. + __vm_wait();
  14893. + va_start(ap, flags);
  14894. + new_addr = va_arg(ap, void *);
  14895. + va_end(ap);
  14896. + }
  14897. return (void *)syscall(SYS_mremap, old_addr, old_len, new_len, flags, new_addr);
  14898. }
  14899. --- a/src/network/getifaddrs.c
  14900. +++ b/src/network/getifaddrs.c
  14901. @@ -162,13 +162,26 @@ static int netlink_msg_to_ifaddr(void *p
  14902. for (rta = NLMSG_RTA(h, sizeof(*ifa)); NLMSG_RTAOK(rta, h); rta = RTA_NEXT(rta)) {
  14903. switch (rta->rta_type) {
  14904. case IFA_ADDRESS:
  14905. - copy_addr(&ifs->ifa.ifa_addr, ifa->ifa_family, &ifs->addr, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index);
  14906. + /* If ifa_addr is already set we, received an IFA_LOCAL before
  14907. + * so treat this as destination address */
  14908. + if (ifs->ifa.ifa_addr)
  14909. + copy_addr(&ifs->ifa.ifa_dstaddr, ifa->ifa_family, &ifs->ifu, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index);
  14910. + else
  14911. + copy_addr(&ifs->ifa.ifa_addr, ifa->ifa_family, &ifs->addr, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index);
  14912. break;
  14913. case IFA_BROADCAST:
  14914. - /* For point-to-point links this is peer, but ifa_broadaddr
  14915. - * and ifa_dstaddr are union, so this works for both. */
  14916. copy_addr(&ifs->ifa.ifa_broadaddr, ifa->ifa_family, &ifs->ifu, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index);
  14917. break;
  14918. + case IFA_LOCAL:
  14919. + /* If ifa_addr is set and we get IFA_LOCAL, assume we have
  14920. + * a point-to-point network. Move address to correct field. */
  14921. + if (ifs->ifa.ifa_addr) {
  14922. + ifs->ifu = ifs->addr;
  14923. + ifs->ifa.ifa_dstaddr = &ifs->ifu.sa;
  14924. + memset(&ifs->addr, 0, sizeof(ifs->addr));
  14925. + }
  14926. + copy_addr(&ifs->ifa.ifa_addr, ifa->ifa_family, &ifs->addr, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index);
  14927. + break;
  14928. case IFA_LABEL:
  14929. if (RTA_DATALEN(rta) < sizeof(ifs->name)) {
  14930. memcpy(ifs->name, RTA_DATA(rta), RTA_DATALEN(rta));
  14931. --- a/src/network/getnameinfo.c
  14932. +++ b/src/network/getnameinfo.c
  14933. @@ -135,13 +135,13 @@ int getnameinfo(const struct sockaddr *r
  14934. switch (af) {
  14935. case AF_INET:
  14936. a = (void *)&((struct sockaddr_in *)sa)->sin_addr;
  14937. - if (sl != sizeof(struct sockaddr_in)) return EAI_FAMILY;
  14938. + if (sl < sizeof(struct sockaddr_in)) return EAI_FAMILY;
  14939. mkptr4(ptr, a);
  14940. scopeid = 0;
  14941. break;
  14942. case AF_INET6:
  14943. a = (void *)&((struct sockaddr_in6 *)sa)->sin6_addr;
  14944. - if (sl != sizeof(struct sockaddr_in6)) return EAI_FAMILY;
  14945. + if (sl < sizeof(struct sockaddr_in6)) return EAI_FAMILY;
  14946. if (memcmp(a, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12))
  14947. mkptr6(ptr, a);
  14948. else
  14949. --- a/src/network/if_nametoindex.c
  14950. +++ b/src/network/if_nametoindex.c
  14951. @@ -10,7 +10,7 @@ unsigned if_nametoindex(const char *name
  14952. struct ifreq ifr;
  14953. int fd, r;
  14954. - if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) return -1;
  14955. + if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) return 0;
  14956. strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
  14957. r = ioctl(fd, SIOCGIFINDEX, &ifr);
  14958. __syscall(SYS_close, fd);
  14959. --- a/src/network/lookup.h
  14960. +++ b/src/network/lookup.h
  14961. @@ -2,6 +2,7 @@
  14962. #define LOOKUP_H
  14963. #include <stdint.h>
  14964. +#include <stddef.h>
  14965. struct address {
  14966. int family;
  14967. @@ -15,6 +16,14 @@ struct service {
  14968. unsigned char proto, socktype;
  14969. };
  14970. +#define MAXNS 3
  14971. +
  14972. +struct resolvconf {
  14973. + struct address ns[MAXNS];
  14974. + unsigned nns, attempts, ndots;
  14975. + unsigned timeout;
  14976. +};
  14977. +
  14978. /* The limit of 48 results is a non-sharp bound on the number of addresses
  14979. * that can fit in one 512-byte DNS packet full of v4 results and a second
  14980. * packet full of v6 results. Due to headers, the actual limit is lower. */
  14981. @@ -25,4 +34,6 @@ int __lookup_serv(struct service buf[sta
  14982. int __lookup_name(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, int flags);
  14983. int __lookup_ipliteral(struct address buf[static 1], const char *name, int family);
  14984. +int __get_resolv_conf(struct resolvconf *, char *, size_t);
  14985. +
  14986. #endif
  14987. --- a/src/network/lookup_name.c
  14988. +++ b/src/network/lookup_name.c
  14989. @@ -9,6 +9,7 @@
  14990. #include <fcntl.h>
  14991. #include <unistd.h>
  14992. #include <pthread.h>
  14993. +#include <errno.h>
  14994. #include "lookup.h"
  14995. #include "stdio_impl.h"
  14996. #include "syscall.h"
  14997. @@ -51,7 +52,14 @@ static int name_from_hosts(struct addres
  14998. int cnt = 0;
  14999. unsigned char _buf[1032];
  15000. FILE _f, *f = __fopen_rb_ca("/etc/hosts", &_f, _buf, sizeof _buf);
  15001. - if (!f) return 0;
  15002. + if (!f) switch (errno) {
  15003. + case ENOENT:
  15004. + case ENOTDIR:
  15005. + case EACCES:
  15006. + return 0;
  15007. + default:
  15008. + return EAI_SYSTEM;
  15009. + }
  15010. while (fgets(line, sizeof line, f) && cnt < MAXADDRS) {
  15011. char *p, *z;
  15012. @@ -85,7 +93,7 @@ struct dpc_ctx {
  15013. int __dns_parse(const unsigned char *, int, int (*)(void *, int, const void *, int, const void *), void *);
  15014. int __dn_expand(const unsigned char *, const unsigned char *, const unsigned char *, char *, int);
  15015. int __res_mkquery(int, const char *, int, int, const unsigned char *, int, const unsigned char*, unsigned char *, int);
  15016. -int __res_msend(int, const unsigned char *const *, const int *, unsigned char *const *, int *, int);
  15017. +int __res_msend_rc(int, const unsigned char *const *, const int *, unsigned char *const *, int *, int, const struct resolvconf *);
  15018. #define RR_A 1
  15019. #define RR_CNAME 5
  15020. @@ -117,7 +125,7 @@ static int dns_parse_callback(void *c, i
  15021. return 0;
  15022. }
  15023. -static int name_from_dns(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family)
  15024. +static int name_from_dns(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, const struct resolvconf *conf)
  15025. {
  15026. unsigned char qbuf[2][280], abuf[2][512];
  15027. const unsigned char *qp[2] = { qbuf[0], qbuf[1] };
  15028. @@ -137,17 +145,59 @@ static int name_from_dns(struct address
  15029. nq++;
  15030. }
  15031. - if (__res_msend(nq, qp, qlens, ap, alens, sizeof *abuf) < 0) return EAI_SYSTEM;
  15032. + if (__res_msend_rc(nq, qp, qlens, ap, alens, sizeof *abuf, conf) < 0)
  15033. + return EAI_SYSTEM;
  15034. for (i=0; i<nq; i++)
  15035. __dns_parse(abuf[i], alens[i], dns_parse_callback, &ctx);
  15036. if (ctx.cnt) return ctx.cnt;
  15037. if (alens[0] < 4 || (abuf[0][3] & 15) == 2) return EAI_AGAIN;
  15038. - if ((abuf[0][3] & 15) == 3) return EAI_NONAME;
  15039. + if ((abuf[0][3] & 15) == 0) return EAI_NONAME;
  15040. + if ((abuf[0][3] & 15) == 3) return 0;
  15041. return EAI_FAIL;
  15042. }
  15043. +static int name_from_dns_search(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family)
  15044. +{
  15045. + char search[256];
  15046. + struct resolvconf conf;
  15047. + size_t l, dots;
  15048. + char *p, *z;
  15049. +
  15050. + if (__get_resolv_conf(&conf, search, sizeof search) < 0) return -1;
  15051. +
  15052. + /* Count dots, suppress search when >=ndots or name ends in
  15053. + * a dot, which is an explicit request for global scope. */
  15054. + for (dots=l=0; name[l]; l++) if (name[l]=='.') dots++;
  15055. + if (dots >= conf.ndots || name[l-1]=='.') *search = 0;
  15056. +
  15057. + /* This can never happen; the caller already checked length. */
  15058. + if (l >= 256) return EAI_NONAME;
  15059. +
  15060. + /* Name with search domain appended is setup in canon[]. This both
  15061. + * provides the desired default canonical name (if the requested
  15062. + * name is not a CNAME record) and serves as a buffer for passing
  15063. + * the full requested name to name_from_dns. */
  15064. + memcpy(canon, name, l);
  15065. + canon[l] = '.';
  15066. +
  15067. + for (p=search; *p; p=z) {
  15068. + for (; isspace(*p); p++);
  15069. + for (z=p; *z && !isspace(*z); z++);
  15070. + if (z==p) break;
  15071. + if (z-p < 256 - l - 1) {
  15072. + memcpy(canon+l+1, p, z-p);
  15073. + canon[z-p+1+l] = 0;
  15074. + int cnt = name_from_dns(buf, canon, canon, family, &conf);
  15075. + if (cnt) return cnt;
  15076. + }
  15077. + }
  15078. +
  15079. + canon[l] = 0;
  15080. + return name_from_dns(buf, canon, name, family, &conf);
  15081. +}
  15082. +
  15083. static const struct policy {
  15084. unsigned char addr[16];
  15085. unsigned char len, mask;
  15086. @@ -248,7 +298,7 @@ int __lookup_name(struct address buf[sta
  15087. if (!cnt) cnt = name_from_numeric(buf, name, family);
  15088. if (!cnt && !(flags & AI_NUMERICHOST)) {
  15089. cnt = name_from_hosts(buf, canon, name, family);
  15090. - if (!cnt) cnt = name_from_dns(buf, canon, name, family);
  15091. + if (!cnt) cnt = name_from_dns_search(buf, canon, name, family);
  15092. }
  15093. if (cnt<=0) return cnt ? cnt : EAI_NONAME;
  15094. --- a/src/network/lookup_serv.c
  15095. +++ b/src/network/lookup_serv.c
  15096. @@ -4,6 +4,7 @@
  15097. #include <ctype.h>
  15098. #include <string.h>
  15099. #include <fcntl.h>
  15100. +#include <errno.h>
  15101. #include "lookup.h"
  15102. #include "stdio_impl.h"
  15103. @@ -69,7 +70,14 @@ int __lookup_serv(struct service buf[sta
  15104. unsigned char _buf[1032];
  15105. FILE _f, *f = __fopen_rb_ca("/etc/services", &_f, _buf, sizeof _buf);
  15106. - if (!f) return EAI_SERVICE;
  15107. + if (!f) switch (errno) {
  15108. + case ENOENT:
  15109. + case ENOTDIR:
  15110. + case EACCES:
  15111. + return EAI_SERVICE;
  15112. + default:
  15113. + return EAI_SYSTEM;
  15114. + }
  15115. while (fgets(line, sizeof line, f) && cnt < MAXSERVS) {
  15116. if ((p=strchr(line, '#'))) *p++='\n', *p=0;
  15117. --- a/src/network/proto.c
  15118. +++ b/src/network/proto.c
  15119. @@ -9,21 +9,36 @@ static const unsigned char protos[] = {
  15120. "\001icmp\0"
  15121. "\002igmp\0"
  15122. "\003ggp\0"
  15123. + "\004ipencap\0"
  15124. + "\005st\0"
  15125. "\006tcp\0"
  15126. + "\008egp\0"
  15127. "\014pup\0"
  15128. "\021udp\0"
  15129. - "\026idp\0"
  15130. + "\024hmp\0"
  15131. + "\026xns-idp\0"
  15132. + "\033rdp\0"
  15133. + "\035iso-tp4\0"
  15134. + "\044xtp\0"
  15135. + "\045ddp\0"
  15136. + "\046idpr-cmtp\0"
  15137. "\051ipv6\0"
  15138. "\053ipv6-route\0"
  15139. "\054ipv6-frag\0"
  15140. + "\055idrp\0"
  15141. + "\056rsvp\0"
  15142. "\057gre\0"
  15143. "\062esp\0"
  15144. "\063ah\0"
  15145. + "\071skip\0"
  15146. "\072ipv6-icmp\0"
  15147. "\073ipv6-nonxt\0"
  15148. "\074ipv6-opts\0"
  15149. + "\111rspf\0"
  15150. + "\121vmtp\0"
  15151. "\131ospf\0"
  15152. "\136ipip\0"
  15153. + "\142encap\0"
  15154. "\147pim\0"
  15155. "\377raw"
  15156. };
  15157. --- a/src/network/res_msend.c
  15158. +++ b/src/network/res_msend.c
  15159. @@ -27,18 +27,16 @@ static unsigned long mtime()
  15160. + ts.tv_nsec / 1000000;
  15161. }
  15162. -int __res_msend(int nqueries, const unsigned char *const *queries,
  15163. - const int *qlens, unsigned char *const *answers, int *alens, int asize)
  15164. +int __res_msend_rc(int nqueries, const unsigned char *const *queries,
  15165. + const int *qlens, unsigned char *const *answers, int *alens, int asize,
  15166. + const struct resolvconf *conf)
  15167. {
  15168. int fd;
  15169. - FILE *f, _f;
  15170. - unsigned char _buf[256];
  15171. - char line[64], *s, *z;
  15172. - int timeout = 5000, attempts = 2, retry_interval, servfail_retry;
  15173. + int timeout, attempts, retry_interval, servfail_retry;
  15174. union {
  15175. struct sockaddr_in sin;
  15176. struct sockaddr_in6 sin6;
  15177. - } sa = {0}, ns[3] = {{0}};
  15178. + } sa = {0}, ns[MAXNS] = {{0}};
  15179. socklen_t sl = sizeof sa.sin;
  15180. int nns = 0;
  15181. int family = AF_INET;
  15182. @@ -48,57 +46,27 @@ int __res_msend(int nqueries, const unsi
  15183. int cs;
  15184. struct pollfd pfd;
  15185. unsigned long t0, t1, t2;
  15186. - struct address iplit;
  15187. pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
  15188. - /* Get nameservers from resolv.conf, fallback to localhost */
  15189. - f = __fopen_rb_ca("/etc/resolv.conf", &_f, _buf, sizeof _buf);
  15190. - if (f) for (nns=0; nns<3 && fgets(line, sizeof line, f); ) {
  15191. - if (!strncmp(line, "options", 7) && isspace(line[7])) {
  15192. - unsigned long x;
  15193. - char *p, *z;
  15194. - p = strstr(line, "timeout:");
  15195. - if (p && isdigit(p[8])) {
  15196. - p += 8;
  15197. - x = strtoul(p, &z, 10);
  15198. - if (z != p) timeout = x < 30 ? x*1000 : 30000;
  15199. - }
  15200. - p = strstr(line, "attempts:");
  15201. - if (p && isdigit(p[9])) {
  15202. - p += 9;
  15203. - x = strtoul(p, &z, 10);
  15204. - if (z != p) attempts = x < 10 ? x : 10;
  15205. - if (!attempts) attempts = 1;
  15206. - }
  15207. - }
  15208. - if (strncmp(line, "nameserver", 10) || !isspace(line[10]))
  15209. - continue;
  15210. - for (s=line+11; isspace(*s); s++);
  15211. - for (z=s; *z && !isspace(*z); z++);
  15212. - *z=0;
  15213. + timeout = 1000*conf->timeout;
  15214. + attempts = conf->attempts;
  15215. - if (__lookup_ipliteral(&iplit, s, AF_UNSPEC)>0) {
  15216. - if (iplit.family == AF_INET) {
  15217. - memcpy(&ns[nns].sin.sin_addr, iplit.addr, 4);
  15218. - ns[nns].sin.sin_port = htons(53);
  15219. - ns[nns++].sin.sin_family = AF_INET;
  15220. - } else {
  15221. - sl = sizeof sa.sin6;
  15222. - memcpy(&ns[nns].sin6.sin6_addr, iplit.addr, 16);
  15223. - ns[nns].sin6.sin6_port = htons(53);
  15224. - ns[nns].sin6.sin6_scope_id = iplit.scopeid;
  15225. - ns[nns++].sin6.sin6_family = family = AF_INET6;
  15226. - }
  15227. + nns = conf->nns;
  15228. + for (nns=0; nns<conf->nns; nns++) {
  15229. + const struct address *iplit = &conf->ns[nns];
  15230. + if (iplit->family == AF_INET) {
  15231. + memcpy(&ns[nns].sin.sin_addr, iplit->addr, 4);
  15232. + ns[nns].sin.sin_port = htons(53);
  15233. + ns[nns].sin.sin_family = AF_INET;
  15234. + } else {
  15235. + sl = sizeof sa.sin6;
  15236. + memcpy(&ns[nns].sin6.sin6_addr, iplit->addr, 16);
  15237. + ns[nns].sin6.sin6_port = htons(53);
  15238. + ns[nns].sin6.sin6_scope_id = iplit->scopeid;
  15239. + ns[nns].sin6.sin6_family = family = AF_INET6;
  15240. }
  15241. }
  15242. - if (f) __fclose_ca(f);
  15243. - if (!nns) {
  15244. - ns[0].sin.sin_family = AF_INET;
  15245. - ns[0].sin.sin_port = htons(53);
  15246. - ns[0].sin.sin_addr.s_addr = htonl(0x7f000001);
  15247. - nns=1;
  15248. - }
  15249. /* Get local address and open/bind a socket */
  15250. sa.sin.sin_family = family;
  15251. @@ -207,3 +175,11 @@ out:
  15252. return 0;
  15253. }
  15254. +
  15255. +int __res_msend(int nqueries, const unsigned char *const *queries,
  15256. + const int *qlens, unsigned char *const *answers, int *alens, int asize)
  15257. +{
  15258. + struct resolvconf conf;
  15259. + if (__get_resolv_conf(&conf, 0, 0) < 0) return -1;
  15260. + return __res_msend_rc(nqueries, queries, qlens, answers, alens, asize, &conf);
  15261. +}
  15262. --- /dev/null
  15263. +++ b/src/network/resolvconf.c
  15264. @@ -0,0 +1,93 @@
  15265. +#include "lookup.h"
  15266. +#include "stdio_impl.h"
  15267. +#include <ctype.h>
  15268. +#include <errno.h>
  15269. +#include <string.h>
  15270. +#include <netinet/in.h>
  15271. +
  15272. +int __get_resolv_conf(struct resolvconf *conf, char *search, size_t search_sz)
  15273. +{
  15274. + char line[256];
  15275. + unsigned char _buf[256];
  15276. + FILE *f, _f;
  15277. + int nns = 0;
  15278. +
  15279. + conf->ndots = 1;
  15280. + conf->timeout = 5;
  15281. + conf->attempts = 2;
  15282. + if (search) *search = 0;
  15283. +
  15284. + f = __fopen_rb_ca("/etc/resolv.conf", &_f, _buf, sizeof _buf);
  15285. + if (!f) switch (errno) {
  15286. + case ENOENT:
  15287. + case ENOTDIR:
  15288. + case EACCES:
  15289. + goto no_resolv_conf;
  15290. + default:
  15291. + return -1;
  15292. + }
  15293. +
  15294. + while (fgets(line, sizeof line, f)) {
  15295. + char *p, *z;
  15296. + if (!strchr(line, '\n') && !feof(f)) {
  15297. + /* Ignore lines that get truncated rather than
  15298. + * potentially misinterpreting them. */
  15299. + int c;
  15300. + do c = getc(f);
  15301. + while (c != '\n' && c != EOF);
  15302. + continue;
  15303. + }
  15304. + if (!strncmp(line, "options", 7) && isspace(line[7])) {
  15305. + p = strstr(line, "ndots:");
  15306. + if (p && isdigit(p[6])) {
  15307. + p += 6;
  15308. + unsigned long x = strtoul(p, &z, 10);
  15309. + if (z != p) conf->ndots = x > 15 ? 15 : x;
  15310. + }
  15311. + p = strstr(line, "attempts:");
  15312. + if (p && isdigit(p[6])) {
  15313. + p += 6;
  15314. + unsigned long x = strtoul(p, &z, 10);
  15315. + if (z != p) conf->attempts = x > 10 ? 10 : x;
  15316. + }
  15317. + p = strstr(line, "timeout:");
  15318. + if (p && (isdigit(p[8]) || p[8]=='.')) {
  15319. + p += 8;
  15320. + unsigned long x = strtoul(p, &z, 10);
  15321. + if (z != p) conf->timeout = x > 60 ? 60 : x;
  15322. + }
  15323. + continue;
  15324. + }
  15325. + if (!strncmp(line, "nameserver", 10) && isspace(line[10])) {
  15326. + if (nns >= MAXNS) continue;
  15327. + for (p=line+11; isspace(*p); p++);
  15328. + for (z=p; *z && !isspace(*z); z++);
  15329. + *z=0;
  15330. + if (__lookup_ipliteral(conf->ns+nns, p, AF_UNSPEC) > 0)
  15331. + nns++;
  15332. + continue;
  15333. + }
  15334. +
  15335. + if (!search) continue;
  15336. + if ((strncmp(line, "domain", 6) && strncmp(line, "search", 6))
  15337. + || !isspace(line[6]))
  15338. + continue;
  15339. + for (p=line+7; isspace(*p); p++);
  15340. + size_t l = strlen(p);
  15341. + /* This can never happen anyway with chosen buffer sizes. */
  15342. + if (l >= search_sz) continue;
  15343. + memcpy(search, p, l+1);
  15344. + }
  15345. +
  15346. + __fclose_ca(f);
  15347. +
  15348. +no_resolv_conf:
  15349. + if (!nns) {
  15350. + __lookup_ipliteral(conf->ns, "127.0.0.1", AF_UNSPEC);
  15351. + nns = 1;
  15352. + }
  15353. +
  15354. + conf->nns = nns;
  15355. +
  15356. + return 0;
  15357. +}
  15358. --- a/src/search/tsearch_avl.c
  15359. +++ b/src/search/tsearch_avl.c
  15360. @@ -77,38 +77,45 @@ static struct node *find(struct node *n,
  15361. return find(n->right, k, cmp);
  15362. }
  15363. -static struct node *insert(struct node **n, const void *k,
  15364. - int (*cmp)(const void *, const void *), int *new)
  15365. +static struct node *insert(struct node *n, const void *k,
  15366. + int (*cmp)(const void *, const void *), struct node **found)
  15367. {
  15368. - struct node *r = *n;
  15369. + struct node *r;
  15370. int c;
  15371. - if (!r) {
  15372. - *n = r = malloc(sizeof **n);
  15373. - if (r) {
  15374. - r->key = k;
  15375. - r->left = r->right = 0;
  15376. - r->height = 1;
  15377. + if (!n) {
  15378. + n = malloc(sizeof *n);
  15379. + if (n) {
  15380. + n->key = k;
  15381. + n->left = n->right = 0;
  15382. + n->height = 1;
  15383. }
  15384. - *new = 1;
  15385. - return r;
  15386. + *found = n;
  15387. + return n;
  15388. + }
  15389. + c = cmp(k, n->key);
  15390. + if (c == 0) {
  15391. + *found = n;
  15392. + return 0;
  15393. + }
  15394. + r = insert(c < 0 ? n->left : n->right, k, cmp, found);
  15395. + if (r) {
  15396. + if (c < 0)
  15397. + n->left = r;
  15398. + else
  15399. + n->right = r;
  15400. + r = balance(n);
  15401. }
  15402. - c = cmp(k, r->key);
  15403. - if (c == 0)
  15404. - return r;
  15405. - if (c < 0)
  15406. - r = insert(&r->left, k, cmp, new);
  15407. - else
  15408. - r = insert(&r->right, k, cmp, new);
  15409. - if (*new)
  15410. - *n = balance(*n);
  15411. return r;
  15412. }
  15413. -static struct node *movr(struct node *n, struct node *r) {
  15414. - if (!n)
  15415. - return r;
  15416. - n->right = movr(n->right, r);
  15417. +static struct node *remove_rightmost(struct node *n, struct node **rightmost)
  15418. +{
  15419. + if (!n->right) {
  15420. + *rightmost = n;
  15421. + return n->left;
  15422. + }
  15423. + n->right = remove_rightmost(n->right, rightmost);
  15424. return balance(n);
  15425. }
  15426. @@ -122,7 +129,13 @@ static struct node *remove(struct node *
  15427. c = cmp(k, (*n)->key);
  15428. if (c == 0) {
  15429. struct node *r = *n;
  15430. - *n = movr(r->left, r->right);
  15431. + if (r->left) {
  15432. + r->left = remove_rightmost(r->left, n);
  15433. + (*n)->left = r->left;
  15434. + (*n)->right = r->right;
  15435. + *n = balance(*n);
  15436. + } else
  15437. + *n = r->right;
  15438. free(r);
  15439. return parent;
  15440. }
  15441. @@ -138,6 +151,8 @@ static struct node *remove(struct node *
  15442. void *tdelete(const void *restrict key, void **restrict rootp,
  15443. int(*compar)(const void *, const void *))
  15444. {
  15445. + if (!rootp)
  15446. + return 0;
  15447. struct node *n = *rootp;
  15448. struct node *ret;
  15449. /* last argument is arbitrary non-null pointer
  15450. @@ -150,17 +165,21 @@ void *tdelete(const void *restrict key,
  15451. void *tfind(const void *key, void *const *rootp,
  15452. int(*compar)(const void *, const void *))
  15453. {
  15454. + if (!rootp)
  15455. + return 0;
  15456. return find(*rootp, key, compar);
  15457. }
  15458. void *tsearch(const void *key, void **rootp,
  15459. int (*compar)(const void *, const void *))
  15460. {
  15461. - int new = 0;
  15462. - struct node *n = *rootp;
  15463. + struct node *update;
  15464. struct node *ret;
  15465. - ret = insert(&n, key, compar, &new);
  15466. - *rootp = n;
  15467. + if (!rootp)
  15468. + return 0;
  15469. + update = insert(*rootp, key, compar, &ret);
  15470. + if (update)
  15471. + *rootp = update;
  15472. return ret;
  15473. }
  15474. --- a/src/setjmp/arm/longjmp.s
  15475. +++ b/src/setjmp/arm/longjmp.s
  15476. @@ -1,3 +1,4 @@
  15477. +.syntax unified
  15478. .global _longjmp
  15479. .global longjmp
  15480. .type _longjmp,%function
  15481. @@ -20,7 +21,11 @@ longjmp:
  15482. ldc p2, cr4, [ip], #48
  15483. 2: tst r1,#0x40
  15484. beq 2f
  15485. - .word 0xecbc8b10 /* vldmia ip!, {d8-d15} */
  15486. + .fpu vfp
  15487. + vldmia ip!, {d8-d15}
  15488. + .fpu softvfp
  15489. + .eabi_attribute 10, 0
  15490. + .eabi_attribute 27, 0
  15491. 2: tst r1,#0x200
  15492. beq 3f
  15493. ldcl p1, cr10, [ip], #8
  15494. @@ -29,9 +34,7 @@ longjmp:
  15495. ldcl p1, cr13, [ip], #8
  15496. ldcl p1, cr14, [ip], #8
  15497. ldcl p1, cr15, [ip], #8
  15498. -3: tst lr,#1
  15499. - moveq pc,lr
  15500. - bx lr
  15501. +3: bx lr
  15502. .hidden __hwcap
  15503. 1: .word __hwcap-1b
  15504. --- a/src/setjmp/arm/setjmp.s
  15505. +++ b/src/setjmp/arm/setjmp.s
  15506. @@ -1,3 +1,4 @@
  15507. +.syntax unified
  15508. .global __setjmp
  15509. .global _setjmp
  15510. .global setjmp
  15511. @@ -22,7 +23,11 @@ setjmp:
  15512. stc p2, cr4, [ip], #48
  15513. 2: tst r1,#0x40
  15514. beq 2f
  15515. - .word 0xecac8b10 /* vstmia ip!, {d8-d15} */
  15516. + .fpu vfp
  15517. + vstmia ip!, {d8-d15}
  15518. + .fpu softvfp
  15519. + .eabi_attribute 10, 0
  15520. + .eabi_attribute 27, 0
  15521. 2: tst r1,#0x200
  15522. beq 3f
  15523. stcl p1, cr10, [ip], #8
  15524. @@ -31,9 +36,7 @@ setjmp:
  15525. stcl p1, cr13, [ip], #8
  15526. stcl p1, cr14, [ip], #8
  15527. stcl p1, cr15, [ip], #8
  15528. -3: tst lr,#1
  15529. - moveq pc,lr
  15530. - bx lr
  15531. +3: bx lr
  15532. .hidden __hwcap
  15533. 1: .word __hwcap-1b
  15534. --- a/src/setjmp/mips-sf/longjmp.s
  15535. +++ /dev/null
  15536. @@ -1,25 +0,0 @@
  15537. -.set noreorder
  15538. -
  15539. -.global _longjmp
  15540. -.global longjmp
  15541. -.type _longjmp,@function
  15542. -.type longjmp,@function
  15543. -_longjmp:
  15544. -longjmp:
  15545. - move $2, $5
  15546. - bne $2, $0, 1f
  15547. - nop
  15548. - addu $2, $2, 1
  15549. -1: lw $ra, 0($4)
  15550. - lw $sp, 4($4)
  15551. - lw $16, 8($4)
  15552. - lw $17, 12($4)
  15553. - lw $18, 16($4)
  15554. - lw $19, 20($4)
  15555. - lw $20, 24($4)
  15556. - lw $21, 28($4)
  15557. - lw $22, 32($4)
  15558. - lw $23, 36($4)
  15559. - lw $30, 40($4)
  15560. - jr $ra
  15561. - lw $28, 44($4)
  15562. --- a/src/setjmp/mips-sf/longjmp.sub
  15563. +++ /dev/null
  15564. @@ -1 +0,0 @@
  15565. -longjmp.s
  15566. --- a/src/setjmp/mips-sf/setjmp.s
  15567. +++ /dev/null
  15568. @@ -1,25 +0,0 @@
  15569. -.set noreorder
  15570. -
  15571. -.global __setjmp
  15572. -.global _setjmp
  15573. -.global setjmp
  15574. -.type __setjmp,@function
  15575. -.type _setjmp,@function
  15576. -.type setjmp,@function
  15577. -__setjmp:
  15578. -_setjmp:
  15579. -setjmp:
  15580. - sw $ra, 0($4)
  15581. - sw $sp, 4($4)
  15582. - sw $16, 8($4)
  15583. - sw $17, 12($4)
  15584. - sw $18, 16($4)
  15585. - sw $19, 20($4)
  15586. - sw $20, 24($4)
  15587. - sw $21, 28($4)
  15588. - sw $22, 32($4)
  15589. - sw $23, 36($4)
  15590. - sw $30, 40($4)
  15591. - sw $28, 44($4)
  15592. - jr $ra
  15593. - li $2, 0
  15594. --- a/src/setjmp/mips-sf/setjmp.sub
  15595. +++ /dev/null
  15596. @@ -1 +0,0 @@
  15597. -setjmp.s
  15598. --- /dev/null
  15599. +++ b/src/setjmp/mips/longjmp.S
  15600. @@ -0,0 +1,40 @@
  15601. +.set noreorder
  15602. +
  15603. +.global _longjmp
  15604. +.global longjmp
  15605. +.type _longjmp,@function
  15606. +.type longjmp,@function
  15607. +_longjmp:
  15608. +longjmp:
  15609. + move $2, $5
  15610. + bne $2, $0, 1f
  15611. + nop
  15612. + addu $2, $2, 1
  15613. +1:
  15614. +#ifndef __mips_soft_float
  15615. + lwc1 $20, 56($4)
  15616. + lwc1 $21, 60($4)
  15617. + lwc1 $22, 64($4)
  15618. + lwc1 $23, 68($4)
  15619. + lwc1 $24, 72($4)
  15620. + lwc1 $25, 76($4)
  15621. + lwc1 $26, 80($4)
  15622. + lwc1 $27, 84($4)
  15623. + lwc1 $28, 88($4)
  15624. + lwc1 $29, 92($4)
  15625. + lwc1 $30, 96($4)
  15626. + lwc1 $31, 100($4)
  15627. +#endif
  15628. + lw $ra, 0($4)
  15629. + lw $sp, 4($4)
  15630. + lw $16, 8($4)
  15631. + lw $17, 12($4)
  15632. + lw $18, 16($4)
  15633. + lw $19, 20($4)
  15634. + lw $20, 24($4)
  15635. + lw $21, 28($4)
  15636. + lw $22, 32($4)
  15637. + lw $23, 36($4)
  15638. + lw $30, 40($4)
  15639. + jr $ra
  15640. + lw $28, 44($4)
  15641. --- a/src/setjmp/mips/longjmp.s
  15642. +++ /dev/null
  15643. @@ -1,37 +0,0 @@
  15644. -.set noreorder
  15645. -
  15646. -.global _longjmp
  15647. -.global longjmp
  15648. -.type _longjmp,@function
  15649. -.type longjmp,@function
  15650. -_longjmp:
  15651. -longjmp:
  15652. - move $2, $5
  15653. - bne $2, $0, 1f
  15654. - nop
  15655. - addu $2, $2, 1
  15656. -1: lwc1 $20, 56($4)
  15657. - lwc1 $21, 60($4)
  15658. - lwc1 $22, 64($4)
  15659. - lwc1 $23, 68($4)
  15660. - lwc1 $24, 72($4)
  15661. - lwc1 $25, 76($4)
  15662. - lwc1 $26, 80($4)
  15663. - lwc1 $27, 84($4)
  15664. - lwc1 $28, 88($4)
  15665. - lwc1 $29, 92($4)
  15666. - lwc1 $30, 96($4)
  15667. - lwc1 $31, 100($4)
  15668. - lw $ra, 0($4)
  15669. - lw $sp, 4($4)
  15670. - lw $16, 8($4)
  15671. - lw $17, 12($4)
  15672. - lw $18, 16($4)
  15673. - lw $19, 20($4)
  15674. - lw $20, 24($4)
  15675. - lw $21, 28($4)
  15676. - lw $22, 32($4)
  15677. - lw $23, 36($4)
  15678. - lw $30, 40($4)
  15679. - jr $ra
  15680. - lw $28, 44($4)
  15681. --- /dev/null
  15682. +++ b/src/setjmp/mips/setjmp.S
  15683. @@ -0,0 +1,39 @@
  15684. +.set noreorder
  15685. +
  15686. +.global __setjmp
  15687. +.global _setjmp
  15688. +.global setjmp
  15689. +.type __setjmp,@function
  15690. +.type _setjmp,@function
  15691. +.type setjmp,@function
  15692. +__setjmp:
  15693. +_setjmp:
  15694. +setjmp:
  15695. + sw $ra, 0($4)
  15696. + sw $sp, 4($4)
  15697. + sw $16, 8($4)
  15698. + sw $17, 12($4)
  15699. + sw $18, 16($4)
  15700. + sw $19, 20($4)
  15701. + sw $20, 24($4)
  15702. + sw $21, 28($4)
  15703. + sw $22, 32($4)
  15704. + sw $23, 36($4)
  15705. + sw $30, 40($4)
  15706. + sw $28, 44($4)
  15707. +#ifndef __mips_soft_float
  15708. + swc1 $20, 56($4)
  15709. + swc1 $21, 60($4)
  15710. + swc1 $22, 64($4)
  15711. + swc1 $23, 68($4)
  15712. + swc1 $24, 72($4)
  15713. + swc1 $25, 76($4)
  15714. + swc1 $26, 80($4)
  15715. + swc1 $27, 84($4)
  15716. + swc1 $28, 88($4)
  15717. + swc1 $29, 92($4)
  15718. + swc1 $30, 96($4)
  15719. + swc1 $31, 100($4)
  15720. +#endif
  15721. + jr $ra
  15722. + li $2, 0
  15723. --- a/src/setjmp/mips/setjmp.s
  15724. +++ /dev/null
  15725. @@ -1,37 +0,0 @@
  15726. -.set noreorder
  15727. -
  15728. -.global __setjmp
  15729. -.global _setjmp
  15730. -.global setjmp
  15731. -.type __setjmp,@function
  15732. -.type _setjmp,@function
  15733. -.type setjmp,@function
  15734. -__setjmp:
  15735. -_setjmp:
  15736. -setjmp:
  15737. - sw $ra, 0($4)
  15738. - sw $sp, 4($4)
  15739. - sw $16, 8($4)
  15740. - sw $17, 12($4)
  15741. - sw $18, 16($4)
  15742. - sw $19, 20($4)
  15743. - sw $20, 24($4)
  15744. - sw $21, 28($4)
  15745. - sw $22, 32($4)
  15746. - sw $23, 36($4)
  15747. - sw $30, 40($4)
  15748. - sw $28, 44($4)
  15749. - swc1 $20, 56($4)
  15750. - swc1 $21, 60($4)
  15751. - swc1 $22, 64($4)
  15752. - swc1 $23, 68($4)
  15753. - swc1 $24, 72($4)
  15754. - swc1 $25, 76($4)
  15755. - swc1 $26, 80($4)
  15756. - swc1 $27, 84($4)
  15757. - swc1 $28, 88($4)
  15758. - swc1 $29, 92($4)
  15759. - swc1 $30, 96($4)
  15760. - swc1 $31, 100($4)
  15761. - jr $ra
  15762. - li $2, 0
  15763. --- a/src/setjmp/mipsel-sf/longjmp.sub
  15764. +++ /dev/null
  15765. @@ -1 +0,0 @@
  15766. -../mips-sf/longjmp.s
  15767. --- a/src/setjmp/mipsel-sf/setjmp.sub
  15768. +++ /dev/null
  15769. @@ -1 +0,0 @@
  15770. -../mips-sf/setjmp.s
  15771. --- a/src/setjmp/sh-nofpu/longjmp.s
  15772. +++ /dev/null
  15773. @@ -1,22 +0,0 @@
  15774. -.global _longjmp
  15775. -.global longjmp
  15776. -.type _longjmp, @function
  15777. -.type longjmp, @function
  15778. -_longjmp:
  15779. -longjmp:
  15780. - mov.l @r4+, r8
  15781. - mov.l @r4+, r9
  15782. - mov.l @r4+, r10
  15783. - mov.l @r4+, r11
  15784. - mov.l @r4+, r12
  15785. - mov.l @r4+, r13
  15786. - mov.l @r4+, r14
  15787. - mov.l @r4+, r15
  15788. - lds.l @r4+, pr
  15789. -
  15790. - tst r5, r5
  15791. - movt r0
  15792. - add r5, r0
  15793. -
  15794. - rts
  15795. - nop
  15796. --- a/src/setjmp/sh-nofpu/longjmp.sub
  15797. +++ /dev/null
  15798. @@ -1 +0,0 @@
  15799. -longjmp.s
  15800. --- a/src/setjmp/sh-nofpu/setjmp.s
  15801. +++ /dev/null
  15802. @@ -1,24 +0,0 @@
  15803. -.global ___setjmp
  15804. -.hidden ___setjmp
  15805. -.global __setjmp
  15806. -.global _setjmp
  15807. -.global setjmp
  15808. -.type __setjmp, @function
  15809. -.type _setjmp, @function
  15810. -.type setjmp, @function
  15811. -___setjmp:
  15812. -__setjmp:
  15813. -_setjmp:
  15814. -setjmp:
  15815. - add #36, r4
  15816. - sts.l pr, @-r4
  15817. - mov.l r15 @-r4
  15818. - mov.l r14, @-r4
  15819. - mov.l r13, @-r4
  15820. - mov.l r12, @-r4
  15821. - mov.l r11, @-r4
  15822. - mov.l r10, @-r4
  15823. - mov.l r9, @-r4
  15824. - mov.l r8, @-r4
  15825. - rts
  15826. - mov #0, r0
  15827. --- a/src/setjmp/sh-nofpu/setjmp.sub
  15828. +++ /dev/null
  15829. @@ -1 +0,0 @@
  15830. -setjmp.s
  15831. --- /dev/null
  15832. +++ b/src/setjmp/sh/longjmp.S
  15833. @@ -0,0 +1,28 @@
  15834. +.global _longjmp
  15835. +.global longjmp
  15836. +.type _longjmp, @function
  15837. +.type longjmp, @function
  15838. +_longjmp:
  15839. +longjmp:
  15840. + mov.l @r4+, r8
  15841. + mov.l @r4+, r9
  15842. + mov.l @r4+, r10
  15843. + mov.l @r4+, r11
  15844. + mov.l @r4+, r12
  15845. + mov.l @r4+, r13
  15846. + mov.l @r4+, r14
  15847. + mov.l @r4+, r15
  15848. + lds.l @r4+, pr
  15849. +#if __SH_FPU_ANY__ || __SH4__
  15850. + fmov.s @r4+, fr12
  15851. + fmov.s @r4+, fr13
  15852. + fmov.s @r4+, fr14
  15853. + fmov.s @r4+, fr15
  15854. +#endif
  15855. +
  15856. + tst r5, r5
  15857. + movt r0
  15858. + add r5, r0
  15859. +
  15860. + rts
  15861. + nop
  15862. --- a/src/setjmp/sh/longjmp.s
  15863. +++ /dev/null
  15864. @@ -1,26 +0,0 @@
  15865. -.global _longjmp
  15866. -.global longjmp
  15867. -.type _longjmp, @function
  15868. -.type longjmp, @function
  15869. -_longjmp:
  15870. -longjmp:
  15871. - mov.l @r4+, r8
  15872. - mov.l @r4+, r9
  15873. - mov.l @r4+, r10
  15874. - mov.l @r4+, r11
  15875. - mov.l @r4+, r12
  15876. - mov.l @r4+, r13
  15877. - mov.l @r4+, r14
  15878. - mov.l @r4+, r15
  15879. - lds.l @r4+, pr
  15880. - fmov.s @r4+, fr12
  15881. - fmov.s @r4+, fr13
  15882. - fmov.s @r4+, fr14
  15883. - fmov.s @r4+, fr15
  15884. -
  15885. - tst r5, r5
  15886. - movt r0
  15887. - add r5, r0
  15888. -
  15889. - rts
  15890. - nop
  15891. --- /dev/null
  15892. +++ b/src/setjmp/sh/setjmp.S
  15893. @@ -0,0 +1,32 @@
  15894. +.global ___setjmp
  15895. +.hidden ___setjmp
  15896. +.global __setjmp
  15897. +.global _setjmp
  15898. +.global setjmp
  15899. +.type __setjmp, @function
  15900. +.type _setjmp, @function
  15901. +.type setjmp, @function
  15902. +___setjmp:
  15903. +__setjmp:
  15904. +_setjmp:
  15905. +setjmp:
  15906. +#if __SH_FPU_ANY__ || __SH4__
  15907. + add #52, r4
  15908. + fmov.s fr15, @-r4
  15909. + fmov.s fr14, @-r4
  15910. + fmov.s fr13, @-r4
  15911. + fmov.s fr12, @-r4
  15912. +#else
  15913. + add #36, r4
  15914. +#endif
  15915. + sts.l pr, @-r4
  15916. + mov.l r15, @-r4
  15917. + mov.l r14, @-r4
  15918. + mov.l r13, @-r4
  15919. + mov.l r12, @-r4
  15920. + mov.l r11, @-r4
  15921. + mov.l r10, @-r4
  15922. + mov.l r9, @-r4
  15923. + mov.l r8, @-r4
  15924. + rts
  15925. + mov #0, r0
  15926. --- a/src/setjmp/sh/setjmp.s
  15927. +++ /dev/null
  15928. @@ -1,28 +0,0 @@
  15929. -.global ___setjmp
  15930. -.hidden ___setjmp
  15931. -.global __setjmp
  15932. -.global _setjmp
  15933. -.global setjmp
  15934. -.type __setjmp, @function
  15935. -.type _setjmp, @function
  15936. -.type setjmp, @function
  15937. -___setjmp:
  15938. -__setjmp:
  15939. -_setjmp:
  15940. -setjmp:
  15941. - add #52, r4
  15942. - fmov.s fr15, @-r4
  15943. - fmov.s fr14, @-r4
  15944. - fmov.s fr13, @-r4
  15945. - fmov.s fr12, @-r4
  15946. - sts.l pr, @-r4
  15947. - mov.l r15, @-r4
  15948. - mov.l r14, @-r4
  15949. - mov.l r13, @-r4
  15950. - mov.l r12, @-r4
  15951. - mov.l r11, @-r4
  15952. - mov.l r10, @-r4
  15953. - mov.l r9, @-r4
  15954. - mov.l r8, @-r4
  15955. - rts
  15956. - mov #0, r0
  15957. --- a/src/setjmp/sheb-nofpu/longjmp.sub
  15958. +++ /dev/null
  15959. @@ -1 +0,0 @@
  15960. -../sh-nofpu/longjmp.s
  15961. --- a/src/setjmp/sheb-nofpu/setjmp.sub
  15962. +++ /dev/null
  15963. @@ -1 +0,0 @@
  15964. -../sh-nofpu/setjmp.s
  15965. --- a/src/signal/arm/restore.s
  15966. +++ b/src/signal/arm/restore.s
  15967. @@ -1,3 +1,5 @@
  15968. +.syntax unified
  15969. +
  15970. .global __restore
  15971. .type __restore,%function
  15972. __restore:
  15973. --- a/src/signal/arm/sigsetjmp.s
  15974. +++ b/src/signal/arm/sigsetjmp.s
  15975. @@ -1,3 +1,4 @@
  15976. +.syntax unified
  15977. .global sigsetjmp
  15978. .global __sigsetjmp
  15979. .type sigsetjmp,%function
  15980. --- a/src/signal/sigaction.c
  15981. +++ b/src/signal/sigaction.c
  15982. @@ -17,10 +17,6 @@ void __get_handler_set(sigset_t *set)
  15983. int __libc_sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old)
  15984. {
  15985. struct k_sigaction ksa, ksa_old;
  15986. - if (sig >= (unsigned)_NSIG) {
  15987. - errno = EINVAL;
  15988. - return -1;
  15989. - }
  15990. if (sa) {
  15991. if ((uintptr_t)sa->sa_handler > 1UL) {
  15992. a_or_l(handler_set+(sig-1)/(8*sizeof(long)),
  15993. @@ -57,7 +53,7 @@ int __libc_sigaction(int sig, const stru
  15994. int __sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old)
  15995. {
  15996. - if (sig-32U < 3) {
  15997. + if (sig-32U < 3 || sig-1U >= _NSIG-1) {
  15998. errno = EINVAL;
  15999. return -1;
  16000. }
  16001. --- a/src/signal/sigsetjmp_tail.c
  16002. +++ b/src/signal/sigsetjmp_tail.c
  16003. @@ -2,9 +2,7 @@
  16004. #include <signal.h>
  16005. #include "syscall.h"
  16006. -#ifdef SHARED
  16007. __attribute__((__visibility__("hidden")))
  16008. -#endif
  16009. int __sigsetjmp_tail(sigjmp_buf jb, int ret)
  16010. {
  16011. void *p = jb->__ss;
  16012. --- a/src/stdio/getdelim.c
  16013. +++ b/src/stdio/getdelim.c
  16014. @@ -27,17 +27,18 @@ ssize_t getdelim(char **restrict s, size
  16015. for (;;) {
  16016. z = memchr(f->rpos, delim, f->rend - f->rpos);
  16017. k = z ? z - f->rpos + 1 : f->rend - f->rpos;
  16018. - if (i+k >= *n) {
  16019. + if (i+k+1 >= *n) {
  16020. if (k >= SIZE_MAX/2-i) goto oom;
  16021. - *n = i+k+2;
  16022. - if (*n < SIZE_MAX/4) *n *= 2;
  16023. - tmp = realloc(*s, *n);
  16024. + size_t m = i+k+2;
  16025. + if (!z && m < SIZE_MAX/4) m += m/2;
  16026. + tmp = realloc(*s, m);
  16027. if (!tmp) {
  16028. - *n = i+k+2;
  16029. - tmp = realloc(*s, *n);
  16030. + m = i+k+2;
  16031. + tmp = realloc(*s, m);
  16032. if (!tmp) goto oom;
  16033. }
  16034. *s = tmp;
  16035. + *n = m;
  16036. }
  16037. memcpy(*s+i, f->rpos, k);
  16038. f->rpos += k;
  16039. --- /dev/null
  16040. +++ b/src/string/arm/__aeabi_memclr.c
  16041. @@ -0,0 +1,9 @@
  16042. +#include <string.h>
  16043. +#include "libc.h"
  16044. +
  16045. +void __aeabi_memclr(void *dest, size_t n)
  16046. +{
  16047. + memset(dest, 0, n);
  16048. +}
  16049. +weak_alias(__aeabi_memclr, __aeabi_memclr4);
  16050. +weak_alias(__aeabi_memclr, __aeabi_memclr8);
  16051. --- /dev/null
  16052. +++ b/src/string/arm/__aeabi_memcpy.c
  16053. @@ -0,0 +1,9 @@
  16054. +#include <string.h>
  16055. +#include "libc.h"
  16056. +
  16057. +void __aeabi_memcpy(void *restrict dest, const void *restrict src, size_t n)
  16058. +{
  16059. + memcpy(dest, src, n);
  16060. +}
  16061. +weak_alias(__aeabi_memcpy, __aeabi_memcpy4);
  16062. +weak_alias(__aeabi_memcpy, __aeabi_memcpy8);
  16063. --- /dev/null
  16064. +++ b/src/string/arm/__aeabi_memmove.c
  16065. @@ -0,0 +1,9 @@
  16066. +#include <string.h>
  16067. +#include "libc.h"
  16068. +
  16069. +void __aeabi_memmove(void *dest, const void *src, size_t n)
  16070. +{
  16071. + memmove(dest, src, n);
  16072. +}
  16073. +weak_alias(__aeabi_memmove, __aeabi_memmove4);
  16074. +weak_alias(__aeabi_memmove, __aeabi_memmove8);
  16075. --- /dev/null
  16076. +++ b/src/string/arm/__aeabi_memset.c
  16077. @@ -0,0 +1,9 @@
  16078. +#include <string.h>
  16079. +#include "libc.h"
  16080. +
  16081. +void __aeabi_memset(void *dest, size_t n, int c)
  16082. +{
  16083. + memset(dest, c, n);
  16084. +}
  16085. +weak_alias(__aeabi_memset, __aeabi_memset4);
  16086. +weak_alias(__aeabi_memset, __aeabi_memset8);
  16087. --- /dev/null
  16088. +++ b/src/string/arm/memcpy.c
  16089. @@ -0,0 +1,3 @@
  16090. +#if __ARMEB__
  16091. +#include "../memcpy.c"
  16092. +#endif
  16093. --- /dev/null
  16094. +++ b/src/string/arm/memcpy_le.S
  16095. @@ -0,0 +1,383 @@
  16096. +#ifndef __ARMEB__
  16097. +
  16098. +/*
  16099. + * Copyright (C) 2008 The Android Open Source Project
  16100. + * All rights reserved.
  16101. + *
  16102. + * Redistribution and use in source and binary forms, with or without
  16103. + * modification, are permitted provided that the following conditions
  16104. + * are met:
  16105. + * * Redistributions of source code must retain the above copyright
  16106. + * notice, this list of conditions and the following disclaimer.
  16107. + * * Redistributions in binary form must reproduce the above copyright
  16108. + * notice, this list of conditions and the following disclaimer in
  16109. + * the documentation and/or other materials provided with the
  16110. + * distribution.
  16111. + *
  16112. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  16113. + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  16114. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  16115. + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  16116. + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  16117. + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  16118. + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  16119. + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  16120. + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  16121. + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  16122. + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  16123. + * SUCH DAMAGE.
  16124. + */
  16125. +
  16126. +
  16127. +/*
  16128. + * Optimized memcpy() for ARM.
  16129. + *
  16130. + * note that memcpy() always returns the destination pointer,
  16131. + * so we have to preserve R0.
  16132. + */
  16133. +
  16134. +/*
  16135. + * This file has been modified from the original for use in musl libc.
  16136. + * The main changes are: addition of .type memcpy,%function to make the
  16137. + * code safely callable from thumb mode, adjusting the return
  16138. + * instructions to be compatible with pre-thumb ARM cpus, and removal
  16139. + * of prefetch code that is not compatible with older cpus.
  16140. + */
  16141. +
  16142. +.syntax unified
  16143. +
  16144. +.global memcpy
  16145. +.type memcpy,%function
  16146. +memcpy:
  16147. + /* The stack must always be 64-bits aligned to be compliant with the
  16148. + * ARM ABI. Since we have to save R0, we might as well save R4
  16149. + * which we can use for better pipelining of the reads below
  16150. + */
  16151. + .fnstart
  16152. + .save {r0, r4, lr}
  16153. + stmfd sp!, {r0, r4, lr}
  16154. + /* Making room for r5-r11 which will be spilled later */
  16155. + .pad #28
  16156. + sub sp, sp, #28
  16157. +
  16158. + /* it simplifies things to take care of len<4 early */
  16159. + cmp r2, #4
  16160. + blo copy_last_3_and_return
  16161. +
  16162. + /* compute the offset to align the source
  16163. + * offset = (4-(src&3))&3 = -src & 3
  16164. + */
  16165. + rsb r3, r1, #0
  16166. + ands r3, r3, #3
  16167. + beq src_aligned
  16168. +
  16169. + /* align source to 32 bits. We need to insert 2 instructions between
  16170. + * a ldr[b|h] and str[b|h] because byte and half-word instructions
  16171. + * stall 2 cycles.
  16172. + */
  16173. + movs r12, r3, lsl #31
  16174. + sub r2, r2, r3 /* we know that r3 <= r2 because r2 >= 4 */
  16175. + ldrbmi r3, [r1], #1
  16176. + ldrbcs r4, [r1], #1
  16177. + ldrbcs r12,[r1], #1
  16178. + strbmi r3, [r0], #1
  16179. + strbcs r4, [r0], #1
  16180. + strbcs r12,[r0], #1
  16181. +
  16182. +src_aligned:
  16183. +
  16184. + /* see if src and dst are aligned together (congruent) */
  16185. + eor r12, r0, r1
  16186. + tst r12, #3
  16187. + bne non_congruent
  16188. +
  16189. + /* Use post-incriment mode for stm to spill r5-r11 to reserved stack
  16190. + * frame. Don't update sp.
  16191. + */
  16192. + stmea sp, {r5-r11}
  16193. +
  16194. + /* align the destination to a cache-line */
  16195. + rsb r3, r0, #0
  16196. + ands r3, r3, #0x1C
  16197. + beq congruent_aligned32
  16198. + cmp r3, r2
  16199. + andhi r3, r2, #0x1C
  16200. +
  16201. + /* conditionnaly copies 0 to 7 words (length in r3) */
  16202. + movs r12, r3, lsl #28
  16203. + ldmcs r1!, {r4, r5, r6, r7} /* 16 bytes */
  16204. + ldmmi r1!, {r8, r9} /* 8 bytes */
  16205. + stmcs r0!, {r4, r5, r6, r7}
  16206. + stmmi r0!, {r8, r9}
  16207. + tst r3, #0x4
  16208. + ldrne r10,[r1], #4 /* 4 bytes */
  16209. + strne r10,[r0], #4
  16210. + sub r2, r2, r3
  16211. +
  16212. +congruent_aligned32:
  16213. + /*
  16214. + * here source is aligned to 32 bytes.
  16215. + */
  16216. +
  16217. +cached_aligned32:
  16218. + subs r2, r2, #32
  16219. + blo less_than_32_left
  16220. +
  16221. + /*
  16222. + * We preload a cache-line up to 64 bytes ahead. On the 926, this will
  16223. + * stall only until the requested world is fetched, but the linefill
  16224. + * continues in the the background.
  16225. + * While the linefill is going, we write our previous cache-line
  16226. + * into the write-buffer (which should have some free space).
  16227. + * When the linefill is done, the writebuffer will
  16228. + * start dumping its content into memory
  16229. + *
  16230. + * While all this is going, we then load a full cache line into
  16231. + * 8 registers, this cache line should be in the cache by now
  16232. + * (or partly in the cache).
  16233. + *
  16234. + * This code should work well regardless of the source/dest alignment.
  16235. + *
  16236. + */
  16237. +
  16238. + /* Align the preload register to a cache-line because the cpu does
  16239. + * "critical word first" (the first word requested is loaded first).
  16240. + */
  16241. + @ bic r12, r1, #0x1F
  16242. + @ add r12, r12, #64
  16243. +
  16244. +1: ldmia r1!, { r4-r11 }
  16245. + subs r2, r2, #32
  16246. +
  16247. + /*
  16248. + * NOTE: if r12 is more than 64 ahead of r1, the following ldrhi
  16249. + * for ARM9 preload will not be safely guarded by the preceding subs.
  16250. + * When it is safely guarded the only possibility to have SIGSEGV here
  16251. + * is because the caller overstates the length.
  16252. + */
  16253. + @ ldrhi r3, [r12], #32 /* cheap ARM9 preload */
  16254. + stmia r0!, { r4-r11 }
  16255. + bhs 1b
  16256. +
  16257. + add r2, r2, #32
  16258. +
  16259. +less_than_32_left:
  16260. + /*
  16261. + * less than 32 bytes left at this point (length in r2)
  16262. + */
  16263. +
  16264. + /* skip all this if there is nothing to do, which should
  16265. + * be a common case (if not executed the code below takes
  16266. + * about 16 cycles)
  16267. + */
  16268. + tst r2, #0x1F
  16269. + beq 1f
  16270. +
  16271. + /* conditionnaly copies 0 to 31 bytes */
  16272. + movs r12, r2, lsl #28
  16273. + ldmcs r1!, {r4, r5, r6, r7} /* 16 bytes */
  16274. + ldmmi r1!, {r8, r9} /* 8 bytes */
  16275. + stmcs r0!, {r4, r5, r6, r7}
  16276. + stmmi r0!, {r8, r9}
  16277. + movs r12, r2, lsl #30
  16278. + ldrcs r3, [r1], #4 /* 4 bytes */
  16279. + ldrhmi r4, [r1], #2 /* 2 bytes */
  16280. + strcs r3, [r0], #4
  16281. + strhmi r4, [r0], #2
  16282. + tst r2, #0x1
  16283. + ldrbne r3, [r1] /* last byte */
  16284. + strbne r3, [r0]
  16285. +
  16286. + /* we're done! restore everything and return */
  16287. +1: ldmfd sp!, {r5-r11}
  16288. + ldmfd sp!, {r0, r4, lr}
  16289. + bx lr
  16290. +
  16291. + /********************************************************************/
  16292. +
  16293. +non_congruent:
  16294. + /*
  16295. + * here source is aligned to 4 bytes
  16296. + * but destination is not.
  16297. + *
  16298. + * in the code below r2 is the number of bytes read
  16299. + * (the number of bytes written is always smaller, because we have
  16300. + * partial words in the shift queue)
  16301. + */
  16302. + cmp r2, #4
  16303. + blo copy_last_3_and_return
  16304. +
  16305. + /* Use post-incriment mode for stm to spill r5-r11 to reserved stack
  16306. + * frame. Don't update sp.
  16307. + */
  16308. + stmea sp, {r5-r11}
  16309. +
  16310. + /* compute shifts needed to align src to dest */
  16311. + rsb r5, r0, #0
  16312. + and r5, r5, #3 /* r5 = # bytes in partial words */
  16313. + mov r12, r5, lsl #3 /* r12 = right */
  16314. + rsb lr, r12, #32 /* lr = left */
  16315. +
  16316. + /* read the first word */
  16317. + ldr r3, [r1], #4
  16318. + sub r2, r2, #4
  16319. +
  16320. + /* write a partial word (0 to 3 bytes), such that destination
  16321. + * becomes aligned to 32 bits (r5 = nb of words to copy for alignment)
  16322. + */
  16323. + movs r5, r5, lsl #31
  16324. + strbmi r3, [r0], #1
  16325. + movmi r3, r3, lsr #8
  16326. + strbcs r3, [r0], #1
  16327. + movcs r3, r3, lsr #8
  16328. + strbcs r3, [r0], #1
  16329. + movcs r3, r3, lsr #8
  16330. +
  16331. + cmp r2, #4
  16332. + blo partial_word_tail
  16333. +
  16334. + /* Align destination to 32 bytes (cache line boundary) */
  16335. +1: tst r0, #0x1c
  16336. + beq 2f
  16337. + ldr r5, [r1], #4
  16338. + sub r2, r2, #4
  16339. + orr r4, r3, r5, lsl lr
  16340. + mov r3, r5, lsr r12
  16341. + str r4, [r0], #4
  16342. + cmp r2, #4
  16343. + bhs 1b
  16344. + blo partial_word_tail
  16345. +
  16346. + /* copy 32 bytes at a time */
  16347. +2: subs r2, r2, #32
  16348. + blo less_than_thirtytwo
  16349. +
  16350. + /* Use immediate mode for the shifts, because there is an extra cycle
  16351. + * for register shifts, which could account for up to 50% of
  16352. + * performance hit.
  16353. + */
  16354. +
  16355. + cmp r12, #24
  16356. + beq loop24
  16357. + cmp r12, #8
  16358. + beq loop8
  16359. +
  16360. +loop16:
  16361. + ldr r12, [r1], #4
  16362. +1: mov r4, r12
  16363. + ldmia r1!, { r5,r6,r7, r8,r9,r10,r11}
  16364. + subs r2, r2, #32
  16365. + ldrhs r12, [r1], #4
  16366. + orr r3, r3, r4, lsl #16
  16367. + mov r4, r4, lsr #16
  16368. + orr r4, r4, r5, lsl #16
  16369. + mov r5, r5, lsr #16
  16370. + orr r5, r5, r6, lsl #16
  16371. + mov r6, r6, lsr #16
  16372. + orr r6, r6, r7, lsl #16
  16373. + mov r7, r7, lsr #16
  16374. + orr r7, r7, r8, lsl #16
  16375. + mov r8, r8, lsr #16
  16376. + orr r8, r8, r9, lsl #16
  16377. + mov r9, r9, lsr #16
  16378. + orr r9, r9, r10, lsl #16
  16379. + mov r10, r10, lsr #16
  16380. + orr r10, r10, r11, lsl #16
  16381. + stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10}
  16382. + mov r3, r11, lsr #16
  16383. + bhs 1b
  16384. + b less_than_thirtytwo
  16385. +
  16386. +loop8:
  16387. + ldr r12, [r1], #4
  16388. +1: mov r4, r12
  16389. + ldmia r1!, { r5,r6,r7, r8,r9,r10,r11}
  16390. + subs r2, r2, #32
  16391. + ldrhs r12, [r1], #4
  16392. + orr r3, r3, r4, lsl #24
  16393. + mov r4, r4, lsr #8
  16394. + orr r4, r4, r5, lsl #24
  16395. + mov r5, r5, lsr #8
  16396. + orr r5, r5, r6, lsl #24
  16397. + mov r6, r6, lsr #8
  16398. + orr r6, r6, r7, lsl #24
  16399. + mov r7, r7, lsr #8
  16400. + orr r7, r7, r8, lsl #24
  16401. + mov r8, r8, lsr #8
  16402. + orr r8, r8, r9, lsl #24
  16403. + mov r9, r9, lsr #8
  16404. + orr r9, r9, r10, lsl #24
  16405. + mov r10, r10, lsr #8
  16406. + orr r10, r10, r11, lsl #24
  16407. + stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10}
  16408. + mov r3, r11, lsr #8
  16409. + bhs 1b
  16410. + b less_than_thirtytwo
  16411. +
  16412. +loop24:
  16413. + ldr r12, [r1], #4
  16414. +1: mov r4, r12
  16415. + ldmia r1!, { r5,r6,r7, r8,r9,r10,r11}
  16416. + subs r2, r2, #32
  16417. + ldrhs r12, [r1], #4
  16418. + orr r3, r3, r4, lsl #8
  16419. + mov r4, r4, lsr #24
  16420. + orr r4, r4, r5, lsl #8
  16421. + mov r5, r5, lsr #24
  16422. + orr r5, r5, r6, lsl #8
  16423. + mov r6, r6, lsr #24
  16424. + orr r6, r6, r7, lsl #8
  16425. + mov r7, r7, lsr #24
  16426. + orr r7, r7, r8, lsl #8
  16427. + mov r8, r8, lsr #24
  16428. + orr r8, r8, r9, lsl #8
  16429. + mov r9, r9, lsr #24
  16430. + orr r9, r9, r10, lsl #8
  16431. + mov r10, r10, lsr #24
  16432. + orr r10, r10, r11, lsl #8
  16433. + stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10}
  16434. + mov r3, r11, lsr #24
  16435. + bhs 1b
  16436. +
  16437. +less_than_thirtytwo:
  16438. + /* copy the last 0 to 31 bytes of the source */
  16439. + rsb r12, lr, #32 /* we corrupted r12, recompute it */
  16440. + add r2, r2, #32
  16441. + cmp r2, #4
  16442. + blo partial_word_tail
  16443. +
  16444. +1: ldr r5, [r1], #4
  16445. + sub r2, r2, #4
  16446. + orr r4, r3, r5, lsl lr
  16447. + mov r3, r5, lsr r12
  16448. + str r4, [r0], #4
  16449. + cmp r2, #4
  16450. + bhs 1b
  16451. +
  16452. +partial_word_tail:
  16453. + /* we have a partial word in the input buffer */
  16454. + movs r5, lr, lsl #(31-3)
  16455. + strbmi r3, [r0], #1
  16456. + movmi r3, r3, lsr #8
  16457. + strbcs r3, [r0], #1
  16458. + movcs r3, r3, lsr #8
  16459. + strbcs r3, [r0], #1
  16460. +
  16461. + /* Refill spilled registers from the stack. Don't update sp. */
  16462. + ldmfd sp, {r5-r11}
  16463. +
  16464. +copy_last_3_and_return:
  16465. + movs r2, r2, lsl #31 /* copy remaining 0, 1, 2 or 3 bytes */
  16466. + ldrbmi r2, [r1], #1
  16467. + ldrbcs r3, [r1], #1
  16468. + ldrbcs r12,[r1]
  16469. + strbmi r2, [r0], #1
  16470. + strbcs r3, [r0], #1
  16471. + strbcs r12,[r0]
  16472. +
  16473. + /* we're done! restore sp and spilled registers and return */
  16474. + add sp, sp, #28
  16475. + ldmfd sp!, {r0, r4, lr}
  16476. + bx lr
  16477. +
  16478. +#endif
  16479. --- a/src/string/armel/memcpy.s
  16480. +++ /dev/null
  16481. @@ -1,381 +0,0 @@
  16482. -/*
  16483. - * Copyright (C) 2008 The Android Open Source Project
  16484. - * All rights reserved.
  16485. - *
  16486. - * Redistribution and use in source and binary forms, with or without
  16487. - * modification, are permitted provided that the following conditions
  16488. - * are met:
  16489. - * * Redistributions of source code must retain the above copyright
  16490. - * notice, this list of conditions and the following disclaimer.
  16491. - * * Redistributions in binary form must reproduce the above copyright
  16492. - * notice, this list of conditions and the following disclaimer in
  16493. - * the documentation and/or other materials provided with the
  16494. - * distribution.
  16495. - *
  16496. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  16497. - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  16498. - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  16499. - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  16500. - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  16501. - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  16502. - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  16503. - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  16504. - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  16505. - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  16506. - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  16507. - * SUCH DAMAGE.
  16508. - */
  16509. -
  16510. -
  16511. -/*
  16512. - * Optimized memcpy() for ARM.
  16513. - *
  16514. - * note that memcpy() always returns the destination pointer,
  16515. - * so we have to preserve R0.
  16516. - */
  16517. -
  16518. -/*
  16519. - * This file has been modified from the original for use in musl libc.
  16520. - * The main changes are: addition of .type memcpy,%function to make the
  16521. - * code safely callable from thumb mode, adjusting the return
  16522. - * instructions to be compatible with pre-thumb ARM cpus, and removal
  16523. - * of prefetch code that is not compatible with older cpus.
  16524. - */
  16525. -
  16526. -.global memcpy
  16527. -.type memcpy,%function
  16528. -memcpy:
  16529. - /* The stack must always be 64-bits aligned to be compliant with the
  16530. - * ARM ABI. Since we have to save R0, we might as well save R4
  16531. - * which we can use for better pipelining of the reads below
  16532. - */
  16533. - .fnstart
  16534. - .save {r0, r4, lr}
  16535. - stmfd sp!, {r0, r4, lr}
  16536. - /* Making room for r5-r11 which will be spilled later */
  16537. - .pad #28
  16538. - sub sp, sp, #28
  16539. -
  16540. - /* it simplifies things to take care of len<4 early */
  16541. - cmp r2, #4
  16542. - blo copy_last_3_and_return
  16543. -
  16544. - /* compute the offset to align the source
  16545. - * offset = (4-(src&3))&3 = -src & 3
  16546. - */
  16547. - rsb r3, r1, #0
  16548. - ands r3, r3, #3
  16549. - beq src_aligned
  16550. -
  16551. - /* align source to 32 bits. We need to insert 2 instructions between
  16552. - * a ldr[b|h] and str[b|h] because byte and half-word instructions
  16553. - * stall 2 cycles.
  16554. - */
  16555. - movs r12, r3, lsl #31
  16556. - sub r2, r2, r3 /* we know that r3 <= r2 because r2 >= 4 */
  16557. - .word 0x44d13001 /* ldrbmi r3, [r1], #1 */
  16558. - .word 0x24d14001 /* ldrbcs r4, [r1], #1 */
  16559. - .word 0x24d1c001 /* ldrbcs r12,[r1], #1 */
  16560. - .word 0x44c03001 /* strbmi r3, [r0], #1 */
  16561. - .word 0x24c04001 /* strbcs r4, [r0], #1 */
  16562. - .word 0x24c0c001 /* strbcs r12,[r0], #1 */
  16563. -
  16564. -src_aligned:
  16565. -
  16566. - /* see if src and dst are aligned together (congruent) */
  16567. - eor r12, r0, r1
  16568. - tst r12, #3
  16569. - bne non_congruent
  16570. -
  16571. - /* Use post-incriment mode for stm to spill r5-r11 to reserved stack
  16572. - * frame. Don't update sp.
  16573. - */
  16574. - stmea sp, {r5-r11}
  16575. -
  16576. - /* align the destination to a cache-line */
  16577. - rsb r3, r0, #0
  16578. - ands r3, r3, #0x1C
  16579. - beq congruent_aligned32
  16580. - cmp r3, r2
  16581. - andhi r3, r2, #0x1C
  16582. -
  16583. - /* conditionnaly copies 0 to 7 words (length in r3) */
  16584. - movs r12, r3, lsl #28
  16585. - ldmcs r1!, {r4, r5, r6, r7} /* 16 bytes */
  16586. - ldmmi r1!, {r8, r9} /* 8 bytes */
  16587. - stmcs r0!, {r4, r5, r6, r7}
  16588. - stmmi r0!, {r8, r9}
  16589. - tst r3, #0x4
  16590. - ldrne r10,[r1], #4 /* 4 bytes */
  16591. - strne r10,[r0], #4
  16592. - sub r2, r2, r3
  16593. -
  16594. -congruent_aligned32:
  16595. - /*
  16596. - * here source is aligned to 32 bytes.
  16597. - */
  16598. -
  16599. -cached_aligned32:
  16600. - subs r2, r2, #32
  16601. - blo less_than_32_left
  16602. -
  16603. - /*
  16604. - * We preload a cache-line up to 64 bytes ahead. On the 926, this will
  16605. - * stall only until the requested world is fetched, but the linefill
  16606. - * continues in the the background.
  16607. - * While the linefill is going, we write our previous cache-line
  16608. - * into the write-buffer (which should have some free space).
  16609. - * When the linefill is done, the writebuffer will
  16610. - * start dumping its content into memory
  16611. - *
  16612. - * While all this is going, we then load a full cache line into
  16613. - * 8 registers, this cache line should be in the cache by now
  16614. - * (or partly in the cache).
  16615. - *
  16616. - * This code should work well regardless of the source/dest alignment.
  16617. - *
  16618. - */
  16619. -
  16620. - /* Align the preload register to a cache-line because the cpu does
  16621. - * "critical word first" (the first word requested is loaded first).
  16622. - */
  16623. - @ bic r12, r1, #0x1F
  16624. - @ add r12, r12, #64
  16625. -
  16626. -1: ldmia r1!, { r4-r11 }
  16627. - subs r2, r2, #32
  16628. -
  16629. - /*
  16630. - * NOTE: if r12 is more than 64 ahead of r1, the following ldrhi
  16631. - * for ARM9 preload will not be safely guarded by the preceding subs.
  16632. - * When it is safely guarded the only possibility to have SIGSEGV here
  16633. - * is because the caller overstates the length.
  16634. - */
  16635. - @ ldrhi r3, [r12], #32 /* cheap ARM9 preload */
  16636. - stmia r0!, { r4-r11 }
  16637. - bhs 1b
  16638. -
  16639. - add r2, r2, #32
  16640. -
  16641. -less_than_32_left:
  16642. - /*
  16643. - * less than 32 bytes left at this point (length in r2)
  16644. - */
  16645. -
  16646. - /* skip all this if there is nothing to do, which should
  16647. - * be a common case (if not executed the code below takes
  16648. - * about 16 cycles)
  16649. - */
  16650. - tst r2, #0x1F
  16651. - beq 1f
  16652. -
  16653. - /* conditionnaly copies 0 to 31 bytes */
  16654. - movs r12, r2, lsl #28
  16655. - ldmcs r1!, {r4, r5, r6, r7} /* 16 bytes */
  16656. - ldmmi r1!, {r8, r9} /* 8 bytes */
  16657. - stmcs r0!, {r4, r5, r6, r7}
  16658. - stmmi r0!, {r8, r9}
  16659. - movs r12, r2, lsl #30
  16660. - ldrcs r3, [r1], #4 /* 4 bytes */
  16661. - .word 0x40d140b2 /* ldrhmi r4, [r1], #2 */ /* 2 bytes */
  16662. - strcs r3, [r0], #4
  16663. - .word 0x40c040b2 /* strhmi r4, [r0], #2 */
  16664. - tst r2, #0x1
  16665. - .word 0x15d13000 /* ldrbne r3, [r1] */ /* last byte */
  16666. - .word 0x15c03000 /* strbne r3, [r0] */
  16667. -
  16668. - /* we're done! restore everything and return */
  16669. -1: ldmfd sp!, {r5-r11}
  16670. - ldmfd sp!, {r0, r4, lr}
  16671. - tst lr, #1
  16672. - moveq pc, lr
  16673. - bx lr
  16674. -
  16675. - /********************************************************************/
  16676. -
  16677. -non_congruent:
  16678. - /*
  16679. - * here source is aligned to 4 bytes
  16680. - * but destination is not.
  16681. - *
  16682. - * in the code below r2 is the number of bytes read
  16683. - * (the number of bytes written is always smaller, because we have
  16684. - * partial words in the shift queue)
  16685. - */
  16686. - cmp r2, #4
  16687. - blo copy_last_3_and_return
  16688. -
  16689. - /* Use post-incriment mode for stm to spill r5-r11 to reserved stack
  16690. - * frame. Don't update sp.
  16691. - */
  16692. - stmea sp, {r5-r11}
  16693. -
  16694. - /* compute shifts needed to align src to dest */
  16695. - rsb r5, r0, #0
  16696. - and r5, r5, #3 /* r5 = # bytes in partial words */
  16697. - mov r12, r5, lsl #3 /* r12 = right */
  16698. - rsb lr, r12, #32 /* lr = left */
  16699. -
  16700. - /* read the first word */
  16701. - ldr r3, [r1], #4
  16702. - sub r2, r2, #4
  16703. -
  16704. - /* write a partial word (0 to 3 bytes), such that destination
  16705. - * becomes aligned to 32 bits (r5 = nb of words to copy for alignment)
  16706. - */
  16707. - movs r5, r5, lsl #31
  16708. - .word 0x44c03001 /* strbmi r3, [r0], #1 */
  16709. - movmi r3, r3, lsr #8
  16710. - .word 0x24c03001 /* strbcs r3, [r0], #1 */
  16711. - movcs r3, r3, lsr #8
  16712. - .word 0x24c03001 /* strbcs r3, [r0], #1 */
  16713. - movcs r3, r3, lsr #8
  16714. -
  16715. - cmp r2, #4
  16716. - blo partial_word_tail
  16717. -
  16718. - /* Align destination to 32 bytes (cache line boundary) */
  16719. -1: tst r0, #0x1c
  16720. - beq 2f
  16721. - ldr r5, [r1], #4
  16722. - sub r2, r2, #4
  16723. - orr r4, r3, r5, lsl lr
  16724. - mov r3, r5, lsr r12
  16725. - str r4, [r0], #4
  16726. - cmp r2, #4
  16727. - bhs 1b
  16728. - blo partial_word_tail
  16729. -
  16730. - /* copy 32 bytes at a time */
  16731. -2: subs r2, r2, #32
  16732. - blo less_than_thirtytwo
  16733. -
  16734. - /* Use immediate mode for the shifts, because there is an extra cycle
  16735. - * for register shifts, which could account for up to 50% of
  16736. - * performance hit.
  16737. - */
  16738. -
  16739. - cmp r12, #24
  16740. - beq loop24
  16741. - cmp r12, #8
  16742. - beq loop8
  16743. -
  16744. -loop16:
  16745. - ldr r12, [r1], #4
  16746. -1: mov r4, r12
  16747. - ldmia r1!, { r5,r6,r7, r8,r9,r10,r11}
  16748. - subs r2, r2, #32
  16749. - ldrhs r12, [r1], #4
  16750. - orr r3, r3, r4, lsl #16
  16751. - mov r4, r4, lsr #16
  16752. - orr r4, r4, r5, lsl #16
  16753. - mov r5, r5, lsr #16
  16754. - orr r5, r5, r6, lsl #16
  16755. - mov r6, r6, lsr #16
  16756. - orr r6, r6, r7, lsl #16
  16757. - mov r7, r7, lsr #16
  16758. - orr r7, r7, r8, lsl #16
  16759. - mov r8, r8, lsr #16
  16760. - orr r8, r8, r9, lsl #16
  16761. - mov r9, r9, lsr #16
  16762. - orr r9, r9, r10, lsl #16
  16763. - mov r10, r10, lsr #16
  16764. - orr r10, r10, r11, lsl #16
  16765. - stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10}
  16766. - mov r3, r11, lsr #16
  16767. - bhs 1b
  16768. - b less_than_thirtytwo
  16769. -
  16770. -loop8:
  16771. - ldr r12, [r1], #4
  16772. -1: mov r4, r12
  16773. - ldmia r1!, { r5,r6,r7, r8,r9,r10,r11}
  16774. - subs r2, r2, #32
  16775. - ldrhs r12, [r1], #4
  16776. - orr r3, r3, r4, lsl #24
  16777. - mov r4, r4, lsr #8
  16778. - orr r4, r4, r5, lsl #24
  16779. - mov r5, r5, lsr #8
  16780. - orr r5, r5, r6, lsl #24
  16781. - mov r6, r6, lsr #8
  16782. - orr r6, r6, r7, lsl #24
  16783. - mov r7, r7, lsr #8
  16784. - orr r7, r7, r8, lsl #24
  16785. - mov r8, r8, lsr #8
  16786. - orr r8, r8, r9, lsl #24
  16787. - mov r9, r9, lsr #8
  16788. - orr r9, r9, r10, lsl #24
  16789. - mov r10, r10, lsr #8
  16790. - orr r10, r10, r11, lsl #24
  16791. - stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10}
  16792. - mov r3, r11, lsr #8
  16793. - bhs 1b
  16794. - b less_than_thirtytwo
  16795. -
  16796. -loop24:
  16797. - ldr r12, [r1], #4
  16798. -1: mov r4, r12
  16799. - ldmia r1!, { r5,r6,r7, r8,r9,r10,r11}
  16800. - subs r2, r2, #32
  16801. - ldrhs r12, [r1], #4
  16802. - orr r3, r3, r4, lsl #8
  16803. - mov r4, r4, lsr #24
  16804. - orr r4, r4, r5, lsl #8
  16805. - mov r5, r5, lsr #24
  16806. - orr r5, r5, r6, lsl #8
  16807. - mov r6, r6, lsr #24
  16808. - orr r6, r6, r7, lsl #8
  16809. - mov r7, r7, lsr #24
  16810. - orr r7, r7, r8, lsl #8
  16811. - mov r8, r8, lsr #24
  16812. - orr r8, r8, r9, lsl #8
  16813. - mov r9, r9, lsr #24
  16814. - orr r9, r9, r10, lsl #8
  16815. - mov r10, r10, lsr #24
  16816. - orr r10, r10, r11, lsl #8
  16817. - stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10}
  16818. - mov r3, r11, lsr #24
  16819. - bhs 1b
  16820. -
  16821. -less_than_thirtytwo:
  16822. - /* copy the last 0 to 31 bytes of the source */
  16823. - rsb r12, lr, #32 /* we corrupted r12, recompute it */
  16824. - add r2, r2, #32
  16825. - cmp r2, #4
  16826. - blo partial_word_tail
  16827. -
  16828. -1: ldr r5, [r1], #4
  16829. - sub r2, r2, #4
  16830. - orr r4, r3, r5, lsl lr
  16831. - mov r3, r5, lsr r12
  16832. - str r4, [r0], #4
  16833. - cmp r2, #4
  16834. - bhs 1b
  16835. -
  16836. -partial_word_tail:
  16837. - /* we have a partial word in the input buffer */
  16838. - movs r5, lr, lsl #(31-3)
  16839. - .word 0x44c03001 /* strbmi r3, [r0], #1 */
  16840. - movmi r3, r3, lsr #8
  16841. - .word 0x24c03001 /* strbcs r3, [r0], #1 */
  16842. - movcs r3, r3, lsr #8
  16843. - .word 0x24c03001 /* strbcs r3, [r0], #1 */
  16844. -
  16845. - /* Refill spilled registers from the stack. Don't update sp. */
  16846. - ldmfd sp, {r5-r11}
  16847. -
  16848. -copy_last_3_and_return:
  16849. - movs r2, r2, lsl #31 /* copy remaining 0, 1, 2 or 3 bytes */
  16850. - .word 0x44d12001 /* ldrbmi r2, [r1], #1 */
  16851. - .word 0x24d13001 /* ldrbcs r3, [r1], #1 */
  16852. - .word 0x25d1c000 /* ldrbcs r12,[r1] */
  16853. - .word 0x44c02001 /* strbmi r2, [r0], #1 */
  16854. - .word 0x24c03001 /* strbcs r3, [r0], #1 */
  16855. - .word 0x25c0c000 /* strbcs r12,[r0] */
  16856. -
  16857. - /* we're done! restore sp and spilled registers and return */
  16858. - add sp, sp, #28
  16859. - ldmfd sp!, {r0, r4, lr}
  16860. - tst lr, #1
  16861. - moveq pc, lr
  16862. - bx lr
  16863. --- a/src/string/armel/memcpy.sub
  16864. +++ /dev/null
  16865. @@ -1 +0,0 @@
  16866. -memcpy.s
  16867. --- a/src/string/armhf/memcpy.sub
  16868. +++ /dev/null
  16869. @@ -1 +0,0 @@
  16870. -../armel/memcpy.s
  16871. --- a/src/thread/__syscall_cp.c
  16872. +++ b/src/thread/__syscall_cp.c
  16873. @@ -1,9 +1,7 @@
  16874. #include "pthread_impl.h"
  16875. #include "syscall.h"
  16876. -#ifdef SHARED
  16877. __attribute__((__visibility__("hidden")))
  16878. -#endif
  16879. long __syscall_cp_c();
  16880. static long sccp(syscall_arg_t nr,
  16881. --- a/src/thread/__tls_get_addr.c
  16882. +++ b/src/thread/__tls_get_addr.c
  16883. @@ -1,16 +1,16 @@
  16884. #include <stddef.h>
  16885. #include "pthread_impl.h"
  16886. +#include "libc.h"
  16887. +
  16888. +__attribute__((__visibility__("hidden")))
  16889. +void *__tls_get_new(size_t *);
  16890. void *__tls_get_addr(size_t *v)
  16891. {
  16892. pthread_t self = __pthread_self();
  16893. -#ifdef SHARED
  16894. - __attribute__((__visibility__("hidden")))
  16895. - void *__tls_get_new(size_t *);
  16896. if (v[0]<=(size_t)self->dtv[0])
  16897. return (char *)self->dtv[v[0]]+v[1]+DTP_OFFSET;
  16898. return __tls_get_new(v);
  16899. -#else
  16900. - return (char *)self->dtv[1]+v[1]+DTP_OFFSET;
  16901. -#endif
  16902. }
  16903. +
  16904. +weak_alias(__tls_get_addr, __tls_get_new);
  16905. --- a/src/thread/aarch64/syscall_cp.s
  16906. +++ b/src/thread/aarch64/syscall_cp.s
  16907. @@ -17,7 +17,7 @@
  16908. __syscall_cp_asm:
  16909. __cp_begin:
  16910. ldr w0,[x0]
  16911. - cbnz w0,1f
  16912. + cbnz w0,__cp_cancel
  16913. mov x8,x1
  16914. mov x0,x2
  16915. mov x1,x3
  16916. @@ -28,6 +28,5 @@ __cp_begin:
  16917. svc 0
  16918. __cp_end:
  16919. ret
  16920. -
  16921. - // cbnz might not be able to jump far enough
  16922. -1: b __cancel
  16923. +__cp_cancel:
  16924. + b __cancel
  16925. --- /dev/null
  16926. +++ b/src/thread/arm/__set_thread_area.c
  16927. @@ -0,0 +1,49 @@
  16928. +#include <stdint.h>
  16929. +#include <elf.h>
  16930. +#include "pthread_impl.h"
  16931. +#include "libc.h"
  16932. +
  16933. +#define HWCAP_TLS (1 << 15)
  16934. +
  16935. +extern const unsigned char __attribute__((__visibility__("hidden")))
  16936. + __a_barrier_dummy[], __a_barrier_oldkuser[],
  16937. + __a_barrier_v6[], __a_barrier_v7[],
  16938. + __a_cas_dummy[], __a_cas_v6[], __a_cas_v7[],
  16939. + __a_gettp_dummy[];
  16940. +
  16941. +#define __a_barrier_kuser 0xffff0fa0
  16942. +#define __a_cas_kuser 0xffff0fc0
  16943. +#define __a_gettp_kuser 0xffff0fe0
  16944. +
  16945. +extern uintptr_t __attribute__((__visibility__("hidden")))
  16946. + __a_barrier_ptr, __a_cas_ptr, __a_gettp_ptr;
  16947. +
  16948. +#define SET(op,ver) (__a_##op##_ptr = \
  16949. + (uintptr_t)__a_##op##_##ver - (uintptr_t)__a_##op##_dummy)
  16950. +
  16951. +int __set_thread_area(void *p)
  16952. +{
  16953. +#if !__ARM_ARCH_7A__ && !__ARM_ARCH_7R__ && __ARM_ARCH < 7
  16954. + if (__hwcap & HWCAP_TLS) {
  16955. + size_t *aux;
  16956. + SET(cas, v7);
  16957. + SET(barrier, v7);
  16958. + for (aux=libc.auxv; *aux; aux+=2) {
  16959. + if (*aux != AT_PLATFORM) continue;
  16960. + const char *s = (void *)aux[1];
  16961. + if (s[0]!='v' || s[1]!='6' || s[2]-'0'<10u) break;
  16962. + SET(cas, v6);
  16963. + SET(barrier, v6);
  16964. + break;
  16965. + }
  16966. + } else {
  16967. + int ver = *(int *)0xffff0ffc;
  16968. + SET(gettp, kuser);
  16969. + SET(cas, kuser);
  16970. + SET(barrier, kuser);
  16971. + if (ver < 2) a_crash();
  16972. + if (ver < 3) SET(barrier, oldkuser);
  16973. + }
  16974. +#endif
  16975. + return __syscall(0xf0005, p);
  16976. +}
  16977. --- a/src/thread/arm/__set_thread_area.s
  16978. +++ /dev/null
  16979. @@ -1 +0,0 @@
  16980. -/* Replaced by C code in arch/arm/src */
  16981. --- a/src/thread/arm/__unmapself.s
  16982. +++ b/src/thread/arm/__unmapself.s
  16983. @@ -1,3 +1,4 @@
  16984. +.syntax unified
  16985. .text
  16986. .global __unmapself
  16987. .type __unmapself,%function
  16988. --- /dev/null
  16989. +++ b/src/thread/arm/atomics.s
  16990. @@ -0,0 +1,113 @@
  16991. +.syntax unified
  16992. +.text
  16993. +
  16994. +.global __a_barrier
  16995. +.hidden __a_barrier
  16996. +.type __a_barrier,%function
  16997. +__a_barrier:
  16998. + ldr ip,1f
  16999. + ldr ip,[pc,ip]
  17000. + add pc,pc,ip
  17001. +1: .word __a_barrier_ptr-1b
  17002. +.global __a_barrier_dummy
  17003. +.hidden __a_barrier_dummy
  17004. +__a_barrier_dummy:
  17005. + bx lr
  17006. +.global __a_barrier_oldkuser
  17007. +.hidden __a_barrier_oldkuser
  17008. +__a_barrier_oldkuser:
  17009. + push {r0,r1,r2,r3,ip,lr}
  17010. + mov r1,r0
  17011. + mov r2,sp
  17012. + ldr ip,=0xffff0fc0
  17013. + mov lr,pc
  17014. + mov pc,ip
  17015. + pop {r0,r1,r2,r3,ip,lr}
  17016. + bx lr
  17017. +.global __a_barrier_v6
  17018. +.hidden __a_barrier_v6
  17019. +__a_barrier_v6:
  17020. + mcr p15,0,r0,c7,c10,5
  17021. + bx lr
  17022. +.global __a_barrier_v7
  17023. +.hidden __a_barrier_v7
  17024. +__a_barrier_v7:
  17025. + .word 0xf57ff05b /* dmb ish */
  17026. + bx lr
  17027. +
  17028. +.global __a_cas
  17029. +.hidden __a_cas
  17030. +.type __a_cas,%function
  17031. +__a_cas:
  17032. + ldr ip,1f
  17033. + ldr ip,[pc,ip]
  17034. + add pc,pc,ip
  17035. +1: .word __a_cas_ptr-1b
  17036. +.global __a_cas_dummy
  17037. +.hidden __a_cas_dummy
  17038. +__a_cas_dummy:
  17039. + mov r3,r0
  17040. + ldr r0,[r2]
  17041. + subs r0,r3,r0
  17042. + streq r1,[r2]
  17043. + bx lr
  17044. +.global __a_cas_v6
  17045. +.hidden __a_cas_v6
  17046. +__a_cas_v6:
  17047. + mov r3,r0
  17048. + mcr p15,0,r0,c7,c10,5
  17049. +1: .word 0xe1920f9f /* ldrex r0,[r2] */
  17050. + subs r0,r3,r0
  17051. + .word 0x01820f91 /* strexeq r0,r1,[r2] */
  17052. + teqeq r0,#1
  17053. + beq 1b
  17054. + mcr p15,0,r0,c7,c10,5
  17055. + bx lr
  17056. +.global __a_cas_v7
  17057. +.hidden __a_cas_v7
  17058. +__a_cas_v7:
  17059. + mov r3,r0
  17060. + .word 0xf57ff05b /* dmb ish */
  17061. +1: .word 0xe1920f9f /* ldrex r0,[r2] */
  17062. + subs r0,r3,r0
  17063. + .word 0x01820f91 /* strexeq r0,r1,[r2] */
  17064. + teqeq r0,#1
  17065. + beq 1b
  17066. + .word 0xf57ff05b /* dmb ish */
  17067. + bx lr
  17068. +
  17069. +.global __aeabi_read_tp
  17070. +.type __aeabi_read_tp,%function
  17071. +__aeabi_read_tp:
  17072. +
  17073. +.global __a_gettp
  17074. +.hidden __a_gettp
  17075. +.type __a_gettp,%function
  17076. +__a_gettp:
  17077. + ldr r0,1f
  17078. + ldr r0,[pc,r0]
  17079. + add pc,pc,r0
  17080. +1: .word __a_gettp_ptr-1b
  17081. +.global __a_gettp_dummy
  17082. +.hidden __a_gettp_dummy
  17083. +__a_gettp_dummy:
  17084. + mrc p15,0,r0,c13,c0,3
  17085. + bx lr
  17086. +
  17087. +.data
  17088. +.align 2
  17089. +
  17090. +.global __a_barrier_ptr
  17091. +.hidden __a_barrier_ptr
  17092. +__a_barrier_ptr:
  17093. + .word 0
  17094. +
  17095. +.global __a_cas_ptr
  17096. +.hidden __a_cas_ptr
  17097. +__a_cas_ptr:
  17098. + .word 0
  17099. +
  17100. +.global __a_gettp_ptr
  17101. +.hidden __a_gettp_ptr
  17102. +__a_gettp_ptr:
  17103. + .word 0
  17104. --- a/src/thread/arm/clone.s
  17105. +++ b/src/thread/arm/clone.s
  17106. @@ -1,3 +1,4 @@
  17107. +.syntax unified
  17108. .text
  17109. .global __clone
  17110. .type __clone,%function
  17111. @@ -15,8 +16,6 @@ __clone:
  17112. tst r0,r0
  17113. beq 1f
  17114. ldmfd sp!,{r4,r5,r6,r7}
  17115. - tst lr,#1
  17116. - moveq pc,lr
  17117. bx lr
  17118. 1: mov r0,r6
  17119. --- a/src/thread/arm/syscall_cp.s
  17120. +++ b/src/thread/arm/syscall_cp.s
  17121. @@ -1,3 +1,4 @@
  17122. +.syntax unified
  17123. .global __cp_begin
  17124. .hidden __cp_begin
  17125. .global __cp_end
  17126. @@ -22,8 +23,6 @@ __cp_begin:
  17127. svc 0
  17128. __cp_end:
  17129. ldmfd sp!,{r4,r5,r6,r7,lr}
  17130. - tst lr,#1
  17131. - moveq pc,lr
  17132. bx lr
  17133. __cp_cancel:
  17134. ldmfd sp!,{r4,r5,r6,r7,lr}
  17135. --- a/src/thread/microblaze/syscall_cp.s
  17136. +++ b/src/thread/microblaze/syscall_cp.s
  17137. @@ -11,7 +11,7 @@
  17138. __syscall_cp_asm:
  17139. __cp_begin:
  17140. lwi r5, r5, 0
  17141. - bnei r5, __cancel
  17142. + bnei r5, __cp_cancel
  17143. addi r12, r6, 0
  17144. add r5, r7, r0
  17145. add r6, r8, r0
  17146. @@ -23,3 +23,5 @@ __cp_begin:
  17147. __cp_end:
  17148. rtsd r15, 8
  17149. nop
  17150. +__cp_cancel:
  17151. + bri __cancel
  17152. --- a/src/thread/or1k/syscall_cp.s
  17153. +++ b/src/thread/or1k/syscall_cp.s
  17154. @@ -12,7 +12,7 @@ __syscall_cp_asm:
  17155. __cp_begin:
  17156. l.lwz r3, 0(r3)
  17157. l.sfeqi r3, 0
  17158. - l.bnf __cancel
  17159. + l.bnf __cp_cancel
  17160. l.ori r11, r4, 0
  17161. l.ori r3, r5, 0
  17162. l.ori r4, r6, 0
  17163. @@ -24,3 +24,6 @@ __cp_begin:
  17164. __cp_end:
  17165. l.jr r9
  17166. l.nop
  17167. +__cp_cancel:
  17168. + l.j __cancel
  17169. + l.nop
  17170. --- a/src/thread/powerpc/syscall_cp.s
  17171. +++ b/src/thread/powerpc/syscall_cp.s
  17172. @@ -38,7 +38,7 @@ __cp_begin:
  17173. cmpwi cr7, 0, 0 #compare r0 with 0, store result in cr7.
  17174. beq+ cr7, 1f #jump to label 1 if r0 was 0
  17175. - b __cancel #else call cancel
  17176. + b __cp_cancel #else call cancel
  17177. 1:
  17178. #ok, the cancel flag was not set
  17179. # syscall: number goes to r0, the rest 3-8
  17180. @@ -55,3 +55,5 @@ __cp_end:
  17181. #else negate result.
  17182. neg 3, 3
  17183. blr
  17184. +__cp_cancel:
  17185. + b __cancel
  17186. --- a/src/thread/pthread_cancel.c
  17187. +++ b/src/thread/pthread_cancel.c
  17188. @@ -1,12 +1,11 @@
  17189. +#define _GNU_SOURCE
  17190. #include <string.h>
  17191. #include "pthread_impl.h"
  17192. #include "syscall.h"
  17193. #include "libc.h"
  17194. -#ifdef SHARED
  17195. __attribute__((__visibility__("hidden")))
  17196. -#endif
  17197. -long __cancel(), __cp_cancel(), __syscall_cp_asm(), __syscall_cp_c();
  17198. +long __cancel(), __syscall_cp_asm(), __syscall_cp_c();
  17199. long __cancel()
  17200. {
  17201. @@ -17,12 +16,6 @@ long __cancel()
  17202. return -ECANCELED;
  17203. }
  17204. -/* If __syscall_cp_asm has adjusted the stack pointer, it must provide a
  17205. - * definition of __cp_cancel to undo those adjustments and call __cancel.
  17206. - * Otherwise, __cancel provides a definition for __cp_cancel. */
  17207. -
  17208. -weak_alias(__cancel, __cp_cancel);
  17209. -
  17210. long __syscall_cp_asm(volatile void *, syscall_arg_t,
  17211. syscall_arg_t, syscall_arg_t, syscall_arg_t,
  17212. syscall_arg_t, syscall_arg_t, syscall_arg_t);
  17213. @@ -52,24 +45,22 @@ static void _sigaddset(sigset_t *set, in
  17214. set->__bits[s/8/sizeof *set->__bits] |= 1UL<<(s&8*sizeof *set->__bits-1);
  17215. }
  17216. -#ifdef SHARED
  17217. __attribute__((__visibility__("hidden")))
  17218. -#endif
  17219. -extern const char __cp_begin[1], __cp_end[1];
  17220. +extern const char __cp_begin[1], __cp_end[1], __cp_cancel[1];
  17221. static void cancel_handler(int sig, siginfo_t *si, void *ctx)
  17222. {
  17223. pthread_t self = __pthread_self();
  17224. ucontext_t *uc = ctx;
  17225. - const char *ip = ((char **)&uc->uc_mcontext)[CANCEL_REG_IP];
  17226. + uintptr_t pc = uc->uc_mcontext.MC_PC;
  17227. a_barrier();
  17228. if (!self->cancel || self->canceldisable == PTHREAD_CANCEL_DISABLE) return;
  17229. _sigaddset(&uc->uc_sigmask, SIGCANCEL);
  17230. - if (self->cancelasync || ip >= __cp_begin && ip < __cp_end) {
  17231. - ((char **)&uc->uc_mcontext)[CANCEL_REG_IP] = (char *)__cp_cancel;
  17232. + if (self->cancelasync || pc >= (uintptr_t)__cp_begin && pc < (uintptr_t)__cp_end) {
  17233. + uc->uc_mcontext.MC_PC = (uintptr_t)__cp_cancel;
  17234. return;
  17235. }
  17236. --- /dev/null
  17237. +++ b/src/thread/sh/__set_thread_area.c
  17238. @@ -0,0 +1,40 @@
  17239. +#include "pthread_impl.h"
  17240. +#include "libc.h"
  17241. +#include <elf.h>
  17242. +
  17243. +/* Also perform sh-specific init */
  17244. +
  17245. +#define CPU_HAS_LLSC 0x0040
  17246. +#define CPU_HAS_CAS_L 0x0400
  17247. +
  17248. +__attribute__((__visibility__("hidden")))
  17249. +extern const char __sh_cas_gusa[], __sh_cas_llsc[], __sh_cas_imask[], __sh_cas_cas_l[];
  17250. +
  17251. +__attribute__((__visibility__("hidden")))
  17252. +const void *__sh_cas_ptr;
  17253. +
  17254. +__attribute__((__visibility__("hidden")))
  17255. +unsigned __sh_nommu;
  17256. +
  17257. +int __set_thread_area(void *p)
  17258. +{
  17259. + size_t *aux;
  17260. + __asm__ __volatile__ ( "ldc %0, gbr" : : "r"(p) : "memory" );
  17261. +#ifndef __SH4A__
  17262. + __sh_cas_ptr = __sh_cas_gusa;
  17263. +#if !defined(__SH3__) && !defined(__SH4__)
  17264. + for (aux=libc.auxv; *aux; aux+=2) {
  17265. + if (*aux != AT_PLATFORM) continue;
  17266. + const char *s = (void *)aux[1];
  17267. + if (s[0]!='s' || s[1]!='h' || s[2]!='2' || s[3]-'0'<10u) break;
  17268. + __sh_cas_ptr = __sh_cas_imask;
  17269. + __sh_nommu = 1;
  17270. + }
  17271. +#endif
  17272. + if (__hwcap & CPU_HAS_CAS_L)
  17273. + __sh_cas_ptr = __sh_cas_cas_l;
  17274. + else if (__hwcap & CPU_HAS_LLSC)
  17275. + __sh_cas_ptr = __sh_cas_llsc;
  17276. +#endif
  17277. + return 0;
  17278. +}
  17279. --- /dev/null
  17280. +++ b/src/thread/sh/__unmapself.c
  17281. @@ -0,0 +1,24 @@
  17282. +#include "pthread_impl.h"
  17283. +
  17284. +void __unmapself_sh_mmu(void *, size_t);
  17285. +void __unmapself_sh_nommu(void *, size_t);
  17286. +
  17287. +#if !defined(__SH3__) && !defined(__SH4__)
  17288. +#define __unmapself __unmapself_sh_nommu
  17289. +#include "dynlink.h"
  17290. +#undef CRTJMP
  17291. +#define CRTJMP(pc,sp) __asm__ __volatile__( \
  17292. + "mov.l @%0+,r0 ; mov.l @%0,r12 ; jmp @r0 ; mov %1,r15" \
  17293. + : : "r"(pc), "r"(sp) : "r0", "memory" )
  17294. +#include "../__unmapself.c"
  17295. +#undef __unmapself
  17296. +extern __attribute__((__visibility__("hidden"))) unsigned __sh_nommu;
  17297. +#else
  17298. +#define __sh_nommu 0
  17299. +#endif
  17300. +
  17301. +void __unmapself(void *base, size_t size)
  17302. +{
  17303. + if (__sh_nommu) __unmapself_sh_nommu(base, size);
  17304. + else __unmapself_sh_mmu(base, size);
  17305. +}
  17306. --- a/src/thread/sh/__unmapself.s
  17307. +++ /dev/null
  17308. @@ -1,22 +0,0 @@
  17309. -.text
  17310. -.global __unmapself_sh_mmu
  17311. -.type __unmapself_sh_mmu, @function
  17312. -__unmapself_sh_mmu:
  17313. - mov #91, r3 ! SYS_munmap
  17314. - trapa #31
  17315. -
  17316. - or r0, r0
  17317. - or r0, r0
  17318. - or r0, r0
  17319. - or r0, r0
  17320. - or r0, r0
  17321. -
  17322. - mov #1, r3 ! SYS_exit
  17323. - mov #0, r4
  17324. - trapa #31
  17325. -
  17326. - or r0, r0
  17327. - or r0, r0
  17328. - or r0, r0
  17329. - or r0, r0
  17330. - or r0, r0
  17331. --- /dev/null
  17332. +++ b/src/thread/sh/__unmapself_mmu.s
  17333. @@ -0,0 +1,22 @@
  17334. +.text
  17335. +.global __unmapself_sh_mmu
  17336. +.type __unmapself_sh_mmu, @function
  17337. +__unmapself_sh_mmu:
  17338. + mov #91, r3 ! SYS_munmap
  17339. + trapa #31
  17340. +
  17341. + or r0, r0
  17342. + or r0, r0
  17343. + or r0, r0
  17344. + or r0, r0
  17345. + or r0, r0
  17346. +
  17347. + mov #1, r3 ! SYS_exit
  17348. + mov #0, r4
  17349. + trapa #31
  17350. +
  17351. + or r0, r0
  17352. + or r0, r0
  17353. + or r0, r0
  17354. + or r0, r0
  17355. + or r0, r0
  17356. --- /dev/null
  17357. +++ b/src/thread/sh/atomics.s
  17358. @@ -0,0 +1,65 @@
  17359. +/* Contract for all versions is same as cas.l r2,r3,@r0
  17360. + * pr and r1 are also clobbered (by jsr & r1 as temp).
  17361. + * r0,r2,r4-r15 must be preserved.
  17362. + * r3 contains result (==r2 iff cas succeeded). */
  17363. +
  17364. + .align 2
  17365. +.global __sh_cas_gusa
  17366. +.hidden __sh_cas_gusa
  17367. +__sh_cas_gusa:
  17368. + mov.l r5,@-r15
  17369. + mov.l r4,@-r15
  17370. + mov r0,r4
  17371. + mova 1f,r0
  17372. + mov r15,r1
  17373. + mov #(0f-1f),r15
  17374. +0: mov.l @r4,r5
  17375. + cmp/eq r5,r2
  17376. + bf 1f
  17377. + mov.l r3,@r4
  17378. +1: mov r1,r15
  17379. + mov r5,r3
  17380. + mov r4,r0
  17381. + mov.l @r15+,r4
  17382. + rts
  17383. + mov.l @r15+,r5
  17384. +
  17385. +.global __sh_cas_llsc
  17386. +.hidden __sh_cas_llsc
  17387. +__sh_cas_llsc:
  17388. + mov r0,r1
  17389. + synco
  17390. +0: movli.l @r1,r0
  17391. + cmp/eq r0,r2
  17392. + bf 1f
  17393. + mov r3,r0
  17394. + movco.l r0,@r1
  17395. + bf 0b
  17396. + mov r2,r0
  17397. +1: synco
  17398. + mov r0,r3
  17399. + rts
  17400. + mov r1,r0
  17401. +
  17402. +.global __sh_cas_imask
  17403. +.hidden __sh_cas_imask
  17404. +__sh_cas_imask:
  17405. + mov r0,r1
  17406. + stc sr,r0
  17407. + mov.l r0,@-r15
  17408. + or #0xf0,r0
  17409. + ldc r0,sr
  17410. + mov.l @r1,r0
  17411. + cmp/eq r0,r2
  17412. + bf 1f
  17413. + mov.l r3,@r1
  17414. +1: ldc.l @r15+,sr
  17415. + mov r0,r3
  17416. + rts
  17417. + mov r1,r0
  17418. +
  17419. +.global __sh_cas_cas_l
  17420. +.hidden __sh_cas_cas_l
  17421. +__sh_cas_cas_l:
  17422. + rts
  17423. + .word 0x2323 /* cas.l r2,r3,@r0 */
  17424. --- a/src/thread/sh/syscall_cp.s
  17425. +++ b/src/thread/sh/syscall_cp.s
  17426. @@ -14,17 +14,8 @@ __syscall_cp_asm:
  17427. __cp_begin:
  17428. mov.l @r4, r4
  17429. tst r4, r4
  17430. - bt 2f
  17431. -
  17432. - mov.l L1, r0
  17433. - braf r0
  17434. - nop
  17435. -1:
  17436. -
  17437. -.align 2
  17438. -L1: .long __cancel@PLT-(1b-.)
  17439. -
  17440. -2: mov r5, r3
  17441. + bf __cp_cancel
  17442. + mov r5, r3
  17443. mov r6, r4
  17444. mov r7, r5
  17445. mov.l @r15, r6
  17446. @@ -43,3 +34,12 @@ __cp_end:
  17447. rts
  17448. nop
  17449. +
  17450. +__cp_cancel:
  17451. + mov.l 2f, r0
  17452. + braf r0
  17453. + nop
  17454. +1:
  17455. +
  17456. +.align 2
  17457. +2: .long __cancel@PCREL-(1b-.)
  17458. --- a/src/thread/x32/syscall_cp.s
  17459. +++ b/src/thread/x32/syscall_cp.s
  17460. @@ -14,7 +14,7 @@ __syscall_cp_internal:
  17461. __cp_begin:
  17462. mov (%rdi),%eax
  17463. test %eax,%eax
  17464. - jnz __cancel
  17465. + jnz __cp_cancel
  17466. mov %rdi,%r11
  17467. mov %rsi,%rax
  17468. mov %rdx,%rdi
  17469. @@ -27,3 +27,5 @@ __cp_begin:
  17470. syscall
  17471. __cp_end:
  17472. ret
  17473. +__cp_cancel:
  17474. + jmp __cancel
  17475. --- /dev/null
  17476. +++ b/src/thread/x32/syscall_cp_fixup.c
  17477. @@ -0,0 +1,38 @@
  17478. +#include <sys/syscall.h>
  17479. +
  17480. +__attribute__((__visibility__("hidden")))
  17481. +long __syscall_cp_internal(volatile void*, long long, long long, long long, long long,
  17482. + long long, long long, long long);
  17483. +
  17484. +struct __timespec { long long tv_sec; long tv_nsec; };
  17485. +struct __timespec_kernel { long long tv_sec; long long tv_nsec; };
  17486. +#define __tsc(X) ((struct __timespec*)(unsigned long)(X))
  17487. +#define __fixup(X) do { if(X) { \
  17488. + ts->tv_sec = __tsc(X)->tv_sec; \
  17489. + ts->tv_nsec = __tsc(X)->tv_nsec; \
  17490. + (X) = (unsigned long)ts; } } while(0)
  17491. +
  17492. +__attribute__((__visibility__("hidden")))
  17493. +long __syscall_cp_asm (volatile void * foo, long long n, long long a1, long long a2, long long a3,
  17494. + long long a4, long long a5, long long a6)
  17495. +{
  17496. + struct __timespec_kernel ts[1];
  17497. + switch (n) {
  17498. + case SYS_mq_timedsend: case SYS_mq_timedreceive: case SYS_pselect6:
  17499. + __fixup(a5);
  17500. + break;
  17501. + case SYS_futex:
  17502. + if((a2 & (~128 /* FUTEX_PRIVATE_FLAG */)) == 0 /* FUTEX_WAIT */)
  17503. + __fixup(a4);
  17504. + break;
  17505. + case SYS_clock_nanosleep:
  17506. + case SYS_rt_sigtimedwait: case SYS_ppoll:
  17507. + __fixup(a3);
  17508. + break;
  17509. + case SYS_nanosleep:
  17510. + __fixup(a1);
  17511. + break;
  17512. + }
  17513. + return __syscall_cp_internal(foo, n, a1, a2, a3, a4, a5, a6);
  17514. +}
  17515. +
  17516. --- a/src/thread/x86_64/syscall_cp.s
  17517. +++ b/src/thread/x86_64/syscall_cp.s
  17518. @@ -14,7 +14,7 @@ __syscall_cp_asm:
  17519. __cp_begin:
  17520. mov (%rdi),%eax
  17521. test %eax,%eax
  17522. - jnz __cancel
  17523. + jnz __cp_cancel
  17524. mov %rdi,%r11
  17525. mov %rsi,%rax
  17526. mov %rdx,%rdi
  17527. @@ -27,3 +27,5 @@ __cp_begin:
  17528. syscall
  17529. __cp_end:
  17530. ret
  17531. +__cp_cancel:
  17532. + jmp __cancel
  17533. --- a/src/time/clock_gettime.c
  17534. +++ b/src/time/clock_gettime.c
  17535. @@ -5,37 +5,54 @@
  17536. #include "libc.h"
  17537. #include "atomic.h"
  17538. -static int sc_clock_gettime(clockid_t clk, struct timespec *ts)
  17539. +#ifdef VDSO_CGT_SYM
  17540. +
  17541. +void *__vdsosym(const char *, const char *);
  17542. +
  17543. +static void *volatile vdso_func;
  17544. +
  17545. +static int cgt_init(clockid_t clk, struct timespec *ts)
  17546. {
  17547. - int r = __syscall(SYS_clock_gettime, clk, ts);
  17548. - if (!r) return r;
  17549. - if (r == -ENOSYS) {
  17550. - if (clk == CLOCK_REALTIME) {
  17551. - __syscall(SYS_gettimeofday, ts, 0);
  17552. - ts->tv_nsec = (int)ts->tv_nsec * 1000;
  17553. - return 0;
  17554. - }
  17555. - r = -EINVAL;
  17556. - }
  17557. - errno = -r;
  17558. - return -1;
  17559. + void *p = __vdsosym(VDSO_CGT_VER, VDSO_CGT_SYM);
  17560. + int (*f)(clockid_t, struct timespec *) =
  17561. + (int (*)(clockid_t, struct timespec *))p;
  17562. + a_cas_p(&vdso_func, (void *)cgt_init, p);
  17563. + return f ? f(clk, ts) : -ENOSYS;
  17564. }
  17565. -void *__vdsosym(const char *, const char *);
  17566. +static void *volatile vdso_func = (void *)cgt_init;
  17567. +
  17568. +#endif
  17569. int __clock_gettime(clockid_t clk, struct timespec *ts)
  17570. {
  17571. + int r;
  17572. +
  17573. #ifdef VDSO_CGT_SYM
  17574. - static int (*volatile cgt)(clockid_t, struct timespec *);
  17575. - if (!cgt) {
  17576. - void *f = __vdsosym(VDSO_CGT_VER, VDSO_CGT_SYM);
  17577. - if (!f) f = (void *)sc_clock_gettime;
  17578. - a_cas_p(&cgt, 0, f);
  17579. + int (*f)(clockid_t, struct timespec *) =
  17580. + (int (*)(clockid_t, struct timespec *))vdso_func;
  17581. + if (f) {
  17582. + r = f(clk, ts);
  17583. + if (!r) return r;
  17584. + if (r == -EINVAL) return __syscall_ret(r);
  17585. + /* Fall through on errors other than EINVAL. Some buggy
  17586. + * vdso implementations return ENOSYS for clocks they
  17587. + * can't handle, rather than making the syscall. This
  17588. + * also handles the case where cgt_init fails to find
  17589. + * a vdso function to use. */
  17590. }
  17591. - return cgt(clk, ts);
  17592. -#else
  17593. - return sc_clock_gettime(clk, ts);
  17594. #endif
  17595. +
  17596. + r = __syscall(SYS_clock_gettime, clk, ts);
  17597. + if (r == -ENOSYS) {
  17598. + if (clk == CLOCK_REALTIME) {
  17599. + __syscall(SYS_gettimeofday, ts, 0);
  17600. + ts->tv_nsec = (int)ts->tv_nsec * 1000;
  17601. + return 0;
  17602. + }
  17603. + r = -EINVAL;
  17604. + }
  17605. + return __syscall_ret(r);
  17606. }
  17607. weak_alias(__clock_gettime, clock_gettime);