licenses.list.txt 423 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891
  1. ====================CC-PDDC====================
  2. Doug Lea and released to the public domain, as explained at
  3. http://creativecommons.org/licenses/publicdomain. Send questions,
  4. ====================COPYRIGHT====================
  5. Copyright (C) 1998 Geoffrey Keating
  6. Copyright (C) 2001 John Hornkvist
  7. Copyright (C) 2002, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
  8. ====================COPYRIGHT====================
  9. Copyright (C) 2003-2004, 2006, 2009-2017 Free Software Foundation, Inc.
  10. ====================COPYRIGHT====================
  11. aix.S - Copyright (c) 2002, 2009 Free Software Foundation, Inc.
  12. based on darwin.S by John Hornkvist
  13. ====================COPYRIGHT====================
  14. aix_closure.S - Copyright (c) 2002, 2003, 2009 Free Software Foundation, Inc.
  15. based on darwin_closure.S
  16. ====================COPYRIGHT====================
  17. asm.h - Copyright (c) 1998 Geoffrey Keating
  18. ====================COPYRIGHT====================
  19. closures.c - Copyright (c) 2019 Anthony Green
  20. Copyright (c) 2007, 2009, 2010 Red Hat, Inc.
  21. Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc
  22. Copyright (c) 2011 Plausible Labs Cooperative, Inc.
  23. ====================COPYRIGHT====================
  24. darwin.S - Copyright (c) 2000 John Hornkvist
  25. Copyright (c) 2004, 2010 Free Software Foundation, Inc.
  26. ====================COPYRIGHT====================
  27. darwin_closure.S - Copyright (c) 2002, 2003, 2004, 2010,
  28. Free Software Foundation, Inc.
  29. based on ppc_closure.S
  30. ====================COPYRIGHT====================
  31. ffi.c - Copyright (C) 2013 IBM
  32. Copyright (C) 2011 Anthony Green
  33. Copyright (C) 2011 Kyle Moffett
  34. Copyright (C) 2008 Red Hat, Inc
  35. Copyright (C) 2007, 2008 Free Software Foundation, Inc
  36. Copyright (c) 1998 Geoffrey Keating
  37. ====================COPYRIGHT====================
  38. ffi.c - Copyright (c) 2011 Timothy Wall
  39. Copyright (c) 2011 Plausible Labs Cooperative, Inc.
  40. Copyright (c) 2011 Anthony Green
  41. Copyright (c) 2011 Free Software Foundation
  42. Copyright (c) 1998, 2008, 2011 Red Hat, Inc.
  43. ====================COPYRIGHT====================
  44. ffi.c - Copyright (c) 2017 Anthony Green
  45. Copyright (c) 1996, 1998, 1999, 2001, 2007, 2008 Red Hat, Inc.
  46. Copyright (c) 2002 Ranjit Mathew
  47. Copyright (c) 2002 Bo Thorsen
  48. Copyright (c) 2002 Roger Sayle
  49. Copyright (C) 2008, 2010 Free Software Foundation, Inc.
  50. ====================COPYRIGHT====================
  51. ffi64.c - Copyright (c) 2011, 2018 Anthony Green
  52. Copyright (c) 2013 The Written Word, Inc.
  53. Copyright (c) 2008, 2010 Red Hat, Inc.
  54. Copyright (c) 2002, 2007 Bo Thorsen <bo@suse.de>
  55. ====================COPYRIGHT====================
  56. ffitarget.h - Copyright (c) 2012 Anthony Green
  57. Copyright (C) 2007, 2008, 2010 Free Software Foundation, Inc
  58. Copyright (c) 1996-2003 Red Hat, Inc.
  59. ====================COPYRIGHT====================
  60. ffitarget.h - Copyright (c) 2012 Anthony Green
  61. Copyright (c) 2010 CodeSourcery
  62. Copyright (c) 1996-2003 Red Hat, Inc.
  63. ====================COPYRIGHT====================
  64. ffitarget.h - Copyright (c) 2012, 2014, 2018 Anthony Green
  65. Copyright (c) 1996-2003, 2010 Red Hat, Inc.
  66. Copyright (C) 2008 Free Software Foundation, Inc.
  67. ====================COPYRIGHT====================
  68. ffiw64.c - Copyright (c) 2018 Anthony Green
  69. Copyright (c) 2014 Red Hat, Inc.
  70. ====================COPYRIGHT====================
  71. java_raw_api.c - Copyright (c) 1999, 2007, 2008 Red Hat, Inc.
  72. ====================COPYRIGHT====================
  73. libffi 3.3 - Copyright (c) 2011, 2014, 2019 Anthony Green
  74. - Copyright (c) 1996-2003, 2007, 2008 Red Hat, Inc.
  75. ====================COPYRIGHT====================
  76. prep_cif.c - Copyright (c) 2011, 2012 Anthony Green
  77. Copyright (c) 1996, 1998, 2007 Red Hat, Inc.
  78. ====================COPYRIGHT====================
  79. raw_api.c - Copyright (c) 1999, 2008 Red Hat, Inc.
  80. ====================COPYRIGHT====================
  81. sysv.S - Copyright (c) 1998 Geoffrey Keating
  82. Copyright (C) 2007 Free Software Foundation, Inc
  83. ====================COPYRIGHT====================
  84. sysv.S - Copyright (c) 1998, 2008, 2011 Red Hat, Inc.
  85. Copyright (c) 2011 Plausible Labs Cooperative, Inc.
  86. Copyright (c) 2019 Microsoft Corporation.
  87. ====================COPYRIGHT====================
  88. sysv.S - Copyright (c) 2017 Anthony Green
  89. - Copyright (c) 2013 The Written Word, Inc.
  90. - Copyright (c) 1996,1998,2001-2003,2005,2008,2010 Red Hat, Inc.
  91. ====================COPYRIGHT====================
  92. sysv.h - Copyright (c) 2003 Jakub Jelinek <jakub@redhat.com>
  93. Copyright (c) 2008 Red Hat, Inc.
  94. ====================COPYRIGHT====================
  95. types.c - Copyright (c) 1996, 1998 Red Hat, Inc.
  96. ====================COPYRIGHT====================
  97. unix64.S - Copyright (c) 2013 The Written Word, Inc.
  98. - Copyright (c) 2008 Red Hat, Inc
  99. - Copyright (c) 2002 Bo Thorsen <bo@suse.de>
  100. ====================COPYRIGHT====================
  101. Copyright 1993 Bill Triggs <Bill.Triggs@inrialpes.fr>
  102. Copyright 1995-2017 Bruno Haible <bruno@clisp.org>
  103. ====================COPYRIGHT====================
  104. Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
  105. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  106. Everyone is permitted to copy and distribute verbatim copies
  107. ====================COPYRIGHT====================
  108. /* Copyright (c) 2009, 2010, 2011, 2012 ARM Ltd.
  109. ====================COPYRIGHT====================
  110. libffi - Copyright (c) 1996-2019 Anthony Green, Red Hat, Inc and others.
  111. See source files for details.
  112. ====================COPYRIGHT====================
  113. programs whose distribution conditions are different, write to the author
  114. to ask for permission. For software which is copyrighted by the Free
  115. Software Foundation, write to the Free Software Foundation; we sometimes
  116. make exceptions for this. Our decision will be guided by the two goals
  117. of preserving the free status of all derivatives of our free software and
  118. of promoting the sharing and reuse of software generally.
  119. ====================File: .yandex_meta/files/configs/aarch64-apple-iphoneos/include/ffitarget.h====================
  120. /* Copyright (c) 2009, 2010, 2011, 2012 ARM Ltd.
  121. Permission is hereby granted, free of charge, to any person obtaining
  122. a copy of this software and associated documentation files (the
  123. ``Software''), to deal in the Software without restriction, including
  124. without limitation the rights to use, copy, modify, merge, publish,
  125. distribute, sublicense, and/or sell copies of the Software, and to
  126. permit persons to whom the Software is furnished to do so, subject to
  127. the following conditions:
  128. The above copyright notice and this permission notice shall be
  129. included in all copies or substantial portions of the Software.
  130. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  131. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  132. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  133. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  134. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  135. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  136. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  137. #ifndef LIBFFI_TARGET_H
  138. #define LIBFFI_TARGET_H
  139. #ifndef LIBFFI_H
  140. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  141. #endif
  142. #ifndef LIBFFI_ASM
  143. #ifdef __ILP32__
  144. #define FFI_SIZEOF_ARG 8
  145. #define FFI_SIZEOF_JAVA_RAW 4
  146. typedef unsigned long long ffi_arg;
  147. typedef signed long long ffi_sarg;
  148. #elif defined(_M_ARM64)
  149. #define FFI_SIZEOF_ARG 8
  150. typedef unsigned long long ffi_arg;
  151. typedef signed long long ffi_sarg;
  152. #else
  153. typedef unsigned long ffi_arg;
  154. typedef signed long ffi_sarg;
  155. #endif
  156. typedef enum ffi_abi
  157. {
  158. FFI_FIRST_ABI = 0,
  159. FFI_SYSV,
  160. FFI_LAST_ABI,
  161. FFI_DEFAULT_ABI = FFI_SYSV
  162. } ffi_abi;
  163. #endif
  164. /* ---- Definitions for closures ----------------------------------------- */
  165. #define FFI_CLOSURES 1
  166. #define FFI_NATIVE_RAW_API 0
  167. #if defined (FFI_EXEC_TRAMPOLINE_TABLE) && FFI_EXEC_TRAMPOLINE_TABLE
  168. #ifdef __MACH__
  169. #define FFI_TRAMPOLINE_SIZE 16
  170. #define FFI_TRAMPOLINE_CLOSURE_OFFSET 16
  171. #else
  172. #error "No trampoline table implementation"
  173. #endif
  174. #else
  175. #define FFI_TRAMPOLINE_SIZE 24
  176. #define FFI_TRAMPOLINE_CLOSURE_OFFSET FFI_TRAMPOLINE_SIZE
  177. #endif
  178. #ifdef _M_ARM64
  179. #define FFI_EXTRA_CIF_FIELDS unsigned is_variadic
  180. #endif
  181. /* ---- Internal ---- */
  182. #if defined (__APPLE__)
  183. #define FFI_TARGET_SPECIFIC_VARIADIC
  184. #define FFI_EXTRA_CIF_FIELDS unsigned aarch64_nfixedargs
  185. #elif !defined(_M_ARM64)
  186. /* iOS and Windows reserve x18 for the system. Disable Go closures until
  187. a new static chain is chosen. */
  188. #define FFI_GO_CLOSURES 1
  189. #endif
  190. #ifndef _M_ARM64
  191. /* No complex type on Windows */
  192. #define FFI_TARGET_HAS_COMPLEX_TYPE
  193. #endif
  194. #endif
  195. ====================File: .yandex_meta/files/configs/aarch64-apple-macos/include/ffitarget.h====================
  196. /* Copyright (c) 2009, 2010, 2011, 2012 ARM Ltd.
  197. Permission is hereby granted, free of charge, to any person obtaining
  198. a copy of this software and associated documentation files (the
  199. ``Software''), to deal in the Software without restriction, including
  200. without limitation the rights to use, copy, modify, merge, publish,
  201. distribute, sublicense, and/or sell copies of the Software, and to
  202. permit persons to whom the Software is furnished to do so, subject to
  203. the following conditions:
  204. The above copyright notice and this permission notice shall be
  205. included in all copies or substantial portions of the Software.
  206. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  207. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  208. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  209. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  210. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  211. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  212. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  213. #ifndef LIBFFI_TARGET_H
  214. #define LIBFFI_TARGET_H
  215. #ifndef LIBFFI_H
  216. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  217. #endif
  218. #ifndef LIBFFI_ASM
  219. #ifdef __ILP32__
  220. #define FFI_SIZEOF_ARG 8
  221. #define FFI_SIZEOF_JAVA_RAW 4
  222. typedef unsigned long long ffi_arg;
  223. typedef signed long long ffi_sarg;
  224. #elif defined(_M_ARM64)
  225. #define FFI_SIZEOF_ARG 8
  226. typedef unsigned long long ffi_arg;
  227. typedef signed long long ffi_sarg;
  228. #else
  229. typedef unsigned long ffi_arg;
  230. typedef signed long ffi_sarg;
  231. #endif
  232. typedef enum ffi_abi
  233. {
  234. FFI_FIRST_ABI = 0,
  235. FFI_SYSV,
  236. FFI_LAST_ABI,
  237. FFI_DEFAULT_ABI = FFI_SYSV
  238. } ffi_abi;
  239. #endif
  240. /* ---- Definitions for closures ----------------------------------------- */
  241. #define FFI_CLOSURES 1
  242. #define FFI_NATIVE_RAW_API 0
  243. #if defined (FFI_EXEC_TRAMPOLINE_TABLE) && FFI_EXEC_TRAMPOLINE_TABLE
  244. #ifdef __MACH__
  245. #define FFI_TRAMPOLINE_SIZE 16
  246. #define FFI_TRAMPOLINE_CLOSURE_OFFSET 16
  247. #else
  248. #error "No trampoline table implementation"
  249. #endif
  250. #else
  251. #define FFI_TRAMPOLINE_SIZE 24
  252. #define FFI_TRAMPOLINE_CLOSURE_OFFSET FFI_TRAMPOLINE_SIZE
  253. #endif
  254. #ifdef _M_ARM64
  255. #define FFI_EXTRA_CIF_FIELDS unsigned is_variadic
  256. #endif
  257. /* ---- Internal ---- */
  258. #if defined (__APPLE__)
  259. #define FFI_TARGET_SPECIFIC_VARIADIC
  260. #define FFI_EXTRA_CIF_FIELDS unsigned aarch64_nfixedargs
  261. #elif !defined(_M_ARM64)
  262. /* iOS and Windows reserve x18 for the system. Disable Go closures until
  263. a new static chain is chosen. */
  264. #define FFI_GO_CLOSURES 1
  265. #endif
  266. #ifndef _M_ARM64
  267. /* No complex type on Windows */
  268. #define FFI_TARGET_HAS_COMPLEX_TYPE
  269. #endif
  270. #endif
  271. ====================File: .yandex_meta/files/configs/aarch64-unknown-linux-android21/include/ffitarget.h====================
  272. /* Copyright (c) 2009, 2010, 2011, 2012 ARM Ltd.
  273. Permission is hereby granted, free of charge, to any person obtaining
  274. a copy of this software and associated documentation files (the
  275. ``Software''), to deal in the Software without restriction, including
  276. without limitation the rights to use, copy, modify, merge, publish,
  277. distribute, sublicense, and/or sell copies of the Software, and to
  278. permit persons to whom the Software is furnished to do so, subject to
  279. the following conditions:
  280. The above copyright notice and this permission notice shall be
  281. included in all copies or substantial portions of the Software.
  282. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  283. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  284. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  285. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  286. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  287. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  288. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  289. #ifndef LIBFFI_TARGET_H
  290. #define LIBFFI_TARGET_H
  291. #ifndef LIBFFI_H
  292. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  293. #endif
  294. #ifndef LIBFFI_ASM
  295. #ifdef __ILP32__
  296. #define FFI_SIZEOF_ARG 8
  297. #define FFI_SIZEOF_JAVA_RAW 4
  298. typedef unsigned long long ffi_arg;
  299. typedef signed long long ffi_sarg;
  300. #elif defined(_M_ARM64)
  301. #define FFI_SIZEOF_ARG 8
  302. typedef unsigned long long ffi_arg;
  303. typedef signed long long ffi_sarg;
  304. #else
  305. typedef unsigned long ffi_arg;
  306. typedef signed long ffi_sarg;
  307. #endif
  308. typedef enum ffi_abi
  309. {
  310. FFI_FIRST_ABI = 0,
  311. FFI_SYSV,
  312. FFI_LAST_ABI,
  313. FFI_DEFAULT_ABI = FFI_SYSV
  314. } ffi_abi;
  315. #endif
  316. /* ---- Definitions for closures ----------------------------------------- */
  317. #define FFI_CLOSURES 1
  318. #define FFI_NATIVE_RAW_API 0
  319. #if defined (FFI_EXEC_TRAMPOLINE_TABLE) && FFI_EXEC_TRAMPOLINE_TABLE
  320. #ifdef __MACH__
  321. #define FFI_TRAMPOLINE_SIZE 16
  322. #define FFI_TRAMPOLINE_CLOSURE_OFFSET 16
  323. #else
  324. #error "No trampoline table implementation"
  325. #endif
  326. #else
  327. #define FFI_TRAMPOLINE_SIZE 24
  328. #define FFI_TRAMPOLINE_CLOSURE_OFFSET FFI_TRAMPOLINE_SIZE
  329. #endif
  330. #ifdef _M_ARM64
  331. #define FFI_EXTRA_CIF_FIELDS unsigned is_variadic
  332. #endif
  333. /* ---- Internal ---- */
  334. #if defined (__APPLE__)
  335. #define FFI_TARGET_SPECIFIC_VARIADIC
  336. #define FFI_EXTRA_CIF_FIELDS unsigned aarch64_nfixedargs
  337. #elif !defined(_M_ARM64)
  338. /* iOS and Windows reserve x18 for the system. Disable Go closures until
  339. a new static chain is chosen. */
  340. #define FFI_GO_CLOSURES 1
  341. #endif
  342. #ifndef _M_ARM64
  343. /* No complex type on Windows */
  344. #define FFI_TARGET_HAS_COMPLEX_TYPE
  345. #endif
  346. #endif
  347. ====================File: .yandex_meta/files/configs/aarch64-unknown-linux-gnu/include/ffitarget.h====================
  348. /* Copyright (c) 2009, 2010, 2011, 2012 ARM Ltd.
  349. Permission is hereby granted, free of charge, to any person obtaining
  350. a copy of this software and associated documentation files (the
  351. ``Software''), to deal in the Software without restriction, including
  352. without limitation the rights to use, copy, modify, merge, publish,
  353. distribute, sublicense, and/or sell copies of the Software, and to
  354. permit persons to whom the Software is furnished to do so, subject to
  355. the following conditions:
  356. The above copyright notice and this permission notice shall be
  357. included in all copies or substantial portions of the Software.
  358. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  359. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  360. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  361. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  362. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  363. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  364. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  365. #ifndef LIBFFI_TARGET_H
  366. #define LIBFFI_TARGET_H
  367. #ifndef LIBFFI_H
  368. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  369. #endif
  370. #ifndef LIBFFI_ASM
  371. #ifdef __ILP32__
  372. #define FFI_SIZEOF_ARG 8
  373. #define FFI_SIZEOF_JAVA_RAW 4
  374. typedef unsigned long long ffi_arg;
  375. typedef signed long long ffi_sarg;
  376. #elif defined(_M_ARM64)
  377. #define FFI_SIZEOF_ARG 8
  378. typedef unsigned long long ffi_arg;
  379. typedef signed long long ffi_sarg;
  380. #else
  381. typedef unsigned long ffi_arg;
  382. typedef signed long ffi_sarg;
  383. #endif
  384. typedef enum ffi_abi
  385. {
  386. FFI_FIRST_ABI = 0,
  387. FFI_SYSV,
  388. FFI_LAST_ABI,
  389. FFI_DEFAULT_ABI = FFI_SYSV
  390. } ffi_abi;
  391. #endif
  392. /* ---- Definitions for closures ----------------------------------------- */
  393. #define FFI_CLOSURES 1
  394. #define FFI_NATIVE_RAW_API 0
  395. #if defined (FFI_EXEC_TRAMPOLINE_TABLE) && FFI_EXEC_TRAMPOLINE_TABLE
  396. #ifdef __MACH__
  397. #define FFI_TRAMPOLINE_SIZE 16
  398. #define FFI_TRAMPOLINE_CLOSURE_OFFSET 16
  399. #else
  400. #error "No trampoline table implementation"
  401. #endif
  402. #else
  403. #define FFI_TRAMPOLINE_SIZE 24
  404. #define FFI_TRAMPOLINE_CLOSURE_OFFSET FFI_TRAMPOLINE_SIZE
  405. #endif
  406. #ifdef _M_ARM64
  407. #define FFI_EXTRA_CIF_FIELDS unsigned is_variadic
  408. #endif
  409. /* ---- Internal ---- */
  410. #if defined (__APPLE__)
  411. #define FFI_TARGET_SPECIFIC_VARIADIC
  412. #define FFI_EXTRA_CIF_FIELDS unsigned aarch64_nfixedargs
  413. #elif !defined(_M_ARM64)
  414. /* iOS and Windows reserve x18 for the system. Disable Go closures until
  415. a new static chain is chosen. */
  416. #define FFI_GO_CLOSURES 1
  417. #endif
  418. #ifndef _M_ARM64
  419. /* No complex type on Windows */
  420. #define FFI_TARGET_HAS_COMPLEX_TYPE
  421. #endif
  422. #endif
  423. ====================File: .yandex_meta/files/configs/armv7a-unknown-linux-androideabi16/include/ffitarget.h====================
  424. /* -----------------------------------------------------------------*-C-*-
  425. ffitarget.h - Copyright (c) 2012 Anthony Green
  426. Copyright (c) 2010 CodeSourcery
  427. Copyright (c) 1996-2003 Red Hat, Inc.
  428. Target configuration macros for ARM.
  429. Permission is hereby granted, free of charge, to any person obtaining
  430. a copy of this software and associated documentation files (the
  431. ``Software''), to deal in the Software without restriction, including
  432. without limitation the rights to use, copy, modify, merge, publish,
  433. distribute, sublicense, and/or sell copies of the Software, and to
  434. permit persons to whom the Software is furnished to do so, subject to
  435. the following conditions:
  436. The above copyright notice and this permission notice shall be included
  437. in all copies or substantial portions of the Software.
  438. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  439. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  440. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  441. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  442. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  443. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  444. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  445. DEALINGS IN THE SOFTWARE.
  446. ----------------------------------------------------------------------- */
  447. #ifndef LIBFFI_TARGET_H
  448. #define LIBFFI_TARGET_H
  449. #ifndef LIBFFI_H
  450. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  451. #endif
  452. #ifndef LIBFFI_ASM
  453. typedef unsigned long ffi_arg;
  454. typedef signed long ffi_sarg;
  455. typedef enum ffi_abi {
  456. FFI_FIRST_ABI = 0,
  457. FFI_SYSV,
  458. FFI_VFP,
  459. FFI_LAST_ABI,
  460. #if defined(__ARM_PCS_VFP) || defined(_M_ARM)
  461. FFI_DEFAULT_ABI = FFI_VFP,
  462. #else
  463. FFI_DEFAULT_ABI = FFI_SYSV,
  464. #endif
  465. } ffi_abi;
  466. #endif
  467. #define FFI_EXTRA_CIF_FIELDS \
  468. int vfp_used; \
  469. unsigned short vfp_reg_free, vfp_nargs; \
  470. signed char vfp_args[16] \
  471. #define FFI_TARGET_SPECIFIC_VARIADIC
  472. #ifndef _M_ARM
  473. #define FFI_TARGET_HAS_COMPLEX_TYPE
  474. #endif
  475. /* ---- Definitions for closures ----------------------------------------- */
  476. #define FFI_CLOSURES 1
  477. #define FFI_GO_CLOSURES 1
  478. #define FFI_NATIVE_RAW_API 0
  479. #if defined (FFI_EXEC_TRAMPOLINE_TABLE) && FFI_EXEC_TRAMPOLINE_TABLE
  480. #ifdef __MACH__
  481. #define FFI_TRAMPOLINE_SIZE 12
  482. #define FFI_TRAMPOLINE_CLOSURE_OFFSET 8
  483. #else
  484. #error "No trampoline table implementation"
  485. #endif
  486. #else
  487. #ifdef _MSC_VER
  488. #define FFI_TRAMPOLINE_SIZE 16
  489. #define FFI_TRAMPOLINE_CLOSURE_FUNCTION 12
  490. #else
  491. #define FFI_TRAMPOLINE_SIZE 12
  492. #endif
  493. #define FFI_TRAMPOLINE_CLOSURE_OFFSET FFI_TRAMPOLINE_SIZE
  494. #endif
  495. #endif
  496. ====================File: .yandex_meta/files/configs/armv7a-unknown-linux-gnueabihf/include/ffitarget.h====================
  497. /* -----------------------------------------------------------------*-C-*-
  498. ffitarget.h - Copyright (c) 2012 Anthony Green
  499. Copyright (c) 2010 CodeSourcery
  500. Copyright (c) 1996-2003 Red Hat, Inc.
  501. Target configuration macros for ARM.
  502. Permission is hereby granted, free of charge, to any person obtaining
  503. a copy of this software and associated documentation files (the
  504. ``Software''), to deal in the Software without restriction, including
  505. without limitation the rights to use, copy, modify, merge, publish,
  506. distribute, sublicense, and/or sell copies of the Software, and to
  507. permit persons to whom the Software is furnished to do so, subject to
  508. the following conditions:
  509. The above copyright notice and this permission notice shall be included
  510. in all copies or substantial portions of the Software.
  511. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  512. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  513. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  514. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  515. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  516. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  517. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  518. DEALINGS IN THE SOFTWARE.
  519. ----------------------------------------------------------------------- */
  520. #ifndef LIBFFI_TARGET_H
  521. #define LIBFFI_TARGET_H
  522. #ifndef LIBFFI_H
  523. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  524. #endif
  525. #ifndef LIBFFI_ASM
  526. typedef unsigned long ffi_arg;
  527. typedef signed long ffi_sarg;
  528. typedef enum ffi_abi {
  529. FFI_FIRST_ABI = 0,
  530. FFI_SYSV,
  531. FFI_VFP,
  532. FFI_LAST_ABI,
  533. #if defined(__ARM_PCS_VFP) || defined(_M_ARM)
  534. FFI_DEFAULT_ABI = FFI_VFP,
  535. #else
  536. FFI_DEFAULT_ABI = FFI_SYSV,
  537. #endif
  538. } ffi_abi;
  539. #endif
  540. #define FFI_EXTRA_CIF_FIELDS \
  541. int vfp_used; \
  542. unsigned short vfp_reg_free, vfp_nargs; \
  543. signed char vfp_args[16] \
  544. #define FFI_TARGET_SPECIFIC_VARIADIC
  545. #ifndef _M_ARM
  546. #define FFI_TARGET_HAS_COMPLEX_TYPE
  547. #endif
  548. /* ---- Definitions for closures ----------------------------------------- */
  549. #define FFI_CLOSURES 1
  550. #define FFI_GO_CLOSURES 1
  551. #define FFI_NATIVE_RAW_API 0
  552. #if defined (FFI_EXEC_TRAMPOLINE_TABLE) && FFI_EXEC_TRAMPOLINE_TABLE
  553. #ifdef __MACH__
  554. #define FFI_TRAMPOLINE_SIZE 12
  555. #define FFI_TRAMPOLINE_CLOSURE_OFFSET 8
  556. #else
  557. #error "No trampoline table implementation"
  558. #endif
  559. #else
  560. #ifdef _MSC_VER
  561. #define FFI_TRAMPOLINE_SIZE 16
  562. #define FFI_TRAMPOLINE_CLOSURE_FUNCTION 12
  563. #else
  564. #define FFI_TRAMPOLINE_SIZE 12
  565. #endif
  566. #define FFI_TRAMPOLINE_CLOSURE_OFFSET FFI_TRAMPOLINE_SIZE
  567. #endif
  568. #endif
  569. ====================File: .yandex_meta/files/configs/i386-microsoft-windows/include/ffitarget.h====================
  570. /* -----------------------------------------------------------------*-C-*-
  571. ffitarget.h - Copyright (c) 2012, 2014, 2018 Anthony Green
  572. Copyright (c) 1996-2003, 2010 Red Hat, Inc.
  573. Copyright (C) 2008 Free Software Foundation, Inc.
  574. Target configuration macros for x86 and x86-64.
  575. Permission is hereby granted, free of charge, to any person obtaining
  576. a copy of this software and associated documentation files (the
  577. ``Software''), to deal in the Software without restriction, including
  578. without limitation the rights to use, copy, modify, merge, publish,
  579. distribute, sublicense, and/or sell copies of the Software, and to
  580. permit persons to whom the Software is furnished to do so, subject to
  581. the following conditions:
  582. The above copyright notice and this permission notice shall be included
  583. in all copies or substantial portions of the Software.
  584. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  585. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  586. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  587. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  588. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  589. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  590. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  591. DEALINGS IN THE SOFTWARE.
  592. ----------------------------------------------------------------------- */
  593. #ifndef LIBFFI_TARGET_H
  594. #define LIBFFI_TARGET_H
  595. #ifndef LIBFFI_H
  596. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  597. #endif
  598. /* ---- System specific configurations ----------------------------------- */
  599. /* For code common to all platforms on x86 and x86_64. */
  600. #define X86_ANY
  601. #if defined (X86_64) && defined (__i386__)
  602. #undef X86_64
  603. #define X86
  604. #endif
  605. #ifdef X86_WIN64
  606. #define FFI_SIZEOF_ARG 8
  607. #define USE_BUILTIN_FFS 0 /* not yet implemented in mingw-64 */
  608. #endif
  609. #define FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION
  610. #ifndef _MSC_VER
  611. #define FFI_TARGET_HAS_COMPLEX_TYPE
  612. #endif
  613. /* ---- Generic type definitions ----------------------------------------- */
  614. #ifndef LIBFFI_ASM
  615. #ifdef X86_WIN64
  616. #ifdef _MSC_VER
  617. typedef unsigned __int64 ffi_arg;
  618. typedef __int64 ffi_sarg;
  619. #else
  620. typedef unsigned long long ffi_arg;
  621. typedef long long ffi_sarg;
  622. #endif
  623. #else
  624. #if defined __x86_64__ && defined __ILP32__
  625. #define FFI_SIZEOF_ARG 8
  626. #define FFI_SIZEOF_JAVA_RAW 4
  627. typedef unsigned long long ffi_arg;
  628. typedef long long ffi_sarg;
  629. #else
  630. typedef unsigned long ffi_arg;
  631. typedef signed long ffi_sarg;
  632. #endif
  633. #endif
  634. typedef enum ffi_abi {
  635. #if defined(X86_WIN64)
  636. FFI_FIRST_ABI = 0,
  637. FFI_WIN64, /* sizeof(long double) == 8 - microsoft compilers */
  638. FFI_GNUW64, /* sizeof(long double) == 16 - GNU compilers */
  639. FFI_LAST_ABI,
  640. #ifdef __GNUC__
  641. FFI_DEFAULT_ABI = FFI_GNUW64
  642. #else
  643. FFI_DEFAULT_ABI = FFI_WIN64
  644. #endif
  645. #elif defined(X86_64) || (defined (__x86_64__) && defined (X86_DARWIN))
  646. FFI_FIRST_ABI = 1,
  647. FFI_UNIX64,
  648. FFI_WIN64,
  649. FFI_EFI64 = FFI_WIN64,
  650. FFI_GNUW64,
  651. FFI_LAST_ABI,
  652. FFI_DEFAULT_ABI = FFI_UNIX64
  653. #elif defined(X86_WIN32)
  654. FFI_FIRST_ABI = 0,
  655. FFI_SYSV = 1,
  656. FFI_STDCALL = 2,
  657. FFI_THISCALL = 3,
  658. FFI_FASTCALL = 4,
  659. FFI_MS_CDECL = 5,
  660. FFI_PASCAL = 6,
  661. FFI_REGISTER = 7,
  662. FFI_LAST_ABI,
  663. FFI_DEFAULT_ABI = FFI_MS_CDECL
  664. #else
  665. FFI_FIRST_ABI = 0,
  666. FFI_SYSV = 1,
  667. FFI_THISCALL = 3,
  668. FFI_FASTCALL = 4,
  669. FFI_STDCALL = 5,
  670. FFI_PASCAL = 6,
  671. FFI_REGISTER = 7,
  672. FFI_MS_CDECL = 8,
  673. FFI_LAST_ABI,
  674. FFI_DEFAULT_ABI = FFI_SYSV
  675. #endif
  676. } ffi_abi;
  677. #endif
  678. /* ---- Definitions for closures ----------------------------------------- */
  679. #define FFI_CLOSURES 1
  680. #define FFI_GO_CLOSURES 1
  681. #define FFI_TYPE_SMALL_STRUCT_1B (FFI_TYPE_LAST + 1)
  682. #define FFI_TYPE_SMALL_STRUCT_2B (FFI_TYPE_LAST + 2)
  683. #define FFI_TYPE_SMALL_STRUCT_4B (FFI_TYPE_LAST + 3)
  684. #define FFI_TYPE_MS_STRUCT (FFI_TYPE_LAST + 4)
  685. #if defined (X86_64) || defined(X86_WIN64) \
  686. || (defined (__x86_64__) && defined (X86_DARWIN))
  687. /* 4 bytes of ENDBR64 + 7 bytes of LEA + 6 bytes of JMP + 7 bytes of NOP
  688. + 8 bytes of pointer. */
  689. # define FFI_TRAMPOLINE_SIZE 32
  690. # define FFI_NATIVE_RAW_API 0
  691. #else
  692. /* 4 bytes of ENDBR32 + 5 bytes of MOV + 5 bytes of JMP + 2 unused
  693. bytes. */
  694. # define FFI_TRAMPOLINE_SIZE 16
  695. # define FFI_NATIVE_RAW_API 1 /* x86 has native raw api support */
  696. #endif
  697. #if !defined(GENERATE_LIBFFI_MAP) && defined(__ASSEMBLER__) \
  698. && defined(__CET__)
  699. # include <cet.h>
  700. # define _CET_NOTRACK notrack
  701. #else
  702. # define _CET_ENDBR
  703. # define _CET_NOTRACK
  704. #endif
  705. #endif
  706. ====================File: .yandex_meta/files/configs/i686-pc-linux-android16/include/ffitarget.h====================
  707. /* -----------------------------------------------------------------*-C-*-
  708. ffitarget.h - Copyright (c) 2012, 2014, 2018 Anthony Green
  709. Copyright (c) 1996-2003, 2010 Red Hat, Inc.
  710. Copyright (C) 2008 Free Software Foundation, Inc.
  711. Target configuration macros for x86 and x86-64.
  712. Permission is hereby granted, free of charge, to any person obtaining
  713. a copy of this software and associated documentation files (the
  714. ``Software''), to deal in the Software without restriction, including
  715. without limitation the rights to use, copy, modify, merge, publish,
  716. distribute, sublicense, and/or sell copies of the Software, and to
  717. permit persons to whom the Software is furnished to do so, subject to
  718. the following conditions:
  719. The above copyright notice and this permission notice shall be included
  720. in all copies or substantial portions of the Software.
  721. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  722. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  723. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  724. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  725. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  726. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  727. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  728. DEALINGS IN THE SOFTWARE.
  729. ----------------------------------------------------------------------- */
  730. #ifndef LIBFFI_TARGET_H
  731. #define LIBFFI_TARGET_H
  732. #ifndef LIBFFI_H
  733. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  734. #endif
  735. /* ---- System specific configurations ----------------------------------- */
  736. /* For code common to all platforms on x86 and x86_64. */
  737. #define X86_ANY
  738. #if defined (X86_64) && defined (__i386__)
  739. #undef X86_64
  740. #define X86
  741. #endif
  742. #ifdef X86_WIN64
  743. #define FFI_SIZEOF_ARG 8
  744. #define USE_BUILTIN_FFS 0 /* not yet implemented in mingw-64 */
  745. #endif
  746. #define FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION
  747. #ifndef _MSC_VER
  748. #define FFI_TARGET_HAS_COMPLEX_TYPE
  749. #endif
  750. /* ---- Generic type definitions ----------------------------------------- */
  751. #ifndef LIBFFI_ASM
  752. #ifdef X86_WIN64
  753. #ifdef _MSC_VER
  754. typedef unsigned __int64 ffi_arg;
  755. typedef __int64 ffi_sarg;
  756. #else
  757. typedef unsigned long long ffi_arg;
  758. typedef long long ffi_sarg;
  759. #endif
  760. #else
  761. #if defined __x86_64__ && defined __ILP32__
  762. #define FFI_SIZEOF_ARG 8
  763. #define FFI_SIZEOF_JAVA_RAW 4
  764. typedef unsigned long long ffi_arg;
  765. typedef long long ffi_sarg;
  766. #else
  767. typedef unsigned long ffi_arg;
  768. typedef signed long ffi_sarg;
  769. #endif
  770. #endif
  771. typedef enum ffi_abi {
  772. #if defined(X86_WIN64)
  773. FFI_FIRST_ABI = 0,
  774. FFI_WIN64, /* sizeof(long double) == 8 - microsoft compilers */
  775. FFI_GNUW64, /* sizeof(long double) == 16 - GNU compilers */
  776. FFI_LAST_ABI,
  777. #ifdef __GNUC__
  778. FFI_DEFAULT_ABI = FFI_GNUW64
  779. #else
  780. FFI_DEFAULT_ABI = FFI_WIN64
  781. #endif
  782. #elif defined(X86_64) || (defined (__x86_64__) && defined (X86_DARWIN))
  783. FFI_FIRST_ABI = 1,
  784. FFI_UNIX64,
  785. FFI_WIN64,
  786. FFI_EFI64 = FFI_WIN64,
  787. FFI_GNUW64,
  788. FFI_LAST_ABI,
  789. FFI_DEFAULT_ABI = FFI_UNIX64
  790. #elif defined(X86_WIN32)
  791. FFI_FIRST_ABI = 0,
  792. FFI_SYSV = 1,
  793. FFI_STDCALL = 2,
  794. FFI_THISCALL = 3,
  795. FFI_FASTCALL = 4,
  796. FFI_MS_CDECL = 5,
  797. FFI_PASCAL = 6,
  798. FFI_REGISTER = 7,
  799. FFI_LAST_ABI,
  800. FFI_DEFAULT_ABI = FFI_MS_CDECL
  801. #else
  802. FFI_FIRST_ABI = 0,
  803. FFI_SYSV = 1,
  804. FFI_THISCALL = 3,
  805. FFI_FASTCALL = 4,
  806. FFI_STDCALL = 5,
  807. FFI_PASCAL = 6,
  808. FFI_REGISTER = 7,
  809. FFI_MS_CDECL = 8,
  810. FFI_LAST_ABI,
  811. FFI_DEFAULT_ABI = FFI_SYSV
  812. #endif
  813. } ffi_abi;
  814. #endif
  815. /* ---- Definitions for closures ----------------------------------------- */
  816. #define FFI_CLOSURES 1
  817. #define FFI_GO_CLOSURES 1
  818. #define FFI_TYPE_SMALL_STRUCT_1B (FFI_TYPE_LAST + 1)
  819. #define FFI_TYPE_SMALL_STRUCT_2B (FFI_TYPE_LAST + 2)
  820. #define FFI_TYPE_SMALL_STRUCT_4B (FFI_TYPE_LAST + 3)
  821. #define FFI_TYPE_MS_STRUCT (FFI_TYPE_LAST + 4)
  822. #if defined (X86_64) || defined(X86_WIN64) \
  823. || (defined (__x86_64__) && defined (X86_DARWIN))
  824. # define FFI_TRAMPOLINE_SIZE 24
  825. # define FFI_NATIVE_RAW_API 0
  826. #else
  827. # define FFI_TRAMPOLINE_SIZE 12
  828. # define FFI_NATIVE_RAW_API 1 /* x86 has native raw api support */
  829. #endif
  830. #endif
  831. ====================File: .yandex_meta/files/configs/powerpc64le-unknown-linux-gnu/include/ffitarget.h====================
  832. /* -----------------------------------------------------------------*-C-*-
  833. ffitarget.h - Copyright (c) 2012 Anthony Green
  834. Copyright (C) 2007, 2008, 2010 Free Software Foundation, Inc
  835. Copyright (c) 1996-2003 Red Hat, Inc.
  836. Target configuration macros for PowerPC.
  837. Permission is hereby granted, free of charge, to any person obtaining
  838. a copy of this software and associated documentation files (the
  839. ``Software''), to deal in the Software without restriction, including
  840. without limitation the rights to use, copy, modify, merge, publish,
  841. distribute, sublicense, and/or sell copies of the Software, and to
  842. permit persons to whom the Software is furnished to do so, subject to
  843. the following conditions:
  844. The above copyright notice and this permission notice shall be included
  845. in all copies or substantial portions of the Software.
  846. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  847. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  848. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  849. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  850. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  851. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  852. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  853. DEALINGS IN THE SOFTWARE.
  854. ----------------------------------------------------------------------- */
  855. #ifndef LIBFFI_TARGET_H
  856. #define LIBFFI_TARGET_H
  857. #ifndef LIBFFI_H
  858. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  859. #endif
  860. /* ---- System specific configurations ----------------------------------- */
  861. #if defined (POWERPC) && defined (__powerpc64__) /* linux64 */
  862. #ifndef POWERPC64
  863. #define POWERPC64
  864. #endif
  865. #elif defined (POWERPC_DARWIN) && defined (__ppc64__) /* Darwin64 */
  866. #ifndef POWERPC64
  867. #define POWERPC64
  868. #endif
  869. #ifndef POWERPC_DARWIN64
  870. #define POWERPC_DARWIN64
  871. #endif
  872. #elif defined (POWERPC_AIX) && defined (__64BIT__) /* AIX64 */
  873. #ifndef POWERPC64
  874. #define POWERPC64
  875. #endif
  876. #endif
  877. #ifndef LIBFFI_ASM
  878. typedef unsigned long ffi_arg;
  879. typedef signed long ffi_sarg;
  880. typedef enum ffi_abi {
  881. FFI_FIRST_ABI = 0,
  882. #if defined (POWERPC_AIX)
  883. FFI_AIX,
  884. FFI_DARWIN,
  885. FFI_DEFAULT_ABI = FFI_AIX,
  886. FFI_LAST_ABI
  887. #elif defined (POWERPC_DARWIN)
  888. FFI_AIX,
  889. FFI_DARWIN,
  890. FFI_DEFAULT_ABI = FFI_DARWIN,
  891. FFI_LAST_ABI
  892. #else
  893. /* The FFI_COMPAT values are used by old code. Since libffi may be
  894. a shared library we have to support old values for backwards
  895. compatibility. */
  896. FFI_COMPAT_SYSV,
  897. FFI_COMPAT_GCC_SYSV,
  898. FFI_COMPAT_LINUX64,
  899. FFI_COMPAT_LINUX,
  900. FFI_COMPAT_LINUX_SOFT_FLOAT,
  901. # if defined (POWERPC64)
  902. /* This bit, always set in new code, must not be set in any of the
  903. old FFI_COMPAT values that might be used for 64-bit linux. We
  904. only need worry about FFI_COMPAT_LINUX64, but to be safe avoid
  905. all old values. */
  906. FFI_LINUX = 8,
  907. /* This and following bits can reuse FFI_COMPAT values. */
  908. FFI_LINUX_STRUCT_ALIGN = 1,
  909. FFI_LINUX_LONG_DOUBLE_128 = 2,
  910. FFI_LINUX_LONG_DOUBLE_IEEE128 = 4,
  911. FFI_DEFAULT_ABI = (FFI_LINUX
  912. # ifdef __STRUCT_PARM_ALIGN__
  913. | FFI_LINUX_STRUCT_ALIGN
  914. # endif
  915. # ifdef __LONG_DOUBLE_128__
  916. | FFI_LINUX_LONG_DOUBLE_128
  917. # ifdef __LONG_DOUBLE_IEEE128__
  918. | FFI_LINUX_LONG_DOUBLE_IEEE128
  919. # endif
  920. # endif
  921. ),
  922. FFI_LAST_ABI = 16
  923. # else
  924. /* This bit, always set in new code, must not be set in any of the
  925. old FFI_COMPAT values that might be used for 32-bit linux/sysv/bsd. */
  926. FFI_SYSV = 8,
  927. /* This and following bits can reuse FFI_COMPAT values. */
  928. FFI_SYSV_SOFT_FLOAT = 1,
  929. FFI_SYSV_STRUCT_RET = 2,
  930. FFI_SYSV_IBM_LONG_DOUBLE = 4,
  931. FFI_SYSV_LONG_DOUBLE_128 = 16,
  932. FFI_DEFAULT_ABI = (FFI_SYSV
  933. # ifdef __NO_FPRS__
  934. | FFI_SYSV_SOFT_FLOAT
  935. # endif
  936. # if (defined (__SVR4_STRUCT_RETURN) \
  937. || defined (POWERPC_FREEBSD) && !defined (__AIX_STRUCT_RETURN))
  938. | FFI_SYSV_STRUCT_RET
  939. # endif
  940. # if __LDBL_MANT_DIG__ == 106
  941. | FFI_SYSV_IBM_LONG_DOUBLE
  942. # endif
  943. # ifdef __LONG_DOUBLE_128__
  944. | FFI_SYSV_LONG_DOUBLE_128
  945. # endif
  946. ),
  947. FFI_LAST_ABI = 32
  948. # endif
  949. #endif
  950. } ffi_abi;
  951. #endif
  952. /* ---- Definitions for closures ----------------------------------------- */
  953. #define FFI_CLOSURES 1
  954. #define FFI_NATIVE_RAW_API 0
  955. #if defined (POWERPC) || defined (POWERPC_FREEBSD)
  956. # define FFI_GO_CLOSURES 1
  957. # define FFI_TARGET_SPECIFIC_VARIADIC 1
  958. # define FFI_EXTRA_CIF_FIELDS unsigned nfixedargs
  959. #endif
  960. #if defined (POWERPC_AIX)
  961. # define FFI_GO_CLOSURES 1
  962. #endif
  963. /* ppc_closure.S and linux64_closure.S expect this. */
  964. #define FFI_PPC_TYPE_LAST FFI_TYPE_POINTER
  965. /* We define additional types below. If generic types are added that
  966. must be supported by powerpc libffi then it is likely that
  967. FFI_PPC_TYPE_LAST needs increasing *and* the jump tables in
  968. ppc_closure.S and linux64_closure.S be extended. */
  969. #if !(FFI_TYPE_LAST == FFI_PPC_TYPE_LAST \
  970. || (FFI_TYPE_LAST == FFI_TYPE_COMPLEX \
  971. && !defined FFI_TARGET_HAS_COMPLEX_TYPE))
  972. # error "You likely have a broken powerpc libffi"
  973. #endif
  974. /* Needed for soft-float long-double-128 support. */
  975. #define FFI_TYPE_UINT128 (FFI_PPC_TYPE_LAST + 1)
  976. /* Needed for FFI_SYSV small structure returns. */
  977. #define FFI_SYSV_TYPE_SMALL_STRUCT (FFI_PPC_TYPE_LAST + 2)
  978. /* Used by ELFv2 for homogenous structure returns. */
  979. #define FFI_V2_TYPE_VECTOR (FFI_PPC_TYPE_LAST + 1)
  980. #define FFI_V2_TYPE_VECTOR_HOMOG (FFI_PPC_TYPE_LAST + 2)
  981. #define FFI_V2_TYPE_FLOAT_HOMOG (FFI_PPC_TYPE_LAST + 3)
  982. #define FFI_V2_TYPE_DOUBLE_HOMOG (FFI_PPC_TYPE_LAST + 4)
  983. #define FFI_V2_TYPE_SMALL_STRUCT (FFI_PPC_TYPE_LAST + 5)
  984. #if _CALL_ELF == 2
  985. # define FFI_TRAMPOLINE_SIZE 32
  986. #else
  987. # if defined(POWERPC64) || defined(POWERPC_AIX)
  988. # if defined(POWERPC_DARWIN64)
  989. # define FFI_TRAMPOLINE_SIZE 48
  990. # else
  991. # define FFI_TRAMPOLINE_SIZE 24
  992. # endif
  993. # else /* POWERPC || POWERPC_AIX */
  994. # define FFI_TRAMPOLINE_SIZE 40
  995. # endif
  996. #endif
  997. #ifndef LIBFFI_ASM
  998. #if defined(POWERPC_DARWIN) || defined(POWERPC_AIX)
  999. struct ffi_aix_trampoline_struct {
  1000. void * code_pointer; /* Pointer to ffi_closure_ASM */
  1001. void * toc; /* TOC */
  1002. void * static_chain; /* Pointer to closure */
  1003. };
  1004. #endif
  1005. #endif
  1006. #endif
  1007. ====================File: .yandex_meta/files/configs/x86_64-apple-iphonesimulator/include/ffitarget.h====================
  1008. /* -----------------------------------------------------------------*-C-*-
  1009. ffitarget.h - Copyright (c) 2012, 2014, 2018 Anthony Green
  1010. Copyright (c) 1996-2003, 2010 Red Hat, Inc.
  1011. Copyright (C) 2008 Free Software Foundation, Inc.
  1012. Target configuration macros for x86 and x86-64.
  1013. Permission is hereby granted, free of charge, to any person obtaining
  1014. a copy of this software and associated documentation files (the
  1015. ``Software''), to deal in the Software without restriction, including
  1016. without limitation the rights to use, copy, modify, merge, publish,
  1017. distribute, sublicense, and/or sell copies of the Software, and to
  1018. permit persons to whom the Software is furnished to do so, subject to
  1019. the following conditions:
  1020. The above copyright notice and this permission notice shall be included
  1021. in all copies or substantial portions of the Software.
  1022. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  1023. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1024. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  1025. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  1026. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  1027. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  1028. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  1029. DEALINGS IN THE SOFTWARE.
  1030. ----------------------------------------------------------------------- */
  1031. #ifndef LIBFFI_TARGET_H
  1032. #define LIBFFI_TARGET_H
  1033. #ifndef LIBFFI_H
  1034. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  1035. #endif
  1036. /* ---- System specific configurations ----------------------------------- */
  1037. /* For code common to all platforms on x86 and x86_64. */
  1038. #define X86_ANY
  1039. #if defined (X86_64) && defined (__i386__)
  1040. #undef X86_64
  1041. #define X86
  1042. #endif
  1043. #ifdef X86_WIN64
  1044. #define FFI_SIZEOF_ARG 8
  1045. #define USE_BUILTIN_FFS 0 /* not yet implemented in mingw-64 */
  1046. #endif
  1047. #define FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION
  1048. #ifndef _MSC_VER
  1049. #define FFI_TARGET_HAS_COMPLEX_TYPE
  1050. #endif
  1051. /* ---- Generic type definitions ----------------------------------------- */
  1052. #ifndef LIBFFI_ASM
  1053. #ifdef X86_WIN64
  1054. #ifdef _MSC_VER
  1055. typedef unsigned __int64 ffi_arg;
  1056. typedef __int64 ffi_sarg;
  1057. #else
  1058. typedef unsigned long long ffi_arg;
  1059. typedef long long ffi_sarg;
  1060. #endif
  1061. #else
  1062. #if defined __x86_64__ && defined __ILP32__
  1063. #define FFI_SIZEOF_ARG 8
  1064. #define FFI_SIZEOF_JAVA_RAW 4
  1065. typedef unsigned long long ffi_arg;
  1066. typedef long long ffi_sarg;
  1067. #else
  1068. typedef unsigned long ffi_arg;
  1069. typedef signed long ffi_sarg;
  1070. #endif
  1071. #endif
  1072. typedef enum ffi_abi {
  1073. #if defined(X86_WIN64)
  1074. FFI_FIRST_ABI = 0,
  1075. FFI_WIN64, /* sizeof(long double) == 8 - microsoft compilers */
  1076. FFI_GNUW64, /* sizeof(long double) == 16 - GNU compilers */
  1077. FFI_LAST_ABI,
  1078. #ifdef __GNUC__
  1079. FFI_DEFAULT_ABI = FFI_GNUW64
  1080. #else
  1081. FFI_DEFAULT_ABI = FFI_WIN64
  1082. #endif
  1083. #elif defined(X86_64) || (defined (__x86_64__) && defined (X86_DARWIN))
  1084. FFI_FIRST_ABI = 1,
  1085. FFI_UNIX64,
  1086. FFI_WIN64,
  1087. FFI_EFI64 = FFI_WIN64,
  1088. FFI_GNUW64,
  1089. FFI_LAST_ABI,
  1090. FFI_DEFAULT_ABI = FFI_UNIX64
  1091. #elif defined(X86_WIN32)
  1092. FFI_FIRST_ABI = 0,
  1093. FFI_SYSV = 1,
  1094. FFI_STDCALL = 2,
  1095. FFI_THISCALL = 3,
  1096. FFI_FASTCALL = 4,
  1097. FFI_MS_CDECL = 5,
  1098. FFI_PASCAL = 6,
  1099. FFI_REGISTER = 7,
  1100. FFI_LAST_ABI,
  1101. FFI_DEFAULT_ABI = FFI_MS_CDECL
  1102. #else
  1103. FFI_FIRST_ABI = 0,
  1104. FFI_SYSV = 1,
  1105. FFI_THISCALL = 3,
  1106. FFI_FASTCALL = 4,
  1107. FFI_STDCALL = 5,
  1108. FFI_PASCAL = 6,
  1109. FFI_REGISTER = 7,
  1110. FFI_MS_CDECL = 8,
  1111. FFI_LAST_ABI,
  1112. FFI_DEFAULT_ABI = FFI_SYSV
  1113. #endif
  1114. } ffi_abi;
  1115. #endif
  1116. /* ---- Definitions for closures ----------------------------------------- */
  1117. #define FFI_CLOSURES 1
  1118. #define FFI_GO_CLOSURES 1
  1119. #define FFI_TYPE_SMALL_STRUCT_1B (FFI_TYPE_LAST + 1)
  1120. #define FFI_TYPE_SMALL_STRUCT_2B (FFI_TYPE_LAST + 2)
  1121. #define FFI_TYPE_SMALL_STRUCT_4B (FFI_TYPE_LAST + 3)
  1122. #define FFI_TYPE_MS_STRUCT (FFI_TYPE_LAST + 4)
  1123. #if defined (X86_64) || defined(X86_WIN64) \
  1124. || (defined (__x86_64__) && defined (X86_DARWIN))
  1125. # define FFI_TRAMPOLINE_SIZE 24
  1126. # define FFI_NATIVE_RAW_API 0
  1127. #else
  1128. # define FFI_TRAMPOLINE_SIZE 12
  1129. # define FFI_NATIVE_RAW_API 1 /* x86 has native raw api support */
  1130. #endif
  1131. #endif
  1132. ====================File: .yandex_meta/files/configs/x86_64-apple-macosx/include/ffitarget.h====================
  1133. /* -----------------------------------------------------------------*-C-*-
  1134. ffitarget.h - Copyright (c) 2012, 2014, 2018 Anthony Green
  1135. Copyright (c) 1996-2003, 2010 Red Hat, Inc.
  1136. Copyright (C) 2008 Free Software Foundation, Inc.
  1137. Target configuration macros for x86 and x86-64.
  1138. Permission is hereby granted, free of charge, to any person obtaining
  1139. a copy of this software and associated documentation files (the
  1140. ``Software''), to deal in the Software without restriction, including
  1141. without limitation the rights to use, copy, modify, merge, publish,
  1142. distribute, sublicense, and/or sell copies of the Software, and to
  1143. permit persons to whom the Software is furnished to do so, subject to
  1144. the following conditions:
  1145. The above copyright notice and this permission notice shall be included
  1146. in all copies or substantial portions of the Software.
  1147. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  1148. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1149. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  1150. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  1151. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  1152. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  1153. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  1154. DEALINGS IN THE SOFTWARE.
  1155. ----------------------------------------------------------------------- */
  1156. #ifndef LIBFFI_TARGET_H
  1157. #define LIBFFI_TARGET_H
  1158. #ifndef LIBFFI_H
  1159. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  1160. #endif
  1161. /* ---- System specific configurations ----------------------------------- */
  1162. /* For code common to all platforms on x86 and x86_64. */
  1163. #define X86_ANY
  1164. #if defined (X86_64) && defined (__i386__)
  1165. #undef X86_64
  1166. #define X86
  1167. #endif
  1168. #ifdef X86_WIN64
  1169. #define FFI_SIZEOF_ARG 8
  1170. #define USE_BUILTIN_FFS 0 /* not yet implemented in mingw-64 */
  1171. #endif
  1172. #define FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION
  1173. #ifndef _MSC_VER
  1174. #define FFI_TARGET_HAS_COMPLEX_TYPE
  1175. #endif
  1176. /* ---- Generic type definitions ----------------------------------------- */
  1177. #ifndef LIBFFI_ASM
  1178. #ifdef X86_WIN64
  1179. #ifdef _MSC_VER
  1180. typedef unsigned __int64 ffi_arg;
  1181. typedef __int64 ffi_sarg;
  1182. #else
  1183. typedef unsigned long long ffi_arg;
  1184. typedef long long ffi_sarg;
  1185. #endif
  1186. #else
  1187. #if defined __x86_64__ && defined __ILP32__
  1188. #define FFI_SIZEOF_ARG 8
  1189. #define FFI_SIZEOF_JAVA_RAW 4
  1190. typedef unsigned long long ffi_arg;
  1191. typedef long long ffi_sarg;
  1192. #else
  1193. typedef unsigned long ffi_arg;
  1194. typedef signed long ffi_sarg;
  1195. #endif
  1196. #endif
  1197. typedef enum ffi_abi {
  1198. #if defined(X86_WIN64)
  1199. FFI_FIRST_ABI = 0,
  1200. FFI_WIN64, /* sizeof(long double) == 8 - microsoft compilers */
  1201. FFI_GNUW64, /* sizeof(long double) == 16 - GNU compilers */
  1202. FFI_LAST_ABI,
  1203. #ifdef __GNUC__
  1204. FFI_DEFAULT_ABI = FFI_GNUW64
  1205. #else
  1206. FFI_DEFAULT_ABI = FFI_WIN64
  1207. #endif
  1208. #elif defined(X86_64) || (defined (__x86_64__) && defined (X86_DARWIN))
  1209. FFI_FIRST_ABI = 1,
  1210. FFI_UNIX64,
  1211. FFI_WIN64,
  1212. FFI_EFI64 = FFI_WIN64,
  1213. FFI_GNUW64,
  1214. FFI_LAST_ABI,
  1215. FFI_DEFAULT_ABI = FFI_UNIX64
  1216. #elif defined(X86_WIN32)
  1217. FFI_FIRST_ABI = 0,
  1218. FFI_SYSV = 1,
  1219. FFI_STDCALL = 2,
  1220. FFI_THISCALL = 3,
  1221. FFI_FASTCALL = 4,
  1222. FFI_MS_CDECL = 5,
  1223. FFI_PASCAL = 6,
  1224. FFI_REGISTER = 7,
  1225. FFI_LAST_ABI,
  1226. FFI_DEFAULT_ABI = FFI_MS_CDECL
  1227. #else
  1228. FFI_FIRST_ABI = 0,
  1229. FFI_SYSV = 1,
  1230. FFI_THISCALL = 3,
  1231. FFI_FASTCALL = 4,
  1232. FFI_STDCALL = 5,
  1233. FFI_PASCAL = 6,
  1234. FFI_REGISTER = 7,
  1235. FFI_MS_CDECL = 8,
  1236. FFI_LAST_ABI,
  1237. FFI_DEFAULT_ABI = FFI_SYSV
  1238. #endif
  1239. } ffi_abi;
  1240. #endif
  1241. /* ---- Definitions for closures ----------------------------------------- */
  1242. #define FFI_CLOSURES 1
  1243. #define FFI_GO_CLOSURES 1
  1244. #define FFI_TYPE_SMALL_STRUCT_1B (FFI_TYPE_LAST + 1)
  1245. #define FFI_TYPE_SMALL_STRUCT_2B (FFI_TYPE_LAST + 2)
  1246. #define FFI_TYPE_SMALL_STRUCT_4B (FFI_TYPE_LAST + 3)
  1247. #define FFI_TYPE_MS_STRUCT (FFI_TYPE_LAST + 4)
  1248. #if defined (X86_64) || defined(X86_WIN64) \
  1249. || (defined (__x86_64__) && defined (X86_DARWIN))
  1250. # define FFI_TRAMPOLINE_SIZE 24
  1251. # define FFI_NATIVE_RAW_API 0
  1252. #else
  1253. # define FFI_TRAMPOLINE_SIZE 12
  1254. # define FFI_NATIVE_RAW_API 1 /* x86 has native raw api support */
  1255. #endif
  1256. #endif
  1257. ====================File: .yandex_meta/files/configs/x86_64-microsoft-windows/include/ffitarget.h====================
  1258. /* -----------------------------------------------------------------*-C-*-
  1259. ffitarget.h - Copyright (c) 2012, 2014, 2018 Anthony Green
  1260. Copyright (c) 1996-2003, 2010 Red Hat, Inc.
  1261. Copyright (C) 2008 Free Software Foundation, Inc.
  1262. Target configuration macros for x86 and x86-64.
  1263. Permission is hereby granted, free of charge, to any person obtaining
  1264. a copy of this software and associated documentation files (the
  1265. ``Software''), to deal in the Software without restriction, including
  1266. without limitation the rights to use, copy, modify, merge, publish,
  1267. distribute, sublicense, and/or sell copies of the Software, and to
  1268. permit persons to whom the Software is furnished to do so, subject to
  1269. the following conditions:
  1270. The above copyright notice and this permission notice shall be included
  1271. in all copies or substantial portions of the Software.
  1272. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  1273. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1274. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  1275. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  1276. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  1277. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  1278. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  1279. DEALINGS IN THE SOFTWARE.
  1280. ----------------------------------------------------------------------- */
  1281. #ifndef LIBFFI_TARGET_H
  1282. #define LIBFFI_TARGET_H
  1283. #ifndef LIBFFI_H
  1284. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  1285. #endif
  1286. /* ---- System specific configurations ----------------------------------- */
  1287. /* For code common to all platforms on x86 and x86_64. */
  1288. #define X86_ANY
  1289. #if defined (X86_64) && defined (__i386__)
  1290. #undef X86_64
  1291. #define X86
  1292. #endif
  1293. #ifdef X86_WIN64
  1294. #define FFI_SIZEOF_ARG 8
  1295. #define USE_BUILTIN_FFS 0 /* not yet implemented in mingw-64 */
  1296. #endif
  1297. #define FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION
  1298. #ifndef _MSC_VER
  1299. #define FFI_TARGET_HAS_COMPLEX_TYPE
  1300. #endif
  1301. /* ---- Generic type definitions ----------------------------------------- */
  1302. #ifndef LIBFFI_ASM
  1303. #ifdef X86_WIN64
  1304. #ifdef _MSC_VER
  1305. typedef unsigned __int64 ffi_arg;
  1306. typedef __int64 ffi_sarg;
  1307. #else
  1308. typedef unsigned long long ffi_arg;
  1309. typedef long long ffi_sarg;
  1310. #endif
  1311. #else
  1312. #if defined __x86_64__ && defined __ILP32__
  1313. #define FFI_SIZEOF_ARG 8
  1314. #define FFI_SIZEOF_JAVA_RAW 4
  1315. typedef unsigned long long ffi_arg;
  1316. typedef long long ffi_sarg;
  1317. #else
  1318. typedef unsigned long ffi_arg;
  1319. typedef signed long ffi_sarg;
  1320. #endif
  1321. #endif
  1322. typedef enum ffi_abi {
  1323. #if defined(X86_WIN64)
  1324. FFI_FIRST_ABI = 0,
  1325. FFI_WIN64, /* sizeof(long double) == 8 - microsoft compilers */
  1326. FFI_GNUW64, /* sizeof(long double) == 16 - GNU compilers */
  1327. FFI_LAST_ABI,
  1328. #ifdef __GNUC__
  1329. FFI_DEFAULT_ABI = FFI_GNUW64
  1330. #else
  1331. FFI_DEFAULT_ABI = FFI_WIN64
  1332. #endif
  1333. #elif defined(X86_64) || (defined (__x86_64__) && defined (X86_DARWIN))
  1334. FFI_FIRST_ABI = 1,
  1335. FFI_UNIX64,
  1336. FFI_WIN64,
  1337. FFI_EFI64 = FFI_WIN64,
  1338. FFI_GNUW64,
  1339. FFI_LAST_ABI,
  1340. FFI_DEFAULT_ABI = FFI_UNIX64
  1341. #elif defined(X86_WIN32)
  1342. FFI_FIRST_ABI = 0,
  1343. FFI_SYSV = 1,
  1344. FFI_STDCALL = 2,
  1345. FFI_THISCALL = 3,
  1346. FFI_FASTCALL = 4,
  1347. FFI_MS_CDECL = 5,
  1348. FFI_PASCAL = 6,
  1349. FFI_REGISTER = 7,
  1350. FFI_LAST_ABI,
  1351. FFI_DEFAULT_ABI = FFI_MS_CDECL
  1352. #else
  1353. FFI_FIRST_ABI = 0,
  1354. FFI_SYSV = 1,
  1355. FFI_THISCALL = 3,
  1356. FFI_FASTCALL = 4,
  1357. FFI_STDCALL = 5,
  1358. FFI_PASCAL = 6,
  1359. FFI_REGISTER = 7,
  1360. FFI_MS_CDECL = 8,
  1361. FFI_LAST_ABI,
  1362. FFI_DEFAULT_ABI = FFI_SYSV
  1363. #endif
  1364. } ffi_abi;
  1365. #endif
  1366. /* ---- Definitions for closures ----------------------------------------- */
  1367. #define FFI_CLOSURES 1
  1368. #define FFI_GO_CLOSURES 1
  1369. #define FFI_TYPE_SMALL_STRUCT_1B (FFI_TYPE_LAST + 1)
  1370. #define FFI_TYPE_SMALL_STRUCT_2B (FFI_TYPE_LAST + 2)
  1371. #define FFI_TYPE_SMALL_STRUCT_4B (FFI_TYPE_LAST + 3)
  1372. #define FFI_TYPE_MS_STRUCT (FFI_TYPE_LAST + 4)
  1373. #if defined (X86_64) || defined(X86_WIN64) \
  1374. || (defined (__x86_64__) && defined (X86_DARWIN))
  1375. /* 4 bytes of ENDBR64 + 7 bytes of LEA + 6 bytes of JMP + 7 bytes of NOP
  1376. + 8 bytes of pointer. */
  1377. # define FFI_TRAMPOLINE_SIZE 32
  1378. # define FFI_NATIVE_RAW_API 0
  1379. #else
  1380. /* 4 bytes of ENDBR32 + 5 bytes of MOV + 5 bytes of JMP + 2 unused
  1381. bytes. */
  1382. # define FFI_TRAMPOLINE_SIZE 16
  1383. # define FFI_NATIVE_RAW_API 1 /* x86 has native raw api support */
  1384. #endif
  1385. #if !defined(GENERATE_LIBFFI_MAP) && defined(__ASSEMBLER__) \
  1386. && defined(__CET__)
  1387. # include <cet.h>
  1388. # define _CET_NOTRACK notrack
  1389. #else
  1390. # define _CET_ENDBR
  1391. # define _CET_NOTRACK
  1392. #endif
  1393. #endif
  1394. ====================File: .yandex_meta/files/configs/x86_64-pc-linux-android21/include/ffitarget.h====================
  1395. /* -----------------------------------------------------------------*-C-*-
  1396. ffitarget.h - Copyright (c) 2012, 2014, 2018 Anthony Green
  1397. Copyright (c) 1996-2003, 2010 Red Hat, Inc.
  1398. Copyright (C) 2008 Free Software Foundation, Inc.
  1399. Target configuration macros for x86 and x86-64.
  1400. Permission is hereby granted, free of charge, to any person obtaining
  1401. a copy of this software and associated documentation files (the
  1402. ``Software''), to deal in the Software without restriction, including
  1403. without limitation the rights to use, copy, modify, merge, publish,
  1404. distribute, sublicense, and/or sell copies of the Software, and to
  1405. permit persons to whom the Software is furnished to do so, subject to
  1406. the following conditions:
  1407. The above copyright notice and this permission notice shall be included
  1408. in all copies or substantial portions of the Software.
  1409. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  1410. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1411. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  1412. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  1413. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  1414. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  1415. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  1416. DEALINGS IN THE SOFTWARE.
  1417. ----------------------------------------------------------------------- */
  1418. #ifndef LIBFFI_TARGET_H
  1419. #define LIBFFI_TARGET_H
  1420. #ifndef LIBFFI_H
  1421. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  1422. #endif
  1423. /* ---- System specific configurations ----------------------------------- */
  1424. /* For code common to all platforms on x86 and x86_64. */
  1425. #define X86_ANY
  1426. #if defined (X86_64) && defined (__i386__)
  1427. #undef X86_64
  1428. #define X86
  1429. #endif
  1430. #ifdef X86_WIN64
  1431. #define FFI_SIZEOF_ARG 8
  1432. #define USE_BUILTIN_FFS 0 /* not yet implemented in mingw-64 */
  1433. #endif
  1434. #define FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION
  1435. #ifndef _MSC_VER
  1436. #define FFI_TARGET_HAS_COMPLEX_TYPE
  1437. #endif
  1438. /* ---- Generic type definitions ----------------------------------------- */
  1439. #ifndef LIBFFI_ASM
  1440. #ifdef X86_WIN64
  1441. #ifdef _MSC_VER
  1442. typedef unsigned __int64 ffi_arg;
  1443. typedef __int64 ffi_sarg;
  1444. #else
  1445. typedef unsigned long long ffi_arg;
  1446. typedef long long ffi_sarg;
  1447. #endif
  1448. #else
  1449. #if defined __x86_64__ && defined __ILP32__
  1450. #define FFI_SIZEOF_ARG 8
  1451. #define FFI_SIZEOF_JAVA_RAW 4
  1452. typedef unsigned long long ffi_arg;
  1453. typedef long long ffi_sarg;
  1454. #else
  1455. typedef unsigned long ffi_arg;
  1456. typedef signed long ffi_sarg;
  1457. #endif
  1458. #endif
  1459. typedef enum ffi_abi {
  1460. #if defined(X86_WIN64)
  1461. FFI_FIRST_ABI = 0,
  1462. FFI_WIN64, /* sizeof(long double) == 8 - microsoft compilers */
  1463. FFI_GNUW64, /* sizeof(long double) == 16 - GNU compilers */
  1464. FFI_LAST_ABI,
  1465. #ifdef __GNUC__
  1466. FFI_DEFAULT_ABI = FFI_GNUW64
  1467. #else
  1468. FFI_DEFAULT_ABI = FFI_WIN64
  1469. #endif
  1470. #elif defined(X86_64) || (defined (__x86_64__) && defined (X86_DARWIN))
  1471. FFI_FIRST_ABI = 1,
  1472. FFI_UNIX64,
  1473. FFI_WIN64,
  1474. FFI_EFI64 = FFI_WIN64,
  1475. FFI_GNUW64,
  1476. FFI_LAST_ABI,
  1477. FFI_DEFAULT_ABI = FFI_UNIX64
  1478. #elif defined(X86_WIN32)
  1479. FFI_FIRST_ABI = 0,
  1480. FFI_SYSV = 1,
  1481. FFI_STDCALL = 2,
  1482. FFI_THISCALL = 3,
  1483. FFI_FASTCALL = 4,
  1484. FFI_MS_CDECL = 5,
  1485. FFI_PASCAL = 6,
  1486. FFI_REGISTER = 7,
  1487. FFI_LAST_ABI,
  1488. FFI_DEFAULT_ABI = FFI_MS_CDECL
  1489. #else
  1490. FFI_FIRST_ABI = 0,
  1491. FFI_SYSV = 1,
  1492. FFI_THISCALL = 3,
  1493. FFI_FASTCALL = 4,
  1494. FFI_STDCALL = 5,
  1495. FFI_PASCAL = 6,
  1496. FFI_REGISTER = 7,
  1497. FFI_MS_CDECL = 8,
  1498. FFI_LAST_ABI,
  1499. FFI_DEFAULT_ABI = FFI_SYSV
  1500. #endif
  1501. } ffi_abi;
  1502. #endif
  1503. /* ---- Definitions for closures ----------------------------------------- */
  1504. #define FFI_CLOSURES 1
  1505. #define FFI_GO_CLOSURES 1
  1506. #define FFI_TYPE_SMALL_STRUCT_1B (FFI_TYPE_LAST + 1)
  1507. #define FFI_TYPE_SMALL_STRUCT_2B (FFI_TYPE_LAST + 2)
  1508. #define FFI_TYPE_SMALL_STRUCT_4B (FFI_TYPE_LAST + 3)
  1509. #define FFI_TYPE_MS_STRUCT (FFI_TYPE_LAST + 4)
  1510. #if defined (X86_64) || defined(X86_WIN64) \
  1511. || (defined (__x86_64__) && defined (X86_DARWIN))
  1512. # define FFI_TRAMPOLINE_SIZE 24
  1513. # define FFI_NATIVE_RAW_API 0
  1514. #else
  1515. # define FFI_TRAMPOLINE_SIZE 12
  1516. # define FFI_NATIVE_RAW_API 1 /* x86 has native raw api support */
  1517. #endif
  1518. #endif
  1519. ====================File: configs/aarch64-apple-iphoneos/include/ffitarget.h====================
  1520. /* Copyright (c) 2009, 2010, 2011, 2012 ARM Ltd.
  1521. Permission is hereby granted, free of charge, to any person obtaining
  1522. a copy of this software and associated documentation files (the
  1523. ``Software''), to deal in the Software without restriction, including
  1524. without limitation the rights to use, copy, modify, merge, publish,
  1525. distribute, sublicense, and/or sell copies of the Software, and to
  1526. permit persons to whom the Software is furnished to do so, subject to
  1527. the following conditions:
  1528. The above copyright notice and this permission notice shall be
  1529. included in all copies or substantial portions of the Software.
  1530. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  1531. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1532. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  1533. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  1534. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  1535. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  1536. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  1537. #ifndef LIBFFI_TARGET_H
  1538. #define LIBFFI_TARGET_H
  1539. #ifndef LIBFFI_H
  1540. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  1541. #endif
  1542. #ifndef LIBFFI_ASM
  1543. #ifdef __ILP32__
  1544. #define FFI_SIZEOF_ARG 8
  1545. #define FFI_SIZEOF_JAVA_RAW 4
  1546. typedef unsigned long long ffi_arg;
  1547. typedef signed long long ffi_sarg;
  1548. #elif defined(_M_ARM64)
  1549. #define FFI_SIZEOF_ARG 8
  1550. typedef unsigned long long ffi_arg;
  1551. typedef signed long long ffi_sarg;
  1552. #else
  1553. typedef unsigned long ffi_arg;
  1554. typedef signed long ffi_sarg;
  1555. #endif
  1556. typedef enum ffi_abi
  1557. {
  1558. FFI_FIRST_ABI = 0,
  1559. FFI_SYSV,
  1560. FFI_LAST_ABI,
  1561. FFI_DEFAULT_ABI = FFI_SYSV
  1562. } ffi_abi;
  1563. #endif
  1564. /* ---- Definitions for closures ----------------------------------------- */
  1565. #define FFI_CLOSURES 1
  1566. #define FFI_NATIVE_RAW_API 0
  1567. #if defined (FFI_EXEC_TRAMPOLINE_TABLE) && FFI_EXEC_TRAMPOLINE_TABLE
  1568. #ifdef __MACH__
  1569. #define FFI_TRAMPOLINE_SIZE 16
  1570. #define FFI_TRAMPOLINE_CLOSURE_OFFSET 16
  1571. #else
  1572. #error "No trampoline table implementation"
  1573. #endif
  1574. #else
  1575. #define FFI_TRAMPOLINE_SIZE 24
  1576. #define FFI_TRAMPOLINE_CLOSURE_OFFSET FFI_TRAMPOLINE_SIZE
  1577. #endif
  1578. #ifdef _M_ARM64
  1579. #define FFI_EXTRA_CIF_FIELDS unsigned is_variadic
  1580. #endif
  1581. /* ---- Internal ---- */
  1582. #if defined (__APPLE__)
  1583. #define FFI_TARGET_SPECIFIC_VARIADIC
  1584. #define FFI_EXTRA_CIF_FIELDS unsigned aarch64_nfixedargs
  1585. #elif !defined(_M_ARM64)
  1586. /* iOS and Windows reserve x18 for the system. Disable Go closures until
  1587. a new static chain is chosen. */
  1588. #define FFI_GO_CLOSURES 1
  1589. #endif
  1590. #ifndef _M_ARM64
  1591. /* No complex type on Windows */
  1592. #define FFI_TARGET_HAS_COMPLEX_TYPE
  1593. #endif
  1594. #endif
  1595. ====================File: configs/aarch64-apple-macos/include/ffitarget.h====================
  1596. /* Copyright (c) 2009, 2010, 2011, 2012 ARM Ltd.
  1597. Permission is hereby granted, free of charge, to any person obtaining
  1598. a copy of this software and associated documentation files (the
  1599. ``Software''), to deal in the Software without restriction, including
  1600. without limitation the rights to use, copy, modify, merge, publish,
  1601. distribute, sublicense, and/or sell copies of the Software, and to
  1602. permit persons to whom the Software is furnished to do so, subject to
  1603. the following conditions:
  1604. The above copyright notice and this permission notice shall be
  1605. included in all copies or substantial portions of the Software.
  1606. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  1607. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1608. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  1609. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  1610. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  1611. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  1612. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  1613. #ifndef LIBFFI_TARGET_H
  1614. #define LIBFFI_TARGET_H
  1615. #ifndef LIBFFI_H
  1616. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  1617. #endif
  1618. #ifndef LIBFFI_ASM
  1619. #ifdef __ILP32__
  1620. #define FFI_SIZEOF_ARG 8
  1621. #define FFI_SIZEOF_JAVA_RAW 4
  1622. typedef unsigned long long ffi_arg;
  1623. typedef signed long long ffi_sarg;
  1624. #elif defined(_M_ARM64)
  1625. #define FFI_SIZEOF_ARG 8
  1626. typedef unsigned long long ffi_arg;
  1627. typedef signed long long ffi_sarg;
  1628. #else
  1629. typedef unsigned long ffi_arg;
  1630. typedef signed long ffi_sarg;
  1631. #endif
  1632. typedef enum ffi_abi
  1633. {
  1634. FFI_FIRST_ABI = 0,
  1635. FFI_SYSV,
  1636. FFI_LAST_ABI,
  1637. FFI_DEFAULT_ABI = FFI_SYSV
  1638. } ffi_abi;
  1639. #endif
  1640. /* ---- Definitions for closures ----------------------------------------- */
  1641. #define FFI_CLOSURES 1
  1642. #define FFI_NATIVE_RAW_API 0
  1643. #if defined (FFI_EXEC_TRAMPOLINE_TABLE) && FFI_EXEC_TRAMPOLINE_TABLE
  1644. #ifdef __MACH__
  1645. #define FFI_TRAMPOLINE_SIZE 16
  1646. #define FFI_TRAMPOLINE_CLOSURE_OFFSET 16
  1647. #else
  1648. #error "No trampoline table implementation"
  1649. #endif
  1650. #else
  1651. #define FFI_TRAMPOLINE_SIZE 24
  1652. #define FFI_TRAMPOLINE_CLOSURE_OFFSET FFI_TRAMPOLINE_SIZE
  1653. #endif
  1654. #ifdef _M_ARM64
  1655. #define FFI_EXTRA_CIF_FIELDS unsigned is_variadic
  1656. #endif
  1657. /* ---- Internal ---- */
  1658. #if defined (__APPLE__)
  1659. #define FFI_TARGET_SPECIFIC_VARIADIC
  1660. #define FFI_EXTRA_CIF_FIELDS unsigned aarch64_nfixedargs
  1661. #elif !defined(_M_ARM64)
  1662. /* iOS and Windows reserve x18 for the system. Disable Go closures until
  1663. a new static chain is chosen. */
  1664. #define FFI_GO_CLOSURES 1
  1665. #endif
  1666. #ifndef _M_ARM64
  1667. /* No complex type on Windows */
  1668. #define FFI_TARGET_HAS_COMPLEX_TYPE
  1669. #endif
  1670. #endif
  1671. ====================File: configs/aarch64-unknown-linux-android21/include/ffitarget.h====================
  1672. /* Copyright (c) 2009, 2010, 2011, 2012 ARM Ltd.
  1673. Permission is hereby granted, free of charge, to any person obtaining
  1674. a copy of this software and associated documentation files (the
  1675. ``Software''), to deal in the Software without restriction, including
  1676. without limitation the rights to use, copy, modify, merge, publish,
  1677. distribute, sublicense, and/or sell copies of the Software, and to
  1678. permit persons to whom the Software is furnished to do so, subject to
  1679. the following conditions:
  1680. The above copyright notice and this permission notice shall be
  1681. included in all copies or substantial portions of the Software.
  1682. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  1683. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1684. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  1685. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  1686. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  1687. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  1688. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  1689. #ifndef LIBFFI_TARGET_H
  1690. #define LIBFFI_TARGET_H
  1691. #ifndef LIBFFI_H
  1692. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  1693. #endif
  1694. #ifndef LIBFFI_ASM
  1695. #ifdef __ILP32__
  1696. #define FFI_SIZEOF_ARG 8
  1697. #define FFI_SIZEOF_JAVA_RAW 4
  1698. typedef unsigned long long ffi_arg;
  1699. typedef signed long long ffi_sarg;
  1700. #elif defined(_M_ARM64)
  1701. #define FFI_SIZEOF_ARG 8
  1702. typedef unsigned long long ffi_arg;
  1703. typedef signed long long ffi_sarg;
  1704. #else
  1705. typedef unsigned long ffi_arg;
  1706. typedef signed long ffi_sarg;
  1707. #endif
  1708. typedef enum ffi_abi
  1709. {
  1710. FFI_FIRST_ABI = 0,
  1711. FFI_SYSV,
  1712. FFI_LAST_ABI,
  1713. FFI_DEFAULT_ABI = FFI_SYSV
  1714. } ffi_abi;
  1715. #endif
  1716. /* ---- Definitions for closures ----------------------------------------- */
  1717. #define FFI_CLOSURES 1
  1718. #define FFI_NATIVE_RAW_API 0
  1719. #if defined (FFI_EXEC_TRAMPOLINE_TABLE) && FFI_EXEC_TRAMPOLINE_TABLE
  1720. #ifdef __MACH__
  1721. #define FFI_TRAMPOLINE_SIZE 16
  1722. #define FFI_TRAMPOLINE_CLOSURE_OFFSET 16
  1723. #else
  1724. #error "No trampoline table implementation"
  1725. #endif
  1726. #else
  1727. #define FFI_TRAMPOLINE_SIZE 24
  1728. #define FFI_TRAMPOLINE_CLOSURE_OFFSET FFI_TRAMPOLINE_SIZE
  1729. #endif
  1730. #ifdef _M_ARM64
  1731. #define FFI_EXTRA_CIF_FIELDS unsigned is_variadic
  1732. #endif
  1733. /* ---- Internal ---- */
  1734. #if defined (__APPLE__)
  1735. #define FFI_TARGET_SPECIFIC_VARIADIC
  1736. #define FFI_EXTRA_CIF_FIELDS unsigned aarch64_nfixedargs
  1737. #elif !defined(_M_ARM64)
  1738. /* iOS and Windows reserve x18 for the system. Disable Go closures until
  1739. a new static chain is chosen. */
  1740. #define FFI_GO_CLOSURES 1
  1741. #endif
  1742. #ifndef _M_ARM64
  1743. /* No complex type on Windows */
  1744. #define FFI_TARGET_HAS_COMPLEX_TYPE
  1745. #endif
  1746. #endif
  1747. ====================File: configs/aarch64-unknown-linux-gnu/include/ffitarget.h====================
  1748. /* Copyright (c) 2009, 2010, 2011, 2012 ARM Ltd.
  1749. Permission is hereby granted, free of charge, to any person obtaining
  1750. a copy of this software and associated documentation files (the
  1751. ``Software''), to deal in the Software without restriction, including
  1752. without limitation the rights to use, copy, modify, merge, publish,
  1753. distribute, sublicense, and/or sell copies of the Software, and to
  1754. permit persons to whom the Software is furnished to do so, subject to
  1755. the following conditions:
  1756. The above copyright notice and this permission notice shall be
  1757. included in all copies or substantial portions of the Software.
  1758. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  1759. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1760. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  1761. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  1762. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  1763. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  1764. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  1765. #ifndef LIBFFI_TARGET_H
  1766. #define LIBFFI_TARGET_H
  1767. #ifndef LIBFFI_H
  1768. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  1769. #endif
  1770. #ifndef LIBFFI_ASM
  1771. #ifdef __ILP32__
  1772. #define FFI_SIZEOF_ARG 8
  1773. #define FFI_SIZEOF_JAVA_RAW 4
  1774. typedef unsigned long long ffi_arg;
  1775. typedef signed long long ffi_sarg;
  1776. #elif defined(_M_ARM64)
  1777. #define FFI_SIZEOF_ARG 8
  1778. typedef unsigned long long ffi_arg;
  1779. typedef signed long long ffi_sarg;
  1780. #else
  1781. typedef unsigned long ffi_arg;
  1782. typedef signed long ffi_sarg;
  1783. #endif
  1784. typedef enum ffi_abi
  1785. {
  1786. FFI_FIRST_ABI = 0,
  1787. FFI_SYSV,
  1788. FFI_LAST_ABI,
  1789. FFI_DEFAULT_ABI = FFI_SYSV
  1790. } ffi_abi;
  1791. #endif
  1792. /* ---- Definitions for closures ----------------------------------------- */
  1793. #define FFI_CLOSURES 1
  1794. #define FFI_NATIVE_RAW_API 0
  1795. #if defined (FFI_EXEC_TRAMPOLINE_TABLE) && FFI_EXEC_TRAMPOLINE_TABLE
  1796. #ifdef __MACH__
  1797. #define FFI_TRAMPOLINE_SIZE 16
  1798. #define FFI_TRAMPOLINE_CLOSURE_OFFSET 16
  1799. #else
  1800. #error "No trampoline table implementation"
  1801. #endif
  1802. #else
  1803. #define FFI_TRAMPOLINE_SIZE 24
  1804. #define FFI_TRAMPOLINE_CLOSURE_OFFSET FFI_TRAMPOLINE_SIZE
  1805. #endif
  1806. #ifdef _M_ARM64
  1807. #define FFI_EXTRA_CIF_FIELDS unsigned is_variadic
  1808. #endif
  1809. /* ---- Internal ---- */
  1810. #if defined (__APPLE__)
  1811. #define FFI_TARGET_SPECIFIC_VARIADIC
  1812. #define FFI_EXTRA_CIF_FIELDS unsigned aarch64_nfixedargs
  1813. #elif !defined(_M_ARM64)
  1814. /* iOS and Windows reserve x18 for the system. Disable Go closures until
  1815. a new static chain is chosen. */
  1816. #define FFI_GO_CLOSURES 1
  1817. #endif
  1818. #ifndef _M_ARM64
  1819. /* No complex type on Windows */
  1820. #define FFI_TARGET_HAS_COMPLEX_TYPE
  1821. #endif
  1822. #endif
  1823. ====================File: configs/armv7a-unknown-linux-androideabi16/include/ffitarget.h====================
  1824. /* -----------------------------------------------------------------*-C-*-
  1825. ffitarget.h - Copyright (c) 2012 Anthony Green
  1826. Copyright (c) 2010 CodeSourcery
  1827. Copyright (c) 1996-2003 Red Hat, Inc.
  1828. Target configuration macros for ARM.
  1829. Permission is hereby granted, free of charge, to any person obtaining
  1830. a copy of this software and associated documentation files (the
  1831. ``Software''), to deal in the Software without restriction, including
  1832. without limitation the rights to use, copy, modify, merge, publish,
  1833. distribute, sublicense, and/or sell copies of the Software, and to
  1834. permit persons to whom the Software is furnished to do so, subject to
  1835. the following conditions:
  1836. The above copyright notice and this permission notice shall be included
  1837. in all copies or substantial portions of the Software.
  1838. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  1839. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1840. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  1841. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  1842. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  1843. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  1844. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  1845. DEALINGS IN THE SOFTWARE.
  1846. ----------------------------------------------------------------------- */
  1847. #ifndef LIBFFI_TARGET_H
  1848. #define LIBFFI_TARGET_H
  1849. #ifndef LIBFFI_H
  1850. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  1851. #endif
  1852. #ifndef LIBFFI_ASM
  1853. typedef unsigned long ffi_arg;
  1854. typedef signed long ffi_sarg;
  1855. typedef enum ffi_abi {
  1856. FFI_FIRST_ABI = 0,
  1857. FFI_SYSV,
  1858. FFI_VFP,
  1859. FFI_LAST_ABI,
  1860. #if defined(__ARM_PCS_VFP) || defined(_M_ARM)
  1861. FFI_DEFAULT_ABI = FFI_VFP,
  1862. #else
  1863. FFI_DEFAULT_ABI = FFI_SYSV,
  1864. #endif
  1865. } ffi_abi;
  1866. #endif
  1867. #define FFI_EXTRA_CIF_FIELDS \
  1868. int vfp_used; \
  1869. unsigned short vfp_reg_free, vfp_nargs; \
  1870. signed char vfp_args[16] \
  1871. #define FFI_TARGET_SPECIFIC_VARIADIC
  1872. #ifndef _M_ARM
  1873. #define FFI_TARGET_HAS_COMPLEX_TYPE
  1874. #endif
  1875. /* ---- Definitions for closures ----------------------------------------- */
  1876. #define FFI_CLOSURES 1
  1877. #define FFI_GO_CLOSURES 1
  1878. #define FFI_NATIVE_RAW_API 0
  1879. #if defined (FFI_EXEC_TRAMPOLINE_TABLE) && FFI_EXEC_TRAMPOLINE_TABLE
  1880. #ifdef __MACH__
  1881. #define FFI_TRAMPOLINE_SIZE 12
  1882. #define FFI_TRAMPOLINE_CLOSURE_OFFSET 8
  1883. #else
  1884. #error "No trampoline table implementation"
  1885. #endif
  1886. #else
  1887. #ifdef _MSC_VER
  1888. #define FFI_TRAMPOLINE_SIZE 16
  1889. #define FFI_TRAMPOLINE_CLOSURE_FUNCTION 12
  1890. #else
  1891. #define FFI_TRAMPOLINE_SIZE 12
  1892. #endif
  1893. #define FFI_TRAMPOLINE_CLOSURE_OFFSET FFI_TRAMPOLINE_SIZE
  1894. #endif
  1895. #endif
  1896. ====================File: configs/armv7a-unknown-linux-gnueabihf/include/ffitarget.h====================
  1897. /* -----------------------------------------------------------------*-C-*-
  1898. ffitarget.h - Copyright (c) 2012 Anthony Green
  1899. Copyright (c) 2010 CodeSourcery
  1900. Copyright (c) 1996-2003 Red Hat, Inc.
  1901. Target configuration macros for ARM.
  1902. Permission is hereby granted, free of charge, to any person obtaining
  1903. a copy of this software and associated documentation files (the
  1904. ``Software''), to deal in the Software without restriction, including
  1905. without limitation the rights to use, copy, modify, merge, publish,
  1906. distribute, sublicense, and/or sell copies of the Software, and to
  1907. permit persons to whom the Software is furnished to do so, subject to
  1908. the following conditions:
  1909. The above copyright notice and this permission notice shall be included
  1910. in all copies or substantial portions of the Software.
  1911. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  1912. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1913. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  1914. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  1915. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  1916. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  1917. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  1918. DEALINGS IN THE SOFTWARE.
  1919. ----------------------------------------------------------------------- */
  1920. #ifndef LIBFFI_TARGET_H
  1921. #define LIBFFI_TARGET_H
  1922. #ifndef LIBFFI_H
  1923. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  1924. #endif
  1925. #ifndef LIBFFI_ASM
  1926. typedef unsigned long ffi_arg;
  1927. typedef signed long ffi_sarg;
  1928. typedef enum ffi_abi {
  1929. FFI_FIRST_ABI = 0,
  1930. FFI_SYSV,
  1931. FFI_VFP,
  1932. FFI_LAST_ABI,
  1933. #if defined(__ARM_PCS_VFP) || defined(_M_ARM)
  1934. FFI_DEFAULT_ABI = FFI_VFP,
  1935. #else
  1936. FFI_DEFAULT_ABI = FFI_SYSV,
  1937. #endif
  1938. } ffi_abi;
  1939. #endif
  1940. #define FFI_EXTRA_CIF_FIELDS \
  1941. int vfp_used; \
  1942. unsigned short vfp_reg_free, vfp_nargs; \
  1943. signed char vfp_args[16] \
  1944. #define FFI_TARGET_SPECIFIC_VARIADIC
  1945. #ifndef _M_ARM
  1946. #define FFI_TARGET_HAS_COMPLEX_TYPE
  1947. #endif
  1948. /* ---- Definitions for closures ----------------------------------------- */
  1949. #define FFI_CLOSURES 1
  1950. #define FFI_GO_CLOSURES 1
  1951. #define FFI_NATIVE_RAW_API 0
  1952. #if defined (FFI_EXEC_TRAMPOLINE_TABLE) && FFI_EXEC_TRAMPOLINE_TABLE
  1953. #ifdef __MACH__
  1954. #define FFI_TRAMPOLINE_SIZE 12
  1955. #define FFI_TRAMPOLINE_CLOSURE_OFFSET 8
  1956. #else
  1957. #error "No trampoline table implementation"
  1958. #endif
  1959. #else
  1960. #ifdef _MSC_VER
  1961. #define FFI_TRAMPOLINE_SIZE 16
  1962. #define FFI_TRAMPOLINE_CLOSURE_FUNCTION 12
  1963. #else
  1964. #define FFI_TRAMPOLINE_SIZE 12
  1965. #endif
  1966. #define FFI_TRAMPOLINE_CLOSURE_OFFSET FFI_TRAMPOLINE_SIZE
  1967. #endif
  1968. #endif
  1969. ====================File: configs/i386-microsoft-windows/include/ffitarget.h====================
  1970. /* -----------------------------------------------------------------*-C-*-
  1971. ffitarget.h - Copyright (c) 2012, 2014, 2018 Anthony Green
  1972. Copyright (c) 1996-2003, 2010 Red Hat, Inc.
  1973. Copyright (C) 2008 Free Software Foundation, Inc.
  1974. Target configuration macros for x86 and x86-64.
  1975. Permission is hereby granted, free of charge, to any person obtaining
  1976. a copy of this software and associated documentation files (the
  1977. ``Software''), to deal in the Software without restriction, including
  1978. without limitation the rights to use, copy, modify, merge, publish,
  1979. distribute, sublicense, and/or sell copies of the Software, and to
  1980. permit persons to whom the Software is furnished to do so, subject to
  1981. the following conditions:
  1982. The above copyright notice and this permission notice shall be included
  1983. in all copies or substantial portions of the Software.
  1984. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  1985. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1986. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  1987. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  1988. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  1989. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  1990. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  1991. DEALINGS IN THE SOFTWARE.
  1992. ----------------------------------------------------------------------- */
  1993. #ifndef LIBFFI_TARGET_H
  1994. #define LIBFFI_TARGET_H
  1995. #ifndef LIBFFI_H
  1996. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  1997. #endif
  1998. /* ---- System specific configurations ----------------------------------- */
  1999. /* For code common to all platforms on x86 and x86_64. */
  2000. #define X86_ANY
  2001. #if defined (X86_64) && defined (__i386__)
  2002. #undef X86_64
  2003. #define X86
  2004. #endif
  2005. #ifdef X86_WIN64
  2006. #define FFI_SIZEOF_ARG 8
  2007. #define USE_BUILTIN_FFS 0 /* not yet implemented in mingw-64 */
  2008. #endif
  2009. #define FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION
  2010. #ifndef _MSC_VER
  2011. #define FFI_TARGET_HAS_COMPLEX_TYPE
  2012. #endif
  2013. /* ---- Generic type definitions ----------------------------------------- */
  2014. #ifndef LIBFFI_ASM
  2015. #ifdef X86_WIN64
  2016. #ifdef _MSC_VER
  2017. typedef unsigned __int64 ffi_arg;
  2018. typedef __int64 ffi_sarg;
  2019. #else
  2020. typedef unsigned long long ffi_arg;
  2021. typedef long long ffi_sarg;
  2022. #endif
  2023. #else
  2024. #if defined __x86_64__ && defined __ILP32__
  2025. #define FFI_SIZEOF_ARG 8
  2026. #define FFI_SIZEOF_JAVA_RAW 4
  2027. typedef unsigned long long ffi_arg;
  2028. typedef long long ffi_sarg;
  2029. #else
  2030. typedef unsigned long ffi_arg;
  2031. typedef signed long ffi_sarg;
  2032. #endif
  2033. #endif
  2034. typedef enum ffi_abi {
  2035. #if defined(X86_WIN64)
  2036. FFI_FIRST_ABI = 0,
  2037. FFI_WIN64, /* sizeof(long double) == 8 - microsoft compilers */
  2038. FFI_GNUW64, /* sizeof(long double) == 16 - GNU compilers */
  2039. FFI_LAST_ABI,
  2040. #ifdef __GNUC__
  2041. FFI_DEFAULT_ABI = FFI_GNUW64
  2042. #else
  2043. FFI_DEFAULT_ABI = FFI_WIN64
  2044. #endif
  2045. #elif defined(X86_64) || (defined (__x86_64__) && defined (X86_DARWIN))
  2046. FFI_FIRST_ABI = 1,
  2047. FFI_UNIX64,
  2048. FFI_WIN64,
  2049. FFI_EFI64 = FFI_WIN64,
  2050. FFI_GNUW64,
  2051. FFI_LAST_ABI,
  2052. FFI_DEFAULT_ABI = FFI_UNIX64
  2053. #elif defined(X86_WIN32)
  2054. FFI_FIRST_ABI = 0,
  2055. FFI_SYSV = 1,
  2056. FFI_STDCALL = 2,
  2057. FFI_THISCALL = 3,
  2058. FFI_FASTCALL = 4,
  2059. FFI_MS_CDECL = 5,
  2060. FFI_PASCAL = 6,
  2061. FFI_REGISTER = 7,
  2062. FFI_LAST_ABI,
  2063. FFI_DEFAULT_ABI = FFI_MS_CDECL
  2064. #else
  2065. FFI_FIRST_ABI = 0,
  2066. FFI_SYSV = 1,
  2067. FFI_THISCALL = 3,
  2068. FFI_FASTCALL = 4,
  2069. FFI_STDCALL = 5,
  2070. FFI_PASCAL = 6,
  2071. FFI_REGISTER = 7,
  2072. FFI_MS_CDECL = 8,
  2073. FFI_LAST_ABI,
  2074. FFI_DEFAULT_ABI = FFI_SYSV
  2075. #endif
  2076. } ffi_abi;
  2077. #endif
  2078. /* ---- Definitions for closures ----------------------------------------- */
  2079. #define FFI_CLOSURES 1
  2080. #define FFI_GO_CLOSURES 1
  2081. #define FFI_TYPE_SMALL_STRUCT_1B (FFI_TYPE_LAST + 1)
  2082. #define FFI_TYPE_SMALL_STRUCT_2B (FFI_TYPE_LAST + 2)
  2083. #define FFI_TYPE_SMALL_STRUCT_4B (FFI_TYPE_LAST + 3)
  2084. #define FFI_TYPE_MS_STRUCT (FFI_TYPE_LAST + 4)
  2085. #if defined (X86_64) || defined(X86_WIN64) \
  2086. || (defined (__x86_64__) && defined (X86_DARWIN))
  2087. /* 4 bytes of ENDBR64 + 7 bytes of LEA + 6 bytes of JMP + 7 bytes of NOP
  2088. + 8 bytes of pointer. */
  2089. # define FFI_TRAMPOLINE_SIZE 32
  2090. # define FFI_NATIVE_RAW_API 0
  2091. #else
  2092. /* 4 bytes of ENDBR32 + 5 bytes of MOV + 5 bytes of JMP + 2 unused
  2093. bytes. */
  2094. # define FFI_TRAMPOLINE_SIZE 16
  2095. # define FFI_NATIVE_RAW_API 1 /* x86 has native raw api support */
  2096. #endif
  2097. #if !defined(GENERATE_LIBFFI_MAP) && defined(__ASSEMBLER__) \
  2098. && defined(__CET__)
  2099. # include <cet.h>
  2100. # define _CET_NOTRACK notrack
  2101. #else
  2102. # define _CET_ENDBR
  2103. # define _CET_NOTRACK
  2104. #endif
  2105. #endif
  2106. ====================File: configs/i686-pc-linux-android16/include/ffitarget.h====================
  2107. /* -----------------------------------------------------------------*-C-*-
  2108. ffitarget.h - Copyright (c) 2012, 2014, 2018 Anthony Green
  2109. Copyright (c) 1996-2003, 2010 Red Hat, Inc.
  2110. Copyright (C) 2008 Free Software Foundation, Inc.
  2111. Target configuration macros for x86 and x86-64.
  2112. Permission is hereby granted, free of charge, to any person obtaining
  2113. a copy of this software and associated documentation files (the
  2114. ``Software''), to deal in the Software without restriction, including
  2115. without limitation the rights to use, copy, modify, merge, publish,
  2116. distribute, sublicense, and/or sell copies of the Software, and to
  2117. permit persons to whom the Software is furnished to do so, subject to
  2118. the following conditions:
  2119. The above copyright notice and this permission notice shall be included
  2120. in all copies or substantial portions of the Software.
  2121. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  2122. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2123. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  2124. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  2125. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  2126. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  2127. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  2128. DEALINGS IN THE SOFTWARE.
  2129. ----------------------------------------------------------------------- */
  2130. #ifndef LIBFFI_TARGET_H
  2131. #define LIBFFI_TARGET_H
  2132. #ifndef LIBFFI_H
  2133. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  2134. #endif
  2135. /* ---- System specific configurations ----------------------------------- */
  2136. /* For code common to all platforms on x86 and x86_64. */
  2137. #define X86_ANY
  2138. #if defined (X86_64) && defined (__i386__)
  2139. #undef X86_64
  2140. #define X86
  2141. #endif
  2142. #ifdef X86_WIN64
  2143. #define FFI_SIZEOF_ARG 8
  2144. #define USE_BUILTIN_FFS 0 /* not yet implemented in mingw-64 */
  2145. #endif
  2146. #define FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION
  2147. #ifndef _MSC_VER
  2148. #define FFI_TARGET_HAS_COMPLEX_TYPE
  2149. #endif
  2150. /* ---- Generic type definitions ----------------------------------------- */
  2151. #ifndef LIBFFI_ASM
  2152. #ifdef X86_WIN64
  2153. #ifdef _MSC_VER
  2154. typedef unsigned __int64 ffi_arg;
  2155. typedef __int64 ffi_sarg;
  2156. #else
  2157. typedef unsigned long long ffi_arg;
  2158. typedef long long ffi_sarg;
  2159. #endif
  2160. #else
  2161. #if defined __x86_64__ && defined __ILP32__
  2162. #define FFI_SIZEOF_ARG 8
  2163. #define FFI_SIZEOF_JAVA_RAW 4
  2164. typedef unsigned long long ffi_arg;
  2165. typedef long long ffi_sarg;
  2166. #else
  2167. typedef unsigned long ffi_arg;
  2168. typedef signed long ffi_sarg;
  2169. #endif
  2170. #endif
  2171. typedef enum ffi_abi {
  2172. #if defined(X86_WIN64)
  2173. FFI_FIRST_ABI = 0,
  2174. FFI_WIN64, /* sizeof(long double) == 8 - microsoft compilers */
  2175. FFI_GNUW64, /* sizeof(long double) == 16 - GNU compilers */
  2176. FFI_LAST_ABI,
  2177. #ifdef __GNUC__
  2178. FFI_DEFAULT_ABI = FFI_GNUW64
  2179. #else
  2180. FFI_DEFAULT_ABI = FFI_WIN64
  2181. #endif
  2182. #elif defined(X86_64) || (defined (__x86_64__) && defined (X86_DARWIN))
  2183. FFI_FIRST_ABI = 1,
  2184. FFI_UNIX64,
  2185. FFI_WIN64,
  2186. FFI_EFI64 = FFI_WIN64,
  2187. FFI_GNUW64,
  2188. FFI_LAST_ABI,
  2189. FFI_DEFAULT_ABI = FFI_UNIX64
  2190. #elif defined(X86_WIN32)
  2191. FFI_FIRST_ABI = 0,
  2192. FFI_SYSV = 1,
  2193. FFI_STDCALL = 2,
  2194. FFI_THISCALL = 3,
  2195. FFI_FASTCALL = 4,
  2196. FFI_MS_CDECL = 5,
  2197. FFI_PASCAL = 6,
  2198. FFI_REGISTER = 7,
  2199. FFI_LAST_ABI,
  2200. FFI_DEFAULT_ABI = FFI_MS_CDECL
  2201. #else
  2202. FFI_FIRST_ABI = 0,
  2203. FFI_SYSV = 1,
  2204. FFI_THISCALL = 3,
  2205. FFI_FASTCALL = 4,
  2206. FFI_STDCALL = 5,
  2207. FFI_PASCAL = 6,
  2208. FFI_REGISTER = 7,
  2209. FFI_MS_CDECL = 8,
  2210. FFI_LAST_ABI,
  2211. FFI_DEFAULT_ABI = FFI_SYSV
  2212. #endif
  2213. } ffi_abi;
  2214. #endif
  2215. /* ---- Definitions for closures ----------------------------------------- */
  2216. #define FFI_CLOSURES 1
  2217. #define FFI_GO_CLOSURES 1
  2218. #define FFI_TYPE_SMALL_STRUCT_1B (FFI_TYPE_LAST + 1)
  2219. #define FFI_TYPE_SMALL_STRUCT_2B (FFI_TYPE_LAST + 2)
  2220. #define FFI_TYPE_SMALL_STRUCT_4B (FFI_TYPE_LAST + 3)
  2221. #define FFI_TYPE_MS_STRUCT (FFI_TYPE_LAST + 4)
  2222. #if defined (X86_64) || defined(X86_WIN64) \
  2223. || (defined (__x86_64__) && defined (X86_DARWIN))
  2224. # define FFI_TRAMPOLINE_SIZE 24
  2225. # define FFI_NATIVE_RAW_API 0
  2226. #else
  2227. # define FFI_TRAMPOLINE_SIZE 12
  2228. # define FFI_NATIVE_RAW_API 1 /* x86 has native raw api support */
  2229. #endif
  2230. #endif
  2231. ====================File: configs/powerpc64le-unknown-linux-gnu/include/ffitarget.h====================
  2232. /* -----------------------------------------------------------------*-C-*-
  2233. ffitarget.h - Copyright (c) 2012 Anthony Green
  2234. Copyright (C) 2007, 2008, 2010 Free Software Foundation, Inc
  2235. Copyright (c) 1996-2003 Red Hat, Inc.
  2236. Target configuration macros for PowerPC.
  2237. Permission is hereby granted, free of charge, to any person obtaining
  2238. a copy of this software and associated documentation files (the
  2239. ``Software''), to deal in the Software without restriction, including
  2240. without limitation the rights to use, copy, modify, merge, publish,
  2241. distribute, sublicense, and/or sell copies of the Software, and to
  2242. permit persons to whom the Software is furnished to do so, subject to
  2243. the following conditions:
  2244. The above copyright notice and this permission notice shall be included
  2245. in all copies or substantial portions of the Software.
  2246. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  2247. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2248. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  2249. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  2250. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  2251. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  2252. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  2253. DEALINGS IN THE SOFTWARE.
  2254. ----------------------------------------------------------------------- */
  2255. #ifndef LIBFFI_TARGET_H
  2256. #define LIBFFI_TARGET_H
  2257. #ifndef LIBFFI_H
  2258. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  2259. #endif
  2260. /* ---- System specific configurations ----------------------------------- */
  2261. #if defined (POWERPC) && defined (__powerpc64__) /* linux64 */
  2262. #ifndef POWERPC64
  2263. #define POWERPC64
  2264. #endif
  2265. #elif defined (POWERPC_DARWIN) && defined (__ppc64__) /* Darwin64 */
  2266. #ifndef POWERPC64
  2267. #define POWERPC64
  2268. #endif
  2269. #ifndef POWERPC_DARWIN64
  2270. #define POWERPC_DARWIN64
  2271. #endif
  2272. #elif defined (POWERPC_AIX) && defined (__64BIT__) /* AIX64 */
  2273. #ifndef POWERPC64
  2274. #define POWERPC64
  2275. #endif
  2276. #endif
  2277. #ifndef LIBFFI_ASM
  2278. typedef unsigned long ffi_arg;
  2279. typedef signed long ffi_sarg;
  2280. typedef enum ffi_abi {
  2281. FFI_FIRST_ABI = 0,
  2282. #if defined (POWERPC_AIX)
  2283. FFI_AIX,
  2284. FFI_DARWIN,
  2285. FFI_DEFAULT_ABI = FFI_AIX,
  2286. FFI_LAST_ABI
  2287. #elif defined (POWERPC_DARWIN)
  2288. FFI_AIX,
  2289. FFI_DARWIN,
  2290. FFI_DEFAULT_ABI = FFI_DARWIN,
  2291. FFI_LAST_ABI
  2292. #else
  2293. /* The FFI_COMPAT values are used by old code. Since libffi may be
  2294. a shared library we have to support old values for backwards
  2295. compatibility. */
  2296. FFI_COMPAT_SYSV,
  2297. FFI_COMPAT_GCC_SYSV,
  2298. FFI_COMPAT_LINUX64,
  2299. FFI_COMPAT_LINUX,
  2300. FFI_COMPAT_LINUX_SOFT_FLOAT,
  2301. # if defined (POWERPC64)
  2302. /* This bit, always set in new code, must not be set in any of the
  2303. old FFI_COMPAT values that might be used for 64-bit linux. We
  2304. only need worry about FFI_COMPAT_LINUX64, but to be safe avoid
  2305. all old values. */
  2306. FFI_LINUX = 8,
  2307. /* This and following bits can reuse FFI_COMPAT values. */
  2308. FFI_LINUX_STRUCT_ALIGN = 1,
  2309. FFI_LINUX_LONG_DOUBLE_128 = 2,
  2310. FFI_LINUX_LONG_DOUBLE_IEEE128 = 4,
  2311. FFI_DEFAULT_ABI = (FFI_LINUX
  2312. # ifdef __STRUCT_PARM_ALIGN__
  2313. | FFI_LINUX_STRUCT_ALIGN
  2314. # endif
  2315. # ifdef __LONG_DOUBLE_128__
  2316. | FFI_LINUX_LONG_DOUBLE_128
  2317. # ifdef __LONG_DOUBLE_IEEE128__
  2318. | FFI_LINUX_LONG_DOUBLE_IEEE128
  2319. # endif
  2320. # endif
  2321. ),
  2322. FFI_LAST_ABI = 16
  2323. # else
  2324. /* This bit, always set in new code, must not be set in any of the
  2325. old FFI_COMPAT values that might be used for 32-bit linux/sysv/bsd. */
  2326. FFI_SYSV = 8,
  2327. /* This and following bits can reuse FFI_COMPAT values. */
  2328. FFI_SYSV_SOFT_FLOAT = 1,
  2329. FFI_SYSV_STRUCT_RET = 2,
  2330. FFI_SYSV_IBM_LONG_DOUBLE = 4,
  2331. FFI_SYSV_LONG_DOUBLE_128 = 16,
  2332. FFI_DEFAULT_ABI = (FFI_SYSV
  2333. # ifdef __NO_FPRS__
  2334. | FFI_SYSV_SOFT_FLOAT
  2335. # endif
  2336. # if (defined (__SVR4_STRUCT_RETURN) \
  2337. || defined (POWERPC_FREEBSD) && !defined (__AIX_STRUCT_RETURN))
  2338. | FFI_SYSV_STRUCT_RET
  2339. # endif
  2340. # if __LDBL_MANT_DIG__ == 106
  2341. | FFI_SYSV_IBM_LONG_DOUBLE
  2342. # endif
  2343. # ifdef __LONG_DOUBLE_128__
  2344. | FFI_SYSV_LONG_DOUBLE_128
  2345. # endif
  2346. ),
  2347. FFI_LAST_ABI = 32
  2348. # endif
  2349. #endif
  2350. } ffi_abi;
  2351. #endif
  2352. /* ---- Definitions for closures ----------------------------------------- */
  2353. #define FFI_CLOSURES 1
  2354. #define FFI_NATIVE_RAW_API 0
  2355. #if defined (POWERPC) || defined (POWERPC_FREEBSD)
  2356. # define FFI_GO_CLOSURES 1
  2357. # define FFI_TARGET_SPECIFIC_VARIADIC 1
  2358. # define FFI_EXTRA_CIF_FIELDS unsigned nfixedargs
  2359. #endif
  2360. #if defined (POWERPC_AIX)
  2361. # define FFI_GO_CLOSURES 1
  2362. #endif
  2363. /* ppc_closure.S and linux64_closure.S expect this. */
  2364. #define FFI_PPC_TYPE_LAST FFI_TYPE_POINTER
  2365. /* We define additional types below. If generic types are added that
  2366. must be supported by powerpc libffi then it is likely that
  2367. FFI_PPC_TYPE_LAST needs increasing *and* the jump tables in
  2368. ppc_closure.S and linux64_closure.S be extended. */
  2369. #if !(FFI_TYPE_LAST == FFI_PPC_TYPE_LAST \
  2370. || (FFI_TYPE_LAST == FFI_TYPE_COMPLEX \
  2371. && !defined FFI_TARGET_HAS_COMPLEX_TYPE))
  2372. # error "You likely have a broken powerpc libffi"
  2373. #endif
  2374. /* Needed for soft-float long-double-128 support. */
  2375. #define FFI_TYPE_UINT128 (FFI_PPC_TYPE_LAST + 1)
  2376. /* Needed for FFI_SYSV small structure returns. */
  2377. #define FFI_SYSV_TYPE_SMALL_STRUCT (FFI_PPC_TYPE_LAST + 2)
  2378. /* Used by ELFv2 for homogenous structure returns. */
  2379. #define FFI_V2_TYPE_VECTOR (FFI_PPC_TYPE_LAST + 1)
  2380. #define FFI_V2_TYPE_VECTOR_HOMOG (FFI_PPC_TYPE_LAST + 2)
  2381. #define FFI_V2_TYPE_FLOAT_HOMOG (FFI_PPC_TYPE_LAST + 3)
  2382. #define FFI_V2_TYPE_DOUBLE_HOMOG (FFI_PPC_TYPE_LAST + 4)
  2383. #define FFI_V2_TYPE_SMALL_STRUCT (FFI_PPC_TYPE_LAST + 5)
  2384. #if _CALL_ELF == 2
  2385. # define FFI_TRAMPOLINE_SIZE 32
  2386. #else
  2387. # if defined(POWERPC64) || defined(POWERPC_AIX)
  2388. # if defined(POWERPC_DARWIN64)
  2389. # define FFI_TRAMPOLINE_SIZE 48
  2390. # else
  2391. # define FFI_TRAMPOLINE_SIZE 24
  2392. # endif
  2393. # else /* POWERPC || POWERPC_AIX */
  2394. # define FFI_TRAMPOLINE_SIZE 40
  2395. # endif
  2396. #endif
  2397. #ifndef LIBFFI_ASM
  2398. #if defined(POWERPC_DARWIN) || defined(POWERPC_AIX)
  2399. struct ffi_aix_trampoline_struct {
  2400. void * code_pointer; /* Pointer to ffi_closure_ASM */
  2401. void * toc; /* TOC */
  2402. void * static_chain; /* Pointer to closure */
  2403. };
  2404. #endif
  2405. #endif
  2406. #endif
  2407. ====================File: configs/x86_64-apple-iphonesimulator/include/ffitarget.h====================
  2408. /* -----------------------------------------------------------------*-C-*-
  2409. ffitarget.h - Copyright (c) 2012, 2014, 2018 Anthony Green
  2410. Copyright (c) 1996-2003, 2010 Red Hat, Inc.
  2411. Copyright (C) 2008 Free Software Foundation, Inc.
  2412. Target configuration macros for x86 and x86-64.
  2413. Permission is hereby granted, free of charge, to any person obtaining
  2414. a copy of this software and associated documentation files (the
  2415. ``Software''), to deal in the Software without restriction, including
  2416. without limitation the rights to use, copy, modify, merge, publish,
  2417. distribute, sublicense, and/or sell copies of the Software, and to
  2418. permit persons to whom the Software is furnished to do so, subject to
  2419. the following conditions:
  2420. The above copyright notice and this permission notice shall be included
  2421. in all copies or substantial portions of the Software.
  2422. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  2423. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2424. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  2425. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  2426. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  2427. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  2428. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  2429. DEALINGS IN THE SOFTWARE.
  2430. ----------------------------------------------------------------------- */
  2431. #ifndef LIBFFI_TARGET_H
  2432. #define LIBFFI_TARGET_H
  2433. #ifndef LIBFFI_H
  2434. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  2435. #endif
  2436. /* ---- System specific configurations ----------------------------------- */
  2437. /* For code common to all platforms on x86 and x86_64. */
  2438. #define X86_ANY
  2439. #if defined (X86_64) && defined (__i386__)
  2440. #undef X86_64
  2441. #define X86
  2442. #endif
  2443. #ifdef X86_WIN64
  2444. #define FFI_SIZEOF_ARG 8
  2445. #define USE_BUILTIN_FFS 0 /* not yet implemented in mingw-64 */
  2446. #endif
  2447. #define FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION
  2448. #ifndef _MSC_VER
  2449. #define FFI_TARGET_HAS_COMPLEX_TYPE
  2450. #endif
  2451. /* ---- Generic type definitions ----------------------------------------- */
  2452. #ifndef LIBFFI_ASM
  2453. #ifdef X86_WIN64
  2454. #ifdef _MSC_VER
  2455. typedef unsigned __int64 ffi_arg;
  2456. typedef __int64 ffi_sarg;
  2457. #else
  2458. typedef unsigned long long ffi_arg;
  2459. typedef long long ffi_sarg;
  2460. #endif
  2461. #else
  2462. #if defined __x86_64__ && defined __ILP32__
  2463. #define FFI_SIZEOF_ARG 8
  2464. #define FFI_SIZEOF_JAVA_RAW 4
  2465. typedef unsigned long long ffi_arg;
  2466. typedef long long ffi_sarg;
  2467. #else
  2468. typedef unsigned long ffi_arg;
  2469. typedef signed long ffi_sarg;
  2470. #endif
  2471. #endif
  2472. typedef enum ffi_abi {
  2473. #if defined(X86_WIN64)
  2474. FFI_FIRST_ABI = 0,
  2475. FFI_WIN64, /* sizeof(long double) == 8 - microsoft compilers */
  2476. FFI_GNUW64, /* sizeof(long double) == 16 - GNU compilers */
  2477. FFI_LAST_ABI,
  2478. #ifdef __GNUC__
  2479. FFI_DEFAULT_ABI = FFI_GNUW64
  2480. #else
  2481. FFI_DEFAULT_ABI = FFI_WIN64
  2482. #endif
  2483. #elif defined(X86_64) || (defined (__x86_64__) && defined (X86_DARWIN))
  2484. FFI_FIRST_ABI = 1,
  2485. FFI_UNIX64,
  2486. FFI_WIN64,
  2487. FFI_EFI64 = FFI_WIN64,
  2488. FFI_GNUW64,
  2489. FFI_LAST_ABI,
  2490. FFI_DEFAULT_ABI = FFI_UNIX64
  2491. #elif defined(X86_WIN32)
  2492. FFI_FIRST_ABI = 0,
  2493. FFI_SYSV = 1,
  2494. FFI_STDCALL = 2,
  2495. FFI_THISCALL = 3,
  2496. FFI_FASTCALL = 4,
  2497. FFI_MS_CDECL = 5,
  2498. FFI_PASCAL = 6,
  2499. FFI_REGISTER = 7,
  2500. FFI_LAST_ABI,
  2501. FFI_DEFAULT_ABI = FFI_MS_CDECL
  2502. #else
  2503. FFI_FIRST_ABI = 0,
  2504. FFI_SYSV = 1,
  2505. FFI_THISCALL = 3,
  2506. FFI_FASTCALL = 4,
  2507. FFI_STDCALL = 5,
  2508. FFI_PASCAL = 6,
  2509. FFI_REGISTER = 7,
  2510. FFI_MS_CDECL = 8,
  2511. FFI_LAST_ABI,
  2512. FFI_DEFAULT_ABI = FFI_SYSV
  2513. #endif
  2514. } ffi_abi;
  2515. #endif
  2516. /* ---- Definitions for closures ----------------------------------------- */
  2517. #define FFI_CLOSURES 1
  2518. #define FFI_GO_CLOSURES 1
  2519. #define FFI_TYPE_SMALL_STRUCT_1B (FFI_TYPE_LAST + 1)
  2520. #define FFI_TYPE_SMALL_STRUCT_2B (FFI_TYPE_LAST + 2)
  2521. #define FFI_TYPE_SMALL_STRUCT_4B (FFI_TYPE_LAST + 3)
  2522. #define FFI_TYPE_MS_STRUCT (FFI_TYPE_LAST + 4)
  2523. #if defined (X86_64) || defined(X86_WIN64) \
  2524. || (defined (__x86_64__) && defined (X86_DARWIN))
  2525. # define FFI_TRAMPOLINE_SIZE 24
  2526. # define FFI_NATIVE_RAW_API 0
  2527. #else
  2528. # define FFI_TRAMPOLINE_SIZE 12
  2529. # define FFI_NATIVE_RAW_API 1 /* x86 has native raw api support */
  2530. #endif
  2531. #endif
  2532. ====================File: configs/x86_64-apple-macosx/include/ffitarget.h====================
  2533. /* -----------------------------------------------------------------*-C-*-
  2534. ffitarget.h - Copyright (c) 2012, 2014, 2018 Anthony Green
  2535. Copyright (c) 1996-2003, 2010 Red Hat, Inc.
  2536. Copyright (C) 2008 Free Software Foundation, Inc.
  2537. Target configuration macros for x86 and x86-64.
  2538. Permission is hereby granted, free of charge, to any person obtaining
  2539. a copy of this software and associated documentation files (the
  2540. ``Software''), to deal in the Software without restriction, including
  2541. without limitation the rights to use, copy, modify, merge, publish,
  2542. distribute, sublicense, and/or sell copies of the Software, and to
  2543. permit persons to whom the Software is furnished to do so, subject to
  2544. the following conditions:
  2545. The above copyright notice and this permission notice shall be included
  2546. in all copies or substantial portions of the Software.
  2547. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  2548. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2549. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  2550. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  2551. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  2552. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  2553. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  2554. DEALINGS IN THE SOFTWARE.
  2555. ----------------------------------------------------------------------- */
  2556. #ifndef LIBFFI_TARGET_H
  2557. #define LIBFFI_TARGET_H
  2558. #ifndef LIBFFI_H
  2559. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  2560. #endif
  2561. /* ---- System specific configurations ----------------------------------- */
  2562. /* For code common to all platforms on x86 and x86_64. */
  2563. #define X86_ANY
  2564. #if defined (X86_64) && defined (__i386__)
  2565. #undef X86_64
  2566. #define X86
  2567. #endif
  2568. #ifdef X86_WIN64
  2569. #define FFI_SIZEOF_ARG 8
  2570. #define USE_BUILTIN_FFS 0 /* not yet implemented in mingw-64 */
  2571. #endif
  2572. #define FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION
  2573. #ifndef _MSC_VER
  2574. #define FFI_TARGET_HAS_COMPLEX_TYPE
  2575. #endif
  2576. /* ---- Generic type definitions ----------------------------------------- */
  2577. #ifndef LIBFFI_ASM
  2578. #ifdef X86_WIN64
  2579. #ifdef _MSC_VER
  2580. typedef unsigned __int64 ffi_arg;
  2581. typedef __int64 ffi_sarg;
  2582. #else
  2583. typedef unsigned long long ffi_arg;
  2584. typedef long long ffi_sarg;
  2585. #endif
  2586. #else
  2587. #if defined __x86_64__ && defined __ILP32__
  2588. #define FFI_SIZEOF_ARG 8
  2589. #define FFI_SIZEOF_JAVA_RAW 4
  2590. typedef unsigned long long ffi_arg;
  2591. typedef long long ffi_sarg;
  2592. #else
  2593. typedef unsigned long ffi_arg;
  2594. typedef signed long ffi_sarg;
  2595. #endif
  2596. #endif
  2597. typedef enum ffi_abi {
  2598. #if defined(X86_WIN64)
  2599. FFI_FIRST_ABI = 0,
  2600. FFI_WIN64, /* sizeof(long double) == 8 - microsoft compilers */
  2601. FFI_GNUW64, /* sizeof(long double) == 16 - GNU compilers */
  2602. FFI_LAST_ABI,
  2603. #ifdef __GNUC__
  2604. FFI_DEFAULT_ABI = FFI_GNUW64
  2605. #else
  2606. FFI_DEFAULT_ABI = FFI_WIN64
  2607. #endif
  2608. #elif defined(X86_64) || (defined (__x86_64__) && defined (X86_DARWIN))
  2609. FFI_FIRST_ABI = 1,
  2610. FFI_UNIX64,
  2611. FFI_WIN64,
  2612. FFI_EFI64 = FFI_WIN64,
  2613. FFI_GNUW64,
  2614. FFI_LAST_ABI,
  2615. FFI_DEFAULT_ABI = FFI_UNIX64
  2616. #elif defined(X86_WIN32)
  2617. FFI_FIRST_ABI = 0,
  2618. FFI_SYSV = 1,
  2619. FFI_STDCALL = 2,
  2620. FFI_THISCALL = 3,
  2621. FFI_FASTCALL = 4,
  2622. FFI_MS_CDECL = 5,
  2623. FFI_PASCAL = 6,
  2624. FFI_REGISTER = 7,
  2625. FFI_LAST_ABI,
  2626. FFI_DEFAULT_ABI = FFI_MS_CDECL
  2627. #else
  2628. FFI_FIRST_ABI = 0,
  2629. FFI_SYSV = 1,
  2630. FFI_THISCALL = 3,
  2631. FFI_FASTCALL = 4,
  2632. FFI_STDCALL = 5,
  2633. FFI_PASCAL = 6,
  2634. FFI_REGISTER = 7,
  2635. FFI_MS_CDECL = 8,
  2636. FFI_LAST_ABI,
  2637. FFI_DEFAULT_ABI = FFI_SYSV
  2638. #endif
  2639. } ffi_abi;
  2640. #endif
  2641. /* ---- Definitions for closures ----------------------------------------- */
  2642. #define FFI_CLOSURES 1
  2643. #define FFI_GO_CLOSURES 1
  2644. #define FFI_TYPE_SMALL_STRUCT_1B (FFI_TYPE_LAST + 1)
  2645. #define FFI_TYPE_SMALL_STRUCT_2B (FFI_TYPE_LAST + 2)
  2646. #define FFI_TYPE_SMALL_STRUCT_4B (FFI_TYPE_LAST + 3)
  2647. #define FFI_TYPE_MS_STRUCT (FFI_TYPE_LAST + 4)
  2648. #if defined (X86_64) || defined(X86_WIN64) \
  2649. || (defined (__x86_64__) && defined (X86_DARWIN))
  2650. # define FFI_TRAMPOLINE_SIZE 24
  2651. # define FFI_NATIVE_RAW_API 0
  2652. #else
  2653. # define FFI_TRAMPOLINE_SIZE 12
  2654. # define FFI_NATIVE_RAW_API 1 /* x86 has native raw api support */
  2655. #endif
  2656. #endif
  2657. ====================File: configs/x86_64-microsoft-windows/include/ffitarget.h====================
  2658. /* -----------------------------------------------------------------*-C-*-
  2659. ffitarget.h - Copyright (c) 2012, 2014, 2018 Anthony Green
  2660. Copyright (c) 1996-2003, 2010 Red Hat, Inc.
  2661. Copyright (C) 2008 Free Software Foundation, Inc.
  2662. Target configuration macros for x86 and x86-64.
  2663. Permission is hereby granted, free of charge, to any person obtaining
  2664. a copy of this software and associated documentation files (the
  2665. ``Software''), to deal in the Software without restriction, including
  2666. without limitation the rights to use, copy, modify, merge, publish,
  2667. distribute, sublicense, and/or sell copies of the Software, and to
  2668. permit persons to whom the Software is furnished to do so, subject to
  2669. the following conditions:
  2670. The above copyright notice and this permission notice shall be included
  2671. in all copies or substantial portions of the Software.
  2672. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  2673. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2674. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  2675. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  2676. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  2677. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  2678. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  2679. DEALINGS IN THE SOFTWARE.
  2680. ----------------------------------------------------------------------- */
  2681. #ifndef LIBFFI_TARGET_H
  2682. #define LIBFFI_TARGET_H
  2683. #ifndef LIBFFI_H
  2684. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  2685. #endif
  2686. /* ---- System specific configurations ----------------------------------- */
  2687. /* For code common to all platforms on x86 and x86_64. */
  2688. #define X86_ANY
  2689. #if defined (X86_64) && defined (__i386__)
  2690. #undef X86_64
  2691. #define X86
  2692. #endif
  2693. #ifdef X86_WIN64
  2694. #define FFI_SIZEOF_ARG 8
  2695. #define USE_BUILTIN_FFS 0 /* not yet implemented in mingw-64 */
  2696. #endif
  2697. #define FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION
  2698. #ifndef _MSC_VER
  2699. #define FFI_TARGET_HAS_COMPLEX_TYPE
  2700. #endif
  2701. /* ---- Generic type definitions ----------------------------------------- */
  2702. #ifndef LIBFFI_ASM
  2703. #ifdef X86_WIN64
  2704. #ifdef _MSC_VER
  2705. typedef unsigned __int64 ffi_arg;
  2706. typedef __int64 ffi_sarg;
  2707. #else
  2708. typedef unsigned long long ffi_arg;
  2709. typedef long long ffi_sarg;
  2710. #endif
  2711. #else
  2712. #if defined __x86_64__ && defined __ILP32__
  2713. #define FFI_SIZEOF_ARG 8
  2714. #define FFI_SIZEOF_JAVA_RAW 4
  2715. typedef unsigned long long ffi_arg;
  2716. typedef long long ffi_sarg;
  2717. #else
  2718. typedef unsigned long ffi_arg;
  2719. typedef signed long ffi_sarg;
  2720. #endif
  2721. #endif
  2722. typedef enum ffi_abi {
  2723. #if defined(X86_WIN64)
  2724. FFI_FIRST_ABI = 0,
  2725. FFI_WIN64, /* sizeof(long double) == 8 - microsoft compilers */
  2726. FFI_GNUW64, /* sizeof(long double) == 16 - GNU compilers */
  2727. FFI_LAST_ABI,
  2728. #ifdef __GNUC__
  2729. FFI_DEFAULT_ABI = FFI_GNUW64
  2730. #else
  2731. FFI_DEFAULT_ABI = FFI_WIN64
  2732. #endif
  2733. #elif defined(X86_64) || (defined (__x86_64__) && defined (X86_DARWIN))
  2734. FFI_FIRST_ABI = 1,
  2735. FFI_UNIX64,
  2736. FFI_WIN64,
  2737. FFI_EFI64 = FFI_WIN64,
  2738. FFI_GNUW64,
  2739. FFI_LAST_ABI,
  2740. FFI_DEFAULT_ABI = FFI_UNIX64
  2741. #elif defined(X86_WIN32)
  2742. FFI_FIRST_ABI = 0,
  2743. FFI_SYSV = 1,
  2744. FFI_STDCALL = 2,
  2745. FFI_THISCALL = 3,
  2746. FFI_FASTCALL = 4,
  2747. FFI_MS_CDECL = 5,
  2748. FFI_PASCAL = 6,
  2749. FFI_REGISTER = 7,
  2750. FFI_LAST_ABI,
  2751. FFI_DEFAULT_ABI = FFI_MS_CDECL
  2752. #else
  2753. FFI_FIRST_ABI = 0,
  2754. FFI_SYSV = 1,
  2755. FFI_THISCALL = 3,
  2756. FFI_FASTCALL = 4,
  2757. FFI_STDCALL = 5,
  2758. FFI_PASCAL = 6,
  2759. FFI_REGISTER = 7,
  2760. FFI_MS_CDECL = 8,
  2761. FFI_LAST_ABI,
  2762. FFI_DEFAULT_ABI = FFI_SYSV
  2763. #endif
  2764. } ffi_abi;
  2765. #endif
  2766. /* ---- Definitions for closures ----------------------------------------- */
  2767. #define FFI_CLOSURES 1
  2768. #define FFI_GO_CLOSURES 1
  2769. #define FFI_TYPE_SMALL_STRUCT_1B (FFI_TYPE_LAST + 1)
  2770. #define FFI_TYPE_SMALL_STRUCT_2B (FFI_TYPE_LAST + 2)
  2771. #define FFI_TYPE_SMALL_STRUCT_4B (FFI_TYPE_LAST + 3)
  2772. #define FFI_TYPE_MS_STRUCT (FFI_TYPE_LAST + 4)
  2773. #if defined (X86_64) || defined(X86_WIN64) \
  2774. || (defined (__x86_64__) && defined (X86_DARWIN))
  2775. /* 4 bytes of ENDBR64 + 7 bytes of LEA + 6 bytes of JMP + 7 bytes of NOP
  2776. + 8 bytes of pointer. */
  2777. # define FFI_TRAMPOLINE_SIZE 32
  2778. # define FFI_NATIVE_RAW_API 0
  2779. #else
  2780. /* 4 bytes of ENDBR32 + 5 bytes of MOV + 5 bytes of JMP + 2 unused
  2781. bytes. */
  2782. # define FFI_TRAMPOLINE_SIZE 16
  2783. # define FFI_NATIVE_RAW_API 1 /* x86 has native raw api support */
  2784. #endif
  2785. #if !defined(GENERATE_LIBFFI_MAP) && defined(__ASSEMBLER__) \
  2786. && defined(__CET__)
  2787. # include <cet.h>
  2788. # define _CET_NOTRACK notrack
  2789. #else
  2790. # define _CET_ENDBR
  2791. # define _CET_NOTRACK
  2792. #endif
  2793. #endif
  2794. ====================File: configs/x86_64-pc-linux-android21/include/ffitarget.h====================
  2795. /* -----------------------------------------------------------------*-C-*-
  2796. ffitarget.h - Copyright (c) 2012, 2014, 2018 Anthony Green
  2797. Copyright (c) 1996-2003, 2010 Red Hat, Inc.
  2798. Copyright (C) 2008 Free Software Foundation, Inc.
  2799. Target configuration macros for x86 and x86-64.
  2800. Permission is hereby granted, free of charge, to any person obtaining
  2801. a copy of this software and associated documentation files (the
  2802. ``Software''), to deal in the Software without restriction, including
  2803. without limitation the rights to use, copy, modify, merge, publish,
  2804. distribute, sublicense, and/or sell copies of the Software, and to
  2805. permit persons to whom the Software is furnished to do so, subject to
  2806. the following conditions:
  2807. The above copyright notice and this permission notice shall be included
  2808. in all copies or substantial portions of the Software.
  2809. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  2810. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2811. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  2812. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  2813. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  2814. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  2815. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  2816. DEALINGS IN THE SOFTWARE.
  2817. ----------------------------------------------------------------------- */
  2818. #ifndef LIBFFI_TARGET_H
  2819. #define LIBFFI_TARGET_H
  2820. #ifndef LIBFFI_H
  2821. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  2822. #endif
  2823. /* ---- System specific configurations ----------------------------------- */
  2824. /* For code common to all platforms on x86 and x86_64. */
  2825. #define X86_ANY
  2826. #if defined (X86_64) && defined (__i386__)
  2827. #undef X86_64
  2828. #define X86
  2829. #endif
  2830. #ifdef X86_WIN64
  2831. #define FFI_SIZEOF_ARG 8
  2832. #define USE_BUILTIN_FFS 0 /* not yet implemented in mingw-64 */
  2833. #endif
  2834. #define FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION
  2835. #ifndef _MSC_VER
  2836. #define FFI_TARGET_HAS_COMPLEX_TYPE
  2837. #endif
  2838. /* ---- Generic type definitions ----------------------------------------- */
  2839. #ifndef LIBFFI_ASM
  2840. #ifdef X86_WIN64
  2841. #ifdef _MSC_VER
  2842. typedef unsigned __int64 ffi_arg;
  2843. typedef __int64 ffi_sarg;
  2844. #else
  2845. typedef unsigned long long ffi_arg;
  2846. typedef long long ffi_sarg;
  2847. #endif
  2848. #else
  2849. #if defined __x86_64__ && defined __ILP32__
  2850. #define FFI_SIZEOF_ARG 8
  2851. #define FFI_SIZEOF_JAVA_RAW 4
  2852. typedef unsigned long long ffi_arg;
  2853. typedef long long ffi_sarg;
  2854. #else
  2855. typedef unsigned long ffi_arg;
  2856. typedef signed long ffi_sarg;
  2857. #endif
  2858. #endif
  2859. typedef enum ffi_abi {
  2860. #if defined(X86_WIN64)
  2861. FFI_FIRST_ABI = 0,
  2862. FFI_WIN64, /* sizeof(long double) == 8 - microsoft compilers */
  2863. FFI_GNUW64, /* sizeof(long double) == 16 - GNU compilers */
  2864. FFI_LAST_ABI,
  2865. #ifdef __GNUC__
  2866. FFI_DEFAULT_ABI = FFI_GNUW64
  2867. #else
  2868. FFI_DEFAULT_ABI = FFI_WIN64
  2869. #endif
  2870. #elif defined(X86_64) || (defined (__x86_64__) && defined (X86_DARWIN))
  2871. FFI_FIRST_ABI = 1,
  2872. FFI_UNIX64,
  2873. FFI_WIN64,
  2874. FFI_EFI64 = FFI_WIN64,
  2875. FFI_GNUW64,
  2876. FFI_LAST_ABI,
  2877. FFI_DEFAULT_ABI = FFI_UNIX64
  2878. #elif defined(X86_WIN32)
  2879. FFI_FIRST_ABI = 0,
  2880. FFI_SYSV = 1,
  2881. FFI_STDCALL = 2,
  2882. FFI_THISCALL = 3,
  2883. FFI_FASTCALL = 4,
  2884. FFI_MS_CDECL = 5,
  2885. FFI_PASCAL = 6,
  2886. FFI_REGISTER = 7,
  2887. FFI_LAST_ABI,
  2888. FFI_DEFAULT_ABI = FFI_MS_CDECL
  2889. #else
  2890. FFI_FIRST_ABI = 0,
  2891. FFI_SYSV = 1,
  2892. FFI_THISCALL = 3,
  2893. FFI_FASTCALL = 4,
  2894. FFI_STDCALL = 5,
  2895. FFI_PASCAL = 6,
  2896. FFI_REGISTER = 7,
  2897. FFI_MS_CDECL = 8,
  2898. FFI_LAST_ABI,
  2899. FFI_DEFAULT_ABI = FFI_SYSV
  2900. #endif
  2901. } ffi_abi;
  2902. #endif
  2903. /* ---- Definitions for closures ----------------------------------------- */
  2904. #define FFI_CLOSURES 1
  2905. #define FFI_GO_CLOSURES 1
  2906. #define FFI_TYPE_SMALL_STRUCT_1B (FFI_TYPE_LAST + 1)
  2907. #define FFI_TYPE_SMALL_STRUCT_2B (FFI_TYPE_LAST + 2)
  2908. #define FFI_TYPE_SMALL_STRUCT_4B (FFI_TYPE_LAST + 3)
  2909. #define FFI_TYPE_MS_STRUCT (FFI_TYPE_LAST + 4)
  2910. #if defined (X86_64) || defined(X86_WIN64) \
  2911. || (defined (__x86_64__) && defined (X86_DARWIN))
  2912. # define FFI_TRAMPOLINE_SIZE 24
  2913. # define FFI_NATIVE_RAW_API 0
  2914. #else
  2915. # define FFI_TRAMPOLINE_SIZE 12
  2916. # define FFI_NATIVE_RAW_API 1 /* x86 has native raw api support */
  2917. #endif
  2918. #endif
  2919. ====================File: configs/x86_64-pc-linux-gnu/include/ffitarget.h====================
  2920. /* -----------------------------------------------------------------*-C-*-
  2921. ffitarget.h - Copyright (c) 2012, 2014, 2018 Anthony Green
  2922. Copyright (c) 1996-2003, 2010 Red Hat, Inc.
  2923. Copyright (C) 2008 Free Software Foundation, Inc.
  2924. Target configuration macros for x86 and x86-64.
  2925. Permission is hereby granted, free of charge, to any person obtaining
  2926. a copy of this software and associated documentation files (the
  2927. ``Software''), to deal in the Software without restriction, including
  2928. without limitation the rights to use, copy, modify, merge, publish,
  2929. distribute, sublicense, and/or sell copies of the Software, and to
  2930. permit persons to whom the Software is furnished to do so, subject to
  2931. the following conditions:
  2932. The above copyright notice and this permission notice shall be included
  2933. in all copies or substantial portions of the Software.
  2934. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  2935. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2936. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  2937. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  2938. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  2939. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  2940. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  2941. DEALINGS IN THE SOFTWARE.
  2942. ----------------------------------------------------------------------- */
  2943. #ifndef LIBFFI_TARGET_H
  2944. #define LIBFFI_TARGET_H
  2945. #ifndef LIBFFI_H
  2946. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  2947. #endif
  2948. /* ---- System specific configurations ----------------------------------- */
  2949. /* For code common to all platforms on x86 and x86_64. */
  2950. #define X86_ANY
  2951. #if defined (X86_64) && defined (__i386__)
  2952. #undef X86_64
  2953. #define X86
  2954. #endif
  2955. #ifdef X86_WIN64
  2956. #define FFI_SIZEOF_ARG 8
  2957. #define USE_BUILTIN_FFS 0 /* not yet implemented in mingw-64 */
  2958. #endif
  2959. #define FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION
  2960. #ifndef _MSC_VER
  2961. #define FFI_TARGET_HAS_COMPLEX_TYPE
  2962. #endif
  2963. /* ---- Generic type definitions ----------------------------------------- */
  2964. #ifndef LIBFFI_ASM
  2965. #ifdef X86_WIN64
  2966. #ifdef _MSC_VER
  2967. typedef unsigned __int64 ffi_arg;
  2968. typedef __int64 ffi_sarg;
  2969. #else
  2970. typedef unsigned long long ffi_arg;
  2971. typedef long long ffi_sarg;
  2972. #endif
  2973. #else
  2974. #if defined __x86_64__ && defined __ILP32__
  2975. #define FFI_SIZEOF_ARG 8
  2976. #define FFI_SIZEOF_JAVA_RAW 4
  2977. typedef unsigned long long ffi_arg;
  2978. typedef long long ffi_sarg;
  2979. #else
  2980. typedef unsigned long ffi_arg;
  2981. typedef signed long ffi_sarg;
  2982. #endif
  2983. #endif
  2984. typedef enum ffi_abi {
  2985. #if defined(X86_WIN64)
  2986. FFI_FIRST_ABI = 0,
  2987. FFI_WIN64, /* sizeof(long double) == 8 - microsoft compilers */
  2988. FFI_GNUW64, /* sizeof(long double) == 16 - GNU compilers */
  2989. FFI_LAST_ABI,
  2990. #ifdef __GNUC__
  2991. FFI_DEFAULT_ABI = FFI_GNUW64
  2992. #else
  2993. FFI_DEFAULT_ABI = FFI_WIN64
  2994. #endif
  2995. #elif defined(X86_64) || (defined (__x86_64__) && defined (X86_DARWIN))
  2996. FFI_FIRST_ABI = 1,
  2997. FFI_UNIX64,
  2998. FFI_WIN64,
  2999. FFI_EFI64 = FFI_WIN64,
  3000. FFI_GNUW64,
  3001. FFI_LAST_ABI,
  3002. FFI_DEFAULT_ABI = FFI_UNIX64
  3003. #elif defined(X86_WIN32)
  3004. FFI_FIRST_ABI = 0,
  3005. FFI_SYSV = 1,
  3006. FFI_STDCALL = 2,
  3007. FFI_THISCALL = 3,
  3008. FFI_FASTCALL = 4,
  3009. FFI_MS_CDECL = 5,
  3010. FFI_PASCAL = 6,
  3011. FFI_REGISTER = 7,
  3012. FFI_LAST_ABI,
  3013. FFI_DEFAULT_ABI = FFI_MS_CDECL
  3014. #else
  3015. FFI_FIRST_ABI = 0,
  3016. FFI_SYSV = 1,
  3017. FFI_THISCALL = 3,
  3018. FFI_FASTCALL = 4,
  3019. FFI_STDCALL = 5,
  3020. FFI_PASCAL = 6,
  3021. FFI_REGISTER = 7,
  3022. FFI_MS_CDECL = 8,
  3023. FFI_LAST_ABI,
  3024. FFI_DEFAULT_ABI = FFI_SYSV
  3025. #endif
  3026. } ffi_abi;
  3027. #endif
  3028. /* ---- Definitions for closures ----------------------------------------- */
  3029. #define FFI_CLOSURES 1
  3030. #define FFI_GO_CLOSURES 1
  3031. #define FFI_TYPE_SMALL_STRUCT_1B (FFI_TYPE_LAST + 1)
  3032. #define FFI_TYPE_SMALL_STRUCT_2B (FFI_TYPE_LAST + 2)
  3033. #define FFI_TYPE_SMALL_STRUCT_4B (FFI_TYPE_LAST + 3)
  3034. #define FFI_TYPE_MS_STRUCT (FFI_TYPE_LAST + 4)
  3035. #if defined (X86_64) || defined(X86_WIN64) \
  3036. || (defined (__x86_64__) && defined (X86_DARWIN))
  3037. # define FFI_TRAMPOLINE_SIZE 24
  3038. # define FFI_NATIVE_RAW_API 0
  3039. #else
  3040. # define FFI_TRAMPOLINE_SIZE 12
  3041. # define FFI_NATIVE_RAW_API 1 /* x86 has native raw api support */
  3042. #endif
  3043. #endif
  3044. ====================File: src/aarch64/ffi.c====================
  3045. /* Copyright (c) 2009, 2010, 2011, 2012 ARM Ltd.
  3046. Permission is hereby granted, free of charge, to any person obtaining
  3047. a copy of this software and associated documentation files (the
  3048. ``Software''), to deal in the Software without restriction, including
  3049. without limitation the rights to use, copy, modify, merge, publish,
  3050. distribute, sublicense, and/or sell copies of the Software, and to
  3051. permit persons to whom the Software is furnished to do so, subject to
  3052. the following conditions:
  3053. The above copyright notice and this permission notice shall be
  3054. included in all copies or substantial portions of the Software.
  3055. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  3056. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  3057. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  3058. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  3059. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  3060. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  3061. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  3062. #if defined(__aarch64__) || defined(__arm64__)|| defined (_M_ARM64)
  3063. #include <stdio.h>
  3064. #include <stdlib.h>
  3065. #include <stdint.h>
  3066. #include <fficonfig.h>
  3067. #include <ffi.h>
  3068. #include <ffi_common.h>
  3069. #include "internal.h"
  3070. #ifdef _M_ARM64
  3071. #include <windows.h> /* FlushInstructionCache */
  3072. #endif
  3073. /* Force FFI_TYPE_LONGDOUBLE to be different than FFI_TYPE_DOUBLE;
  3074. all further uses in this file will refer to the 128-bit type. */
  3075. #if FFI_TYPE_DOUBLE != FFI_TYPE_LONGDOUBLE
  3076. # if FFI_TYPE_LONGDOUBLE != 4
  3077. # error FFI_TYPE_LONGDOUBLE out of date
  3078. # endif
  3079. #else
  3080. # undef FFI_TYPE_LONGDOUBLE
  3081. # define FFI_TYPE_LONGDOUBLE 4
  3082. #endif
  3083. union _d
  3084. {
  3085. UINT64 d;
  3086. UINT32 s[2];
  3087. };
  3088. struct _v
  3089. {
  3090. union _d d[2] __attribute__((aligned(16)));
  3091. };
  3092. struct call_context
  3093. {
  3094. struct _v v[N_V_ARG_REG];
  3095. UINT64 x[N_X_ARG_REG];
  3096. };
  3097. #if FFI_EXEC_TRAMPOLINE_TABLE
  3098. #ifdef __MACH__
  3099. #include <mach/vm_param.h>
  3100. #endif
  3101. #else
  3102. #if defined (__clang__) && defined (__APPLE__)
  3103. extern void sys_icache_invalidate (void *start, size_t len);
  3104. #endif
  3105. static inline void
  3106. ffi_clear_cache (void *start, void *end)
  3107. {
  3108. #if defined (__clang__) && defined (__APPLE__)
  3109. sys_icache_invalidate (start, (char *)end - (char *)start);
  3110. #elif defined (__GNUC__)
  3111. __builtin___clear_cache (start, end);
  3112. #elif defined (_M_ARM64)
  3113. FlushInstructionCache(GetCurrentProcess(), start, (char*)end - (char*)start);
  3114. #else
  3115. #error "Missing builtin to flush instruction cache"
  3116. #endif
  3117. }
  3118. #endif
  3119. /* A subroutine of is_vfp_type. Given a structure type, return the type code
  3120. of the first non-structure element. Recurse for structure elements.
  3121. Return -1 if the structure is in fact empty, i.e. no nested elements. */
  3122. static int
  3123. is_hfa0 (const ffi_type *ty)
  3124. {
  3125. ffi_type **elements = ty->elements;
  3126. int i, ret = -1;
  3127. if (elements != NULL)
  3128. for (i = 0; elements[i]; ++i)
  3129. {
  3130. ret = elements[i]->type;
  3131. if (ret == FFI_TYPE_STRUCT || ret == FFI_TYPE_COMPLEX)
  3132. {
  3133. ret = is_hfa0 (elements[i]);
  3134. if (ret < 0)
  3135. continue;
  3136. }
  3137. break;
  3138. }
  3139. return ret;
  3140. }
  3141. /* A subroutine of is_vfp_type. Given a structure type, return true if all
  3142. of the non-structure elements are the same as CANDIDATE. */
  3143. static int
  3144. is_hfa1 (const ffi_type *ty, int candidate)
  3145. {
  3146. ffi_type **elements = ty->elements;
  3147. int i;
  3148. if (elements != NULL)
  3149. for (i = 0; elements[i]; ++i)
  3150. {
  3151. int t = elements[i]->type;
  3152. if (t == FFI_TYPE_STRUCT || t == FFI_TYPE_COMPLEX)
  3153. {
  3154. if (!is_hfa1 (elements[i], candidate))
  3155. return 0;
  3156. }
  3157. else if (t != candidate)
  3158. return 0;
  3159. }
  3160. return 1;
  3161. }
  3162. /* Determine if TY may be allocated to the FP registers. This is both an
  3163. fp scalar type as well as an homogenous floating point aggregate (HFA).
  3164. That is, a structure consisting of 1 to 4 members of all the same type,
  3165. where that type is an fp scalar.
  3166. Returns non-zero iff TY is an HFA. The result is the AARCH64_RET_*
  3167. constant for the type. */
  3168. static int
  3169. is_vfp_type (const ffi_type *ty)
  3170. {
  3171. ffi_type **elements;
  3172. int candidate, i;
  3173. size_t size, ele_count;
  3174. /* Quickest tests first. */
  3175. candidate = ty->type;
  3176. switch (candidate)
  3177. {
  3178. default:
  3179. return 0;
  3180. case FFI_TYPE_FLOAT:
  3181. case FFI_TYPE_DOUBLE:
  3182. case FFI_TYPE_LONGDOUBLE:
  3183. ele_count = 1;
  3184. goto done;
  3185. case FFI_TYPE_COMPLEX:
  3186. candidate = ty->elements[0]->type;
  3187. switch (candidate)
  3188. {
  3189. case FFI_TYPE_FLOAT:
  3190. case FFI_TYPE_DOUBLE:
  3191. case FFI_TYPE_LONGDOUBLE:
  3192. ele_count = 2;
  3193. goto done;
  3194. }
  3195. return 0;
  3196. case FFI_TYPE_STRUCT:
  3197. break;
  3198. }
  3199. /* No HFA types are smaller than 4 bytes, or larger than 64 bytes. */
  3200. size = ty->size;
  3201. if (size < 4 || size > 64)
  3202. return 0;
  3203. /* Find the type of the first non-structure member. */
  3204. elements = ty->elements;
  3205. candidate = elements[0]->type;
  3206. if (candidate == FFI_TYPE_STRUCT || candidate == FFI_TYPE_COMPLEX)
  3207. {
  3208. for (i = 0; ; ++i)
  3209. {
  3210. candidate = is_hfa0 (elements[i]);
  3211. if (candidate >= 0)
  3212. break;
  3213. }
  3214. }
  3215. /* If the first member is not a floating point type, it's not an HFA.
  3216. Also quickly re-check the size of the structure. */
  3217. switch (candidate)
  3218. {
  3219. case FFI_TYPE_FLOAT:
  3220. ele_count = size / sizeof(float);
  3221. if (size != ele_count * sizeof(float))
  3222. return 0;
  3223. break;
  3224. case FFI_TYPE_DOUBLE:
  3225. ele_count = size / sizeof(double);
  3226. if (size != ele_count * sizeof(double))
  3227. return 0;
  3228. break;
  3229. case FFI_TYPE_LONGDOUBLE:
  3230. ele_count = size / sizeof(long double);
  3231. if (size != ele_count * sizeof(long double))
  3232. return 0;
  3233. break;
  3234. default:
  3235. return 0;
  3236. }
  3237. if (ele_count > 4)
  3238. return 0;
  3239. /* Finally, make sure that all scalar elements are the same type. */
  3240. for (i = 0; elements[i]; ++i)
  3241. {
  3242. int t = elements[i]->type;
  3243. if (t == FFI_TYPE_STRUCT || t == FFI_TYPE_COMPLEX)
  3244. {
  3245. if (!is_hfa1 (elements[i], candidate))
  3246. return 0;
  3247. }
  3248. else if (t != candidate)
  3249. return 0;
  3250. }
  3251. /* All tests succeeded. Encode the result. */
  3252. done:
  3253. return candidate * 4 + (4 - (int)ele_count);
  3254. }
  3255. /* Representation of the procedure call argument marshalling
  3256. state.
  3257. The terse state variable names match the names used in the AARCH64
  3258. PCS. */
  3259. struct arg_state
  3260. {
  3261. unsigned ngrn; /* Next general-purpose register number. */
  3262. unsigned nsrn; /* Next vector register number. */
  3263. size_t nsaa; /* Next stack offset. */
  3264. #if defined (__APPLE__)
  3265. unsigned allocating_variadic;
  3266. #endif
  3267. };
  3268. /* Initialize a procedure call argument marshalling state. */
  3269. static void
  3270. arg_init (struct arg_state *state)
  3271. {
  3272. state->ngrn = 0;
  3273. state->nsrn = 0;
  3274. state->nsaa = 0;
  3275. #if defined (__APPLE__)
  3276. state->allocating_variadic = 0;
  3277. #endif
  3278. }
  3279. /* Allocate an aligned slot on the stack and return a pointer to it. */
  3280. static void *
  3281. allocate_to_stack (struct arg_state *state, void *stack,
  3282. size_t alignment, size_t size)
  3283. {
  3284. size_t nsaa = state->nsaa;
  3285. /* Round up the NSAA to the larger of 8 or the natural
  3286. alignment of the argument's type. */
  3287. #if defined (__APPLE__)
  3288. if (state->allocating_variadic && alignment < 8)
  3289. alignment = 8;
  3290. #else
  3291. if (alignment < 8)
  3292. alignment = 8;
  3293. #endif
  3294. nsaa = FFI_ALIGN (nsaa, alignment);
  3295. state->nsaa = nsaa + size;
  3296. return (char *)stack + nsaa;
  3297. }
  3298. static ffi_arg
  3299. extend_integer_type (void *source, int type)
  3300. {
  3301. switch (type)
  3302. {
  3303. case FFI_TYPE_UINT8:
  3304. return *(UINT8 *) source;
  3305. case FFI_TYPE_SINT8:
  3306. return *(SINT8 *) source;
  3307. case FFI_TYPE_UINT16:
  3308. return *(UINT16 *) source;
  3309. case FFI_TYPE_SINT16:
  3310. return *(SINT16 *) source;
  3311. case FFI_TYPE_UINT32:
  3312. return *(UINT32 *) source;
  3313. case FFI_TYPE_INT:
  3314. case FFI_TYPE_SINT32:
  3315. return *(SINT32 *) source;
  3316. case FFI_TYPE_UINT64:
  3317. case FFI_TYPE_SINT64:
  3318. return *(UINT64 *) source;
  3319. break;
  3320. case FFI_TYPE_POINTER:
  3321. return *(uintptr_t *) source;
  3322. default:
  3323. abort();
  3324. }
  3325. }
  3326. #if defined(_MSC_VER)
  3327. void extend_hfa_type (void *dest, void *src, int h);
  3328. #else
  3329. static void
  3330. extend_hfa_type (void *dest, void *src, int h)
  3331. {
  3332. ssize_t f = h - AARCH64_RET_S4;
  3333. void *x0;
  3334. asm volatile (
  3335. "adr %0, 0f\n"
  3336. " add %0, %0, %1\n"
  3337. " br %0\n"
  3338. "0: ldp s16, s17, [%3]\n" /* S4 */
  3339. " ldp s18, s19, [%3, #8]\n"
  3340. " b 4f\n"
  3341. " ldp s16, s17, [%3]\n" /* S3 */
  3342. " ldr s18, [%3, #8]\n"
  3343. " b 3f\n"
  3344. " ldp s16, s17, [%3]\n" /* S2 */
  3345. " b 2f\n"
  3346. " nop\n"
  3347. " ldr s16, [%3]\n" /* S1 */
  3348. " b 1f\n"
  3349. " nop\n"
  3350. " ldp d16, d17, [%3]\n" /* D4 */
  3351. " ldp d18, d19, [%3, #16]\n"
  3352. " b 4f\n"
  3353. " ldp d16, d17, [%3]\n" /* D3 */
  3354. " ldr d18, [%3, #16]\n"
  3355. " b 3f\n"
  3356. " ldp d16, d17, [%3]\n" /* D2 */
  3357. " b 2f\n"
  3358. " nop\n"
  3359. " ldr d16, [%3]\n" /* D1 */
  3360. " b 1f\n"
  3361. " nop\n"
  3362. " ldp q16, q17, [%3]\n" /* Q4 */
  3363. " ldp q18, q19, [%3, #32]\n"
  3364. " b 4f\n"
  3365. " ldp q16, q17, [%3]\n" /* Q3 */
  3366. " ldr q18, [%3, #32]\n"
  3367. " b 3f\n"
  3368. " ldp q16, q17, [%3]\n" /* Q2 */
  3369. " b 2f\n"
  3370. " nop\n"
  3371. " ldr q16, [%3]\n" /* Q1 */
  3372. " b 1f\n"
  3373. "4: str q19, [%2, #48]\n"
  3374. "3: str q18, [%2, #32]\n"
  3375. "2: str q17, [%2, #16]\n"
  3376. "1: str q16, [%2]"
  3377. : "=&r"(x0)
  3378. : "r"(f * 12), "r"(dest), "r"(src)
  3379. : "memory", "v16", "v17", "v18", "v19");
  3380. }
  3381. #endif
  3382. #if defined(_MSC_VER)
  3383. void* compress_hfa_type (void *dest, void *src, int h);
  3384. #else
  3385. static void *
  3386. compress_hfa_type (void *dest, void *reg, int h)
  3387. {
  3388. switch (h)
  3389. {
  3390. case AARCH64_RET_S1:
  3391. if (dest == reg)
  3392. {
  3393. #ifdef __AARCH64EB__
  3394. dest += 12;
  3395. #endif
  3396. }
  3397. else
  3398. *(float *)dest = *(float *)reg;
  3399. break;
  3400. case AARCH64_RET_S2:
  3401. asm ("ldp q16, q17, [%1]\n\t"
  3402. "st2 { v16.s, v17.s }[0], [%0]"
  3403. : : "r"(dest), "r"(reg) : "memory", "v16", "v17");
  3404. break;
  3405. case AARCH64_RET_S3:
  3406. asm ("ldp q16, q17, [%1]\n\t"
  3407. "ldr q18, [%1, #32]\n\t"
  3408. "st3 { v16.s, v17.s, v18.s }[0], [%0]"
  3409. : : "r"(dest), "r"(reg) : "memory", "v16", "v17", "v18");
  3410. break;
  3411. case AARCH64_RET_S4:
  3412. asm ("ldp q16, q17, [%1]\n\t"
  3413. "ldp q18, q19, [%1, #32]\n\t"
  3414. "st4 { v16.s, v17.s, v18.s, v19.s }[0], [%0]"
  3415. : : "r"(dest), "r"(reg) : "memory", "v16", "v17", "v18", "v19");
  3416. break;
  3417. case AARCH64_RET_D1:
  3418. if (dest == reg)
  3419. {
  3420. #ifdef __AARCH64EB__
  3421. dest += 8;
  3422. #endif
  3423. }
  3424. else
  3425. *(double *)dest = *(double *)reg;
  3426. break;
  3427. case AARCH64_RET_D2:
  3428. asm ("ldp q16, q17, [%1]\n\t"
  3429. "st2 { v16.d, v17.d }[0], [%0]"
  3430. : : "r"(dest), "r"(reg) : "memory", "v16", "v17");
  3431. break;
  3432. case AARCH64_RET_D3:
  3433. asm ("ldp q16, q17, [%1]\n\t"
  3434. "ldr q18, [%1, #32]\n\t"
  3435. "st3 { v16.d, v17.d, v18.d }[0], [%0]"
  3436. : : "r"(dest), "r"(reg) : "memory", "v16", "v17", "v18");
  3437. break;
  3438. case AARCH64_RET_D4:
  3439. asm ("ldp q16, q17, [%1]\n\t"
  3440. "ldp q18, q19, [%1, #32]\n\t"
  3441. "st4 { v16.d, v17.d, v18.d, v19.d }[0], [%0]"
  3442. : : "r"(dest), "r"(reg) : "memory", "v16", "v17", "v18", "v19");
  3443. break;
  3444. default:
  3445. if (dest != reg)
  3446. return memcpy (dest, reg, 16 * (4 - (h & 3)));
  3447. break;
  3448. }
  3449. return dest;
  3450. }
  3451. #endif
  3452. /* Either allocate an appropriate register for the argument type, or if
  3453. none are available, allocate a stack slot and return a pointer
  3454. to the allocated space. */
  3455. static void *
  3456. allocate_int_to_reg_or_stack (struct call_context *context,
  3457. struct arg_state *state,
  3458. void *stack, size_t size)
  3459. {
  3460. if (state->ngrn < N_X_ARG_REG)
  3461. return &context->x[state->ngrn++];
  3462. state->ngrn = N_X_ARG_REG;
  3463. return allocate_to_stack (state, stack, size, size);
  3464. }
  3465. ffi_status FFI_HIDDEN
  3466. ffi_prep_cif_machdep (ffi_cif *cif)
  3467. {
  3468. ffi_type *rtype = cif->rtype;
  3469. size_t bytes = cif->bytes;
  3470. int flags, i, n;
  3471. switch (rtype->type)
  3472. {
  3473. case FFI_TYPE_VOID:
  3474. flags = AARCH64_RET_VOID;
  3475. break;
  3476. case FFI_TYPE_UINT8:
  3477. flags = AARCH64_RET_UINT8;
  3478. break;
  3479. case FFI_TYPE_UINT16:
  3480. flags = AARCH64_RET_UINT16;
  3481. break;
  3482. case FFI_TYPE_UINT32:
  3483. flags = AARCH64_RET_UINT32;
  3484. break;
  3485. case FFI_TYPE_SINT8:
  3486. flags = AARCH64_RET_SINT8;
  3487. break;
  3488. case FFI_TYPE_SINT16:
  3489. flags = AARCH64_RET_SINT16;
  3490. break;
  3491. case FFI_TYPE_INT:
  3492. case FFI_TYPE_SINT32:
  3493. flags = AARCH64_RET_SINT32;
  3494. break;
  3495. case FFI_TYPE_SINT64:
  3496. case FFI_TYPE_UINT64:
  3497. flags = AARCH64_RET_INT64;
  3498. break;
  3499. case FFI_TYPE_POINTER:
  3500. flags = (sizeof(void *) == 4 ? AARCH64_RET_UINT32 : AARCH64_RET_INT64);
  3501. break;
  3502. case FFI_TYPE_FLOAT:
  3503. case FFI_TYPE_DOUBLE:
  3504. case FFI_TYPE_LONGDOUBLE:
  3505. case FFI_TYPE_STRUCT:
  3506. case FFI_TYPE_COMPLEX:
  3507. flags = is_vfp_type (rtype);
  3508. if (flags == 0)
  3509. {
  3510. size_t s = rtype->size;
  3511. if (s > 16)
  3512. {
  3513. flags = AARCH64_RET_VOID | AARCH64_RET_IN_MEM;
  3514. bytes += 8;
  3515. }
  3516. else if (s == 16)
  3517. flags = AARCH64_RET_INT128;
  3518. else if (s == 8)
  3519. flags = AARCH64_RET_INT64;
  3520. else
  3521. flags = AARCH64_RET_INT128 | AARCH64_RET_NEED_COPY;
  3522. }
  3523. break;
  3524. default:
  3525. abort();
  3526. }
  3527. for (i = 0, n = cif->nargs; i < n; i++)
  3528. if (is_vfp_type (cif->arg_types[i]))
  3529. {
  3530. flags |= AARCH64_FLAG_ARG_V;
  3531. break;
  3532. }
  3533. /* Round the stack up to a multiple of the stack alignment requirement. */
  3534. cif->bytes = (unsigned) FFI_ALIGN(bytes, 16);
  3535. cif->flags = flags;
  3536. #if defined (__APPLE__)
  3537. cif->aarch64_nfixedargs = 0;
  3538. #endif
  3539. return FFI_OK;
  3540. }
  3541. #if defined (__APPLE__)
  3542. /* Perform Apple-specific cif processing for variadic calls */
  3543. ffi_status FFI_HIDDEN
  3544. ffi_prep_cif_machdep_var(ffi_cif *cif, unsigned int nfixedargs,
  3545. unsigned int ntotalargs)
  3546. {
  3547. ffi_status status = ffi_prep_cif_machdep (cif);
  3548. cif->aarch64_nfixedargs = nfixedargs;
  3549. return status;
  3550. }
  3551. #endif /* __APPLE__ */
  3552. extern void ffi_call_SYSV (struct call_context *context, void *frame,
  3553. void (*fn)(void), void *rvalue, int flags,
  3554. void *closure) FFI_HIDDEN;
  3555. /* Call a function with the provided arguments and capture the return
  3556. value. */
  3557. static void
  3558. ffi_call_int (ffi_cif *cif, void (*fn)(void), void *orig_rvalue,
  3559. void **avalue, void *closure)
  3560. {
  3561. struct call_context *context;
  3562. void *stack, *frame, *rvalue;
  3563. struct arg_state state;
  3564. size_t stack_bytes, rtype_size, rsize;
  3565. int i, nargs, flags;
  3566. ffi_type *rtype;
  3567. flags = cif->flags;
  3568. rtype = cif->rtype;
  3569. rtype_size = rtype->size;
  3570. stack_bytes = cif->bytes;
  3571. /* If the target function returns a structure via hidden pointer,
  3572. then we cannot allow a null rvalue. Otherwise, mash a null
  3573. rvalue to void return type. */
  3574. rsize = 0;
  3575. if (flags & AARCH64_RET_IN_MEM)
  3576. {
  3577. if (orig_rvalue == NULL)
  3578. rsize = rtype_size;
  3579. }
  3580. else if (orig_rvalue == NULL)
  3581. flags &= AARCH64_FLAG_ARG_V;
  3582. else if (flags & AARCH64_RET_NEED_COPY)
  3583. rsize = 16;
  3584. /* Allocate consectutive stack for everything we'll need. */
  3585. context = alloca (sizeof(struct call_context) + stack_bytes + 32 + rsize);
  3586. stack = context + 1;
  3587. frame = (void*)((uintptr_t)stack + (uintptr_t)stack_bytes);
  3588. rvalue = (rsize ? (void*)((uintptr_t)frame + 32) : orig_rvalue);
  3589. arg_init (&state);
  3590. for (i = 0, nargs = cif->nargs; i < nargs; i++)
  3591. {
  3592. ffi_type *ty = cif->arg_types[i];
  3593. size_t s = ty->size;
  3594. void *a = avalue[i];
  3595. int h, t;
  3596. t = ty->type;
  3597. switch (t)
  3598. {
  3599. case FFI_TYPE_VOID:
  3600. FFI_ASSERT (0);
  3601. break;
  3602. /* If the argument is a basic type the argument is allocated to an
  3603. appropriate register, or if none are available, to the stack. */
  3604. case FFI_TYPE_INT:
  3605. case FFI_TYPE_UINT8:
  3606. case FFI_TYPE_SINT8:
  3607. case FFI_TYPE_UINT16:
  3608. case FFI_TYPE_SINT16:
  3609. case FFI_TYPE_UINT32:
  3610. case FFI_TYPE_SINT32:
  3611. case FFI_TYPE_UINT64:
  3612. case FFI_TYPE_SINT64:
  3613. case FFI_TYPE_POINTER:
  3614. do_pointer:
  3615. {
  3616. ffi_arg ext = extend_integer_type (a, t);
  3617. if (state.ngrn < N_X_ARG_REG)
  3618. context->x[state.ngrn++] = ext;
  3619. else
  3620. {
  3621. void *d = allocate_to_stack (&state, stack, ty->alignment, s);
  3622. state.ngrn = N_X_ARG_REG;
  3623. /* Note that the default abi extends each argument
  3624. to a full 64-bit slot, while the iOS abi allocates
  3625. only enough space. */
  3626. #ifdef __APPLE__
  3627. memcpy(d, a, s);
  3628. #else
  3629. *(ffi_arg *)d = ext;
  3630. #endif
  3631. }
  3632. }
  3633. break;
  3634. case FFI_TYPE_FLOAT:
  3635. case FFI_TYPE_DOUBLE:
  3636. case FFI_TYPE_LONGDOUBLE:
  3637. case FFI_TYPE_STRUCT:
  3638. case FFI_TYPE_COMPLEX:
  3639. {
  3640. void *dest;
  3641. h = is_vfp_type (ty);
  3642. if (h)
  3643. {
  3644. int elems = 4 - (h & 3);
  3645. #ifdef _M_ARM64 /* for handling armasm calling convention */
  3646. if (cif->is_variadic)
  3647. {
  3648. if (state.ngrn + elems <= N_X_ARG_REG)
  3649. {
  3650. dest = &context->x[state.ngrn];
  3651. state.ngrn += elems;
  3652. extend_hfa_type(dest, a, h);
  3653. break;
  3654. }
  3655. state.nsrn = N_X_ARG_REG;
  3656. dest = allocate_to_stack(&state, stack, ty->alignment, s);
  3657. }
  3658. else
  3659. {
  3660. #endif /* for handling armasm calling convention */
  3661. if (state.nsrn + elems <= N_V_ARG_REG)
  3662. {
  3663. dest = &context->v[state.nsrn];
  3664. state.nsrn += elems;
  3665. extend_hfa_type (dest, a, h);
  3666. break;
  3667. }
  3668. state.nsrn = N_V_ARG_REG;
  3669. dest = allocate_to_stack (&state, stack, ty->alignment, s);
  3670. #ifdef _M_ARM64 /* for handling armasm calling convention */
  3671. }
  3672. #endif /* for handling armasm calling convention */
  3673. }
  3674. else if (s > 16)
  3675. {
  3676. /* If the argument is a composite type that is larger than 16
  3677. bytes, then the argument has been copied to memory, and
  3678. the argument is replaced by a pointer to the copy. */
  3679. a = &avalue[i];
  3680. t = FFI_TYPE_POINTER;
  3681. s = sizeof (void *);
  3682. goto do_pointer;
  3683. }
  3684. else
  3685. {
  3686. size_t n = (s + 7) / 8;
  3687. if (state.ngrn + n <= N_X_ARG_REG)
  3688. {
  3689. /* If the argument is a composite type and the size in
  3690. double-words is not more than the number of available
  3691. X registers, then the argument is copied into
  3692. consecutive X registers. */
  3693. dest = &context->x[state.ngrn];
  3694. state.ngrn += (unsigned int)n;
  3695. }
  3696. else
  3697. {
  3698. /* Otherwise, there are insufficient X registers. Further
  3699. X register allocations are prevented, the NSAA is
  3700. adjusted and the argument is copied to memory at the
  3701. adjusted NSAA. */
  3702. state.ngrn = N_X_ARG_REG;
  3703. dest = allocate_to_stack (&state, stack, ty->alignment, s);
  3704. }
  3705. }
  3706. memcpy (dest, a, s);
  3707. }
  3708. break;
  3709. default:
  3710. abort();
  3711. }
  3712. #if defined (__APPLE__)
  3713. if (i + 1 == cif->aarch64_nfixedargs)
  3714. {
  3715. state.ngrn = N_X_ARG_REG;
  3716. state.nsrn = N_V_ARG_REG;
  3717. state.allocating_variadic = 1;
  3718. }
  3719. #endif
  3720. }
  3721. ffi_call_SYSV (context, frame, fn, rvalue, flags, closure);
  3722. if (flags & AARCH64_RET_NEED_COPY)
  3723. memcpy (orig_rvalue, rvalue, rtype_size);
  3724. }
  3725. void
  3726. ffi_call (ffi_cif *cif, void (*fn) (void), void *rvalue, void **avalue)
  3727. {
  3728. ffi_call_int (cif, fn, rvalue, avalue, NULL);
  3729. }
  3730. #ifdef FFI_GO_CLOSURES
  3731. void
  3732. ffi_call_go (ffi_cif *cif, void (*fn) (void), void *rvalue,
  3733. void **avalue, void *closure)
  3734. {
  3735. ffi_call_int (cif, fn, rvalue, avalue, closure);
  3736. }
  3737. #endif /* FFI_GO_CLOSURES */
  3738. /* Build a trampoline. */
  3739. extern void ffi_closure_SYSV (void) FFI_HIDDEN;
  3740. extern void ffi_closure_SYSV_V (void) FFI_HIDDEN;
  3741. ffi_status
  3742. ffi_prep_closure_loc (ffi_closure *closure,
  3743. ffi_cif* cif,
  3744. void (*fun)(ffi_cif*,void*,void**,void*),
  3745. void *user_data,
  3746. void *codeloc)
  3747. {
  3748. if (cif->abi != FFI_SYSV)
  3749. return FFI_BAD_ABI;
  3750. void (*start)(void);
  3751. if (cif->flags & AARCH64_FLAG_ARG_V)
  3752. start = ffi_closure_SYSV_V;
  3753. else
  3754. start = ffi_closure_SYSV;
  3755. #if FFI_EXEC_TRAMPOLINE_TABLE
  3756. #ifdef __MACH__
  3757. void **config = (void **)((uint8_t *)codeloc - PAGE_MAX_SIZE);
  3758. config[0] = closure;
  3759. config[1] = start;
  3760. #endif
  3761. #else
  3762. static const unsigned char trampoline[16] = {
  3763. 0x90, 0x00, 0x00, 0x58, /* ldr x16, tramp+16 */
  3764. 0xf1, 0xff, 0xff, 0x10, /* adr x17, tramp+0 */
  3765. 0x00, 0x02, 0x1f, 0xd6 /* br x16 */
  3766. };
  3767. char *tramp = closure->tramp;
  3768. memcpy (tramp, trampoline, sizeof(trampoline));
  3769. *(UINT64 *)(tramp + 16) = (uintptr_t)start;
  3770. ffi_clear_cache(tramp, tramp + FFI_TRAMPOLINE_SIZE);
  3771. /* Also flush the cache for code mapping. */
  3772. #ifdef _M_ARM64
  3773. // Not using dlmalloc.c for Windows ARM64 builds
  3774. // so calling ffi_data_to_code_pointer() isn't necessary
  3775. unsigned char *tramp_code = tramp;
  3776. #else
  3777. unsigned char *tramp_code = ffi_data_to_code_pointer (tramp);
  3778. #endif
  3779. ffi_clear_cache (tramp_code, tramp_code + FFI_TRAMPOLINE_SIZE);
  3780. #endif
  3781. closure->cif = cif;
  3782. closure->fun = fun;
  3783. closure->user_data = user_data;
  3784. return FFI_OK;
  3785. }
  3786. #ifdef FFI_GO_CLOSURES
  3787. extern void ffi_go_closure_SYSV (void) FFI_HIDDEN;
  3788. extern void ffi_go_closure_SYSV_V (void) FFI_HIDDEN;
  3789. ffi_status
  3790. ffi_prep_go_closure (ffi_go_closure *closure, ffi_cif* cif,
  3791. void (*fun)(ffi_cif*,void*,void**,void*))
  3792. {
  3793. void (*start)(void);
  3794. if (cif->abi != FFI_SYSV)
  3795. return FFI_BAD_ABI;
  3796. if (cif->flags & AARCH64_FLAG_ARG_V)
  3797. start = ffi_go_closure_SYSV_V;
  3798. else
  3799. start = ffi_go_closure_SYSV;
  3800. closure->tramp = start;
  3801. closure->cif = cif;
  3802. closure->fun = fun;
  3803. return FFI_OK;
  3804. }
  3805. #endif /* FFI_GO_CLOSURES */
  3806. /* Primary handler to setup and invoke a function within a closure.
  3807. A closure when invoked enters via the assembler wrapper
  3808. ffi_closure_SYSV(). The wrapper allocates a call context on the
  3809. stack, saves the interesting registers (from the perspective of
  3810. the calling convention) into the context then passes control to
  3811. ffi_closure_SYSV_inner() passing the saved context and a pointer to
  3812. the stack at the point ffi_closure_SYSV() was invoked.
  3813. On the return path the assembler wrapper will reload call context
  3814. registers.
  3815. ffi_closure_SYSV_inner() marshalls the call context into ffi value
  3816. descriptors, invokes the wrapped function, then marshalls the return
  3817. value back into the call context. */
  3818. int FFI_HIDDEN
  3819. ffi_closure_SYSV_inner (ffi_cif *cif,
  3820. void (*fun)(ffi_cif*,void*,void**,void*),
  3821. void *user_data,
  3822. struct call_context *context,
  3823. void *stack, void *rvalue, void *struct_rvalue)
  3824. {
  3825. void **avalue = (void**) alloca (cif->nargs * sizeof (void*));
  3826. int i, h, nargs, flags;
  3827. struct arg_state state;
  3828. arg_init (&state);
  3829. for (i = 0, nargs = cif->nargs; i < nargs; i++)
  3830. {
  3831. ffi_type *ty = cif->arg_types[i];
  3832. int t = ty->type;
  3833. size_t n, s = ty->size;
  3834. switch (t)
  3835. {
  3836. case FFI_TYPE_VOID:
  3837. FFI_ASSERT (0);
  3838. break;
  3839. case FFI_TYPE_INT:
  3840. case FFI_TYPE_UINT8:
  3841. case FFI_TYPE_SINT8:
  3842. case FFI_TYPE_UINT16:
  3843. case FFI_TYPE_SINT16:
  3844. case FFI_TYPE_UINT32:
  3845. case FFI_TYPE_SINT32:
  3846. case FFI_TYPE_UINT64:
  3847. case FFI_TYPE_SINT64:
  3848. case FFI_TYPE_POINTER:
  3849. avalue[i] = allocate_int_to_reg_or_stack (context, &state, stack, s);
  3850. break;
  3851. case FFI_TYPE_FLOAT:
  3852. case FFI_TYPE_DOUBLE:
  3853. case FFI_TYPE_LONGDOUBLE:
  3854. case FFI_TYPE_STRUCT:
  3855. case FFI_TYPE_COMPLEX:
  3856. h = is_vfp_type (ty);
  3857. if (h)
  3858. {
  3859. n = 4 - (h & 3);
  3860. #ifdef _M_ARM64 /* for handling armasm calling convention */
  3861. if (cif->is_variadic)
  3862. {
  3863. if (state.ngrn + n <= N_X_ARG_REG)
  3864. {
  3865. void *reg = &context->x[state.ngrn];
  3866. state.ngrn += (unsigned int)n;
  3867. /* Eeek! We need a pointer to the structure, however the
  3868. homogeneous float elements are being passed in individual
  3869. registers, therefore for float and double the structure
  3870. is not represented as a contiguous sequence of bytes in
  3871. our saved register context. We don't need the original
  3872. contents of the register storage, so we reformat the
  3873. structure into the same memory. */
  3874. avalue[i] = compress_hfa_type(reg, reg, h);
  3875. }
  3876. else
  3877. {
  3878. state.ngrn = N_X_ARG_REG;
  3879. state.nsrn = N_V_ARG_REG;
  3880. avalue[i] = allocate_to_stack(&state, stack,
  3881. ty->alignment, s);
  3882. }
  3883. }
  3884. else
  3885. {
  3886. #endif /* for handling armasm calling convention */
  3887. if (state.nsrn + n <= N_V_ARG_REG)
  3888. {
  3889. void *reg = &context->v[state.nsrn];
  3890. state.nsrn += (unsigned int)n;
  3891. avalue[i] = compress_hfa_type(reg, reg, h);
  3892. }
  3893. else
  3894. {
  3895. state.nsrn = N_V_ARG_REG;
  3896. avalue[i] = allocate_to_stack(&state, stack,
  3897. ty->alignment, s);
  3898. }
  3899. #ifdef _M_ARM64 /* for handling armasm calling convention */
  3900. }
  3901. #endif /* for handling armasm calling convention */
  3902. }
  3903. else if (s > 16)
  3904. {
  3905. /* Replace Composite type of size greater than 16 with a
  3906. pointer. */
  3907. avalue[i] = *(void **)
  3908. allocate_int_to_reg_or_stack (context, &state, stack,
  3909. sizeof (void *));
  3910. }
  3911. else
  3912. {
  3913. n = (s + 7) / 8;
  3914. if (state.ngrn + n <= N_X_ARG_REG)
  3915. {
  3916. avalue[i] = &context->x[state.ngrn];
  3917. state.ngrn += (unsigned int)n;
  3918. }
  3919. else
  3920. {
  3921. state.ngrn = N_X_ARG_REG;
  3922. avalue[i] = allocate_to_stack(&state, stack,
  3923. ty->alignment, s);
  3924. }
  3925. }
  3926. break;
  3927. default:
  3928. abort();
  3929. }
  3930. #if defined (__APPLE__)
  3931. if (i + 1 == cif->aarch64_nfixedargs)
  3932. {
  3933. state.ngrn = N_X_ARG_REG;
  3934. state.nsrn = N_V_ARG_REG;
  3935. state.allocating_variadic = 1;
  3936. }
  3937. #endif
  3938. }
  3939. flags = cif->flags;
  3940. if (flags & AARCH64_RET_IN_MEM)
  3941. rvalue = struct_rvalue;
  3942. fun (cif, rvalue, avalue, user_data);
  3943. return flags;
  3944. }
  3945. #endif /* (__aarch64__) || defined(__arm64__)|| defined (_M_ARM64)*/
  3946. ====================File: src/aarch64/ffitarget.h====================
  3947. /* Copyright (c) 2009, 2010, 2011, 2012 ARM Ltd.
  3948. Permission is hereby granted, free of charge, to any person obtaining
  3949. a copy of this software and associated documentation files (the
  3950. ``Software''), to deal in the Software without restriction, including
  3951. without limitation the rights to use, copy, modify, merge, publish,
  3952. distribute, sublicense, and/or sell copies of the Software, and to
  3953. permit persons to whom the Software is furnished to do so, subject to
  3954. the following conditions:
  3955. The above copyright notice and this permission notice shall be
  3956. included in all copies or substantial portions of the Software.
  3957. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  3958. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  3959. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  3960. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  3961. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  3962. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  3963. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  3964. #ifndef LIBFFI_TARGET_H
  3965. #define LIBFFI_TARGET_H
  3966. #ifndef LIBFFI_H
  3967. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  3968. #endif
  3969. #ifndef LIBFFI_ASM
  3970. #ifdef __ILP32__
  3971. #define FFI_SIZEOF_ARG 8
  3972. #define FFI_SIZEOF_JAVA_RAW 4
  3973. typedef unsigned long long ffi_arg;
  3974. typedef signed long long ffi_sarg;
  3975. #elif defined(_M_ARM64)
  3976. #define FFI_SIZEOF_ARG 8
  3977. typedef unsigned long long ffi_arg;
  3978. typedef signed long long ffi_sarg;
  3979. #else
  3980. typedef unsigned long ffi_arg;
  3981. typedef signed long ffi_sarg;
  3982. #endif
  3983. typedef enum ffi_abi
  3984. {
  3985. FFI_FIRST_ABI = 0,
  3986. FFI_SYSV,
  3987. FFI_LAST_ABI,
  3988. FFI_DEFAULT_ABI = FFI_SYSV
  3989. } ffi_abi;
  3990. #endif
  3991. /* ---- Definitions for closures ----------------------------------------- */
  3992. #define FFI_CLOSURES 1
  3993. #define FFI_NATIVE_RAW_API 0
  3994. #if defined (FFI_EXEC_TRAMPOLINE_TABLE) && FFI_EXEC_TRAMPOLINE_TABLE
  3995. #ifdef __MACH__
  3996. #define FFI_TRAMPOLINE_SIZE 16
  3997. #define FFI_TRAMPOLINE_CLOSURE_OFFSET 16
  3998. #else
  3999. #error "No trampoline table implementation"
  4000. #endif
  4001. #else
  4002. #define FFI_TRAMPOLINE_SIZE 24
  4003. #define FFI_TRAMPOLINE_CLOSURE_OFFSET FFI_TRAMPOLINE_SIZE
  4004. #endif
  4005. #ifdef _M_ARM64
  4006. #define FFI_EXTRA_CIF_FIELDS unsigned is_variadic
  4007. #endif
  4008. /* ---- Internal ---- */
  4009. #if defined (__APPLE__)
  4010. #define FFI_TARGET_SPECIFIC_VARIADIC
  4011. #define FFI_EXTRA_CIF_FIELDS unsigned aarch64_nfixedargs
  4012. #elif !defined(_M_ARM64)
  4013. /* iOS and Windows reserve x18 for the system. Disable Go closures until
  4014. a new static chain is chosen. */
  4015. #define FFI_GO_CLOSURES 1
  4016. #endif
  4017. #ifndef _M_ARM64
  4018. /* No complex type on Windows */
  4019. #define FFI_TARGET_HAS_COMPLEX_TYPE
  4020. #endif
  4021. #endif
  4022. ====================File: src/aarch64/sysv.S====================
  4023. /* Copyright (c) 2009, 2010, 2011, 2012 ARM Ltd.
  4024. Permission is hereby granted, free of charge, to any person obtaining
  4025. a copy of this software and associated documentation files (the
  4026. ``Software''), to deal in the Software without restriction, including
  4027. without limitation the rights to use, copy, modify, merge, publish,
  4028. distribute, sublicense, and/or sell copies of the Software, and to
  4029. permit persons to whom the Software is furnished to do so, subject to
  4030. the following conditions:
  4031. The above copyright notice and this permission notice shall be
  4032. included in all copies or substantial portions of the Software.
  4033. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  4034. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  4035. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  4036. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  4037. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  4038. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  4039. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  4040. #if defined(__aarch64__) || defined(__arm64__)
  4041. #define LIBFFI_ASM
  4042. #include <fficonfig.h>
  4043. #include <ffi.h>
  4044. #include <ffi_cfi.h>
  4045. #include "internal.h"
  4046. #ifdef HAVE_MACHINE_ASM_H
  4047. #include <machine/asm.h>
  4048. #else
  4049. #ifdef __USER_LABEL_PREFIX__
  4050. #define CONCAT1(a, b) CONCAT2(a, b)
  4051. #define CONCAT2(a, b) a ## b
  4052. /* Use the right prefix for global labels. */
  4053. #define CNAME(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
  4054. #else
  4055. #define CNAME(x) x
  4056. #endif
  4057. #endif
  4058. #ifdef __AARCH64EB__
  4059. # define BE(X) X
  4060. #else
  4061. # define BE(X) 0
  4062. #endif
  4063. #ifdef __ILP32__
  4064. #define PTR_REG(n) w##n
  4065. #else
  4066. #define PTR_REG(n) x##n
  4067. #endif
  4068. #ifdef __ILP32__
  4069. #define PTR_SIZE 4
  4070. #else
  4071. #define PTR_SIZE 8
  4072. #endif
  4073. .text
  4074. .align 4
  4075. /* ffi_call_SYSV
  4076. extern void ffi_call_SYSV (void *stack, void *frame,
  4077. void (*fn)(void), void *rvalue,
  4078. int flags, void *closure);
  4079. Therefore on entry we have:
  4080. x0 stack
  4081. x1 frame
  4082. x2 fn
  4083. x3 rvalue
  4084. x4 flags
  4085. x5 closure
  4086. */
  4087. cfi_startproc
  4088. CNAME(ffi_call_SYSV):
  4089. /* Use a stack frame allocated by our caller. */
  4090. cfi_def_cfa(x1, 32);
  4091. stp x29, x30, [x1]
  4092. mov x29, x1
  4093. mov sp, x0
  4094. cfi_def_cfa_register(x29)
  4095. cfi_rel_offset (x29, 0)
  4096. cfi_rel_offset (x30, 8)
  4097. mov x9, x2 /* save fn */
  4098. mov x8, x3 /* install structure return */
  4099. #ifdef FFI_GO_CLOSURES
  4100. mov x18, x5 /* install static chain */
  4101. #endif
  4102. stp x3, x4, [x29, #16] /* save rvalue and flags */
  4103. /* Load the vector argument passing registers, if necessary. */
  4104. tbz w4, #AARCH64_FLAG_ARG_V_BIT, 1f
  4105. ldp q0, q1, [sp, #0]
  4106. ldp q2, q3, [sp, #32]
  4107. ldp q4, q5, [sp, #64]
  4108. ldp q6, q7, [sp, #96]
  4109. 1:
  4110. /* Load the core argument passing registers, including
  4111. the structure return pointer. */
  4112. ldp x0, x1, [sp, #16*N_V_ARG_REG + 0]
  4113. ldp x2, x3, [sp, #16*N_V_ARG_REG + 16]
  4114. ldp x4, x5, [sp, #16*N_V_ARG_REG + 32]
  4115. ldp x6, x7, [sp, #16*N_V_ARG_REG + 48]
  4116. /* Deallocate the context, leaving the stacked arguments. */
  4117. add sp, sp, #CALL_CONTEXT_SIZE
  4118. blr x9 /* call fn */
  4119. ldp x3, x4, [x29, #16] /* reload rvalue and flags */
  4120. /* Partially deconstruct the stack frame. */
  4121. mov sp, x29
  4122. cfi_def_cfa_register (sp)
  4123. ldp x29, x30, [x29]
  4124. /* Save the return value as directed. */
  4125. adr x5, 0f
  4126. and w4, w4, #AARCH64_RET_MASK
  4127. add x5, x5, x4, lsl #3
  4128. br x5
  4129. /* Note that each table entry is 2 insns, and thus 8 bytes.
  4130. For integer data, note that we're storing into ffi_arg
  4131. and therefore we want to extend to 64 bits; these types
  4132. have two consecutive entries allocated for them. */
  4133. .align 4
  4134. 0: ret /* VOID */
  4135. nop
  4136. 1: str x0, [x3] /* INT64 */
  4137. ret
  4138. 2: stp x0, x1, [x3] /* INT128 */
  4139. ret
  4140. 3: brk #1000 /* UNUSED */
  4141. ret
  4142. 4: brk #1000 /* UNUSED */
  4143. ret
  4144. 5: brk #1000 /* UNUSED */
  4145. ret
  4146. 6: brk #1000 /* UNUSED */
  4147. ret
  4148. 7: brk #1000 /* UNUSED */
  4149. ret
  4150. 8: st4 { v0.s, v1.s, v2.s, v3.s }[0], [x3] /* S4 */
  4151. ret
  4152. 9: st3 { v0.s, v1.s, v2.s }[0], [x3] /* S3 */
  4153. ret
  4154. 10: stp s0, s1, [x3] /* S2 */
  4155. ret
  4156. 11: str s0, [x3] /* S1 */
  4157. ret
  4158. 12: st4 { v0.d, v1.d, v2.d, v3.d }[0], [x3] /* D4 */
  4159. ret
  4160. 13: st3 { v0.d, v1.d, v2.d }[0], [x3] /* D3 */
  4161. ret
  4162. 14: stp d0, d1, [x3] /* D2 */
  4163. ret
  4164. 15: str d0, [x3] /* D1 */
  4165. ret
  4166. 16: str q3, [x3, #48] /* Q4 */
  4167. nop
  4168. 17: str q2, [x3, #32] /* Q3 */
  4169. nop
  4170. 18: stp q0, q1, [x3] /* Q2 */
  4171. ret
  4172. 19: str q0, [x3] /* Q1 */
  4173. ret
  4174. 20: uxtb w0, w0 /* UINT8 */
  4175. str x0, [x3]
  4176. 21: ret /* reserved */
  4177. nop
  4178. 22: uxth w0, w0 /* UINT16 */
  4179. str x0, [x3]
  4180. 23: ret /* reserved */
  4181. nop
  4182. 24: mov w0, w0 /* UINT32 */
  4183. str x0, [x3]
  4184. 25: ret /* reserved */
  4185. nop
  4186. 26: sxtb x0, w0 /* SINT8 */
  4187. str x0, [x3]
  4188. 27: ret /* reserved */
  4189. nop
  4190. 28: sxth x0, w0 /* SINT16 */
  4191. str x0, [x3]
  4192. 29: ret /* reserved */
  4193. nop
  4194. 30: sxtw x0, w0 /* SINT32 */
  4195. str x0, [x3]
  4196. 31: ret /* reserved */
  4197. nop
  4198. cfi_endproc
  4199. .globl CNAME(ffi_call_SYSV)
  4200. FFI_HIDDEN(CNAME(ffi_call_SYSV))
  4201. #ifdef __ELF__
  4202. .type CNAME(ffi_call_SYSV), #function
  4203. .size CNAME(ffi_call_SYSV), .-CNAME(ffi_call_SYSV)
  4204. #endif
  4205. /* ffi_closure_SYSV
  4206. Closure invocation glue. This is the low level code invoked directly by
  4207. the closure trampoline to setup and call a closure.
  4208. On entry x17 points to a struct ffi_closure, x16 has been clobbered
  4209. all other registers are preserved.
  4210. We allocate a call context and save the argument passing registers,
  4211. then invoked the generic C ffi_closure_SYSV_inner() function to do all
  4212. the real work, on return we load the result passing registers back from
  4213. the call context.
  4214. */
  4215. #define ffi_closure_SYSV_FS (8*2 + CALL_CONTEXT_SIZE + 64)
  4216. .align 4
  4217. CNAME(ffi_closure_SYSV_V):
  4218. cfi_startproc
  4219. stp x29, x30, [sp, #-ffi_closure_SYSV_FS]!
  4220. cfi_adjust_cfa_offset (ffi_closure_SYSV_FS)
  4221. cfi_rel_offset (x29, 0)
  4222. cfi_rel_offset (x30, 8)
  4223. /* Save the argument passing vector registers. */
  4224. stp q0, q1, [sp, #16 + 0]
  4225. stp q2, q3, [sp, #16 + 32]
  4226. stp q4, q5, [sp, #16 + 64]
  4227. stp q6, q7, [sp, #16 + 96]
  4228. b 0f
  4229. cfi_endproc
  4230. .globl CNAME(ffi_closure_SYSV_V)
  4231. FFI_HIDDEN(CNAME(ffi_closure_SYSV_V))
  4232. #ifdef __ELF__
  4233. .type CNAME(ffi_closure_SYSV_V), #function
  4234. .size CNAME(ffi_closure_SYSV_V), . - CNAME(ffi_closure_SYSV_V)
  4235. #endif
  4236. .align 4
  4237. cfi_startproc
  4238. CNAME(ffi_closure_SYSV):
  4239. stp x29, x30, [sp, #-ffi_closure_SYSV_FS]!
  4240. cfi_adjust_cfa_offset (ffi_closure_SYSV_FS)
  4241. cfi_rel_offset (x29, 0)
  4242. cfi_rel_offset (x30, 8)
  4243. 0:
  4244. mov x29, sp
  4245. /* Save the argument passing core registers. */
  4246. stp x0, x1, [sp, #16 + 16*N_V_ARG_REG + 0]
  4247. stp x2, x3, [sp, #16 + 16*N_V_ARG_REG + 16]
  4248. stp x4, x5, [sp, #16 + 16*N_V_ARG_REG + 32]
  4249. stp x6, x7, [sp, #16 + 16*N_V_ARG_REG + 48]
  4250. /* Load ffi_closure_inner arguments. */
  4251. ldp PTR_REG(0), PTR_REG(1), [x17, #FFI_TRAMPOLINE_CLOSURE_OFFSET] /* load cif, fn */
  4252. ldr PTR_REG(2), [x17, #FFI_TRAMPOLINE_CLOSURE_OFFSET+PTR_SIZE*2] /* load user_data */
  4253. .Ldo_closure:
  4254. add x3, sp, #16 /* load context */
  4255. add x4, sp, #ffi_closure_SYSV_FS /* load stack */
  4256. add x5, sp, #16+CALL_CONTEXT_SIZE /* load rvalue */
  4257. mov x6, x8 /* load struct_rval */
  4258. bl CNAME(ffi_closure_SYSV_inner)
  4259. /* Load the return value as directed. */
  4260. adr x1, 0f
  4261. and w0, w0, #AARCH64_RET_MASK
  4262. add x1, x1, x0, lsl #3
  4263. add x3, sp, #16+CALL_CONTEXT_SIZE
  4264. br x1
  4265. /* Note that each table entry is 2 insns, and thus 8 bytes. */
  4266. .align 4
  4267. 0: b 99f /* VOID */
  4268. nop
  4269. 1: ldr x0, [x3] /* INT64 */
  4270. b 99f
  4271. 2: ldp x0, x1, [x3] /* INT128 */
  4272. b 99f
  4273. 3: brk #1000 /* UNUSED */
  4274. nop
  4275. 4: brk #1000 /* UNUSED */
  4276. nop
  4277. 5: brk #1000 /* UNUSED */
  4278. nop
  4279. 6: brk #1000 /* UNUSED */
  4280. nop
  4281. 7: brk #1000 /* UNUSED */
  4282. nop
  4283. 8: ldr s3, [x3, #12] /* S4 */
  4284. nop
  4285. 9: ldr s2, [x3, #8] /* S3 */
  4286. nop
  4287. 10: ldp s0, s1, [x3] /* S2 */
  4288. b 99f
  4289. 11: ldr s0, [x3] /* S1 */
  4290. b 99f
  4291. 12: ldr d3, [x3, #24] /* D4 */
  4292. nop
  4293. 13: ldr d2, [x3, #16] /* D3 */
  4294. nop
  4295. 14: ldp d0, d1, [x3] /* D2 */
  4296. b 99f
  4297. 15: ldr d0, [x3] /* D1 */
  4298. b 99f
  4299. 16: ldr q3, [x3, #48] /* Q4 */
  4300. nop
  4301. 17: ldr q2, [x3, #32] /* Q3 */
  4302. nop
  4303. 18: ldp q0, q1, [x3] /* Q2 */
  4304. b 99f
  4305. 19: ldr q0, [x3] /* Q1 */
  4306. b 99f
  4307. 20: ldrb w0, [x3, #BE(7)] /* UINT8 */
  4308. b 99f
  4309. 21: brk #1000 /* reserved */
  4310. nop
  4311. 22: ldrh w0, [x3, #BE(6)] /* UINT16 */
  4312. b 99f
  4313. 23: brk #1000 /* reserved */
  4314. nop
  4315. 24: ldr w0, [x3, #BE(4)] /* UINT32 */
  4316. b 99f
  4317. 25: brk #1000 /* reserved */
  4318. nop
  4319. 26: ldrsb x0, [x3, #BE(7)] /* SINT8 */
  4320. b 99f
  4321. 27: brk #1000 /* reserved */
  4322. nop
  4323. 28: ldrsh x0, [x3, #BE(6)] /* SINT16 */
  4324. b 99f
  4325. 29: brk #1000 /* reserved */
  4326. nop
  4327. 30: ldrsw x0, [x3, #BE(4)] /* SINT32 */
  4328. nop
  4329. 31: /* reserved */
  4330. 99: ldp x29, x30, [sp], #ffi_closure_SYSV_FS
  4331. cfi_adjust_cfa_offset (-ffi_closure_SYSV_FS)
  4332. cfi_restore (x29)
  4333. cfi_restore (x30)
  4334. ret
  4335. cfi_endproc
  4336. .globl CNAME(ffi_closure_SYSV)
  4337. FFI_HIDDEN(CNAME(ffi_closure_SYSV))
  4338. #ifdef __ELF__
  4339. .type CNAME(ffi_closure_SYSV), #function
  4340. .size CNAME(ffi_closure_SYSV), . - CNAME(ffi_closure_SYSV)
  4341. #endif
  4342. #if FFI_EXEC_TRAMPOLINE_TABLE
  4343. #ifdef __MACH__
  4344. #include <mach/machine/vm_param.h>
  4345. .align PAGE_MAX_SHIFT
  4346. CNAME(ffi_closure_trampoline_table_page):
  4347. .rept PAGE_MAX_SIZE / FFI_TRAMPOLINE_SIZE
  4348. adr x16, -PAGE_MAX_SIZE
  4349. ldp x17, x16, [x16]
  4350. br x16
  4351. nop /* each entry in the trampoline config page is 2*sizeof(void*) so the trampoline itself cannot be smaller that 16 bytes */
  4352. .endr
  4353. .globl CNAME(ffi_closure_trampoline_table_page)
  4354. FFI_HIDDEN(CNAME(ffi_closure_trampoline_table_page))
  4355. #ifdef __ELF__
  4356. .type CNAME(ffi_closure_trampoline_table_page), #function
  4357. .size CNAME(ffi_closure_trampoline_table_page), . - CNAME(ffi_closure_trampoline_table_page)
  4358. #endif
  4359. #endif
  4360. #endif /* FFI_EXEC_TRAMPOLINE_TABLE */
  4361. #ifdef FFI_GO_CLOSURES
  4362. .align 4
  4363. CNAME(ffi_go_closure_SYSV_V):
  4364. cfi_startproc
  4365. stp x29, x30, [sp, #-ffi_closure_SYSV_FS]!
  4366. cfi_adjust_cfa_offset (ffi_closure_SYSV_FS)
  4367. cfi_rel_offset (x29, 0)
  4368. cfi_rel_offset (x30, 8)
  4369. /* Save the argument passing vector registers. */
  4370. stp q0, q1, [sp, #16 + 0]
  4371. stp q2, q3, [sp, #16 + 32]
  4372. stp q4, q5, [sp, #16 + 64]
  4373. stp q6, q7, [sp, #16 + 96]
  4374. b 0f
  4375. cfi_endproc
  4376. .globl CNAME(ffi_go_closure_SYSV_V)
  4377. FFI_HIDDEN(CNAME(ffi_go_closure_SYSV_V))
  4378. #ifdef __ELF__
  4379. .type CNAME(ffi_go_closure_SYSV_V), #function
  4380. .size CNAME(ffi_go_closure_SYSV_V), . - CNAME(ffi_go_closure_SYSV_V)
  4381. #endif
  4382. .align 4
  4383. cfi_startproc
  4384. CNAME(ffi_go_closure_SYSV):
  4385. stp x29, x30, [sp, #-ffi_closure_SYSV_FS]!
  4386. cfi_adjust_cfa_offset (ffi_closure_SYSV_FS)
  4387. cfi_rel_offset (x29, 0)
  4388. cfi_rel_offset (x30, 8)
  4389. 0:
  4390. mov x29, sp
  4391. /* Save the argument passing core registers. */
  4392. stp x0, x1, [sp, #16 + 16*N_V_ARG_REG + 0]
  4393. stp x2, x3, [sp, #16 + 16*N_V_ARG_REG + 16]
  4394. stp x4, x5, [sp, #16 + 16*N_V_ARG_REG + 32]
  4395. stp x6, x7, [sp, #16 + 16*N_V_ARG_REG + 48]
  4396. /* Load ffi_closure_inner arguments. */
  4397. ldp PTR_REG(0), PTR_REG(1), [x18, #PTR_SIZE]/* load cif, fn */
  4398. mov x2, x18 /* load user_data */
  4399. b .Ldo_closure
  4400. cfi_endproc
  4401. .globl CNAME(ffi_go_closure_SYSV)
  4402. FFI_HIDDEN(CNAME(ffi_go_closure_SYSV))
  4403. #ifdef __ELF__
  4404. .type CNAME(ffi_go_closure_SYSV), #function
  4405. .size CNAME(ffi_go_closure_SYSV), . - CNAME(ffi_go_closure_SYSV)
  4406. #endif
  4407. #endif /* FFI_GO_CLOSURES */
  4408. #endif /* __arm64__ */
  4409. #if defined __ELF__ && defined __linux__
  4410. .section .note.GNU-stack,"",%progbits
  4411. #endif
  4412. ====================File: src/arm/ffi.c====================
  4413. /* -----------------------------------------------------------------------
  4414. ffi.c - Copyright (c) 2011 Timothy Wall
  4415. Copyright (c) 2011 Plausible Labs Cooperative, Inc.
  4416. Copyright (c) 2011 Anthony Green
  4417. Copyright (c) 2011 Free Software Foundation
  4418. Copyright (c) 1998, 2008, 2011 Red Hat, Inc.
  4419. ARM Foreign Function Interface
  4420. Permission is hereby granted, free of charge, to any person obtaining
  4421. a copy of this software and associated documentation files (the
  4422. ``Software''), to deal in the Software without restriction, including
  4423. without limitation the rights to use, copy, modify, merge, publish,
  4424. distribute, sublicense, and/or sell copies of the Software, and to
  4425. permit persons to whom the Software is furnished to do so, subject to
  4426. the following conditions:
  4427. The above copyright notice and this permission notice shall be included
  4428. in all copies or substantial portions of the Software.
  4429. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  4430. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  4431. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  4432. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  4433. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  4434. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  4435. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  4436. DEALINGS IN THE SOFTWARE.
  4437. ----------------------------------------------------------------------- */
  4438. #if defined(__arm__) || defined(_M_ARM)
  4439. #include <fficonfig.h>
  4440. #include <ffi.h>
  4441. #include <ffi_common.h>
  4442. #include <stdint.h>
  4443. #include <stdlib.h>
  4444. #include "internal.h"
  4445. #if defined(_MSC_VER) && defined(_M_ARM)
  4446. #define WIN32_LEAN_AND_MEAN
  4447. #include <windows.h>
  4448. #endif
  4449. #if FFI_EXEC_TRAMPOLINE_TABLE
  4450. #ifdef __MACH__
  4451. #include <mach/machine/vm_param.h>
  4452. #endif
  4453. #else
  4454. #ifndef _M_ARM
  4455. extern unsigned int ffi_arm_trampoline[2] FFI_HIDDEN;
  4456. #else
  4457. extern unsigned int ffi_arm_trampoline[3] FFI_HIDDEN;
  4458. #endif
  4459. #endif
  4460. /* Forward declares. */
  4461. static int vfp_type_p (const ffi_type *);
  4462. static void layout_vfp_args (ffi_cif *);
  4463. static void *
  4464. ffi_align (ffi_type *ty, void *p)
  4465. {
  4466. /* Align if necessary */
  4467. size_t alignment;
  4468. #ifdef _WIN32_WCE
  4469. alignment = 4;
  4470. #else
  4471. alignment = ty->alignment;
  4472. if (alignment < 4)
  4473. alignment = 4;
  4474. #endif
  4475. return (void *) FFI_ALIGN (p, alignment);
  4476. }
  4477. static size_t
  4478. ffi_put_arg (ffi_type *ty, void *src, void *dst)
  4479. {
  4480. size_t z = ty->size;
  4481. switch (ty->type)
  4482. {
  4483. case FFI_TYPE_SINT8:
  4484. *(UINT32 *)dst = *(SINT8 *)src;
  4485. break;
  4486. case FFI_TYPE_UINT8:
  4487. *(UINT32 *)dst = *(UINT8 *)src;
  4488. break;
  4489. case FFI_TYPE_SINT16:
  4490. *(UINT32 *)dst = *(SINT16 *)src;
  4491. break;
  4492. case FFI_TYPE_UINT16:
  4493. *(UINT32 *)dst = *(UINT16 *)src;
  4494. break;
  4495. case FFI_TYPE_INT:
  4496. case FFI_TYPE_SINT32:
  4497. case FFI_TYPE_UINT32:
  4498. case FFI_TYPE_POINTER:
  4499. #ifndef _MSC_VER
  4500. case FFI_TYPE_FLOAT:
  4501. #endif
  4502. *(UINT32 *)dst = *(UINT32 *)src;
  4503. break;
  4504. #ifdef _MSC_VER
  4505. // casting a float* to a UINT32* doesn't work on Windows
  4506. case FFI_TYPE_FLOAT:
  4507. *(uintptr_t *)dst = 0;
  4508. *(float *)dst = *(float *)src;
  4509. break;
  4510. #endif
  4511. case FFI_TYPE_SINT64:
  4512. case FFI_TYPE_UINT64:
  4513. case FFI_TYPE_DOUBLE:
  4514. *(UINT64 *)dst = *(UINT64 *)src;
  4515. break;
  4516. case FFI_TYPE_STRUCT:
  4517. case FFI_TYPE_COMPLEX:
  4518. memcpy (dst, src, z);
  4519. break;
  4520. default:
  4521. abort();
  4522. }
  4523. return FFI_ALIGN (z, 4);
  4524. }
  4525. /* ffi_prep_args is called once stack space has been allocated
  4526. for the function's arguments.
  4527. The vfp_space parameter is the load area for VFP regs, the return
  4528. value is cif->vfp_used (word bitset of VFP regs used for passing
  4529. arguments). These are only used for the VFP hard-float ABI.
  4530. */
  4531. static void
  4532. ffi_prep_args_SYSV (ffi_cif *cif, int flags, void *rvalue,
  4533. void **avalue, char *argp)
  4534. {
  4535. ffi_type **arg_types = cif->arg_types;
  4536. int i, n;
  4537. if (flags == ARM_TYPE_STRUCT)
  4538. {
  4539. *(void **) argp = rvalue;
  4540. argp += 4;
  4541. }
  4542. for (i = 0, n = cif->nargs; i < n; i++)
  4543. {
  4544. ffi_type *ty = arg_types[i];
  4545. argp = ffi_align (ty, argp);
  4546. argp += ffi_put_arg (ty, avalue[i], argp);
  4547. }
  4548. }
  4549. static void
  4550. ffi_prep_args_VFP (ffi_cif *cif, int flags, void *rvalue,
  4551. void **avalue, char *stack, char *vfp_space)
  4552. {
  4553. ffi_type **arg_types = cif->arg_types;
  4554. int i, n, vi = 0;
  4555. char *argp, *regp, *eo_regp;
  4556. char stack_used = 0;
  4557. char done_with_regs = 0;
  4558. /* The first 4 words on the stack are used for values
  4559. passed in core registers. */
  4560. regp = stack;
  4561. eo_regp = argp = regp + 16;
  4562. /* If the function returns an FFI_TYPE_STRUCT in memory,
  4563. that address is passed in r0 to the function. */
  4564. if (flags == ARM_TYPE_STRUCT)
  4565. {
  4566. *(void **) regp = rvalue;
  4567. regp += 4;
  4568. }
  4569. for (i = 0, n = cif->nargs; i < n; i++)
  4570. {
  4571. ffi_type *ty = arg_types[i];
  4572. void *a = avalue[i];
  4573. int is_vfp_type = vfp_type_p (ty);
  4574. /* Allocated in VFP registers. */
  4575. if (vi < cif->vfp_nargs && is_vfp_type)
  4576. {
  4577. char *vfp_slot = vfp_space + cif->vfp_args[vi++] * 4;
  4578. ffi_put_arg (ty, a, vfp_slot);
  4579. continue;
  4580. }
  4581. /* Try allocating in core registers. */
  4582. else if (!done_with_regs && !is_vfp_type)
  4583. {
  4584. char *tregp = ffi_align (ty, regp);
  4585. size_t size = ty->size;
  4586. size = (size < 4) ? 4 : size; // pad
  4587. /* Check if there is space left in the aligned register
  4588. area to place the argument. */
  4589. if (tregp + size <= eo_regp)
  4590. {
  4591. regp = tregp + ffi_put_arg (ty, a, tregp);
  4592. done_with_regs = (regp == argp);
  4593. // ensure we did not write into the stack area
  4594. FFI_ASSERT (regp <= argp);
  4595. continue;
  4596. }
  4597. /* In case there are no arguments in the stack area yet,
  4598. the argument is passed in the remaining core registers
  4599. and on the stack. */
  4600. else if (!stack_used)
  4601. {
  4602. stack_used = 1;
  4603. done_with_regs = 1;
  4604. argp = tregp + ffi_put_arg (ty, a, tregp);
  4605. FFI_ASSERT (eo_regp < argp);
  4606. continue;
  4607. }
  4608. }
  4609. /* Base case, arguments are passed on the stack */
  4610. stack_used = 1;
  4611. argp = ffi_align (ty, argp);
  4612. argp += ffi_put_arg (ty, a, argp);
  4613. }
  4614. }
  4615. /* Perform machine dependent cif processing */
  4616. ffi_status FFI_HIDDEN
  4617. ffi_prep_cif_machdep (ffi_cif *cif)
  4618. {
  4619. int flags = 0, cabi = cif->abi;
  4620. size_t bytes = cif->bytes;
  4621. /* Map out the register placements of VFP register args. The VFP
  4622. hard-float calling conventions are slightly more sophisticated
  4623. than the base calling conventions, so we do it here instead of
  4624. in ffi_prep_args(). */
  4625. if (cabi == FFI_VFP)
  4626. layout_vfp_args (cif);
  4627. /* Set the return type flag */
  4628. switch (cif->rtype->type)
  4629. {
  4630. case FFI_TYPE_VOID:
  4631. flags = ARM_TYPE_VOID;
  4632. break;
  4633. case FFI_TYPE_INT:
  4634. case FFI_TYPE_UINT8:
  4635. case FFI_TYPE_SINT8:
  4636. case FFI_TYPE_UINT16:
  4637. case FFI_TYPE_SINT16:
  4638. case FFI_TYPE_UINT32:
  4639. case FFI_TYPE_SINT32:
  4640. case FFI_TYPE_POINTER:
  4641. flags = ARM_TYPE_INT;
  4642. break;
  4643. case FFI_TYPE_SINT64:
  4644. case FFI_TYPE_UINT64:
  4645. flags = ARM_TYPE_INT64;
  4646. break;
  4647. case FFI_TYPE_FLOAT:
  4648. flags = (cabi == FFI_VFP ? ARM_TYPE_VFP_S : ARM_TYPE_INT);
  4649. break;
  4650. case FFI_TYPE_DOUBLE:
  4651. flags = (cabi == FFI_VFP ? ARM_TYPE_VFP_D : ARM_TYPE_INT64);
  4652. break;
  4653. case FFI_TYPE_STRUCT:
  4654. case FFI_TYPE_COMPLEX:
  4655. if (cabi == FFI_VFP)
  4656. {
  4657. int h = vfp_type_p (cif->rtype);
  4658. flags = ARM_TYPE_VFP_N;
  4659. if (h == 0x100 + FFI_TYPE_FLOAT)
  4660. flags = ARM_TYPE_VFP_S;
  4661. if (h == 0x100 + FFI_TYPE_DOUBLE)
  4662. flags = ARM_TYPE_VFP_D;
  4663. if (h != 0)
  4664. break;
  4665. }
  4666. /* A Composite Type not larger than 4 bytes is returned in r0.
  4667. A Composite Type larger than 4 bytes, or whose size cannot
  4668. be determined statically ... is stored in memory at an
  4669. address passed [in r0]. */
  4670. if (cif->rtype->size <= 4)
  4671. flags = ARM_TYPE_INT;
  4672. else
  4673. {
  4674. flags = ARM_TYPE_STRUCT;
  4675. bytes += 4;
  4676. }
  4677. break;
  4678. default:
  4679. abort();
  4680. }
  4681. /* Round the stack up to a multiple of 8 bytes. This isn't needed
  4682. everywhere, but it is on some platforms, and it doesn't harm anything
  4683. when it isn't needed. */
  4684. bytes = FFI_ALIGN (bytes, 8);
  4685. /* Minimum stack space is the 4 register arguments that we pop. */
  4686. if (bytes < 4*4)
  4687. bytes = 4*4;
  4688. cif->bytes = bytes;
  4689. cif->flags = flags;
  4690. return FFI_OK;
  4691. }
  4692. /* Perform machine dependent cif processing for variadic calls */
  4693. ffi_status FFI_HIDDEN
  4694. ffi_prep_cif_machdep_var (ffi_cif * cif,
  4695. unsigned int nfixedargs, unsigned int ntotalargs)
  4696. {
  4697. /* VFP variadic calls actually use the SYSV ABI */
  4698. if (cif->abi == FFI_VFP)
  4699. cif->abi = FFI_SYSV;
  4700. return ffi_prep_cif_machdep (cif);
  4701. }
  4702. /* Prototypes for assembly functions, in sysv.S. */
  4703. struct call_frame
  4704. {
  4705. void *fp;
  4706. void *lr;
  4707. void *rvalue;
  4708. int flags;
  4709. void *closure;
  4710. };
  4711. extern void ffi_call_SYSV (void *stack, struct call_frame *,
  4712. void (*fn) (void)) FFI_HIDDEN;
  4713. extern void ffi_call_VFP (void *vfp_space, struct call_frame *,
  4714. void (*fn) (void), unsigned vfp_used) FFI_HIDDEN;
  4715. static void
  4716. ffi_call_int (ffi_cif * cif, void (*fn) (void), void *rvalue,
  4717. void **avalue, void *closure)
  4718. {
  4719. int flags = cif->flags;
  4720. ffi_type *rtype = cif->rtype;
  4721. size_t bytes, rsize, vfp_size;
  4722. char *stack, *vfp_space, *new_rvalue;
  4723. struct call_frame *frame;
  4724. rsize = 0;
  4725. if (rvalue == NULL)
  4726. {
  4727. /* If the return value is a struct and we don't have a return
  4728. value address then we need to make one. Otherwise the return
  4729. value is in registers and we can ignore them. */
  4730. if (flags == ARM_TYPE_STRUCT)
  4731. rsize = rtype->size;
  4732. else
  4733. flags = ARM_TYPE_VOID;
  4734. }
  4735. else if (flags == ARM_TYPE_VFP_N)
  4736. {
  4737. /* Largest case is double x 4. */
  4738. rsize = 32;
  4739. }
  4740. else if (flags == ARM_TYPE_INT && rtype->type == FFI_TYPE_STRUCT)
  4741. rsize = 4;
  4742. /* Largest case. */
  4743. vfp_size = (cif->abi == FFI_VFP && cif->vfp_used ? 8*8: 0);
  4744. bytes = cif->bytes;
  4745. stack = alloca (vfp_size + bytes + sizeof(struct call_frame) + rsize);
  4746. vfp_space = NULL;
  4747. if (vfp_size)
  4748. {
  4749. vfp_space = stack;
  4750. stack += vfp_size;
  4751. }
  4752. frame = (struct call_frame *)(stack + bytes);
  4753. new_rvalue = rvalue;
  4754. if (rsize)
  4755. new_rvalue = (void *)(frame + 1);
  4756. frame->rvalue = new_rvalue;
  4757. frame->flags = flags;
  4758. frame->closure = closure;
  4759. if (vfp_space)
  4760. {
  4761. ffi_prep_args_VFP (cif, flags, new_rvalue, avalue, stack, vfp_space);
  4762. ffi_call_VFP (vfp_space, frame, fn, cif->vfp_used);
  4763. }
  4764. else
  4765. {
  4766. ffi_prep_args_SYSV (cif, flags, new_rvalue, avalue, stack);
  4767. ffi_call_SYSV (stack, frame, fn);
  4768. }
  4769. if (rvalue && rvalue != new_rvalue)
  4770. memcpy (rvalue, new_rvalue, rtype->size);
  4771. }
  4772. void
  4773. ffi_call (ffi_cif *cif, void (*fn) (void), void *rvalue, void **avalue)
  4774. {
  4775. ffi_call_int (cif, fn, rvalue, avalue, NULL);
  4776. }
  4777. void
  4778. ffi_call_go (ffi_cif *cif, void (*fn) (void), void *rvalue,
  4779. void **avalue, void *closure)
  4780. {
  4781. ffi_call_int (cif, fn, rvalue, avalue, closure);
  4782. }
  4783. static void *
  4784. ffi_prep_incoming_args_SYSV (ffi_cif *cif, void *rvalue,
  4785. char *argp, void **avalue)
  4786. {
  4787. ffi_type **arg_types = cif->arg_types;
  4788. int i, n;
  4789. if (cif->flags == ARM_TYPE_STRUCT)
  4790. {
  4791. rvalue = *(void **) argp;
  4792. argp += 4;
  4793. }
  4794. else
  4795. {
  4796. if (cif->rtype->size && cif->rtype->size < 4)
  4797. *(uint32_t *) rvalue = 0;
  4798. }
  4799. for (i = 0, n = cif->nargs; i < n; i++)
  4800. {
  4801. ffi_type *ty = arg_types[i];
  4802. size_t z = ty->size;
  4803. argp = ffi_align (ty, argp);
  4804. avalue[i] = (void *) argp;
  4805. argp += z;
  4806. }
  4807. return rvalue;
  4808. }
  4809. static void *
  4810. ffi_prep_incoming_args_VFP (ffi_cif *cif, void *rvalue, char *stack,
  4811. char *vfp_space, void **avalue)
  4812. {
  4813. ffi_type **arg_types = cif->arg_types;
  4814. int i, n, vi = 0;
  4815. char *argp, *regp, *eo_regp;
  4816. char done_with_regs = 0;
  4817. char stack_used = 0;
  4818. regp = stack;
  4819. eo_regp = argp = regp + 16;
  4820. if (cif->flags == ARM_TYPE_STRUCT)
  4821. {
  4822. rvalue = *(void **) regp;
  4823. regp += 4;
  4824. }
  4825. for (i = 0, n = cif->nargs; i < n; i++)
  4826. {
  4827. ffi_type *ty = arg_types[i];
  4828. int is_vfp_type = vfp_type_p (ty);
  4829. size_t z = ty->size;
  4830. if (vi < cif->vfp_nargs && is_vfp_type)
  4831. {
  4832. avalue[i] = vfp_space + cif->vfp_args[vi++] * 4;
  4833. continue;
  4834. }
  4835. else if (!done_with_regs && !is_vfp_type)
  4836. {
  4837. char *tregp = ffi_align (ty, regp);
  4838. z = (z < 4) ? 4 : z; // pad
  4839. /* If the arguments either fits into the registers or uses registers
  4840. and stack, while we haven't read other things from the stack */
  4841. if (tregp + z <= eo_regp || !stack_used)
  4842. {
  4843. /* Because we're little endian, this is what it turns into. */
  4844. avalue[i] = (void *) tregp;
  4845. regp = tregp + z;
  4846. /* If we read past the last core register, make sure we
  4847. have not read from the stack before and continue
  4848. reading after regp. */
  4849. if (regp > eo_regp)
  4850. {
  4851. FFI_ASSERT (!stack_used);
  4852. argp = regp;
  4853. }
  4854. if (regp >= eo_regp)
  4855. {
  4856. done_with_regs = 1;
  4857. stack_used = 1;
  4858. }
  4859. continue;
  4860. }
  4861. }
  4862. stack_used = 1;
  4863. argp = ffi_align (ty, argp);
  4864. avalue[i] = (void *) argp;
  4865. argp += z;
  4866. }
  4867. return rvalue;
  4868. }
  4869. struct closure_frame
  4870. {
  4871. char vfp_space[8*8] __attribute__((aligned(8)));
  4872. char result[8*4];
  4873. char argp[];
  4874. };
  4875. int FFI_HIDDEN
  4876. ffi_closure_inner_SYSV (ffi_cif *cif,
  4877. void (*fun) (ffi_cif *, void *, void **, void *),
  4878. void *user_data,
  4879. struct closure_frame *frame)
  4880. {
  4881. void **avalue = (void **) alloca (cif->nargs * sizeof (void *));
  4882. void *rvalue = ffi_prep_incoming_args_SYSV (cif, frame->result,
  4883. frame->argp, avalue);
  4884. fun (cif, rvalue, avalue, user_data);
  4885. return cif->flags;
  4886. }
  4887. int FFI_HIDDEN
  4888. ffi_closure_inner_VFP (ffi_cif *cif,
  4889. void (*fun) (ffi_cif *, void *, void **, void *),
  4890. void *user_data,
  4891. struct closure_frame *frame)
  4892. {
  4893. void **avalue = (void **) alloca (cif->nargs * sizeof (void *));
  4894. void *rvalue = ffi_prep_incoming_args_VFP (cif, frame->result, frame->argp,
  4895. frame->vfp_space, avalue);
  4896. fun (cif, rvalue, avalue, user_data);
  4897. return cif->flags;
  4898. }
  4899. void ffi_closure_SYSV (void) FFI_HIDDEN;
  4900. void ffi_closure_VFP (void) FFI_HIDDEN;
  4901. void ffi_go_closure_SYSV (void) FFI_HIDDEN;
  4902. void ffi_go_closure_VFP (void) FFI_HIDDEN;
  4903. /* the cif must already be prep'ed */
  4904. ffi_status
  4905. ffi_prep_closure_loc (ffi_closure * closure,
  4906. ffi_cif * cif,
  4907. void (*fun) (ffi_cif *, void *, void **, void *),
  4908. void *user_data, void *codeloc)
  4909. {
  4910. void (*closure_func) (void) = ffi_closure_SYSV;
  4911. if (cif->abi == FFI_VFP)
  4912. {
  4913. /* We only need take the vfp path if there are vfp arguments. */
  4914. if (cif->vfp_used)
  4915. closure_func = ffi_closure_VFP;
  4916. }
  4917. else if (cif->abi != FFI_SYSV)
  4918. return FFI_BAD_ABI;
  4919. #if FFI_EXEC_TRAMPOLINE_TABLE
  4920. void **config = (void **)((uint8_t *)codeloc - PAGE_MAX_SIZE);
  4921. config[0] = closure;
  4922. config[1] = closure_func;
  4923. #else
  4924. #ifndef _M_ARM
  4925. memcpy(closure->tramp, ffi_arm_trampoline, 8);
  4926. #else
  4927. // cast away function type so MSVC doesn't set the lower bit of the function pointer
  4928. memcpy(closure->tramp, (void*)((uintptr_t)ffi_arm_trampoline & 0xFFFFFFFE), FFI_TRAMPOLINE_CLOSURE_OFFSET);
  4929. #endif
  4930. #if defined (__QNX__)
  4931. msync(closure->tramp, 8, 0x1000000); /* clear data map */
  4932. msync(codeloc, 8, 0x1000000); /* clear insn map */
  4933. #elif defined(_MSC_VER)
  4934. FlushInstructionCache(GetCurrentProcess(), closure->tramp, FFI_TRAMPOLINE_SIZE);
  4935. #else
  4936. __clear_cache(closure->tramp, closure->tramp + 8); /* clear data map */
  4937. __clear_cache(codeloc, codeloc + 8); /* clear insn map */
  4938. #endif
  4939. #ifdef _M_ARM
  4940. *(void(**)(void))(closure->tramp + FFI_TRAMPOLINE_CLOSURE_FUNCTION) = closure_func;
  4941. #else
  4942. *(void (**)(void))(closure->tramp + 8) = closure_func;
  4943. #endif
  4944. #endif
  4945. closure->cif = cif;
  4946. closure->fun = fun;
  4947. closure->user_data = user_data;
  4948. return FFI_OK;
  4949. }
  4950. ffi_status
  4951. ffi_prep_go_closure (ffi_go_closure *closure, ffi_cif *cif,
  4952. void (*fun) (ffi_cif *, void *, void **, void *))
  4953. {
  4954. void (*closure_func) (void) = ffi_go_closure_SYSV;
  4955. if (cif->abi == FFI_VFP)
  4956. {
  4957. /* We only need take the vfp path if there are vfp arguments. */
  4958. if (cif->vfp_used)
  4959. closure_func = ffi_go_closure_VFP;
  4960. }
  4961. else if (cif->abi != FFI_SYSV)
  4962. return FFI_BAD_ABI;
  4963. closure->tramp = closure_func;
  4964. closure->cif = cif;
  4965. closure->fun = fun;
  4966. return FFI_OK;
  4967. }
  4968. /* Below are routines for VFP hard-float support. */
  4969. /* A subroutine of vfp_type_p. Given a structure type, return the type code
  4970. of the first non-structure element. Recurse for structure elements.
  4971. Return -1 if the structure is in fact empty, i.e. no nested elements. */
  4972. static int
  4973. is_hfa0 (const ffi_type *ty)
  4974. {
  4975. ffi_type **elements = ty->elements;
  4976. int i, ret = -1;
  4977. if (elements != NULL)
  4978. for (i = 0; elements[i]; ++i)
  4979. {
  4980. ret = elements[i]->type;
  4981. if (ret == FFI_TYPE_STRUCT || ret == FFI_TYPE_COMPLEX)
  4982. {
  4983. ret = is_hfa0 (elements[i]);
  4984. if (ret < 0)
  4985. continue;
  4986. }
  4987. break;
  4988. }
  4989. return ret;
  4990. }
  4991. /* A subroutine of vfp_type_p. Given a structure type, return true if all
  4992. of the non-structure elements are the same as CANDIDATE. */
  4993. static int
  4994. is_hfa1 (const ffi_type *ty, int candidate)
  4995. {
  4996. ffi_type **elements = ty->elements;
  4997. int i;
  4998. if (elements != NULL)
  4999. for (i = 0; elements[i]; ++i)
  5000. {
  5001. int t = elements[i]->type;
  5002. if (t == FFI_TYPE_STRUCT || t == FFI_TYPE_COMPLEX)
  5003. {
  5004. if (!is_hfa1 (elements[i], candidate))
  5005. return 0;
  5006. }
  5007. else if (t != candidate)
  5008. return 0;
  5009. }
  5010. return 1;
  5011. }
  5012. /* Determine if TY is an homogenous floating point aggregate (HFA).
  5013. That is, a structure consisting of 1 to 4 members of all the same type,
  5014. where that type is a floating point scalar.
  5015. Returns non-zero iff TY is an HFA. The result is an encoded value where
  5016. bits 0-7 contain the type code, and bits 8-10 contain the element count. */
  5017. static int
  5018. vfp_type_p (const ffi_type *ty)
  5019. {
  5020. ffi_type **elements;
  5021. int candidate, i;
  5022. size_t size, ele_count;
  5023. /* Quickest tests first. */
  5024. candidate = ty->type;
  5025. switch (ty->type)
  5026. {
  5027. default:
  5028. return 0;
  5029. case FFI_TYPE_FLOAT:
  5030. case FFI_TYPE_DOUBLE:
  5031. ele_count = 1;
  5032. goto done;
  5033. case FFI_TYPE_COMPLEX:
  5034. candidate = ty->elements[0]->type;
  5035. if (candidate != FFI_TYPE_FLOAT && candidate != FFI_TYPE_DOUBLE)
  5036. return 0;
  5037. ele_count = 2;
  5038. goto done;
  5039. case FFI_TYPE_STRUCT:
  5040. break;
  5041. }
  5042. /* No HFA types are smaller than 4 bytes, or larger than 32 bytes. */
  5043. size = ty->size;
  5044. if (size < 4 || size > 32)
  5045. return 0;
  5046. /* Find the type of the first non-structure member. */
  5047. elements = ty->elements;
  5048. candidate = elements[0]->type;
  5049. if (candidate == FFI_TYPE_STRUCT || candidate == FFI_TYPE_COMPLEX)
  5050. {
  5051. for (i = 0; ; ++i)
  5052. {
  5053. candidate = is_hfa0 (elements[i]);
  5054. if (candidate >= 0)
  5055. break;
  5056. }
  5057. }
  5058. /* If the first member is not a floating point type, it's not an HFA.
  5059. Also quickly re-check the size of the structure. */
  5060. switch (candidate)
  5061. {
  5062. case FFI_TYPE_FLOAT:
  5063. ele_count = size / sizeof(float);
  5064. if (size != ele_count * sizeof(float))
  5065. return 0;
  5066. break;
  5067. case FFI_TYPE_DOUBLE:
  5068. ele_count = size / sizeof(double);
  5069. if (size != ele_count * sizeof(double))
  5070. return 0;
  5071. break;
  5072. default:
  5073. return 0;
  5074. }
  5075. if (ele_count > 4)
  5076. return 0;
  5077. /* Finally, make sure that all scalar elements are the same type. */
  5078. for (i = 0; elements[i]; ++i)
  5079. {
  5080. int t = elements[i]->type;
  5081. if (t == FFI_TYPE_STRUCT || t == FFI_TYPE_COMPLEX)
  5082. {
  5083. if (!is_hfa1 (elements[i], candidate))
  5084. return 0;
  5085. }
  5086. else if (t != candidate)
  5087. return 0;
  5088. }
  5089. /* All tests succeeded. Encode the result. */
  5090. done:
  5091. return (ele_count << 8) | candidate;
  5092. }
  5093. static int
  5094. place_vfp_arg (ffi_cif *cif, int h)
  5095. {
  5096. unsigned short reg = cif->vfp_reg_free;
  5097. int align = 1, nregs = h >> 8;
  5098. if ((h & 0xff) == FFI_TYPE_DOUBLE)
  5099. align = 2, nregs *= 2;
  5100. /* Align register number. */
  5101. if ((reg & 1) && align == 2)
  5102. reg++;
  5103. while (reg + nregs <= 16)
  5104. {
  5105. int s, new_used = 0;
  5106. for (s = reg; s < reg + nregs; s++)
  5107. {
  5108. new_used |= (1 << s);
  5109. if (cif->vfp_used & (1 << s))
  5110. {
  5111. reg += align;
  5112. goto next_reg;
  5113. }
  5114. }
  5115. /* Found regs to allocate. */
  5116. cif->vfp_used |= new_used;
  5117. cif->vfp_args[cif->vfp_nargs++] = (signed char)reg;
  5118. /* Update vfp_reg_free. */
  5119. if (cif->vfp_used & (1 << cif->vfp_reg_free))
  5120. {
  5121. reg += nregs;
  5122. while (cif->vfp_used & (1 << reg))
  5123. reg += 1;
  5124. cif->vfp_reg_free = reg;
  5125. }
  5126. return 0;
  5127. next_reg:;
  5128. }
  5129. // done, mark all regs as used
  5130. cif->vfp_reg_free = 16;
  5131. cif->vfp_used = 0xFFFF;
  5132. return 1;
  5133. }
  5134. static void
  5135. layout_vfp_args (ffi_cif * cif)
  5136. {
  5137. unsigned int i;
  5138. /* Init VFP fields */
  5139. cif->vfp_used = 0;
  5140. cif->vfp_nargs = 0;
  5141. cif->vfp_reg_free = 0;
  5142. memset (cif->vfp_args, -1, 16); /* Init to -1. */
  5143. for (i = 0; i < cif->nargs; i++)
  5144. {
  5145. int h = vfp_type_p (cif->arg_types[i]);
  5146. if (h && place_vfp_arg (cif, h) == 1)
  5147. break;
  5148. }
  5149. }
  5150. #endif /* __arm__ or _M_ARM */
  5151. ====================File: src/arm/ffitarget.h====================
  5152. /* -----------------------------------------------------------------*-C-*-
  5153. ffitarget.h - Copyright (c) 2012 Anthony Green
  5154. Copyright (c) 2010 CodeSourcery
  5155. Copyright (c) 1996-2003 Red Hat, Inc.
  5156. Target configuration macros for ARM.
  5157. Permission is hereby granted, free of charge, to any person obtaining
  5158. a copy of this software and associated documentation files (the
  5159. ``Software''), to deal in the Software without restriction, including
  5160. without limitation the rights to use, copy, modify, merge, publish,
  5161. distribute, sublicense, and/or sell copies of the Software, and to
  5162. permit persons to whom the Software is furnished to do so, subject to
  5163. the following conditions:
  5164. The above copyright notice and this permission notice shall be included
  5165. in all copies or substantial portions of the Software.
  5166. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  5167. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  5168. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  5169. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  5170. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  5171. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  5172. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  5173. DEALINGS IN THE SOFTWARE.
  5174. ----------------------------------------------------------------------- */
  5175. #ifndef LIBFFI_TARGET_H
  5176. #define LIBFFI_TARGET_H
  5177. #ifndef LIBFFI_H
  5178. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  5179. #endif
  5180. #ifndef LIBFFI_ASM
  5181. typedef unsigned long ffi_arg;
  5182. typedef signed long ffi_sarg;
  5183. typedef enum ffi_abi {
  5184. FFI_FIRST_ABI = 0,
  5185. FFI_SYSV,
  5186. FFI_VFP,
  5187. FFI_LAST_ABI,
  5188. #if defined(__ARM_PCS_VFP) || defined(_M_ARM)
  5189. FFI_DEFAULT_ABI = FFI_VFP,
  5190. #else
  5191. FFI_DEFAULT_ABI = FFI_SYSV,
  5192. #endif
  5193. } ffi_abi;
  5194. #endif
  5195. #define FFI_EXTRA_CIF_FIELDS \
  5196. int vfp_used; \
  5197. unsigned short vfp_reg_free, vfp_nargs; \
  5198. signed char vfp_args[16] \
  5199. #define FFI_TARGET_SPECIFIC_VARIADIC
  5200. #ifndef _M_ARM
  5201. #define FFI_TARGET_HAS_COMPLEX_TYPE
  5202. #endif
  5203. /* ---- Definitions for closures ----------------------------------------- */
  5204. #define FFI_CLOSURES 1
  5205. #define FFI_GO_CLOSURES 1
  5206. #define FFI_NATIVE_RAW_API 0
  5207. #if defined (FFI_EXEC_TRAMPOLINE_TABLE) && FFI_EXEC_TRAMPOLINE_TABLE
  5208. #ifdef __MACH__
  5209. #define FFI_TRAMPOLINE_SIZE 12
  5210. #define FFI_TRAMPOLINE_CLOSURE_OFFSET 8
  5211. #else
  5212. #error "No trampoline table implementation"
  5213. #endif
  5214. #else
  5215. #ifdef _MSC_VER
  5216. #define FFI_TRAMPOLINE_SIZE 16
  5217. #define FFI_TRAMPOLINE_CLOSURE_FUNCTION 12
  5218. #else
  5219. #define FFI_TRAMPOLINE_SIZE 12
  5220. #endif
  5221. #define FFI_TRAMPOLINE_CLOSURE_OFFSET FFI_TRAMPOLINE_SIZE
  5222. #endif
  5223. #endif
  5224. ====================File: src/arm/sysv.S====================
  5225. /* -----------------------------------------------------------------------
  5226. sysv.S - Copyright (c) 1998, 2008, 2011 Red Hat, Inc.
  5227. Copyright (c) 2011 Plausible Labs Cooperative, Inc.
  5228. ARM Foreign Function Interface
  5229. Permission is hereby granted, free of charge, to any person obtaining
  5230. a copy of this software and associated documentation files (the
  5231. ``Software''), to deal in the Software without restriction, including
  5232. without limitation the rights to use, copy, modify, merge, publish,
  5233. distribute, sublicense, and/or sell copies of the Software, and to
  5234. permit persons to whom the Software is furnished to do so, subject to
  5235. the following conditions:
  5236. The above copyright notice and this permission notice shall be included
  5237. in all copies or substantial portions of the Software.
  5238. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  5239. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  5240. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  5241. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  5242. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  5243. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  5244. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  5245. DEALINGS IN THE SOFTWARE.
  5246. ----------------------------------------------------------------------- */
  5247. #ifdef __arm__
  5248. #define LIBFFI_ASM
  5249. #include <fficonfig.h>
  5250. #include <ffi.h>
  5251. #include <ffi_cfi.h>
  5252. #include "internal.h"
  5253. /* GCC 4.8 provides __ARM_ARCH; construct it otherwise. */
  5254. #ifndef __ARM_ARCH
  5255. # if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) \
  5256. || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) \
  5257. || defined(__ARM_ARCH_7EM__)
  5258. # define __ARM_ARCH 7
  5259. # elif defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) \
  5260. || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) \
  5261. || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) \
  5262. || defined(__ARM_ARCH_6M__)
  5263. # define __ARM_ARCH 6
  5264. # elif defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) \
  5265. || defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) \
  5266. || defined(__ARM_ARCH_5TEJ__)
  5267. # define __ARM_ARCH 5
  5268. # else
  5269. # define __ARM_ARCH 4
  5270. # endif
  5271. #endif
  5272. /* Conditionally compile unwinder directives. */
  5273. #ifdef __ARM_EABI__
  5274. # define UNWIND(...) __VA_ARGS__
  5275. #else
  5276. # define UNWIND(...)
  5277. #endif
  5278. #if defined(HAVE_AS_CFI_PSEUDO_OP) && defined(__ARM_EABI__)
  5279. .cfi_sections .debug_frame
  5280. #endif
  5281. #define CONCAT(a, b) CONCAT2(a, b)
  5282. #define CONCAT2(a, b) a ## b
  5283. #ifdef __USER_LABEL_PREFIX__
  5284. # define CNAME(X) CONCAT (__USER_LABEL_PREFIX__, X)
  5285. #else
  5286. # define CNAME(X) X
  5287. #endif
  5288. #ifdef __ELF__
  5289. # define SIZE(X) .size CNAME(X), . - CNAME(X)
  5290. # define TYPE(X, Y) .type CNAME(X), Y
  5291. #else
  5292. # define SIZE(X)
  5293. # define TYPE(X, Y)
  5294. #endif
  5295. #define ARM_FUNC_START_LOCAL(name) \
  5296. .align 3; \
  5297. TYPE(CNAME(name), %function); \
  5298. CNAME(name):
  5299. #define ARM_FUNC_START(name) \
  5300. .globl CNAME(name); \
  5301. FFI_HIDDEN(CNAME(name)); \
  5302. ARM_FUNC_START_LOCAL(name)
  5303. #define ARM_FUNC_END(name) \
  5304. SIZE(name)
  5305. /* Aid in defining a jump table with 8 bytes between entries. */
  5306. /* ??? The clang assembler doesn't handle .if with symbolic expressions. */
  5307. #ifdef __clang__
  5308. # define E(index)
  5309. #else
  5310. # define E(index) \
  5311. .if . - 0b - 8*index; \
  5312. .error "type table out of sync"; \
  5313. .endif
  5314. #endif
  5315. .text
  5316. .syntax unified
  5317. .arm
  5318. #ifndef __clang__
  5319. /* We require interworking on LDM, which implies ARMv5T,
  5320. which implies the existance of BLX. */
  5321. .arch armv5t
  5322. #endif
  5323. /* Note that we use STC and LDC to encode VFP instructions,
  5324. so that we do not need ".fpu vfp", nor get that added to
  5325. the object file attributes. These will not be executed
  5326. unless the FFI_VFP abi is used. */
  5327. @ r0: stack
  5328. @ r1: frame
  5329. @ r2: fn
  5330. @ r3: vfp_used
  5331. ARM_FUNC_START(ffi_call_VFP)
  5332. UNWIND(.fnstart)
  5333. cfi_startproc
  5334. cmp r3, #3 @ load only d0 if possible
  5335. #ifdef __clang__
  5336. vldrle d0, [sp]
  5337. vldmgt sp, {d0-d7}
  5338. #else
  5339. ldcle p11, cr0, [r0] @ vldrle d0, [sp]
  5340. ldcgt p11, cr0, [r0], {16} @ vldmgt sp, {d0-d7}
  5341. #endif
  5342. add r0, r0, #64 @ discard the vfp register args
  5343. /* FALLTHRU */
  5344. ARM_FUNC_END(ffi_call_VFP)
  5345. ARM_FUNC_START(ffi_call_SYSV)
  5346. stm r1, {fp, lr}
  5347. mov fp, r1
  5348. @ This is a bit of a lie wrt the origin of the unwind info, but
  5349. @ now we've got the usual frame pointer and two saved registers.
  5350. UNWIND(.save {fp,lr})
  5351. UNWIND(.setfp fp, sp)
  5352. cfi_def_cfa(fp, 8)
  5353. cfi_rel_offset(fp, 0)
  5354. cfi_rel_offset(lr, 4)
  5355. mov sp, r0 @ install the stack pointer
  5356. mov lr, r2 @ move the fn pointer out of the way
  5357. ldr ip, [fp, #16] @ install the static chain
  5358. ldmia sp!, {r0-r3} @ move first 4 parameters in registers.
  5359. blx lr @ call fn
  5360. @ Load r2 with the pointer to storage for the return value
  5361. @ Load r3 with the return type code
  5362. ldr r2, [fp, #8]
  5363. ldr r3, [fp, #12]
  5364. @ Deallocate the stack with the arguments.
  5365. mov sp, fp
  5366. cfi_def_cfa_register(sp)
  5367. @ Store values stored in registers.
  5368. .align 3
  5369. add pc, pc, r3, lsl #3
  5370. nop
  5371. 0:
  5372. E(ARM_TYPE_VFP_S)
  5373. #ifdef __clang__
  5374. vstr s0, [r2]
  5375. #else
  5376. stc p10, cr0, [r2] @ vstr s0, [r2]
  5377. #endif
  5378. pop {fp,pc}
  5379. E(ARM_TYPE_VFP_D)
  5380. #ifdef __clang__
  5381. vstr d0, [r2]
  5382. #else
  5383. stc p11, cr0, [r2] @ vstr d0, [r2]
  5384. #endif
  5385. pop {fp,pc}
  5386. E(ARM_TYPE_VFP_N)
  5387. #ifdef __clang__
  5388. vstm r2, {d0-d3}
  5389. #else
  5390. stc p11, cr0, [r2], {8} @ vstm r2, {d0-d3}
  5391. #endif
  5392. pop {fp,pc}
  5393. E(ARM_TYPE_INT64)
  5394. str r1, [r2, #4]
  5395. nop
  5396. E(ARM_TYPE_INT)
  5397. str r0, [r2]
  5398. pop {fp,pc}
  5399. E(ARM_TYPE_VOID)
  5400. pop {fp,pc}
  5401. nop
  5402. E(ARM_TYPE_STRUCT)
  5403. pop {fp,pc}
  5404. cfi_endproc
  5405. UNWIND(.fnend)
  5406. ARM_FUNC_END(ffi_call_SYSV)
  5407. /*
  5408. int ffi_closure_inner_* (cif, fun, user_data, frame)
  5409. */
  5410. ARM_FUNC_START(ffi_go_closure_SYSV)
  5411. cfi_startproc
  5412. stmdb sp!, {r0-r3} @ save argument regs
  5413. cfi_adjust_cfa_offset(16)
  5414. ldr r0, [ip, #4] @ load cif
  5415. ldr r1, [ip, #8] @ load fun
  5416. mov r2, ip @ load user_data
  5417. b 0f
  5418. cfi_endproc
  5419. ARM_FUNC_END(ffi_go_closure_SYSV)
  5420. ARM_FUNC_START(ffi_closure_SYSV)
  5421. UNWIND(.fnstart)
  5422. cfi_startproc
  5423. stmdb sp!, {r0-r3} @ save argument regs
  5424. cfi_adjust_cfa_offset(16)
  5425. #if FFI_EXEC_TRAMPOLINE_TABLE
  5426. ldr ip, [ip] @ ip points to the config page, dereference to get the ffi_closure*
  5427. #endif
  5428. ldr r0, [ip, #FFI_TRAMPOLINE_CLOSURE_OFFSET] @ load cif
  5429. ldr r1, [ip, #FFI_TRAMPOLINE_CLOSURE_OFFSET+4] @ load fun
  5430. ldr r2, [ip, #FFI_TRAMPOLINE_CLOSURE_OFFSET+8] @ load user_data
  5431. 0:
  5432. add ip, sp, #16 @ compute entry sp
  5433. sub sp, sp, #64+32 @ allocate frame
  5434. cfi_adjust_cfa_offset(64+32)
  5435. stmdb sp!, {ip,lr}
  5436. /* Remember that EABI unwind info only applies at call sites.
  5437. We need do nothing except note the save of the stack pointer
  5438. and the link registers. */
  5439. UNWIND(.save {sp,lr})
  5440. cfi_adjust_cfa_offset(8)
  5441. cfi_rel_offset(lr, 4)
  5442. add r3, sp, #8 @ load frame
  5443. bl CNAME(ffi_closure_inner_SYSV)
  5444. @ Load values returned in registers.
  5445. add r2, sp, #8+64 @ load result
  5446. adr r3, CNAME(ffi_closure_ret)
  5447. add pc, r3, r0, lsl #3
  5448. cfi_endproc
  5449. UNWIND(.fnend)
  5450. ARM_FUNC_END(ffi_closure_SYSV)
  5451. ARM_FUNC_START(ffi_go_closure_VFP)
  5452. cfi_startproc
  5453. stmdb sp!, {r0-r3} @ save argument regs
  5454. cfi_adjust_cfa_offset(16)
  5455. ldr r0, [ip, #4] @ load cif
  5456. ldr r1, [ip, #8] @ load fun
  5457. mov r2, ip @ load user_data
  5458. b 0f
  5459. cfi_endproc
  5460. ARM_FUNC_END(ffi_go_closure_VFP)
  5461. ARM_FUNC_START(ffi_closure_VFP)
  5462. UNWIND(.fnstart)
  5463. cfi_startproc
  5464. stmdb sp!, {r0-r3} @ save argument regs
  5465. cfi_adjust_cfa_offset(16)
  5466. #if FFI_EXEC_TRAMPOLINE_TABLE
  5467. ldr ip, [ip] @ ip points to the config page, dereference to get the ffi_closure*
  5468. #endif
  5469. ldr r0, [ip, #FFI_TRAMPOLINE_CLOSURE_OFFSET] @ load cif
  5470. ldr r1, [ip, #FFI_TRAMPOLINE_CLOSURE_OFFSET+4] @ load fun
  5471. ldr r2, [ip, #FFI_TRAMPOLINE_CLOSURE_OFFSET+8] @ load user_data
  5472. 0:
  5473. add ip, sp, #16
  5474. sub sp, sp, #64+32 @ allocate frame
  5475. cfi_adjust_cfa_offset(64+32)
  5476. #ifdef __clang__
  5477. vstm sp, {d0-d7}
  5478. #else
  5479. stc p11, cr0, [sp], {16} @ vstm sp, {d0-d7}
  5480. #endif
  5481. stmdb sp!, {ip,lr}
  5482. /* See above. */
  5483. UNWIND(.save {sp,lr})
  5484. cfi_adjust_cfa_offset(8)
  5485. cfi_rel_offset(lr, 4)
  5486. add r3, sp, #8 @ load frame
  5487. bl CNAME(ffi_closure_inner_VFP)
  5488. @ Load values returned in registers.
  5489. add r2, sp, #8+64 @ load result
  5490. adr r3, CNAME(ffi_closure_ret)
  5491. add pc, r3, r0, lsl #3
  5492. cfi_endproc
  5493. UNWIND(.fnend)
  5494. ARM_FUNC_END(ffi_closure_VFP)
  5495. /* Load values returned in registers for both closure entry points.
  5496. Note that we use LDM with SP in the register set. This is deprecated
  5497. by ARM, but not yet unpredictable. */
  5498. ARM_FUNC_START_LOCAL(ffi_closure_ret)
  5499. cfi_startproc
  5500. cfi_rel_offset(sp, 0)
  5501. cfi_rel_offset(lr, 4)
  5502. 0:
  5503. E(ARM_TYPE_VFP_S)
  5504. #ifdef __clang__
  5505. vldr s0, [r2]
  5506. #else
  5507. ldc p10, cr0, [r2] @ vldr s0, [r2]
  5508. #endif
  5509. ldm sp, {sp,pc}
  5510. E(ARM_TYPE_VFP_D)
  5511. #ifdef __clang__
  5512. vldr d0, [r2]
  5513. #else
  5514. ldc p11, cr0, [r2] @ vldr d0, [r2]
  5515. #endif
  5516. ldm sp, {sp,pc}
  5517. E(ARM_TYPE_VFP_N)
  5518. #ifdef __clang__
  5519. vldm r2, {d0-d3}
  5520. #else
  5521. ldc p11, cr0, [r2], {8} @ vldm r2, {d0-d3}
  5522. #endif
  5523. ldm sp, {sp,pc}
  5524. E(ARM_TYPE_INT64)
  5525. ldr r1, [r2, #4]
  5526. nop
  5527. E(ARM_TYPE_INT)
  5528. ldr r0, [r2]
  5529. ldm sp, {sp,pc}
  5530. E(ARM_TYPE_VOID)
  5531. ldm sp, {sp,pc}
  5532. nop
  5533. E(ARM_TYPE_STRUCT)
  5534. ldm sp, {sp,pc}
  5535. cfi_endproc
  5536. ARM_FUNC_END(ffi_closure_ret)
  5537. #if FFI_EXEC_TRAMPOLINE_TABLE
  5538. #ifdef __MACH__
  5539. #include <mach/machine/vm_param.h>
  5540. .align PAGE_MAX_SHIFT
  5541. ARM_FUNC_START(ffi_closure_trampoline_table_page)
  5542. .rept PAGE_MAX_SIZE / FFI_TRAMPOLINE_SIZE
  5543. adr ip, #-PAGE_MAX_SIZE @ the config page is PAGE_MAX_SIZE behind the trampoline page
  5544. sub ip, #8 @ account for pc bias
  5545. ldr pc, [ip, #4] @ jump to ffi_closure_SYSV or ffi_closure_VFP
  5546. .endr
  5547. ARM_FUNC_END(ffi_closure_trampoline_table_page)
  5548. #endif
  5549. #else
  5550. ARM_FUNC_START(ffi_arm_trampoline)
  5551. 0: adr ip, 0b
  5552. ldr pc, 1f
  5553. 1: .long 0
  5554. ARM_FUNC_END(ffi_arm_trampoline)
  5555. #endif /* FFI_EXEC_TRAMPOLINE_TABLE */
  5556. #endif /* __arm__ */
  5557. #if defined __ELF__ && defined __linux__
  5558. .section .note.GNU-stack,"",%progbits
  5559. #endif
  5560. ====================File: src/closures.c====================
  5561. /* -----------------------------------------------------------------------
  5562. closures.c - Copyright (c) 2019 Anthony Green
  5563. Copyright (c) 2007, 2009, 2010 Red Hat, Inc.
  5564. Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc
  5565. Copyright (c) 2011 Plausible Labs Cooperative, Inc.
  5566. Code to allocate and deallocate memory for closures.
  5567. Permission is hereby granted, free of charge, to any person obtaining
  5568. a copy of this software and associated documentation files (the
  5569. ``Software''), to deal in the Software without restriction, including
  5570. without limitation the rights to use, copy, modify, merge, publish,
  5571. distribute, sublicense, and/or sell copies of the Software, and to
  5572. permit persons to whom the Software is furnished to do so, subject to
  5573. the following conditions:
  5574. The above copyright notice and this permission notice shall be included
  5575. in all copies or substantial portions of the Software.
  5576. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  5577. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  5578. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  5579. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  5580. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  5581. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  5582. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  5583. DEALINGS IN THE SOFTWARE.
  5584. ----------------------------------------------------------------------- */
  5585. #if defined __linux__ && !defined _GNU_SOURCE
  5586. #define _GNU_SOURCE 1
  5587. #endif
  5588. #include <fficonfig.h>
  5589. #include <ffi.h>
  5590. #include <ffi_common.h>
  5591. #ifdef __NetBSD__
  5592. #include <sys/param.h>
  5593. #endif
  5594. #if __NetBSD_Version__ - 0 >= 799007200
  5595. /* NetBSD with PROT_MPROTECT */
  5596. #include <sys/mman.h>
  5597. #include <stddef.h>
  5598. #include <unistd.h>
  5599. static const size_t overhead =
  5600. (sizeof(max_align_t) > sizeof(void *) + sizeof(size_t)) ?
  5601. sizeof(max_align_t)
  5602. : sizeof(void *) + sizeof(size_t);
  5603. #define ADD_TO_POINTER(p, d) ((void *)((uintptr_t)(p) + (d)))
  5604. void *
  5605. ffi_closure_alloc (size_t size, void **code)
  5606. {
  5607. static size_t page_size;
  5608. size_t rounded_size;
  5609. void *codeseg, *dataseg;
  5610. int prot;
  5611. /* Expect that PAX mprotect is active and a separate code mapping is necessary. */
  5612. if (!code)
  5613. return NULL;
  5614. /* Obtain system page size. */
  5615. if (!page_size)
  5616. page_size = sysconf(_SC_PAGESIZE);
  5617. /* Round allocation size up to the next page, keeping in mind the size field and pointer to code map. */
  5618. rounded_size = (size + overhead + page_size - 1) & ~(page_size - 1);
  5619. /* Primary mapping is RW, but request permission to switch to PROT_EXEC later. */
  5620. prot = PROT_READ | PROT_WRITE | PROT_MPROTECT(PROT_EXEC);
  5621. dataseg = mmap(NULL, rounded_size, prot, MAP_ANON | MAP_PRIVATE, -1, 0);
  5622. if (dataseg == MAP_FAILED)
  5623. return NULL;
  5624. /* Create secondary mapping and switch it to RX. */
  5625. codeseg = mremap(dataseg, rounded_size, NULL, rounded_size, MAP_REMAPDUP);
  5626. if (codeseg == MAP_FAILED) {
  5627. munmap(dataseg, rounded_size);
  5628. return NULL;
  5629. }
  5630. if (mprotect(codeseg, rounded_size, PROT_READ | PROT_EXEC) == -1) {
  5631. munmap(codeseg, rounded_size);
  5632. munmap(dataseg, rounded_size);
  5633. return NULL;
  5634. }
  5635. /* Remember allocation size and location of the secondary mapping for ffi_closure_free. */
  5636. memcpy(dataseg, &rounded_size, sizeof(rounded_size));
  5637. memcpy(ADD_TO_POINTER(dataseg, sizeof(size_t)), &codeseg, sizeof(void *));
  5638. *code = ADD_TO_POINTER(codeseg, overhead);
  5639. return ADD_TO_POINTER(dataseg, overhead);
  5640. }
  5641. void
  5642. ffi_closure_free (void *ptr)
  5643. {
  5644. void *codeseg, *dataseg;
  5645. size_t rounded_size;
  5646. dataseg = ADD_TO_POINTER(ptr, -overhead);
  5647. memcpy(&rounded_size, dataseg, sizeof(rounded_size));
  5648. memcpy(&codeseg, ADD_TO_POINTER(dataseg, sizeof(size_t)), sizeof(void *));
  5649. munmap(dataseg, rounded_size);
  5650. munmap(codeseg, rounded_size);
  5651. }
  5652. #else /* !NetBSD with PROT_MPROTECT */
  5653. #if !FFI_MMAP_EXEC_WRIT && !FFI_EXEC_TRAMPOLINE_TABLE
  5654. # if __linux__ && !defined(__ANDROID__)
  5655. /* This macro indicates it may be forbidden to map anonymous memory
  5656. with both write and execute permission. Code compiled when this
  5657. option is defined will attempt to map such pages once, but if it
  5658. fails, it falls back to creating a temporary file in a writable and
  5659. executable filesystem and mapping pages from it into separate
  5660. locations in the virtual memory space, one location writable and
  5661. another executable. */
  5662. # define FFI_MMAP_EXEC_WRIT 1
  5663. # define HAVE_MNTENT 1
  5664. # endif
  5665. # if defined(X86_WIN32) || defined(X86_WIN64) || defined(_M_ARM64) || defined(__OS2__)
  5666. /* Windows systems may have Data Execution Protection (DEP) enabled,
  5667. which requires the use of VirtualMalloc/VirtualFree to alloc/free
  5668. executable memory. */
  5669. # define FFI_MMAP_EXEC_WRIT 1
  5670. # endif
  5671. #endif
  5672. #if FFI_MMAP_EXEC_WRIT && !defined FFI_MMAP_EXEC_SELINUX
  5673. # if defined(__linux__) && !defined(__ANDROID__)
  5674. /* When defined to 1 check for SELinux and if SELinux is active,
  5675. don't attempt PROT_EXEC|PROT_WRITE mapping at all, as that
  5676. might cause audit messages. */
  5677. # define FFI_MMAP_EXEC_SELINUX 1
  5678. # endif
  5679. #endif
  5680. #if FFI_CLOSURES
  5681. #if FFI_EXEC_TRAMPOLINE_TABLE
  5682. #ifdef __MACH__
  5683. #include <mach/mach.h>
  5684. #include <pthread.h>
  5685. #include <stdio.h>
  5686. #include <stdlib.h>
  5687. extern void *ffi_closure_trampoline_table_page;
  5688. typedef struct ffi_trampoline_table ffi_trampoline_table;
  5689. typedef struct ffi_trampoline_table_entry ffi_trampoline_table_entry;
  5690. struct ffi_trampoline_table
  5691. {
  5692. /* contiguous writable and executable pages */
  5693. vm_address_t config_page;
  5694. vm_address_t trampoline_page;
  5695. /* free list tracking */
  5696. uint16_t free_count;
  5697. ffi_trampoline_table_entry *free_list;
  5698. ffi_trampoline_table_entry *free_list_pool;
  5699. ffi_trampoline_table *prev;
  5700. ffi_trampoline_table *next;
  5701. };
  5702. struct ffi_trampoline_table_entry
  5703. {
  5704. void *(*trampoline) (void);
  5705. ffi_trampoline_table_entry *next;
  5706. };
  5707. /* Total number of trampolines that fit in one trampoline table */
  5708. #define FFI_TRAMPOLINE_COUNT (PAGE_MAX_SIZE / FFI_TRAMPOLINE_SIZE)
  5709. static pthread_mutex_t ffi_trampoline_lock = PTHREAD_MUTEX_INITIALIZER;
  5710. static ffi_trampoline_table *ffi_trampoline_tables = NULL;
  5711. static ffi_trampoline_table *
  5712. ffi_trampoline_table_alloc (void)
  5713. {
  5714. ffi_trampoline_table *table;
  5715. vm_address_t config_page;
  5716. vm_address_t trampoline_page;
  5717. vm_address_t trampoline_page_template;
  5718. vm_prot_t cur_prot;
  5719. vm_prot_t max_prot;
  5720. kern_return_t kt;
  5721. uint16_t i;
  5722. /* Allocate two pages -- a config page and a placeholder page */
  5723. config_page = 0x0;
  5724. kt = vm_allocate (mach_task_self (), &config_page, PAGE_MAX_SIZE * 2,
  5725. VM_FLAGS_ANYWHERE);
  5726. if (kt != KERN_SUCCESS)
  5727. return NULL;
  5728. /* Remap the trampoline table on top of the placeholder page */
  5729. trampoline_page = config_page + PAGE_MAX_SIZE;
  5730. trampoline_page_template = (vm_address_t)&ffi_closure_trampoline_table_page;
  5731. #ifdef __arm__
  5732. /* ffi_closure_trampoline_table_page can be thumb-biased on some ARM archs */
  5733. trampoline_page_template &= ~1UL;
  5734. #endif
  5735. kt = vm_remap (mach_task_self (), &trampoline_page, PAGE_MAX_SIZE, 0x0,
  5736. VM_FLAGS_OVERWRITE, mach_task_self (), trampoline_page_template,
  5737. FALSE, &cur_prot, &max_prot, VM_INHERIT_SHARE);
  5738. if (kt != KERN_SUCCESS)
  5739. {
  5740. vm_deallocate (mach_task_self (), config_page, PAGE_MAX_SIZE * 2);
  5741. return NULL;
  5742. }
  5743. /* We have valid trampoline and config pages */
  5744. table = calloc (1, sizeof (ffi_trampoline_table));
  5745. table->free_count = FFI_TRAMPOLINE_COUNT;
  5746. table->config_page = config_page;
  5747. table->trampoline_page = trampoline_page;
  5748. /* Create and initialize the free list */
  5749. table->free_list_pool =
  5750. calloc (FFI_TRAMPOLINE_COUNT, sizeof (ffi_trampoline_table_entry));
  5751. for (i = 0; i < table->free_count; i++)
  5752. {
  5753. ffi_trampoline_table_entry *entry = &table->free_list_pool[i];
  5754. entry->trampoline =
  5755. (void *) (table->trampoline_page + (i * FFI_TRAMPOLINE_SIZE));
  5756. if (i < table->free_count - 1)
  5757. entry->next = &table->free_list_pool[i + 1];
  5758. }
  5759. table->free_list = table->free_list_pool;
  5760. return table;
  5761. }
  5762. static void
  5763. ffi_trampoline_table_free (ffi_trampoline_table *table)
  5764. {
  5765. /* Remove from the list */
  5766. if (table->prev != NULL)
  5767. table->prev->next = table->next;
  5768. if (table->next != NULL)
  5769. table->next->prev = table->prev;
  5770. /* Deallocate pages */
  5771. vm_deallocate (mach_task_self (), table->config_page, PAGE_MAX_SIZE * 2);
  5772. /* Deallocate free list */
  5773. free (table->free_list_pool);
  5774. free (table);
  5775. }
  5776. void *
  5777. ffi_closure_alloc (size_t size, void **code)
  5778. {
  5779. /* Create the closure */
  5780. ffi_closure *closure = malloc (size);
  5781. if (closure == NULL)
  5782. return NULL;
  5783. pthread_mutex_lock (&ffi_trampoline_lock);
  5784. /* Check for an active trampoline table with available entries. */
  5785. ffi_trampoline_table *table = ffi_trampoline_tables;
  5786. if (table == NULL || table->free_list == NULL)
  5787. {
  5788. table = ffi_trampoline_table_alloc ();
  5789. if (table == NULL)
  5790. {
  5791. pthread_mutex_unlock (&ffi_trampoline_lock);
  5792. free (closure);
  5793. return NULL;
  5794. }
  5795. /* Insert the new table at the top of the list */
  5796. table->next = ffi_trampoline_tables;
  5797. if (table->next != NULL)
  5798. table->next->prev = table;
  5799. ffi_trampoline_tables = table;
  5800. }
  5801. /* Claim the free entry */
  5802. ffi_trampoline_table_entry *entry = ffi_trampoline_tables->free_list;
  5803. ffi_trampoline_tables->free_list = entry->next;
  5804. ffi_trampoline_tables->free_count--;
  5805. entry->next = NULL;
  5806. pthread_mutex_unlock (&ffi_trampoline_lock);
  5807. /* Initialize the return values */
  5808. *code = entry->trampoline;
  5809. closure->trampoline_table = table;
  5810. closure->trampoline_table_entry = entry;
  5811. return closure;
  5812. }
  5813. void
  5814. ffi_closure_free (void *ptr)
  5815. {
  5816. ffi_closure *closure = ptr;
  5817. pthread_mutex_lock (&ffi_trampoline_lock);
  5818. /* Fetch the table and entry references */
  5819. ffi_trampoline_table *table = closure->trampoline_table;
  5820. ffi_trampoline_table_entry *entry = closure->trampoline_table_entry;
  5821. /* Return the entry to the free list */
  5822. entry->next = table->free_list;
  5823. table->free_list = entry;
  5824. table->free_count++;
  5825. /* If all trampolines within this table are free, and at least one other table exists, deallocate
  5826. * the table */
  5827. if (table->free_count == FFI_TRAMPOLINE_COUNT
  5828. && ffi_trampoline_tables != table)
  5829. {
  5830. ffi_trampoline_table_free (table);
  5831. }
  5832. else if (ffi_trampoline_tables != table)
  5833. {
  5834. /* Otherwise, bump this table to the top of the list */
  5835. table->prev = NULL;
  5836. table->next = ffi_trampoline_tables;
  5837. if (ffi_trampoline_tables != NULL)
  5838. ffi_trampoline_tables->prev = table;
  5839. ffi_trampoline_tables = table;
  5840. }
  5841. pthread_mutex_unlock (&ffi_trampoline_lock);
  5842. /* Free the closure */
  5843. free (closure);
  5844. }
  5845. #endif
  5846. // Per-target implementation; It's unclear what can reasonable be shared between two OS/architecture implementations.
  5847. #elif FFI_MMAP_EXEC_WRIT /* !FFI_EXEC_TRAMPOLINE_TABLE */
  5848. #define USE_LOCKS 1
  5849. #define USE_DL_PREFIX 1
  5850. #ifdef __GNUC__
  5851. #ifndef USE_BUILTIN_FFS
  5852. #define USE_BUILTIN_FFS 1
  5853. #endif
  5854. #endif
  5855. /* We need to use mmap, not sbrk. */
  5856. #define HAVE_MORECORE 0
  5857. /* We could, in theory, support mremap, but it wouldn't buy us anything. */
  5858. #define HAVE_MREMAP 0
  5859. /* We have no use for this, so save some code and data. */
  5860. #define NO_MALLINFO 1
  5861. /* We need all allocations to be in regular segments, otherwise we
  5862. lose track of the corresponding code address. */
  5863. #define DEFAULT_MMAP_THRESHOLD MAX_SIZE_T
  5864. /* Don't allocate more than a page unless needed. */
  5865. #define DEFAULT_GRANULARITY ((size_t)malloc_getpagesize)
  5866. #include <sys/types.h>
  5867. #include <sys/stat.h>
  5868. #include <fcntl.h>
  5869. #include <errno.h>
  5870. #ifndef _MSC_VER
  5871. #include <unistd.h>
  5872. #endif
  5873. #include <string.h>
  5874. #include <stdio.h>
  5875. #if !defined(X86_WIN32) && !defined(X86_WIN64) && !defined(_M_ARM64)
  5876. #ifdef HAVE_MNTENT
  5877. #include <mntent.h>
  5878. #endif /* HAVE_MNTENT */
  5879. #include <sys/param.h>
  5880. #include <pthread.h>
  5881. /* We don't want sys/mman.h to be included after we redefine mmap and
  5882. dlmunmap. */
  5883. #include <sys/mman.h>
  5884. #define LACKS_SYS_MMAN_H 1
  5885. #if FFI_MMAP_EXEC_SELINUX
  5886. #include <sys/statfs.h>
  5887. #include <stdlib.h>
  5888. static int selinux_enabled = -1;
  5889. static int
  5890. selinux_enabled_check (void)
  5891. {
  5892. struct statfs sfs;
  5893. FILE *f;
  5894. char *buf = NULL;
  5895. size_t len = 0;
  5896. if (statfs ("/selinux", &sfs) >= 0
  5897. && (unsigned int) sfs.f_type == 0xf97cff8cU)
  5898. return 1;
  5899. f = fopen ("/proc/mounts", "r");
  5900. if (f == NULL)
  5901. return 0;
  5902. while (getline (&buf, &len, f) >= 0)
  5903. {
  5904. char *p = strchr (buf, ' ');
  5905. if (p == NULL)
  5906. break;
  5907. p = strchr (p + 1, ' ');
  5908. if (p == NULL)
  5909. break;
  5910. if (strncmp (p + 1, "selinuxfs ", 10) == 0)
  5911. {
  5912. free (buf);
  5913. fclose (f);
  5914. return 1;
  5915. }
  5916. }
  5917. free (buf);
  5918. fclose (f);
  5919. return 0;
  5920. }
  5921. #define is_selinux_enabled() (selinux_enabled >= 0 ? selinux_enabled \
  5922. : (selinux_enabled = selinux_enabled_check ()))
  5923. #else
  5924. #define is_selinux_enabled() 0
  5925. #endif /* !FFI_MMAP_EXEC_SELINUX */
  5926. /* On PaX enable kernels that have MPROTECT enable we can't use PROT_EXEC. */
  5927. #ifdef FFI_MMAP_EXEC_EMUTRAMP_PAX
  5928. #include <stdlib.h>
  5929. static int emutramp_enabled = -1;
  5930. static int
  5931. emutramp_enabled_check (void)
  5932. {
  5933. char *buf = NULL;
  5934. size_t len = 0;
  5935. FILE *f;
  5936. int ret;
  5937. f = fopen ("/proc/self/status", "r");
  5938. if (f == NULL)
  5939. return 0;
  5940. ret = 0;
  5941. while (getline (&buf, &len, f) != -1)
  5942. if (!strncmp (buf, "PaX:", 4))
  5943. {
  5944. char emutramp;
  5945. if (sscanf (buf, "%*s %*c%c", &emutramp) == 1)
  5946. ret = (emutramp == 'E');
  5947. break;
  5948. }
  5949. free (buf);
  5950. fclose (f);
  5951. return ret;
  5952. }
  5953. #define is_emutramp_enabled() (emutramp_enabled >= 0 ? emutramp_enabled \
  5954. : (emutramp_enabled = emutramp_enabled_check ()))
  5955. #endif /* FFI_MMAP_EXEC_EMUTRAMP_PAX */
  5956. #elif defined (__CYGWIN__) || defined(__INTERIX)
  5957. #include <sys/mman.h>
  5958. /* Cygwin is Linux-like, but not quite that Linux-like. */
  5959. #define is_selinux_enabled() 0
  5960. #endif /* !defined(X86_WIN32) && !defined(X86_WIN64) */
  5961. #ifndef FFI_MMAP_EXEC_EMUTRAMP_PAX
  5962. #define is_emutramp_enabled() 0
  5963. #endif /* FFI_MMAP_EXEC_EMUTRAMP_PAX */
  5964. /* Declare all functions defined in dlmalloc.c as static. */
  5965. static void *dlmalloc(size_t);
  5966. static void dlfree(void*);
  5967. static void *dlcalloc(size_t, size_t) MAYBE_UNUSED;
  5968. static void *dlrealloc(void *, size_t) MAYBE_UNUSED;
  5969. static void *dlmemalign(size_t, size_t) MAYBE_UNUSED;
  5970. static void *dlvalloc(size_t) MAYBE_UNUSED;
  5971. static int dlmallopt(int, int) MAYBE_UNUSED;
  5972. static size_t dlmalloc_footprint(void) MAYBE_UNUSED;
  5973. static size_t dlmalloc_max_footprint(void) MAYBE_UNUSED;
  5974. static void** dlindependent_calloc(size_t, size_t, void**) MAYBE_UNUSED;
  5975. static void** dlindependent_comalloc(size_t, size_t*, void**) MAYBE_UNUSED;
  5976. static void *dlpvalloc(size_t) MAYBE_UNUSED;
  5977. static int dlmalloc_trim(size_t) MAYBE_UNUSED;
  5978. static size_t dlmalloc_usable_size(void*) MAYBE_UNUSED;
  5979. static void dlmalloc_stats(void) MAYBE_UNUSED;
  5980. #if !(defined(X86_WIN32) || defined(X86_WIN64) || defined(_M_ARM64) || defined(__OS2__)) || defined (__CYGWIN__) || defined(__INTERIX)
  5981. /* Use these for mmap and munmap within dlmalloc.c. */
  5982. static void *dlmmap(void *, size_t, int, int, int, off_t);
  5983. static int dlmunmap(void *, size_t);
  5984. #endif /* !(defined(X86_WIN32) || defined(X86_WIN64) || defined(__OS2__)) || defined (__CYGWIN__) || defined(__INTERIX) */
  5985. #define mmap dlmmap
  5986. #define munmap dlmunmap
  5987. #include "dlmalloc.c"
  5988. #undef mmap
  5989. #undef munmap
  5990. #if !(defined(X86_WIN32) || defined(X86_WIN64) || defined(_M_ARM64) || defined(__OS2__)) || defined (__CYGWIN__) || defined(__INTERIX)
  5991. /* A mutex used to synchronize access to *exec* variables in this file. */
  5992. static pthread_mutex_t open_temp_exec_file_mutex = PTHREAD_MUTEX_INITIALIZER;
  5993. /* A file descriptor of a temporary file from which we'll map
  5994. executable pages. */
  5995. static int execfd = -1;
  5996. /* The amount of space already allocated from the temporary file. */
  5997. static size_t execsize = 0;
  5998. /* Open a temporary file name, and immediately unlink it. */
  5999. static int
  6000. open_temp_exec_file_name (char *name, int flags)
  6001. {
  6002. int fd;
  6003. #ifdef HAVE_MKOSTEMP
  6004. fd = mkostemp (name, flags);
  6005. #else
  6006. fd = mkstemp (name);
  6007. #endif
  6008. if (fd != -1)
  6009. unlink (name);
  6010. return fd;
  6011. }
  6012. /* Open a temporary file in the named directory. */
  6013. static int
  6014. open_temp_exec_file_dir (const char *dir)
  6015. {
  6016. static const char suffix[] = "/ffiXXXXXX";
  6017. int lendir, flags;
  6018. char *tempname;
  6019. #ifdef O_TMPFILE
  6020. int fd;
  6021. #endif
  6022. #ifdef O_CLOEXEC
  6023. flags = O_CLOEXEC;
  6024. #else
  6025. flags = 0;
  6026. #endif
  6027. #ifdef O_TMPFILE
  6028. fd = open (dir, flags | O_RDWR | O_EXCL | O_TMPFILE, 0700);
  6029. /* If the running system does not support the O_TMPFILE flag then retry without it. */
  6030. if (fd != -1 || (errno != EINVAL && errno != EISDIR && errno != EOPNOTSUPP)) {
  6031. return fd;
  6032. } else {
  6033. errno = 0;
  6034. }
  6035. #endif
  6036. lendir = (int) strlen (dir);
  6037. tempname = __builtin_alloca (lendir + sizeof (suffix));
  6038. if (!tempname)
  6039. return -1;
  6040. memcpy (tempname, dir, lendir);
  6041. memcpy (tempname + lendir, suffix, sizeof (suffix));
  6042. return open_temp_exec_file_name (tempname, flags);
  6043. }
  6044. /* Open a temporary file in the directory in the named environment
  6045. variable. */
  6046. static int
  6047. open_temp_exec_file_env (const char *envvar)
  6048. {
  6049. const char *value = getenv (envvar);
  6050. if (!value)
  6051. return -1;
  6052. return open_temp_exec_file_dir (value);
  6053. }
  6054. #ifdef HAVE_MNTENT
  6055. /* Open a temporary file in an executable and writable mount point
  6056. listed in the mounts file. Subsequent calls with the same mounts
  6057. keep searching for mount points in the same file. Providing NULL
  6058. as the mounts file closes the file. */
  6059. static int
  6060. open_temp_exec_file_mnt (const char *mounts)
  6061. {
  6062. static const char *last_mounts;
  6063. static FILE *last_mntent;
  6064. if (mounts != last_mounts)
  6065. {
  6066. if (last_mntent)
  6067. endmntent (last_mntent);
  6068. last_mounts = mounts;
  6069. if (mounts)
  6070. last_mntent = setmntent (mounts, "r");
  6071. else
  6072. last_mntent = NULL;
  6073. }
  6074. if (!last_mntent)
  6075. return -1;
  6076. for (;;)
  6077. {
  6078. int fd;
  6079. struct mntent mnt;
  6080. char buf[MAXPATHLEN * 3];
  6081. if (getmntent_r (last_mntent, &mnt, buf, sizeof (buf)) == NULL)
  6082. return -1;
  6083. if (hasmntopt (&mnt, "ro")
  6084. || hasmntopt (&mnt, "noexec")
  6085. || access (mnt.mnt_dir, W_OK))
  6086. continue;
  6087. fd = open_temp_exec_file_dir (mnt.mnt_dir);
  6088. if (fd != -1)
  6089. return fd;
  6090. }
  6091. }
  6092. #endif /* HAVE_MNTENT */
  6093. /* Instructions to look for a location to hold a temporary file that
  6094. can be mapped in for execution. */
  6095. static struct
  6096. {
  6097. int (*func)(const char *);
  6098. const char *arg;
  6099. int repeat;
  6100. } open_temp_exec_file_opts[] = {
  6101. { open_temp_exec_file_env, "TMPDIR", 0 },
  6102. { open_temp_exec_file_dir, "/tmp", 0 },
  6103. { open_temp_exec_file_dir, "/var/tmp", 0 },
  6104. { open_temp_exec_file_dir, "/dev/shm", 0 },
  6105. { open_temp_exec_file_env, "HOME", 0 },
  6106. #ifdef HAVE_MNTENT
  6107. { open_temp_exec_file_mnt, "/etc/mtab", 1 },
  6108. { open_temp_exec_file_mnt, "/proc/mounts", 1 },
  6109. #endif /* HAVE_MNTENT */
  6110. };
  6111. /* Current index into open_temp_exec_file_opts. */
  6112. static int open_temp_exec_file_opts_idx = 0;
  6113. /* Reset a current multi-call func, then advances to the next entry.
  6114. If we're at the last, go back to the first and return nonzero,
  6115. otherwise return zero. */
  6116. static int
  6117. open_temp_exec_file_opts_next (void)
  6118. {
  6119. if (open_temp_exec_file_opts[open_temp_exec_file_opts_idx].repeat)
  6120. open_temp_exec_file_opts[open_temp_exec_file_opts_idx].func (NULL);
  6121. open_temp_exec_file_opts_idx++;
  6122. if (open_temp_exec_file_opts_idx
  6123. == (sizeof (open_temp_exec_file_opts)
  6124. / sizeof (*open_temp_exec_file_opts)))
  6125. {
  6126. open_temp_exec_file_opts_idx = 0;
  6127. return 1;
  6128. }
  6129. return 0;
  6130. }
  6131. /* Return a file descriptor of a temporary zero-sized file in a
  6132. writable and executable filesystem. */
  6133. static int
  6134. open_temp_exec_file (void)
  6135. {
  6136. int fd;
  6137. do
  6138. {
  6139. fd = open_temp_exec_file_opts[open_temp_exec_file_opts_idx].func
  6140. (open_temp_exec_file_opts[open_temp_exec_file_opts_idx].arg);
  6141. if (!open_temp_exec_file_opts[open_temp_exec_file_opts_idx].repeat
  6142. || fd == -1)
  6143. {
  6144. if (open_temp_exec_file_opts_next ())
  6145. break;
  6146. }
  6147. }
  6148. while (fd == -1);
  6149. return fd;
  6150. }
  6151. /* We need to allocate space in a file that will be backing a writable
  6152. mapping. Several problems exist with the usual approaches:
  6153. - fallocate() is Linux-only
  6154. - posix_fallocate() is not available on all platforms
  6155. - ftruncate() does not allocate space on filesystems with sparse files
  6156. Failure to allocate the space will cause SIGBUS to be thrown when
  6157. the mapping is subsequently written to. */
  6158. static int
  6159. allocate_space (int fd, off_t offset, off_t len)
  6160. {
  6161. static size_t page_size;
  6162. /* Obtain system page size. */
  6163. if (!page_size)
  6164. page_size = sysconf(_SC_PAGESIZE);
  6165. unsigned char buf[page_size];
  6166. memset (buf, 0, page_size);
  6167. while (len > 0)
  6168. {
  6169. off_t to_write = (len < page_size) ? len : page_size;
  6170. if (write (fd, buf, to_write) < to_write)
  6171. return -1;
  6172. len -= to_write;
  6173. }
  6174. return 0;
  6175. }
  6176. /* Map in a chunk of memory from the temporary exec file into separate
  6177. locations in the virtual memory address space, one writable and one
  6178. executable. Returns the address of the writable portion, after
  6179. storing an offset to the corresponding executable portion at the
  6180. last word of the requested chunk. */
  6181. static void *
  6182. dlmmap_locked (void *start, size_t length, int prot, int flags, off_t offset)
  6183. {
  6184. void *ptr;
  6185. if (execfd == -1)
  6186. {
  6187. open_temp_exec_file_opts_idx = 0;
  6188. retry_open:
  6189. execfd = open_temp_exec_file ();
  6190. if (execfd == -1)
  6191. return MFAIL;
  6192. }
  6193. offset = execsize;
  6194. if (allocate_space (execfd, offset, length))
  6195. return MFAIL;
  6196. flags &= ~(MAP_PRIVATE | MAP_ANONYMOUS);
  6197. flags |= MAP_SHARED;
  6198. ptr = mmap (NULL, length, (prot & ~PROT_WRITE) | PROT_EXEC,
  6199. flags, execfd, offset);
  6200. if (ptr == MFAIL)
  6201. {
  6202. if (!offset)
  6203. {
  6204. close (execfd);
  6205. goto retry_open;
  6206. }
  6207. if (ftruncate (execfd, offset) != 0)
  6208. {
  6209. /* Fixme : Error logs can be added here. Returning an error for
  6210. * ftruncte() will not add any advantage as it is being
  6211. * validating in the error case. */
  6212. }
  6213. return MFAIL;
  6214. }
  6215. else if (!offset
  6216. && open_temp_exec_file_opts[open_temp_exec_file_opts_idx].repeat)
  6217. open_temp_exec_file_opts_next ();
  6218. start = mmap (start, length, prot, flags, execfd, offset);
  6219. if (start == MFAIL)
  6220. {
  6221. munmap (ptr, length);
  6222. if (ftruncate (execfd, offset) != 0)
  6223. {
  6224. /* Fixme : Error logs can be added here. Returning an error for
  6225. * ftruncte() will not add any advantage as it is being
  6226. * validating in the error case. */
  6227. }
  6228. return start;
  6229. }
  6230. mmap_exec_offset ((char *)start, length) = (char*)ptr - (char*)start;
  6231. execsize += length;
  6232. return start;
  6233. }
  6234. /* Map in a writable and executable chunk of memory if possible.
  6235. Failing that, fall back to dlmmap_locked. */
  6236. static void *
  6237. dlmmap (void *start, size_t length, int prot,
  6238. int flags, int fd, off_t offset)
  6239. {
  6240. void *ptr;
  6241. assert (start == NULL && length % malloc_getpagesize == 0
  6242. && prot == (PROT_READ | PROT_WRITE)
  6243. && flags == (MAP_PRIVATE | MAP_ANONYMOUS)
  6244. && fd == -1 && offset == 0);
  6245. if (execfd == -1 && is_emutramp_enabled ())
  6246. {
  6247. ptr = mmap (start, length, prot & ~PROT_EXEC, flags, fd, offset);
  6248. return ptr;
  6249. }
  6250. if (execfd == -1 && !is_selinux_enabled ())
  6251. {
  6252. ptr = mmap (start, length, prot | PROT_EXEC, flags, fd, offset);
  6253. if (ptr != MFAIL || (errno != EPERM && errno != EACCES))
  6254. /* Cool, no need to mess with separate segments. */
  6255. return ptr;
  6256. /* If MREMAP_DUP is ever introduced and implemented, try mmap
  6257. with ((prot & ~PROT_WRITE) | PROT_EXEC) and mremap with
  6258. MREMAP_DUP and prot at this point. */
  6259. }
  6260. if (execsize == 0 || execfd == -1)
  6261. {
  6262. pthread_mutex_lock (&open_temp_exec_file_mutex);
  6263. ptr = dlmmap_locked (start, length, prot, flags, offset);
  6264. pthread_mutex_unlock (&open_temp_exec_file_mutex);
  6265. return ptr;
  6266. }
  6267. return dlmmap_locked (start, length, prot, flags, offset);
  6268. }
  6269. /* Release memory at the given address, as well as the corresponding
  6270. executable page if it's separate. */
  6271. static int
  6272. dlmunmap (void *start, size_t length)
  6273. {
  6274. /* We don't bother decreasing execsize or truncating the file, since
  6275. we can't quite tell whether we're unmapping the end of the file.
  6276. We don't expect frequent deallocation anyway. If we did, we
  6277. could locate pages in the file by writing to the pages being
  6278. deallocated and checking that the file contents change.
  6279. Yuck. */
  6280. msegmentptr seg = segment_holding (gm, start);
  6281. void *code;
  6282. if (seg && (code = add_segment_exec_offset (start, seg)) != start)
  6283. {
  6284. int ret = munmap (code, length);
  6285. if (ret)
  6286. return ret;
  6287. }
  6288. return munmap (start, length);
  6289. }
  6290. #if FFI_CLOSURE_FREE_CODE
  6291. /* Return segment holding given code address. */
  6292. static msegmentptr
  6293. segment_holding_code (mstate m, char* addr)
  6294. {
  6295. msegmentptr sp = &m->seg;
  6296. for (;;) {
  6297. if (addr >= add_segment_exec_offset (sp->base, sp)
  6298. && addr < add_segment_exec_offset (sp->base, sp) + sp->size)
  6299. return sp;
  6300. if ((sp = sp->next) == 0)
  6301. return 0;
  6302. }
  6303. }
  6304. #endif
  6305. #endif /* !(defined(X86_WIN32) || defined(X86_WIN64) || defined(_M_ARM64) || defined(__OS2__)) || defined (__CYGWIN__) || defined(__INTERIX) */
  6306. /* Allocate a chunk of memory with the given size. Returns a pointer
  6307. to the writable address, and sets *CODE to the executable
  6308. corresponding virtual address. */
  6309. void *
  6310. ffi_closure_alloc (size_t size, void **code)
  6311. {
  6312. void *ptr;
  6313. if (!code)
  6314. return NULL;
  6315. ptr = dlmalloc (size);
  6316. if (ptr)
  6317. {
  6318. msegmentptr seg = segment_holding (gm, ptr);
  6319. *code = add_segment_exec_offset (ptr, seg);
  6320. }
  6321. return ptr;
  6322. }
  6323. void *
  6324. ffi_data_to_code_pointer (void *data)
  6325. {
  6326. msegmentptr seg = segment_holding (gm, data);
  6327. /* We expect closures to be allocated with ffi_closure_alloc(), in
  6328. which case seg will be non-NULL. However, some users take on the
  6329. burden of managing this memory themselves, in which case this
  6330. we'll just return data. */
  6331. if (seg)
  6332. return add_segment_exec_offset (data, seg);
  6333. else
  6334. return data;
  6335. }
  6336. /* Release a chunk of memory allocated with ffi_closure_alloc. If
  6337. FFI_CLOSURE_FREE_CODE is nonzero, the given address can be the
  6338. writable or the executable address given. Otherwise, only the
  6339. writable address can be provided here. */
  6340. void
  6341. ffi_closure_free (void *ptr)
  6342. {
  6343. #if FFI_CLOSURE_FREE_CODE
  6344. msegmentptr seg = segment_holding_code (gm, ptr);
  6345. if (seg)
  6346. ptr = sub_segment_exec_offset (ptr, seg);
  6347. #endif
  6348. dlfree (ptr);
  6349. }
  6350. # else /* ! FFI_MMAP_EXEC_WRIT */
  6351. /* On many systems, memory returned by malloc is writable and
  6352. executable, so just use it. */
  6353. #include <stdlib.h>
  6354. void *
  6355. ffi_closure_alloc (size_t size, void **code)
  6356. {
  6357. if (!code)
  6358. return NULL;
  6359. return *code = malloc (size);
  6360. }
  6361. void
  6362. ffi_closure_free (void *ptr)
  6363. {
  6364. free (ptr);
  6365. }
  6366. void *
  6367. ffi_data_to_code_pointer (void *data)
  6368. {
  6369. return data;
  6370. }
  6371. # endif /* ! FFI_MMAP_EXEC_WRIT */
  6372. #endif /* FFI_CLOSURES */
  6373. #endif /* NetBSD with PROT_MPROTECT */
  6374. ====================File: src/java_raw_api.c====================
  6375. /* -----------------------------------------------------------------------
  6376. java_raw_api.c - Copyright (c) 1999, 2007, 2008 Red Hat, Inc.
  6377. Cloned from raw_api.c
  6378. Raw_api.c author: Kresten Krab Thorup <krab@gnu.org>
  6379. Java_raw_api.c author: Hans-J. Boehm <hboehm@hpl.hp.com>
  6380. $Id $
  6381. Permission is hereby granted, free of charge, to any person obtaining
  6382. a copy of this software and associated documentation files (the
  6383. ``Software''), to deal in the Software without restriction, including
  6384. without limitation the rights to use, copy, modify, merge, publish,
  6385. distribute, sublicense, and/or sell copies of the Software, and to
  6386. permit persons to whom the Software is furnished to do so, subject to
  6387. the following conditions:
  6388. The above copyright notice and this permission notice shall be included
  6389. in all copies or substantial portions of the Software.
  6390. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  6391. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  6392. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  6393. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  6394. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  6395. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  6396. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  6397. DEALINGS IN THE SOFTWARE.
  6398. ----------------------------------------------------------------------- */
  6399. /* This defines a Java- and 64-bit specific variant of the raw API. */
  6400. /* It assumes that "raw" argument blocks look like Java stacks on a */
  6401. /* 64-bit machine. Arguments that can be stored in a single stack */
  6402. /* stack slots (longs, doubles) occupy 128 bits, but only the first */
  6403. /* 64 bits are actually used. */
  6404. #include <ffi.h>
  6405. #include <ffi_common.h>
  6406. #include <stdlib.h>
  6407. #if !defined(NO_JAVA_RAW_API)
  6408. size_t
  6409. ffi_java_raw_size (ffi_cif *cif)
  6410. {
  6411. size_t result = 0;
  6412. int i;
  6413. ffi_type **at = cif->arg_types;
  6414. for (i = cif->nargs-1; i >= 0; i--, at++)
  6415. {
  6416. switch((*at) -> type) {
  6417. case FFI_TYPE_UINT64:
  6418. case FFI_TYPE_SINT64:
  6419. case FFI_TYPE_DOUBLE:
  6420. result += 2 * FFI_SIZEOF_JAVA_RAW;
  6421. break;
  6422. case FFI_TYPE_STRUCT:
  6423. /* No structure parameters in Java. */
  6424. abort();
  6425. case FFI_TYPE_COMPLEX:
  6426. /* Not supported yet. */
  6427. abort();
  6428. default:
  6429. result += FFI_SIZEOF_JAVA_RAW;
  6430. }
  6431. }
  6432. return result;
  6433. }
  6434. void
  6435. ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_java_raw *raw, void **args)
  6436. {
  6437. unsigned i;
  6438. ffi_type **tp = cif->arg_types;
  6439. #if WORDS_BIGENDIAN
  6440. for (i = 0; i < cif->nargs; i++, tp++, args++)
  6441. {
  6442. switch ((*tp)->type)
  6443. {
  6444. case FFI_TYPE_UINT8:
  6445. case FFI_TYPE_SINT8:
  6446. *args = (void*) ((char*)(raw++) + 3);
  6447. break;
  6448. case FFI_TYPE_UINT16:
  6449. case FFI_TYPE_SINT16:
  6450. *args = (void*) ((char*)(raw++) + 2);
  6451. break;
  6452. #if FFI_SIZEOF_JAVA_RAW == 8
  6453. case FFI_TYPE_UINT64:
  6454. case FFI_TYPE_SINT64:
  6455. case FFI_TYPE_DOUBLE:
  6456. *args = (void *)raw;
  6457. raw += 2;
  6458. break;
  6459. #endif
  6460. case FFI_TYPE_POINTER:
  6461. *args = (void*) &(raw++)->ptr;
  6462. break;
  6463. case FFI_TYPE_COMPLEX:
  6464. /* Not supported yet. */
  6465. abort();
  6466. default:
  6467. *args = raw;
  6468. raw +=
  6469. FFI_ALIGN ((*tp)->size, sizeof(ffi_java_raw)) / sizeof(ffi_java_raw);
  6470. }
  6471. }
  6472. #else /* WORDS_BIGENDIAN */
  6473. #if !PDP
  6474. /* then assume little endian */
  6475. for (i = 0; i < cif->nargs; i++, tp++, args++)
  6476. {
  6477. #if FFI_SIZEOF_JAVA_RAW == 8
  6478. switch((*tp)->type) {
  6479. case FFI_TYPE_UINT64:
  6480. case FFI_TYPE_SINT64:
  6481. case FFI_TYPE_DOUBLE:
  6482. *args = (void*) raw;
  6483. raw += 2;
  6484. break;
  6485. case FFI_TYPE_COMPLEX:
  6486. /* Not supported yet. */
  6487. abort();
  6488. default:
  6489. *args = (void*) raw++;
  6490. }
  6491. #else /* FFI_SIZEOF_JAVA_RAW != 8 */
  6492. *args = (void*) raw;
  6493. raw +=
  6494. FFI_ALIGN ((*tp)->size, sizeof(ffi_java_raw)) / sizeof(ffi_java_raw);
  6495. #endif /* FFI_SIZEOF_JAVA_RAW == 8 */
  6496. }
  6497. #else
  6498. #error "pdp endian not supported"
  6499. #endif /* ! PDP */
  6500. #endif /* WORDS_BIGENDIAN */
  6501. }
  6502. void
  6503. ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_java_raw *raw)
  6504. {
  6505. unsigned i;
  6506. ffi_type **tp = cif->arg_types;
  6507. for (i = 0; i < cif->nargs; i++, tp++, args++)
  6508. {
  6509. switch ((*tp)->type)
  6510. {
  6511. case FFI_TYPE_UINT8:
  6512. #if WORDS_BIGENDIAN
  6513. *(UINT32*)(raw++) = *(UINT8*) (*args);
  6514. #else
  6515. (raw++)->uint = *(UINT8*) (*args);
  6516. #endif
  6517. break;
  6518. case FFI_TYPE_SINT8:
  6519. #if WORDS_BIGENDIAN
  6520. *(SINT32*)(raw++) = *(SINT8*) (*args);
  6521. #else
  6522. (raw++)->sint = *(SINT8*) (*args);
  6523. #endif
  6524. break;
  6525. case FFI_TYPE_UINT16:
  6526. #if WORDS_BIGENDIAN
  6527. *(UINT32*)(raw++) = *(UINT16*) (*args);
  6528. #else
  6529. (raw++)->uint = *(UINT16*) (*args);
  6530. #endif
  6531. break;
  6532. case FFI_TYPE_SINT16:
  6533. #if WORDS_BIGENDIAN
  6534. *(SINT32*)(raw++) = *(SINT16*) (*args);
  6535. #else
  6536. (raw++)->sint = *(SINT16*) (*args);
  6537. #endif
  6538. break;
  6539. case FFI_TYPE_UINT32:
  6540. #if WORDS_BIGENDIAN
  6541. *(UINT32*)(raw++) = *(UINT32*) (*args);
  6542. #else
  6543. (raw++)->uint = *(UINT32*) (*args);
  6544. #endif
  6545. break;
  6546. case FFI_TYPE_SINT32:
  6547. #if WORDS_BIGENDIAN
  6548. *(SINT32*)(raw++) = *(SINT32*) (*args);
  6549. #else
  6550. (raw++)->sint = *(SINT32*) (*args);
  6551. #endif
  6552. break;
  6553. case FFI_TYPE_FLOAT:
  6554. (raw++)->flt = *(FLOAT32*) (*args);
  6555. break;
  6556. #if FFI_SIZEOF_JAVA_RAW == 8
  6557. case FFI_TYPE_UINT64:
  6558. case FFI_TYPE_SINT64:
  6559. case FFI_TYPE_DOUBLE:
  6560. raw->uint = *(UINT64*) (*args);
  6561. raw += 2;
  6562. break;
  6563. #endif
  6564. case FFI_TYPE_POINTER:
  6565. (raw++)->ptr = **(void***) args;
  6566. break;
  6567. default:
  6568. #if FFI_SIZEOF_JAVA_RAW == 8
  6569. FFI_ASSERT(0); /* Should have covered all cases */
  6570. #else
  6571. memcpy ((void*) raw->data, (void*)*args, (*tp)->size);
  6572. raw +=
  6573. FFI_ALIGN ((*tp)->size, sizeof(ffi_java_raw)) / sizeof(ffi_java_raw);
  6574. #endif
  6575. }
  6576. }
  6577. }
  6578. #if !FFI_NATIVE_RAW_API
  6579. static void
  6580. ffi_java_rvalue_to_raw (ffi_cif *cif, void *rvalue)
  6581. {
  6582. #if WORDS_BIGENDIAN && FFI_SIZEOF_ARG == 8
  6583. switch (cif->rtype->type)
  6584. {
  6585. case FFI_TYPE_UINT8:
  6586. case FFI_TYPE_UINT16:
  6587. case FFI_TYPE_UINT32:
  6588. *(UINT64 *)rvalue <<= 32;
  6589. break;
  6590. case FFI_TYPE_SINT8:
  6591. case FFI_TYPE_SINT16:
  6592. case FFI_TYPE_SINT32:
  6593. case FFI_TYPE_INT:
  6594. #if FFI_SIZEOF_JAVA_RAW == 4
  6595. case FFI_TYPE_POINTER:
  6596. #endif
  6597. *(SINT64 *)rvalue <<= 32;
  6598. break;
  6599. case FFI_TYPE_COMPLEX:
  6600. /* Not supported yet. */
  6601. abort();
  6602. default:
  6603. break;
  6604. }
  6605. #endif
  6606. }
  6607. static void
  6608. ffi_java_raw_to_rvalue (ffi_cif *cif, void *rvalue)
  6609. {
  6610. #if WORDS_BIGENDIAN && FFI_SIZEOF_ARG == 8
  6611. switch (cif->rtype->type)
  6612. {
  6613. case FFI_TYPE_UINT8:
  6614. case FFI_TYPE_UINT16:
  6615. case FFI_TYPE_UINT32:
  6616. *(UINT64 *)rvalue >>= 32;
  6617. break;
  6618. case FFI_TYPE_SINT8:
  6619. case FFI_TYPE_SINT16:
  6620. case FFI_TYPE_SINT32:
  6621. case FFI_TYPE_INT:
  6622. *(SINT64 *)rvalue >>= 32;
  6623. break;
  6624. case FFI_TYPE_COMPLEX:
  6625. /* Not supported yet. */
  6626. abort();
  6627. default:
  6628. break;
  6629. }
  6630. #endif
  6631. }
  6632. /* This is a generic definition of ffi_raw_call, to be used if the
  6633. * native system does not provide a machine-specific implementation.
  6634. * Having this, allows code to be written for the raw API, without
  6635. * the need for system-specific code to handle input in that format;
  6636. * these following couple of functions will handle the translation forth
  6637. * and back automatically. */
  6638. void ffi_java_raw_call (ffi_cif *cif, void (*fn)(void), void *rvalue,
  6639. ffi_java_raw *raw)
  6640. {
  6641. void **avalue = (void**) alloca (cif->nargs * sizeof (void*));
  6642. ffi_java_raw_to_ptrarray (cif, raw, avalue);
  6643. ffi_call (cif, fn, rvalue, avalue);
  6644. ffi_java_rvalue_to_raw (cif, rvalue);
  6645. }
  6646. #if FFI_CLOSURES /* base system provides closures */
  6647. static void
  6648. ffi_java_translate_args (ffi_cif *cif, void *rvalue,
  6649. void **avalue, void *user_data)
  6650. {
  6651. ffi_java_raw *raw = (ffi_java_raw*)alloca (ffi_java_raw_size (cif));
  6652. ffi_raw_closure *cl = (ffi_raw_closure*)user_data;
  6653. ffi_java_ptrarray_to_raw (cif, avalue, raw);
  6654. (*cl->fun) (cif, rvalue, (ffi_raw*)raw, cl->user_data);
  6655. ffi_java_raw_to_rvalue (cif, rvalue);
  6656. }
  6657. ffi_status
  6658. ffi_prep_java_raw_closure_loc (ffi_java_raw_closure* cl,
  6659. ffi_cif *cif,
  6660. void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*),
  6661. void *user_data,
  6662. void *codeloc)
  6663. {
  6664. ffi_status status;
  6665. status = ffi_prep_closure_loc ((ffi_closure*) cl,
  6666. cif,
  6667. &ffi_java_translate_args,
  6668. codeloc,
  6669. codeloc);
  6670. if (status == FFI_OK)
  6671. {
  6672. cl->fun = fun;
  6673. cl->user_data = user_data;
  6674. }
  6675. return status;
  6676. }
  6677. /* Again, here is the generic version of ffi_prep_raw_closure, which
  6678. * will install an intermediate "hub" for translation of arguments from
  6679. * the pointer-array format, to the raw format */
  6680. ffi_status
  6681. ffi_prep_java_raw_closure (ffi_java_raw_closure* cl,
  6682. ffi_cif *cif,
  6683. void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*),
  6684. void *user_data)
  6685. {
  6686. return ffi_prep_java_raw_closure_loc (cl, cif, fun, user_data, cl);
  6687. }
  6688. #endif /* FFI_CLOSURES */
  6689. #endif /* !FFI_NATIVE_RAW_API */
  6690. #endif /* !NO_JAVA_RAW_API */
  6691. ====================File: src/powerpc/aix.S====================
  6692. /* -----------------------------------------------------------------------
  6693. aix.S - Copyright (c) 2002, 2009 Free Software Foundation, Inc.
  6694. based on darwin.S by John Hornkvist
  6695. PowerPC Assembly glue.
  6696. Permission is hereby granted, free of charge, to any person obtaining
  6697. a copy of this software and associated documentation files (the
  6698. ``Software''), to deal in the Software without restriction, including
  6699. without limitation the rights to use, copy, modify, merge, publish,
  6700. distribute, sublicense, and/or sell copies of the Software, and to
  6701. permit persons to whom the Software is furnished to do so, subject to
  6702. the following conditions:
  6703. The above copyright notice and this permission notice shall be included
  6704. in all copies or substantial portions of the Software.
  6705. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
  6706. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  6707. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  6708. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
  6709. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  6710. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  6711. OTHER DEALINGS IN THE SOFTWARE.
  6712. ----------------------------------------------------------------------- */
  6713. .set r0,0
  6714. .set r1,1
  6715. .set r2,2
  6716. .set r3,3
  6717. .set r4,4
  6718. .set r5,5
  6719. .set r6,6
  6720. .set r7,7
  6721. .set r8,8
  6722. .set r9,9
  6723. .set r10,10
  6724. .set r11,11
  6725. .set r12,12
  6726. .set r13,13
  6727. .set r14,14
  6728. .set r15,15
  6729. .set r16,16
  6730. .set r17,17
  6731. .set r18,18
  6732. .set r19,19
  6733. .set r20,20
  6734. .set r21,21
  6735. .set r22,22
  6736. .set r23,23
  6737. .set r24,24
  6738. .set r25,25
  6739. .set r26,26
  6740. .set r27,27
  6741. .set r28,28
  6742. .set r29,29
  6743. .set r30,30
  6744. .set r31,31
  6745. .set f0,0
  6746. .set f1,1
  6747. .set f2,2
  6748. .set f3,3
  6749. .set f4,4
  6750. .set f5,5
  6751. .set f6,6
  6752. .set f7,7
  6753. .set f8,8
  6754. .set f9,9
  6755. .set f10,10
  6756. .set f11,11
  6757. .set f12,12
  6758. .set f13,13
  6759. .set f14,14
  6760. .set f15,15
  6761. .set f16,16
  6762. .set f17,17
  6763. .set f18,18
  6764. .set f19,19
  6765. .set f20,20
  6766. .set f21,21
  6767. .extern .ffi_prep_args
  6768. #define LIBFFI_ASM
  6769. #include <fficonfig.h>
  6770. #include <ffi.h>
  6771. #define JUMPTARGET(name) name
  6772. #define L(x) x
  6773. .file "aix.S"
  6774. .toc
  6775. /* void ffi_call_AIX(extended_cif *ecif, unsigned long bytes,
  6776. * unsigned int flags, unsigned int *rvalue,
  6777. * void (*fn)(),
  6778. * void (*prep_args)(extended_cif*, unsigned *const));
  6779. * r3=ecif, r4=bytes, r5=flags, r6=rvalue, r7=fn, r8=prep_args
  6780. */
  6781. .csect .text[PR]
  6782. .align 2
  6783. .globl ffi_call_AIX
  6784. .globl .ffi_call_AIX
  6785. .csect ffi_call_AIX[DS]
  6786. ffi_call_AIX:
  6787. #ifdef __64BIT__
  6788. .llong .ffi_call_AIX, TOC[tc0], 0
  6789. .csect .text[PR]
  6790. .ffi_call_AIX:
  6791. .function .ffi_call_AIX,.ffi_call_AIX,16,044,LFE..0-LFB..0
  6792. .bf __LINE__
  6793. .line 1
  6794. LFB..0:
  6795. /* Save registers we use. */
  6796. mflr r0
  6797. std r28,-32(r1)
  6798. std r29,-24(r1)
  6799. std r30,-16(r1)
  6800. std r31, -8(r1)
  6801. std r0, 16(r1)
  6802. LCFI..0:
  6803. mr r28, r1 /* our AP. */
  6804. stdux r1, r1, r4
  6805. LCFI..1:
  6806. /* Save arguments over call... */
  6807. mr r31, r5 /* flags, */
  6808. mr r30, r6 /* rvalue, */
  6809. mr r29, r7 /* function address. */
  6810. std r2, 40(r1)
  6811. /* Call ffi_prep_args. */
  6812. mr r4, r1
  6813. bl .ffi_prep_args
  6814. nop
  6815. /* Now do the call. */
  6816. ld r0, 0(r29)
  6817. ld r2, 8(r29)
  6818. ld r11, 16(r29)
  6819. /* Set up cr1 with bits 4-7 of the flags. */
  6820. mtcrf 0x40, r31
  6821. mtctr r0
  6822. /* Load all those argument registers. */
  6823. /* We have set up a nice stack frame, just load it into registers. */
  6824. ld r3, 40+(1*8)(r1)
  6825. ld r4, 40+(2*8)(r1)
  6826. ld r5, 40+(3*8)(r1)
  6827. ld r6, 40+(4*8)(r1)
  6828. nop
  6829. ld r7, 40+(5*8)(r1)
  6830. ld r8, 40+(6*8)(r1)
  6831. ld r9, 40+(7*8)(r1)
  6832. ld r10,40+(8*8)(r1)
  6833. L1:
  6834. /* Load all the FP registers. */
  6835. bf 6,L2 /* 2f + 0x18 */
  6836. lfd f1,-32-(13*8)(r28)
  6837. lfd f2,-32-(12*8)(r28)
  6838. lfd f3,-32-(11*8)(r28)
  6839. lfd f4,-32-(10*8)(r28)
  6840. nop
  6841. lfd f5,-32-(9*8)(r28)
  6842. lfd f6,-32-(8*8)(r28)
  6843. lfd f7,-32-(7*8)(r28)
  6844. lfd f8,-32-(6*8)(r28)
  6845. nop
  6846. lfd f9,-32-(5*8)(r28)
  6847. lfd f10,-32-(4*8)(r28)
  6848. lfd f11,-32-(3*8)(r28)
  6849. lfd f12,-32-(2*8)(r28)
  6850. nop
  6851. lfd f13,-32-(1*8)(r28)
  6852. L2:
  6853. /* Make the call. */
  6854. bctrl
  6855. ld r2, 40(r1)
  6856. /* Now, deal with the return value. */
  6857. mtcrf 0x01, r31
  6858. bt 30, L(done_return_value)
  6859. bt 29, L(fp_return_value)
  6860. std r3, 0(r30)
  6861. /* Fall through... */
  6862. L(done_return_value):
  6863. /* Restore the registers we used and return. */
  6864. mr r1, r28
  6865. ld r0, 16(r28)
  6866. ld r28, -32(r1)
  6867. mtlr r0
  6868. ld r29, -24(r1)
  6869. ld r30, -16(r1)
  6870. ld r31, -8(r1)
  6871. blr
  6872. L(fp_return_value):
  6873. bf 28, L(float_return_value)
  6874. stfd f1, 0(r30)
  6875. bf 31, L(done_return_value)
  6876. stfd f2, 8(r30)
  6877. b L(done_return_value)
  6878. L(float_return_value):
  6879. stfs f1, 0(r30)
  6880. b L(done_return_value)
  6881. LFE..0:
  6882. #else /* ! __64BIT__ */
  6883. .long .ffi_call_AIX, TOC[tc0], 0
  6884. .csect .text[PR]
  6885. .ffi_call_AIX:
  6886. .function .ffi_call_AIX,.ffi_call_AIX,16,044,LFE..0-LFB..0
  6887. .bf __LINE__
  6888. .line 1
  6889. LFB..0:
  6890. /* Save registers we use. */
  6891. mflr r0
  6892. stw r28,-16(r1)
  6893. stw r29,-12(r1)
  6894. stw r30, -8(r1)
  6895. stw r31, -4(r1)
  6896. stw r0, 8(r1)
  6897. LCFI..0:
  6898. mr r28, r1 /* out AP. */
  6899. stwux r1, r1, r4
  6900. LCFI..1:
  6901. /* Save arguments over call... */
  6902. mr r31, r5 /* flags, */
  6903. mr r30, r6 /* rvalue, */
  6904. mr r29, r7 /* function address, */
  6905. stw r2, 20(r1)
  6906. /* Call ffi_prep_args. */
  6907. mr r4, r1
  6908. bl .ffi_prep_args
  6909. nop
  6910. /* Now do the call. */
  6911. lwz r0, 0(r29)
  6912. lwz r2, 4(r29)
  6913. lwz r11, 8(r29)
  6914. /* Set up cr1 with bits 4-7 of the flags. */
  6915. mtcrf 0x40, r31
  6916. mtctr r0
  6917. /* Load all those argument registers. */
  6918. /* We have set up a nice stack frame, just load it into registers. */
  6919. lwz r3, 20+(1*4)(r1)
  6920. lwz r4, 20+(2*4)(r1)
  6921. lwz r5, 20+(3*4)(r1)
  6922. lwz r6, 20+(4*4)(r1)
  6923. nop
  6924. lwz r7, 20+(5*4)(r1)
  6925. lwz r8, 20+(6*4)(r1)
  6926. lwz r9, 20+(7*4)(r1)
  6927. lwz r10,20+(8*4)(r1)
  6928. L1:
  6929. /* Load all the FP registers. */
  6930. bf 6,L2 /* 2f + 0x18 */
  6931. lfd f1,-16-(13*8)(r28)
  6932. lfd f2,-16-(12*8)(r28)
  6933. lfd f3,-16-(11*8)(r28)
  6934. lfd f4,-16-(10*8)(r28)
  6935. nop
  6936. lfd f5,-16-(9*8)(r28)
  6937. lfd f6,-16-(8*8)(r28)
  6938. lfd f7,-16-(7*8)(r28)
  6939. lfd f8,-16-(6*8)(r28)
  6940. nop
  6941. lfd f9,-16-(5*8)(r28)
  6942. lfd f10,-16-(4*8)(r28)
  6943. lfd f11,-16-(3*8)(r28)
  6944. lfd f12,-16-(2*8)(r28)
  6945. nop
  6946. lfd f13,-16-(1*8)(r28)
  6947. L2:
  6948. /* Make the call. */
  6949. bctrl
  6950. lwz r2, 20(r1)
  6951. /* Now, deal with the return value. */
  6952. mtcrf 0x01, r31
  6953. bt 30, L(done_return_value)
  6954. bt 29, L(fp_return_value)
  6955. stw r3, 0(r30)
  6956. bf 28, L(done_return_value)
  6957. stw r4, 4(r30)
  6958. /* Fall through... */
  6959. L(done_return_value):
  6960. /* Restore the registers we used and return. */
  6961. mr r1, r28
  6962. lwz r0, 8(r28)
  6963. lwz r28,-16(r1)
  6964. mtlr r0
  6965. lwz r29,-12(r1)
  6966. lwz r30, -8(r1)
  6967. lwz r31, -4(r1)
  6968. blr
  6969. L(fp_return_value):
  6970. bf 28, L(float_return_value)
  6971. stfd f1, 0(r30)
  6972. b L(done_return_value)
  6973. L(float_return_value):
  6974. stfs f1, 0(r30)
  6975. b L(done_return_value)
  6976. LFE..0:
  6977. #endif
  6978. .ef __LINE__
  6979. .long 0
  6980. .byte 0,0,0,1,128,4,0,0
  6981. /* END(ffi_call_AIX) */
  6982. /* void ffi_call_go_AIX(extended_cif *ecif, unsigned long bytes,
  6983. * unsigned int flags, unsigned int *rvalue,
  6984. * void (*fn)(),
  6985. * void (*prep_args)(extended_cif*, unsigned *const),
  6986. * void *closure);
  6987. * r3=ecif, r4=bytes, r5=flags, r6=rvalue, r7=fn, r8=prep_args, r9=closure
  6988. */
  6989. .csect .text[PR]
  6990. .align 2
  6991. .globl ffi_call_go_AIX
  6992. .globl .ffi_call_go_AIX
  6993. .csect ffi_call_go_AIX[DS]
  6994. ffi_call_go_AIX:
  6995. #ifdef __64BIT__
  6996. .llong .ffi_call_go_AIX, TOC[tc0], 0
  6997. .csect .text[PR]
  6998. .ffi_call_go_AIX:
  6999. .function .ffi_call_go_AIX,.ffi_call_go_AIX,16,044,LFE..1-LFB..1
  7000. .bf __LINE__
  7001. .line 1
  7002. LFB..1:
  7003. /* Save registers we use. */
  7004. mflr r0
  7005. std r28,-32(r1)
  7006. std r29,-24(r1)
  7007. std r30,-16(r1)
  7008. std r31, -8(r1)
  7009. std r9, 8(r1) /* closure, saved in cr field. */
  7010. std r0, 16(r1)
  7011. LCFI..2:
  7012. mr r28, r1 /* our AP. */
  7013. stdux r1, r1, r4
  7014. LCFI..3:
  7015. /* Save arguments over call... */
  7016. mr r31, r5 /* flags, */
  7017. mr r30, r6 /* rvalue, */
  7018. mr r29, r7 /* function address, */
  7019. std r2, 40(r1)
  7020. /* Call ffi_prep_args. */
  7021. mr r4, r1
  7022. bl .ffi_prep_args
  7023. nop
  7024. /* Now do the call. */
  7025. ld r0, 0(r29)
  7026. ld r2, 8(r29)
  7027. ld r11, 8(r28) /* closure */
  7028. /* Set up cr1 with bits 4-7 of the flags. */
  7029. mtcrf 0x40, r31
  7030. mtctr r0
  7031. /* Load all those argument registers. */
  7032. /* We have set up a nice stack frame, just load it into registers. */
  7033. ld r3, 40+(1*8)(r1)
  7034. ld r4, 40+(2*8)(r1)
  7035. ld r5, 40+(3*8)(r1)
  7036. ld r6, 40+(4*8)(r1)
  7037. nop
  7038. ld r7, 40+(5*8)(r1)
  7039. ld r8, 40+(6*8)(r1)
  7040. ld r9, 40+(7*8)(r1)
  7041. ld r10,40+(8*8)(r1)
  7042. b L1
  7043. LFE..1:
  7044. #else /* ! __64BIT__ */
  7045. .long .ffi_call_go_AIX, TOC[tc0], 0
  7046. .csect .text[PR]
  7047. .ffi_call_go_AIX:
  7048. .function .ffi_call_go_AIX,.ffi_call_go_AIX,16,044,LFE..1-LFB..1
  7049. .bf __LINE__
  7050. .line 1
  7051. /* Save registers we use. */
  7052. LFB..1:
  7053. mflr r0
  7054. stw r28,-16(r1)
  7055. stw r29,-12(r1)
  7056. stw r30, -8(r1)
  7057. stw r31, -4(r1)
  7058. stw r9, 4(r1) /* closure, saved in cr field. */
  7059. stw r0, 8(r1)
  7060. LCFI..2:
  7061. mr r28, r1 /* out AP. */
  7062. stwux r1, r1, r4
  7063. LCFI..3:
  7064. /* Save arguments over call... */
  7065. mr r31, r5 /* flags, */
  7066. mr r30, r6 /* rvalue, */
  7067. mr r29, r7 /* function address, */
  7068. stw r2, 20(r1)
  7069. /* Call ffi_prep_args. */
  7070. mr r4, r1
  7071. bl .ffi_prep_args
  7072. nop
  7073. /* Now do the call. */
  7074. lwz r0, 0(r29)
  7075. lwz r2, 4(r29)
  7076. lwz r11, 4(r28) /* closure */
  7077. /* Set up cr1 with bits 4-7 of the flags. */
  7078. mtcrf 0x40, r31
  7079. mtctr r0
  7080. /* Load all those argument registers. */
  7081. /* We have set up a nice stack frame, just load it into registers. */
  7082. lwz r3, 20+(1*4)(r1)
  7083. lwz r4, 20+(2*4)(r1)
  7084. lwz r5, 20+(3*4)(r1)
  7085. lwz r6, 20+(4*4)(r1)
  7086. nop
  7087. lwz r7, 20+(5*4)(r1)
  7088. lwz r8, 20+(6*4)(r1)
  7089. lwz r9, 20+(7*4)(r1)
  7090. lwz r10,20+(8*4)(r1)
  7091. b L1
  7092. LFE..1:
  7093. #endif
  7094. .ef __LINE__
  7095. .long 0
  7096. .byte 0,0,0,1,128,4,0,0
  7097. /* END(ffi_call_go_AIX) */
  7098. .csect .text[PR]
  7099. .align 2
  7100. .globl ffi_call_DARWIN
  7101. .globl .ffi_call_DARWIN
  7102. .csect ffi_call_DARWIN[DS]
  7103. ffi_call_DARWIN:
  7104. #ifdef __64BIT__
  7105. .llong .ffi_call_DARWIN, TOC[tc0], 0
  7106. #else
  7107. .long .ffi_call_DARWIN, TOC[tc0], 0
  7108. #endif
  7109. .csect .text[PR]
  7110. .ffi_call_DARWIN:
  7111. blr
  7112. .long 0
  7113. .byte 0,0,0,0,0,0,0,0
  7114. /* END(ffi_call_DARWIN) */
  7115. /* EH frame stuff. */
  7116. #define LR_REGNO 0x41 /* Link Register (65), see rs6000.md */
  7117. #ifdef __64BIT__
  7118. #define PTRSIZE 8
  7119. #define LOG2_PTRSIZE 3
  7120. #define FDE_ENCODING 0x1c /* DW_EH_PE_pcrel|DW_EH_PE_sdata8 */
  7121. #define EH_DATA_ALIGN_FACT 0x78 /* LEB128 -8 */
  7122. #else
  7123. #define PTRSIZE 4
  7124. #define LOG2_PTRSIZE 2
  7125. #define FDE_ENCODING 0x1b /* DW_EH_PE_pcrel|DW_EH_PE_sdata4 */
  7126. #define EH_DATA_ALIGN_FACT 0x7c /* LEB128 -4 */
  7127. #endif
  7128. .csect _unwind.ro_[RO],4
  7129. .align LOG2_PTRSIZE
  7130. .globl _GLOBAL__F_libffi_src_powerpc_aix
  7131. _GLOBAL__F_libffi_src_powerpc_aix:
  7132. Lframe..1:
  7133. .vbyte 4,LECIE..1-LSCIE..1 /* CIE Length */
  7134. LSCIE..1:
  7135. .vbyte 4,0 /* CIE Identifier Tag */
  7136. .byte 0x3 /* CIE Version */
  7137. .byte "zR" /* CIE Augmentation */
  7138. .byte 0
  7139. .byte 0x1 /* uleb128 0x1; CIE Code Alignment Factor */
  7140. .byte EH_DATA_ALIGN_FACT /* leb128 -4/-8; CIE Data Alignment Factor */
  7141. .byte 0x41 /* CIE RA Column */
  7142. .byte 0x1 /* uleb128 0x1; Augmentation size */
  7143. .byte FDE_ENCODING /* FDE Encoding (pcrel|sdata4/8) */
  7144. .byte 0xc /* DW_CFA_def_cfa */
  7145. .byte 0x1 /* uleb128 0x1; Register r1 */
  7146. .byte 0 /* uleb128 0x0; Offset 0 */
  7147. .align LOG2_PTRSIZE
  7148. LECIE..1:
  7149. LSFDE..1:
  7150. .vbyte 4,LEFDE..1-LASFDE..1 /* FDE Length */
  7151. LASFDE..1:
  7152. .vbyte 4,LASFDE..1-Lframe..1 /* FDE CIE offset */
  7153. .vbyte PTRSIZE,LFB..0-$ /* FDE initial location */
  7154. .vbyte PTRSIZE,LFE..0-LFB..0 /* FDE address range */
  7155. .byte 0 /* uleb128 0x0; Augmentation size */
  7156. .byte 0x4 /* DW_CFA_advance_loc4 */
  7157. .vbyte 4,LCFI..0-LFB..0
  7158. .byte 0x11 /* DW_CFA_def_offset_extended_sf */
  7159. .byte LR_REGNO /* uleb128 LR_REGNO; Register LR */
  7160. .byte 0x7e /* leb128 -2; Offset -2 (8/16) */
  7161. .byte 0x9f /* DW_CFA_offset Register r31 */
  7162. .byte 0x1 /* uleb128 0x1; Offset 1 (-4/-8) */
  7163. .byte 0x9e /* DW_CFA_offset Register r30 */
  7164. .byte 0x2 /* uleb128 0x2; Offset 2 (-8/-16) */
  7165. .byte 0x9d /* DW_CFA_offset Register r29 */
  7166. .byte 0x3 /* uleb128 0x3; Offset 3 (-12/-24) */
  7167. .byte 0x9c /* DW_CFA_offset Register r28 */
  7168. .byte 0x4 /* uleb128 0x4; Offset 4 (-16/-32) */
  7169. .byte 0x4 /* DW_CFA_advance_loc4 */
  7170. .vbyte 4,LCFI..1-LCFI..0
  7171. .byte 0xd /* DW_CFA_def_cfa_register */
  7172. .byte 0x1c /* uleb128 28; Register r28 */
  7173. .align LOG2_PTRSIZE
  7174. LEFDE..1:
  7175. LSFDE..2:
  7176. .vbyte 4,LEFDE..2-LASFDE..2 /* FDE Length */
  7177. LASFDE..2:
  7178. .vbyte 4,LASFDE..2-Lframe..1 /* FDE CIE offset */
  7179. .vbyte PTRSIZE,LFB..1-$ /* FDE initial location */
  7180. .vbyte PTRSIZE,LFE..1-LFB..1 /* FDE address range */
  7181. .byte 0 /* uleb128 0x0; Augmentation size */
  7182. .byte 0x4 /* DW_CFA_advance_loc4 */
  7183. .vbyte 4,LCFI..2-LFB..1
  7184. .byte 0x11 /* DW_CFA_def_offset_extended_sf */
  7185. .byte LR_REGNO /* uleb128 LR_REGNO; Register LR */
  7186. .byte 0x7e /* leb128 -2; Offset -2 (8/16) */
  7187. .byte 0x9f /* DW_CFA_offset Register r31 */
  7188. .byte 0x1 /* uleb128 0x1; Offset 1 (-4/-8) */
  7189. .byte 0x9e /* DW_CFA_offset Register r30 */
  7190. .byte 0x2 /* uleb128 0x2; Offset 2 (-8/-16) */
  7191. .byte 0x9d /* DW_CFA_offset Register r29 */
  7192. .byte 0x3 /* uleb128 0x3; Offset 3 (-12/-24) */
  7193. .byte 0x9c /* DW_CFA_offset Register r28 */
  7194. .byte 0x4 /* uleb128 0x4; Offset 4 (-16/-32) */
  7195. .byte 0x4 /* DW_CFA_advance_loc4 */
  7196. .vbyte 4,LCFI..3-LCFI..2
  7197. .byte 0xd /* DW_CFA_def_cfa_register */
  7198. .byte 0x1c /* uleb128 28; Register r28 */
  7199. .align LOG2_PTRSIZE
  7200. LEFDE..2:
  7201. .vbyte 4,0 /* End of FDEs */
  7202. .csect .text[PR]
  7203. .ref _GLOBAL__F_libffi_src_powerpc_aix /* Prevents garbage collection by AIX linker */
  7204. ====================File: src/powerpc/aix_closure.S====================
  7205. /* -----------------------------------------------------------------------
  7206. aix_closure.S - Copyright (c) 2002, 2003, 2009 Free Software Foundation, Inc.
  7207. based on darwin_closure.S
  7208. PowerPC Assembly glue.
  7209. Permission is hereby granted, free of charge, to any person obtaining
  7210. a copy of this software and associated documentation files (the
  7211. ``Software''), to deal in the Software without restriction, including
  7212. without limitation the rights to use, copy, modify, merge, publish,
  7213. distribute, sublicense, and/or sell copies of the Software, and to
  7214. permit persons to whom the Software is furnished to do so, subject to
  7215. the following conditions:
  7216. The above copyright notice and this permission notice shall be included
  7217. in all copies or substantial portions of the Software.
  7218. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
  7219. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  7220. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  7221. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
  7222. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  7223. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  7224. OTHER DEALINGS IN THE SOFTWARE.
  7225. ----------------------------------------------------------------------- */
  7226. .set r0,0
  7227. .set r1,1
  7228. .set r2,2
  7229. .set r3,3
  7230. .set r4,4
  7231. .set r5,5
  7232. .set r6,6
  7233. .set r7,7
  7234. .set r8,8
  7235. .set r9,9
  7236. .set r10,10
  7237. .set r11,11
  7238. .set r12,12
  7239. .set r13,13
  7240. .set r14,14
  7241. .set r15,15
  7242. .set r16,16
  7243. .set r17,17
  7244. .set r18,18
  7245. .set r19,19
  7246. .set r20,20
  7247. .set r21,21
  7248. .set r22,22
  7249. .set r23,23
  7250. .set r24,24
  7251. .set r25,25
  7252. .set r26,26
  7253. .set r27,27
  7254. .set r28,28
  7255. .set r29,29
  7256. .set r30,30
  7257. .set r31,31
  7258. .set f0,0
  7259. .set f1,1
  7260. .set f2,2
  7261. .set f3,3
  7262. .set f4,4
  7263. .set f5,5
  7264. .set f6,6
  7265. .set f7,7
  7266. .set f8,8
  7267. .set f9,9
  7268. .set f10,10
  7269. .set f11,11
  7270. .set f12,12
  7271. .set f13,13
  7272. .set f14,14
  7273. .set f15,15
  7274. .set f16,16
  7275. .set f17,17
  7276. .set f18,18
  7277. .set f19,19
  7278. .set f20,20
  7279. .set f21,21
  7280. .extern .ffi_closure_helper_DARWIN
  7281. .extern .ffi_go_closure_helper_DARWIN
  7282. #define LIBFFI_ASM
  7283. #define JUMPTARGET(name) name
  7284. #define L(x) x
  7285. .file "aix_closure.S"
  7286. .toc
  7287. LC..60:
  7288. .tc L..60[TC],L..60
  7289. .csect .text[PR]
  7290. .align 2
  7291. .csect .text[PR]
  7292. .align 2
  7293. .globl ffi_closure_ASM
  7294. .globl .ffi_closure_ASM
  7295. .csect ffi_closure_ASM[DS]
  7296. ffi_closure_ASM:
  7297. #ifdef __64BIT__
  7298. .llong .ffi_closure_ASM, TOC[tc0], 0
  7299. .csect .text[PR]
  7300. .ffi_closure_ASM:
  7301. .function .ffi_closure_ASM,.ffi_closure_ASM,16,044,LFE..0-LFB..0
  7302. .bf __LINE__
  7303. .line 1
  7304. LFB..0:
  7305. /* we want to build up an area for the parameters passed */
  7306. /* in registers (both floating point and integer) */
  7307. /* we store gpr 3 to gpr 10 (aligned to 4)
  7308. in the parents outgoing area */
  7309. std r3, 48+(0*8)(r1)
  7310. std r4, 48+(1*8)(r1)
  7311. std r5, 48+(2*8)(r1)
  7312. std r6, 48+(3*8)(r1)
  7313. mflr r0
  7314. std r7, 48+(4*8)(r1)
  7315. std r8, 48+(5*8)(r1)
  7316. std r9, 48+(6*8)(r1)
  7317. std r10, 48+(7*8)(r1)
  7318. std r0, 16(r1) /* save the return address */
  7319. LCFI..0:
  7320. /* 48 Bytes (Linkage Area) */
  7321. /* 64 Bytes (params) */
  7322. /* 16 Bytes (result) */
  7323. /* 104 Bytes (13*8 from FPR) */
  7324. /* 8 Bytes (alignment) */
  7325. /* 240 Bytes */
  7326. stdu r1, -240(r1) /* skip over caller save area
  7327. keep stack aligned to 16 */
  7328. LCFI..1:
  7329. /* next save fpr 1 to fpr 13 (aligned to 8) */
  7330. stfd f1, 128+(0*8)(r1)
  7331. stfd f2, 128+(1*8)(r1)
  7332. stfd f3, 128+(2*8)(r1)
  7333. stfd f4, 128+(3*8)(r1)
  7334. stfd f5, 128+(4*8)(r1)
  7335. stfd f6, 128+(5*8)(r1)
  7336. stfd f7, 128+(6*8)(r1)
  7337. stfd f8, 128+(7*8)(r1)
  7338. stfd f9, 128+(8*8)(r1)
  7339. stfd f10, 128+(9*8)(r1)
  7340. stfd f11, 128+(10*8)(r1)
  7341. stfd f12, 128+(11*8)(r1)
  7342. stfd f13, 128+(12*8)(r1)
  7343. /* set up registers for the routine that actually does the work */
  7344. /* get the context pointer from the trampoline */
  7345. mr r3, r11
  7346. /* now load up the pointer to the result storage */
  7347. addi r4, r1, 112
  7348. /* now load up the pointer to the saved gpr registers */
  7349. addi r5, r1, 288
  7350. /* now load up the pointer to the saved fpr registers */
  7351. addi r6, r1, 128
  7352. /* make the call */
  7353. bl .ffi_closure_helper_DARWIN
  7354. nop
  7355. .Ldoneclosure:
  7356. /* now r3 contains the return type */
  7357. /* so use it to look up in a table */
  7358. /* so we know how to deal with each type */
  7359. /* look up the proper starting point in table */
  7360. /* by using return type as offset */
  7361. lhz r3, 10(r3) /* load type from return type */
  7362. ld r4, LC..60(2) /* get address of jump table */
  7363. sldi r3, r3, 4 /* now multiply return type by 16 */
  7364. ld r0, 240+16(r1) /* load return address */
  7365. add r3, r3, r4 /* add contents of table to table address */
  7366. mtctr r3
  7367. bctr /* jump to it */
  7368. /* Each fragment must be exactly 16 bytes long (4 instructions).
  7369. Align to 16 byte boundary for cache and dispatch efficiency. */
  7370. .align 4
  7371. L..60:
  7372. /* case FFI_TYPE_VOID */
  7373. mtlr r0
  7374. addi r1, r1, 240
  7375. blr
  7376. nop
  7377. /* case FFI_TYPE_INT */
  7378. lwa r3, 112+4(r1)
  7379. mtlr r0
  7380. addi r1, r1, 240
  7381. blr
  7382. /* case FFI_TYPE_FLOAT */
  7383. lfs f1, 112+0(r1)
  7384. mtlr r0
  7385. addi r1, r1, 240
  7386. blr
  7387. /* case FFI_TYPE_DOUBLE */
  7388. lfd f1, 112+0(r1)
  7389. mtlr r0
  7390. addi r1, r1, 240
  7391. blr
  7392. /* case FFI_TYPE_LONGDOUBLE */
  7393. lfd f1, 112+0(r1)
  7394. mtlr r0
  7395. lfd f2, 112+8(r1)
  7396. b L..finish
  7397. /* case FFI_TYPE_UINT8 */
  7398. lbz r3, 112+7(r1)
  7399. mtlr r0
  7400. addi r1, r1, 240
  7401. blr
  7402. /* case FFI_TYPE_SINT8 */
  7403. lbz r3, 112+7(r1)
  7404. mtlr r0
  7405. extsb r3, r3
  7406. b L..finish
  7407. /* case FFI_TYPE_UINT16 */
  7408. lhz r3, 112+6(r1)
  7409. mtlr r0
  7410. L..finish:
  7411. addi r1, r1, 240
  7412. blr
  7413. /* case FFI_TYPE_SINT16 */
  7414. lha r3, 112+6(r1)
  7415. mtlr r0
  7416. addi r1, r1, 240
  7417. blr
  7418. /* case FFI_TYPE_UINT32 */
  7419. lwz r3, 112+4(r1)
  7420. mtlr r0
  7421. addi r1, r1, 240
  7422. blr
  7423. /* case FFI_TYPE_SINT32 */
  7424. lwa r3, 112+4(r1)
  7425. mtlr r0
  7426. addi r1, r1, 240
  7427. blr
  7428. /* case FFI_TYPE_UINT64 */
  7429. ld r3, 112+0(r1)
  7430. mtlr r0
  7431. addi r1, r1, 240
  7432. blr
  7433. /* case FFI_TYPE_SINT64 */
  7434. ld r3, 112+0(r1)
  7435. mtlr r0
  7436. addi r1, r1, 240
  7437. blr
  7438. /* case FFI_TYPE_STRUCT */
  7439. mtlr r0
  7440. addi r1, r1, 240
  7441. blr
  7442. nop
  7443. /* case FFI_TYPE_POINTER */
  7444. ld r3, 112+0(r1)
  7445. mtlr r0
  7446. addi r1, r1, 240
  7447. blr
  7448. LFE..0:
  7449. #else /* ! __64BIT__ */
  7450. .long .ffi_closure_ASM, TOC[tc0], 0
  7451. .csect .text[PR]
  7452. .ffi_closure_ASM:
  7453. .function .ffi_closure_ASM,.ffi_closure_ASM,16,044,LFE..0-LFB..0
  7454. .bf __LINE__
  7455. .line 1
  7456. LFB..0:
  7457. /* we want to build up an area for the parameters passed */
  7458. /* in registers (both floating point and integer) */
  7459. /* we store gpr 3 to gpr 10 (aligned to 4)
  7460. in the parents outgoing area */
  7461. stw r3, 24+(0*4)(r1)
  7462. stw r4, 24+(1*4)(r1)
  7463. stw r5, 24+(2*4)(r1)
  7464. stw r6, 24+(3*4)(r1)
  7465. mflr r0
  7466. stw r7, 24+(4*4)(r1)
  7467. stw r8, 24+(5*4)(r1)
  7468. stw r9, 24+(6*4)(r1)
  7469. stw r10, 24+(7*4)(r1)
  7470. stw r0, 8(r1)
  7471. LCFI..0:
  7472. /* 24 Bytes (Linkage Area) */
  7473. /* 32 Bytes (params) */
  7474. /* 16 Bytes (result) */
  7475. /* 104 Bytes (13*8 from FPR) */
  7476. /* 176 Bytes */
  7477. stwu r1, -176(r1) /* skip over caller save area
  7478. keep stack aligned to 16 */
  7479. LCFI..1:
  7480. /* next save fpr 1 to fpr 13 (aligned to 8) */
  7481. stfd f1, 72+(0*8)(r1)
  7482. stfd f2, 72+(1*8)(r1)
  7483. stfd f3, 72+(2*8)(r1)
  7484. stfd f4, 72+(3*8)(r1)
  7485. stfd f5, 72+(4*8)(r1)
  7486. stfd f6, 72+(5*8)(r1)
  7487. stfd f7, 72+(6*8)(r1)
  7488. stfd f8, 72+(7*8)(r1)
  7489. stfd f9, 72+(8*8)(r1)
  7490. stfd f10, 72+(9*8)(r1)
  7491. stfd f11, 72+(10*8)(r1)
  7492. stfd f12, 72+(11*8)(r1)
  7493. stfd f13, 72+(12*8)(r1)
  7494. /* set up registers for the routine that actually does the work */
  7495. /* get the context pointer from the trampoline */
  7496. mr r3, r11
  7497. /* now load up the pointer to the result storage */
  7498. addi r4, r1, 56
  7499. /* now load up the pointer to the saved gpr registers */
  7500. addi r5, r1, 200
  7501. /* now load up the pointer to the saved fpr registers */
  7502. addi r6, r1, 72
  7503. /* make the call */
  7504. bl .ffi_closure_helper_DARWIN
  7505. nop
  7506. .Ldoneclosure:
  7507. /* now r3 contains the return type */
  7508. /* so use it to look up in a table */
  7509. /* so we know how to deal with each type */
  7510. /* look up the proper starting point in table */
  7511. /* by using return type as offset */
  7512. lhz r3, 6(r3) /* load type from return type */
  7513. lwz r4, LC..60(2) /* get address of jump table */
  7514. slwi r3, r3, 4 /* now multiply return type by 16 */
  7515. lwz r0, 176+8(r1) /* load return address */
  7516. add r3, r3, r4 /* add contents of table to table address */
  7517. mtctr r3
  7518. bctr /* jump to it */
  7519. /* Each fragment must be exactly 16 bytes long (4 instructions).
  7520. Align to 16 byte boundary for cache and dispatch efficiency. */
  7521. .align 4
  7522. L..60:
  7523. /* case FFI_TYPE_VOID */
  7524. mtlr r0
  7525. addi r1, r1, 176
  7526. blr
  7527. nop
  7528. /* case FFI_TYPE_INT */
  7529. lwz r3, 56+0(r1)
  7530. mtlr r0
  7531. addi r1, r1, 176
  7532. blr
  7533. /* case FFI_TYPE_FLOAT */
  7534. lfs f1, 56+0(r1)
  7535. mtlr r0
  7536. addi r1, r1, 176
  7537. blr
  7538. /* case FFI_TYPE_DOUBLE */
  7539. lfd f1, 56+0(r1)
  7540. mtlr r0
  7541. addi r1, r1, 176
  7542. blr
  7543. /* case FFI_TYPE_LONGDOUBLE */
  7544. lfd f1, 56+0(r1)
  7545. mtlr r0
  7546. lfd f2, 56+8(r1)
  7547. b L..finish
  7548. /* case FFI_TYPE_UINT8 */
  7549. lbz r3, 56+3(r1)
  7550. mtlr r0
  7551. addi r1, r1, 176
  7552. blr
  7553. /* case FFI_TYPE_SINT8 */
  7554. lbz r3, 56+3(r1)
  7555. mtlr r0
  7556. extsb r3, r3
  7557. b L..finish
  7558. /* case FFI_TYPE_UINT16 */
  7559. lhz r3, 56+2(r1)
  7560. mtlr r0
  7561. addi r1, r1, 176
  7562. blr
  7563. /* case FFI_TYPE_SINT16 */
  7564. lha r3, 56+2(r1)
  7565. mtlr r0
  7566. addi r1, r1, 176
  7567. blr
  7568. /* case FFI_TYPE_UINT32 */
  7569. lwz r3, 56+0(r1)
  7570. mtlr r0
  7571. addi r1, r1, 176
  7572. blr
  7573. /* case FFI_TYPE_SINT32 */
  7574. lwz r3, 56+0(r1)
  7575. mtlr r0
  7576. addi r1, r1, 176
  7577. blr
  7578. /* case FFI_TYPE_UINT64 */
  7579. lwz r3, 56+0(r1)
  7580. mtlr r0
  7581. lwz r4, 56+4(r1)
  7582. b L..finish
  7583. /* case FFI_TYPE_SINT64 */
  7584. lwz r3, 56+0(r1)
  7585. mtlr r0
  7586. lwz r4, 56+4(r1)
  7587. b L..finish
  7588. /* case FFI_TYPE_STRUCT */
  7589. mtlr r0
  7590. addi r1, r1, 176
  7591. blr
  7592. nop
  7593. /* case FFI_TYPE_POINTER */
  7594. lwz r3, 56+0(r1)
  7595. mtlr r0
  7596. L..finish:
  7597. addi r1, r1, 176
  7598. blr
  7599. LFE..0:
  7600. #endif
  7601. .ef __LINE__
  7602. /* END(ffi_closure_ASM) */
  7603. .csect .text[PR]
  7604. .align 2
  7605. .globl ffi_go_closure_ASM
  7606. .globl .ffi_go_closure_ASM
  7607. .csect ffi_go_closure_ASM[DS]
  7608. ffi_go_closure_ASM:
  7609. #ifdef __64BIT__
  7610. .llong .ffi_go_closure_ASM, TOC[tc0], 0
  7611. .csect .text[PR]
  7612. .ffi_go_closure_ASM:
  7613. .function .ffi_go_closure_ASM,.ffi_go_closure_ASM,16,044,LFE..1-LFB..1
  7614. .bf __LINE__
  7615. .line 1
  7616. LFB..1:
  7617. /* we want to build up an area for the parameters passed */
  7618. /* in registers (both floating point and integer) */
  7619. /* we store gpr 3 to gpr 10 (aligned to 4)
  7620. in the parents outgoing area */
  7621. std r3, 48+(0*8)(r1)
  7622. std r4, 48+(1*8)(r1)
  7623. std r5, 48+(2*8)(r1)
  7624. std r6, 48+(3*8)(r1)
  7625. mflr r0
  7626. std r7, 48+(4*8)(r1)
  7627. std r8, 48+(5*8)(r1)
  7628. std r9, 48+(6*8)(r1)
  7629. std r10, 48+(7*8)(r1)
  7630. std r0, 16(r1) /* save the return address */
  7631. LCFI..2:
  7632. /* 48 Bytes (Linkage Area) */
  7633. /* 64 Bytes (params) */
  7634. /* 16 Bytes (result) */
  7635. /* 104 Bytes (13*8 from FPR) */
  7636. /* 8 Bytes (alignment) */
  7637. /* 240 Bytes */
  7638. stdu r1, -240(r1) /* skip over caller save area
  7639. keep stack aligned to 16 */
  7640. LCFI..3:
  7641. /* next save fpr 1 to fpr 13 (aligned to 8) */
  7642. stfd f1, 128+(0*8)(r1)
  7643. stfd f2, 128+(1*8)(r1)
  7644. stfd f3, 128+(2*8)(r1)
  7645. stfd f4, 128+(3*8)(r1)
  7646. stfd f5, 128+(4*8)(r1)
  7647. stfd f6, 128+(5*8)(r1)
  7648. stfd f7, 128+(6*8)(r1)
  7649. stfd f8, 128+(7*8)(r1)
  7650. stfd f9, 128+(8*8)(r1)
  7651. stfd f10, 128+(9*8)(r1)
  7652. stfd f11, 128+(10*8)(r1)
  7653. stfd f12, 128+(11*8)(r1)
  7654. stfd f13, 128+(12*8)(r1)
  7655. /* set up registers for the routine that actually does the work */
  7656. mr r3, r11 /* go closure */
  7657. /* now load up the pointer to the result storage */
  7658. addi r4, r1, 112
  7659. /* now load up the pointer to the saved gpr registers */
  7660. addi r5, r1, 288
  7661. /* now load up the pointer to the saved fpr registers */
  7662. addi r6, r1, 128
  7663. /* make the call */
  7664. bl .ffi_go_closure_helper_DARWIN
  7665. nop
  7666. b .Ldoneclosure
  7667. LFE..1:
  7668. #else /* ! __64BIT__ */
  7669. .long .ffi_go_closure_ASM, TOC[tc0], 0
  7670. .csect .text[PR]
  7671. .ffi_go_closure_ASM:
  7672. .function .ffi_go_closure_ASM,.ffi_go_closure_ASM,16,044,LFE..1-LFB..1
  7673. .bf __LINE__
  7674. .line 1
  7675. LFB..1:
  7676. /* we want to build up an area for the parameters passed */
  7677. /* in registers (both floating point and integer) */
  7678. /* we store gpr 3 to gpr 10 (aligned to 4)
  7679. in the parents outgoing area */
  7680. stw r3, 24+(0*4)(r1)
  7681. stw r4, 24+(1*4)(r1)
  7682. stw r5, 24+(2*4)(r1)
  7683. stw r6, 24+(3*4)(r1)
  7684. mflr r0
  7685. stw r7, 24+(4*4)(r1)
  7686. stw r8, 24+(5*4)(r1)
  7687. stw r9, 24+(6*4)(r1)
  7688. stw r10, 24+(7*4)(r1)
  7689. stw r0, 8(r1)
  7690. LCFI..2:
  7691. /* 24 Bytes (Linkage Area) */
  7692. /* 32 Bytes (params) */
  7693. /* 16 Bytes (result) */
  7694. /* 104 Bytes (13*8 from FPR) */
  7695. /* 176 Bytes */
  7696. stwu r1, -176(r1) /* skip over caller save area
  7697. keep stack aligned to 16 */
  7698. LCFI..3:
  7699. /* next save fpr 1 to fpr 13 (aligned to 8) */
  7700. stfd f1, 72+(0*8)(r1)
  7701. stfd f2, 72+(1*8)(r1)
  7702. stfd f3, 72+(2*8)(r1)
  7703. stfd f4, 72+(3*8)(r1)
  7704. stfd f5, 72+(4*8)(r1)
  7705. stfd f6, 72+(5*8)(r1)
  7706. stfd f7, 72+(6*8)(r1)
  7707. stfd f8, 72+(7*8)(r1)
  7708. stfd f9, 72+(8*8)(r1)
  7709. stfd f10, 72+(9*8)(r1)
  7710. stfd f11, 72+(10*8)(r1)
  7711. stfd f12, 72+(11*8)(r1)
  7712. stfd f13, 72+(12*8)(r1)
  7713. /* set up registers for the routine that actually does the work */
  7714. mr r3, 11 /* go closure */
  7715. /* now load up the pointer to the result storage */
  7716. addi r4, r1, 56
  7717. /* now load up the pointer to the saved gpr registers */
  7718. addi r5, r1, 200
  7719. /* now load up the pointer to the saved fpr registers */
  7720. addi r6, r1, 72
  7721. /* make the call */
  7722. bl .ffi_go_closure_helper_DARWIN
  7723. nop
  7724. b .Ldoneclosure
  7725. LFE..1:
  7726. #endif
  7727. .ef __LINE__
  7728. /* END(ffi_go_closure_ASM) */
  7729. /* EH frame stuff. */
  7730. #define LR_REGNO 0x41 /* Link Register (65), see rs6000.md */
  7731. #ifdef __64BIT__
  7732. #define PTRSIZE 8
  7733. #define LOG2_PTRSIZE 3
  7734. #define CFA_OFFSET 0xf0,0x01 /* LEB128 240 */
  7735. #define FDE_ENCODING 0x1c /* DW_EH_PE_pcrel|DW_EH_PE_sdata8 */
  7736. #define EH_DATA_ALIGN_FACT 0x78 /* LEB128 -8 */
  7737. #else
  7738. #define PTRSIZE 4
  7739. #define LOG2_PTRSIZE 2
  7740. #define CFA_OFFSET 0xb0,0x01 /* LEB128 176 */
  7741. #define FDE_ENCODING 0x1b /* DW_EH_PE_pcrel|DW_EH_PE_sdata4 */
  7742. #define EH_DATA_ALIGN_FACT 0x7c /* LEB128 -4 */
  7743. #endif
  7744. .csect _unwind.ro_[RO],4
  7745. .align LOG2_PTRSIZE
  7746. .globl _GLOBAL__F_libffi_src_powerpc_aix_closure
  7747. _GLOBAL__F_libffi_src_powerpc_aix_closure:
  7748. Lframe..1:
  7749. .vbyte 4,LECIE..1-LSCIE..1 /* CIE Length */
  7750. LSCIE..1:
  7751. .vbyte 4,0 /* CIE Identifier Tag */
  7752. .byte 0x3 /* CIE Version */
  7753. .byte "zR" /* CIE Augmentation */
  7754. .byte 0
  7755. .byte 0x1 /* uleb128 0x1; CIE Code Alignment Factor */
  7756. .byte EH_DATA_ALIGN_FACT /* leb128 -4/-8; CIE Data Alignment Factor */
  7757. .byte LR_REGNO /* CIE RA Column */
  7758. .byte 0x1 /* uleb128 0x1; Augmentation size */
  7759. .byte FDE_ENCODING /* FDE Encoding (pcrel|sdata4/8) */
  7760. .byte 0xc /* DW_CFA_def_cfa */
  7761. .byte 0x1 /* uleb128 0x1; Register r1 */
  7762. .byte 0 /* uleb128 0x0; Offset 0 */
  7763. .align LOG2_PTRSIZE
  7764. LECIE..1:
  7765. LSFDE..1:
  7766. .vbyte 4,LEFDE..1-LASFDE..1 /* FDE Length */
  7767. LASFDE..1:
  7768. .vbyte 4,LASFDE..1-Lframe..1 /* FDE CIE offset */
  7769. .vbyte PTRSIZE,LFB..0-$ /* FDE initial location */
  7770. .vbyte PTRSIZE,LFE..0-LFB..0 /* FDE address range */
  7771. .byte 0 /* uleb128 0x0; Augmentation size */
  7772. .byte 0x4 /* DW_CFA_advance_loc4 */
  7773. .vbyte 4,LCFI..1-LCFI..0
  7774. .byte 0xe /* DW_CFA_def_cfa_offset */
  7775. .byte CFA_OFFSET /* uleb128 176/240 */
  7776. .byte 0x4 /* DW_CFA_advance_loc4 */
  7777. .vbyte 4,LCFI..0-LFB..0
  7778. .byte 0x11 /* DW_CFA_offset_extended_sf */
  7779. .byte LR_REGNO /* uleb128 LR_REGNO; Register LR */
  7780. .byte 0x7e /* leb128 -2; Offset -2 (8/16) */
  7781. .align LOG2_PTRSIZE
  7782. LEFDE..1:
  7783. LSFDE..2:
  7784. .vbyte 4,LEFDE..2-LASFDE..2 /* FDE Length */
  7785. LASFDE..2:
  7786. .vbyte 4,LASFDE..2-Lframe..1 /* FDE CIE offset */
  7787. .vbyte PTRSIZE,LFB..1-$ /* FDE initial location */
  7788. .vbyte PTRSIZE,LFE..1-LFB..1 /* FDE address range */
  7789. .byte 0 /* uleb128 0x0; Augmentation size */
  7790. .byte 0x4 /* DW_CFA_advance_loc4 */
  7791. .vbyte 4,LCFI..3-LCFI..2
  7792. .byte 0xe /* DW_CFA_def_cfa_offset */
  7793. .byte CFA_OFFSET /* uleb128 176/240 */
  7794. .byte 0x4 /* DW_CFA_advance_loc4 */
  7795. .vbyte 4,LCFI..2-LFB..1
  7796. .byte 0x11 /* DW_CFA_offset_extended_sf */
  7797. .byte LR_REGNO /* uleb128 LR_REGNO; Register LR */
  7798. .byte 0x7e /* leb128 -2; Offset -2 (8/16) */
  7799. .align LOG2_PTRSIZE
  7800. LEFDE..2:
  7801. .vbyte 4,0 /* End of FDEs */
  7802. .csect .text[PR]
  7803. .ref _GLOBAL__F_libffi_src_powerpc_aix_closure /* Prevents garbage collection by AIX linker */
  7804. ====================File: src/powerpc/asm.h====================
  7805. /* -----------------------------------------------------------------------
  7806. asm.h - Copyright (c) 1998 Geoffrey Keating
  7807. PowerPC Assembly glue.
  7808. Permission is hereby granted, free of charge, to any person obtaining
  7809. a copy of this software and associated documentation files (the
  7810. ``Software''), to deal in the Software without restriction, including
  7811. without limitation the rights to use, copy, modify, merge, publish,
  7812. distribute, sublicense, and/or sell copies of the Software, and to
  7813. permit persons to whom the Software is furnished to do so, subject to
  7814. the following conditions:
  7815. The above copyright notice and this permission notice shall be included
  7816. in all copies or substantial portions of the Software.
  7817. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
  7818. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  7819. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  7820. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
  7821. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  7822. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  7823. OTHER DEALINGS IN THE SOFTWARE.
  7824. ----------------------------------------------------------------------- */
  7825. #define ASM_GLOBAL_DIRECTIVE .globl
  7826. #define C_SYMBOL_NAME(name) name
  7827. /* Macro for a label. */
  7828. #ifdef __STDC__
  7829. #define C_LABEL(name) name##:
  7830. #else
  7831. #define C_LABEL(name) name/**/:
  7832. #endif
  7833. /* This seems to always be the case on PPC. */
  7834. #define ALIGNARG(log2) log2
  7835. /* For ELF we need the `.type' directive to make shared libs work right. */
  7836. #define ASM_TYPE_DIRECTIVE(name,typearg) .type name,typearg;
  7837. #define ASM_SIZE_DIRECTIVE(name) .size name,.-name
  7838. /* If compiled for profiling, call `_mcount' at the start of each function. */
  7839. #ifdef PROF
  7840. /* The mcount code relies on the return address being on the stack
  7841. to locate our caller and so it can restore it; so store one just
  7842. for its benefit. */
  7843. #ifdef PIC
  7844. #define CALL_MCOUNT \
  7845. .pushsection; \
  7846. .section ".data"; \
  7847. .align ALIGNARG(2); \
  7848. 0:.long 0; \
  7849. .previous; \
  7850. mflr %r0; \
  7851. stw %r0,4(%r1); \
  7852. bl _GLOBAL_OFFSET_TABLE_@local-4; \
  7853. mflr %r11; \
  7854. lwz %r0,0b@got(%r11); \
  7855. bl JUMPTARGET(_mcount);
  7856. #else /* PIC */
  7857. #define CALL_MCOUNT \
  7858. .section ".data"; \
  7859. .align ALIGNARG(2); \
  7860. 0:.long 0; \
  7861. .previous; \
  7862. mflr %r0; \
  7863. lis %r11,0b@ha; \
  7864. stw %r0,4(%r1); \
  7865. addi %r0,%r11,0b@l; \
  7866. bl JUMPTARGET(_mcount);
  7867. #endif /* PIC */
  7868. #else /* PROF */
  7869. #define CALL_MCOUNT /* Do nothing. */
  7870. #endif /* PROF */
  7871. #define ENTRY(name) \
  7872. ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(name); \
  7873. ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name),@function) \
  7874. .align ALIGNARG(2); \
  7875. C_LABEL(name) \
  7876. CALL_MCOUNT
  7877. #define EALIGN_W_0 /* No words to insert. */
  7878. #define EALIGN_W_1 nop
  7879. #define EALIGN_W_2 nop;nop
  7880. #define EALIGN_W_3 nop;nop;nop
  7881. #define EALIGN_W_4 EALIGN_W_3;nop
  7882. #define EALIGN_W_5 EALIGN_W_4;nop
  7883. #define EALIGN_W_6 EALIGN_W_5;nop
  7884. #define EALIGN_W_7 EALIGN_W_6;nop
  7885. /* EALIGN is like ENTRY, but does alignment to 'words'*4 bytes
  7886. past a 2^align boundary. */
  7887. #ifdef PROF
  7888. #define EFFI_ALIGN(name, alignt, words) \
  7889. ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(name); \
  7890. ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name),@function) \
  7891. .align ALIGNARG(2); \
  7892. C_LABEL(name) \
  7893. CALL_MCOUNT \
  7894. b 0f; \
  7895. .align ALIGNARG(alignt); \
  7896. EALIGN_W_##words; \
  7897. 0:
  7898. #else /* PROF */
  7899. #define EFFI_ALIGN(name, alignt, words) \
  7900. ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(name); \
  7901. ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name),@function) \
  7902. .align ALIGNARG(alignt); \
  7903. EALIGN_W_##words; \
  7904. C_LABEL(name)
  7905. #endif
  7906. #define END(name) \
  7907. ASM_SIZE_DIRECTIVE(name)
  7908. #ifdef PIC
  7909. #define JUMPTARGET(name) name##@plt
  7910. #else
  7911. #define JUMPTARGET(name) name
  7912. #endif
  7913. /* Local labels stripped out by the linker. */
  7914. #define L(x) .L##x
  7915. ====================File: src/powerpc/darwin.S====================
  7916. /* -----------------------------------------------------------------------
  7917. darwin.S - Copyright (c) 2000 John Hornkvist
  7918. Copyright (c) 2004, 2010 Free Software Foundation, Inc.
  7919. PowerPC Assembly glue.
  7920. Permission is hereby granted, free of charge, to any person obtaining
  7921. a copy of this software and associated documentation files (the
  7922. ``Software''), to deal in the Software without restriction, including
  7923. without limitation the rights to use, copy, modify, merge, publish,
  7924. distribute, sublicense, and/or sell copies of the Software, and to
  7925. permit persons to whom the Software is furnished to do so, subject to
  7926. the following conditions:
  7927. The above copyright notice and this permission notice shall be included
  7928. in all copies or substantial portions of the Software.
  7929. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
  7930. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  7931. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  7932. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
  7933. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  7934. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  7935. OTHER DEALINGS IN THE SOFTWARE.
  7936. ----------------------------------------------------------------------- */
  7937. #define LIBFFI_ASM
  7938. #if defined(__ppc64__)
  7939. #define MODE_CHOICE(x, y) y
  7940. #else
  7941. #define MODE_CHOICE(x, y) x
  7942. #endif
  7943. #define machine_choice MODE_CHOICE(ppc7400,ppc64)
  7944. ; Define some pseudo-opcodes for size-independent load & store of GPRs ...
  7945. #define lgu MODE_CHOICE(lwzu, ldu)
  7946. #define lg MODE_CHOICE(lwz,ld)
  7947. #define sg MODE_CHOICE(stw,std)
  7948. #define sgu MODE_CHOICE(stwu,stdu)
  7949. #define sgux MODE_CHOICE(stwux,stdux)
  7950. ; ... and the size of GPRs and their storage indicator.
  7951. #define GPR_BYTES MODE_CHOICE(4,8)
  7952. #define LOG2_GPR_BYTES MODE_CHOICE(2,3) /* log2(GPR_BYTES) */
  7953. #define g_long MODE_CHOICE(long, quad) /* usage is ".g_long" */
  7954. ; From the ABI doc: "Mac OS X ABI Function Call Guide" Version 2009-02-04.
  7955. #define LINKAGE_SIZE MODE_CHOICE(24,48)
  7956. #define PARAM_AREA MODE_CHOICE(32,64)
  7957. #define SAVED_LR_OFFSET MODE_CHOICE(8,16) /* save position for lr */
  7958. /* If there is any FP stuff we make space for all of the regs. */
  7959. #define SAVED_FPR_COUNT 13
  7960. #define FPR_SIZE 8
  7961. #define RESULT_BYTES 16
  7962. /* This should be kept in step with the same value in ffi_darwin.c. */
  7963. #define ASM_NEEDS_REGISTERS 4
  7964. #define SAVE_REGS_SIZE (ASM_NEEDS_REGISTERS * GPR_BYTES)
  7965. #include <fficonfig.h>
  7966. #include <ffi.h>
  7967. #define JUMPTARGET(name) name
  7968. #define L(x) x
  7969. .text
  7970. .align 2
  7971. .globl _ffi_prep_args
  7972. .align 2
  7973. .globl _ffi_call_DARWIN
  7974. /* We arrive here with:
  7975. r3 = ptr to extended cif.
  7976. r4 = -bytes.
  7977. r5 = cif flags.
  7978. r6 = ptr to return value.
  7979. r7 = fn pointer (user func).
  7980. r8 = fn pointer (ffi_prep_args).
  7981. r9 = ffi_type* for the ret val. */
  7982. _ffi_call_DARWIN:
  7983. Lstartcode:
  7984. mr r12,r8 /* We only need r12 until the call,
  7985. so it does not have to be saved. */
  7986. LFB1:
  7987. /* Save the old stack pointer as AP. */
  7988. mr r8,r1
  7989. LCFI0:
  7990. /* Save the retval type in parents frame. */
  7991. sg r9,(LINKAGE_SIZE+6*GPR_BYTES)(r8)
  7992. /* Allocate the stack space we need. */
  7993. sgux r1,r1,r4
  7994. /* Save registers we use. */
  7995. mflr r9
  7996. sg r9,SAVED_LR_OFFSET(r8)
  7997. sg r28,-(4 * GPR_BYTES)(r8)
  7998. sg r29,-(3 * GPR_BYTES)(r8)
  7999. sg r30,-(2 * GPR_BYTES)(r8)
  8000. sg r31,-( GPR_BYTES)(r8)
  8001. #if !defined(POWERPC_DARWIN)
  8002. /* The TOC slot is reserved in the Darwin ABI and r2 is volatile. */
  8003. sg r2,(5 * GPR_BYTES)(r1)
  8004. #endif
  8005. LCFI1:
  8006. /* Save arguments over call. */
  8007. mr r31,r5 /* flags, */
  8008. mr r30,r6 /* rvalue, */
  8009. mr r29,r7 /* function address, */
  8010. mr r28,r8 /* our AP. */
  8011. LCFI2:
  8012. /* Call ffi_prep_args. r3 = extended cif, r4 = stack ptr copy. */
  8013. mr r4,r1
  8014. li r9,0
  8015. mtctr r12 /* r12 holds address of _ffi_prep_args. */
  8016. bctrl
  8017. #if !defined(POWERPC_DARWIN)
  8018. /* The TOC slot is reserved in the Darwin ABI and r2 is volatile. */
  8019. lg r2,(5 * GPR_BYTES)(r1)
  8020. #endif
  8021. /* Now do the call.
  8022. Set up cr1 with bits 4-7 of the flags. */
  8023. mtcrf 0x40,r31
  8024. /* Get the address to call into CTR. */
  8025. mtctr r29
  8026. /* Load all those argument registers.
  8027. We have set up a nice stack frame, just load it into registers. */
  8028. lg r3, (LINKAGE_SIZE )(r1)
  8029. lg r4, (LINKAGE_SIZE + GPR_BYTES)(r1)
  8030. lg r5, (LINKAGE_SIZE + 2 * GPR_BYTES)(r1)
  8031. lg r6, (LINKAGE_SIZE + 3 * GPR_BYTES)(r1)
  8032. nop
  8033. lg r7, (LINKAGE_SIZE + 4 * GPR_BYTES)(r1)
  8034. lg r8, (LINKAGE_SIZE + 5 * GPR_BYTES)(r1)
  8035. lg r9, (LINKAGE_SIZE + 6 * GPR_BYTES)(r1)
  8036. lg r10,(LINKAGE_SIZE + 7 * GPR_BYTES)(r1)
  8037. L1:
  8038. /* ... Load all the FP registers. */
  8039. bf 6,L2 /* No floats to load. */
  8040. lfd f1, -SAVE_REGS_SIZE-(13*FPR_SIZE)(r28)
  8041. lfd f2, -SAVE_REGS_SIZE-(12*FPR_SIZE)(r28)
  8042. lfd f3, -SAVE_REGS_SIZE-(11*FPR_SIZE)(r28)
  8043. lfd f4, -SAVE_REGS_SIZE-(10*FPR_SIZE)(r28)
  8044. nop
  8045. lfd f5, -SAVE_REGS_SIZE-( 9*FPR_SIZE)(r28)
  8046. lfd f6, -SAVE_REGS_SIZE-( 8*FPR_SIZE)(r28)
  8047. lfd f7, -SAVE_REGS_SIZE-( 7*FPR_SIZE)(r28)
  8048. lfd f8, -SAVE_REGS_SIZE-( 6*FPR_SIZE)(r28)
  8049. nop
  8050. lfd f9, -SAVE_REGS_SIZE-( 5*FPR_SIZE)(r28)
  8051. lfd f10,-SAVE_REGS_SIZE-( 4*FPR_SIZE)(r28)
  8052. lfd f11,-SAVE_REGS_SIZE-( 3*FPR_SIZE)(r28)
  8053. lfd f12,-SAVE_REGS_SIZE-( 2*FPR_SIZE)(r28)
  8054. nop
  8055. lfd f13,-SAVE_REGS_SIZE-( 1*FPR_SIZE)(r28)
  8056. L2:
  8057. mr r12,r29 /* Put the target address in r12 as specified. */
  8058. mtctr r12
  8059. nop
  8060. nop
  8061. /* Make the call. */
  8062. bctrl
  8063. /* Now, deal with the return value. */
  8064. /* m64 structure returns can occupy the same set of registers as
  8065. would be used to pass such a structure as arg0 - so take care
  8066. not to step on any possibly hot regs. */
  8067. /* Get the flags.. */
  8068. mtcrf 0x03,r31 ; we need c6 & cr7 now.
  8069. ; FLAG_RETURNS_NOTHING also covers struct ret-by-ref.
  8070. bt 30,L(done_return_value) ; FLAG_RETURNS_NOTHING
  8071. bf 27,L(scalar_return_value) ; not FLAG_RETURNS_STRUCT
  8072. /* OK, so we have a struct. */
  8073. #if defined(__ppc64__)
  8074. bt 31,L(maybe_return_128) ; FLAG_RETURNS_128BITS, special case
  8075. /* OK, we have to map the return back to a mem struct.
  8076. We are about to trample the parents param area, so recover the
  8077. return type. r29 is free, since the call is done. */
  8078. lg r29,(LINKAGE_SIZE + 6 * GPR_BYTES)(r28)
  8079. sg r3, (LINKAGE_SIZE )(r28)
  8080. sg r4, (LINKAGE_SIZE + GPR_BYTES)(r28)
  8081. sg r5, (LINKAGE_SIZE + 2 * GPR_BYTES)(r28)
  8082. sg r6, (LINKAGE_SIZE + 3 * GPR_BYTES)(r28)
  8083. nop
  8084. sg r7, (LINKAGE_SIZE + 4 * GPR_BYTES)(r28)
  8085. sg r8, (LINKAGE_SIZE + 5 * GPR_BYTES)(r28)
  8086. sg r9, (LINKAGE_SIZE + 6 * GPR_BYTES)(r28)
  8087. sg r10,(LINKAGE_SIZE + 7 * GPR_BYTES)(r28)
  8088. /* OK, so do the block move - we trust that memcpy will not trample
  8089. the fprs... */
  8090. mr r3,r30 ; dest
  8091. addi r4,r28,LINKAGE_SIZE ; source
  8092. /* The size is a size_t, should be long. */
  8093. lg r5,0(r29)
  8094. /* Figure out small structs */
  8095. cmpi 0,r5,4
  8096. bgt L3 ; 1, 2 and 4 bytes have special rules.
  8097. cmpi 0,r5,3
  8098. beq L3 ; not 3
  8099. addi r4,r4,8
  8100. subf r4,r5,r4
  8101. L3:
  8102. bl _memcpy
  8103. /* ... do we need the FP registers? - recover the flags.. */
  8104. mtcrf 0x03,r31 ; we need c6 & cr7 now.
  8105. bf 29,L(done_return_value) /* No floats in the struct. */
  8106. stfd f1, -SAVE_REGS_SIZE-(13*FPR_SIZE)(r28)
  8107. stfd f2, -SAVE_REGS_SIZE-(12*FPR_SIZE)(r28)
  8108. stfd f3, -SAVE_REGS_SIZE-(11*FPR_SIZE)(r28)
  8109. stfd f4, -SAVE_REGS_SIZE-(10*FPR_SIZE)(r28)
  8110. nop
  8111. stfd f5, -SAVE_REGS_SIZE-( 9*FPR_SIZE)(r28)
  8112. stfd f6, -SAVE_REGS_SIZE-( 8*FPR_SIZE)(r28)
  8113. stfd f7, -SAVE_REGS_SIZE-( 7*FPR_SIZE)(r28)
  8114. stfd f8, -SAVE_REGS_SIZE-( 6*FPR_SIZE)(r28)
  8115. nop
  8116. stfd f9, -SAVE_REGS_SIZE-( 5*FPR_SIZE)(r28)
  8117. stfd f10,-SAVE_REGS_SIZE-( 4*FPR_SIZE)(r28)
  8118. stfd f11,-SAVE_REGS_SIZE-( 3*FPR_SIZE)(r28)
  8119. stfd f12,-SAVE_REGS_SIZE-( 2*FPR_SIZE)(r28)
  8120. nop
  8121. stfd f13,-SAVE_REGS_SIZE-( 1*FPR_SIZE)(r28)
  8122. mr r3,r29 ; ffi_type *
  8123. mr r4,r30 ; dest
  8124. addi r5,r28,-SAVE_REGS_SIZE-(13*FPR_SIZE) ; fprs
  8125. xor r6,r6,r6
  8126. sg r6,(LINKAGE_SIZE + 7 * GPR_BYTES)(r28)
  8127. addi r6,r28,(LINKAGE_SIZE + 7 * GPR_BYTES) ; point to a zeroed counter.
  8128. bl _darwin64_struct_floats_to_mem
  8129. b L(done_return_value)
  8130. #else
  8131. stw r3,0(r30) ; m32 the only struct return in reg is 4 bytes.
  8132. #endif
  8133. b L(done_return_value)
  8134. L(fp_return_value):
  8135. /* Do we have long double to store? */
  8136. bf 31,L(fd_return_value) ; FLAG_RETURNS_128BITS
  8137. stfd f1,0(r30)
  8138. stfd f2,FPR_SIZE(r30)
  8139. b L(done_return_value)
  8140. L(fd_return_value):
  8141. /* Do we have double to store? */
  8142. bf 28,L(float_return_value)
  8143. stfd f1,0(r30)
  8144. b L(done_return_value)
  8145. L(float_return_value):
  8146. /* We only have a float to store. */
  8147. stfs f1,0(r30)
  8148. b L(done_return_value)
  8149. L(scalar_return_value):
  8150. bt 29,L(fp_return_value) ; FLAG_RETURNS_FP
  8151. ; ffi_arg is defined as unsigned long.
  8152. sg r3,0(r30) ; Save the reg.
  8153. bf 28,L(done_return_value) ; not FLAG_RETURNS_64BITS
  8154. #if defined(__ppc64__)
  8155. L(maybe_return_128):
  8156. std r3,0(r30)
  8157. bf 31,L(done_return_value) ; not FLAG_RETURNS_128BITS
  8158. std r4,8(r30)
  8159. #else
  8160. stw r4,4(r30)
  8161. #endif
  8162. /* Fall through. */
  8163. /* We want this at the end to simplify eh epilog computation. */
  8164. L(done_return_value):
  8165. /* Restore the registers we used and return. */
  8166. lg r29,SAVED_LR_OFFSET(r28)
  8167. ; epilog
  8168. lg r31,-(1 * GPR_BYTES)(r28)
  8169. mtlr r29
  8170. lg r30,-(2 * GPR_BYTES)(r28)
  8171. lg r29,-(3 * GPR_BYTES)(r28)
  8172. lg r28,-(4 * GPR_BYTES)(r28)
  8173. lg r1,0(r1)
  8174. blr
  8175. LFE1:
  8176. .align 1
  8177. /* END(_ffi_call_DARWIN) */
  8178. /* Provide a null definition of _ffi_call_AIX. */
  8179. .text
  8180. .globl _ffi_call_AIX
  8181. .align 2
  8182. _ffi_call_AIX:
  8183. blr
  8184. /* END(_ffi_call_AIX) */
  8185. /* EH stuff. */
  8186. #define EH_DATA_ALIGN_FACT MODE_CHOICE(0x7c,0x78)
  8187. .section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support
  8188. EH_frame1:
  8189. .set L$set$0,LECIE1-LSCIE1
  8190. .long L$set$0 ; Length of Common Information Entry
  8191. LSCIE1:
  8192. .long 0x0 ; CIE Identifier Tag
  8193. .byte 0x1 ; CIE Version
  8194. .ascii "zR\0" ; CIE Augmentation
  8195. .byte 0x1 ; uleb128 0x1; CIE Code Alignment Factor
  8196. .byte EH_DATA_ALIGN_FACT ; sleb128 -4; CIE Data Alignment Factor
  8197. .byte 0x41 ; CIE RA Column
  8198. .byte 0x1 ; uleb128 0x1; Augmentation size
  8199. .byte 0x10 ; FDE Encoding (pcrel)
  8200. .byte 0xc ; DW_CFA_def_cfa
  8201. .byte 0x1 ; uleb128 0x1
  8202. .byte 0x0 ; uleb128 0x0
  8203. .align LOG2_GPR_BYTES
  8204. LECIE1:
  8205. .globl _ffi_call_DARWIN.eh
  8206. _ffi_call_DARWIN.eh:
  8207. LSFDE1:
  8208. .set L$set$1,LEFDE1-LASFDE1
  8209. .long L$set$1 ; FDE Length
  8210. LASFDE1:
  8211. .long LASFDE1-EH_frame1 ; FDE CIE offset
  8212. .g_long Lstartcode-. ; FDE initial location
  8213. .set L$set$3,LFE1-Lstartcode
  8214. .g_long L$set$3 ; FDE address range
  8215. .byte 0x0 ; uleb128 0x0; Augmentation size
  8216. .byte 0x4 ; DW_CFA_advance_loc4
  8217. .set L$set$4,LCFI0-Lstartcode
  8218. .long L$set$4
  8219. .byte 0xd ; DW_CFA_def_cfa_register
  8220. .byte 0x08 ; uleb128 0x08
  8221. .byte 0x4 ; DW_CFA_advance_loc4
  8222. .set L$set$5,LCFI1-LCFI0
  8223. .long L$set$5
  8224. .byte 0x11 ; DW_CFA_offset_extended_sf
  8225. .byte 0x41 ; uleb128 0x41
  8226. .byte 0x7e ; sleb128 -2
  8227. .byte 0x9f ; DW_CFA_offset, column 0x1f
  8228. .byte 0x1 ; uleb128 0x1
  8229. .byte 0x9e ; DW_CFA_offset, column 0x1e
  8230. .byte 0x2 ; uleb128 0x2
  8231. .byte 0x9d ; DW_CFA_offset, column 0x1d
  8232. .byte 0x3 ; uleb128 0x3
  8233. .byte 0x9c ; DW_CFA_offset, column 0x1c
  8234. .byte 0x4 ; uleb128 0x4
  8235. .byte 0x4 ; DW_CFA_advance_loc4
  8236. .set L$set$6,LCFI2-LCFI1
  8237. .long L$set$6
  8238. .byte 0xd ; DW_CFA_def_cfa_register
  8239. .byte 0x1c ; uleb128 0x1c
  8240. .align LOG2_GPR_BYTES
  8241. LEFDE1:
  8242. .align 1
  8243. ====================File: src/powerpc/darwin_closure.S====================
  8244. /* -----------------------------------------------------------------------
  8245. darwin_closure.S - Copyright (c) 2002, 2003, 2004, 2010,
  8246. Free Software Foundation, Inc.
  8247. based on ppc_closure.S
  8248. PowerPC Assembly glue.
  8249. Permission is hereby granted, free of charge, to any person obtaining
  8250. a copy of this software and associated documentation files (the
  8251. ``Software''), to deal in the Software without restriction, including
  8252. without limitation the rights to use, copy, modify, merge, publish,
  8253. distribute, sublicense, and/or sell copies of the Software, and to
  8254. permit persons to whom the Software is furnished to do so, subject to
  8255. the following conditions:
  8256. The above copyright notice and this permission notice shall be included
  8257. in all copies or substantial portions of the Software.
  8258. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
  8259. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  8260. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  8261. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
  8262. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  8263. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  8264. OTHER DEALINGS IN THE SOFTWARE.
  8265. ----------------------------------------------------------------------- */
  8266. #define LIBFFI_ASM
  8267. #define L(x) x
  8268. #if defined(__ppc64__)
  8269. #define MODE_CHOICE(x, y) y
  8270. #else
  8271. #define MODE_CHOICE(x, y) x
  8272. #endif
  8273. #define machine_choice MODE_CHOICE(ppc7400,ppc64)
  8274. ; Define some pseudo-opcodes for size-independent load & store of GPRs ...
  8275. #define lgu MODE_CHOICE(lwzu, ldu)
  8276. #define lg MODE_CHOICE(lwz,ld)
  8277. #define sg MODE_CHOICE(stw,std)
  8278. #define sgu MODE_CHOICE(stwu,stdu)
  8279. ; ... and the size of GPRs and their storage indicator.
  8280. #define GPR_BYTES MODE_CHOICE(4,8)
  8281. #define LOG2_GPR_BYTES MODE_CHOICE(2,3) /* log2(GPR_BYTES) */
  8282. #define g_long MODE_CHOICE(long, quad) /* usage is ".g_long" */
  8283. ; From the ABI doc: "Mac OS X ABI Function Call Guide" Version 2009-02-04.
  8284. #define LINKAGE_SIZE MODE_CHOICE(24,48)
  8285. #define PARAM_AREA MODE_CHOICE(32,64)
  8286. #define SAVED_CR_OFFSET MODE_CHOICE(4,8) /* save position for CR */
  8287. #define SAVED_LR_OFFSET MODE_CHOICE(8,16) /* save position for lr */
  8288. /* WARNING: if ffi_type is changed... here be monsters.
  8289. Offsets of items within the result type. */
  8290. #define FFI_TYPE_TYPE MODE_CHOICE(6,10)
  8291. #define FFI_TYPE_ELEM MODE_CHOICE(8,16)
  8292. #define SAVED_FPR_COUNT 13
  8293. #define FPR_SIZE 8
  8294. /* biggest m64 struct ret is 8GPRS + 13FPRS = 168 bytes - rounded to 16bytes = 176. */
  8295. #define RESULT_BYTES MODE_CHOICE(16,176)
  8296. ; The whole stack frame **MUST** be 16byte-aligned.
  8297. #define SAVE_SIZE (((LINKAGE_SIZE+PARAM_AREA+SAVED_FPR_COUNT*FPR_SIZE+RESULT_BYTES)+15) & -16LL)
  8298. #define PAD_SIZE (SAVE_SIZE-(LINKAGE_SIZE+PARAM_AREA+SAVED_FPR_COUNT*FPR_SIZE+RESULT_BYTES))
  8299. #define PARENT_PARM_BASE (SAVE_SIZE+LINKAGE_SIZE)
  8300. #define FP_SAVE_BASE (LINKAGE_SIZE+PARAM_AREA)
  8301. #if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050
  8302. ; We no longer need the pic symbol stub for Darwin >= 9.
  8303. #define BLCLS_HELP _ffi_closure_helper_DARWIN
  8304. #define STRUCT_RETVALUE_P _darwin64_struct_ret_by_value_p
  8305. #define PASS_STR_FLOATS _darwin64_pass_struct_floats
  8306. #undef WANT_STUB
  8307. #else
  8308. #define BLCLS_HELP L_ffi_closure_helper_DARWIN$stub
  8309. #define STRUCT_RETVALUE_P L_darwin64_struct_ret_by_value_p$stub
  8310. #define PASS_STR_FLOATS L_darwin64_pass_struct_floats$stub
  8311. #define WANT_STUB
  8312. #endif
  8313. /* m32/m64
  8314. The stack layout looks like this:
  8315. | Additional params... | | Higher address
  8316. ~ ~ ~
  8317. | Parameters (at least 8*4/8=32/64) | | NUM_GPR_ARG_REGISTERS
  8318. |--------------------------------------------| |
  8319. | TOC=R2 (AIX) Reserved (Darwin) 4/8 | |
  8320. |--------------------------------------------| |
  8321. | Reserved 2*4/8 | |
  8322. |--------------------------------------------| |
  8323. | Space for callee`s LR 4/8 | |
  8324. |--------------------------------------------| |
  8325. | Saved CR [low word for m64] 4/8 | |
  8326. |--------------------------------------------| |
  8327. | Current backchain pointer 4/8 |-/ Parent`s frame.
  8328. |--------------------------------------------| <+ <<< on entry to
  8329. | Result Bytes 16/176 | |
  8330. |--------------------------------------------| |
  8331. ~ padding to 16-byte alignment ~ ~
  8332. |--------------------------------------------| |
  8333. | NUM_FPR_ARG_REGISTERS slots | |
  8334. | here fp13 .. fp1 13*8 | |
  8335. |--------------------------------------------| |
  8336. | R3..R10 8*4/8=32/64 | | NUM_GPR_ARG_REGISTERS
  8337. |--------------------------------------------| |
  8338. | TOC=R2 (AIX) Reserved (Darwin) 4/8 | |
  8339. |--------------------------------------------| | stack |
  8340. | Reserved [compiler,binder] 2*4/8 | | grows |
  8341. |--------------------------------------------| | down V
  8342. | Space for callees LR 4/8 | |
  8343. |--------------------------------------------| | lower addresses
  8344. | Saved CR [low word for m64] 4/8 | |
  8345. |--------------------------------------------| | stack pointer here
  8346. | Current backchain pointer 4/8 |-/ during
  8347. |--------------------------------------------| <<< call.
  8348. */
  8349. .file "darwin_closure.S"
  8350. .machine machine_choice
  8351. .text
  8352. .globl _ffi_closure_ASM
  8353. .align LOG2_GPR_BYTES
  8354. _ffi_closure_ASM:
  8355. LFB1:
  8356. Lstartcode:
  8357. mflr r0 /* extract return address */
  8358. sg r0,SAVED_LR_OFFSET(r1) /* save the return address */
  8359. LCFI0:
  8360. sgu r1,-SAVE_SIZE(r1) /* skip over caller save area
  8361. keep stack aligned to 16. */
  8362. LCFI1:
  8363. /* We want to build up an area for the parameters passed
  8364. in registers. (both floating point and integer) */
  8365. /* Put gpr 3 to gpr 10 in the parents outgoing area...
  8366. ... the remainder of any params that overflowed the regs will
  8367. follow here. */
  8368. sg r3, (PARENT_PARM_BASE )(r1)
  8369. sg r4, (PARENT_PARM_BASE + GPR_BYTES )(r1)
  8370. sg r5, (PARENT_PARM_BASE + GPR_BYTES * 2)(r1)
  8371. sg r6, (PARENT_PARM_BASE + GPR_BYTES * 3)(r1)
  8372. sg r7, (PARENT_PARM_BASE + GPR_BYTES * 4)(r1)
  8373. sg r8, (PARENT_PARM_BASE + GPR_BYTES * 5)(r1)
  8374. sg r9, (PARENT_PARM_BASE + GPR_BYTES * 6)(r1)
  8375. sg r10,(PARENT_PARM_BASE + GPR_BYTES * 7)(r1)
  8376. /* We save fpr 1 to fpr 14 in our own save frame. */
  8377. stfd f1, (FP_SAVE_BASE )(r1)
  8378. stfd f2, (FP_SAVE_BASE + FPR_SIZE )(r1)
  8379. stfd f3, (FP_SAVE_BASE + FPR_SIZE * 2 )(r1)
  8380. stfd f4, (FP_SAVE_BASE + FPR_SIZE * 3 )(r1)
  8381. stfd f5, (FP_SAVE_BASE + FPR_SIZE * 4 )(r1)
  8382. stfd f6, (FP_SAVE_BASE + FPR_SIZE * 5 )(r1)
  8383. stfd f7, (FP_SAVE_BASE + FPR_SIZE * 6 )(r1)
  8384. stfd f8, (FP_SAVE_BASE + FPR_SIZE * 7 )(r1)
  8385. stfd f9, (FP_SAVE_BASE + FPR_SIZE * 8 )(r1)
  8386. stfd f10,(FP_SAVE_BASE + FPR_SIZE * 9 )(r1)
  8387. stfd f11,(FP_SAVE_BASE + FPR_SIZE * 10)(r1)
  8388. stfd f12,(FP_SAVE_BASE + FPR_SIZE * 11)(r1)
  8389. stfd f13,(FP_SAVE_BASE + FPR_SIZE * 12)(r1)
  8390. /* Set up registers for the routine that actually does the work
  8391. get the context pointer from the trampoline. */
  8392. mr r3,r11
  8393. /* Now load up the pointer to the result storage. */
  8394. addi r4,r1,(SAVE_SIZE-RESULT_BYTES)
  8395. /* Now load up the pointer to the saved gpr registers. */
  8396. addi r5,r1,PARENT_PARM_BASE
  8397. /* Now load up the pointer to the saved fpr registers. */
  8398. addi r6,r1,FP_SAVE_BASE
  8399. /* Make the call. */
  8400. bl BLCLS_HELP
  8401. /* r3 contains the rtype pointer... save it since we will need
  8402. it later. */
  8403. sg r3,LINKAGE_SIZE(r1) ; ffi_type * result_type
  8404. lg r0,0(r3) ; size => r0
  8405. lhz r3,FFI_TYPE_TYPE(r3) ; type => r3
  8406. /* The helper will have intercepted structure returns and inserted
  8407. the caller`s destination address for structs returned by ref. */
  8408. /* r3 contains the return type so use it to look up in a table
  8409. so we know how to deal with each type. */
  8410. addi r5,r1,(SAVE_SIZE-RESULT_BYTES) /* Otherwise, our return is here. */
  8411. bl Lget_ret_type0_addr /* Get pointer to Lret_type0 into LR. */
  8412. mflr r4 /* Move to r4. */
  8413. slwi r3,r3,4 /* Now multiply return type by 16. */
  8414. add r3,r3,r4 /* Add contents of table to table address. */
  8415. mtctr r3
  8416. bctr /* Jump to it. */
  8417. LFE1:
  8418. /* Each of the ret_typeX code fragments has to be exactly 16 bytes long
  8419. (4 instructions). For cache effectiveness we align to a 16 byte boundary
  8420. first. */
  8421. .align 4
  8422. nop
  8423. nop
  8424. nop
  8425. Lget_ret_type0_addr:
  8426. blrl
  8427. /* case FFI_TYPE_VOID */
  8428. Lret_type0:
  8429. b Lfinish
  8430. nop
  8431. nop
  8432. nop
  8433. /* case FFI_TYPE_INT */
  8434. Lret_type1:
  8435. lg r3,0(r5)
  8436. b Lfinish
  8437. nop
  8438. nop
  8439. /* case FFI_TYPE_FLOAT */
  8440. Lret_type2:
  8441. lfs f1,0(r5)
  8442. b Lfinish
  8443. nop
  8444. nop
  8445. /* case FFI_TYPE_DOUBLE */
  8446. Lret_type3:
  8447. lfd f1,0(r5)
  8448. b Lfinish
  8449. nop
  8450. nop
  8451. /* case FFI_TYPE_LONGDOUBLE */
  8452. Lret_type4:
  8453. lfd f1,0(r5)
  8454. lfd f2,8(r5)
  8455. b Lfinish
  8456. nop
  8457. /* case FFI_TYPE_UINT8 */
  8458. Lret_type5:
  8459. #if defined(__ppc64__)
  8460. lbz r3,7(r5)
  8461. #else
  8462. lbz r3,3(r5)
  8463. #endif
  8464. b Lfinish
  8465. nop
  8466. nop
  8467. /* case FFI_TYPE_SINT8 */
  8468. Lret_type6:
  8469. #if defined(__ppc64__)
  8470. lbz r3,7(r5)
  8471. #else
  8472. lbz r3,3(r5)
  8473. #endif
  8474. extsb r3,r3
  8475. b Lfinish
  8476. nop
  8477. /* case FFI_TYPE_UINT16 */
  8478. Lret_type7:
  8479. #if defined(__ppc64__)
  8480. lhz r3,6(r5)
  8481. #else
  8482. lhz r3,2(r5)
  8483. #endif
  8484. b Lfinish
  8485. nop
  8486. nop
  8487. /* case FFI_TYPE_SINT16 */
  8488. Lret_type8:
  8489. #if defined(__ppc64__)
  8490. lha r3,6(r5)
  8491. #else
  8492. lha r3,2(r5)
  8493. #endif
  8494. b Lfinish
  8495. nop
  8496. nop
  8497. /* case FFI_TYPE_UINT32 */
  8498. Lret_type9:
  8499. #if defined(__ppc64__)
  8500. lwz r3,4(r5)
  8501. #else
  8502. lwz r3,0(r5)
  8503. #endif
  8504. b Lfinish
  8505. nop
  8506. nop
  8507. /* case FFI_TYPE_SINT32 */
  8508. Lret_type10:
  8509. #if defined(__ppc64__)
  8510. lwz r3,4(r5)
  8511. #else
  8512. lwz r3,0(r5)
  8513. #endif
  8514. b Lfinish
  8515. nop
  8516. nop
  8517. /* case FFI_TYPE_UINT64 */
  8518. Lret_type11:
  8519. #if defined(__ppc64__)
  8520. lg r3,0(r5)
  8521. b Lfinish
  8522. nop
  8523. #else
  8524. lwz r3,0(r5)
  8525. lwz r4,4(r5)
  8526. b Lfinish
  8527. #endif
  8528. nop
  8529. /* case FFI_TYPE_SINT64 */
  8530. Lret_type12:
  8531. #if defined(__ppc64__)
  8532. lg r3,0(r5)
  8533. b Lfinish
  8534. nop
  8535. #else
  8536. lwz r3,0(r5)
  8537. lwz r4,4(r5)
  8538. b Lfinish
  8539. #endif
  8540. nop
  8541. /* case FFI_TYPE_STRUCT */
  8542. Lret_type13:
  8543. #if defined(__ppc64__)
  8544. lg r3,0(r5) ; we need at least this...
  8545. cmpi 0,r0,4
  8546. bgt Lstructend ; not a special small case
  8547. b Lsmallstruct ; see if we need more.
  8548. #else
  8549. cmpwi 0,r0,4
  8550. bgt Lfinish ; not by value
  8551. lg r3,0(r5)
  8552. b Lfinish
  8553. #endif
  8554. /* case FFI_TYPE_POINTER */
  8555. Lret_type14:
  8556. lg r3,0(r5)
  8557. b Lfinish
  8558. nop
  8559. nop
  8560. #if defined(__ppc64__)
  8561. Lsmallstruct:
  8562. beq Lfour ; continuation of Lret13.
  8563. cmpi 0,r0,3
  8564. beq Lfinish ; don`t adjust this - can`t be any floats here...
  8565. srdi r3,r3,48
  8566. cmpi 0,r0,2
  8567. beq Lfinish ; .. or here ..
  8568. srdi r3,r3,8
  8569. b Lfinish ; .. or here.
  8570. Lfour:
  8571. lg r6,LINKAGE_SIZE(r1) ; get the result type
  8572. lg r6,FFI_TYPE_ELEM(r6) ; elements array pointer
  8573. lg r6,0(r6) ; first element
  8574. lhz r0,FFI_TYPE_TYPE(r6) ; OK go the type
  8575. cmpi 0,r0,2 ; FFI_TYPE_FLOAT
  8576. bne Lfourint
  8577. lfs f1,0(r5) ; just one float in the struct.
  8578. b Lfinish
  8579. Lfourint:
  8580. srdi r3,r3,32 ; four bytes.
  8581. b Lfinish
  8582. Lstructend:
  8583. lg r3,LINKAGE_SIZE(r1) ; get the result type
  8584. bl STRUCT_RETVALUE_P
  8585. cmpi 0,r3,0
  8586. beq Lfinish ; nope.
  8587. /* Recover a pointer to the results. */
  8588. addi r11,r1,(SAVE_SIZE-RESULT_BYTES)
  8589. lg r3,0(r11) ; we need at least this...
  8590. lg r4,8(r11)
  8591. cmpi 0,r0,16
  8592. beq Lfinish ; special case 16 bytes we don't consider floats.
  8593. /* OK, frustratingly, the process of saving the struct to mem might have
  8594. messed with the FPRs, so we have to re-load them :(.
  8595. We`ll use our FPRs space again - calling:
  8596. void darwin64_pass_struct_floats (ffi_type *s, char *src,
  8597. unsigned *nfpr, double **fprs)
  8598. We`ll temporarily pinch the first two slots of the param area for local
  8599. vars used by the routine. */
  8600. xor r6,r6,r6
  8601. addi r5,r1,PARENT_PARM_BASE ; some space
  8602. sg r6,0(r5) ; *nfpr zeroed.
  8603. addi r6,r5,8 ; **fprs
  8604. addi r3,r1,FP_SAVE_BASE ; pointer to FPRs space
  8605. sg r3,0(r6)
  8606. mr r4,r11 ; the struct is here...
  8607. lg r3,LINKAGE_SIZE(r1) ; ffi_type * result_type.
  8608. bl PASS_STR_FLOATS ; get struct floats into FPR save space.
  8609. /* See if we used any floats */
  8610. lwz r0,(SAVE_SIZE-RESULT_BYTES)(r1)
  8611. cmpi 0,r0,0
  8612. beq Lstructints ; nope.
  8613. /* OK load `em up... */
  8614. lfd f1, (FP_SAVE_BASE )(r1)
  8615. lfd f2, (FP_SAVE_BASE + FPR_SIZE )(r1)
  8616. lfd f3, (FP_SAVE_BASE + FPR_SIZE * 2 )(r1)
  8617. lfd f4, (FP_SAVE_BASE + FPR_SIZE * 3 )(r1)
  8618. lfd f5, (FP_SAVE_BASE + FPR_SIZE * 4 )(r1)
  8619. lfd f6, (FP_SAVE_BASE + FPR_SIZE * 5 )(r1)
  8620. lfd f7, (FP_SAVE_BASE + FPR_SIZE * 6 )(r1)
  8621. lfd f8, (FP_SAVE_BASE + FPR_SIZE * 7 )(r1)
  8622. lfd f9, (FP_SAVE_BASE + FPR_SIZE * 8 )(r1)
  8623. lfd f10,(FP_SAVE_BASE + FPR_SIZE * 9 )(r1)
  8624. lfd f11,(FP_SAVE_BASE + FPR_SIZE * 10)(r1)
  8625. lfd f12,(FP_SAVE_BASE + FPR_SIZE * 11)(r1)
  8626. lfd f13,(FP_SAVE_BASE + FPR_SIZE * 12)(r1)
  8627. /* point back at our saved struct. */
  8628. Lstructints:
  8629. addi r11,r1,(SAVE_SIZE-RESULT_BYTES)
  8630. lg r3,0(r11) ; we end up picking the
  8631. lg r4,8(r11) ; first two again.
  8632. lg r5,16(r11)
  8633. lg r6,24(r11)
  8634. lg r7,32(r11)
  8635. lg r8,40(r11)
  8636. lg r9,48(r11)
  8637. lg r10,56(r11)
  8638. #endif
  8639. /* case done */
  8640. Lfinish:
  8641. addi r1,r1,SAVE_SIZE /* Restore stack pointer. */
  8642. lg r0,SAVED_LR_OFFSET(r1) /* Get return address. */
  8643. mtlr r0 /* Reset link register. */
  8644. blr
  8645. Lendcode:
  8646. .align 1
  8647. /* END(ffi_closure_ASM) */
  8648. /* EH frame stuff. */
  8649. #define EH_DATA_ALIGN_FACT MODE_CHOICE(0x7c,0x78)
  8650. /* 176, 400 */
  8651. #define EH_FRAME_OFFSETA MODE_CHOICE(176,0x90)
  8652. #define EH_FRAME_OFFSETB MODE_CHOICE(1,3)
  8653. .section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support
  8654. EH_frame1:
  8655. .set L$set$0,LECIE1-LSCIE1
  8656. .long L$set$0 ; Length of Common Information Entry
  8657. LSCIE1:
  8658. .long 0x0 ; CIE Identifier Tag
  8659. .byte 0x1 ; CIE Version
  8660. .ascii "zR\0" ; CIE Augmentation
  8661. .byte 0x1 ; uleb128 0x1; CIE Code Alignment Factor
  8662. .byte EH_DATA_ALIGN_FACT ; sleb128 -4; CIE Data Alignment Factor
  8663. .byte 0x41 ; CIE RA Column
  8664. .byte 0x1 ; uleb128 0x1; Augmentation size
  8665. .byte 0x10 ; FDE Encoding (pcrel)
  8666. .byte 0xc ; DW_CFA_def_cfa
  8667. .byte 0x1 ; uleb128 0x1
  8668. .byte 0x0 ; uleb128 0x0
  8669. .align LOG2_GPR_BYTES
  8670. LECIE1:
  8671. .globl _ffi_closure_ASM.eh
  8672. _ffi_closure_ASM.eh:
  8673. LSFDE1:
  8674. .set L$set$1,LEFDE1-LASFDE1
  8675. .long L$set$1 ; FDE Length
  8676. LASFDE1:
  8677. .long LASFDE1-EH_frame1 ; FDE CIE offset
  8678. .g_long Lstartcode-. ; FDE initial location
  8679. .set L$set$2,LFE1-Lstartcode
  8680. .g_long L$set$2 ; FDE address range
  8681. .byte 0x0 ; uleb128 0x0; Augmentation size
  8682. .byte 0x4 ; DW_CFA_advance_loc4
  8683. .set L$set$3,LCFI1-LCFI0
  8684. .long L$set$3
  8685. .byte 0xe ; DW_CFA_def_cfa_offset
  8686. .byte EH_FRAME_OFFSETA,EH_FRAME_OFFSETB ; uleb128 176,1/190,3
  8687. .byte 0x4 ; DW_CFA_advance_loc4
  8688. .set L$set$4,LCFI0-Lstartcode
  8689. .long L$set$4
  8690. .byte 0x11 ; DW_CFA_offset_extended_sf
  8691. .byte 0x41 ; uleb128 0x41
  8692. .byte 0x7e ; sleb128 -2
  8693. .align LOG2_GPR_BYTES
  8694. LEFDE1:
  8695. .align 1
  8696. #ifdef WANT_STUB
  8697. .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
  8698. .align 5
  8699. L_ffi_closure_helper_DARWIN$stub:
  8700. .indirect_symbol _ffi_closure_helper_DARWIN
  8701. mflr r0
  8702. bcl 20,31,"L1$spb"
  8703. "L1$spb":
  8704. mflr r11
  8705. addis r11,r11,ha16(L_ffi_closure_helper_DARWIN$lazy_ptr-"L1$spb")
  8706. mtlr r0
  8707. lwzu r12,lo16(L_ffi_closure_helper_DARWIN$lazy_ptr-"L1$spb")(r11)
  8708. mtctr r12
  8709. bctr
  8710. .lazy_symbol_pointer
  8711. L_ffi_closure_helper_DARWIN$lazy_ptr:
  8712. .indirect_symbol _ffi_closure_helper_DARWIN
  8713. .g_long dyld_stub_binding_helper
  8714. #if defined(__ppc64__)
  8715. .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
  8716. .align 5
  8717. L_darwin64_struct_ret_by_value_p$stub:
  8718. .indirect_symbol _darwin64_struct_ret_by_value_p
  8719. mflr r0
  8720. bcl 20,31,"L2$spb"
  8721. "L2$spb":
  8722. mflr r11
  8723. addis r11,r11,ha16(L_darwin64_struct_ret_by_value_p$lazy_ptr-"L2$spb")
  8724. mtlr r0
  8725. lwzu r12,lo16(L_darwin64_struct_ret_by_value_p$lazy_ptr-"L2$spb")(r11)
  8726. mtctr r12
  8727. bctr
  8728. .lazy_symbol_pointer
  8729. L_darwin64_struct_ret_by_value_p$lazy_ptr:
  8730. .indirect_symbol _darwin64_struct_ret_by_value_p
  8731. .g_long dyld_stub_binding_helper
  8732. .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
  8733. .align 5
  8734. L_darwin64_pass_struct_floats$stub:
  8735. .indirect_symbol _darwin64_pass_struct_floats
  8736. mflr r0
  8737. bcl 20,31,"L3$spb"
  8738. "L3$spb":
  8739. mflr r11
  8740. addis r11,r11,ha16(L_darwin64_pass_struct_floats$lazy_ptr-"L3$spb")
  8741. mtlr r0
  8742. lwzu r12,lo16(L_darwin64_pass_struct_floats$lazy_ptr-"L3$spb")(r11)
  8743. mtctr r12
  8744. bctr
  8745. .lazy_symbol_pointer
  8746. L_darwin64_pass_struct_floats$lazy_ptr:
  8747. .indirect_symbol _darwin64_pass_struct_floats
  8748. .g_long dyld_stub_binding_helper
  8749. # endif
  8750. #endif
  8751. ====================File: src/powerpc/ffi.c====================
  8752. /* -----------------------------------------------------------------------
  8753. ffi.c - Copyright (C) 2013 IBM
  8754. Copyright (C) 2011 Anthony Green
  8755. Copyright (C) 2011 Kyle Moffett
  8756. Copyright (C) 2008 Red Hat, Inc
  8757. Copyright (C) 2007, 2008 Free Software Foundation, Inc
  8758. Copyright (c) 1998 Geoffrey Keating
  8759. PowerPC Foreign Function Interface
  8760. Permission is hereby granted, free of charge, to any person obtaining
  8761. a copy of this software and associated documentation files (the
  8762. ``Software''), to deal in the Software without restriction, including
  8763. without limitation the rights to use, copy, modify, merge, publish,
  8764. distribute, sublicense, and/or sell copies of the Software, and to
  8765. permit persons to whom the Software is furnished to do so, subject to
  8766. the following conditions:
  8767. The above copyright notice and this permission notice shall be included
  8768. in all copies or substantial portions of the Software.
  8769. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
  8770. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  8771. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  8772. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
  8773. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  8774. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  8775. OTHER DEALINGS IN THE SOFTWARE.
  8776. ----------------------------------------------------------------------- */
  8777. #include "ffi.h"
  8778. #include "ffi_common.h"
  8779. #include "ffi_powerpc.h"
  8780. #if HAVE_LONG_DOUBLE_VARIANT
  8781. /* Adjust ffi_type_longdouble. */
  8782. void FFI_HIDDEN
  8783. ffi_prep_types (ffi_abi abi)
  8784. {
  8785. # if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
  8786. # ifdef POWERPC64
  8787. ffi_prep_types_linux64 (abi);
  8788. # else
  8789. ffi_prep_types_sysv (abi);
  8790. # endif
  8791. # endif
  8792. }
  8793. #endif
  8794. /* Perform machine dependent cif processing */
  8795. ffi_status FFI_HIDDEN
  8796. ffi_prep_cif_machdep (ffi_cif *cif)
  8797. {
  8798. #ifdef POWERPC64
  8799. return ffi_prep_cif_linux64 (cif);
  8800. #else
  8801. return ffi_prep_cif_sysv (cif);
  8802. #endif
  8803. }
  8804. ffi_status FFI_HIDDEN
  8805. ffi_prep_cif_machdep_var (ffi_cif *cif,
  8806. unsigned int nfixedargs MAYBE_UNUSED,
  8807. unsigned int ntotalargs MAYBE_UNUSED)
  8808. {
  8809. #ifdef POWERPC64
  8810. return ffi_prep_cif_linux64_var (cif, nfixedargs, ntotalargs);
  8811. #else
  8812. return ffi_prep_cif_sysv (cif);
  8813. #endif
  8814. }
  8815. static void
  8816. ffi_call_int (ffi_cif *cif,
  8817. void (*fn) (void),
  8818. void *rvalue,
  8819. void **avalue,
  8820. void *closure)
  8821. {
  8822. /* The final SYSV ABI says that structures smaller or equal 8 bytes
  8823. are returned in r3/r4. A draft ABI used by linux instead returns
  8824. them in memory.
  8825. We bounce-buffer SYSV small struct return values so that sysv.S
  8826. can write r3 and r4 to memory without worrying about struct size.
  8827. For ELFv2 ABI, use a bounce buffer for homogeneous structs too,
  8828. for similar reasons. This bounce buffer must be aligned to 16
  8829. bytes for use with homogeneous structs of vectors (float128). */
  8830. float128 smst_buffer[8];
  8831. extended_cif ecif;
  8832. ecif.cif = cif;
  8833. ecif.avalue = avalue;
  8834. ecif.rvalue = rvalue;
  8835. if ((cif->flags & FLAG_RETURNS_SMST) != 0)
  8836. ecif.rvalue = smst_buffer;
  8837. /* Ensure that we have a valid struct return value.
  8838. FIXME: Isn't this just papering over a user problem? */
  8839. else if (!rvalue && cif->rtype->type == FFI_TYPE_STRUCT)
  8840. ecif.rvalue = alloca (cif->rtype->size);
  8841. #ifdef POWERPC64
  8842. ffi_call_LINUX64 (&ecif, fn, ecif.rvalue, cif->flags, closure,
  8843. -(long) cif->bytes);
  8844. #else
  8845. ffi_call_SYSV (&ecif, fn, ecif.rvalue, cif->flags, closure, -cif->bytes);
  8846. #endif
  8847. /* Check for a bounce-buffered return value */
  8848. if (rvalue && ecif.rvalue == smst_buffer)
  8849. {
  8850. unsigned int rsize = cif->rtype->size;
  8851. #ifndef __LITTLE_ENDIAN__
  8852. /* The SYSV ABI returns a structure of up to 4 bytes in size
  8853. left-padded in r3. */
  8854. # ifndef POWERPC64
  8855. if (rsize <= 4)
  8856. memcpy (rvalue, (char *) smst_buffer + 4 - rsize, rsize);
  8857. else
  8858. # endif
  8859. /* The SYSV ABI returns a structure of up to 8 bytes in size
  8860. left-padded in r3/r4, and the ELFv2 ABI similarly returns a
  8861. structure of up to 8 bytes in size left-padded in r3. But
  8862. note that a structure of a single float is not paddded. */
  8863. if (rsize <= 8 && (cif->flags & FLAG_RETURNS_FP) == 0)
  8864. memcpy (rvalue, (char *) smst_buffer + 8 - rsize, rsize);
  8865. else
  8866. #endif
  8867. memcpy (rvalue, smst_buffer, rsize);
  8868. }
  8869. }
  8870. void
  8871. ffi_call (ffi_cif *cif, void (*fn) (void), void *rvalue, void **avalue)
  8872. {
  8873. ffi_call_int (cif, fn, rvalue, avalue, NULL);
  8874. }
  8875. void
  8876. ffi_call_go (ffi_cif *cif, void (*fn) (void), void *rvalue, void **avalue,
  8877. void *closure)
  8878. {
  8879. ffi_call_int (cif, fn, rvalue, avalue, closure);
  8880. }
  8881. ffi_status
  8882. ffi_prep_closure_loc (ffi_closure *closure,
  8883. ffi_cif *cif,
  8884. void (*fun) (ffi_cif *, void *, void **, void *),
  8885. void *user_data,
  8886. void *codeloc)
  8887. {
  8888. #ifdef POWERPC64
  8889. return ffi_prep_closure_loc_linux64 (closure, cif, fun, user_data, codeloc);
  8890. #else
  8891. return ffi_prep_closure_loc_sysv (closure, cif, fun, user_data, codeloc);
  8892. #endif
  8893. }
  8894. ffi_status
  8895. ffi_prep_go_closure (ffi_go_closure *closure,
  8896. ffi_cif *cif,
  8897. void (*fun) (ffi_cif *, void *, void **, void *))
  8898. {
  8899. #ifdef POWERPC64
  8900. closure->tramp = ffi_go_closure_linux64;
  8901. #else
  8902. closure->tramp = ffi_go_closure_sysv;
  8903. #endif
  8904. closure->cif = cif;
  8905. closure->fun = fun;
  8906. return FFI_OK;
  8907. }
  8908. ====================File: src/powerpc/ffitarget.h====================
  8909. /* -----------------------------------------------------------------*-C-*-
  8910. ffitarget.h - Copyright (c) 2012 Anthony Green
  8911. Copyright (C) 2007, 2008, 2010 Free Software Foundation, Inc
  8912. Copyright (c) 1996-2003 Red Hat, Inc.
  8913. Target configuration macros for PowerPC.
  8914. Permission is hereby granted, free of charge, to any person obtaining
  8915. a copy of this software and associated documentation files (the
  8916. ``Software''), to deal in the Software without restriction, including
  8917. without limitation the rights to use, copy, modify, merge, publish,
  8918. distribute, sublicense, and/or sell copies of the Software, and to
  8919. permit persons to whom the Software is furnished to do so, subject to
  8920. the following conditions:
  8921. The above copyright notice and this permission notice shall be included
  8922. in all copies or substantial portions of the Software.
  8923. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  8924. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  8925. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  8926. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  8927. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  8928. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  8929. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  8930. DEALINGS IN THE SOFTWARE.
  8931. ----------------------------------------------------------------------- */
  8932. #ifndef LIBFFI_TARGET_H
  8933. #define LIBFFI_TARGET_H
  8934. #ifndef LIBFFI_H
  8935. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  8936. #endif
  8937. /* ---- System specific configurations ----------------------------------- */
  8938. #if defined (POWERPC) && defined (__powerpc64__) /* linux64 */
  8939. #ifndef POWERPC64
  8940. #define POWERPC64
  8941. #endif
  8942. #elif defined (POWERPC_DARWIN) && defined (__ppc64__) /* Darwin64 */
  8943. #ifndef POWERPC64
  8944. #define POWERPC64
  8945. #endif
  8946. #ifndef POWERPC_DARWIN64
  8947. #define POWERPC_DARWIN64
  8948. #endif
  8949. #elif defined (POWERPC_AIX) && defined (__64BIT__) /* AIX64 */
  8950. #ifndef POWERPC64
  8951. #define POWERPC64
  8952. #endif
  8953. #endif
  8954. #ifndef LIBFFI_ASM
  8955. typedef unsigned long ffi_arg;
  8956. typedef signed long ffi_sarg;
  8957. typedef enum ffi_abi {
  8958. FFI_FIRST_ABI = 0,
  8959. #if defined (POWERPC_AIX)
  8960. FFI_AIX,
  8961. FFI_DARWIN,
  8962. FFI_DEFAULT_ABI = FFI_AIX,
  8963. FFI_LAST_ABI
  8964. #elif defined (POWERPC_DARWIN)
  8965. FFI_AIX,
  8966. FFI_DARWIN,
  8967. FFI_DEFAULT_ABI = FFI_DARWIN,
  8968. FFI_LAST_ABI
  8969. #else
  8970. /* The FFI_COMPAT values are used by old code. Since libffi may be
  8971. a shared library we have to support old values for backwards
  8972. compatibility. */
  8973. FFI_COMPAT_SYSV,
  8974. FFI_COMPAT_GCC_SYSV,
  8975. FFI_COMPAT_LINUX64,
  8976. FFI_COMPAT_LINUX,
  8977. FFI_COMPAT_LINUX_SOFT_FLOAT,
  8978. # if defined (POWERPC64)
  8979. /* This bit, always set in new code, must not be set in any of the
  8980. old FFI_COMPAT values that might be used for 64-bit linux. We
  8981. only need worry about FFI_COMPAT_LINUX64, but to be safe avoid
  8982. all old values. */
  8983. FFI_LINUX = 8,
  8984. /* This and following bits can reuse FFI_COMPAT values. */
  8985. FFI_LINUX_STRUCT_ALIGN = 1,
  8986. FFI_LINUX_LONG_DOUBLE_128 = 2,
  8987. FFI_LINUX_LONG_DOUBLE_IEEE128 = 4,
  8988. FFI_DEFAULT_ABI = (FFI_LINUX
  8989. # ifdef __STRUCT_PARM_ALIGN__
  8990. | FFI_LINUX_STRUCT_ALIGN
  8991. # endif
  8992. # ifdef __LONG_DOUBLE_128__
  8993. | FFI_LINUX_LONG_DOUBLE_128
  8994. # ifdef __LONG_DOUBLE_IEEE128__
  8995. | FFI_LINUX_LONG_DOUBLE_IEEE128
  8996. # endif
  8997. # endif
  8998. ),
  8999. FFI_LAST_ABI = 16
  9000. # else
  9001. /* This bit, always set in new code, must not be set in any of the
  9002. old FFI_COMPAT values that might be used for 32-bit linux/sysv/bsd. */
  9003. FFI_SYSV = 8,
  9004. /* This and following bits can reuse FFI_COMPAT values. */
  9005. FFI_SYSV_SOFT_FLOAT = 1,
  9006. FFI_SYSV_STRUCT_RET = 2,
  9007. FFI_SYSV_IBM_LONG_DOUBLE = 4,
  9008. FFI_SYSV_LONG_DOUBLE_128 = 16,
  9009. FFI_DEFAULT_ABI = (FFI_SYSV
  9010. # ifdef __NO_FPRS__
  9011. | FFI_SYSV_SOFT_FLOAT
  9012. # endif
  9013. # if (defined (__SVR4_STRUCT_RETURN) \
  9014. || defined (POWERPC_FREEBSD) && !defined (__AIX_STRUCT_RETURN))
  9015. | FFI_SYSV_STRUCT_RET
  9016. # endif
  9017. # if __LDBL_MANT_DIG__ == 106
  9018. | FFI_SYSV_IBM_LONG_DOUBLE
  9019. # endif
  9020. # ifdef __LONG_DOUBLE_128__
  9021. | FFI_SYSV_LONG_DOUBLE_128
  9022. # endif
  9023. ),
  9024. FFI_LAST_ABI = 32
  9025. # endif
  9026. #endif
  9027. } ffi_abi;
  9028. #endif
  9029. /* ---- Definitions for closures ----------------------------------------- */
  9030. #define FFI_CLOSURES 1
  9031. #define FFI_NATIVE_RAW_API 0
  9032. #if defined (POWERPC) || defined (POWERPC_FREEBSD)
  9033. # define FFI_GO_CLOSURES 1
  9034. # define FFI_TARGET_SPECIFIC_VARIADIC 1
  9035. # define FFI_EXTRA_CIF_FIELDS unsigned nfixedargs
  9036. #endif
  9037. #if defined (POWERPC_AIX)
  9038. # define FFI_GO_CLOSURES 1
  9039. #endif
  9040. /* ppc_closure.S and linux64_closure.S expect this. */
  9041. #define FFI_PPC_TYPE_LAST FFI_TYPE_POINTER
  9042. /* We define additional types below. If generic types are added that
  9043. must be supported by powerpc libffi then it is likely that
  9044. FFI_PPC_TYPE_LAST needs increasing *and* the jump tables in
  9045. ppc_closure.S and linux64_closure.S be extended. */
  9046. #if !(FFI_TYPE_LAST == FFI_PPC_TYPE_LAST \
  9047. || (FFI_TYPE_LAST == FFI_TYPE_COMPLEX \
  9048. && !defined FFI_TARGET_HAS_COMPLEX_TYPE))
  9049. # error "You likely have a broken powerpc libffi"
  9050. #endif
  9051. /* Needed for soft-float long-double-128 support. */
  9052. #define FFI_TYPE_UINT128 (FFI_PPC_TYPE_LAST + 1)
  9053. /* Needed for FFI_SYSV small structure returns. */
  9054. #define FFI_SYSV_TYPE_SMALL_STRUCT (FFI_PPC_TYPE_LAST + 2)
  9055. /* Used by ELFv2 for homogenous structure returns. */
  9056. #define FFI_V2_TYPE_VECTOR (FFI_PPC_TYPE_LAST + 1)
  9057. #define FFI_V2_TYPE_VECTOR_HOMOG (FFI_PPC_TYPE_LAST + 2)
  9058. #define FFI_V2_TYPE_FLOAT_HOMOG (FFI_PPC_TYPE_LAST + 3)
  9059. #define FFI_V2_TYPE_DOUBLE_HOMOG (FFI_PPC_TYPE_LAST + 4)
  9060. #define FFI_V2_TYPE_SMALL_STRUCT (FFI_PPC_TYPE_LAST + 5)
  9061. #if _CALL_ELF == 2
  9062. # define FFI_TRAMPOLINE_SIZE 32
  9063. #else
  9064. # if defined(POWERPC64) || defined(POWERPC_AIX)
  9065. # if defined(POWERPC_DARWIN64)
  9066. # define FFI_TRAMPOLINE_SIZE 48
  9067. # else
  9068. # define FFI_TRAMPOLINE_SIZE 24
  9069. # endif
  9070. # else /* POWERPC || POWERPC_AIX */
  9071. # define FFI_TRAMPOLINE_SIZE 40
  9072. # endif
  9073. #endif
  9074. #ifndef LIBFFI_ASM
  9075. #if defined(POWERPC_DARWIN) || defined(POWERPC_AIX)
  9076. struct ffi_aix_trampoline_struct {
  9077. void * code_pointer; /* Pointer to ffi_closure_ASM */
  9078. void * toc; /* TOC */
  9079. void * static_chain; /* Pointer to closure */
  9080. };
  9081. #endif
  9082. #endif
  9083. #endif
  9084. ====================File: src/powerpc/ppc_closure.S====================
  9085. /* -----------------------------------------------------------------------
  9086. sysv.h - Copyright (c) 2003 Jakub Jelinek <jakub@redhat.com>
  9087. Copyright (c) 2008 Red Hat, Inc.
  9088. PowerPC Assembly glue.
  9089. Permission is hereby granted, free of charge, to any person obtaining
  9090. a copy of this software and associated documentation files (the
  9091. ``Software''), to deal in the Software without restriction, including
  9092. without limitation the rights to use, copy, modify, merge, publish,
  9093. distribute, sublicense, and/or sell copies of the Software, and to
  9094. permit persons to whom the Software is furnished to do so, subject to
  9095. the following conditions:
  9096. The above copyright notice and this permission notice shall be included
  9097. in all copies or substantial portions of the Software.
  9098. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  9099. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  9100. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  9101. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  9102. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  9103. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  9104. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  9105. DEALINGS IN THE SOFTWARE.
  9106. ----------------------------------------------------------------------- */
  9107. #define LIBFFI_ASM
  9108. #include <fficonfig.h>
  9109. #include <ffi.h>
  9110. #include <powerpc/asm.h>
  9111. .file "ppc_closure.S"
  9112. #ifndef POWERPC64
  9113. FFI_HIDDEN(ffi_closure_SYSV)
  9114. ENTRY(ffi_closure_SYSV)
  9115. .cfi_startproc
  9116. stwu %r1,-144(%r1)
  9117. .cfi_def_cfa_offset 144
  9118. mflr %r0
  9119. stw %r0,148(%r1)
  9120. .cfi_offset 65, 4
  9121. # we want to build up an areas for the parameters passed
  9122. # in registers (both floating point and integer)
  9123. # so first save gpr 3 to gpr 10 (aligned to 4)
  9124. stw %r3, 16(%r1)
  9125. stw %r4, 20(%r1)
  9126. stw %r5, 24(%r1)
  9127. # set up registers for the routine that does the work
  9128. # closure->cif
  9129. lwz %r3,FFI_TRAMPOLINE_SIZE(%r11)
  9130. # closure->fun
  9131. lwz %r4,FFI_TRAMPOLINE_SIZE+4(%r11)
  9132. # closure->user_data
  9133. lwz %r5,FFI_TRAMPOLINE_SIZE+8(%r11)
  9134. .Ldoclosure:
  9135. stw %r6, 28(%r1)
  9136. stw %r7, 32(%r1)
  9137. stw %r8, 36(%r1)
  9138. stw %r9, 40(%r1)
  9139. stw %r10,44(%r1)
  9140. #ifndef __NO_FPRS__
  9141. # next save fpr 1 to fpr 8 (aligned to 8)
  9142. stfd %f1, 48(%r1)
  9143. stfd %f2, 56(%r1)
  9144. stfd %f3, 64(%r1)
  9145. stfd %f4, 72(%r1)
  9146. stfd %f5, 80(%r1)
  9147. stfd %f6, 88(%r1)
  9148. stfd %f7, 96(%r1)
  9149. stfd %f8, 104(%r1)
  9150. #endif
  9151. # pointer to the result storage
  9152. addi %r6,%r1,112
  9153. # pointer to the saved gpr registers
  9154. addi %r7,%r1,16
  9155. # pointer to the saved fpr registers
  9156. addi %r8,%r1,48
  9157. # pointer to the outgoing parameter save area in the previous frame
  9158. # i.e. the previous frame pointer + 8
  9159. addi %r9,%r1,152
  9160. # make the call
  9161. bl ffi_closure_helper_SYSV@local
  9162. .Lret:
  9163. # now r3 contains the return type
  9164. # so use it to look up in a table
  9165. # so we know how to deal with each type
  9166. # look up the proper starting point in table
  9167. # by using return type as offset
  9168. mflr %r4 # move address of .Lret to r4
  9169. slwi %r3,%r3,4 # now multiply return type by 16
  9170. addi %r4, %r4, .Lret_type0 - .Lret
  9171. lwz %r0,148(%r1)
  9172. add %r3,%r3,%r4 # add contents of table to table address
  9173. mtctr %r3
  9174. bctr # jump to it
  9175. # Each of the ret_typeX code fragments has to be exactly 16 bytes long
  9176. # (4 instructions). For cache effectiveness we align to a 16 byte boundary
  9177. # first.
  9178. .align 4
  9179. # case FFI_TYPE_VOID
  9180. .Lret_type0:
  9181. mtlr %r0
  9182. addi %r1,%r1,144
  9183. .cfi_def_cfa_offset 0
  9184. blr
  9185. .cfi_def_cfa_offset 144
  9186. nop
  9187. # case FFI_TYPE_INT
  9188. lwz %r3,112+0(%r1)
  9189. mtlr %r0
  9190. .Lfinish:
  9191. addi %r1,%r1,144
  9192. .cfi_def_cfa_offset 0
  9193. blr
  9194. .cfi_def_cfa_offset 144
  9195. # case FFI_TYPE_FLOAT
  9196. #ifndef __NO_FPRS__
  9197. lfs %f1,112+0(%r1)
  9198. #else
  9199. nop
  9200. #endif
  9201. mtlr %r0
  9202. addi %r1,%r1,144
  9203. .cfi_def_cfa_offset 0
  9204. blr
  9205. .cfi_def_cfa_offset 144
  9206. # case FFI_TYPE_DOUBLE
  9207. #ifndef __NO_FPRS__
  9208. lfd %f1,112+0(%r1)
  9209. #else
  9210. nop
  9211. #endif
  9212. mtlr %r0
  9213. addi %r1,%r1,144
  9214. .cfi_def_cfa_offset 0
  9215. blr
  9216. .cfi_def_cfa_offset 144
  9217. # case FFI_TYPE_LONGDOUBLE
  9218. #ifndef __NO_FPRS__
  9219. lfd %f1,112+0(%r1)
  9220. lfd %f2,112+8(%r1)
  9221. mtlr %r0
  9222. b .Lfinish
  9223. #else
  9224. mtlr %r0
  9225. addi %r1,%r1,144
  9226. .cfi_def_cfa_offset 0
  9227. blr
  9228. .cfi_def_cfa_offset 144
  9229. nop
  9230. #endif
  9231. # case FFI_TYPE_UINT8
  9232. #ifdef __LITTLE_ENDIAN__
  9233. lbz %r3,112+0(%r1)
  9234. #else
  9235. lbz %r3,112+3(%r1)
  9236. #endif
  9237. mtlr %r0
  9238. addi %r1,%r1,144
  9239. .cfi_def_cfa_offset 0
  9240. blr
  9241. .cfi_def_cfa_offset 144
  9242. # case FFI_TYPE_SINT8
  9243. #ifdef __LITTLE_ENDIAN__
  9244. lbz %r3,112+0(%r1)
  9245. #else
  9246. lbz %r3,112+3(%r1)
  9247. #endif
  9248. extsb %r3,%r3
  9249. mtlr %r0
  9250. b .Lfinish
  9251. # case FFI_TYPE_UINT16
  9252. #ifdef __LITTLE_ENDIAN__
  9253. lhz %r3,112+0(%r1)
  9254. #else
  9255. lhz %r3,112+2(%r1)
  9256. #endif
  9257. mtlr %r0
  9258. addi %r1,%r1,144
  9259. .cfi_def_cfa_offset 0
  9260. blr
  9261. .cfi_def_cfa_offset 144
  9262. # case FFI_TYPE_SINT16
  9263. #ifdef __LITTLE_ENDIAN__
  9264. lha %r3,112+0(%r1)
  9265. #else
  9266. lha %r3,112+2(%r1)
  9267. #endif
  9268. mtlr %r0
  9269. addi %r1,%r1,144
  9270. .cfi_def_cfa_offset 0
  9271. blr
  9272. .cfi_def_cfa_offset 144
  9273. # case FFI_TYPE_UINT32
  9274. lwz %r3,112+0(%r1)
  9275. mtlr %r0
  9276. addi %r1,%r1,144
  9277. .cfi_def_cfa_offset 0
  9278. blr
  9279. .cfi_def_cfa_offset 144
  9280. # case FFI_TYPE_SINT32
  9281. lwz %r3,112+0(%r1)
  9282. mtlr %r0
  9283. addi %r1,%r1,144
  9284. .cfi_def_cfa_offset 0
  9285. blr
  9286. .cfi_def_cfa_offset 144
  9287. # case FFI_TYPE_UINT64
  9288. lwz %r3,112+0(%r1)
  9289. lwz %r4,112+4(%r1)
  9290. mtlr %r0
  9291. b .Lfinish
  9292. # case FFI_TYPE_SINT64
  9293. lwz %r3,112+0(%r1)
  9294. lwz %r4,112+4(%r1)
  9295. mtlr %r0
  9296. b .Lfinish
  9297. # case FFI_TYPE_STRUCT
  9298. mtlr %r0
  9299. addi %r1,%r1,144
  9300. .cfi_def_cfa_offset 0
  9301. blr
  9302. .cfi_def_cfa_offset 144
  9303. nop
  9304. # case FFI_TYPE_POINTER
  9305. lwz %r3,112+0(%r1)
  9306. mtlr %r0
  9307. addi %r1,%r1,144
  9308. .cfi_def_cfa_offset 0
  9309. blr
  9310. .cfi_def_cfa_offset 144
  9311. # case FFI_TYPE_UINT128
  9312. lwz %r3,112+0(%r1)
  9313. lwz %r4,112+4(%r1)
  9314. lwz %r5,112+8(%r1)
  9315. b .Luint128
  9316. # The return types below are only used when the ABI type is FFI_SYSV.
  9317. # case FFI_SYSV_TYPE_SMALL_STRUCT + 1. One byte struct.
  9318. lbz %r3,112+0(%r1)
  9319. mtlr %r0
  9320. addi %r1,%r1,144
  9321. .cfi_def_cfa_offset 0
  9322. blr
  9323. .cfi_def_cfa_offset 144
  9324. # case FFI_SYSV_TYPE_SMALL_STRUCT + 2. Two byte struct.
  9325. lhz %r3,112+0(%r1)
  9326. mtlr %r0
  9327. addi %r1,%r1,144
  9328. .cfi_def_cfa_offset 0
  9329. blr
  9330. .cfi_def_cfa_offset 144
  9331. # case FFI_SYSV_TYPE_SMALL_STRUCT + 3. Three byte struct.
  9332. lwz %r3,112+0(%r1)
  9333. #ifdef __LITTLE_ENDIAN__
  9334. mtlr %r0
  9335. addi %r1,%r1,144
  9336. .cfi_def_cfa_offset 0
  9337. blr
  9338. .cfi_def_cfa_offset 144
  9339. #else
  9340. srwi %r3,%r3,8
  9341. mtlr %r0
  9342. b .Lfinish
  9343. #endif
  9344. # case FFI_SYSV_TYPE_SMALL_STRUCT + 4. Four byte struct.
  9345. lwz %r3,112+0(%r1)
  9346. mtlr %r0
  9347. addi %r1,%r1,144
  9348. .cfi_def_cfa_offset 0
  9349. blr
  9350. .cfi_def_cfa_offset 144
  9351. # case FFI_SYSV_TYPE_SMALL_STRUCT + 5. Five byte struct.
  9352. lwz %r3,112+0(%r1)
  9353. lwz %r4,112+4(%r1)
  9354. #ifdef __LITTLE_ENDIAN__
  9355. mtlr %r0
  9356. b .Lfinish
  9357. #else
  9358. li %r5,24
  9359. b .Lstruct567
  9360. #endif
  9361. # case FFI_SYSV_TYPE_SMALL_STRUCT + 6. Six byte struct.
  9362. lwz %r3,112+0(%r1)
  9363. lwz %r4,112+4(%r1)
  9364. #ifdef __LITTLE_ENDIAN__
  9365. mtlr %r0
  9366. b .Lfinish
  9367. #else
  9368. li %r5,16
  9369. b .Lstruct567
  9370. #endif
  9371. # case FFI_SYSV_TYPE_SMALL_STRUCT + 7. Seven byte struct.
  9372. lwz %r3,112+0(%r1)
  9373. lwz %r4,112+4(%r1)
  9374. #ifdef __LITTLE_ENDIAN__
  9375. mtlr %r0
  9376. b .Lfinish
  9377. #else
  9378. li %r5,8
  9379. b .Lstruct567
  9380. #endif
  9381. # case FFI_SYSV_TYPE_SMALL_STRUCT + 8. Eight byte struct.
  9382. lwz %r3,112+0(%r1)
  9383. lwz %r4,112+4(%r1)
  9384. mtlr %r0
  9385. b .Lfinish
  9386. #ifndef __LITTLE_ENDIAN__
  9387. .Lstruct567:
  9388. subfic %r6,%r5,32
  9389. srw %r4,%r4,%r5
  9390. slw %r6,%r3,%r6
  9391. srw %r3,%r3,%r5
  9392. or %r4,%r6,%r4
  9393. mtlr %r0
  9394. addi %r1,%r1,144
  9395. .cfi_def_cfa_offset 0
  9396. blr
  9397. .cfi_def_cfa_offset 144
  9398. #endif
  9399. .Luint128:
  9400. lwz %r6,112+12(%r1)
  9401. mtlr %r0
  9402. addi %r1,%r1,144
  9403. .cfi_def_cfa_offset 0
  9404. blr
  9405. .cfi_endproc
  9406. END(ffi_closure_SYSV)
  9407. FFI_HIDDEN(ffi_go_closure_sysv)
  9408. ENTRY(ffi_go_closure_sysv)
  9409. .cfi_startproc
  9410. stwu %r1,-144(%r1)
  9411. .cfi_def_cfa_offset 144
  9412. mflr %r0
  9413. stw %r0,148(%r1)
  9414. .cfi_offset 65, 4
  9415. stw %r3, 16(%r1)
  9416. stw %r4, 20(%r1)
  9417. stw %r5, 24(%r1)
  9418. # closure->cif
  9419. lwz %r3,4(%r11)
  9420. # closure->fun
  9421. lwz %r4,8(%r11)
  9422. # user_data
  9423. mr %r5,%r11
  9424. b .Ldoclosure
  9425. .cfi_endproc
  9426. END(ffi_go_closure_sysv)
  9427. #if defined __ELF__ && defined __linux__
  9428. .section .note.GNU-stack,"",@progbits
  9429. #endif
  9430. #endif
  9431. ====================File: src/powerpc/sysv.S====================
  9432. /* -----------------------------------------------------------------------
  9433. sysv.S - Copyright (c) 1998 Geoffrey Keating
  9434. Copyright (C) 2007 Free Software Foundation, Inc
  9435. PowerPC Assembly glue.
  9436. Permission is hereby granted, free of charge, to any person obtaining
  9437. a copy of this software and associated documentation files (the
  9438. ``Software''), to deal in the Software without restriction, including
  9439. without limitation the rights to use, copy, modify, merge, publish,
  9440. distribute, sublicense, and/or sell copies of the Software, and to
  9441. permit persons to whom the Software is furnished to do so, subject to
  9442. the following conditions:
  9443. The above copyright notice and this permission notice shall be included
  9444. in all copies or substantial portions of the Software.
  9445. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  9446. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  9447. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  9448. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  9449. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  9450. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  9451. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  9452. DEALINGS IN THE SOFTWARE.
  9453. ----------------------------------------------------------------------- */
  9454. #define LIBFFI_ASM
  9455. #include <fficonfig.h>
  9456. #include <ffi.h>
  9457. #include <powerpc/asm.h>
  9458. #ifndef POWERPC64
  9459. FFI_HIDDEN(ffi_call_SYSV)
  9460. ENTRY(ffi_call_SYSV)
  9461. .cfi_startproc
  9462. /* Save the old stack pointer as AP. */
  9463. mr %r10,%r1
  9464. .cfi_def_cfa_register 10
  9465. /* Allocate the stack space we need. */
  9466. stwux %r1,%r1,%r8
  9467. /* Save registers we use. */
  9468. mflr %r9
  9469. stw %r28,-16(%r10)
  9470. stw %r29,-12(%r10)
  9471. stw %r30, -8(%r10)
  9472. stw %r31, -4(%r10)
  9473. stw %r9, 4(%r10)
  9474. .cfi_offset 65, 4
  9475. .cfi_offset 31, -4
  9476. .cfi_offset 30, -8
  9477. .cfi_offset 29, -12
  9478. .cfi_offset 28, -16
  9479. /* Save arguments over call... */
  9480. stw %r7, -20(%r10) /* closure, */
  9481. mr %r31,%r6 /* flags, */
  9482. mr %r30,%r5 /* rvalue, */
  9483. mr %r29,%r4 /* function address, */
  9484. mr %r28,%r10 /* our AP. */
  9485. .cfi_def_cfa_register 28
  9486. /* Call ffi_prep_args_SYSV. */
  9487. mr %r4,%r1
  9488. bl ffi_prep_args_SYSV@local
  9489. /* Now do the call. */
  9490. /* Set up cr1 with bits 4-7 of the flags. */
  9491. mtcrf 0x40,%r31
  9492. /* Get the address to call into CTR. */
  9493. mtctr %r29
  9494. /* Load all those argument registers. */
  9495. lwz %r3,-24-(8*4)(%r28)
  9496. lwz %r4,-24-(7*4)(%r28)
  9497. lwz %r5,-24-(6*4)(%r28)
  9498. lwz %r6,-24-(5*4)(%r28)
  9499. bf- 5,1f
  9500. nop
  9501. lwz %r7,-24-(4*4)(%r28)
  9502. lwz %r8,-24-(3*4)(%r28)
  9503. lwz %r9,-24-(2*4)(%r28)
  9504. lwz %r10,-24-(1*4)(%r28)
  9505. nop
  9506. 1:
  9507. #ifndef __NO_FPRS__
  9508. /* Load all the FP registers. */
  9509. bf- 6,2f
  9510. lfd %f1,-24-(8*4)-(8*8)(%r28)
  9511. lfd %f2,-24-(8*4)-(7*8)(%r28)
  9512. lfd %f3,-24-(8*4)-(6*8)(%r28)
  9513. lfd %f4,-24-(8*4)-(5*8)(%r28)
  9514. nop
  9515. lfd %f5,-24-(8*4)-(4*8)(%r28)
  9516. lfd %f6,-24-(8*4)-(3*8)(%r28)
  9517. lfd %f7,-24-(8*4)-(2*8)(%r28)
  9518. lfd %f8,-24-(8*4)-(1*8)(%r28)
  9519. #endif
  9520. 2:
  9521. /* Make the call. */
  9522. lwz %r11, -20(%r28)
  9523. bctrl
  9524. /* Now, deal with the return value. */
  9525. mtcrf 0x01,%r31 /* cr7 */
  9526. bt- 31,L(small_struct_return_value)
  9527. bt- 30,L(done_return_value)
  9528. #ifndef __NO_FPRS__
  9529. bt- 29,L(fp_return_value)
  9530. #endif
  9531. stw %r3,0(%r30)
  9532. bf+ 28,L(done_return_value)
  9533. stw %r4,4(%r30)
  9534. mtcrf 0x02,%r31 /* cr6 */
  9535. bf 27,L(done_return_value)
  9536. stw %r5,8(%r30)
  9537. stw %r6,12(%r30)
  9538. /* Fall through... */
  9539. L(done_return_value):
  9540. /* Restore the registers we used and return. */
  9541. lwz %r9, 4(%r28)
  9542. lwz %r31, -4(%r28)
  9543. mtlr %r9
  9544. lwz %r30, -8(%r28)
  9545. lwz %r29,-12(%r28)
  9546. lwz %r28,-16(%r28)
  9547. .cfi_remember_state
  9548. /* At this point we don't have a cfa register. Say all our
  9549. saved regs have been restored. */
  9550. .cfi_same_value 65
  9551. .cfi_same_value 31
  9552. .cfi_same_value 30
  9553. .cfi_same_value 29
  9554. .cfi_same_value 28
  9555. /* Hopefully this works.. */
  9556. .cfi_def_cfa_register 1
  9557. .cfi_offset 1, 0
  9558. lwz %r1,0(%r1)
  9559. .cfi_same_value 1
  9560. blr
  9561. #ifndef __NO_FPRS__
  9562. L(fp_return_value):
  9563. .cfi_restore_state
  9564. bf 28,L(float_return_value)
  9565. stfd %f1,0(%r30)
  9566. mtcrf 0x02,%r31 /* cr6 */
  9567. bf 27,L(done_return_value)
  9568. stfd %f2,8(%r30)
  9569. b L(done_return_value)
  9570. L(float_return_value):
  9571. stfs %f1,0(%r30)
  9572. b L(done_return_value)
  9573. #endif
  9574. L(small_struct_return_value):
  9575. /*
  9576. * The C code always allocates a properly-aligned 8-byte bounce
  9577. * buffer to make this assembly code very simple. Just write out
  9578. * r3 and r4 to the buffer to allow the C code to handle the rest.
  9579. */
  9580. stw %r3, 0(%r30)
  9581. stw %r4, 4(%r30)
  9582. b L(done_return_value)
  9583. .cfi_endproc
  9584. END(ffi_call_SYSV)
  9585. #if defined __ELF__ && defined __linux__
  9586. .section .note.GNU-stack,"",@progbits
  9587. #endif
  9588. #endif
  9589. ====================File: src/prep_cif.c====================
  9590. /* -----------------------------------------------------------------------
  9591. prep_cif.c - Copyright (c) 2011, 2012 Anthony Green
  9592. Copyright (c) 1996, 1998, 2007 Red Hat, Inc.
  9593. Permission is hereby granted, free of charge, to any person obtaining
  9594. a copy of this software and associated documentation files (the
  9595. ``Software''), to deal in the Software without restriction, including
  9596. without limitation the rights to use, copy, modify, merge, publish,
  9597. distribute, sublicense, and/or sell copies of the Software, and to
  9598. permit persons to whom the Software is furnished to do so, subject to
  9599. the following conditions:
  9600. The above copyright notice and this permission notice shall be included
  9601. in all copies or substantial portions of the Software.
  9602. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  9603. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  9604. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  9605. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  9606. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  9607. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  9608. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  9609. DEALINGS IN THE SOFTWARE.
  9610. ----------------------------------------------------------------------- */
  9611. #include <ffi.h>
  9612. #include <ffi_common.h>
  9613. #include <stdlib.h>
  9614. /* Round up to FFI_SIZEOF_ARG. */
  9615. #define STACK_ARG_SIZE(x) FFI_ALIGN(x, FFI_SIZEOF_ARG)
  9616. /* Perform machine independent initialization of aggregate type
  9617. specifications. */
  9618. static ffi_status initialize_aggregate(ffi_type *arg, size_t *offsets)
  9619. {
  9620. ffi_type **ptr;
  9621. if (UNLIKELY(arg == NULL || arg->elements == NULL))
  9622. return FFI_BAD_TYPEDEF;
  9623. arg->size = 0;
  9624. arg->alignment = 0;
  9625. ptr = &(arg->elements[0]);
  9626. if (UNLIKELY(ptr == 0))
  9627. return FFI_BAD_TYPEDEF;
  9628. while ((*ptr) != NULL)
  9629. {
  9630. if (UNLIKELY(((*ptr)->size == 0)
  9631. && (initialize_aggregate((*ptr), NULL) != FFI_OK)))
  9632. return FFI_BAD_TYPEDEF;
  9633. /* Perform a sanity check on the argument type */
  9634. FFI_ASSERT_VALID_TYPE(*ptr);
  9635. arg->size = FFI_ALIGN(arg->size, (*ptr)->alignment);
  9636. if (offsets)
  9637. *offsets++ = arg->size;
  9638. arg->size += (*ptr)->size;
  9639. arg->alignment = (arg->alignment > (*ptr)->alignment) ?
  9640. arg->alignment : (*ptr)->alignment;
  9641. ptr++;
  9642. }
  9643. /* Structure size includes tail padding. This is important for
  9644. structures that fit in one register on ABIs like the PowerPC64
  9645. Linux ABI that right justify small structs in a register.
  9646. It's also needed for nested structure layout, for example
  9647. struct A { long a; char b; }; struct B { struct A x; char y; };
  9648. should find y at an offset of 2*sizeof(long) and result in a
  9649. total size of 3*sizeof(long). */
  9650. arg->size = FFI_ALIGN (arg->size, arg->alignment);
  9651. /* On some targets, the ABI defines that structures have an additional
  9652. alignment beyond the "natural" one based on their elements. */
  9653. #ifdef FFI_AGGREGATE_ALIGNMENT
  9654. if (FFI_AGGREGATE_ALIGNMENT > arg->alignment)
  9655. arg->alignment = FFI_AGGREGATE_ALIGNMENT;
  9656. #endif
  9657. if (arg->size == 0)
  9658. return FFI_BAD_TYPEDEF;
  9659. else
  9660. return FFI_OK;
  9661. }
  9662. #ifndef __CRIS__
  9663. /* The CRIS ABI specifies structure elements to have byte
  9664. alignment only, so it completely overrides this functions,
  9665. which assumes "natural" alignment and padding. */
  9666. /* Perform machine independent ffi_cif preparation, then call
  9667. machine dependent routine. */
  9668. /* For non variadic functions isvariadic should be 0 and
  9669. nfixedargs==ntotalargs.
  9670. For variadic calls, isvariadic should be 1 and nfixedargs
  9671. and ntotalargs set as appropriate. nfixedargs must always be >=1 */
  9672. ffi_status FFI_HIDDEN ffi_prep_cif_core(ffi_cif *cif, ffi_abi abi,
  9673. unsigned int isvariadic,
  9674. unsigned int nfixedargs,
  9675. unsigned int ntotalargs,
  9676. ffi_type *rtype, ffi_type **atypes)
  9677. {
  9678. unsigned bytes = 0;
  9679. unsigned int i;
  9680. ffi_type **ptr;
  9681. FFI_ASSERT(cif != NULL);
  9682. FFI_ASSERT((!isvariadic) || (nfixedargs >= 1));
  9683. FFI_ASSERT(nfixedargs <= ntotalargs);
  9684. if (! (abi > FFI_FIRST_ABI && abi < FFI_LAST_ABI))
  9685. return FFI_BAD_ABI;
  9686. cif->abi = abi;
  9687. cif->arg_types = atypes;
  9688. cif->nargs = ntotalargs;
  9689. cif->rtype = rtype;
  9690. cif->flags = 0;
  9691. #ifdef _M_ARM64
  9692. cif->is_variadic = isvariadic;
  9693. #endif
  9694. #if HAVE_LONG_DOUBLE_VARIANT
  9695. ffi_prep_types (abi);
  9696. #endif
  9697. /* Initialize the return type if necessary */
  9698. if ((cif->rtype->size == 0)
  9699. && (initialize_aggregate(cif->rtype, NULL) != FFI_OK))
  9700. return FFI_BAD_TYPEDEF;
  9701. #ifndef FFI_TARGET_HAS_COMPLEX_TYPE
  9702. if (rtype->type == FFI_TYPE_COMPLEX)
  9703. abort();
  9704. #endif
  9705. /* Perform a sanity check on the return type */
  9706. FFI_ASSERT_VALID_TYPE(cif->rtype);
  9707. /* x86, x86-64 and s390 stack space allocation is handled in prep_machdep. */
  9708. #if !defined FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION
  9709. /* Make space for the return structure pointer */
  9710. if (cif->rtype->type == FFI_TYPE_STRUCT
  9711. #ifdef TILE
  9712. && (cif->rtype->size > 10 * FFI_SIZEOF_ARG)
  9713. #endif
  9714. #ifdef XTENSA
  9715. && (cif->rtype->size > 16)
  9716. #endif
  9717. #ifdef NIOS2
  9718. && (cif->rtype->size > 8)
  9719. #endif
  9720. )
  9721. bytes = STACK_ARG_SIZE(sizeof(void*));
  9722. #endif
  9723. for (ptr = cif->arg_types, i = cif->nargs; i > 0; i--, ptr++)
  9724. {
  9725. /* Initialize any uninitialized aggregate type definitions */
  9726. if (((*ptr)->size == 0)
  9727. && (initialize_aggregate((*ptr), NULL) != FFI_OK))
  9728. return FFI_BAD_TYPEDEF;
  9729. #ifndef FFI_TARGET_HAS_COMPLEX_TYPE
  9730. if ((*ptr)->type == FFI_TYPE_COMPLEX)
  9731. abort();
  9732. #endif
  9733. /* Perform a sanity check on the argument type, do this
  9734. check after the initialization. */
  9735. FFI_ASSERT_VALID_TYPE(*ptr);
  9736. #if !defined FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION
  9737. {
  9738. /* Add any padding if necessary */
  9739. if (((*ptr)->alignment - 1) & bytes)
  9740. bytes = (unsigned)FFI_ALIGN(bytes, (*ptr)->alignment);
  9741. #ifdef TILE
  9742. if (bytes < 10 * FFI_SIZEOF_ARG &&
  9743. bytes + STACK_ARG_SIZE((*ptr)->size) > 10 * FFI_SIZEOF_ARG)
  9744. {
  9745. /* An argument is never split between the 10 parameter
  9746. registers and the stack. */
  9747. bytes = 10 * FFI_SIZEOF_ARG;
  9748. }
  9749. #endif
  9750. #ifdef XTENSA
  9751. if (bytes <= 6*4 && bytes + STACK_ARG_SIZE((*ptr)->size) > 6*4)
  9752. bytes = 6*4;
  9753. #endif
  9754. bytes += (unsigned int)STACK_ARG_SIZE((*ptr)->size);
  9755. }
  9756. #endif
  9757. }
  9758. cif->bytes = bytes;
  9759. /* Perform machine dependent cif processing */
  9760. #ifdef FFI_TARGET_SPECIFIC_VARIADIC
  9761. if (isvariadic)
  9762. return ffi_prep_cif_machdep_var(cif, nfixedargs, ntotalargs);
  9763. #endif
  9764. return ffi_prep_cif_machdep(cif);
  9765. }
  9766. #endif /* not __CRIS__ */
  9767. ffi_status ffi_prep_cif(ffi_cif *cif, ffi_abi abi, unsigned int nargs,
  9768. ffi_type *rtype, ffi_type **atypes)
  9769. {
  9770. return ffi_prep_cif_core(cif, abi, 0, nargs, nargs, rtype, atypes);
  9771. }
  9772. ffi_status ffi_prep_cif_var(ffi_cif *cif,
  9773. ffi_abi abi,
  9774. unsigned int nfixedargs,
  9775. unsigned int ntotalargs,
  9776. ffi_type *rtype,
  9777. ffi_type **atypes)
  9778. {
  9779. return ffi_prep_cif_core(cif, abi, 1, nfixedargs, ntotalargs, rtype, atypes);
  9780. }
  9781. #if FFI_CLOSURES
  9782. ffi_status
  9783. ffi_prep_closure (ffi_closure* closure,
  9784. ffi_cif* cif,
  9785. void (*fun)(ffi_cif*,void*,void**,void*),
  9786. void *user_data)
  9787. {
  9788. return ffi_prep_closure_loc (closure, cif, fun, user_data, closure);
  9789. }
  9790. #endif
  9791. ffi_status
  9792. ffi_get_struct_offsets (ffi_abi abi, ffi_type *struct_type, size_t *offsets)
  9793. {
  9794. if (! (abi > FFI_FIRST_ABI && abi < FFI_LAST_ABI))
  9795. return FFI_BAD_ABI;
  9796. if (struct_type->type != FFI_TYPE_STRUCT)
  9797. return FFI_BAD_TYPEDEF;
  9798. #if HAVE_LONG_DOUBLE_VARIANT
  9799. ffi_prep_types (abi);
  9800. #endif
  9801. return initialize_aggregate(struct_type, offsets);
  9802. }
  9803. ====================File: src/raw_api.c====================
  9804. /* -----------------------------------------------------------------------
  9805. raw_api.c - Copyright (c) 1999, 2008 Red Hat, Inc.
  9806. Author: Kresten Krab Thorup <krab@gnu.org>
  9807. Permission is hereby granted, free of charge, to any person obtaining
  9808. a copy of this software and associated documentation files (the
  9809. ``Software''), to deal in the Software without restriction, including
  9810. without limitation the rights to use, copy, modify, merge, publish,
  9811. distribute, sublicense, and/or sell copies of the Software, and to
  9812. permit persons to whom the Software is furnished to do so, subject to
  9813. the following conditions:
  9814. The above copyright notice and this permission notice shall be included
  9815. in all copies or substantial portions of the Software.
  9816. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  9817. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  9818. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  9819. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  9820. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  9821. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  9822. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  9823. DEALINGS IN THE SOFTWARE.
  9824. ----------------------------------------------------------------------- */
  9825. /* This file defines generic functions for use with the raw api. */
  9826. #include <ffi.h>
  9827. #include <ffi_common.h>
  9828. #if !FFI_NO_RAW_API
  9829. size_t
  9830. ffi_raw_size (ffi_cif *cif)
  9831. {
  9832. size_t result = 0;
  9833. int i;
  9834. ffi_type **at = cif->arg_types;
  9835. for (i = cif->nargs-1; i >= 0; i--, at++)
  9836. {
  9837. #if !FFI_NO_STRUCTS
  9838. if ((*at)->type == FFI_TYPE_STRUCT)
  9839. result += FFI_ALIGN (sizeof (void*), FFI_SIZEOF_ARG);
  9840. else
  9841. #endif
  9842. result += FFI_ALIGN ((*at)->size, FFI_SIZEOF_ARG);
  9843. }
  9844. return result;
  9845. }
  9846. void
  9847. ffi_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args)
  9848. {
  9849. unsigned i;
  9850. ffi_type **tp = cif->arg_types;
  9851. #if WORDS_BIGENDIAN
  9852. for (i = 0; i < cif->nargs; i++, tp++, args++)
  9853. {
  9854. switch ((*tp)->type)
  9855. {
  9856. case FFI_TYPE_UINT8:
  9857. case FFI_TYPE_SINT8:
  9858. *args = (void*) ((char*)(raw++) + FFI_SIZEOF_ARG - 1);
  9859. break;
  9860. case FFI_TYPE_UINT16:
  9861. case FFI_TYPE_SINT16:
  9862. *args = (void*) ((char*)(raw++) + FFI_SIZEOF_ARG - 2);
  9863. break;
  9864. #if FFI_SIZEOF_ARG >= 4
  9865. case FFI_TYPE_UINT32:
  9866. case FFI_TYPE_SINT32:
  9867. *args = (void*) ((char*)(raw++) + FFI_SIZEOF_ARG - 4);
  9868. break;
  9869. #endif
  9870. #if !FFI_NO_STRUCTS
  9871. case FFI_TYPE_STRUCT:
  9872. *args = (raw++)->ptr;
  9873. break;
  9874. #endif
  9875. case FFI_TYPE_COMPLEX:
  9876. *args = (raw++)->ptr;
  9877. break;
  9878. case FFI_TYPE_POINTER:
  9879. *args = (void*) &(raw++)->ptr;
  9880. break;
  9881. default:
  9882. *args = raw;
  9883. raw += FFI_ALIGN ((*tp)->size, FFI_SIZEOF_ARG) / FFI_SIZEOF_ARG;
  9884. }
  9885. }
  9886. #else /* WORDS_BIGENDIAN */
  9887. #if !PDP
  9888. /* then assume little endian */
  9889. for (i = 0; i < cif->nargs; i++, tp++, args++)
  9890. {
  9891. #if !FFI_NO_STRUCTS
  9892. if ((*tp)->type == FFI_TYPE_STRUCT)
  9893. {
  9894. *args = (raw++)->ptr;
  9895. }
  9896. else
  9897. #endif
  9898. if ((*tp)->type == FFI_TYPE_COMPLEX)
  9899. {
  9900. *args = (raw++)->ptr;
  9901. }
  9902. else
  9903. {
  9904. *args = (void*) raw;
  9905. raw += FFI_ALIGN ((*tp)->size, sizeof (void*)) / sizeof (void*);
  9906. }
  9907. }
  9908. #else
  9909. #error "pdp endian not supported"
  9910. #endif /* ! PDP */
  9911. #endif /* WORDS_BIGENDIAN */
  9912. }
  9913. void
  9914. ffi_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw)
  9915. {
  9916. unsigned i;
  9917. ffi_type **tp = cif->arg_types;
  9918. for (i = 0; i < cif->nargs; i++, tp++, args++)
  9919. {
  9920. switch ((*tp)->type)
  9921. {
  9922. case FFI_TYPE_UINT8:
  9923. (raw++)->uint = *(UINT8*) (*args);
  9924. break;
  9925. case FFI_TYPE_SINT8:
  9926. (raw++)->sint = *(SINT8*) (*args);
  9927. break;
  9928. case FFI_TYPE_UINT16:
  9929. (raw++)->uint = *(UINT16*) (*args);
  9930. break;
  9931. case FFI_TYPE_SINT16:
  9932. (raw++)->sint = *(SINT16*) (*args);
  9933. break;
  9934. #if FFI_SIZEOF_ARG >= 4
  9935. case FFI_TYPE_UINT32:
  9936. (raw++)->uint = *(UINT32*) (*args);
  9937. break;
  9938. case FFI_TYPE_SINT32:
  9939. (raw++)->sint = *(SINT32*) (*args);
  9940. break;
  9941. #endif
  9942. #if !FFI_NO_STRUCTS
  9943. case FFI_TYPE_STRUCT:
  9944. (raw++)->ptr = *args;
  9945. break;
  9946. #endif
  9947. case FFI_TYPE_COMPLEX:
  9948. (raw++)->ptr = *args;
  9949. break;
  9950. case FFI_TYPE_POINTER:
  9951. (raw++)->ptr = **(void***) args;
  9952. break;
  9953. default:
  9954. memcpy ((void*) raw->data, (void*)*args, (*tp)->size);
  9955. raw += FFI_ALIGN ((*tp)->size, FFI_SIZEOF_ARG) / FFI_SIZEOF_ARG;
  9956. }
  9957. }
  9958. }
  9959. #if !FFI_NATIVE_RAW_API
  9960. /* This is a generic definition of ffi_raw_call, to be used if the
  9961. * native system does not provide a machine-specific implementation.
  9962. * Having this, allows code to be written for the raw API, without
  9963. * the need for system-specific code to handle input in that format;
  9964. * these following couple of functions will handle the translation forth
  9965. * and back automatically. */
  9966. void ffi_raw_call (ffi_cif *cif, void (*fn)(void), void *rvalue, ffi_raw *raw)
  9967. {
  9968. void **avalue = (void**) alloca (cif->nargs * sizeof (void*));
  9969. ffi_raw_to_ptrarray (cif, raw, avalue);
  9970. ffi_call (cif, fn, rvalue, avalue);
  9971. }
  9972. #if FFI_CLOSURES /* base system provides closures */
  9973. static void
  9974. ffi_translate_args (ffi_cif *cif, void *rvalue,
  9975. void **avalue, void *user_data)
  9976. {
  9977. ffi_raw *raw = (ffi_raw*)alloca (ffi_raw_size (cif));
  9978. ffi_raw_closure *cl = (ffi_raw_closure*)user_data;
  9979. ffi_ptrarray_to_raw (cif, avalue, raw);
  9980. (*cl->fun) (cif, rvalue, raw, cl->user_data);
  9981. }
  9982. ffi_status
  9983. ffi_prep_raw_closure_loc (ffi_raw_closure* cl,
  9984. ffi_cif *cif,
  9985. void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
  9986. void *user_data,
  9987. void *codeloc)
  9988. {
  9989. ffi_status status;
  9990. status = ffi_prep_closure_loc ((ffi_closure*) cl,
  9991. cif,
  9992. &ffi_translate_args,
  9993. codeloc,
  9994. codeloc);
  9995. if (status == FFI_OK)
  9996. {
  9997. cl->fun = fun;
  9998. cl->user_data = user_data;
  9999. }
  10000. return status;
  10001. }
  10002. #endif /* FFI_CLOSURES */
  10003. #endif /* !FFI_NATIVE_RAW_API */
  10004. #if FFI_CLOSURES
  10005. /* Again, here is the generic version of ffi_prep_raw_closure, which
  10006. * will install an intermediate "hub" for translation of arguments from
  10007. * the pointer-array format, to the raw format */
  10008. ffi_status
  10009. ffi_prep_raw_closure (ffi_raw_closure* cl,
  10010. ffi_cif *cif,
  10011. void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
  10012. void *user_data)
  10013. {
  10014. return ffi_prep_raw_closure_loc (cl, cif, fun, user_data, cl);
  10015. }
  10016. #endif /* FFI_CLOSURES */
  10017. #endif /* !FFI_NO_RAW_API */
  10018. ====================File: src/types.c====================
  10019. /* -----------------------------------------------------------------------
  10020. types.c - Copyright (c) 1996, 1998 Red Hat, Inc.
  10021. Predefined ffi_types needed by libffi.
  10022. Permission is hereby granted, free of charge, to any person obtaining
  10023. a copy of this software and associated documentation files (the
  10024. ``Software''), to deal in the Software without restriction, including
  10025. without limitation the rights to use, copy, modify, merge, publish,
  10026. distribute, sublicense, and/or sell copies of the Software, and to
  10027. permit persons to whom the Software is furnished to do so, subject to
  10028. the following conditions:
  10029. The above copyright notice and this permission notice shall be included
  10030. in all copies or substantial portions of the Software.
  10031. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  10032. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  10033. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  10034. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  10035. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  10036. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  10037. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  10038. DEALINGS IN THE SOFTWARE.
  10039. ----------------------------------------------------------------------- */
  10040. /* Hide the basic type definitions from the header file, so that we
  10041. can redefine them here as "const". */
  10042. #define LIBFFI_HIDE_BASIC_TYPES
  10043. #include <ffi.h>
  10044. #include <ffi_common.h>
  10045. /* Type definitions */
  10046. #define FFI_TYPEDEF(name, type, id, maybe_const)\
  10047. struct struct_align_##name { \
  10048. char c; \
  10049. type x; \
  10050. }; \
  10051. FFI_EXTERN \
  10052. maybe_const ffi_type ffi_type_##name = { \
  10053. sizeof(type), \
  10054. offsetof(struct struct_align_##name, x), \
  10055. id, NULL \
  10056. }
  10057. #define FFI_COMPLEX_TYPEDEF(name, type, maybe_const) \
  10058. static ffi_type *ffi_elements_complex_##name [2] = { \
  10059. (ffi_type *)(&ffi_type_##name), NULL \
  10060. }; \
  10061. struct struct_align_complex_##name { \
  10062. char c; \
  10063. _Complex type x; \
  10064. }; \
  10065. FFI_EXTERN \
  10066. maybe_const ffi_type ffi_type_complex_##name = { \
  10067. sizeof(_Complex type), \
  10068. offsetof(struct struct_align_complex_##name, x), \
  10069. FFI_TYPE_COMPLEX, \
  10070. (ffi_type **)ffi_elements_complex_##name \
  10071. }
  10072. /* Size and alignment are fake here. They must not be 0. */
  10073. FFI_EXTERN const ffi_type ffi_type_void = {
  10074. 1, 1, FFI_TYPE_VOID, NULL
  10075. };
  10076. FFI_TYPEDEF(uint8, UINT8, FFI_TYPE_UINT8, const);
  10077. FFI_TYPEDEF(sint8, SINT8, FFI_TYPE_SINT8, const);
  10078. FFI_TYPEDEF(uint16, UINT16, FFI_TYPE_UINT16, const);
  10079. FFI_TYPEDEF(sint16, SINT16, FFI_TYPE_SINT16, const);
  10080. FFI_TYPEDEF(uint32, UINT32, FFI_TYPE_UINT32, const);
  10081. FFI_TYPEDEF(sint32, SINT32, FFI_TYPE_SINT32, const);
  10082. FFI_TYPEDEF(uint64, UINT64, FFI_TYPE_UINT64, const);
  10083. FFI_TYPEDEF(sint64, SINT64, FFI_TYPE_SINT64, const);
  10084. FFI_TYPEDEF(pointer, void*, FFI_TYPE_POINTER, const);
  10085. FFI_TYPEDEF(float, float, FFI_TYPE_FLOAT, const);
  10086. FFI_TYPEDEF(double, double, FFI_TYPE_DOUBLE, const);
  10087. #if !defined HAVE_LONG_DOUBLE_VARIANT || defined __alpha__
  10088. #define FFI_LDBL_CONST const
  10089. #else
  10090. #define FFI_LDBL_CONST
  10091. #endif
  10092. #ifdef __alpha__
  10093. /* Even if we're not configured to default to 128-bit long double,
  10094. maintain binary compatibility, as -mlong-double-128 can be used
  10095. at any time. */
  10096. /* Validate the hard-coded number below. */
  10097. # if defined(__LONG_DOUBLE_128__) && FFI_TYPE_LONGDOUBLE != 4
  10098. # error FFI_TYPE_LONGDOUBLE out of date
  10099. # endif
  10100. const ffi_type ffi_type_longdouble = { 16, 16, 4, NULL };
  10101. #elif FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
  10102. FFI_TYPEDEF(longdouble, long double, FFI_TYPE_LONGDOUBLE, FFI_LDBL_CONST);
  10103. #endif
  10104. #ifdef FFI_TARGET_HAS_COMPLEX_TYPE
  10105. FFI_COMPLEX_TYPEDEF(float, float, const);
  10106. FFI_COMPLEX_TYPEDEF(double, double, const);
  10107. #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
  10108. FFI_COMPLEX_TYPEDEF(longdouble, long double, FFI_LDBL_CONST);
  10109. #endif
  10110. #endif
  10111. ====================File: src/x86/ffi.c====================
  10112. /* -----------------------------------------------------------------------
  10113. ffi.c - Copyright (c) 2017 Anthony Green
  10114. Copyright (c) 1996, 1998, 1999, 2001, 2007, 2008 Red Hat, Inc.
  10115. Copyright (c) 2002 Ranjit Mathew
  10116. Copyright (c) 2002 Bo Thorsen
  10117. Copyright (c) 2002 Roger Sayle
  10118. Copyright (C) 2008, 2010 Free Software Foundation, Inc.
  10119. x86 Foreign Function Interface
  10120. Permission is hereby granted, free of charge, to any person obtaining
  10121. a copy of this software and associated documentation files (the
  10122. ``Software''), to deal in the Software without restriction, including
  10123. without limitation the rights to use, copy, modify, merge, publish,
  10124. distribute, sublicense, and/or sell copies of the Software, and to
  10125. permit persons to whom the Software is furnished to do so, subject to
  10126. the following conditions:
  10127. The above copyright notice and this permission notice shall be included
  10128. in all copies or substantial portions of the Software.
  10129. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  10130. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  10131. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  10132. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  10133. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  10134. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  10135. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  10136. DEALINGS IN THE SOFTWARE.
  10137. ----------------------------------------------------------------------- */
  10138. #if defined(__i386__) || defined(_M_IX86)
  10139. #include <ffi.h>
  10140. #include <ffi_common.h>
  10141. #include <stdint.h>
  10142. #include <stdlib.h>
  10143. #include "internal.h"
  10144. /* Force FFI_TYPE_LONGDOUBLE to be different than FFI_TYPE_DOUBLE;
  10145. all further uses in this file will refer to the 80-bit type. */
  10146. #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
  10147. # if FFI_TYPE_LONGDOUBLE != 4
  10148. # error FFI_TYPE_LONGDOUBLE out of date
  10149. # endif
  10150. #else
  10151. # undef FFI_TYPE_LONGDOUBLE
  10152. # define FFI_TYPE_LONGDOUBLE 4
  10153. #endif
  10154. #if defined(__GNUC__) && !defined(__declspec)
  10155. # define __declspec(x) __attribute__((x))
  10156. #endif
  10157. #if defined(_MSC_VER) && defined(_M_IX86)
  10158. /* Stack is not 16-byte aligned on Windows. */
  10159. #define STACK_ALIGN(bytes) (bytes)
  10160. #else
  10161. #define STACK_ALIGN(bytes) FFI_ALIGN (bytes, 16)
  10162. #endif
  10163. /* Perform machine dependent cif processing. */
  10164. ffi_status FFI_HIDDEN
  10165. ffi_prep_cif_machdep(ffi_cif *cif)
  10166. {
  10167. size_t bytes = 0;
  10168. int i, n, flags, cabi = cif->abi;
  10169. switch (cabi)
  10170. {
  10171. case FFI_SYSV:
  10172. case FFI_STDCALL:
  10173. case FFI_THISCALL:
  10174. case FFI_FASTCALL:
  10175. case FFI_MS_CDECL:
  10176. case FFI_PASCAL:
  10177. case FFI_REGISTER:
  10178. break;
  10179. default:
  10180. return FFI_BAD_ABI;
  10181. }
  10182. switch (cif->rtype->type)
  10183. {
  10184. case FFI_TYPE_VOID:
  10185. flags = X86_RET_VOID;
  10186. break;
  10187. case FFI_TYPE_FLOAT:
  10188. flags = X86_RET_FLOAT;
  10189. break;
  10190. case FFI_TYPE_DOUBLE:
  10191. flags = X86_RET_DOUBLE;
  10192. break;
  10193. case FFI_TYPE_LONGDOUBLE:
  10194. flags = X86_RET_LDOUBLE;
  10195. break;
  10196. case FFI_TYPE_UINT8:
  10197. flags = X86_RET_UINT8;
  10198. break;
  10199. case FFI_TYPE_UINT16:
  10200. flags = X86_RET_UINT16;
  10201. break;
  10202. case FFI_TYPE_SINT8:
  10203. flags = X86_RET_SINT8;
  10204. break;
  10205. case FFI_TYPE_SINT16:
  10206. flags = X86_RET_SINT16;
  10207. break;
  10208. case FFI_TYPE_INT:
  10209. case FFI_TYPE_SINT32:
  10210. case FFI_TYPE_UINT32:
  10211. case FFI_TYPE_POINTER:
  10212. flags = X86_RET_INT32;
  10213. break;
  10214. case FFI_TYPE_SINT64:
  10215. case FFI_TYPE_UINT64:
  10216. flags = X86_RET_INT64;
  10217. break;
  10218. case FFI_TYPE_STRUCT:
  10219. #ifndef X86
  10220. /* ??? This should be a different ABI rather than an ifdef. */
  10221. if (cif->rtype->size == 1)
  10222. flags = X86_RET_STRUCT_1B;
  10223. else if (cif->rtype->size == 2)
  10224. flags = X86_RET_STRUCT_2B;
  10225. else if (cif->rtype->size == 4)
  10226. flags = X86_RET_INT32;
  10227. else if (cif->rtype->size == 8)
  10228. flags = X86_RET_INT64;
  10229. else
  10230. #endif
  10231. {
  10232. do_struct:
  10233. switch (cabi)
  10234. {
  10235. case FFI_THISCALL:
  10236. case FFI_FASTCALL:
  10237. case FFI_STDCALL:
  10238. case FFI_MS_CDECL:
  10239. flags = X86_RET_STRUCTARG;
  10240. break;
  10241. default:
  10242. flags = X86_RET_STRUCTPOP;
  10243. break;
  10244. }
  10245. /* Allocate space for return value pointer. */
  10246. bytes += FFI_ALIGN (sizeof(void*), FFI_SIZEOF_ARG);
  10247. }
  10248. break;
  10249. case FFI_TYPE_COMPLEX:
  10250. switch (cif->rtype->elements[0]->type)
  10251. {
  10252. case FFI_TYPE_DOUBLE:
  10253. case FFI_TYPE_LONGDOUBLE:
  10254. case FFI_TYPE_SINT64:
  10255. case FFI_TYPE_UINT64:
  10256. goto do_struct;
  10257. case FFI_TYPE_FLOAT:
  10258. case FFI_TYPE_INT:
  10259. case FFI_TYPE_SINT32:
  10260. case FFI_TYPE_UINT32:
  10261. flags = X86_RET_INT64;
  10262. break;
  10263. case FFI_TYPE_SINT16:
  10264. case FFI_TYPE_UINT16:
  10265. flags = X86_RET_INT32;
  10266. break;
  10267. case FFI_TYPE_SINT8:
  10268. case FFI_TYPE_UINT8:
  10269. flags = X86_RET_STRUCT_2B;
  10270. break;
  10271. default:
  10272. return FFI_BAD_TYPEDEF;
  10273. }
  10274. break;
  10275. default:
  10276. return FFI_BAD_TYPEDEF;
  10277. }
  10278. cif->flags = flags;
  10279. for (i = 0, n = cif->nargs; i < n; i++)
  10280. {
  10281. ffi_type *t = cif->arg_types[i];
  10282. bytes = FFI_ALIGN (bytes, t->alignment);
  10283. bytes += FFI_ALIGN (t->size, FFI_SIZEOF_ARG);
  10284. }
  10285. cif->bytes = bytes;
  10286. return FFI_OK;
  10287. }
  10288. static ffi_arg
  10289. extend_basic_type(void *arg, int type)
  10290. {
  10291. switch (type)
  10292. {
  10293. case FFI_TYPE_SINT8:
  10294. return *(SINT8 *)arg;
  10295. case FFI_TYPE_UINT8:
  10296. return *(UINT8 *)arg;
  10297. case FFI_TYPE_SINT16:
  10298. return *(SINT16 *)arg;
  10299. case FFI_TYPE_UINT16:
  10300. return *(UINT16 *)arg;
  10301. case FFI_TYPE_SINT32:
  10302. case FFI_TYPE_UINT32:
  10303. case FFI_TYPE_POINTER:
  10304. case FFI_TYPE_FLOAT:
  10305. return *(UINT32 *)arg;
  10306. default:
  10307. abort();
  10308. }
  10309. }
  10310. struct call_frame
  10311. {
  10312. void *ebp; /* 0 */
  10313. void *retaddr; /* 4 */
  10314. void (*fn)(void); /* 8 */
  10315. int flags; /* 12 */
  10316. void *rvalue; /* 16 */
  10317. unsigned regs[3]; /* 20-28 */
  10318. };
  10319. struct abi_params
  10320. {
  10321. int dir; /* parameter growth direction */
  10322. int static_chain; /* the static chain register used by gcc */
  10323. int nregs; /* number of register parameters */
  10324. int regs[3];
  10325. };
  10326. static const struct abi_params abi_params[FFI_LAST_ABI] = {
  10327. [FFI_SYSV] = { 1, R_ECX, 0 },
  10328. [FFI_THISCALL] = { 1, R_EAX, 1, { R_ECX } },
  10329. [FFI_FASTCALL] = { 1, R_EAX, 2, { R_ECX, R_EDX } },
  10330. [FFI_STDCALL] = { 1, R_ECX, 0 },
  10331. [FFI_PASCAL] = { -1, R_ECX, 0 },
  10332. /* ??? No defined static chain; gcc does not support REGISTER. */
  10333. [FFI_REGISTER] = { -1, R_ECX, 3, { R_EAX, R_EDX, R_ECX } },
  10334. [FFI_MS_CDECL] = { 1, R_ECX, 0 }
  10335. };
  10336. #ifdef HAVE_FASTCALL
  10337. #ifdef _MSC_VER
  10338. #define FFI_DECLARE_FASTCALL __fastcall
  10339. #else
  10340. #define FFI_DECLARE_FASTCALL __declspec(fastcall)
  10341. #endif
  10342. #else
  10343. #define FFI_DECLARE_FASTCALL
  10344. #endif
  10345. extern void FFI_DECLARE_FASTCALL ffi_call_i386(struct call_frame *, char *) FFI_HIDDEN;
  10346. static void
  10347. ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue,
  10348. void **avalue, void *closure)
  10349. {
  10350. size_t rsize, bytes;
  10351. struct call_frame *frame;
  10352. char *stack, *argp;
  10353. ffi_type **arg_types;
  10354. int flags, cabi, i, n, dir, narg_reg;
  10355. const struct abi_params *pabi;
  10356. flags = cif->flags;
  10357. cabi = cif->abi;
  10358. pabi = &abi_params[cabi];
  10359. dir = pabi->dir;
  10360. rsize = 0;
  10361. if (rvalue == NULL)
  10362. {
  10363. switch (flags)
  10364. {
  10365. case X86_RET_FLOAT:
  10366. case X86_RET_DOUBLE:
  10367. case X86_RET_LDOUBLE:
  10368. case X86_RET_STRUCTPOP:
  10369. case X86_RET_STRUCTARG:
  10370. /* The float cases need to pop the 387 stack.
  10371. The struct cases need to pass a valid pointer to the callee. */
  10372. rsize = cif->rtype->size;
  10373. break;
  10374. default:
  10375. /* We can pretend that the callee returns nothing. */
  10376. flags = X86_RET_VOID;
  10377. break;
  10378. }
  10379. }
  10380. bytes = STACK_ALIGN (cif->bytes);
  10381. stack = alloca(bytes + sizeof(*frame) + rsize);
  10382. argp = (dir < 0 ? stack + bytes : stack);
  10383. frame = (struct call_frame *)(stack + bytes);
  10384. if (rsize)
  10385. rvalue = frame + 1;
  10386. frame->fn = fn;
  10387. frame->flags = flags;
  10388. frame->rvalue = rvalue;
  10389. frame->regs[pabi->static_chain] = (unsigned)closure;
  10390. narg_reg = 0;
  10391. switch (flags)
  10392. {
  10393. case X86_RET_STRUCTARG:
  10394. /* The pointer is passed as the first argument. */
  10395. if (pabi->nregs > 0)
  10396. {
  10397. frame->regs[pabi->regs[0]] = (unsigned)rvalue;
  10398. narg_reg = 1;
  10399. break;
  10400. }
  10401. /* fallthru */
  10402. case X86_RET_STRUCTPOP:
  10403. *(void **)argp = rvalue;
  10404. argp += sizeof(void *);
  10405. break;
  10406. }
  10407. arg_types = cif->arg_types;
  10408. for (i = 0, n = cif->nargs; i < n; i++)
  10409. {
  10410. ffi_type *ty = arg_types[i];
  10411. void *valp = avalue[i];
  10412. size_t z = ty->size;
  10413. int t = ty->type;
  10414. if (z <= FFI_SIZEOF_ARG && t != FFI_TYPE_STRUCT)
  10415. {
  10416. ffi_arg val = extend_basic_type (valp, t);
  10417. if (t != FFI_TYPE_FLOAT && narg_reg < pabi->nregs)
  10418. frame->regs[pabi->regs[narg_reg++]] = val;
  10419. else if (dir < 0)
  10420. {
  10421. argp -= 4;
  10422. *(ffi_arg *)argp = val;
  10423. }
  10424. else
  10425. {
  10426. *(ffi_arg *)argp = val;
  10427. argp += 4;
  10428. }
  10429. }
  10430. else
  10431. {
  10432. size_t za = FFI_ALIGN (z, FFI_SIZEOF_ARG);
  10433. size_t align = FFI_SIZEOF_ARG;
  10434. /* Issue 434: For thiscall and fastcall, if the paramter passed
  10435. as 64-bit integer or struct, all following integer paramters
  10436. will be passed on stack. */
  10437. if ((cabi == FFI_THISCALL || cabi == FFI_FASTCALL)
  10438. && (t == FFI_TYPE_SINT64
  10439. || t == FFI_TYPE_UINT64
  10440. || t == FFI_TYPE_STRUCT))
  10441. narg_reg = 2;
  10442. /* Alignment rules for arguments are quite complex. Vectors and
  10443. structures with 16 byte alignment get it. Note that long double
  10444. on Darwin does have 16 byte alignment, and does not get this
  10445. alignment if passed directly; a structure with a long double
  10446. inside, however, would get 16 byte alignment. Since libffi does
  10447. not support vectors, we need non concern ourselves with other
  10448. cases. */
  10449. if (t == FFI_TYPE_STRUCT && ty->alignment >= 16)
  10450. align = 16;
  10451. if (dir < 0)
  10452. {
  10453. /* ??? These reverse argument ABIs are probably too old
  10454. to have cared about alignment. Someone should check. */
  10455. argp -= za;
  10456. memcpy (argp, valp, z);
  10457. }
  10458. else
  10459. {
  10460. argp = (char *)FFI_ALIGN (argp, align);
  10461. memcpy (argp, valp, z);
  10462. argp += za;
  10463. }
  10464. }
  10465. }
  10466. FFI_ASSERT (dir > 0 || argp == stack);
  10467. ffi_call_i386 (frame, stack);
  10468. }
  10469. void
  10470. ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
  10471. {
  10472. ffi_call_int (cif, fn, rvalue, avalue, NULL);
  10473. }
  10474. void
  10475. ffi_call_go (ffi_cif *cif, void (*fn)(void), void *rvalue,
  10476. void **avalue, void *closure)
  10477. {
  10478. ffi_call_int (cif, fn, rvalue, avalue, closure);
  10479. }
  10480. /** private members **/
  10481. void FFI_HIDDEN ffi_closure_i386(void);
  10482. void FFI_HIDDEN ffi_closure_STDCALL(void);
  10483. void FFI_HIDDEN ffi_closure_REGISTER(void);
  10484. struct closure_frame
  10485. {
  10486. unsigned rettemp[4]; /* 0 */
  10487. unsigned regs[3]; /* 16-24 */
  10488. ffi_cif *cif; /* 28 */
  10489. void (*fun)(ffi_cif*,void*,void**,void*); /* 32 */
  10490. void *user_data; /* 36 */
  10491. };
  10492. int FFI_HIDDEN FFI_DECLARE_FASTCALL
  10493. ffi_closure_inner (struct closure_frame *frame, char *stack)
  10494. {
  10495. ffi_cif *cif = frame->cif;
  10496. int cabi, i, n, flags, dir, narg_reg;
  10497. const struct abi_params *pabi;
  10498. ffi_type **arg_types;
  10499. char *argp;
  10500. void *rvalue;
  10501. void **avalue;
  10502. cabi = cif->abi;
  10503. flags = cif->flags;
  10504. narg_reg = 0;
  10505. rvalue = frame->rettemp;
  10506. pabi = &abi_params[cabi];
  10507. dir = pabi->dir;
  10508. argp = (dir < 0 ? stack + STACK_ALIGN (cif->bytes) : stack);
  10509. switch (flags)
  10510. {
  10511. case X86_RET_STRUCTARG:
  10512. if (pabi->nregs > 0)
  10513. {
  10514. rvalue = (void *)frame->regs[pabi->regs[0]];
  10515. narg_reg = 1;
  10516. frame->rettemp[0] = (unsigned)rvalue;
  10517. break;
  10518. }
  10519. /* fallthru */
  10520. case X86_RET_STRUCTPOP:
  10521. rvalue = *(void **)argp;
  10522. argp += sizeof(void *);
  10523. frame->rettemp[0] = (unsigned)rvalue;
  10524. break;
  10525. }
  10526. n = cif->nargs;
  10527. avalue = alloca(sizeof(void *) * n);
  10528. arg_types = cif->arg_types;
  10529. for (i = 0; i < n; ++i)
  10530. {
  10531. ffi_type *ty = arg_types[i];
  10532. size_t z = ty->size;
  10533. int t = ty->type;
  10534. void *valp;
  10535. if (z <= FFI_SIZEOF_ARG && t != FFI_TYPE_STRUCT)
  10536. {
  10537. if (t != FFI_TYPE_FLOAT && narg_reg < pabi->nregs)
  10538. valp = &frame->regs[pabi->regs[narg_reg++]];
  10539. else if (dir < 0)
  10540. {
  10541. argp -= 4;
  10542. valp = argp;
  10543. }
  10544. else
  10545. {
  10546. valp = argp;
  10547. argp += 4;
  10548. }
  10549. }
  10550. else
  10551. {
  10552. size_t za = FFI_ALIGN (z, FFI_SIZEOF_ARG);
  10553. size_t align = FFI_SIZEOF_ARG;
  10554. /* See the comment in ffi_call_int. */
  10555. if (t == FFI_TYPE_STRUCT && ty->alignment >= 16)
  10556. align = 16;
  10557. /* Issue 434: For thiscall and fastcall, if the paramter passed
  10558. as 64-bit integer or struct, all following integer paramters
  10559. will be passed on stack. */
  10560. if ((cabi == FFI_THISCALL || cabi == FFI_FASTCALL)
  10561. && (t == FFI_TYPE_SINT64
  10562. || t == FFI_TYPE_UINT64
  10563. || t == FFI_TYPE_STRUCT))
  10564. narg_reg = 2;
  10565. if (dir < 0)
  10566. {
  10567. /* ??? These reverse argument ABIs are probably too old
  10568. to have cared about alignment. Someone should check. */
  10569. argp -= za;
  10570. valp = argp;
  10571. }
  10572. else
  10573. {
  10574. argp = (char *)FFI_ALIGN (argp, align);
  10575. valp = argp;
  10576. argp += za;
  10577. }
  10578. }
  10579. avalue[i] = valp;
  10580. }
  10581. frame->fun (cif, rvalue, avalue, frame->user_data);
  10582. if (cabi == FFI_STDCALL)
  10583. return flags + (cif->bytes << X86_RET_POP_SHIFT);
  10584. else
  10585. return flags;
  10586. }
  10587. ffi_status
  10588. ffi_prep_closure_loc (ffi_closure* closure,
  10589. ffi_cif* cif,
  10590. void (*fun)(ffi_cif*,void*,void**,void*),
  10591. void *user_data,
  10592. void *codeloc)
  10593. {
  10594. char *tramp = closure->tramp;
  10595. void (*dest)(void);
  10596. int op = 0xb8; /* movl imm, %eax */
  10597. switch (cif->abi)
  10598. {
  10599. case FFI_SYSV:
  10600. case FFI_THISCALL:
  10601. case FFI_FASTCALL:
  10602. case FFI_MS_CDECL:
  10603. dest = ffi_closure_i386;
  10604. break;
  10605. case FFI_STDCALL:
  10606. case FFI_PASCAL:
  10607. dest = ffi_closure_STDCALL;
  10608. break;
  10609. case FFI_REGISTER:
  10610. dest = ffi_closure_REGISTER;
  10611. op = 0x68; /* pushl imm */
  10612. break;
  10613. default:
  10614. return FFI_BAD_ABI;
  10615. }
  10616. /* movl or pushl immediate. */
  10617. tramp[0] = op;
  10618. *(void **)(tramp + 1) = codeloc;
  10619. /* jmp dest */
  10620. tramp[5] = 0xe9;
  10621. *(unsigned *)(tramp + 6) = (unsigned)dest - ((unsigned)codeloc + 10);
  10622. closure->cif = cif;
  10623. closure->fun = fun;
  10624. closure->user_data = user_data;
  10625. return FFI_OK;
  10626. }
  10627. void FFI_HIDDEN ffi_go_closure_EAX(void);
  10628. void FFI_HIDDEN ffi_go_closure_ECX(void);
  10629. void FFI_HIDDEN ffi_go_closure_STDCALL(void);
  10630. ffi_status
  10631. ffi_prep_go_closure (ffi_go_closure* closure, ffi_cif* cif,
  10632. void (*fun)(ffi_cif*,void*,void**,void*))
  10633. {
  10634. void (*dest)(void);
  10635. switch (cif->abi)
  10636. {
  10637. case FFI_SYSV:
  10638. case FFI_MS_CDECL:
  10639. dest = ffi_go_closure_ECX;
  10640. break;
  10641. case FFI_THISCALL:
  10642. case FFI_FASTCALL:
  10643. dest = ffi_go_closure_EAX;
  10644. break;
  10645. case FFI_STDCALL:
  10646. case FFI_PASCAL:
  10647. dest = ffi_go_closure_STDCALL;
  10648. break;
  10649. case FFI_REGISTER:
  10650. default:
  10651. return FFI_BAD_ABI;
  10652. }
  10653. closure->tramp = dest;
  10654. closure->cif = cif;
  10655. closure->fun = fun;
  10656. return FFI_OK;
  10657. }
  10658. /* ------- Native raw API support -------------------------------- */
  10659. #if !FFI_NO_RAW_API
  10660. void FFI_HIDDEN ffi_closure_raw_SYSV(void);
  10661. void FFI_HIDDEN ffi_closure_raw_THISCALL(void);
  10662. ffi_status
  10663. ffi_prep_raw_closure_loc (ffi_raw_closure *closure,
  10664. ffi_cif *cif,
  10665. void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
  10666. void *user_data,
  10667. void *codeloc)
  10668. {
  10669. char *tramp = closure->tramp;
  10670. void (*dest)(void);
  10671. int i;
  10672. /* We currently don't support certain kinds of arguments for raw
  10673. closures. This should be implemented by a separate assembly
  10674. language routine, since it would require argument processing,
  10675. something we don't do now for performance. */
  10676. for (i = cif->nargs-1; i >= 0; i--)
  10677. switch (cif->arg_types[i]->type)
  10678. {
  10679. case FFI_TYPE_STRUCT:
  10680. case FFI_TYPE_LONGDOUBLE:
  10681. return FFI_BAD_TYPEDEF;
  10682. }
  10683. switch (cif->abi)
  10684. {
  10685. case FFI_THISCALL:
  10686. dest = ffi_closure_raw_THISCALL;
  10687. break;
  10688. case FFI_SYSV:
  10689. dest = ffi_closure_raw_SYSV;
  10690. break;
  10691. default:
  10692. return FFI_BAD_ABI;
  10693. }
  10694. /* movl imm, %eax. */
  10695. tramp[0] = 0xb8;
  10696. *(void **)(tramp + 1) = codeloc;
  10697. /* jmp dest */
  10698. tramp[5] = 0xe9;
  10699. *(unsigned *)(tramp + 6) = (unsigned)dest - ((unsigned)codeloc + 10);
  10700. closure->cif = cif;
  10701. closure->fun = fun;
  10702. closure->user_data = user_data;
  10703. return FFI_OK;
  10704. }
  10705. void
  10706. ffi_raw_call(ffi_cif *cif, void (*fn)(void), void *rvalue, ffi_raw *avalue)
  10707. {
  10708. size_t rsize, bytes;
  10709. struct call_frame *frame;
  10710. char *stack, *argp;
  10711. ffi_type **arg_types;
  10712. int flags, cabi, i, n, narg_reg;
  10713. const struct abi_params *pabi;
  10714. flags = cif->flags;
  10715. cabi = cif->abi;
  10716. pabi = &abi_params[cabi];
  10717. rsize = 0;
  10718. if (rvalue == NULL)
  10719. {
  10720. switch (flags)
  10721. {
  10722. case X86_RET_FLOAT:
  10723. case X86_RET_DOUBLE:
  10724. case X86_RET_LDOUBLE:
  10725. case X86_RET_STRUCTPOP:
  10726. case X86_RET_STRUCTARG:
  10727. /* The float cases need to pop the 387 stack.
  10728. The struct cases need to pass a valid pointer to the callee. */
  10729. rsize = cif->rtype->size;
  10730. break;
  10731. default:
  10732. /* We can pretend that the callee returns nothing. */
  10733. flags = X86_RET_VOID;
  10734. break;
  10735. }
  10736. }
  10737. bytes = STACK_ALIGN (cif->bytes);
  10738. argp = stack =
  10739. (void *)((uintptr_t)alloca(bytes + sizeof(*frame) + rsize + 15) & ~16);
  10740. frame = (struct call_frame *)(stack + bytes);
  10741. if (rsize)
  10742. rvalue = frame + 1;
  10743. frame->fn = fn;
  10744. frame->flags = flags;
  10745. frame->rvalue = rvalue;
  10746. narg_reg = 0;
  10747. switch (flags)
  10748. {
  10749. case X86_RET_STRUCTARG:
  10750. /* The pointer is passed as the first argument. */
  10751. if (pabi->nregs > 0)
  10752. {
  10753. frame->regs[pabi->regs[0]] = (unsigned)rvalue;
  10754. narg_reg = 1;
  10755. break;
  10756. }
  10757. /* fallthru */
  10758. case X86_RET_STRUCTPOP:
  10759. *(void **)argp = rvalue;
  10760. argp += sizeof(void *);
  10761. bytes -= sizeof(void *);
  10762. break;
  10763. }
  10764. arg_types = cif->arg_types;
  10765. for (i = 0, n = cif->nargs; narg_reg < pabi->nregs && i < n; i++)
  10766. {
  10767. ffi_type *ty = arg_types[i];
  10768. size_t z = ty->size;
  10769. int t = ty->type;
  10770. if (z <= FFI_SIZEOF_ARG && t != FFI_TYPE_STRUCT && t != FFI_TYPE_FLOAT)
  10771. {
  10772. ffi_arg val = extend_basic_type (avalue, t);
  10773. frame->regs[pabi->regs[narg_reg++]] = val;
  10774. z = FFI_SIZEOF_ARG;
  10775. }
  10776. else
  10777. {
  10778. memcpy (argp, avalue, z);
  10779. z = FFI_ALIGN (z, FFI_SIZEOF_ARG);
  10780. argp += z;
  10781. }
  10782. avalue += z;
  10783. bytes -= z;
  10784. }
  10785. if (i < n)
  10786. memcpy (argp, avalue, bytes);
  10787. ffi_call_i386 (frame, stack);
  10788. }
  10789. #endif /* !FFI_NO_RAW_API */
  10790. #endif /* __i386__ */
  10791. ====================File: src/x86/ffi64.c====================
  10792. /* -----------------------------------------------------------------------
  10793. ffi64.c - Copyright (c) 2011, 2018 Anthony Green
  10794. Copyright (c) 2013 The Written Word, Inc.
  10795. Copyright (c) 2008, 2010 Red Hat, Inc.
  10796. Copyright (c) 2002, 2007 Bo Thorsen <bo@suse.de>
  10797. x86-64 Foreign Function Interface
  10798. Permission is hereby granted, free of charge, to any person obtaining
  10799. a copy of this software and associated documentation files (the
  10800. ``Software''), to deal in the Software without restriction, including
  10801. without limitation the rights to use, copy, modify, merge, publish,
  10802. distribute, sublicense, and/or sell copies of the Software, and to
  10803. permit persons to whom the Software is furnished to do so, subject to
  10804. the following conditions:
  10805. The above copyright notice and this permission notice shall be included
  10806. in all copies or substantial portions of the Software.
  10807. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  10808. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  10809. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  10810. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  10811. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  10812. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  10813. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  10814. DEALINGS IN THE SOFTWARE.
  10815. ----------------------------------------------------------------------- */
  10816. #include <ffi.h>
  10817. #include <ffi_common.h>
  10818. #include <stdlib.h>
  10819. #include <stdarg.h>
  10820. #include <stdint.h>
  10821. #include "internal64.h"
  10822. #ifdef __x86_64__
  10823. #define MAX_GPR_REGS 6
  10824. #define MAX_SSE_REGS 8
  10825. #if defined(__INTEL_COMPILER)
  10826. #include "xmmintrin.h"
  10827. #define UINT128 __m128
  10828. #else
  10829. #if defined(__SUNPRO_C)
  10830. #error #include <sunmedia_types.h>
  10831. #define UINT128 __m128i
  10832. #else
  10833. #define UINT128 __int128_t
  10834. #endif
  10835. #endif
  10836. union big_int_union
  10837. {
  10838. UINT32 i32;
  10839. UINT64 i64;
  10840. UINT128 i128;
  10841. };
  10842. struct register_args
  10843. {
  10844. /* Registers for argument passing. */
  10845. UINT64 gpr[MAX_GPR_REGS];
  10846. union big_int_union sse[MAX_SSE_REGS];
  10847. UINT64 rax; /* ssecount */
  10848. UINT64 r10; /* static chain */
  10849. };
  10850. extern void ffi_call_unix64 (void *args, unsigned long bytes, unsigned flags,
  10851. void *raddr, void (*fnaddr)(void)) FFI_HIDDEN;
  10852. /* All reference to register classes here is identical to the code in
  10853. gcc/config/i386/i386.c. Do *not* change one without the other. */
  10854. /* Register class used for passing given 64bit part of the argument.
  10855. These represent classes as documented by the PS ABI, with the
  10856. exception of SSESF, SSEDF classes, that are basically SSE class,
  10857. just gcc will use SF or DFmode move instead of DImode to avoid
  10858. reformatting penalties.
  10859. Similary we play games with INTEGERSI_CLASS to use cheaper SImode moves
  10860. whenever possible (upper half does contain padding). */
  10861. enum x86_64_reg_class
  10862. {
  10863. X86_64_NO_CLASS,
  10864. X86_64_INTEGER_CLASS,
  10865. X86_64_INTEGERSI_CLASS,
  10866. X86_64_SSE_CLASS,
  10867. X86_64_SSESF_CLASS,
  10868. X86_64_SSEDF_CLASS,
  10869. X86_64_SSEUP_CLASS,
  10870. X86_64_X87_CLASS,
  10871. X86_64_X87UP_CLASS,
  10872. X86_64_COMPLEX_X87_CLASS,
  10873. X86_64_MEMORY_CLASS
  10874. };
  10875. #define MAX_CLASSES 4
  10876. #define SSE_CLASS_P(X) ((X) >= X86_64_SSE_CLASS && X <= X86_64_SSEUP_CLASS)
  10877. /* x86-64 register passing implementation. See x86-64 ABI for details. Goal
  10878. of this code is to classify each 8bytes of incoming argument by the register
  10879. class and assign registers accordingly. */
  10880. /* Return the union class of CLASS1 and CLASS2.
  10881. See the x86-64 PS ABI for details. */
  10882. static enum x86_64_reg_class
  10883. merge_classes (enum x86_64_reg_class class1, enum x86_64_reg_class class2)
  10884. {
  10885. /* Rule #1: If both classes are equal, this is the resulting class. */
  10886. if (class1 == class2)
  10887. return class1;
  10888. /* Rule #2: If one of the classes is NO_CLASS, the resulting class is
  10889. the other class. */
  10890. if (class1 == X86_64_NO_CLASS)
  10891. return class2;
  10892. if (class2 == X86_64_NO_CLASS)
  10893. return class1;
  10894. /* Rule #3: If one of the classes is MEMORY, the result is MEMORY. */
  10895. if (class1 == X86_64_MEMORY_CLASS || class2 == X86_64_MEMORY_CLASS)
  10896. return X86_64_MEMORY_CLASS;
  10897. /* Rule #4: If one of the classes is INTEGER, the result is INTEGER. */
  10898. if ((class1 == X86_64_INTEGERSI_CLASS && class2 == X86_64_SSESF_CLASS)
  10899. || (class2 == X86_64_INTEGERSI_CLASS && class1 == X86_64_SSESF_CLASS))
  10900. return X86_64_INTEGERSI_CLASS;
  10901. if (class1 == X86_64_INTEGER_CLASS || class1 == X86_64_INTEGERSI_CLASS
  10902. || class2 == X86_64_INTEGER_CLASS || class2 == X86_64_INTEGERSI_CLASS)
  10903. return X86_64_INTEGER_CLASS;
  10904. /* Rule #5: If one of the classes is X87, X87UP, or COMPLEX_X87 class,
  10905. MEMORY is used. */
  10906. if (class1 == X86_64_X87_CLASS
  10907. || class1 == X86_64_X87UP_CLASS
  10908. || class1 == X86_64_COMPLEX_X87_CLASS
  10909. || class2 == X86_64_X87_CLASS
  10910. || class2 == X86_64_X87UP_CLASS
  10911. || class2 == X86_64_COMPLEX_X87_CLASS)
  10912. return X86_64_MEMORY_CLASS;
  10913. /* Rule #6: Otherwise class SSE is used. */
  10914. return X86_64_SSE_CLASS;
  10915. }
  10916. /* Classify the argument of type TYPE and mode MODE.
  10917. CLASSES will be filled by the register class used to pass each word
  10918. of the operand. The number of words is returned. In case the parameter
  10919. should be passed in memory, 0 is returned. As a special case for zero
  10920. sized containers, classes[0] will be NO_CLASS and 1 is returned.
  10921. See the x86-64 PS ABI for details.
  10922. */
  10923. static size_t
  10924. classify_argument (ffi_type *type, enum x86_64_reg_class classes[],
  10925. size_t byte_offset)
  10926. {
  10927. switch (type->type)
  10928. {
  10929. case FFI_TYPE_UINT8:
  10930. case FFI_TYPE_SINT8:
  10931. case FFI_TYPE_UINT16:
  10932. case FFI_TYPE_SINT16:
  10933. case FFI_TYPE_UINT32:
  10934. case FFI_TYPE_SINT32:
  10935. case FFI_TYPE_UINT64:
  10936. case FFI_TYPE_SINT64:
  10937. case FFI_TYPE_POINTER:
  10938. do_integer:
  10939. {
  10940. size_t size = byte_offset + type->size;
  10941. if (size <= 4)
  10942. {
  10943. classes[0] = X86_64_INTEGERSI_CLASS;
  10944. return 1;
  10945. }
  10946. else if (size <= 8)
  10947. {
  10948. classes[0] = X86_64_INTEGER_CLASS;
  10949. return 1;
  10950. }
  10951. else if (size <= 12)
  10952. {
  10953. classes[0] = X86_64_INTEGER_CLASS;
  10954. classes[1] = X86_64_INTEGERSI_CLASS;
  10955. return 2;
  10956. }
  10957. else if (size <= 16)
  10958. {
  10959. classes[0] = classes[1] = X86_64_INTEGER_CLASS;
  10960. return 2;
  10961. }
  10962. else
  10963. FFI_ASSERT (0);
  10964. }
  10965. case FFI_TYPE_FLOAT:
  10966. if (!(byte_offset % 8))
  10967. classes[0] = X86_64_SSESF_CLASS;
  10968. else
  10969. classes[0] = X86_64_SSE_CLASS;
  10970. return 1;
  10971. case FFI_TYPE_DOUBLE:
  10972. classes[0] = X86_64_SSEDF_CLASS;
  10973. return 1;
  10974. #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
  10975. case FFI_TYPE_LONGDOUBLE:
  10976. classes[0] = X86_64_X87_CLASS;
  10977. classes[1] = X86_64_X87UP_CLASS;
  10978. return 2;
  10979. #endif
  10980. case FFI_TYPE_STRUCT:
  10981. {
  10982. const size_t UNITS_PER_WORD = 8;
  10983. size_t words = (type->size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
  10984. ffi_type **ptr;
  10985. unsigned int i;
  10986. enum x86_64_reg_class subclasses[MAX_CLASSES];
  10987. /* If the struct is larger than 32 bytes, pass it on the stack. */
  10988. if (type->size > 32)
  10989. return 0;
  10990. for (i = 0; i < words; i++)
  10991. classes[i] = X86_64_NO_CLASS;
  10992. /* Zero sized arrays or structures are NO_CLASS. We return 0 to
  10993. signalize memory class, so handle it as special case. */
  10994. if (!words)
  10995. {
  10996. case FFI_TYPE_VOID:
  10997. classes[0] = X86_64_NO_CLASS;
  10998. return 1;
  10999. }
  11000. /* Merge the fields of structure. */
  11001. for (ptr = type->elements; *ptr != NULL; ptr++)
  11002. {
  11003. size_t num;
  11004. byte_offset = FFI_ALIGN (byte_offset, (*ptr)->alignment);
  11005. num = classify_argument (*ptr, subclasses, byte_offset % 8);
  11006. if (num == 0)
  11007. return 0;
  11008. for (i = 0; i < num; i++)
  11009. {
  11010. size_t pos = byte_offset / 8;
  11011. classes[i + pos] =
  11012. merge_classes (subclasses[i], classes[i + pos]);
  11013. }
  11014. byte_offset += (*ptr)->size;
  11015. }
  11016. if (words > 2)
  11017. {
  11018. /* When size > 16 bytes, if the first one isn't
  11019. X86_64_SSE_CLASS or any other ones aren't
  11020. X86_64_SSEUP_CLASS, everything should be passed in
  11021. memory. */
  11022. if (classes[0] != X86_64_SSE_CLASS)
  11023. return 0;
  11024. for (i = 1; i < words; i++)
  11025. if (classes[i] != X86_64_SSEUP_CLASS)
  11026. return 0;
  11027. }
  11028. /* Final merger cleanup. */
  11029. for (i = 0; i < words; i++)
  11030. {
  11031. /* If one class is MEMORY, everything should be passed in
  11032. memory. */
  11033. if (classes[i] == X86_64_MEMORY_CLASS)
  11034. return 0;
  11035. /* The X86_64_SSEUP_CLASS should be always preceded by
  11036. X86_64_SSE_CLASS or X86_64_SSEUP_CLASS. */
  11037. if (i > 1 && classes[i] == X86_64_SSEUP_CLASS
  11038. && classes[i - 1] != X86_64_SSE_CLASS
  11039. && classes[i - 1] != X86_64_SSEUP_CLASS)
  11040. {
  11041. /* The first one should never be X86_64_SSEUP_CLASS. */
  11042. FFI_ASSERT (i != 0);
  11043. classes[i] = X86_64_SSE_CLASS;
  11044. }
  11045. /* If X86_64_X87UP_CLASS isn't preceded by X86_64_X87_CLASS,
  11046. everything should be passed in memory. */
  11047. if (i > 1 && classes[i] == X86_64_X87UP_CLASS
  11048. && (classes[i - 1] != X86_64_X87_CLASS))
  11049. {
  11050. /* The first one should never be X86_64_X87UP_CLASS. */
  11051. FFI_ASSERT (i != 0);
  11052. return 0;
  11053. }
  11054. }
  11055. return words;
  11056. }
  11057. case FFI_TYPE_COMPLEX:
  11058. {
  11059. ffi_type *inner = type->elements[0];
  11060. switch (inner->type)
  11061. {
  11062. case FFI_TYPE_INT:
  11063. case FFI_TYPE_UINT8:
  11064. case FFI_TYPE_SINT8:
  11065. case FFI_TYPE_UINT16:
  11066. case FFI_TYPE_SINT16:
  11067. case FFI_TYPE_UINT32:
  11068. case FFI_TYPE_SINT32:
  11069. case FFI_TYPE_UINT64:
  11070. case FFI_TYPE_SINT64:
  11071. goto do_integer;
  11072. case FFI_TYPE_FLOAT:
  11073. classes[0] = X86_64_SSE_CLASS;
  11074. if (byte_offset % 8)
  11075. {
  11076. classes[1] = X86_64_SSESF_CLASS;
  11077. return 2;
  11078. }
  11079. return 1;
  11080. case FFI_TYPE_DOUBLE:
  11081. classes[0] = classes[1] = X86_64_SSEDF_CLASS;
  11082. return 2;
  11083. #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
  11084. case FFI_TYPE_LONGDOUBLE:
  11085. classes[0] = X86_64_COMPLEX_X87_CLASS;
  11086. return 1;
  11087. #endif
  11088. }
  11089. }
  11090. }
  11091. abort();
  11092. }
  11093. /* Examine the argument and return set number of register required in each
  11094. class. Return zero iff parameter should be passed in memory, otherwise
  11095. the number of registers. */
  11096. static size_t
  11097. examine_argument (ffi_type *type, enum x86_64_reg_class classes[MAX_CLASSES],
  11098. _Bool in_return, int *pngpr, int *pnsse)
  11099. {
  11100. size_t n;
  11101. unsigned int i;
  11102. int ngpr, nsse;
  11103. n = classify_argument (type, classes, 0);
  11104. if (n == 0)
  11105. return 0;
  11106. ngpr = nsse = 0;
  11107. for (i = 0; i < n; ++i)
  11108. switch (classes[i])
  11109. {
  11110. case X86_64_INTEGER_CLASS:
  11111. case X86_64_INTEGERSI_CLASS:
  11112. ngpr++;
  11113. break;
  11114. case X86_64_SSE_CLASS:
  11115. case X86_64_SSESF_CLASS:
  11116. case X86_64_SSEDF_CLASS:
  11117. nsse++;
  11118. break;
  11119. case X86_64_NO_CLASS:
  11120. case X86_64_SSEUP_CLASS:
  11121. break;
  11122. case X86_64_X87_CLASS:
  11123. case X86_64_X87UP_CLASS:
  11124. case X86_64_COMPLEX_X87_CLASS:
  11125. return in_return != 0;
  11126. default:
  11127. abort ();
  11128. }
  11129. *pngpr = ngpr;
  11130. *pnsse = nsse;
  11131. return n;
  11132. }
  11133. /* Perform machine dependent cif processing. */
  11134. #ifndef __ILP32__
  11135. extern ffi_status
  11136. ffi_prep_cif_machdep_efi64(ffi_cif *cif);
  11137. #endif
  11138. ffi_status FFI_HIDDEN
  11139. ffi_prep_cif_machdep (ffi_cif *cif)
  11140. {
  11141. int gprcount, ssecount, i, avn, ngpr, nsse;
  11142. unsigned flags;
  11143. enum x86_64_reg_class classes[MAX_CLASSES];
  11144. size_t bytes, n, rtype_size;
  11145. ffi_type *rtype;
  11146. #ifndef __ILP32__
  11147. if (cif->abi == FFI_EFI64 || cif->abi == FFI_GNUW64)
  11148. return ffi_prep_cif_machdep_efi64(cif);
  11149. #endif
  11150. if (cif->abi != FFI_UNIX64)
  11151. return FFI_BAD_ABI;
  11152. gprcount = ssecount = 0;
  11153. rtype = cif->rtype;
  11154. rtype_size = rtype->size;
  11155. switch (rtype->type)
  11156. {
  11157. case FFI_TYPE_VOID:
  11158. flags = UNIX64_RET_VOID;
  11159. break;
  11160. case FFI_TYPE_UINT8:
  11161. flags = UNIX64_RET_UINT8;
  11162. break;
  11163. case FFI_TYPE_SINT8:
  11164. flags = UNIX64_RET_SINT8;
  11165. break;
  11166. case FFI_TYPE_UINT16:
  11167. flags = UNIX64_RET_UINT16;
  11168. break;
  11169. case FFI_TYPE_SINT16:
  11170. flags = UNIX64_RET_SINT16;
  11171. break;
  11172. case FFI_TYPE_UINT32:
  11173. flags = UNIX64_RET_UINT32;
  11174. break;
  11175. case FFI_TYPE_INT:
  11176. case FFI_TYPE_SINT32:
  11177. flags = UNIX64_RET_SINT32;
  11178. break;
  11179. case FFI_TYPE_UINT64:
  11180. case FFI_TYPE_SINT64:
  11181. flags = UNIX64_RET_INT64;
  11182. break;
  11183. case FFI_TYPE_POINTER:
  11184. flags = (sizeof(void *) == 4 ? UNIX64_RET_UINT32 : UNIX64_RET_INT64);
  11185. break;
  11186. case FFI_TYPE_FLOAT:
  11187. flags = UNIX64_RET_XMM32;
  11188. break;
  11189. case FFI_TYPE_DOUBLE:
  11190. flags = UNIX64_RET_XMM64;
  11191. break;
  11192. #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
  11193. case FFI_TYPE_LONGDOUBLE:
  11194. flags = UNIX64_RET_X87;
  11195. break;
  11196. #endif
  11197. case FFI_TYPE_STRUCT:
  11198. n = examine_argument (cif->rtype, classes, 1, &ngpr, &nsse);
  11199. if (n == 0)
  11200. {
  11201. /* The return value is passed in memory. A pointer to that
  11202. memory is the first argument. Allocate a register for it. */
  11203. gprcount++;
  11204. /* We don't have to do anything in asm for the return. */
  11205. flags = UNIX64_RET_VOID | UNIX64_FLAG_RET_IN_MEM;
  11206. }
  11207. else
  11208. {
  11209. _Bool sse0 = SSE_CLASS_P (classes[0]);
  11210. if (rtype_size == 4 && sse0)
  11211. flags = UNIX64_RET_XMM32;
  11212. else if (rtype_size == 8)
  11213. flags = sse0 ? UNIX64_RET_XMM64 : UNIX64_RET_INT64;
  11214. else
  11215. {
  11216. _Bool sse1 = n == 2 && SSE_CLASS_P (classes[1]);
  11217. if (sse0 && sse1)
  11218. flags = UNIX64_RET_ST_XMM0_XMM1;
  11219. else if (sse0)
  11220. flags = UNIX64_RET_ST_XMM0_RAX;
  11221. else if (sse1)
  11222. flags = UNIX64_RET_ST_RAX_XMM0;
  11223. else
  11224. flags = UNIX64_RET_ST_RAX_RDX;
  11225. flags |= rtype_size << UNIX64_SIZE_SHIFT;
  11226. }
  11227. }
  11228. break;
  11229. case FFI_TYPE_COMPLEX:
  11230. switch (rtype->elements[0]->type)
  11231. {
  11232. case FFI_TYPE_UINT8:
  11233. case FFI_TYPE_SINT8:
  11234. case FFI_TYPE_UINT16:
  11235. case FFI_TYPE_SINT16:
  11236. case FFI_TYPE_INT:
  11237. case FFI_TYPE_UINT32:
  11238. case FFI_TYPE_SINT32:
  11239. case FFI_TYPE_UINT64:
  11240. case FFI_TYPE_SINT64:
  11241. flags = UNIX64_RET_ST_RAX_RDX | ((unsigned) rtype_size << UNIX64_SIZE_SHIFT);
  11242. break;
  11243. case FFI_TYPE_FLOAT:
  11244. flags = UNIX64_RET_XMM64;
  11245. break;
  11246. case FFI_TYPE_DOUBLE:
  11247. flags = UNIX64_RET_ST_XMM0_XMM1 | (16 << UNIX64_SIZE_SHIFT);
  11248. break;
  11249. #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
  11250. case FFI_TYPE_LONGDOUBLE:
  11251. flags = UNIX64_RET_X87_2;
  11252. break;
  11253. #endif
  11254. default:
  11255. return FFI_BAD_TYPEDEF;
  11256. }
  11257. break;
  11258. default:
  11259. return FFI_BAD_TYPEDEF;
  11260. }
  11261. /* Go over all arguments and determine the way they should be passed.
  11262. If it's in a register and there is space for it, let that be so. If
  11263. not, add it's size to the stack byte count. */
  11264. for (bytes = 0, i = 0, avn = cif->nargs; i < avn; i++)
  11265. {
  11266. if (examine_argument (cif->arg_types[i], classes, 0, &ngpr, &nsse) == 0
  11267. || gprcount + ngpr > MAX_GPR_REGS
  11268. || ssecount + nsse > MAX_SSE_REGS)
  11269. {
  11270. long align = cif->arg_types[i]->alignment;
  11271. if (align < 8)
  11272. align = 8;
  11273. bytes = FFI_ALIGN (bytes, align);
  11274. bytes += cif->arg_types[i]->size;
  11275. }
  11276. else
  11277. {
  11278. gprcount += ngpr;
  11279. ssecount += nsse;
  11280. }
  11281. }
  11282. if (ssecount)
  11283. flags |= UNIX64_FLAG_XMM_ARGS;
  11284. cif->flags = flags;
  11285. cif->bytes = (unsigned) FFI_ALIGN (bytes, 8);
  11286. return FFI_OK;
  11287. }
  11288. static void
  11289. ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue,
  11290. void **avalue, void *closure)
  11291. {
  11292. enum x86_64_reg_class classes[MAX_CLASSES];
  11293. char *stack, *argp;
  11294. ffi_type **arg_types;
  11295. int gprcount, ssecount, ngpr, nsse, i, avn, flags;
  11296. struct register_args *reg_args;
  11297. /* Can't call 32-bit mode from 64-bit mode. */
  11298. FFI_ASSERT (cif->abi == FFI_UNIX64);
  11299. /* If the return value is a struct and we don't have a return value
  11300. address then we need to make one. Otherwise we can ignore it. */
  11301. flags = cif->flags;
  11302. if (rvalue == NULL)
  11303. {
  11304. if (flags & UNIX64_FLAG_RET_IN_MEM)
  11305. rvalue = alloca (cif->rtype->size);
  11306. else
  11307. flags = UNIX64_RET_VOID;
  11308. }
  11309. /* Allocate the space for the arguments, plus 4 words of temp space. */
  11310. stack = alloca (sizeof (struct register_args) + cif->bytes + 4*8);
  11311. reg_args = (struct register_args *) stack;
  11312. argp = stack + sizeof (struct register_args);
  11313. reg_args->r10 = (uintptr_t) closure;
  11314. gprcount = ssecount = 0;
  11315. /* If the return value is passed in memory, add the pointer as the
  11316. first integer argument. */
  11317. if (flags & UNIX64_FLAG_RET_IN_MEM)
  11318. reg_args->gpr[gprcount++] = (unsigned long) rvalue;
  11319. avn = cif->nargs;
  11320. arg_types = cif->arg_types;
  11321. for (i = 0; i < avn; ++i)
  11322. {
  11323. size_t n, size = arg_types[i]->size;
  11324. n = examine_argument (arg_types[i], classes, 0, &ngpr, &nsse);
  11325. if (n == 0
  11326. || gprcount + ngpr > MAX_GPR_REGS
  11327. || ssecount + nsse > MAX_SSE_REGS)
  11328. {
  11329. long align = arg_types[i]->alignment;
  11330. /* Stack arguments are *always* at least 8 byte aligned. */
  11331. if (align < 8)
  11332. align = 8;
  11333. /* Pass this argument in memory. */
  11334. argp = (void *) FFI_ALIGN (argp, align);
  11335. memcpy (argp, avalue[i], size);
  11336. argp += size;
  11337. }
  11338. else
  11339. {
  11340. /* The argument is passed entirely in registers. */
  11341. char *a = (char *) avalue[i];
  11342. unsigned int j;
  11343. for (j = 0; j < n; j++, a += 8, size -= 8)
  11344. {
  11345. switch (classes[j])
  11346. {
  11347. case X86_64_NO_CLASS:
  11348. case X86_64_SSEUP_CLASS:
  11349. break;
  11350. case X86_64_INTEGER_CLASS:
  11351. case X86_64_INTEGERSI_CLASS:
  11352. /* Sign-extend integer arguments passed in general
  11353. purpose registers, to cope with the fact that
  11354. LLVM incorrectly assumes that this will be done
  11355. (the x86-64 PS ABI does not specify this). */
  11356. switch (arg_types[i]->type)
  11357. {
  11358. case FFI_TYPE_SINT8:
  11359. reg_args->gpr[gprcount] = (SINT64) *((SINT8 *) a);
  11360. break;
  11361. case FFI_TYPE_SINT16:
  11362. reg_args->gpr[gprcount] = (SINT64) *((SINT16 *) a);
  11363. break;
  11364. case FFI_TYPE_SINT32:
  11365. reg_args->gpr[gprcount] = (SINT64) *((SINT32 *) a);
  11366. break;
  11367. default:
  11368. reg_args->gpr[gprcount] = 0;
  11369. memcpy (&reg_args->gpr[gprcount], a, size);
  11370. }
  11371. gprcount++;
  11372. break;
  11373. case X86_64_SSE_CLASS:
  11374. case X86_64_SSEDF_CLASS:
  11375. memcpy (&reg_args->sse[ssecount++].i64, a, sizeof(UINT64));
  11376. break;
  11377. case X86_64_SSESF_CLASS:
  11378. memcpy (&reg_args->sse[ssecount++].i32, a, sizeof(UINT32));
  11379. break;
  11380. default:
  11381. abort();
  11382. }
  11383. }
  11384. }
  11385. }
  11386. reg_args->rax = ssecount;
  11387. ffi_call_unix64 (stack, cif->bytes + sizeof (struct register_args),
  11388. flags, rvalue, fn);
  11389. }
  11390. #ifndef __ILP32__
  11391. extern void
  11392. ffi_call_efi64(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue);
  11393. #endif
  11394. void
  11395. ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
  11396. {
  11397. #ifndef __ILP32__
  11398. if (cif->abi == FFI_EFI64 || cif->abi == FFI_GNUW64)
  11399. {
  11400. ffi_call_efi64(cif, fn, rvalue, avalue);
  11401. return;
  11402. }
  11403. #endif
  11404. ffi_call_int (cif, fn, rvalue, avalue, NULL);
  11405. }
  11406. #ifndef __ILP32__
  11407. extern void
  11408. ffi_call_go_efi64(ffi_cif *cif, void (*fn)(void), void *rvalue,
  11409. void **avalue, void *closure);
  11410. #endif
  11411. void
  11412. ffi_call_go (ffi_cif *cif, void (*fn)(void), void *rvalue,
  11413. void **avalue, void *closure)
  11414. {
  11415. #ifndef __ILP32__
  11416. if (cif->abi == FFI_EFI64 || cif->abi == FFI_GNUW64)
  11417. {
  11418. ffi_call_go_efi64(cif, fn, rvalue, avalue, closure);
  11419. return;
  11420. }
  11421. #endif
  11422. ffi_call_int (cif, fn, rvalue, avalue, closure);
  11423. }
  11424. extern void ffi_closure_unix64(void) FFI_HIDDEN;
  11425. extern void ffi_closure_unix64_sse(void) FFI_HIDDEN;
  11426. #ifndef __ILP32__
  11427. extern ffi_status
  11428. ffi_prep_closure_loc_efi64(ffi_closure* closure,
  11429. ffi_cif* cif,
  11430. void (*fun)(ffi_cif*, void*, void**, void*),
  11431. void *user_data,
  11432. void *codeloc);
  11433. #endif
  11434. ffi_status
  11435. ffi_prep_closure_loc (ffi_closure* closure,
  11436. ffi_cif* cif,
  11437. void (*fun)(ffi_cif*, void*, void**, void*),
  11438. void *user_data,
  11439. void *codeloc)
  11440. {
  11441. static const unsigned char trampoline[16] = {
  11442. /* leaq -0x7(%rip),%r10 # 0x0 */
  11443. 0x4c, 0x8d, 0x15, 0xf9, 0xff, 0xff, 0xff,
  11444. /* jmpq *0x3(%rip) # 0x10 */
  11445. 0xff, 0x25, 0x03, 0x00, 0x00, 0x00,
  11446. /* nopl (%rax) */
  11447. 0x0f, 0x1f, 0x00
  11448. };
  11449. void (*dest)(void);
  11450. char *tramp = closure->tramp;
  11451. #ifndef __ILP32__
  11452. if (cif->abi == FFI_EFI64 || cif->abi == FFI_GNUW64)
  11453. return ffi_prep_closure_loc_efi64(closure, cif, fun, user_data, codeloc);
  11454. #endif
  11455. if (cif->abi != FFI_UNIX64)
  11456. return FFI_BAD_ABI;
  11457. if (cif->flags & UNIX64_FLAG_XMM_ARGS)
  11458. dest = ffi_closure_unix64_sse;
  11459. else
  11460. dest = ffi_closure_unix64;
  11461. memcpy (tramp, trampoline, sizeof(trampoline));
  11462. *(UINT64 *)(tramp + 16) = (uintptr_t)dest;
  11463. closure->cif = cif;
  11464. closure->fun = fun;
  11465. closure->user_data = user_data;
  11466. return FFI_OK;
  11467. }
  11468. int FFI_HIDDEN
  11469. ffi_closure_unix64_inner(ffi_cif *cif,
  11470. void (*fun)(ffi_cif*, void*, void**, void*),
  11471. void *user_data,
  11472. void *rvalue,
  11473. struct register_args *reg_args,
  11474. char *argp)
  11475. {
  11476. void **avalue;
  11477. ffi_type **arg_types;
  11478. long i, avn;
  11479. int gprcount, ssecount, ngpr, nsse;
  11480. int flags;
  11481. avn = cif->nargs;
  11482. flags = cif->flags;
  11483. avalue = alloca(avn * sizeof(void *));
  11484. gprcount = ssecount = 0;
  11485. if (flags & UNIX64_FLAG_RET_IN_MEM)
  11486. {
  11487. /* On return, %rax will contain the address that was passed
  11488. by the caller in %rdi. */
  11489. void *r = (void *)(uintptr_t)reg_args->gpr[gprcount++];
  11490. *(void **)rvalue = r;
  11491. rvalue = r;
  11492. flags = (sizeof(void *) == 4 ? UNIX64_RET_UINT32 : UNIX64_RET_INT64);
  11493. }
  11494. arg_types = cif->arg_types;
  11495. for (i = 0; i < avn; ++i)
  11496. {
  11497. enum x86_64_reg_class classes[MAX_CLASSES];
  11498. size_t n;
  11499. n = examine_argument (arg_types[i], classes, 0, &ngpr, &nsse);
  11500. if (n == 0
  11501. || gprcount + ngpr > MAX_GPR_REGS
  11502. || ssecount + nsse > MAX_SSE_REGS)
  11503. {
  11504. long align = arg_types[i]->alignment;
  11505. /* Stack arguments are *always* at least 8 byte aligned. */
  11506. if (align < 8)
  11507. align = 8;
  11508. /* Pass this argument in memory. */
  11509. argp = (void *) FFI_ALIGN (argp, align);
  11510. avalue[i] = argp;
  11511. argp += arg_types[i]->size;
  11512. }
  11513. /* If the argument is in a single register, or two consecutive
  11514. integer registers, then we can use that address directly. */
  11515. else if (n == 1
  11516. || (n == 2 && !(SSE_CLASS_P (classes[0])
  11517. || SSE_CLASS_P (classes[1]))))
  11518. {
  11519. /* The argument is in a single register. */
  11520. if (SSE_CLASS_P (classes[0]))
  11521. {
  11522. avalue[i] = &reg_args->sse[ssecount];
  11523. ssecount += n;
  11524. }
  11525. else
  11526. {
  11527. avalue[i] = &reg_args->gpr[gprcount];
  11528. gprcount += n;
  11529. }
  11530. }
  11531. /* Otherwise, allocate space to make them consecutive. */
  11532. else
  11533. {
  11534. char *a = alloca (16);
  11535. unsigned int j;
  11536. avalue[i] = a;
  11537. for (j = 0; j < n; j++, a += 8)
  11538. {
  11539. if (SSE_CLASS_P (classes[j]))
  11540. memcpy (a, &reg_args->sse[ssecount++], 8);
  11541. else
  11542. memcpy (a, &reg_args->gpr[gprcount++], 8);
  11543. }
  11544. }
  11545. }
  11546. /* Invoke the closure. */
  11547. fun (cif, rvalue, avalue, user_data);
  11548. /* Tell assembly how to perform return type promotions. */
  11549. return flags;
  11550. }
  11551. extern void ffi_go_closure_unix64(void) FFI_HIDDEN;
  11552. extern void ffi_go_closure_unix64_sse(void) FFI_HIDDEN;
  11553. #ifndef __ILP32__
  11554. extern ffi_status
  11555. ffi_prep_go_closure_efi64(ffi_go_closure* closure, ffi_cif* cif,
  11556. void (*fun)(ffi_cif*, void*, void**, void*));
  11557. #endif
  11558. ffi_status
  11559. ffi_prep_go_closure (ffi_go_closure* closure, ffi_cif* cif,
  11560. void (*fun)(ffi_cif*, void*, void**, void*))
  11561. {
  11562. #ifndef __ILP32__
  11563. if (cif->abi == FFI_EFI64 || cif->abi == FFI_GNUW64)
  11564. return ffi_prep_go_closure_efi64(closure, cif, fun);
  11565. #endif
  11566. if (cif->abi != FFI_UNIX64)
  11567. return FFI_BAD_ABI;
  11568. closure->tramp = (cif->flags & UNIX64_FLAG_XMM_ARGS
  11569. ? ffi_go_closure_unix64_sse
  11570. : ffi_go_closure_unix64);
  11571. closure->cif = cif;
  11572. closure->fun = fun;
  11573. return FFI_OK;
  11574. }
  11575. #endif /* __x86_64__ */
  11576. ====================File: src/x86/ffitarget.h====================
  11577. /* -----------------------------------------------------------------*-C-*-
  11578. ffitarget.h - Copyright (c) 2012, 2014, 2018 Anthony Green
  11579. Copyright (c) 1996-2003, 2010 Red Hat, Inc.
  11580. Copyright (C) 2008 Free Software Foundation, Inc.
  11581. Target configuration macros for x86 and x86-64.
  11582. Permission is hereby granted, free of charge, to any person obtaining
  11583. a copy of this software and associated documentation files (the
  11584. ``Software''), to deal in the Software without restriction, including
  11585. without limitation the rights to use, copy, modify, merge, publish,
  11586. distribute, sublicense, and/or sell copies of the Software, and to
  11587. permit persons to whom the Software is furnished to do so, subject to
  11588. the following conditions:
  11589. The above copyright notice and this permission notice shall be included
  11590. in all copies or substantial portions of the Software.
  11591. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  11592. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  11593. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  11594. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  11595. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  11596. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  11597. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  11598. DEALINGS IN THE SOFTWARE.
  11599. ----------------------------------------------------------------------- */
  11600. #ifndef LIBFFI_TARGET_H
  11601. #define LIBFFI_TARGET_H
  11602. #ifndef LIBFFI_H
  11603. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  11604. #endif
  11605. /* ---- System specific configurations ----------------------------------- */
  11606. /* For code common to all platforms on x86 and x86_64. */
  11607. #define X86_ANY
  11608. #if defined (X86_64) && defined (__i386__)
  11609. #undef X86_64
  11610. #define X86
  11611. #endif
  11612. #ifdef X86_WIN64
  11613. #define FFI_SIZEOF_ARG 8
  11614. #define USE_BUILTIN_FFS 0 /* not yet implemented in mingw-64 */
  11615. #endif
  11616. #define FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION
  11617. #ifndef _MSC_VER
  11618. #define FFI_TARGET_HAS_COMPLEX_TYPE
  11619. #endif
  11620. /* ---- Generic type definitions ----------------------------------------- */
  11621. #ifndef LIBFFI_ASM
  11622. #ifdef X86_WIN64
  11623. #ifdef _MSC_VER
  11624. typedef unsigned __int64 ffi_arg;
  11625. typedef __int64 ffi_sarg;
  11626. #else
  11627. typedef unsigned long long ffi_arg;
  11628. typedef long long ffi_sarg;
  11629. #endif
  11630. #else
  11631. #if defined __x86_64__ && defined __ILP32__
  11632. #define FFI_SIZEOF_ARG 8
  11633. #define FFI_SIZEOF_JAVA_RAW 4
  11634. typedef unsigned long long ffi_arg;
  11635. typedef long long ffi_sarg;
  11636. #else
  11637. typedef unsigned long ffi_arg;
  11638. typedef signed long ffi_sarg;
  11639. #endif
  11640. #endif
  11641. typedef enum ffi_abi {
  11642. #if defined(X86_WIN64)
  11643. FFI_FIRST_ABI = 0,
  11644. FFI_WIN64, /* sizeof(long double) == 8 - microsoft compilers */
  11645. FFI_GNUW64, /* sizeof(long double) == 16 - GNU compilers */
  11646. FFI_LAST_ABI,
  11647. #ifdef __GNUC__
  11648. FFI_DEFAULT_ABI = FFI_GNUW64
  11649. #else
  11650. FFI_DEFAULT_ABI = FFI_WIN64
  11651. #endif
  11652. #elif defined(X86_64) || (defined (__x86_64__) && defined (X86_DARWIN))
  11653. FFI_FIRST_ABI = 1,
  11654. FFI_UNIX64,
  11655. FFI_WIN64,
  11656. FFI_EFI64 = FFI_WIN64,
  11657. FFI_GNUW64,
  11658. FFI_LAST_ABI,
  11659. FFI_DEFAULT_ABI = FFI_UNIX64
  11660. #elif defined(X86_WIN32)
  11661. FFI_FIRST_ABI = 0,
  11662. FFI_SYSV = 1,
  11663. FFI_STDCALL = 2,
  11664. FFI_THISCALL = 3,
  11665. FFI_FASTCALL = 4,
  11666. FFI_MS_CDECL = 5,
  11667. FFI_PASCAL = 6,
  11668. FFI_REGISTER = 7,
  11669. FFI_LAST_ABI,
  11670. FFI_DEFAULT_ABI = FFI_MS_CDECL
  11671. #else
  11672. FFI_FIRST_ABI = 0,
  11673. FFI_SYSV = 1,
  11674. FFI_THISCALL = 3,
  11675. FFI_FASTCALL = 4,
  11676. FFI_STDCALL = 5,
  11677. FFI_PASCAL = 6,
  11678. FFI_REGISTER = 7,
  11679. FFI_MS_CDECL = 8,
  11680. FFI_LAST_ABI,
  11681. FFI_DEFAULT_ABI = FFI_SYSV
  11682. #endif
  11683. } ffi_abi;
  11684. #endif
  11685. /* ---- Definitions for closures ----------------------------------------- */
  11686. #define FFI_CLOSURES 1
  11687. #define FFI_GO_CLOSURES 1
  11688. #define FFI_TYPE_SMALL_STRUCT_1B (FFI_TYPE_LAST + 1)
  11689. #define FFI_TYPE_SMALL_STRUCT_2B (FFI_TYPE_LAST + 2)
  11690. #define FFI_TYPE_SMALL_STRUCT_4B (FFI_TYPE_LAST + 3)
  11691. #define FFI_TYPE_MS_STRUCT (FFI_TYPE_LAST + 4)
  11692. #if defined (X86_64) || defined(X86_WIN64) \
  11693. || (defined (__x86_64__) && defined (X86_DARWIN))
  11694. # define FFI_TRAMPOLINE_SIZE 24
  11695. # define FFI_NATIVE_RAW_API 0
  11696. #else
  11697. # define FFI_TRAMPOLINE_SIZE 12
  11698. # define FFI_NATIVE_RAW_API 1 /* x86 has native raw api support */
  11699. #endif
  11700. #endif
  11701. ====================File: src/x86/ffiw64.c====================
  11702. /* -----------------------------------------------------------------------
  11703. ffiw64.c - Copyright (c) 2018 Anthony Green
  11704. Copyright (c) 2014 Red Hat, Inc.
  11705. x86 win64 Foreign Function Interface
  11706. Permission is hereby granted, free of charge, to any person obtaining
  11707. a copy of this software and associated documentation files (the
  11708. ``Software''), to deal in the Software without restriction, including
  11709. without limitation the rights to use, copy, modify, merge, publish,
  11710. distribute, sublicense, and/or sell copies of the Software, and to
  11711. permit persons to whom the Software is furnished to do so, subject to
  11712. the following conditions:
  11713. The above copyright notice and this permission notice shall be included
  11714. in all copies or substantial portions of the Software.
  11715. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  11716. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  11717. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  11718. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  11719. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  11720. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  11721. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  11722. DEALINGS IN THE SOFTWARE.
  11723. ----------------------------------------------------------------------- */
  11724. #if defined(__x86_64__) || defined(_M_AMD64)
  11725. #include <ffi.h>
  11726. #include <ffi_common.h>
  11727. #include <stdlib.h>
  11728. #include <stdint.h>
  11729. #ifdef X86_WIN64
  11730. #define EFI64(name) name
  11731. #else
  11732. #define EFI64(name) FFI_HIDDEN name##_efi64
  11733. #endif
  11734. struct win64_call_frame
  11735. {
  11736. UINT64 rbp; /* 0 */
  11737. UINT64 retaddr; /* 8 */
  11738. UINT64 fn; /* 16 */
  11739. UINT64 flags; /* 24 */
  11740. UINT64 rvalue; /* 32 */
  11741. };
  11742. extern void ffi_call_win64 (void *stack, struct win64_call_frame *,
  11743. void *closure) FFI_HIDDEN;
  11744. ffi_status FFI_HIDDEN
  11745. EFI64(ffi_prep_cif_machdep)(ffi_cif *cif)
  11746. {
  11747. int flags, n;
  11748. switch (cif->abi)
  11749. {
  11750. case FFI_WIN64:
  11751. case FFI_GNUW64:
  11752. break;
  11753. default:
  11754. return FFI_BAD_ABI;
  11755. }
  11756. flags = cif->rtype->type;
  11757. switch (flags)
  11758. {
  11759. default:
  11760. break;
  11761. case FFI_TYPE_LONGDOUBLE:
  11762. /* GCC returns long double values by reference, like a struct */
  11763. if (cif->abi == FFI_GNUW64)
  11764. flags = FFI_TYPE_STRUCT;
  11765. break;
  11766. case FFI_TYPE_COMPLEX:
  11767. flags = FFI_TYPE_STRUCT;
  11768. /* FALLTHRU */
  11769. case FFI_TYPE_STRUCT:
  11770. switch (cif->rtype->size)
  11771. {
  11772. case 8:
  11773. flags = FFI_TYPE_UINT64;
  11774. break;
  11775. case 4:
  11776. flags = FFI_TYPE_SMALL_STRUCT_4B;
  11777. break;
  11778. case 2:
  11779. flags = FFI_TYPE_SMALL_STRUCT_2B;
  11780. break;
  11781. case 1:
  11782. flags = FFI_TYPE_SMALL_STRUCT_1B;
  11783. break;
  11784. }
  11785. break;
  11786. }
  11787. cif->flags = flags;
  11788. /* Each argument either fits in a register, an 8 byte slot, or is
  11789. passed by reference with the pointer in the 8 byte slot. */
  11790. n = cif->nargs;
  11791. n += (flags == FFI_TYPE_STRUCT);
  11792. if (n < 4)
  11793. n = 4;
  11794. cif->bytes = n * 8;
  11795. return FFI_OK;
  11796. }
  11797. static void
  11798. ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue,
  11799. void **avalue, void *closure)
  11800. {
  11801. int i, j, n, flags;
  11802. UINT64 *stack;
  11803. size_t rsize;
  11804. struct win64_call_frame *frame;
  11805. FFI_ASSERT(cif->abi == FFI_GNUW64 || cif->abi == FFI_WIN64);
  11806. flags = cif->flags;
  11807. rsize = 0;
  11808. /* If we have no return value for a structure, we need to create one.
  11809. Otherwise we can ignore the return type entirely. */
  11810. if (rvalue == NULL)
  11811. {
  11812. if (flags == FFI_TYPE_STRUCT)
  11813. rsize = cif->rtype->size;
  11814. else
  11815. flags = FFI_TYPE_VOID;
  11816. }
  11817. stack = alloca(cif->bytes + sizeof(struct win64_call_frame) + rsize);
  11818. frame = (struct win64_call_frame *)((char *)stack + cif->bytes);
  11819. if (rsize)
  11820. rvalue = frame + 1;
  11821. frame->fn = (uintptr_t)fn;
  11822. frame->flags = flags;
  11823. frame->rvalue = (uintptr_t)rvalue;
  11824. j = 0;
  11825. if (flags == FFI_TYPE_STRUCT)
  11826. {
  11827. stack[0] = (uintptr_t)rvalue;
  11828. j = 1;
  11829. }
  11830. for (i = 0, n = cif->nargs; i < n; ++i, ++j)
  11831. {
  11832. switch (cif->arg_types[i]->size)
  11833. {
  11834. case 8:
  11835. stack[j] = *(UINT64 *)avalue[i];
  11836. break;
  11837. case 4:
  11838. stack[j] = *(UINT32 *)avalue[i];
  11839. break;
  11840. case 2:
  11841. stack[j] = *(UINT16 *)avalue[i];
  11842. break;
  11843. case 1:
  11844. stack[j] = *(UINT8 *)avalue[i];
  11845. break;
  11846. default:
  11847. stack[j] = (uintptr_t)avalue[i];
  11848. break;
  11849. }
  11850. }
  11851. ffi_call_win64 (stack, frame, closure);
  11852. }
  11853. void
  11854. EFI64(ffi_call)(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
  11855. {
  11856. ffi_call_int (cif, fn, rvalue, avalue, NULL);
  11857. }
  11858. void
  11859. EFI64(ffi_call_go)(ffi_cif *cif, void (*fn)(void), void *rvalue,
  11860. void **avalue, void *closure)
  11861. {
  11862. ffi_call_int (cif, fn, rvalue, avalue, closure);
  11863. }
  11864. extern void ffi_closure_win64(void) FFI_HIDDEN;
  11865. extern void ffi_go_closure_win64(void) FFI_HIDDEN;
  11866. ffi_status
  11867. EFI64(ffi_prep_closure_loc)(ffi_closure* closure,
  11868. ffi_cif* cif,
  11869. void (*fun)(ffi_cif*, void*, void**, void*),
  11870. void *user_data,
  11871. void *codeloc)
  11872. {
  11873. static const unsigned char trampoline[16] = {
  11874. /* leaq -0x7(%rip),%r10 # 0x0 */
  11875. 0x4c, 0x8d, 0x15, 0xf9, 0xff, 0xff, 0xff,
  11876. /* jmpq *0x3(%rip) # 0x10 */
  11877. 0xff, 0x25, 0x03, 0x00, 0x00, 0x00,
  11878. /* nopl (%rax) */
  11879. 0x0f, 0x1f, 0x00
  11880. };
  11881. char *tramp = closure->tramp;
  11882. switch (cif->abi)
  11883. {
  11884. case FFI_WIN64:
  11885. case FFI_GNUW64:
  11886. break;
  11887. default:
  11888. return FFI_BAD_ABI;
  11889. }
  11890. memcpy (tramp, trampoline, sizeof(trampoline));
  11891. *(UINT64 *)(tramp + 16) = (uintptr_t)ffi_closure_win64;
  11892. closure->cif = cif;
  11893. closure->fun = fun;
  11894. closure->user_data = user_data;
  11895. return FFI_OK;
  11896. }
  11897. ffi_status
  11898. EFI64(ffi_prep_go_closure)(ffi_go_closure* closure, ffi_cif* cif,
  11899. void (*fun)(ffi_cif*, void*, void**, void*))
  11900. {
  11901. switch (cif->abi)
  11902. {
  11903. case FFI_WIN64:
  11904. case FFI_GNUW64:
  11905. break;
  11906. default:
  11907. return FFI_BAD_ABI;
  11908. }
  11909. closure->tramp = ffi_go_closure_win64;
  11910. closure->cif = cif;
  11911. closure->fun = fun;
  11912. return FFI_OK;
  11913. }
  11914. struct win64_closure_frame
  11915. {
  11916. UINT64 rvalue[2];
  11917. UINT64 fargs[4];
  11918. UINT64 retaddr;
  11919. UINT64 args[];
  11920. };
  11921. /* Force the inner function to use the MS ABI. When compiling on win64
  11922. this is a nop. When compiling on unix, this simplifies the assembly,
  11923. and places the burden of saving the extra call-saved registers on
  11924. the compiler. */
  11925. int FFI_HIDDEN __attribute__((ms_abi))
  11926. ffi_closure_win64_inner(ffi_cif *cif,
  11927. void (*fun)(ffi_cif*, void*, void**, void*),
  11928. void *user_data,
  11929. struct win64_closure_frame *frame)
  11930. {
  11931. void **avalue;
  11932. void *rvalue;
  11933. int i, n, nreg, flags;
  11934. avalue = alloca(cif->nargs * sizeof(void *));
  11935. rvalue = frame->rvalue;
  11936. nreg = 0;
  11937. /* When returning a structure, the address is in the first argument.
  11938. We must also be prepared to return the same address in eax, so
  11939. install that address in the frame and pretend we return a pointer. */
  11940. flags = cif->flags;
  11941. if (flags == FFI_TYPE_STRUCT)
  11942. {
  11943. rvalue = (void *)(uintptr_t)frame->args[0];
  11944. frame->rvalue[0] = frame->args[0];
  11945. nreg = 1;
  11946. }
  11947. for (i = 0, n = cif->nargs; i < n; ++i, ++nreg)
  11948. {
  11949. size_t size = cif->arg_types[i]->size;
  11950. size_t type = cif->arg_types[i]->type;
  11951. void *a;
  11952. if (type == FFI_TYPE_DOUBLE || type == FFI_TYPE_FLOAT)
  11953. {
  11954. if (nreg < 4)
  11955. a = &frame->fargs[nreg];
  11956. else
  11957. a = &frame->args[nreg];
  11958. }
  11959. else if (size == 1 || size == 2 || size == 4 || size == 8)
  11960. a = &frame->args[nreg];
  11961. else
  11962. a = (void *)(uintptr_t)frame->args[nreg];
  11963. avalue[i] = a;
  11964. }
  11965. /* Invoke the closure. */
  11966. fun (cif, rvalue, avalue, user_data);
  11967. return flags;
  11968. }
  11969. #endif /* __x86_64__ */
  11970. ====================File: src/x86/sysv.S====================
  11971. /* -----------------------------------------------------------------------
  11972. sysv.S - Copyright (c) 2017 Anthony Green
  11973. - Copyright (c) 2013 The Written Word, Inc.
  11974. - Copyright (c) 1996,1998,2001-2003,2005,2008,2010 Red Hat, Inc.
  11975. X86 Foreign Function Interface
  11976. Permission is hereby granted, free of charge, to any person obtaining
  11977. a copy of this software and associated documentation files (the
  11978. ``Software''), to deal in the Software without restriction, including
  11979. without limitation the rights to use, copy, modify, merge, publish,
  11980. distribute, sublicense, and/or sell copies of the Software, and to
  11981. permit persons to whom the Software is furnished to do so, subject to
  11982. the following conditions:
  11983. The above copyright notice and this permission notice shall be included
  11984. in all copies or substantial portions of the Software.
  11985. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  11986. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  11987. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  11988. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  11989. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  11990. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  11991. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  11992. DEALINGS IN THE SOFTWARE.
  11993. ----------------------------------------------------------------------- */
  11994. #ifdef __i386__
  11995. #ifndef _MSC_VER
  11996. #define LIBFFI_ASM
  11997. #include <fficonfig.h>
  11998. #include <ffi.h>
  11999. #include "internal.h"
  12000. #define C2(X, Y) X ## Y
  12001. #define C1(X, Y) C2(X, Y)
  12002. #ifdef __USER_LABEL_PREFIX__
  12003. # define C(X) C1(__USER_LABEL_PREFIX__, X)
  12004. #else
  12005. # define C(X) X
  12006. #endif
  12007. #ifdef X86_DARWIN
  12008. # define L(X) C1(L, X)
  12009. #else
  12010. # define L(X) C1(.L, X)
  12011. #endif
  12012. #ifdef __ELF__
  12013. # define ENDF(X) .type X,@function; .size X, . - X
  12014. #else
  12015. # define ENDF(X)
  12016. #endif
  12017. /* Handle win32 fastcall name mangling. */
  12018. #ifdef X86_WIN32
  12019. # define ffi_call_i386 @ffi_call_i386@8
  12020. # define ffi_closure_inner @ffi_closure_inner@8
  12021. #else
  12022. # define ffi_call_i386 C(ffi_call_i386)
  12023. # define ffi_closure_inner C(ffi_closure_inner)
  12024. #endif
  12025. /* This macro allows the safe creation of jump tables without an
  12026. actual table. The entry points into the table are all 8 bytes.
  12027. The use of ORG asserts that we're at the correct location. */
  12028. /* ??? The clang assembler doesn't handle .org with symbolic expressions. */
  12029. #if defined(__clang__) || defined(__APPLE__) || (defined (__sun__) && defined(__svr4__))
  12030. # define E(BASE, X) .balign 8
  12031. #else
  12032. # define E(BASE, X) .balign 8; .org BASE + X * 8
  12033. #endif
  12034. .text
  12035. .balign 16
  12036. .globl ffi_call_i386
  12037. FFI_HIDDEN(ffi_call_i386)
  12038. /* This is declared as
  12039. void ffi_call_i386(struct call_frame *frame, char *argp)
  12040. __attribute__((fastcall));
  12041. Thus the arguments are present in
  12042. ecx: frame
  12043. edx: argp
  12044. */
  12045. ffi_call_i386:
  12046. L(UW0):
  12047. # cfi_startproc
  12048. #if !HAVE_FASTCALL
  12049. movl 4(%esp), %ecx
  12050. movl 8(%esp), %edx
  12051. #endif
  12052. movl (%esp), %eax /* move the return address */
  12053. movl %ebp, (%ecx) /* store %ebp into local frame */
  12054. movl %eax, 4(%ecx) /* store retaddr into local frame */
  12055. /* New stack frame based off ebp. This is a itty bit of unwind
  12056. trickery in that the CFA *has* changed. There is no easy way
  12057. to describe it correctly on entry to the function. Fortunately,
  12058. it doesn't matter too much since at all points we can correctly
  12059. unwind back to ffi_call. Note that the location to which we
  12060. moved the return address is (the new) CFA-4, so from the
  12061. perspective of the unwind info, it hasn't moved. */
  12062. movl %ecx, %ebp
  12063. L(UW1):
  12064. # cfi_def_cfa(%ebp, 8)
  12065. # cfi_rel_offset(%ebp, 0)
  12066. movl %edx, %esp /* set outgoing argument stack */
  12067. movl 20+R_EAX*4(%ebp), %eax /* set register arguments */
  12068. movl 20+R_EDX*4(%ebp), %edx
  12069. movl 20+R_ECX*4(%ebp), %ecx
  12070. call *8(%ebp)
  12071. movl 12(%ebp), %ecx /* load return type code */
  12072. movl %ebx, 8(%ebp) /* preserve %ebx */
  12073. L(UW2):
  12074. # cfi_rel_offset(%ebx, 8)
  12075. andl $X86_RET_TYPE_MASK, %ecx
  12076. #ifdef __PIC__
  12077. call C(__x86.get_pc_thunk.bx)
  12078. L(pc1):
  12079. leal L(store_table)-L(pc1)(%ebx, %ecx, 8), %ebx
  12080. #else
  12081. leal L(store_table)(,%ecx, 8), %ebx
  12082. #endif
  12083. movl 16(%ebp), %ecx /* load result address */
  12084. jmp *%ebx
  12085. .balign 8
  12086. L(store_table):
  12087. E(L(store_table), X86_RET_FLOAT)
  12088. fstps (%ecx)
  12089. jmp L(e1)
  12090. E(L(store_table), X86_RET_DOUBLE)
  12091. fstpl (%ecx)
  12092. jmp L(e1)
  12093. E(L(store_table), X86_RET_LDOUBLE)
  12094. fstpt (%ecx)
  12095. jmp L(e1)
  12096. E(L(store_table), X86_RET_SINT8)
  12097. movsbl %al, %eax
  12098. mov %eax, (%ecx)
  12099. jmp L(e1)
  12100. E(L(store_table), X86_RET_SINT16)
  12101. movswl %ax, %eax
  12102. mov %eax, (%ecx)
  12103. jmp L(e1)
  12104. E(L(store_table), X86_RET_UINT8)
  12105. movzbl %al, %eax
  12106. mov %eax, (%ecx)
  12107. jmp L(e1)
  12108. E(L(store_table), X86_RET_UINT16)
  12109. movzwl %ax, %eax
  12110. mov %eax, (%ecx)
  12111. jmp L(e1)
  12112. E(L(store_table), X86_RET_INT64)
  12113. movl %edx, 4(%ecx)
  12114. /* fallthru */
  12115. E(L(store_table), X86_RET_INT32)
  12116. movl %eax, (%ecx)
  12117. /* fallthru */
  12118. E(L(store_table), X86_RET_VOID)
  12119. L(e1):
  12120. movl 8(%ebp), %ebx
  12121. movl %ebp, %esp
  12122. popl %ebp
  12123. L(UW3):
  12124. # cfi_remember_state
  12125. # cfi_def_cfa(%esp, 4)
  12126. # cfi_restore(%ebx)
  12127. # cfi_restore(%ebp)
  12128. ret
  12129. L(UW4):
  12130. # cfi_restore_state
  12131. E(L(store_table), X86_RET_STRUCTPOP)
  12132. jmp L(e1)
  12133. E(L(store_table), X86_RET_STRUCTARG)
  12134. jmp L(e1)
  12135. E(L(store_table), X86_RET_STRUCT_1B)
  12136. movb %al, (%ecx)
  12137. jmp L(e1)
  12138. E(L(store_table), X86_RET_STRUCT_2B)
  12139. movw %ax, (%ecx)
  12140. jmp L(e1)
  12141. /* Fill out the table so that bad values are predictable. */
  12142. E(L(store_table), X86_RET_UNUSED14)
  12143. ud2
  12144. E(L(store_table), X86_RET_UNUSED15)
  12145. ud2
  12146. L(UW5):
  12147. # cfi_endproc
  12148. ENDF(ffi_call_i386)
  12149. /* The inner helper is declared as
  12150. void ffi_closure_inner(struct closure_frame *frame, char *argp)
  12151. __attribute_((fastcall))
  12152. Thus the arguments are placed in
  12153. ecx: frame
  12154. edx: argp
  12155. */
  12156. /* Macros to help setting up the closure_data structure. */
  12157. #if HAVE_FASTCALL
  12158. # define closure_FS (40 + 4)
  12159. # define closure_CF 0
  12160. #else
  12161. # define closure_FS (8 + 40 + 12)
  12162. # define closure_CF 8
  12163. #endif
  12164. #define FFI_CLOSURE_SAVE_REGS \
  12165. movl %eax, closure_CF+16+R_EAX*4(%esp); \
  12166. movl %edx, closure_CF+16+R_EDX*4(%esp); \
  12167. movl %ecx, closure_CF+16+R_ECX*4(%esp)
  12168. #define FFI_CLOSURE_COPY_TRAMP_DATA \
  12169. movl FFI_TRAMPOLINE_SIZE(%eax), %edx; /* copy cif */ \
  12170. movl FFI_TRAMPOLINE_SIZE+4(%eax), %ecx; /* copy fun */ \
  12171. movl FFI_TRAMPOLINE_SIZE+8(%eax), %eax; /* copy user_data */ \
  12172. movl %edx, closure_CF+28(%esp); \
  12173. movl %ecx, closure_CF+32(%esp); \
  12174. movl %eax, closure_CF+36(%esp)
  12175. #if HAVE_FASTCALL
  12176. # define FFI_CLOSURE_PREP_CALL \
  12177. movl %esp, %ecx; /* load closure_data */ \
  12178. leal closure_FS+4(%esp), %edx; /* load incoming stack */
  12179. #else
  12180. # define FFI_CLOSURE_PREP_CALL \
  12181. leal closure_CF(%esp), %ecx; /* load closure_data */ \
  12182. leal closure_FS+4(%esp), %edx; /* load incoming stack */ \
  12183. movl %ecx, (%esp); \
  12184. movl %edx, 4(%esp)
  12185. #endif
  12186. #define FFI_CLOSURE_CALL_INNER(UWN) \
  12187. call ffi_closure_inner
  12188. #define FFI_CLOSURE_MASK_AND_JUMP(N, UW) \
  12189. andl $X86_RET_TYPE_MASK, %eax; \
  12190. leal L(C1(load_table,N))(, %eax, 8), %edx; \
  12191. movl closure_CF(%esp), %eax; /* optimiztic load */ \
  12192. jmp *%edx
  12193. #ifdef __PIC__
  12194. # if defined X86_DARWIN || defined HAVE_HIDDEN_VISIBILITY_ATTRIBUTE
  12195. # undef FFI_CLOSURE_MASK_AND_JUMP
  12196. # define FFI_CLOSURE_MASK_AND_JUMP(N, UW) \
  12197. andl $X86_RET_TYPE_MASK, %eax; \
  12198. call C(__x86.get_pc_thunk.dx); \
  12199. L(C1(pc,N)): \
  12200. leal L(C1(load_table,N))-L(C1(pc,N))(%edx, %eax, 8), %edx; \
  12201. movl closure_CF(%esp), %eax; /* optimiztic load */ \
  12202. jmp *%edx
  12203. # else
  12204. # define FFI_CLOSURE_CALL_INNER_SAVE_EBX
  12205. # undef FFI_CLOSURE_CALL_INNER
  12206. # define FFI_CLOSURE_CALL_INNER(UWN) \
  12207. movl %ebx, 40(%esp); /* save ebx */ \
  12208. L(C1(UW,UWN)): \
  12209. /* cfi_rel_offset(%ebx, 40); */ \
  12210. call C(__x86.get_pc_thunk.bx); /* load got register */ \
  12211. addl $C(_GLOBAL_OFFSET_TABLE_), %ebx; \
  12212. call ffi_closure_inner@PLT
  12213. # undef FFI_CLOSURE_MASK_AND_JUMP
  12214. # define FFI_CLOSURE_MASK_AND_JUMP(N, UWN) \
  12215. andl $X86_RET_TYPE_MASK, %eax; \
  12216. leal L(C1(load_table,N))@GOTOFF(%ebx, %eax, 8), %edx; \
  12217. movl 40(%esp), %ebx; /* restore ebx */ \
  12218. L(C1(UW,UWN)): \
  12219. /* cfi_restore(%ebx); */ \
  12220. movl closure_CF(%esp), %eax; /* optimiztic load */ \
  12221. jmp *%edx
  12222. # endif /* DARWIN || HIDDEN */
  12223. #endif /* __PIC__ */
  12224. .balign 16
  12225. .globl C(ffi_go_closure_EAX)
  12226. FFI_HIDDEN(C(ffi_go_closure_EAX))
  12227. C(ffi_go_closure_EAX):
  12228. L(UW6):
  12229. # cfi_startproc
  12230. subl $closure_FS, %esp
  12231. L(UW7):
  12232. # cfi_def_cfa_offset(closure_FS + 4)
  12233. FFI_CLOSURE_SAVE_REGS
  12234. movl 4(%eax), %edx /* copy cif */
  12235. movl 8(%eax), %ecx /* copy fun */
  12236. movl %edx, closure_CF+28(%esp)
  12237. movl %ecx, closure_CF+32(%esp)
  12238. movl %eax, closure_CF+36(%esp) /* closure is user_data */
  12239. jmp L(do_closure_i386)
  12240. L(UW8):
  12241. # cfi_endproc
  12242. ENDF(C(ffi_go_closure_EAX))
  12243. .balign 16
  12244. .globl C(ffi_go_closure_ECX)
  12245. FFI_HIDDEN(C(ffi_go_closure_ECX))
  12246. C(ffi_go_closure_ECX):
  12247. L(UW9):
  12248. # cfi_startproc
  12249. subl $closure_FS, %esp
  12250. L(UW10):
  12251. # cfi_def_cfa_offset(closure_FS + 4)
  12252. FFI_CLOSURE_SAVE_REGS
  12253. movl 4(%ecx), %edx /* copy cif */
  12254. movl 8(%ecx), %eax /* copy fun */
  12255. movl %edx, closure_CF+28(%esp)
  12256. movl %eax, closure_CF+32(%esp)
  12257. movl %ecx, closure_CF+36(%esp) /* closure is user_data */
  12258. jmp L(do_closure_i386)
  12259. L(UW11):
  12260. # cfi_endproc
  12261. ENDF(C(ffi_go_closure_ECX))
  12262. /* The closure entry points are reached from the ffi_closure trampoline.
  12263. On entry, %eax contains the address of the ffi_closure. */
  12264. .balign 16
  12265. .globl C(ffi_closure_i386)
  12266. FFI_HIDDEN(C(ffi_closure_i386))
  12267. C(ffi_closure_i386):
  12268. L(UW12):
  12269. # cfi_startproc
  12270. subl $closure_FS, %esp
  12271. L(UW13):
  12272. # cfi_def_cfa_offset(closure_FS + 4)
  12273. FFI_CLOSURE_SAVE_REGS
  12274. FFI_CLOSURE_COPY_TRAMP_DATA
  12275. /* Entry point from preceeding Go closures. */
  12276. L(do_closure_i386):
  12277. FFI_CLOSURE_PREP_CALL
  12278. FFI_CLOSURE_CALL_INNER(14)
  12279. FFI_CLOSURE_MASK_AND_JUMP(2, 15)
  12280. .balign 8
  12281. L(load_table2):
  12282. E(L(load_table2), X86_RET_FLOAT)
  12283. flds closure_CF(%esp)
  12284. jmp L(e2)
  12285. E(L(load_table2), X86_RET_DOUBLE)
  12286. fldl closure_CF(%esp)
  12287. jmp L(e2)
  12288. E(L(load_table2), X86_RET_LDOUBLE)
  12289. fldt closure_CF(%esp)
  12290. jmp L(e2)
  12291. E(L(load_table2), X86_RET_SINT8)
  12292. movsbl %al, %eax
  12293. jmp L(e2)
  12294. E(L(load_table2), X86_RET_SINT16)
  12295. movswl %ax, %eax
  12296. jmp L(e2)
  12297. E(L(load_table2), X86_RET_UINT8)
  12298. movzbl %al, %eax
  12299. jmp L(e2)
  12300. E(L(load_table2), X86_RET_UINT16)
  12301. movzwl %ax, %eax
  12302. jmp L(e2)
  12303. E(L(load_table2), X86_RET_INT64)
  12304. movl closure_CF+4(%esp), %edx
  12305. jmp L(e2)
  12306. E(L(load_table2), X86_RET_INT32)
  12307. nop
  12308. /* fallthru */
  12309. E(L(load_table2), X86_RET_VOID)
  12310. L(e2):
  12311. addl $closure_FS, %esp
  12312. L(UW16):
  12313. # cfi_adjust_cfa_offset(-closure_FS)
  12314. ret
  12315. L(UW17):
  12316. # cfi_adjust_cfa_offset(closure_FS)
  12317. E(L(load_table2), X86_RET_STRUCTPOP)
  12318. addl $closure_FS, %esp
  12319. L(UW18):
  12320. # cfi_adjust_cfa_offset(-closure_FS)
  12321. ret $4
  12322. L(UW19):
  12323. # cfi_adjust_cfa_offset(closure_FS)
  12324. E(L(load_table2), X86_RET_STRUCTARG)
  12325. jmp L(e2)
  12326. E(L(load_table2), X86_RET_STRUCT_1B)
  12327. movzbl %al, %eax
  12328. jmp L(e2)
  12329. E(L(load_table2), X86_RET_STRUCT_2B)
  12330. movzwl %ax, %eax
  12331. jmp L(e2)
  12332. /* Fill out the table so that bad values are predictable. */
  12333. E(L(load_table2), X86_RET_UNUSED14)
  12334. ud2
  12335. E(L(load_table2), X86_RET_UNUSED15)
  12336. ud2
  12337. L(UW20):
  12338. # cfi_endproc
  12339. ENDF(C(ffi_closure_i386))
  12340. .balign 16
  12341. .globl C(ffi_go_closure_STDCALL)
  12342. FFI_HIDDEN(C(ffi_go_closure_STDCALL))
  12343. C(ffi_go_closure_STDCALL):
  12344. L(UW21):
  12345. # cfi_startproc
  12346. subl $closure_FS, %esp
  12347. L(UW22):
  12348. # cfi_def_cfa_offset(closure_FS + 4)
  12349. FFI_CLOSURE_SAVE_REGS
  12350. movl 4(%ecx), %edx /* copy cif */
  12351. movl 8(%ecx), %eax /* copy fun */
  12352. movl %edx, closure_CF+28(%esp)
  12353. movl %eax, closure_CF+32(%esp)
  12354. movl %ecx, closure_CF+36(%esp) /* closure is user_data */
  12355. jmp L(do_closure_STDCALL)
  12356. L(UW23):
  12357. # cfi_endproc
  12358. ENDF(C(ffi_go_closure_STDCALL))
  12359. /* For REGISTER, we have no available parameter registers, and so we
  12360. enter here having pushed the closure onto the stack. */
  12361. .balign 16
  12362. .globl C(ffi_closure_REGISTER)
  12363. FFI_HIDDEN(C(ffi_closure_REGISTER))
  12364. C(ffi_closure_REGISTER):
  12365. L(UW24):
  12366. # cfi_startproc
  12367. # cfi_def_cfa(%esp, 8)
  12368. # cfi_offset(%eip, -8)
  12369. subl $closure_FS-4, %esp
  12370. L(UW25):
  12371. # cfi_def_cfa_offset(closure_FS + 4)
  12372. FFI_CLOSURE_SAVE_REGS
  12373. movl closure_FS-4(%esp), %ecx /* load retaddr */
  12374. movl closure_FS(%esp), %eax /* load closure */
  12375. movl %ecx, closure_FS(%esp) /* move retaddr */
  12376. jmp L(do_closure_REGISTER)
  12377. L(UW26):
  12378. # cfi_endproc
  12379. ENDF(C(ffi_closure_REGISTER))
  12380. /* For STDCALL (and others), we need to pop N bytes of arguments off
  12381. the stack following the closure. The amount needing to be popped
  12382. is returned to us from ffi_closure_inner. */
  12383. .balign 16
  12384. .globl C(ffi_closure_STDCALL)
  12385. FFI_HIDDEN(C(ffi_closure_STDCALL))
  12386. C(ffi_closure_STDCALL):
  12387. L(UW27):
  12388. # cfi_startproc
  12389. subl $closure_FS, %esp
  12390. L(UW28):
  12391. # cfi_def_cfa_offset(closure_FS + 4)
  12392. FFI_CLOSURE_SAVE_REGS
  12393. /* Entry point from ffi_closure_REGISTER. */
  12394. L(do_closure_REGISTER):
  12395. FFI_CLOSURE_COPY_TRAMP_DATA
  12396. /* Entry point from preceeding Go closure. */
  12397. L(do_closure_STDCALL):
  12398. FFI_CLOSURE_PREP_CALL
  12399. FFI_CLOSURE_CALL_INNER(29)
  12400. movl %eax, %ecx
  12401. shrl $X86_RET_POP_SHIFT, %ecx /* isolate pop count */
  12402. leal closure_FS(%esp, %ecx), %ecx /* compute popped esp */
  12403. movl closure_FS(%esp), %edx /* move return address */
  12404. movl %edx, (%ecx)
  12405. /* From this point on, the value of %esp upon return is %ecx+4,
  12406. and we've copied the return address to %ecx to make return easy.
  12407. There's no point in representing this in the unwind info, as
  12408. there is always a window between the mov and the ret which
  12409. will be wrong from one point of view or another. */
  12410. FFI_CLOSURE_MASK_AND_JUMP(3, 30)
  12411. .balign 8
  12412. L(load_table3):
  12413. E(L(load_table3), X86_RET_FLOAT)
  12414. flds closure_CF(%esp)
  12415. movl %ecx, %esp
  12416. ret
  12417. E(L(load_table3), X86_RET_DOUBLE)
  12418. fldl closure_CF(%esp)
  12419. movl %ecx, %esp
  12420. ret
  12421. E(L(load_table3), X86_RET_LDOUBLE)
  12422. fldt closure_CF(%esp)
  12423. movl %ecx, %esp
  12424. ret
  12425. E(L(load_table3), X86_RET_SINT8)
  12426. movsbl %al, %eax
  12427. movl %ecx, %esp
  12428. ret
  12429. E(L(load_table3), X86_RET_SINT16)
  12430. movswl %ax, %eax
  12431. movl %ecx, %esp
  12432. ret
  12433. E(L(load_table3), X86_RET_UINT8)
  12434. movzbl %al, %eax
  12435. movl %ecx, %esp
  12436. ret
  12437. E(L(load_table3), X86_RET_UINT16)
  12438. movzwl %ax, %eax
  12439. movl %ecx, %esp
  12440. ret
  12441. E(L(load_table3), X86_RET_INT64)
  12442. movl closure_CF+4(%esp), %edx
  12443. movl %ecx, %esp
  12444. ret
  12445. E(L(load_table3), X86_RET_INT32)
  12446. movl %ecx, %esp
  12447. ret
  12448. E(L(load_table3), X86_RET_VOID)
  12449. movl %ecx, %esp
  12450. ret
  12451. E(L(load_table3), X86_RET_STRUCTPOP)
  12452. movl %ecx, %esp
  12453. ret
  12454. E(L(load_table3), X86_RET_STRUCTARG)
  12455. movl %ecx, %esp
  12456. ret
  12457. E(L(load_table3), X86_RET_STRUCT_1B)
  12458. movzbl %al, %eax
  12459. movl %ecx, %esp
  12460. ret
  12461. E(L(load_table3), X86_RET_STRUCT_2B)
  12462. movzwl %ax, %eax
  12463. movl %ecx, %esp
  12464. ret
  12465. /* Fill out the table so that bad values are predictable. */
  12466. E(L(load_table3), X86_RET_UNUSED14)
  12467. ud2
  12468. E(L(load_table3), X86_RET_UNUSED15)
  12469. ud2
  12470. L(UW31):
  12471. # cfi_endproc
  12472. ENDF(C(ffi_closure_STDCALL))
  12473. #if !FFI_NO_RAW_API
  12474. #define raw_closure_S_FS (16+16+12)
  12475. .balign 16
  12476. .globl C(ffi_closure_raw_SYSV)
  12477. FFI_HIDDEN(C(ffi_closure_raw_SYSV))
  12478. C(ffi_closure_raw_SYSV):
  12479. L(UW32):
  12480. # cfi_startproc
  12481. subl $raw_closure_S_FS, %esp
  12482. L(UW33):
  12483. # cfi_def_cfa_offset(raw_closure_S_FS + 4)
  12484. movl %ebx, raw_closure_S_FS-4(%esp)
  12485. L(UW34):
  12486. # cfi_rel_offset(%ebx, raw_closure_S_FS-4)
  12487. movl FFI_TRAMPOLINE_SIZE+8(%eax), %edx /* load cl->user_data */
  12488. movl %edx, 12(%esp)
  12489. leal raw_closure_S_FS+4(%esp), %edx /* load raw_args */
  12490. movl %edx, 8(%esp)
  12491. leal 16(%esp), %edx /* load &res */
  12492. movl %edx, 4(%esp)
  12493. movl FFI_TRAMPOLINE_SIZE(%eax), %ebx /* load cl->cif */
  12494. movl %ebx, (%esp)
  12495. call *FFI_TRAMPOLINE_SIZE+4(%eax) /* call cl->fun */
  12496. movl 20(%ebx), %eax /* load cif->flags */
  12497. andl $X86_RET_TYPE_MASK, %eax
  12498. #ifdef __PIC__
  12499. call C(__x86.get_pc_thunk.bx)
  12500. L(pc4):
  12501. leal L(load_table4)-L(pc4)(%ebx, %eax, 8), %ecx
  12502. #else
  12503. leal L(load_table4)(,%eax, 8), %ecx
  12504. #endif
  12505. movl raw_closure_S_FS-4(%esp), %ebx
  12506. L(UW35):
  12507. # cfi_restore(%ebx)
  12508. movl 16(%esp), %eax /* Optimistic load */
  12509. jmp *%ecx
  12510. .balign 8
  12511. L(load_table4):
  12512. E(L(load_table4), X86_RET_FLOAT)
  12513. flds 16(%esp)
  12514. jmp L(e4)
  12515. E(L(load_table4), X86_RET_DOUBLE)
  12516. fldl 16(%esp)
  12517. jmp L(e4)
  12518. E(L(load_table4), X86_RET_LDOUBLE)
  12519. fldt 16(%esp)
  12520. jmp L(e4)
  12521. E(L(load_table4), X86_RET_SINT8)
  12522. movsbl %al, %eax
  12523. jmp L(e4)
  12524. E(L(load_table4), X86_RET_SINT16)
  12525. movswl %ax, %eax
  12526. jmp L(e4)
  12527. E(L(load_table4), X86_RET_UINT8)
  12528. movzbl %al, %eax
  12529. jmp L(e4)
  12530. E(L(load_table4), X86_RET_UINT16)
  12531. movzwl %ax, %eax
  12532. jmp L(e4)
  12533. E(L(load_table4), X86_RET_INT64)
  12534. movl 16+4(%esp), %edx
  12535. jmp L(e4)
  12536. E(L(load_table4), X86_RET_INT32)
  12537. nop
  12538. /* fallthru */
  12539. E(L(load_table4), X86_RET_VOID)
  12540. L(e4):
  12541. addl $raw_closure_S_FS, %esp
  12542. L(UW36):
  12543. # cfi_adjust_cfa_offset(-raw_closure_S_FS)
  12544. ret
  12545. L(UW37):
  12546. # cfi_adjust_cfa_offset(raw_closure_S_FS)
  12547. E(L(load_table4), X86_RET_STRUCTPOP)
  12548. addl $raw_closure_S_FS, %esp
  12549. L(UW38):
  12550. # cfi_adjust_cfa_offset(-raw_closure_S_FS)
  12551. ret $4
  12552. L(UW39):
  12553. # cfi_adjust_cfa_offset(raw_closure_S_FS)
  12554. E(L(load_table4), X86_RET_STRUCTARG)
  12555. jmp L(e4)
  12556. E(L(load_table4), X86_RET_STRUCT_1B)
  12557. movzbl %al, %eax
  12558. jmp L(e4)
  12559. E(L(load_table4), X86_RET_STRUCT_2B)
  12560. movzwl %ax, %eax
  12561. jmp L(e4)
  12562. /* Fill out the table so that bad values are predictable. */
  12563. E(L(load_table4), X86_RET_UNUSED14)
  12564. ud2
  12565. E(L(load_table4), X86_RET_UNUSED15)
  12566. ud2
  12567. L(UW40):
  12568. # cfi_endproc
  12569. ENDF(C(ffi_closure_raw_SYSV))
  12570. #define raw_closure_T_FS (16+16+8)
  12571. .balign 16
  12572. .globl C(ffi_closure_raw_THISCALL)
  12573. FFI_HIDDEN(C(ffi_closure_raw_THISCALL))
  12574. C(ffi_closure_raw_THISCALL):
  12575. L(UW41):
  12576. # cfi_startproc
  12577. /* Rearrange the stack such that %ecx is the first argument.
  12578. This means moving the return address. */
  12579. popl %edx
  12580. L(UW42):
  12581. # cfi_def_cfa_offset(0)
  12582. # cfi_register(%eip, %edx)
  12583. pushl %ecx
  12584. L(UW43):
  12585. # cfi_adjust_cfa_offset(4)
  12586. pushl %edx
  12587. L(UW44):
  12588. # cfi_adjust_cfa_offset(4)
  12589. # cfi_rel_offset(%eip, 0)
  12590. subl $raw_closure_T_FS, %esp
  12591. L(UW45):
  12592. # cfi_adjust_cfa_offset(raw_closure_T_FS)
  12593. movl %ebx, raw_closure_T_FS-4(%esp)
  12594. L(UW46):
  12595. # cfi_rel_offset(%ebx, raw_closure_T_FS-4)
  12596. movl FFI_TRAMPOLINE_SIZE+8(%eax), %edx /* load cl->user_data */
  12597. movl %edx, 12(%esp)
  12598. leal raw_closure_T_FS+4(%esp), %edx /* load raw_args */
  12599. movl %edx, 8(%esp)
  12600. leal 16(%esp), %edx /* load &res */
  12601. movl %edx, 4(%esp)
  12602. movl FFI_TRAMPOLINE_SIZE(%eax), %ebx /* load cl->cif */
  12603. movl %ebx, (%esp)
  12604. call *FFI_TRAMPOLINE_SIZE+4(%eax) /* call cl->fun */
  12605. movl 20(%ebx), %eax /* load cif->flags */
  12606. andl $X86_RET_TYPE_MASK, %eax
  12607. #ifdef __PIC__
  12608. call C(__x86.get_pc_thunk.bx)
  12609. L(pc5):
  12610. leal L(load_table5)-L(pc5)(%ebx, %eax, 8), %ecx
  12611. #else
  12612. leal L(load_table5)(,%eax, 8), %ecx
  12613. #endif
  12614. movl raw_closure_T_FS-4(%esp), %ebx
  12615. L(UW47):
  12616. # cfi_restore(%ebx)
  12617. movl 16(%esp), %eax /* Optimistic load */
  12618. jmp *%ecx
  12619. .balign 8
  12620. L(load_table5):
  12621. E(L(load_table5), X86_RET_FLOAT)
  12622. flds 16(%esp)
  12623. jmp L(e5)
  12624. E(L(load_table5), X86_RET_DOUBLE)
  12625. fldl 16(%esp)
  12626. jmp L(e5)
  12627. E(L(load_table5), X86_RET_LDOUBLE)
  12628. fldt 16(%esp)
  12629. jmp L(e5)
  12630. E(L(load_table5), X86_RET_SINT8)
  12631. movsbl %al, %eax
  12632. jmp L(e5)
  12633. E(L(load_table5), X86_RET_SINT16)
  12634. movswl %ax, %eax
  12635. jmp L(e5)
  12636. E(L(load_table5), X86_RET_UINT8)
  12637. movzbl %al, %eax
  12638. jmp L(e5)
  12639. E(L(load_table5), X86_RET_UINT16)
  12640. movzwl %ax, %eax
  12641. jmp L(e5)
  12642. E(L(load_table5), X86_RET_INT64)
  12643. movl 16+4(%esp), %edx
  12644. jmp L(e5)
  12645. E(L(load_table5), X86_RET_INT32)
  12646. nop
  12647. /* fallthru */
  12648. E(L(load_table5), X86_RET_VOID)
  12649. L(e5):
  12650. addl $raw_closure_T_FS, %esp
  12651. L(UW48):
  12652. # cfi_adjust_cfa_offset(-raw_closure_T_FS)
  12653. /* Remove the extra %ecx argument we pushed. */
  12654. ret $4
  12655. L(UW49):
  12656. # cfi_adjust_cfa_offset(raw_closure_T_FS)
  12657. E(L(load_table5), X86_RET_STRUCTPOP)
  12658. addl $raw_closure_T_FS, %esp
  12659. L(UW50):
  12660. # cfi_adjust_cfa_offset(-raw_closure_T_FS)
  12661. ret $8
  12662. L(UW51):
  12663. # cfi_adjust_cfa_offset(raw_closure_T_FS)
  12664. E(L(load_table5), X86_RET_STRUCTARG)
  12665. jmp L(e5)
  12666. E(L(load_table5), X86_RET_STRUCT_1B)
  12667. movzbl %al, %eax
  12668. jmp L(e5)
  12669. E(L(load_table5), X86_RET_STRUCT_2B)
  12670. movzwl %ax, %eax
  12671. jmp L(e5)
  12672. /* Fill out the table so that bad values are predictable. */
  12673. E(L(load_table5), X86_RET_UNUSED14)
  12674. ud2
  12675. E(L(load_table5), X86_RET_UNUSED15)
  12676. ud2
  12677. L(UW52):
  12678. # cfi_endproc
  12679. ENDF(C(ffi_closure_raw_THISCALL))
  12680. #endif /* !FFI_NO_RAW_API */
  12681. #ifdef X86_DARWIN
  12682. # define COMDAT(X) \
  12683. .section __TEXT,__text,coalesced,pure_instructions; \
  12684. .weak_definition X; \
  12685. FFI_HIDDEN(X)
  12686. #elif defined __ELF__ && !(defined(__sun__) && defined(__svr4__))
  12687. # define COMDAT(X) \
  12688. .section .text.X,"axG",@progbits,X,comdat; \
  12689. .globl X; \
  12690. FFI_HIDDEN(X)
  12691. #else
  12692. # define COMDAT(X)
  12693. #endif
  12694. #if defined(__PIC__)
  12695. COMDAT(C(__x86.get_pc_thunk.bx))
  12696. C(__x86.get_pc_thunk.bx):
  12697. movl (%esp), %ebx
  12698. ret
  12699. ENDF(C(__x86.get_pc_thunk.bx))
  12700. # if defined X86_DARWIN || defined HAVE_HIDDEN_VISIBILITY_ATTRIBUTE
  12701. COMDAT(C(__x86.get_pc_thunk.dx))
  12702. C(__x86.get_pc_thunk.dx):
  12703. movl (%esp), %edx
  12704. ret
  12705. ENDF(C(__x86.get_pc_thunk.dx))
  12706. #endif /* DARWIN || HIDDEN */
  12707. #endif /* __PIC__ */
  12708. /* Sadly, OSX cctools-as doesn't understand .cfi directives at all. */
  12709. #ifdef __APPLE__
  12710. .section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support
  12711. EHFrame0:
  12712. #elif defined(X86_WIN32)
  12713. .section .eh_frame,"r"
  12714. #elif defined(HAVE_AS_X86_64_UNWIND_SECTION_TYPE)
  12715. .section .eh_frame,EH_FRAME_FLAGS,@unwind
  12716. #else
  12717. .section .eh_frame,EH_FRAME_FLAGS,@progbits
  12718. #endif
  12719. #ifdef HAVE_AS_X86_PCREL
  12720. # define PCREL(X) X - .
  12721. #else
  12722. # define PCREL(X) X@rel
  12723. #endif
  12724. /* Simplify advancing between labels. Assume DW_CFA_advance_loc1 fits. */
  12725. #define ADV(N, P) .byte 2, L(N)-L(P)
  12726. .balign 4
  12727. L(CIE):
  12728. .set L(set0),L(ECIE)-L(SCIE)
  12729. .long L(set0) /* CIE Length */
  12730. L(SCIE):
  12731. .long 0 /* CIE Identifier Tag */
  12732. .byte 1 /* CIE Version */
  12733. .ascii "zR\0" /* CIE Augmentation */
  12734. .byte 1 /* CIE Code Alignment Factor */
  12735. .byte 0x7c /* CIE Data Alignment Factor */
  12736. .byte 0x8 /* CIE RA Column */
  12737. .byte 1 /* Augmentation size */
  12738. .byte 0x1b /* FDE Encoding (pcrel sdata4) */
  12739. .byte 0xc, 4, 4 /* DW_CFA_def_cfa, %esp offset 4 */
  12740. .byte 0x80+8, 1 /* DW_CFA_offset, %eip offset 1*-4 */
  12741. .balign 4
  12742. L(ECIE):
  12743. .set L(set1),L(EFDE1)-L(SFDE1)
  12744. .long L(set1) /* FDE Length */
  12745. L(SFDE1):
  12746. .long L(SFDE1)-L(CIE) /* FDE CIE offset */
  12747. .long PCREL(L(UW0)) /* Initial location */
  12748. .long L(UW5)-L(UW0) /* Address range */
  12749. .byte 0 /* Augmentation size */
  12750. ADV(UW1, UW0)
  12751. .byte 0xc, 5, 8 /* DW_CFA_def_cfa, %ebp 8 */
  12752. .byte 0x80+5, 2 /* DW_CFA_offset, %ebp 2*-4 */
  12753. ADV(UW2, UW1)
  12754. .byte 0x80+3, 0 /* DW_CFA_offset, %ebx 0*-4 */
  12755. ADV(UW3, UW2)
  12756. .byte 0xa /* DW_CFA_remember_state */
  12757. .byte 0xc, 4, 4 /* DW_CFA_def_cfa, %esp 4 */
  12758. .byte 0xc0+3 /* DW_CFA_restore, %ebx */
  12759. .byte 0xc0+5 /* DW_CFA_restore, %ebp */
  12760. ADV(UW4, UW3)
  12761. .byte 0xb /* DW_CFA_restore_state */
  12762. .balign 4
  12763. L(EFDE1):
  12764. .set L(set2),L(EFDE2)-L(SFDE2)
  12765. .long L(set2) /* FDE Length */
  12766. L(SFDE2):
  12767. .long L(SFDE2)-L(CIE) /* FDE CIE offset */
  12768. .long PCREL(L(UW6)) /* Initial location */
  12769. .long L(UW8)-L(UW6) /* Address range */
  12770. .byte 0 /* Augmentation size */
  12771. ADV(UW7, UW6)
  12772. .byte 0xe, closure_FS+4 /* DW_CFA_def_cfa_offset */
  12773. .balign 4
  12774. L(EFDE2):
  12775. .set L(set3),L(EFDE3)-L(SFDE3)
  12776. .long L(set3) /* FDE Length */
  12777. L(SFDE3):
  12778. .long L(SFDE3)-L(CIE) /* FDE CIE offset */
  12779. .long PCREL(L(UW9)) /* Initial location */
  12780. .long L(UW11)-L(UW9) /* Address range */
  12781. .byte 0 /* Augmentation size */
  12782. ADV(UW10, UW9)
  12783. .byte 0xe, closure_FS+4 /* DW_CFA_def_cfa_offset */
  12784. .balign 4
  12785. L(EFDE3):
  12786. .set L(set4),L(EFDE4)-L(SFDE4)
  12787. .long L(set4) /* FDE Length */
  12788. L(SFDE4):
  12789. .long L(SFDE4)-L(CIE) /* FDE CIE offset */
  12790. .long PCREL(L(UW12)) /* Initial location */
  12791. .long L(UW20)-L(UW12) /* Address range */
  12792. .byte 0 /* Augmentation size */
  12793. ADV(UW13, UW12)
  12794. .byte 0xe, closure_FS+4 /* DW_CFA_def_cfa_offset */
  12795. #ifdef FFI_CLOSURE_CALL_INNER_SAVE_EBX
  12796. ADV(UW14, UW13)
  12797. .byte 0x80+3, (40-(closure_FS+4))/-4 /* DW_CFA_offset %ebx */
  12798. ADV(UW15, UW14)
  12799. .byte 0xc0+3 /* DW_CFA_restore %ebx */
  12800. ADV(UW16, UW15)
  12801. #else
  12802. ADV(UW16, UW13)
  12803. #endif
  12804. .byte 0xe, 4 /* DW_CFA_def_cfa_offset */
  12805. ADV(UW17, UW16)
  12806. .byte 0xe, closure_FS+4 /* DW_CFA_def_cfa_offset */
  12807. ADV(UW18, UW17)
  12808. .byte 0xe, 4 /* DW_CFA_def_cfa_offset */
  12809. ADV(UW19, UW18)
  12810. .byte 0xe, closure_FS+4 /* DW_CFA_def_cfa_offset */
  12811. .balign 4
  12812. L(EFDE4):
  12813. .set L(set5),L(EFDE5)-L(SFDE5)
  12814. .long L(set5) /* FDE Length */
  12815. L(SFDE5):
  12816. .long L(SFDE5)-L(CIE) /* FDE CIE offset */
  12817. .long PCREL(L(UW21)) /* Initial location */
  12818. .long L(UW23)-L(UW21) /* Address range */
  12819. .byte 0 /* Augmentation size */
  12820. ADV(UW22, UW21)
  12821. .byte 0xe, closure_FS+4 /* DW_CFA_def_cfa_offset */
  12822. .balign 4
  12823. L(EFDE5):
  12824. .set L(set6),L(EFDE6)-L(SFDE6)
  12825. .long L(set6) /* FDE Length */
  12826. L(SFDE6):
  12827. .long L(SFDE6)-L(CIE) /* FDE CIE offset */
  12828. .long PCREL(L(UW24)) /* Initial location */
  12829. .long L(UW26)-L(UW24) /* Address range */
  12830. .byte 0 /* Augmentation size */
  12831. .byte 0xe, 8 /* DW_CFA_def_cfa_offset */
  12832. .byte 0x80+8, 2 /* DW_CFA_offset %eip, 2*-4 */
  12833. ADV(UW25, UW24)
  12834. .byte 0xe, closure_FS+4 /* DW_CFA_def_cfa_offset */
  12835. .balign 4
  12836. L(EFDE6):
  12837. .set L(set7),L(EFDE7)-L(SFDE7)
  12838. .long L(set7) /* FDE Length */
  12839. L(SFDE7):
  12840. .long L(SFDE7)-L(CIE) /* FDE CIE offset */
  12841. .long PCREL(L(UW27)) /* Initial location */
  12842. .long L(UW31)-L(UW27) /* Address range */
  12843. .byte 0 /* Augmentation size */
  12844. ADV(UW28, UW27)
  12845. .byte 0xe, closure_FS+4 /* DW_CFA_def_cfa_offset */
  12846. #ifdef FFI_CLOSURE_CALL_INNER_SAVE_EBX
  12847. ADV(UW29, UW28)
  12848. .byte 0x80+3, (40-(closure_FS+4))/-4 /* DW_CFA_offset %ebx */
  12849. ADV(UW30, UW29)
  12850. .byte 0xc0+3 /* DW_CFA_restore %ebx */
  12851. #endif
  12852. .balign 4
  12853. L(EFDE7):
  12854. #if !FFI_NO_RAW_API
  12855. .set L(set8),L(EFDE8)-L(SFDE8)
  12856. .long L(set8) /* FDE Length */
  12857. L(SFDE8):
  12858. .long L(SFDE8)-L(CIE) /* FDE CIE offset */
  12859. .long PCREL(L(UW32)) /* Initial location */
  12860. .long L(UW40)-L(UW32) /* Address range */
  12861. .byte 0 /* Augmentation size */
  12862. ADV(UW33, UW32)
  12863. .byte 0xe, raw_closure_S_FS+4 /* DW_CFA_def_cfa_offset */
  12864. ADV(UW34, UW33)
  12865. .byte 0x80+3, 2 /* DW_CFA_offset %ebx 2*-4 */
  12866. ADV(UW35, UW34)
  12867. .byte 0xc0+3 /* DW_CFA_restore %ebx */
  12868. ADV(UW36, UW35)
  12869. .byte 0xe, 4 /* DW_CFA_def_cfa_offset */
  12870. ADV(UW37, UW36)
  12871. .byte 0xe, raw_closure_S_FS+4 /* DW_CFA_def_cfa_offset */
  12872. ADV(UW38, UW37)
  12873. .byte 0xe, 4 /* DW_CFA_def_cfa_offset */
  12874. ADV(UW39, UW38)
  12875. .byte 0xe, raw_closure_S_FS+4 /* DW_CFA_def_cfa_offset */
  12876. .balign 4
  12877. L(EFDE8):
  12878. .set L(set9),L(EFDE9)-L(SFDE9)
  12879. .long L(set9) /* FDE Length */
  12880. L(SFDE9):
  12881. .long L(SFDE9)-L(CIE) /* FDE CIE offset */
  12882. .long PCREL(L(UW41)) /* Initial location */
  12883. .long L(UW52)-L(UW41) /* Address range */
  12884. .byte 0 /* Augmentation size */
  12885. ADV(UW42, UW41)
  12886. .byte 0xe, 0 /* DW_CFA_def_cfa_offset */
  12887. .byte 0x9, 8, 2 /* DW_CFA_register %eip, %edx */
  12888. ADV(UW43, UW42)
  12889. .byte 0xe, 4 /* DW_CFA_def_cfa_offset */
  12890. ADV(UW44, UW43)
  12891. .byte 0xe, 8 /* DW_CFA_def_cfa_offset */
  12892. .byte 0x80+8, 2 /* DW_CFA_offset %eip 2*-4 */
  12893. ADV(UW45, UW44)
  12894. .byte 0xe, raw_closure_T_FS+8 /* DW_CFA_def_cfa_offset */
  12895. ADV(UW46, UW45)
  12896. .byte 0x80+3, 3 /* DW_CFA_offset %ebx 3*-4 */
  12897. ADV(UW47, UW46)
  12898. .byte 0xc0+3 /* DW_CFA_restore %ebx */
  12899. ADV(UW48, UW47)
  12900. .byte 0xe, 8 /* DW_CFA_def_cfa_offset */
  12901. ADV(UW49, UW48)
  12902. .byte 0xe, raw_closure_T_FS+8 /* DW_CFA_def_cfa_offset */
  12903. ADV(UW50, UW49)
  12904. .byte 0xe, 8 /* DW_CFA_def_cfa_offset */
  12905. ADV(UW51, UW50)
  12906. .byte 0xe, raw_closure_T_FS+8 /* DW_CFA_def_cfa_offset */
  12907. .balign 4
  12908. L(EFDE9):
  12909. #endif /* !FFI_NO_RAW_API */
  12910. #ifdef _WIN32
  12911. .def @feat.00;
  12912. .scl 3;
  12913. .type 0;
  12914. .endef
  12915. .globl @feat.00
  12916. @feat.00 = 1
  12917. #endif
  12918. #ifdef __APPLE__
  12919. .subsections_via_symbols
  12920. .section __LD,__compact_unwind,regular,debug
  12921. /* compact unwind for ffi_call_i386 */
  12922. .long C(ffi_call_i386)
  12923. .set L1,L(UW5)-L(UW0)
  12924. .long L1
  12925. .long 0x04000000 /* use dwarf unwind info */
  12926. .long 0
  12927. .long 0
  12928. /* compact unwind for ffi_go_closure_EAX */
  12929. .long C(ffi_go_closure_EAX)
  12930. .set L2,L(UW8)-L(UW6)
  12931. .long L2
  12932. .long 0x04000000 /* use dwarf unwind info */
  12933. .long 0
  12934. .long 0
  12935. /* compact unwind for ffi_go_closure_ECX */
  12936. .long C(ffi_go_closure_ECX)
  12937. .set L3,L(UW11)-L(UW9)
  12938. .long L3
  12939. .long 0x04000000 /* use dwarf unwind info */
  12940. .long 0
  12941. .long 0
  12942. /* compact unwind for ffi_closure_i386 */
  12943. .long C(ffi_closure_i386)
  12944. .set L4,L(UW20)-L(UW12)
  12945. .long L4
  12946. .long 0x04000000 /* use dwarf unwind info */
  12947. .long 0
  12948. .long 0
  12949. /* compact unwind for ffi_go_closure_STDCALL */
  12950. .long C(ffi_go_closure_STDCALL)
  12951. .set L5,L(UW23)-L(UW21)
  12952. .long L5
  12953. .long 0x04000000 /* use dwarf unwind info */
  12954. .long 0
  12955. .long 0
  12956. /* compact unwind for ffi_closure_REGISTER */
  12957. .long C(ffi_closure_REGISTER)
  12958. .set L6,L(UW26)-L(UW24)
  12959. .long L6
  12960. .long 0x04000000 /* use dwarf unwind info */
  12961. .long 0
  12962. .long 0
  12963. /* compact unwind for ffi_closure_STDCALL */
  12964. .long C(ffi_closure_STDCALL)
  12965. .set L7,L(UW31)-L(UW27)
  12966. .long L7
  12967. .long 0x04000000 /* use dwarf unwind info */
  12968. .long 0
  12969. .long 0
  12970. /* compact unwind for ffi_closure_raw_SYSV */
  12971. .long C(ffi_closure_raw_SYSV)
  12972. .set L8,L(UW40)-L(UW32)
  12973. .long L8
  12974. .long 0x04000000 /* use dwarf unwind info */
  12975. .long 0
  12976. .long 0
  12977. /* compact unwind for ffi_closure_raw_THISCALL */
  12978. .long C(ffi_closure_raw_THISCALL)
  12979. .set L9,L(UW52)-L(UW41)
  12980. .long L9
  12981. .long 0x04000000 /* use dwarf unwind info */
  12982. .long 0
  12983. .long 0
  12984. #endif /* __APPLE__ */
  12985. #endif /* ifndef _MSC_VER */
  12986. #endif /* ifdef __i386__ */
  12987. #if defined __ELF__ && defined __linux__
  12988. .section .note.GNU-stack,"",@progbits
  12989. #endif
  12990. ====================File: src/x86/unix64.S====================
  12991. /* -----------------------------------------------------------------------
  12992. unix64.S - Copyright (c) 2013 The Written Word, Inc.
  12993. - Copyright (c) 2008 Red Hat, Inc
  12994. - Copyright (c) 2002 Bo Thorsen <bo@suse.de>
  12995. x86-64 Foreign Function Interface
  12996. Permission is hereby granted, free of charge, to any person obtaining
  12997. a copy of this software and associated documentation files (the
  12998. ``Software''), to deal in the Software without restriction, including
  12999. without limitation the rights to use, copy, modify, merge, publish,
  13000. distribute, sublicense, and/or sell copies of the Software, and to
  13001. permit persons to whom the Software is furnished to do so, subject to
  13002. the following conditions:
  13003. The above copyright notice and this permission notice shall be included
  13004. in all copies or substantial portions of the Software.
  13005. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  13006. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  13007. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  13008. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  13009. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  13010. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  13011. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  13012. DEALINGS IN THE SOFTWARE.
  13013. ----------------------------------------------------------------------- */
  13014. #ifdef __x86_64__
  13015. #define LIBFFI_ASM
  13016. #include <fficonfig.h>
  13017. #include <ffi.h>
  13018. #include "internal64.h"
  13019. #include "asmnames.h"
  13020. .text
  13021. /* This macro allows the safe creation of jump tables without an
  13022. actual table. The entry points into the table are all 8 bytes.
  13023. The use of ORG asserts that we're at the correct location. */
  13024. /* ??? The clang assembler doesn't handle .org with symbolic expressions. */
  13025. #if defined(__clang__) || defined(__APPLE__) || (defined (__sun__) && defined(__svr4__))
  13026. # define E(BASE, X) .balign 8
  13027. #else
  13028. # define E(BASE, X) .balign 8; .org BASE + X * 8
  13029. #endif
  13030. /* ffi_call_unix64 (void *args, unsigned long bytes, unsigned flags,
  13031. void *raddr, void (*fnaddr)(void));
  13032. Bit o trickiness here -- ARGS+BYTES is the base of the stack frame
  13033. for this function. This has been allocated by ffi_call. We also
  13034. deallocate some of the stack that has been alloca'd. */
  13035. .balign 8
  13036. .globl C(ffi_call_unix64)
  13037. FFI_HIDDEN(C(ffi_call_unix64))
  13038. C(ffi_call_unix64):
  13039. L(UW0):
  13040. movq (%rsp), %r10 /* Load return address. */
  13041. leaq (%rdi, %rsi), %rax /* Find local stack base. */
  13042. movq %rdx, (%rax) /* Save flags. */
  13043. movq %rcx, 8(%rax) /* Save raddr. */
  13044. movq %rbp, 16(%rax) /* Save old frame pointer. */
  13045. movq %r10, 24(%rax) /* Relocate return address. */
  13046. movq %rax, %rbp /* Finalize local stack frame. */
  13047. /* New stack frame based off rbp. This is a itty bit of unwind
  13048. trickery in that the CFA *has* changed. There is no easy way
  13049. to describe it correctly on entry to the function. Fortunately,
  13050. it doesn't matter too much since at all points we can correctly
  13051. unwind back to ffi_call. Note that the location to which we
  13052. moved the return address is (the new) CFA-8, so from the
  13053. perspective of the unwind info, it hasn't moved. */
  13054. L(UW1):
  13055. /* cfi_def_cfa(%rbp, 32) */
  13056. /* cfi_rel_offset(%rbp, 16) */
  13057. movq %rdi, %r10 /* Save a copy of the register area. */
  13058. movq %r8, %r11 /* Save a copy of the target fn. */
  13059. movl %r9d, %eax /* Set number of SSE registers. */
  13060. /* Load up all argument registers. */
  13061. movq (%r10), %rdi
  13062. movq 0x08(%r10), %rsi
  13063. movq 0x10(%r10), %rdx
  13064. movq 0x18(%r10), %rcx
  13065. movq 0x20(%r10), %r8
  13066. movq 0x28(%r10), %r9
  13067. movl 0xb0(%r10), %eax
  13068. testl %eax, %eax
  13069. jnz L(load_sse)
  13070. L(ret_from_load_sse):
  13071. /* Deallocate the reg arg area, except for r10, then load via pop. */
  13072. leaq 0xb8(%r10), %rsp
  13073. popq %r10
  13074. /* Call the user function. */
  13075. call *%r11
  13076. /* Deallocate stack arg area; local stack frame in redzone. */
  13077. leaq 24(%rbp), %rsp
  13078. movq 0(%rbp), %rcx /* Reload flags. */
  13079. movq 8(%rbp), %rdi /* Reload raddr. */
  13080. movq 16(%rbp), %rbp /* Reload old frame pointer. */
  13081. L(UW2):
  13082. /* cfi_remember_state */
  13083. /* cfi_def_cfa(%rsp, 8) */
  13084. /* cfi_restore(%rbp) */
  13085. /* The first byte of the flags contains the FFI_TYPE. */
  13086. cmpb $UNIX64_RET_LAST, %cl
  13087. movzbl %cl, %r10d
  13088. leaq L(store_table)(%rip), %r11
  13089. ja L(sa)
  13090. leaq (%r11, %r10, 8), %r10
  13091. /* Prep for the structure cases: scratch area in redzone. */
  13092. leaq -20(%rsp), %rsi
  13093. jmp *%r10
  13094. .balign 8
  13095. L(store_table):
  13096. E(L(store_table), UNIX64_RET_VOID)
  13097. ret
  13098. E(L(store_table), UNIX64_RET_UINT8)
  13099. movzbl %al, %eax
  13100. movq %rax, (%rdi)
  13101. ret
  13102. E(L(store_table), UNIX64_RET_UINT16)
  13103. movzwl %ax, %eax
  13104. movq %rax, (%rdi)
  13105. ret
  13106. E(L(store_table), UNIX64_RET_UINT32)
  13107. movl %eax, %eax
  13108. movq %rax, (%rdi)
  13109. ret
  13110. E(L(store_table), UNIX64_RET_SINT8)
  13111. movsbq %al, %rax
  13112. movq %rax, (%rdi)
  13113. ret
  13114. E(L(store_table), UNIX64_RET_SINT16)
  13115. movswq %ax, %rax
  13116. movq %rax, (%rdi)
  13117. ret
  13118. E(L(store_table), UNIX64_RET_SINT32)
  13119. cltq
  13120. movq %rax, (%rdi)
  13121. ret
  13122. E(L(store_table), UNIX64_RET_INT64)
  13123. movq %rax, (%rdi)
  13124. ret
  13125. E(L(store_table), UNIX64_RET_XMM32)
  13126. movd %xmm0, (%rdi)
  13127. ret
  13128. E(L(store_table), UNIX64_RET_XMM64)
  13129. movq %xmm0, (%rdi)
  13130. ret
  13131. E(L(store_table), UNIX64_RET_X87)
  13132. fstpt (%rdi)
  13133. ret
  13134. E(L(store_table), UNIX64_RET_X87_2)
  13135. fstpt (%rdi)
  13136. fstpt 16(%rdi)
  13137. ret
  13138. E(L(store_table), UNIX64_RET_ST_XMM0_RAX)
  13139. movq %rax, 8(%rsi)
  13140. jmp L(s3)
  13141. E(L(store_table), UNIX64_RET_ST_RAX_XMM0)
  13142. movq %xmm0, 8(%rsi)
  13143. jmp L(s2)
  13144. E(L(store_table), UNIX64_RET_ST_XMM0_XMM1)
  13145. movq %xmm1, 8(%rsi)
  13146. jmp L(s3)
  13147. E(L(store_table), UNIX64_RET_ST_RAX_RDX)
  13148. movq %rdx, 8(%rsi)
  13149. L(s2):
  13150. movq %rax, (%rsi)
  13151. shrl $UNIX64_SIZE_SHIFT, %ecx
  13152. rep movsb
  13153. ret
  13154. .balign 8
  13155. L(s3):
  13156. movq %xmm0, (%rsi)
  13157. shrl $UNIX64_SIZE_SHIFT, %ecx
  13158. rep movsb
  13159. ret
  13160. L(sa): call PLT(C(abort))
  13161. /* Many times we can avoid loading any SSE registers at all.
  13162. It's not worth an indirect jump to load the exact set of
  13163. SSE registers needed; zero or all is a good compromise. */
  13164. .balign 2
  13165. L(UW3):
  13166. /* cfi_restore_state */
  13167. L(load_sse):
  13168. movdqa 0x30(%r10), %xmm0
  13169. movdqa 0x40(%r10), %xmm1
  13170. movdqa 0x50(%r10), %xmm2
  13171. movdqa 0x60(%r10), %xmm3
  13172. movdqa 0x70(%r10), %xmm4
  13173. movdqa 0x80(%r10), %xmm5
  13174. movdqa 0x90(%r10), %xmm6
  13175. movdqa 0xa0(%r10), %xmm7
  13176. jmp L(ret_from_load_sse)
  13177. L(UW4):
  13178. ENDF(C(ffi_call_unix64))
  13179. /* 6 general registers, 8 vector registers,
  13180. 32 bytes of rvalue, 8 bytes of alignment. */
  13181. #define ffi_closure_OFS_G 0
  13182. #define ffi_closure_OFS_V (6*8)
  13183. #define ffi_closure_OFS_RVALUE (ffi_closure_OFS_V + 8*16)
  13184. #define ffi_closure_FS (ffi_closure_OFS_RVALUE + 32 + 8)
  13185. /* The location of rvalue within the red zone after deallocating the frame. */
  13186. #define ffi_closure_RED_RVALUE (ffi_closure_OFS_RVALUE - ffi_closure_FS)
  13187. .balign 2
  13188. .globl C(ffi_closure_unix64_sse)
  13189. FFI_HIDDEN(C(ffi_closure_unix64_sse))
  13190. C(ffi_closure_unix64_sse):
  13191. L(UW5):
  13192. subq $ffi_closure_FS, %rsp
  13193. L(UW6):
  13194. /* cfi_adjust_cfa_offset(ffi_closure_FS) */
  13195. movdqa %xmm0, ffi_closure_OFS_V+0x00(%rsp)
  13196. movdqa %xmm1, ffi_closure_OFS_V+0x10(%rsp)
  13197. movdqa %xmm2, ffi_closure_OFS_V+0x20(%rsp)
  13198. movdqa %xmm3, ffi_closure_OFS_V+0x30(%rsp)
  13199. movdqa %xmm4, ffi_closure_OFS_V+0x40(%rsp)
  13200. movdqa %xmm5, ffi_closure_OFS_V+0x50(%rsp)
  13201. movdqa %xmm6, ffi_closure_OFS_V+0x60(%rsp)
  13202. movdqa %xmm7, ffi_closure_OFS_V+0x70(%rsp)
  13203. jmp L(sse_entry1)
  13204. L(UW7):
  13205. ENDF(C(ffi_closure_unix64_sse))
  13206. .balign 2
  13207. .globl C(ffi_closure_unix64)
  13208. FFI_HIDDEN(C(ffi_closure_unix64))
  13209. C(ffi_closure_unix64):
  13210. L(UW8):
  13211. subq $ffi_closure_FS, %rsp
  13212. L(UW9):
  13213. /* cfi_adjust_cfa_offset(ffi_closure_FS) */
  13214. L(sse_entry1):
  13215. movq %rdi, ffi_closure_OFS_G+0x00(%rsp)
  13216. movq %rsi, ffi_closure_OFS_G+0x08(%rsp)
  13217. movq %rdx, ffi_closure_OFS_G+0x10(%rsp)
  13218. movq %rcx, ffi_closure_OFS_G+0x18(%rsp)
  13219. movq %r8, ffi_closure_OFS_G+0x20(%rsp)
  13220. movq %r9, ffi_closure_OFS_G+0x28(%rsp)
  13221. #ifdef __ILP32__
  13222. movl FFI_TRAMPOLINE_SIZE(%r10), %edi /* Load cif */
  13223. movl FFI_TRAMPOLINE_SIZE+4(%r10), %esi /* Load fun */
  13224. movl FFI_TRAMPOLINE_SIZE+8(%r10), %edx /* Load user_data */
  13225. #else
  13226. movq FFI_TRAMPOLINE_SIZE(%r10), %rdi /* Load cif */
  13227. movq FFI_TRAMPOLINE_SIZE+8(%r10), %rsi /* Load fun */
  13228. movq FFI_TRAMPOLINE_SIZE+16(%r10), %rdx /* Load user_data */
  13229. #endif
  13230. L(do_closure):
  13231. leaq ffi_closure_OFS_RVALUE(%rsp), %rcx /* Load rvalue */
  13232. movq %rsp, %r8 /* Load reg_args */
  13233. leaq ffi_closure_FS+8(%rsp), %r9 /* Load argp */
  13234. call PLT(C(ffi_closure_unix64_inner))
  13235. /* Deallocate stack frame early; return value is now in redzone. */
  13236. addq $ffi_closure_FS, %rsp
  13237. L(UW10):
  13238. /* cfi_adjust_cfa_offset(-ffi_closure_FS) */
  13239. /* The first byte of the return value contains the FFI_TYPE. */
  13240. cmpb $UNIX64_RET_LAST, %al
  13241. movzbl %al, %r10d
  13242. leaq L(load_table)(%rip), %r11
  13243. ja L(la)
  13244. leaq (%r11, %r10, 8), %r10
  13245. leaq ffi_closure_RED_RVALUE(%rsp), %rsi
  13246. jmp *%r10
  13247. .balign 8
  13248. L(load_table):
  13249. E(L(load_table), UNIX64_RET_VOID)
  13250. ret
  13251. E(L(load_table), UNIX64_RET_UINT8)
  13252. movzbl (%rsi), %eax
  13253. ret
  13254. E(L(load_table), UNIX64_RET_UINT16)
  13255. movzwl (%rsi), %eax
  13256. ret
  13257. E(L(load_table), UNIX64_RET_UINT32)
  13258. movl (%rsi), %eax
  13259. ret
  13260. E(L(load_table), UNIX64_RET_SINT8)
  13261. movsbl (%rsi), %eax
  13262. ret
  13263. E(L(load_table), UNIX64_RET_SINT16)
  13264. movswl (%rsi), %eax
  13265. ret
  13266. E(L(load_table), UNIX64_RET_SINT32)
  13267. movl (%rsi), %eax
  13268. ret
  13269. E(L(load_table), UNIX64_RET_INT64)
  13270. movq (%rsi), %rax
  13271. ret
  13272. E(L(load_table), UNIX64_RET_XMM32)
  13273. movd (%rsi), %xmm0
  13274. ret
  13275. E(L(load_table), UNIX64_RET_XMM64)
  13276. movq (%rsi), %xmm0
  13277. ret
  13278. E(L(load_table), UNIX64_RET_X87)
  13279. fldt (%rsi)
  13280. ret
  13281. E(L(load_table), UNIX64_RET_X87_2)
  13282. fldt 16(%rsi)
  13283. fldt (%rsi)
  13284. ret
  13285. E(L(load_table), UNIX64_RET_ST_XMM0_RAX)
  13286. movq 8(%rsi), %rax
  13287. jmp L(l3)
  13288. E(L(load_table), UNIX64_RET_ST_RAX_XMM0)
  13289. movq 8(%rsi), %xmm0
  13290. jmp L(l2)
  13291. E(L(load_table), UNIX64_RET_ST_XMM0_XMM1)
  13292. movq 8(%rsi), %xmm1
  13293. jmp L(l3)
  13294. E(L(load_table), UNIX64_RET_ST_RAX_RDX)
  13295. movq 8(%rsi), %rdx
  13296. L(l2):
  13297. movq (%rsi), %rax
  13298. ret
  13299. .balign 8
  13300. L(l3):
  13301. movq (%rsi), %xmm0
  13302. ret
  13303. L(la): call PLT(C(abort))
  13304. L(UW11):
  13305. ENDF(C(ffi_closure_unix64))
  13306. .balign 2
  13307. .globl C(ffi_go_closure_unix64_sse)
  13308. FFI_HIDDEN(C(ffi_go_closure_unix64_sse))
  13309. C(ffi_go_closure_unix64_sse):
  13310. L(UW12):
  13311. subq $ffi_closure_FS, %rsp
  13312. L(UW13):
  13313. /* cfi_adjust_cfa_offset(ffi_closure_FS) */
  13314. movdqa %xmm0, ffi_closure_OFS_V+0x00(%rsp)
  13315. movdqa %xmm1, ffi_closure_OFS_V+0x10(%rsp)
  13316. movdqa %xmm2, ffi_closure_OFS_V+0x20(%rsp)
  13317. movdqa %xmm3, ffi_closure_OFS_V+0x30(%rsp)
  13318. movdqa %xmm4, ffi_closure_OFS_V+0x40(%rsp)
  13319. movdqa %xmm5, ffi_closure_OFS_V+0x50(%rsp)
  13320. movdqa %xmm6, ffi_closure_OFS_V+0x60(%rsp)
  13321. movdqa %xmm7, ffi_closure_OFS_V+0x70(%rsp)
  13322. jmp L(sse_entry2)
  13323. L(UW14):
  13324. ENDF(C(ffi_go_closure_unix64_sse))
  13325. .balign 2
  13326. .globl C(ffi_go_closure_unix64)
  13327. FFI_HIDDEN(C(ffi_go_closure_unix64))
  13328. C(ffi_go_closure_unix64):
  13329. L(UW15):
  13330. subq $ffi_closure_FS, %rsp
  13331. L(UW16):
  13332. /* cfi_adjust_cfa_offset(ffi_closure_FS) */
  13333. L(sse_entry2):
  13334. movq %rdi, ffi_closure_OFS_G+0x00(%rsp)
  13335. movq %rsi, ffi_closure_OFS_G+0x08(%rsp)
  13336. movq %rdx, ffi_closure_OFS_G+0x10(%rsp)
  13337. movq %rcx, ffi_closure_OFS_G+0x18(%rsp)
  13338. movq %r8, ffi_closure_OFS_G+0x20(%rsp)
  13339. movq %r9, ffi_closure_OFS_G+0x28(%rsp)
  13340. #ifdef __ILP32__
  13341. movl 4(%r10), %edi /* Load cif */
  13342. movl 8(%r10), %esi /* Load fun */
  13343. movl %r10d, %edx /* Load closure (user_data) */
  13344. #else
  13345. movq 8(%r10), %rdi /* Load cif */
  13346. movq 16(%r10), %rsi /* Load fun */
  13347. movq %r10, %rdx /* Load closure (user_data) */
  13348. #endif
  13349. jmp L(do_closure)
  13350. L(UW17):
  13351. ENDF(C(ffi_go_closure_unix64))
  13352. /* Sadly, OSX cctools-as doesn't understand .cfi directives at all. */
  13353. #ifdef __APPLE__
  13354. .section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support
  13355. EHFrame0:
  13356. #elif defined(HAVE_AS_X86_64_UNWIND_SECTION_TYPE)
  13357. .section .eh_frame,"a",@unwind
  13358. #else
  13359. .section .eh_frame,"a",@progbits
  13360. #endif
  13361. #ifdef HAVE_AS_X86_PCREL
  13362. # define PCREL(X) X - .
  13363. #else
  13364. # define PCREL(X) X@rel
  13365. #endif
  13366. /* Simplify advancing between labels. Assume DW_CFA_advance_loc1 fits. */
  13367. #define ADV(N, P) .byte 2, L(N)-L(P)
  13368. .balign 8
  13369. L(CIE):
  13370. .set L(set0),L(ECIE)-L(SCIE)
  13371. .long L(set0) /* CIE Length */
  13372. L(SCIE):
  13373. .long 0 /* CIE Identifier Tag */
  13374. .byte 1 /* CIE Version */
  13375. .ascii "zR\0" /* CIE Augmentation */
  13376. .byte 1 /* CIE Code Alignment Factor */
  13377. .byte 0x78 /* CIE Data Alignment Factor */
  13378. .byte 0x10 /* CIE RA Column */
  13379. .byte 1 /* Augmentation size */
  13380. .byte 0x1b /* FDE Encoding (pcrel sdata4) */
  13381. .byte 0xc, 7, 8 /* DW_CFA_def_cfa, %rsp offset 8 */
  13382. .byte 0x80+16, 1 /* DW_CFA_offset, %rip offset 1*-8 */
  13383. .balign 8
  13384. L(ECIE):
  13385. .set L(set1),L(EFDE1)-L(SFDE1)
  13386. .long L(set1) /* FDE Length */
  13387. L(SFDE1):
  13388. .long L(SFDE1)-L(CIE) /* FDE CIE offset */
  13389. .long PCREL(L(UW0)) /* Initial location */
  13390. .long L(UW4)-L(UW0) /* Address range */
  13391. .byte 0 /* Augmentation size */
  13392. ADV(UW1, UW0)
  13393. .byte 0xc, 6, 32 /* DW_CFA_def_cfa, %rbp 32 */
  13394. .byte 0x80+6, 2 /* DW_CFA_offset, %rbp 2*-8 */
  13395. ADV(UW2, UW1)
  13396. .byte 0xa /* DW_CFA_remember_state */
  13397. .byte 0xc, 7, 8 /* DW_CFA_def_cfa, %rsp 8 */
  13398. .byte 0xc0+6 /* DW_CFA_restore, %rbp */
  13399. ADV(UW3, UW2)
  13400. .byte 0xb /* DW_CFA_restore_state */
  13401. .balign 8
  13402. L(EFDE1):
  13403. .set L(set2),L(EFDE2)-L(SFDE2)
  13404. .long L(set2) /* FDE Length */
  13405. L(SFDE2):
  13406. .long L(SFDE2)-L(CIE) /* FDE CIE offset */
  13407. .long PCREL(L(UW5)) /* Initial location */
  13408. .long L(UW7)-L(UW5) /* Address range */
  13409. .byte 0 /* Augmentation size */
  13410. ADV(UW6, UW5)
  13411. .byte 0xe /* DW_CFA_def_cfa_offset */
  13412. .byte ffi_closure_FS + 8, 1 /* uleb128, assuming 128 <= FS < 255 */
  13413. .balign 8
  13414. L(EFDE2):
  13415. .set L(set3),L(EFDE3)-L(SFDE3)
  13416. .long L(set3) /* FDE Length */
  13417. L(SFDE3):
  13418. .long L(SFDE3)-L(CIE) /* FDE CIE offset */
  13419. .long PCREL(L(UW8)) /* Initial location */
  13420. .long L(UW11)-L(UW8) /* Address range */
  13421. .byte 0 /* Augmentation size */
  13422. ADV(UW9, UW8)
  13423. .byte 0xe /* DW_CFA_def_cfa_offset */
  13424. .byte ffi_closure_FS + 8, 1 /* uleb128, assuming 128 <= FS < 255 */
  13425. ADV(UW10, UW9)
  13426. .byte 0xe, 8 /* DW_CFA_def_cfa_offset 8 */
  13427. L(EFDE3):
  13428. .set L(set4),L(EFDE4)-L(SFDE4)
  13429. .long L(set4) /* FDE Length */
  13430. L(SFDE4):
  13431. .long L(SFDE4)-L(CIE) /* FDE CIE offset */
  13432. .long PCREL(L(UW12)) /* Initial location */
  13433. .long L(UW14)-L(UW12) /* Address range */
  13434. .byte 0 /* Augmentation size */
  13435. ADV(UW13, UW12)
  13436. .byte 0xe /* DW_CFA_def_cfa_offset */
  13437. .byte ffi_closure_FS + 8, 1 /* uleb128, assuming 128 <= FS < 255 */
  13438. .balign 8
  13439. L(EFDE4):
  13440. .set L(set5),L(EFDE5)-L(SFDE5)
  13441. .long L(set5) /* FDE Length */
  13442. L(SFDE5):
  13443. .long L(SFDE5)-L(CIE) /* FDE CIE offset */
  13444. .long PCREL(L(UW15)) /* Initial location */
  13445. .long L(UW17)-L(UW15) /* Address range */
  13446. .byte 0 /* Augmentation size */
  13447. ADV(UW16, UW15)
  13448. .byte 0xe /* DW_CFA_def_cfa_offset */
  13449. .byte ffi_closure_FS + 8, 1 /* uleb128, assuming 128 <= FS < 255 */
  13450. .balign 8
  13451. L(EFDE5):
  13452. #ifdef __APPLE__
  13453. .subsections_via_symbols
  13454. .section __LD,__compact_unwind,regular,debug
  13455. /* compact unwind for ffi_call_unix64 */
  13456. .quad C(ffi_call_unix64)
  13457. .set L1,L(UW4)-L(UW0)
  13458. .long L1
  13459. .long 0x04000000 /* use dwarf unwind info */
  13460. .quad 0
  13461. .quad 0
  13462. /* compact unwind for ffi_closure_unix64_sse */
  13463. .quad C(ffi_closure_unix64_sse)
  13464. .set L2,L(UW7)-L(UW5)
  13465. .long L2
  13466. .long 0x04000000 /* use dwarf unwind info */
  13467. .quad 0
  13468. .quad 0
  13469. /* compact unwind for ffi_closure_unix64 */
  13470. .quad C(ffi_closure_unix64)
  13471. .set L3,L(UW11)-L(UW8)
  13472. .long L3
  13473. .long 0x04000000 /* use dwarf unwind info */
  13474. .quad 0
  13475. .quad 0
  13476. /* compact unwind for ffi_go_closure_unix64_sse */
  13477. .quad C(ffi_go_closure_unix64_sse)
  13478. .set L4,L(UW14)-L(UW12)
  13479. .long L4
  13480. .long 0x04000000 /* use dwarf unwind info */
  13481. .quad 0
  13482. .quad 0
  13483. /* compact unwind for ffi_go_closure_unix64 */
  13484. .quad C(ffi_go_closure_unix64)
  13485. .set L5,L(UW17)-L(UW15)
  13486. .long L5
  13487. .long 0x04000000 /* use dwarf unwind info */
  13488. .quad 0
  13489. .quad 0
  13490. #endif
  13491. #endif /* __x86_64__ */
  13492. #if defined __ELF__ && defined __linux__
  13493. .section .note.GNU-stack,"",@progbits
  13494. #endif
  13495. ====================MIT====================
  13496. Permission is hereby granted, free of charge, to any person
  13497. obtaining a copy of this software and associated documentation
  13498. files (the ``Software''), to deal in the Software without
  13499. restriction, including without limitation the rights to use, copy,
  13500. modify, merge, publish, distribute, sublicense, and/or sell copies
  13501. of the Software, and to permit persons to whom the Software is
  13502. furnished to do so, subject to the following conditions:
  13503. The above copyright notice and this permission notice shall be
  13504. included in all copies or substantial portions of the Software.
  13505. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  13506. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  13507. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  13508. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  13509. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  13510. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  13511. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  13512. DEALINGS IN THE SOFTWARE.
  13513. ====================MIT====================
  13514. Permission is hereby granted, free of charge, to any person obtaining
  13515. a copy of this software and associated documentation files (the
  13516. ``Software''), to deal in the Software without restriction, including
  13517. without limitation the rights to use, copy, modify, merge, publish,
  13518. distribute, sublicense, and/or sell copies of the Software, and to
  13519. permit persons to whom the Software is furnished to do so, subject to
  13520. the following conditions:
  13521. The above copyright notice and this permission notice shall be included
  13522. in all copies or substantial portions of the Software.
  13523. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  13524. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  13525. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  13526. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  13527. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  13528. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  13529. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  13530. DEALINGS IN THE SOFTWARE.
  13531. ====================MIT====================
  13532. Permission is hereby granted, free of charge, to any person obtaining
  13533. a copy of this software and associated documentation files (the
  13534. ``Software''), to deal in the Software without restriction, including
  13535. without limitation the rights to use, copy, modify, merge, publish,
  13536. distribute, sublicense, and/or sell copies of the Software, and to
  13537. permit persons to whom the Software is furnished to do so, subject to
  13538. the following conditions:
  13539. The above copyright notice and this permission notice shall be included
  13540. in all copies or substantial portions of the Software.
  13541. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
  13542. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  13543. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  13544. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
  13545. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  13546. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  13547. OTHER DEALINGS IN THE SOFTWARE.
  13548. ====================MIT====================
  13549. Permission is hereby granted, free of charge, to any person obtaining
  13550. a copy of this software and associated documentation files (the
  13551. ``Software''), to deal in the Software without restriction, including
  13552. without limitation the rights to use, copy, modify, merge, publish,
  13553. distribute, sublicense, and/or sell copies of the Software, and to
  13554. permit persons to whom the Software is furnished to do so, subject to
  13555. the following conditions:
  13556. The above copyright notice and this permission notice shall be
  13557. included in all copies or substantial portions of the Software.
  13558. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  13559. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  13560. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  13561. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  13562. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  13563. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  13564. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  13565. ====================MIT====================
  13566. Permission is hereby granted, free of charge, to any person obtaining
  13567. a copy of this software and associated documentation files (the
  13568. ``Software''), to deal in the Software without restriction, including
  13569. without limitation the rights to use, copy, modify, merge, publish,
  13570. distribute, sublicense, and/or sell copies of the Software, and to
  13571. permit persons to whom the Software is furnished to do so, subject to
  13572. the following conditions:
  13573. The above copyright notice and this permission notice shall be
  13574. included in all copies or substantial portions of the Software.
  13575. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  13576. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  13577. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  13578. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  13579. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  13580. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  13581. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  13582. ====================MIT====================
  13583. Permission is hereby granted, free of charge, to any person obtaining
  13584. a copy of this software and associated documentation files (the
  13585. ``Software''), to deal in the Software without restriction, including
  13586. without limitation the rights to use, copy, modify, merge, publish,
  13587. distribute, sublicense, and/or sell copies of the Software, and to
  13588. permit persons to whom the Software is furnished to do so, subject to
  13589. the following conditions:
  13590. The above copyright notice and this permission notice shall be
  13591. included in all copies or substantial portions of the Software.
  13592. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  13593. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  13594. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  13595. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  13596. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  13597. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  13598. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */