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