ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 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> |
| 9 | #include <unistd.h> |
| 10 | #include "qemu.h" |
| 11 | |
| 12 | int do_strace=0; |
| 13 | |
| 14 | struct syscallname { |
| 15 | int nr; |
blueswir1 | 7ccfb2e | 2008-09-14 06:45:34 +0000 | [diff] [blame] | 16 | const char *name; |
| 17 | const char *format; |
| 18 | void (*call)(const struct syscallname *, |
bellard | c16f9ed | 2007-11-11 17:23:29 +0000 | [diff] [blame] | 19 | abi_long, abi_long, abi_long, |
| 20 | abi_long, abi_long, abi_long); |
blueswir1 | 7ccfb2e | 2008-09-14 06:45:34 +0000 | [diff] [blame] | 21 | void (*result)(const struct syscallname *, abi_long); |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 22 | }; |
| 23 | |
| 24 | /* |
| 25 | * Utility functions |
| 26 | */ |
| 27 | static void |
| 28 | print_ipc_cmd(int cmd) |
| 29 | { |
| 30 | #define output_cmd(val) \ |
| 31 | if( cmd == val ) { \ |
| 32 | gemu_log(#val); \ |
| 33 | return; \ |
| 34 | } |
| 35 | |
| 36 | cmd &= 0xff; |
| 37 | |
| 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 */ |
| 44 | #ifdef __USER_MISC |
| 45 | output_cmd( MSG_STAT ); |
| 46 | output_cmd( MSG_INFO ); |
| 47 | #endif |
| 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 */ |
| 54 | output_cmd( GETPID ); |
| 55 | output_cmd( GETVAL ); |
| 56 | output_cmd( GETALL ); |
| 57 | output_cmd( GETNCNT ); |
| 58 | output_cmd( GETZCNT ); |
| 59 | output_cmd( SETVAL ); |
| 60 | output_cmd( SETALL ); |
| 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 ); |
| 72 | |
| 73 | /* Some value we don't recognize */ |
| 74 | gemu_log("%d",cmd); |
| 75 | } |
| 76 | |
bellard | c16f9ed | 2007-11-11 17:23:29 +0000 | [diff] [blame] | 77 | #ifdef TARGET_NR__newselect |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 78 | static void |
bellard | c16f9ed | 2007-11-11 17:23:29 +0000 | [diff] [blame] | 79 | print_fdset(int n, abi_ulong target_fds_addr) |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 80 | { |
| 81 | int i; |
| 82 | |
| 83 | gemu_log("["); |
| 84 | if( target_fds_addr ) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 85 | abi_long *target_fds; |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 86 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 87 | target_fds = lock_user(VERIFY_READ, |
| 88 | target_fds_addr, |
| 89 | sizeof(*target_fds)*(n / TARGET_ABI_BITS + 1), |
| 90 | 1); |
| 91 | |
| 92 | if (!target_fds) |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 93 | return; |
| 94 | |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 95 | for (i=n; i>=0; i--) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 96 | if ((tswapl(target_fds[i / TARGET_ABI_BITS]) >> (i & (TARGET_ABI_BITS - 1))) & 1) |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 97 | gemu_log("%d,", i ); |
| 98 | } |
| 99 | unlock_user(target_fds, target_fds_addr, 0); |
| 100 | } |
| 101 | gemu_log("]"); |
| 102 | } |
| 103 | |
| 104 | static void |
bellard | c16f9ed | 2007-11-11 17:23:29 +0000 | [diff] [blame] | 105 | print_timeval(abi_ulong tv_addr) |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 106 | { |
| 107 | if( tv_addr ) { |
| 108 | struct target_timeval *tv; |
| 109 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 110 | tv = lock_user(VERIFY_READ, tv_addr, sizeof(*tv), 1); |
| 111 | if (!tv) |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 112 | return; |
ths | f3e3285 | 2007-11-03 15:12:16 +0000 | [diff] [blame] | 113 | gemu_log("{" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "}", |
| 114 | tv->tv_sec, tv->tv_usec); |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 115 | unlock_user(tv, tv_addr, 0); |
| 116 | } else |
| 117 | gemu_log("NULL"); |
| 118 | } |
bellard | c16f9ed | 2007-11-11 17:23:29 +0000 | [diff] [blame] | 119 | #endif |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 120 | |
| 121 | /* |
| 122 | * Sysycall specific output functions |
| 123 | */ |
| 124 | |
| 125 | /* select */ |
bellard | c16f9ed | 2007-11-11 17:23:29 +0000 | [diff] [blame] | 126 | #ifdef TARGET_NR__newselect |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 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; |
| 132 | |
| 133 | static void |
blueswir1 | 7ccfb2e | 2008-09-14 06:45:34 +0000 | [diff] [blame] | 134 | print_newselect(const struct syscallname *name, |
bellard | c16f9ed | 2007-11-11 17:23:29 +0000 | [diff] [blame] | 135 | abi_long arg1, abi_long arg2, abi_long arg3, |
| 136 | abi_long arg4, abi_long arg5, abi_long arg6) |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 137 | { |
bellard | c16f9ed | 2007-11-11 17:23:29 +0000 | [diff] [blame] | 138 | gemu_log("%s(" TARGET_ABI_FMT_ld ",", name->name, arg1); |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 139 | print_fdset(arg1, arg2); |
| 140 | gemu_log(","); |
| 141 | print_fdset(arg1, arg3); |
| 142 | gemu_log(","); |
| 143 | print_fdset(arg1, arg4); |
| 144 | gemu_log(","); |
| 145 | print_timeval(arg5); |
| 146 | gemu_log(")"); |
| 147 | |
| 148 | /* save for use in the return output function below */ |
| 149 | newselect_arg1=arg1; |
| 150 | newselect_arg2=arg2; |
| 151 | newselect_arg3=arg3; |
| 152 | newselect_arg4=arg4; |
| 153 | newselect_arg5=arg5; |
| 154 | } |
bellard | c16f9ed | 2007-11-11 17:23:29 +0000 | [diff] [blame] | 155 | #endif |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 156 | |
blueswir1 | 3e46b2e | 2008-10-03 19:01:41 +0000 | [diff] [blame] | 157 | #ifdef TARGET_NR_semctl |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 158 | static void |
blueswir1 | 7ccfb2e | 2008-09-14 06:45:34 +0000 | [diff] [blame] | 159 | print_semctl(const struct syscallname *name, |
bellard | c16f9ed | 2007-11-11 17:23:29 +0000 | [diff] [blame] | 160 | abi_long arg1, abi_long arg2, abi_long arg3, |
| 161 | abi_long arg4, abi_long arg5, abi_long arg6) |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 162 | { |
bellard | c16f9ed | 2007-11-11 17:23:29 +0000 | [diff] [blame] | 163 | gemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",", name->name, arg1, arg2); |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 164 | print_ipc_cmd(arg3); |
bellard | c16f9ed | 2007-11-11 17:23:29 +0000 | [diff] [blame] | 165 | gemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4); |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 166 | } |
blueswir1 | 3e46b2e | 2008-10-03 19:01:41 +0000 | [diff] [blame] | 167 | #endif |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 168 | |
| 169 | static void |
blueswir1 | 7ccfb2e | 2008-09-14 06:45:34 +0000 | [diff] [blame] | 170 | print_execve(const struct syscallname *name, |
bellard | c16f9ed | 2007-11-11 17:23:29 +0000 | [diff] [blame] | 171 | abi_long arg1, abi_long arg2, abi_long arg3, |
| 172 | abi_long arg4, abi_long arg5, abi_long arg6) |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 173 | { |
bellard | c16f9ed | 2007-11-11 17:23:29 +0000 | [diff] [blame] | 174 | abi_ulong arg_ptr_addr; |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 175 | char *s; |
| 176 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 177 | if (!(s = lock_user_string(arg1))) |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 178 | return; |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 179 | gemu_log("%s(\"%s\",{", name->name, s); |
| 180 | unlock_user(s, arg1, 0); |
| 181 | |
bellard | c16f9ed | 2007-11-11 17:23:29 +0000 | [diff] [blame] | 182 | for (arg_ptr_addr = arg2; ; arg_ptr_addr += sizeof(abi_ulong)) { |
blueswir1 | 98448f5 | 2008-09-30 18:16:09 +0000 | [diff] [blame] | 183 | abi_ulong *arg_ptr, arg_addr; |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 184 | |
bellard | c16f9ed | 2007-11-11 17:23:29 +0000 | [diff] [blame] | 185 | arg_ptr = lock_user(VERIFY_READ, arg_ptr_addr, sizeof(abi_ulong), 1); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 186 | if (!arg_ptr) |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 187 | return; |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 188 | arg_addr = tswapl(*arg_ptr); |
| 189 | unlock_user(arg_ptr, arg_ptr_addr, 0); |
| 190 | if (!arg_addr) |
| 191 | break; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 192 | if ((s = lock_user_string(arg_addr))) { |
| 193 | gemu_log("\"%s\",", s); |
blueswir1 | 98448f5 | 2008-09-30 18:16:09 +0000 | [diff] [blame] | 194 | unlock_user(s, arg_addr, 0); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 195 | } |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | gemu_log("NULL})"); |
| 199 | } |
| 200 | |
bellard | c16f9ed | 2007-11-11 17:23:29 +0000 | [diff] [blame] | 201 | #ifdef TARGET_NR_ipc |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 202 | static void |
blueswir1 | 7ccfb2e | 2008-09-14 06:45:34 +0000 | [diff] [blame] | 203 | print_ipc(const struct syscallname *name, |
bellard | c16f9ed | 2007-11-11 17:23:29 +0000 | [diff] [blame] | 204 | abi_long arg1, abi_long arg2, abi_long arg3, |
| 205 | abi_long arg4, abi_long arg5, abi_long arg6) |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 206 | { |
| 207 | switch(arg1) { |
| 208 | case IPCOP_semctl: |
blueswir1 | 7ccfb2e | 2008-09-14 06:45:34 +0000 | [diff] [blame] | 209 | gemu_log("semctl(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",", arg1, arg2); |
| 210 | print_ipc_cmd(arg3); |
| 211 | gemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4); |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 212 | break; |
| 213 | default: |
bellard | c16f9ed | 2007-11-11 17:23:29 +0000 | [diff] [blame] | 214 | gemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ")", |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 215 | name->name, arg1, arg2, arg3, arg4); |
| 216 | } |
| 217 | } |
bellard | c16f9ed | 2007-11-11 17:23:29 +0000 | [diff] [blame] | 218 | #endif |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 219 | |
| 220 | /* |
| 221 | * Variants for the return value output function |
| 222 | */ |
| 223 | |
| 224 | static void |
blueswir1 | 7ccfb2e | 2008-09-14 06:45:34 +0000 | [diff] [blame] | 225 | print_syscall_ret_addr(const struct syscallname *name, abi_long ret) |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 226 | { |
| 227 | if( ret == -1 ) { |
| 228 | gemu_log(" = -1 errno=%d (%s)\n", errno, target_strerror(errno)); |
| 229 | } else { |
bellard | 29fa23e | 2007-11-11 17:55:50 +0000 | [diff] [blame] | 230 | gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret); |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | |
ths | f3e3285 | 2007-11-03 15:12:16 +0000 | [diff] [blame] | 234 | #if 0 /* currently unused */ |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 235 | static void |
bellard | c16f9ed | 2007-11-11 17:23:29 +0000 | [diff] [blame] | 236 | print_syscall_ret_raw(struct syscallname *name, abi_long ret) |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 237 | { |
bellard | 29fa23e | 2007-11-11 17:55:50 +0000 | [diff] [blame] | 238 | gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret); |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 239 | } |
ths | f3e3285 | 2007-11-03 15:12:16 +0000 | [diff] [blame] | 240 | #endif |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 241 | |
ths | f3e3285 | 2007-11-03 15:12:16 +0000 | [diff] [blame] | 242 | #ifdef TARGET_NR__newselect |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 243 | static void |
blueswir1 | 7ccfb2e | 2008-09-14 06:45:34 +0000 | [diff] [blame] | 244 | print_syscall_ret_newselect(const struct syscallname *name, abi_long ret) |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 245 | { |
bellard | 29fa23e | 2007-11-11 17:55:50 +0000 | [diff] [blame] | 246 | gemu_log(" = 0x" TARGET_ABI_FMT_lx " (", ret); |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 247 | print_fdset(newselect_arg1,newselect_arg2); |
| 248 | gemu_log(","); |
| 249 | print_fdset(newselect_arg1,newselect_arg3); |
| 250 | gemu_log(","); |
| 251 | print_fdset(newselect_arg1,newselect_arg4); |
| 252 | gemu_log(","); |
| 253 | print_timeval(newselect_arg5); |
| 254 | gemu_log(")\n"); |
| 255 | } |
ths | f3e3285 | 2007-11-03 15:12:16 +0000 | [diff] [blame] | 256 | #endif |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 257 | |
| 258 | /* |
| 259 | * An array of all of the syscalls we know about |
| 260 | */ |
| 261 | |
blueswir1 | 7ccfb2e | 2008-09-14 06:45:34 +0000 | [diff] [blame] | 262 | static const struct syscallname scnames[] = { |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 263 | #include "strace.list" |
| 264 | }; |
| 265 | |
malc | b1503cd | 2008-12-22 20:33:55 +0000 | [diff] [blame] | 266 | static int nsyscalls = ARRAY_SIZE(scnames); |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 267 | |
| 268 | /* |
| 269 | * The public interface to this module. |
| 270 | */ |
| 271 | void |
| 272 | print_syscall(int num, |
bellard | c16f9ed | 2007-11-11 17:23:29 +0000 | [diff] [blame] | 273 | abi_long arg1, abi_long arg2, abi_long arg3, |
| 274 | abi_long arg4, abi_long arg5, abi_long arg6) |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 275 | { |
| 276 | int i; |
blueswir1 | 7ccfb2e | 2008-09-14 06:45:34 +0000 | [diff] [blame] | 277 | 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 ")"; |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 278 | |
| 279 | gemu_log("%d ", getpid() ); |
| 280 | |
| 281 | for(i=0;i<nsyscalls;i++) |
| 282 | if( scnames[i].nr == num ) { |
| 283 | if( scnames[i].call != NULL ) { |
| 284 | scnames[i].call(&scnames[i],arg1,arg2,arg3,arg4,arg5,arg6); |
| 285 | } else { |
bellard | 6b23f77 | 2007-11-14 18:04:05 +0000 | [diff] [blame] | 286 | /* XXX: this format system is broken because it uses |
| 287 | host types and host pointers for strings */ |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 288 | if( scnames[i].format != NULL ) |
| 289 | format = scnames[i].format; |
| 290 | gemu_log(format,scnames[i].name, arg1,arg2,arg3,arg4,arg5,arg6); |
| 291 | } |
pbrook | 74c11e5 | 2008-05-29 13:49:09 +0000 | [diff] [blame] | 292 | return; |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 293 | } |
pbrook | 74c11e5 | 2008-05-29 13:49:09 +0000 | [diff] [blame] | 294 | gemu_log("Unknown syscall %d\n", num); |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | |
| 298 | void |
bellard | c16f9ed | 2007-11-11 17:23:29 +0000 | [diff] [blame] | 299 | print_syscall_ret(int num, abi_long ret) |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 300 | { |
| 301 | int i; |
| 302 | |
| 303 | for(i=0;i<nsyscalls;i++) |
| 304 | if( scnames[i].nr == num ) { |
| 305 | if( scnames[i].result != NULL ) { |
| 306 | scnames[i].result(&scnames[i],ret); |
| 307 | } else { |
| 308 | if( ret < 0 ) { |
bellard | c16f9ed | 2007-11-11 17:23:29 +0000 | [diff] [blame] | 309 | gemu_log(" = -1 errno=" TARGET_ABI_FMT_ld " (%s)\n", -ret, target_strerror(-ret)); |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 310 | } else { |
bellard | c16f9ed | 2007-11-11 17:23:29 +0000 | [diff] [blame] | 311 | gemu_log(" = " TARGET_ABI_FMT_ld "\n", ret); |
ths | 33189d3 | 2007-11-01 00:13:36 +0000 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | break; |
| 315 | } |
| 316 | } |