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