1 /* 2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk (at) cs.few.eur.nl> 3 * Copyright (c) 1993 Branko Lankester <branko (at) hacktic.nl> 4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs (at) world.std.com> 5 * Copyright (c) 1996-1999 Wichert Akkerman <wichert (at) cistron.nl> 6 * Copyright (c) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation 7 * Linux for s390 port by D.J. Barrow 8 * <barrow_dj (at) mail.yahoo.com,djbarrow (at) de.ibm.com> 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. The name of the author may not be used to endorse or promote products 20 * derived from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * 33 * $Id$ 34 */ 35 36 #include "defs.h" 37 38 #include <stdint.h> 39 #include <signal.h> 40 #ifndef HAVE_ANDROID_OS 41 #include <sys/user.h> 42 #endif 43 #include <fcntl.h> 44 45 #ifdef HAVE_ANDROID_OS 46 //FIXME use "sigprocmask" or something 47 #define sigmask(sig) (1UL << ((sig) - 1)) 48 #define sigcontext_struct sigcontext 49 #endif 50 51 #ifdef SVR4 52 #include <sys/ucontext.h> 53 #endif /* SVR4 */ 54 55 #ifdef HAVE_SYS_REG_H 56 # include <sys/reg.h> 57 #ifndef PTRACE_PEEKUSR 58 # define PTRACE_PEEKUSR PTRACE_PEEKUSER 59 #endif 60 #ifndef PTRACE_POKEUSR 61 # define PTRACE_POKEUSR PTRACE_POKEUSER 62 #endif 63 #elif defined(HAVE_LINUX_PTRACE_H) 64 #undef PTRACE_SYSCALL 65 # ifdef HAVE_STRUCT_IA64_FPREG 66 # define ia64_fpreg XXX_ia64_fpreg 67 # endif 68 # ifdef HAVE_STRUCT_PT_ALL_USER_REGS 69 # define pt_all_user_regs XXX_pt_all_user_regs 70 # endif 71 #include <linux/ptrace.h> 72 # undef ia64_fpreg 73 # undef pt_all_user_regs 74 #endif 75 76 77 #ifdef LINUX 78 79 #ifdef IA64 80 # include <asm/ptrace_offsets.h> 81 #endif /* !IA64 */ 82 83 #if defined (LINUX) && defined (SPARC64) 84 # undef PTRACE_GETREGS 85 # define PTRACE_GETREGS PTRACE_GETREGS64 86 # undef PTRACE_SETREGS 87 # define PTRACE_SETREGS PTRACE_SETREGS64 88 #endif /* LINUX && SPARC64 */ 89 90 #if defined (SPARC) || defined (SPARC64) || defined (MIPS) 91 typedef struct { 92 struct pt_regs si_regs; 93 int si_mask; 94 } m_siginfo_t; 95 #elif defined HAVE_ASM_SIGCONTEXT_H 96 #if !defined(IA64) && !defined(X86_64) 97 #include <asm/sigcontext.h> 98 #endif /* !IA64 && !X86_64 */ 99 #else /* !HAVE_ASM_SIGCONTEXT_H */ 100 #if defined I386 && !defined HAVE_STRUCT_SIGCONTEXT_STRUCT 101 struct sigcontext_struct { 102 unsigned short gs, __gsh; 103 unsigned short fs, __fsh; 104 unsigned short es, __esh; 105 unsigned short ds, __dsh; 106 unsigned long edi; 107 unsigned long esi; 108 unsigned long ebp; 109 unsigned long esp; 110 unsigned long ebx; 111 unsigned long edx; 112 unsigned long ecx; 113 unsigned long eax; 114 unsigned long trapno; 115 unsigned long err; 116 unsigned long eip; 117 unsigned short cs, __csh; 118 unsigned long eflags; 119 unsigned long esp_at_signal; 120 unsigned short ss, __ssh; 121 unsigned long i387; 122 unsigned long oldmask; 123 unsigned long cr2; 124 }; 125 #else /* !I386 */ 126 #if defined M68K && !defined HAVE_STRUCT_SIGCONTEXT 127 struct sigcontext 128 { 129 unsigned long sc_mask; 130 unsigned long sc_usp; 131 unsigned long sc_d0; 132 unsigned long sc_d1; 133 unsigned long sc_a0; 134 unsigned long sc_a1; 135 unsigned short sc_sr; 136 unsigned long sc_pc; 137 unsigned short sc_formatvec; 138 }; 139 #endif /* M68K */ 140 #endif /* !I386 */ 141 #endif /* !HAVE_ASM_SIGCONTEXT_H */ 142 #ifndef NSIG 143 #define NSIG 32 144 #endif 145 #ifdef ARM 146 #undef NSIG 147 #define NSIG 32 148 #endif 149 #endif /* LINUX */ 150 151 const char *const signalent0[] = { 152 #include "signalent.h" 153 }; 154 const int nsignals0 = sizeof signalent0 / sizeof signalent0[0]; 155 156 #if SUPPORTED_PERSONALITIES >= 2 157 const char *const signalent1[] = { 158 #include "signalent1.h" 159 }; 160 const int nsignals1 = sizeof signalent1 / sizeof signalent1[0]; 161 #endif /* SUPPORTED_PERSONALITIES >= 2 */ 162 163 #if SUPPORTED_PERSONALITIES >= 3 164 const char *const signalent2[] = { 165 #include "signalent2.h" 166 }; 167 const int nsignals2 = sizeof signalent2 / sizeof signalent2[0]; 168 #endif /* SUPPORTED_PERSONALITIES >= 3 */ 169 170 const char *const *signalent; 171 int nsignals; 172 173 #if defined(SUNOS4) || defined(FREEBSD) 174 175 static const struct xlat sigvec_flags[] = { 176 { SV_ONSTACK, "SV_ONSTACK" }, 177 { SV_INTERRUPT, "SV_INTERRUPT" }, 178 { SV_RESETHAND, "SV_RESETHAND" }, 179 { SA_NOCLDSTOP, "SA_NOCLDSTOP" }, 180 { 0, NULL }, 181 }; 182 183 #endif /* SUNOS4 || FREEBSD */ 184 185 #ifdef HAVE_SIGACTION 186 187 #if defined LINUX && (defined I386 || defined X86_64) 188 /* The libc headers do not define this constant since it should only be 189 used by the implementation. So wwe define it here. */ 190 # ifndef SA_RESTORER 191 # define SA_RESTORER 0x04000000 192 # endif 193 #endif 194 195 static const struct xlat sigact_flags[] = { 196 #ifdef SA_RESTORER 197 { SA_RESTORER, "SA_RESTORER" }, 198 #endif 199 #ifdef SA_STACK 200 { SA_STACK, "SA_STACK" }, 201 #endif 202 #ifdef SA_RESTART 203 { SA_RESTART, "SA_RESTART" }, 204 #endif 205 #ifdef SA_INTERRUPT 206 { SA_INTERRUPT, "SA_INTERRUPT" }, 207 #endif 208 #ifdef SA_NODEFER 209 { SA_NODEFER, "SA_NODEFER" }, 210 #endif 211 #if defined SA_NOMASK && SA_NODEFER != SA_NOMASK 212 { SA_NOMASK, "SA_NOMASK" }, 213 #endif 214 #ifdef SA_RESETHAND 215 { SA_RESETHAND, "SA_RESETHAND" }, 216 #endif 217 #if defined SA_ONESHOT && SA_ONESHOT != SA_RESETHAND 218 { SA_ONESHOT, "SA_ONESHOT" }, 219 #endif 220 #ifdef SA_SIGINFO 221 { SA_SIGINFO, "SA_SIGINFO" }, 222 #endif 223 #ifdef SA_RESETHAND 224 { SA_RESETHAND, "SA_RESETHAND" }, 225 #endif 226 #ifdef SA_ONSTACK 227 { SA_ONSTACK, "SA_ONSTACK" }, 228 #endif 229 #ifdef SA_NODEFER 230 { SA_NODEFER, "SA_NODEFER" }, 231 #endif 232 #ifdef SA_NOCLDSTOP 233 { SA_NOCLDSTOP, "SA_NOCLDSTOP" }, 234 #endif 235 #ifdef SA_NOCLDWAIT 236 { SA_NOCLDWAIT, "SA_NOCLDWAIT" }, 237 #endif 238 #ifdef _SA_BSDCALL 239 { _SA_BSDCALL, "_SA_BSDCALL" }, 240 #endif 241 #ifdef SA_NOPTRACE 242 { SA_NOPTRACE, "SA_NOPTRACE" }, 243 #endif 244 { 0, NULL }, 245 }; 246 247 static const struct xlat sigprocmaskcmds[] = { 248 { SIG_BLOCK, "SIG_BLOCK" }, 249 { SIG_UNBLOCK, "SIG_UNBLOCK" }, 250 { SIG_SETMASK, "SIG_SETMASK" }, 251 #ifdef SIG_SETMASK32 252 { SIG_SETMASK32,"SIG_SETMASK32" }, 253 #endif 254 { 0, NULL }, 255 }; 256 257 #endif /* HAVE_SIGACTION */ 258 259 /* Anonymous realtime signals. */ 260 /* Under glibc 2.1, SIGRTMIN et al are functions, but __SIGRTMIN is a 261 constant. This is what we want. Otherwise, just use SIGRTMIN. */ 262 #ifdef SIGRTMIN 263 #ifndef __SIGRTMIN 264 #define __SIGRTMIN SIGRTMIN 265 #define __SIGRTMAX SIGRTMAX /* likewise */ 266 #endif 267 #endif 268 269 const char * 270 signame(sig) 271 int sig; 272 { 273 static char buf[30]; 274 if (sig >= 0 && sig < nsignals) { 275 return signalent[sig]; 276 #ifdef SIGRTMIN 277 } else if (sig >= __SIGRTMIN && sig <= __SIGRTMAX) { 278 sprintf(buf, "SIGRT_%ld", (long)(sig - __SIGRTMIN)); 279 return buf; 280 #endif /* SIGRTMIN */ 281 } else { 282 sprintf(buf, "%d", sig); 283 return buf; 284 } 285 } 286 287 #ifndef UNIXWARE 288 static void 289 long_to_sigset(l, s) 290 long l; 291 sigset_t *s; 292 { 293 sigemptyset(s); 294 *(long *)s = l; 295 } 296 #endif 297 298 static int 299 copy_sigset_len(tcp, addr, s, len) 300 struct tcb *tcp; 301 long addr; 302 sigset_t *s; 303 int len; 304 { 305 if (len > sizeof(*s)) 306 len = sizeof(*s); 307 sigemptyset(s); 308 if (umoven(tcp, addr, len, (char *)s) < 0) 309 return -1; 310 return 0; 311 } 312 313 #ifdef LINUX 314 /* Original sigset is unsigned long */ 315 #define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(long)) 316 #else 317 #define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(sigset_t)) 318 #endif 319 320 static const char * 321 sprintsigmask(const char *str, sigset_t *mask, int rt) 322 /* set might include realtime sigs */ 323 { 324 int i, nsigs; 325 int maxsigs; 326 const char *format; 327 char *s; 328 static char outstr[8 * sizeof(sigset_t) * 8]; 329 330 strcpy(outstr, str); 331 s = outstr + strlen(outstr); 332 nsigs = 0; 333 maxsigs = nsignals; 334 #ifdef __SIGRTMAX 335 if (rt) 336 maxsigs = __SIGRTMAX; /* instead */ 337 #endif 338 for (i = 1; i < maxsigs; i++) { 339 if (sigismember(mask, i) == 1) 340 nsigs++; 341 } 342 if (nsigs >= nsignals * 2 / 3) { 343 *s++ = '~'; 344 for (i = 1; i < maxsigs; i++) { 345 switch (sigismember(mask, i)) { 346 case 1: 347 sigdelset(mask, i); 348 break; 349 case 0: 350 sigaddset(mask, i); 351 break; 352 } 353 } 354 } 355 format = "%s"; 356 *s++ = '['; 357 for (i = 1; i < maxsigs; i++) { 358 if (sigismember(mask, i) == 1) { 359 /* real-time signals on solaris don't have 360 * signalent entries 361 */ 362 if (i < nsignals) { 363 sprintf(s, format, signalent[i] + 3); 364 } 365 #ifdef SIGRTMIN 366 else if (i >= __SIGRTMIN && i <= __SIGRTMAX) { 367 char tsig[40]; 368 sprintf(tsig, "RT_%u", i - __SIGRTMIN); 369 sprintf(s, format, tsig); 370 } 371 #endif /* SIGRTMIN */ 372 else { 373 char tsig[32]; 374 sprintf(tsig, "%u", i); 375 sprintf(s, format, tsig); 376 } 377 s += strlen(s); 378 format = " %s"; 379 } 380 } 381 *s++ = ']'; 382 *s = '\0'; 383 return outstr; 384 } 385 386 static void 387 printsigmask(mask, rt) 388 sigset_t *mask; 389 int rt; 390 { 391 tprintf("%s", sprintsigmask("", mask, rt)); 392 } 393 394 void 395 printsignal(nr) 396 int nr; 397 { 398 tprintf("%s", signame(nr)); 399 } 400 401 void 402 print_sigset(struct tcb *tcp, long addr, int rt) 403 { 404 sigset_t ss; 405 406 if (!addr) 407 tprintf("NULL"); 408 else if (copy_sigset(tcp, addr, &ss) < 0) 409 tprintf("%#lx", addr); 410 else 411 printsigmask(&ss, rt); 412 } 413 414 #ifdef LINUX 415 416 #ifndef ILL_ILLOPC 417 #define ILL_ILLOPC 1 /* illegal opcode */ 418 #define ILL_ILLOPN 2 /* illegal operand */ 419 #define ILL_ILLADR 3 /* illegal addressing mode */ 420 #define ILL_ILLTRP 4 /* illegal trap */ 421 #define ILL_PRVOPC 5 /* privileged opcode */ 422 #define ILL_PRVREG 6 /* privileged register */ 423 #define ILL_COPROC 7 /* coprocessor error */ 424 #define ILL_BADSTK 8 /* internal stack error */ 425 #define FPE_INTDIV 1 /* integer divide by zero */ 426 #define FPE_INTOVF 2 /* integer overflow */ 427 #define FPE_FLTDIV 3 /* floating point divide by zero */ 428 #define FPE_FLTOVF 4 /* floating point overflow */ 429 #define FPE_FLTUND 5 /* floating point underflow */ 430 #define FPE_FLTRES 6 /* floating point inexact result */ 431 #define FPE_FLTINV 7 /* floating point invalid operation */ 432 #define FPE_FLTSUB 8 /* subscript out of range */ 433 #define SEGV_MAPERR 1 /* address not mapped to object */ 434 #define SEGV_ACCERR 2 /* invalid permissions for mapped object */ 435 #define BUS_ADRALN 1 /* invalid address alignment */ 436 #define BUS_ADRERR 2 /* non-existant physical address */ 437 #define BUS_OBJERR 3 /* object specific hardware error */ 438 #define TRAP_BRKPT 1 /* process breakpoint */ 439 #define TRAP_TRACE 2 /* process trace trap */ 440 #define CLD_EXITED 1 /* child has exited */ 441 #define CLD_KILLED 2 /* child was killed */ 442 #define CLD_DUMPED 3 /* child terminated abnormally */ 443 #define CLD_TRAPPED 4 /* traced child has trapped */ 444 #define CLD_STOPPED 5 /* child has stopped */ 445 #define CLD_CONTINUED 6 /* stopped child has continued */ 446 #define POLL_IN 1 /* data input available */ 447 #define POLL_OUT 2 /* output buffers available */ 448 #define POLL_MSG 3 /* input message available */ 449 #define POLL_ERR 4 /* i/o error */ 450 #define POLL_PRI 5 /* high priority input available */ 451 #define POLL_HUP 6 /* device disconnected */ 452 #define SI_KERNEL 0x80 /* sent by kernel */ 453 #define SI_USER 0 /* sent by kill, sigsend, raise */ 454 #define SI_QUEUE -1 /* sent by sigqueue */ 455 #define SI_TIMER -2 /* sent by timer expiration */ 456 #define SI_MESGQ -3 /* sent by real time mesq state change */ 457 #define SI_ASYNCIO -4 /* sent by AIO completion */ 458 #define SI_SIGIO -5 /* sent by SIGIO */ 459 #define SI_TKILL -6 /* sent by tkill */ 460 #define SI_ASYNCNL -60 /* sent by asynch name lookup completion */ 461 462 #define SI_FROMUSER(sip) ((sip)->si_code <= 0) 463 464 #endif /* LINUX */ 465 466 #if __GLIBC_MINOR__ < 1 && !defined(HAVE_ANDROID_OS) 467 /* Type for data associated with a signal. */ 468 typedef union sigval 469 { 470 int sival_int; 471 void *sival_ptr; 472 } sigval_t; 473 474 # define __SI_MAX_SIZE 128 475 # define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 3) 476 477 typedef struct siginfo 478 { 479 int si_signo; /* Signal number. */ 480 int si_errno; /* If non-zero, an errno value associated with 481 this signal, as defined in <errno.h>. */ 482 int si_code; /* Signal code. */ 483 484 union 485 { 486 int _pad[__SI_PAD_SIZE]; 487 488 /* kill(). */ 489 struct 490 { 491 __pid_t si_pid; /* Sending process ID. */ 492 __uid_t si_uid; /* Real user ID of sending process. */ 493 } _kill; 494 495 /* POSIX.1b timers. */ 496 struct 497 { 498 unsigned int _timer1; 499 unsigned int _timer2; 500 } _timer; 501 502 /* POSIX.1b signals. */ 503 struct 504 { 505 __pid_t si_pid; /* Sending process ID. */ 506 __uid_t si_uid; /* Real user ID of sending process. */ 507 sigval_t si_sigval; /* Signal value. */ 508 } _rt; 509 510 /* SIGCHLD. */ 511 struct 512 { 513 __pid_t si_pid; /* Which child. */ 514 int si_status; /* Exit value or signal. */ 515 __clock_t si_utime; 516 __clock_t si_stime; 517 } _sigchld; 518 519 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */ 520 struct 521 { 522 void *si_addr; /* Faulting insn/memory ref. */ 523 } _sigfault; 524 525 /* SIGPOLL. */ 526 struct 527 { 528 int si_band; /* Band event for SIGPOLL. */ 529 int si_fd; 530 } _sigpoll; 531 } _sifields; 532 } siginfo_t; 533 534 #define si_pid _sifields._kill.si_pid 535 #define si_uid _sifields._kill.si_uid 536 #define si_status _sifields._sigchld.si_status 537 #define si_utime _sifields._sigchld.si_utime 538 #define si_stime _sifields._sigchld.si_stime 539 #define si_value _sifields._rt.si_sigval 540 #define si_int _sifields._rt.si_sigval.sival_int 541 #define si_ptr _sifields._rt.si_sigval.sival_ptr 542 #define si_addr _sifields._sigfault.si_addr 543 #define si_band _sifields._sigpoll.si_band 544 #define si_fd _sifields._sigpoll.si_fd 545 546 #endif 547 548 #endif 549 550 #if defined (SVR4) || defined (LINUX) 551 552 static const struct xlat siginfo_codes[] = { 553 #ifdef SI_KERNEL 554 { SI_KERNEL, "SI_KERNEL" }, 555 #endif 556 #ifdef SI_USER 557 { SI_USER, "SI_USER" }, 558 #endif 559 #ifdef SI_QUEUE 560 { SI_QUEUE, "SI_QUEUE" }, 561 #endif 562 #ifdef SI_TIMER 563 { SI_TIMER, "SI_TIMER" }, 564 #endif 565 #ifdef SI_MESGQ 566 { SI_MESGQ, "SI_MESGQ" }, 567 #endif 568 #ifdef SI_ASYNCIO 569 { SI_ASYNCIO, "SI_ASYNCIO" }, 570 #endif 571 #ifdef SI_SIGIO 572 { SI_SIGIO, "SI_SIGIO" }, 573 #endif 574 #ifdef SI_TKILL 575 { SI_TKILL, "SI_TKILL" }, 576 #endif 577 #ifdef SI_ASYNCNL 578 { SI_ASYNCNL, "SI_ASYNCNL" }, 579 #endif 580 #ifdef SI_NOINFO 581 { SI_NOINFO, "SI_NOINFO" }, 582 #endif 583 #ifdef SI_LWP 584 { SI_LWP, "SI_LWP" }, 585 #endif 586 { 0, NULL }, 587 }; 588 589 static const struct xlat sigill_codes[] = { 590 { ILL_ILLOPC, "ILL_ILLOPC" }, 591 { ILL_ILLOPN, "ILL_ILLOPN" }, 592 { ILL_ILLADR, "ILL_ILLADR" }, 593 { ILL_ILLTRP, "ILL_ILLTRP" }, 594 { ILL_PRVOPC, "ILL_PRVOPC" }, 595 { ILL_PRVREG, "ILL_PRVREG" }, 596 { ILL_COPROC, "ILL_COPROC" }, 597 { ILL_BADSTK, "ILL_BADSTK" }, 598 { 0, NULL }, 599 }; 600 601 static const struct xlat sigfpe_codes[] = { 602 { FPE_INTDIV, "FPE_INTDIV" }, 603 { FPE_INTOVF, "FPE_INTOVF" }, 604 { FPE_FLTDIV, "FPE_FLTDIV" }, 605 { FPE_FLTOVF, "FPE_FLTOVF" }, 606 { FPE_FLTUND, "FPE_FLTUND" }, 607 { FPE_FLTRES, "FPE_FLTRES" }, 608 { FPE_FLTINV, "FPE_FLTINV" }, 609 { FPE_FLTSUB, "FPE_FLTSUB" }, 610 { 0, NULL }, 611 }; 612 613 static const struct xlat sigtrap_codes[] = { 614 { TRAP_BRKPT, "TRAP_BRKPT" }, 615 { TRAP_TRACE, "TRAP_TRACE" }, 616 { 0, NULL }, 617 }; 618 619 static const struct xlat sigchld_codes[] = { 620 { CLD_EXITED, "CLD_EXITED" }, 621 { CLD_KILLED, "CLD_KILLED" }, 622 { CLD_DUMPED, "CLD_DUMPED" }, 623 { CLD_TRAPPED, "CLD_TRAPPED" }, 624 { CLD_STOPPED, "CLD_STOPPED" }, 625 { CLD_CONTINUED,"CLD_CONTINUED" }, 626 { 0, NULL }, 627 }; 628 629 static const struct xlat sigpoll_codes[] = { 630 { POLL_IN, "POLL_IN" }, 631 { POLL_OUT, "POLL_OUT" }, 632 { POLL_MSG, "POLL_MSG" }, 633 { POLL_ERR, "POLL_ERR" }, 634 { POLL_PRI, "POLL_PRI" }, 635 { POLL_HUP, "POLL_HUP" }, 636 { 0, NULL }, 637 }; 638 639 static const struct xlat sigprof_codes[] = { 640 #ifdef PROF_SIG 641 { PROF_SIG, "PROF_SIG" }, 642 #endif 643 { 0, NULL }, 644 }; 645 646 #ifdef SIGEMT 647 static const struct xlat sigemt_codes[] = { 648 #ifdef EMT_TAGOVF 649 { EMT_TAGOVF, "EMT_TAGOVF" }, 650 #endif 651 { 0, NULL }, 652 }; 653 #endif 654 655 static const struct xlat sigsegv_codes[] = { 656 { SEGV_MAPERR, "SEGV_MAPERR" }, 657 { SEGV_ACCERR, "SEGV_ACCERR" }, 658 { 0, NULL }, 659 }; 660 661 static const struct xlat sigbus_codes[] = { 662 { BUS_ADRALN, "BUS_ADRALN" }, 663 { BUS_ADRERR, "BUS_ADRERR" }, 664 { BUS_OBJERR, "BUS_OBJERR" }, 665 { 0, NULL }, 666 }; 667 668 void 669 printsiginfo(siginfo_t *sip, int verbose) 670 { 671 const char *code; 672 673 if (sip->si_signo == 0) { 674 tprintf ("{}"); 675 return; 676 } 677 tprintf("{si_signo="); 678 printsignal(sip->si_signo); 679 code = xlookup(siginfo_codes, sip->si_code); 680 if (!code) { 681 switch (sip->si_signo) { 682 case SIGTRAP: 683 code = xlookup(sigtrap_codes, sip->si_code); 684 break; 685 case SIGCHLD: 686 code = xlookup(sigchld_codes, sip->si_code); 687 break; 688 case SIGPOLL: 689 code = xlookup(sigpoll_codes, sip->si_code); 690 break; 691 case SIGPROF: 692 code = xlookup(sigprof_codes, sip->si_code); 693 break; 694 case SIGILL: 695 code = xlookup(sigill_codes, sip->si_code); 696 break; 697 #ifdef SIGEMT 698 case SIGEMT: 699 code = xlookup(sigemt_codes, sip->si_code); 700 break; 701 #endif 702 case SIGFPE: 703 code = xlookup(sigfpe_codes, sip->si_code); 704 break; 705 case SIGSEGV: 706 code = xlookup(sigsegv_codes, sip->si_code); 707 break; 708 case SIGBUS: 709 code = xlookup(sigbus_codes, sip->si_code); 710 break; 711 } 712 } 713 if (code) 714 tprintf(", si_code=%s", code); 715 else 716 tprintf(", si_code=%#x", sip->si_code); 717 #ifdef SI_NOINFO 718 if (sip->si_code != SI_NOINFO) 719 #endif 720 { 721 if (sip->si_errno) { 722 if (sip->si_errno < 0 || sip->si_errno >= nerrnos) 723 tprintf(", si_errno=%d", sip->si_errno); 724 else 725 tprintf(", si_errno=%s", 726 errnoent[sip->si_errno]); 727 } 728 #ifdef SI_FROMUSER 729 if (SI_FROMUSER(sip)) { 730 tprintf(", si_pid=%lu, si_uid=%lu", 731 (unsigned long) sip->si_pid, 732 (unsigned long) sip->si_uid); 733 switch (sip->si_code) { 734 #ifdef SI_USER 735 case SI_USER: 736 break; 737 #endif 738 #ifdef SI_TKILL 739 case SI_TKILL: 740 break; 741 #endif 742 #ifdef SI_TIMER 743 case SI_TIMER: 744 tprintf(", si_value=%d", sip->si_int); 745 break; 746 #endif 747 #ifdef LINUX 748 default: 749 if (!sip->si_ptr) 750 break; 751 if (!verbose) 752 tprintf(", ..."); 753 else 754 tprintf(", si_value={int=%u, ptr=%#lx}", 755 sip->si_int, 756 (unsigned long) sip->si_ptr); 757 break; 758 #endif 759 } 760 } 761 else 762 #endif /* SI_FROMUSER */ 763 { 764 switch (sip->si_signo) { 765 case SIGCHLD: 766 tprintf(", si_pid=%ld, si_status=", 767 (long) sip->si_pid); 768 if (sip->si_code == CLD_EXITED) 769 tprintf("%d", sip->si_status); 770 else 771 printsignal(sip->si_status); 772 #if LINUX 773 if (!verbose) 774 tprintf(", ..."); 775 else 776 tprintf(", si_utime=%lu, si_stime=%lu", 777 sip->si_utime, 778 sip->si_stime); 779 #endif 780 break; 781 case SIGILL: case SIGFPE: 782 case SIGSEGV: case SIGBUS: 783 tprintf(", si_addr=%#lx", 784 (unsigned long) sip->si_addr); 785 break; 786 case SIGPOLL: 787 switch (sip->si_code) { 788 case POLL_IN: case POLL_OUT: case POLL_MSG: 789 tprintf(", si_band=%ld", 790 (long) sip->si_band); 791 break; 792 } 793 break; 794 #ifdef LINUX 795 default: 796 if (sip->si_pid || sip->si_uid) 797 tprintf(", si_pid=%lu, si_uid=%lu", 798 (unsigned long) sip->si_pid, 799 (unsigned long) sip->si_uid); 800 if (!sip->si_ptr) 801 break; 802 if (!verbose) 803 tprintf(", ..."); 804 else { 805 tprintf(", si_value={int=%u, ptr=%#lx}", 806 sip->si_int, 807 (unsigned long) sip->si_ptr); 808 } 809 #endif 810 811 } 812 } 813 } 814 tprintf("}"); 815 } 816 817 #endif /* SVR4 || LINUX */ 818 819 #ifdef LINUX 820 821 static void 822 parse_sigset_t(const char *str, sigset_t *set) 823 { 824 const char *p; 825 unsigned int digit; 826 int i; 827 828 sigemptyset(set); 829 830 p = strchr(str, '\n'); 831 if (p == NULL) 832 p = strchr(str, '\0'); 833 for (i = 0; p-- > str; i += 4) { 834 if (*p >= '0' && *p <= '9') 835 digit = *p - '0'; 836 else if (*p >= 'a' && *p <= 'f') 837 digit = *p - 'a' + 10; 838 else if (*p >= 'A' && *p <= 'F') 839 digit = *p - 'A' + 10; 840 else 841 break; 842 if (digit & 1) 843 sigaddset(set, i + 1); 844 if (digit & 2) 845 sigaddset(set, i + 2); 846 if (digit & 4) 847 sigaddset(set, i + 3); 848 if (digit & 8) 849 sigaddset(set, i + 4); 850 } 851 } 852 853 #endif 854 855 /* 856 * Check process TCP for the disposition of signal SIG. 857 * Return 1 if the process would somehow manage to survive signal SIG, 858 * else return 0. This routine will never be called with SIGKILL. 859 */ 860 int 861 sigishandled(tcp, sig) 862 struct tcb *tcp; 863 int sig; 864 { 865 #ifdef LINUX 866 int sfd; 867 char sname[32]; 868 char buf[2048]; 869 const char *s; 870 int i; 871 sigset_t ignored, caught; 872 #endif 873 #ifdef SVR4 874 /* 875 * Since procfs doesn't interfere with wait I think it is safe 876 * to punt on this question. If not, the information is there. 877 */ 878 return 1; 879 #else /* !SVR4 */ 880 switch (sig) { 881 case SIGCONT: 882 case SIGSTOP: 883 case SIGTSTP: 884 case SIGTTIN: 885 case SIGTTOU: 886 case SIGCHLD: 887 case SIGIO: 888 #if defined(SIGURG) && SIGURG != SIGIO 889 case SIGURG: 890 #endif 891 case SIGWINCH: 892 /* Gloria Gaynor says ... */ 893 return 1; 894 default: 895 break; 896 } 897 #endif /* !SVR4 */ 898 #ifdef LINUX 899 900 /* This is incredibly costly but it's worth it. */ 901 /* NOTE: LinuxThreads internally uses SIGRTMIN, SIGRTMIN + 1 and 902 SIGRTMIN + 2, so we can't use the obsolete /proc/%d/stat which 903 doesn't handle real-time signals). */ 904 sprintf(sname, "/proc/%d/status", tcp->pid); 905 if ((sfd = open(sname, O_RDONLY)) == -1) { 906 perror(sname); 907 return 1; 908 } 909 i = read(sfd, buf, sizeof(buf)); 910 buf[i] = '\0'; 911 close(sfd); 912 /* 913 * Skip the extraneous fields. We need to skip 914 * command name has any spaces in it. So be it. 915 */ 916 s = strstr(buf, "SigIgn:\t"); 917 if (!s) 918 { 919 fprintf(stderr, "/proc/pid/status format error\n"); 920 return 1; 921 } 922 parse_sigset_t(s + 8, &ignored); 923 924 s = strstr(buf, "SigCgt:\t"); 925 if (!s) 926 { 927 fprintf(stderr, "/proc/pid/status format error\n"); 928 return 1; 929 } 930 parse_sigset_t(s + 8, &caught); 931 932 #ifdef DEBUG 933 fprintf(stderr, "sigs: %016qx %016qx (sig=%d)\n", 934 *(long long *) &ignored, *(long long *) &caught, sig); 935 #endif 936 if (sigismember(&ignored, sig) || sigismember(&caught, sig)) 937 return 1; 938 #endif /* LINUX */ 939 940 #ifdef SUNOS4 941 void (*u_signal)(); 942 943 if (upeek(tcp, uoff(u_signal[0]) + sig*sizeof(u_signal), 944 (long *) &u_signal) < 0) { 945 return 0; 946 } 947 if (u_signal != SIG_DFL) 948 return 1; 949 #endif /* SUNOS4 */ 950 951 return 0; 952 } 953 954 #if defined(SUNOS4) || defined(FREEBSD) 955 956 int 957 sys_sigvec(tcp) 958 struct tcb *tcp; 959 { 960 struct sigvec sv; 961 long addr; 962 963 if (entering(tcp)) { 964 printsignal(tcp->u_arg[0]); 965 tprintf(", "); 966 addr = tcp->u_arg[1]; 967 } else { 968 addr = tcp->u_arg[2]; 969 } 970 if (addr == 0) 971 tprintf("NULL"); 972 else if (!verbose(tcp)) 973 tprintf("%#lx", addr); 974 else if (umove(tcp, addr, &sv) < 0) 975 tprintf("{...}"); 976 else { 977 switch ((int) sv.sv_handler) { 978 case (int) SIG_ERR: 979 tprintf("{SIG_ERR}"); 980 break; 981 case (int) SIG_DFL: 982 tprintf("{SIG_DFL}"); 983 break; 984 case (int) SIG_IGN: 985 if (tcp->u_arg[0] == SIGTRAP) { 986 tcp->flags |= TCB_SIGTRAPPED; 987 kill(tcp->pid, SIGSTOP); 988 } 989 tprintf("{SIG_IGN}"); 990 break; 991 case (int) SIG_HOLD: 992 if (tcp->u_arg[0] == SIGTRAP) { 993 tcp->flags |= TCB_SIGTRAPPED; 994 kill(tcp->pid, SIGSTOP); 995 } 996 tprintf("SIG_HOLD"); 997 break; 998 default: 999 if (tcp->u_arg[0] == SIGTRAP) { 1000 tcp->flags |= TCB_SIGTRAPPED; 1001 kill(tcp->pid, SIGSTOP); 1002 } 1003 tprintf("{%#lx, ", (unsigned long) sv.sv_handler); 1004 printsigmask(&sv.sv_mask, 0); 1005 tprintf(", "); 1006 printflags(sigvec_flags, sv.sv_flags, "SV_???"); 1007 tprintf("}"); 1008 } 1009 } 1010 if (entering(tcp)) 1011 tprintf(", "); 1012 return 0; 1013 } 1014 1015 int 1016 sys_sigpause(tcp) 1017 struct tcb *tcp; 1018 { 1019 if (entering(tcp)) { /* WTA: UD had a bug here: he forgot the braces */ 1020 sigset_t sigm; 1021 long_to_sigset(tcp->u_arg[0], &sigm); 1022 printsigmask(&sigm, 0); 1023 } 1024 return 0; 1025 } 1026 1027 int 1028 sys_sigstack(tcp) 1029 struct tcb *tcp; 1030 { 1031 struct sigstack ss; 1032 long addr; 1033 1034 if (entering(tcp)) 1035 addr = tcp->u_arg[0]; 1036 else 1037 addr = tcp->u_arg[1]; 1038 if (addr == 0) 1039 tprintf("NULL"); 1040 else if (umove(tcp, addr, &ss) < 0) 1041 tprintf("%#lx", addr); 1042 else { 1043 tprintf("{ss_sp %#lx ", (unsigned long) ss.ss_sp); 1044 tprintf("ss_onstack %s}", ss.ss_onstack ? "YES" : "NO"); 1045 } 1046 if (entering(tcp)) 1047 tprintf(", "); 1048 return 0; 1049 } 1050 1051 int 1052 sys_sigcleanup(tcp) 1053 struct tcb *tcp; 1054 { 1055 return 0; 1056 } 1057 1058 #endif /* SUNOS4 || FREEBSD */ 1059 1060 #ifndef SVR4 1061 1062 int 1063 sys_sigsetmask(tcp) 1064 struct tcb *tcp; 1065 { 1066 if (entering(tcp)) { 1067 sigset_t sigm; 1068 long_to_sigset(tcp->u_arg[0], &sigm); 1069 printsigmask(&sigm, 0); 1070 #ifndef USE_PROCFS 1071 if ((tcp->u_arg[0] & sigmask(SIGTRAP))) { 1072 /* Mark attempt to block SIGTRAP */ 1073 tcp->flags |= TCB_SIGTRAPPED; 1074 /* Send unblockable signal */ 1075 kill(tcp->pid, SIGSTOP); 1076 } 1077 #endif /* !USE_PROCFS */ 1078 } 1079 else if (!syserror(tcp)) { 1080 sigset_t sigm; 1081 long_to_sigset(tcp->u_rval, &sigm); 1082 tcp->auxstr = sprintsigmask("old mask ", &sigm, 0); 1083 1084 return RVAL_HEX | RVAL_STR; 1085 } 1086 return 0; 1087 } 1088 1089 #if defined(SUNOS4) || defined(FREEBSD) 1090 int 1091 sys_sigblock(tcp) 1092 struct tcb *tcp; 1093 { 1094 return sys_sigsetmask(tcp); 1095 } 1096 #endif /* SUNOS4 || FREEBSD */ 1097 1098 #endif /* !SVR4 */ 1099 1100 #ifdef HAVE_SIGACTION 1101 1102 #ifdef LINUX 1103 struct old_sigaction { 1104 __sighandler_t __sa_handler; 1105 unsigned long sa_mask; 1106 unsigned long sa_flags; 1107 void (*sa_restorer)(void); 1108 }; 1109 #define SA_HANDLER __sa_handler 1110 #endif /* LINUX */ 1111 1112 #ifndef SA_HANDLER 1113 #define SA_HANDLER sa_handler 1114 #endif 1115 1116 int 1117 sys_sigaction(tcp) 1118 struct tcb *tcp; 1119 { 1120 long addr; 1121 #ifdef LINUX 1122 sigset_t sigset; 1123 struct old_sigaction sa; 1124 #else 1125 struct sigaction sa; 1126 #endif 1127 1128 1129 if (entering(tcp)) { 1130 printsignal(tcp->u_arg[0]); 1131 tprintf(", "); 1132 addr = tcp->u_arg[1]; 1133 } else 1134 addr = tcp->u_arg[2]; 1135 if (addr == 0) 1136 tprintf("NULL"); 1137 else if (!verbose(tcp)) 1138 tprintf("%#lx", addr); 1139 else if (umove(tcp, addr, &sa) < 0) 1140 tprintf("{...}"); 1141 else { 1142 /* Architectures using function pointers, like 1143 * hppa, may need to manipulate the function pointer 1144 * to compute the result of a comparison. However, 1145 * the SA_HANDLER function pointer exists only in 1146 * the address space of the traced process, and can't 1147 * be manipulated by strace. In order to prevent the 1148 * compiler from generating code to manipulate 1149 * SA_HANDLER we cast the function pointers to long. */ 1150 if ((long)sa.SA_HANDLER == (long)SIG_ERR) 1151 tprintf("{SIG_ERR, "); 1152 else if ((long)sa.SA_HANDLER == (long)SIG_DFL) 1153 tprintf("{SIG_DFL, "); 1154 else if ((long)sa.SA_HANDLER == (long)SIG_IGN) { 1155 #ifndef USE_PROCFS 1156 if (tcp->u_arg[0] == SIGTRAP) { 1157 tcp->flags |= TCB_SIGTRAPPED; 1158 kill(tcp->pid, SIGSTOP); 1159 } 1160 #endif /* !USE_PROCFS */ 1161 tprintf("{SIG_IGN, "); 1162 } 1163 else { 1164 #ifndef USE_PROCFS 1165 if (tcp->u_arg[0] == SIGTRAP) { 1166 tcp->flags |= TCB_SIGTRAPPED; 1167 kill(tcp->pid, SIGSTOP); 1168 } 1169 #endif /* !USE_PROCFS */ 1170 tprintf("{%#lx, ", (long) sa.SA_HANDLER); 1171 #ifndef LINUX 1172 printsigmask (&sa.sa_mask, 0); 1173 #else 1174 long_to_sigset(sa.sa_mask, &sigset); 1175 printsigmask(&sigset, 0); 1176 #endif 1177 tprintf(", "); 1178 printflags(sigact_flags, sa.sa_flags, "SA_???"); 1179 #ifdef SA_RESTORER 1180 if (sa.sa_flags & SA_RESTORER) 1181 tprintf(", %p", sa.sa_restorer); 1182 #endif 1183 tprintf("}"); 1184 } 1185 } 1186 if (entering(tcp)) 1187 tprintf(", "); 1188 #ifdef LINUX 1189 else 1190 tprintf(", %#lx", (unsigned long) sa.sa_restorer); 1191 #endif 1192 return 0; 1193 } 1194 1195 int 1196 sys_signal(tcp) 1197 struct tcb *tcp; 1198 { 1199 if (entering(tcp)) { 1200 printsignal(tcp->u_arg[0]); 1201 tprintf(", "); 1202 switch (tcp->u_arg[1]) { 1203 case (long) SIG_ERR: 1204 tprintf("SIG_ERR"); 1205 break; 1206 case (long) SIG_DFL: 1207 tprintf("SIG_DFL"); 1208 break; 1209 case (long) SIG_IGN: 1210 #ifndef USE_PROCFS 1211 if (tcp->u_arg[0] == SIGTRAP) { 1212 tcp->flags |= TCB_SIGTRAPPED; 1213 kill(tcp->pid, SIGSTOP); 1214 } 1215 #endif /* !USE_PROCFS */ 1216 tprintf("SIG_IGN"); 1217 break; 1218 default: 1219 #ifndef USE_PROCFS 1220 if (tcp->u_arg[0] == SIGTRAP) { 1221 tcp->flags |= TCB_SIGTRAPPED; 1222 kill(tcp->pid, SIGSTOP); 1223 } 1224 #endif /* !USE_PROCFS */ 1225 tprintf("%#lx", tcp->u_arg[1]); 1226 } 1227 return 0; 1228 } 1229 else if (!syserror(tcp)) { 1230 switch (tcp->u_rval) { 1231 case (long) SIG_ERR: 1232 tcp->auxstr = "SIG_ERR"; break; 1233 case (long) SIG_DFL: 1234 tcp->auxstr = "SIG_DFL"; break; 1235 case (long) SIG_IGN: 1236 tcp->auxstr = "SIG_IGN"; break; 1237 default: 1238 tcp->auxstr = NULL; 1239 } 1240 return RVAL_HEX | RVAL_STR; 1241 } 1242 return 0; 1243 } 1244 1245 #ifdef SVR4 1246 int 1247 sys_sighold(tcp) 1248 struct tcb *tcp; 1249 { 1250 if (entering(tcp)) { 1251 printsignal(tcp->u_arg[0]); 1252 } 1253 return 0; 1254 } 1255 #endif /* SVR4 */ 1256 1257 #endif /* HAVE_SIGACTION */ 1258 1259 #ifdef LINUX 1260 1261 int 1262 sys_sigreturn(struct tcb *tcp) 1263 { 1264 #if defined(ARM) 1265 struct pt_regs regs; 1266 struct sigcontext_struct sc; 1267 1268 if (entering(tcp)) { 1269 tcp->u_arg[0] = 0; 1270 1271 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)®s) == -1) 1272 return 0; 1273 1274 if (umove(tcp, regs.ARM_sp, &sc) < 0) 1275 return 0; 1276 1277 tcp->u_arg[0] = 1; 1278 tcp->u_arg[1] = sc.oldmask; 1279 } else { 1280 sigset_t sigm; 1281 long_to_sigset(tcp->u_arg[1], &sigm); 1282 tcp->u_rval = tcp->u_error = 0; 1283 if (tcp->u_arg[0] == 0) 1284 return 0; 1285 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0); 1286 return RVAL_NONE | RVAL_STR; 1287 } 1288 return 0; 1289 #elif defined(S390) || defined(S390X) 1290 long usp; 1291 struct sigcontext_struct sc; 1292 1293 if (entering(tcp)) { 1294 tcp->u_arg[0] = 0; 1295 if (upeek(tcp,PT_GPR15,&usp)<0) 1296 return 0; 1297 if (umove(tcp, usp+__SIGNAL_FRAMESIZE, &sc) < 0) 1298 return 0; 1299 tcp->u_arg[0] = 1; 1300 memcpy(&tcp->u_arg[1],&sc.oldmask[0],sizeof(sigset_t)); 1301 } else { 1302 tcp->u_rval = tcp->u_error = 0; 1303 if (tcp->u_arg[0] == 0) 1304 return 0; 1305 tcp->auxstr = sprintsigmask("mask now ",(sigset_t *)&tcp->u_arg[1],0); 1306 return RVAL_NONE | RVAL_STR; 1307 } 1308 return 0; 1309 #elif defined(I386) 1310 long esp; 1311 struct sigcontext_struct sc; 1312 1313 if (entering(tcp)) { 1314 tcp->u_arg[0] = 0; 1315 if (upeek(tcp, 4*UESP, &esp) < 0) 1316 return 0; 1317 if (umove(tcp, esp, &sc) < 0) 1318 return 0; 1319 tcp->u_arg[0] = 1; 1320 tcp->u_arg[1] = sc.oldmask; 1321 } 1322 else { 1323 sigset_t sigm; 1324 long_to_sigset(tcp->u_arg[1], &sigm); 1325 tcp->u_rval = tcp->u_error = 0; 1326 if (tcp->u_arg[0] == 0) 1327 return 0; 1328 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0); 1329 return RVAL_NONE | RVAL_STR; 1330 } 1331 return 0; 1332 #elif defined(IA64) 1333 struct sigcontext sc; 1334 long sp; 1335 1336 if (entering(tcp)) { 1337 /* offset of sigcontext in the kernel's sigframe structure: */ 1338 # define SIGFRAME_SC_OFFSET 0x90 1339 tcp->u_arg[0] = 0; 1340 if (upeek(tcp, PT_R12, &sp) < 0) 1341 return 0; 1342 if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0) 1343 return 0; 1344 tcp->u_arg[0] = 1; 1345 memcpy(tcp->u_arg + 1, &sc.sc_mask, sizeof(sc.sc_mask)); 1346 } 1347 else { 1348 sigset_t sigm; 1349 1350 memcpy(&sigm, tcp->u_arg + 1, sizeof (sigm)); 1351 tcp->u_rval = tcp->u_error = 0; 1352 if (tcp->u_arg[0] == 0) 1353 return 0; 1354 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0); 1355 return RVAL_NONE | RVAL_STR; 1356 } 1357 return 0; 1358 #elif defined(POWERPC) 1359 long esp; 1360 struct sigcontext_struct sc; 1361 1362 if (entering(tcp)) { 1363 tcp->u_arg[0] = 0; 1364 if (upeek(tcp, sizeof(unsigned long)*PT_R1, &esp) < 0) 1365 return 0; 1366 /* Skip dummy stack frame. */ 1367 #ifdef POWERPC64 1368 if (current_personality == 0) 1369 esp += 128; 1370 else 1371 esp += 64; 1372 #else 1373 esp += 64; 1374 #endif 1375 if (umove(tcp, esp, &sc) < 0) 1376 return 0; 1377 tcp->u_arg[0] = 1; 1378 tcp->u_arg[1] = sc.oldmask; 1379 } 1380 else { 1381 sigset_t sigm; 1382 long_to_sigset(tcp->u_arg[1], &sigm); 1383 tcp->u_rval = tcp->u_error = 0; 1384 if (tcp->u_arg[0] == 0) 1385 return 0; 1386 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0); 1387 return RVAL_NONE | RVAL_STR; 1388 } 1389 return 0; 1390 #elif defined(M68K) 1391 long usp; 1392 struct sigcontext sc; 1393 1394 if (entering(tcp)) { 1395 tcp->u_arg[0] = 0; 1396 if (upeek(tcp, 4*PT_USP, &usp) < 0) 1397 return 0; 1398 if (umove(tcp, usp, &sc) < 0) 1399 return 0; 1400 tcp->u_arg[0] = 1; 1401 tcp->u_arg[1] = sc.sc_mask; 1402 } 1403 else { 1404 sigset_t sigm; 1405 long_to_sigset(tcp->u_arg[1], &sigm); 1406 tcp->u_rval = tcp->u_error = 0; 1407 if (tcp->u_arg[0] == 0) 1408 return 0; 1409 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0); 1410 return RVAL_NONE | RVAL_STR; 1411 } 1412 return 0; 1413 #elif defined(ALPHA) 1414 long fp; 1415 struct sigcontext_struct sc; 1416 1417 if (entering(tcp)) { 1418 tcp->u_arg[0] = 0; 1419 if (upeek(tcp, REG_FP, &fp) < 0) 1420 return 0; 1421 if (umove(tcp, fp, &sc) < 0) 1422 return 0; 1423 tcp->u_arg[0] = 1; 1424 tcp->u_arg[1] = sc.sc_mask; 1425 } 1426 else { 1427 sigset_t sigm; 1428 long_to_sigset(tcp->u_arg[1], &sigm); 1429 tcp->u_rval = tcp->u_error = 0; 1430 if (tcp->u_arg[0] == 0) 1431 return 0; 1432 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0); 1433 return RVAL_NONE | RVAL_STR; 1434 } 1435 return 0; 1436 #elif defined (SPARC) || defined (SPARC64) 1437 long i1; 1438 struct pt_regs regs; 1439 m_siginfo_t si; 1440 1441 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)®s, 0) < 0) { 1442 perror("sigreturn: PTRACE_GETREGS "); 1443 return 0; 1444 } 1445 if(entering(tcp)) { 1446 tcp->u_arg[0] = 0; 1447 i1 = regs.u_regs[U_REG_O1]; 1448 if(umove(tcp, i1, &si) < 0) { 1449 perror("sigreturn: umove "); 1450 return 0; 1451 } 1452 tcp->u_arg[0] = 1; 1453 tcp->u_arg[1] = si.si_mask; 1454 } else { 1455 sigset_t sigm; 1456 long_to_sigset(tcp->u_arg[1], &sigm); 1457 tcp->u_rval = tcp->u_error = 0; 1458 if(tcp->u_arg[0] == 0) 1459 return 0; 1460 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0); 1461 return RVAL_NONE | RVAL_STR; 1462 } 1463 return 0; 1464 #elif defined (LINUX_MIPSN32) || defined (LINUX_MIPSN64) 1465 /* This decodes rt_sigreturn. The 64-bit ABIs do not have 1466 sigreturn. */ 1467 long sp; 1468 struct ucontext uc; 1469 1470 if(entering(tcp)) { 1471 tcp->u_arg[0] = 0; 1472 if (upeek(tcp, REG_SP, &sp) < 0) 1473 return 0; 1474 /* There are six words followed by a 128-byte siginfo. */ 1475 sp = sp + 6 * 4 + 128; 1476 if (umove(tcp, sp, &uc) < 0) 1477 return 0; 1478 tcp->u_arg[0] = 1; 1479 tcp->u_arg[1] = *(long *) &uc.uc_sigmask; 1480 } else { 1481 sigset_t sigm; 1482 long_to_sigset(tcp->u_arg[1], &sigm); 1483 tcp->u_rval = tcp->u_error = 0; 1484 if(tcp->u_arg[0] == 0) 1485 return 0; 1486 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0); 1487 return RVAL_NONE | RVAL_STR; 1488 } 1489 return 0; 1490 #elif defined(MIPS) 1491 long sp; 1492 struct pt_regs regs; 1493 m_siginfo_t si; 1494 1495 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)®s, 0) < 0) { 1496 perror("sigreturn: PTRACE_GETREGS "); 1497 return 0; 1498 } 1499 if(entering(tcp)) { 1500 tcp->u_arg[0] = 0; 1501 sp = regs.regs[29]; 1502 if (umove(tcp, sp, &si) < 0) 1503 return 0; 1504 tcp->u_arg[0] = 1; 1505 tcp->u_arg[1] = si.si_mask; 1506 } else { 1507 sigset_t sigm; 1508 long_to_sigset(tcp->u_arg[1], &sigm); 1509 tcp->u_rval = tcp->u_error = 0; 1510 if(tcp->u_arg[0] == 0) 1511 return 0; 1512 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0); 1513 return RVAL_NONE | RVAL_STR; 1514 } 1515 return 0; 1516 #elif defined(CRISV10) || defined(CRISV32) 1517 struct sigcontext sc; 1518 1519 if (entering(tcp)) { 1520 long regs[PT_MAX+1]; 1521 1522 tcp->u_arg[0] = 0; 1523 1524 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) { 1525 perror("sigreturn: PTRACE_GETREGS"); 1526 return 0; 1527 } 1528 if (umove(tcp, regs[PT_USP], &sc) < 0) 1529 return 0; 1530 tcp->u_arg[0] = 1; 1531 tcp->u_arg[1] = sc.oldmask; 1532 } else { 1533 sigset_t sigm; 1534 long_to_sigset(tcp->u_arg[1], &sigm); 1535 tcp->u_rval = tcp->u_error = 0; 1536 1537 if (tcp->u_arg[0] == 0) 1538 return 0; 1539 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0); 1540 return RVAL_NONE | RVAL_STR; 1541 } 1542 return 0; 1543 #elif defined(TILE) 1544 struct ucontext uc; 1545 long sp; 1546 1547 /* offset of ucontext in the kernel's sigframe structure */ 1548 # define SIGFRAME_UC_OFFSET C_ABI_SAVE_AREA_SIZE + sizeof(struct siginfo) 1549 1550 if (entering(tcp)) { 1551 tcp->u_arg[0] = 0; 1552 if (upeek(tcp, PTREGS_OFFSET_SP, &sp) < 0) 1553 return 0; 1554 if (umove(tcp, sp + SIGFRAME_UC_OFFSET, &uc) < 0) 1555 return 0; 1556 tcp->u_arg[0] = 1; 1557 memcpy(tcp->u_arg + 1, &uc.uc_sigmask, sizeof(uc.uc_sigmask)); 1558 } 1559 else { 1560 sigset_t sigm; 1561 1562 memcpy(&sigm, tcp->u_arg + 1, sizeof (sigm)); 1563 tcp->u_rval = tcp->u_error = 0; 1564 if (tcp->u_arg[0] == 0) 1565 return 0; 1566 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0); 1567 return RVAL_NONE | RVAL_STR; 1568 } 1569 return 0; 1570 #elif defined(MICROBLAZE) 1571 struct sigcontext sc; 1572 1573 /* TODO: Verify that this is correct... */ 1574 if (entering(tcp)) { 1575 long sp; 1576 1577 tcp->u_arg[0] = 0; 1578 1579 /* Read r1, the stack pointer. */ 1580 if (upeek(tcp, 1 * 4, &sp) < 0) 1581 return 0; 1582 if (umove(tcp, sp, &sc) < 0) 1583 return 0; 1584 tcp->u_arg[0] = 1; 1585 tcp->u_arg[1] = sc.oldmask; 1586 } else { 1587 sigset_t sigm; 1588 long_to_sigset(tcp->u_arg[1], &sigm); 1589 tcp->u_rval = tcp->u_error = 0; 1590 if (tcp->u_arg[0] == 0) 1591 return 0; 1592 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0); 1593 return RVAL_NONE | RVAL_STR; 1594 } 1595 return 0; 1596 #else 1597 #warning No sys_sigreturn() for this architecture 1598 #warning (no problem, just a reminder :-) 1599 return 0; 1600 #endif 1601 } 1602 1603 int 1604 sys_siggetmask(tcp) 1605 struct tcb *tcp; 1606 { 1607 if (exiting(tcp)) { 1608 sigset_t sigm; 1609 long_to_sigset(tcp->u_rval, &sigm); 1610 tcp->auxstr = sprintsigmask("mask ", &sigm, 0); 1611 } 1612 return RVAL_HEX | RVAL_STR; 1613 } 1614 1615 int 1616 sys_sigsuspend(struct tcb *tcp) 1617 { 1618 if (entering(tcp)) { 1619 sigset_t sigm; 1620 long_to_sigset(tcp->u_arg[2], &sigm); 1621 printsigmask(&sigm, 0); 1622 } 1623 return 0; 1624 } 1625 1626 #endif /* LINUX */ 1627 1628 #if defined(SVR4) || defined(FREEBSD) 1629 1630 int 1631 sys_sigsuspend(tcp) 1632 struct tcb *tcp; 1633 { 1634 sigset_t sigset; 1635 1636 if (entering(tcp)) { 1637 if (umove(tcp, tcp->u_arg[0], &sigset) < 0) 1638 tprintf("[?]"); 1639 else 1640 printsigmask(&sigset, 0); 1641 } 1642 return 0; 1643 } 1644 #ifndef FREEBSD 1645 static const struct xlat ucontext_flags[] = { 1646 { UC_SIGMASK, "UC_SIGMASK" }, 1647 { UC_STACK, "UC_STACK" }, 1648 { UC_CPU, "UC_CPU" }, 1649 #ifdef UC_FPU 1650 { UC_FPU, "UC_FPU" }, 1651 #endif 1652 #ifdef UC_INTR 1653 { UC_INTR, "UC_INTR" }, 1654 #endif 1655 { 0, NULL }, 1656 }; 1657 #endif /* !FREEBSD */ 1658 #endif /* SVR4 || FREEBSD */ 1659 1660 #if defined SVR4 || defined LINUX || defined FREEBSD 1661 #if defined LINUX && !defined SS_ONSTACK 1662 #define SS_ONSTACK 1 1663 #define SS_DISABLE 2 1664 #if __GLIBC_MINOR__ == 0 1665 typedef struct 1666 { 1667 __ptr_t ss_sp; 1668 int ss_flags; 1669 size_t ss_size; 1670 } stack_t; 1671 #endif 1672 #endif 1673 #ifdef FREEBSD 1674 #define stack_t struct sigaltstack 1675 #endif 1676 1677 static const struct xlat sigaltstack_flags[] = { 1678 { SS_ONSTACK, "SS_ONSTACK" }, 1679 { SS_DISABLE, "SS_DISABLE" }, 1680 { 0, NULL }, 1681 }; 1682 #endif 1683 1684 #ifdef SVR4 1685 static void 1686 printcontext(tcp, ucp) 1687 struct tcb *tcp; 1688 ucontext_t *ucp; 1689 { 1690 tprintf("{"); 1691 if (!abbrev(tcp)) { 1692 tprintf("uc_flags="); 1693 printflags(ucontext_flags, ucp->uc_flags, "UC_???"); 1694 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link); 1695 } 1696 tprintf("uc_sigmask="); 1697 printsigmask(&ucp->uc_sigmask, 0); 1698 if (!abbrev(tcp)) { 1699 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=", 1700 (unsigned long) ucp->uc_stack.ss_sp, 1701 ucp->uc_stack.ss_size); 1702 printflags(sigaltstack_flags, ucp->uc_stack.ss_flags, "SS_???"); 1703 tprintf("}"); 1704 } 1705 tprintf(", ...}"); 1706 } 1707 1708 int 1709 sys_getcontext(tcp) 1710 struct tcb *tcp; 1711 { 1712 ucontext_t uc; 1713 1714 if (exiting(tcp)) { 1715 if (tcp->u_error) 1716 tprintf("%#lx", tcp->u_arg[0]); 1717 else if (!tcp->u_arg[0]) 1718 tprintf("NULL"); 1719 else if (umove(tcp, tcp->u_arg[0], &uc) < 0) 1720 tprintf("{...}"); 1721 else 1722 printcontext(tcp, &uc); 1723 } 1724 return 0; 1725 } 1726 1727 int 1728 sys_setcontext(tcp) 1729 struct tcb *tcp; 1730 { 1731 ucontext_t uc; 1732 1733 if (entering(tcp)) { 1734 if (!tcp->u_arg[0]) 1735 tprintf("NULL"); 1736 else if (umove(tcp, tcp->u_arg[0], &uc) < 0) 1737 tprintf("{...}"); 1738 else 1739 printcontext(tcp, &uc); 1740 } 1741 else { 1742 tcp->u_rval = tcp->u_error = 0; 1743 if (tcp->u_arg[0] == 0) 1744 return 0; 1745 return RVAL_NONE; 1746 } 1747 return 0; 1748 } 1749 1750 #endif /* SVR4 */ 1751 1752 #if defined(LINUX) || defined(FREEBSD) 1753 1754 static int 1755 print_stack_t(tcp, addr) 1756 struct tcb *tcp; 1757 unsigned long addr; 1758 { 1759 stack_t ss; 1760 if (umove(tcp, addr, &ss) < 0) 1761 return -1; 1762 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp); 1763 printflags(sigaltstack_flags, ss.ss_flags, "SS_???"); 1764 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size); 1765 return 0; 1766 } 1767 1768 int 1769 sys_sigaltstack(tcp) 1770 struct tcb *tcp; 1771 { 1772 if (entering(tcp)) { 1773 if (tcp->u_arg[0] == 0) 1774 tprintf("NULL"); 1775 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0) 1776 return -1; 1777 } 1778 else { 1779 tprintf(", "); 1780 if (tcp->u_arg[1] == 0) 1781 tprintf("NULL"); 1782 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0) 1783 return -1; 1784 } 1785 return 0; 1786 } 1787 #endif 1788 1789 #ifdef HAVE_SIGACTION 1790 1791 int 1792 sys_sigprocmask(tcp) 1793 struct tcb *tcp; 1794 { 1795 #ifdef ALPHA 1796 if (entering(tcp)) { 1797 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???"); 1798 tprintf(", "); 1799 printsigmask(tcp->u_arg[1], 0); 1800 } 1801 else if (!syserror(tcp)) { 1802 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0); 1803 return RVAL_HEX | RVAL_STR; 1804 } 1805 #else /* !ALPHA */ 1806 if (entering(tcp)) { 1807 #ifdef SVR4 1808 if (tcp->u_arg[0] == 0) 1809 tprintf("0"); 1810 else 1811 #endif /* SVR4 */ 1812 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???"); 1813 tprintf(", "); 1814 print_sigset(tcp, tcp->u_arg[1], 0); 1815 tprintf(", "); 1816 } 1817 else { 1818 if (!tcp->u_arg[2]) 1819 tprintf("NULL"); 1820 else if (syserror(tcp)) 1821 tprintf("%#lx", tcp->u_arg[2]); 1822 else 1823 print_sigset(tcp, tcp->u_arg[2], 0); 1824 } 1825 #endif /* !ALPHA */ 1826 return 0; 1827 } 1828 1829 #endif /* HAVE_SIGACTION */ 1830 1831 int 1832 sys_kill(tcp) 1833 struct tcb *tcp; 1834 { 1835 if (entering(tcp)) { 1836 /* 1837 * Sign-extend a 32-bit value when that's what it is. 1838 */ 1839 long pid = tcp->u_arg[0]; 1840 if (personality_wordsize[current_personality] < sizeof pid) 1841 pid = (long) (int) pid; 1842 tprintf("%ld, %s", pid, signame(tcp->u_arg[1])); 1843 } 1844 return 0; 1845 } 1846 1847 #if defined(FREEBSD) || defined(SUNOS4) 1848 int 1849 sys_killpg(tcp) 1850 struct tcb *tcp; 1851 { 1852 return sys_kill(tcp); 1853 } 1854 #endif /* FREEBSD || SUNOS4 */ 1855 1856 #ifdef LINUX 1857 int 1858 sys_tgkill(tcp) 1859 struct tcb *tcp; 1860 { 1861 if (entering(tcp)) { 1862 tprintf("%ld, %ld, %s", 1863 tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2])); 1864 } 1865 return 0; 1866 } 1867 #endif 1868 1869 int 1870 sys_sigpending(tcp) 1871 struct tcb *tcp; 1872 { 1873 sigset_t sigset; 1874 1875 if (exiting(tcp)) { 1876 if (syserror(tcp)) 1877 tprintf("%#lx", tcp->u_arg[0]); 1878 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0) 1879 tprintf("[?]"); 1880 else 1881 printsigmask(&sigset, 0); 1882 } 1883 return 0; 1884 } 1885 1886 #ifdef SVR4 1887 int sys_sigwait(tcp) 1888 struct tcb *tcp; 1889 { 1890 sigset_t sigset; 1891 1892 if (entering(tcp)) { 1893 if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0) 1894 tprintf("[?]"); 1895 else 1896 printsigmask(&sigset, 0); 1897 } 1898 else { 1899 if (!syserror(tcp)) { 1900 tcp->auxstr = signalent[tcp->u_rval]; 1901 return RVAL_DECIMAL | RVAL_STR; 1902 } 1903 } 1904 return 0; 1905 } 1906 #endif /* SVR4 */ 1907 1908 #ifdef LINUX 1909 1910 int 1911 sys_rt_sigprocmask(tcp) 1912 struct tcb *tcp; 1913 { 1914 sigset_t sigset; 1915 1916 /* Note: arg[3] is the length of the sigset. */ 1917 if (entering(tcp)) { 1918 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???"); 1919 tprintf(", "); 1920 if (!tcp->u_arg[1]) 1921 tprintf("NULL, "); 1922 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0) 1923 tprintf("%#lx, ", tcp->u_arg[1]); 1924 else { 1925 printsigmask(&sigset, 1); 1926 tprintf(", "); 1927 } 1928 } 1929 else { 1930 if (!tcp->u_arg[2]) 1931 1932 tprintf("NULL"); 1933 else if (syserror(tcp)) 1934 tprintf("%#lx", tcp->u_arg[2]); 1935 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0) 1936 tprintf("[?]"); 1937 else 1938 printsigmask(&sigset, 1); 1939 tprintf(", %lu", tcp->u_arg[3]); 1940 } 1941 return 0; 1942 } 1943 1944 1945 /* Structure describing the action to be taken when a signal arrives. */ 1946 struct new_sigaction 1947 { 1948 __sighandler_t __sa_handler; 1949 unsigned long sa_flags; 1950 void (*sa_restorer) (void); 1951 /* Kernel treats sa_mask as an array of longs. */ 1952 unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1]; 1953 }; 1954 /* Same for i386-on-x86_64 and similar cases */ 1955 struct new_sigaction32 1956 { 1957 uint32_t __sa_handler; 1958 uint32_t sa_flags; 1959 uint32_t sa_restorer; 1960 uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)]; 1961 }; 1962 1963 1964 int 1965 sys_rt_sigaction(struct tcb *tcp) 1966 { 1967 struct new_sigaction sa; 1968 sigset_t sigset; 1969 long addr; 1970 int r; 1971 1972 if (entering(tcp)) { 1973 printsignal(tcp->u_arg[0]); 1974 tprintf(", "); 1975 addr = tcp->u_arg[1]; 1976 } else 1977 addr = tcp->u_arg[2]; 1978 1979 if (addr == 0) { 1980 tprintf("NULL"); 1981 goto after_sa; 1982 } 1983 if (!verbose(tcp)) { 1984 tprintf("%#lx", addr); 1985 goto after_sa; 1986 } 1987 #if SUPPORTED_PERSONALITIES > 1 1988 if (personality_wordsize[current_personality] != sizeof(sa.sa_flags) 1989 && personality_wordsize[current_personality] == 4 1990 ) { 1991 struct new_sigaction32 sa32; 1992 r = umove(tcp, addr, &sa32); 1993 if (r >= 0) { 1994 memset(&sa, 0, sizeof(sa)); 1995 sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler; 1996 sa.sa_flags = sa32.sa_flags; 1997 sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer; 1998 /* Kernel treats sa_mask as an array of longs. 1999 * For 32-bit process, "long" is uint32_t, thus, for example, 2000 * 32th bit in sa_mask will end up as bit 0 in sa_mask[1]. 2001 * But for (64-bit) kernel, 32th bit in sa_mask is 2002 * 32th bit in 0th (64-bit) long! 2003 * For little-endian, it's the same. 2004 * For big-endian, we swap 32-bit words. 2005 */ 2006 sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32); 2007 } 2008 } else 2009 #endif 2010 { 2011 r = umove(tcp, addr, &sa); 2012 } 2013 if (r < 0) { 2014 tprintf("{...}"); 2015 goto after_sa; 2016 } 2017 /* Architectures using function pointers, like 2018 * hppa, may need to manipulate the function pointer 2019 * to compute the result of a comparison. However, 2020 * the SA_HANDLER function pointer exists only in 2021 * the address space of the traced process, and can't 2022 * be manipulated by strace. In order to prevent the 2023 * compiler from generating code to manipulate 2024 * SA_HANDLER we cast the function pointers to long. */ 2025 if ((long)sa.__sa_handler == (long)SIG_ERR) 2026 tprintf("{SIG_ERR, "); 2027 else if ((long)sa.__sa_handler == (long)SIG_DFL) 2028 tprintf("{SIG_DFL, "); 2029 else if ((long)sa.__sa_handler == (long)SIG_IGN) 2030 tprintf("{SIG_IGN, "); 2031 else 2032 tprintf("{%#lx, ", (long) sa.__sa_handler); 2033 /* Questionable code below. 2034 * Kernel won't handle sys_rt_sigaction 2035 * with wrong sigset size (just returns EINVAL) 2036 * therefore tcp->u_arg[3(4)] _must_ be NSIG / 8 here, 2037 * and we always use smaller memcpy. */ 2038 sigemptyset(&sigset); 2039 #ifdef LINUXSPARC 2040 if (tcp->u_arg[4] <= sizeof(sigset)) 2041 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[4]); 2042 #else 2043 if (tcp->u_arg[3] <= sizeof(sigset)) 2044 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]); 2045 #endif 2046 else 2047 memcpy(&sigset, &sa.sa_mask, sizeof(sigset)); 2048 printsigmask(&sigset, 1); 2049 tprintf(", "); 2050 printflags(sigact_flags, sa.sa_flags, "SA_???"); 2051 #ifdef SA_RESTORER 2052 if (sa.sa_flags & SA_RESTORER) 2053 tprintf(", %p", sa.sa_restorer); 2054 #endif 2055 tprintf("}"); 2056 2057 after_sa: 2058 if (entering(tcp)) 2059 tprintf(", "); 2060 else 2061 #ifdef LINUXSPARC 2062 tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]); 2063 #elif defined(ALPHA) 2064 tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]); 2065 #else 2066 tprintf(", %lu", tcp->u_arg[3]); 2067 #endif 2068 return 0; 2069 } 2070 2071 int 2072 sys_rt_sigpending(struct tcb *tcp) 2073 { 2074 sigset_t sigset; 2075 2076 if (exiting(tcp)) { 2077 if (syserror(tcp)) 2078 tprintf("%#lx", tcp->u_arg[0]); 2079 else if (copy_sigset_len(tcp, tcp->u_arg[0], 2080 &sigset, tcp->u_arg[1]) < 0) 2081 tprintf("[?]"); 2082 else 2083 printsigmask(&sigset, 1); 2084 } 2085 return 0; 2086 } 2087 2088 int 2089 sys_rt_sigsuspend(struct tcb *tcp) 2090 { 2091 if (entering(tcp)) { 2092 sigset_t sigm; 2093 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0) 2094 tprintf("[?]"); 2095 else 2096 printsigmask(&sigm, 1); 2097 } 2098 return 0; 2099 } 2100 2101 int 2102 sys_rt_sigqueueinfo(struct tcb *tcp) 2103 { 2104 if (entering(tcp)) { 2105 siginfo_t si; 2106 tprintf("%lu, ", tcp->u_arg[0]); 2107 printsignal(tcp->u_arg[1]); 2108 tprintf(", "); 2109 if (umove(tcp, tcp->u_arg[2], &si) < 0) 2110 tprintf("%#lx", tcp->u_arg[2]); 2111 else 2112 printsiginfo(&si, verbose(tcp)); 2113 } 2114 return 0; 2115 } 2116 2117 int sys_rt_sigtimedwait(struct tcb *tcp) 2118 { 2119 if (entering(tcp)) { 2120 sigset_t sigset; 2121 2122 if (copy_sigset_len(tcp, tcp->u_arg[0], 2123 &sigset, tcp->u_arg[3]) < 0) 2124 tprintf("[?]"); 2125 else 2126 printsigmask(&sigset, 1); 2127 tprintf(", "); 2128 /* This is the only "return" parameter, */ 2129 if (tcp->u_arg[1] != 0) 2130 return 0; 2131 /* ... if it's NULL, can decode all on entry */ 2132 tprintf("NULL, "); 2133 } 2134 else if (tcp->u_arg[1] != 0) { 2135 /* syscall exit, and u_arg[1] wasn't NULL */ 2136 if (syserror(tcp)) 2137 tprintf("%#lx, ", tcp->u_arg[1]); 2138 else { 2139 siginfo_t si; 2140 if (umove(tcp, tcp->u_arg[1], &si) < 0) 2141 tprintf("%#lx, ", tcp->u_arg[1]); 2142 else { 2143 printsiginfo(&si, verbose(tcp)); 2144 tprintf(", "); 2145 } 2146 } 2147 } 2148 else { 2149 /* syscall exit, and u_arg[1] was NULL */ 2150 return 0; 2151 } 2152 print_timespec(tcp, tcp->u_arg[2]); 2153 tprintf(", %d", (int) tcp->u_arg[3]); 2154 return 0; 2155 }; 2156 2157 int 2158 sys_restart_syscall(struct tcb *tcp) 2159 { 2160 if (entering(tcp)) 2161 tprintf("<... resuming interrupted call ...>"); 2162 return 0; 2163 } 2164 2165 static int 2166 do_signalfd(struct tcb *tcp, int flags_arg) 2167 { 2168 if (entering(tcp)) { 2169 printfd(tcp, tcp->u_arg[0]); 2170 tprintf(", "); 2171 print_sigset(tcp, tcp->u_arg[1], 1); 2172 tprintf(", %lu", tcp->u_arg[2]); 2173 if (flags_arg >= 0) { 2174 tprintf(", "); 2175 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???"); 2176 } 2177 } 2178 return 0; 2179 } 2180 2181 int 2182 sys_signalfd(struct tcb *tcp) 2183 { 2184 return do_signalfd(tcp, -1); 2185 } 2186 2187 int 2188 sys_signalfd4(struct tcb *tcp) 2189 { 2190 return do_signalfd(tcp, 3); 2191 } 2192 #endif /* LINUX */ 2193