7 #include <sys/select.h>
18 void (*call)(const struct syscallname *,
19 abi_long, abi_long, abi_long,
20 abi_long, abi_long, abi_long);
21 void (*result)(const struct syscallname *, abi_long);
28 print_ipc_cmd(int cmd)
30 #define output_cmd(val) \
38 /* General IPC commands */
39 output_cmd( IPC_RMID );
40 output_cmd( IPC_SET );
41 output_cmd( IPC_STAT );
42 output_cmd( IPC_INFO );
43 /* msgctl() commands */
45 output_cmd( MSG_STAT );
46 output_cmd( MSG_INFO );
48 /* shmctl() commands */
49 output_cmd( SHM_LOCK );
50 output_cmd( SHM_UNLOCK );
51 output_cmd( SHM_STAT );
52 output_cmd( SHM_INFO );
53 /* semctl() commands */
57 output_cmd( GETNCNT );
58 output_cmd( GETZCNT );
61 output_cmd( SEM_STAT );
62 output_cmd( SEM_INFO );
63 output_cmd( IPC_RMID );
64 output_cmd( IPC_RMID );
65 output_cmd( IPC_RMID );
66 output_cmd( IPC_RMID );
67 output_cmd( IPC_RMID );
68 output_cmd( IPC_RMID );
69 output_cmd( IPC_RMID );
70 output_cmd( IPC_RMID );
71 output_cmd( IPC_RMID );
73 /* Some value we don't recognize */
77 #ifdef TARGET_NR__newselect
79 print_fdset(int n, abi_ulong target_fds_addr)
84 if( target_fds_addr ) {
87 target_fds = lock_user(VERIFY_READ,
89 sizeof(*target_fds)*(n / TARGET_ABI_BITS + 1),
95 for (i=n; i>=0; i--) {
96 if ((tswapl(target_fds[i / TARGET_ABI_BITS]) >> (i & (TARGET_ABI_BITS - 1))) & 1)
99 unlock_user(target_fds, target_fds_addr, 0);
105 print_timeval(abi_ulong tv_addr)
108 struct target_timeval *tv;
110 tv = lock_user(VERIFY_READ, tv_addr, sizeof(*tv), 1);
113 gemu_log("{" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "}",
114 tv->tv_sec, tv->tv_usec);
115 unlock_user(tv, tv_addr, 0);
122 * Sysycall specific output functions
126 #ifdef TARGET_NR__newselect
127 static long newselect_arg1 = 0;
128 static long newselect_arg2 = 0;
129 static long newselect_arg3 = 0;
130 static long newselect_arg4 = 0;
131 static long newselect_arg5 = 0;
134 print_newselect(const struct syscallname *name,
135 abi_long arg1, abi_long arg2, abi_long arg3,
136 abi_long arg4, abi_long arg5, abi_long arg6)
138 gemu_log("%s(" TARGET_ABI_FMT_ld ",", name->name, arg1);
139 print_fdset(arg1, arg2);
141 print_fdset(arg1, arg3);
143 print_fdset(arg1, arg4);
148 /* save for use in the return output function below */
157 #ifdef TARGET_NR_semctl
159 print_semctl(const struct syscallname *name,
160 abi_long arg1, abi_long arg2, abi_long arg3,
161 abi_long arg4, abi_long arg5, abi_long arg6)
163 gemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",", name->name, arg1, arg2);
165 gemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
170 print_execve(const struct syscallname *name,
171 abi_long arg1, abi_long arg2, abi_long arg3,
172 abi_long arg4, abi_long arg5, abi_long arg6)
174 abi_ulong arg_ptr_addr;
177 if (!(s = lock_user_string(arg1)))
179 gemu_log("%s(\"%s\",{", name->name, s);
180 unlock_user(s, arg1, 0);
182 for (arg_ptr_addr = arg2; ; arg_ptr_addr += sizeof(abi_ulong)) {
183 abi_ulong *arg_ptr, arg_addr;
185 arg_ptr = lock_user(VERIFY_READ, arg_ptr_addr, sizeof(abi_ulong), 1);
188 arg_addr = tswapl(*arg_ptr);
189 unlock_user(arg_ptr, arg_ptr_addr, 0);
192 if ((s = lock_user_string(arg_addr))) {
193 gemu_log("\"%s\",", s);
194 unlock_user(s, arg_addr, 0);
203 print_ipc(const struct syscallname *name,
204 abi_long arg1, abi_long arg2, abi_long arg3,
205 abi_long arg4, abi_long arg5, abi_long arg6)
209 gemu_log("semctl(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",", arg1, arg2);
211 gemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
214 gemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ")",
215 name->name, arg1, arg2, arg3, arg4);
221 * Variants for the return value output function
225 print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
228 gemu_log(" = -1 errno=%d (%s)\n", errno, target_strerror(errno));
230 gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
234 #if 0 /* currently unused */
236 print_syscall_ret_raw(struct syscallname *name, abi_long ret)
238 gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
242 #ifdef TARGET_NR__newselect
244 print_syscall_ret_newselect(const struct syscallname *name, abi_long ret)
246 gemu_log(" = 0x" TARGET_ABI_FMT_lx " (", ret);
247 print_fdset(newselect_arg1,newselect_arg2);
249 print_fdset(newselect_arg1,newselect_arg3);
251 print_fdset(newselect_arg1,newselect_arg4);
253 print_timeval(newselect_arg5);
258 #define LOCKED_ARG0 (1 << 0)
259 #define LOCKED_ARG1 (1 << 1)
260 #define LOCKED_ARG2 (1 << 2)
261 #define LOCKED_ARG3 (1 << 3)
262 #define LOCKED_ARG4 (1 << 4)
263 #define LOCKED_ARG5 (1 << 5)
266 abi_long arg_guest; /* guest argument */
267 uintptr_t arg_host; /* host argument */
268 int arg_locked; /* is this argument locked? */
272 * This function locks strings from guest memory and prints
273 * strace output according to format specified in strace.list.
275 * First parameter specifies, which guest arguments should be
276 * locked (LOCKED_ARG0 - LOCKED_ARG5).
279 print_locked(unsigned int locked, const struct syscallname *name,
280 abi_long arg0, abi_long arg1, abi_long arg2,
281 abi_long arg3, abi_long arg4, abi_long arg5)
283 struct args args[6] = {
284 { arg0, 0, (locked & LOCKED_ARG0) },
285 { arg1, 0, (locked & LOCKED_ARG1) },
286 { arg2, 0, (locked & LOCKED_ARG2) },
287 { arg3, 0, (locked & LOCKED_ARG3) },
288 { arg4, 0, (locked & LOCKED_ARG4) },
289 { arg5, 0, (locked & LOCKED_ARG5) },
294 for (i = 0; i < 6; i++) {
297 a->arg_host = (uintptr_t)lock_user_string(a->arg_guest);
298 if (a->arg_host == 0)
301 a->arg_host = (uintptr_t)a->arg_guest;
306 * Now we can have all strings locked and converted into host
309 gemu_log(name->format,
319 for (i = 0; i < 6; i++) {
322 unlock_user((void *)a->arg_host, a->arg_guest, 0);
327 print_1st_locked(const struct syscallname *name,
328 abi_long arg0, abi_long arg1, abi_long arg2,
329 abi_long arg3, abi_long arg4, abi_long arg5)
331 print_locked(LOCKED_ARG0, name, arg0, arg1, arg2, arg3, arg4, arg5);
335 print_2nd_locked(const struct syscallname *name,
336 abi_long arg0, abi_long arg1, abi_long arg2,
337 abi_long arg3, abi_long arg4, abi_long arg5)
339 print_locked(LOCKED_ARG1, name, arg0, arg1, arg2, arg3, arg4, arg5);
343 print_1st_and_2nd_locked(const struct syscallname *name,
344 abi_long arg0, abi_long arg1, abi_long arg2,
345 abi_long arg3, abi_long arg4, abi_long arg5)
347 print_locked(LOCKED_ARG0 | LOCKED_ARG1, name, arg0, arg1, arg2,
352 print_1st_and_3rd_locked(const struct syscallname *name,
353 abi_long arg0, abi_long arg1, abi_long arg2,
354 abi_long arg3, abi_long arg4, abi_long arg5)
356 print_locked(LOCKED_ARG0 | LOCKED_ARG2, name, arg0, arg1, arg2,
361 print_1st_2nd_and_3rd_locked(const struct syscallname *name,
362 abi_long arg0, abi_long arg1, abi_long arg2,
363 abi_long arg3, abi_long arg4, abi_long arg5)
365 print_locked(LOCKED_ARG0 | LOCKED_ARG1 | LOCKED_ARG2, name,
366 arg0, arg1, arg2, arg3, arg4, arg5);
370 print_2nd_and_4th_locked(const struct syscallname *name,
371 abi_long arg0, abi_long arg1, abi_long arg2,
372 abi_long arg3, abi_long arg4, abi_long arg5)
374 print_locked(LOCKED_ARG1 | LOCKED_ARG3, name, arg0, arg1, arg2,
379 * Here is list of syscalls that we support reading in (locking)
380 * strings from guest addresses. Every syscall that has "%s" in its
381 * parameter list and doesn't have specific print function, should
384 #define print_access print_1st_locked
385 #define print_chdir print_1st_locked
386 #define print_chmod print_1st_locked
387 #define print_creat print_1st_locked
388 #define print_execv print_1st_locked
389 #define print_faccessat print_2nd_locked
390 #define print_fchmodat print_2nd_locked
391 #define print_fchown print_1st_locked
392 #define print_fchownat print_2nd_locked
393 #define print_futimesat print_2nd_locked
394 #define print_link print_1st_and_2nd_locked
395 #define print_linkat print_2nd_and_4th_locked
396 #define print_lstat print_1st_locked
397 #define print_lstat64 print_1st_locked
398 #define print_mkdir print_1st_locked
399 #define print_mkdirat print_2nd_locked
400 #define print_mknod print_1st_locked
401 #define print_mknodat print_2nd_locked
402 #define print_mq_open print_1st_locked
403 #define print_mq_unlink print_1st_locked
404 #define print_fstatat64 print_2nd_locked
405 #define print_newfstatat print_2nd_locked
406 #define print_open print_1st_locked
407 #define print_openat print_2nd_locked
408 #define print_readlink print_1st_locked
409 #define print_readlinkat print_2nd_locked
410 #define print_rename print_1st_and_2nd_locked
411 #define print_renameat print_2nd_and_4th_locked
412 #define print_stat print_1st_locked
413 #define print_stat64 print_1st_locked
414 #define print_statfs print_1st_locked
415 #define print_statfs64 print_1st_locked
416 #define print_symlink print_1st_and_2nd_locked
417 #define print_symlinkat print_1st_and_3rd_locked
418 #define print_umount print_1st_2nd_and_3rd_locked
419 #define print_unlink print_1st_locked
420 #define print_unlinkat print_2nd_locked
421 #define print_utime print_1st_locked
422 #define print_utimensat print_2nd_locked
425 * An array of all of the syscalls we know about
428 static const struct syscallname scnames[] = {
429 #include "strace.list"
432 static int nsyscalls = ARRAY_SIZE(scnames);
435 * The public interface to this module.
438 print_syscall(int num,
439 abi_long arg1, abi_long arg2, abi_long arg3,
440 abi_long arg4, abi_long arg5, abi_long arg6)
443 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 ")";
445 gemu_log("%d ", getpid() );
447 for(i=0;i<nsyscalls;i++)
448 if( scnames[i].nr == num ) {
449 if( scnames[i].call != NULL ) {
450 scnames[i].call(&scnames[i],arg1,arg2,arg3,arg4,arg5,arg6);
452 /* XXX: this format system is broken because it uses
453 host types and host pointers for strings */
455 * It now works when it has print_xxx_locked function
456 * as its printing function.
458 if( scnames[i].format != NULL )
459 format = scnames[i].format;
460 gemu_log(format,scnames[i].name, arg1,arg2,arg3,arg4,arg5,arg6);
464 gemu_log("Unknown syscall %d\n", num);
469 print_syscall_ret(int num, abi_long ret)
473 for(i=0;i<nsyscalls;i++)
474 if( scnames[i].nr == num ) {
475 if( scnames[i].result != NULL ) {
476 scnames[i].result(&scnames[i],ret);
479 gemu_log(" = -1 errno=" TARGET_ABI_FMT_ld " (%s)\n", -ret, target_strerror(-ret));
481 gemu_log(" = " TARGET_ABI_FMT_ld "\n", ret);