linux_syscall_support.h 178 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488
  1. /* Copyright (c) 2005-2011, Google Inc.
  2. * All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above
  11. * copyright notice, this list of conditions and the following disclaimer
  12. * in the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Google Inc. nor the names of its
  15. * contributors may be used to endorse or promote products derived from
  16. * this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. * ---
  31. * Author: Markus Gutschke
  32. */
  33. /* This file includes Linux-specific support functions common to the
  34. * coredumper and the thread lister; primarily, this is a collection
  35. * of direct system calls, and a couple of symbols missing from
  36. * standard header files.
  37. * There are a few options that the including file can set to control
  38. * the behavior of this file:
  39. *
  40. * SYS_CPLUSPLUS:
  41. * The entire header file will normally be wrapped in 'extern "C" { }",
  42. * making it suitable for compilation as both C and C++ source. If you
  43. * do not want to do this, you can set the SYS_CPLUSPLUS macro to inhibit
  44. * the wrapping. N.B. doing so will suppress inclusion of all prerequisite
  45. * system header files, too. It is the caller's responsibility to provide
  46. * the necessary definitions.
  47. *
  48. * SYS_ERRNO:
  49. * All system calls will update "errno" unless overriden by setting the
  50. * SYS_ERRNO macro prior to including this file. SYS_ERRNO should be
  51. * an l-value.
  52. *
  53. * SYS_INLINE:
  54. * New symbols will be defined "static inline", unless overridden by
  55. * the SYS_INLINE macro.
  56. *
  57. * SYS_LINUX_SYSCALL_SUPPORT_H
  58. * This macro is used to avoid multiple inclusions of this header file.
  59. * If you need to include this file more than once, make sure to
  60. * unset SYS_LINUX_SYSCALL_SUPPORT_H before each inclusion.
  61. *
  62. * SYS_PREFIX:
  63. * New system calls will have a prefix of "sys_" unless overridden by
  64. * the SYS_PREFIX macro. Valid values for this macro are [0..9] which
  65. * results in prefixes "sys[0..9]_". It is also possible to set this
  66. * macro to -1, which avoids all prefixes.
  67. *
  68. * SYS_SYSCALL_ENTRYPOINT:
  69. * Some applications (such as sandboxes that filter system calls), need
  70. * to be able to run custom-code each time a system call is made. If this
  71. * macro is defined, it expands to the name of a "common" symbol. If
  72. * this symbol is assigned a non-NULL pointer value, it is used as the
  73. * address of the system call entrypoint.
  74. * A pointer to this symbol can be obtained by calling
  75. * get_syscall_entrypoint()
  76. *
  77. * This file defines a few internal symbols that all start with "LSS_".
  78. * Do not access these symbols from outside this file. They are not part
  79. * of the supported API.
  80. */
  81. #ifndef SYS_LINUX_SYSCALL_SUPPORT_H
  82. #define SYS_LINUX_SYSCALL_SUPPORT_H
  83. /* We currently only support x86-32, x86-64, ARM, MIPS, PPC, s390 and s390x
  84. * on Linux.
  85. * Porting to other related platforms should not be difficult.
  86. */
  87. #if (defined(__i386__) || defined(__x86_64__) || defined(__ARM_ARCH_3__) || \
  88. defined(__mips__) || defined(__PPC__) || defined(__ARM_EABI__) || \
  89. defined(__aarch64__) || defined(__s390__)) \
  90. && (defined(__linux) || defined(__ANDROID__))
  91. #ifndef SYS_CPLUSPLUS
  92. #ifdef __cplusplus
  93. /* Some system header files in older versions of gcc neglect to properly
  94. * handle being included from C++. As it appears to be harmless to have
  95. * multiple nested 'extern "C"' blocks, just add another one here.
  96. */
  97. extern "C" {
  98. #endif
  99. #include <errno.h>
  100. #include <fcntl.h>
  101. #include <sched.h>
  102. #include <signal.h>
  103. #include <stdarg.h>
  104. #include <stddef.h>
  105. #include <stdint.h>
  106. #include <string.h>
  107. #include <sys/ptrace.h>
  108. #include <sys/resource.h>
  109. #include <sys/time.h>
  110. #include <sys/types.h>
  111. #include <sys/syscall.h>
  112. #include <unistd.h>
  113. #include <linux/unistd.h>
  114. #include <endian.h>
  115. #ifdef __mips__
  116. /* Include definitions of the ABI currently in use. */
  117. #ifdef __ANDROID__
  118. /* Android doesn't have sgidefs.h, but does have asm/sgidefs.h,
  119. * which has the definitions we need.
  120. */
  121. #include <asm/sgidefs.h>
  122. #else
  123. #include <sgidefs.h>
  124. #endif
  125. #endif
  126. #endif
  127. /* The Android NDK's <sys/stat.h> #defines these macros as aliases
  128. * to their non-64 counterparts. To avoid naming conflict, remove them. */
  129. #ifdef __ANDROID__
  130. /* These are restored by the corresponding #pragma pop_macro near
  131. * the end of this file. */
  132. # pragma push_macro("stat64")
  133. # pragma push_macro("fstat64")
  134. # pragma push_macro("lstat64")
  135. # undef stat64
  136. # undef fstat64
  137. # undef lstat64
  138. #endif
  139. /* As glibc often provides subtly incompatible data structures (and implicit
  140. * wrapper functions that convert them), we provide our own kernel data
  141. * structures for use by the system calls.
  142. * These structures have been developed by using Linux 2.6.23 headers for
  143. * reference. Note though, we do not care about exact API compatibility
  144. * with the kernel, and in fact the kernel often does not have a single
  145. * API that works across architectures. Instead, we try to mimic the glibc
  146. * API where reasonable, and only guarantee ABI compatibility with the
  147. * kernel headers.
  148. * Most notably, here are a few changes that were made to the structures
  149. * defined by kernel headers:
  150. *
  151. * - we only define structures, but not symbolic names for kernel data
  152. * types. For the latter, we directly use the native C datatype
  153. * (i.e. "unsigned" instead of "mode_t").
  154. * - in a few cases, it is possible to define identical structures for
  155. * both 32bit (e.g. i386) and 64bit (e.g. x86-64) platforms by
  156. * standardizing on the 64bit version of the data types. In particular,
  157. * this means that we use "unsigned" where the 32bit headers say
  158. * "unsigned long".
  159. * - overall, we try to minimize the number of cases where we need to
  160. * conditionally define different structures.
  161. * - the "struct kernel_sigaction" class of structures have been
  162. * modified to more closely mimic glibc's API by introducing an
  163. * anonymous union for the function pointer.
  164. * - a small number of field names had to have an underscore appended to
  165. * them, because glibc defines a global macro by the same name.
  166. */
  167. /* include/linux/dirent.h */
  168. struct kernel_dirent64 {
  169. unsigned long long d_ino;
  170. long long d_off;
  171. unsigned short d_reclen;
  172. unsigned char d_type;
  173. char d_name[256];
  174. };
  175. /* include/linux/dirent.h */
  176. #if defined(__aarch64__)
  177. // aarch64 only defines dirent64, just uses that for dirent too.
  178. #define kernel_dirent kernel_dirent64
  179. #else
  180. struct kernel_dirent {
  181. long d_ino;
  182. long d_off;
  183. unsigned short d_reclen;
  184. char d_name[256];
  185. };
  186. #endif
  187. /* include/linux/uio.h */
  188. struct kernel_iovec {
  189. void *iov_base;
  190. unsigned long iov_len;
  191. };
  192. /* include/linux/socket.h */
  193. struct kernel_msghdr {
  194. void *msg_name;
  195. int msg_namelen;
  196. struct kernel_iovec*msg_iov;
  197. unsigned long msg_iovlen;
  198. void *msg_control;
  199. unsigned long msg_controllen;
  200. unsigned msg_flags;
  201. };
  202. /* include/asm-generic/poll.h */
  203. struct kernel_pollfd {
  204. int fd;
  205. short events;
  206. short revents;
  207. };
  208. /* include/linux/resource.h */
  209. struct kernel_rlimit {
  210. unsigned long rlim_cur;
  211. unsigned long rlim_max;
  212. };
  213. /* include/linux/time.h */
  214. struct kernel_timespec {
  215. long tv_sec;
  216. long tv_nsec;
  217. };
  218. /* include/linux/time.h */
  219. struct kernel_timeval {
  220. long tv_sec;
  221. long tv_usec;
  222. };
  223. /* include/linux/resource.h */
  224. struct kernel_rusage {
  225. struct kernel_timeval ru_utime;
  226. struct kernel_timeval ru_stime;
  227. long ru_maxrss;
  228. long ru_ixrss;
  229. long ru_idrss;
  230. long ru_isrss;
  231. long ru_minflt;
  232. long ru_majflt;
  233. long ru_nswap;
  234. long ru_inblock;
  235. long ru_oublock;
  236. long ru_msgsnd;
  237. long ru_msgrcv;
  238. long ru_nsignals;
  239. long ru_nvcsw;
  240. long ru_nivcsw;
  241. };
  242. #if defined(__i386__) || defined(__ARM_EABI__) || defined(__ARM_ARCH_3__) \
  243. || defined(__PPC__) || (defined(__s390__) && !defined(__s390x__))
  244. /* include/asm-{arm,i386,mips,ppc}/signal.h */
  245. struct kernel_old_sigaction {
  246. union {
  247. void (*sa_handler_)(int);
  248. void (*sa_sigaction_)(int, siginfo_t *, void *);
  249. };
  250. unsigned long sa_mask;
  251. unsigned long sa_flags;
  252. void (*sa_restorer)(void);
  253. } __attribute__((packed,aligned(4)));
  254. #elif (defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI32)
  255. #define kernel_old_sigaction kernel_sigaction
  256. #elif defined(__aarch64__)
  257. // No kernel_old_sigaction defined for arm64.
  258. #endif
  259. /* Some kernel functions (e.g. sigaction() in 2.6.23) require that the
  260. * exactly match the size of the signal set, even though the API was
  261. * intended to be extensible. We define our own KERNEL_NSIG to deal with
  262. * this.
  263. * Please note that glibc provides signals [1.._NSIG-1], whereas the
  264. * kernel (and this header) provides the range [1..KERNEL_NSIG]. The
  265. * actual number of signals is obviously the same, but the constants
  266. * differ by one.
  267. */
  268. #ifdef __mips__
  269. #define KERNEL_NSIG 128
  270. #else
  271. #define KERNEL_NSIG 64
  272. #endif
  273. /* include/asm-{arm,aarch64,i386,mips,x86_64}/signal.h */
  274. struct kernel_sigset_t {
  275. unsigned long sig[(KERNEL_NSIG + 8*sizeof(unsigned long) - 1)/
  276. (8*sizeof(unsigned long))];
  277. };
  278. /* include/asm-{arm,i386,mips,x86_64,ppc}/signal.h */
  279. struct kernel_sigaction {
  280. #ifdef __mips__
  281. unsigned long sa_flags;
  282. union {
  283. void (*sa_handler_)(int);
  284. void (*sa_sigaction_)(int, siginfo_t *, void *);
  285. };
  286. struct kernel_sigset_t sa_mask;
  287. #else
  288. union {
  289. void (*sa_handler_)(int);
  290. void (*sa_sigaction_)(int, siginfo_t *, void *);
  291. };
  292. unsigned long sa_flags;
  293. void (*sa_restorer)(void);
  294. struct kernel_sigset_t sa_mask;
  295. #endif
  296. };
  297. /* include/linux/socket.h */
  298. struct kernel_sockaddr {
  299. unsigned short sa_family;
  300. char sa_data[14];
  301. };
  302. /* include/asm-{arm,aarch64,i386,mips,ppc,s390}/stat.h */
  303. #ifdef __mips__
  304. #if _MIPS_SIM == _MIPS_SIM_ABI64
  305. struct kernel_stat {
  306. #else
  307. struct kernel_stat64 {
  308. #endif
  309. unsigned st_dev;
  310. unsigned __pad0[3];
  311. unsigned long long st_ino;
  312. unsigned st_mode;
  313. unsigned st_nlink;
  314. unsigned st_uid;
  315. unsigned st_gid;
  316. unsigned st_rdev;
  317. unsigned __pad1[3];
  318. long long st_size;
  319. unsigned st_atime_;
  320. unsigned st_atime_nsec_;
  321. unsigned st_mtime_;
  322. unsigned st_mtime_nsec_;
  323. unsigned st_ctime_;
  324. unsigned st_ctime_nsec_;
  325. unsigned st_blksize;
  326. unsigned __pad2;
  327. unsigned long long st_blocks;
  328. };
  329. #elif defined __PPC__
  330. struct kernel_stat64 {
  331. unsigned long long st_dev;
  332. unsigned long long st_ino;
  333. unsigned st_mode;
  334. unsigned st_nlink;
  335. unsigned st_uid;
  336. unsigned st_gid;
  337. unsigned long long st_rdev;
  338. unsigned short int __pad2;
  339. long long st_size;
  340. long st_blksize;
  341. long long st_blocks;
  342. long st_atime_;
  343. unsigned long st_atime_nsec_;
  344. long st_mtime_;
  345. unsigned long st_mtime_nsec_;
  346. long st_ctime_;
  347. unsigned long st_ctime_nsec_;
  348. unsigned long __unused4;
  349. unsigned long __unused5;
  350. };
  351. #else
  352. struct kernel_stat64 {
  353. unsigned long long st_dev;
  354. unsigned char __pad0[4];
  355. unsigned __st_ino;
  356. unsigned st_mode;
  357. unsigned st_nlink;
  358. unsigned st_uid;
  359. unsigned st_gid;
  360. unsigned long long st_rdev;
  361. unsigned char __pad3[4];
  362. long long st_size;
  363. unsigned st_blksize;
  364. unsigned long long st_blocks;
  365. unsigned st_atime_;
  366. unsigned st_atime_nsec_;
  367. unsigned st_mtime_;
  368. unsigned st_mtime_nsec_;
  369. unsigned st_ctime_;
  370. unsigned st_ctime_nsec_;
  371. unsigned long long st_ino;
  372. };
  373. #endif
  374. /* include/asm-{arm,aarch64,i386,mips,x86_64,ppc,s390}/stat.h */
  375. #if defined(__i386__) || defined(__ARM_ARCH_3__) || defined(__ARM_EABI__)
  376. struct kernel_stat {
  377. /* The kernel headers suggest that st_dev and st_rdev should be 32bit
  378. * quantities encoding 12bit major and 20bit minor numbers in an interleaved
  379. * format. In reality, we do not see useful data in the top bits. So,
  380. * we'll leave the padding in here, until we find a better solution.
  381. */
  382. unsigned short st_dev;
  383. short pad1;
  384. unsigned st_ino;
  385. unsigned short st_mode;
  386. unsigned short st_nlink;
  387. unsigned short st_uid;
  388. unsigned short st_gid;
  389. unsigned short st_rdev;
  390. short pad2;
  391. unsigned st_size;
  392. unsigned st_blksize;
  393. unsigned st_blocks;
  394. unsigned st_atime_;
  395. unsigned st_atime_nsec_;
  396. unsigned st_mtime_;
  397. unsigned st_mtime_nsec_;
  398. unsigned st_ctime_;
  399. unsigned st_ctime_nsec_;
  400. unsigned __unused4;
  401. unsigned __unused5;
  402. };
  403. #elif defined(__x86_64__)
  404. struct kernel_stat {
  405. uint64_t st_dev;
  406. uint64_t st_ino;
  407. uint64_t st_nlink;
  408. unsigned st_mode;
  409. unsigned st_uid;
  410. unsigned st_gid;
  411. unsigned __pad0;
  412. uint64_t st_rdev;
  413. int64_t st_size;
  414. int64_t st_blksize;
  415. int64_t st_blocks;
  416. uint64_t st_atime_;
  417. uint64_t st_atime_nsec_;
  418. uint64_t st_mtime_;
  419. uint64_t st_mtime_nsec_;
  420. uint64_t st_ctime_;
  421. uint64_t st_ctime_nsec_;
  422. int64_t __unused4[3];
  423. };
  424. #elif defined(__PPC__)
  425. struct kernel_stat {
  426. unsigned st_dev;
  427. unsigned long st_ino; // ino_t
  428. unsigned long st_mode; // mode_t
  429. unsigned short st_nlink; // nlink_t
  430. unsigned st_uid; // uid_t
  431. unsigned st_gid; // gid_t
  432. unsigned st_rdev;
  433. long st_size; // off_t
  434. unsigned long st_blksize;
  435. unsigned long st_blocks;
  436. unsigned long st_atime_;
  437. unsigned long st_atime_nsec_;
  438. unsigned long st_mtime_;
  439. unsigned long st_mtime_nsec_;
  440. unsigned long st_ctime_;
  441. unsigned long st_ctime_nsec_;
  442. unsigned long __unused4;
  443. unsigned long __unused5;
  444. };
  445. #elif (defined(__mips__) && _MIPS_SIM != _MIPS_SIM_ABI64)
  446. struct kernel_stat {
  447. unsigned st_dev;
  448. int st_pad1[3];
  449. unsigned st_ino;
  450. unsigned st_mode;
  451. unsigned st_nlink;
  452. unsigned st_uid;
  453. unsigned st_gid;
  454. unsigned st_rdev;
  455. int st_pad2[2];
  456. long st_size;
  457. int st_pad3;
  458. long st_atime_;
  459. long st_atime_nsec_;
  460. long st_mtime_;
  461. long st_mtime_nsec_;
  462. long st_ctime_;
  463. long st_ctime_nsec_;
  464. int st_blksize;
  465. int st_blocks;
  466. int st_pad4[14];
  467. };
  468. #elif defined(__aarch64__)
  469. struct kernel_stat {
  470. unsigned long st_dev;
  471. unsigned long st_ino;
  472. unsigned int st_mode;
  473. unsigned int st_nlink;
  474. unsigned int st_uid;
  475. unsigned int st_gid;
  476. unsigned long st_rdev;
  477. unsigned long __pad1;
  478. long st_size;
  479. int st_blksize;
  480. int __pad2;
  481. long st_blocks;
  482. long st_atime_;
  483. unsigned long st_atime_nsec_;
  484. long st_mtime_;
  485. unsigned long st_mtime_nsec_;
  486. long st_ctime_;
  487. unsigned long st_ctime_nsec_;
  488. unsigned int __unused4;
  489. unsigned int __unused5;
  490. };
  491. #elif defined(__s390x__)
  492. struct kernel_stat {
  493. unsigned long st_dev;
  494. unsigned long st_ino;
  495. unsigned long st_nlink;
  496. unsigned int st_mode;
  497. unsigned int st_uid;
  498. unsigned int st_gid;
  499. unsigned int __pad1;
  500. unsigned long st_rdev;
  501. unsigned long st_size;
  502. unsigned long st_atime_;
  503. unsigned long st_atime_nsec_;
  504. unsigned long st_mtime_;
  505. unsigned long st_mtime_nsec_;
  506. unsigned long st_ctime_;
  507. unsigned long st_ctime_nsec_;
  508. unsigned long st_blksize;
  509. long st_blocks;
  510. unsigned long __unused[3];
  511. };
  512. #elif defined(__s390__)
  513. struct kernel_stat {
  514. unsigned short st_dev;
  515. unsigned short __pad1;
  516. unsigned long st_ino;
  517. unsigned short st_mode;
  518. unsigned short st_nlink;
  519. unsigned short st_uid;
  520. unsigned short st_gid;
  521. unsigned short st_rdev;
  522. unsigned short __pad2;
  523. unsigned long st_size;
  524. unsigned long st_blksize;
  525. unsigned long st_blocks;
  526. unsigned long st_atime_;
  527. unsigned long st_atime_nsec_;
  528. unsigned long st_mtime_;
  529. unsigned long st_mtime_nsec_;
  530. unsigned long st_ctime_;
  531. unsigned long st_ctime_nsec_;
  532. unsigned long __unused4;
  533. unsigned long __unused5;
  534. };
  535. #endif
  536. /* include/asm-{arm,aarch64,i386,mips,x86_64,ppc,s390}/statfs.h */
  537. #ifdef __mips__
  538. #if _MIPS_SIM != _MIPS_SIM_ABI64
  539. struct kernel_statfs64 {
  540. unsigned long f_type;
  541. unsigned long f_bsize;
  542. unsigned long f_frsize;
  543. unsigned long __pad;
  544. unsigned long long f_blocks;
  545. unsigned long long f_bfree;
  546. unsigned long long f_files;
  547. unsigned long long f_ffree;
  548. unsigned long long f_bavail;
  549. struct { int val[2]; } f_fsid;
  550. unsigned long f_namelen;
  551. unsigned long f_spare[6];
  552. };
  553. #endif
  554. #elif defined(__s390__)
  555. /* See also arch/s390/include/asm/compat.h */
  556. struct kernel_statfs64 {
  557. unsigned int f_type;
  558. unsigned int f_bsize;
  559. unsigned long long f_blocks;
  560. unsigned long long f_bfree;
  561. unsigned long long f_bavail;
  562. unsigned long long f_files;
  563. unsigned long long f_ffree;
  564. struct { int val[2]; } f_fsid;
  565. unsigned int f_namelen;
  566. unsigned int f_frsize;
  567. unsigned int f_flags;
  568. unsigned int f_spare[4];
  569. };
  570. #elif !defined(__x86_64__)
  571. struct kernel_statfs64 {
  572. unsigned long f_type;
  573. unsigned long f_bsize;
  574. unsigned long long f_blocks;
  575. unsigned long long f_bfree;
  576. unsigned long long f_bavail;
  577. unsigned long long f_files;
  578. unsigned long long f_ffree;
  579. struct { int val[2]; } f_fsid;
  580. unsigned long f_namelen;
  581. unsigned long f_frsize;
  582. unsigned long f_spare[5];
  583. };
  584. #endif
  585. /* include/asm-{arm,i386,mips,x86_64,ppc,generic,s390}/statfs.h */
  586. #ifdef __mips__
  587. struct kernel_statfs {
  588. long f_type;
  589. long f_bsize;
  590. long f_frsize;
  591. long f_blocks;
  592. long f_bfree;
  593. long f_files;
  594. long f_ffree;
  595. long f_bavail;
  596. struct { int val[2]; } f_fsid;
  597. long f_namelen;
  598. long f_spare[6];
  599. };
  600. #elif defined(__x86_64__)
  601. struct kernel_statfs {
  602. /* x86_64 actually defines all these fields as signed, whereas all other */
  603. /* platforms define them as unsigned. Leaving them at unsigned should not */
  604. /* cause any problems. Make sure these are 64-bit even on x32. */
  605. uint64_t f_type;
  606. uint64_t f_bsize;
  607. uint64_t f_blocks;
  608. uint64_t f_bfree;
  609. uint64_t f_bavail;
  610. uint64_t f_files;
  611. uint64_t f_ffree;
  612. struct { int val[2]; } f_fsid;
  613. uint64_t f_namelen;
  614. uint64_t f_frsize;
  615. uint64_t f_spare[5];
  616. };
  617. #elif defined(__s390__)
  618. struct kernel_statfs {
  619. unsigned int f_type;
  620. unsigned int f_bsize;
  621. unsigned long f_blocks;
  622. unsigned long f_bfree;
  623. unsigned long f_bavail;
  624. unsigned long f_files;
  625. unsigned long f_ffree;
  626. struct { int val[2]; } f_fsid;
  627. unsigned int f_namelen;
  628. unsigned int f_frsize;
  629. unsigned int f_flags;
  630. unsigned int f_spare[4];
  631. };
  632. #else
  633. struct kernel_statfs {
  634. unsigned long f_type;
  635. unsigned long f_bsize;
  636. unsigned long f_blocks;
  637. unsigned long f_bfree;
  638. unsigned long f_bavail;
  639. unsigned long f_files;
  640. unsigned long f_ffree;
  641. struct { int val[2]; } f_fsid;
  642. unsigned long f_namelen;
  643. unsigned long f_frsize;
  644. unsigned long f_spare[5];
  645. };
  646. #endif
  647. /* Definitions missing from the standard header files */
  648. #ifndef O_DIRECTORY
  649. #if defined(__ARM_ARCH_3__) || defined(__ARM_EABI__) || defined(__aarch64__)
  650. #define O_DIRECTORY 0040000
  651. #else
  652. #define O_DIRECTORY 0200000
  653. #endif
  654. #endif
  655. #ifndef NT_PRXFPREG
  656. #define NT_PRXFPREG 0x46e62b7f
  657. #endif
  658. #ifndef PTRACE_GETFPXREGS
  659. #define PTRACE_GETFPXREGS ((enum __ptrace_request)18)
  660. #endif
  661. #ifndef PR_GET_DUMPABLE
  662. #define PR_GET_DUMPABLE 3
  663. #endif
  664. #ifndef PR_SET_DUMPABLE
  665. #define PR_SET_DUMPABLE 4
  666. #endif
  667. #ifndef PR_GET_SECCOMP
  668. #define PR_GET_SECCOMP 21
  669. #endif
  670. #ifndef PR_SET_SECCOMP
  671. #define PR_SET_SECCOMP 22
  672. #endif
  673. #ifndef AT_FDCWD
  674. #define AT_FDCWD (-100)
  675. #endif
  676. #ifndef AT_SYMLINK_NOFOLLOW
  677. #define AT_SYMLINK_NOFOLLOW 0x100
  678. #endif
  679. #ifndef AT_REMOVEDIR
  680. #define AT_REMOVEDIR 0x200
  681. #endif
  682. #ifndef MREMAP_FIXED
  683. #define MREMAP_FIXED 2
  684. #endif
  685. #ifndef SA_RESTORER
  686. #define SA_RESTORER 0x04000000
  687. #endif
  688. #ifndef CPUCLOCK_PROF
  689. #define CPUCLOCK_PROF 0
  690. #endif
  691. #ifndef CPUCLOCK_VIRT
  692. #define CPUCLOCK_VIRT 1
  693. #endif
  694. #ifndef CPUCLOCK_SCHED
  695. #define CPUCLOCK_SCHED 2
  696. #endif
  697. #ifndef CPUCLOCK_PERTHREAD_MASK
  698. #define CPUCLOCK_PERTHREAD_MASK 4
  699. #endif
  700. #ifndef MAKE_PROCESS_CPUCLOCK
  701. #define MAKE_PROCESS_CPUCLOCK(pid, clock) \
  702. ((int)(~(unsigned)(pid) << 3) | (int)(clock))
  703. #endif
  704. #ifndef MAKE_THREAD_CPUCLOCK
  705. #define MAKE_THREAD_CPUCLOCK(tid, clock) \
  706. ((int)(~(unsigned)(tid) << 3) | \
  707. (int)((clock) | CPUCLOCK_PERTHREAD_MASK))
  708. #endif
  709. #ifndef FUTEX_WAIT
  710. #define FUTEX_WAIT 0
  711. #endif
  712. #ifndef FUTEX_WAKE
  713. #define FUTEX_WAKE 1
  714. #endif
  715. #ifndef FUTEX_FD
  716. #define FUTEX_FD 2
  717. #endif
  718. #ifndef FUTEX_REQUEUE
  719. #define FUTEX_REQUEUE 3
  720. #endif
  721. #ifndef FUTEX_CMP_REQUEUE
  722. #define FUTEX_CMP_REQUEUE 4
  723. #endif
  724. #ifndef FUTEX_WAKE_OP
  725. #define FUTEX_WAKE_OP 5
  726. #endif
  727. #ifndef FUTEX_LOCK_PI
  728. #define FUTEX_LOCK_PI 6
  729. #endif
  730. #ifndef FUTEX_UNLOCK_PI
  731. #define FUTEX_UNLOCK_PI 7
  732. #endif
  733. #ifndef FUTEX_TRYLOCK_PI
  734. #define FUTEX_TRYLOCK_PI 8
  735. #endif
  736. #ifndef FUTEX_PRIVATE_FLAG
  737. #define FUTEX_PRIVATE_FLAG 128
  738. #endif
  739. #ifndef FUTEX_CMD_MASK
  740. #define FUTEX_CMD_MASK ~FUTEX_PRIVATE_FLAG
  741. #endif
  742. #ifndef FUTEX_WAIT_PRIVATE
  743. #define FUTEX_WAIT_PRIVATE (FUTEX_WAIT | FUTEX_PRIVATE_FLAG)
  744. #endif
  745. #ifndef FUTEX_WAKE_PRIVATE
  746. #define FUTEX_WAKE_PRIVATE (FUTEX_WAKE | FUTEX_PRIVATE_FLAG)
  747. #endif
  748. #ifndef FUTEX_REQUEUE_PRIVATE
  749. #define FUTEX_REQUEUE_PRIVATE (FUTEX_REQUEUE | FUTEX_PRIVATE_FLAG)
  750. #endif
  751. #ifndef FUTEX_CMP_REQUEUE_PRIVATE
  752. #define FUTEX_CMP_REQUEUE_PRIVATE (FUTEX_CMP_REQUEUE | FUTEX_PRIVATE_FLAG)
  753. #endif
  754. #ifndef FUTEX_WAKE_OP_PRIVATE
  755. #define FUTEX_WAKE_OP_PRIVATE (FUTEX_WAKE_OP | FUTEX_PRIVATE_FLAG)
  756. #endif
  757. #ifndef FUTEX_LOCK_PI_PRIVATE
  758. #define FUTEX_LOCK_PI_PRIVATE (FUTEX_LOCK_PI | FUTEX_PRIVATE_FLAG)
  759. #endif
  760. #ifndef FUTEX_UNLOCK_PI_PRIVATE
  761. #define FUTEX_UNLOCK_PI_PRIVATE (FUTEX_UNLOCK_PI | FUTEX_PRIVATE_FLAG)
  762. #endif
  763. #ifndef FUTEX_TRYLOCK_PI_PRIVATE
  764. #define FUTEX_TRYLOCK_PI_PRIVATE (FUTEX_TRYLOCK_PI | FUTEX_PRIVATE_FLAG)
  765. #endif
  766. #if defined(__x86_64__)
  767. #ifndef ARCH_SET_GS
  768. #define ARCH_SET_GS 0x1001
  769. #endif
  770. #ifndef ARCH_GET_GS
  771. #define ARCH_GET_GS 0x1004
  772. #endif
  773. #endif
  774. #if defined(__i386__)
  775. #ifndef __NR_quotactl
  776. #define __NR_quotactl 131
  777. #endif
  778. #ifndef __NR_setresuid
  779. #define __NR_setresuid 164
  780. #define __NR_getresuid 165
  781. #define __NR_setresgid 170
  782. #define __NR_getresgid 171
  783. #endif
  784. #ifndef __NR_rt_sigaction
  785. #define __NR_rt_sigreturn 173
  786. #define __NR_rt_sigaction 174
  787. #define __NR_rt_sigprocmask 175
  788. #define __NR_rt_sigpending 176
  789. #define __NR_rt_sigsuspend 179
  790. #endif
  791. #ifndef __NR_pread64
  792. #define __NR_pread64 180
  793. #endif
  794. #ifndef __NR_pwrite64
  795. #define __NR_pwrite64 181
  796. #endif
  797. #ifndef __NR_ugetrlimit
  798. #define __NR_ugetrlimit 191
  799. #endif
  800. #ifndef __NR_stat64
  801. #define __NR_stat64 195
  802. #endif
  803. #ifndef __NR_fstat64
  804. #define __NR_fstat64 197
  805. #endif
  806. #ifndef __NR_setresuid32
  807. #define __NR_setresuid32 208
  808. #define __NR_getresuid32 209
  809. #define __NR_setresgid32 210
  810. #define __NR_getresgid32 211
  811. #endif
  812. #ifndef __NR_setfsuid32
  813. #define __NR_setfsuid32 215
  814. #define __NR_setfsgid32 216
  815. #endif
  816. #ifndef __NR_getdents64
  817. #define __NR_getdents64 220
  818. #endif
  819. #ifndef __NR_gettid
  820. #define __NR_gettid 224
  821. #endif
  822. #ifndef __NR_readahead
  823. #define __NR_readahead 225
  824. #endif
  825. #ifndef __NR_setxattr
  826. #define __NR_setxattr 226
  827. #endif
  828. #ifndef __NR_lsetxattr
  829. #define __NR_lsetxattr 227
  830. #endif
  831. #ifndef __NR_getxattr
  832. #define __NR_getxattr 229
  833. #endif
  834. #ifndef __NR_lgetxattr
  835. #define __NR_lgetxattr 230
  836. #endif
  837. #ifndef __NR_listxattr
  838. #define __NR_listxattr 232
  839. #endif
  840. #ifndef __NR_llistxattr
  841. #define __NR_llistxattr 233
  842. #endif
  843. #ifndef __NR_tkill
  844. #define __NR_tkill 238
  845. #endif
  846. #ifndef __NR_futex
  847. #define __NR_futex 240
  848. #endif
  849. #ifndef __NR_sched_setaffinity
  850. #define __NR_sched_setaffinity 241
  851. #define __NR_sched_getaffinity 242
  852. #endif
  853. #ifndef __NR_set_tid_address
  854. #define __NR_set_tid_address 258
  855. #endif
  856. #ifndef __NR_clock_gettime
  857. #define __NR_clock_gettime 265
  858. #endif
  859. #ifndef __NR_clock_getres
  860. #define __NR_clock_getres 266
  861. #endif
  862. #ifndef __NR_statfs64
  863. #define __NR_statfs64 268
  864. #endif
  865. #ifndef __NR_fstatfs64
  866. #define __NR_fstatfs64 269
  867. #endif
  868. #ifndef __NR_fadvise64_64
  869. #define __NR_fadvise64_64 272
  870. #endif
  871. #ifndef __NR_ioprio_set
  872. #define __NR_ioprio_set 289
  873. #endif
  874. #ifndef __NR_ioprio_get
  875. #define __NR_ioprio_get 290
  876. #endif
  877. #ifndef __NR_openat
  878. #define __NR_openat 295
  879. #endif
  880. #ifndef __NR_fstatat64
  881. #define __NR_fstatat64 300
  882. #endif
  883. #ifndef __NR_unlinkat
  884. #define __NR_unlinkat 301
  885. #endif
  886. #ifndef __NR_move_pages
  887. #define __NR_move_pages 317
  888. #endif
  889. #ifndef __NR_getcpu
  890. #define __NR_getcpu 318
  891. #endif
  892. #ifndef __NR_fallocate
  893. #define __NR_fallocate 324
  894. #endif
  895. /* End of i386 definitions */
  896. #elif defined(__ARM_ARCH_3__) || defined(__ARM_EABI__)
  897. #ifndef __NR_setresuid
  898. #define __NR_setresuid (__NR_SYSCALL_BASE + 164)
  899. #define __NR_getresuid (__NR_SYSCALL_BASE + 165)
  900. #define __NR_setresgid (__NR_SYSCALL_BASE + 170)
  901. #define __NR_getresgid (__NR_SYSCALL_BASE + 171)
  902. #endif
  903. #ifndef __NR_rt_sigaction
  904. #define __NR_rt_sigreturn (__NR_SYSCALL_BASE + 173)
  905. #define __NR_rt_sigaction (__NR_SYSCALL_BASE + 174)
  906. #define __NR_rt_sigprocmask (__NR_SYSCALL_BASE + 175)
  907. #define __NR_rt_sigpending (__NR_SYSCALL_BASE + 176)
  908. #define __NR_rt_sigsuspend (__NR_SYSCALL_BASE + 179)
  909. #endif
  910. #ifndef __NR_pread64
  911. #define __NR_pread64 (__NR_SYSCALL_BASE + 180)
  912. #endif
  913. #ifndef __NR_pwrite64
  914. #define __NR_pwrite64 (__NR_SYSCALL_BASE + 181)
  915. #endif
  916. #ifndef __NR_ugetrlimit
  917. #define __NR_ugetrlimit (__NR_SYSCALL_BASE + 191)
  918. #endif
  919. #ifndef __NR_stat64
  920. #define __NR_stat64 (__NR_SYSCALL_BASE + 195)
  921. #endif
  922. #ifndef __NR_fstat64
  923. #define __NR_fstat64 (__NR_SYSCALL_BASE + 197)
  924. #endif
  925. #ifndef __NR_setresuid32
  926. #define __NR_setresuid32 (__NR_SYSCALL_BASE + 208)
  927. #define __NR_getresuid32 (__NR_SYSCALL_BASE + 209)
  928. #define __NR_setresgid32 (__NR_SYSCALL_BASE + 210)
  929. #define __NR_getresgid32 (__NR_SYSCALL_BASE + 211)
  930. #endif
  931. #ifndef __NR_setfsuid32
  932. #define __NR_setfsuid32 (__NR_SYSCALL_BASE + 215)
  933. #define __NR_setfsgid32 (__NR_SYSCALL_BASE + 216)
  934. #endif
  935. #ifndef __NR_getdents64
  936. #define __NR_getdents64 (__NR_SYSCALL_BASE + 217)
  937. #endif
  938. #ifndef __NR_gettid
  939. #define __NR_gettid (__NR_SYSCALL_BASE + 224)
  940. #endif
  941. #ifndef __NR_readahead
  942. #define __NR_readahead (__NR_SYSCALL_BASE + 225)
  943. #endif
  944. #ifndef __NR_setxattr
  945. #define __NR_setxattr (__NR_SYSCALL_BASE + 226)
  946. #endif
  947. #ifndef __NR_lsetxattr
  948. #define __NR_lsetxattr (__NR_SYSCALL_BASE + 227)
  949. #endif
  950. #ifndef __NR_getxattr
  951. #define __NR_getxattr (__NR_SYSCALL_BASE + 229)
  952. #endif
  953. #ifndef __NR_lgetxattr
  954. #define __NR_lgetxattr (__NR_SYSCALL_BASE + 230)
  955. #endif
  956. #ifndef __NR_listxattr
  957. #define __NR_listxattr (__NR_SYSCALL_BASE + 232)
  958. #endif
  959. #ifndef __NR_llistxattr
  960. #define __NR_llistxattr (__NR_SYSCALL_BASE + 233)
  961. #endif
  962. #ifndef __NR_tkill
  963. #define __NR_tkill (__NR_SYSCALL_BASE + 238)
  964. #endif
  965. #ifndef __NR_futex
  966. #define __NR_futex (__NR_SYSCALL_BASE + 240)
  967. #endif
  968. #ifndef __NR_sched_setaffinity
  969. #define __NR_sched_setaffinity (__NR_SYSCALL_BASE + 241)
  970. #define __NR_sched_getaffinity (__NR_SYSCALL_BASE + 242)
  971. #endif
  972. #ifndef __NR_set_tid_address
  973. #define __NR_set_tid_address (__NR_SYSCALL_BASE + 256)
  974. #endif
  975. #ifndef __NR_clock_gettime
  976. #define __NR_clock_gettime (__NR_SYSCALL_BASE + 263)
  977. #endif
  978. #ifndef __NR_clock_getres
  979. #define __NR_clock_getres (__NR_SYSCALL_BASE + 264)
  980. #endif
  981. #ifndef __NR_statfs64
  982. #define __NR_statfs64 (__NR_SYSCALL_BASE + 266)
  983. #endif
  984. #ifndef __NR_fstatfs64
  985. #define __NR_fstatfs64 (__NR_SYSCALL_BASE + 267)
  986. #endif
  987. #ifndef __NR_ioprio_set
  988. #define __NR_ioprio_set (__NR_SYSCALL_BASE + 314)
  989. #endif
  990. #ifndef __NR_ioprio_get
  991. #define __NR_ioprio_get (__NR_SYSCALL_BASE + 315)
  992. #endif
  993. #ifndef __NR_move_pages
  994. #define __NR_move_pages (__NR_SYSCALL_BASE + 344)
  995. #endif
  996. #ifndef __NR_getcpu
  997. #define __NR_getcpu (__NR_SYSCALL_BASE + 345)
  998. #endif
  999. /* End of ARM 3/EABI definitions */
  1000. #elif defined(__aarch64__)
  1001. #ifndef __NR_setxattr
  1002. #define __NR_setxattr 5
  1003. #endif
  1004. #ifndef __NR_lsetxattr
  1005. #define __NR_lsetxattr 6
  1006. #endif
  1007. #ifndef __NR_getxattr
  1008. #define __NR_getxattr 8
  1009. #endif
  1010. #ifndef __NR_lgetxattr
  1011. #define __NR_lgetxattr 9
  1012. #endif
  1013. #ifndef __NR_listxattr
  1014. #define __NR_listxattr 11
  1015. #endif
  1016. #ifndef __NR_llistxattr
  1017. #define __NR_llistxattr 12
  1018. #endif
  1019. #ifndef __NR_ioprio_set
  1020. #define __NR_ioprio_set 30
  1021. #endif
  1022. #ifndef __NR_ioprio_get
  1023. #define __NR_ioprio_get 31
  1024. #endif
  1025. #ifndef __NR_unlinkat
  1026. #define __NR_unlinkat 35
  1027. #endif
  1028. #ifndef __NR_fallocate
  1029. #define __NR_fallocate 47
  1030. #endif
  1031. #ifndef __NR_openat
  1032. #define __NR_openat 56
  1033. #endif
  1034. #ifndef __NR_quotactl
  1035. #define __NR_quotactl 60
  1036. #endif
  1037. #ifndef __NR_getdents64
  1038. #define __NR_getdents64 61
  1039. #endif
  1040. #ifndef __NR_getdents
  1041. #define __NR_getdents __NR_getdents64
  1042. #endif
  1043. #ifndef __NR_pread64
  1044. #define __NR_pread64 67
  1045. #endif
  1046. #ifndef __NR_pwrite64
  1047. #define __NR_pwrite64 68
  1048. #endif
  1049. #ifndef __NR_ppoll
  1050. #define __NR_ppoll 73
  1051. #endif
  1052. #ifndef __NR_readlinkat
  1053. #define __NR_readlinkat 78
  1054. #endif
  1055. #ifndef __NR_newfstatat
  1056. #define __NR_newfstatat 79
  1057. #endif
  1058. #ifndef __NR_set_tid_address
  1059. #define __NR_set_tid_address 96
  1060. #endif
  1061. #ifndef __NR_futex
  1062. #define __NR_futex 98
  1063. #endif
  1064. #ifndef __NR_clock_gettime
  1065. #define __NR_clock_gettime 113
  1066. #endif
  1067. #ifndef __NR_clock_getres
  1068. #define __NR_clock_getres 114
  1069. #endif
  1070. #ifndef __NR_sched_setaffinity
  1071. #define __NR_sched_setaffinity 122
  1072. #define __NR_sched_getaffinity 123
  1073. #endif
  1074. #ifndef __NR_tkill
  1075. #define __NR_tkill 130
  1076. #endif
  1077. #ifndef __NR_setresuid
  1078. #define __NR_setresuid 147
  1079. #define __NR_getresuid 148
  1080. #define __NR_setresgid 149
  1081. #define __NR_getresgid 150
  1082. #endif
  1083. #ifndef __NR_gettid
  1084. #define __NR_gettid 178
  1085. #endif
  1086. #ifndef __NR_readahead
  1087. #define __NR_readahead 213
  1088. #endif
  1089. #ifndef __NR_fadvise64
  1090. #define __NR_fadvise64 223
  1091. #endif
  1092. #ifndef __NR_move_pages
  1093. #define __NR_move_pages 239
  1094. #endif
  1095. /* End of aarch64 definitions */
  1096. #elif defined(__x86_64__)
  1097. #ifndef __NR_pread64
  1098. #define __NR_pread64 17
  1099. #endif
  1100. #ifndef __NR_pwrite64
  1101. #define __NR_pwrite64 18
  1102. #endif
  1103. #ifndef __NR_setresuid
  1104. #define __NR_setresuid 117
  1105. #define __NR_getresuid 118
  1106. #define __NR_setresgid 119
  1107. #define __NR_getresgid 120
  1108. #endif
  1109. #ifndef __NR_quotactl
  1110. #define __NR_quotactl 179
  1111. #endif
  1112. #ifndef __NR_gettid
  1113. #define __NR_gettid 186
  1114. #endif
  1115. #ifndef __NR_readahead
  1116. #define __NR_readahead 187
  1117. #endif
  1118. #ifndef __NR_setxattr
  1119. #define __NR_setxattr 188
  1120. #endif
  1121. #ifndef __NR_lsetxattr
  1122. #define __NR_lsetxattr 189
  1123. #endif
  1124. #ifndef __NR_getxattr
  1125. #define __NR_getxattr 191
  1126. #endif
  1127. #ifndef __NR_lgetxattr
  1128. #define __NR_lgetxattr 192
  1129. #endif
  1130. #ifndef __NR_listxattr
  1131. #define __NR_listxattr 194
  1132. #endif
  1133. #ifndef __NR_llistxattr
  1134. #define __NR_llistxattr 195
  1135. #endif
  1136. #ifndef __NR_tkill
  1137. #define __NR_tkill 200
  1138. #endif
  1139. #ifndef __NR_futex
  1140. #define __NR_futex 202
  1141. #endif
  1142. #ifndef __NR_sched_setaffinity
  1143. #define __NR_sched_setaffinity 203
  1144. #define __NR_sched_getaffinity 204
  1145. #endif
  1146. #ifndef __NR_getdents64
  1147. #define __NR_getdents64 217
  1148. #endif
  1149. #ifndef __NR_set_tid_address
  1150. #define __NR_set_tid_address 218
  1151. #endif
  1152. #ifndef __NR_fadvise64
  1153. #define __NR_fadvise64 221
  1154. #endif
  1155. #ifndef __NR_clock_gettime
  1156. #define __NR_clock_gettime 228
  1157. #endif
  1158. #ifndef __NR_clock_getres
  1159. #define __NR_clock_getres 229
  1160. #endif
  1161. #ifndef __NR_ioprio_set
  1162. #define __NR_ioprio_set 251
  1163. #endif
  1164. #ifndef __NR_ioprio_get
  1165. #define __NR_ioprio_get 252
  1166. #endif
  1167. #ifndef __NR_openat
  1168. #define __NR_openat 257
  1169. #endif
  1170. #ifndef __NR_newfstatat
  1171. #define __NR_newfstatat 262
  1172. #endif
  1173. #ifndef __NR_unlinkat
  1174. #define __NR_unlinkat 263
  1175. #endif
  1176. #ifndef __NR_move_pages
  1177. #define __NR_move_pages 279
  1178. #endif
  1179. #ifndef __NR_fallocate
  1180. #define __NR_fallocate 285
  1181. #endif
  1182. /* End of x86-64 definitions */
  1183. #elif defined(__mips__)
  1184. #if _MIPS_SIM == _MIPS_SIM_ABI32
  1185. #ifndef __NR_setresuid
  1186. #define __NR_setresuid (__NR_Linux + 185)
  1187. #define __NR_getresuid (__NR_Linux + 186)
  1188. #define __NR_setresgid (__NR_Linux + 190)
  1189. #define __NR_getresgid (__NR_Linux + 191)
  1190. #endif
  1191. #ifndef __NR_rt_sigaction
  1192. #define __NR_rt_sigreturn (__NR_Linux + 193)
  1193. #define __NR_rt_sigaction (__NR_Linux + 194)
  1194. #define __NR_rt_sigprocmask (__NR_Linux + 195)
  1195. #define __NR_rt_sigpending (__NR_Linux + 196)
  1196. #define __NR_rt_sigsuspend (__NR_Linux + 199)
  1197. #endif
  1198. #ifndef __NR_pread64
  1199. #define __NR_pread64 (__NR_Linux + 200)
  1200. #endif
  1201. #ifndef __NR_pwrite64
  1202. #define __NR_pwrite64 (__NR_Linux + 201)
  1203. #endif
  1204. #ifndef __NR_stat64
  1205. #define __NR_stat64 (__NR_Linux + 213)
  1206. #endif
  1207. #ifndef __NR_fstat64
  1208. #define __NR_fstat64 (__NR_Linux + 215)
  1209. #endif
  1210. #ifndef __NR_getdents64
  1211. #define __NR_getdents64 (__NR_Linux + 219)
  1212. #endif
  1213. #ifndef __NR_gettid
  1214. #define __NR_gettid (__NR_Linux + 222)
  1215. #endif
  1216. #ifndef __NR_readahead
  1217. #define __NR_readahead (__NR_Linux + 223)
  1218. #endif
  1219. #ifndef __NR_setxattr
  1220. #define __NR_setxattr (__NR_Linux + 224)
  1221. #endif
  1222. #ifndef __NR_lsetxattr
  1223. #define __NR_lsetxattr (__NR_Linux + 225)
  1224. #endif
  1225. #ifndef __NR_getxattr
  1226. #define __NR_getxattr (__NR_Linux + 227)
  1227. #endif
  1228. #ifndef __NR_lgetxattr
  1229. #define __NR_lgetxattr (__NR_Linux + 228)
  1230. #endif
  1231. #ifndef __NR_listxattr
  1232. #define __NR_listxattr (__NR_Linux + 230)
  1233. #endif
  1234. #ifndef __NR_llistxattr
  1235. #define __NR_llistxattr (__NR_Linux + 231)
  1236. #endif
  1237. #ifndef __NR_tkill
  1238. #define __NR_tkill (__NR_Linux + 236)
  1239. #endif
  1240. #ifndef __NR_futex
  1241. #define __NR_futex (__NR_Linux + 238)
  1242. #endif
  1243. #ifndef __NR_sched_setaffinity
  1244. #define __NR_sched_setaffinity (__NR_Linux + 239)
  1245. #define __NR_sched_getaffinity (__NR_Linux + 240)
  1246. #endif
  1247. #ifndef __NR_set_tid_address
  1248. #define __NR_set_tid_address (__NR_Linux + 252)
  1249. #endif
  1250. #ifndef __NR_statfs64
  1251. #define __NR_statfs64 (__NR_Linux + 255)
  1252. #endif
  1253. #ifndef __NR_fstatfs64
  1254. #define __NR_fstatfs64 (__NR_Linux + 256)
  1255. #endif
  1256. #ifndef __NR_clock_gettime
  1257. #define __NR_clock_gettime (__NR_Linux + 263)
  1258. #endif
  1259. #ifndef __NR_clock_getres
  1260. #define __NR_clock_getres (__NR_Linux + 264)
  1261. #endif
  1262. #ifndef __NR_openat
  1263. #define __NR_openat (__NR_Linux + 288)
  1264. #endif
  1265. #ifndef __NR_fstatat
  1266. #define __NR_fstatat (__NR_Linux + 293)
  1267. #endif
  1268. #ifndef __NR_unlinkat
  1269. #define __NR_unlinkat (__NR_Linux + 294)
  1270. #endif
  1271. #ifndef __NR_move_pages
  1272. #define __NR_move_pages (__NR_Linux + 308)
  1273. #endif
  1274. #ifndef __NR_getcpu
  1275. #define __NR_getcpu (__NR_Linux + 312)
  1276. #endif
  1277. #ifndef __NR_ioprio_set
  1278. #define __NR_ioprio_set (__NR_Linux + 314)
  1279. #endif
  1280. #ifndef __NR_ioprio_get
  1281. #define __NR_ioprio_get (__NR_Linux + 315)
  1282. #endif
  1283. /* End of MIPS (old 32bit API) definitions */
  1284. #elif _MIPS_SIM == _MIPS_SIM_ABI64
  1285. #ifndef __NR_pread64
  1286. #define __NR_pread64 (__NR_Linux + 16)
  1287. #endif
  1288. #ifndef __NR_pwrite64
  1289. #define __NR_pwrite64 (__NR_Linux + 17)
  1290. #endif
  1291. #ifndef __NR_setresuid
  1292. #define __NR_setresuid (__NR_Linux + 115)
  1293. #define __NR_getresuid (__NR_Linux + 116)
  1294. #define __NR_setresgid (__NR_Linux + 117)
  1295. #define __NR_getresgid (__NR_Linux + 118)
  1296. #endif
  1297. #ifndef __NR_gettid
  1298. #define __NR_gettid (__NR_Linux + 178)
  1299. #endif
  1300. #ifndef __NR_readahead
  1301. #define __NR_readahead (__NR_Linux + 179)
  1302. #endif
  1303. #ifndef __NR_setxattr
  1304. #define __NR_setxattr (__NR_Linux + 180)
  1305. #endif
  1306. #ifndef __NR_lsetxattr
  1307. #define __NR_lsetxattr (__NR_Linux + 181)
  1308. #endif
  1309. #ifndef __NR_getxattr
  1310. #define __NR_getxattr (__NR_Linux + 183)
  1311. #endif
  1312. #ifndef __NR_lgetxattr
  1313. #define __NR_lgetxattr (__NR_Linux + 184)
  1314. #endif
  1315. #ifndef __NR_listxattr
  1316. #define __NR_listxattr (__NR_Linux + 186)
  1317. #endif
  1318. #ifndef __NR_llistxattr
  1319. #define __NR_llistxattr (__NR_Linux + 187)
  1320. #endif
  1321. #ifndef __NR_tkill
  1322. #define __NR_tkill (__NR_Linux + 192)
  1323. #endif
  1324. #ifndef __NR_futex
  1325. #define __NR_futex (__NR_Linux + 194)
  1326. #endif
  1327. #ifndef __NR_sched_setaffinity
  1328. #define __NR_sched_setaffinity (__NR_Linux + 195)
  1329. #define __NR_sched_getaffinity (__NR_Linux + 196)
  1330. #endif
  1331. #ifndef __NR_set_tid_address
  1332. #define __NR_set_tid_address (__NR_Linux + 212)
  1333. #endif
  1334. #ifndef __NR_clock_gettime
  1335. #define __NR_clock_gettime (__NR_Linux + 222)
  1336. #endif
  1337. #ifndef __NR_clock_getres
  1338. #define __NR_clock_getres (__NR_Linux + 223)
  1339. #endif
  1340. #ifndef __NR_openat
  1341. #define __NR_openat (__NR_Linux + 247)
  1342. #endif
  1343. #ifndef __NR_fstatat
  1344. #define __NR_fstatat (__NR_Linux + 252)
  1345. #endif
  1346. #ifndef __NR_unlinkat
  1347. #define __NR_unlinkat (__NR_Linux + 253)
  1348. #endif
  1349. #ifndef __NR_move_pages
  1350. #define __NR_move_pages (__NR_Linux + 267)
  1351. #endif
  1352. #ifndef __NR_getcpu
  1353. #define __NR_getcpu (__NR_Linux + 271)
  1354. #endif
  1355. #ifndef __NR_ioprio_set
  1356. #define __NR_ioprio_set (__NR_Linux + 273)
  1357. #endif
  1358. #ifndef __NR_ioprio_get
  1359. #define __NR_ioprio_get (__NR_Linux + 274)
  1360. #endif
  1361. /* End of MIPS (64bit API) definitions */
  1362. #else
  1363. #ifndef __NR_setresuid
  1364. #define __NR_setresuid (__NR_Linux + 115)
  1365. #define __NR_getresuid (__NR_Linux + 116)
  1366. #define __NR_setresgid (__NR_Linux + 117)
  1367. #define __NR_getresgid (__NR_Linux + 118)
  1368. #endif
  1369. #ifndef __NR_gettid
  1370. #define __NR_gettid (__NR_Linux + 178)
  1371. #endif
  1372. #ifndef __NR_readahead
  1373. #define __NR_readahead (__NR_Linux + 179)
  1374. #endif
  1375. #ifndef __NR_setxattr
  1376. #define __NR_setxattr (__NR_Linux + 180)
  1377. #endif
  1378. #ifndef __NR_lsetxattr
  1379. #define __NR_lsetxattr (__NR_Linux + 181)
  1380. #endif
  1381. #ifndef __NR_getxattr
  1382. #define __NR_getxattr (__NR_Linux + 183)
  1383. #endif
  1384. #ifndef __NR_lgetxattr
  1385. #define __NR_lgetxattr (__NR_Linux + 184)
  1386. #endif
  1387. #ifndef __NR_listxattr
  1388. #define __NR_listxattr (__NR_Linux + 186)
  1389. #endif
  1390. #ifndef __NR_llistxattr
  1391. #define __NR_llistxattr (__NR_Linux + 187)
  1392. #endif
  1393. #ifndef __NR_tkill
  1394. #define __NR_tkill (__NR_Linux + 192)
  1395. #endif
  1396. #ifndef __NR_futex
  1397. #define __NR_futex (__NR_Linux + 194)
  1398. #endif
  1399. #ifndef __NR_sched_setaffinity
  1400. #define __NR_sched_setaffinity (__NR_Linux + 195)
  1401. #define __NR_sched_getaffinity (__NR_Linux + 196)
  1402. #endif
  1403. #ifndef __NR_set_tid_address
  1404. #define __NR_set_tid_address (__NR_Linux + 213)
  1405. #endif
  1406. #ifndef __NR_statfs64
  1407. #define __NR_statfs64 (__NR_Linux + 217)
  1408. #endif
  1409. #ifndef __NR_fstatfs64
  1410. #define __NR_fstatfs64 (__NR_Linux + 218)
  1411. #endif
  1412. #ifndef __NR_clock_gettime
  1413. #define __NR_clock_gettime (__NR_Linux + 226)
  1414. #endif
  1415. #ifndef __NR_clock_getres
  1416. #define __NR_clock_getres (__NR_Linux + 227)
  1417. #endif
  1418. #ifndef __NR_openat
  1419. #define __NR_openat (__NR_Linux + 251)
  1420. #endif
  1421. #ifndef __NR_fstatat
  1422. #define __NR_fstatat (__NR_Linux + 256)
  1423. #endif
  1424. #ifndef __NR_unlinkat
  1425. #define __NR_unlinkat (__NR_Linux + 257)
  1426. #endif
  1427. #ifndef __NR_move_pages
  1428. #define __NR_move_pages (__NR_Linux + 271)
  1429. #endif
  1430. #ifndef __NR_getcpu
  1431. #define __NR_getcpu (__NR_Linux + 275)
  1432. #endif
  1433. #ifndef __NR_ioprio_set
  1434. #define __NR_ioprio_set (__NR_Linux + 277)
  1435. #endif
  1436. #ifndef __NR_ioprio_get
  1437. #define __NR_ioprio_get (__NR_Linux + 278)
  1438. #endif
  1439. /* End of MIPS (new 32bit API) definitions */
  1440. #endif
  1441. /* End of MIPS definitions */
  1442. #elif defined(__PPC__)
  1443. #ifndef __NR_setfsuid
  1444. #define __NR_setfsuid 138
  1445. #define __NR_setfsgid 139
  1446. #endif
  1447. #ifndef __NR_setresuid
  1448. #define __NR_setresuid 164
  1449. #define __NR_getresuid 165
  1450. #define __NR_setresgid 169
  1451. #define __NR_getresgid 170
  1452. #endif
  1453. #ifndef __NR_rt_sigaction
  1454. #define __NR_rt_sigreturn 172
  1455. #define __NR_rt_sigaction 173
  1456. #define __NR_rt_sigprocmask 174
  1457. #define __NR_rt_sigpending 175
  1458. #define __NR_rt_sigsuspend 178
  1459. #endif
  1460. #ifndef __NR_pread64
  1461. #define __NR_pread64 179
  1462. #endif
  1463. #ifndef __NR_pwrite64
  1464. #define __NR_pwrite64 180
  1465. #endif
  1466. #ifndef __NR_ugetrlimit
  1467. #define __NR_ugetrlimit 190
  1468. #endif
  1469. #ifndef __NR_readahead
  1470. #define __NR_readahead 191
  1471. #endif
  1472. #ifndef __NR_stat64
  1473. #define __NR_stat64 195
  1474. #endif
  1475. #ifndef __NR_fstat64
  1476. #define __NR_fstat64 197
  1477. #endif
  1478. #ifndef __NR_getdents64
  1479. #define __NR_getdents64 202
  1480. #endif
  1481. #ifndef __NR_gettid
  1482. #define __NR_gettid 207
  1483. #endif
  1484. #ifndef __NR_tkill
  1485. #define __NR_tkill 208
  1486. #endif
  1487. #ifndef __NR_setxattr
  1488. #define __NR_setxattr 209
  1489. #endif
  1490. #ifndef __NR_lsetxattr
  1491. #define __NR_lsetxattr 210
  1492. #endif
  1493. #ifndef __NR_getxattr
  1494. #define __NR_getxattr 212
  1495. #endif
  1496. #ifndef __NR_lgetxattr
  1497. #define __NR_lgetxattr 213
  1498. #endif
  1499. #ifndef __NR_listxattr
  1500. #define __NR_listxattr 215
  1501. #endif
  1502. #ifndef __NR_llistxattr
  1503. #define __NR_llistxattr 216
  1504. #endif
  1505. #ifndef __NR_futex
  1506. #define __NR_futex 221
  1507. #endif
  1508. #ifndef __NR_sched_setaffinity
  1509. #define __NR_sched_setaffinity 222
  1510. #define __NR_sched_getaffinity 223
  1511. #endif
  1512. #ifndef __NR_set_tid_address
  1513. #define __NR_set_tid_address 232
  1514. #endif
  1515. #ifndef __NR_clock_gettime
  1516. #define __NR_clock_gettime 246
  1517. #endif
  1518. #ifndef __NR_clock_getres
  1519. #define __NR_clock_getres 247
  1520. #endif
  1521. #ifndef __NR_statfs64
  1522. #define __NR_statfs64 252
  1523. #endif
  1524. #ifndef __NR_fstatfs64
  1525. #define __NR_fstatfs64 253
  1526. #endif
  1527. #ifndef __NR_fadvise64_64
  1528. #define __NR_fadvise64_64 254
  1529. #endif
  1530. #ifndef __NR_ioprio_set
  1531. #define __NR_ioprio_set 273
  1532. #endif
  1533. #ifndef __NR_ioprio_get
  1534. #define __NR_ioprio_get 274
  1535. #endif
  1536. #ifndef __NR_openat
  1537. #define __NR_openat 286
  1538. #endif
  1539. #ifndef __NR_fstatat64
  1540. #define __NR_fstatat64 291
  1541. #endif
  1542. #ifndef __NR_unlinkat
  1543. #define __NR_unlinkat 292
  1544. #endif
  1545. #ifndef __NR_move_pages
  1546. #define __NR_move_pages 301
  1547. #endif
  1548. #ifndef __NR_getcpu
  1549. #define __NR_getcpu 302
  1550. #endif
  1551. /* End of powerpc defininitions */
  1552. #elif defined(__s390__)
  1553. #ifndef __NR_quotactl
  1554. #define __NR_quotactl 131
  1555. #endif
  1556. #ifndef __NR_rt_sigreturn
  1557. #define __NR_rt_sigreturn 173
  1558. #endif
  1559. #ifndef __NR_rt_sigaction
  1560. #define __NR_rt_sigaction 174
  1561. #endif
  1562. #ifndef __NR_rt_sigprocmask
  1563. #define __NR_rt_sigprocmask 175
  1564. #endif
  1565. #ifndef __NR_rt_sigpending
  1566. #define __NR_rt_sigpending 176
  1567. #endif
  1568. #ifndef __NR_rt_sigsuspend
  1569. #define __NR_rt_sigsuspend 179
  1570. #endif
  1571. #ifndef __NR_pread64
  1572. #define __NR_pread64 180
  1573. #endif
  1574. #ifndef __NR_pwrite64
  1575. #define __NR_pwrite64 181
  1576. #endif
  1577. #ifndef __NR_getdents64
  1578. #define __NR_getdents64 220
  1579. #endif
  1580. #ifndef __NR_readahead
  1581. #define __NR_readahead 222
  1582. #endif
  1583. #ifndef __NR_setxattr
  1584. #define __NR_setxattr 224
  1585. #endif
  1586. #ifndef __NR_lsetxattr
  1587. #define __NR_lsetxattr 225
  1588. #endif
  1589. #ifndef __NR_getxattr
  1590. #define __NR_getxattr 227
  1591. #endif
  1592. #ifndef __NR_lgetxattr
  1593. #define __NR_lgetxattr 228
  1594. #endif
  1595. #ifndef __NR_listxattr
  1596. #define __NR_listxattr 230
  1597. #endif
  1598. #ifndef __NR_llistxattr
  1599. #define __NR_llistxattr 231
  1600. #endif
  1601. #ifndef __NR_gettid
  1602. #define __NR_gettid 236
  1603. #endif
  1604. #ifndef __NR_tkill
  1605. #define __NR_tkill 237
  1606. #endif
  1607. #ifndef __NR_futex
  1608. #define __NR_futex 238
  1609. #endif
  1610. #ifndef __NR_sched_setaffinity
  1611. #define __NR_sched_setaffinity 239
  1612. #endif
  1613. #ifndef __NR_sched_getaffinity
  1614. #define __NR_sched_getaffinity 240
  1615. #endif
  1616. #ifndef __NR_set_tid_address
  1617. #define __NR_set_tid_address 252
  1618. #endif
  1619. #ifndef __NR_clock_gettime
  1620. #define __NR_clock_gettime 260
  1621. #endif
  1622. #ifndef __NR_clock_getres
  1623. #define __NR_clock_getres 261
  1624. #endif
  1625. #ifndef __NR_statfs64
  1626. #define __NR_statfs64 265
  1627. #endif
  1628. #ifndef __NR_fstatfs64
  1629. #define __NR_fstatfs64 266
  1630. #endif
  1631. #ifndef __NR_ioprio_set
  1632. #define __NR_ioprio_set 282
  1633. #endif
  1634. #ifndef __NR_ioprio_get
  1635. #define __NR_ioprio_get 283
  1636. #endif
  1637. #ifndef __NR_openat
  1638. #define __NR_openat 288
  1639. #endif
  1640. #ifndef __NR_unlinkat
  1641. #define __NR_unlinkat 294
  1642. #endif
  1643. #ifndef __NR_move_pages
  1644. #define __NR_move_pages 310
  1645. #endif
  1646. #ifndef __NR_getcpu
  1647. #define __NR_getcpu 311
  1648. #endif
  1649. #ifndef __NR_fallocate
  1650. #define __NR_fallocate 314
  1651. #endif
  1652. /* Some syscalls are named/numbered differently between s390 and s390x. */
  1653. #ifdef __s390x__
  1654. # ifndef __NR_getrlimit
  1655. # define __NR_getrlimit 191
  1656. # endif
  1657. # ifndef __NR_setresuid
  1658. # define __NR_setresuid 208
  1659. # endif
  1660. # ifndef __NR_getresuid
  1661. # define __NR_getresuid 209
  1662. # endif
  1663. # ifndef __NR_setresgid
  1664. # define __NR_setresgid 210
  1665. # endif
  1666. # ifndef __NR_getresgid
  1667. # define __NR_getresgid 211
  1668. # endif
  1669. # ifndef __NR_setfsuid
  1670. # define __NR_setfsuid 215
  1671. # endif
  1672. # ifndef __NR_setfsgid
  1673. # define __NR_setfsgid 216
  1674. # endif
  1675. # ifndef __NR_fadvise64
  1676. # define __NR_fadvise64 253
  1677. # endif
  1678. # ifndef __NR_newfstatat
  1679. # define __NR_newfstatat 293
  1680. # endif
  1681. #else /* __s390x__ */
  1682. # ifndef __NR_getrlimit
  1683. # define __NR_getrlimit 76
  1684. # endif
  1685. # ifndef __NR_setfsuid
  1686. # define __NR_setfsuid 138
  1687. # endif
  1688. # ifndef __NR_setfsgid
  1689. # define __NR_setfsgid 139
  1690. # endif
  1691. # ifndef __NR_setresuid
  1692. # define __NR_setresuid 164
  1693. # endif
  1694. # ifndef __NR_getresuid
  1695. # define __NR_getresuid 165
  1696. # endif
  1697. # ifndef __NR_setresgid
  1698. # define __NR_setresgid 170
  1699. # endif
  1700. # ifndef __NR_getresgid
  1701. # define __NR_getresgid 171
  1702. # endif
  1703. # ifndef __NR_ugetrlimit
  1704. # define __NR_ugetrlimit 191
  1705. # endif
  1706. # ifndef __NR_mmap2
  1707. # define __NR_mmap2 192
  1708. # endif
  1709. # ifndef __NR_setresuid32
  1710. # define __NR_setresuid32 208
  1711. # endif
  1712. # ifndef __NR_getresuid32
  1713. # define __NR_getresuid32 209
  1714. # endif
  1715. # ifndef __NR_setresgid32
  1716. # define __NR_setresgid32 210
  1717. # endif
  1718. # ifndef __NR_getresgid32
  1719. # define __NR_getresgid32 211
  1720. # endif
  1721. # ifndef __NR_setfsuid32
  1722. # define __NR_setfsuid32 215
  1723. # endif
  1724. # ifndef __NR_setfsgid32
  1725. # define __NR_setfsgid32 216
  1726. # endif
  1727. # ifndef __NR_fadvise64_64
  1728. # define __NR_fadvise64_64 264
  1729. # endif
  1730. # ifndef __NR_fstatat64
  1731. # define __NR_fstatat64 293
  1732. # endif
  1733. #endif /* __s390__ */
  1734. /* End of s390/s390x definitions */
  1735. #endif
  1736. /* After forking, we must make sure to only call system calls. */
  1737. #if defined(__BOUNDED_POINTERS__)
  1738. #error "Need to port invocations of syscalls for bounded ptrs"
  1739. #else
  1740. /* The core dumper and the thread lister get executed after threads
  1741. * have been suspended. As a consequence, we cannot call any functions
  1742. * that acquire locks. Unfortunately, libc wraps most system calls
  1743. * (e.g. in order to implement pthread_atfork, and to make calls
  1744. * cancellable), which means we cannot call these functions. Instead,
  1745. * we have to call syscall() directly.
  1746. */
  1747. #undef LSS_ERRNO
  1748. #ifdef SYS_ERRNO
  1749. /* Allow the including file to override the location of errno. This can
  1750. * be useful when using clone() with the CLONE_VM option.
  1751. */
  1752. #define LSS_ERRNO SYS_ERRNO
  1753. #else
  1754. #define LSS_ERRNO errno
  1755. #endif
  1756. #undef LSS_INLINE
  1757. #ifdef SYS_INLINE
  1758. #define LSS_INLINE SYS_INLINE
  1759. #else
  1760. #define LSS_INLINE static inline
  1761. #endif
  1762. /* Allow the including file to override the prefix used for all new
  1763. * system calls. By default, it will be set to "sys_".
  1764. */
  1765. #undef LSS_NAME
  1766. #ifndef SYS_PREFIX
  1767. #define LSS_NAME(name) sys_##name
  1768. #elif defined(SYS_PREFIX) && SYS_PREFIX < 0
  1769. #define LSS_NAME(name) name
  1770. #elif defined(SYS_PREFIX) && SYS_PREFIX == 0
  1771. #define LSS_NAME(name) sys0_##name
  1772. #elif defined(SYS_PREFIX) && SYS_PREFIX == 1
  1773. #define LSS_NAME(name) sys1_##name
  1774. #elif defined(SYS_PREFIX) && SYS_PREFIX == 2
  1775. #define LSS_NAME(name) sys2_##name
  1776. #elif defined(SYS_PREFIX) && SYS_PREFIX == 3
  1777. #define LSS_NAME(name) sys3_##name
  1778. #elif defined(SYS_PREFIX) && SYS_PREFIX == 4
  1779. #define LSS_NAME(name) sys4_##name
  1780. #elif defined(SYS_PREFIX) && SYS_PREFIX == 5
  1781. #define LSS_NAME(name) sys5_##name
  1782. #elif defined(SYS_PREFIX) && SYS_PREFIX == 6
  1783. #define LSS_NAME(name) sys6_##name
  1784. #elif defined(SYS_PREFIX) && SYS_PREFIX == 7
  1785. #define LSS_NAME(name) sys7_##name
  1786. #elif defined(SYS_PREFIX) && SYS_PREFIX == 8
  1787. #define LSS_NAME(name) sys8_##name
  1788. #elif defined(SYS_PREFIX) && SYS_PREFIX == 9
  1789. #define LSS_NAME(name) sys9_##name
  1790. #endif
  1791. #undef LSS_RETURN
  1792. #if (defined(__i386__) || defined(__x86_64__) || defined(__ARM_ARCH_3__) \
  1793. || defined(__ARM_EABI__) || defined(__aarch64__) || defined(__s390__))
  1794. /* Failing system calls return a negative result in the range of
  1795. * -1..-4095. These are "errno" values with the sign inverted.
  1796. */
  1797. #define LSS_RETURN(type, res) \
  1798. do { \
  1799. if ((unsigned long)(res) >= (unsigned long)(-4095)) { \
  1800. LSS_ERRNO = -(res); \
  1801. res = -1; \
  1802. } \
  1803. return (type) (res); \
  1804. } while (0)
  1805. #elif defined(__mips__)
  1806. /* On MIPS, failing system calls return -1, and set errno in a
  1807. * separate CPU register.
  1808. */
  1809. #define LSS_RETURN(type, res, err) \
  1810. do { \
  1811. if (err) { \
  1812. unsigned long __errnovalue = (res); \
  1813. LSS_ERRNO = __errnovalue; \
  1814. res = -1; \
  1815. } \
  1816. return (type) (res); \
  1817. } while (0)
  1818. #elif defined(__PPC__)
  1819. /* On PPC, failing system calls return -1, and set errno in a
  1820. * separate CPU register. See linux/unistd.h.
  1821. */
  1822. #define LSS_RETURN(type, res, err) \
  1823. do { \
  1824. if (err & 0x10000000 ) { \
  1825. LSS_ERRNO = (res); \
  1826. res = -1; \
  1827. } \
  1828. return (type) (res); \
  1829. } while (0)
  1830. #endif
  1831. #if defined(__i386__)
  1832. /* In PIC mode (e.g. when building shared libraries), gcc for i386
  1833. * reserves ebx. Unfortunately, most distribution ship with implementations
  1834. * of _syscallX() which clobber ebx.
  1835. * Also, most definitions of _syscallX() neglect to mark "memory" as being
  1836. * clobbered. This causes problems with compilers, that do a better job
  1837. * at optimizing across __asm__ calls.
  1838. * So, we just have to redefine all of the _syscallX() macros.
  1839. */
  1840. #undef LSS_ENTRYPOINT
  1841. #ifdef SYS_SYSCALL_ENTRYPOINT
  1842. static inline void (**LSS_NAME(get_syscall_entrypoint)(void))(void) {
  1843. void (**entrypoint)(void);
  1844. asm volatile(".bss\n"
  1845. ".align 8\n"
  1846. ".globl " SYS_SYSCALL_ENTRYPOINT "\n"
  1847. ".common " SYS_SYSCALL_ENTRYPOINT ",8,8\n"
  1848. ".previous\n"
  1849. /* This logically does 'lea "SYS_SYSCALL_ENTRYPOINT", %0' */
  1850. "call 0f\n"
  1851. "0:pop %0\n"
  1852. "add $_GLOBAL_OFFSET_TABLE_+[.-0b], %0\n"
  1853. "mov " SYS_SYSCALL_ENTRYPOINT "@GOT(%0), %0\n"
  1854. : "=r"(entrypoint));
  1855. return entrypoint;
  1856. }
  1857. #define LSS_ENTRYPOINT ".bss\n" \
  1858. ".align 8\n" \
  1859. ".globl " SYS_SYSCALL_ENTRYPOINT "\n" \
  1860. ".common " SYS_SYSCALL_ENTRYPOINT ",8,8\n" \
  1861. ".previous\n" \
  1862. /* Check the SYS_SYSCALL_ENTRYPOINT vector */ \
  1863. "push %%eax\n" \
  1864. "call 10000f\n" \
  1865. "10000:pop %%eax\n" \
  1866. "add $_GLOBAL_OFFSET_TABLE_+[.-10000b], %%eax\n" \
  1867. "mov " SYS_SYSCALL_ENTRYPOINT \
  1868. "@GOT(%%eax), %%eax\n" \
  1869. "mov 0(%%eax), %%eax\n" \
  1870. "test %%eax, %%eax\n" \
  1871. "jz 10002f\n" \
  1872. "push %%eax\n" \
  1873. "call 10001f\n" \
  1874. "10001:pop %%eax\n" \
  1875. "add $(10003f-10001b), %%eax\n" \
  1876. "xchg 4(%%esp), %%eax\n" \
  1877. "ret\n" \
  1878. "10002:pop %%eax\n" \
  1879. "int $0x80\n" \
  1880. "10003:\n"
  1881. #else
  1882. #define LSS_ENTRYPOINT "int $0x80\n"
  1883. #endif
  1884. #undef LSS_BODY
  1885. #define LSS_BODY(type,args...) \
  1886. long __res; \
  1887. __asm__ __volatile__("push %%ebx\n" \
  1888. "movl %2,%%ebx\n" \
  1889. LSS_ENTRYPOINT \
  1890. "pop %%ebx" \
  1891. args \
  1892. : "esp", "memory"); \
  1893. LSS_RETURN(type,__res)
  1894. #undef _syscall0
  1895. #define _syscall0(type,name) \
  1896. type LSS_NAME(name)(void) { \
  1897. long __res; \
  1898. __asm__ volatile(LSS_ENTRYPOINT \
  1899. : "=a" (__res) \
  1900. : "0" (__NR_##name) \
  1901. : "esp", "memory"); \
  1902. LSS_RETURN(type,__res); \
  1903. }
  1904. #undef _syscall1
  1905. #define _syscall1(type,name,type1,arg1) \
  1906. type LSS_NAME(name)(type1 arg1) { \
  1907. LSS_BODY(type, \
  1908. : "=a" (__res) \
  1909. : "0" (__NR_##name), "ri" ((long)(arg1))); \
  1910. }
  1911. #undef _syscall2
  1912. #define _syscall2(type,name,type1,arg1,type2,arg2) \
  1913. type LSS_NAME(name)(type1 arg1,type2 arg2) { \
  1914. LSS_BODY(type, \
  1915. : "=a" (__res) \
  1916. : "0" (__NR_##name),"ri" ((long)(arg1)), "c" ((long)(arg2))); \
  1917. }
  1918. #undef _syscall3
  1919. #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  1920. type LSS_NAME(name)(type1 arg1,type2 arg2,type3 arg3) { \
  1921. LSS_BODY(type, \
  1922. : "=a" (__res) \
  1923. : "0" (__NR_##name), "ri" ((long)(arg1)), "c" ((long)(arg2)), \
  1924. "d" ((long)(arg3))); \
  1925. }
  1926. #undef _syscall4
  1927. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  1928. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \
  1929. LSS_BODY(type, \
  1930. : "=a" (__res) \
  1931. : "0" (__NR_##name), "ri" ((long)(arg1)), "c" ((long)(arg2)), \
  1932. "d" ((long)(arg3)),"S" ((long)(arg4))); \
  1933. }
  1934. #undef _syscall5
  1935. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  1936. type5,arg5) \
  1937. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
  1938. type5 arg5) { \
  1939. long __res; \
  1940. __asm__ __volatile__("push %%ebx\n" \
  1941. "movl %2,%%ebx\n" \
  1942. "movl %1,%%eax\n" \
  1943. LSS_ENTRYPOINT \
  1944. "pop %%ebx" \
  1945. : "=a" (__res) \
  1946. : "i" (__NR_##name), "ri" ((long)(arg1)), \
  1947. "c" ((long)(arg2)), "d" ((long)(arg3)), \
  1948. "S" ((long)(arg4)), "D" ((long)(arg5)) \
  1949. : "esp", "memory"); \
  1950. LSS_RETURN(type,__res); \
  1951. }
  1952. #undef _syscall6
  1953. #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  1954. type5,arg5,type6,arg6) \
  1955. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
  1956. type5 arg5, type6 arg6) { \
  1957. long __res; \
  1958. struct { long __a1; long __a6; } __s = { (long)arg1, (long) arg6 }; \
  1959. __asm__ __volatile__("push %%ebp\n" \
  1960. "push %%ebx\n" \
  1961. "movl 4(%2),%%ebp\n" \
  1962. "movl 0(%2), %%ebx\n" \
  1963. "movl %1,%%eax\n" \
  1964. LSS_ENTRYPOINT \
  1965. "pop %%ebx\n" \
  1966. "pop %%ebp" \
  1967. : "=a" (__res) \
  1968. : "i" (__NR_##name), "0" ((long)(&__s)), \
  1969. "c" ((long)(arg2)), "d" ((long)(arg3)), \
  1970. "S" ((long)(arg4)), "D" ((long)(arg5)) \
  1971. : "esp", "memory"); \
  1972. LSS_RETURN(type,__res); \
  1973. }
  1974. LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack,
  1975. int flags, void *arg, int *parent_tidptr,
  1976. void *newtls, int *child_tidptr) {
  1977. long __res;
  1978. __asm__ __volatile__(/* if (fn == NULL)
  1979. * return -EINVAL;
  1980. */
  1981. "movl %3,%%ecx\n"
  1982. "jecxz 1f\n"
  1983. /* if (child_stack == NULL)
  1984. * return -EINVAL;
  1985. */
  1986. "movl %4,%%ecx\n"
  1987. "jecxz 1f\n"
  1988. /* Set up alignment of the child stack:
  1989. * child_stack = (child_stack & ~0xF) - 20;
  1990. */
  1991. "andl $-16,%%ecx\n"
  1992. "subl $20,%%ecx\n"
  1993. /* Push "arg" and "fn" onto the stack that will be
  1994. * used by the child.
  1995. */
  1996. "movl %6,%%eax\n"
  1997. "movl %%eax,4(%%ecx)\n"
  1998. "movl %3,%%eax\n"
  1999. "movl %%eax,(%%ecx)\n"
  2000. /* %eax = syscall(%eax = __NR_clone,
  2001. * %ebx = flags,
  2002. * %ecx = child_stack,
  2003. * %edx = parent_tidptr,
  2004. * %esi = newtls,
  2005. * %edi = child_tidptr)
  2006. * Also, make sure that %ebx gets preserved as it is
  2007. * used in PIC mode.
  2008. */
  2009. "movl %8,%%esi\n"
  2010. "movl %7,%%edx\n"
  2011. "movl %5,%%eax\n"
  2012. "movl %9,%%edi\n"
  2013. "pushl %%ebx\n"
  2014. "movl %%eax,%%ebx\n"
  2015. "movl %2,%%eax\n"
  2016. LSS_ENTRYPOINT
  2017. /* In the parent: restore %ebx
  2018. * In the child: move "fn" into %ebx
  2019. */
  2020. "popl %%ebx\n"
  2021. /* if (%eax != 0)
  2022. * return %eax;
  2023. */
  2024. "test %%eax,%%eax\n"
  2025. "jnz 1f\n"
  2026. /* In the child, now. Terminate frame pointer chain.
  2027. */
  2028. "movl $0,%%ebp\n"
  2029. /* Call "fn". "arg" is already on the stack.
  2030. */
  2031. "call *%%ebx\n"
  2032. /* Call _exit(%ebx). Unfortunately older versions
  2033. * of gcc restrict the number of arguments that can
  2034. * be passed to asm(). So, we need to hard-code the
  2035. * system call number.
  2036. */
  2037. "movl %%eax,%%ebx\n"
  2038. "movl $1,%%eax\n"
  2039. LSS_ENTRYPOINT
  2040. /* Return to parent.
  2041. */
  2042. "1:\n"
  2043. : "=a" (__res)
  2044. : "0"(-EINVAL), "i"(__NR_clone),
  2045. "m"(fn), "m"(child_stack), "m"(flags), "m"(arg),
  2046. "m"(parent_tidptr), "m"(newtls), "m"(child_tidptr)
  2047. : "esp", "memory", "ecx", "edx", "esi", "edi");
  2048. LSS_RETURN(int, __res);
  2049. }
  2050. LSS_INLINE _syscall1(int, set_thread_area, void *, u)
  2051. LSS_INLINE _syscall1(int, get_thread_area, void *, u)
  2052. LSS_INLINE void (*LSS_NAME(restore_rt)(void))(void) {
  2053. /* On i386, the kernel does not know how to return from a signal
  2054. * handler. Instead, it relies on user space to provide a
  2055. * restorer function that calls the {rt_,}sigreturn() system call.
  2056. * Unfortunately, we cannot just reference the glibc version of this
  2057. * function, as glibc goes out of its way to make it inaccessible.
  2058. */
  2059. void (*res)(void);
  2060. __asm__ __volatile__("call 2f\n"
  2061. "0:.align 16\n"
  2062. "1:movl %1,%%eax\n"
  2063. LSS_ENTRYPOINT
  2064. "2:popl %0\n"
  2065. "addl $(1b-0b),%0\n"
  2066. : "=a" (res)
  2067. : "i" (__NR_rt_sigreturn));
  2068. return res;
  2069. }
  2070. LSS_INLINE void (*LSS_NAME(restore)(void))(void) {
  2071. /* On i386, the kernel does not know how to return from a signal
  2072. * handler. Instead, it relies on user space to provide a
  2073. * restorer function that calls the {rt_,}sigreturn() system call.
  2074. * Unfortunately, we cannot just reference the glibc version of this
  2075. * function, as glibc goes out of its way to make it inaccessible.
  2076. */
  2077. void (*res)(void);
  2078. __asm__ __volatile__("call 2f\n"
  2079. "0:.align 16\n"
  2080. "1:pop %%eax\n"
  2081. "movl %1,%%eax\n"
  2082. LSS_ENTRYPOINT
  2083. "2:popl %0\n"
  2084. "addl $(1b-0b),%0\n"
  2085. : "=a" (res)
  2086. : "i" (__NR_sigreturn));
  2087. return res;
  2088. }
  2089. #elif defined(__x86_64__)
  2090. /* There are no known problems with any of the _syscallX() macros
  2091. * currently shipping for x86_64, but we still need to be able to define
  2092. * our own version so that we can override the location of the errno
  2093. * location (e.g. when using the clone() system call with the CLONE_VM
  2094. * option).
  2095. */
  2096. #undef LSS_ENTRYPOINT
  2097. #ifdef SYS_SYSCALL_ENTRYPOINT
  2098. static inline void (**LSS_NAME(get_syscall_entrypoint)(void))(void) {
  2099. void (**entrypoint)(void);
  2100. asm volatile(".bss\n"
  2101. ".align 8\n"
  2102. ".globl " SYS_SYSCALL_ENTRYPOINT "\n"
  2103. ".common " SYS_SYSCALL_ENTRYPOINT ",8,8\n"
  2104. ".previous\n"
  2105. "mov " SYS_SYSCALL_ENTRYPOINT "@GOTPCREL(%%rip), %0\n"
  2106. : "=r"(entrypoint));
  2107. return entrypoint;
  2108. }
  2109. #define LSS_ENTRYPOINT \
  2110. ".bss\n" \
  2111. ".align 8\n" \
  2112. ".globl " SYS_SYSCALL_ENTRYPOINT "\n" \
  2113. ".common " SYS_SYSCALL_ENTRYPOINT ",8,8\n" \
  2114. ".previous\n" \
  2115. "mov " SYS_SYSCALL_ENTRYPOINT "@GOTPCREL(%%rip), %%rcx\n" \
  2116. "mov 0(%%rcx), %%rcx\n" \
  2117. "test %%rcx, %%rcx\n" \
  2118. "jz 10001f\n" \
  2119. "call *%%rcx\n" \
  2120. "jmp 10002f\n" \
  2121. "10001:syscall\n" \
  2122. "10002:\n"
  2123. #else
  2124. #define LSS_ENTRYPOINT "syscall\n"
  2125. #endif
  2126. /* The x32 ABI has 32 bit longs, but the syscall interface is 64 bit.
  2127. * We need to explicitly cast to an unsigned 64 bit type to avoid implicit
  2128. * sign extension. We can't cast pointers directly because those are
  2129. * 32 bits, and gcc will dump ugly warnings about casting from a pointer
  2130. * to an integer of a different size.
  2131. */
  2132. #undef LSS_SYSCALL_ARG
  2133. #define LSS_SYSCALL_ARG(a) ((uint64_t)(uintptr_t)(a))
  2134. #undef _LSS_RETURN
  2135. #define _LSS_RETURN(type, res, cast) \
  2136. do { \
  2137. if ((uint64_t)(res) >= (uint64_t)(-4095)) { \
  2138. LSS_ERRNO = -(res); \
  2139. res = -1; \
  2140. } \
  2141. return (type)(cast)(res); \
  2142. } while (0)
  2143. #undef LSS_RETURN
  2144. #define LSS_RETURN(type, res) _LSS_RETURN(type, res, uintptr_t)
  2145. #undef _LSS_BODY
  2146. #define _LSS_BODY(nr, type, name, cast, ...) \
  2147. long long __res; \
  2148. __asm__ __volatile__(LSS_BODY_ASM##nr LSS_ENTRYPOINT \
  2149. : "=a" (__res) \
  2150. : "0" (__NR_##name) LSS_BODY_ARG##nr(__VA_ARGS__) \
  2151. : LSS_BODY_CLOBBER##nr "r11", "rcx", "memory"); \
  2152. _LSS_RETURN(type, __res, cast)
  2153. #undef LSS_BODY
  2154. #define LSS_BODY(nr, type, name, args...) \
  2155. _LSS_BODY(nr, type, name, uintptr_t, ## args)
  2156. #undef LSS_BODY_ASM0
  2157. #undef LSS_BODY_ASM1
  2158. #undef LSS_BODY_ASM2
  2159. #undef LSS_BODY_ASM3
  2160. #undef LSS_BODY_ASM4
  2161. #undef LSS_BODY_ASM5
  2162. #undef LSS_BODY_ASM6
  2163. #define LSS_BODY_ASM0
  2164. #define LSS_BODY_ASM1 LSS_BODY_ASM0
  2165. #define LSS_BODY_ASM2 LSS_BODY_ASM1
  2166. #define LSS_BODY_ASM3 LSS_BODY_ASM2
  2167. #define LSS_BODY_ASM4 LSS_BODY_ASM3 "movq %5,%%r10;"
  2168. #define LSS_BODY_ASM5 LSS_BODY_ASM4 "movq %6,%%r8;"
  2169. #define LSS_BODY_ASM6 LSS_BODY_ASM5 "movq %7,%%r9;"
  2170. #undef LSS_BODY_CLOBBER0
  2171. #undef LSS_BODY_CLOBBER1
  2172. #undef LSS_BODY_CLOBBER2
  2173. #undef LSS_BODY_CLOBBER3
  2174. #undef LSS_BODY_CLOBBER4
  2175. #undef LSS_BODY_CLOBBER5
  2176. #undef LSS_BODY_CLOBBER6
  2177. #define LSS_BODY_CLOBBER0
  2178. #define LSS_BODY_CLOBBER1 LSS_BODY_CLOBBER0
  2179. #define LSS_BODY_CLOBBER2 LSS_BODY_CLOBBER1
  2180. #define LSS_BODY_CLOBBER3 LSS_BODY_CLOBBER2
  2181. #define LSS_BODY_CLOBBER4 LSS_BODY_CLOBBER3 "r10",
  2182. #define LSS_BODY_CLOBBER5 LSS_BODY_CLOBBER4 "r8",
  2183. #define LSS_BODY_CLOBBER6 LSS_BODY_CLOBBER5 "r9",
  2184. #undef LSS_BODY_ARG0
  2185. #undef LSS_BODY_ARG1
  2186. #undef LSS_BODY_ARG2
  2187. #undef LSS_BODY_ARG3
  2188. #undef LSS_BODY_ARG4
  2189. #undef LSS_BODY_ARG5
  2190. #undef LSS_BODY_ARG6
  2191. #define LSS_BODY_ARG0()
  2192. #define LSS_BODY_ARG1(arg1) \
  2193. LSS_BODY_ARG0(), "D" (arg1)
  2194. #define LSS_BODY_ARG2(arg1, arg2) \
  2195. LSS_BODY_ARG1(arg1), "S" (arg2)
  2196. #define LSS_BODY_ARG3(arg1, arg2, arg3) \
  2197. LSS_BODY_ARG2(arg1, arg2), "d" (arg3)
  2198. #define LSS_BODY_ARG4(arg1, arg2, arg3, arg4) \
  2199. LSS_BODY_ARG3(arg1, arg2, arg3), "r" (arg4)
  2200. #define LSS_BODY_ARG5(arg1, arg2, arg3, arg4, arg5) \
  2201. LSS_BODY_ARG4(arg1, arg2, arg3, arg4), "r" (arg5)
  2202. #define LSS_BODY_ARG6(arg1, arg2, arg3, arg4, arg5, arg6) \
  2203. LSS_BODY_ARG5(arg1, arg2, arg3, arg4, arg5), "r" (arg6)
  2204. #undef _syscall0
  2205. #define _syscall0(type,name) \
  2206. type LSS_NAME(name)(void) { \
  2207. LSS_BODY(0, type, name); \
  2208. }
  2209. #undef _syscall1
  2210. #define _syscall1(type,name,type1,arg1) \
  2211. type LSS_NAME(name)(type1 arg1) { \
  2212. LSS_BODY(1, type, name, LSS_SYSCALL_ARG(arg1)); \
  2213. }
  2214. #undef _syscall2
  2215. #define _syscall2(type,name,type1,arg1,type2,arg2) \
  2216. type LSS_NAME(name)(type1 arg1, type2 arg2) { \
  2217. LSS_BODY(2, type, name, LSS_SYSCALL_ARG(arg1), LSS_SYSCALL_ARG(arg2));\
  2218. }
  2219. #undef _syscall3
  2220. #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  2221. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) { \
  2222. LSS_BODY(3, type, name, LSS_SYSCALL_ARG(arg1), LSS_SYSCALL_ARG(arg2), \
  2223. LSS_SYSCALL_ARG(arg3)); \
  2224. }
  2225. #undef _syscall4
  2226. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  2227. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \
  2228. LSS_BODY(4, type, name, LSS_SYSCALL_ARG(arg1), LSS_SYSCALL_ARG(arg2), \
  2229. LSS_SYSCALL_ARG(arg3), LSS_SYSCALL_ARG(arg4));\
  2230. }
  2231. #undef _syscall5
  2232. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  2233. type5,arg5) \
  2234. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
  2235. type5 arg5) { \
  2236. LSS_BODY(5, type, name, LSS_SYSCALL_ARG(arg1), LSS_SYSCALL_ARG(arg2), \
  2237. LSS_SYSCALL_ARG(arg3), LSS_SYSCALL_ARG(arg4), \
  2238. LSS_SYSCALL_ARG(arg5)); \
  2239. }
  2240. #undef _syscall6
  2241. #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  2242. type5,arg5,type6,arg6) \
  2243. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
  2244. type5 arg5, type6 arg6) { \
  2245. LSS_BODY(6, type, name, LSS_SYSCALL_ARG(arg1), LSS_SYSCALL_ARG(arg2), \
  2246. LSS_SYSCALL_ARG(arg3), LSS_SYSCALL_ARG(arg4), \
  2247. LSS_SYSCALL_ARG(arg5), LSS_SYSCALL_ARG(arg6));\
  2248. }
  2249. LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack,
  2250. int flags, void *arg, int *parent_tidptr,
  2251. void *newtls, int *child_tidptr) {
  2252. long long __res;
  2253. {
  2254. __asm__ __volatile__(/* if (fn == NULL)
  2255. * return -EINVAL;
  2256. */
  2257. "testq %4,%4\n"
  2258. "jz 1f\n"
  2259. /* if (child_stack == NULL)
  2260. * return -EINVAL;
  2261. */
  2262. "testq %5,%5\n"
  2263. "jz 1f\n"
  2264. /* childstack -= 2*sizeof(void *);
  2265. */
  2266. "subq $16,%5\n"
  2267. /* Push "arg" and "fn" onto the stack that will be
  2268. * used by the child.
  2269. */
  2270. "movq %7,8(%5)\n"
  2271. "movq %4,0(%5)\n"
  2272. /* %rax = syscall(%rax = __NR_clone,
  2273. * %rdi = flags,
  2274. * %rsi = child_stack,
  2275. * %rdx = parent_tidptr,
  2276. * %r8 = new_tls,
  2277. * %r10 = child_tidptr)
  2278. */
  2279. "movq %2,%%rax\n"
  2280. "movq %9,%%r8\n"
  2281. "movq %10,%%r10\n"
  2282. LSS_ENTRYPOINT
  2283. /* if (%rax != 0)
  2284. * return;
  2285. */
  2286. "testq %%rax,%%rax\n"
  2287. "jnz 1f\n"
  2288. /* In the child. Terminate frame pointer chain.
  2289. */
  2290. "xorq %%rbp,%%rbp\n"
  2291. /* Call "fn(arg)".
  2292. */
  2293. "popq %%rax\n"
  2294. "popq %%rdi\n"
  2295. "call *%%rax\n"
  2296. /* Call _exit(%ebx).
  2297. */
  2298. "movq %%rax,%%rdi\n"
  2299. "movq %3,%%rax\n"
  2300. LSS_ENTRYPOINT
  2301. /* Return to parent.
  2302. */
  2303. "1:\n"
  2304. : "=a" (__res)
  2305. : "0"(-EINVAL), "i"(__NR_clone), "i"(__NR_exit),
  2306. "r"(LSS_SYSCALL_ARG(fn)),
  2307. "S"(LSS_SYSCALL_ARG(child_stack)),
  2308. "D"(LSS_SYSCALL_ARG(flags)),
  2309. "r"(LSS_SYSCALL_ARG(arg)),
  2310. "d"(LSS_SYSCALL_ARG(parent_tidptr)),
  2311. "r"(LSS_SYSCALL_ARG(newtls)),
  2312. "r"(LSS_SYSCALL_ARG(child_tidptr))
  2313. : "rsp", "memory", "r8", "r10", "r11", "rcx");
  2314. }
  2315. LSS_RETURN(int, __res);
  2316. }
  2317. LSS_INLINE _syscall2(int, arch_prctl, int, c, void *, a)
  2318. LSS_INLINE void (*LSS_NAME(restore_rt)(void))(void) {
  2319. /* On x86-64, the kernel does not know how to return from
  2320. * a signal handler. Instead, it relies on user space to provide a
  2321. * restorer function that calls the rt_sigreturn() system call.
  2322. * Unfortunately, we cannot just reference the glibc version of this
  2323. * function, as glibc goes out of its way to make it inaccessible.
  2324. */
  2325. long long res;
  2326. __asm__ __volatile__("jmp 2f\n"
  2327. ".align 16\n"
  2328. "1:movq %1,%%rax\n"
  2329. LSS_ENTRYPOINT
  2330. "2:leaq 1b(%%rip),%0\n"
  2331. : "=r" (res)
  2332. : "i" (__NR_rt_sigreturn));
  2333. return (void (*)(void))(uintptr_t)res;
  2334. }
  2335. #elif defined(__ARM_ARCH_3__)
  2336. /* Most definitions of _syscallX() neglect to mark "memory" as being
  2337. * clobbered. This causes problems with compilers, that do a better job
  2338. * at optimizing across __asm__ calls.
  2339. * So, we just have to redefine all of the _syscallX() macros.
  2340. */
  2341. #undef LSS_REG
  2342. #define LSS_REG(r,a) register long __r##r __asm__("r"#r) = (long)a
  2343. #undef LSS_BODY
  2344. #define LSS_BODY(type,name,args...) \
  2345. register long __res_r0 __asm__("r0"); \
  2346. long __res; \
  2347. __asm__ __volatile__ (__syscall(name) \
  2348. : "=r"(__res_r0) : args : "lr", "memory"); \
  2349. __res = __res_r0; \
  2350. LSS_RETURN(type, __res)
  2351. #undef _syscall0
  2352. #define _syscall0(type, name) \
  2353. type LSS_NAME(name)(void) { \
  2354. LSS_BODY(type, name); \
  2355. }
  2356. #undef _syscall1
  2357. #define _syscall1(type, name, type1, arg1) \
  2358. type LSS_NAME(name)(type1 arg1) { \
  2359. LSS_REG(0, arg1); LSS_BODY(type, name, "r"(__r0)); \
  2360. }
  2361. #undef _syscall2
  2362. #define _syscall2(type, name, type1, arg1, type2, arg2) \
  2363. type LSS_NAME(name)(type1 arg1, type2 arg2) { \
  2364. LSS_REG(0, arg1); LSS_REG(1, arg2); \
  2365. LSS_BODY(type, name, "r"(__r0), "r"(__r1)); \
  2366. }
  2367. #undef _syscall3
  2368. #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
  2369. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) { \
  2370. LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \
  2371. LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2)); \
  2372. }
  2373. #undef _syscall4
  2374. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  2375. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \
  2376. LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \
  2377. LSS_REG(3, arg4); \
  2378. LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3)); \
  2379. }
  2380. #undef _syscall5
  2381. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  2382. type5,arg5) \
  2383. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
  2384. type5 arg5) { \
  2385. LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \
  2386. LSS_REG(3, arg4); LSS_REG(4, arg5); \
  2387. LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3), \
  2388. "r"(__r4)); \
  2389. }
  2390. #undef _syscall6
  2391. #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  2392. type5,arg5,type6,arg6) \
  2393. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
  2394. type5 arg5, type6 arg6) { \
  2395. LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \
  2396. LSS_REG(3, arg4); LSS_REG(4, arg5); LSS_REG(5, arg6); \
  2397. LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3), \
  2398. "r"(__r4), "r"(__r5)); \
  2399. }
  2400. LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack,
  2401. int flags, void *arg, int *parent_tidptr,
  2402. void *newtls, int *child_tidptr) {
  2403. long __res;
  2404. {
  2405. register int __flags __asm__("r0") = flags;
  2406. register void *__stack __asm__("r1") = child_stack;
  2407. register void *__ptid __asm__("r2") = parent_tidptr;
  2408. register void *__tls __asm__("r3") = newtls;
  2409. register int *__ctid __asm__("r4") = child_tidptr;
  2410. __asm__ __volatile__(/* if (fn == NULL || child_stack == NULL)
  2411. * return -EINVAL;
  2412. */
  2413. "cmp %2,#0\n"
  2414. "cmpne %3,#0\n"
  2415. "moveq %0,%1\n"
  2416. "beq 1f\n"
  2417. /* Push "arg" and "fn" onto the stack that will be
  2418. * used by the child.
  2419. */
  2420. "str %5,[%3,#-4]!\n"
  2421. "str %2,[%3,#-4]!\n"
  2422. /* %r0 = syscall(%r0 = flags,
  2423. * %r1 = child_stack,
  2424. * %r2 = parent_tidptr,
  2425. * %r3 = newtls,
  2426. * %r4 = child_tidptr)
  2427. */
  2428. __syscall(clone)"\n"
  2429. /* if (%r0 != 0)
  2430. * return %r0;
  2431. */
  2432. "movs %0,r0\n"
  2433. "bne 1f\n"
  2434. /* In the child, now. Call "fn(arg)".
  2435. */
  2436. "ldr r0,[sp, #4]\n"
  2437. "mov lr,pc\n"
  2438. "ldr pc,[sp]\n"
  2439. /* Call _exit(%r0).
  2440. */
  2441. __syscall(exit)"\n"
  2442. "1:\n"
  2443. : "=r" (__res)
  2444. : "i"(-EINVAL),
  2445. "r"(fn), "r"(__stack), "r"(__flags), "r"(arg),
  2446. "r"(__ptid), "r"(__tls), "r"(__ctid)
  2447. : "cc", "lr", "memory");
  2448. }
  2449. LSS_RETURN(int, __res);
  2450. }
  2451. #elif defined(__ARM_EABI__)
  2452. /* Most definitions of _syscallX() neglect to mark "memory" as being
  2453. * clobbered. This causes problems with compilers, that do a better job
  2454. * at optimizing across __asm__ calls.
  2455. * So, we just have to redefine all fo the _syscallX() macros.
  2456. */
  2457. #undef LSS_REG
  2458. #define LSS_REG(r,a) register long __r##r __asm__("r"#r) = (long)a
  2459. #undef LSS_BODY
  2460. #define LSS_BODY(type,name,args...) \
  2461. register long __res_r0 __asm__("r0"); \
  2462. long __res; \
  2463. __asm__ __volatile__ ("push {r7}\n" \
  2464. "mov r7, %1\n" \
  2465. "swi 0x0\n" \
  2466. "pop {r7}\n" \
  2467. : "=r"(__res_r0) \
  2468. : "i"(__NR_##name) , ## args \
  2469. : "lr", "memory"); \
  2470. __res = __res_r0; \
  2471. LSS_RETURN(type, __res)
  2472. #undef _syscall0
  2473. #define _syscall0(type, name) \
  2474. type LSS_NAME(name)(void) { \
  2475. LSS_BODY(type, name); \
  2476. }
  2477. #undef _syscall1
  2478. #define _syscall1(type, name, type1, arg1) \
  2479. type LSS_NAME(name)(type1 arg1) { \
  2480. LSS_REG(0, arg1); LSS_BODY(type, name, "r"(__r0)); \
  2481. }
  2482. #undef _syscall2
  2483. #define _syscall2(type, name, type1, arg1, type2, arg2) \
  2484. type LSS_NAME(name)(type1 arg1, type2 arg2) { \
  2485. LSS_REG(0, arg1); LSS_REG(1, arg2); \
  2486. LSS_BODY(type, name, "r"(__r0), "r"(__r1)); \
  2487. }
  2488. #undef _syscall3
  2489. #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
  2490. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) { \
  2491. LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \
  2492. LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2)); \
  2493. }
  2494. #undef _syscall4
  2495. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  2496. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \
  2497. LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \
  2498. LSS_REG(3, arg4); \
  2499. LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3)); \
  2500. }
  2501. #undef _syscall5
  2502. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  2503. type5,arg5) \
  2504. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
  2505. type5 arg5) { \
  2506. LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \
  2507. LSS_REG(3, arg4); LSS_REG(4, arg5); \
  2508. LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3), \
  2509. "r"(__r4)); \
  2510. }
  2511. #undef _syscall6
  2512. #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  2513. type5,arg5,type6,arg6) \
  2514. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
  2515. type5 arg5, type6 arg6) { \
  2516. LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \
  2517. LSS_REG(3, arg4); LSS_REG(4, arg5); LSS_REG(5, arg6); \
  2518. LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3), \
  2519. "r"(__r4), "r"(__r5)); \
  2520. }
  2521. LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack,
  2522. int flags, void *arg, int *parent_tidptr,
  2523. void *newtls, int *child_tidptr) {
  2524. long __res;
  2525. if (fn == NULL || child_stack == NULL) {
  2526. __res = -EINVAL;
  2527. LSS_RETURN(int, __res);
  2528. }
  2529. /* Push "arg" and "fn" onto the stack that will be
  2530. * used by the child.
  2531. */
  2532. {
  2533. uintptr_t* cstack = (uintptr_t*)child_stack - 2;
  2534. cstack[0] = (uintptr_t)fn;
  2535. cstack[1] = (uintptr_t)arg;
  2536. child_stack = cstack;
  2537. }
  2538. {
  2539. register int __flags __asm__("r0") = flags;
  2540. register void *__stack __asm__("r1") = child_stack;
  2541. register void *__ptid __asm__("r2") = parent_tidptr;
  2542. register void *__tls __asm__("r3") = newtls;
  2543. register int *__ctid __asm__("r4") = child_tidptr;
  2544. __asm__ __volatile__(
  2545. #ifdef __thumb2__
  2546. "push {r7}\n"
  2547. #endif
  2548. /* %r0 = syscall(%r0 = flags,
  2549. * %r1 = child_stack,
  2550. * %r2 = parent_tidptr,
  2551. * %r3 = newtls,
  2552. * %r4 = child_tidptr)
  2553. */
  2554. "mov r7, %6\n"
  2555. "swi 0x0\n"
  2556. /* if (%r0 != 0)
  2557. * return %r0;
  2558. */
  2559. "cmp r0, #0\n"
  2560. "bne 1f\n"
  2561. /* In the child, now. Call "fn(arg)".
  2562. */
  2563. "ldr r0,[sp, #4]\n"
  2564. "ldr lr,[sp]\n"
  2565. "blx lr\n"
  2566. /* Call _exit(%r0).
  2567. */
  2568. "mov r7, %7\n"
  2569. "swi 0x0\n"
  2570. /* Unreachable */
  2571. "bkpt #0\n"
  2572. "1:\n"
  2573. #ifdef __thumb2__
  2574. "pop {r7}\n"
  2575. #endif
  2576. "movs %0,r0\n"
  2577. : "=r"(__res)
  2578. : "r"(__stack), "r"(__flags), "r"(__ptid), "r"(__tls), "r"(__ctid),
  2579. "i"(__NR_clone), "i"(__NR_exit)
  2580. : "cc", "lr", "memory"
  2581. #ifndef __thumb2__
  2582. , "r7"
  2583. #endif
  2584. );
  2585. }
  2586. LSS_RETURN(int, __res);
  2587. }
  2588. #elif defined(__aarch64__)
  2589. /* Most definitions of _syscallX() neglect to mark "memory" as being
  2590. * clobbered. This causes problems with compilers, that do a better job
  2591. * at optimizing across __asm__ calls.
  2592. * So, we just have to redefine all of the _syscallX() macros.
  2593. */
  2594. #undef LSS_REG
  2595. #define LSS_REG(r,a) register int64_t __r##r __asm__("x"#r) = (int64_t)a
  2596. #undef LSS_BODY
  2597. #define LSS_BODY(type,name,args...) \
  2598. register int64_t __res_x0 __asm__("x0"); \
  2599. int64_t __res; \
  2600. __asm__ __volatile__ ("mov x8, %1\n" \
  2601. "svc 0x0\n" \
  2602. : "=r"(__res_x0) \
  2603. : "i"(__NR_##name) , ## args \
  2604. : "x8", "memory"); \
  2605. __res = __res_x0; \
  2606. LSS_RETURN(type, __res)
  2607. #undef _syscall0
  2608. #define _syscall0(type, name) \
  2609. type LSS_NAME(name)(void) { \
  2610. LSS_BODY(type, name); \
  2611. }
  2612. #undef _syscall1
  2613. #define _syscall1(type, name, type1, arg1) \
  2614. type LSS_NAME(name)(type1 arg1) { \
  2615. LSS_REG(0, arg1); LSS_BODY(type, name, "r"(__r0)); \
  2616. }
  2617. #undef _syscall2
  2618. #define _syscall2(type, name, type1, arg1, type2, arg2) \
  2619. type LSS_NAME(name)(type1 arg1, type2 arg2) { \
  2620. LSS_REG(0, arg1); LSS_REG(1, arg2); \
  2621. LSS_BODY(type, name, "r"(__r0), "r"(__r1)); \
  2622. }
  2623. #undef _syscall3
  2624. #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
  2625. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) { \
  2626. LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \
  2627. LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2)); \
  2628. }
  2629. #undef _syscall4
  2630. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  2631. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \
  2632. LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \
  2633. LSS_REG(3, arg4); \
  2634. LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3)); \
  2635. }
  2636. #undef _syscall5
  2637. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  2638. type5,arg5) \
  2639. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
  2640. type5 arg5) { \
  2641. LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \
  2642. LSS_REG(3, arg4); LSS_REG(4, arg5); \
  2643. LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3), \
  2644. "r"(__r4)); \
  2645. }
  2646. #undef _syscall6
  2647. #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  2648. type5,arg5,type6,arg6) \
  2649. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
  2650. type5 arg5, type6 arg6) { \
  2651. LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \
  2652. LSS_REG(3, arg4); LSS_REG(4, arg5); LSS_REG(5, arg6); \
  2653. LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3), \
  2654. "r"(__r4), "r"(__r5)); \
  2655. }
  2656. LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack,
  2657. int flags, void *arg, int *parent_tidptr,
  2658. void *newtls, int *child_tidptr) {
  2659. int64_t __res;
  2660. {
  2661. register uint64_t __flags __asm__("x0") = flags;
  2662. register void *__stack __asm__("x1") = child_stack;
  2663. register void *__ptid __asm__("x2") = parent_tidptr;
  2664. register void *__tls __asm__("x3") = newtls;
  2665. register int *__ctid __asm__("x4") = child_tidptr;
  2666. __asm__ __volatile__(/* Push "arg" and "fn" onto the stack that will be
  2667. * used by the child.
  2668. */
  2669. "stp %1, %4, [%2, #-16]!\n"
  2670. /* %x0 = syscall(%x0 = flags,
  2671. * %x1 = child_stack,
  2672. * %x2 = parent_tidptr,
  2673. * %x3 = newtls,
  2674. * %x4 = child_tidptr)
  2675. */
  2676. "mov x8, %8\n"
  2677. "svc 0x0\n"
  2678. /* if (%r0 != 0)
  2679. * return %r0;
  2680. */
  2681. "mov %0, x0\n"
  2682. "cbnz x0, 1f\n"
  2683. /* In the child, now. Call "fn(arg)".
  2684. */
  2685. "ldp x1, x0, [sp], #16\n"
  2686. "blr x1\n"
  2687. /* Call _exit(%r0).
  2688. */
  2689. "mov x8, %9\n"
  2690. "svc 0x0\n"
  2691. "1:\n"
  2692. : "=r" (__res)
  2693. : "r"(fn), "r"(__stack), "r"(__flags), "r"(arg),
  2694. "r"(__ptid), "r"(__tls), "r"(__ctid),
  2695. "i"(__NR_clone), "i"(__NR_exit)
  2696. : "cc", "x8", "memory");
  2697. }
  2698. LSS_RETURN(int, __res);
  2699. }
  2700. #elif defined(__mips__)
  2701. #undef LSS_REG
  2702. #define LSS_REG(r,a) register unsigned long __r##r __asm__("$"#r) = \
  2703. (unsigned long)(a)
  2704. #undef LSS_BODY
  2705. #undef LSS_SYSCALL_CLOBBERS
  2706. #if _MIPS_SIM == _MIPS_SIM_ABI32
  2707. #define LSS_SYSCALL_CLOBBERS "$1", "$3", "$8", "$9", "$10", \
  2708. "$11", "$12", "$13", "$14", "$15", \
  2709. "$24", "$25", "hi", "lo", "memory"
  2710. #else
  2711. #define LSS_SYSCALL_CLOBBERS "$1", "$3", "$10", "$11", "$12", \
  2712. "$13", "$14", "$15", "$24", "$25", \
  2713. "hi", "lo", "memory"
  2714. #endif
  2715. #define LSS_BODY(type,name,r7,...) \
  2716. register unsigned long __v0 __asm__("$2") = __NR_##name; \
  2717. __asm__ __volatile__ ("syscall\n" \
  2718. : "=r"(__v0), r7 (__r7) \
  2719. : "0"(__v0), ##__VA_ARGS__ \
  2720. : LSS_SYSCALL_CLOBBERS); \
  2721. LSS_RETURN(type, __v0, __r7)
  2722. #undef _syscall0
  2723. #define _syscall0(type, name) \
  2724. type LSS_NAME(name)(void) { \
  2725. register unsigned long __r7 __asm__("$7"); \
  2726. LSS_BODY(type, name, "=r"); \
  2727. }
  2728. #undef _syscall1
  2729. #define _syscall1(type, name, type1, arg1) \
  2730. type LSS_NAME(name)(type1 arg1) { \
  2731. register unsigned long __r7 __asm__("$7"); \
  2732. LSS_REG(4, arg1); LSS_BODY(type, name, "=r", "r"(__r4)); \
  2733. }
  2734. #undef _syscall2
  2735. #define _syscall2(type, name, type1, arg1, type2, arg2) \
  2736. type LSS_NAME(name)(type1 arg1, type2 arg2) { \
  2737. register unsigned long __r7 __asm__("$7"); \
  2738. LSS_REG(4, arg1); LSS_REG(5, arg2); \
  2739. LSS_BODY(type, name, "=r", "r"(__r4), "r"(__r5)); \
  2740. }
  2741. #undef _syscall3
  2742. #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
  2743. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) { \
  2744. register unsigned long __r7 __asm__("$7"); \
  2745. LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3); \
  2746. LSS_BODY(type, name, "=r", "r"(__r4), "r"(__r5), "r"(__r6)); \
  2747. }
  2748. #undef _syscall4
  2749. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  2750. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \
  2751. LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3); \
  2752. LSS_REG(7, arg4); \
  2753. LSS_BODY(type, name, "+r", "r"(__r4), "r"(__r5), "r"(__r6)); \
  2754. }
  2755. #undef _syscall5
  2756. #if _MIPS_SIM == _MIPS_SIM_ABI32
  2757. /* The old 32bit MIPS system call API passes the fifth and sixth argument
  2758. * on the stack, whereas the new APIs use registers "r8" and "r9".
  2759. */
  2760. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  2761. type5,arg5) \
  2762. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
  2763. type5 arg5) { \
  2764. LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3); \
  2765. LSS_REG(7, arg4); \
  2766. register unsigned long __v0 __asm__("$2") = __NR_##name; \
  2767. __asm__ __volatile__ (".set noreorder\n" \
  2768. "subu $29, 32\n" \
  2769. "sw %5, 16($29)\n" \
  2770. "syscall\n" \
  2771. "addiu $29, 32\n" \
  2772. ".set reorder\n" \
  2773. : "+r"(__v0), "+r" (__r7) \
  2774. : "r"(__r4), "r"(__r5), \
  2775. "r"(__r6), "r" ((unsigned long)arg5) \
  2776. : "$8", "$9", "$10", "$11", "$12", \
  2777. "$13", "$14", "$15", "$24", "$25", \
  2778. "memory"); \
  2779. LSS_RETURN(type, __v0, __r7); \
  2780. }
  2781. #else
  2782. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  2783. type5,arg5) \
  2784. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
  2785. type5 arg5) { \
  2786. LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3); \
  2787. LSS_REG(7, arg4); LSS_REG(8, arg5); \
  2788. LSS_BODY(type, name, "+r", "r"(__r4), "r"(__r5), "r"(__r6), \
  2789. "r"(__r8)); \
  2790. }
  2791. #endif
  2792. #undef _syscall6
  2793. #if _MIPS_SIM == _MIPS_SIM_ABI32
  2794. /* The old 32bit MIPS system call API passes the fifth and sixth argument
  2795. * on the stack, whereas the new APIs use registers "r8" and "r9".
  2796. */
  2797. #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  2798. type5,arg5,type6,arg6) \
  2799. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
  2800. type5 arg5, type6 arg6) { \
  2801. LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3); \
  2802. LSS_REG(7, arg4); \
  2803. register unsigned long __v0 __asm__("$2") = __NR_##name; \
  2804. __asm__ __volatile__ (".set noreorder\n" \
  2805. "subu $29, 32\n" \
  2806. "sw %5, 16($29)\n" \
  2807. "sw %6, 20($29)\n" \
  2808. "syscall\n" \
  2809. "addiu $29, 32\n" \
  2810. ".set reorder\n" \
  2811. : "+r"(__v0), "+r" (__r7) \
  2812. : "r"(__r4), "r"(__r5), \
  2813. "r"(__r6), "r" ((unsigned long)arg5), \
  2814. "r" ((unsigned long)arg6) \
  2815. : "$8", "$9", "$10", "$11", "$12", \
  2816. "$13", "$14", "$15", "$24", "$25", \
  2817. "memory"); \
  2818. LSS_RETURN(type, __v0, __r7); \
  2819. }
  2820. #else
  2821. #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  2822. type5,arg5,type6,arg6) \
  2823. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
  2824. type5 arg5,type6 arg6) { \
  2825. LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3); \
  2826. LSS_REG(7, arg4); LSS_REG(8, arg5); LSS_REG(9, arg6); \
  2827. LSS_BODY(type, name, "+r", "r"(__r4), "r"(__r5), "r"(__r6), \
  2828. "r"(__r8), "r"(__r9)); \
  2829. }
  2830. #endif
  2831. LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack,
  2832. int flags, void *arg, int *parent_tidptr,
  2833. void *newtls, int *child_tidptr) {
  2834. register unsigned long __v0 __asm__("$2") = -EINVAL;
  2835. register unsigned long __r7 __asm__("$7") = (unsigned long)newtls;
  2836. {
  2837. register int __flags __asm__("$4") = flags;
  2838. register void *__stack __asm__("$5") = child_stack;
  2839. register void *__ptid __asm__("$6") = parent_tidptr;
  2840. register int *__ctid __asm__("$8") = child_tidptr;
  2841. __asm__ __volatile__(
  2842. #if _MIPS_SIM == _MIPS_SIM_ABI32 && _MIPS_SZPTR == 32
  2843. "subu $29,24\n"
  2844. #elif _MIPS_SIM == _MIPS_SIM_NABI32
  2845. "sub $29,16\n"
  2846. #else
  2847. "dsubu $29,16\n"
  2848. #endif
  2849. /* if (fn == NULL || child_stack == NULL)
  2850. * return -EINVAL;
  2851. */
  2852. "beqz %4,1f\n"
  2853. "beqz %5,1f\n"
  2854. /* Push "arg" and "fn" onto the stack that will be
  2855. * used by the child.
  2856. */
  2857. #if _MIPS_SIM == _MIPS_SIM_ABI32 && _MIPS_SZPTR == 32
  2858. "subu %5,32\n"
  2859. "sw %4,0(%5)\n"
  2860. "sw %7,4(%5)\n"
  2861. #elif _MIPS_SIM == _MIPS_SIM_NABI32
  2862. "sub %5,32\n"
  2863. "sw %4,0(%5)\n"
  2864. "sw %7,8(%5)\n"
  2865. #else
  2866. "dsubu %5,32\n"
  2867. "sd %4,0(%5)\n"
  2868. "sd %7,8(%5)\n"
  2869. #endif
  2870. /* $7 = syscall($4 = flags,
  2871. * $5 = child_stack,
  2872. * $6 = parent_tidptr,
  2873. * $7 = newtls,
  2874. * $8 = child_tidptr)
  2875. */
  2876. "li $2,%2\n"
  2877. "syscall\n"
  2878. /* if ($7 != 0)
  2879. * return $2;
  2880. */
  2881. "bnez $7,1f\n"
  2882. "bnez $2,1f\n"
  2883. /* In the child, now. Call "fn(arg)".
  2884. */
  2885. #if _MIPS_SIM == _MIPS_SIM_ABI32 && _MIPS_SZPTR == 32
  2886. "lw $25,0($29)\n"
  2887. "lw $4,4($29)\n"
  2888. #elif _MIPS_SIM == _MIPS_SIM_NABI32
  2889. "lw $25,0($29)\n"
  2890. "lw $4,8($29)\n"
  2891. #else
  2892. "ld $25,0($29)\n"
  2893. "ld $4,8($29)\n"
  2894. #endif
  2895. "jalr $25\n"
  2896. /* Call _exit($2)
  2897. */
  2898. "move $4,$2\n"
  2899. "li $2,%3\n"
  2900. "syscall\n"
  2901. "1:\n"
  2902. #if _MIPS_SIM == _MIPS_SIM_ABI32 && _MIPS_SZPTR == 32
  2903. "addu $29, 24\n"
  2904. #elif _MIPS_SIM == _MIPS_SIM_NABI32
  2905. "add $29, 16\n"
  2906. #else
  2907. "daddu $29,16\n"
  2908. #endif
  2909. : "+r" (__v0), "+r" (__r7)
  2910. : "i"(__NR_clone), "i"(__NR_exit), "r"(fn),
  2911. "r"(__stack), "r"(__flags), "r"(arg),
  2912. "r"(__ptid), "r"(__ctid)
  2913. : "$9", "$10", "$11", "$12", "$13", "$14", "$15",
  2914. "$24", "$25", "memory");
  2915. }
  2916. LSS_RETURN(int, __v0, __r7);
  2917. }
  2918. #elif defined (__PPC__)
  2919. #undef LSS_LOADARGS_0
  2920. #define LSS_LOADARGS_0(name, dummy...) \
  2921. __sc_0 = __NR_##name
  2922. #undef LSS_LOADARGS_1
  2923. #define LSS_LOADARGS_1(name, arg1) \
  2924. LSS_LOADARGS_0(name); \
  2925. __sc_3 = (unsigned long) (arg1)
  2926. #undef LSS_LOADARGS_2
  2927. #define LSS_LOADARGS_2(name, arg1, arg2) \
  2928. LSS_LOADARGS_1(name, arg1); \
  2929. __sc_4 = (unsigned long) (arg2)
  2930. #undef LSS_LOADARGS_3
  2931. #define LSS_LOADARGS_3(name, arg1, arg2, arg3) \
  2932. LSS_LOADARGS_2(name, arg1, arg2); \
  2933. __sc_5 = (unsigned long) (arg3)
  2934. #undef LSS_LOADARGS_4
  2935. #define LSS_LOADARGS_4(name, arg1, arg2, arg3, arg4) \
  2936. LSS_LOADARGS_3(name, arg1, arg2, arg3); \
  2937. __sc_6 = (unsigned long) (arg4)
  2938. #undef LSS_LOADARGS_5
  2939. #define LSS_LOADARGS_5(name, arg1, arg2, arg3, arg4, arg5) \
  2940. LSS_LOADARGS_4(name, arg1, arg2, arg3, arg4); \
  2941. __sc_7 = (unsigned long) (arg5)
  2942. #undef LSS_LOADARGS_6
  2943. #define LSS_LOADARGS_6(name, arg1, arg2, arg3, arg4, arg5, arg6) \
  2944. LSS_LOADARGS_5(name, arg1, arg2, arg3, arg4, arg5); \
  2945. __sc_8 = (unsigned long) (arg6)
  2946. #undef LSS_ASMINPUT_0
  2947. #define LSS_ASMINPUT_0 "0" (__sc_0)
  2948. #undef LSS_ASMINPUT_1
  2949. #define LSS_ASMINPUT_1 LSS_ASMINPUT_0, "1" (__sc_3)
  2950. #undef LSS_ASMINPUT_2
  2951. #define LSS_ASMINPUT_2 LSS_ASMINPUT_1, "2" (__sc_4)
  2952. #undef LSS_ASMINPUT_3
  2953. #define LSS_ASMINPUT_3 LSS_ASMINPUT_2, "3" (__sc_5)
  2954. #undef LSS_ASMINPUT_4
  2955. #define LSS_ASMINPUT_4 LSS_ASMINPUT_3, "4" (__sc_6)
  2956. #undef LSS_ASMINPUT_5
  2957. #define LSS_ASMINPUT_5 LSS_ASMINPUT_4, "5" (__sc_7)
  2958. #undef LSS_ASMINPUT_6
  2959. #define LSS_ASMINPUT_6 LSS_ASMINPUT_5, "6" (__sc_8)
  2960. #undef LSS_BODY
  2961. #define LSS_BODY(nr, type, name, args...) \
  2962. long __sc_ret, __sc_err; \
  2963. { \
  2964. register unsigned long __sc_0 __asm__ ("r0"); \
  2965. register unsigned long __sc_3 __asm__ ("r3"); \
  2966. register unsigned long __sc_4 __asm__ ("r4"); \
  2967. register unsigned long __sc_5 __asm__ ("r5"); \
  2968. register unsigned long __sc_6 __asm__ ("r6"); \
  2969. register unsigned long __sc_7 __asm__ ("r7"); \
  2970. register unsigned long __sc_8 __asm__ ("r8"); \
  2971. \
  2972. LSS_LOADARGS_##nr(name, args); \
  2973. __asm__ __volatile__ \
  2974. ("sc\n\t" \
  2975. "mfcr %0" \
  2976. : "=&r" (__sc_0), \
  2977. "=&r" (__sc_3), "=&r" (__sc_4), \
  2978. "=&r" (__sc_5), "=&r" (__sc_6), \
  2979. "=&r" (__sc_7), "=&r" (__sc_8) \
  2980. : LSS_ASMINPUT_##nr \
  2981. : "cr0", "ctr", "memory", \
  2982. "r9", "r10", "r11", "r12"); \
  2983. __sc_ret = __sc_3; \
  2984. __sc_err = __sc_0; \
  2985. } \
  2986. LSS_RETURN(type, __sc_ret, __sc_err)
  2987. #undef _syscall0
  2988. #define _syscall0(type, name) \
  2989. type LSS_NAME(name)(void) { \
  2990. LSS_BODY(0, type, name); \
  2991. }
  2992. #undef _syscall1
  2993. #define _syscall1(type, name, type1, arg1) \
  2994. type LSS_NAME(name)(type1 arg1) { \
  2995. LSS_BODY(1, type, name, arg1); \
  2996. }
  2997. #undef _syscall2
  2998. #define _syscall2(type, name, type1, arg1, type2, arg2) \
  2999. type LSS_NAME(name)(type1 arg1, type2 arg2) { \
  3000. LSS_BODY(2, type, name, arg1, arg2); \
  3001. }
  3002. #undef _syscall3
  3003. #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
  3004. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) { \
  3005. LSS_BODY(3, type, name, arg1, arg2, arg3); \
  3006. }
  3007. #undef _syscall4
  3008. #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3, \
  3009. type4, arg4) \
  3010. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \
  3011. LSS_BODY(4, type, name, arg1, arg2, arg3, arg4); \
  3012. }
  3013. #undef _syscall5
  3014. #define _syscall5(type, name, type1, arg1, type2, arg2, type3, arg3, \
  3015. type4, arg4, type5, arg5) \
  3016. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
  3017. type5 arg5) { \
  3018. LSS_BODY(5, type, name, arg1, arg2, arg3, arg4, arg5); \
  3019. }
  3020. #undef _syscall6
  3021. #define _syscall6(type, name, type1, arg1, type2, arg2, type3, arg3, \
  3022. type4, arg4, type5, arg5, type6, arg6) \
  3023. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
  3024. type5 arg5, type6 arg6) { \
  3025. LSS_BODY(6, type, name, arg1, arg2, arg3, arg4, arg5, arg6); \
  3026. }
  3027. /* clone function adapted from glibc 2.3.6 clone.S */
  3028. /* TODO(csilvers): consider wrapping some args up in a struct, like we
  3029. * do for i386's _syscall6, so we can compile successfully on gcc 2.95
  3030. */
  3031. LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack,
  3032. int flags, void *arg, int *parent_tidptr,
  3033. void *newtls, int *child_tidptr) {
  3034. long __ret, __err;
  3035. {
  3036. register int (*__fn)(void *) __asm__ ("r8") = fn;
  3037. register void *__cstack __asm__ ("r4") = child_stack;
  3038. register int __flags __asm__ ("r3") = flags;
  3039. register void * __arg __asm__ ("r9") = arg;
  3040. register int * __ptidptr __asm__ ("r5") = parent_tidptr;
  3041. register void * __newtls __asm__ ("r6") = newtls;
  3042. register int * __ctidptr __asm__ ("r7") = child_tidptr;
  3043. __asm__ __volatile__(
  3044. /* check for fn == NULL
  3045. * and child_stack == NULL
  3046. */
  3047. "cmpwi cr0, %6, 0\n\t"
  3048. "cmpwi cr1, %7, 0\n\t"
  3049. "cror cr0*4+eq, cr1*4+eq, cr0*4+eq\n\t"
  3050. "beq- cr0, 1f\n\t"
  3051. /* set up stack frame for child */
  3052. "clrrwi %7, %7, 4\n\t"
  3053. "li 0, 0\n\t"
  3054. "stwu 0, -16(%7)\n\t"
  3055. /* fn, arg, child_stack are saved across the syscall: r28-30 */
  3056. "mr 28, %6\n\t"
  3057. "mr 29, %7\n\t"
  3058. "mr 27, %9\n\t"
  3059. /* syscall */
  3060. "li 0, %4\n\t"
  3061. /* flags already in r3
  3062. * child_stack already in r4
  3063. * ptidptr already in r5
  3064. * newtls already in r6
  3065. * ctidptr already in r7
  3066. */
  3067. "sc\n\t"
  3068. /* Test if syscall was successful */
  3069. "cmpwi cr1, 3, 0\n\t"
  3070. "crandc cr1*4+eq, cr1*4+eq, cr0*4+so\n\t"
  3071. "bne- cr1, 1f\n\t"
  3072. /* Do the function call */
  3073. "mtctr 28\n\t"
  3074. "mr 3, 27\n\t"
  3075. "bctrl\n\t"
  3076. /* Call _exit(r3) */
  3077. "li 0, %5\n\t"
  3078. "sc\n\t"
  3079. /* Return to parent */
  3080. "1:\n"
  3081. "mfcr %1\n\t"
  3082. "mr %0, 3\n\t"
  3083. : "=r" (__ret), "=r" (__err)
  3084. : "0" (-1), "1" (EINVAL),
  3085. "i" (__NR_clone), "i" (__NR_exit),
  3086. "r" (__fn), "r" (__cstack), "r" (__flags),
  3087. "r" (__arg), "r" (__ptidptr), "r" (__newtls),
  3088. "r" (__ctidptr)
  3089. : "cr0", "cr1", "memory", "ctr",
  3090. "r0", "r29", "r27", "r28");
  3091. }
  3092. LSS_RETURN(int, __ret, __err);
  3093. }
  3094. #elif defined(__s390__)
  3095. #undef LSS_REG
  3096. #define LSS_REG(r, a) register unsigned long __r##r __asm__("r"#r) = (unsigned long) a
  3097. #undef LSS_BODY
  3098. #define LSS_BODY(type, name, args...) \
  3099. register unsigned long __nr __asm__("r1") \
  3100. = (unsigned long)(__NR_##name); \
  3101. register long __res_r2 __asm__("r2"); \
  3102. long __res; \
  3103. __asm__ __volatile__ \
  3104. ("svc 0\n\t" \
  3105. : "=d"(__res_r2) \
  3106. : "d"(__nr), ## args \
  3107. : "memory"); \
  3108. __res = __res_r2; \
  3109. LSS_RETURN(type, __res)
  3110. #undef _syscall0
  3111. #define _syscall0(type, name) \
  3112. type LSS_NAME(name)(void) { \
  3113. LSS_BODY(type, name); \
  3114. }
  3115. #undef _syscall1
  3116. #define _syscall1(type, name, type1, arg1) \
  3117. type LSS_NAME(name)(type1 arg1) { \
  3118. LSS_REG(2, arg1); \
  3119. LSS_BODY(type, name, "0"(__r2)); \
  3120. }
  3121. #undef _syscall2
  3122. #define _syscall2(type, name, type1, arg1, type2, arg2) \
  3123. type LSS_NAME(name)(type1 arg1, type2 arg2) { \
  3124. LSS_REG(2, arg1); LSS_REG(3, arg2); \
  3125. LSS_BODY(type, name, "0"(__r2), "d"(__r3)); \
  3126. }
  3127. #undef _syscall3
  3128. #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
  3129. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) { \
  3130. LSS_REG(2, arg1); LSS_REG(3, arg2); LSS_REG(4, arg3); \
  3131. LSS_BODY(type, name, "0"(__r2), "d"(__r3), "d"(__r4)); \
  3132. }
  3133. #undef _syscall4
  3134. #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3, \
  3135. type4, arg4) \
  3136. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, \
  3137. type4 arg4) { \
  3138. LSS_REG(2, arg1); LSS_REG(3, arg2); LSS_REG(4, arg3); \
  3139. LSS_REG(5, arg4); \
  3140. LSS_BODY(type, name, "0"(__r2), "d"(__r3), "d"(__r4), \
  3141. "d"(__r5)); \
  3142. }
  3143. #undef _syscall5
  3144. #define _syscall5(type, name, type1, arg1, type2, arg2, type3, arg3, \
  3145. type4, arg4, type5, arg5) \
  3146. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, \
  3147. type4 arg4, type5 arg5) { \
  3148. LSS_REG(2, arg1); LSS_REG(3, arg2); LSS_REG(4, arg3); \
  3149. LSS_REG(5, arg4); LSS_REG(6, arg5); \
  3150. LSS_BODY(type, name, "0"(__r2), "d"(__r3), "d"(__r4), \
  3151. "d"(__r5), "d"(__r6)); \
  3152. }
  3153. #undef _syscall6
  3154. #define _syscall6(type, name, type1, arg1, type2, arg2, type3, arg3, \
  3155. type4, arg4, type5, arg5, type6, arg6) \
  3156. type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, \
  3157. type4 arg4, type5 arg5, type6 arg6) { \
  3158. LSS_REG(2, arg1); LSS_REG(3, arg2); LSS_REG(4, arg3); \
  3159. LSS_REG(5, arg4); LSS_REG(6, arg5); LSS_REG(7, arg6); \
  3160. LSS_BODY(type, name, "0"(__r2), "d"(__r3), "d"(__r4), \
  3161. "d"(__r5), "d"(__r6), "d"(__r7)); \
  3162. }
  3163. LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack,
  3164. int flags, void *arg, int *parent_tidptr,
  3165. void *newtls, int *child_tidptr) {
  3166. long __ret;
  3167. {
  3168. register int (*__fn)(void *) __asm__ ("r1") = fn;
  3169. register void *__cstack __asm__ ("r2") = child_stack;
  3170. register int __flags __asm__ ("r3") = flags;
  3171. register void *__arg __asm__ ("r0") = arg;
  3172. register int *__ptidptr __asm__ ("r4") = parent_tidptr;
  3173. register void *__newtls __asm__ ("r6") = newtls;
  3174. register int *__ctidptr __asm__ ("r5") = child_tidptr;
  3175. __asm__ __volatile__ (
  3176. #ifndef __s390x__
  3177. /* arg already in r0 */
  3178. "ltr %4, %4\n\t" /* check fn, which is already in r1 */
  3179. "jz 1f\n\t" /* NULL function pointer, return -EINVAL */
  3180. "ltr %5, %5\n\t" /* check child_stack, which is already in r2 */
  3181. "jz 1f\n\t" /* NULL stack pointer, return -EINVAL */
  3182. /* flags already in r3 */
  3183. /* parent_tidptr already in r4 */
  3184. /* child_tidptr already in r5 */
  3185. /* newtls already in r6 */
  3186. "svc %2\n\t" /* invoke clone syscall */
  3187. "ltr %0,%%r2\n\t" /* load return code into __ret and test */
  3188. "jnz 1f\n\t" /* return to parent if non-zero */
  3189. /* start child thread */
  3190. "lr %%r2, %7\n\t" /* set first parameter to void *arg */
  3191. "ahi %%r15, -96\n\t" /* make room on the stack for the save area */
  3192. "xc 0(4,%%r15), 0(%%r15)\n\t"
  3193. "basr %%r14, %4\n\t" /* jump to fn */
  3194. "svc %3\n" /* invoke exit syscall */
  3195. "1:\n"
  3196. #else
  3197. /* arg already in r0 */
  3198. "ltgr %4, %4\n\t" /* check fn, which is already in r1 */
  3199. "jz 1f\n\t" /* NULL function pointer, return -EINVAL */
  3200. "ltgr %5, %5\n\t" /* check child_stack, which is already in r2 */
  3201. "jz 1f\n\t" /* NULL stack pointer, return -EINVAL */
  3202. /* flags already in r3 */
  3203. /* parent_tidptr already in r4 */
  3204. /* child_tidptr already in r5 */
  3205. /* newtls already in r6 */
  3206. "svc %2\n\t" /* invoke clone syscall */
  3207. "ltgr %0, %%r2\n\t" /* load return code into __ret and test */
  3208. "jnz 1f\n\t" /* return to parent if non-zero */
  3209. /* start child thread */
  3210. "lgr %%r2, %7\n\t" /* set first parameter to void *arg */
  3211. "aghi %%r15, -160\n\t" /* make room on the stack for the save area */
  3212. "xc 0(8,%%r15), 0(%%r15)\n\t"
  3213. "basr %%r14, %4\n\t" /* jump to fn */
  3214. "svc %3\n" /* invoke exit syscall */
  3215. "1:\n"
  3216. #endif
  3217. : "=r" (__ret)
  3218. : "0" (-EINVAL), "i" (__NR_clone), "i" (__NR_exit),
  3219. "d" (__fn), "d" (__cstack), "d" (__flags), "d" (__arg),
  3220. "d" (__ptidptr), "d" (__newtls), "d" (__ctidptr)
  3221. : "cc", "r14", "memory"
  3222. );
  3223. }
  3224. LSS_RETURN(int, __ret);
  3225. }
  3226. #endif
  3227. #define __NR__exit __NR_exit
  3228. #define __NR__gettid __NR_gettid
  3229. #define __NR__mremap __NR_mremap
  3230. LSS_INLINE _syscall1(void *, brk, void *, e)
  3231. LSS_INLINE _syscall1(int, chdir, const char *,p)
  3232. LSS_INLINE _syscall1(int, close, int, f)
  3233. LSS_INLINE _syscall2(int, clock_getres, int, c,
  3234. struct kernel_timespec*, t)
  3235. LSS_INLINE _syscall2(int, clock_gettime, int, c,
  3236. struct kernel_timespec*, t)
  3237. LSS_INLINE _syscall1(int, dup, int, f)
  3238. #if !defined(__aarch64__)
  3239. // The dup2 syscall has been deprecated on aarch64. We polyfill it below.
  3240. LSS_INLINE _syscall2(int, dup2, int, s,
  3241. int, d)
  3242. #endif
  3243. LSS_INLINE _syscall3(int, execve, const char*, f,
  3244. const char*const*,a,const char*const*, e)
  3245. LSS_INLINE _syscall1(int, _exit, int, e)
  3246. LSS_INLINE _syscall1(int, exit_group, int, e)
  3247. LSS_INLINE _syscall3(int, fcntl, int, f,
  3248. int, c, long, a)
  3249. #if !defined(__aarch64__)
  3250. // The fork syscall has been deprecated on aarch64. We polyfill it below.
  3251. LSS_INLINE _syscall0(pid_t, fork)
  3252. #endif
  3253. LSS_INLINE _syscall2(int, fstat, int, f,
  3254. struct kernel_stat*, b)
  3255. LSS_INLINE _syscall2(int, fstatfs, int, f,
  3256. struct kernel_statfs*, b)
  3257. #if defined(__x86_64__)
  3258. /* Need to make sure off_t isn't truncated to 32-bits under x32. */
  3259. LSS_INLINE int LSS_NAME(ftruncate)(int f, off_t l) {
  3260. LSS_BODY(2, int, ftruncate, LSS_SYSCALL_ARG(f), (uint64_t)(l));
  3261. }
  3262. #else
  3263. LSS_INLINE _syscall2(int, ftruncate, int, f,
  3264. off_t, l)
  3265. #endif
  3266. LSS_INLINE _syscall4(int, futex, int*, a,
  3267. int, o, int, v,
  3268. struct kernel_timespec*, t)
  3269. LSS_INLINE _syscall3(int, getdents, int, f,
  3270. struct kernel_dirent*, d, int, c)
  3271. LSS_INLINE _syscall3(int, getdents64, int, f,
  3272. struct kernel_dirent64*, d, int, c)
  3273. LSS_INLINE _syscall0(gid_t, getegid)
  3274. LSS_INLINE _syscall0(uid_t, geteuid)
  3275. #if !defined(__aarch64__)
  3276. // The getgprp syscall has been deprecated on aarch64.
  3277. LSS_INLINE _syscall0(pid_t, getpgrp)
  3278. #endif
  3279. LSS_INLINE _syscall0(pid_t, getpid)
  3280. LSS_INLINE _syscall0(pid_t, getppid)
  3281. LSS_INLINE _syscall2(int, getpriority, int, a,
  3282. int, b)
  3283. LSS_INLINE _syscall3(int, getresgid, gid_t *, r,
  3284. gid_t *, e, gid_t *, s)
  3285. LSS_INLINE _syscall3(int, getresuid, uid_t *, r,
  3286. uid_t *, e, uid_t *, s)
  3287. #if !defined(__ARM_EABI__)
  3288. LSS_INLINE _syscall2(int, getrlimit, int, r,
  3289. struct kernel_rlimit*, l)
  3290. #endif
  3291. LSS_INLINE _syscall1(pid_t, getsid, pid_t, p)
  3292. LSS_INLINE _syscall0(pid_t, _gettid)
  3293. LSS_INLINE _syscall2(pid_t, gettimeofday, struct kernel_timeval*, t,
  3294. void*, tz)
  3295. LSS_INLINE _syscall5(int, setxattr, const char *,p,
  3296. const char *, n, const void *,v,
  3297. size_t, s, int, f)
  3298. LSS_INLINE _syscall5(int, lsetxattr, const char *,p,
  3299. const char *, n, const void *,v,
  3300. size_t, s, int, f)
  3301. LSS_INLINE _syscall4(ssize_t, getxattr, const char *,p,
  3302. const char *, n, void *, v, size_t, s)
  3303. LSS_INLINE _syscall4(ssize_t, lgetxattr, const char *,p,
  3304. const char *, n, void *, v, size_t, s)
  3305. LSS_INLINE _syscall3(ssize_t, listxattr, const char *,p,
  3306. char *, l, size_t, s)
  3307. LSS_INLINE _syscall3(ssize_t, llistxattr, const char *,p,
  3308. char *, l, size_t, s)
  3309. LSS_INLINE _syscall3(int, ioctl, int, d,
  3310. int, r, void *, a)
  3311. LSS_INLINE _syscall2(int, ioprio_get, int, which,
  3312. int, who)
  3313. LSS_INLINE _syscall3(int, ioprio_set, int, which,
  3314. int, who, int, ioprio)
  3315. LSS_INLINE _syscall2(int, kill, pid_t, p,
  3316. int, s)
  3317. #if defined(__x86_64__)
  3318. /* Need to make sure off_t isn't truncated to 32-bits under x32. */
  3319. LSS_INLINE off_t LSS_NAME(lseek)(int f, off_t o, int w) {
  3320. _LSS_BODY(3, off_t, lseek, off_t, LSS_SYSCALL_ARG(f), (uint64_t)(o),
  3321. LSS_SYSCALL_ARG(w));
  3322. }
  3323. #else
  3324. LSS_INLINE _syscall3(off_t, lseek, int, f,
  3325. off_t, o, int, w)
  3326. #endif
  3327. LSS_INLINE _syscall2(int, munmap, void*, s,
  3328. size_t, l)
  3329. LSS_INLINE _syscall6(long, move_pages, pid_t, p,
  3330. unsigned long, n, void **,g, int *, d,
  3331. int *, s, int, f)
  3332. LSS_INLINE _syscall3(int, mprotect, const void *,a,
  3333. size_t, l, int, p)
  3334. LSS_INLINE _syscall5(void*, _mremap, void*, o,
  3335. size_t, os, size_t, ns,
  3336. unsigned long, f, void *, a)
  3337. #if !defined(__aarch64__)
  3338. // The open and poll syscalls have been deprecated on aarch64. We polyfill
  3339. // them below.
  3340. LSS_INLINE _syscall3(int, open, const char*, p,
  3341. int, f, int, m)
  3342. LSS_INLINE _syscall3(int, poll, struct kernel_pollfd*, u,
  3343. unsigned int, n, int, t)
  3344. #endif
  3345. LSS_INLINE _syscall5(int, prctl, int, option,
  3346. unsigned long, arg2,
  3347. unsigned long, arg3,
  3348. unsigned long, arg4,
  3349. unsigned long, arg5)
  3350. LSS_INLINE _syscall4(long, ptrace, int, r,
  3351. pid_t, p, void *, a, void *, d)
  3352. #if defined(__NR_quotactl)
  3353. // Defined on x86_64 / i386 only
  3354. LSS_INLINE _syscall4(int, quotactl, int, cmd, const char *, special,
  3355. int, id, caddr_t, addr)
  3356. #endif
  3357. LSS_INLINE _syscall3(ssize_t, read, int, f,
  3358. void *, b, size_t, c)
  3359. #if !defined(__aarch64__)
  3360. // The readlink syscall has been deprecated on aarch64. We polyfill below.
  3361. LSS_INLINE _syscall3(int, readlink, const char*, p,
  3362. char*, b, size_t, s)
  3363. #endif
  3364. LSS_INLINE _syscall4(int, rt_sigaction, int, s,
  3365. const struct kernel_sigaction*, a,
  3366. struct kernel_sigaction*, o, size_t, c)
  3367. LSS_INLINE _syscall2(int, rt_sigpending, struct kernel_sigset_t *, s,
  3368. size_t, c)
  3369. LSS_INLINE _syscall4(int, rt_sigprocmask, int, h,
  3370. const struct kernel_sigset_t*, s,
  3371. struct kernel_sigset_t*, o, size_t, c)
  3372. LSS_INLINE _syscall2(int, rt_sigsuspend,
  3373. const struct kernel_sigset_t*, s, size_t, c)
  3374. LSS_INLINE _syscall3(int, sched_getaffinity,pid_t, p,
  3375. unsigned int, l, unsigned long *, m)
  3376. LSS_INLINE _syscall3(int, sched_setaffinity,pid_t, p,
  3377. unsigned int, l, unsigned long *, m)
  3378. LSS_INLINE _syscall0(int, sched_yield)
  3379. LSS_INLINE _syscall1(long, set_tid_address, int *, t)
  3380. LSS_INLINE _syscall1(int, setfsgid, gid_t, g)
  3381. LSS_INLINE _syscall1(int, setfsuid, uid_t, u)
  3382. LSS_INLINE _syscall1(int, setuid, uid_t, u)
  3383. LSS_INLINE _syscall1(int, setgid, gid_t, g)
  3384. LSS_INLINE _syscall2(int, setpgid, pid_t, p,
  3385. pid_t, g)
  3386. LSS_INLINE _syscall3(int, setpriority, int, a,
  3387. int, b, int, p)
  3388. LSS_INLINE _syscall3(int, setresgid, gid_t, r,
  3389. gid_t, e, gid_t, s)
  3390. LSS_INLINE _syscall3(int, setresuid, uid_t, r,
  3391. uid_t, e, uid_t, s)
  3392. LSS_INLINE _syscall2(int, setrlimit, int, r,
  3393. const struct kernel_rlimit*, l)
  3394. LSS_INLINE _syscall0(pid_t, setsid)
  3395. LSS_INLINE _syscall2(int, sigaltstack, const stack_t*, s,
  3396. const stack_t*, o)
  3397. #if defined(__NR_sigreturn)
  3398. LSS_INLINE _syscall1(int, sigreturn, unsigned long, u)
  3399. #endif
  3400. #if !defined(__aarch64__)
  3401. // The stat syscall has been deprecated on aarch64. We polyfill it below.
  3402. LSS_INLINE _syscall2(int, stat, const char*, f,
  3403. struct kernel_stat*, b)
  3404. #endif
  3405. LSS_INLINE _syscall2(int, statfs, const char*, f,
  3406. struct kernel_statfs*, b)
  3407. LSS_INLINE _syscall3(int, tgkill, pid_t, p,
  3408. pid_t, t, int, s)
  3409. LSS_INLINE _syscall2(int, tkill, pid_t, p,
  3410. int, s)
  3411. #if !defined(__aarch64__)
  3412. // The unlink syscall has been deprecated on aarch64. We polyfill it below.
  3413. LSS_INLINE _syscall1(int, unlink, const char*, f)
  3414. #endif
  3415. LSS_INLINE _syscall3(ssize_t, write, int, f,
  3416. const void *, b, size_t, c)
  3417. LSS_INLINE _syscall3(ssize_t, writev, int, f,
  3418. const struct kernel_iovec*, v, size_t, c)
  3419. #if defined(__NR_getcpu)
  3420. LSS_INLINE _syscall3(long, getcpu, unsigned *, cpu,
  3421. unsigned *, node, void *, unused)
  3422. #endif
  3423. #if defined(__x86_64__) || \
  3424. (defined(__mips__) && _MIPS_SIM != _MIPS_SIM_ABI32)
  3425. LSS_INLINE _syscall3(int, recvmsg, int, s,
  3426. struct kernel_msghdr*, m, int, f)
  3427. LSS_INLINE _syscall3(int, sendmsg, int, s,
  3428. const struct kernel_msghdr*, m, int, f)
  3429. LSS_INLINE _syscall6(int, sendto, int, s,
  3430. const void*, m, size_t, l,
  3431. int, f,
  3432. const struct kernel_sockaddr*, a, int, t)
  3433. LSS_INLINE _syscall2(int, shutdown, int, s,
  3434. int, h)
  3435. LSS_INLINE _syscall3(int, socket, int, d,
  3436. int, t, int, p)
  3437. LSS_INLINE _syscall4(int, socketpair, int, d,
  3438. int, t, int, p, int*, s)
  3439. #endif
  3440. #if defined(__NR_fadvise64)
  3441. #if defined(__x86_64__)
  3442. /* Need to make sure loff_t isn't truncated to 32-bits under x32. */
  3443. LSS_INLINE int LSS_NAME(fadvise64)(int fd, loff_t offset, loff_t len,
  3444. int advice) {
  3445. LSS_BODY(4, int, fadvise64, LSS_SYSCALL_ARG(fd), (uint64_t)(offset),
  3446. (uint64_t)(len), LSS_SYSCALL_ARG(advice));
  3447. }
  3448. #else
  3449. LSS_INLINE _syscall4(int, fadvise64,
  3450. int, fd, loff_t, offset, loff_t, len, int, advice)
  3451. #endif
  3452. #elif defined(__i386__)
  3453. #define __NR__fadvise64_64 __NR_fadvise64_64
  3454. LSS_INLINE _syscall6(int, _fadvise64_64, int, fd,
  3455. unsigned, offset_lo, unsigned, offset_hi,
  3456. unsigned, len_lo, unsigned, len_hi,
  3457. int, advice)
  3458. LSS_INLINE int LSS_NAME(fadvise64)(int fd, loff_t offset,
  3459. loff_t len, int advice) {
  3460. return LSS_NAME(_fadvise64_64)(fd,
  3461. (unsigned)offset, (unsigned)(offset >>32),
  3462. (unsigned)len, (unsigned)(len >> 32),
  3463. advice);
  3464. }
  3465. #elif defined(__s390__) && !defined(__s390x__)
  3466. #define __NR__fadvise64_64 __NR_fadvise64_64
  3467. struct kernel_fadvise64_64_args {
  3468. int fd;
  3469. long long offset;
  3470. long long len;
  3471. int advice;
  3472. };
  3473. LSS_INLINE _syscall1(int, _fadvise64_64,
  3474. struct kernel_fadvise64_64_args *args)
  3475. LSS_INLINE int LSS_NAME(fadvise64)(int fd, loff_t offset,
  3476. loff_t len, int advice) {
  3477. struct kernel_fadvise64_64_args args = { fd, offset, len, advice };
  3478. return LSS_NAME(_fadvise64_64)(&args);
  3479. }
  3480. #endif
  3481. #if defined(__NR_fallocate)
  3482. #if defined(__x86_64__)
  3483. /* Need to make sure loff_t isn't truncated to 32-bits under x32. */
  3484. LSS_INLINE int LSS_NAME(fallocate)(int f, int mode, loff_t offset,
  3485. loff_t len) {
  3486. LSS_BODY(4, int, fallocate, LSS_SYSCALL_ARG(f), LSS_SYSCALL_ARG(mode),
  3487. (uint64_t)(offset), (uint64_t)(len));
  3488. }
  3489. #elif defined(__i386__) || (defined(__s390__) && !defined(__s390x__))
  3490. #define __NR__fallocate __NR_fallocate
  3491. LSS_INLINE _syscall6(int, _fallocate, int, fd,
  3492. int, mode,
  3493. unsigned, offset_lo, unsigned, offset_hi,
  3494. unsigned, len_lo, unsigned, len_hi)
  3495. LSS_INLINE int LSS_NAME(fallocate)(int fd, int mode,
  3496. loff_t offset, loff_t len) {
  3497. union { loff_t off; unsigned w[2]; } o = { offset }, l = { len };
  3498. return LSS_NAME(_fallocate)(fd, mode, o.w[0], o.w[1], l.w[0], l.w[1]);
  3499. }
  3500. #else
  3501. LSS_INLINE _syscall4(int, fallocate,
  3502. int, f, int, mode, loff_t, offset, loff_t, len)
  3503. #endif
  3504. #endif
  3505. #if defined(__x86_64__) || defined(__s390x__)
  3506. LSS_INLINE int LSS_NAME(getresgid32)(gid_t *rgid,
  3507. gid_t *egid,
  3508. gid_t *sgid) {
  3509. return LSS_NAME(getresgid)(rgid, egid, sgid);
  3510. }
  3511. LSS_INLINE int LSS_NAME(getresuid32)(uid_t *ruid,
  3512. uid_t *euid,
  3513. uid_t *suid) {
  3514. return LSS_NAME(getresuid)(ruid, euid, suid);
  3515. }
  3516. LSS_INLINE _syscall4(int, newfstatat, int, d,
  3517. const char *, p,
  3518. struct kernel_stat*, b, int, f)
  3519. LSS_INLINE int LSS_NAME(setfsgid32)(gid_t gid) {
  3520. return LSS_NAME(setfsgid)(gid);
  3521. }
  3522. LSS_INLINE int LSS_NAME(setfsuid32)(uid_t uid) {
  3523. return LSS_NAME(setfsuid)(uid);
  3524. }
  3525. LSS_INLINE int LSS_NAME(setresgid32)(gid_t rgid, gid_t egid, gid_t sgid) {
  3526. return LSS_NAME(setresgid)(rgid, egid, sgid);
  3527. }
  3528. LSS_INLINE int LSS_NAME(setresuid32)(uid_t ruid, uid_t euid, uid_t suid) {
  3529. return LSS_NAME(setresuid)(ruid, euid, suid);
  3530. }
  3531. LSS_INLINE int LSS_NAME(sigaction)(int signum,
  3532. const struct kernel_sigaction *act,
  3533. struct kernel_sigaction *oldact) {
  3534. #if defined(__x86_64__)
  3535. /* On x86_64, the kernel requires us to always set our own
  3536. * SA_RESTORER in order to be able to return from a signal handler.
  3537. * This function must have a "magic" signature that the "gdb"
  3538. * (and maybe the kernel?) can recognize.
  3539. */
  3540. if (act != NULL && !(act->sa_flags & SA_RESTORER)) {
  3541. struct kernel_sigaction a = *act;
  3542. a.sa_flags |= SA_RESTORER;
  3543. a.sa_restorer = LSS_NAME(restore_rt)();
  3544. return LSS_NAME(rt_sigaction)(signum, &a, oldact,
  3545. (KERNEL_NSIG+7)/8);
  3546. } else
  3547. #endif
  3548. return LSS_NAME(rt_sigaction)(signum, act, oldact,
  3549. (KERNEL_NSIG+7)/8);
  3550. }
  3551. LSS_INLINE int LSS_NAME(sigpending)(struct kernel_sigset_t *set) {
  3552. return LSS_NAME(rt_sigpending)(set, (KERNEL_NSIG+7)/8);
  3553. }
  3554. LSS_INLINE int LSS_NAME(sigprocmask)(int how,
  3555. const struct kernel_sigset_t *set,
  3556. struct kernel_sigset_t *oldset) {
  3557. return LSS_NAME(rt_sigprocmask)(how, set, oldset, (KERNEL_NSIG+7)/8);
  3558. }
  3559. LSS_INLINE int LSS_NAME(sigsuspend)(const struct kernel_sigset_t *set) {
  3560. return LSS_NAME(rt_sigsuspend)(set, (KERNEL_NSIG+7)/8);
  3561. }
  3562. #endif
  3563. #if defined(__x86_64__) || defined(__ARM_ARCH_3__) || \
  3564. defined(__ARM_EABI__) || defined(__aarch64__) || \
  3565. (defined(__mips__) && _MIPS_SIM != _MIPS_SIM_ABI32) || \
  3566. defined(__s390__)
  3567. LSS_INLINE _syscall4(pid_t, wait4, pid_t, p,
  3568. int*, s, int, o,
  3569. struct kernel_rusage*, r)
  3570. LSS_INLINE pid_t LSS_NAME(waitpid)(pid_t pid, int *status, int options){
  3571. return LSS_NAME(wait4)(pid, status, options, 0);
  3572. }
  3573. #endif
  3574. #if defined(__NR_openat)
  3575. LSS_INLINE _syscall4(int, openat, int, d, const char *, p, int, f, int, m)
  3576. #endif
  3577. #if defined(__NR_unlinkat)
  3578. LSS_INLINE _syscall3(int, unlinkat, int, d, const char *, p, int, f)
  3579. #endif
  3580. #if defined(__i386__) || defined(__ARM_ARCH_3__) || defined(__ARM_EABI__) || \
  3581. (defined(__s390__) && !defined(__s390x__))
  3582. #define __NR__getresgid32 __NR_getresgid32
  3583. #define __NR__getresuid32 __NR_getresuid32
  3584. #define __NR__setfsgid32 __NR_setfsgid32
  3585. #define __NR__setfsuid32 __NR_setfsuid32
  3586. #define __NR__setresgid32 __NR_setresgid32
  3587. #define __NR__setresuid32 __NR_setresuid32
  3588. #if defined(__ARM_EABI__)
  3589. LSS_INLINE _syscall2(int, ugetrlimit, int, r,
  3590. struct kernel_rlimit*, l)
  3591. #endif
  3592. LSS_INLINE _syscall3(int, _getresgid32, gid_t *, r,
  3593. gid_t *, e, gid_t *, s)
  3594. LSS_INLINE _syscall3(int, _getresuid32, uid_t *, r,
  3595. uid_t *, e, uid_t *, s)
  3596. LSS_INLINE _syscall1(int, _setfsgid32, gid_t, f)
  3597. LSS_INLINE _syscall1(int, _setfsuid32, uid_t, f)
  3598. LSS_INLINE _syscall3(int, _setresgid32, gid_t, r,
  3599. gid_t, e, gid_t, s)
  3600. LSS_INLINE _syscall3(int, _setresuid32, uid_t, r,
  3601. uid_t, e, uid_t, s)
  3602. LSS_INLINE int LSS_NAME(getresgid32)(gid_t *rgid,
  3603. gid_t *egid,
  3604. gid_t *sgid) {
  3605. int rc;
  3606. if ((rc = LSS_NAME(_getresgid32)(rgid, egid, sgid)) < 0 &&
  3607. LSS_ERRNO == ENOSYS) {
  3608. if ((rgid == NULL) || (egid == NULL) || (sgid == NULL)) {
  3609. return EFAULT;
  3610. }
  3611. // Clear the high bits first, since getresgid only sets 16 bits
  3612. *rgid = *egid = *sgid = 0;
  3613. rc = LSS_NAME(getresgid)(rgid, egid, sgid);
  3614. }
  3615. return rc;
  3616. }
  3617. LSS_INLINE int LSS_NAME(getresuid32)(uid_t *ruid,
  3618. uid_t *euid,
  3619. uid_t *suid) {
  3620. int rc;
  3621. if ((rc = LSS_NAME(_getresuid32)(ruid, euid, suid)) < 0 &&
  3622. LSS_ERRNO == ENOSYS) {
  3623. if ((ruid == NULL) || (euid == NULL) || (suid == NULL)) {
  3624. return EFAULT;
  3625. }
  3626. // Clear the high bits first, since getresuid only sets 16 bits
  3627. *ruid = *euid = *suid = 0;
  3628. rc = LSS_NAME(getresuid)(ruid, euid, suid);
  3629. }
  3630. return rc;
  3631. }
  3632. LSS_INLINE int LSS_NAME(setfsgid32)(gid_t gid) {
  3633. int rc;
  3634. if ((rc = LSS_NAME(_setfsgid32)(gid)) < 0 &&
  3635. LSS_ERRNO == ENOSYS) {
  3636. if ((unsigned int)gid & ~0xFFFFu) {
  3637. rc = EINVAL;
  3638. } else {
  3639. rc = LSS_NAME(setfsgid)(gid);
  3640. }
  3641. }
  3642. return rc;
  3643. }
  3644. LSS_INLINE int LSS_NAME(setfsuid32)(uid_t uid) {
  3645. int rc;
  3646. if ((rc = LSS_NAME(_setfsuid32)(uid)) < 0 &&
  3647. LSS_ERRNO == ENOSYS) {
  3648. if ((unsigned int)uid & ~0xFFFFu) {
  3649. rc = EINVAL;
  3650. } else {
  3651. rc = LSS_NAME(setfsuid)(uid);
  3652. }
  3653. }
  3654. return rc;
  3655. }
  3656. LSS_INLINE int LSS_NAME(setresgid32)(gid_t rgid, gid_t egid, gid_t sgid) {
  3657. int rc;
  3658. if ((rc = LSS_NAME(_setresgid32)(rgid, egid, sgid)) < 0 &&
  3659. LSS_ERRNO == ENOSYS) {
  3660. if ((unsigned int)rgid & ~0xFFFFu ||
  3661. (unsigned int)egid & ~0xFFFFu ||
  3662. (unsigned int)sgid & ~0xFFFFu) {
  3663. rc = EINVAL;
  3664. } else {
  3665. rc = LSS_NAME(setresgid)(rgid, egid, sgid);
  3666. }
  3667. }
  3668. return rc;
  3669. }
  3670. LSS_INLINE int LSS_NAME(setresuid32)(uid_t ruid, uid_t euid, uid_t suid) {
  3671. int rc;
  3672. if ((rc = LSS_NAME(_setresuid32)(ruid, euid, suid)) < 0 &&
  3673. LSS_ERRNO == ENOSYS) {
  3674. if ((unsigned int)ruid & ~0xFFFFu ||
  3675. (unsigned int)euid & ~0xFFFFu ||
  3676. (unsigned int)suid & ~0xFFFFu) {
  3677. rc = EINVAL;
  3678. } else {
  3679. rc = LSS_NAME(setresuid)(ruid, euid, suid);
  3680. }
  3681. }
  3682. return rc;
  3683. }
  3684. #endif
  3685. LSS_INLINE int LSS_NAME(sigemptyset)(struct kernel_sigset_t *set) {
  3686. memset(&set->sig, 0, sizeof(set->sig));
  3687. return 0;
  3688. }
  3689. LSS_INLINE int LSS_NAME(sigfillset)(struct kernel_sigset_t *set) {
  3690. memset(&set->sig, -1, sizeof(set->sig));
  3691. return 0;
  3692. }
  3693. LSS_INLINE int LSS_NAME(sigaddset)(struct kernel_sigset_t *set,
  3694. int signum) {
  3695. if (signum < 1 || signum > (int)(8*sizeof(set->sig))) {
  3696. LSS_ERRNO = EINVAL;
  3697. return -1;
  3698. } else {
  3699. set->sig[(signum - 1)/(8*sizeof(set->sig[0]))]
  3700. |= 1UL << ((signum - 1) % (8*sizeof(set->sig[0])));
  3701. return 0;
  3702. }
  3703. }
  3704. LSS_INLINE int LSS_NAME(sigdelset)(struct kernel_sigset_t *set,
  3705. int signum) {
  3706. if (signum < 1 || signum > (int)(8*sizeof(set->sig))) {
  3707. LSS_ERRNO = EINVAL;
  3708. return -1;
  3709. } else {
  3710. set->sig[(signum - 1)/(8*sizeof(set->sig[0]))]
  3711. &= ~(1UL << ((signum - 1) % (8*sizeof(set->sig[0]))));
  3712. return 0;
  3713. }
  3714. }
  3715. LSS_INLINE int LSS_NAME(sigismember)(struct kernel_sigset_t *set,
  3716. int signum) {
  3717. if (signum < 1 || signum > (int)(8*sizeof(set->sig))) {
  3718. LSS_ERRNO = EINVAL;
  3719. return -1;
  3720. } else {
  3721. return !!(set->sig[(signum - 1)/(8*sizeof(set->sig[0]))] &
  3722. (1UL << ((signum - 1) % (8*sizeof(set->sig[0])))));
  3723. }
  3724. }
  3725. #if defined(__i386__) || \
  3726. defined(__ARM_ARCH_3__) || defined(__ARM_EABI__) || \
  3727. (defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI32) || \
  3728. defined(__PPC__) || \
  3729. (defined(__s390__) && !defined(__s390x__))
  3730. #define __NR__sigaction __NR_sigaction
  3731. #define __NR__sigpending __NR_sigpending
  3732. #define __NR__sigprocmask __NR_sigprocmask
  3733. #define __NR__sigsuspend __NR_sigsuspend
  3734. #define __NR__socketcall __NR_socketcall
  3735. LSS_INLINE _syscall2(int, fstat64, int, f,
  3736. struct kernel_stat64 *, b)
  3737. LSS_INLINE _syscall5(int, _llseek, uint, fd,
  3738. unsigned long, hi, unsigned long, lo,
  3739. loff_t *, res, uint, wh)
  3740. #if defined(__s390__) && !defined(__s390x__)
  3741. /* On s390, mmap2() arguments are passed in memory. */
  3742. LSS_INLINE void* LSS_NAME(_mmap2)(void *s, size_t l, int p, int f, int d,
  3743. off_t o) {
  3744. unsigned long buf[6] = { (unsigned long) s, (unsigned long) l,
  3745. (unsigned long) p, (unsigned long) f,
  3746. (unsigned long) d, (unsigned long) o };
  3747. LSS_REG(2, buf);
  3748. LSS_BODY(void*, mmap2, "0"(__r2));
  3749. }
  3750. #else
  3751. #define __NR__mmap2 __NR_mmap2
  3752. LSS_INLINE _syscall6(void*, _mmap2, void*, s,
  3753. size_t, l, int, p,
  3754. int, f, int, d,
  3755. off_t, o)
  3756. #endif
  3757. LSS_INLINE _syscall3(int, _sigaction, int, s,
  3758. const struct kernel_old_sigaction*, a,
  3759. struct kernel_old_sigaction*, o)
  3760. LSS_INLINE _syscall1(int, _sigpending, unsigned long*, s)
  3761. LSS_INLINE _syscall3(int, _sigprocmask, int, h,
  3762. const unsigned long*, s,
  3763. unsigned long*, o)
  3764. #ifdef __PPC__
  3765. LSS_INLINE _syscall1(int, _sigsuspend, unsigned long, s)
  3766. #else
  3767. LSS_INLINE _syscall3(int, _sigsuspend, const void*, a,
  3768. int, b,
  3769. unsigned long, s)
  3770. #endif
  3771. LSS_INLINE _syscall2(int, stat64, const char *, p,
  3772. struct kernel_stat64 *, b)
  3773. LSS_INLINE int LSS_NAME(sigaction)(int signum,
  3774. const struct kernel_sigaction *act,
  3775. struct kernel_sigaction *oldact) {
  3776. int old_errno = LSS_ERRNO;
  3777. int rc;
  3778. struct kernel_sigaction a;
  3779. if (act != NULL) {
  3780. a = *act;
  3781. #ifdef __i386__
  3782. /* On i386, the kernel requires us to always set our own
  3783. * SA_RESTORER when using realtime signals. Otherwise, it does not
  3784. * know how to return from a signal handler. This function must have
  3785. * a "magic" signature that the "gdb" (and maybe the kernel?) can
  3786. * recognize.
  3787. * Apparently, a SA_RESTORER is implicitly set by the kernel, when
  3788. * using non-realtime signals.
  3789. *
  3790. * TODO: Test whether ARM needs a restorer
  3791. */
  3792. if (!(a.sa_flags & SA_RESTORER)) {
  3793. a.sa_flags |= SA_RESTORER;
  3794. a.sa_restorer = (a.sa_flags & SA_SIGINFO)
  3795. ? LSS_NAME(restore_rt)() : LSS_NAME(restore)();
  3796. }
  3797. #endif
  3798. }
  3799. rc = LSS_NAME(rt_sigaction)(signum, act ? &a : act, oldact,
  3800. (KERNEL_NSIG+7)/8);
  3801. if (rc < 0 && LSS_ERRNO == ENOSYS) {
  3802. struct kernel_old_sigaction oa, ooa, *ptr_a = &oa, *ptr_oa = &ooa;
  3803. if (!act) {
  3804. ptr_a = NULL;
  3805. } else {
  3806. oa.sa_handler_ = act->sa_handler_;
  3807. memcpy(&oa.sa_mask, &act->sa_mask, sizeof(oa.sa_mask));
  3808. #ifndef __mips__
  3809. oa.sa_restorer = act->sa_restorer;
  3810. #endif
  3811. oa.sa_flags = act->sa_flags;
  3812. }
  3813. if (!oldact) {
  3814. ptr_oa = NULL;
  3815. }
  3816. LSS_ERRNO = old_errno;
  3817. rc = LSS_NAME(_sigaction)(signum, ptr_a, ptr_oa);
  3818. if (rc == 0 && oldact) {
  3819. if (act) {
  3820. memcpy(oldact, act, sizeof(*act));
  3821. } else {
  3822. memset(oldact, 0, sizeof(*oldact));
  3823. }
  3824. oldact->sa_handler_ = ptr_oa->sa_handler_;
  3825. oldact->sa_flags = ptr_oa->sa_flags;
  3826. memcpy(&oldact->sa_mask, &ptr_oa->sa_mask, sizeof(ptr_oa->sa_mask));
  3827. #ifndef __mips__
  3828. oldact->sa_restorer = ptr_oa->sa_restorer;
  3829. #endif
  3830. }
  3831. }
  3832. return rc;
  3833. }
  3834. LSS_INLINE int LSS_NAME(sigpending)(struct kernel_sigset_t *set) {
  3835. int old_errno = LSS_ERRNO;
  3836. int rc = LSS_NAME(rt_sigpending)(set, (KERNEL_NSIG+7)/8);
  3837. if (rc < 0 && LSS_ERRNO == ENOSYS) {
  3838. LSS_ERRNO = old_errno;
  3839. LSS_NAME(sigemptyset)(set);
  3840. rc = LSS_NAME(_sigpending)(&set->sig[0]);
  3841. }
  3842. return rc;
  3843. }
  3844. LSS_INLINE int LSS_NAME(sigprocmask)(int how,
  3845. const struct kernel_sigset_t *set,
  3846. struct kernel_sigset_t *oldset) {
  3847. int olderrno = LSS_ERRNO;
  3848. int rc = LSS_NAME(rt_sigprocmask)(how, set, oldset, (KERNEL_NSIG+7)/8);
  3849. if (rc < 0 && LSS_ERRNO == ENOSYS) {
  3850. LSS_ERRNO = olderrno;
  3851. if (oldset) {
  3852. LSS_NAME(sigemptyset)(oldset);
  3853. }
  3854. rc = LSS_NAME(_sigprocmask)(how,
  3855. set ? &set->sig[0] : NULL,
  3856. oldset ? &oldset->sig[0] : NULL);
  3857. }
  3858. return rc;
  3859. }
  3860. LSS_INLINE int LSS_NAME(sigsuspend)(const struct kernel_sigset_t *set) {
  3861. int olderrno = LSS_ERRNO;
  3862. int rc = LSS_NAME(rt_sigsuspend)(set, (KERNEL_NSIG+7)/8);
  3863. if (rc < 0 && LSS_ERRNO == ENOSYS) {
  3864. LSS_ERRNO = olderrno;
  3865. rc = LSS_NAME(_sigsuspend)(
  3866. #ifndef __PPC__
  3867. set, 0,
  3868. #endif
  3869. set->sig[0]);
  3870. }
  3871. return rc;
  3872. }
  3873. #endif
  3874. #if defined(__i386__) || \
  3875. defined(__ARM_ARCH_3__) || defined(__ARM_EABI__) || \
  3876. (defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI32) || \
  3877. defined(__PPC__) || \
  3878. (defined(__s390__) && !defined(__s390x__))
  3879. /* On these architectures, implement mmap() with mmap2(). */
  3880. LSS_INLINE void* LSS_NAME(mmap)(void *s, size_t l, int p, int f, int d,
  3881. int64_t o) {
  3882. if (o % 4096) {
  3883. LSS_ERRNO = EINVAL;
  3884. return (void *) -1;
  3885. }
  3886. return LSS_NAME(_mmap2)(s, l, p, f, d, (o / 4096));
  3887. }
  3888. #elif defined(__s390x__)
  3889. /* On s390x, mmap() arguments are passed in memory. */
  3890. LSS_INLINE void* LSS_NAME(mmap)(void *s, size_t l, int p, int f, int d,
  3891. int64_t o) {
  3892. unsigned long buf[6] = { (unsigned long) s, (unsigned long) l,
  3893. (unsigned long) p, (unsigned long) f,
  3894. (unsigned long) d, (unsigned long) o };
  3895. LSS_REG(2, buf);
  3896. LSS_BODY(void*, mmap, "0"(__r2));
  3897. }
  3898. #elif defined(__x86_64__)
  3899. /* Need to make sure __off64_t isn't truncated to 32-bits under x32. */
  3900. LSS_INLINE void* LSS_NAME(mmap)(void *s, size_t l, int p, int f, int d,
  3901. int64_t o) {
  3902. LSS_BODY(6, void*, mmap, LSS_SYSCALL_ARG(s), LSS_SYSCALL_ARG(l),
  3903. LSS_SYSCALL_ARG(p), LSS_SYSCALL_ARG(f),
  3904. LSS_SYSCALL_ARG(d), (uint64_t)(o));
  3905. }
  3906. #else
  3907. /* Remaining 64-bit architectures. */
  3908. LSS_INLINE _syscall6(void*, mmap, void*, addr, size_t, length, int, prot,
  3909. int, flags, int, fd, int64_t, offset)
  3910. #endif
  3911. #if defined(__PPC__)
  3912. #undef LSS_SC_LOADARGS_0
  3913. #define LSS_SC_LOADARGS_0(dummy...)
  3914. #undef LSS_SC_LOADARGS_1
  3915. #define LSS_SC_LOADARGS_1(arg1) \
  3916. __sc_4 = (unsigned long) (arg1)
  3917. #undef LSS_SC_LOADARGS_2
  3918. #define LSS_SC_LOADARGS_2(arg1, arg2) \
  3919. LSS_SC_LOADARGS_1(arg1); \
  3920. __sc_5 = (unsigned long) (arg2)
  3921. #undef LSS_SC_LOADARGS_3
  3922. #define LSS_SC_LOADARGS_3(arg1, arg2, arg3) \
  3923. LSS_SC_LOADARGS_2(arg1, arg2); \
  3924. __sc_6 = (unsigned long) (arg3)
  3925. #undef LSS_SC_LOADARGS_4
  3926. #define LSS_SC_LOADARGS_4(arg1, arg2, arg3, arg4) \
  3927. LSS_SC_LOADARGS_3(arg1, arg2, arg3); \
  3928. __sc_7 = (unsigned long) (arg4)
  3929. #undef LSS_SC_LOADARGS_5
  3930. #define LSS_SC_LOADARGS_5(arg1, arg2, arg3, arg4, arg5) \
  3931. LSS_SC_LOADARGS_4(arg1, arg2, arg3, arg4); \
  3932. __sc_8 = (unsigned long) (arg5)
  3933. #undef LSS_SC_BODY
  3934. #define LSS_SC_BODY(nr, type, opt, args...) \
  3935. long __sc_ret, __sc_err; \
  3936. { \
  3937. register unsigned long __sc_0 __asm__ ("r0") = __NR_socketcall; \
  3938. register unsigned long __sc_3 __asm__ ("r3") = opt; \
  3939. register unsigned long __sc_4 __asm__ ("r4"); \
  3940. register unsigned long __sc_5 __asm__ ("r5"); \
  3941. register unsigned long __sc_6 __asm__ ("r6"); \
  3942. register unsigned long __sc_7 __asm__ ("r7"); \
  3943. register unsigned long __sc_8 __asm__ ("r8"); \
  3944. LSS_SC_LOADARGS_##nr(args); \
  3945. __asm__ __volatile__ \
  3946. ("stwu 1, -48(1)\n\t" \
  3947. "stw 4, 20(1)\n\t" \
  3948. "stw 5, 24(1)\n\t" \
  3949. "stw 6, 28(1)\n\t" \
  3950. "stw 7, 32(1)\n\t" \
  3951. "stw 8, 36(1)\n\t" \
  3952. "addi 4, 1, 20\n\t" \
  3953. "sc\n\t" \
  3954. "mfcr %0" \
  3955. : "=&r" (__sc_0), \
  3956. "=&r" (__sc_3), "=&r" (__sc_4), \
  3957. "=&r" (__sc_5), "=&r" (__sc_6), \
  3958. "=&r" (__sc_7), "=&r" (__sc_8) \
  3959. : LSS_ASMINPUT_##nr \
  3960. : "cr0", "ctr", "memory"); \
  3961. __sc_ret = __sc_3; \
  3962. __sc_err = __sc_0; \
  3963. } \
  3964. LSS_RETURN(type, __sc_ret, __sc_err)
  3965. LSS_INLINE ssize_t LSS_NAME(recvmsg)(int s,struct kernel_msghdr *msg,
  3966. int flags){
  3967. LSS_SC_BODY(3, ssize_t, 17, s, msg, flags);
  3968. }
  3969. LSS_INLINE ssize_t LSS_NAME(sendmsg)(int s,
  3970. const struct kernel_msghdr *msg,
  3971. int flags) {
  3972. LSS_SC_BODY(3, ssize_t, 16, s, msg, flags);
  3973. }
  3974. // TODO(csilvers): why is this ifdef'ed out?
  3975. #if 0
  3976. LSS_INLINE ssize_t LSS_NAME(sendto)(int s, const void *buf, size_t len,
  3977. int flags,
  3978. const struct kernel_sockaddr *to,
  3979. unsigned int tolen) {
  3980. LSS_BODY(6, ssize_t, 11, s, buf, len, flags, to, tolen);
  3981. }
  3982. #endif
  3983. LSS_INLINE int LSS_NAME(shutdown)(int s, int how) {
  3984. LSS_SC_BODY(2, int, 13, s, how);
  3985. }
  3986. LSS_INLINE int LSS_NAME(socket)(int domain, int type, int protocol) {
  3987. LSS_SC_BODY(3, int, 1, domain, type, protocol);
  3988. }
  3989. LSS_INLINE int LSS_NAME(socketpair)(int d, int type, int protocol,
  3990. int sv[2]) {
  3991. LSS_SC_BODY(4, int, 8, d, type, protocol, sv);
  3992. }
  3993. #endif
  3994. #if defined(__ARM_EABI__) || defined (__aarch64__)
  3995. LSS_INLINE _syscall3(ssize_t, recvmsg, int, s, struct kernel_msghdr*, msg,
  3996. int, flags)
  3997. LSS_INLINE _syscall3(ssize_t, sendmsg, int, s, const struct kernel_msghdr*,
  3998. msg, int, flags)
  3999. LSS_INLINE _syscall6(ssize_t, sendto, int, s, const void*, buf, size_t,len,
  4000. int, flags, const struct kernel_sockaddr*, to,
  4001. unsigned int, tolen)
  4002. LSS_INLINE _syscall2(int, shutdown, int, s, int, how)
  4003. LSS_INLINE _syscall3(int, socket, int, domain, int, type, int, protocol)
  4004. LSS_INLINE _syscall4(int, socketpair, int, d, int, type, int, protocol,
  4005. int*, sv)
  4006. #endif
  4007. #if defined(__i386__) || defined(__ARM_ARCH_3__) || \
  4008. (defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI32) || \
  4009. defined(__s390__)
  4010. #define __NR__socketcall __NR_socketcall
  4011. LSS_INLINE _syscall2(int, _socketcall, int, c,
  4012. va_list, a)
  4013. LSS_INLINE int LSS_NAME(socketcall)(int op, ...) {
  4014. int rc;
  4015. va_list ap;
  4016. va_start(ap, op);
  4017. rc = LSS_NAME(_socketcall)(op, ap);
  4018. va_end(ap);
  4019. return rc;
  4020. }
  4021. LSS_INLINE ssize_t LSS_NAME(recvmsg)(int s,struct kernel_msghdr *msg,
  4022. int flags){
  4023. return (ssize_t)LSS_NAME(socketcall)(17, s, msg, flags);
  4024. }
  4025. LSS_INLINE ssize_t LSS_NAME(sendmsg)(int s,
  4026. const struct kernel_msghdr *msg,
  4027. int flags) {
  4028. return (ssize_t)LSS_NAME(socketcall)(16, s, msg, flags);
  4029. }
  4030. LSS_INLINE ssize_t LSS_NAME(sendto)(int s, const void *buf, size_t len,
  4031. int flags,
  4032. const struct kernel_sockaddr *to,
  4033. unsigned int tolen) {
  4034. return (ssize_t)LSS_NAME(socketcall)(11, s, buf, len, flags, to, tolen);
  4035. }
  4036. LSS_INLINE int LSS_NAME(shutdown)(int s, int how) {
  4037. return LSS_NAME(socketcall)(13, s, how);
  4038. }
  4039. LSS_INLINE int LSS_NAME(socket)(int domain, int type, int protocol) {
  4040. return LSS_NAME(socketcall)(1, domain, type, protocol);
  4041. }
  4042. LSS_INLINE int LSS_NAME(socketpair)(int d, int type, int protocol,
  4043. int sv[2]) {
  4044. return LSS_NAME(socketcall)(8, d, type, protocol, sv);
  4045. }
  4046. #endif
  4047. #if defined(__NR_fstatat64)
  4048. LSS_INLINE _syscall4(int, fstatat64, int, d,
  4049. const char *, p,
  4050. struct kernel_stat64 *, b, int, f)
  4051. #endif
  4052. #if defined(__i386__) || defined(__PPC__) || \
  4053. (defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI32)
  4054. LSS_INLINE _syscall3(pid_t, waitpid, pid_t, p,
  4055. int*, s, int, o)
  4056. #endif
  4057. #if defined(__mips__)
  4058. /* sys_pipe() on MIPS has non-standard calling conventions, as it returns
  4059. * both file handles through CPU registers.
  4060. */
  4061. LSS_INLINE int LSS_NAME(pipe)(int *p) {
  4062. register unsigned long __v0 __asm__("$2") = __NR_pipe;
  4063. register unsigned long __v1 __asm__("$3");
  4064. register unsigned long __r7 __asm__("$7");
  4065. __asm__ __volatile__ ("syscall\n"
  4066. : "=r"(__v0), "=r"(__v1), "=r" (__r7)
  4067. : "0"(__v0)
  4068. : "$8", "$9", "$10", "$11", "$12",
  4069. "$13", "$14", "$15", "$24", "$25", "memory");
  4070. if (__r7) {
  4071. unsigned long __errnovalue = __v0;
  4072. LSS_ERRNO = __errnovalue;
  4073. return -1;
  4074. } else {
  4075. p[0] = __v0;
  4076. p[1] = __v1;
  4077. return 0;
  4078. }
  4079. }
  4080. #elif !defined(__aarch64__)
  4081. // The unlink syscall has been deprecated on aarch64. We polyfill it below.
  4082. LSS_INLINE _syscall1(int, pipe, int *, p)
  4083. #endif
  4084. /* TODO(csilvers): see if ppc can/should support this as well */
  4085. #if defined(__i386__) || defined(__ARM_ARCH_3__) || \
  4086. defined(__ARM_EABI__) || \
  4087. (defined(__mips__) && _MIPS_SIM != _MIPS_SIM_ABI64) || \
  4088. (defined(__s390__) && !defined(__s390x__))
  4089. #define __NR__statfs64 __NR_statfs64
  4090. #define __NR__fstatfs64 __NR_fstatfs64
  4091. LSS_INLINE _syscall3(int, _statfs64, const char*, p,
  4092. size_t, s,struct kernel_statfs64*, b)
  4093. LSS_INLINE _syscall3(int, _fstatfs64, int, f,
  4094. size_t, s,struct kernel_statfs64*, b)
  4095. LSS_INLINE int LSS_NAME(statfs64)(const char *p,
  4096. struct kernel_statfs64 *b) {
  4097. return LSS_NAME(_statfs64)(p, sizeof(*b), b);
  4098. }
  4099. LSS_INLINE int LSS_NAME(fstatfs64)(int f,struct kernel_statfs64 *b) {
  4100. return LSS_NAME(_fstatfs64)(f, sizeof(*b), b);
  4101. }
  4102. #endif
  4103. LSS_INLINE int LSS_NAME(execv)(const char *path, const char *const argv[]) {
  4104. extern char **environ;
  4105. return LSS_NAME(execve)(path, argv, (const char *const *)environ);
  4106. }
  4107. LSS_INLINE pid_t LSS_NAME(gettid)(void) {
  4108. pid_t tid = LSS_NAME(_gettid)();
  4109. if (tid != -1) {
  4110. return tid;
  4111. }
  4112. return LSS_NAME(getpid)();
  4113. }
  4114. LSS_INLINE void *LSS_NAME(mremap)(void *old_address, size_t old_size,
  4115. size_t new_size, int flags, ...) {
  4116. va_list ap;
  4117. void *new_address, *rc;
  4118. va_start(ap, flags);
  4119. new_address = va_arg(ap, void *);
  4120. rc = LSS_NAME(_mremap)(old_address, old_size, new_size,
  4121. flags, new_address);
  4122. va_end(ap);
  4123. return rc;
  4124. }
  4125. LSS_INLINE int LSS_NAME(ptrace_detach)(pid_t pid) {
  4126. /* PTRACE_DETACH can sometimes forget to wake up the tracee and it
  4127. * then sends job control signals to the real parent, rather than to
  4128. * the tracer. We reduce the risk of this happening by starting a
  4129. * whole new time slice, and then quickly sending a SIGCONT signal
  4130. * right after detaching from the tracee.
  4131. *
  4132. * We use tkill to ensure that we only issue a wakeup for the thread being
  4133. * detached. Large multi threaded apps can take a long time in the kernel
  4134. * processing SIGCONT.
  4135. */
  4136. int rc, err;
  4137. LSS_NAME(sched_yield)();
  4138. rc = LSS_NAME(ptrace)(PTRACE_DETACH, pid, (void *)0, (void *)0);
  4139. err = LSS_ERRNO;
  4140. LSS_NAME(tkill)(pid, SIGCONT);
  4141. /* Old systems don't have tkill */
  4142. if (LSS_ERRNO == ENOSYS)
  4143. LSS_NAME(kill)(pid, SIGCONT);
  4144. LSS_ERRNO = err;
  4145. return rc;
  4146. }
  4147. LSS_INLINE int LSS_NAME(raise)(int sig) {
  4148. return LSS_NAME(kill)(LSS_NAME(getpid)(), sig);
  4149. }
  4150. LSS_INLINE int LSS_NAME(setpgrp)(void) {
  4151. return LSS_NAME(setpgid)(0, 0);
  4152. }
  4153. LSS_INLINE int LSS_NAME(sysconf)(int name) {
  4154. extern int __getpagesize(void);
  4155. switch (name) {
  4156. case _SC_OPEN_MAX: {
  4157. struct kernel_rlimit limit;
  4158. #if defined(__ARM_EABI__)
  4159. return LSS_NAME(ugetrlimit)(RLIMIT_NOFILE, &limit) < 0
  4160. ? 8192 : limit.rlim_cur;
  4161. #else
  4162. return LSS_NAME(getrlimit)(RLIMIT_NOFILE, &limit) < 0
  4163. ? 8192 : limit.rlim_cur;
  4164. #endif
  4165. }
  4166. case _SC_PAGESIZE:
  4167. return __getpagesize();
  4168. default:
  4169. LSS_ERRNO = ENOSYS;
  4170. return -1;
  4171. }
  4172. }
  4173. #if defined(__x86_64__)
  4174. /* Need to make sure loff_t isn't truncated to 32-bits under x32. */
  4175. LSS_INLINE ssize_t LSS_NAME(pread64)(int f, void *b, size_t c, loff_t o) {
  4176. LSS_BODY(4, ssize_t, pread64, LSS_SYSCALL_ARG(f), LSS_SYSCALL_ARG(b),
  4177. LSS_SYSCALL_ARG(c), (uint64_t)(o));
  4178. }
  4179. LSS_INLINE ssize_t LSS_NAME(pwrite64)(int f, const void *b, size_t c,
  4180. loff_t o) {
  4181. LSS_BODY(4, ssize_t, pwrite64, LSS_SYSCALL_ARG(f), LSS_SYSCALL_ARG(b),
  4182. LSS_SYSCALL_ARG(c), (uint64_t)(o));
  4183. }
  4184. LSS_INLINE int LSS_NAME(readahead)(int f, loff_t o, unsigned c) {
  4185. LSS_BODY(3, int, readahead, LSS_SYSCALL_ARG(f), (uint64_t)(o),
  4186. LSS_SYSCALL_ARG(c));
  4187. }
  4188. #elif defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI64
  4189. LSS_INLINE _syscall4(ssize_t, pread64, int, f,
  4190. void *, b, size_t, c,
  4191. loff_t, o)
  4192. LSS_INLINE _syscall4(ssize_t, pwrite64, int, f,
  4193. const void *, b, size_t, c,
  4194. loff_t, o)
  4195. LSS_INLINE _syscall3(int, readahead, int, f,
  4196. loff_t, o, unsigned, c)
  4197. #else
  4198. #define __NR__pread64 __NR_pread64
  4199. #define __NR__pwrite64 __NR_pwrite64
  4200. #define __NR__readahead __NR_readahead
  4201. #if defined(__ARM_EABI__) || defined(__mips__)
  4202. /* On ARM and MIPS, a 64-bit parameter has to be in an even-odd register
  4203. * pair. Hence these calls ignore their fourth argument (r3) so that their
  4204. * fifth and sixth make such a pair (r4,r5).
  4205. */
  4206. #define LSS_LLARG_PAD 0,
  4207. LSS_INLINE _syscall6(ssize_t, _pread64, int, f,
  4208. void *, b, size_t, c,
  4209. unsigned, skip, unsigned, o1, unsigned, o2)
  4210. LSS_INLINE _syscall6(ssize_t, _pwrite64, int, f,
  4211. const void *, b, size_t, c,
  4212. unsigned, skip, unsigned, o1, unsigned, o2)
  4213. LSS_INLINE _syscall5(int, _readahead, int, f,
  4214. unsigned, skip,
  4215. unsigned, o1, unsigned, o2, size_t, c)
  4216. #else
  4217. #define LSS_LLARG_PAD
  4218. LSS_INLINE _syscall5(ssize_t, _pread64, int, f,
  4219. void *, b, size_t, c, unsigned, o1,
  4220. unsigned, o2)
  4221. LSS_INLINE _syscall5(ssize_t, _pwrite64, int, f,
  4222. const void *, b, size_t, c, unsigned, o1,
  4223. long, o2)
  4224. LSS_INLINE _syscall4(int, _readahead, int, f,
  4225. unsigned, o1, unsigned, o2, size_t, c)
  4226. #endif
  4227. /* We force 64bit-wide parameters onto the stack, then access each
  4228. * 32-bit component individually. This guarantees that we build the
  4229. * correct parameters independent of the native byte-order of the
  4230. * underlying architecture.
  4231. */
  4232. LSS_INLINE ssize_t LSS_NAME(pread64)(int fd, void *buf, size_t count,
  4233. loff_t off) {
  4234. union { loff_t off; unsigned arg[2]; } o = { off };
  4235. return LSS_NAME(_pread64)(fd, buf, count,
  4236. LSS_LLARG_PAD o.arg[0], o.arg[1]);
  4237. }
  4238. LSS_INLINE ssize_t LSS_NAME(pwrite64)(int fd, const void *buf,
  4239. size_t count, loff_t off) {
  4240. union { loff_t off; unsigned arg[2]; } o = { off };
  4241. return LSS_NAME(_pwrite64)(fd, buf, count,
  4242. LSS_LLARG_PAD o.arg[0], o.arg[1]);
  4243. }
  4244. LSS_INLINE int LSS_NAME(readahead)(int fd, loff_t off, int len) {
  4245. union { loff_t off; unsigned arg[2]; } o = { off };
  4246. return LSS_NAME(_readahead)(fd, LSS_LLARG_PAD o.arg[0], o.arg[1], len);
  4247. }
  4248. #endif
  4249. #endif
  4250. #if defined(__aarch64__)
  4251. LSS_INLINE _syscall3(int, dup3, int, s, int, d, int, f)
  4252. LSS_INLINE _syscall4(int, newfstatat, int, dirfd, const char *, pathname,
  4253. struct kernel_stat *, buf, int, flags)
  4254. LSS_INLINE _syscall2(int, pipe2, int *, pipefd, int, flags)
  4255. LSS_INLINE _syscall5(int, ppoll, struct kernel_pollfd *, u,
  4256. unsigned int, n, const struct kernel_timespec *, t,
  4257. const struct kernel_sigset_t *, sigmask, size_t, s)
  4258. LSS_INLINE _syscall4(int, readlinkat, int, d, const char *, p, char *, b,
  4259. size_t, s)
  4260. #endif
  4261. /*
  4262. * Polyfills for deprecated syscalls.
  4263. */
  4264. #if defined(__aarch64__)
  4265. LSS_INLINE int LSS_NAME(dup2)(int s, int d) {
  4266. return LSS_NAME(dup3)(s, d, 0);
  4267. }
  4268. LSS_INLINE int LSS_NAME(open)(const char *pathname, int flags, int mode) {
  4269. return LSS_NAME(openat)(AT_FDCWD, pathname, flags, mode);
  4270. }
  4271. LSS_INLINE int LSS_NAME(unlink)(const char *pathname) {
  4272. return LSS_NAME(unlinkat)(AT_FDCWD, pathname, 0);
  4273. }
  4274. LSS_INLINE int LSS_NAME(readlink)(const char *pathname, char *buffer,
  4275. size_t size) {
  4276. return LSS_NAME(readlinkat)(AT_FDCWD, pathname, buffer, size);
  4277. }
  4278. LSS_INLINE pid_t LSS_NAME(pipe)(int *pipefd) {
  4279. return LSS_NAME(pipe2)(pipefd, 0);
  4280. }
  4281. LSS_INLINE int LSS_NAME(poll)(struct kernel_pollfd *fds, unsigned int nfds,
  4282. int timeout) {
  4283. struct kernel_timespec timeout_ts;
  4284. struct kernel_timespec *timeout_ts_p = NULL;
  4285. if (timeout >= 0) {
  4286. timeout_ts.tv_sec = timeout / 1000;
  4287. timeout_ts.tv_nsec = (timeout % 1000) * 1000000;
  4288. timeout_ts_p = &timeout_ts;
  4289. }
  4290. return LSS_NAME(ppoll)(fds, nfds, timeout_ts_p, NULL, 0);
  4291. }
  4292. LSS_INLINE int LSS_NAME(stat)(const char *pathname,
  4293. struct kernel_stat *buf) {
  4294. return LSS_NAME(newfstatat)(AT_FDCWD, pathname, buf, 0);
  4295. }
  4296. LSS_INLINE pid_t LSS_NAME(fork)(void) {
  4297. // No fork syscall on aarch64 - implement by means of the clone syscall.
  4298. // Note that this does not reset glibc's cached view of the PID/TID, so
  4299. // some glibc interfaces might go wrong in the forked subprocess.
  4300. int flags = SIGCHLD;
  4301. void *child_stack = NULL;
  4302. void *parent_tidptr = NULL;
  4303. void *newtls = NULL;
  4304. void *child_tidptr = NULL;
  4305. LSS_REG(0, flags);
  4306. LSS_REG(1, child_stack);
  4307. LSS_REG(2, parent_tidptr);
  4308. LSS_REG(3, newtls);
  4309. LSS_REG(4, child_tidptr);
  4310. LSS_BODY(pid_t, clone, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3),
  4311. "r"(__r4));
  4312. }
  4313. #endif
  4314. #ifdef __ANDROID__
  4315. /* These restore the original values of these macros saved by the
  4316. * corresponding #pragma push_macro near the top of this file. */
  4317. # pragma pop_macro("stat64")
  4318. # pragma pop_macro("fstat64")
  4319. # pragma pop_macro("lstat64")
  4320. #endif
  4321. #if defined(__cplusplus) && !defined(SYS_CPLUSPLUS)
  4322. }
  4323. #endif
  4324. #endif
  4325. #endif