2
0

strace.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618
  1. #include <stdio.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/types.h>
  8. #include <sys/mount.h>
  9. #include <sys/mman.h>
  10. #include <unistd.h>
  11. #include <sched.h>
  12. #include "qemu.h"
  13. int do_strace=0;
  14. struct syscallname {
  15. int nr;
  16. const char *name;
  17. const char *format;
  18. void (*call)(const struct syscallname *,
  19. abi_long, abi_long, abi_long,
  20. abi_long, abi_long, abi_long);
  21. void (*result)(const struct syscallname *, abi_long);
  22. };
  23. #ifdef __GNUC__
  24. /*
  25. * It is possible that target doesn't have syscall that uses
  26. * following flags but we don't want the compiler to warn
  27. * us about them being unused. Same applies to utility print
  28. * functions. It is ok to keep them while not used.
  29. */
  30. #define UNUSED __attribute__ ((unused))
  31. #else
  32. #define UNUSED
  33. #endif
  34. /*
  35. * Structure used to translate flag values into strings. This is
  36. * similar that is in the actual strace tool.
  37. */
  38. struct flags {
  39. abi_long f_value; /* flag */
  40. const char *f_string; /* stringified flag */
  41. };
  42. /* common flags for all architectures */
  43. #define FLAG_GENERIC(name) { name, #name }
  44. /* target specific flags (syscall_defs.h has TARGET_<flag>) */
  45. #define FLAG_TARGET(name) { TARGET_ ## name, #name }
  46. /* end of flags array */
  47. #define FLAG_END { 0, NULL }
  48. UNUSED static const char *get_comma(int);
  49. UNUSED static void print_pointer(abi_long, int);
  50. UNUSED static void print_flags(const struct flags *, abi_long, int);
  51. UNUSED static void print_at_dirfd(abi_long, int);
  52. UNUSED static void print_file_mode(abi_long, int);
  53. UNUSED static void print_open_flags(abi_long, int);
  54. UNUSED static void print_syscall_prologue(const struct syscallname *);
  55. UNUSED static void print_syscall_epilogue(const struct syscallname *);
  56. UNUSED static void print_string(abi_long, int);
  57. UNUSED static void print_raw_param(const char *, abi_long, int);
  58. UNUSED static void print_timeval(abi_ulong, int);
  59. UNUSED static void print_number(abi_long, int);
  60. UNUSED static void print_signal(abi_ulong, int);
  61. /*
  62. * Utility functions
  63. */
  64. static void
  65. print_ipc_cmd(int cmd)
  66. {
  67. #define output_cmd(val) \
  68. if( cmd == val ) { \
  69. gemu_log(#val); \
  70. return; \
  71. }
  72. cmd &= 0xff;
  73. /* General IPC commands */
  74. output_cmd( IPC_RMID );
  75. output_cmd( IPC_SET );
  76. output_cmd( IPC_STAT );
  77. output_cmd( IPC_INFO );
  78. /* msgctl() commands */
  79. #ifdef __USER_MISC
  80. output_cmd( MSG_STAT );
  81. output_cmd( MSG_INFO );
  82. #endif
  83. /* shmctl() commands */
  84. output_cmd( SHM_LOCK );
  85. output_cmd( SHM_UNLOCK );
  86. output_cmd( SHM_STAT );
  87. output_cmd( SHM_INFO );
  88. /* semctl() commands */
  89. output_cmd( GETPID );
  90. output_cmd( GETVAL );
  91. output_cmd( GETALL );
  92. output_cmd( GETNCNT );
  93. output_cmd( GETZCNT );
  94. output_cmd( SETVAL );
  95. output_cmd( SETALL );
  96. output_cmd( SEM_STAT );
  97. output_cmd( SEM_INFO );
  98. output_cmd( IPC_RMID );
  99. output_cmd( IPC_RMID );
  100. output_cmd( IPC_RMID );
  101. output_cmd( IPC_RMID );
  102. output_cmd( IPC_RMID );
  103. output_cmd( IPC_RMID );
  104. output_cmd( IPC_RMID );
  105. output_cmd( IPC_RMID );
  106. output_cmd( IPC_RMID );
  107. /* Some value we don't recognize */
  108. gemu_log("%d",cmd);
  109. }
  110. static void
  111. print_signal(abi_ulong arg, int last)
  112. {
  113. const char *signal_name = NULL;
  114. switch(arg) {
  115. case TARGET_SIGHUP: signal_name = "SIGHUP"; break;
  116. case TARGET_SIGINT: signal_name = "SIGINT"; break;
  117. case TARGET_SIGQUIT: signal_name = "SIGQUIT"; break;
  118. case TARGET_SIGILL: signal_name = "SIGILL"; break;
  119. case TARGET_SIGABRT: signal_name = "SIGABRT"; break;
  120. case TARGET_SIGFPE: signal_name = "SIGFPE"; break;
  121. case TARGET_SIGKILL: signal_name = "SIGKILL"; break;
  122. case TARGET_SIGSEGV: signal_name = "SIGSEGV"; break;
  123. case TARGET_SIGPIPE: signal_name = "SIGPIPE"; break;
  124. case TARGET_SIGALRM: signal_name = "SIGALRM"; break;
  125. case TARGET_SIGTERM: signal_name = "SIGTERM"; break;
  126. case TARGET_SIGUSR1: signal_name = "SIGUSR1"; break;
  127. case TARGET_SIGUSR2: signal_name = "SIGUSR2"; break;
  128. case TARGET_SIGCHLD: signal_name = "SIGCHLD"; break;
  129. case TARGET_SIGCONT: signal_name = "SIGCONT"; break;
  130. case TARGET_SIGSTOP: signal_name = "SIGSTOP"; break;
  131. case TARGET_SIGTTIN: signal_name = "SIGTTIN"; break;
  132. case TARGET_SIGTTOU: signal_name = "SIGTTOU"; break;
  133. }
  134. if (signal_name == NULL) {
  135. print_raw_param("%ld", arg, last);
  136. return;
  137. }
  138. gemu_log("%s%s", signal_name, get_comma(last));
  139. }
  140. #ifdef TARGET_NR__newselect
  141. static void
  142. print_fdset(int n, abi_ulong target_fds_addr)
  143. {
  144. int i;
  145. gemu_log("[");
  146. if( target_fds_addr ) {
  147. abi_long *target_fds;
  148. target_fds = lock_user(VERIFY_READ,
  149. target_fds_addr,
  150. sizeof(*target_fds)*(n / TARGET_ABI_BITS + 1),
  151. 1);
  152. if (!target_fds)
  153. return;
  154. for (i=n; i>=0; i--) {
  155. if ((tswapal(target_fds[i / TARGET_ABI_BITS]) >> (i & (TARGET_ABI_BITS - 1))) & 1)
  156. gemu_log("%d,", i );
  157. }
  158. unlock_user(target_fds, target_fds_addr, 0);
  159. }
  160. gemu_log("]");
  161. }
  162. #endif
  163. /*
  164. * Sysycall specific output functions
  165. */
  166. /* select */
  167. #ifdef TARGET_NR__newselect
  168. static long newselect_arg1 = 0;
  169. static long newselect_arg2 = 0;
  170. static long newselect_arg3 = 0;
  171. static long newselect_arg4 = 0;
  172. static long newselect_arg5 = 0;
  173. static void
  174. print_newselect(const struct syscallname *name,
  175. abi_long arg1, abi_long arg2, abi_long arg3,
  176. abi_long arg4, abi_long arg5, abi_long arg6)
  177. {
  178. gemu_log("%s(" TARGET_ABI_FMT_ld ",", name->name, arg1);
  179. print_fdset(arg1, arg2);
  180. gemu_log(",");
  181. print_fdset(arg1, arg3);
  182. gemu_log(",");
  183. print_fdset(arg1, arg4);
  184. gemu_log(",");
  185. print_timeval(arg5, 1);
  186. gemu_log(")");
  187. /* save for use in the return output function below */
  188. newselect_arg1=arg1;
  189. newselect_arg2=arg2;
  190. newselect_arg3=arg3;
  191. newselect_arg4=arg4;
  192. newselect_arg5=arg5;
  193. }
  194. #endif
  195. #ifdef TARGET_NR_semctl
  196. static void
  197. print_semctl(const struct syscallname *name,
  198. abi_long arg1, abi_long arg2, abi_long arg3,
  199. abi_long arg4, abi_long arg5, abi_long arg6)
  200. {
  201. gemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",", name->name, arg1, arg2);
  202. print_ipc_cmd(arg3);
  203. gemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
  204. }
  205. #endif
  206. static void
  207. print_execve(const struct syscallname *name,
  208. abi_long arg1, abi_long arg2, abi_long arg3,
  209. abi_long arg4, abi_long arg5, abi_long arg6)
  210. {
  211. abi_ulong arg_ptr_addr;
  212. char *s;
  213. if (!(s = lock_user_string(arg1)))
  214. return;
  215. gemu_log("%s(\"%s\",{", name->name, s);
  216. unlock_user(s, arg1, 0);
  217. for (arg_ptr_addr = arg2; ; arg_ptr_addr += sizeof(abi_ulong)) {
  218. abi_ulong *arg_ptr, arg_addr;
  219. arg_ptr = lock_user(VERIFY_READ, arg_ptr_addr, sizeof(abi_ulong), 1);
  220. if (!arg_ptr)
  221. return;
  222. arg_addr = tswapal(*arg_ptr);
  223. unlock_user(arg_ptr, arg_ptr_addr, 0);
  224. if (!arg_addr)
  225. break;
  226. if ((s = lock_user_string(arg_addr))) {
  227. gemu_log("\"%s\",", s);
  228. unlock_user(s, arg_addr, 0);
  229. }
  230. }
  231. gemu_log("NULL})");
  232. }
  233. #ifdef TARGET_NR_ipc
  234. static void
  235. print_ipc(const struct syscallname *name,
  236. abi_long arg1, abi_long arg2, abi_long arg3,
  237. abi_long arg4, abi_long arg5, abi_long arg6)
  238. {
  239. switch(arg1) {
  240. case IPCOP_semctl:
  241. gemu_log("semctl(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",", arg1, arg2);
  242. print_ipc_cmd(arg3);
  243. gemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
  244. break;
  245. default:
  246. gemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ")",
  247. name->name, arg1, arg2, arg3, arg4);
  248. }
  249. }
  250. #endif
  251. /*
  252. * Variants for the return value output function
  253. */
  254. static void
  255. print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
  256. {
  257. char *errstr = NULL;
  258. if (ret < 0) {
  259. errstr = target_strerror(-ret);
  260. }
  261. if (errstr) {
  262. gemu_log(" = -1 errno=%d (%s)\n", (int)-ret, errstr);
  263. } else {
  264. gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
  265. }
  266. }
  267. #if 0 /* currently unused */
  268. static void
  269. print_syscall_ret_raw(struct syscallname *name, abi_long ret)
  270. {
  271. gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
  272. }
  273. #endif
  274. #ifdef TARGET_NR__newselect
  275. static void
  276. print_syscall_ret_newselect(const struct syscallname *name, abi_long ret)
  277. {
  278. gemu_log(" = 0x" TARGET_ABI_FMT_lx " (", ret);
  279. print_fdset(newselect_arg1,newselect_arg2);
  280. gemu_log(",");
  281. print_fdset(newselect_arg1,newselect_arg3);
  282. gemu_log(",");
  283. print_fdset(newselect_arg1,newselect_arg4);
  284. gemu_log(",");
  285. print_timeval(newselect_arg5, 1);
  286. gemu_log(")\n");
  287. }
  288. #endif
  289. UNUSED static struct flags access_flags[] = {
  290. FLAG_GENERIC(F_OK),
  291. FLAG_GENERIC(R_OK),
  292. FLAG_GENERIC(W_OK),
  293. FLAG_GENERIC(X_OK),
  294. FLAG_END,
  295. };
  296. UNUSED static struct flags at_file_flags[] = {
  297. #ifdef AT_EACCESS
  298. FLAG_GENERIC(AT_EACCESS),
  299. #endif
  300. #ifdef AT_SYMLINK_NOFOLLOW
  301. FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
  302. #endif
  303. FLAG_END,
  304. };
  305. UNUSED static struct flags unlinkat_flags[] = {
  306. #ifdef AT_REMOVEDIR
  307. FLAG_GENERIC(AT_REMOVEDIR),
  308. #endif
  309. FLAG_END,
  310. };
  311. UNUSED static struct flags mode_flags[] = {
  312. FLAG_GENERIC(S_IFSOCK),
  313. FLAG_GENERIC(S_IFLNK),
  314. FLAG_GENERIC(S_IFREG),
  315. FLAG_GENERIC(S_IFBLK),
  316. FLAG_GENERIC(S_IFDIR),
  317. FLAG_GENERIC(S_IFCHR),
  318. FLAG_GENERIC(S_IFIFO),
  319. FLAG_END,
  320. };
  321. UNUSED static struct flags open_access_flags[] = {
  322. FLAG_TARGET(O_RDONLY),
  323. FLAG_TARGET(O_WRONLY),
  324. FLAG_TARGET(O_RDWR),
  325. FLAG_END,
  326. };
  327. UNUSED static struct flags open_flags[] = {
  328. FLAG_TARGET(O_APPEND),
  329. FLAG_TARGET(O_CREAT),
  330. FLAG_TARGET(O_DIRECTORY),
  331. FLAG_TARGET(O_EXCL),
  332. FLAG_TARGET(O_LARGEFILE),
  333. FLAG_TARGET(O_NOCTTY),
  334. FLAG_TARGET(O_NOFOLLOW),
  335. FLAG_TARGET(O_NONBLOCK), /* also O_NDELAY */
  336. FLAG_TARGET(O_DSYNC),
  337. FLAG_TARGET(__O_SYNC),
  338. FLAG_TARGET(O_TRUNC),
  339. #ifdef O_DIRECT
  340. FLAG_TARGET(O_DIRECT),
  341. #endif
  342. #ifdef O_NOATIME
  343. FLAG_TARGET(O_NOATIME),
  344. #endif
  345. #ifdef O_CLOEXEC
  346. FLAG_TARGET(O_CLOEXEC),
  347. #endif
  348. #ifdef O_PATH
  349. FLAG_TARGET(O_PATH),
  350. #endif
  351. FLAG_END,
  352. };
  353. UNUSED static struct flags mount_flags[] = {
  354. #ifdef MS_BIND
  355. FLAG_GENERIC(MS_BIND),
  356. #endif
  357. #ifdef MS_DIRSYNC
  358. FLAG_GENERIC(MS_DIRSYNC),
  359. #endif
  360. FLAG_GENERIC(MS_MANDLOCK),
  361. #ifdef MS_MOVE
  362. FLAG_GENERIC(MS_MOVE),
  363. #endif
  364. FLAG_GENERIC(MS_NOATIME),
  365. FLAG_GENERIC(MS_NODEV),
  366. FLAG_GENERIC(MS_NODIRATIME),
  367. FLAG_GENERIC(MS_NOEXEC),
  368. FLAG_GENERIC(MS_NOSUID),
  369. FLAG_GENERIC(MS_RDONLY),
  370. #ifdef MS_RELATIME
  371. FLAG_GENERIC(MS_RELATIME),
  372. #endif
  373. FLAG_GENERIC(MS_REMOUNT),
  374. FLAG_GENERIC(MS_SYNCHRONOUS),
  375. FLAG_END,
  376. };
  377. UNUSED static struct flags umount2_flags[] = {
  378. #ifdef MNT_FORCE
  379. FLAG_GENERIC(MNT_FORCE),
  380. #endif
  381. #ifdef MNT_DETACH
  382. FLAG_GENERIC(MNT_DETACH),
  383. #endif
  384. #ifdef MNT_EXPIRE
  385. FLAG_GENERIC(MNT_EXPIRE),
  386. #endif
  387. FLAG_END,
  388. };
  389. UNUSED static struct flags mmap_prot_flags[] = {
  390. FLAG_GENERIC(PROT_NONE),
  391. FLAG_GENERIC(PROT_EXEC),
  392. FLAG_GENERIC(PROT_READ),
  393. FLAG_GENERIC(PROT_WRITE),
  394. FLAG_TARGET(PROT_SEM),
  395. FLAG_GENERIC(PROT_GROWSDOWN),
  396. FLAG_GENERIC(PROT_GROWSUP),
  397. FLAG_END,
  398. };
  399. UNUSED static struct flags mmap_flags[] = {
  400. FLAG_TARGET(MAP_SHARED),
  401. FLAG_TARGET(MAP_PRIVATE),
  402. FLAG_TARGET(MAP_ANONYMOUS),
  403. FLAG_TARGET(MAP_DENYWRITE),
  404. FLAG_TARGET(MAP_FIXED),
  405. FLAG_TARGET(MAP_GROWSDOWN),
  406. FLAG_TARGET(MAP_EXECUTABLE),
  407. #ifdef MAP_LOCKED
  408. FLAG_TARGET(MAP_LOCKED),
  409. #endif
  410. #ifdef MAP_NONBLOCK
  411. FLAG_TARGET(MAP_NONBLOCK),
  412. #endif
  413. FLAG_TARGET(MAP_NORESERVE),
  414. #ifdef MAP_POPULATE
  415. FLAG_TARGET(MAP_POPULATE),
  416. #endif
  417. #ifdef TARGET_MAP_UNINITIALIZED
  418. FLAG_TARGET(MAP_UNINITIALIZED),
  419. #endif
  420. FLAG_END,
  421. };
  422. UNUSED static struct flags clone_flags[] = {
  423. FLAG_GENERIC(CLONE_VM),
  424. FLAG_GENERIC(CLONE_FS),
  425. FLAG_GENERIC(CLONE_FILES),
  426. FLAG_GENERIC(CLONE_SIGHAND),
  427. FLAG_GENERIC(CLONE_PTRACE),
  428. FLAG_GENERIC(CLONE_VFORK),
  429. FLAG_GENERIC(CLONE_PARENT),
  430. FLAG_GENERIC(CLONE_THREAD),
  431. FLAG_GENERIC(CLONE_NEWNS),
  432. FLAG_GENERIC(CLONE_SYSVSEM),
  433. FLAG_GENERIC(CLONE_SETTLS),
  434. FLAG_GENERIC(CLONE_PARENT_SETTID),
  435. FLAG_GENERIC(CLONE_CHILD_CLEARTID),
  436. FLAG_GENERIC(CLONE_DETACHED),
  437. FLAG_GENERIC(CLONE_UNTRACED),
  438. FLAG_GENERIC(CLONE_CHILD_SETTID),
  439. #if defined(CLONE_NEWUTS)
  440. FLAG_GENERIC(CLONE_NEWUTS),
  441. #endif
  442. #if defined(CLONE_NEWIPC)
  443. FLAG_GENERIC(CLONE_NEWIPC),
  444. #endif
  445. #if defined(CLONE_NEWUSER)
  446. FLAG_GENERIC(CLONE_NEWUSER),
  447. #endif
  448. #if defined(CLONE_NEWPID)
  449. FLAG_GENERIC(CLONE_NEWPID),
  450. #endif
  451. #if defined(CLONE_NEWNET)
  452. FLAG_GENERIC(CLONE_NEWNET),
  453. #endif
  454. #if defined(CLONE_IO)
  455. FLAG_GENERIC(CLONE_IO),
  456. #endif
  457. FLAG_END,
  458. };
  459. /*
  460. * print_xxx utility functions. These are used to print syscall
  461. * parameters in certain format. All of these have parameter
  462. * named 'last'. This parameter is used to add comma to output
  463. * when last == 0.
  464. */
  465. static const char *
  466. get_comma(int last)
  467. {
  468. return ((last) ? "" : ",");
  469. }
  470. static void
  471. print_flags(const struct flags *f, abi_long flags, int last)
  472. {
  473. const char *sep = "";
  474. int n;
  475. if ((flags == 0) && (f->f_value == 0)) {
  476. gemu_log("%s%s", f->f_string, get_comma(last));
  477. return;
  478. }
  479. for (n = 0; f->f_string != NULL; f++) {
  480. if ((f->f_value != 0) && ((flags & f->f_value) == f->f_value)) {
  481. gemu_log("%s%s", sep, f->f_string);
  482. flags &= ~f->f_value;
  483. sep = "|";
  484. n++;
  485. }
  486. }
  487. if (n > 0) {
  488. /* print rest of the flags as numeric */
  489. if (flags != 0) {
  490. gemu_log("%s%#x%s", sep, (unsigned int)flags, get_comma(last));
  491. } else {
  492. gemu_log("%s", get_comma(last));
  493. }
  494. } else {
  495. /* no string version of flags found, print them in hex then */
  496. gemu_log("%#x%s", (unsigned int)flags, get_comma(last));
  497. }
  498. }
  499. static void
  500. print_at_dirfd(abi_long dirfd, int last)
  501. {
  502. #ifdef AT_FDCWD
  503. if (dirfd == AT_FDCWD) {
  504. gemu_log("AT_FDCWD%s", get_comma(last));
  505. return;
  506. }
  507. #endif
  508. gemu_log("%d%s", (int)dirfd, get_comma(last));
  509. }
  510. static void
  511. print_file_mode(abi_long mode, int last)
  512. {
  513. const char *sep = "";
  514. const struct flags *m;
  515. for (m = &mode_flags[0]; m->f_string != NULL; m++) {
  516. if ((m->f_value & mode) == m->f_value) {
  517. gemu_log("%s%s", m->f_string, sep);
  518. sep = "|";
  519. mode &= ~m->f_value;
  520. break;
  521. }
  522. }
  523. mode &= ~S_IFMT;
  524. /* print rest of the mode as octal */
  525. if (mode != 0)
  526. gemu_log("%s%#o", sep, (unsigned int)mode);
  527. gemu_log("%s", get_comma(last));
  528. }
  529. static void
  530. print_open_flags(abi_long flags, int last)
  531. {
  532. print_flags(open_access_flags, flags & TARGET_O_ACCMODE, 1);
  533. flags &= ~TARGET_O_ACCMODE;
  534. if (flags == 0) {
  535. gemu_log("%s", get_comma(last));
  536. return;
  537. }
  538. gemu_log("|");
  539. print_flags(open_flags, flags, last);
  540. }
  541. static void
  542. print_syscall_prologue(const struct syscallname *sc)
  543. {
  544. gemu_log("%s(", sc->name);
  545. }
  546. /*ARGSUSED*/
  547. static void
  548. print_syscall_epilogue(const struct syscallname *sc)
  549. {
  550. (void)sc;
  551. gemu_log(")");
  552. }
  553. static void
  554. print_string(abi_long addr, int last)
  555. {
  556. char *s;
  557. if ((s = lock_user_string(addr)) != NULL) {
  558. gemu_log("\"%s\"%s", s, get_comma(last));
  559. unlock_user(s, addr, 0);
  560. } else {
  561. /* can't get string out of it, so print it as pointer */
  562. print_pointer(addr, last);
  563. }
  564. }
  565. /*
  566. * Prints out raw parameter using given format. Caller needs
  567. * to do byte swapping if needed.
  568. */
  569. static void
  570. print_raw_param(const char *fmt, abi_long param, int last)
  571. {
  572. char format[64];
  573. (void) snprintf(format, sizeof (format), "%s%s", fmt, get_comma(last));
  574. gemu_log(format, param);
  575. }
  576. static void
  577. print_pointer(abi_long p, int last)
  578. {
  579. if (p == 0)
  580. gemu_log("NULL%s", get_comma(last));
  581. else
  582. gemu_log("0x" TARGET_ABI_FMT_lx "%s", p, get_comma(last));
  583. }
  584. /*
  585. * Reads 32-bit (int) number from guest address space from
  586. * address 'addr' and prints it.
  587. */
  588. static void
  589. print_number(abi_long addr, int last)
  590. {
  591. if (addr == 0) {
  592. gemu_log("NULL%s", get_comma(last));
  593. } else {
  594. int num;
  595. get_user_s32(num, addr);
  596. gemu_log("[%d]%s", num, get_comma(last));
  597. }
  598. }
  599. static void
  600. print_timeval(abi_ulong tv_addr, int last)
  601. {
  602. if( tv_addr ) {
  603. struct target_timeval *tv;
  604. tv = lock_user(VERIFY_READ, tv_addr, sizeof(*tv), 1);
  605. if (!tv)
  606. return;
  607. gemu_log("{" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "}%s",
  608. tswapal(tv->tv_sec), tswapal(tv->tv_usec), get_comma(last));
  609. unlock_user(tv, tv_addr, 0);
  610. } else
  611. gemu_log("NULL%s", get_comma(last));
  612. }
  613. #undef UNUSED
  614. #ifdef TARGET_NR_accept
  615. static void
  616. print_accept(const struct syscallname *name,
  617. abi_long arg0, abi_long arg1, abi_long arg2,
  618. abi_long arg3, abi_long arg4, abi_long arg5)
  619. {
  620. print_syscall_prologue(name);
  621. print_raw_param("%d", arg0, 0);
  622. print_pointer(arg1, 0);
  623. print_number(arg2, 1);
  624. print_syscall_epilogue(name);
  625. }
  626. #endif
  627. #ifdef TARGET_NR_access
  628. static void
  629. print_access(const struct syscallname *name,
  630. abi_long arg0, abi_long arg1, abi_long arg2,
  631. abi_long arg3, abi_long arg4, abi_long arg5)
  632. {
  633. print_syscall_prologue(name);
  634. print_string(arg0, 0);
  635. print_flags(access_flags, arg1, 1);
  636. print_syscall_epilogue(name);
  637. }
  638. #endif
  639. #ifdef TARGET_NR_brk
  640. static void
  641. print_brk(const struct syscallname *name,
  642. abi_long arg0, abi_long arg1, abi_long arg2,
  643. abi_long arg3, abi_long arg4, abi_long arg5)
  644. {
  645. print_syscall_prologue(name);
  646. print_pointer(arg0, 1);
  647. print_syscall_epilogue(name);
  648. }
  649. #endif
  650. #ifdef TARGET_NR_chdir
  651. static void
  652. print_chdir(const struct syscallname *name,
  653. abi_long arg0, abi_long arg1, abi_long arg2,
  654. abi_long arg3, abi_long arg4, abi_long arg5)
  655. {
  656. print_syscall_prologue(name);
  657. print_string(arg0, 1);
  658. print_syscall_epilogue(name);
  659. }
  660. #endif
  661. #ifdef TARGET_NR_chmod
  662. static void
  663. print_chmod(const struct syscallname *name,
  664. abi_long arg0, abi_long arg1, abi_long arg2,
  665. abi_long arg3, abi_long arg4, abi_long arg5)
  666. {
  667. print_syscall_prologue(name);
  668. print_string(arg0, 0);
  669. print_file_mode(arg1, 1);
  670. print_syscall_epilogue(name);
  671. }
  672. #endif
  673. #ifdef TARGET_NR_clone
  674. static void
  675. print_clone(const struct syscallname *name,
  676. abi_long arg0, abi_long arg1, abi_long arg2,
  677. abi_long arg3, abi_long arg4, abi_long arg5)
  678. {
  679. print_syscall_prologue(name);
  680. #if defined(TARGET_M68K)
  681. print_flags(clone_flags, arg0, 0);
  682. print_raw_param("newsp=0x" TARGET_ABI_FMT_lx, arg1, 1);
  683. #elif defined(TARGET_SH4) || defined(TARGET_ALPHA)
  684. print_flags(clone_flags, arg0, 0);
  685. print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, arg1, 0);
  686. print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, arg2, 0);
  687. print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, arg3, 0);
  688. print_raw_param("tls=0x" TARGET_ABI_FMT_lx, arg4, 1);
  689. #elif defined(TARGET_CRIS)
  690. print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, arg0, 0);
  691. print_flags(clone_flags, arg1, 0);
  692. print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, arg2, 0);
  693. print_raw_param("tls=0x" TARGET_ABI_FMT_lx, arg3, 0);
  694. print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, arg4, 1);
  695. #else
  696. print_flags(clone_flags, arg0, 0);
  697. print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, arg1, 0);
  698. print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, arg2, 0);
  699. print_raw_param("tls=0x" TARGET_ABI_FMT_lx, arg3, 0);
  700. print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, arg4, 1);
  701. #endif
  702. print_syscall_epilogue(name);
  703. }
  704. #endif
  705. #ifdef TARGET_NR_creat
  706. static void
  707. print_creat(const struct syscallname *name,
  708. abi_long arg0, abi_long arg1, abi_long arg2,
  709. abi_long arg3, abi_long arg4, abi_long arg5)
  710. {
  711. print_syscall_prologue(name);
  712. print_string(arg0, 0);
  713. print_file_mode(arg1, 1);
  714. print_syscall_epilogue(name);
  715. }
  716. #endif
  717. #ifdef TARGET_NR_execv
  718. static void
  719. print_execv(const struct syscallname *name,
  720. abi_long arg0, abi_long arg1, abi_long arg2,
  721. abi_long arg3, abi_long arg4, abi_long arg5)
  722. {
  723. print_syscall_prologue(name);
  724. print_string(arg0, 0);
  725. print_raw_param("0x" TARGET_ABI_FMT_lx, arg1, 1);
  726. print_syscall_epilogue(name);
  727. }
  728. #endif
  729. #ifdef TARGET_NR_faccessat
  730. static void
  731. print_faccessat(const struct syscallname *name,
  732. abi_long arg0, abi_long arg1, abi_long arg2,
  733. abi_long arg3, abi_long arg4, abi_long arg5)
  734. {
  735. print_syscall_prologue(name);
  736. print_at_dirfd(arg0, 0);
  737. print_string(arg1, 0);
  738. print_flags(access_flags, arg2, 0);
  739. print_flags(at_file_flags, arg3, 1);
  740. print_syscall_epilogue(name);
  741. }
  742. #endif
  743. #ifdef TARGET_NR_fchmodat
  744. static void
  745. print_fchmodat(const struct syscallname *name,
  746. abi_long arg0, abi_long arg1, abi_long arg2,
  747. abi_long arg3, abi_long arg4, abi_long arg5)
  748. {
  749. print_syscall_prologue(name);
  750. print_at_dirfd(arg0, 0);
  751. print_string(arg1, 0);
  752. print_file_mode(arg2, 0);
  753. print_flags(at_file_flags, arg3, 1);
  754. print_syscall_epilogue(name);
  755. }
  756. #endif
  757. #ifdef TARGET_NR_fchownat
  758. static void
  759. print_fchownat(const struct syscallname *name,
  760. abi_long arg0, abi_long arg1, abi_long arg2,
  761. abi_long arg3, abi_long arg4, abi_long arg5)
  762. {
  763. print_syscall_prologue(name);
  764. print_at_dirfd(arg0, 0);
  765. print_string(arg1, 0);
  766. print_raw_param("%d", arg2, 0);
  767. print_raw_param("%d", arg3, 0);
  768. print_flags(at_file_flags, arg4, 1);
  769. print_syscall_epilogue(name);
  770. }
  771. #endif
  772. #if defined(TARGET_NR_fcntl) || defined(TARGET_NR_fcntl64)
  773. static void
  774. print_fcntl(const struct syscallname *name,
  775. abi_long arg0, abi_long arg1, abi_long arg2,
  776. abi_long arg3, abi_long arg4, abi_long arg5)
  777. {
  778. print_syscall_prologue(name);
  779. print_raw_param("%d", arg0, 0);
  780. switch(arg1) {
  781. case TARGET_F_DUPFD:
  782. gemu_log("F_DUPFD,");
  783. print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
  784. break;
  785. case TARGET_F_GETFD:
  786. gemu_log("F_GETFD");
  787. break;
  788. case TARGET_F_SETFD:
  789. gemu_log("F_SETFD,");
  790. print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
  791. break;
  792. case TARGET_F_GETFL:
  793. gemu_log("F_GETFL");
  794. break;
  795. case TARGET_F_SETFL:
  796. gemu_log("F_SETFL,");
  797. print_open_flags(arg2, 1);
  798. break;
  799. case TARGET_F_GETLK:
  800. gemu_log("F_GETLK,");
  801. print_pointer(arg2, 1);
  802. break;
  803. case TARGET_F_SETLK:
  804. gemu_log("F_SETLK,");
  805. print_pointer(arg2, 1);
  806. break;
  807. case TARGET_F_SETLKW:
  808. gemu_log("F_SETLKW,");
  809. print_pointer(arg2, 1);
  810. break;
  811. case TARGET_F_GETOWN:
  812. gemu_log("F_GETOWN");
  813. break;
  814. case TARGET_F_SETOWN:
  815. gemu_log("F_SETOWN,");
  816. print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
  817. break;
  818. case TARGET_F_GETSIG:
  819. gemu_log("F_GETSIG");
  820. break;
  821. case TARGET_F_SETSIG:
  822. gemu_log("F_SETSIG,");
  823. print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
  824. break;
  825. #if TARGET_ABI_BITS == 32
  826. case TARGET_F_GETLK64:
  827. gemu_log("F_GETLK64,");
  828. print_pointer(arg2, 1);
  829. break;
  830. case TARGET_F_SETLK64:
  831. gemu_log("F_SETLK64,");
  832. print_pointer(arg2, 1);
  833. break;
  834. case TARGET_F_SETLKW64:
  835. gemu_log("F_SETLKW64,");
  836. print_pointer(arg2, 1);
  837. break;
  838. #endif
  839. case TARGET_F_SETLEASE:
  840. gemu_log("F_SETLEASE,");
  841. print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
  842. break;
  843. case TARGET_F_GETLEASE:
  844. gemu_log("F_GETLEASE");
  845. break;
  846. case TARGET_F_DUPFD_CLOEXEC:
  847. gemu_log("F_DUPFD_CLOEXEC,");
  848. print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
  849. break;
  850. case TARGET_F_NOTIFY:
  851. gemu_log("F_NOTIFY,");
  852. print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
  853. break;
  854. default:
  855. print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
  856. print_pointer(arg2, 1);
  857. break;
  858. }
  859. print_syscall_epilogue(name);
  860. }
  861. #define print_fcntl64 print_fcntl
  862. #endif
  863. #ifdef TARGET_NR_futimesat
  864. static void
  865. print_futimesat(const struct syscallname *name,
  866. abi_long arg0, abi_long arg1, abi_long arg2,
  867. abi_long arg3, abi_long arg4, abi_long arg5)
  868. {
  869. print_syscall_prologue(name);
  870. print_at_dirfd(arg0, 0);
  871. print_string(arg1, 0);
  872. print_timeval(arg2, 0);
  873. print_timeval(arg2 + sizeof (struct target_timeval), 1);
  874. print_syscall_epilogue(name);
  875. }
  876. #endif
  877. #ifdef TARGET_NR_link
  878. static void
  879. print_link(const struct syscallname *name,
  880. abi_long arg0, abi_long arg1, abi_long arg2,
  881. abi_long arg3, abi_long arg4, abi_long arg5)
  882. {
  883. print_syscall_prologue(name);
  884. print_string(arg0, 0);
  885. print_string(arg1, 1);
  886. print_syscall_epilogue(name);
  887. }
  888. #endif
  889. #ifdef TARGET_NR_linkat
  890. static void
  891. print_linkat(const struct syscallname *name,
  892. abi_long arg0, abi_long arg1, abi_long arg2,
  893. abi_long arg3, abi_long arg4, abi_long arg5)
  894. {
  895. print_syscall_prologue(name);
  896. print_at_dirfd(arg0, 0);
  897. print_string(arg1, 0);
  898. print_at_dirfd(arg2, 0);
  899. print_string(arg3, 0);
  900. print_flags(at_file_flags, arg4, 1);
  901. print_syscall_epilogue(name);
  902. }
  903. #endif
  904. #ifdef TARGET_NR__llseek
  905. static void
  906. print__llseek(const struct syscallname *name,
  907. abi_long arg0, abi_long arg1, abi_long arg2,
  908. abi_long arg3, abi_long arg4, abi_long arg5)
  909. {
  910. const char *whence = "UNKNOWN";
  911. print_syscall_prologue(name);
  912. print_raw_param("%d", arg0, 0);
  913. print_raw_param("%ld", arg1, 0);
  914. print_raw_param("%ld", arg2, 0);
  915. print_pointer(arg3, 0);
  916. switch(arg4) {
  917. case SEEK_SET: whence = "SEEK_SET"; break;
  918. case SEEK_CUR: whence = "SEEK_CUR"; break;
  919. case SEEK_END: whence = "SEEK_END"; break;
  920. }
  921. gemu_log("%s",whence);
  922. print_syscall_epilogue(name);
  923. }
  924. #endif
  925. #if defined(TARGET_NR_stat) || defined(TARGET_NR_stat64) || \
  926. defined(TARGET_NR_lstat) || defined(TARGET_NR_lstat64)
  927. static void
  928. print_stat(const struct syscallname *name,
  929. abi_long arg0, abi_long arg1, abi_long arg2,
  930. abi_long arg3, abi_long arg4, abi_long arg5)
  931. {
  932. print_syscall_prologue(name);
  933. print_string(arg0, 0);
  934. print_pointer(arg1, 1);
  935. print_syscall_epilogue(name);
  936. }
  937. #define print_lstat print_stat
  938. #define print_stat64 print_stat
  939. #define print_lstat64 print_stat
  940. #endif
  941. #if defined(TARGET_NR_fstat) || defined(TARGET_NR_fstat64)
  942. static void
  943. print_fstat(const struct syscallname *name,
  944. abi_long arg0, abi_long arg1, abi_long arg2,
  945. abi_long arg3, abi_long arg4, abi_long arg5)
  946. {
  947. print_syscall_prologue(name);
  948. print_raw_param("%d", arg0, 0);
  949. print_pointer(arg1, 1);
  950. print_syscall_epilogue(name);
  951. }
  952. #define print_fstat64 print_fstat
  953. #endif
  954. #ifdef TARGET_NR_mkdir
  955. static void
  956. print_mkdir(const struct syscallname *name,
  957. abi_long arg0, abi_long arg1, abi_long arg2,
  958. abi_long arg3, abi_long arg4, abi_long arg5)
  959. {
  960. print_syscall_prologue(name);
  961. print_string(arg0, 0);
  962. print_file_mode(arg1, 1);
  963. print_syscall_epilogue(name);
  964. }
  965. #endif
  966. #ifdef TARGET_NR_mkdirat
  967. static void
  968. print_mkdirat(const struct syscallname *name,
  969. abi_long arg0, abi_long arg1, abi_long arg2,
  970. abi_long arg3, abi_long arg4, abi_long arg5)
  971. {
  972. print_syscall_prologue(name);
  973. print_at_dirfd(arg0, 0);
  974. print_string(arg1, 0);
  975. print_file_mode(arg2, 1);
  976. print_syscall_epilogue(name);
  977. }
  978. #endif
  979. #ifdef TARGET_NR_rmdir
  980. static void
  981. print_rmdir(const struct syscallname *name,
  982. abi_long arg0, abi_long arg1, abi_long arg2,
  983. abi_long arg3, abi_long arg4, abi_long arg5)
  984. {
  985. print_syscall_prologue(name);
  986. print_string(arg0, 0);
  987. print_syscall_epilogue(name);
  988. }
  989. #endif
  990. #ifdef TARGET_NR_rt_sigaction
  991. static void
  992. print_rt_sigaction(const struct syscallname *name,
  993. abi_long arg0, abi_long arg1, abi_long arg2,
  994. abi_long arg3, abi_long arg4, abi_long arg5)
  995. {
  996. print_syscall_prologue(name);
  997. print_signal(arg0, 0);
  998. print_pointer(arg1, 0);
  999. print_pointer(arg2, 1);
  1000. print_syscall_epilogue(name);
  1001. }
  1002. #endif
  1003. #ifdef TARGET_NR_rt_sigprocmask
  1004. static void
  1005. print_rt_sigprocmask(const struct syscallname *name,
  1006. abi_long arg0, abi_long arg1, abi_long arg2,
  1007. abi_long arg3, abi_long arg4, abi_long arg5)
  1008. {
  1009. const char *how = "UNKNOWN";
  1010. print_syscall_prologue(name);
  1011. switch(arg0) {
  1012. case TARGET_SIG_BLOCK: how = "SIG_BLOCK"; break;
  1013. case TARGET_SIG_UNBLOCK: how = "SIG_UNBLOCK"; break;
  1014. case TARGET_SIG_SETMASK: how = "SIG_SETMASK"; break;
  1015. }
  1016. gemu_log("%s,",how);
  1017. print_pointer(arg1, 0);
  1018. print_pointer(arg2, 1);
  1019. print_syscall_epilogue(name);
  1020. }
  1021. #endif
  1022. #ifdef TARGET_NR_mknod
  1023. static void
  1024. print_mknod(const struct syscallname *name,
  1025. abi_long arg0, abi_long arg1, abi_long arg2,
  1026. abi_long arg3, abi_long arg4, abi_long arg5)
  1027. {
  1028. int hasdev = (arg1 & (S_IFCHR|S_IFBLK));
  1029. print_syscall_prologue(name);
  1030. print_string(arg0, 0);
  1031. print_file_mode(arg1, (hasdev == 0));
  1032. if (hasdev) {
  1033. print_raw_param("makedev(%d", major(arg2), 0);
  1034. print_raw_param("%d)", minor(arg2), 1);
  1035. }
  1036. print_syscall_epilogue(name);
  1037. }
  1038. #endif
  1039. #ifdef TARGET_NR_mknodat
  1040. static void
  1041. print_mknodat(const struct syscallname *name,
  1042. abi_long arg0, abi_long arg1, abi_long arg2,
  1043. abi_long arg3, abi_long arg4, abi_long arg5)
  1044. {
  1045. int hasdev = (arg2 & (S_IFCHR|S_IFBLK));
  1046. print_syscall_prologue(name);
  1047. print_at_dirfd(arg0, 0);
  1048. print_string(arg1, 0);
  1049. print_file_mode(arg2, (hasdev == 0));
  1050. if (hasdev) {
  1051. print_raw_param("makedev(%d", major(arg3), 0);
  1052. print_raw_param("%d)", minor(arg3), 1);
  1053. }
  1054. print_syscall_epilogue(name);
  1055. }
  1056. #endif
  1057. #ifdef TARGET_NR_mq_open
  1058. static void
  1059. print_mq_open(const struct syscallname *name,
  1060. abi_long arg0, abi_long arg1, abi_long arg2,
  1061. abi_long arg3, abi_long arg4, abi_long arg5)
  1062. {
  1063. int is_creat = (arg1 & TARGET_O_CREAT);
  1064. print_syscall_prologue(name);
  1065. print_string(arg0, 0);
  1066. print_open_flags(arg1, (is_creat == 0));
  1067. if (is_creat) {
  1068. print_file_mode(arg2, 0);
  1069. print_pointer(arg3, 1);
  1070. }
  1071. print_syscall_epilogue(name);
  1072. }
  1073. #endif
  1074. #ifdef TARGET_NR_open
  1075. static void
  1076. print_open(const struct syscallname *name,
  1077. abi_long arg0, abi_long arg1, abi_long arg2,
  1078. abi_long arg3, abi_long arg4, abi_long arg5)
  1079. {
  1080. int is_creat = (arg1 & TARGET_O_CREAT);
  1081. print_syscall_prologue(name);
  1082. print_string(arg0, 0);
  1083. print_open_flags(arg1, (is_creat == 0));
  1084. if (is_creat)
  1085. print_file_mode(arg2, 1);
  1086. print_syscall_epilogue(name);
  1087. }
  1088. #endif
  1089. #ifdef TARGET_NR_openat
  1090. static void
  1091. print_openat(const struct syscallname *name,
  1092. abi_long arg0, abi_long arg1, abi_long arg2,
  1093. abi_long arg3, abi_long arg4, abi_long arg5)
  1094. {
  1095. int is_creat = (arg2 & TARGET_O_CREAT);
  1096. print_syscall_prologue(name);
  1097. print_at_dirfd(arg0, 0);
  1098. print_string(arg1, 0);
  1099. print_open_flags(arg2, (is_creat == 0));
  1100. if (is_creat)
  1101. print_file_mode(arg3, 1);
  1102. print_syscall_epilogue(name);
  1103. }
  1104. #endif
  1105. #ifdef TARGET_NR_mq_unlink
  1106. static void
  1107. print_mq_unlink(const struct syscallname *name,
  1108. abi_long arg0, abi_long arg1, abi_long arg2,
  1109. abi_long arg3, abi_long arg4, abi_long arg5)
  1110. {
  1111. print_syscall_prologue(name);
  1112. print_string(arg0, 1);
  1113. print_syscall_epilogue(name);
  1114. }
  1115. #endif
  1116. #if defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)
  1117. static void
  1118. print_fstatat64(const struct syscallname *name,
  1119. abi_long arg0, abi_long arg1, abi_long arg2,
  1120. abi_long arg3, abi_long arg4, abi_long arg5)
  1121. {
  1122. print_syscall_prologue(name);
  1123. print_at_dirfd(arg0, 0);
  1124. print_string(arg1, 0);
  1125. print_pointer(arg2, 0);
  1126. print_flags(at_file_flags, arg3, 1);
  1127. print_syscall_epilogue(name);
  1128. }
  1129. #define print_newfstatat print_fstatat64
  1130. #endif
  1131. #ifdef TARGET_NR_readlink
  1132. static void
  1133. print_readlink(const struct syscallname *name,
  1134. abi_long arg0, abi_long arg1, abi_long arg2,
  1135. abi_long arg3, abi_long arg4, abi_long arg5)
  1136. {
  1137. print_syscall_prologue(name);
  1138. print_string(arg0, 0);
  1139. print_pointer(arg1, 0);
  1140. print_raw_param("%u", arg2, 1);
  1141. print_syscall_epilogue(name);
  1142. }
  1143. #endif
  1144. #ifdef TARGET_NR_readlinkat
  1145. static void
  1146. print_readlinkat(const struct syscallname *name,
  1147. abi_long arg0, abi_long arg1, abi_long arg2,
  1148. abi_long arg3, abi_long arg4, abi_long arg5)
  1149. {
  1150. print_syscall_prologue(name);
  1151. print_at_dirfd(arg0, 0);
  1152. print_string(arg1, 0);
  1153. print_pointer(arg2, 0);
  1154. print_raw_param("%u", arg3, 1);
  1155. print_syscall_epilogue(name);
  1156. }
  1157. #endif
  1158. #ifdef TARGET_NR_rename
  1159. static void
  1160. print_rename(const struct syscallname *name,
  1161. abi_long arg0, abi_long arg1, abi_long arg2,
  1162. abi_long arg3, abi_long arg4, abi_long arg5)
  1163. {
  1164. print_syscall_prologue(name);
  1165. print_string(arg0, 0);
  1166. print_string(arg1, 1);
  1167. print_syscall_epilogue(name);
  1168. }
  1169. #endif
  1170. #ifdef TARGET_NR_renameat
  1171. static void
  1172. print_renameat(const struct syscallname *name,
  1173. abi_long arg0, abi_long arg1, abi_long arg2,
  1174. abi_long arg3, abi_long arg4, abi_long arg5)
  1175. {
  1176. print_syscall_prologue(name);
  1177. print_at_dirfd(arg0, 0);
  1178. print_string(arg1, 0);
  1179. print_at_dirfd(arg2, 0);
  1180. print_string(arg3, 1);
  1181. print_syscall_epilogue(name);
  1182. }
  1183. #endif
  1184. #ifdef TARGET_NR_statfs
  1185. static void
  1186. print_statfs(const struct syscallname *name,
  1187. abi_long arg0, abi_long arg1, abi_long arg2,
  1188. abi_long arg3, abi_long arg4, abi_long arg5)
  1189. {
  1190. print_syscall_prologue(name);
  1191. print_string(arg0, 0);
  1192. print_pointer(arg1, 1);
  1193. print_syscall_epilogue(name);
  1194. }
  1195. #define print_statfs64 print_statfs
  1196. #endif
  1197. #ifdef TARGET_NR_symlink
  1198. static void
  1199. print_symlink(const struct syscallname *name,
  1200. abi_long arg0, abi_long arg1, abi_long arg2,
  1201. abi_long arg3, abi_long arg4, abi_long arg5)
  1202. {
  1203. print_syscall_prologue(name);
  1204. print_string(arg0, 0);
  1205. print_string(arg1, 1);
  1206. print_syscall_epilogue(name);
  1207. }
  1208. #endif
  1209. #ifdef TARGET_NR_symlinkat
  1210. static void
  1211. print_symlinkat(const struct syscallname *name,
  1212. abi_long arg0, abi_long arg1, abi_long arg2,
  1213. abi_long arg3, abi_long arg4, abi_long arg5)
  1214. {
  1215. print_syscall_prologue(name);
  1216. print_string(arg0, 0);
  1217. print_at_dirfd(arg1, 0);
  1218. print_string(arg2, 1);
  1219. print_syscall_epilogue(name);
  1220. }
  1221. #endif
  1222. #ifdef TARGET_NR_mount
  1223. static void
  1224. print_mount(const struct syscallname *name,
  1225. abi_long arg0, abi_long arg1, abi_long arg2,
  1226. abi_long arg3, abi_long arg4, abi_long arg5)
  1227. {
  1228. print_syscall_prologue(name);
  1229. print_string(arg0, 0);
  1230. print_string(arg1, 0);
  1231. print_string(arg2, 0);
  1232. print_flags(mount_flags, arg3, 0);
  1233. print_pointer(arg4, 1);
  1234. print_syscall_epilogue(name);
  1235. }
  1236. #endif
  1237. #ifdef TARGET_NR_umount
  1238. static void
  1239. print_umount(const struct syscallname *name,
  1240. abi_long arg0, abi_long arg1, abi_long arg2,
  1241. abi_long arg3, abi_long arg4, abi_long arg5)
  1242. {
  1243. print_syscall_prologue(name);
  1244. print_string(arg0, 1);
  1245. print_syscall_epilogue(name);
  1246. }
  1247. #endif
  1248. #ifdef TARGET_NR_umount2
  1249. static void
  1250. print_umount2(const struct syscallname *name,
  1251. abi_long arg0, abi_long arg1, abi_long arg2,
  1252. abi_long arg3, abi_long arg4, abi_long arg5)
  1253. {
  1254. print_syscall_prologue(name);
  1255. print_string(arg0, 0);
  1256. print_flags(umount2_flags, arg1, 1);
  1257. print_syscall_epilogue(name);
  1258. }
  1259. #endif
  1260. #ifdef TARGET_NR_unlink
  1261. static void
  1262. print_unlink(const struct syscallname *name,
  1263. abi_long arg0, abi_long arg1, abi_long arg2,
  1264. abi_long arg3, abi_long arg4, abi_long arg5)
  1265. {
  1266. print_syscall_prologue(name);
  1267. print_string(arg0, 1);
  1268. print_syscall_epilogue(name);
  1269. }
  1270. #endif
  1271. #ifdef TARGET_NR_unlinkat
  1272. static void
  1273. print_unlinkat(const struct syscallname *name,
  1274. abi_long arg0, abi_long arg1, abi_long arg2,
  1275. abi_long arg3, abi_long arg4, abi_long arg5)
  1276. {
  1277. print_syscall_prologue(name);
  1278. print_at_dirfd(arg0, 0);
  1279. print_string(arg1, 0);
  1280. print_flags(unlinkat_flags, arg2, 1);
  1281. print_syscall_epilogue(name);
  1282. }
  1283. #endif
  1284. #ifdef TARGET_NR_utime
  1285. static void
  1286. print_utime(const struct syscallname *name,
  1287. abi_long arg0, abi_long arg1, abi_long arg2,
  1288. abi_long arg3, abi_long arg4, abi_long arg5)
  1289. {
  1290. print_syscall_prologue(name);
  1291. print_string(arg0, 0);
  1292. print_pointer(arg1, 1);
  1293. print_syscall_epilogue(name);
  1294. }
  1295. #endif
  1296. #ifdef TARGET_NR_utimes
  1297. static void
  1298. print_utimes(const struct syscallname *name,
  1299. abi_long arg0, abi_long arg1, abi_long arg2,
  1300. abi_long arg3, abi_long arg4, abi_long arg5)
  1301. {
  1302. print_syscall_prologue(name);
  1303. print_string(arg0, 0);
  1304. print_pointer(arg1, 1);
  1305. print_syscall_epilogue(name);
  1306. }
  1307. #endif
  1308. #ifdef TARGET_NR_utimensat
  1309. static void
  1310. print_utimensat(const struct syscallname *name,
  1311. abi_long arg0, abi_long arg1, abi_long arg2,
  1312. abi_long arg3, abi_long arg4, abi_long arg5)
  1313. {
  1314. print_syscall_prologue(name);
  1315. print_at_dirfd(arg0, 0);
  1316. print_string(arg1, 0);
  1317. print_pointer(arg2, 0);
  1318. print_flags(at_file_flags, arg3, 1);
  1319. print_syscall_epilogue(name);
  1320. }
  1321. #endif
  1322. #if defined(TARGET_NR_mmap) || defined(TARGET_NR_mmap2)
  1323. static void
  1324. print_mmap(const struct syscallname *name,
  1325. abi_long arg0, abi_long arg1, abi_long arg2,
  1326. abi_long arg3, abi_long arg4, abi_long arg5)
  1327. {
  1328. print_syscall_prologue(name);
  1329. print_pointer(arg0, 0);
  1330. print_raw_param("%d", arg1, 0);
  1331. print_flags(mmap_prot_flags, arg2, 0);
  1332. print_flags(mmap_flags, arg3, 0);
  1333. print_raw_param("%d", arg4, 0);
  1334. print_raw_param("%#x", arg5, 1);
  1335. print_syscall_epilogue(name);
  1336. }
  1337. #define print_mmap2 print_mmap
  1338. #endif
  1339. #ifdef TARGET_NR_mprotect
  1340. static void
  1341. print_mprotect(const struct syscallname *name,
  1342. abi_long arg0, abi_long arg1, abi_long arg2,
  1343. abi_long arg3, abi_long arg4, abi_long arg5)
  1344. {
  1345. print_syscall_prologue(name);
  1346. print_pointer(arg0, 0);
  1347. print_raw_param("%d", arg1, 0);
  1348. print_flags(mmap_prot_flags, arg2, 1);
  1349. print_syscall_epilogue(name);
  1350. }
  1351. #endif
  1352. #ifdef TARGET_NR_munmap
  1353. static void
  1354. print_munmap(const struct syscallname *name,
  1355. abi_long arg0, abi_long arg1, abi_long arg2,
  1356. abi_long arg3, abi_long arg4, abi_long arg5)
  1357. {
  1358. print_syscall_prologue(name);
  1359. print_pointer(arg0, 0);
  1360. print_raw_param("%d", arg1, 1);
  1361. print_syscall_epilogue(name);
  1362. }
  1363. #endif
  1364. #ifdef TARGET_NR_futex
  1365. static void print_futex_op(abi_long tflag, int last)
  1366. {
  1367. #define print_op(val) \
  1368. if( cmd == val ) { \
  1369. gemu_log(#val); \
  1370. return; \
  1371. }
  1372. int cmd = (int)tflag;
  1373. #ifdef FUTEX_PRIVATE_FLAG
  1374. if (cmd & FUTEX_PRIVATE_FLAG) {
  1375. gemu_log("FUTEX_PRIVATE_FLAG|");
  1376. cmd &= ~FUTEX_PRIVATE_FLAG;
  1377. }
  1378. #endif
  1379. #ifdef FUTEX_CLOCK_REALTIME
  1380. if (cmd & FUTEX_CLOCK_REALTIME) {
  1381. gemu_log("FUTEX_CLOCK_REALTIME|");
  1382. cmd &= ~FUTEX_CLOCK_REALTIME;
  1383. }
  1384. #endif
  1385. print_op(FUTEX_WAIT)
  1386. print_op(FUTEX_WAKE)
  1387. print_op(FUTEX_FD)
  1388. print_op(FUTEX_REQUEUE)
  1389. print_op(FUTEX_CMP_REQUEUE)
  1390. print_op(FUTEX_WAKE_OP)
  1391. print_op(FUTEX_LOCK_PI)
  1392. print_op(FUTEX_UNLOCK_PI)
  1393. print_op(FUTEX_TRYLOCK_PI)
  1394. #ifdef FUTEX_WAIT_BITSET
  1395. print_op(FUTEX_WAIT_BITSET)
  1396. #endif
  1397. #ifdef FUTEX_WAKE_BITSET
  1398. print_op(FUTEX_WAKE_BITSET)
  1399. #endif
  1400. /* unknown values */
  1401. gemu_log("%d",cmd);
  1402. }
  1403. static void
  1404. print_futex(const struct syscallname *name,
  1405. abi_long arg0, abi_long arg1, abi_long arg2,
  1406. abi_long arg3, abi_long arg4, abi_long arg5)
  1407. {
  1408. print_syscall_prologue(name);
  1409. print_pointer(arg0, 0);
  1410. print_futex_op(arg1, 0);
  1411. print_raw_param(",%d", arg2, 0);
  1412. print_pointer(arg3, 0); /* struct timespec */
  1413. print_pointer(arg4, 0);
  1414. print_raw_param("%d", arg4, 1);
  1415. print_syscall_epilogue(name);
  1416. }
  1417. #endif
  1418. #ifdef TARGET_NR_kill
  1419. static void
  1420. print_kill(const struct syscallname *name,
  1421. abi_long arg0, abi_long arg1, abi_long arg2,
  1422. abi_long arg3, abi_long arg4, abi_long arg5)
  1423. {
  1424. print_syscall_prologue(name);
  1425. print_raw_param("%d", arg0, 0);
  1426. print_signal(arg1, 1);
  1427. print_syscall_epilogue(name);
  1428. }
  1429. #endif
  1430. /*
  1431. * An array of all of the syscalls we know about
  1432. */
  1433. static const struct syscallname scnames[] = {
  1434. #include "strace.list"
  1435. };
  1436. static int nsyscalls = ARRAY_SIZE(scnames);
  1437. /*
  1438. * The public interface to this module.
  1439. */
  1440. void
  1441. print_syscall(int num,
  1442. abi_long arg1, abi_long arg2, abi_long arg3,
  1443. abi_long arg4, abi_long arg5, abi_long arg6)
  1444. {
  1445. int i;
  1446. 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 ")";
  1447. gemu_log("%d ", getpid() );
  1448. for(i=0;i<nsyscalls;i++)
  1449. if( scnames[i].nr == num ) {
  1450. if( scnames[i].call != NULL ) {
  1451. scnames[i].call(&scnames[i],arg1,arg2,arg3,arg4,arg5,arg6);
  1452. } else {
  1453. /* XXX: this format system is broken because it uses
  1454. host types and host pointers for strings */
  1455. if( scnames[i].format != NULL )
  1456. format = scnames[i].format;
  1457. gemu_log(format,scnames[i].name, arg1,arg2,arg3,arg4,arg5,arg6);
  1458. }
  1459. return;
  1460. }
  1461. gemu_log("Unknown syscall %d\n", num);
  1462. }
  1463. void
  1464. print_syscall_ret(int num, abi_long ret)
  1465. {
  1466. int i;
  1467. char *errstr = NULL;
  1468. for(i=0;i<nsyscalls;i++)
  1469. if( scnames[i].nr == num ) {
  1470. if( scnames[i].result != NULL ) {
  1471. scnames[i].result(&scnames[i],ret);
  1472. } else {
  1473. if (ret < 0) {
  1474. errstr = target_strerror(-ret);
  1475. }
  1476. if (errstr) {
  1477. gemu_log(" = -1 errno=" TARGET_ABI_FMT_ld " (%s)\n",
  1478. -ret, errstr);
  1479. } else {
  1480. gemu_log(" = " TARGET_ABI_FMT_ld "\n", ret);
  1481. }
  1482. }
  1483. break;
  1484. }
  1485. }