strace.c 67 KB

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