2
0

strace.c 124 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478
  1. #include "qemu/osdep.h"
  2. #include <sys/ipc.h>
  3. #include <sys/msg.h>
  4. #include <sys/sem.h>
  5. #include <sys/shm.h>
  6. #include <sys/select.h>
  7. #include <sys/mount.h>
  8. #include <arpa/inet.h>
  9. #include <netinet/in.h>
  10. #include <netinet/tcp.h>
  11. #include <netinet/udp.h>
  12. #include <linux/if_packet.h>
  13. #include <linux/in6.h>
  14. #include <linux/netlink.h>
  15. #ifdef HAVE_OPENAT2_H
  16. #include <linux/openat2.h>
  17. #endif
  18. #include <sched.h>
  19. #include "qemu.h"
  20. #include "user-internals.h"
  21. #include "strace.h"
  22. #include "signal-common.h"
  23. #include "target_mman.h"
  24. struct syscallname {
  25. int nr;
  26. const char *name;
  27. const char *format;
  28. void (*call)(CPUArchState *, const struct syscallname *,
  29. abi_long, abi_long, abi_long,
  30. abi_long, abi_long, abi_long);
  31. void (*result)(CPUArchState *, const struct syscallname *, abi_long,
  32. abi_long, abi_long, abi_long,
  33. abi_long, abi_long, abi_long);
  34. };
  35. /*
  36. * It is possible that target doesn't have syscall that uses
  37. * following flags but we don't want the compiler to warn
  38. * us about them being unused. Same applies to utility print
  39. * functions. It is ok to keep them while not used.
  40. */
  41. #define UNUSED __attribute__ ((unused))
  42. /*
  43. * Structure used to translate flag values into strings. This is
  44. * similar that is in the actual strace tool.
  45. */
  46. struct flags {
  47. abi_long f_value; /* flag */
  48. abi_long f_mask; /* mask */
  49. const char *f_string; /* stringified flag */
  50. };
  51. /* No 'struct flags' element should have a zero mask. */
  52. #define FLAG_BASIC(V, M, N) { V, M | QEMU_BUILD_BUG_ON_ZERO(!(M)), N }
  53. /* common flags for all architectures */
  54. #define FLAG_GENERIC_MASK(V, M) FLAG_BASIC(V, M, #V)
  55. #define FLAG_GENERIC(V) FLAG_BASIC(V, V, #V)
  56. /* target specific flags (syscall_defs.h has TARGET_<flag>) */
  57. #define FLAG_TARGET_MASK(V, M) FLAG_BASIC(TARGET_##V, TARGET_##M, #V)
  58. #define FLAG_TARGET(V) FLAG_BASIC(TARGET_##V, TARGET_##V, #V)
  59. /* end of flags array */
  60. #define FLAG_END { 0, 0, NULL }
  61. /* Structure used to translate enumerated values into strings */
  62. struct enums {
  63. abi_long e_value; /* enum value */
  64. const char *e_string; /* stringified enum */
  65. };
  66. /* common enums for all architectures */
  67. #define ENUM_GENERIC(name) { name, #name }
  68. /* target specific enums */
  69. #define ENUM_TARGET(name) { TARGET_ ## name, #name }
  70. /* end of enums array */
  71. #define ENUM_END { 0, NULL }
  72. UNUSED static const char *get_comma(int);
  73. UNUSED static void print_pointer(abi_long, int);
  74. UNUSED static void print_flags(const struct flags *, abi_long, int);
  75. UNUSED static void print_enums(const struct enums *, abi_long, int);
  76. UNUSED static void print_at_dirfd(abi_long, int);
  77. UNUSED static void print_file_mode(abi_long, int);
  78. UNUSED static void print_open_flags(abi_long, int);
  79. UNUSED static void print_syscall_prologue(const struct syscallname *);
  80. UNUSED static void print_syscall_epilogue(const struct syscallname *);
  81. UNUSED static void print_string(abi_long, int);
  82. UNUSED static void print_buf(abi_long addr, abi_long len, int last);
  83. UNUSED static void print_raw_param(const char *, abi_long, int);
  84. UNUSED static void print_raw_param64(const char *, long long, int last);
  85. UNUSED static void print_timeval(abi_ulong, int);
  86. UNUSED static void print_timespec(abi_ulong, int);
  87. UNUSED static void print_timespec64(abi_ulong, int);
  88. UNUSED static void print_timezone(abi_ulong, int);
  89. UNUSED static void print_itimerval(abi_ulong, int);
  90. UNUSED static void print_number(abi_long, int);
  91. UNUSED static void print_signal(abi_ulong, int);
  92. UNUSED static void print_sockaddr(abi_ulong, abi_long, int);
  93. UNUSED static void print_socket_domain(int domain);
  94. UNUSED static void print_socket_type(int type);
  95. UNUSED static void print_socket_protocol(int domain, int type, int protocol);
  96. /*
  97. * Utility functions
  98. */
  99. static void
  100. print_ipc_cmd(int cmd)
  101. {
  102. #define output_cmd(val) \
  103. if( cmd == val ) { \
  104. qemu_log(#val); \
  105. return; \
  106. }
  107. cmd &= 0xff;
  108. /* General IPC commands */
  109. output_cmd( IPC_RMID );
  110. output_cmd( IPC_SET );
  111. output_cmd( IPC_STAT );
  112. output_cmd( IPC_INFO );
  113. /* msgctl() commands */
  114. output_cmd( MSG_STAT );
  115. output_cmd( MSG_INFO );
  116. /* shmctl() commands */
  117. output_cmd( SHM_LOCK );
  118. output_cmd( SHM_UNLOCK );
  119. output_cmd( SHM_STAT );
  120. output_cmd( SHM_INFO );
  121. /* semctl() commands */
  122. output_cmd( GETPID );
  123. output_cmd( GETVAL );
  124. output_cmd( GETALL );
  125. output_cmd( GETNCNT );
  126. output_cmd( GETZCNT );
  127. output_cmd( SETVAL );
  128. output_cmd( SETALL );
  129. output_cmd( SEM_STAT );
  130. output_cmd( SEM_INFO );
  131. output_cmd( IPC_RMID );
  132. output_cmd( IPC_RMID );
  133. output_cmd( IPC_RMID );
  134. output_cmd( IPC_RMID );
  135. output_cmd( IPC_RMID );
  136. output_cmd( IPC_RMID );
  137. output_cmd( IPC_RMID );
  138. output_cmd( IPC_RMID );
  139. output_cmd( IPC_RMID );
  140. /* Some value we don't recognize */
  141. qemu_log("%d", cmd);
  142. }
  143. static const char * const target_signal_name[] = {
  144. #define MAKE_SIG_ENTRY(sig) [TARGET_##sig] = #sig,
  145. MAKE_SIGNAL_LIST
  146. #undef MAKE_SIG_ENTRY
  147. };
  148. static void
  149. print_signal_1(abi_ulong arg)
  150. {
  151. if (arg < ARRAY_SIZE(target_signal_name)) {
  152. qemu_log("%s", target_signal_name[arg]);
  153. } else {
  154. qemu_log(TARGET_ABI_FMT_lu, arg);
  155. }
  156. }
  157. static void
  158. print_signal(abi_ulong arg, int last)
  159. {
  160. print_signal_1(arg);
  161. qemu_log("%s", get_comma(last));
  162. }
  163. static void print_si_code(int arg)
  164. {
  165. const char *codename = NULL;
  166. switch (arg) {
  167. case SI_USER:
  168. codename = "SI_USER";
  169. break;
  170. case SI_KERNEL:
  171. codename = "SI_KERNEL";
  172. break;
  173. case SI_QUEUE:
  174. codename = "SI_QUEUE";
  175. break;
  176. case SI_TIMER:
  177. codename = "SI_TIMER";
  178. break;
  179. case SI_MESGQ:
  180. codename = "SI_MESGQ";
  181. break;
  182. case SI_ASYNCIO:
  183. codename = "SI_ASYNCIO";
  184. break;
  185. case SI_SIGIO:
  186. codename = "SI_SIGIO";
  187. break;
  188. case SI_TKILL:
  189. codename = "SI_TKILL";
  190. break;
  191. default:
  192. qemu_log("%d", arg);
  193. return;
  194. }
  195. qemu_log("%s", codename);
  196. }
  197. static void get_target_siginfo(target_siginfo_t *tinfo,
  198. const target_siginfo_t *info)
  199. {
  200. abi_ulong sival_ptr;
  201. int sig;
  202. int si_errno;
  203. int si_code;
  204. int si_type;
  205. __get_user(sig, &info->si_signo);
  206. __get_user(si_errno, &tinfo->si_errno);
  207. __get_user(si_code, &info->si_code);
  208. tinfo->si_signo = sig;
  209. tinfo->si_errno = si_errno;
  210. tinfo->si_code = si_code;
  211. /* Ensure we don't leak random junk to the guest later */
  212. memset(tinfo->_sifields._pad, 0, sizeof(tinfo->_sifields._pad));
  213. /* This is awkward, because we have to use a combination of
  214. * the si_code and si_signo to figure out which of the union's
  215. * members are valid. (Within the host kernel it is always possible
  216. * to tell, but the kernel carefully avoids giving userspace the
  217. * high 16 bits of si_code, so we don't have the information to
  218. * do this the easy way...) We therefore make our best guess,
  219. * bearing in mind that a guest can spoof most of the si_codes
  220. * via rt_sigqueueinfo() if it likes.
  221. *
  222. * Once we have made our guess, we record it in the top 16 bits of
  223. * the si_code, so that print_siginfo() later can use it.
  224. * print_siginfo() will strip these top bits out before printing
  225. * the si_code.
  226. */
  227. switch (si_code) {
  228. case SI_USER:
  229. case SI_TKILL:
  230. case SI_KERNEL:
  231. /* Sent via kill(), tkill() or tgkill(), or direct from the kernel.
  232. * These are the only unspoofable si_code values.
  233. */
  234. __get_user(tinfo->_sifields._kill._pid, &info->_sifields._kill._pid);
  235. __get_user(tinfo->_sifields._kill._uid, &info->_sifields._kill._uid);
  236. si_type = QEMU_SI_KILL;
  237. break;
  238. default:
  239. /* Everything else is spoofable. Make best guess based on signal */
  240. switch (sig) {
  241. case TARGET_SIGCHLD:
  242. __get_user(tinfo->_sifields._sigchld._pid,
  243. &info->_sifields._sigchld._pid);
  244. __get_user(tinfo->_sifields._sigchld._uid,
  245. &info->_sifields._sigchld._uid);
  246. __get_user(tinfo->_sifields._sigchld._status,
  247. &info->_sifields._sigchld._status);
  248. __get_user(tinfo->_sifields._sigchld._utime,
  249. &info->_sifields._sigchld._utime);
  250. __get_user(tinfo->_sifields._sigchld._stime,
  251. &info->_sifields._sigchld._stime);
  252. si_type = QEMU_SI_CHLD;
  253. break;
  254. case TARGET_SIGIO:
  255. __get_user(tinfo->_sifields._sigpoll._band,
  256. &info->_sifields._sigpoll._band);
  257. __get_user(tinfo->_sifields._sigpoll._fd,
  258. &info->_sifields._sigpoll._fd);
  259. si_type = QEMU_SI_POLL;
  260. break;
  261. default:
  262. /* Assume a sigqueue()/mq_notify()/rt_sigqueueinfo() source. */
  263. __get_user(tinfo->_sifields._rt._pid, &info->_sifields._rt._pid);
  264. __get_user(tinfo->_sifields._rt._uid, &info->_sifields._rt._uid);
  265. /* XXX: potential problem if 64 bit */
  266. __get_user(sival_ptr, &info->_sifields._rt._sigval.sival_ptr);
  267. tinfo->_sifields._rt._sigval.sival_ptr = sival_ptr;
  268. si_type = QEMU_SI_RT;
  269. break;
  270. }
  271. break;
  272. }
  273. tinfo->si_code = deposit32(si_code, 16, 16, si_type);
  274. }
  275. static void print_siginfo(const target_siginfo_t *tinfo)
  276. {
  277. /* Print a target_siginfo_t in the format desired for printing
  278. * signals being taken. We assume the target_siginfo_t is in the
  279. * internal form where the top 16 bits of si_code indicate which
  280. * part of the union is valid, rather than in the guest-visible
  281. * form where the bottom 16 bits are sign-extended into the top 16.
  282. */
  283. int si_type = extract32(tinfo->si_code, 16, 16);
  284. int si_code = sextract32(tinfo->si_code, 0, 16);
  285. qemu_log("{si_signo=");
  286. print_signal(tinfo->si_signo, 1);
  287. qemu_log(", si_code=");
  288. print_si_code(si_code);
  289. switch (si_type) {
  290. case QEMU_SI_KILL:
  291. qemu_log(", si_pid=%u, si_uid=%u",
  292. (unsigned int)tinfo->_sifields._kill._pid,
  293. (unsigned int)tinfo->_sifields._kill._uid);
  294. break;
  295. case QEMU_SI_TIMER:
  296. qemu_log(", si_timer1=%u, si_timer2=%u",
  297. tinfo->_sifields._timer._timer1,
  298. tinfo->_sifields._timer._timer2);
  299. break;
  300. case QEMU_SI_POLL:
  301. qemu_log(", si_band=%d, si_fd=%d",
  302. tinfo->_sifields._sigpoll._band,
  303. tinfo->_sifields._sigpoll._fd);
  304. break;
  305. case QEMU_SI_FAULT:
  306. qemu_log(", si_addr=");
  307. print_pointer(tinfo->_sifields._sigfault._addr, 1);
  308. break;
  309. case QEMU_SI_CHLD:
  310. qemu_log(", si_pid=%u, si_uid=%u, si_status=%d"
  311. ", si_utime=" TARGET_ABI_FMT_ld
  312. ", si_stime=" TARGET_ABI_FMT_ld,
  313. (unsigned int)(tinfo->_sifields._sigchld._pid),
  314. (unsigned int)(tinfo->_sifields._sigchld._uid),
  315. tinfo->_sifields._sigchld._status,
  316. tinfo->_sifields._sigchld._utime,
  317. tinfo->_sifields._sigchld._stime);
  318. break;
  319. case QEMU_SI_RT:
  320. qemu_log(", si_pid=%u, si_uid=%u, si_sigval=" TARGET_ABI_FMT_ld,
  321. (unsigned int)tinfo->_sifields._rt._pid,
  322. (unsigned int)tinfo->_sifields._rt._uid,
  323. tinfo->_sifields._rt._sigval.sival_ptr);
  324. break;
  325. default:
  326. g_assert_not_reached();
  327. }
  328. qemu_log("}");
  329. }
  330. static void
  331. print_sockaddr(abi_ulong addr, abi_long addrlen, int last)
  332. {
  333. struct target_sockaddr *sa;
  334. int i;
  335. int sa_family;
  336. sa = lock_user(VERIFY_READ, addr, addrlen, 1);
  337. if (sa) {
  338. sa_family = tswap16(sa->sa_family);
  339. switch (sa_family) {
  340. case AF_UNIX: {
  341. struct target_sockaddr_un *un = (struct target_sockaddr_un *)sa;
  342. qemu_log("{sun_family=AF_UNIX,sun_path=\"");
  343. for (i = 0; i < addrlen -
  344. offsetof(struct target_sockaddr_un, sun_path) &&
  345. un->sun_path[i]; i++) {
  346. qemu_log("%c", un->sun_path[i]);
  347. }
  348. qemu_log("\"},");
  349. break;
  350. }
  351. case AF_INET: {
  352. struct target_sockaddr_in *in = (struct target_sockaddr_in *)sa;
  353. uint8_t *c = (uint8_t *)&in->sin_addr.s_addr;
  354. qemu_log("{sin_family=AF_INET,sin_port=htons(%d),",
  355. ntohs(in->sin_port));
  356. qemu_log("sin_addr=inet_addr(\"%d.%d.%d.%d\")",
  357. c[0], c[1], c[2], c[3]);
  358. qemu_log("},");
  359. break;
  360. }
  361. case AF_PACKET: {
  362. struct target_sockaddr_ll *ll = (struct target_sockaddr_ll *)sa;
  363. uint8_t *c = (uint8_t *)&ll->sll_addr;
  364. qemu_log("{sll_family=AF_PACKET,"
  365. "sll_protocol=htons(0x%04x),if%d,pkttype=",
  366. ntohs(ll->sll_protocol), ll->sll_ifindex);
  367. switch (ll->sll_pkttype) {
  368. case PACKET_HOST:
  369. qemu_log("PACKET_HOST");
  370. break;
  371. case PACKET_BROADCAST:
  372. qemu_log("PACKET_BROADCAST");
  373. break;
  374. case PACKET_MULTICAST:
  375. qemu_log("PACKET_MULTICAST");
  376. break;
  377. case PACKET_OTHERHOST:
  378. qemu_log("PACKET_OTHERHOST");
  379. break;
  380. case PACKET_OUTGOING:
  381. qemu_log("PACKET_OUTGOING");
  382. break;
  383. default:
  384. qemu_log("%d", ll->sll_pkttype);
  385. break;
  386. }
  387. qemu_log(",sll_addr=%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
  388. c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]);
  389. qemu_log("},");
  390. break;
  391. }
  392. case AF_NETLINK: {
  393. struct target_sockaddr_nl *nl = (struct target_sockaddr_nl *)sa;
  394. qemu_log("{nl_family=AF_NETLINK,nl_pid=%u,nl_groups=%u},",
  395. tswap32(nl->nl_pid), tswap32(nl->nl_groups));
  396. break;
  397. }
  398. default:
  399. qemu_log("{sa_family=%d, sa_data={", sa->sa_family);
  400. for (i = 0; i < 13; i++) {
  401. qemu_log("%02x, ", sa->sa_data[i]);
  402. }
  403. qemu_log("%02x}", sa->sa_data[i]);
  404. qemu_log("},");
  405. break;
  406. }
  407. unlock_user(sa, addr, 0);
  408. } else {
  409. print_pointer(addr, 0);
  410. }
  411. qemu_log(TARGET_ABI_FMT_ld"%s", addrlen, get_comma(last));
  412. }
  413. static void
  414. print_socket_domain(int domain)
  415. {
  416. switch (domain) {
  417. case PF_UNIX:
  418. qemu_log("PF_UNIX");
  419. break;
  420. case PF_INET:
  421. qemu_log("PF_INET");
  422. break;
  423. case PF_NETLINK:
  424. qemu_log("PF_NETLINK");
  425. break;
  426. case PF_PACKET:
  427. qemu_log("PF_PACKET");
  428. break;
  429. default:
  430. qemu_log("%d", domain);
  431. break;
  432. }
  433. }
  434. static void
  435. print_socket_type(int type)
  436. {
  437. switch (type & TARGET_SOCK_TYPE_MASK) {
  438. case TARGET_SOCK_DGRAM:
  439. qemu_log("SOCK_DGRAM");
  440. break;
  441. case TARGET_SOCK_STREAM:
  442. qemu_log("SOCK_STREAM");
  443. break;
  444. case TARGET_SOCK_RAW:
  445. qemu_log("SOCK_RAW");
  446. break;
  447. case TARGET_SOCK_RDM:
  448. qemu_log("SOCK_RDM");
  449. break;
  450. case TARGET_SOCK_SEQPACKET:
  451. qemu_log("SOCK_SEQPACKET");
  452. break;
  453. case TARGET_SOCK_PACKET:
  454. qemu_log("SOCK_PACKET");
  455. break;
  456. }
  457. if (type & TARGET_SOCK_CLOEXEC) {
  458. qemu_log("|SOCK_CLOEXEC");
  459. }
  460. if (type & TARGET_SOCK_NONBLOCK) {
  461. qemu_log("|SOCK_NONBLOCK");
  462. }
  463. }
  464. static void
  465. print_socket_protocol(int domain, int type, int protocol)
  466. {
  467. if (domain == AF_PACKET ||
  468. (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
  469. switch (protocol) {
  470. case 0x0003:
  471. qemu_log("ETH_P_ALL");
  472. break;
  473. default:
  474. qemu_log("%d", protocol);
  475. }
  476. return;
  477. }
  478. if (domain == PF_NETLINK) {
  479. switch (protocol) {
  480. case NETLINK_ROUTE:
  481. qemu_log("NETLINK_ROUTE");
  482. break;
  483. case NETLINK_UNUSED:
  484. qemu_log("NETLINK_UNUSED");
  485. break;
  486. case NETLINK_USERSOCK:
  487. qemu_log("NETLINK_USERSOCK");
  488. break;
  489. case NETLINK_FIREWALL:
  490. qemu_log("NETLINK_FIREWALL");
  491. break;
  492. case NETLINK_SOCK_DIAG:
  493. qemu_log("NETLINK_SOCK_DIAG");
  494. break;
  495. case NETLINK_NFLOG:
  496. qemu_log("NETLINK_NFLOG");
  497. break;
  498. case NETLINK_XFRM:
  499. qemu_log("NETLINK_XFRM");
  500. break;
  501. case NETLINK_SELINUX:
  502. qemu_log("NETLINK_SELINUX");
  503. break;
  504. case NETLINK_ISCSI:
  505. qemu_log("NETLINK_ISCSI");
  506. break;
  507. case NETLINK_AUDIT:
  508. qemu_log("NETLINK_AUDIT");
  509. break;
  510. case NETLINK_FIB_LOOKUP:
  511. qemu_log("NETLINK_FIB_LOOKUP");
  512. break;
  513. case NETLINK_CONNECTOR:
  514. qemu_log("NETLINK_CONNECTOR");
  515. break;
  516. case NETLINK_NETFILTER:
  517. qemu_log("NETLINK_NETFILTER");
  518. break;
  519. case NETLINK_IP6_FW:
  520. qemu_log("NETLINK_IP6_FW");
  521. break;
  522. case NETLINK_DNRTMSG:
  523. qemu_log("NETLINK_DNRTMSG");
  524. break;
  525. case NETLINK_KOBJECT_UEVENT:
  526. qemu_log("NETLINK_KOBJECT_UEVENT");
  527. break;
  528. case NETLINK_GENERIC:
  529. qemu_log("NETLINK_GENERIC");
  530. break;
  531. case NETLINK_SCSITRANSPORT:
  532. qemu_log("NETLINK_SCSITRANSPORT");
  533. break;
  534. case NETLINK_ECRYPTFS:
  535. qemu_log("NETLINK_ECRYPTFS");
  536. break;
  537. case NETLINK_RDMA:
  538. qemu_log("NETLINK_RDMA");
  539. break;
  540. case NETLINK_CRYPTO:
  541. qemu_log("NETLINK_CRYPTO");
  542. break;
  543. case NETLINK_SMC:
  544. qemu_log("NETLINK_SMC");
  545. break;
  546. default:
  547. qemu_log("%d", protocol);
  548. break;
  549. }
  550. return;
  551. }
  552. switch (protocol) {
  553. case IPPROTO_IP:
  554. qemu_log("IPPROTO_IP");
  555. break;
  556. case IPPROTO_TCP:
  557. qemu_log("IPPROTO_TCP");
  558. break;
  559. case IPPROTO_UDP:
  560. qemu_log("IPPROTO_UDP");
  561. break;
  562. case IPPROTO_RAW:
  563. qemu_log("IPPROTO_RAW");
  564. break;
  565. default:
  566. qemu_log("%d", protocol);
  567. break;
  568. }
  569. }
  570. #ifdef TARGET_NR__newselect
  571. static void
  572. print_fdset(int n, abi_ulong target_fds_addr)
  573. {
  574. int i;
  575. int first = 1;
  576. qemu_log("[");
  577. if( target_fds_addr ) {
  578. abi_long *target_fds;
  579. target_fds = lock_user(VERIFY_READ,
  580. target_fds_addr,
  581. sizeof(*target_fds)*(n / TARGET_ABI_BITS + 1),
  582. 1);
  583. if (!target_fds)
  584. return;
  585. for (i=n; i>=0; i--) {
  586. if ((tswapal(target_fds[i / TARGET_ABI_BITS]) >>
  587. (i & (TARGET_ABI_BITS - 1))) & 1) {
  588. qemu_log("%s%d", get_comma(first), i);
  589. first = 0;
  590. }
  591. }
  592. unlock_user(target_fds, target_fds_addr, 0);
  593. }
  594. qemu_log("]");
  595. }
  596. #endif
  597. /*
  598. * Sysycall specific output functions
  599. */
  600. /* select */
  601. #ifdef TARGET_NR__newselect
  602. static void
  603. print_newselect(CPUArchState *cpu_env, const struct syscallname *name,
  604. abi_long arg1, abi_long arg2, abi_long arg3,
  605. abi_long arg4, abi_long arg5, abi_long arg6)
  606. {
  607. print_syscall_prologue(name);
  608. print_fdset(arg1, arg2);
  609. qemu_log(",");
  610. print_fdset(arg1, arg3);
  611. qemu_log(",");
  612. print_fdset(arg1, arg4);
  613. qemu_log(",");
  614. print_timeval(arg5, 1);
  615. print_syscall_epilogue(name);
  616. }
  617. #endif
  618. static void
  619. print_semctl(CPUArchState *cpu_env, const struct syscallname *name,
  620. abi_long arg1, abi_long arg2, abi_long arg3,
  621. abi_long arg4, abi_long arg5, abi_long arg6)
  622. {
  623. qemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",",
  624. name->name, arg1, arg2);
  625. print_ipc_cmd(arg3);
  626. qemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
  627. }
  628. static void
  629. print_shmat(CPUArchState *cpu_env, const struct syscallname *name,
  630. abi_long arg0, abi_long arg1, abi_long arg2,
  631. abi_long arg3, abi_long arg4, abi_long arg5)
  632. {
  633. static const struct flags shmat_flags[] = {
  634. FLAG_GENERIC(SHM_RND),
  635. FLAG_GENERIC(SHM_REMAP),
  636. FLAG_GENERIC(SHM_RDONLY),
  637. FLAG_GENERIC(SHM_EXEC),
  638. FLAG_END
  639. };
  640. print_syscall_prologue(name);
  641. print_raw_param(TARGET_ABI_FMT_ld, arg0, 0);
  642. print_pointer(arg1, 0);
  643. print_flags(shmat_flags, arg2, 1);
  644. print_syscall_epilogue(name);
  645. }
  646. #ifdef TARGET_NR_ipc
  647. static void
  648. print_ipc(CPUArchState *cpu_env, const struct syscallname *name,
  649. abi_long arg1, abi_long arg2, abi_long arg3,
  650. abi_long arg4, abi_long arg5, abi_long arg6)
  651. {
  652. switch(arg1) {
  653. case IPCOP_semctl:
  654. print_semctl(cpu_env, &(const struct syscallname){ .name = "semctl" },
  655. arg2, arg3, arg4, arg5, 0, 0);
  656. break;
  657. case IPCOP_shmat:
  658. print_shmat(cpu_env, &(const struct syscallname){ .name = "shmat" },
  659. arg2, arg5, arg3, 0, 0, 0);
  660. break;
  661. default:
  662. qemu_log(("%s("
  663. TARGET_ABI_FMT_ld ","
  664. TARGET_ABI_FMT_ld ","
  665. TARGET_ABI_FMT_ld ","
  666. TARGET_ABI_FMT_ld
  667. ")"),
  668. name->name, arg1, arg2, arg3, arg4);
  669. }
  670. }
  671. #endif
  672. #ifdef TARGET_NR_rt_sigprocmask
  673. static void print_target_sigset_t_1(target_sigset_t *set, int last)
  674. {
  675. bool first = true;
  676. int i, sig = 1;
  677. qemu_log("[");
  678. for (i = 0; i < TARGET_NSIG_WORDS; i++) {
  679. abi_ulong bits = 0;
  680. int j;
  681. __get_user(bits, &set->sig[i]);
  682. for (j = 0; j < sizeof(bits) * 8; j++) {
  683. if (bits & ((abi_ulong)1 << j)) {
  684. if (first) {
  685. first = false;
  686. } else {
  687. qemu_log(" ");
  688. }
  689. print_signal_1(sig);
  690. }
  691. sig++;
  692. }
  693. }
  694. qemu_log("]%s", get_comma(last));
  695. }
  696. static void print_target_sigset_t(abi_ulong addr, abi_ulong size, int last)
  697. {
  698. if (addr && size == sizeof(target_sigset_t)) {
  699. target_sigset_t *set;
  700. set = lock_user(VERIFY_READ, addr, sizeof(target_sigset_t), 1);
  701. if (set) {
  702. print_target_sigset_t_1(set, last);
  703. unlock_user(set, addr, 0);
  704. } else {
  705. print_pointer(addr, last);
  706. }
  707. } else {
  708. print_pointer(addr, last);
  709. }
  710. }
  711. #endif
  712. /*
  713. * Variants for the return value output function
  714. */
  715. static bool
  716. print_syscall_err(abi_long ret)
  717. {
  718. const char *errstr;
  719. qemu_log(" = ");
  720. if (is_error(ret)) {
  721. errstr = target_strerror(-ret);
  722. if (errstr) {
  723. qemu_log("-1 errno=%d (%s)", (int)-ret, errstr);
  724. return true;
  725. }
  726. }
  727. return false;
  728. }
  729. static void
  730. print_syscall_ret_addr(CPUArchState *cpu_env, const struct syscallname *name,
  731. abi_long ret, abi_long arg0, abi_long arg1,
  732. abi_long arg2, abi_long arg3, abi_long arg4,
  733. abi_long arg5)
  734. {
  735. if (!print_syscall_err(ret)) {
  736. qemu_log("0x" TARGET_ABI_FMT_lx, ret);
  737. }
  738. qemu_log("\n");
  739. }
  740. #if 0 /* currently unused */
  741. static void
  742. print_syscall_ret_raw(struct syscallname *name, abi_long ret)
  743. {
  744. qemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
  745. }
  746. #endif
  747. #ifdef TARGET_NR__newselect
  748. static void
  749. print_syscall_ret_newselect(CPUArchState *cpu_env, const struct syscallname *name,
  750. abi_long ret, abi_long arg0, abi_long arg1,
  751. abi_long arg2, abi_long arg3, abi_long arg4,
  752. abi_long arg5)
  753. {
  754. if (!print_syscall_err(ret)) {
  755. qemu_log(" = 0x" TARGET_ABI_FMT_lx " (", ret);
  756. print_fdset(arg0, arg1);
  757. qemu_log(",");
  758. print_fdset(arg0, arg2);
  759. qemu_log(",");
  760. print_fdset(arg0, arg3);
  761. qemu_log(",");
  762. print_timeval(arg4, 1);
  763. qemu_log(")");
  764. }
  765. qemu_log("\n");
  766. }
  767. #endif
  768. /* special meanings of adjtimex()' non-negative return values */
  769. #define TARGET_TIME_OK 0 /* clock synchronized, no leap second */
  770. #define TARGET_TIME_INS 1 /* insert leap second */
  771. #define TARGET_TIME_DEL 2 /* delete leap second */
  772. #define TARGET_TIME_OOP 3 /* leap second in progress */
  773. #define TARGET_TIME_WAIT 4 /* leap second has occurred */
  774. #define TARGET_TIME_ERROR 5 /* clock not synchronized */
  775. #ifdef TARGET_NR_adjtimex
  776. static void
  777. print_syscall_ret_adjtimex(CPUArchState *cpu_env, const struct syscallname *name,
  778. abi_long ret, abi_long arg0, abi_long arg1,
  779. abi_long arg2, abi_long arg3, abi_long arg4,
  780. abi_long arg5)
  781. {
  782. if (!print_syscall_err(ret)) {
  783. qemu_log(TARGET_ABI_FMT_ld, ret);
  784. switch (ret) {
  785. case TARGET_TIME_OK:
  786. qemu_log(" TIME_OK (clock synchronized, no leap second)");
  787. break;
  788. case TARGET_TIME_INS:
  789. qemu_log(" TIME_INS (insert leap second)");
  790. break;
  791. case TARGET_TIME_DEL:
  792. qemu_log(" TIME_DEL (delete leap second)");
  793. break;
  794. case TARGET_TIME_OOP:
  795. qemu_log(" TIME_OOP (leap second in progress)");
  796. break;
  797. case TARGET_TIME_WAIT:
  798. qemu_log(" TIME_WAIT (leap second has occurred)");
  799. break;
  800. case TARGET_TIME_ERROR:
  801. qemu_log(" TIME_ERROR (clock not synchronized)");
  802. break;
  803. }
  804. }
  805. qemu_log("\n");
  806. }
  807. #endif
  808. #if defined(TARGET_NR_clock_gettime) || defined(TARGET_NR_clock_getres)
  809. static void
  810. print_syscall_ret_clock_gettime(CPUArchState *cpu_env, const struct syscallname *name,
  811. abi_long ret, abi_long arg0, abi_long arg1,
  812. abi_long arg2, abi_long arg3, abi_long arg4,
  813. abi_long arg5)
  814. {
  815. if (!print_syscall_err(ret)) {
  816. qemu_log(TARGET_ABI_FMT_ld, ret);
  817. qemu_log(" (");
  818. print_timespec(arg1, 1);
  819. qemu_log(")");
  820. }
  821. qemu_log("\n");
  822. }
  823. #define print_syscall_ret_clock_getres print_syscall_ret_clock_gettime
  824. #endif
  825. #if defined(TARGET_NR_clock_gettime64)
  826. static void
  827. print_syscall_ret_clock_gettime64(CPUArchState *cpu_env, const struct syscallname *name,
  828. abi_long ret, abi_long arg0, abi_long arg1,
  829. abi_long arg2, abi_long arg3, abi_long arg4,
  830. abi_long arg5)
  831. {
  832. if (!print_syscall_err(ret)) {
  833. qemu_log(TARGET_ABI_FMT_ld, ret);
  834. qemu_log(" (");
  835. print_timespec64(arg1, 1);
  836. qemu_log(")");
  837. }
  838. qemu_log("\n");
  839. }
  840. #endif
  841. #ifdef TARGET_NR_gettimeofday
  842. static void
  843. print_syscall_ret_gettimeofday(CPUArchState *cpu_env, const struct syscallname *name,
  844. abi_long ret, abi_long arg0, abi_long arg1,
  845. abi_long arg2, abi_long arg3, abi_long arg4,
  846. abi_long arg5)
  847. {
  848. if (!print_syscall_err(ret)) {
  849. qemu_log(TARGET_ABI_FMT_ld, ret);
  850. qemu_log(" (");
  851. print_timeval(arg0, 0);
  852. print_timezone(arg1, 1);
  853. qemu_log(")");
  854. }
  855. qemu_log("\n");
  856. }
  857. #endif
  858. #ifdef TARGET_NR_getitimer
  859. static void
  860. print_syscall_ret_getitimer(CPUArchState *cpu_env, const struct syscallname *name,
  861. abi_long ret, abi_long arg0, abi_long arg1,
  862. abi_long arg2, abi_long arg3, abi_long arg4,
  863. abi_long arg5)
  864. {
  865. if (!print_syscall_err(ret)) {
  866. qemu_log(TARGET_ABI_FMT_ld, ret);
  867. qemu_log(" (");
  868. print_itimerval(arg1, 1);
  869. qemu_log(")");
  870. }
  871. qemu_log("\n");
  872. }
  873. #endif
  874. #ifdef TARGET_NR_getitimer
  875. static void
  876. print_syscall_ret_setitimer(CPUArchState *cpu_env, const struct syscallname *name,
  877. abi_long ret, abi_long arg0, abi_long arg1,
  878. abi_long arg2, abi_long arg3, abi_long arg4,
  879. abi_long arg5)
  880. {
  881. if (!print_syscall_err(ret)) {
  882. qemu_log(TARGET_ABI_FMT_ld, ret);
  883. qemu_log(" (old_value = ");
  884. print_itimerval(arg2, 1);
  885. qemu_log(")");
  886. }
  887. qemu_log("\n");
  888. }
  889. #endif
  890. #if defined(TARGET_NR_listxattr) || defined(TARGET_NR_llistxattr) \
  891. || defined(TARGGET_NR_flistxattr)
  892. static void
  893. print_syscall_ret_listxattr(CPUArchState *cpu_env, const struct syscallname *name,
  894. abi_long ret, abi_long arg0, abi_long arg1,
  895. abi_long arg2, abi_long arg3, abi_long arg4,
  896. abi_long arg5)
  897. {
  898. if (!print_syscall_err(ret)) {
  899. qemu_log(TARGET_ABI_FMT_ld, ret);
  900. qemu_log(" (list = ");
  901. if (arg1 != 0) {
  902. abi_long attr = arg1;
  903. while (ret) {
  904. if (attr != arg1) {
  905. qemu_log(",");
  906. }
  907. print_string(attr, 1);
  908. ret -= target_strlen(attr) + 1;
  909. attr += target_strlen(attr) + 1;
  910. }
  911. } else {
  912. qemu_log("NULL");
  913. }
  914. qemu_log(")");
  915. }
  916. qemu_log("\n");
  917. }
  918. #define print_syscall_ret_llistxattr print_syscall_ret_listxattr
  919. #define print_syscall_ret_flistxattr print_syscall_ret_listxattr
  920. #endif
  921. #ifdef TARGET_NR_ioctl
  922. static void
  923. print_syscall_ret_ioctl(CPUArchState *cpu_env, const struct syscallname *name,
  924. abi_long ret, abi_long arg0, abi_long arg1,
  925. abi_long arg2, abi_long arg3, abi_long arg4,
  926. abi_long arg5)
  927. {
  928. if (!print_syscall_err(ret)) {
  929. qemu_log(TARGET_ABI_FMT_ld, ret);
  930. const IOCTLEntry *ie;
  931. const argtype *arg_type;
  932. void *argptr;
  933. int target_size;
  934. for (ie = ioctl_entries; ie->target_cmd != 0; ie++) {
  935. if (ie->target_cmd == arg1) {
  936. break;
  937. }
  938. }
  939. if (ie->target_cmd == arg1 &&
  940. (ie->access == IOC_R || ie->access == IOC_RW)) {
  941. arg_type = ie->arg_type;
  942. qemu_log(" (");
  943. arg_type++;
  944. target_size = thunk_type_size(arg_type, 0);
  945. argptr = lock_user(VERIFY_READ, arg2, target_size, 1);
  946. if (argptr) {
  947. thunk_print(argptr, arg_type);
  948. unlock_user(argptr, arg2, target_size);
  949. } else {
  950. print_pointer(arg2, 1);
  951. }
  952. qemu_log(")");
  953. }
  954. }
  955. qemu_log("\n");
  956. }
  957. #endif
  958. UNUSED static const struct flags access_flags[] = {
  959. FLAG_GENERIC_MASK(F_OK, R_OK | W_OK | X_OK),
  960. FLAG_GENERIC(R_OK),
  961. FLAG_GENERIC(W_OK),
  962. FLAG_GENERIC(X_OK),
  963. FLAG_END,
  964. };
  965. UNUSED static const struct flags at_file_flags[] = {
  966. #ifdef AT_EACCESS
  967. FLAG_GENERIC(AT_EACCESS),
  968. #endif
  969. #ifdef AT_SYMLINK_NOFOLLOW
  970. FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
  971. #endif
  972. FLAG_END,
  973. };
  974. UNUSED static const struct flags unlinkat_flags[] = {
  975. #ifdef AT_REMOVEDIR
  976. FLAG_GENERIC(AT_REMOVEDIR),
  977. #endif
  978. FLAG_END,
  979. };
  980. UNUSED static const struct flags mode_flags[] = {
  981. FLAG_GENERIC(S_IFSOCK),
  982. FLAG_GENERIC(S_IFLNK),
  983. FLAG_GENERIC(S_IFREG),
  984. FLAG_GENERIC(S_IFBLK),
  985. FLAG_GENERIC(S_IFDIR),
  986. FLAG_GENERIC(S_IFCHR),
  987. FLAG_GENERIC(S_IFIFO),
  988. FLAG_END,
  989. };
  990. UNUSED static const struct flags open_access_flags[] = {
  991. FLAG_TARGET_MASK(O_RDONLY, O_ACCMODE),
  992. FLAG_TARGET_MASK(O_WRONLY, O_ACCMODE),
  993. FLAG_TARGET_MASK(O_RDWR, O_ACCMODE),
  994. FLAG_END,
  995. };
  996. UNUSED static const struct flags open_flags[] = {
  997. FLAG_TARGET(O_APPEND),
  998. FLAG_TARGET(O_CREAT),
  999. FLAG_TARGET(O_DIRECTORY),
  1000. FLAG_TARGET(O_EXCL),
  1001. #if TARGET_O_LARGEFILE != 0
  1002. FLAG_TARGET(O_LARGEFILE),
  1003. #endif
  1004. FLAG_TARGET(O_NOCTTY),
  1005. FLAG_TARGET(O_NOFOLLOW),
  1006. FLAG_TARGET(O_NONBLOCK), /* also O_NDELAY */
  1007. FLAG_TARGET(O_DSYNC),
  1008. FLAG_TARGET(__O_SYNC),
  1009. FLAG_TARGET(O_TRUNC),
  1010. #ifdef O_DIRECT
  1011. FLAG_TARGET(O_DIRECT),
  1012. #endif
  1013. #ifdef O_NOATIME
  1014. FLAG_TARGET(O_NOATIME),
  1015. #endif
  1016. #ifdef O_CLOEXEC
  1017. FLAG_TARGET(O_CLOEXEC),
  1018. #endif
  1019. #ifdef O_PATH
  1020. FLAG_TARGET(O_PATH),
  1021. #endif
  1022. #ifdef O_TMPFILE
  1023. FLAG_TARGET(O_TMPFILE),
  1024. FLAG_TARGET(__O_TMPFILE),
  1025. #endif
  1026. FLAG_END,
  1027. };
  1028. UNUSED static const struct flags openat2_resolve_flags[] = {
  1029. #ifdef HAVE_OPENAT2_H
  1030. FLAG_GENERIC(RESOLVE_NO_XDEV),
  1031. FLAG_GENERIC(RESOLVE_NO_MAGICLINKS),
  1032. FLAG_GENERIC(RESOLVE_NO_SYMLINKS),
  1033. FLAG_GENERIC(RESOLVE_BENEATH),
  1034. FLAG_GENERIC(RESOLVE_IN_ROOT),
  1035. FLAG_GENERIC(RESOLVE_CACHED),
  1036. #endif
  1037. FLAG_END,
  1038. };
  1039. UNUSED static const struct flags mount_flags[] = {
  1040. #ifdef MS_BIND
  1041. FLAG_GENERIC(MS_BIND),
  1042. #endif
  1043. #ifdef MS_DIRSYNC
  1044. FLAG_GENERIC(MS_DIRSYNC),
  1045. #endif
  1046. FLAG_GENERIC(MS_MANDLOCK),
  1047. #ifdef MS_MOVE
  1048. FLAG_GENERIC(MS_MOVE),
  1049. #endif
  1050. FLAG_GENERIC(MS_NOATIME),
  1051. FLAG_GENERIC(MS_NODEV),
  1052. FLAG_GENERIC(MS_NODIRATIME),
  1053. FLAG_GENERIC(MS_NOEXEC),
  1054. FLAG_GENERIC(MS_NOSUID),
  1055. FLAG_GENERIC(MS_RDONLY),
  1056. #ifdef MS_RELATIME
  1057. FLAG_GENERIC(MS_RELATIME),
  1058. #endif
  1059. FLAG_GENERIC(MS_REMOUNT),
  1060. FLAG_GENERIC(MS_SYNCHRONOUS),
  1061. FLAG_END,
  1062. };
  1063. UNUSED static const struct flags umount2_flags[] = {
  1064. #ifdef MNT_FORCE
  1065. FLAG_GENERIC(MNT_FORCE),
  1066. #endif
  1067. #ifdef MNT_DETACH
  1068. FLAG_GENERIC(MNT_DETACH),
  1069. #endif
  1070. #ifdef MNT_EXPIRE
  1071. FLAG_GENERIC(MNT_EXPIRE),
  1072. #endif
  1073. FLAG_END,
  1074. };
  1075. UNUSED static const struct flags mmap_prot_flags[] = {
  1076. FLAG_GENERIC_MASK(PROT_NONE, PROT_READ | PROT_WRITE | PROT_EXEC),
  1077. FLAG_GENERIC(PROT_EXEC),
  1078. FLAG_GENERIC(PROT_READ),
  1079. FLAG_GENERIC(PROT_WRITE),
  1080. FLAG_TARGET(PROT_SEM),
  1081. FLAG_GENERIC(PROT_GROWSDOWN),
  1082. FLAG_GENERIC(PROT_GROWSUP),
  1083. FLAG_END,
  1084. };
  1085. UNUSED static const struct flags mmap_flags[] = {
  1086. FLAG_TARGET_MASK(MAP_SHARED, MAP_TYPE),
  1087. FLAG_TARGET_MASK(MAP_PRIVATE, MAP_TYPE),
  1088. FLAG_TARGET_MASK(MAP_SHARED_VALIDATE, MAP_TYPE),
  1089. FLAG_TARGET(MAP_ANONYMOUS),
  1090. FLAG_TARGET(MAP_DENYWRITE),
  1091. FLAG_TARGET(MAP_EXECUTABLE),
  1092. FLAG_TARGET(MAP_FIXED),
  1093. FLAG_TARGET(MAP_FIXED_NOREPLACE),
  1094. FLAG_TARGET(MAP_GROWSDOWN),
  1095. FLAG_TARGET(MAP_HUGETLB),
  1096. FLAG_TARGET(MAP_LOCKED),
  1097. FLAG_TARGET(MAP_NONBLOCK),
  1098. FLAG_TARGET(MAP_NORESERVE),
  1099. FLAG_TARGET(MAP_POPULATE),
  1100. FLAG_TARGET(MAP_STACK),
  1101. FLAG_TARGET(MAP_SYNC),
  1102. #if TARGET_MAP_UNINITIALIZED != 0
  1103. FLAG_TARGET(MAP_UNINITIALIZED),
  1104. #endif
  1105. FLAG_END,
  1106. };
  1107. #ifndef CLONE_PIDFD
  1108. # define CLONE_PIDFD 0x00001000
  1109. #endif
  1110. UNUSED static const struct flags clone_flags[] = {
  1111. FLAG_GENERIC(CLONE_VM),
  1112. FLAG_GENERIC(CLONE_FS),
  1113. FLAG_GENERIC(CLONE_FILES),
  1114. FLAG_GENERIC(CLONE_SIGHAND),
  1115. FLAG_GENERIC(CLONE_PIDFD),
  1116. FLAG_GENERIC(CLONE_PTRACE),
  1117. FLAG_GENERIC(CLONE_VFORK),
  1118. FLAG_GENERIC(CLONE_PARENT),
  1119. FLAG_GENERIC(CLONE_THREAD),
  1120. FLAG_GENERIC(CLONE_NEWNS),
  1121. FLAG_GENERIC(CLONE_SYSVSEM),
  1122. FLAG_GENERIC(CLONE_SETTLS),
  1123. FLAG_GENERIC(CLONE_PARENT_SETTID),
  1124. FLAG_GENERIC(CLONE_CHILD_CLEARTID),
  1125. FLAG_GENERIC(CLONE_DETACHED),
  1126. FLAG_GENERIC(CLONE_UNTRACED),
  1127. FLAG_GENERIC(CLONE_CHILD_SETTID),
  1128. #if defined(CLONE_NEWUTS)
  1129. FLAG_GENERIC(CLONE_NEWUTS),
  1130. #endif
  1131. #if defined(CLONE_NEWIPC)
  1132. FLAG_GENERIC(CLONE_NEWIPC),
  1133. #endif
  1134. #if defined(CLONE_NEWUSER)
  1135. FLAG_GENERIC(CLONE_NEWUSER),
  1136. #endif
  1137. #if defined(CLONE_NEWPID)
  1138. FLAG_GENERIC(CLONE_NEWPID),
  1139. #endif
  1140. #if defined(CLONE_NEWNET)
  1141. FLAG_GENERIC(CLONE_NEWNET),
  1142. #endif
  1143. #if defined(CLONE_NEWCGROUP)
  1144. FLAG_GENERIC(CLONE_NEWCGROUP),
  1145. #endif
  1146. #if defined(CLONE_NEWTIME)
  1147. FLAG_GENERIC(CLONE_NEWTIME),
  1148. #endif
  1149. #if defined(CLONE_IO)
  1150. FLAG_GENERIC(CLONE_IO),
  1151. #endif
  1152. FLAG_END,
  1153. };
  1154. UNUSED static const struct flags execveat_flags[] = {
  1155. #ifdef AT_EMPTY_PATH
  1156. FLAG_GENERIC(AT_EMPTY_PATH),
  1157. #endif
  1158. #ifdef AT_SYMLINK_NOFOLLOW
  1159. FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
  1160. #endif
  1161. FLAG_END,
  1162. };
  1163. UNUSED static const struct flags msg_flags[] = {
  1164. /* send */
  1165. FLAG_GENERIC(MSG_CONFIRM),
  1166. FLAG_GENERIC(MSG_DONTROUTE),
  1167. FLAG_GENERIC(MSG_DONTWAIT),
  1168. FLAG_GENERIC(MSG_EOR),
  1169. FLAG_GENERIC(MSG_MORE),
  1170. FLAG_GENERIC(MSG_NOSIGNAL),
  1171. FLAG_GENERIC(MSG_OOB),
  1172. /* recv */
  1173. FLAG_GENERIC(MSG_CMSG_CLOEXEC),
  1174. FLAG_GENERIC(MSG_ERRQUEUE),
  1175. FLAG_GENERIC(MSG_PEEK),
  1176. FLAG_GENERIC(MSG_TRUNC),
  1177. FLAG_GENERIC(MSG_WAITALL),
  1178. /* recvmsg */
  1179. FLAG_GENERIC(MSG_CTRUNC),
  1180. FLAG_END,
  1181. };
  1182. UNUSED static const struct flags statx_flags[] = {
  1183. #ifdef AT_EMPTY_PATH
  1184. FLAG_GENERIC(AT_EMPTY_PATH),
  1185. #endif
  1186. #ifdef AT_NO_AUTOMOUNT
  1187. FLAG_GENERIC(AT_NO_AUTOMOUNT),
  1188. #endif
  1189. #ifdef AT_SYMLINK_NOFOLLOW
  1190. FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
  1191. #endif
  1192. #ifdef AT_STATX_SYNC_AS_STAT
  1193. FLAG_GENERIC_MASK(AT_STATX_SYNC_AS_STAT, AT_STATX_SYNC_TYPE),
  1194. #endif
  1195. #ifdef AT_STATX_FORCE_SYNC
  1196. FLAG_GENERIC_MASK(AT_STATX_FORCE_SYNC, AT_STATX_SYNC_TYPE),
  1197. #endif
  1198. #ifdef AT_STATX_DONT_SYNC
  1199. FLAG_GENERIC_MASK(AT_STATX_DONT_SYNC, AT_STATX_SYNC_TYPE),
  1200. #endif
  1201. FLAG_END,
  1202. };
  1203. UNUSED static const struct flags statx_mask[] = {
  1204. /* This must come first, because it includes everything. */
  1205. #ifdef STATX_ALL
  1206. FLAG_GENERIC(STATX_ALL),
  1207. #endif
  1208. /* This must come second; it includes everything except STATX_BTIME. */
  1209. #ifdef STATX_BASIC_STATS
  1210. FLAG_GENERIC(STATX_BASIC_STATS),
  1211. #endif
  1212. #ifdef STATX_TYPE
  1213. FLAG_GENERIC(STATX_TYPE),
  1214. #endif
  1215. #ifdef STATX_MODE
  1216. FLAG_GENERIC(STATX_MODE),
  1217. #endif
  1218. #ifdef STATX_NLINK
  1219. FLAG_GENERIC(STATX_NLINK),
  1220. #endif
  1221. #ifdef STATX_UID
  1222. FLAG_GENERIC(STATX_UID),
  1223. #endif
  1224. #ifdef STATX_GID
  1225. FLAG_GENERIC(STATX_GID),
  1226. #endif
  1227. #ifdef STATX_ATIME
  1228. FLAG_GENERIC(STATX_ATIME),
  1229. #endif
  1230. #ifdef STATX_MTIME
  1231. FLAG_GENERIC(STATX_MTIME),
  1232. #endif
  1233. #ifdef STATX_CTIME
  1234. FLAG_GENERIC(STATX_CTIME),
  1235. #endif
  1236. #ifdef STATX_INO
  1237. FLAG_GENERIC(STATX_INO),
  1238. #endif
  1239. #ifdef STATX_SIZE
  1240. FLAG_GENERIC(STATX_SIZE),
  1241. #endif
  1242. #ifdef STATX_BLOCKS
  1243. FLAG_GENERIC(STATX_BLOCKS),
  1244. #endif
  1245. #ifdef STATX_BTIME
  1246. FLAG_GENERIC(STATX_BTIME),
  1247. #endif
  1248. FLAG_END,
  1249. };
  1250. UNUSED static const struct flags falloc_flags[] = {
  1251. FLAG_GENERIC(FALLOC_FL_KEEP_SIZE),
  1252. FLAG_GENERIC(FALLOC_FL_PUNCH_HOLE),
  1253. #ifdef FALLOC_FL_NO_HIDE_STALE
  1254. FLAG_GENERIC(FALLOC_FL_NO_HIDE_STALE),
  1255. #endif
  1256. #ifdef FALLOC_FL_COLLAPSE_RANGE
  1257. FLAG_GENERIC(FALLOC_FL_COLLAPSE_RANGE),
  1258. #endif
  1259. #ifdef FALLOC_FL_ZERO_RANGE
  1260. FLAG_GENERIC(FALLOC_FL_ZERO_RANGE),
  1261. #endif
  1262. #ifdef FALLOC_FL_INSERT_RANGE
  1263. FLAG_GENERIC(FALLOC_FL_INSERT_RANGE),
  1264. #endif
  1265. #ifdef FALLOC_FL_UNSHARE_RANGE
  1266. FLAG_GENERIC(FALLOC_FL_UNSHARE_RANGE),
  1267. #endif
  1268. };
  1269. UNUSED static const struct flags termios_iflags[] = {
  1270. FLAG_TARGET(IGNBRK),
  1271. FLAG_TARGET(BRKINT),
  1272. FLAG_TARGET(IGNPAR),
  1273. FLAG_TARGET(PARMRK),
  1274. FLAG_TARGET(INPCK),
  1275. FLAG_TARGET(ISTRIP),
  1276. FLAG_TARGET(INLCR),
  1277. FLAG_TARGET(IGNCR),
  1278. FLAG_TARGET(ICRNL),
  1279. FLAG_TARGET(IUCLC),
  1280. FLAG_TARGET(IXON),
  1281. FLAG_TARGET(IXANY),
  1282. FLAG_TARGET(IXOFF),
  1283. FLAG_TARGET(IMAXBEL),
  1284. FLAG_TARGET(IUTF8),
  1285. FLAG_END,
  1286. };
  1287. UNUSED static const struct flags termios_oflags[] = {
  1288. FLAG_TARGET(OPOST),
  1289. FLAG_TARGET(OLCUC),
  1290. FLAG_TARGET(ONLCR),
  1291. FLAG_TARGET(OCRNL),
  1292. FLAG_TARGET(ONOCR),
  1293. FLAG_TARGET(ONLRET),
  1294. FLAG_TARGET(OFILL),
  1295. FLAG_TARGET(OFDEL),
  1296. FLAG_END,
  1297. };
  1298. UNUSED static struct enums termios_oflags_NLDLY[] = {
  1299. ENUM_TARGET(NL0),
  1300. ENUM_TARGET(NL1),
  1301. ENUM_END,
  1302. };
  1303. UNUSED static struct enums termios_oflags_CRDLY[] = {
  1304. ENUM_TARGET(CR0),
  1305. ENUM_TARGET(CR1),
  1306. ENUM_TARGET(CR2),
  1307. ENUM_TARGET(CR3),
  1308. ENUM_END,
  1309. };
  1310. UNUSED static struct enums termios_oflags_TABDLY[] = {
  1311. ENUM_TARGET(TAB0),
  1312. ENUM_TARGET(TAB1),
  1313. ENUM_TARGET(TAB2),
  1314. ENUM_TARGET(TAB3),
  1315. ENUM_END,
  1316. };
  1317. UNUSED static struct enums termios_oflags_VTDLY[] = {
  1318. ENUM_TARGET(VT0),
  1319. ENUM_TARGET(VT1),
  1320. ENUM_END,
  1321. };
  1322. UNUSED static struct enums termios_oflags_FFDLY[] = {
  1323. ENUM_TARGET(FF0),
  1324. ENUM_TARGET(FF1),
  1325. ENUM_END,
  1326. };
  1327. UNUSED static struct enums termios_oflags_BSDLY[] = {
  1328. ENUM_TARGET(BS0),
  1329. ENUM_TARGET(BS1),
  1330. ENUM_END,
  1331. };
  1332. UNUSED static struct enums termios_cflags_CBAUD[] = {
  1333. ENUM_TARGET(B0),
  1334. ENUM_TARGET(B50),
  1335. ENUM_TARGET(B75),
  1336. ENUM_TARGET(B110),
  1337. ENUM_TARGET(B134),
  1338. ENUM_TARGET(B150),
  1339. ENUM_TARGET(B200),
  1340. ENUM_TARGET(B300),
  1341. ENUM_TARGET(B600),
  1342. ENUM_TARGET(B1200),
  1343. ENUM_TARGET(B1800),
  1344. ENUM_TARGET(B2400),
  1345. ENUM_TARGET(B4800),
  1346. ENUM_TARGET(B9600),
  1347. ENUM_TARGET(B19200),
  1348. ENUM_TARGET(B38400),
  1349. ENUM_TARGET(B57600),
  1350. ENUM_TARGET(B115200),
  1351. ENUM_TARGET(B230400),
  1352. ENUM_TARGET(B460800),
  1353. ENUM_END,
  1354. };
  1355. UNUSED static struct enums termios_cflags_CSIZE[] = {
  1356. ENUM_TARGET(CS5),
  1357. ENUM_TARGET(CS6),
  1358. ENUM_TARGET(CS7),
  1359. ENUM_TARGET(CS8),
  1360. ENUM_END,
  1361. };
  1362. UNUSED static const struct flags termios_cflags[] = {
  1363. FLAG_TARGET(CSTOPB),
  1364. FLAG_TARGET(CREAD),
  1365. FLAG_TARGET(PARENB),
  1366. FLAG_TARGET(PARODD),
  1367. FLAG_TARGET(HUPCL),
  1368. FLAG_TARGET(CLOCAL),
  1369. FLAG_TARGET(CRTSCTS),
  1370. FLAG_END,
  1371. };
  1372. UNUSED static const struct flags termios_lflags[] = {
  1373. FLAG_TARGET(ISIG),
  1374. FLAG_TARGET(ICANON),
  1375. FLAG_TARGET(XCASE),
  1376. FLAG_TARGET(ECHO),
  1377. FLAG_TARGET(ECHOE),
  1378. FLAG_TARGET(ECHOK),
  1379. FLAG_TARGET(ECHONL),
  1380. FLAG_TARGET(NOFLSH),
  1381. FLAG_TARGET(TOSTOP),
  1382. FLAG_TARGET(ECHOCTL),
  1383. FLAG_TARGET(ECHOPRT),
  1384. FLAG_TARGET(ECHOKE),
  1385. FLAG_TARGET(FLUSHO),
  1386. FLAG_TARGET(PENDIN),
  1387. FLAG_TARGET(IEXTEN),
  1388. FLAG_TARGET(EXTPROC),
  1389. FLAG_END,
  1390. };
  1391. #ifdef TARGET_NR_mlockall
  1392. static const struct flags mlockall_flags[] = {
  1393. FLAG_TARGET(MCL_CURRENT),
  1394. FLAG_TARGET(MCL_FUTURE),
  1395. #ifdef MCL_ONFAULT
  1396. FLAG_TARGET(MCL_ONFAULT),
  1397. #endif
  1398. FLAG_END,
  1399. };
  1400. #endif
  1401. /* IDs of the various system clocks */
  1402. #define TARGET_CLOCK_REALTIME 0
  1403. #define TARGET_CLOCK_MONOTONIC 1
  1404. #define TARGET_CLOCK_PROCESS_CPUTIME_ID 2
  1405. #define TARGET_CLOCK_THREAD_CPUTIME_ID 3
  1406. #define TARGET_CLOCK_MONOTONIC_RAW 4
  1407. #define TARGET_CLOCK_REALTIME_COARSE 5
  1408. #define TARGET_CLOCK_MONOTONIC_COARSE 6
  1409. #define TARGET_CLOCK_BOOTTIME 7
  1410. #define TARGET_CLOCK_REALTIME_ALARM 8
  1411. #define TARGET_CLOCK_BOOTTIME_ALARM 9
  1412. #define TARGET_CLOCK_SGI_CYCLE 10
  1413. #define TARGET_CLOCK_TAI 11
  1414. UNUSED static struct enums clockids[] = {
  1415. ENUM_TARGET(CLOCK_REALTIME),
  1416. ENUM_TARGET(CLOCK_MONOTONIC),
  1417. ENUM_TARGET(CLOCK_PROCESS_CPUTIME_ID),
  1418. ENUM_TARGET(CLOCK_THREAD_CPUTIME_ID),
  1419. ENUM_TARGET(CLOCK_MONOTONIC_RAW),
  1420. ENUM_TARGET(CLOCK_REALTIME_COARSE),
  1421. ENUM_TARGET(CLOCK_MONOTONIC_COARSE),
  1422. ENUM_TARGET(CLOCK_BOOTTIME),
  1423. ENUM_TARGET(CLOCK_REALTIME_ALARM),
  1424. ENUM_TARGET(CLOCK_BOOTTIME_ALARM),
  1425. ENUM_TARGET(CLOCK_SGI_CYCLE),
  1426. ENUM_TARGET(CLOCK_TAI),
  1427. ENUM_END,
  1428. };
  1429. UNUSED static struct enums itimer_types[] = {
  1430. ENUM_GENERIC(ITIMER_REAL),
  1431. ENUM_GENERIC(ITIMER_VIRTUAL),
  1432. ENUM_GENERIC(ITIMER_PROF),
  1433. ENUM_END,
  1434. };
  1435. /*
  1436. * print_xxx utility functions. These are used to print syscall
  1437. * parameters in certain format. All of these have parameter
  1438. * named 'last'. This parameter is used to add comma to output
  1439. * when last == 0.
  1440. */
  1441. static const char *
  1442. get_comma(int last)
  1443. {
  1444. return ((last) ? "" : ",");
  1445. }
  1446. static void
  1447. print_flags(const struct flags *f, abi_long flags, int last)
  1448. {
  1449. const char *sep = "";
  1450. int n;
  1451. for (n = 0; f->f_string != NULL; f++) {
  1452. if ((flags & f->f_mask) == f->f_value) {
  1453. qemu_log("%s%s", sep, f->f_string);
  1454. flags &= ~f->f_mask;
  1455. sep = "|";
  1456. n++;
  1457. }
  1458. }
  1459. if (n > 0) {
  1460. /* print rest of the flags as numeric */
  1461. if (flags != 0) {
  1462. qemu_log("%s%#x%s", sep, (unsigned int)flags, get_comma(last));
  1463. } else {
  1464. qemu_log("%s", get_comma(last));
  1465. }
  1466. } else {
  1467. /* no string version of flags found, print them in hex then */
  1468. qemu_log("%#x%s", (unsigned int)flags, get_comma(last));
  1469. }
  1470. }
  1471. static void
  1472. print_enums(const struct enums *e, abi_long enum_arg, int last)
  1473. {
  1474. for (; e->e_string != NULL; e++) {
  1475. if (e->e_value == enum_arg) {
  1476. qemu_log("%s", e->e_string);
  1477. break;
  1478. }
  1479. }
  1480. if (e->e_string == NULL) {
  1481. qemu_log("%#x", (unsigned int)enum_arg);
  1482. }
  1483. qemu_log("%s", get_comma(last));
  1484. }
  1485. static void
  1486. print_at_dirfd(abi_long dirfd, int last)
  1487. {
  1488. #ifdef AT_FDCWD
  1489. if (dirfd == AT_FDCWD) {
  1490. qemu_log("AT_FDCWD%s", get_comma(last));
  1491. return;
  1492. }
  1493. #endif
  1494. qemu_log("%d%s", (int)dirfd, get_comma(last));
  1495. }
  1496. static void
  1497. print_file_mode(abi_long mode, int last)
  1498. {
  1499. const char *sep = "";
  1500. const struct flags *m;
  1501. if (mode == 0) {
  1502. qemu_log("000%s", get_comma(last));
  1503. return;
  1504. }
  1505. for (m = &mode_flags[0]; m->f_string != NULL; m++) {
  1506. if ((m->f_value & mode) == m->f_value) {
  1507. qemu_log("%s%s", m->f_string, sep);
  1508. sep = "|";
  1509. mode &= ~m->f_value;
  1510. break;
  1511. }
  1512. }
  1513. mode &= ~S_IFMT;
  1514. /* print rest of the mode as octal */
  1515. if (mode != 0)
  1516. qemu_log("%s%#o", sep, (unsigned int)mode);
  1517. qemu_log("%s", get_comma(last));
  1518. }
  1519. static void
  1520. print_open_flags(abi_long flags, int last)
  1521. {
  1522. print_flags(open_access_flags, flags & TARGET_O_ACCMODE, 1);
  1523. flags &= ~TARGET_O_ACCMODE;
  1524. if (flags == 0) {
  1525. qemu_log("%s", get_comma(last));
  1526. return;
  1527. }
  1528. qemu_log("|");
  1529. print_flags(open_flags, flags, last);
  1530. }
  1531. static void
  1532. print_syscall_prologue(const struct syscallname *sc)
  1533. {
  1534. qemu_log("%s(", sc->name);
  1535. }
  1536. /*ARGSUSED*/
  1537. static void
  1538. print_syscall_epilogue(const struct syscallname *sc)
  1539. {
  1540. (void)sc;
  1541. qemu_log(")");
  1542. }
  1543. static void
  1544. print_string(abi_long addr, int last)
  1545. {
  1546. char *s;
  1547. if ((s = lock_user_string(addr)) != NULL) {
  1548. qemu_log("\"%s\"%s", s, get_comma(last));
  1549. unlock_user(s, addr, 0);
  1550. } else {
  1551. /* can't get string out of it, so print it as pointer */
  1552. print_pointer(addr, last);
  1553. }
  1554. }
  1555. #define MAX_PRINT_BUF 40
  1556. static void
  1557. print_buf(abi_long addr, abi_long len, int last)
  1558. {
  1559. uint8_t *s;
  1560. int i;
  1561. s = lock_user(VERIFY_READ, addr, len, 1);
  1562. if (s) {
  1563. qemu_log("\"");
  1564. for (i = 0; i < MAX_PRINT_BUF && i < len; i++) {
  1565. if (isprint(s[i])) {
  1566. qemu_log("%c", s[i]);
  1567. } else {
  1568. qemu_log("\\%o", s[i]);
  1569. }
  1570. }
  1571. qemu_log("\"");
  1572. if (i != len) {
  1573. qemu_log("...");
  1574. }
  1575. if (!last) {
  1576. qemu_log(",");
  1577. }
  1578. unlock_user(s, addr, 0);
  1579. } else {
  1580. print_pointer(addr, last);
  1581. }
  1582. }
  1583. static void
  1584. print_buf_len(abi_long addr, abi_long len, int last)
  1585. {
  1586. print_buf(addr, len, 0);
  1587. print_raw_param(TARGET_ABI_FMT_ld, len, last);
  1588. }
  1589. /*
  1590. * Prints out raw parameter using given format. Caller needs
  1591. * to do byte swapping if needed.
  1592. */
  1593. static void
  1594. print_raw_param(const char *fmt, abi_long param, int last)
  1595. {
  1596. char format[64];
  1597. (void) snprintf(format, sizeof (format), "%s%s", fmt, get_comma(last));
  1598. qemu_log(format, param);
  1599. }
  1600. /*
  1601. * Same as print_raw_param() but prints out raw 64-bit parameter.
  1602. */
  1603. static void
  1604. print_raw_param64(const char *fmt, long long param, int last)
  1605. {
  1606. char format[64];
  1607. (void)snprintf(format, sizeof(format), "%s%s", fmt, get_comma(last));
  1608. qemu_log(format, param);
  1609. }
  1610. static void
  1611. print_pointer(abi_long p, int last)
  1612. {
  1613. if (p == 0)
  1614. qemu_log("NULL%s", get_comma(last));
  1615. else
  1616. qemu_log("0x" TARGET_ABI_FMT_lx "%s", p, get_comma(last));
  1617. }
  1618. /*
  1619. * Reads 32-bit (int) number from guest address space from
  1620. * address 'addr' and prints it.
  1621. */
  1622. static void
  1623. print_number(abi_long addr, int last)
  1624. {
  1625. if (addr == 0) {
  1626. qemu_log("NULL%s", get_comma(last));
  1627. } else {
  1628. int num;
  1629. get_user_s32(num, addr);
  1630. qemu_log("[%d]%s", num, get_comma(last));
  1631. }
  1632. }
  1633. static void
  1634. print_timeval(abi_ulong tv_addr, int last)
  1635. {
  1636. if( tv_addr ) {
  1637. struct target_timeval *tv;
  1638. tv = lock_user(VERIFY_READ, tv_addr, sizeof(*tv), 1);
  1639. if (!tv) {
  1640. print_pointer(tv_addr, last);
  1641. return;
  1642. }
  1643. qemu_log("{tv_sec = " TARGET_ABI_FMT_ld
  1644. ",tv_usec = " TARGET_ABI_FMT_ld "}%s",
  1645. tswapal(tv->tv_sec), tswapal(tv->tv_usec), get_comma(last));
  1646. unlock_user(tv, tv_addr, 0);
  1647. } else
  1648. qemu_log("NULL%s", get_comma(last));
  1649. }
  1650. static void
  1651. print_timespec(abi_ulong ts_addr, int last)
  1652. {
  1653. if (ts_addr) {
  1654. struct target_timespec *ts;
  1655. ts = lock_user(VERIFY_READ, ts_addr, sizeof(*ts), 1);
  1656. if (!ts) {
  1657. print_pointer(ts_addr, last);
  1658. return;
  1659. }
  1660. qemu_log("{tv_sec = " TARGET_ABI_FMT_ld
  1661. ",tv_nsec = " TARGET_ABI_FMT_ld "}%s",
  1662. tswapal(ts->tv_sec), tswapal(ts->tv_nsec), get_comma(last));
  1663. unlock_user(ts, ts_addr, 0);
  1664. } else {
  1665. qemu_log("NULL%s", get_comma(last));
  1666. }
  1667. }
  1668. static void
  1669. print_timespec64(abi_ulong ts_addr, int last)
  1670. {
  1671. if (ts_addr) {
  1672. struct target__kernel_timespec *ts;
  1673. ts = lock_user(VERIFY_READ, ts_addr, sizeof(*ts), 1);
  1674. if (!ts) {
  1675. print_pointer(ts_addr, last);
  1676. return;
  1677. }
  1678. print_raw_param64("{tv_sec=%" PRId64, tswap64(ts->tv_sec), 0);
  1679. print_raw_param64("tv_nsec=%" PRId64 "}", tswap64(ts->tv_nsec), last);
  1680. unlock_user(ts, ts_addr, 0);
  1681. } else {
  1682. qemu_log("NULL%s", get_comma(last));
  1683. }
  1684. }
  1685. static void
  1686. print_timezone(abi_ulong tz_addr, int last)
  1687. {
  1688. if (tz_addr) {
  1689. struct target_timezone *tz;
  1690. tz = lock_user(VERIFY_READ, tz_addr, sizeof(*tz), 1);
  1691. if (!tz) {
  1692. print_pointer(tz_addr, last);
  1693. return;
  1694. }
  1695. qemu_log("{%d,%d}%s", tswap32(tz->tz_minuteswest),
  1696. tswap32(tz->tz_dsttime), get_comma(last));
  1697. unlock_user(tz, tz_addr, 0);
  1698. } else {
  1699. qemu_log("NULL%s", get_comma(last));
  1700. }
  1701. }
  1702. static void
  1703. print_itimerval(abi_ulong it_addr, int last)
  1704. {
  1705. if (it_addr) {
  1706. qemu_log("{it_interval=");
  1707. print_timeval(it_addr +
  1708. offsetof(struct target_itimerval, it_interval), 0);
  1709. qemu_log("it_value=");
  1710. print_timeval(it_addr +
  1711. offsetof(struct target_itimerval, it_value), 0);
  1712. qemu_log("}%s", get_comma(last));
  1713. } else {
  1714. qemu_log("NULL%s", get_comma(last));
  1715. }
  1716. }
  1717. void
  1718. print_termios(void *arg)
  1719. {
  1720. const struct target_termios *target = arg;
  1721. target_tcflag_t iflags = tswap32(target->c_iflag);
  1722. target_tcflag_t oflags = tswap32(target->c_oflag);
  1723. target_tcflag_t cflags = tswap32(target->c_cflag);
  1724. target_tcflag_t lflags = tswap32(target->c_lflag);
  1725. qemu_log("{");
  1726. qemu_log("c_iflag = ");
  1727. print_flags(termios_iflags, iflags, 0);
  1728. qemu_log("c_oflag = ");
  1729. target_tcflag_t oflags_clean = oflags & ~(TARGET_NLDLY | TARGET_CRDLY |
  1730. TARGET_TABDLY | TARGET_BSDLY |
  1731. TARGET_VTDLY | TARGET_FFDLY);
  1732. print_flags(termios_oflags, oflags_clean, 0);
  1733. if (oflags & TARGET_NLDLY) {
  1734. print_enums(termios_oflags_NLDLY, oflags & TARGET_NLDLY, 0);
  1735. }
  1736. if (oflags & TARGET_CRDLY) {
  1737. print_enums(termios_oflags_CRDLY, oflags & TARGET_CRDLY, 0);
  1738. }
  1739. if (oflags & TARGET_TABDLY) {
  1740. print_enums(termios_oflags_TABDLY, oflags & TARGET_TABDLY, 0);
  1741. }
  1742. if (oflags & TARGET_BSDLY) {
  1743. print_enums(termios_oflags_BSDLY, oflags & TARGET_BSDLY, 0);
  1744. }
  1745. if (oflags & TARGET_VTDLY) {
  1746. print_enums(termios_oflags_VTDLY, oflags & TARGET_VTDLY, 0);
  1747. }
  1748. if (oflags & TARGET_FFDLY) {
  1749. print_enums(termios_oflags_FFDLY, oflags & TARGET_FFDLY, 0);
  1750. }
  1751. qemu_log("c_cflag = ");
  1752. if (cflags & TARGET_CBAUD) {
  1753. print_enums(termios_cflags_CBAUD, cflags & TARGET_CBAUD, 0);
  1754. }
  1755. if (cflags & TARGET_CSIZE) {
  1756. print_enums(termios_cflags_CSIZE, cflags & TARGET_CSIZE, 0);
  1757. }
  1758. target_tcflag_t cflags_clean = cflags & ~(TARGET_CBAUD | TARGET_CSIZE);
  1759. print_flags(termios_cflags, cflags_clean, 0);
  1760. qemu_log("c_lflag = ");
  1761. print_flags(termios_lflags, lflags, 0);
  1762. qemu_log("c_cc = ");
  1763. qemu_log("\"%s\",", target->c_cc);
  1764. qemu_log("c_line = ");
  1765. print_raw_param("\'%c\'", target->c_line, 1);
  1766. qemu_log("}");
  1767. }
  1768. #undef UNUSED
  1769. #ifdef TARGET_NR_accept
  1770. static void
  1771. print_accept(CPUArchState *cpu_env, const struct syscallname *name,
  1772. abi_long arg0, abi_long arg1, abi_long arg2,
  1773. abi_long arg3, abi_long arg4, abi_long arg5)
  1774. {
  1775. print_syscall_prologue(name);
  1776. print_raw_param("%d", arg0, 0);
  1777. print_pointer(arg1, 0);
  1778. print_number(arg2, 1);
  1779. print_syscall_epilogue(name);
  1780. }
  1781. #endif
  1782. #ifdef TARGET_NR_access
  1783. static void
  1784. print_access(CPUArchState *cpu_env, const struct syscallname *name,
  1785. abi_long arg0, abi_long arg1, abi_long arg2,
  1786. abi_long arg3, abi_long arg4, abi_long arg5)
  1787. {
  1788. print_syscall_prologue(name);
  1789. print_string(arg0, 0);
  1790. print_flags(access_flags, arg1, 1);
  1791. print_syscall_epilogue(name);
  1792. }
  1793. #endif
  1794. #ifdef TARGET_NR_acct
  1795. static void
  1796. print_acct(CPUArchState *cpu_env, const struct syscallname *name,
  1797. abi_long arg0, abi_long arg1, abi_long arg2,
  1798. abi_long arg3, abi_long arg4, abi_long arg5)
  1799. {
  1800. print_syscall_prologue(name);
  1801. print_string(arg0, 1);
  1802. print_syscall_epilogue(name);
  1803. }
  1804. #endif
  1805. #ifdef TARGET_NR_brk
  1806. static void
  1807. print_brk(CPUArchState *cpu_env, const struct syscallname *name,
  1808. abi_long arg0, abi_long arg1, abi_long arg2,
  1809. abi_long arg3, abi_long arg4, abi_long arg5)
  1810. {
  1811. print_syscall_prologue(name);
  1812. print_pointer(arg0, 1);
  1813. print_syscall_epilogue(name);
  1814. }
  1815. #endif
  1816. #ifdef TARGET_NR_chdir
  1817. static void
  1818. print_chdir(CPUArchState *cpu_env, const struct syscallname *name,
  1819. abi_long arg0, abi_long arg1, abi_long arg2,
  1820. abi_long arg3, abi_long arg4, abi_long arg5)
  1821. {
  1822. print_syscall_prologue(name);
  1823. print_string(arg0, 1);
  1824. print_syscall_epilogue(name);
  1825. }
  1826. #endif
  1827. #ifdef TARGET_NR_chroot
  1828. static void
  1829. print_chroot(CPUArchState *cpu_env, const struct syscallname *name,
  1830. abi_long arg0, abi_long arg1, abi_long arg2,
  1831. abi_long arg3, abi_long arg4, abi_long arg5)
  1832. {
  1833. print_syscall_prologue(name);
  1834. print_string(arg0, 1);
  1835. print_syscall_epilogue(name);
  1836. }
  1837. #endif
  1838. #ifdef TARGET_NR_chmod
  1839. static void
  1840. print_chmod(CPUArchState *cpu_env, const struct syscallname *name,
  1841. abi_long arg0, abi_long arg1, abi_long arg2,
  1842. abi_long arg3, abi_long arg4, abi_long arg5)
  1843. {
  1844. print_syscall_prologue(name);
  1845. print_string(arg0, 0);
  1846. print_file_mode(arg1, 1);
  1847. print_syscall_epilogue(name);
  1848. }
  1849. #endif
  1850. #if defined(TARGET_NR_chown) || defined(TARGET_NR_lchown)
  1851. static void
  1852. print_chown(CPUArchState *cpu_env, const struct syscallname *name,
  1853. abi_long arg0, abi_long arg1, abi_long arg2,
  1854. abi_long arg3, abi_long arg4, abi_long arg5)
  1855. {
  1856. print_syscall_prologue(name);
  1857. print_string(arg0, 0);
  1858. print_raw_param("%d", arg1, 0);
  1859. print_raw_param("%d", arg2, 1);
  1860. print_syscall_epilogue(name);
  1861. }
  1862. #define print_lchown print_chown
  1863. #endif
  1864. #ifdef TARGET_NR_clock_adjtime
  1865. static void
  1866. print_clock_adjtime(CPUArchState *cpu_env, const struct syscallname *name,
  1867. abi_long arg0, abi_long arg1, abi_long arg2,
  1868. abi_long arg3, abi_long arg4, abi_long arg5)
  1869. {
  1870. print_syscall_prologue(name);
  1871. print_enums(clockids, arg0, 0);
  1872. print_pointer(arg1, 1);
  1873. print_syscall_epilogue(name);
  1874. }
  1875. #endif
  1876. #ifdef TARGET_NR_clone
  1877. static void do_print_clone(unsigned int flags, abi_ulong newsp,
  1878. abi_ulong parent_tidptr, target_ulong newtls,
  1879. abi_ulong child_tidptr)
  1880. {
  1881. print_flags(clone_flags, flags, 0);
  1882. print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, newsp, 0);
  1883. print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, parent_tidptr, 0);
  1884. print_raw_param("tls=0x" TARGET_ABI_FMT_lx, newtls, 0);
  1885. print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, child_tidptr, 1);
  1886. }
  1887. static void
  1888. print_clone(CPUArchState *cpu_env, const struct syscallname *name,
  1889. abi_long arg1, abi_long arg2, abi_long arg3,
  1890. abi_long arg4, abi_long arg5, abi_long arg6)
  1891. {
  1892. print_syscall_prologue(name);
  1893. #if defined(TARGET_MICROBLAZE)
  1894. do_print_clone(arg1, arg2, arg4, arg6, arg5);
  1895. #elif defined(TARGET_CLONE_BACKWARDS)
  1896. do_print_clone(arg1, arg2, arg3, arg4, arg5);
  1897. #elif defined(TARGET_CLONE_BACKWARDS2)
  1898. do_print_clone(arg2, arg1, arg3, arg5, arg4);
  1899. #else
  1900. do_print_clone(arg1, arg2, arg3, arg5, arg4);
  1901. #endif
  1902. print_syscall_epilogue(name);
  1903. }
  1904. #endif
  1905. #ifdef TARGET_NR_creat
  1906. static void
  1907. print_creat(CPUArchState *cpu_env, const struct syscallname *name,
  1908. abi_long arg0, abi_long arg1, abi_long arg2,
  1909. abi_long arg3, abi_long arg4, abi_long arg5)
  1910. {
  1911. print_syscall_prologue(name);
  1912. print_string(arg0, 0);
  1913. print_file_mode(arg1, 1);
  1914. print_syscall_epilogue(name);
  1915. }
  1916. #endif
  1917. #ifdef TARGET_NR_execv
  1918. static void
  1919. print_execv(CPUArchState *cpu_env, const struct syscallname *name,
  1920. abi_long arg0, abi_long arg1, abi_long arg2,
  1921. abi_long arg3, abi_long arg4, abi_long arg5)
  1922. {
  1923. print_syscall_prologue(name);
  1924. print_string(arg0, 0);
  1925. print_raw_param("0x" TARGET_ABI_FMT_lx, arg1, 1);
  1926. print_syscall_epilogue(name);
  1927. }
  1928. #endif
  1929. static void
  1930. print_execve_argv(abi_long argv, int last)
  1931. {
  1932. abi_ulong arg_ptr_addr;
  1933. char *s;
  1934. qemu_log("{");
  1935. for (arg_ptr_addr = argv; ; arg_ptr_addr += sizeof(abi_ulong)) {
  1936. abi_ulong *arg_ptr, arg_addr;
  1937. arg_ptr = lock_user(VERIFY_READ, arg_ptr_addr, sizeof(abi_ulong), 1);
  1938. if (!arg_ptr) {
  1939. return;
  1940. }
  1941. arg_addr = tswapal(*arg_ptr);
  1942. unlock_user(arg_ptr, arg_ptr_addr, 0);
  1943. if (!arg_addr) {
  1944. break;
  1945. }
  1946. s = lock_user_string(arg_addr);
  1947. if (s) {
  1948. qemu_log("\"%s\",", s);
  1949. unlock_user(s, arg_addr, 0);
  1950. }
  1951. }
  1952. qemu_log("NULL}%s", get_comma(last));
  1953. }
  1954. static void
  1955. print_execve(CPUArchState *cpu_env, const struct syscallname *name,
  1956. abi_long arg1, abi_long arg2, abi_long arg3,
  1957. abi_long arg4, abi_long arg5, abi_long arg6)
  1958. {
  1959. print_syscall_prologue(name);
  1960. print_string(arg1, 0);
  1961. print_execve_argv(arg2, 1);
  1962. print_syscall_epilogue(name);
  1963. }
  1964. static void
  1965. print_execveat(CPUArchState *cpu_env, const struct syscallname *name,
  1966. abi_long arg1, abi_long arg2, abi_long arg3,
  1967. abi_long arg4, abi_long arg5, abi_long arg6)
  1968. {
  1969. print_syscall_prologue(name);
  1970. print_at_dirfd(arg1, 0);
  1971. print_string(arg2, 0);
  1972. print_execve_argv(arg3, 0);
  1973. print_flags(execveat_flags, arg5, 1);
  1974. print_syscall_epilogue(name);
  1975. }
  1976. #if defined(TARGET_NR_faccessat) || defined(TARGET_NR_faccessat2)
  1977. static void
  1978. print_faccessat(CPUArchState *cpu_env, const struct syscallname *name,
  1979. abi_long arg0, abi_long arg1, abi_long arg2,
  1980. abi_long arg3, abi_long arg4, abi_long arg5)
  1981. {
  1982. print_syscall_prologue(name);
  1983. print_at_dirfd(arg0, 0);
  1984. print_string(arg1, 0);
  1985. print_flags(access_flags, arg2, 0);
  1986. print_flags(at_file_flags, arg3, 1);
  1987. print_syscall_epilogue(name);
  1988. }
  1989. #endif
  1990. #ifdef TARGET_NR_fallocate
  1991. static void
  1992. print_fallocate(CPUArchState *cpu_env, const struct syscallname *name,
  1993. abi_long arg0, abi_long arg1, abi_long arg2,
  1994. abi_long arg3, abi_long arg4, abi_long arg5)
  1995. {
  1996. print_syscall_prologue(name);
  1997. print_raw_param("%d", arg0, 0);
  1998. print_flags(falloc_flags, arg1, 0);
  1999. #if TARGET_ABI_BITS == 32
  2000. print_raw_param("%" PRIu64, target_offset64(arg2, arg3), 0);
  2001. print_raw_param("%" PRIu64, target_offset64(arg4, arg5), 1);
  2002. #else
  2003. print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
  2004. print_raw_param(TARGET_ABI_FMT_ld, arg3, 1);
  2005. #endif
  2006. print_syscall_epilogue(name);
  2007. }
  2008. #endif
  2009. #ifdef TARGET_NR_fchmodat
  2010. static void
  2011. print_fchmodat(CPUArchState *cpu_env, const struct syscallname *name,
  2012. abi_long arg0, abi_long arg1, abi_long arg2,
  2013. abi_long arg3, abi_long arg4, abi_long arg5)
  2014. {
  2015. print_syscall_prologue(name);
  2016. print_at_dirfd(arg0, 0);
  2017. print_string(arg1, 0);
  2018. print_file_mode(arg2, 0);
  2019. print_flags(at_file_flags, arg3, 1);
  2020. print_syscall_epilogue(name);
  2021. }
  2022. #endif
  2023. #ifdef TARGET_NR_fchownat
  2024. static void
  2025. print_fchownat(CPUArchState *cpu_env, const struct syscallname *name,
  2026. abi_long arg0, abi_long arg1, abi_long arg2,
  2027. abi_long arg3, abi_long arg4, abi_long arg5)
  2028. {
  2029. print_syscall_prologue(name);
  2030. print_at_dirfd(arg0, 0);
  2031. print_string(arg1, 0);
  2032. print_raw_param("%d", arg2, 0);
  2033. print_raw_param("%d", arg3, 0);
  2034. print_flags(at_file_flags, arg4, 1);
  2035. print_syscall_epilogue(name);
  2036. }
  2037. #endif
  2038. #if defined(TARGET_NR_fcntl) || defined(TARGET_NR_fcntl64)
  2039. static void
  2040. print_fcntl(CPUArchState *cpu_env, const struct syscallname *name,
  2041. abi_long arg0, abi_long arg1, abi_long arg2,
  2042. abi_long arg3, abi_long arg4, abi_long arg5)
  2043. {
  2044. print_syscall_prologue(name);
  2045. print_raw_param("%d", arg0, 0);
  2046. switch(arg1) {
  2047. case TARGET_F_DUPFD:
  2048. qemu_log("F_DUPFD,");
  2049. print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
  2050. break;
  2051. case TARGET_F_GETFD:
  2052. qemu_log("F_GETFD");
  2053. break;
  2054. case TARGET_F_SETFD:
  2055. qemu_log("F_SETFD,");
  2056. print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
  2057. break;
  2058. case TARGET_F_GETFL:
  2059. qemu_log("F_GETFL");
  2060. break;
  2061. case TARGET_F_SETFL:
  2062. qemu_log("F_SETFL,");
  2063. print_open_flags(arg2, 1);
  2064. break;
  2065. case TARGET_F_GETLK:
  2066. qemu_log("F_GETLK,");
  2067. print_pointer(arg2, 1);
  2068. break;
  2069. case TARGET_F_SETLK:
  2070. qemu_log("F_SETLK,");
  2071. print_pointer(arg2, 1);
  2072. break;
  2073. case TARGET_F_SETLKW:
  2074. qemu_log("F_SETLKW,");
  2075. print_pointer(arg2, 1);
  2076. break;
  2077. case TARGET_F_GETOWN:
  2078. qemu_log("F_GETOWN");
  2079. break;
  2080. case TARGET_F_SETOWN:
  2081. qemu_log("F_SETOWN,");
  2082. print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
  2083. break;
  2084. case TARGET_F_GETSIG:
  2085. qemu_log("F_GETSIG");
  2086. break;
  2087. case TARGET_F_SETSIG:
  2088. qemu_log("F_SETSIG,");
  2089. print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
  2090. break;
  2091. #if TARGET_ABI_BITS == 32
  2092. case TARGET_F_GETLK64:
  2093. qemu_log("F_GETLK64,");
  2094. print_pointer(arg2, 1);
  2095. break;
  2096. case TARGET_F_SETLK64:
  2097. qemu_log("F_SETLK64,");
  2098. print_pointer(arg2, 1);
  2099. break;
  2100. case TARGET_F_SETLKW64:
  2101. qemu_log("F_SETLKW64,");
  2102. print_pointer(arg2, 1);
  2103. break;
  2104. #endif
  2105. case TARGET_F_OFD_GETLK:
  2106. qemu_log("F_OFD_GETLK,");
  2107. print_pointer(arg2, 1);
  2108. break;
  2109. case TARGET_F_OFD_SETLK:
  2110. qemu_log("F_OFD_SETLK,");
  2111. print_pointer(arg2, 1);
  2112. break;
  2113. case TARGET_F_OFD_SETLKW:
  2114. qemu_log("F_OFD_SETLKW,");
  2115. print_pointer(arg2, 1);
  2116. break;
  2117. case TARGET_F_SETLEASE:
  2118. qemu_log("F_SETLEASE,");
  2119. print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
  2120. break;
  2121. case TARGET_F_GETLEASE:
  2122. qemu_log("F_GETLEASE");
  2123. break;
  2124. #ifdef F_DUPFD_CLOEXEC
  2125. case TARGET_F_DUPFD_CLOEXEC:
  2126. qemu_log("F_DUPFD_CLOEXEC,");
  2127. print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
  2128. break;
  2129. #endif
  2130. case TARGET_F_NOTIFY:
  2131. qemu_log("F_NOTIFY,");
  2132. print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
  2133. break;
  2134. #ifdef F_GETOWN_EX
  2135. case TARGET_F_GETOWN_EX:
  2136. qemu_log("F_GETOWN_EX,");
  2137. print_pointer(arg2, 1);
  2138. break;
  2139. #endif
  2140. #ifdef F_SETOWN_EX
  2141. case TARGET_F_SETOWN_EX:
  2142. qemu_log("F_SETOWN_EX,");
  2143. print_pointer(arg2, 1);
  2144. break;
  2145. #endif
  2146. #ifdef F_SETPIPE_SZ
  2147. case TARGET_F_SETPIPE_SZ:
  2148. qemu_log("F_SETPIPE_SZ,");
  2149. print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
  2150. break;
  2151. case TARGET_F_GETPIPE_SZ:
  2152. qemu_log("F_GETPIPE_SZ");
  2153. break;
  2154. #endif
  2155. #ifdef F_ADD_SEALS
  2156. case TARGET_F_ADD_SEALS:
  2157. qemu_log("F_ADD_SEALS,");
  2158. print_raw_param("0x"TARGET_ABI_FMT_lx, arg2, 1);
  2159. break;
  2160. case TARGET_F_GET_SEALS:
  2161. qemu_log("F_GET_SEALS");
  2162. break;
  2163. #endif
  2164. default:
  2165. print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
  2166. print_pointer(arg2, 1);
  2167. break;
  2168. }
  2169. print_syscall_epilogue(name);
  2170. }
  2171. #define print_fcntl64 print_fcntl
  2172. #endif
  2173. #ifdef TARGET_NR_fgetxattr
  2174. static void
  2175. print_fgetxattr(CPUArchState *cpu_env, const struct syscallname *name,
  2176. abi_long arg0, abi_long arg1, abi_long arg2,
  2177. abi_long arg3, abi_long arg4, abi_long arg5)
  2178. {
  2179. print_syscall_prologue(name);
  2180. print_raw_param("%d", arg0, 0);
  2181. print_string(arg1, 0);
  2182. print_pointer(arg2, 0);
  2183. print_raw_param(TARGET_FMT_lu, arg3, 1);
  2184. print_syscall_epilogue(name);
  2185. }
  2186. #endif
  2187. #ifdef TARGET_NR_flistxattr
  2188. static void
  2189. print_flistxattr(CPUArchState *cpu_env, const struct syscallname *name,
  2190. abi_long arg0, abi_long arg1, abi_long arg2,
  2191. abi_long arg3, abi_long arg4, abi_long arg5)
  2192. {
  2193. print_syscall_prologue(name);
  2194. print_raw_param("%d", arg0, 0);
  2195. print_pointer(arg1, 0);
  2196. print_raw_param(TARGET_FMT_lu, arg2, 1);
  2197. print_syscall_epilogue(name);
  2198. }
  2199. #endif
  2200. #if defined(TARGET_NR_getxattr) || defined(TARGET_NR_lgetxattr)
  2201. static void
  2202. print_getxattr(CPUArchState *cpu_env, const struct syscallname *name,
  2203. abi_long arg0, abi_long arg1, abi_long arg2,
  2204. abi_long arg3, abi_long arg4, abi_long arg5)
  2205. {
  2206. print_syscall_prologue(name);
  2207. print_string(arg0, 0);
  2208. print_string(arg1, 0);
  2209. print_pointer(arg2, 0);
  2210. print_raw_param(TARGET_FMT_lu, arg3, 1);
  2211. print_syscall_epilogue(name);
  2212. }
  2213. #define print_lgetxattr print_getxattr
  2214. #endif
  2215. #if defined(TARGET_NR_listxattr) || defined(TARGET_NR_llistxattr)
  2216. static void
  2217. print_listxattr(CPUArchState *cpu_env, const struct syscallname *name,
  2218. abi_long arg0, abi_long arg1, abi_long arg2,
  2219. abi_long arg3, abi_long arg4, abi_long arg5)
  2220. {
  2221. print_syscall_prologue(name);
  2222. print_string(arg0, 0);
  2223. print_pointer(arg1, 0);
  2224. print_raw_param(TARGET_FMT_lu, arg2, 1);
  2225. print_syscall_epilogue(name);
  2226. }
  2227. #define print_llistxattr print_listxattr
  2228. #endif
  2229. #if defined(TARGET_NR_fremovexattr)
  2230. static void
  2231. print_fremovexattr(CPUArchState *cpu_env, const struct syscallname *name,
  2232. abi_long arg0, abi_long arg1, abi_long arg2,
  2233. abi_long arg3, abi_long arg4, abi_long arg5)
  2234. {
  2235. print_syscall_prologue(name);
  2236. print_raw_param("%d", arg0, 0);
  2237. print_string(arg1, 1);
  2238. print_syscall_epilogue(name);
  2239. }
  2240. #endif
  2241. #if defined(TARGET_NR_removexattr) || defined(TARGET_NR_lremovexattr)
  2242. static void
  2243. print_removexattr(CPUArchState *cpu_env, const struct syscallname *name,
  2244. abi_long arg0, abi_long arg1, abi_long arg2,
  2245. abi_long arg3, abi_long arg4, abi_long arg5)
  2246. {
  2247. print_syscall_prologue(name);
  2248. print_string(arg0, 0);
  2249. print_string(arg1, 1);
  2250. print_syscall_epilogue(name);
  2251. }
  2252. #define print_lremovexattr print_removexattr
  2253. #endif
  2254. #ifdef TARGET_NR_futimesat
  2255. static void
  2256. print_futimesat(CPUArchState *cpu_env, const struct syscallname *name,
  2257. abi_long arg0, abi_long arg1, abi_long arg2,
  2258. abi_long arg3, abi_long arg4, abi_long arg5)
  2259. {
  2260. print_syscall_prologue(name);
  2261. print_at_dirfd(arg0, 0);
  2262. print_string(arg1, 0);
  2263. print_timeval(arg2, 0);
  2264. print_timeval(arg2 + sizeof (struct target_timeval), 1);
  2265. print_syscall_epilogue(name);
  2266. }
  2267. #endif
  2268. #ifdef TARGET_NR_gettimeofday
  2269. static void
  2270. print_gettimeofday(CPUArchState *cpu_env, const struct syscallname *name,
  2271. abi_long arg0, abi_long arg1, abi_long arg2,
  2272. abi_long arg3, abi_long arg4, abi_long arg5)
  2273. {
  2274. print_syscall_prologue(name);
  2275. print_pointer(arg0, 0);
  2276. print_pointer(arg1, 1);
  2277. print_syscall_epilogue(name);
  2278. }
  2279. #endif
  2280. #ifdef TARGET_NR_settimeofday
  2281. static void
  2282. print_settimeofday(CPUArchState *cpu_env, const struct syscallname *name,
  2283. abi_long arg0, abi_long arg1, abi_long arg2,
  2284. abi_long arg3, abi_long arg4, abi_long arg5)
  2285. {
  2286. print_syscall_prologue(name);
  2287. print_timeval(arg0, 0);
  2288. print_timezone(arg1, 1);
  2289. print_syscall_epilogue(name);
  2290. }
  2291. #endif
  2292. #if defined(TARGET_NR_clock_gettime) || defined(TARGET_NR_clock_getres)
  2293. static void
  2294. print_clock_gettime(CPUArchState *cpu_env, const struct syscallname *name,
  2295. abi_long arg0, abi_long arg1, abi_long arg2,
  2296. abi_long arg3, abi_long arg4, abi_long arg5)
  2297. {
  2298. print_syscall_prologue(name);
  2299. print_enums(clockids, arg0, 0);
  2300. print_pointer(arg1, 1);
  2301. print_syscall_epilogue(name);
  2302. }
  2303. #define print_clock_getres print_clock_gettime
  2304. #endif
  2305. #if defined(TARGET_NR_clock_gettime64)
  2306. static void
  2307. print_clock_gettime64(CPUArchState *cpu_env, const struct syscallname *name,
  2308. abi_long arg0, abi_long arg1, abi_long arg2,
  2309. abi_long arg3, abi_long arg4, abi_long arg5)
  2310. {
  2311. print_syscall_prologue(name);
  2312. print_enums(clockids, arg0, 0);
  2313. print_pointer(arg1, 1);
  2314. print_syscall_epilogue(name);
  2315. }
  2316. #endif
  2317. #ifdef TARGET_NR_clock_settime
  2318. static void
  2319. print_clock_settime(CPUArchState *cpu_env, const struct syscallname *name,
  2320. abi_long arg0, abi_long arg1, abi_long arg2,
  2321. abi_long arg3, abi_long arg4, abi_long arg5)
  2322. {
  2323. print_syscall_prologue(name);
  2324. print_enums(clockids, arg0, 0);
  2325. print_timespec(arg1, 1);
  2326. print_syscall_epilogue(name);
  2327. }
  2328. #endif
  2329. #ifdef TARGET_NR_getitimer
  2330. static void
  2331. print_getitimer(CPUArchState *cpu_env, const struct syscallname *name,
  2332. abi_long arg0, abi_long arg1, abi_long arg2,
  2333. abi_long arg3, abi_long arg4, abi_long arg5)
  2334. {
  2335. print_syscall_prologue(name);
  2336. print_enums(itimer_types, arg0, 0);
  2337. print_pointer(arg1, 1);
  2338. print_syscall_epilogue(name);
  2339. }
  2340. #endif
  2341. #ifdef TARGET_NR_setitimer
  2342. static void
  2343. print_setitimer(CPUArchState *cpu_env, const struct syscallname *name,
  2344. abi_long arg0, abi_long arg1, abi_long arg2,
  2345. abi_long arg3, abi_long arg4, abi_long arg5)
  2346. {
  2347. print_syscall_prologue(name);
  2348. print_enums(itimer_types, arg0, 0);
  2349. print_itimerval(arg1, 0);
  2350. print_pointer(arg2, 1);
  2351. print_syscall_epilogue(name);
  2352. }
  2353. #endif
  2354. #ifdef TARGET_NR_link
  2355. static void
  2356. print_link(CPUArchState *cpu_env, const struct syscallname *name,
  2357. abi_long arg0, abi_long arg1, abi_long arg2,
  2358. abi_long arg3, abi_long arg4, abi_long arg5)
  2359. {
  2360. print_syscall_prologue(name);
  2361. print_string(arg0, 0);
  2362. print_string(arg1, 1);
  2363. print_syscall_epilogue(name);
  2364. }
  2365. #endif
  2366. #ifdef TARGET_NR_linkat
  2367. static void
  2368. print_linkat(CPUArchState *cpu_env, const struct syscallname *name,
  2369. abi_long arg0, abi_long arg1, abi_long arg2,
  2370. abi_long arg3, abi_long arg4, abi_long arg5)
  2371. {
  2372. print_syscall_prologue(name);
  2373. print_at_dirfd(arg0, 0);
  2374. print_string(arg1, 0);
  2375. print_at_dirfd(arg2, 0);
  2376. print_string(arg3, 0);
  2377. print_flags(at_file_flags, arg4, 1);
  2378. print_syscall_epilogue(name);
  2379. }
  2380. #endif
  2381. #if defined(TARGET_NR__llseek) || defined(TARGET_NR_llseek)
  2382. static void
  2383. print__llseek(CPUArchState *cpu_env, const struct syscallname *name,
  2384. abi_long arg0, abi_long arg1, abi_long arg2,
  2385. abi_long arg3, abi_long arg4, abi_long arg5)
  2386. {
  2387. const char *whence = "UNKNOWN";
  2388. print_syscall_prologue(name);
  2389. print_raw_param("%d", arg0, 0);
  2390. print_raw_param("%ld", arg1, 0);
  2391. print_raw_param("%ld", arg2, 0);
  2392. print_pointer(arg3, 0);
  2393. switch(arg4) {
  2394. case SEEK_SET: whence = "SEEK_SET"; break;
  2395. case SEEK_CUR: whence = "SEEK_CUR"; break;
  2396. case SEEK_END: whence = "SEEK_END"; break;
  2397. }
  2398. qemu_log("%s", whence);
  2399. print_syscall_epilogue(name);
  2400. }
  2401. #define print_llseek print__llseek
  2402. #endif
  2403. #ifdef TARGET_NR_lseek
  2404. static void
  2405. print_lseek(CPUArchState *cpu_env, const struct syscallname *name,
  2406. abi_long arg0, abi_long arg1, abi_long arg2,
  2407. abi_long arg3, abi_long arg4, abi_long arg5)
  2408. {
  2409. print_syscall_prologue(name);
  2410. print_raw_param("%d", arg0, 0);
  2411. print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
  2412. switch (arg2) {
  2413. case SEEK_SET:
  2414. qemu_log("SEEK_SET"); break;
  2415. case SEEK_CUR:
  2416. qemu_log("SEEK_CUR"); break;
  2417. case SEEK_END:
  2418. qemu_log("SEEK_END"); break;
  2419. #ifdef SEEK_DATA
  2420. case SEEK_DATA:
  2421. qemu_log("SEEK_DATA"); break;
  2422. #endif
  2423. #ifdef SEEK_HOLE
  2424. case SEEK_HOLE:
  2425. qemu_log("SEEK_HOLE"); break;
  2426. #endif
  2427. default:
  2428. print_raw_param("%#x", arg2, 1);
  2429. }
  2430. print_syscall_epilogue(name);
  2431. }
  2432. #endif
  2433. #ifdef TARGET_NR_truncate
  2434. static void
  2435. print_truncate(CPUArchState *cpu_env, const struct syscallname *name,
  2436. abi_long arg0, abi_long arg1, abi_long arg2,
  2437. abi_long arg3, abi_long arg4, abi_long arg5)
  2438. {
  2439. print_syscall_prologue(name);
  2440. print_string(arg0, 0);
  2441. print_raw_param(TARGET_ABI_FMT_ld, arg1, 1);
  2442. print_syscall_epilogue(name);
  2443. }
  2444. #endif
  2445. #ifdef TARGET_NR_truncate64
  2446. static void
  2447. print_truncate64(CPUArchState *cpu_env, const struct syscallname *name,
  2448. abi_long arg0, abi_long arg1, abi_long arg2,
  2449. abi_long arg3, abi_long arg4, abi_long arg5)
  2450. {
  2451. print_syscall_prologue(name);
  2452. print_string(arg0, 0);
  2453. if (regpairs_aligned(cpu_env, TARGET_NR_truncate64)) {
  2454. arg1 = arg2;
  2455. arg2 = arg3;
  2456. }
  2457. print_raw_param("%" PRIu64, target_offset64(arg1, arg2), 1);
  2458. print_syscall_epilogue(name);
  2459. }
  2460. #endif
  2461. #ifdef TARGET_NR_ftruncate64
  2462. static void
  2463. print_ftruncate64(CPUArchState *cpu_env, const struct syscallname *name,
  2464. abi_long arg0, abi_long arg1, abi_long arg2,
  2465. abi_long arg3, abi_long arg4, abi_long arg5)
  2466. {
  2467. print_syscall_prologue(name);
  2468. print_raw_param("%d", arg0, 0);
  2469. if (regpairs_aligned(cpu_env, TARGET_NR_ftruncate64)) {
  2470. arg1 = arg2;
  2471. arg2 = arg3;
  2472. }
  2473. print_raw_param("%" PRIu64, target_offset64(arg1, arg2), 1);
  2474. print_syscall_epilogue(name);
  2475. }
  2476. #endif
  2477. #ifdef TARGET_NR_mlockall
  2478. static void
  2479. print_mlockall(CPUArchState *cpu_env, const struct syscallname *name,
  2480. abi_long arg0, abi_long arg1, abi_long arg2,
  2481. abi_long arg3, abi_long arg4, abi_long arg5)
  2482. {
  2483. print_syscall_prologue(name);
  2484. print_flags(mlockall_flags, arg0, 1);
  2485. print_syscall_epilogue(name);
  2486. }
  2487. #endif
  2488. #if defined(TARGET_NR_socket)
  2489. static void
  2490. print_socket(CPUArchState *cpu_env, const struct syscallname *name,
  2491. abi_long arg0, abi_long arg1, abi_long arg2,
  2492. abi_long arg3, abi_long arg4, abi_long arg5)
  2493. {
  2494. abi_ulong domain = arg0, type = arg1, protocol = arg2;
  2495. print_syscall_prologue(name);
  2496. print_socket_domain(domain);
  2497. qemu_log(",");
  2498. print_socket_type(type);
  2499. qemu_log(",");
  2500. if (domain == AF_PACKET ||
  2501. (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
  2502. protocol = tswap16(protocol);
  2503. }
  2504. print_socket_protocol(domain, type, protocol);
  2505. print_syscall_epilogue(name);
  2506. }
  2507. #endif
  2508. #if defined(TARGET_NR_socketcall) || defined(TARGET_NR_bind)
  2509. static void print_sockfd(abi_long sockfd, int last)
  2510. {
  2511. print_raw_param(TARGET_ABI_FMT_ld, sockfd, last);
  2512. }
  2513. #endif
  2514. #if defined(TARGET_NR_socketcall)
  2515. #define get_user_ualx(x, gaddr, idx) \
  2516. get_user_ual(x, (gaddr) + (idx) * sizeof(abi_long))
  2517. static void do_print_socket(const char *name, abi_long arg1)
  2518. {
  2519. abi_ulong domain, type, protocol;
  2520. get_user_ualx(domain, arg1, 0);
  2521. get_user_ualx(type, arg1, 1);
  2522. get_user_ualx(protocol, arg1, 2);
  2523. qemu_log("%s(", name);
  2524. print_socket_domain(domain);
  2525. qemu_log(",");
  2526. print_socket_type(type);
  2527. qemu_log(",");
  2528. if (domain == AF_PACKET ||
  2529. (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
  2530. protocol = tswap16(protocol);
  2531. }
  2532. print_socket_protocol(domain, type, protocol);
  2533. qemu_log(")");
  2534. }
  2535. static void do_print_sockaddr(const char *name, abi_long arg1)
  2536. {
  2537. abi_ulong sockfd, addr, addrlen;
  2538. get_user_ualx(sockfd, arg1, 0);
  2539. get_user_ualx(addr, arg1, 1);
  2540. get_user_ualx(addrlen, arg1, 2);
  2541. qemu_log("%s(", name);
  2542. print_sockfd(sockfd, 0);
  2543. print_sockaddr(addr, addrlen, 0);
  2544. qemu_log(")");
  2545. }
  2546. static void do_print_listen(const char *name, abi_long arg1)
  2547. {
  2548. abi_ulong sockfd, backlog;
  2549. get_user_ualx(sockfd, arg1, 0);
  2550. get_user_ualx(backlog, arg1, 1);
  2551. qemu_log("%s(", name);
  2552. print_sockfd(sockfd, 0);
  2553. print_raw_param(TARGET_ABI_FMT_ld, backlog, 1);
  2554. qemu_log(")");
  2555. }
  2556. static void do_print_socketpair(const char *name, abi_long arg1)
  2557. {
  2558. abi_ulong domain, type, protocol, tab;
  2559. get_user_ualx(domain, arg1, 0);
  2560. get_user_ualx(type, arg1, 1);
  2561. get_user_ualx(protocol, arg1, 2);
  2562. get_user_ualx(tab, arg1, 3);
  2563. qemu_log("%s(", name);
  2564. print_socket_domain(domain);
  2565. qemu_log(",");
  2566. print_socket_type(type);
  2567. qemu_log(",");
  2568. print_socket_protocol(domain, type, protocol);
  2569. qemu_log(",");
  2570. print_raw_param(TARGET_ABI_FMT_lx, tab, 1);
  2571. qemu_log(")");
  2572. }
  2573. static void do_print_sendrecv(const char *name, abi_long arg1)
  2574. {
  2575. abi_ulong sockfd, msg, len, flags;
  2576. get_user_ualx(sockfd, arg1, 0);
  2577. get_user_ualx(msg, arg1, 1);
  2578. get_user_ualx(len, arg1, 2);
  2579. get_user_ualx(flags, arg1, 3);
  2580. qemu_log("%s(", name);
  2581. print_sockfd(sockfd, 0);
  2582. print_buf_len(msg, len, 0);
  2583. print_flags(msg_flags, flags, 1);
  2584. qemu_log(")");
  2585. }
  2586. static void do_print_msgaddr(const char *name, abi_long arg1)
  2587. {
  2588. abi_ulong sockfd, msg, len, flags, addr, addrlen;
  2589. get_user_ualx(sockfd, arg1, 0);
  2590. get_user_ualx(msg, arg1, 1);
  2591. get_user_ualx(len, arg1, 2);
  2592. get_user_ualx(flags, arg1, 3);
  2593. get_user_ualx(addr, arg1, 4);
  2594. get_user_ualx(addrlen, arg1, 5);
  2595. qemu_log("%s(", name);
  2596. print_sockfd(sockfd, 0);
  2597. print_buf_len(msg, len, 0);
  2598. print_flags(msg_flags, flags, 0);
  2599. print_sockaddr(addr, addrlen, 0);
  2600. qemu_log(")");
  2601. }
  2602. static void do_print_shutdown(const char *name, abi_long arg1)
  2603. {
  2604. abi_ulong sockfd, how;
  2605. get_user_ualx(sockfd, arg1, 0);
  2606. get_user_ualx(how, arg1, 1);
  2607. qemu_log("shutdown(");
  2608. print_sockfd(sockfd, 0);
  2609. switch (how) {
  2610. case SHUT_RD:
  2611. qemu_log("SHUT_RD");
  2612. break;
  2613. case SHUT_WR:
  2614. qemu_log("SHUT_WR");
  2615. break;
  2616. case SHUT_RDWR:
  2617. qemu_log("SHUT_RDWR");
  2618. break;
  2619. default:
  2620. print_raw_param(TARGET_ABI_FMT_ld, how, 1);
  2621. break;
  2622. }
  2623. qemu_log(")");
  2624. }
  2625. static void do_print_msg(const char *name, abi_long arg1)
  2626. {
  2627. abi_ulong sockfd, msg, flags;
  2628. get_user_ualx(sockfd, arg1, 0);
  2629. get_user_ualx(msg, arg1, 1);
  2630. get_user_ualx(flags, arg1, 2);
  2631. qemu_log("%s(", name);
  2632. print_sockfd(sockfd, 0);
  2633. print_pointer(msg, 0);
  2634. print_flags(msg_flags, flags, 1);
  2635. qemu_log(")");
  2636. }
  2637. static void do_print_sockopt(const char *name, abi_long arg1)
  2638. {
  2639. abi_ulong sockfd, level, optname, optval, optlen;
  2640. get_user_ualx(sockfd, arg1, 0);
  2641. get_user_ualx(level, arg1, 1);
  2642. get_user_ualx(optname, arg1, 2);
  2643. get_user_ualx(optval, arg1, 3);
  2644. get_user_ualx(optlen, arg1, 4);
  2645. qemu_log("%s(", name);
  2646. print_sockfd(sockfd, 0);
  2647. switch (level) {
  2648. case SOL_TCP:
  2649. qemu_log("SOL_TCP,");
  2650. print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
  2651. print_pointer(optval, 0);
  2652. break;
  2653. case SOL_UDP:
  2654. qemu_log("SOL_UDP,");
  2655. print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
  2656. print_pointer(optval, 0);
  2657. break;
  2658. case SOL_IP:
  2659. qemu_log("SOL_IP,");
  2660. print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
  2661. print_pointer(optval, 0);
  2662. break;
  2663. case SOL_RAW:
  2664. qemu_log("SOL_RAW,");
  2665. print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
  2666. print_pointer(optval, 0);
  2667. break;
  2668. case TARGET_SOL_SOCKET:
  2669. qemu_log("SOL_SOCKET,");
  2670. switch (optname) {
  2671. case TARGET_SO_DEBUG:
  2672. qemu_log("SO_DEBUG,");
  2673. print_optint:
  2674. print_number(optval, 0);
  2675. break;
  2676. case TARGET_SO_REUSEADDR:
  2677. qemu_log("SO_REUSEADDR,");
  2678. goto print_optint;
  2679. case TARGET_SO_REUSEPORT:
  2680. qemu_log("SO_REUSEPORT,");
  2681. goto print_optint;
  2682. case TARGET_SO_TYPE:
  2683. qemu_log("SO_TYPE,");
  2684. goto print_optint;
  2685. case TARGET_SO_ERROR:
  2686. qemu_log("SO_ERROR,");
  2687. goto print_optint;
  2688. case TARGET_SO_DONTROUTE:
  2689. qemu_log("SO_DONTROUTE,");
  2690. goto print_optint;
  2691. case TARGET_SO_BROADCAST:
  2692. qemu_log("SO_BROADCAST,");
  2693. goto print_optint;
  2694. case TARGET_SO_SNDBUF:
  2695. qemu_log("SO_SNDBUF,");
  2696. goto print_optint;
  2697. case TARGET_SO_RCVBUF:
  2698. qemu_log("SO_RCVBUF,");
  2699. goto print_optint;
  2700. case TARGET_SO_KEEPALIVE:
  2701. qemu_log("SO_KEEPALIVE,");
  2702. goto print_optint;
  2703. case TARGET_SO_OOBINLINE:
  2704. qemu_log("SO_OOBINLINE,");
  2705. goto print_optint;
  2706. case TARGET_SO_NO_CHECK:
  2707. qemu_log("SO_NO_CHECK,");
  2708. goto print_optint;
  2709. case TARGET_SO_PRIORITY:
  2710. qemu_log("SO_PRIORITY,");
  2711. goto print_optint;
  2712. case TARGET_SO_BSDCOMPAT:
  2713. qemu_log("SO_BSDCOMPAT,");
  2714. goto print_optint;
  2715. case TARGET_SO_PASSCRED:
  2716. qemu_log("SO_PASSCRED,");
  2717. goto print_optint;
  2718. case TARGET_SO_TIMESTAMP:
  2719. qemu_log("SO_TIMESTAMP,");
  2720. goto print_optint;
  2721. case TARGET_SO_RCVLOWAT:
  2722. qemu_log("SO_RCVLOWAT,");
  2723. goto print_optint;
  2724. case TARGET_SO_RCVTIMEO:
  2725. qemu_log("SO_RCVTIMEO,");
  2726. print_timeval(optval, 0);
  2727. break;
  2728. case TARGET_SO_SNDTIMEO:
  2729. qemu_log("SO_SNDTIMEO,");
  2730. print_timeval(optval, 0);
  2731. break;
  2732. case TARGET_SO_ATTACH_FILTER: {
  2733. struct target_sock_fprog *fprog;
  2734. qemu_log("SO_ATTACH_FILTER,");
  2735. if (lock_user_struct(VERIFY_READ, fprog, optval, 0)) {
  2736. struct target_sock_filter *filter;
  2737. qemu_log("{");
  2738. if (lock_user_struct(VERIFY_READ, filter,
  2739. tswapal(fprog->filter), 0)) {
  2740. int i;
  2741. for (i = 0; i < tswap16(fprog->len) - 1; i++) {
  2742. qemu_log("[%d]{0x%x,%d,%d,0x%x},",
  2743. i, tswap16(filter[i].code),
  2744. filter[i].jt, filter[i].jf,
  2745. tswap32(filter[i].k));
  2746. }
  2747. qemu_log("[%d]{0x%x,%d,%d,0x%x}",
  2748. i, tswap16(filter[i].code),
  2749. filter[i].jt, filter[i].jf,
  2750. tswap32(filter[i].k));
  2751. } else {
  2752. qemu_log(TARGET_ABI_FMT_lx, tswapal(fprog->filter));
  2753. }
  2754. qemu_log(",%d},", tswap16(fprog->len));
  2755. unlock_user(fprog, optval, 0);
  2756. } else {
  2757. print_pointer(optval, 0);
  2758. }
  2759. break;
  2760. }
  2761. default:
  2762. print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
  2763. print_pointer(optval, 0);
  2764. break;
  2765. }
  2766. break;
  2767. case SOL_IPV6:
  2768. qemu_log("SOL_IPV6,");
  2769. switch (optname) {
  2770. case IPV6_MTU_DISCOVER:
  2771. qemu_log("IPV6_MTU_DISCOVER,");
  2772. goto print_optint;
  2773. case IPV6_MTU:
  2774. qemu_log("IPV6_MTU,");
  2775. goto print_optint;
  2776. case IPV6_V6ONLY:
  2777. qemu_log("IPV6_V6ONLY,");
  2778. goto print_optint;
  2779. case IPV6_RECVPKTINFO:
  2780. qemu_log("IPV6_RECVPKTINFO,");
  2781. goto print_optint;
  2782. case IPV6_UNICAST_HOPS:
  2783. qemu_log("IPV6_UNICAST_HOPS,");
  2784. goto print_optint;
  2785. case IPV6_MULTICAST_HOPS:
  2786. qemu_log("IPV6_MULTICAST_HOPS,");
  2787. goto print_optint;
  2788. case IPV6_MULTICAST_LOOP:
  2789. qemu_log("IPV6_MULTICAST_LOOP,");
  2790. goto print_optint;
  2791. case IPV6_RECVERR:
  2792. qemu_log("IPV6_RECVERR,");
  2793. goto print_optint;
  2794. case IPV6_RECVHOPLIMIT:
  2795. qemu_log("IPV6_RECVHOPLIMIT,");
  2796. goto print_optint;
  2797. case IPV6_2292HOPLIMIT:
  2798. qemu_log("IPV6_2292HOPLIMIT,");
  2799. goto print_optint;
  2800. case IPV6_CHECKSUM:
  2801. qemu_log("IPV6_CHECKSUM,");
  2802. goto print_optint;
  2803. case IPV6_ADDRFORM:
  2804. qemu_log("IPV6_ADDRFORM,");
  2805. goto print_optint;
  2806. case IPV6_2292PKTINFO:
  2807. qemu_log("IPV6_2292PKTINFO,");
  2808. goto print_optint;
  2809. case IPV6_RECVTCLASS:
  2810. qemu_log("IPV6_RECVTCLASS,");
  2811. goto print_optint;
  2812. case IPV6_RECVRTHDR:
  2813. qemu_log("IPV6_RECVRTHDR,");
  2814. goto print_optint;
  2815. case IPV6_2292RTHDR:
  2816. qemu_log("IPV6_2292RTHDR,");
  2817. goto print_optint;
  2818. case IPV6_RECVHOPOPTS:
  2819. qemu_log("IPV6_RECVHOPOPTS,");
  2820. goto print_optint;
  2821. case IPV6_2292HOPOPTS:
  2822. qemu_log("IPV6_2292HOPOPTS,");
  2823. goto print_optint;
  2824. case IPV6_RECVDSTOPTS:
  2825. qemu_log("IPV6_RECVDSTOPTS,");
  2826. goto print_optint;
  2827. case IPV6_2292DSTOPTS:
  2828. qemu_log("IPV6_2292DSTOPTS,");
  2829. goto print_optint;
  2830. case IPV6_TCLASS:
  2831. qemu_log("IPV6_TCLASS,");
  2832. goto print_optint;
  2833. case IPV6_ADDR_PREFERENCES:
  2834. qemu_log("IPV6_ADDR_PREFERENCES,");
  2835. goto print_optint;
  2836. #ifdef IPV6_RECVPATHMTU
  2837. case IPV6_RECVPATHMTU:
  2838. qemu_log("IPV6_RECVPATHMTU,");
  2839. goto print_optint;
  2840. #endif
  2841. #ifdef IPV6_TRANSPARENT
  2842. case IPV6_TRANSPARENT:
  2843. qemu_log("IPV6_TRANSPARENT,");
  2844. goto print_optint;
  2845. #endif
  2846. #ifdef IPV6_FREEBIND
  2847. case IPV6_FREEBIND:
  2848. qemu_log("IPV6_FREEBIND,");
  2849. goto print_optint;
  2850. #endif
  2851. #ifdef IPV6_RECVORIGDSTADDR
  2852. case IPV6_RECVORIGDSTADDR:
  2853. qemu_log("IPV6_RECVORIGDSTADDR,");
  2854. goto print_optint;
  2855. #endif
  2856. case IPV6_PKTINFO:
  2857. qemu_log("IPV6_PKTINFO,");
  2858. print_pointer(optval, 0);
  2859. break;
  2860. case IPV6_ADD_MEMBERSHIP:
  2861. qemu_log("IPV6_ADD_MEMBERSHIP,");
  2862. print_pointer(optval, 0);
  2863. break;
  2864. case IPV6_DROP_MEMBERSHIP:
  2865. qemu_log("IPV6_DROP_MEMBERSHIP,");
  2866. print_pointer(optval, 0);
  2867. break;
  2868. default:
  2869. print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
  2870. print_pointer(optval, 0);
  2871. break;
  2872. }
  2873. break;
  2874. default:
  2875. print_raw_param(TARGET_ABI_FMT_ld, level, 0);
  2876. print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
  2877. print_pointer(optval, 0);
  2878. break;
  2879. }
  2880. print_raw_param(TARGET_ABI_FMT_ld, optlen, 1);
  2881. qemu_log(")");
  2882. }
  2883. #define PRINT_SOCKOP(name, func) \
  2884. [TARGET_SYS_##name] = { #name, func }
  2885. static struct {
  2886. const char *name;
  2887. void (*print)(const char *, abi_long);
  2888. } scall[] = {
  2889. PRINT_SOCKOP(SOCKET, do_print_socket),
  2890. PRINT_SOCKOP(BIND, do_print_sockaddr),
  2891. PRINT_SOCKOP(CONNECT, do_print_sockaddr),
  2892. PRINT_SOCKOP(LISTEN, do_print_listen),
  2893. PRINT_SOCKOP(ACCEPT, do_print_sockaddr),
  2894. PRINT_SOCKOP(GETSOCKNAME, do_print_sockaddr),
  2895. PRINT_SOCKOP(GETPEERNAME, do_print_sockaddr),
  2896. PRINT_SOCKOP(SOCKETPAIR, do_print_socketpair),
  2897. PRINT_SOCKOP(SEND, do_print_sendrecv),
  2898. PRINT_SOCKOP(RECV, do_print_sendrecv),
  2899. PRINT_SOCKOP(SENDTO, do_print_msgaddr),
  2900. PRINT_SOCKOP(RECVFROM, do_print_msgaddr),
  2901. PRINT_SOCKOP(SHUTDOWN, do_print_shutdown),
  2902. PRINT_SOCKOP(SETSOCKOPT, do_print_sockopt),
  2903. PRINT_SOCKOP(GETSOCKOPT, do_print_sockopt),
  2904. PRINT_SOCKOP(SENDMSG, do_print_msg),
  2905. PRINT_SOCKOP(RECVMSG, do_print_msg),
  2906. PRINT_SOCKOP(ACCEPT4, NULL),
  2907. PRINT_SOCKOP(RECVMMSG, NULL),
  2908. PRINT_SOCKOP(SENDMMSG, NULL),
  2909. };
  2910. static void
  2911. print_socketcall(CPUArchState *cpu_env, const struct syscallname *name,
  2912. abi_long arg0, abi_long arg1, abi_long arg2,
  2913. abi_long arg3, abi_long arg4, abi_long arg5)
  2914. {
  2915. if (arg0 >= 0 && arg0 < ARRAY_SIZE(scall) && scall[arg0].print) {
  2916. scall[arg0].print(scall[arg0].name, arg1);
  2917. return;
  2918. }
  2919. print_syscall_prologue(name);
  2920. print_raw_param(TARGET_ABI_FMT_ld, arg0, 0);
  2921. print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
  2922. print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
  2923. print_raw_param(TARGET_ABI_FMT_ld, arg3, 0);
  2924. print_raw_param(TARGET_ABI_FMT_ld, arg4, 0);
  2925. print_raw_param(TARGET_ABI_FMT_ld, arg5, 0);
  2926. print_syscall_epilogue(name);
  2927. }
  2928. #endif
  2929. #if defined(TARGET_NR_bind)
  2930. static void
  2931. print_bind(CPUArchState *cpu_env, const struct syscallname *name,
  2932. abi_long arg0, abi_long arg1, abi_long arg2,
  2933. abi_long arg3, abi_long arg4, abi_long arg5)
  2934. {
  2935. print_syscall_prologue(name);
  2936. print_sockfd(arg0, 0);
  2937. print_sockaddr(arg1, arg2, 1);
  2938. print_syscall_epilogue(name);
  2939. }
  2940. #endif
  2941. #ifdef TARGET_NR_recvfrom
  2942. static void
  2943. print_recvfrom(CPUArchState *cpu_env, const struct syscallname *name,
  2944. abi_long arg0, abi_long arg1, abi_long arg2,
  2945. abi_long arg3, abi_long arg4, abi_long arg5)
  2946. {
  2947. print_syscall_prologue(name);
  2948. print_sockfd(arg0, 0);
  2949. print_pointer(arg1, 0); /* output */
  2950. print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
  2951. print_flags(msg_flags, arg3, 0);
  2952. print_pointer(arg4, 0); /* output */
  2953. print_pointer(arg5, 1); /* in/out */
  2954. print_syscall_epilogue(name);
  2955. }
  2956. #endif
  2957. #ifdef TARGET_NR_sendto
  2958. static void
  2959. print_sendto(CPUArchState *cpu_env, const struct syscallname *name,
  2960. abi_long arg0, abi_long arg1, abi_long arg2,
  2961. abi_long arg3, abi_long arg4, abi_long arg5)
  2962. {
  2963. print_syscall_prologue(name);
  2964. print_sockfd(arg0, 0);
  2965. print_buf_len(arg1, arg2, 0);
  2966. print_flags(msg_flags, arg3, 0);
  2967. print_sockaddr(arg4, arg5, 1);
  2968. print_syscall_epilogue(name);
  2969. }
  2970. #endif
  2971. #if defined(TARGET_NR_stat) || defined(TARGET_NR_stat64) || \
  2972. defined(TARGET_NR_lstat) || defined(TARGET_NR_lstat64)
  2973. static void
  2974. print_stat(CPUArchState *cpu_env, const struct syscallname *name,
  2975. abi_long arg0, abi_long arg1, abi_long arg2,
  2976. abi_long arg3, abi_long arg4, abi_long arg5)
  2977. {
  2978. print_syscall_prologue(name);
  2979. print_string(arg0, 0);
  2980. print_pointer(arg1, 1);
  2981. print_syscall_epilogue(name);
  2982. }
  2983. #define print_lstat print_stat
  2984. #define print_stat64 print_stat
  2985. #define print_lstat64 print_stat
  2986. #endif
  2987. #if defined(TARGET_NR_madvise)
  2988. static struct enums madvise_advice[] = {
  2989. ENUM_TARGET(MADV_NORMAL),
  2990. ENUM_TARGET(MADV_RANDOM),
  2991. ENUM_TARGET(MADV_SEQUENTIAL),
  2992. ENUM_TARGET(MADV_WILLNEED),
  2993. ENUM_TARGET(MADV_DONTNEED),
  2994. ENUM_TARGET(MADV_FREE),
  2995. ENUM_TARGET(MADV_REMOVE),
  2996. ENUM_TARGET(MADV_DONTFORK),
  2997. ENUM_TARGET(MADV_DOFORK),
  2998. ENUM_TARGET(MADV_MERGEABLE),
  2999. ENUM_TARGET(MADV_UNMERGEABLE),
  3000. ENUM_TARGET(MADV_HUGEPAGE),
  3001. ENUM_TARGET(MADV_NOHUGEPAGE),
  3002. ENUM_TARGET(MADV_DONTDUMP),
  3003. ENUM_TARGET(MADV_DODUMP),
  3004. ENUM_TARGET(MADV_WIPEONFORK),
  3005. ENUM_TARGET(MADV_KEEPONFORK),
  3006. ENUM_TARGET(MADV_COLD),
  3007. ENUM_TARGET(MADV_PAGEOUT),
  3008. ENUM_TARGET(MADV_POPULATE_READ),
  3009. ENUM_TARGET(MADV_POPULATE_WRITE),
  3010. ENUM_TARGET(MADV_DONTNEED_LOCKED),
  3011. ENUM_END,
  3012. };
  3013. static void
  3014. print_madvise(CPUArchState *cpu_env, const struct syscallname *name,
  3015. abi_long arg0, abi_long arg1, abi_long arg2,
  3016. abi_long arg3, abi_long arg4, abi_long arg5)
  3017. {
  3018. print_syscall_prologue(name);
  3019. print_pointer(arg0, 0);
  3020. print_raw_param("%d", arg1, 0);
  3021. print_enums(madvise_advice, arg2, 1);
  3022. print_syscall_epilogue(name);
  3023. }
  3024. #endif
  3025. #if defined(TARGET_NR_fstat) || defined(TARGET_NR_fstat64)
  3026. static void
  3027. print_fstat(CPUArchState *cpu_env, const struct syscallname *name,
  3028. abi_long arg0, abi_long arg1, abi_long arg2,
  3029. abi_long arg3, abi_long arg4, abi_long arg5)
  3030. {
  3031. print_syscall_prologue(name);
  3032. print_raw_param("%d", arg0, 0);
  3033. print_pointer(arg1, 1);
  3034. print_syscall_epilogue(name);
  3035. }
  3036. #define print_fstat64 print_fstat
  3037. #endif
  3038. #ifdef TARGET_NR_mkdir
  3039. static void
  3040. print_mkdir(CPUArchState *cpu_env, const struct syscallname *name,
  3041. abi_long arg0, abi_long arg1, abi_long arg2,
  3042. abi_long arg3, abi_long arg4, abi_long arg5)
  3043. {
  3044. print_syscall_prologue(name);
  3045. print_string(arg0, 0);
  3046. print_file_mode(arg1, 1);
  3047. print_syscall_epilogue(name);
  3048. }
  3049. #endif
  3050. #ifdef TARGET_NR_mkdirat
  3051. static void
  3052. print_mkdirat(CPUArchState *cpu_env, const struct syscallname *name,
  3053. abi_long arg0, abi_long arg1, abi_long arg2,
  3054. abi_long arg3, abi_long arg4, abi_long arg5)
  3055. {
  3056. print_syscall_prologue(name);
  3057. print_at_dirfd(arg0, 0);
  3058. print_string(arg1, 0);
  3059. print_file_mode(arg2, 1);
  3060. print_syscall_epilogue(name);
  3061. }
  3062. #endif
  3063. #ifdef TARGET_NR_rmdir
  3064. static void
  3065. print_rmdir(CPUArchState *cpu_env, const struct syscallname *name,
  3066. abi_long arg0, abi_long arg1, abi_long arg2,
  3067. abi_long arg3, abi_long arg4, abi_long arg5)
  3068. {
  3069. print_syscall_prologue(name);
  3070. print_string(arg0, 0);
  3071. print_syscall_epilogue(name);
  3072. }
  3073. #endif
  3074. #ifdef TARGET_NR_rt_sigaction
  3075. static void
  3076. print_rt_sigaction(CPUArchState *cpu_env, const struct syscallname *name,
  3077. abi_long arg0, abi_long arg1, abi_long arg2,
  3078. abi_long arg3, abi_long arg4, abi_long arg5)
  3079. {
  3080. print_syscall_prologue(name);
  3081. print_signal(arg0, 0);
  3082. print_pointer(arg1, 0);
  3083. print_pointer(arg2, 1);
  3084. print_syscall_epilogue(name);
  3085. }
  3086. #endif
  3087. #ifdef TARGET_NR_rt_sigprocmask
  3088. static void
  3089. print_rt_sigprocmask(CPUArchState *cpu_env, const struct syscallname *name,
  3090. abi_long arg0, abi_long arg1, abi_long arg2,
  3091. abi_long arg3, abi_long arg4, abi_long arg5)
  3092. {
  3093. const char *how = "UNKNOWN";
  3094. print_syscall_prologue(name);
  3095. switch(arg0) {
  3096. case TARGET_SIG_BLOCK: how = "SIG_BLOCK"; break;
  3097. case TARGET_SIG_UNBLOCK: how = "SIG_UNBLOCK"; break;
  3098. case TARGET_SIG_SETMASK: how = "SIG_SETMASK"; break;
  3099. }
  3100. qemu_log("%s,", how);
  3101. print_target_sigset_t(arg1, arg3, 0);
  3102. print_pointer(arg2, 0);
  3103. print_raw_param("%u", arg3, 1);
  3104. print_syscall_epilogue(name);
  3105. }
  3106. static void
  3107. print_rt_sigprocmask_ret(CPUArchState *cpu_env, const struct syscallname *name,
  3108. abi_long ret, abi_long arg0, abi_long arg1,
  3109. abi_long arg2, abi_long arg3, abi_long arg4,
  3110. abi_long arg5)
  3111. {
  3112. if (!print_syscall_err(ret)) {
  3113. qemu_log(TARGET_ABI_FMT_ld, ret);
  3114. if (arg2) {
  3115. qemu_log(" (oldset=");
  3116. print_target_sigset_t(arg2, arg3, 1);
  3117. qemu_log(")");
  3118. }
  3119. }
  3120. qemu_log("\n");
  3121. }
  3122. #endif
  3123. #ifdef TARGET_NR_rt_sigqueueinfo
  3124. static void
  3125. print_rt_sigqueueinfo(CPUArchState *cpu_env, const struct syscallname *name,
  3126. abi_long arg0, abi_long arg1, abi_long arg2,
  3127. abi_long arg3, abi_long arg4, abi_long arg5)
  3128. {
  3129. void *p;
  3130. target_siginfo_t uinfo;
  3131. print_syscall_prologue(name);
  3132. print_raw_param("%d", arg0, 0);
  3133. print_signal(arg1, 0);
  3134. p = lock_user(VERIFY_READ, arg2, sizeof(target_siginfo_t), 1);
  3135. if (p) {
  3136. get_target_siginfo(&uinfo, p);
  3137. print_siginfo(&uinfo);
  3138. unlock_user(p, arg2, 0);
  3139. } else {
  3140. print_pointer(arg2, 1);
  3141. }
  3142. print_syscall_epilogue(name);
  3143. }
  3144. #endif
  3145. #ifdef TARGET_NR_rt_tgsigqueueinfo
  3146. static void
  3147. print_rt_tgsigqueueinfo(CPUArchState *cpu_env, const struct syscallname *name,
  3148. abi_long arg0, abi_long arg1, abi_long arg2,
  3149. abi_long arg3, abi_long arg4, abi_long arg5)
  3150. {
  3151. void *p;
  3152. target_siginfo_t uinfo;
  3153. print_syscall_prologue(name);
  3154. print_raw_param("%d", arg0, 0);
  3155. print_raw_param("%d", arg1, 0);
  3156. print_signal(arg2, 0);
  3157. p = lock_user(VERIFY_READ, arg3, sizeof(target_siginfo_t), 1);
  3158. if (p) {
  3159. get_target_siginfo(&uinfo, p);
  3160. print_siginfo(&uinfo);
  3161. unlock_user(p, arg3, 0);
  3162. } else {
  3163. print_pointer(arg3, 1);
  3164. }
  3165. print_syscall_epilogue(name);
  3166. }
  3167. #endif
  3168. #ifdef TARGET_NR_syslog
  3169. static void
  3170. print_syslog_action(abi_ulong arg, int last)
  3171. {
  3172. const char *type;
  3173. switch (arg) {
  3174. case TARGET_SYSLOG_ACTION_CLOSE: {
  3175. type = "SYSLOG_ACTION_CLOSE";
  3176. break;
  3177. }
  3178. case TARGET_SYSLOG_ACTION_OPEN: {
  3179. type = "SYSLOG_ACTION_OPEN";
  3180. break;
  3181. }
  3182. case TARGET_SYSLOG_ACTION_READ: {
  3183. type = "SYSLOG_ACTION_READ";
  3184. break;
  3185. }
  3186. case TARGET_SYSLOG_ACTION_READ_ALL: {
  3187. type = "SYSLOG_ACTION_READ_ALL";
  3188. break;
  3189. }
  3190. case TARGET_SYSLOG_ACTION_READ_CLEAR: {
  3191. type = "SYSLOG_ACTION_READ_CLEAR";
  3192. break;
  3193. }
  3194. case TARGET_SYSLOG_ACTION_CLEAR: {
  3195. type = "SYSLOG_ACTION_CLEAR";
  3196. break;
  3197. }
  3198. case TARGET_SYSLOG_ACTION_CONSOLE_OFF: {
  3199. type = "SYSLOG_ACTION_CONSOLE_OFF";
  3200. break;
  3201. }
  3202. case TARGET_SYSLOG_ACTION_CONSOLE_ON: {
  3203. type = "SYSLOG_ACTION_CONSOLE_ON";
  3204. break;
  3205. }
  3206. case TARGET_SYSLOG_ACTION_CONSOLE_LEVEL: {
  3207. type = "SYSLOG_ACTION_CONSOLE_LEVEL";
  3208. break;
  3209. }
  3210. case TARGET_SYSLOG_ACTION_SIZE_UNREAD: {
  3211. type = "SYSLOG_ACTION_SIZE_UNREAD";
  3212. break;
  3213. }
  3214. case TARGET_SYSLOG_ACTION_SIZE_BUFFER: {
  3215. type = "SYSLOG_ACTION_SIZE_BUFFER";
  3216. break;
  3217. }
  3218. default: {
  3219. print_raw_param("%ld", arg, last);
  3220. return;
  3221. }
  3222. }
  3223. qemu_log("%s%s", type, get_comma(last));
  3224. }
  3225. static void
  3226. print_syslog(CPUArchState *cpu_env, const struct syscallname *name,
  3227. abi_long arg0, abi_long arg1, abi_long arg2,
  3228. abi_long arg3, abi_long arg4, abi_long arg5)
  3229. {
  3230. print_syscall_prologue(name);
  3231. print_syslog_action(arg0, 0);
  3232. print_pointer(arg1, 0);
  3233. print_raw_param("%d", arg2, 1);
  3234. print_syscall_epilogue(name);
  3235. }
  3236. #endif
  3237. #ifdef TARGET_NR_mknod
  3238. static void
  3239. print_mknod(CPUArchState *cpu_env, const struct syscallname *name,
  3240. abi_long arg0, abi_long arg1, abi_long arg2,
  3241. abi_long arg3, abi_long arg4, abi_long arg5)
  3242. {
  3243. int hasdev = (arg1 & (S_IFCHR|S_IFBLK));
  3244. print_syscall_prologue(name);
  3245. print_string(arg0, 0);
  3246. print_file_mode(arg1, (hasdev == 0));
  3247. if (hasdev) {
  3248. print_raw_param("makedev(%d", major(arg2), 0);
  3249. print_raw_param("%d)", minor(arg2), 1);
  3250. }
  3251. print_syscall_epilogue(name);
  3252. }
  3253. #endif
  3254. #ifdef TARGET_NR_mknodat
  3255. static void
  3256. print_mknodat(CPUArchState *cpu_env, const struct syscallname *name,
  3257. abi_long arg0, abi_long arg1, abi_long arg2,
  3258. abi_long arg3, abi_long arg4, abi_long arg5)
  3259. {
  3260. int hasdev = (arg2 & (S_IFCHR|S_IFBLK));
  3261. print_syscall_prologue(name);
  3262. print_at_dirfd(arg0, 0);
  3263. print_string(arg1, 0);
  3264. print_file_mode(arg2, (hasdev == 0));
  3265. if (hasdev) {
  3266. print_raw_param("makedev(%d", major(arg3), 0);
  3267. print_raw_param("%d)", minor(arg3), 1);
  3268. }
  3269. print_syscall_epilogue(name);
  3270. }
  3271. #endif
  3272. #ifdef TARGET_NR_mq_open
  3273. static void
  3274. print_mq_open(CPUArchState *cpu_env, const struct syscallname *name,
  3275. abi_long arg0, abi_long arg1, abi_long arg2,
  3276. abi_long arg3, abi_long arg4, abi_long arg5)
  3277. {
  3278. int is_creat = (arg1 & TARGET_O_CREAT);
  3279. print_syscall_prologue(name);
  3280. print_string(arg0, 0);
  3281. print_open_flags(arg1, (is_creat == 0));
  3282. if (is_creat) {
  3283. print_file_mode(arg2, 0);
  3284. print_pointer(arg3, 1);
  3285. }
  3286. print_syscall_epilogue(name);
  3287. }
  3288. #endif
  3289. #ifdef TARGET_NR_open
  3290. static void
  3291. print_open(CPUArchState *cpu_env, const struct syscallname *name,
  3292. abi_long arg0, abi_long arg1, abi_long arg2,
  3293. abi_long arg3, abi_long arg4, abi_long arg5)
  3294. {
  3295. int is_creat = (arg1 & TARGET_O_CREAT);
  3296. print_syscall_prologue(name);
  3297. print_string(arg0, 0);
  3298. print_open_flags(arg1, (is_creat == 0));
  3299. if (is_creat)
  3300. print_file_mode(arg2, 1);
  3301. print_syscall_epilogue(name);
  3302. }
  3303. #endif
  3304. #ifdef TARGET_NR_openat
  3305. static void
  3306. print_openat(CPUArchState *cpu_env, const struct syscallname *name,
  3307. abi_long arg0, abi_long arg1, abi_long arg2,
  3308. abi_long arg3, abi_long arg4, abi_long arg5)
  3309. {
  3310. int is_creat = (arg2 & TARGET_O_CREAT);
  3311. print_syscall_prologue(name);
  3312. print_at_dirfd(arg0, 0);
  3313. print_string(arg1, 0);
  3314. print_open_flags(arg2, (is_creat == 0));
  3315. if (is_creat)
  3316. print_file_mode(arg3, 1);
  3317. print_syscall_epilogue(name);
  3318. }
  3319. #endif
  3320. #ifdef TARGET_NR_openat2
  3321. static void
  3322. print_openat2(CPUArchState *cpu_env, const struct syscallname *name,
  3323. abi_long arg0, abi_long arg1, abi_long arg2,
  3324. abi_long arg3, abi_long arg4, abi_long arg5)
  3325. {
  3326. struct open_how_ver0 how;
  3327. print_syscall_prologue(name);
  3328. print_at_dirfd(arg0, 0);
  3329. print_string(arg1, 0);
  3330. if ((abi_ulong)arg3 >= sizeof(struct target_open_how_ver0) &&
  3331. copy_struct_from_user(&how, sizeof(how), arg2, arg3) == 0) {
  3332. how.flags = tswap64(how.flags);
  3333. how.mode = tswap64(how.mode);
  3334. how.resolve = tswap64(how.resolve);
  3335. qemu_log("{");
  3336. print_open_flags(how.flags, 0);
  3337. if (how.flags & TARGET_O_CREAT) {
  3338. print_file_mode(how.mode, 0);
  3339. }
  3340. print_flags(openat2_resolve_flags, how.resolve, 1);
  3341. qemu_log("},");
  3342. } else {
  3343. print_pointer(arg2, 0);
  3344. }
  3345. print_raw_param(TARGET_ABI_FMT_lu, arg3, 1);
  3346. print_syscall_epilogue(name);
  3347. }
  3348. #endif
  3349. #ifdef TARGET_NR_pidfd_send_signal
  3350. static void
  3351. print_pidfd_send_signal(CPUArchState *cpu_env, const struct syscallname *name,
  3352. abi_long arg0, abi_long arg1, abi_long arg2,
  3353. abi_long arg3, abi_long arg4, abi_long arg5)
  3354. {
  3355. void *p;
  3356. target_siginfo_t uinfo;
  3357. print_syscall_prologue(name);
  3358. print_raw_param("%d", arg0, 0);
  3359. print_signal(arg1, 0);
  3360. p = lock_user(VERIFY_READ, arg2, sizeof(target_siginfo_t), 1);
  3361. if (p) {
  3362. get_target_siginfo(&uinfo, p);
  3363. print_siginfo(&uinfo);
  3364. unlock_user(p, arg2, 0);
  3365. } else {
  3366. print_pointer(arg2, 0);
  3367. }
  3368. print_raw_param("%u", arg3, 1);
  3369. print_syscall_epilogue(name);
  3370. }
  3371. #endif
  3372. #ifdef TARGET_NR_mq_unlink
  3373. static void
  3374. print_mq_unlink(CPUArchState *cpu_env, const struct syscallname *name,
  3375. abi_long arg0, abi_long arg1, abi_long arg2,
  3376. abi_long arg3, abi_long arg4, abi_long arg5)
  3377. {
  3378. print_syscall_prologue(name);
  3379. print_string(arg0, 1);
  3380. print_syscall_epilogue(name);
  3381. }
  3382. #endif
  3383. #if defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)
  3384. static void
  3385. print_fstatat64(CPUArchState *cpu_env, const struct syscallname *name,
  3386. abi_long arg0, abi_long arg1, abi_long arg2,
  3387. abi_long arg3, abi_long arg4, abi_long arg5)
  3388. {
  3389. print_syscall_prologue(name);
  3390. print_at_dirfd(arg0, 0);
  3391. print_string(arg1, 0);
  3392. print_pointer(arg2, 0);
  3393. print_flags(at_file_flags, arg3, 1);
  3394. print_syscall_epilogue(name);
  3395. }
  3396. #define print_newfstatat print_fstatat64
  3397. #endif
  3398. #ifdef TARGET_NR_readlink
  3399. static void
  3400. print_readlink(CPUArchState *cpu_env, const struct syscallname *name,
  3401. abi_long arg0, abi_long arg1, abi_long arg2,
  3402. abi_long arg3, abi_long arg4, abi_long arg5)
  3403. {
  3404. print_syscall_prologue(name);
  3405. print_string(arg0, 0);
  3406. print_pointer(arg1, 0);
  3407. print_raw_param("%u", arg2, 1);
  3408. print_syscall_epilogue(name);
  3409. }
  3410. #endif
  3411. #ifdef TARGET_NR_readlinkat
  3412. static void
  3413. print_readlinkat(CPUArchState *cpu_env, const struct syscallname *name,
  3414. abi_long arg0, abi_long arg1, abi_long arg2,
  3415. abi_long arg3, abi_long arg4, abi_long arg5)
  3416. {
  3417. print_syscall_prologue(name);
  3418. print_at_dirfd(arg0, 0);
  3419. print_string(arg1, 0);
  3420. print_pointer(arg2, 0);
  3421. print_raw_param("%u", arg3, 1);
  3422. print_syscall_epilogue(name);
  3423. }
  3424. #endif
  3425. #ifdef TARGET_NR_rename
  3426. static void
  3427. print_rename(CPUArchState *cpu_env, const struct syscallname *name,
  3428. abi_long arg0, abi_long arg1, abi_long arg2,
  3429. abi_long arg3, abi_long arg4, abi_long arg5)
  3430. {
  3431. print_syscall_prologue(name);
  3432. print_string(arg0, 0);
  3433. print_string(arg1, 1);
  3434. print_syscall_epilogue(name);
  3435. }
  3436. #endif
  3437. #ifdef TARGET_NR_renameat
  3438. static void
  3439. print_renameat(CPUArchState *cpu_env, const struct syscallname *name,
  3440. abi_long arg0, abi_long arg1, abi_long arg2,
  3441. abi_long arg3, abi_long arg4, abi_long arg5)
  3442. {
  3443. print_syscall_prologue(name);
  3444. print_at_dirfd(arg0, 0);
  3445. print_string(arg1, 0);
  3446. print_at_dirfd(arg2, 0);
  3447. print_string(arg3, 1);
  3448. print_syscall_epilogue(name);
  3449. }
  3450. #endif
  3451. #ifdef TARGET_NR_statfs
  3452. static void
  3453. print_statfs(CPUArchState *cpu_env, const struct syscallname *name,
  3454. abi_long arg0, abi_long arg1, abi_long arg2,
  3455. abi_long arg3, abi_long arg4, abi_long arg5)
  3456. {
  3457. print_syscall_prologue(name);
  3458. print_string(arg0, 0);
  3459. print_pointer(arg1, 1);
  3460. print_syscall_epilogue(name);
  3461. }
  3462. #endif
  3463. #ifdef TARGET_NR_statfs64
  3464. static void
  3465. print_statfs64(CPUArchState *cpu_env, const struct syscallname *name,
  3466. abi_long arg0, abi_long arg1, abi_long arg2,
  3467. abi_long arg3, abi_long arg4, abi_long arg5)
  3468. {
  3469. print_syscall_prologue(name);
  3470. print_string(arg0, 0);
  3471. print_pointer(arg1, 1);
  3472. print_syscall_epilogue(name);
  3473. }
  3474. #endif
  3475. #ifdef TARGET_NR_symlink
  3476. static void
  3477. print_symlink(CPUArchState *cpu_env, const struct syscallname *name,
  3478. abi_long arg0, abi_long arg1, abi_long arg2,
  3479. abi_long arg3, abi_long arg4, abi_long arg5)
  3480. {
  3481. print_syscall_prologue(name);
  3482. print_string(arg0, 0);
  3483. print_string(arg1, 1);
  3484. print_syscall_epilogue(name);
  3485. }
  3486. #endif
  3487. #ifdef TARGET_NR_symlinkat
  3488. static void
  3489. print_symlinkat(CPUArchState *cpu_env, const struct syscallname *name,
  3490. abi_long arg0, abi_long arg1, abi_long arg2,
  3491. abi_long arg3, abi_long arg4, abi_long arg5)
  3492. {
  3493. print_syscall_prologue(name);
  3494. print_string(arg0, 0);
  3495. print_at_dirfd(arg1, 0);
  3496. print_string(arg2, 1);
  3497. print_syscall_epilogue(name);
  3498. }
  3499. #endif
  3500. #ifdef TARGET_NR_mount
  3501. static void
  3502. print_mount(CPUArchState *cpu_env, const struct syscallname *name,
  3503. abi_long arg0, abi_long arg1, abi_long arg2,
  3504. abi_long arg3, abi_long arg4, abi_long arg5)
  3505. {
  3506. print_syscall_prologue(name);
  3507. print_string(arg0, 0);
  3508. print_string(arg1, 0);
  3509. print_string(arg2, 0);
  3510. print_flags(mount_flags, arg3, 0);
  3511. print_pointer(arg4, 1);
  3512. print_syscall_epilogue(name);
  3513. }
  3514. #endif
  3515. #ifdef TARGET_NR_umount
  3516. static void
  3517. print_umount(CPUArchState *cpu_env, const struct syscallname *name,
  3518. abi_long arg0, abi_long arg1, abi_long arg2,
  3519. abi_long arg3, abi_long arg4, abi_long arg5)
  3520. {
  3521. print_syscall_prologue(name);
  3522. print_string(arg0, 1);
  3523. print_syscall_epilogue(name);
  3524. }
  3525. #endif
  3526. #ifdef TARGET_NR_umount2
  3527. static void
  3528. print_umount2(CPUArchState *cpu_env, const struct syscallname *name,
  3529. abi_long arg0, abi_long arg1, abi_long arg2,
  3530. abi_long arg3, abi_long arg4, abi_long arg5)
  3531. {
  3532. print_syscall_prologue(name);
  3533. print_string(arg0, 0);
  3534. print_flags(umount2_flags, arg1, 1);
  3535. print_syscall_epilogue(name);
  3536. }
  3537. #endif
  3538. #ifdef TARGET_NR_unlink
  3539. static void
  3540. print_unlink(CPUArchState *cpu_env, const struct syscallname *name,
  3541. abi_long arg0, abi_long arg1, abi_long arg2,
  3542. abi_long arg3, abi_long arg4, abi_long arg5)
  3543. {
  3544. print_syscall_prologue(name);
  3545. print_string(arg0, 1);
  3546. print_syscall_epilogue(name);
  3547. }
  3548. #endif
  3549. #ifdef TARGET_NR_unlinkat
  3550. static void
  3551. print_unlinkat(CPUArchState *cpu_env, const struct syscallname *name,
  3552. abi_long arg0, abi_long arg1, abi_long arg2,
  3553. abi_long arg3, abi_long arg4, abi_long arg5)
  3554. {
  3555. print_syscall_prologue(name);
  3556. print_at_dirfd(arg0, 0);
  3557. print_string(arg1, 0);
  3558. print_flags(unlinkat_flags, arg2, 1);
  3559. print_syscall_epilogue(name);
  3560. }
  3561. #endif
  3562. #ifdef TARGET_NR_unshare
  3563. static void
  3564. print_unshare(CPUArchState *cpu_env, const struct syscallname *name,
  3565. abi_long arg0, abi_long arg1, abi_long arg2,
  3566. abi_long arg3, abi_long arg4, abi_long arg5)
  3567. {
  3568. print_syscall_prologue(name);
  3569. print_flags(clone_flags, arg0, 1);
  3570. print_syscall_epilogue(name);
  3571. }
  3572. #endif
  3573. #ifdef TARGET_NR_clock_nanosleep
  3574. static void
  3575. print_clock_nanosleep(CPUArchState *cpu_env, const struct syscallname *name,
  3576. abi_long arg0, abi_long arg1, abi_long arg2,
  3577. abi_long arg3, abi_long arg4, abi_long arg5)
  3578. {
  3579. print_syscall_prologue(name);
  3580. print_enums(clockids, arg0, 0);
  3581. print_raw_param("%d", arg1, 0);
  3582. print_timespec(arg2, 0);
  3583. print_timespec(arg3, 1);
  3584. print_syscall_epilogue(name);
  3585. }
  3586. #endif
  3587. #ifdef TARGET_NR_utime
  3588. static void
  3589. print_utime(CPUArchState *cpu_env, const struct syscallname *name,
  3590. abi_long arg0, abi_long arg1, abi_long arg2,
  3591. abi_long arg3, abi_long arg4, abi_long arg5)
  3592. {
  3593. print_syscall_prologue(name);
  3594. print_string(arg0, 0);
  3595. print_pointer(arg1, 1);
  3596. print_syscall_epilogue(name);
  3597. }
  3598. #endif
  3599. #ifdef TARGET_NR_utimes
  3600. static void
  3601. print_utimes(CPUArchState *cpu_env, const struct syscallname *name,
  3602. abi_long arg0, abi_long arg1, abi_long arg2,
  3603. abi_long arg3, abi_long arg4, abi_long arg5)
  3604. {
  3605. print_syscall_prologue(name);
  3606. print_string(arg0, 0);
  3607. print_pointer(arg1, 1);
  3608. print_syscall_epilogue(name);
  3609. }
  3610. #endif
  3611. #ifdef TARGET_NR_utimensat
  3612. static void
  3613. print_utimensat(CPUArchState *cpu_env, const struct syscallname *name,
  3614. abi_long arg0, abi_long arg1, abi_long arg2,
  3615. abi_long arg3, abi_long arg4, abi_long arg5)
  3616. {
  3617. print_syscall_prologue(name);
  3618. print_at_dirfd(arg0, 0);
  3619. print_string(arg1, 0);
  3620. print_pointer(arg2, 0);
  3621. print_flags(at_file_flags, arg3, 1);
  3622. print_syscall_epilogue(name);
  3623. }
  3624. #endif
  3625. #if defined(TARGET_NR_mmap) || defined(TARGET_NR_mmap2)
  3626. static void
  3627. print_mmap_both(CPUArchState *cpu_env, const struct syscallname *name,
  3628. abi_long arg0, abi_long arg1, abi_long arg2,
  3629. abi_long arg3, abi_long arg4, abi_long arg5,
  3630. bool is_old_mmap)
  3631. {
  3632. if (is_old_mmap) {
  3633. abi_ulong *v;
  3634. abi_ulong argp = arg0;
  3635. if (!(v = lock_user(VERIFY_READ, argp, 6 * sizeof(abi_ulong), 1)))
  3636. return;
  3637. arg0 = tswapal(v[0]);
  3638. arg1 = tswapal(v[1]);
  3639. arg2 = tswapal(v[2]);
  3640. arg3 = tswapal(v[3]);
  3641. arg4 = tswapal(v[4]);
  3642. arg5 = tswapal(v[5]);
  3643. unlock_user(v, argp, 0);
  3644. }
  3645. print_syscall_prologue(name);
  3646. print_pointer(arg0, 0);
  3647. print_raw_param("%d", arg1, 0);
  3648. print_flags(mmap_prot_flags, arg2, 0);
  3649. print_flags(mmap_flags, arg3, 0);
  3650. print_raw_param("%d", arg4, 0);
  3651. print_raw_param("%#x", arg5, 1);
  3652. print_syscall_epilogue(name);
  3653. }
  3654. #endif
  3655. #if defined(TARGET_NR_mmap)
  3656. static void
  3657. print_mmap(CPUArchState *cpu_env, const struct syscallname *name,
  3658. abi_long arg0, abi_long arg1, abi_long arg2,
  3659. abi_long arg3, abi_long arg4, abi_long arg5)
  3660. {
  3661. return print_mmap_both(cpu_env, name, arg0, arg1, arg2, arg3,
  3662. arg4, arg5,
  3663. #ifdef TARGET_ARCH_WANT_SYS_OLD_MMAP
  3664. true
  3665. #else
  3666. false
  3667. #endif
  3668. );
  3669. }
  3670. #endif
  3671. #if defined(TARGET_NR_mmap2)
  3672. static void
  3673. print_mmap2(CPUArchState *cpu_env, const struct syscallname *name,
  3674. abi_long arg0, abi_long arg1, abi_long arg2,
  3675. abi_long arg3, abi_long arg4, abi_long arg5)
  3676. {
  3677. return print_mmap_both(cpu_env, name, arg0, arg1, arg2, arg3,
  3678. arg4, arg5, false);
  3679. }
  3680. #endif
  3681. #ifdef TARGET_NR_mprotect
  3682. static void
  3683. print_mprotect(CPUArchState *cpu_env, const struct syscallname *name,
  3684. abi_long arg0, abi_long arg1, abi_long arg2,
  3685. abi_long arg3, abi_long arg4, abi_long arg5)
  3686. {
  3687. print_syscall_prologue(name);
  3688. print_pointer(arg0, 0);
  3689. print_raw_param("%d", arg1, 0);
  3690. print_flags(mmap_prot_flags, arg2, 1);
  3691. print_syscall_epilogue(name);
  3692. }
  3693. #endif
  3694. #ifdef TARGET_NR_munmap
  3695. static void
  3696. print_munmap(CPUArchState *cpu_env, const struct syscallname *name,
  3697. abi_long arg0, abi_long arg1, abi_long arg2,
  3698. abi_long arg3, abi_long arg4, abi_long arg5)
  3699. {
  3700. print_syscall_prologue(name);
  3701. print_pointer(arg0, 0);
  3702. print_raw_param("%d", arg1, 1);
  3703. print_syscall_epilogue(name);
  3704. }
  3705. #endif
  3706. #ifdef TARGET_NR_futex
  3707. static void print_futex_op(int cmd, int last)
  3708. {
  3709. static const char * const futex_names[] = {
  3710. #define NAME(X) [X] = #X
  3711. NAME(FUTEX_WAIT),
  3712. NAME(FUTEX_WAKE),
  3713. NAME(FUTEX_FD),
  3714. NAME(FUTEX_REQUEUE),
  3715. NAME(FUTEX_CMP_REQUEUE),
  3716. NAME(FUTEX_WAKE_OP),
  3717. NAME(FUTEX_LOCK_PI),
  3718. NAME(FUTEX_UNLOCK_PI),
  3719. NAME(FUTEX_TRYLOCK_PI),
  3720. NAME(FUTEX_WAIT_BITSET),
  3721. NAME(FUTEX_WAKE_BITSET),
  3722. NAME(FUTEX_WAIT_REQUEUE_PI),
  3723. NAME(FUTEX_CMP_REQUEUE_PI),
  3724. NAME(FUTEX_LOCK_PI2),
  3725. #undef NAME
  3726. };
  3727. unsigned base_cmd = cmd & FUTEX_CMD_MASK;
  3728. if (base_cmd < ARRAY_SIZE(futex_names)) {
  3729. qemu_log("%s%s%s",
  3730. (cmd & FUTEX_PRIVATE_FLAG ? "FUTEX_PRIVATE_FLAG|" : ""),
  3731. (cmd & FUTEX_CLOCK_REALTIME ? "FUTEX_CLOCK_REALTIME|" : ""),
  3732. futex_names[base_cmd]);
  3733. } else {
  3734. qemu_log("0x%x", cmd);
  3735. }
  3736. }
  3737. static void
  3738. print_futex(CPUArchState *cpu_env, const struct syscallname *name,
  3739. abi_long arg0, abi_long arg1, abi_long arg2,
  3740. abi_long arg3, abi_long arg4, abi_long arg5)
  3741. {
  3742. abi_long op = arg1 & FUTEX_CMD_MASK;
  3743. print_syscall_prologue(name);
  3744. print_pointer(arg0, 0);
  3745. print_futex_op(arg1, 0);
  3746. print_raw_param(",%d", arg2, 0);
  3747. switch (op) {
  3748. case FUTEX_WAIT:
  3749. case FUTEX_WAIT_BITSET:
  3750. case FUTEX_LOCK_PI:
  3751. case FUTEX_LOCK_PI2:
  3752. case FUTEX_WAIT_REQUEUE_PI:
  3753. print_timespec(arg3, 0);
  3754. break;
  3755. default:
  3756. print_pointer(arg3, 0);
  3757. break;
  3758. }
  3759. print_pointer(arg4, 0);
  3760. print_raw_param("%d", arg4, 1);
  3761. print_syscall_epilogue(name);
  3762. }
  3763. #endif
  3764. #ifdef TARGET_NR_prlimit64
  3765. static const char *target_ressource_string(abi_ulong r)
  3766. {
  3767. #define RET_RES_ENTRY(res) case TARGET_##res: return #res;
  3768. switch (r) {
  3769. RET_RES_ENTRY(RLIMIT_AS);
  3770. RET_RES_ENTRY(RLIMIT_CORE);
  3771. RET_RES_ENTRY(RLIMIT_CPU);
  3772. RET_RES_ENTRY(RLIMIT_DATA);
  3773. RET_RES_ENTRY(RLIMIT_FSIZE);
  3774. RET_RES_ENTRY(RLIMIT_LOCKS);
  3775. RET_RES_ENTRY(RLIMIT_MEMLOCK);
  3776. RET_RES_ENTRY(RLIMIT_MSGQUEUE);
  3777. RET_RES_ENTRY(RLIMIT_NICE);
  3778. RET_RES_ENTRY(RLIMIT_NOFILE);
  3779. RET_RES_ENTRY(RLIMIT_NPROC);
  3780. RET_RES_ENTRY(RLIMIT_RSS);
  3781. RET_RES_ENTRY(RLIMIT_RTPRIO);
  3782. #ifdef RLIMIT_RTTIME
  3783. RET_RES_ENTRY(RLIMIT_RTTIME);
  3784. #endif
  3785. RET_RES_ENTRY(RLIMIT_SIGPENDING);
  3786. RET_RES_ENTRY(RLIMIT_STACK);
  3787. default:
  3788. return NULL;
  3789. }
  3790. #undef RET_RES_ENTRY
  3791. }
  3792. static void
  3793. print_rlimit64(abi_ulong rlim_addr, int last)
  3794. {
  3795. if (rlim_addr) {
  3796. struct target_rlimit64 *rl;
  3797. rl = lock_user(VERIFY_READ, rlim_addr, sizeof(*rl), 1);
  3798. if (!rl) {
  3799. print_pointer(rlim_addr, last);
  3800. return;
  3801. }
  3802. print_raw_param64("{rlim_cur=%" PRId64, tswap64(rl->rlim_cur), 0);
  3803. print_raw_param64("rlim_max=%" PRId64 "}", tswap64(rl->rlim_max),
  3804. last);
  3805. unlock_user(rl, rlim_addr, 0);
  3806. } else {
  3807. qemu_log("NULL%s", get_comma(last));
  3808. }
  3809. }
  3810. static void
  3811. print_prlimit64(CPUArchState *cpu_env, const struct syscallname *name,
  3812. abi_long arg0, abi_long arg1, abi_long arg2,
  3813. abi_long arg3, abi_long arg4, abi_long arg5)
  3814. {
  3815. const char *rlim_name;
  3816. print_syscall_prologue(name);
  3817. print_raw_param("%d", arg0, 0);
  3818. rlim_name = target_ressource_string(arg1);
  3819. if (rlim_name) {
  3820. qemu_log("%s,", rlim_name);
  3821. } else {
  3822. print_raw_param("%d", arg1, 0);
  3823. }
  3824. print_rlimit64(arg2, 0);
  3825. print_pointer(arg3, 1);
  3826. print_syscall_epilogue(name);
  3827. }
  3828. static void
  3829. print_syscall_ret_prlimit64(CPUArchState *cpu_env,
  3830. const struct syscallname *name,
  3831. abi_long ret, abi_long arg0, abi_long arg1,
  3832. abi_long arg2, abi_long arg3, abi_long arg4,
  3833. abi_long arg5)
  3834. {
  3835. if (!print_syscall_err(ret)) {
  3836. qemu_log(TARGET_ABI_FMT_ld, ret);
  3837. if (arg3) {
  3838. qemu_log(" (");
  3839. print_rlimit64(arg3, 1);
  3840. qemu_log(")");
  3841. }
  3842. }
  3843. qemu_log("\n");
  3844. }
  3845. #endif
  3846. #ifdef TARGET_NR_kill
  3847. static void
  3848. print_kill(CPUArchState *cpu_env, const struct syscallname *name,
  3849. abi_long arg0, abi_long arg1, abi_long arg2,
  3850. abi_long arg3, abi_long arg4, abi_long arg5)
  3851. {
  3852. print_syscall_prologue(name);
  3853. print_raw_param("%d", arg0, 0);
  3854. print_signal(arg1, 1);
  3855. print_syscall_epilogue(name);
  3856. }
  3857. #endif
  3858. #ifdef TARGET_NR_tkill
  3859. static void
  3860. print_tkill(CPUArchState *cpu_env, const struct syscallname *name,
  3861. abi_long arg0, abi_long arg1, abi_long arg2,
  3862. abi_long arg3, abi_long arg4, abi_long arg5)
  3863. {
  3864. print_syscall_prologue(name);
  3865. print_raw_param("%d", arg0, 0);
  3866. print_signal(arg1, 1);
  3867. print_syscall_epilogue(name);
  3868. }
  3869. #endif
  3870. #ifdef TARGET_NR_tgkill
  3871. static void
  3872. print_tgkill(CPUArchState *cpu_env, const struct syscallname *name,
  3873. abi_long arg0, abi_long arg1, abi_long arg2,
  3874. abi_long arg3, abi_long arg4, abi_long arg5)
  3875. {
  3876. print_syscall_prologue(name);
  3877. print_raw_param("%d", arg0, 0);
  3878. print_raw_param("%d", arg1, 0);
  3879. print_signal(arg2, 1);
  3880. print_syscall_epilogue(name);
  3881. }
  3882. #endif
  3883. #if defined(TARGET_NR_pread64) || defined(TARGET_NR_pwrite64)
  3884. static void
  3885. print_pread64(CPUArchState *cpu_env, const struct syscallname *name,
  3886. abi_long arg0, abi_long arg1, abi_long arg2,
  3887. abi_long arg3, abi_long arg4, abi_long arg5)
  3888. {
  3889. if (regpairs_aligned(cpu_env, TARGET_NR_pread64)) {
  3890. arg3 = arg4;
  3891. arg4 = arg5;
  3892. }
  3893. print_syscall_prologue(name);
  3894. print_raw_param("%d", arg0, 0);
  3895. print_pointer(arg1, 0);
  3896. print_raw_param("%d", arg2, 0);
  3897. print_raw_param("%" PRIu64, target_offset64(arg3, arg4), 1);
  3898. print_syscall_epilogue(name);
  3899. }
  3900. #endif
  3901. #ifdef TARGET_NR_statx
  3902. static void
  3903. print_statx(CPUArchState *cpu_env, const struct syscallname *name,
  3904. abi_long arg0, abi_long arg1, abi_long arg2,
  3905. abi_long arg3, abi_long arg4, abi_long arg5)
  3906. {
  3907. print_syscall_prologue(name);
  3908. print_at_dirfd(arg0, 0);
  3909. print_string(arg1, 0);
  3910. print_flags(statx_flags, arg2, 0);
  3911. print_flags(statx_mask, arg3, 0);
  3912. print_pointer(arg4, 1);
  3913. print_syscall_epilogue(name);
  3914. }
  3915. #endif
  3916. #ifdef TARGET_NR_ioctl
  3917. static void
  3918. print_ioctl(CPUArchState *cpu_env, const struct syscallname *name,
  3919. abi_long arg0, abi_long arg1, abi_long arg2,
  3920. abi_long arg3, abi_long arg4, abi_long arg5)
  3921. {
  3922. print_syscall_prologue(name);
  3923. print_raw_param("%d", arg0, 0);
  3924. const IOCTLEntry *ie;
  3925. const argtype *arg_type;
  3926. void *argptr;
  3927. int target_size;
  3928. for (ie = ioctl_entries; ie->target_cmd != 0; ie++) {
  3929. if (ie->target_cmd == arg1) {
  3930. break;
  3931. }
  3932. }
  3933. if (ie->target_cmd == 0) {
  3934. print_raw_param("%#x", arg1, 0);
  3935. print_raw_param("%#x", arg2, 1);
  3936. } else {
  3937. qemu_log("%s", ie->name);
  3938. arg_type = ie->arg_type;
  3939. if (arg_type[0] != TYPE_NULL) {
  3940. qemu_log(",");
  3941. switch (arg_type[0]) {
  3942. case TYPE_PTRVOID:
  3943. print_pointer(arg2, 1);
  3944. break;
  3945. case TYPE_CHAR:
  3946. case TYPE_SHORT:
  3947. case TYPE_INT:
  3948. print_raw_param("%d", arg2, 1);
  3949. break;
  3950. case TYPE_LONG:
  3951. print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
  3952. break;
  3953. case TYPE_ULONG:
  3954. print_raw_param(TARGET_ABI_FMT_lu, arg2, 1);
  3955. break;
  3956. case TYPE_PTR:
  3957. switch (ie->access) {
  3958. case IOC_R:
  3959. print_pointer(arg2, 1);
  3960. break;
  3961. case IOC_W:
  3962. case IOC_RW:
  3963. arg_type++;
  3964. target_size = thunk_type_size(arg_type, 0);
  3965. argptr = lock_user(VERIFY_READ, arg2, target_size, 1);
  3966. if (argptr) {
  3967. thunk_print(argptr, arg_type);
  3968. unlock_user(argptr, arg2, target_size);
  3969. } else {
  3970. print_pointer(arg2, 1);
  3971. }
  3972. break;
  3973. }
  3974. break;
  3975. default:
  3976. g_assert_not_reached();
  3977. }
  3978. }
  3979. }
  3980. print_syscall_epilogue(name);
  3981. }
  3982. #endif
  3983. #if defined(TARGET_NR_wait4) || defined(TARGET_NR_waitpid)
  3984. static void print_wstatus(int wstatus)
  3985. {
  3986. if (WIFSIGNALED(wstatus)) {
  3987. qemu_log("{WIFSIGNALED(s) && WTERMSIG(s) == ");
  3988. print_signal(WTERMSIG(wstatus), 1);
  3989. if (WCOREDUMP(wstatus)) {
  3990. qemu_log(" && WCOREDUMP(s)");
  3991. }
  3992. qemu_log("}");
  3993. } else if (WIFEXITED(wstatus)) {
  3994. qemu_log("{WIFEXITED(s) && WEXITSTATUS(s) == %d}",
  3995. WEXITSTATUS(wstatus));
  3996. } else {
  3997. print_number(wstatus, 1);
  3998. }
  3999. }
  4000. static void print_ret_wstatus(abi_long ret, abi_long wstatus_addr)
  4001. {
  4002. int wstatus;
  4003. if (!print_syscall_err(ret)
  4004. && wstatus_addr
  4005. && get_user_s32(wstatus, wstatus_addr)) {
  4006. qemu_log(TARGET_ABI_FMT_ld " (wstatus=", ret);
  4007. print_wstatus(wstatus);
  4008. qemu_log(")");
  4009. }
  4010. qemu_log("\n");
  4011. }
  4012. #endif
  4013. #ifdef TARGET_NR_wait4
  4014. static void
  4015. print_syscall_ret_wait4(CPUArchState *cpu_env,
  4016. const struct syscallname *name,
  4017. abi_long ret, abi_long arg0, abi_long arg1,
  4018. abi_long arg2, abi_long arg3, abi_long arg4,
  4019. abi_long arg5)
  4020. {
  4021. print_ret_wstatus(ret, arg1);
  4022. }
  4023. #endif
  4024. #ifdef TARGET_NR_waitpid
  4025. static void
  4026. print_syscall_ret_waitpid(CPUArchState *cpu_env,
  4027. const struct syscallname *name,
  4028. abi_long ret, abi_long arg0, abi_long arg1,
  4029. abi_long arg2, abi_long arg3, abi_long arg4,
  4030. abi_long arg5)
  4031. {
  4032. print_ret_wstatus(ret, arg1);
  4033. }
  4034. #endif
  4035. /*
  4036. * An array of all of the syscalls we know about
  4037. */
  4038. static const struct syscallname scnames[] = {
  4039. #include "strace.list"
  4040. };
  4041. static int nsyscalls = ARRAY_SIZE(scnames);
  4042. /*
  4043. * The public interface to this module.
  4044. */
  4045. void
  4046. print_syscall(CPUArchState *cpu_env, int num,
  4047. abi_long arg1, abi_long arg2, abi_long arg3,
  4048. abi_long arg4, abi_long arg5, abi_long arg6)
  4049. {
  4050. int i;
  4051. FILE *f;
  4052. const char *format = "%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ","
  4053. TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ","
  4054. TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ")";
  4055. f = qemu_log_trylock();
  4056. if (!f) {
  4057. return;
  4058. }
  4059. fprintf(f, "%d ", get_task_state(env_cpu(cpu_env))->ts_tid);
  4060. for (i = 0; i < nsyscalls; i++) {
  4061. if (scnames[i].nr == num) {
  4062. if (scnames[i].call != NULL) {
  4063. scnames[i].call(cpu_env, &scnames[i], arg1, arg2, arg3,
  4064. arg4, arg5, arg6);
  4065. } else {
  4066. /* XXX: this format system is broken because it uses
  4067. host types and host pointers for strings */
  4068. if (scnames[i].format != NULL) {
  4069. format = scnames[i].format;
  4070. }
  4071. fprintf(f, format, scnames[i].name, arg1, arg2,
  4072. arg3, arg4, arg5, arg6);
  4073. }
  4074. qemu_log_unlock(f);
  4075. return;
  4076. }
  4077. }
  4078. fprintf(f, "Unknown syscall %d\n", num);
  4079. qemu_log_unlock(f);
  4080. }
  4081. void
  4082. print_syscall_ret(CPUArchState *cpu_env, int num, abi_long ret,
  4083. abi_long arg1, abi_long arg2, abi_long arg3,
  4084. abi_long arg4, abi_long arg5, abi_long arg6)
  4085. {
  4086. int i;
  4087. FILE *f;
  4088. f = qemu_log_trylock();
  4089. if (!f) {
  4090. return;
  4091. }
  4092. for (i = 0; i < nsyscalls; i++) {
  4093. if (scnames[i].nr == num) {
  4094. if (scnames[i].result != NULL) {
  4095. scnames[i].result(cpu_env, &scnames[i], ret,
  4096. arg1, arg2, arg3,
  4097. arg4, arg5, arg6);
  4098. } else {
  4099. if (!print_syscall_err(ret)) {
  4100. fprintf(f, TARGET_ABI_FMT_ld, ret);
  4101. }
  4102. fprintf(f, "\n");
  4103. }
  4104. break;
  4105. }
  4106. }
  4107. qemu_log_unlock(f);
  4108. }
  4109. void print_taken_signal(int target_signum, const target_siginfo_t *tinfo)
  4110. {
  4111. /* Print the strace output for a signal being taken:
  4112. * --- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=0} ---
  4113. */
  4114. FILE *f;
  4115. f = qemu_log_trylock();
  4116. if (!f) {
  4117. return;
  4118. }
  4119. fprintf(f, "--- ");
  4120. print_signal(target_signum, 1);
  4121. fprintf(f, " ");
  4122. print_siginfo(tinfo);
  4123. fprintf(f, " ---\n");
  4124. qemu_log_unlock(f);
  4125. }