strace.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551
  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, 1);
  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 fcntl_flags[] = {
  423. FLAG_TARGET(F_DUPFD),
  424. FLAG_TARGET(F_GETFD),
  425. FLAG_TARGET(F_SETFD),
  426. FLAG_TARGET(F_GETFL),
  427. FLAG_TARGET(F_SETFL),
  428. FLAG_TARGET(F_GETLK),
  429. FLAG_TARGET(F_SETLK),
  430. FLAG_TARGET(F_SETLKW),
  431. FLAG_END,
  432. };
  433. UNUSED static struct flags clone_flags[] = {
  434. FLAG_GENERIC(CLONE_VM),
  435. FLAG_GENERIC(CLONE_FS),
  436. FLAG_GENERIC(CLONE_FILES),
  437. FLAG_GENERIC(CLONE_SIGHAND),
  438. FLAG_GENERIC(CLONE_PTRACE),
  439. FLAG_GENERIC(CLONE_VFORK),
  440. FLAG_GENERIC(CLONE_PARENT),
  441. FLAG_GENERIC(CLONE_THREAD),
  442. FLAG_GENERIC(CLONE_NEWNS),
  443. FLAG_GENERIC(CLONE_SYSVSEM),
  444. FLAG_GENERIC(CLONE_SETTLS),
  445. FLAG_GENERIC(CLONE_PARENT_SETTID),
  446. FLAG_GENERIC(CLONE_CHILD_CLEARTID),
  447. FLAG_GENERIC(CLONE_DETACHED),
  448. FLAG_GENERIC(CLONE_UNTRACED),
  449. FLAG_GENERIC(CLONE_CHILD_SETTID),
  450. #if defined(CLONE_NEWUTS)
  451. FLAG_GENERIC(CLONE_NEWUTS),
  452. #endif
  453. #if defined(CLONE_NEWIPC)
  454. FLAG_GENERIC(CLONE_NEWIPC),
  455. #endif
  456. #if defined(CLONE_NEWUSER)
  457. FLAG_GENERIC(CLONE_NEWUSER),
  458. #endif
  459. #if defined(CLONE_NEWPID)
  460. FLAG_GENERIC(CLONE_NEWPID),
  461. #endif
  462. #if defined(CLONE_NEWNET)
  463. FLAG_GENERIC(CLONE_NEWNET),
  464. #endif
  465. #if defined(CLONE_IO)
  466. FLAG_GENERIC(CLONE_IO),
  467. #endif
  468. FLAG_END,
  469. };
  470. /*
  471. * print_xxx utility functions. These are used to print syscall
  472. * parameters in certain format. All of these have parameter
  473. * named 'last'. This parameter is used to add comma to output
  474. * when last == 0.
  475. */
  476. static const char *
  477. get_comma(int last)
  478. {
  479. return ((last) ? "" : ",");
  480. }
  481. static void
  482. print_flags(const struct flags *f, abi_long flags, int last)
  483. {
  484. const char *sep = "";
  485. int n;
  486. if ((flags == 0) && (f->f_value == 0)) {
  487. gemu_log("%s%s", f->f_string, get_comma(last));
  488. return;
  489. }
  490. for (n = 0; f->f_string != NULL; f++) {
  491. if ((f->f_value != 0) && ((flags & f->f_value) == f->f_value)) {
  492. gemu_log("%s%s", sep, f->f_string);
  493. flags &= ~f->f_value;
  494. sep = "|";
  495. n++;
  496. }
  497. }
  498. if (n > 0) {
  499. /* print rest of the flags as numeric */
  500. if (flags != 0) {
  501. gemu_log("%s%#x%s", sep, (unsigned int)flags, get_comma(last));
  502. } else {
  503. gemu_log("%s", get_comma(last));
  504. }
  505. } else {
  506. /* no string version of flags found, print them in hex then */
  507. gemu_log("%#x%s", (unsigned int)flags, get_comma(last));
  508. }
  509. }
  510. static void
  511. print_at_dirfd(abi_long dirfd, int last)
  512. {
  513. #ifdef AT_FDCWD
  514. if (dirfd == AT_FDCWD) {
  515. gemu_log("AT_FDCWD%s", get_comma(last));
  516. return;
  517. }
  518. #endif
  519. gemu_log("%d%s", (int)dirfd, get_comma(last));
  520. }
  521. static void
  522. print_file_mode(abi_long mode, int last)
  523. {
  524. const char *sep = "";
  525. const struct flags *m;
  526. for (m = &mode_flags[0]; m->f_string != NULL; m++) {
  527. if ((m->f_value & mode) == m->f_value) {
  528. gemu_log("%s%s", m->f_string, sep);
  529. sep = "|";
  530. mode &= ~m->f_value;
  531. break;
  532. }
  533. }
  534. mode &= ~S_IFMT;
  535. /* print rest of the mode as octal */
  536. if (mode != 0)
  537. gemu_log("%s%#o", sep, (unsigned int)mode);
  538. gemu_log("%s", get_comma(last));
  539. }
  540. static void
  541. print_open_flags(abi_long flags, int last)
  542. {
  543. print_flags(open_access_flags, flags & TARGET_O_ACCMODE, 1);
  544. flags &= ~TARGET_O_ACCMODE;
  545. if (flags == 0) {
  546. gemu_log("%s", get_comma(last));
  547. return;
  548. }
  549. gemu_log("|");
  550. print_flags(open_flags, flags, last);
  551. }
  552. static void
  553. print_syscall_prologue(const struct syscallname *sc)
  554. {
  555. gemu_log("%s(", sc->name);
  556. }
  557. /*ARGSUSED*/
  558. static void
  559. print_syscall_epilogue(const struct syscallname *sc)
  560. {
  561. (void)sc;
  562. gemu_log(")");
  563. }
  564. static void
  565. print_string(abi_long addr, int last)
  566. {
  567. char *s;
  568. if ((s = lock_user_string(addr)) != NULL) {
  569. gemu_log("\"%s\"%s", s, get_comma(last));
  570. unlock_user(s, addr, 0);
  571. } else {
  572. /* can't get string out of it, so print it as pointer */
  573. print_pointer(addr, last);
  574. }
  575. }
  576. /*
  577. * Prints out raw parameter using given format. Caller needs
  578. * to do byte swapping if needed.
  579. */
  580. static void
  581. print_raw_param(const char *fmt, abi_long param, int last)
  582. {
  583. char format[64];
  584. (void) snprintf(format, sizeof (format), "%s%s", fmt, get_comma(last));
  585. gemu_log(format, param);
  586. }
  587. static void
  588. print_pointer(abi_long p, int last)
  589. {
  590. if (p == 0)
  591. gemu_log("NULL%s", get_comma(last));
  592. else
  593. gemu_log("0x" TARGET_ABI_FMT_lx "%s", p, get_comma(last));
  594. }
  595. /*
  596. * Reads 32-bit (int) number from guest address space from
  597. * address 'addr' and prints it.
  598. */
  599. static void
  600. print_number(abi_long addr, int last)
  601. {
  602. if (addr == 0) {
  603. gemu_log("NULL%s", get_comma(last));
  604. } else {
  605. int num;
  606. get_user_s32(num, addr);
  607. gemu_log("[%d]%s", num, get_comma(last));
  608. }
  609. }
  610. static void
  611. print_timeval(abi_ulong tv_addr, int last)
  612. {
  613. if( tv_addr ) {
  614. struct target_timeval *tv;
  615. tv = lock_user(VERIFY_READ, tv_addr, sizeof(*tv), 1);
  616. if (!tv)
  617. return;
  618. gemu_log("{" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "}%s",
  619. tv->tv_sec, tv->tv_usec, get_comma(last));
  620. unlock_user(tv, tv_addr, 0);
  621. } else
  622. gemu_log("NULL%s", get_comma(last));
  623. }
  624. #undef UNUSED
  625. #ifdef TARGET_NR_accept
  626. static void
  627. print_accept(const struct syscallname *name,
  628. abi_long arg0, abi_long arg1, abi_long arg2,
  629. abi_long arg3, abi_long arg4, abi_long arg5)
  630. {
  631. print_syscall_prologue(name);
  632. print_raw_param("%d", arg0, 0);
  633. print_pointer(arg1, 0);
  634. print_number(arg2, 1);
  635. print_syscall_epilogue(name);
  636. }
  637. #endif
  638. #ifdef TARGET_NR_access
  639. static void
  640. print_access(const struct syscallname *name,
  641. abi_long arg0, abi_long arg1, abi_long arg2,
  642. abi_long arg3, abi_long arg4, abi_long arg5)
  643. {
  644. print_syscall_prologue(name);
  645. print_string(arg0, 0);
  646. print_flags(access_flags, arg1, 1);
  647. print_syscall_epilogue(name);
  648. }
  649. #endif
  650. #ifdef TARGET_NR_brk
  651. static void
  652. print_brk(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_pointer(arg0, 1);
  658. print_syscall_epilogue(name);
  659. }
  660. #endif
  661. #ifdef TARGET_NR_chdir
  662. static void
  663. print_chdir(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, 1);
  669. print_syscall_epilogue(name);
  670. }
  671. #endif
  672. #ifdef TARGET_NR_chmod
  673. static void
  674. print_chmod(const struct syscallname *name,
  675. abi_long arg0, abi_long arg1, abi_long arg2,
  676. abi_long arg3, abi_long arg4, abi_long arg5)
  677. {
  678. print_syscall_prologue(name);
  679. print_string(arg0, 0);
  680. print_file_mode(arg1, 1);
  681. print_syscall_epilogue(name);
  682. }
  683. #endif
  684. #ifdef TARGET_NR_clone
  685. static void
  686. print_clone(const struct syscallname *name,
  687. abi_long arg0, abi_long arg1, abi_long arg2,
  688. abi_long arg3, abi_long arg4, abi_long arg5)
  689. {
  690. print_syscall_prologue(name);
  691. #if defined(TARGET_M68K)
  692. print_flags(clone_flags, arg0, 0);
  693. print_raw_param("newsp=0x" TARGET_ABI_FMT_lx, arg1, 1);
  694. #elif defined(TARGET_SH4) || defined(TARGET_ALPHA)
  695. print_flags(clone_flags, arg0, 0);
  696. print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, arg1, 0);
  697. print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, arg2, 0);
  698. print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, arg3, 0);
  699. print_raw_param("tls=0x" TARGET_ABI_FMT_lx, arg4, 1);
  700. #elif defined(TARGET_CRIS)
  701. print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, arg0, 0);
  702. print_flags(clone_flags, arg1, 0);
  703. print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, arg2, 0);
  704. print_raw_param("tls=0x" TARGET_ABI_FMT_lx, arg3, 0);
  705. print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, arg4, 1);
  706. #else
  707. print_flags(clone_flags, arg0, 0);
  708. print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, arg1, 0);
  709. print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, arg2, 0);
  710. print_raw_param("tls=0x" TARGET_ABI_FMT_lx, arg3, 0);
  711. print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, arg4, 1);
  712. #endif
  713. print_syscall_epilogue(name);
  714. }
  715. #endif
  716. #ifdef TARGET_NR_creat
  717. static void
  718. print_creat(const struct syscallname *name,
  719. abi_long arg0, abi_long arg1, abi_long arg2,
  720. abi_long arg3, abi_long arg4, abi_long arg5)
  721. {
  722. print_syscall_prologue(name);
  723. print_string(arg0, 0);
  724. print_file_mode(arg1, 1);
  725. print_syscall_epilogue(name);
  726. }
  727. #endif
  728. #ifdef TARGET_NR_execv
  729. static void
  730. print_execv(const struct syscallname *name,
  731. abi_long arg0, abi_long arg1, abi_long arg2,
  732. abi_long arg3, abi_long arg4, abi_long arg5)
  733. {
  734. print_syscall_prologue(name);
  735. print_string(arg0, 0);
  736. print_raw_param("0x" TARGET_ABI_FMT_lx, arg1, 1);
  737. print_syscall_epilogue(name);
  738. }
  739. #endif
  740. #ifdef TARGET_NR_faccessat
  741. static void
  742. print_faccessat(const struct syscallname *name,
  743. abi_long arg0, abi_long arg1, abi_long arg2,
  744. abi_long arg3, abi_long arg4, abi_long arg5)
  745. {
  746. print_syscall_prologue(name);
  747. print_at_dirfd(arg0, 0);
  748. print_string(arg1, 0);
  749. print_flags(access_flags, arg2, 0);
  750. print_flags(at_file_flags, arg3, 1);
  751. print_syscall_epilogue(name);
  752. }
  753. #endif
  754. #ifdef TARGET_NR_fchmodat
  755. static void
  756. print_fchmodat(const struct syscallname *name,
  757. abi_long arg0, abi_long arg1, abi_long arg2,
  758. abi_long arg3, abi_long arg4, abi_long arg5)
  759. {
  760. print_syscall_prologue(name);
  761. print_at_dirfd(arg0, 0);
  762. print_string(arg1, 0);
  763. print_file_mode(arg2, 0);
  764. print_flags(at_file_flags, arg3, 1);
  765. print_syscall_epilogue(name);
  766. }
  767. #endif
  768. #ifdef TARGET_NR_fchownat
  769. static void
  770. print_fchownat(const struct syscallname *name,
  771. abi_long arg0, abi_long arg1, abi_long arg2,
  772. abi_long arg3, abi_long arg4, abi_long arg5)
  773. {
  774. print_syscall_prologue(name);
  775. print_at_dirfd(arg0, 0);
  776. print_string(arg1, 0);
  777. print_raw_param("%d", arg2, 0);
  778. print_raw_param("%d", arg3, 0);
  779. print_flags(at_file_flags, arg4, 1);
  780. print_syscall_epilogue(name);
  781. }
  782. #endif
  783. #if defined(TARGET_NR_fcntl) || defined(TARGET_NR_fcntl64)
  784. static void
  785. print_fcntl(const struct syscallname *name,
  786. abi_long arg0, abi_long arg1, abi_long arg2,
  787. abi_long arg3, abi_long arg4, abi_long arg5)
  788. {
  789. print_syscall_prologue(name);
  790. print_raw_param("%d", arg0, 0);
  791. print_flags(fcntl_flags, arg1, 0);
  792. /*
  793. * TODO: check flags and print following argument only
  794. * when needed.
  795. */
  796. print_pointer(arg2, 1);
  797. print_syscall_epilogue(name);
  798. }
  799. #define print_fcntl64 print_fcntl
  800. #endif
  801. #ifdef TARGET_NR_futimesat
  802. static void
  803. print_futimesat(const struct syscallname *name,
  804. abi_long arg0, abi_long arg1, abi_long arg2,
  805. abi_long arg3, abi_long arg4, abi_long arg5)
  806. {
  807. print_syscall_prologue(name);
  808. print_at_dirfd(arg0, 0);
  809. print_string(arg1, 0);
  810. print_timeval(arg2, 0);
  811. print_timeval(arg2 + sizeof (struct target_timeval), 1);
  812. print_syscall_epilogue(name);
  813. }
  814. #endif
  815. #ifdef TARGET_NR_link
  816. static void
  817. print_link(const struct syscallname *name,
  818. abi_long arg0, abi_long arg1, abi_long arg2,
  819. abi_long arg3, abi_long arg4, abi_long arg5)
  820. {
  821. print_syscall_prologue(name);
  822. print_string(arg0, 0);
  823. print_string(arg1, 1);
  824. print_syscall_epilogue(name);
  825. }
  826. #endif
  827. #ifdef TARGET_NR_linkat
  828. static void
  829. print_linkat(const struct syscallname *name,
  830. abi_long arg0, abi_long arg1, abi_long arg2,
  831. abi_long arg3, abi_long arg4, abi_long arg5)
  832. {
  833. print_syscall_prologue(name);
  834. print_at_dirfd(arg0, 0);
  835. print_string(arg1, 0);
  836. print_at_dirfd(arg2, 0);
  837. print_string(arg3, 0);
  838. print_flags(at_file_flags, arg4, 1);
  839. print_syscall_epilogue(name);
  840. }
  841. #endif
  842. #ifdef TARGET_NR__llseek
  843. static void
  844. print__llseek(const struct syscallname *name,
  845. abi_long arg0, abi_long arg1, abi_long arg2,
  846. abi_long arg3, abi_long arg4, abi_long arg5)
  847. {
  848. const char *whence = "UNKNOWN";
  849. print_syscall_prologue(name);
  850. print_raw_param("%d", arg0, 0);
  851. print_raw_param("%ld", arg1, 0);
  852. print_raw_param("%ld", arg2, 0);
  853. print_pointer(arg3, 0);
  854. switch(arg4) {
  855. case SEEK_SET: whence = "SEEK_SET"; break;
  856. case SEEK_CUR: whence = "SEEK_CUR"; break;
  857. case SEEK_END: whence = "SEEK_END"; break;
  858. }
  859. gemu_log("%s",whence);
  860. print_syscall_epilogue(name);
  861. }
  862. #endif
  863. #if defined(TARGET_NR_stat) || defined(TARGET_NR_stat64) || \
  864. defined(TARGET_NR_lstat) || defined(TARGET_NR_lstat64)
  865. static void
  866. print_stat(const struct syscallname *name,
  867. abi_long arg0, abi_long arg1, abi_long arg2,
  868. abi_long arg3, abi_long arg4, abi_long arg5)
  869. {
  870. print_syscall_prologue(name);
  871. print_string(arg0, 0);
  872. print_pointer(arg1, 1);
  873. print_syscall_epilogue(name);
  874. }
  875. #define print_lstat print_stat
  876. #define print_stat64 print_stat
  877. #define print_lstat64 print_stat
  878. #endif
  879. #if defined(TARGET_NR_fstat) || defined(TARGET_NR_fstat64)
  880. static void
  881. print_fstat(const struct syscallname *name,
  882. abi_long arg0, abi_long arg1, abi_long arg2,
  883. abi_long arg3, abi_long arg4, abi_long arg5)
  884. {
  885. print_syscall_prologue(name);
  886. print_raw_param("%d", arg0, 0);
  887. print_pointer(arg1, 1);
  888. print_syscall_epilogue(name);
  889. }
  890. #define print_fstat64 print_fstat
  891. #endif
  892. #ifdef TARGET_NR_mkdir
  893. static void
  894. print_mkdir(const struct syscallname *name,
  895. abi_long arg0, abi_long arg1, abi_long arg2,
  896. abi_long arg3, abi_long arg4, abi_long arg5)
  897. {
  898. print_syscall_prologue(name);
  899. print_string(arg0, 0);
  900. print_file_mode(arg1, 1);
  901. print_syscall_epilogue(name);
  902. }
  903. #endif
  904. #ifdef TARGET_NR_mkdirat
  905. static void
  906. print_mkdirat(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. print_syscall_prologue(name);
  911. print_at_dirfd(arg0, 0);
  912. print_string(arg1, 0);
  913. print_file_mode(arg2, 1);
  914. print_syscall_epilogue(name);
  915. }
  916. #endif
  917. #ifdef TARGET_NR_rmdir
  918. static void
  919. print_rmdir(const struct syscallname *name,
  920. abi_long arg0, abi_long arg1, abi_long arg2,
  921. abi_long arg3, abi_long arg4, abi_long arg5)
  922. {
  923. print_syscall_prologue(name);
  924. print_string(arg0, 0);
  925. print_syscall_epilogue(name);
  926. }
  927. #endif
  928. #ifdef TARGET_NR_rt_sigaction
  929. static void
  930. print_rt_sigaction(const struct syscallname *name,
  931. abi_long arg0, abi_long arg1, abi_long arg2,
  932. abi_long arg3, abi_long arg4, abi_long arg5)
  933. {
  934. print_syscall_prologue(name);
  935. print_signal(arg0, 0);
  936. print_pointer(arg1, 0);
  937. print_pointer(arg2, 1);
  938. print_syscall_epilogue(name);
  939. }
  940. #endif
  941. #ifdef TARGET_NR_rt_sigprocmask
  942. static void
  943. print_rt_sigprocmask(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. const char *how = "UNKNOWN";
  948. print_syscall_prologue(name);
  949. switch(arg0) {
  950. case TARGET_SIG_BLOCK: how = "SIG_BLOCK"; break;
  951. case TARGET_SIG_UNBLOCK: how = "SIG_UNBLOCK"; break;
  952. case TARGET_SIG_SETMASK: how = "SIG_SETMASK"; break;
  953. }
  954. gemu_log("%s,",how);
  955. print_pointer(arg1, 0);
  956. print_pointer(arg2, 1);
  957. print_syscall_epilogue(name);
  958. }
  959. #endif
  960. #ifdef TARGET_NR_mknod
  961. static void
  962. print_mknod(const struct syscallname *name,
  963. abi_long arg0, abi_long arg1, abi_long arg2,
  964. abi_long arg3, abi_long arg4, abi_long arg5)
  965. {
  966. int hasdev = (arg1 & (S_IFCHR|S_IFBLK));
  967. print_syscall_prologue(name);
  968. print_string(arg0, 0);
  969. print_file_mode(arg1, (hasdev == 0));
  970. if (hasdev) {
  971. print_raw_param("makedev(%d", major(arg2), 0);
  972. print_raw_param("%d)", minor(arg2), 1);
  973. }
  974. print_syscall_epilogue(name);
  975. }
  976. #endif
  977. #ifdef TARGET_NR_mknodat
  978. static void
  979. print_mknodat(const struct syscallname *name,
  980. abi_long arg0, abi_long arg1, abi_long arg2,
  981. abi_long arg3, abi_long arg4, abi_long arg5)
  982. {
  983. int hasdev = (arg2 & (S_IFCHR|S_IFBLK));
  984. print_syscall_prologue(name);
  985. print_at_dirfd(arg0, 0);
  986. print_string(arg1, 0);
  987. print_file_mode(arg2, (hasdev == 0));
  988. if (hasdev) {
  989. print_raw_param("makedev(%d", major(arg3), 0);
  990. print_raw_param("%d)", minor(arg3), 1);
  991. }
  992. print_syscall_epilogue(name);
  993. }
  994. #endif
  995. #ifdef TARGET_NR_mq_open
  996. static void
  997. print_mq_open(const struct syscallname *name,
  998. abi_long arg0, abi_long arg1, abi_long arg2,
  999. abi_long arg3, abi_long arg4, abi_long arg5)
  1000. {
  1001. int is_creat = (arg1 & TARGET_O_CREAT);
  1002. print_syscall_prologue(name);
  1003. print_string(arg0, 0);
  1004. print_open_flags(arg1, (is_creat == 0));
  1005. if (is_creat) {
  1006. print_file_mode(arg2, 0);
  1007. print_pointer(arg3, 1);
  1008. }
  1009. print_syscall_epilogue(name);
  1010. }
  1011. #endif
  1012. #ifdef TARGET_NR_open
  1013. static void
  1014. print_open(const struct syscallname *name,
  1015. abi_long arg0, abi_long arg1, abi_long arg2,
  1016. abi_long arg3, abi_long arg4, abi_long arg5)
  1017. {
  1018. int is_creat = (arg1 & TARGET_O_CREAT);
  1019. print_syscall_prologue(name);
  1020. print_string(arg0, 0);
  1021. print_open_flags(arg1, (is_creat == 0));
  1022. if (is_creat)
  1023. print_file_mode(arg2, 1);
  1024. print_syscall_epilogue(name);
  1025. }
  1026. #endif
  1027. #ifdef TARGET_NR_openat
  1028. static void
  1029. print_openat(const struct syscallname *name,
  1030. abi_long arg0, abi_long arg1, abi_long arg2,
  1031. abi_long arg3, abi_long arg4, abi_long arg5)
  1032. {
  1033. int is_creat = (arg2 & TARGET_O_CREAT);
  1034. print_syscall_prologue(name);
  1035. print_at_dirfd(arg0, 0);
  1036. print_string(arg1, 0);
  1037. print_open_flags(arg2, (is_creat == 0));
  1038. if (is_creat)
  1039. print_file_mode(arg3, 1);
  1040. print_syscall_epilogue(name);
  1041. }
  1042. #endif
  1043. #ifdef TARGET_NR_mq_unlink
  1044. static void
  1045. print_mq_unlink(const struct syscallname *name,
  1046. abi_long arg0, abi_long arg1, abi_long arg2,
  1047. abi_long arg3, abi_long arg4, abi_long arg5)
  1048. {
  1049. print_syscall_prologue(name);
  1050. print_string(arg0, 1);
  1051. print_syscall_epilogue(name);
  1052. }
  1053. #endif
  1054. #if defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)
  1055. static void
  1056. print_fstatat64(const struct syscallname *name,
  1057. abi_long arg0, abi_long arg1, abi_long arg2,
  1058. abi_long arg3, abi_long arg4, abi_long arg5)
  1059. {
  1060. print_syscall_prologue(name);
  1061. print_at_dirfd(arg0, 0);
  1062. print_string(arg1, 0);
  1063. print_pointer(arg2, 0);
  1064. print_flags(at_file_flags, arg3, 1);
  1065. print_syscall_epilogue(name);
  1066. }
  1067. #define print_newfstatat print_fstatat64
  1068. #endif
  1069. #ifdef TARGET_NR_readlink
  1070. static void
  1071. print_readlink(const struct syscallname *name,
  1072. abi_long arg0, abi_long arg1, abi_long arg2,
  1073. abi_long arg3, abi_long arg4, abi_long arg5)
  1074. {
  1075. print_syscall_prologue(name);
  1076. print_string(arg0, 0);
  1077. print_pointer(arg1, 0);
  1078. print_raw_param("%u", arg2, 1);
  1079. print_syscall_epilogue(name);
  1080. }
  1081. #endif
  1082. #ifdef TARGET_NR_readlinkat
  1083. static void
  1084. print_readlinkat(const struct syscallname *name,
  1085. abi_long arg0, abi_long arg1, abi_long arg2,
  1086. abi_long arg3, abi_long arg4, abi_long arg5)
  1087. {
  1088. print_syscall_prologue(name);
  1089. print_at_dirfd(arg0, 0);
  1090. print_string(arg1, 0);
  1091. print_pointer(arg2, 0);
  1092. print_raw_param("%u", arg3, 1);
  1093. print_syscall_epilogue(name);
  1094. }
  1095. #endif
  1096. #ifdef TARGET_NR_rename
  1097. static void
  1098. print_rename(const struct syscallname *name,
  1099. abi_long arg0, abi_long arg1, abi_long arg2,
  1100. abi_long arg3, abi_long arg4, abi_long arg5)
  1101. {
  1102. print_syscall_prologue(name);
  1103. print_string(arg0, 0);
  1104. print_string(arg1, 1);
  1105. print_syscall_epilogue(name);
  1106. }
  1107. #endif
  1108. #ifdef TARGET_NR_renameat
  1109. static void
  1110. print_renameat(const struct syscallname *name,
  1111. abi_long arg0, abi_long arg1, abi_long arg2,
  1112. abi_long arg3, abi_long arg4, abi_long arg5)
  1113. {
  1114. print_syscall_prologue(name);
  1115. print_at_dirfd(arg0, 0);
  1116. print_string(arg1, 0);
  1117. print_at_dirfd(arg2, 0);
  1118. print_string(arg3, 1);
  1119. print_syscall_epilogue(name);
  1120. }
  1121. #endif
  1122. #ifdef TARGET_NR_statfs
  1123. static void
  1124. print_statfs(const struct syscallname *name,
  1125. abi_long arg0, abi_long arg1, abi_long arg2,
  1126. abi_long arg3, abi_long arg4, abi_long arg5)
  1127. {
  1128. print_syscall_prologue(name);
  1129. print_string(arg0, 0);
  1130. print_pointer(arg1, 1);
  1131. print_syscall_epilogue(name);
  1132. }
  1133. #define print_statfs64 print_statfs
  1134. #endif
  1135. #ifdef TARGET_NR_symlink
  1136. static void
  1137. print_symlink(const struct syscallname *name,
  1138. abi_long arg0, abi_long arg1, abi_long arg2,
  1139. abi_long arg3, abi_long arg4, abi_long arg5)
  1140. {
  1141. print_syscall_prologue(name);
  1142. print_string(arg0, 0);
  1143. print_string(arg1, 1);
  1144. print_syscall_epilogue(name);
  1145. }
  1146. #endif
  1147. #ifdef TARGET_NR_symlinkat
  1148. static void
  1149. print_symlinkat(const struct syscallname *name,
  1150. abi_long arg0, abi_long arg1, abi_long arg2,
  1151. abi_long arg3, abi_long arg4, abi_long arg5)
  1152. {
  1153. print_syscall_prologue(name);
  1154. print_string(arg0, 0);
  1155. print_at_dirfd(arg1, 0);
  1156. print_string(arg2, 1);
  1157. print_syscall_epilogue(name);
  1158. }
  1159. #endif
  1160. #ifdef TARGET_NR_mount
  1161. static void
  1162. print_mount(const struct syscallname *name,
  1163. abi_long arg0, abi_long arg1, abi_long arg2,
  1164. abi_long arg3, abi_long arg4, abi_long arg5)
  1165. {
  1166. print_syscall_prologue(name);
  1167. print_string(arg0, 0);
  1168. print_string(arg1, 0);
  1169. print_string(arg2, 0);
  1170. print_flags(mount_flags, arg3, 0);
  1171. print_pointer(arg4, 1);
  1172. print_syscall_epilogue(name);
  1173. }
  1174. #endif
  1175. #ifdef TARGET_NR_umount
  1176. static void
  1177. print_umount(const struct syscallname *name,
  1178. abi_long arg0, abi_long arg1, abi_long arg2,
  1179. abi_long arg3, abi_long arg4, abi_long arg5)
  1180. {
  1181. print_syscall_prologue(name);
  1182. print_string(arg0, 1);
  1183. print_syscall_epilogue(name);
  1184. }
  1185. #endif
  1186. #ifdef TARGET_NR_umount2
  1187. static void
  1188. print_umount2(const struct syscallname *name,
  1189. abi_long arg0, abi_long arg1, abi_long arg2,
  1190. abi_long arg3, abi_long arg4, abi_long arg5)
  1191. {
  1192. print_syscall_prologue(name);
  1193. print_string(arg0, 0);
  1194. print_flags(umount2_flags, arg1, 1);
  1195. print_syscall_epilogue(name);
  1196. }
  1197. #endif
  1198. #ifdef TARGET_NR_unlink
  1199. static void
  1200. print_unlink(const struct syscallname *name,
  1201. abi_long arg0, abi_long arg1, abi_long arg2,
  1202. abi_long arg3, abi_long arg4, abi_long arg5)
  1203. {
  1204. print_syscall_prologue(name);
  1205. print_string(arg0, 1);
  1206. print_syscall_epilogue(name);
  1207. }
  1208. #endif
  1209. #ifdef TARGET_NR_unlinkat
  1210. static void
  1211. print_unlinkat(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_at_dirfd(arg0, 0);
  1217. print_string(arg1, 0);
  1218. print_flags(unlinkat_flags, arg2, 1);
  1219. print_syscall_epilogue(name);
  1220. }
  1221. #endif
  1222. #ifdef TARGET_NR_utime
  1223. static void
  1224. print_utime(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_pointer(arg1, 1);
  1231. print_syscall_epilogue(name);
  1232. }
  1233. #endif
  1234. #ifdef TARGET_NR_utimes
  1235. static void
  1236. print_utimes(const struct syscallname *name,
  1237. abi_long arg0, abi_long arg1, abi_long arg2,
  1238. abi_long arg3, abi_long arg4, abi_long arg5)
  1239. {
  1240. print_syscall_prologue(name);
  1241. print_string(arg0, 0);
  1242. print_pointer(arg1, 1);
  1243. print_syscall_epilogue(name);
  1244. }
  1245. #endif
  1246. #ifdef TARGET_NR_utimensat
  1247. static void
  1248. print_utimensat(const struct syscallname *name,
  1249. abi_long arg0, abi_long arg1, abi_long arg2,
  1250. abi_long arg3, abi_long arg4, abi_long arg5)
  1251. {
  1252. print_syscall_prologue(name);
  1253. print_at_dirfd(arg0, 0);
  1254. print_string(arg1, 0);
  1255. print_pointer(arg2, 0);
  1256. print_flags(at_file_flags, arg3, 1);
  1257. print_syscall_epilogue(name);
  1258. }
  1259. #endif
  1260. #if defined(TARGET_NR_mmap) || defined(TARGET_NR_mmap2)
  1261. static void
  1262. print_mmap(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_pointer(arg0, 0);
  1268. print_raw_param("%d", arg1, 0);
  1269. print_flags(mmap_prot_flags, arg2, 0);
  1270. print_flags(mmap_flags, arg3, 0);
  1271. print_raw_param("%d", arg4, 0);
  1272. print_raw_param("%#x", arg5, 1);
  1273. print_syscall_epilogue(name);
  1274. }
  1275. #define print_mmap2 print_mmap
  1276. #endif
  1277. #ifdef TARGET_NR_mprotect
  1278. static void
  1279. print_mprotect(const struct syscallname *name,
  1280. abi_long arg0, abi_long arg1, abi_long arg2,
  1281. abi_long arg3, abi_long arg4, abi_long arg5)
  1282. {
  1283. print_syscall_prologue(name);
  1284. print_pointer(arg0, 0);
  1285. print_raw_param("%d", arg1, 0);
  1286. print_flags(mmap_prot_flags, arg2, 1);
  1287. print_syscall_epilogue(name);
  1288. }
  1289. #endif
  1290. #ifdef TARGET_NR_munmap
  1291. static void
  1292. print_munmap(const struct syscallname *name,
  1293. abi_long arg0, abi_long arg1, abi_long arg2,
  1294. abi_long arg3, abi_long arg4, abi_long arg5)
  1295. {
  1296. print_syscall_prologue(name);
  1297. print_pointer(arg0, 0);
  1298. print_raw_param("%d", arg1, 1);
  1299. print_syscall_epilogue(name);
  1300. }
  1301. #endif
  1302. #ifdef TARGET_NR_futex
  1303. static void print_futex_op(abi_long tflag, int last)
  1304. {
  1305. #define print_op(val) \
  1306. if( cmd == val ) { \
  1307. gemu_log(#val); \
  1308. return; \
  1309. }
  1310. int cmd = (int)tflag;
  1311. #ifdef FUTEX_PRIVATE_FLAG
  1312. if (cmd & FUTEX_PRIVATE_FLAG) {
  1313. gemu_log("FUTEX_PRIVATE_FLAG|");
  1314. cmd &= ~FUTEX_PRIVATE_FLAG;
  1315. }
  1316. #endif
  1317. print_op(FUTEX_WAIT)
  1318. print_op(FUTEX_WAKE)
  1319. print_op(FUTEX_FD)
  1320. print_op(FUTEX_REQUEUE)
  1321. print_op(FUTEX_CMP_REQUEUE)
  1322. print_op(FUTEX_WAKE_OP)
  1323. print_op(FUTEX_LOCK_PI)
  1324. print_op(FUTEX_UNLOCK_PI)
  1325. print_op(FUTEX_TRYLOCK_PI)
  1326. #ifdef FUTEX_WAIT_BITSET
  1327. print_op(FUTEX_WAIT_BITSET)
  1328. #endif
  1329. #ifdef FUTEX_WAKE_BITSET
  1330. print_op(FUTEX_WAKE_BITSET)
  1331. #endif
  1332. /* unknown values */
  1333. gemu_log("%d",cmd);
  1334. }
  1335. static void
  1336. print_futex(const struct syscallname *name,
  1337. abi_long arg0, abi_long arg1, abi_long arg2,
  1338. abi_long arg3, abi_long arg4, abi_long arg5)
  1339. {
  1340. print_syscall_prologue(name);
  1341. print_pointer(arg0, 0);
  1342. print_futex_op(arg1, 0);
  1343. print_raw_param(",%d", arg2, 0);
  1344. print_pointer(arg3, 0); /* struct timespec */
  1345. print_pointer(arg4, 0);
  1346. print_raw_param("%d", arg4, 1);
  1347. print_syscall_epilogue(name);
  1348. }
  1349. #endif
  1350. #ifdef TARGET_NR_kill
  1351. static void
  1352. print_kill(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_raw_param("%d", arg0, 0);
  1358. print_signal(arg1, 1);
  1359. print_syscall_epilogue(name);
  1360. }
  1361. #endif
  1362. /*
  1363. * An array of all of the syscalls we know about
  1364. */
  1365. static const struct syscallname scnames[] = {
  1366. #include "strace.list"
  1367. };
  1368. static int nsyscalls = ARRAY_SIZE(scnames);
  1369. /*
  1370. * The public interface to this module.
  1371. */
  1372. void
  1373. print_syscall(int num,
  1374. abi_long arg1, abi_long arg2, abi_long arg3,
  1375. abi_long arg4, abi_long arg5, abi_long arg6)
  1376. {
  1377. int i;
  1378. 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 ")";
  1379. gemu_log("%d ", getpid() );
  1380. for(i=0;i<nsyscalls;i++)
  1381. if( scnames[i].nr == num ) {
  1382. if( scnames[i].call != NULL ) {
  1383. scnames[i].call(&scnames[i],arg1,arg2,arg3,arg4,arg5,arg6);
  1384. } else {
  1385. /* XXX: this format system is broken because it uses
  1386. host types and host pointers for strings */
  1387. if( scnames[i].format != NULL )
  1388. format = scnames[i].format;
  1389. gemu_log(format,scnames[i].name, arg1,arg2,arg3,arg4,arg5,arg6);
  1390. }
  1391. return;
  1392. }
  1393. gemu_log("Unknown syscall %d\n", num);
  1394. }
  1395. void
  1396. print_syscall_ret(int num, abi_long ret)
  1397. {
  1398. int i;
  1399. char *errstr = NULL;
  1400. for(i=0;i<nsyscalls;i++)
  1401. if( scnames[i].nr == num ) {
  1402. if( scnames[i].result != NULL ) {
  1403. scnames[i].result(&scnames[i],ret);
  1404. } else {
  1405. if (ret < 0) {
  1406. errstr = target_strerror(-ret);
  1407. }
  1408. if (errstr) {
  1409. gemu_log(" = -1 errno=" TARGET_ABI_FMT_ld " (%s)\n",
  1410. -ret, errstr);
  1411. } else {
  1412. gemu_log(" = " TARGET_ABI_FMT_ld "\n", ret);
  1413. }
  1414. }
  1415. break;
  1416. }
  1417. }