Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl> |
| 3 | * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl> |
| 4 | * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com> |
Wichert Akkerman | 4dc8a2a | 1999-12-23 14:20:14 +0000 | [diff] [blame] | 5 | * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl> |
| 6 | * Copyright (c) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation |
| 7 | * Linux for s390 port by D.J. Barrow |
| 8 | * <barrow_dj@mail.yahoo.com,djbarrow@de.ibm.com> |
| 9 | * |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 10 | * All rights reserved. |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * 1. Redistributions of source code must retain the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer. |
| 17 | * 2. Redistributions in binary form must reproduce the above copyright |
| 18 | * notice, this list of conditions and the following disclaimer in the |
| 19 | * documentation and/or other materials provided with the distribution. |
| 20 | * 3. The name of the author may not be used to endorse or promote products |
| 21 | * derived from this software without specific prior written permission. |
| 22 | * |
| 23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 25 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 26 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 | * |
| 34 | * $Id$ |
| 35 | */ |
| 36 | |
| 37 | #include "defs.h" |
| 38 | |
| 39 | #include <fcntl.h> |
| 40 | #include <sys/stat.h> |
| 41 | #include <sys/time.h> |
| 42 | #include <sys/wait.h> |
| 43 | #include <sys/resource.h> |
| 44 | #include <sys/utsname.h> |
| 45 | #include <sys/user.h> |
| 46 | #include <sys/syscall.h> |
| 47 | #include <signal.h> |
| 48 | #ifdef SUNOS4 |
| 49 | #include <machine/reg.h> |
| 50 | #endif /* SUNOS4 */ |
| 51 | |
Wichert Akkerman | 15dea97 | 1999-10-06 13:06:34 +0000 | [diff] [blame] | 52 | #if HAVE_LINUX_PTRACE_H |
| 53 | #undef PTRACE_SYSCALL |
Wichert Akkerman | 36915a1 | 1999-07-13 15:45:02 +0000 | [diff] [blame] | 54 | #include <linux/ptrace.h> |
| 55 | #endif |
| 56 | |
| 57 | #ifdef HAVE_SYS_REG_H |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 58 | # include <sys/reg.h> |
Wichert Akkerman | 15dea97 | 1999-10-06 13:06:34 +0000 | [diff] [blame] | 59 | #ifndef PTRACE_PEEKUSR |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 60 | # define PTRACE_PEEKUSR PTRACE_PEEKUSER |
Wichert Akkerman | 15dea97 | 1999-10-06 13:06:34 +0000 | [diff] [blame] | 61 | #endif |
| 62 | #ifndef PTRACE_POKEUSR |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 63 | # define PTRACE_POKEUSR PTRACE_POKEUSER |
| 64 | #endif |
Wichert Akkerman | 15dea97 | 1999-10-06 13:06:34 +0000 | [diff] [blame] | 65 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 66 | |
| 67 | #ifdef LINUX |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 68 | #include <asm/posix_types.h> |
| 69 | #undef GETGROUPS_T |
| 70 | #define GETGROUPS_T __kernel_gid_t |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 71 | #endif /* LINUX */ |
| 72 | |
| 73 | #ifdef HAVE_PRCTL |
| 74 | #include <sys/prctl.h> |
| 75 | #endif |
| 76 | |
| 77 | #ifndef WCOREDUMP |
| 78 | #define WCOREDUMP(status) ((status) & 0200) |
| 79 | #endif |
| 80 | |
Wichert Akkerman | 7a0b649 | 1999-12-23 15:08:17 +0000 | [diff] [blame] | 81 | /* WTA: this was `&& !defined(LINUXSPARC)', this seems unneeded though? */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 82 | #if defined(HAVE_PRCTL) |
| 83 | static struct xlat prctl_options[] = { |
| 84 | #ifdef PR_MAXPROCS |
| 85 | { PR_MAXPROCS, "PR_MAXPROCS" }, |
| 86 | #endif |
| 87 | #ifdef PR_ISBLOCKED |
| 88 | { PR_ISBLOCKED, "PR_ISBLOCKED" }, |
| 89 | #endif |
| 90 | #ifdef PR_SETSTACKSIZE |
| 91 | { PR_SETSTACKSIZE, "PR_SETSTACKSIZE" }, |
| 92 | #endif |
| 93 | #ifdef PR_GETSTACKSIZE |
| 94 | { PR_GETSTACKSIZE, "PR_GETSTACKSIZE" }, |
| 95 | #endif |
| 96 | #ifdef PR_MAXPPROCS |
| 97 | { PR_MAXPPROCS, "PR_MAXPPROCS" }, |
| 98 | #endif |
| 99 | #ifdef PR_UNBLKONEXEC |
| 100 | { PR_UNBLKONEXEC, "PR_UNBLKONEXEC" }, |
| 101 | #endif |
| 102 | #ifdef PR_ATOMICSIM |
| 103 | { PR_ATOMICSIM, "PR_ATOMICSIM" }, |
| 104 | #endif |
| 105 | #ifdef PR_SETEXITSIG |
| 106 | { PR_SETEXITSIG, "PR_SETEXITSIG" }, |
| 107 | #endif |
| 108 | #ifdef PR_RESIDENT |
| 109 | { PR_RESIDENT, "PR_RESIDENT" }, |
| 110 | #endif |
| 111 | #ifdef PR_ATTACHADDR |
| 112 | { PR_ATTACHADDR, "PR_ATTACHADDR" }, |
| 113 | #endif |
| 114 | #ifdef PR_DETACHADDR |
| 115 | { PR_DETACHADDR, "PR_DETACHADDR" }, |
| 116 | #endif |
| 117 | #ifdef PR_TERMCHILD |
| 118 | { PR_TERMCHILD, "PR_TERMCHILD" }, |
| 119 | #endif |
| 120 | #ifdef PR_GETSHMASK |
| 121 | { PR_GETSHMASK, "PR_GETSHMASK" }, |
| 122 | #endif |
| 123 | #ifdef PR_GETNSHARE |
| 124 | { PR_GETNSHARE, "PR_GETNSHARE" }, |
| 125 | #endif |
| 126 | #if defined(PR_SET_PDEATHSIG) |
| 127 | { PR_SET_PDEATHSIG, "PR_SET_PDEATHSIG" }, |
| 128 | #endif |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 129 | #ifdef PR_COREPID |
| 130 | { PR_COREPID, "PR_COREPID" }, |
| 131 | #endif |
| 132 | #ifdef PR_ATTACHADDRPERM |
| 133 | { PR_ATTACHADDRPERM, "PR_ATTACHADDRPERM" }, |
| 134 | #endif |
| 135 | #ifdef PR_PTHREADEXIT |
| 136 | { PR_PTHREADEXIT, "PR_PTHREADEXIT" }, |
| 137 | #endif |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 138 | #ifdef PR_SET_PDEATHSIG |
| 139 | { PR_SET_PDEATHSIG, "PR_SET_PDEATHSIG" }, |
| 140 | #endif |
| 141 | #ifdef PR_GET_PDEATHSIG |
| 142 | { PR_GET_PDEATHSIG, "PR_GET_PDEATHSIG" }, |
| 143 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 144 | { 0, NULL }, |
| 145 | }; |
| 146 | |
| 147 | int |
| 148 | sys_prctl(tcp) |
| 149 | struct tcb *tcp; |
| 150 | { |
| 151 | int i; |
| 152 | |
| 153 | if (entering(tcp)) { |
| 154 | printxval(prctl_options, tcp->u_arg[0], "PR_???"); |
| 155 | switch (tcp->u_arg[0]) { |
| 156 | #ifdef PR_GETNSHARE |
| 157 | case PR_GETNSHARE: |
| 158 | break; |
| 159 | #endif |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 160 | #ifdef PR_SET_DEATHSIG |
| 161 | case PR_GET_PDEATHSIG: |
| 162 | break; |
| 163 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 164 | default: |
| 165 | for (i = 1; i < tcp->u_nargs; i++) |
| 166 | tprintf(", %#lx", tcp->u_arg[i]); |
| 167 | break; |
| 168 | } |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 169 | } else { |
| 170 | switch (tcp->u_arg[0]) { |
| 171 | #ifdef PR_GET_PDEATHSIG |
| 172 | case PR_GET_PDEATHSIG: |
| 173 | for (i=1; i<tcp->u_nargs; i++) |
Wichert Akkerman | 4dc8a2a | 1999-12-23 14:20:14 +0000 | [diff] [blame] | 174 | tprintf(", %#lx", tcp->u_arg[i]); |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 175 | break; |
| 176 | #endif |
| 177 | default: |
| 178 | break; |
| 179 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 180 | } |
| 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | #endif /* HAVE_PRCTL */ |
| 185 | |
| 186 | int |
| 187 | sys_gethostid(tcp) |
| 188 | struct tcb *tcp; |
| 189 | { |
| 190 | if (exiting(tcp)) |
| 191 | return RVAL_HEX; |
| 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | int |
| 196 | sys_sethostname(tcp) |
| 197 | struct tcb *tcp; |
| 198 | { |
| 199 | if (entering(tcp)) { |
| 200 | printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]); |
| 201 | tprintf(", %lu", tcp->u_arg[1]); |
| 202 | } |
| 203 | return 0; |
| 204 | } |
| 205 | |
| 206 | int |
| 207 | sys_gethostname(tcp) |
| 208 | struct tcb *tcp; |
| 209 | { |
| 210 | if (exiting(tcp)) { |
| 211 | if (syserror(tcp)) |
| 212 | tprintf("%#lx", tcp->u_arg[0]); |
| 213 | else |
| 214 | printpath(tcp, tcp->u_arg[0]); |
| 215 | tprintf(", %lu", tcp->u_arg[1]); |
| 216 | } |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | int |
| 221 | sys_setdomainname(tcp) |
| 222 | struct tcb *tcp; |
| 223 | { |
| 224 | if (entering(tcp)) { |
| 225 | printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]); |
| 226 | tprintf(", %lu", tcp->u_arg[1]); |
| 227 | } |
| 228 | return 0; |
| 229 | } |
| 230 | |
Wichert Akkerman | 5daa028 | 1999-03-15 19:49:42 +0000 | [diff] [blame] | 231 | #if !defined(LINUX) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 232 | |
| 233 | int |
| 234 | sys_getdomainname(tcp) |
| 235 | struct tcb *tcp; |
| 236 | { |
| 237 | if (exiting(tcp)) { |
| 238 | if (syserror(tcp)) |
| 239 | tprintf("%#lx", tcp->u_arg[0]); |
| 240 | else |
| 241 | printpath(tcp, tcp->u_arg[0]); |
| 242 | tprintf(", %lu", tcp->u_arg[1]); |
| 243 | } |
| 244 | return 0; |
| 245 | } |
| 246 | #endif /* !LINUX */ |
| 247 | |
| 248 | int |
| 249 | sys_exit(tcp) |
| 250 | struct tcb *tcp; |
| 251 | { |
| 252 | if (exiting(tcp)) { |
| 253 | fprintf(stderr, "_exit returned!\n"); |
| 254 | return -1; |
| 255 | } |
| 256 | /* special case: we stop tracing this process, finish line now */ |
| 257 | tprintf("%ld) ", tcp->u_arg[0]); |
| 258 | tabto(acolumn); |
| 259 | tprintf("= ?"); |
| 260 | printtrailer(tcp); |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | int |
| 265 | internal_exit(tcp) |
| 266 | struct tcb *tcp; |
| 267 | { |
| 268 | if (entering(tcp)) |
| 269 | tcp->flags |= TCB_EXITING; |
| 270 | return 0; |
| 271 | } |
| 272 | |
| 273 | #ifdef SVR4 |
| 274 | |
| 275 | int |
| 276 | sys_fork(tcp) |
| 277 | struct tcb *tcp; |
| 278 | { |
| 279 | if (exiting(tcp)) { |
| 280 | if (getrval2(tcp)) { |
| 281 | tcp->auxstr = "child process"; |
| 282 | return RVAL_UDECIMAL | RVAL_STR; |
| 283 | } |
| 284 | } |
| 285 | return 0; |
| 286 | } |
| 287 | |
| 288 | int |
Pavel Machek | 9a9f10b | 2000-02-01 16:22:52 +0000 | [diff] [blame^] | 289 | change_syscall(tcp, new) |
| 290 | struct tcb *tcp; |
| 291 | int new; |
| 292 | { |
| 293 | #if defined(I386) && defined(LINUX) |
| 294 | /* Attempt to make vfork into fork, which we can follow. */ |
| 295 | if (ptrace(PTRACE_POKEUSER, tcp->pid, |
| 296 | (void *)(ORIG_EAX * 4), new) < 0) |
| 297 | return -1; |
| 298 | return 0; |
| 299 | #endif |
| 300 | return -1; |
| 301 | } |
| 302 | |
| 303 | int |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 304 | internal_fork(tcp) |
| 305 | struct tcb *tcp; |
| 306 | { |
| 307 | struct tcb *tcpchild; |
| 308 | |
| 309 | if (exiting(tcp)) { |
| 310 | if (getrval2(tcp)) |
| 311 | return 0; |
| 312 | if (!followfork) |
| 313 | return 0; |
| 314 | if (nprocs == MAX_PROCS) { |
| 315 | tcp->flags &= ~TCB_FOLLOWFORK; |
| 316 | fprintf(stderr, "sys_fork: tcb table full\n"); |
| 317 | return 0; |
| 318 | } |
| 319 | else |
| 320 | tcp->flags |= TCB_FOLLOWFORK; |
| 321 | if (syserror(tcp)) |
| 322 | return 0; |
| 323 | if ((tcpchild = alloctcb(tcp->u_rval)) == NULL) { |
| 324 | fprintf(stderr, "sys_fork: tcb table full\n"); |
| 325 | return 0; |
| 326 | } |
| 327 | proc_open(tcpchild, 1); |
| 328 | } |
| 329 | return 0; |
| 330 | } |
| 331 | |
| 332 | #else /* !SVR4 */ |
| 333 | |
Wichert Akkerman | 7a0b649 | 1999-12-23 15:08:17 +0000 | [diff] [blame] | 334 | #ifdef LINUX |
| 335 | |
| 336 | /* defines copied from linux/sched.h since we can't include that |
| 337 | * ourselves (it conflicts with *lots* of libc includes) |
| 338 | */ |
| 339 | #define CSIGNAL 0x000000ff /* signal mask to be sent at exit */ |
| 340 | #define CLONE_VM 0x00000100 /* set if VM shared between processes */ |
| 341 | #define CLONE_FS 0x00000200 /* set if fs info shared between processes */ |
| 342 | #define CLONE_FILES 0x00000400 /* set if open files shared between processes */ |
| 343 | #define CLONE_SIGHAND 0x00000800 /* set if signal handlers shared */ |
| 344 | #define CLONE_PID 0x00001000 /* set if pid shared */ |
| 345 | #define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */ |
| 346 | #define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */ |
| 347 | #define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */ |
| 348 | |
| 349 | static struct xlat clone_flags[] = { |
| 350 | { CLONE_VM, "CLONE_VM" }, |
| 351 | { CLONE_FS, "CLONE_FS" }, |
| 352 | { CLONE_FILES, "CLONE_FILES" }, |
| 353 | { CLONE_SIGHAND, "CLONE_SIGHAND" }, |
| 354 | { CLONE_PID, "CLONE_PID" }, |
| 355 | { CLONE_PTRACE, "CLONE_PTRACE" }, |
| 356 | { CLONE_VFORK, "CLONE_VFORK" }, |
| 357 | { CLONE_PARENT, "CLONE_PARENT" }, |
| 358 | { 0, NULL }, |
| 359 | }; |
| 360 | |
| 361 | #endif |
| 362 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 363 | int |
| 364 | sys_fork(tcp) |
| 365 | struct tcb *tcp; |
| 366 | { |
| 367 | if (exiting(tcp)) |
| 368 | return RVAL_UDECIMAL; |
| 369 | return 0; |
| 370 | } |
| 371 | |
Wichert Akkerman | 7a0b649 | 1999-12-23 15:08:17 +0000 | [diff] [blame] | 372 | #ifdef SYS_clone |
| 373 | int |
| 374 | internal_clone(tcp) |
| 375 | struct tcb *tcp; |
| 376 | { |
Ulrich Drepper | 90512f0 | 1999-12-24 07:22:25 +0000 | [diff] [blame] | 377 | struct tcb *tcpchild; |
| 378 | int pid; |
| 379 | int dont_follow = 0; |
Wichert Akkerman | 7a0b649 | 1999-12-23 15:08:17 +0000 | [diff] [blame] | 380 | if (entering(tcp)) { |
| 381 | tprintf("fn=%#lx, child_stack=%#lx, flags=", |
| 382 | tcp->u_arg[0], tcp->u_arg[1]); |
| 383 | if (printflags(clone_flags, tcp->u_arg[2]) == 0) |
| 384 | tprintf("0"); |
| 385 | tprintf(", args=%#lx", tcp->u_arg[3]); |
| 386 | |
| 387 | /* For now we don't follow clone yet.. we're just preparing the code */ |
| 388 | dont_follow = 1; |
| 389 | |
| 390 | if (!followfork || dont_follow) |
| 391 | return 0; |
| 392 | if (nprocs == MAX_PROCS) { |
| 393 | tcp->flags &= ~TCB_FOLLOWFORK; |
| 394 | fprintf(stderr, "sys_fork: tcb table full\n"); |
| 395 | return 0; |
| 396 | } |
| 397 | tcp->flags |= TCB_FOLLOWFORK; |
| 398 | |
| 399 | /* XXX |
Ulrich Drepper | 90512f0 | 1999-12-24 07:22:25 +0000 | [diff] [blame] | 400 | * We will take the simple approach and add CLONE_PTRACE to the clone |
Wichert Akkerman | 7a0b649 | 1999-12-23 15:08:17 +0000 | [diff] [blame] | 401 | * options. This only works on Linux 2.2.x and later. This means that |
| 402 | * we break all programs using clone on older kernels.. |
| 403 | * We should try to fallback to the bpt-trick if this fails, but right |
| 404 | * now we don't. |
| 405 | */ |
| 406 | |
| 407 | /* TODO: actually change the flags */ |
| 408 | } else { |
| 409 | if (!(tcp->flags & TCB_FOLLOWFORK)) |
| 410 | return 0; |
| 411 | |
| 412 | if (syserror(tcp)) |
| 413 | return 0; |
| 414 | |
| 415 | pid = tcp->u_rval; |
| 416 | if ((tcpchild = alloctcb(pid)) == NULL) { |
| 417 | fprintf(stderr, " [tcb table full]\n"); |
| 418 | kill(pid, SIGKILL); /* XXX */ |
| 419 | return 0; |
| 420 | } |
| 421 | |
| 422 | /* For fork we need to re-attach, but thanks to CLONE_PTRACE we're |
| 423 | * already attached. |
| 424 | */ |
Ulrich Drepper | 90512f0 | 1999-12-24 07:22:25 +0000 | [diff] [blame] | 425 | tcpchild->flags |= TCB_ATTACHED; |
| 426 | newoutf(tcpchild); |
Wichert Akkerman | 7a0b649 | 1999-12-23 15:08:17 +0000 | [diff] [blame] | 427 | tcp->nchildren++; |
| 428 | if (!qflag) |
| 429 | fprintf(stderr, "Process %d attached\n", pid); |
| 430 | } |
| 431 | return 0; |
| 432 | } |
| 433 | #endif |
| 434 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 435 | int |
| 436 | internal_fork(tcp) |
| 437 | struct tcb *tcp; |
| 438 | { |
| 439 | struct tcb *tcpchild; |
| 440 | int pid; |
Nate Sammons | ccd8f21 | 1999-03-29 22:57:54 +0000 | [diff] [blame] | 441 | int dont_follow = 0; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 442 | |
| 443 | #ifdef SYS_vfork |
Nate Sammons | ccd8f21 | 1999-03-29 22:57:54 +0000 | [diff] [blame] | 444 | if (tcp->scno == SYS_vfork) { |
Nate Sammons | ccd8f21 | 1999-03-29 22:57:54 +0000 | [diff] [blame] | 445 | /* Attempt to make vfork into fork, which we can follow. */ |
| 446 | if (!followvfork || |
Pavel Machek | 9a9f10b | 2000-02-01 16:22:52 +0000 | [diff] [blame^] | 447 | change_syscall(tcp, SYS_fork) < 0) |
Nate Sammons | ccd8f21 | 1999-03-29 22:57:54 +0000 | [diff] [blame] | 448 | dont_follow = 1; |
Nate Sammons | ccd8f21 | 1999-03-29 22:57:54 +0000 | [diff] [blame] | 449 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 450 | #endif |
Nate Sammons | 38508fd | 1999-03-29 23:02:29 +0000 | [diff] [blame] | 451 | #ifdef SYS_clone |
| 452 | /* clone can do many things, not all of which we know how to handle. |
Wichert Akkerman | 7a0b649 | 1999-12-23 15:08:17 +0000 | [diff] [blame] | 453 | Don't do much for now. */ |
| 454 | if (tcp->scno == SYS_clone) { |
| 455 | if (entering(tcp)) { |
| 456 | tprintf("fn=%#lx, child_stack=%#lx, flags=", |
| 457 | tcp->u_arg[0], tcp->u_arg[1]); |
| 458 | if (printflags(clone_flags, tcp->u_arg[2]) == 0) |
| 459 | tprintf("0"); |
| 460 | tprintf(", args=%#lx", tcp->u_arg[3]); |
| 461 | } |
Nate Sammons | 38508fd | 1999-03-29 23:02:29 +0000 | [diff] [blame] | 462 | dont_follow = 1; |
Wichert Akkerman | 7a0b649 | 1999-12-23 15:08:17 +0000 | [diff] [blame] | 463 | } |
Nate Sammons | 38508fd | 1999-03-29 23:02:29 +0000 | [diff] [blame] | 464 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 465 | if (entering(tcp)) { |
Nate Sammons | ccd8f21 | 1999-03-29 22:57:54 +0000 | [diff] [blame] | 466 | if (!followfork || dont_follow) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 467 | return 0; |
| 468 | if (nprocs == MAX_PROCS) { |
| 469 | tcp->flags &= ~TCB_FOLLOWFORK; |
| 470 | fprintf(stderr, "sys_fork: tcb table full\n"); |
| 471 | return 0; |
| 472 | } |
| 473 | tcp->flags |= TCB_FOLLOWFORK; |
| 474 | if (setbpt(tcp) < 0) |
| 475 | return 0; |
Wichert Akkerman | 7a0b649 | 1999-12-23 15:08:17 +0000 | [diff] [blame] | 476 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 477 | else { |
| 478 | int bpt = tcp->flags & TCB_BPTSET; |
| 479 | |
| 480 | if (!(tcp->flags & TCB_FOLLOWFORK)) |
| 481 | return 0; |
| 482 | if (bpt) |
| 483 | clearbpt(tcp); |
| 484 | |
| 485 | if (syserror(tcp)) |
| 486 | return 0; |
| 487 | |
| 488 | pid = tcp->u_rval; |
| 489 | if ((tcpchild = alloctcb(pid)) == NULL) { |
| 490 | fprintf(stderr, " [tcb table full]\n"); |
| 491 | kill(pid, SIGKILL); /* XXX */ |
| 492 | return 0; |
| 493 | } |
| 494 | #ifdef LINUX |
| 495 | if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) { |
| 496 | perror("PTRACE_ATTACH"); |
| 497 | fprintf(stderr, "Too late?\n"); |
| 498 | droptcb(tcpchild); |
| 499 | return 0; |
| 500 | } |
| 501 | #endif /* LINUX */ |
| 502 | #ifdef SUNOS4 |
| 503 | #ifdef oldway |
| 504 | /* The child must have run before it can be attached. */ |
| 505 | { |
| 506 | struct timeval tv; |
| 507 | tv.tv_sec = 0; |
| 508 | tv.tv_usec = 10000; |
| 509 | select(0, NULL, NULL, NULL, &tv); |
| 510 | } |
| 511 | if (ptrace(PTRACE_ATTACH, pid, (char *)1, 0) < 0) { |
| 512 | perror("PTRACE_ATTACH"); |
| 513 | fprintf(stderr, "Too late?\n"); |
| 514 | droptcb(tcpchild); |
| 515 | return 0; |
| 516 | } |
| 517 | #else /* !oldway */ |
| 518 | /* Try to catch the new process as soon as possible. */ |
| 519 | { |
| 520 | int i; |
| 521 | for (i = 0; i < 1024; i++) |
| 522 | if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) >= 0) |
| 523 | break; |
| 524 | if (i == 1024) { |
| 525 | perror("PTRACE_ATTACH"); |
| 526 | fprintf(stderr, "Too late?\n"); |
| 527 | droptcb(tcpchild); |
| 528 | return 0; |
| 529 | } |
| 530 | } |
| 531 | #endif /* !oldway */ |
| 532 | #endif /* SUNOS4 */ |
| 533 | tcpchild->flags |= TCB_ATTACHED; |
| 534 | /* Child has BPT too, must be removed on first occasion */ |
| 535 | if (bpt) { |
| 536 | tcpchild->flags |= TCB_BPTSET; |
| 537 | tcpchild->baddr = tcp->baddr; |
| 538 | memcpy(tcpchild->inst, tcp->inst, |
| 539 | sizeof tcpchild->inst); |
| 540 | } |
| 541 | newoutf(tcpchild); |
| 542 | tcpchild->parent = tcp; |
| 543 | tcp->nchildren++; |
| 544 | if (!qflag) |
| 545 | fprintf(stderr, "Process %d attached\n", pid); |
| 546 | } |
| 547 | return 0; |
| 548 | } |
| 549 | |
| 550 | #endif /* !SVR4 */ |
| 551 | |
| 552 | #if defined(SUNOS4) || defined(LINUX) |
| 553 | |
| 554 | int |
| 555 | sys_vfork(tcp) |
| 556 | struct tcb *tcp; |
| 557 | { |
| 558 | if (exiting(tcp)) |
| 559 | return RVAL_UDECIMAL; |
| 560 | return 0; |
| 561 | } |
| 562 | |
| 563 | #endif /* SUNOS4 || LINUX */ |
| 564 | |
| 565 | #ifndef LINUX |
| 566 | |
| 567 | static char idstr[16]; |
| 568 | |
| 569 | int |
| 570 | sys_getpid(tcp) |
| 571 | struct tcb *tcp; |
| 572 | { |
| 573 | if (exiting(tcp)) { |
| 574 | sprintf(idstr, "ppid %lu", getrval2(tcp)); |
| 575 | tcp->auxstr = idstr; |
| 576 | return RVAL_STR; |
| 577 | } |
| 578 | return 0; |
| 579 | } |
| 580 | |
| 581 | int |
| 582 | sys_getuid(tcp) |
| 583 | struct tcb *tcp; |
| 584 | { |
| 585 | if (exiting(tcp)) { |
| 586 | sprintf(idstr, "euid %lu", getrval2(tcp)); |
| 587 | tcp->auxstr = idstr; |
| 588 | return RVAL_STR; |
| 589 | } |
| 590 | return 0; |
| 591 | } |
| 592 | |
| 593 | int |
| 594 | sys_getgid(tcp) |
| 595 | struct tcb *tcp; |
| 596 | { |
| 597 | if (exiting(tcp)) { |
| 598 | sprintf(idstr, "egid %lu", getrval2(tcp)); |
| 599 | tcp->auxstr = idstr; |
| 600 | return RVAL_STR; |
| 601 | } |
| 602 | return 0; |
| 603 | } |
| 604 | |
| 605 | #endif /* !LINUX */ |
| 606 | |
| 607 | #ifdef LINUX |
| 608 | |
| 609 | int |
| 610 | sys_setuid(tcp) |
| 611 | struct tcb *tcp; |
| 612 | { |
| 613 | if (entering(tcp)) { |
| 614 | tprintf("%u", (uid_t) tcp->u_arg[0]); |
| 615 | } |
| 616 | return 0; |
| 617 | } |
| 618 | |
| 619 | int |
| 620 | sys_setgid(tcp) |
| 621 | struct tcb *tcp; |
| 622 | { |
| 623 | if (entering(tcp)) { |
| 624 | tprintf("%u", (gid_t) tcp->u_arg[0]); |
| 625 | } |
| 626 | return 0; |
| 627 | } |
| 628 | |
| 629 | int |
| 630 | sys_getresuid(tcp) |
| 631 | struct tcb *tcp; |
| 632 | { |
| 633 | if (exiting(tcp)) { |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 634 | __kernel_uid_t uid; |
| 635 | if (syserror(tcp)) |
| 636 | tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0], |
| 637 | tcp->u_arg[1], tcp->u_arg[2]); |
| 638 | else { |
| 639 | if (umove(tcp, tcp->u_arg[0], &uid) < 0) |
| 640 | tprintf("%#lx, ", tcp->u_arg[0]); |
| 641 | else |
| 642 | tprintf("ruid %lu, ", (unsigned long) uid); |
| 643 | if (umove(tcp, tcp->u_arg[0], &uid) < 0) |
| 644 | tprintf("%#lx, ", tcp->u_arg[0]); |
| 645 | else |
| 646 | tprintf("euid %lu, ", (unsigned long) uid); |
| 647 | if (umove(tcp, tcp->u_arg[0], &uid) < 0) |
| 648 | tprintf("%#lx", tcp->u_arg[0]); |
| 649 | else |
| 650 | tprintf("suid %lu", (unsigned long) uid); |
| 651 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 652 | } |
| 653 | return 0; |
| 654 | } |
| 655 | |
| 656 | int |
| 657 | sys_getresgid(tcp) |
| 658 | struct tcb *tcp; |
| 659 | { |
| 660 | if (exiting(tcp)) { |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 661 | __kernel_gid_t gid; |
| 662 | if (syserror(tcp)) |
| 663 | tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0], |
| 664 | tcp->u_arg[1], tcp->u_arg[2]); |
| 665 | else { |
| 666 | if (umove(tcp, tcp->u_arg[0], &gid) < 0) |
| 667 | tprintf("%#lx, ", tcp->u_arg[0]); |
| 668 | else |
| 669 | tprintf("rgid %lu, ", (unsigned long) gid); |
| 670 | if (umove(tcp, tcp->u_arg[0], &gid) < 0) |
| 671 | tprintf("%#lx, ", tcp->u_arg[0]); |
| 672 | else |
| 673 | tprintf("egid %lu, ", (unsigned long) gid); |
| 674 | if (umove(tcp, tcp->u_arg[0], &gid) < 0) |
| 675 | tprintf("%#lx", tcp->u_arg[0]); |
| 676 | else |
| 677 | tprintf("sgid %lu", (unsigned long) gid); |
| 678 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 679 | } |
| 680 | return 0; |
| 681 | } |
| 682 | |
| 683 | #endif /* LINUX */ |
| 684 | |
| 685 | int |
| 686 | sys_setreuid(tcp) |
| 687 | struct tcb *tcp; |
| 688 | { |
| 689 | if (entering(tcp)) { |
| 690 | tprintf("%lu, %lu", |
| 691 | (unsigned long) (uid_t) tcp->u_arg[0], |
| 692 | (unsigned long) (uid_t) tcp->u_arg[1]); |
| 693 | } |
| 694 | return 0; |
| 695 | } |
| 696 | |
| 697 | int |
| 698 | sys_setregid(tcp) |
| 699 | struct tcb *tcp; |
| 700 | { |
| 701 | if (entering(tcp)) { |
| 702 | tprintf("%lu, %lu", |
| 703 | (unsigned long) (gid_t) tcp->u_arg[0], |
| 704 | (unsigned long) (gid_t) tcp->u_arg[1]); |
| 705 | } |
| 706 | return 0; |
| 707 | } |
| 708 | |
| 709 | #ifdef LINUX |
| 710 | int |
| 711 | sys_setresuid(tcp) |
| 712 | struct tcb *tcp; |
| 713 | { |
| 714 | if (entering(tcp)) { |
| 715 | tprintf("ruid %u, euid %u, suid %u", |
| 716 | (uid_t) tcp->u_arg[0], |
| 717 | (uid_t) tcp->u_arg[1], |
| 718 | (uid_t) tcp->u_arg[2]); |
| 719 | } |
| 720 | return 0; |
| 721 | } |
| 722 | int |
| 723 | sys_setresgid(tcp) |
| 724 | struct tcb *tcp; |
| 725 | { |
| 726 | if (entering(tcp)) { |
| 727 | tprintf("rgid %u, egid %u, sgid %u", |
| 728 | (uid_t) tcp->u_arg[0], |
| 729 | (uid_t) tcp->u_arg[1], |
| 730 | (uid_t) tcp->u_arg[2]); |
| 731 | } |
| 732 | return 0; |
| 733 | } |
| 734 | |
| 735 | #endif /* LINUX */ |
| 736 | |
| 737 | int |
| 738 | sys_setgroups(tcp) |
| 739 | struct tcb *tcp; |
| 740 | { |
| 741 | int i, len; |
| 742 | GETGROUPS_T *gidset; |
| 743 | |
| 744 | if (entering(tcp)) { |
| 745 | len = tcp->u_arg[0]; |
| 746 | tprintf("%u, ", len); |
| 747 | if (len <= 0) { |
| 748 | tprintf("[]"); |
| 749 | return 0; |
| 750 | } |
| 751 | gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T)); |
| 752 | if (gidset == NULL) { |
| 753 | fprintf(stderr, "sys_setgroups: out of memory\n"); |
| 754 | return -1; |
| 755 | } |
| 756 | if (!verbose(tcp)) |
| 757 | tprintf("%#lx", tcp->u_arg[1]); |
| 758 | else if (umoven(tcp, tcp->u_arg[1], |
| 759 | len * sizeof(GETGROUPS_T), (char *) gidset) < 0) |
| 760 | tprintf("[?]"); |
| 761 | else { |
| 762 | tprintf("["); |
| 763 | for (i = 0; i < len; i++) |
| 764 | tprintf("%s%lu", i ? ", " : "", |
| 765 | (unsigned long) gidset[i]); |
| 766 | tprintf("]"); |
| 767 | } |
| 768 | free((char *) gidset); |
| 769 | } |
| 770 | return 0; |
| 771 | } |
| 772 | |
| 773 | int |
| 774 | sys_getgroups(tcp) |
| 775 | struct tcb *tcp; |
| 776 | { |
| 777 | int i, len; |
| 778 | GETGROUPS_T *gidset; |
| 779 | |
| 780 | if (entering(tcp)) { |
| 781 | len = tcp->u_arg[0]; |
| 782 | tprintf("%u, ", len); |
| 783 | } else { |
| 784 | len = tcp->u_rval; |
| 785 | if (len <= 0) { |
| 786 | tprintf("[]"); |
| 787 | return 0; |
| 788 | } |
| 789 | gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T)); |
| 790 | if (gidset == NULL) { |
| 791 | fprintf(stderr, "sys_getgroups: out of memory\n"); |
| 792 | return -1; |
| 793 | } |
| 794 | if (!tcp->u_arg[1]) |
| 795 | tprintf("NULL"); |
| 796 | else if (!verbose(tcp) || tcp->u_arg[0] == 0) |
| 797 | tprintf("%#lx", tcp->u_arg[1]); |
| 798 | else if (umoven(tcp, tcp->u_arg[1], |
| 799 | len * sizeof(GETGROUPS_T), (char *) gidset) < 0) |
| 800 | tprintf("[?]"); |
| 801 | else { |
| 802 | tprintf("["); |
| 803 | for (i = 0; i < len; i++) |
| 804 | tprintf("%s%lu", i ? ", " : "", |
| 805 | (unsigned long) gidset[i]); |
| 806 | tprintf("]"); |
| 807 | } |
| 808 | free((char *)gidset); |
| 809 | } |
| 810 | return 0; |
| 811 | } |
| 812 | |
| 813 | int |
| 814 | sys_setpgrp(tcp) |
| 815 | struct tcb *tcp; |
| 816 | { |
| 817 | if (entering(tcp)) { |
| 818 | #ifndef SVR4 |
| 819 | tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]); |
| 820 | #endif /* !SVR4 */ |
| 821 | } |
| 822 | return 0; |
| 823 | } |
| 824 | |
| 825 | int |
| 826 | sys_getpgrp(tcp) |
| 827 | struct tcb *tcp; |
| 828 | { |
| 829 | if (entering(tcp)) { |
| 830 | #ifndef SVR4 |
| 831 | tprintf("%lu", tcp->u_arg[0]); |
| 832 | #endif /* !SVR4 */ |
| 833 | } |
| 834 | return 0; |
| 835 | } |
| 836 | |
| 837 | int |
| 838 | sys_getsid(tcp) |
| 839 | struct tcb *tcp; |
| 840 | { |
| 841 | if (entering(tcp)) { |
| 842 | tprintf("%lu", tcp->u_arg[0]); |
| 843 | } |
| 844 | return 0; |
| 845 | } |
| 846 | |
| 847 | int |
| 848 | sys_setsid(tcp) |
| 849 | struct tcb *tcp; |
| 850 | { |
| 851 | return 0; |
| 852 | } |
| 853 | |
| 854 | int |
| 855 | sys_getpgid(tcp) |
| 856 | struct tcb *tcp; |
| 857 | { |
| 858 | if (entering(tcp)) { |
| 859 | tprintf("%lu", tcp->u_arg[0]); |
| 860 | } |
| 861 | return 0; |
| 862 | } |
| 863 | |
| 864 | int |
| 865 | sys_setpgid(tcp) |
| 866 | struct tcb *tcp; |
| 867 | { |
| 868 | if (entering(tcp)) { |
| 869 | tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]); |
| 870 | } |
| 871 | return 0; |
| 872 | } |
| 873 | |
| 874 | void |
| 875 | fake_execve(tcp, program, argv, envp) |
| 876 | struct tcb *tcp; |
| 877 | char *program; |
| 878 | char *argv[]; |
| 879 | char *envp[]; |
| 880 | { |
| 881 | int i; |
| 882 | |
| 883 | #ifdef ARM |
| 884 | if (!(qual_flags[SYS_execve - __NR_SYSCALL_BASE] & QUAL_TRACE)) |
| 885 | return; |
| 886 | #else |
| 887 | if (!(qual_flags[SYS_execve] & QUAL_TRACE)) |
| 888 | return; |
| 889 | #endif /* !ARM */ |
| 890 | printleader(tcp); |
| 891 | tprintf("execve("); |
| 892 | string_quote(program); |
| 893 | tprintf(", ["); |
| 894 | for (i = 0; argv[i] != NULL; i++) { |
| 895 | if (i != 0) |
| 896 | tprintf(", "); |
| 897 | string_quote(argv[i]); |
| 898 | } |
| 899 | for (i = 0; envp[i] != NULL; i++) |
| 900 | ; |
| 901 | tprintf("], [/* %d var%s */]) ", i, (i != 1) ? "s" : ""); |
| 902 | tabto(acolumn); |
| 903 | tprintf("= 0"); |
| 904 | printtrailer(tcp); |
| 905 | } |
| 906 | |
| 907 | static void |
| 908 | printargv(tcp, addr) |
| 909 | struct tcb *tcp; |
| 910 | long addr; |
| 911 | { |
| 912 | char *cp; |
| 913 | char *sep; |
| 914 | int max = max_strlen / 2; |
| 915 | |
| 916 | for (sep = ""; --max >= 0; sep = ", ") { |
| 917 | if (!abbrev(tcp)) |
| 918 | max++; |
| 919 | if (umove(tcp, addr, &cp) < 0) { |
| 920 | tprintf("%#lx", addr); |
| 921 | return; |
| 922 | } |
| 923 | if (cp == 0) |
| 924 | break; |
| 925 | tprintf(sep); |
| 926 | printstr(tcp, (long) cp, -1); |
| 927 | addr += sizeof(char *); |
| 928 | } |
| 929 | if (cp) |
| 930 | tprintf(", ..."); |
| 931 | } |
| 932 | |
| 933 | static void |
| 934 | printargc(fmt, tcp, addr) |
| 935 | char *fmt; |
| 936 | struct tcb *tcp; |
| 937 | long addr; |
| 938 | { |
| 939 | int count; |
| 940 | char *cp; |
| 941 | |
| 942 | for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) { |
| 943 | addr += sizeof(char *); |
| 944 | } |
| 945 | tprintf(fmt, count, count == 1 ? "" : "s"); |
| 946 | } |
| 947 | |
| 948 | int |
| 949 | sys_execv(tcp) |
| 950 | struct tcb *tcp; |
| 951 | { |
| 952 | if (entering(tcp)) { |
| 953 | printpath(tcp, tcp->u_arg[0]); |
| 954 | if (!verbose(tcp)) |
| 955 | tprintf(", %#lx", tcp->u_arg[1]); |
| 956 | #if 0 |
| 957 | else if (abbrev(tcp)) |
| 958 | printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]); |
| 959 | #endif |
| 960 | else { |
| 961 | tprintf(", ["); |
| 962 | printargv(tcp, tcp->u_arg[1]); |
| 963 | tprintf("]"); |
| 964 | } |
| 965 | } |
| 966 | return 0; |
| 967 | } |
| 968 | |
| 969 | int |
| 970 | sys_execve(tcp) |
| 971 | struct tcb *tcp; |
| 972 | { |
| 973 | if (entering(tcp)) { |
| 974 | printpath(tcp, tcp->u_arg[0]); |
| 975 | if (!verbose(tcp)) |
| 976 | tprintf(", %#lx", tcp->u_arg[1]); |
| 977 | #if 0 |
| 978 | else if (abbrev(tcp)) |
| 979 | printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]); |
| 980 | #endif |
| 981 | else { |
| 982 | tprintf(", ["); |
| 983 | printargv(tcp, tcp->u_arg[1]); |
| 984 | tprintf("]"); |
| 985 | } |
| 986 | if (!verbose(tcp)) |
| 987 | tprintf(", %#lx", tcp->u_arg[2]); |
| 988 | else if (abbrev(tcp)) |
| 989 | printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]); |
| 990 | else { |
| 991 | tprintf(", ["); |
| 992 | printargv(tcp, tcp->u_arg[2]); |
| 993 | tprintf("]"); |
| 994 | } |
| 995 | } |
| 996 | #ifdef LINUX |
| 997 | #if defined(ALPHA) || defined(SPARC) || defined(POWERPC) |
| 998 | tcp->flags |= TCB_WAITEXECVE; |
| 999 | #endif /* ALPHA || SPARC || POWERPC */ |
| 1000 | #endif /* LINUX */ |
| 1001 | return 0; |
| 1002 | } |
| 1003 | |
| 1004 | int |
| 1005 | internal_exec(tcp) |
| 1006 | struct tcb *tcp; |
| 1007 | { |
| 1008 | #ifdef SUNOS4 |
| 1009 | if (exiting(tcp) && !syserror(tcp) && followfork) |
| 1010 | fixvfork(tcp); |
| 1011 | #endif /* SUNOS4 */ |
| 1012 | return 0; |
| 1013 | } |
| 1014 | |
| 1015 | #ifdef LINUX |
| 1016 | #ifndef __WCLONE |
| 1017 | #define __WCLONE 0x8000000 |
| 1018 | #endif |
| 1019 | #endif /* LINUX */ |
| 1020 | |
| 1021 | static struct xlat wait4_options[] = { |
| 1022 | { WNOHANG, "WNOHANG" }, |
| 1023 | #ifndef WSTOPPED |
| 1024 | { WUNTRACED, "WUNTRACED" }, |
| 1025 | #endif |
| 1026 | #ifdef WEXITED |
| 1027 | { WEXITED, "WEXITED" }, |
| 1028 | #endif |
| 1029 | #ifdef WTRAPPED |
| 1030 | { WTRAPPED, "WTRAPPED" }, |
| 1031 | #endif |
| 1032 | #ifdef WSTOPPED |
| 1033 | { WSTOPPED, "WSTOPPED" }, |
| 1034 | #endif |
| 1035 | #ifdef WCONTINUED |
| 1036 | { WCONTINUED, "WCONTINUED" }, |
| 1037 | #endif |
| 1038 | #ifdef WNOWAIT |
| 1039 | { WNOWAIT, "WNOWAIT" }, |
| 1040 | #endif |
| 1041 | #ifdef __WCLONE |
| 1042 | { __WCLONE, "__WCLONE" }, |
| 1043 | #endif |
| 1044 | { 0, NULL }, |
| 1045 | }; |
| 1046 | |
| 1047 | static int |
| 1048 | printstatus(status) |
| 1049 | int status; |
| 1050 | { |
| 1051 | int exited = 0; |
| 1052 | |
| 1053 | /* |
| 1054 | * Here is a tricky presentation problem. This solution |
| 1055 | * is still not entirely satisfactory but since there |
| 1056 | * are no wait status constructors it will have to do. |
| 1057 | */ |
| 1058 | if (WIFSTOPPED(status)) |
| 1059 | tprintf("[WIFSTOPPED(s) && WSTOPSIG(s) == %s]", |
Nate Sammons | ce780fc | 1999-03-29 23:23:13 +0000 | [diff] [blame] | 1060 | signame(WSTOPSIG(status))); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1061 | else if WIFSIGNALED(status) |
| 1062 | tprintf("[WIFSIGNALED(s) && WTERMSIG(s) == %s%s]", |
Nate Sammons | ce780fc | 1999-03-29 23:23:13 +0000 | [diff] [blame] | 1063 | signame(WTERMSIG(status)), |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1064 | WCOREDUMP(status) ? " && WCOREDUMP(s)" : ""); |
| 1065 | else if WIFEXITED(status) { |
| 1066 | tprintf("[WIFEXITED(s) && WEXITSTATUS(s) == %d]", |
| 1067 | WEXITSTATUS(status)); |
| 1068 | exited = 1; |
| 1069 | } |
| 1070 | else |
| 1071 | tprintf("[%#x]", status); |
| 1072 | return exited; |
| 1073 | } |
| 1074 | |
| 1075 | static int |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 1076 | printwaitn(tcp, n, bitness) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1077 | struct tcb *tcp; |
| 1078 | int n; |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 1079 | int bitness; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1080 | { |
| 1081 | int status; |
| 1082 | int exited = 0; |
| 1083 | |
| 1084 | if (entering(tcp)) { |
| 1085 | tprintf("%ld, ", tcp->u_arg[0]); |
| 1086 | } else { |
| 1087 | /* status */ |
| 1088 | if (!tcp->u_arg[1]) |
| 1089 | tprintf("NULL"); |
| 1090 | else if (syserror(tcp) || tcp->u_rval == 0) |
| 1091 | tprintf("%#lx", tcp->u_arg[1]); |
| 1092 | else if (umove(tcp, tcp->u_arg[1], &status) < 0) |
| 1093 | tprintf("[?]"); |
| 1094 | else |
| 1095 | exited = printstatus(status); |
| 1096 | /* options */ |
| 1097 | tprintf(", "); |
| 1098 | if (!printflags(wait4_options, tcp->u_arg[2])) |
| 1099 | tprintf("0"); |
| 1100 | if (n == 4) { |
| 1101 | tprintf(", "); |
| 1102 | /* usage */ |
| 1103 | if (!tcp->u_arg[3]) |
| 1104 | tprintf("NULL"); |
| 1105 | #ifdef LINUX |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 1106 | else if (tcp->u_rval > 0) { |
| 1107 | #ifdef LINUX_64BIT |
| 1108 | if (bitness) |
| 1109 | printrusage32(tcp, tcp->u_arg[3]); |
| 1110 | else |
| 1111 | #endif |
| 1112 | printrusage(tcp, tcp->u_arg[3]); |
| 1113 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1114 | #endif /* LINUX */ |
| 1115 | #ifdef SUNOS4 |
| 1116 | else if (tcp->u_rval > 0 && exited) |
| 1117 | printrusage(tcp, tcp->u_arg[3]); |
| 1118 | #endif /* SUNOS4 */ |
| 1119 | else |
| 1120 | tprintf("%#lx", tcp->u_arg[3]); |
| 1121 | } |
| 1122 | } |
| 1123 | return 0; |
| 1124 | } |
| 1125 | |
| 1126 | int |
| 1127 | internal_wait(tcp) |
| 1128 | struct tcb *tcp; |
| 1129 | { |
| 1130 | if (entering(tcp)) { |
Wichert Akkerman | 5daa028 | 1999-03-15 19:49:42 +0000 | [diff] [blame] | 1131 | /* WTA: fix bug with hanging children */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1132 | if (!(tcp->u_arg[2] & WNOHANG) && tcp->nchildren > 0) { |
| 1133 | /* There are traced children */ |
| 1134 | tcp->flags |= TCB_SUSPENDED; |
| 1135 | tcp->waitpid = tcp->u_arg[0]; |
| 1136 | } |
| 1137 | } |
| 1138 | return 0; |
| 1139 | } |
| 1140 | |
| 1141 | #ifdef SVR4 |
| 1142 | |
| 1143 | int |
| 1144 | sys_wait(tcp) |
| 1145 | struct tcb *tcp; |
| 1146 | { |
| 1147 | if (exiting(tcp)) { |
| 1148 | /* The library wrapper stuffs this into the user variable. */ |
| 1149 | if (!syserror(tcp)) |
| 1150 | printstatus(getrval2(tcp)); |
| 1151 | } |
| 1152 | return 0; |
| 1153 | } |
| 1154 | |
| 1155 | #endif /* SVR4 */ |
| 1156 | |
| 1157 | int |
| 1158 | sys_waitpid(tcp) |
| 1159 | struct tcb *tcp; |
| 1160 | { |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 1161 | return printwaitn(tcp, 3, 0); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | int |
| 1165 | sys_wait4(tcp) |
| 1166 | struct tcb *tcp; |
| 1167 | { |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 1168 | return printwaitn(tcp, 4, 0); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1169 | } |
| 1170 | |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 1171 | #ifdef ALPHA |
| 1172 | int |
| 1173 | sys_osf_wait4(tcp) |
| 1174 | struct tcb *tcp; |
| 1175 | { |
| 1176 | return printwaitn(tcp, 4, 1); |
| 1177 | } |
| 1178 | #endif |
| 1179 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1180 | #ifdef SVR4 |
| 1181 | |
| 1182 | static struct xlat waitid_types[] = { |
| 1183 | { P_PID, "P_PID" }, |
| 1184 | { P_PPID, "P_PPID" }, |
| 1185 | { P_PGID, "P_PGID" }, |
| 1186 | { P_SID, "P_SID" }, |
| 1187 | { P_CID, "P_CID" }, |
| 1188 | { P_UID, "P_UID" }, |
| 1189 | { P_GID, "P_GID" }, |
| 1190 | { P_ALL, "P_ALL" }, |
| 1191 | #ifdef P_LWPID |
| 1192 | { P_LWPID, "P_LWPID" }, |
| 1193 | #endif |
| 1194 | { 0, NULL }, |
| 1195 | }; |
| 1196 | |
| 1197 | static struct xlat siginfo_codes[] = { |
| 1198 | #ifdef SI_NOINFO |
| 1199 | { SI_NOINFO, "SI_NOINFO" }, |
| 1200 | #endif |
| 1201 | #ifdef SI_USER |
| 1202 | { SI_USER, "SI_USER" }, |
| 1203 | #endif |
| 1204 | #ifdef SI_LWP |
| 1205 | { SI_LWP, "SI_LWP" }, |
| 1206 | #endif |
| 1207 | #ifdef SI_QUEUE |
| 1208 | { SI_QUEUE, "SI_QUEUE" }, |
| 1209 | #endif |
| 1210 | #ifdef SI_TIMER |
| 1211 | { SI_TIMER, "SI_TIMER" }, |
| 1212 | #endif |
| 1213 | #ifdef SI_ASYNCIO |
| 1214 | { SI_ASYNCIO, "SI_ASYNCIO" }, |
| 1215 | #endif |
| 1216 | #ifdef SI_MESGQ |
| 1217 | { SI_MESGQ, "SI_MESGQ" }, |
| 1218 | #endif |
| 1219 | { 0, NULL }, |
| 1220 | }; |
| 1221 | |
| 1222 | static struct xlat sigtrap_codes[] = { |
| 1223 | { TRAP_BRKPT, "TRAP_BRKPT" }, |
| 1224 | { TRAP_TRACE, "TRAP_TRACE" }, |
| 1225 | { 0, NULL }, |
| 1226 | }; |
| 1227 | |
| 1228 | static struct xlat sigcld_codes[] = { |
| 1229 | { CLD_EXITED, "CLD_EXITED" }, |
| 1230 | { CLD_KILLED, "CLD_KILLED" }, |
| 1231 | { CLD_DUMPED, "CLD_DUMPED" }, |
| 1232 | { CLD_TRAPPED, "CLD_TRAPPED" }, |
| 1233 | { CLD_STOPPED, "CLD_STOPPED" }, |
| 1234 | { CLD_CONTINUED,"CLD_CONTINUED" }, |
| 1235 | { 0, NULL }, |
| 1236 | }; |
| 1237 | |
| 1238 | static struct xlat sigpoll_codes[] = { |
| 1239 | { POLL_IN, "POLL_IN" }, |
| 1240 | { POLL_OUT, "POLL_OUT" }, |
| 1241 | { POLL_MSG, "POLL_MSG" }, |
| 1242 | { POLL_ERR, "POLL_ERR" }, |
| 1243 | { POLL_PRI, "POLL_PRI" }, |
| 1244 | { POLL_HUP, "POLL_HUP" }, |
| 1245 | { 0, NULL }, |
| 1246 | }; |
| 1247 | |
| 1248 | static struct xlat sigprof_codes[] = { |
| 1249 | #ifdef PROF_SIG |
| 1250 | { PROF_SIG, "PROF_SIG" }, |
| 1251 | #endif |
| 1252 | { 0, NULL }, |
| 1253 | }; |
| 1254 | |
| 1255 | static struct xlat sigill_codes[] = { |
| 1256 | { ILL_ILLOPC, "ILL_ILLOPC" }, |
| 1257 | { ILL_ILLOPN, "ILL_ILLOPN" }, |
| 1258 | { ILL_ILLADR, "ILL_ILLADR" }, |
| 1259 | { ILL_ILLTRP, "ILL_ILLTRP" }, |
| 1260 | { ILL_PRVOPC, "ILL_PRVOPC" }, |
| 1261 | { ILL_PRVREG, "ILL_PRVREG" }, |
| 1262 | { ILL_COPROC, "ILL_COPROC" }, |
| 1263 | { ILL_BADSTK, "ILL_BADSTK" }, |
| 1264 | { 0, NULL }, |
| 1265 | }; |
| 1266 | |
| 1267 | static struct xlat sigemt_codes[] = { |
| 1268 | #ifdef EMT_TAGOVF |
| 1269 | { EMT_TAGOVF, "EMT_TAGOVF" }, |
| 1270 | #endif |
| 1271 | { 0, NULL }, |
| 1272 | }; |
| 1273 | |
| 1274 | static struct xlat sigfpe_codes[] = { |
| 1275 | { FPE_INTDIV, "FPE_INTDIV" }, |
| 1276 | { FPE_INTOVF, "FPE_INTOVF" }, |
| 1277 | { FPE_FLTDIV, "FPE_FLTDIV" }, |
| 1278 | { FPE_FLTOVF, "FPE_FLTOVF" }, |
| 1279 | { FPE_FLTUND, "FPE_FLTUND" }, |
| 1280 | { FPE_FLTRES, "FPE_FLTRES" }, |
| 1281 | { FPE_FLTINV, "FPE_FLTINV" }, |
| 1282 | { FPE_FLTSUB, "FPE_FLTSUB" }, |
| 1283 | { 0, NULL }, |
| 1284 | }; |
| 1285 | |
| 1286 | static struct xlat sigsegv_codes[] = { |
| 1287 | { SEGV_MAPERR, "SEGV_MAPERR" }, |
| 1288 | { SEGV_ACCERR, "SEGV_ACCERR" }, |
| 1289 | { 0, NULL }, |
| 1290 | }; |
| 1291 | |
| 1292 | static struct xlat sigbus_codes[] = { |
| 1293 | { BUS_ADRALN, "BUS_ADRALN" }, |
| 1294 | { BUS_ADRERR, "BUS_ADRERR" }, |
| 1295 | { BUS_OBJERR, "BUS_OBJERR" }, |
| 1296 | { 0, NULL }, |
| 1297 | }; |
| 1298 | |
| 1299 | void |
| 1300 | printsiginfo(sip) |
| 1301 | siginfo_t *sip; |
| 1302 | { |
| 1303 | char *code; |
| 1304 | |
| 1305 | tprintf("{si_signo="); |
| 1306 | printsignal(sip->si_signo); |
| 1307 | code = xlookup(siginfo_codes, sip->si_code); |
| 1308 | if (!code) { |
| 1309 | switch (sip->si_signo) { |
| 1310 | case SIGTRAP: |
| 1311 | code = xlookup(sigtrap_codes, sip->si_code); |
| 1312 | break; |
| 1313 | case SIGCHLD: |
| 1314 | code = xlookup(sigcld_codes, sip->si_code); |
| 1315 | break; |
| 1316 | case SIGPOLL: |
| 1317 | code = xlookup(sigpoll_codes, sip->si_code); |
| 1318 | break; |
| 1319 | case SIGPROF: |
| 1320 | code = xlookup(sigprof_codes, sip->si_code); |
| 1321 | break; |
| 1322 | case SIGILL: |
| 1323 | code = xlookup(sigill_codes, sip->si_code); |
| 1324 | break; |
| 1325 | case SIGEMT: |
| 1326 | code = xlookup(sigemt_codes, sip->si_code); |
| 1327 | break; |
| 1328 | case SIGFPE: |
| 1329 | code = xlookup(sigfpe_codes, sip->si_code); |
| 1330 | break; |
| 1331 | case SIGSEGV: |
| 1332 | code = xlookup(sigsegv_codes, sip->si_code); |
| 1333 | break; |
| 1334 | case SIGBUS: |
| 1335 | code = xlookup(sigbus_codes, sip->si_code); |
| 1336 | break; |
| 1337 | } |
| 1338 | } |
| 1339 | if (code) |
| 1340 | tprintf(", si_code=%s", code); |
| 1341 | else |
| 1342 | tprintf(", si_code=%#x", sip->si_code); |
| 1343 | #ifdef SI_NOINFO |
| 1344 | if (sip->si_code != SI_NOINFO) { |
| 1345 | #endif |
| 1346 | if (sip->si_errno) { |
| 1347 | if (sip->si_errno < 0 || sip->si_errno >= nerrnos) |
| 1348 | tprintf(", si_errno=%d", sip->si_errno); |
| 1349 | else |
| 1350 | tprintf(", si_errno=%s", |
| 1351 | errnoent[sip->si_errno]); |
| 1352 | } |
| 1353 | if (SI_FROMUSER(sip)) { |
| 1354 | #ifdef SI_QUEUE |
| 1355 | tprintf(", si_pid=%ld, si_uid=%ld", |
| 1356 | sip->si_pid, sip->si_uid); |
| 1357 | switch (sip->si_code) { |
| 1358 | case SI_QUEUE: |
| 1359 | #ifdef SI_TIMER |
| 1360 | case SI_TIMER: |
| 1361 | #endif /* SI_QUEUE */ |
| 1362 | case SI_ASYNCIO: |
| 1363 | #ifdef SI_MESGQ |
| 1364 | case SI_MESGQ: |
| 1365 | #endif /* SI_MESGQ */ |
| 1366 | tprintf(", si_value=%d", |
| 1367 | sip->si_value.sival_int); |
| 1368 | break; |
| 1369 | } |
| 1370 | #endif /* SI_QUEUE */ |
| 1371 | } |
| 1372 | else { |
| 1373 | switch (sip->si_signo) { |
| 1374 | case SIGCHLD: |
| 1375 | tprintf(", si_pid=%ld, si_status=", |
| 1376 | sip->si_pid); |
| 1377 | if (sip->si_code == CLD_EXITED) |
| 1378 | tprintf("%d", sip->si_status); |
| 1379 | else |
| 1380 | printsignal(sip->si_status); |
| 1381 | break; |
| 1382 | case SIGILL: case SIGFPE: |
| 1383 | case SIGSEGV: case SIGBUS: |
| 1384 | tprintf(", si_addr=%#lx", |
| 1385 | (unsigned long) sip->si_addr); |
| 1386 | break; |
| 1387 | case SIGPOLL: |
| 1388 | switch (sip->si_code) { |
| 1389 | case POLL_IN: case POLL_OUT: case POLL_MSG: |
| 1390 | tprintf(", si_band=%ld", |
| 1391 | (long) sip->si_band); |
| 1392 | break; |
| 1393 | } |
| 1394 | break; |
| 1395 | } |
| 1396 | } |
| 1397 | tprintf(", ..."); |
| 1398 | #ifdef SI_NOINFO |
| 1399 | } |
| 1400 | #endif |
| 1401 | tprintf("}"); |
| 1402 | } |
| 1403 | |
| 1404 | int |
| 1405 | sys_waitid(tcp) |
| 1406 | struct tcb *tcp; |
| 1407 | { |
| 1408 | siginfo_t si; |
| 1409 | int exited; |
| 1410 | |
| 1411 | if (entering(tcp)) { |
| 1412 | printxval(waitid_types, tcp->u_arg[0], "P_???"); |
| 1413 | tprintf(", %ld, ", tcp->u_arg[1]); |
| 1414 | if (tcp->nchildren > 0) { |
| 1415 | /* There are traced children */ |
| 1416 | tcp->flags |= TCB_SUSPENDED; |
| 1417 | tcp->waitpid = tcp->u_arg[0]; |
| 1418 | } |
| 1419 | } |
| 1420 | else { |
| 1421 | /* siginfo */ |
| 1422 | exited = 0; |
| 1423 | if (!tcp->u_arg[2]) |
| 1424 | tprintf("NULL"); |
| 1425 | else if (syserror(tcp)) |
| 1426 | tprintf("%#lx", tcp->u_arg[2]); |
| 1427 | else if (umove(tcp, tcp->u_arg[2], &si) < 0) |
| 1428 | tprintf("{???}"); |
| 1429 | else |
| 1430 | printsiginfo(&si); |
| 1431 | /* options */ |
| 1432 | tprintf(", "); |
| 1433 | if (!printflags(wait4_options, tcp->u_arg[3])) |
| 1434 | tprintf("0"); |
| 1435 | } |
| 1436 | return 0; |
| 1437 | } |
| 1438 | |
| 1439 | #endif /* SVR4 */ |
| 1440 | |
| 1441 | int |
| 1442 | sys_alarm(tcp) |
| 1443 | struct tcb *tcp; |
| 1444 | { |
| 1445 | if (entering(tcp)) |
| 1446 | tprintf("%lu", tcp->u_arg[0]); |
| 1447 | return 0; |
| 1448 | } |
| 1449 | |
| 1450 | int |
| 1451 | sys_uname(tcp) |
| 1452 | struct tcb *tcp; |
| 1453 | { |
| 1454 | struct utsname uname; |
| 1455 | |
| 1456 | if (exiting(tcp)) { |
| 1457 | if (syserror(tcp) || !verbose(tcp)) |
| 1458 | tprintf("%#lx", tcp->u_arg[0]); |
| 1459 | else if (umove(tcp, tcp->u_arg[0], &uname) < 0) |
| 1460 | tprintf("{...}"); |
| 1461 | else if (!abbrev(tcp)) { |
| 1462 | |
| 1463 | tprintf("{sysname=\"%s\", nodename=\"%s\", ", |
| 1464 | uname.sysname, uname.nodename); |
| 1465 | tprintf("release=\"%s\", version=\"%s\", ", |
| 1466 | uname.release, uname.version); |
| 1467 | tprintf("machine=\"%s\"", uname.machine); |
| 1468 | #ifdef LINUX |
| 1469 | #ifndef __GLIBC__ |
| 1470 | tprintf(", domainname=\"%s\"", uname.domainname); |
| 1471 | #endif /* __GLIBC__ */ |
| 1472 | #endif /* LINUX */ |
| 1473 | tprintf("}"); |
| 1474 | } |
| 1475 | else |
| 1476 | tprintf("{sys=\"%s\", node=\"%s\", ...}", |
| 1477 | uname.sysname, uname.nodename); |
| 1478 | } |
| 1479 | return 0; |
| 1480 | } |
| 1481 | |
| 1482 | #ifndef SVR4 |
| 1483 | |
| 1484 | static struct xlat ptrace_cmds[] = { |
| 1485 | { PTRACE_TRACEME, "PTRACE_TRACEME" }, |
| 1486 | { PTRACE_PEEKTEXT, "PTRACE_PEEKTEXT", }, |
| 1487 | { PTRACE_PEEKDATA, "PTRACE_PEEKDATA", }, |
| 1488 | { PTRACE_PEEKUSER, "PTRACE_PEEKUSER", }, |
| 1489 | { PTRACE_POKETEXT, "PTRACE_POKETEXT", }, |
| 1490 | { PTRACE_POKEDATA, "PTRACE_POKEDATA", }, |
| 1491 | { PTRACE_POKEUSER, "PTRACE_POKEUSER", }, |
| 1492 | { PTRACE_CONT, "PTRACE_CONT" }, |
| 1493 | { PTRACE_KILL, "PTRACE_KILL" }, |
| 1494 | { PTRACE_SINGLESTEP, "PTRACE_SINGLESTEP" }, |
| 1495 | { PTRACE_ATTACH, "PTRACE_ATTACH" }, |
| 1496 | { PTRACE_DETACH, "PTRACE_DETACH" }, |
| 1497 | #ifdef SUNOS4 |
| 1498 | { PTRACE_GETREGS, "PTRACE_GETREGS" }, |
| 1499 | { PTRACE_SETREGS, "PTRACE_SETREGS" }, |
| 1500 | { PTRACE_GETFPREGS, "PTRACE_GETFPREGS", }, |
| 1501 | { PTRACE_SETFPREGS, "PTRACE_SETFPREGS", }, |
| 1502 | { PTRACE_READDATA, "PTRACE_READDATA" }, |
| 1503 | { PTRACE_WRITEDATA, "PTRACE_WRITEDATA" }, |
| 1504 | { PTRACE_READTEXT, "PTRACE_READTEXT" }, |
| 1505 | { PTRACE_WRITETEXT, "PTRACE_WRITETEXT" }, |
| 1506 | { PTRACE_GETFPAREGS, "PTRACE_GETFPAREGS" }, |
| 1507 | { PTRACE_SETFPAREGS, "PTRACE_SETFPAREGS" }, |
| 1508 | #ifdef SPARC |
| 1509 | { PTRACE_GETWINDOW, "PTRACE_GETWINDOW" }, |
| 1510 | { PTRACE_SETWINDOW, "PTRACE_SETWINDOW" }, |
| 1511 | #else /* !SPARC */ |
| 1512 | { PTRACE_22, "PTRACE_PTRACE_22" }, |
| 1513 | { PTRACE_23, "PTRACE_PTRACE_23" }, |
| 1514 | #endif /* !SPARC */ |
| 1515 | #endif /* SUNOS4 */ |
| 1516 | { PTRACE_SYSCALL, "PTRACE_SYSCALL" }, |
| 1517 | #ifdef SUNOS4 |
| 1518 | { PTRACE_DUMPCORE, "PTRACE_DUMPCORE" }, |
| 1519 | #ifdef I386 |
| 1520 | { PTRACE_SETWRBKPT, "PTRACE_SETWRBKPT" }, |
| 1521 | { PTRACE_SETACBKPT, "PTRACE_SETACBKPT" }, |
| 1522 | { PTRACE_CLRDR7, "PTRACE_CLRDR7" }, |
| 1523 | #else /* !I386 */ |
| 1524 | { PTRACE_26, "PTRACE_26" }, |
| 1525 | { PTRACE_27, "PTRACE_27" }, |
| 1526 | { PTRACE_28, "PTRACE_28" }, |
| 1527 | #endif /* !I386 */ |
| 1528 | { PTRACE_GETUCODE, "PTRACE_GETUCODE" }, |
| 1529 | #endif /* SUNOS4 */ |
| 1530 | { 0, NULL }, |
| 1531 | }; |
| 1532 | |
| 1533 | #ifndef SUNOS4_KERNEL_ARCH_KLUDGE |
| 1534 | static |
| 1535 | #endif /* !SUNOS4_KERNEL_ARCH_KLUDGE */ |
| 1536 | struct xlat struct_user_offsets[] = { |
| 1537 | #ifdef LINUX |
Wichert Akkerman | 4dc8a2a | 1999-12-23 14:20:14 +0000 | [diff] [blame] | 1538 | #ifdef S390 |
| 1539 | { PT_PSWMASK, "psw_mask" }, |
| 1540 | { PT_PSWADDR, "psw_addr" }, |
| 1541 | { PT_GPR0, "gpr0" }, |
| 1542 | { PT_GPR1, "gpr1" }, |
| 1543 | { PT_GPR2, "gpr2" }, |
| 1544 | { PT_GPR3, "gpr3" }, |
| 1545 | { PT_GPR4, "gpr4" }, |
| 1546 | { PT_GPR5, "gpr5" }, |
| 1547 | { PT_GPR6, "gpr6" }, |
| 1548 | { PT_GPR7, "gpr7" }, |
| 1549 | { PT_GPR8, "gpr8" }, |
| 1550 | { PT_GPR9, "gpr9" }, |
| 1551 | { PT_GPR10, "gpr10" }, |
| 1552 | { PT_GPR11, "gpr11" }, |
| 1553 | { PT_GPR12, "gpr12" }, |
| 1554 | { PT_GPR13, "gpr13" }, |
| 1555 | { PT_GPR14, "gpr14" }, |
| 1556 | { PT_GPR15, "gpr15" }, |
| 1557 | { PT_ACR0, "acr0" }, |
| 1558 | { PT_ACR1, "acr1" }, |
| 1559 | { PT_ACR2, "acr2" }, |
| 1560 | { PT_ACR3, "acr3" }, |
| 1561 | { PT_ACR4, "acr4" }, |
| 1562 | { PT_ACR5, "acr5" }, |
| 1563 | { PT_ACR6, "acr6" }, |
| 1564 | { PT_ACR7, "acr7" }, |
| 1565 | { PT_ACR8, "acr8" }, |
| 1566 | { PT_ACR9, "acr9" }, |
| 1567 | { PT_ACR10, "acr10" }, |
| 1568 | { PT_ACR11, "acr11" }, |
| 1569 | { PT_ACR12, "acr12" }, |
| 1570 | { PT_ACR13, "acr13" }, |
| 1571 | { PT_ACR14, "acr14" }, |
| 1572 | { PT_ACR15, "acr15" }, |
| 1573 | { PT_ORIGGPR2, "orig_gpr2" }, |
| 1574 | { PT_FPC, "fpc" }, |
| 1575 | { PT_FPR0_HI, "fpr0.hi" }, |
| 1576 | { PT_FPR0_LO, "fpr0.lo" }, |
| 1577 | { PT_FPR1_HI, "fpr1.hi" }, |
| 1578 | { PT_FPR1_LO, "fpr1.lo" }, |
| 1579 | { PT_FPR2_HI, "fpr2.hi" }, |
| 1580 | { PT_FPR2_LO, "fpr2.lo" }, |
| 1581 | { PT_FPR3_HI, "fpr3.hi" }, |
| 1582 | { PT_FPR3_LO, "fpr3.lo" }, |
| 1583 | { PT_FPR4_HI, "fpr4.hi" }, |
| 1584 | { PT_FPR4_LO, "fpr4.lo" }, |
| 1585 | { PT_FPR5_HI, "fpr5.hi" }, |
| 1586 | { PT_FPR5_LO, "fpr5.lo" }, |
| 1587 | { PT_FPR6_HI, "fpr6.hi" }, |
| 1588 | { PT_FPR6_LO, "fpr6.lo" }, |
| 1589 | { PT_FPR7_HI, "fpr7.hi" }, |
| 1590 | { PT_FPR7_LO, "fpr7.lo" }, |
| 1591 | { PT_FPR8_HI, "fpr8.hi" }, |
| 1592 | { PT_FPR8_LO, "fpr8.lo" }, |
| 1593 | { PT_FPR9_HI, "fpr9.hi" }, |
| 1594 | { PT_FPR9_LO, "fpr9.lo" }, |
| 1595 | { PT_FPR10_HI, "fpr10.hi" }, |
| 1596 | { PT_FPR10_LO, "fpr10.lo" }, |
| 1597 | { PT_FPR11_HI, "fpr11.hi" }, |
| 1598 | { PT_FPR11_LO, "fpr11.lo" }, |
| 1599 | { PT_FPR12_HI, "fpr12.hi" }, |
| 1600 | { PT_FPR12_LO, "fpr12.lo" }, |
| 1601 | { PT_FPR13_HI, "fpr13.hi" }, |
| 1602 | { PT_FPR13_LO, "fpr13.lo" }, |
| 1603 | { PT_FPR14_HI, "fpr14.hi" }, |
| 1604 | { PT_FPR14_LO, "fpr14.lo" }, |
| 1605 | { PT_FPR15_HI, "fpr15.hi" }, |
| 1606 | { PT_FPR15_LO, "fpr15.lo" }, |
| 1607 | { PT_CR_9, "cr9" }, |
| 1608 | { PT_CR_10, "cr10" }, |
| 1609 | { PT_CR_11, "cr11" }, |
| 1610 | #endif |
| 1611 | #if defined(SPARC) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1612 | /* XXX No support for these offsets yet. */ |
| 1613 | #elif defined(POWERPC) |
Wichert Akkerman | 4dc8a2a | 1999-12-23 14:20:14 +0000 | [diff] [blame] | 1614 | { 4*PT_R0, "4*PT_R0" }, |
| 1615 | { 4*PT_R1, "4*PT_R1" }, |
| 1616 | { 4*PT_R2, "4*PT_R2" }, |
| 1617 | { 4*PT_R3, "4*PT_R3" }, |
| 1618 | { 4*PT_R4, "4*PT_R4" }, |
| 1619 | { 4*PT_R5, "4*PT_R5" }, |
| 1620 | { 4*PT_R6, "4*PT_R6" }, |
| 1621 | { 4*PT_R7, "4*PT_R7" }, |
| 1622 | { 4*PT_R8, "4*PT_R8" }, |
| 1623 | { 4*PT_R9, "4*PT_R9" }, |
| 1624 | { 4*PT_R10, "4*PT_R10" }, |
| 1625 | { 4*PT_R11, "4*PT_R11" }, |
| 1626 | { 4*PT_R12, "4*PT_R12" }, |
| 1627 | { 4*PT_R13, "4*PT_R13" }, |
| 1628 | { 4*PT_R14, "4*PT_R14" }, |
| 1629 | { 4*PT_R15, "4*PT_R15" }, |
| 1630 | { 4*PT_R16, "4*PT_R16" }, |
| 1631 | { 4*PT_R17, "4*PT_R17" }, |
| 1632 | { 4*PT_R18, "4*PT_R18" }, |
| 1633 | { 4*PT_R19, "4*PT_R19" }, |
| 1634 | { 4*PT_R20, "4*PT_R20" }, |
| 1635 | { 4*PT_R21, "4*PT_R21" }, |
| 1636 | { 4*PT_R22, "4*PT_R22" }, |
| 1637 | { 4*PT_R23, "4*PT_R23" }, |
| 1638 | { 4*PT_R24, "4*PT_R24" }, |
| 1639 | { 4*PT_R25, "4*PT_R25" }, |
| 1640 | { 4*PT_R26, "4*PT_R26" }, |
| 1641 | { 4*PT_R27, "4*PT_R27" }, |
| 1642 | { 4*PT_R28, "4*PT_R28" }, |
| 1643 | { 4*PT_R29, "4*PT_R29" }, |
| 1644 | { 4*PT_R30, "4*PT_R30" }, |
| 1645 | { 4*PT_R31, "4*PT_R31" }, |
| 1646 | { 4*PT_NIP, "4*PT_NIP" }, |
| 1647 | { 4*PT_MSR, "4*PT_MSR" }, |
| 1648 | { 4*PT_ORIG_R3, "4*PT_ORIG_R3" }, |
| 1649 | { 4*PT_CTR, "4*PT_CTR" }, |
| 1650 | { 4*PT_LNK, "4*PT_LNK" }, |
| 1651 | { 4*PT_XER, "4*PT_XER" }, |
| 1652 | { 4*PT_CCR, "4*PT_CCR" }, |
| 1653 | { 4*PT_FPR0, "4*PT_FPR0" }, |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1654 | #else |
| 1655 | #ifdef ALPHA |
Wichert Akkerman | 4dc8a2a | 1999-12-23 14:20:14 +0000 | [diff] [blame] | 1656 | { 0, "r0" }, |
| 1657 | { 1, "r1" }, |
| 1658 | { 2, "r2" }, |
| 1659 | { 3, "r3" }, |
| 1660 | { 4, "r4" }, |
| 1661 | { 5, "r5" }, |
| 1662 | { 6, "r6" }, |
| 1663 | { 7, "r7" }, |
| 1664 | { 8, "r8" }, |
| 1665 | { 9, "r9" }, |
| 1666 | { 10, "r10" }, |
| 1667 | { 11, "r11" }, |
| 1668 | { 12, "r12" }, |
| 1669 | { 13, "r13" }, |
| 1670 | { 14, "r14" }, |
| 1671 | { 15, "r15" }, |
| 1672 | { 16, "r16" }, |
| 1673 | { 17, "r17" }, |
| 1674 | { 18, "r18" }, |
| 1675 | { 19, "r19" }, |
| 1676 | { 20, "r20" }, |
| 1677 | { 21, "r21" }, |
| 1678 | { 22, "r22" }, |
| 1679 | { 23, "r23" }, |
| 1680 | { 24, "r24" }, |
| 1681 | { 25, "r25" }, |
| 1682 | { 26, "r26" }, |
| 1683 | { 27, "r27" }, |
| 1684 | { 28, "r28" }, |
| 1685 | { 29, "gp" }, |
| 1686 | { 30, "fp" }, |
| 1687 | { 31, "zero" }, |
| 1688 | { 32, "fp0" }, |
| 1689 | { 33, "fp" }, |
| 1690 | { 34, "fp2" }, |
| 1691 | { 35, "fp3" }, |
| 1692 | { 36, "fp4" }, |
| 1693 | { 37, "fp5" }, |
| 1694 | { 38, "fp6" }, |
| 1695 | { 39, "fp7" }, |
| 1696 | { 40, "fp8" }, |
| 1697 | { 41, "fp9" }, |
| 1698 | { 42, "fp10" }, |
| 1699 | { 43, "fp11" }, |
| 1700 | { 44, "fp12" }, |
| 1701 | { 45, "fp13" }, |
| 1702 | { 46, "fp14" }, |
| 1703 | { 47, "fp15" }, |
| 1704 | { 48, "fp16" }, |
| 1705 | { 49, "fp17" }, |
| 1706 | { 50, "fp18" }, |
| 1707 | { 51, "fp19" }, |
| 1708 | { 52, "fp20" }, |
| 1709 | { 53, "fp21" }, |
| 1710 | { 54, "fp22" }, |
| 1711 | { 55, "fp23" }, |
| 1712 | { 56, "fp24" }, |
| 1713 | { 57, "fp25" }, |
| 1714 | { 58, "fp26" }, |
| 1715 | { 59, "fp27" }, |
| 1716 | { 60, "fp28" }, |
| 1717 | { 61, "fp29" }, |
| 1718 | { 62, "fp30" }, |
| 1719 | { 63, "fp31" }, |
| 1720 | { 64, "pc" }, |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1721 | #else /* !ALPHA */ |
| 1722 | #ifdef I386 |
| 1723 | { 4*EBX, "4*EBX" }, |
| 1724 | { 4*ECX, "4*ECX" }, |
| 1725 | { 4*EDX, "4*EDX" }, |
| 1726 | { 4*ESI, "4*ESI" }, |
| 1727 | { 4*EDI, "4*EDI" }, |
| 1728 | { 4*EBP, "4*EBP" }, |
| 1729 | { 4*EAX, "4*EAX" }, |
| 1730 | { 4*DS, "4*DS" }, |
| 1731 | { 4*ES, "4*ES" }, |
| 1732 | { 4*FS, "4*FS" }, |
| 1733 | { 4*GS, "4*GS" }, |
| 1734 | { 4*ORIG_EAX, "4*ORIG_EAX" }, |
| 1735 | { 4*EIP, "4*EIP" }, |
| 1736 | { 4*CS, "4*CS" }, |
| 1737 | { 4*EFL, "4*EFL" }, |
| 1738 | { 4*UESP, "4*UESP" }, |
| 1739 | { 4*SS, "4*SS" }, |
| 1740 | #else /* !I386 */ |
| 1741 | #ifdef M68K |
| 1742 | { 4*PT_D1, "4*PT_D1" }, |
| 1743 | { 4*PT_D2, "4*PT_D2" }, |
| 1744 | { 4*PT_D3, "4*PT_D3" }, |
| 1745 | { 4*PT_D4, "4*PT_D4" }, |
| 1746 | { 4*PT_D5, "4*PT_D5" }, |
| 1747 | { 4*PT_D6, "4*PT_D6" }, |
| 1748 | { 4*PT_D7, "4*PT_D7" }, |
| 1749 | { 4*PT_A0, "4*PT_A0" }, |
| 1750 | { 4*PT_A1, "4*PT_A1" }, |
| 1751 | { 4*PT_A2, "4*PT_A2" }, |
| 1752 | { 4*PT_A3, "4*PT_A3" }, |
| 1753 | { 4*PT_A4, "4*PT_A4" }, |
| 1754 | { 4*PT_A5, "4*PT_A5" }, |
| 1755 | { 4*PT_A6, "4*PT_A6" }, |
| 1756 | { 4*PT_D0, "4*PT_D0" }, |
| 1757 | { 4*PT_USP, "4*PT_USP" }, |
| 1758 | { 4*PT_ORIG_D0, "4*PT_ORIG_D0" }, |
| 1759 | { 4*PT_SR, "4*PT_SR" }, |
| 1760 | { 4*PT_PC, "4*PT_PC" }, |
| 1761 | #endif /* M68K */ |
| 1762 | #endif /* !I386 */ |
Wichert Akkerman | 4dc8a2a | 1999-12-23 14:20:14 +0000 | [diff] [blame] | 1763 | #ifdef S390 |
| 1764 | { uoff(u_fpvalid), "offsetof(struct user, u_fpvalid)" }, |
| 1765 | #endif |
Wichert Akkerman | f90da01 | 1999-10-31 21:15:38 +0000 | [diff] [blame] | 1766 | #ifndef MIPS |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1767 | { uoff(u_fpvalid), "offsetof(struct user, u_fpvalid)" }, |
Wichert Akkerman | f90da01 | 1999-10-31 21:15:38 +0000 | [diff] [blame] | 1768 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1769 | #ifdef I386 |
| 1770 | { uoff(i387), "offsetof(struct user, i387)" }, |
| 1771 | #else /* !I386 */ |
| 1772 | #ifdef M68K |
| 1773 | { uoff(m68kfp), "offsetof(struct user, m68kfp)" }, |
| 1774 | #endif /* M68K */ |
| 1775 | #endif /* !I386 */ |
| 1776 | { uoff(u_tsize), "offsetof(struct user, u_tsize)" }, |
| 1777 | { uoff(u_dsize), "offsetof(struct user, u_dsize)" }, |
| 1778 | { uoff(u_ssize), "offsetof(struct user, u_ssize)" }, |
| 1779 | { uoff(start_code), "offsetof(struct user, start_code)" }, |
| 1780 | { uoff(start_stack), "offsetof(struct user, start_stack)" }, |
| 1781 | { uoff(signal), "offsetof(struct user, signal)" }, |
Wichert Akkerman | f90da01 | 1999-10-31 21:15:38 +0000 | [diff] [blame] | 1782 | #ifndef MIPS |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1783 | { uoff(reserved), "offsetof(struct user, reserved)" }, |
Wichert Akkerman | f90da01 | 1999-10-31 21:15:38 +0000 | [diff] [blame] | 1784 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1785 | { uoff(u_ar0), "offsetof(struct user, u_ar0)" }, |
Wichert Akkerman | 4dc8a2a | 1999-12-23 14:20:14 +0000 | [diff] [blame] | 1786 | #if !defined(ARM) && !defined(MIPS) && !defined(S390) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1787 | { uoff(u_fpstate), "offsetof(struct user, u_fpstate)" }, |
| 1788 | #endif |
| 1789 | { uoff(magic), "offsetof(struct user, magic)" }, |
| 1790 | { uoff(u_comm), "offsetof(struct user, u_comm)" }, |
| 1791 | #ifdef I386 |
| 1792 | { uoff(u_debugreg), "offsetof(struct user, u_debugreg)" }, |
| 1793 | #endif /* I386 */ |
| 1794 | #endif /* !ALPHA */ |
| 1795 | #endif /* !POWERPC/!SPARC */ |
| 1796 | #endif /* LINUX */ |
| 1797 | #ifdef SUNOS4 |
| 1798 | { uoff(u_pcb), "offsetof(struct user, u_pcb)" }, |
| 1799 | { uoff(u_procp), "offsetof(struct user, u_procp)" }, |
| 1800 | { uoff(u_ar0), "offsetof(struct user, u_ar0)" }, |
| 1801 | { uoff(u_comm[0]), "offsetof(struct user, u_comm[0])" }, |
| 1802 | { uoff(u_arg[0]), "offsetof(struct user, u_arg[0])" }, |
| 1803 | { uoff(u_ap), "offsetof(struct user, u_ap)" }, |
| 1804 | { uoff(u_qsave), "offsetof(struct user, u_qsave)" }, |
| 1805 | { uoff(u_rval1), "offsetof(struct user, u_rval1)" }, |
| 1806 | { uoff(u_rval2), "offsetof(struct user, u_rval2)" }, |
| 1807 | { uoff(u_error), "offsetof(struct user, u_error)" }, |
| 1808 | { uoff(u_eosys), "offsetof(struct user, u_eosys)" }, |
| 1809 | { uoff(u_ssave), "offsetof(struct user, u_ssave)" }, |
| 1810 | { uoff(u_signal[0]), "offsetof(struct user, u_signal)" }, |
| 1811 | { uoff(u_sigmask[0]), "offsetof(struct user, u_sigmask)" }, |
| 1812 | { uoff(u_sigonstack), "offsetof(struct user, u_sigonstack)" }, |
| 1813 | { uoff(u_sigintr), "offsetof(struct user, u_sigintr)" }, |
| 1814 | { uoff(u_sigreset), "offsetof(struct user, u_sigreset)" }, |
| 1815 | { uoff(u_oldmask), "offsetof(struct user, u_oldmask)" }, |
| 1816 | { uoff(u_code), "offsetof(struct user, u_code)" }, |
| 1817 | { uoff(u_addr), "offsetof(struct user, u_addr)" }, |
| 1818 | { uoff(u_sigstack), "offsetof(struct user, u_sigstack)" }, |
| 1819 | { uoff(u_ofile), "offsetof(struct user, u_ofile)" }, |
| 1820 | { uoff(u_pofile), "offsetof(struct user, u_pofile)" }, |
| 1821 | { uoff(u_ofile_arr[0]), "offsetof(struct user, u_ofile_arr[0])" }, |
| 1822 | { uoff(u_pofile_arr[0]),"offsetof(struct user, u_pofile_arr[0])"}, |
| 1823 | { uoff(u_lastfile), "offsetof(struct user, u_lastfile)" }, |
| 1824 | { uoff(u_cwd), "offsetof(struct user, u_cwd)" }, |
| 1825 | { uoff(u_cdir), "offsetof(struct user, u_cdir)" }, |
| 1826 | { uoff(u_rdir), "offsetof(struct user, u_rdir)" }, |
| 1827 | { uoff(u_cmask), "offsetof(struct user, u_cmask)" }, |
| 1828 | { uoff(u_ru), "offsetof(struct user, u_ru)" }, |
| 1829 | { uoff(u_cru), "offsetof(struct user, u_cru)" }, |
| 1830 | { uoff(u_timer[0]), "offsetof(struct user, u_timer[0])" }, |
| 1831 | { uoff(u_XXX[0]), "offsetof(struct user, u_XXX[0])" }, |
| 1832 | { uoff(u_ioch), "offsetof(struct user, u_ioch)" }, |
| 1833 | { uoff(u_start), "offsetof(struct user, u_start)" }, |
| 1834 | { uoff(u_acflag), "offsetof(struct user, u_acflag)" }, |
| 1835 | { uoff(u_prof.pr_base), "offsetof(struct user, u_prof.pr_base)" }, |
| 1836 | { uoff(u_prof.pr_size), "offsetof(struct user, u_prof.pr_size)" }, |
| 1837 | { uoff(u_prof.pr_off), "offsetof(struct user, u_prof.pr_off)" }, |
| 1838 | { uoff(u_prof.pr_scale),"offsetof(struct user, u_prof.pr_scale)"}, |
| 1839 | { uoff(u_rlimit[0]), "offsetof(struct user, u_rlimit)" }, |
| 1840 | { uoff(u_exdata.Ux_A), "offsetof(struct user, u_exdata.Ux_A)" }, |
| 1841 | { uoff(u_exdata.ux_shell[0]),"offsetof(struct user, u_exdata.ux_shell[0])"}, |
| 1842 | { uoff(u_lofault), "offsetof(struct user, u_lofault)" }, |
| 1843 | #endif /* SUNOS4 */ |
| 1844 | { sizeof(struct user), "sizeof(struct user)" }, |
| 1845 | { 0, NULL }, |
| 1846 | }; |
| 1847 | |
| 1848 | int |
| 1849 | sys_ptrace(tcp) |
| 1850 | struct tcb *tcp; |
| 1851 | { |
| 1852 | char *cmd; |
| 1853 | struct xlat *x; |
| 1854 | long addr; |
| 1855 | |
| 1856 | cmd = xlookup(ptrace_cmds, tcp->u_arg[0]); |
| 1857 | if (!cmd) |
| 1858 | cmd = "PTRACE_???"; |
| 1859 | if (entering(tcp)) { |
| 1860 | tprintf("%s, %lu, ", cmd, tcp->u_arg[1]); |
| 1861 | addr = tcp->u_arg[2]; |
| 1862 | if (tcp->u_arg[0] == PTRACE_PEEKUSER |
| 1863 | || tcp->u_arg[0] == PTRACE_POKEUSER) { |
| 1864 | for (x = struct_user_offsets; x->str; x++) { |
| 1865 | if (x->val >= addr) |
| 1866 | break; |
| 1867 | } |
| 1868 | if (!x->str) |
| 1869 | tprintf("%#lx, ", addr); |
| 1870 | else if (x->val > addr && x != struct_user_offsets) { |
| 1871 | x--; |
| 1872 | tprintf("%s + %ld, ", x->str, addr - x->val); |
| 1873 | } |
| 1874 | else |
| 1875 | tprintf("%s, ", x->str); |
| 1876 | } |
| 1877 | else |
| 1878 | tprintf("%#lx, ", tcp->u_arg[2]); |
| 1879 | #ifdef LINUX |
| 1880 | switch (tcp->u_arg[0]) { |
| 1881 | case PTRACE_PEEKDATA: |
| 1882 | case PTRACE_PEEKTEXT: |
| 1883 | case PTRACE_PEEKUSER: |
| 1884 | break; |
| 1885 | case PTRACE_CONT: |
| 1886 | case PTRACE_SINGLESTEP: |
| 1887 | case PTRACE_SYSCALL: |
| 1888 | case PTRACE_DETACH: |
| 1889 | printsignal(tcp->u_arg[3]); |
| 1890 | break; |
| 1891 | default: |
| 1892 | tprintf("%#lx", tcp->u_arg[3]); |
| 1893 | break; |
| 1894 | } |
| 1895 | } else { |
| 1896 | switch (tcp->u_arg[0]) { |
| 1897 | case PTRACE_PEEKDATA: |
| 1898 | case PTRACE_PEEKTEXT: |
| 1899 | case PTRACE_PEEKUSER: |
| 1900 | printnum(tcp, tcp->u_arg[3], "%#x"); |
| 1901 | break; |
| 1902 | } |
| 1903 | } |
| 1904 | #endif /* LINUX */ |
| 1905 | #ifdef SUNOS4 |
| 1906 | if (tcp->u_arg[0] == PTRACE_WRITEDATA || |
| 1907 | tcp->u_arg[0] == PTRACE_WRITETEXT) { |
| 1908 | tprintf("%lu, ", tcp->u_arg[3]); |
| 1909 | printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]); |
| 1910 | } else if (tcp->u_arg[0] != PTRACE_READDATA && |
| 1911 | tcp->u_arg[0] != PTRACE_READTEXT) { |
| 1912 | tprintf("%#lx", tcp->u_arg[3]); |
| 1913 | } |
| 1914 | } else { |
| 1915 | if (tcp->u_arg[0] == PTRACE_READDATA || |
| 1916 | tcp->u_arg[0] == PTRACE_READTEXT) { |
| 1917 | tprintf("%lu, ", tcp->u_arg[3]); |
| 1918 | printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]); |
| 1919 | } |
| 1920 | } |
| 1921 | #endif /* SUNOS4 */ |
| 1922 | return 0; |
| 1923 | } |
| 1924 | |
| 1925 | #endif /* !SVR4 */ |