strace.c 76 KB

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