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