strace.c 76 KB

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