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