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