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