strace.c 86 KB

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