2
0

strace.c 101 KB

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