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