strace.c 39 KB

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