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. |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 32 | */ |
| 33 | |
| 34 | #include "defs.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 35 | #include <sys/user.h> |
| 36 | #include <fcntl.h> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 37 | |
Wichert Akkerman | 36915a1 | 1999-07-13 15:45:02 +0000 | [diff] [blame] | 38 | #ifdef HAVE_SYS_REG_H |
| 39 | # include <sys/reg.h> |
Wichert Akkerman | faf7222 | 2000-02-19 23:59:03 +0000 | [diff] [blame] | 40 | #elif defined(HAVE_LINUX_PTRACE_H) |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 41 | # undef PTRACE_SYSCALL |
Roland McGrath | b0acdfd | 2004-03-01 21:31:02 +0000 | [diff] [blame] | 42 | # ifdef HAVE_STRUCT_IA64_FPREG |
| 43 | # define ia64_fpreg XXX_ia64_fpreg |
| 44 | # endif |
| 45 | # ifdef HAVE_STRUCT_PT_ALL_USER_REGS |
| 46 | # define pt_all_user_regs XXX_pt_all_user_regs |
| 47 | # endif |
Ali Polatel | 0b4060f | 2013-09-24 20:04:32 +0300 | [diff] [blame] | 48 | # ifdef HAVE_STRUCT_PTRACE_PEEKSIGINFO_ARGS |
| 49 | # define ptrace_peeksiginfo_args XXX_ptrace_peeksiginfo_args |
| 50 | # endif |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 51 | # include <linux/ptrace.h> |
Ali Polatel | 0b4060f | 2013-09-24 20:04:32 +0300 | [diff] [blame] | 52 | # undef ptrace_peeksiginfo_args |
Roland McGrath | b0acdfd | 2004-03-01 21:31:02 +0000 | [diff] [blame] | 53 | # undef ia64_fpreg |
| 54 | # undef pt_all_user_regs |
Wichert Akkerman | 15dea97 | 1999-10-06 13:06:34 +0000 | [diff] [blame] | 55 | #endif |
Wichert Akkerman | 36915a1 | 1999-07-13 15:45:02 +0000 | [diff] [blame] | 56 | |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame] | 57 | #ifdef IA64 |
| 58 | # include <asm/ptrace_offsets.h> |
Denys Vlasenko | 041b3ee | 2011-08-18 12:48:56 +0200 | [diff] [blame] | 59 | #endif |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame] | 60 | |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 61 | #if defined(SPARC) || defined(SPARC64) || defined(MIPS) |
Roland McGrath | 576b784 | 2007-11-04 00:00:00 +0000 | [diff] [blame] | 62 | typedef struct { |
| 63 | struct pt_regs si_regs; |
| 64 | int si_mask; |
| 65 | } m_siginfo_t; |
Roland McGrath | 30ff45e | 2003-01-30 20:15:23 +0000 | [diff] [blame] | 66 | #elif defined HAVE_ASM_SIGCONTEXT_H |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 67 | # if !defined(IA64) && !defined(X86_64) && !defined(X32) |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 68 | # include <asm/sigcontext.h> |
Denys Vlasenko | a6d91de | 2012-03-16 12:02:22 +0100 | [diff] [blame] | 69 | # endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 70 | #else /* !HAVE_ASM_SIGCONTEXT_H */ |
Denys Vlasenko | b51f364 | 2013-07-16 12:06:25 +0200 | [diff] [blame] | 71 | # if defined M68K && !defined HAVE_STRUCT_SIGCONTEXT |
| 72 | struct sigcontext { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 73 | unsigned long sc_mask; |
| 74 | unsigned long sc_usp; |
| 75 | unsigned long sc_d0; |
| 76 | unsigned long sc_d1; |
| 77 | unsigned long sc_a0; |
| 78 | unsigned long sc_a1; |
| 79 | unsigned short sc_sr; |
| 80 | unsigned long sc_pc; |
| 81 | unsigned short sc_formatvec; |
| 82 | }; |
Denys Vlasenko | b51f364 | 2013-07-16 12:06:25 +0200 | [diff] [blame] | 83 | # endif /* M68K */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 84 | #endif /* !HAVE_ASM_SIGCONTEXT_H */ |
Denys Vlasenko | 041b3ee | 2011-08-18 12:48:56 +0200 | [diff] [blame] | 85 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 86 | #ifndef NSIG |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 87 | # warning: NSIG is not defined, using 32 |
| 88 | # define NSIG 32 |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 89 | #elif NSIG < 32 |
| 90 | # error: NSIG < 32 |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 91 | #endif |
Denys Vlasenko | 041b3ee | 2011-08-18 12:48:56 +0200 | [diff] [blame] | 92 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 93 | #ifdef HAVE_SIGACTION |
| 94 | |
Roland McGrath | 2638cb4 | 2002-12-15 23:58:41 +0000 | [diff] [blame] | 95 | /* 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] | 96 | used by the implementation. So we define it here. */ |
Dmitry V. Levin | 5c7f627 | 2014-02-08 00:26:06 +0000 | [diff] [blame] | 97 | #ifndef SA_RESTORER |
| 98 | # ifdef ASM_SA_RESTORER |
| 99 | # define SA_RESTORER ASM_SA_RESTORER |
Roland McGrath | 2638cb4 | 2002-12-15 23:58:41 +0000 | [diff] [blame] | 100 | # endif |
| 101 | #endif |
| 102 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 103 | static const struct xlat sigact_flags[] = { |
Wichert Akkerman | c792698 | 2000-04-10 22:22:31 +0000 | [diff] [blame] | 104 | #ifdef SA_RESTORER |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 105 | XLAT(SA_RESTORER), |
Wichert Akkerman | c792698 | 2000-04-10 22:22:31 +0000 | [diff] [blame] | 106 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 107 | #ifdef SA_STACK |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 108 | XLAT(SA_STACK), |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 109 | #endif |
| 110 | #ifdef SA_RESTART |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 111 | XLAT(SA_RESTART), |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 112 | #endif |
| 113 | #ifdef SA_INTERRUPT |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 114 | XLAT(SA_INTERRUPT), |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 115 | #endif |
Roland McGrath | 4fef51d | 2008-07-18 01:02:41 +0000 | [diff] [blame] | 116 | #ifdef SA_NODEFER |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 117 | XLAT(SA_NODEFER), |
Roland McGrath | 4fef51d | 2008-07-18 01:02:41 +0000 | [diff] [blame] | 118 | #endif |
| 119 | #if defined SA_NOMASK && SA_NODEFER != SA_NOMASK |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 120 | XLAT(SA_NOMASK), |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 121 | #endif |
Roland McGrath | 4fef51d | 2008-07-18 01:02:41 +0000 | [diff] [blame] | 122 | #ifdef SA_RESETHAND |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 123 | XLAT(SA_RESETHAND), |
Roland McGrath | 4fef51d | 2008-07-18 01:02:41 +0000 | [diff] [blame] | 124 | #endif |
| 125 | #if defined SA_ONESHOT && SA_ONESHOT != SA_RESETHAND |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 126 | XLAT(SA_ONESHOT), |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 127 | #endif |
| 128 | #ifdef SA_SIGINFO |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 129 | XLAT(SA_SIGINFO), |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 130 | #endif |
| 131 | #ifdef SA_RESETHAND |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 132 | XLAT(SA_RESETHAND), |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 133 | #endif |
| 134 | #ifdef SA_ONSTACK |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 135 | XLAT(SA_ONSTACK), |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 136 | #endif |
| 137 | #ifdef SA_NODEFER |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 138 | XLAT(SA_NODEFER), |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 139 | #endif |
| 140 | #ifdef SA_NOCLDSTOP |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 141 | XLAT(SA_NOCLDSTOP), |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 142 | #endif |
| 143 | #ifdef SA_NOCLDWAIT |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 144 | XLAT(SA_NOCLDWAIT), |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 145 | #endif |
| 146 | #ifdef _SA_BSDCALL |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 147 | XLAT(_SA_BSDCALL), |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 148 | #endif |
Chris Metcalf | c8c6698 | 2009-12-28 10:00:15 -0500 | [diff] [blame] | 149 | #ifdef SA_NOPTRACE |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 150 | XLAT(SA_NOPTRACE), |
Chris Metcalf | c8c6698 | 2009-12-28 10:00:15 -0500 | [diff] [blame] | 151 | #endif |
Dmitry V. Levin | 5945273 | 2014-02-05 02:20:51 +0000 | [diff] [blame] | 152 | XLAT_END |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 153 | }; |
| 154 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 155 | static const struct xlat sigprocmaskcmds[] = { |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 156 | XLAT(SIG_BLOCK), |
| 157 | XLAT(SIG_UNBLOCK), |
| 158 | XLAT(SIG_SETMASK), |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 159 | #ifdef SIG_SETMASK32 |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 160 | XLAT(SIG_SETMASK32), |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 161 | #endif |
Dmitry V. Levin | 5945273 | 2014-02-05 02:20:51 +0000 | [diff] [blame] | 162 | XLAT_END |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 163 | }; |
| 164 | |
| 165 | #endif /* HAVE_SIGACTION */ |
| 166 | |
Nate Sammons | ce780fc | 1999-03-29 23:23:13 +0000 | [diff] [blame] | 167 | /* Anonymous realtime signals. */ |
| 168 | /* Under glibc 2.1, SIGRTMIN et al are functions, but __SIGRTMIN is a |
| 169 | constant. This is what we want. Otherwise, just use SIGRTMIN. */ |
| 170 | #ifdef SIGRTMIN |
| 171 | #ifndef __SIGRTMIN |
| 172 | #define __SIGRTMIN SIGRTMIN |
| 173 | #define __SIGRTMAX SIGRTMAX /* likewise */ |
| 174 | #endif |
| 175 | #endif |
| 176 | |
Denys Vlasenko | d9560c1 | 2011-08-19 17:41:28 +0200 | [diff] [blame] | 177 | /* Note on the size of sigset_t: |
| 178 | * |
| 179 | * In glibc, sigset_t is an array with space for 1024 bits (!), |
| 180 | * even though all arches supported by Linux have only 64 signals |
| 181 | * except MIPS, which has 128. IOW, it is 128 bytes long. |
| 182 | * |
| 183 | * In-kernel sigset_t is sized correctly (it is either 64 or 128 bit long). |
| 184 | * However, some old syscall return only 32 lower bits (one word). |
| 185 | * Example: sys_sigpending vs sys_rt_sigpending. |
| 186 | * |
| 187 | * Be aware of this fact when you try to |
| 188 | * memcpy(&tcp->u_arg[1], &something, sizeof(sigset_t)) |
| 189 | * - sizeof(sigset_t) is much bigger than you think, |
| 190 | * it may overflow tcp->u_arg[] array, and it may try to copy more data |
| 191 | * than is really available in <something>. |
| 192 | * Similarly, |
| 193 | * umoven(tcp, addr, sizeof(sigset_t), &sigset) |
| 194 | * may be a bad idea: it'll try to read much more data than needed |
| 195 | * to fetch a sigset_t. |
| 196 | * Use (NSIG / 8) as a size instead. |
| 197 | */ |
| 198 | |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 199 | const char * |
Denys Vlasenko | eccc48c | 2011-06-09 01:28:11 +0200 | [diff] [blame] | 200 | signame(int sig) |
Nate Sammons | ce780fc | 1999-03-29 23:23:13 +0000 | [diff] [blame] | 201 | { |
Denys Vlasenko | 041b3ee | 2011-08-18 12:48:56 +0200 | [diff] [blame] | 202 | static char buf[sizeof("SIGRT_%d") + sizeof(int)*3]; |
| 203 | |
| 204 | if (sig >= 0 && sig < nsignals) |
Nate Sammons | ce780fc | 1999-03-29 23:23:13 +0000 | [diff] [blame] | 205 | return signalent[sig]; |
| 206 | #ifdef SIGRTMIN |
Denys Vlasenko | 041b3ee | 2011-08-18 12:48:56 +0200 | [diff] [blame] | 207 | if (sig >= __SIGRTMIN && sig <= __SIGRTMAX) { |
| 208 | sprintf(buf, "SIGRT_%d", (int)(sig - __SIGRTMIN)); |
Nate Sammons | ce780fc | 1999-03-29 23:23:13 +0000 | [diff] [blame] | 209 | return buf; |
| 210 | } |
Denys Vlasenko | 041b3ee | 2011-08-18 12:48:56 +0200 | [diff] [blame] | 211 | #endif |
| 212 | sprintf(buf, "%d", sig); |
| 213 | return buf; |
Nate Sammons | ce780fc | 1999-03-29 23:23:13 +0000 | [diff] [blame] | 214 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 215 | |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 216 | static unsigned int |
| 217 | popcount32(const uint32_t *a, unsigned int size) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 218 | { |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 219 | unsigned int count = 0; |
Denys Vlasenko | d9560c1 | 2011-08-19 17:41:28 +0200 | [diff] [blame] | 220 | |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 221 | for (; size; ++a, --size) { |
| 222 | uint32_t x = *a; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 223 | |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 224 | #ifdef HAVE___BUILTIN_POPCOUNT |
| 225 | count += __builtin_popcount(x); |
Denys Vlasenko | a877379 | 2013-07-18 20:42:41 +0200 | [diff] [blame] | 226 | #else |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 227 | for (; x; ++count) |
| 228 | x &= x - 1; |
Nate Sammons | 4a12143 | 1999-04-06 01:19:39 +0000 | [diff] [blame] | 229 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 230 | } |
Denys Vlasenko | 4f3df07 | 2012-01-29 22:38:35 +0100 | [diff] [blame] | 231 | |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 232 | return count; |
| 233 | } |
| 234 | |
| 235 | static const char * |
| 236 | sprintsigmask_n(const char *prefix, const void *sig_mask, unsigned int bytes) |
| 237 | { |
| 238 | /* |
| 239 | * The maximum number of signal names to be printed is NSIG * 2 / 3. |
| 240 | * Most of signal names have length 7, |
| 241 | * average length of signal names is less than 7. |
| 242 | * The length of prefix string does not exceed 16. |
| 243 | */ |
| 244 | static char outstr[128 + 8 * (NSIG * 2 / 3)]; |
| 245 | |
| 246 | char *s; |
| 247 | const uint32_t *mask; |
| 248 | uint32_t inverted_mask[NSIG / 32]; |
| 249 | unsigned int size; |
| 250 | int i; |
| 251 | char sep; |
| 252 | |
| 253 | s = stpcpy(outstr, prefix); |
| 254 | |
| 255 | mask = sig_mask; |
| 256 | /* length of signal mask in 4-byte words */ |
| 257 | size = (bytes >= NSIG / 8) ? NSIG / 32 : (bytes + 3) / 4; |
| 258 | |
| 259 | /* check whether 2/3 or more bits are set */ |
| 260 | if (popcount32(mask, size) >= size * 32 * 2 / 3) { |
| 261 | /* show those signals that are NOT in the mask */ |
| 262 | unsigned int j; |
| 263 | for (j = 0; j < size; ++j) |
| 264 | inverted_mask[j] = ~mask[j]; |
| 265 | mask = inverted_mask; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 266 | *s++ = '~'; |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 267 | } |
Denys Vlasenko | 4f3df07 | 2012-01-29 22:38:35 +0100 | [diff] [blame] | 268 | |
| 269 | sep = '['; |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 270 | for (i = 0; (i = next_set_bit(mask, i, size * 32)) >= 0; ) { |
| 271 | ++i; |
| 272 | *s++ = sep; |
| 273 | if (i < nsignals) { |
| 274 | s = stpcpy(s, signalent[i] + 3); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 275 | } |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 276 | #ifdef SIGRTMIN |
| 277 | else if (i >= __SIGRTMIN && i <= __SIGRTMAX) { |
| 278 | s += sprintf(s, "RT_%u", i - __SIGRTMIN); |
| 279 | } |
| 280 | #endif |
| 281 | else { |
| 282 | s += sprintf(s, "%u", i); |
| 283 | } |
| 284 | sep = ' '; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 285 | } |
Denys Vlasenko | 4f3df07 | 2012-01-29 22:38:35 +0100 | [diff] [blame] | 286 | if (sep == '[') |
| 287 | *s++ = sep; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 288 | *s++ = ']'; |
| 289 | *s = '\0'; |
| 290 | return outstr; |
| 291 | } |
| 292 | |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 293 | #define tprintsigmask_addr(prefix, mask) \ |
| 294 | tprints(sprintsigmask_n((prefix), (mask), sizeof(mask))) |
Denys Vlasenko | 75f4e1f | 2013-07-18 20:37:06 +0200 | [diff] [blame] | 295 | |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 296 | #define sprintsigmask_val(prefix, mask) \ |
| 297 | sprintsigmask_n((prefix), &(mask), sizeof(mask)) |
| 298 | |
| 299 | #define tprintsigmask_val(prefix, mask) \ |
| 300 | tprints(sprintsigmask_n((prefix), &(mask), sizeof(mask))) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 301 | |
| 302 | void |
Denys Vlasenko | eccc48c | 2011-06-09 01:28:11 +0200 | [diff] [blame] | 303 | printsignal(int nr) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 304 | { |
Denys Vlasenko | 5940e65 | 2011-09-01 09:55:05 +0200 | [diff] [blame] | 305 | tprints(signame(nr)); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 306 | } |
| 307 | |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 308 | void |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 309 | print_sigset_addr_len(struct tcb *tcp, long addr, long len) |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 310 | { |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 311 | char mask[NSIG / 8]; |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 312 | |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 313 | if (!addr) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 314 | tprints("NULL"); |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 315 | return; |
| 316 | } |
| 317 | /* Here len is usually equals NSIG / 8 or current_wordsize. |
| 318 | * But we code this defensively: |
| 319 | */ |
| 320 | if (len < 0) { |
| 321 | bad: |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 322 | tprintf("%#lx", addr); |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 323 | return; |
| 324 | } |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 325 | if (len >= NSIG / 8) |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 326 | len = NSIG / 8; |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 327 | else |
| 328 | len = (len + 3) & ~3; |
| 329 | |
| 330 | if (umoven(tcp, addr, len, mask) < 0) |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 331 | goto bad; |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 332 | tprints(sprintsigmask_n("", mask, len)); |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 333 | } |
| 334 | |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 335 | #ifndef ILL_ILLOPC |
| 336 | #define ILL_ILLOPC 1 /* illegal opcode */ |
| 337 | #define ILL_ILLOPN 2 /* illegal operand */ |
| 338 | #define ILL_ILLADR 3 /* illegal addressing mode */ |
| 339 | #define ILL_ILLTRP 4 /* illegal trap */ |
| 340 | #define ILL_PRVOPC 5 /* privileged opcode */ |
| 341 | #define ILL_PRVREG 6 /* privileged register */ |
| 342 | #define ILL_COPROC 7 /* coprocessor error */ |
| 343 | #define ILL_BADSTK 8 /* internal stack error */ |
| 344 | #define FPE_INTDIV 1 /* integer divide by zero */ |
| 345 | #define FPE_INTOVF 2 /* integer overflow */ |
| 346 | #define FPE_FLTDIV 3 /* floating point divide by zero */ |
| 347 | #define FPE_FLTOVF 4 /* floating point overflow */ |
| 348 | #define FPE_FLTUND 5 /* floating point underflow */ |
| 349 | #define FPE_FLTRES 6 /* floating point inexact result */ |
| 350 | #define FPE_FLTINV 7 /* floating point invalid operation */ |
| 351 | #define FPE_FLTSUB 8 /* subscript out of range */ |
| 352 | #define SEGV_MAPERR 1 /* address not mapped to object */ |
| 353 | #define SEGV_ACCERR 2 /* invalid permissions for mapped object */ |
| 354 | #define BUS_ADRALN 1 /* invalid address alignment */ |
| 355 | #define BUS_ADRERR 2 /* non-existant physical address */ |
| 356 | #define BUS_OBJERR 3 /* object specific hardware error */ |
| 357 | #define TRAP_BRKPT 1 /* process breakpoint */ |
| 358 | #define TRAP_TRACE 2 /* process trace trap */ |
| 359 | #define CLD_EXITED 1 /* child has exited */ |
| 360 | #define CLD_KILLED 2 /* child was killed */ |
| 361 | #define CLD_DUMPED 3 /* child terminated abnormally */ |
| 362 | #define CLD_TRAPPED 4 /* traced child has trapped */ |
| 363 | #define CLD_STOPPED 5 /* child has stopped */ |
| 364 | #define CLD_CONTINUED 6 /* stopped child has continued */ |
| 365 | #define POLL_IN 1 /* data input available */ |
| 366 | #define POLL_OUT 2 /* output buffers available */ |
| 367 | #define POLL_MSG 3 /* input message available */ |
| 368 | #define POLL_ERR 4 /* i/o error */ |
| 369 | #define POLL_PRI 5 /* high priority input available */ |
| 370 | #define POLL_HUP 6 /* device disconnected */ |
Dmitry V. Levin | 7d4bff1 | 2011-03-10 21:41:34 +0000 | [diff] [blame] | 371 | #define SI_KERNEL 0x80 /* sent by kernel */ |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 372 | #define SI_USER 0 /* sent by kill, sigsend, raise */ |
| 373 | #define SI_QUEUE -1 /* sent by sigqueue */ |
| 374 | #define SI_TIMER -2 /* sent by timer expiration */ |
| 375 | #define SI_MESGQ -3 /* sent by real time mesq state change */ |
| 376 | #define SI_ASYNCIO -4 /* sent by AIO completion */ |
Dmitry V. Levin | 7d4bff1 | 2011-03-10 21:41:34 +0000 | [diff] [blame] | 377 | #define SI_SIGIO -5 /* sent by SIGIO */ |
| 378 | #define SI_TKILL -6 /* sent by tkill */ |
| 379 | #define SI_ASYNCNL -60 /* sent by asynch name lookup completion */ |
Denys Vlasenko | 2c4fb90 | 2012-03-15 17:24:49 +0100 | [diff] [blame] | 380 | #endif |
Dmitry V. Levin | 6d9e8e8 | 2011-03-10 22:18:56 +0000 | [diff] [blame] | 381 | |
Denys Vlasenko | 2c4fb90 | 2012-03-15 17:24:49 +0100 | [diff] [blame] | 382 | #ifndef SI_FROMUSER |
| 383 | # define SI_FROMUSER(sip) ((sip)->si_code <= 0) |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 384 | #endif |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 385 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 386 | static const struct xlat siginfo_codes[] = { |
Dmitry V. Levin | 7d4bff1 | 2011-03-10 21:41:34 +0000 | [diff] [blame] | 387 | #ifdef SI_KERNEL |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 388 | XLAT(SI_KERNEL), |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 389 | #endif |
| 390 | #ifdef SI_USER |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 391 | XLAT(SI_USER), |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 392 | #endif |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 393 | #ifdef SI_QUEUE |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 394 | XLAT(SI_QUEUE), |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 395 | #endif |
| 396 | #ifdef SI_TIMER |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 397 | XLAT(SI_TIMER), |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 398 | #endif |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 399 | #ifdef SI_MESGQ |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 400 | XLAT(SI_MESGQ), |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 401 | #endif |
Dmitry V. Levin | 7d4bff1 | 2011-03-10 21:41:34 +0000 | [diff] [blame] | 402 | #ifdef SI_ASYNCIO |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 403 | XLAT(SI_ASYNCIO), |
Dmitry V. Levin | 7d4bff1 | 2011-03-10 21:41:34 +0000 | [diff] [blame] | 404 | #endif |
Roland McGrath | 941b740 | 2003-05-23 00:29:02 +0000 | [diff] [blame] | 405 | #ifdef SI_SIGIO |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 406 | XLAT(SI_SIGIO), |
Roland McGrath | 941b740 | 2003-05-23 00:29:02 +0000 | [diff] [blame] | 407 | #endif |
| 408 | #ifdef SI_TKILL |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 409 | XLAT(SI_TKILL), |
Roland McGrath | 941b740 | 2003-05-23 00:29:02 +0000 | [diff] [blame] | 410 | #endif |
Dmitry V. Levin | 7d4bff1 | 2011-03-10 21:41:34 +0000 | [diff] [blame] | 411 | #ifdef SI_ASYNCNL |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 412 | XLAT(SI_ASYNCNL), |
Dmitry V. Levin | 7d4bff1 | 2011-03-10 21:41:34 +0000 | [diff] [blame] | 413 | #endif |
| 414 | #ifdef SI_NOINFO |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 415 | XLAT(SI_NOINFO), |
Dmitry V. Levin | 7d4bff1 | 2011-03-10 21:41:34 +0000 | [diff] [blame] | 416 | #endif |
| 417 | #ifdef SI_LWP |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 418 | XLAT(SI_LWP), |
Dmitry V. Levin | 7d4bff1 | 2011-03-10 21:41:34 +0000 | [diff] [blame] | 419 | #endif |
Dmitry V. Levin | 5945273 | 2014-02-05 02:20:51 +0000 | [diff] [blame] | 420 | XLAT_END |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 421 | }; |
| 422 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 423 | static const struct xlat sigill_codes[] = { |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 424 | XLAT(ILL_ILLOPC), |
| 425 | XLAT(ILL_ILLOPN), |
| 426 | XLAT(ILL_ILLADR), |
| 427 | XLAT(ILL_ILLTRP), |
| 428 | XLAT(ILL_PRVOPC), |
| 429 | XLAT(ILL_PRVREG), |
| 430 | XLAT(ILL_COPROC), |
| 431 | XLAT(ILL_BADSTK), |
Dmitry V. Levin | 5945273 | 2014-02-05 02:20:51 +0000 | [diff] [blame] | 432 | XLAT_END |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 433 | }; |
| 434 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 435 | static const struct xlat sigfpe_codes[] = { |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 436 | XLAT(FPE_INTDIV), |
| 437 | XLAT(FPE_INTOVF), |
| 438 | XLAT(FPE_FLTDIV), |
| 439 | XLAT(FPE_FLTOVF), |
| 440 | XLAT(FPE_FLTUND), |
| 441 | XLAT(FPE_FLTRES), |
| 442 | XLAT(FPE_FLTINV), |
| 443 | XLAT(FPE_FLTSUB), |
Dmitry V. Levin | 5945273 | 2014-02-05 02:20:51 +0000 | [diff] [blame] | 444 | XLAT_END |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 445 | }; |
| 446 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 447 | static const struct xlat sigtrap_codes[] = { |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 448 | XLAT(TRAP_BRKPT), |
| 449 | XLAT(TRAP_TRACE), |
Dmitry V. Levin | 5945273 | 2014-02-05 02:20:51 +0000 | [diff] [blame] | 450 | XLAT_END |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 451 | }; |
| 452 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 453 | static const struct xlat sigchld_codes[] = { |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 454 | XLAT(CLD_EXITED), |
| 455 | XLAT(CLD_KILLED), |
| 456 | XLAT(CLD_DUMPED), |
| 457 | XLAT(CLD_TRAPPED), |
| 458 | XLAT(CLD_STOPPED), |
| 459 | XLAT(CLD_CONTINUED), |
Dmitry V. Levin | 5945273 | 2014-02-05 02:20:51 +0000 | [diff] [blame] | 460 | XLAT_END |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 461 | }; |
| 462 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 463 | static const struct xlat sigpoll_codes[] = { |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 464 | XLAT(POLL_IN), |
| 465 | XLAT(POLL_OUT), |
| 466 | XLAT(POLL_MSG), |
| 467 | XLAT(POLL_ERR), |
| 468 | XLAT(POLL_PRI), |
| 469 | XLAT(POLL_HUP), |
Dmitry V. Levin | 5945273 | 2014-02-05 02:20:51 +0000 | [diff] [blame] | 470 | XLAT_END |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 471 | }; |
| 472 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 473 | static const struct xlat sigprof_codes[] = { |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 474 | #ifdef PROF_SIG |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 475 | XLAT(PROF_SIG), |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 476 | #endif |
Dmitry V. Levin | 5945273 | 2014-02-05 02:20:51 +0000 | [diff] [blame] | 477 | XLAT_END |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 478 | }; |
| 479 | |
| 480 | #ifdef SIGEMT |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 481 | static const struct xlat sigemt_codes[] = { |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 482 | #ifdef EMT_TAGOVF |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 483 | XLAT(EMT_TAGOVF), |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 484 | #endif |
Dmitry V. Levin | 5945273 | 2014-02-05 02:20:51 +0000 | [diff] [blame] | 485 | XLAT_END |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 486 | }; |
| 487 | #endif |
| 488 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 489 | static const struct xlat sigsegv_codes[] = { |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 490 | XLAT(SEGV_MAPERR), |
| 491 | XLAT(SEGV_ACCERR), |
Dmitry V. Levin | 5945273 | 2014-02-05 02:20:51 +0000 | [diff] [blame] | 492 | XLAT_END |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 493 | }; |
| 494 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 495 | static const struct xlat sigbus_codes[] = { |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 496 | XLAT(BUS_ADRALN), |
| 497 | XLAT(BUS_ADRERR), |
| 498 | XLAT(BUS_OBJERR), |
Dmitry V. Levin | 5945273 | 2014-02-05 02:20:51 +0000 | [diff] [blame] | 499 | XLAT_END |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 500 | }; |
| 501 | |
| 502 | void |
Dmitry V. Levin | 6d9e8e8 | 2011-03-10 22:18:56 +0000 | [diff] [blame] | 503 | printsiginfo(siginfo_t *sip, int verbose) |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 504 | { |
Roland McGrath | f9c49b2 | 2004-10-06 22:11:54 +0000 | [diff] [blame] | 505 | const char *code; |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 506 | |
| 507 | if (sip->si_signo == 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 508 | tprints("{}"); |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 509 | return; |
| 510 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 511 | tprints("{si_signo="); |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 512 | printsignal(sip->si_signo); |
| 513 | code = xlookup(siginfo_codes, sip->si_code); |
| 514 | if (!code) { |
| 515 | switch (sip->si_signo) { |
| 516 | case SIGTRAP: |
| 517 | code = xlookup(sigtrap_codes, sip->si_code); |
| 518 | break; |
| 519 | case SIGCHLD: |
| 520 | code = xlookup(sigchld_codes, sip->si_code); |
| 521 | break; |
| 522 | case SIGPOLL: |
| 523 | code = xlookup(sigpoll_codes, sip->si_code); |
| 524 | break; |
| 525 | case SIGPROF: |
| 526 | code = xlookup(sigprof_codes, sip->si_code); |
| 527 | break; |
| 528 | case SIGILL: |
| 529 | code = xlookup(sigill_codes, sip->si_code); |
| 530 | break; |
| 531 | #ifdef SIGEMT |
| 532 | case SIGEMT: |
| 533 | code = xlookup(sigemt_codes, sip->si_code); |
| 534 | break; |
| 535 | #endif |
| 536 | case SIGFPE: |
| 537 | code = xlookup(sigfpe_codes, sip->si_code); |
| 538 | break; |
| 539 | case SIGSEGV: |
| 540 | code = xlookup(sigsegv_codes, sip->si_code); |
| 541 | break; |
| 542 | case SIGBUS: |
| 543 | code = xlookup(sigbus_codes, sip->si_code); |
| 544 | break; |
| 545 | } |
| 546 | } |
| 547 | if (code) |
| 548 | tprintf(", si_code=%s", code); |
| 549 | else |
| 550 | tprintf(", si_code=%#x", sip->si_code); |
| 551 | #ifdef SI_NOINFO |
| 552 | if (sip->si_code != SI_NOINFO) |
| 553 | #endif |
| 554 | { |
| 555 | if (sip->si_errno) { |
| 556 | if (sip->si_errno < 0 || sip->si_errno >= nerrnos) |
| 557 | tprintf(", si_errno=%d", sip->si_errno); |
| 558 | else |
| 559 | tprintf(", si_errno=%s", |
| 560 | errnoent[sip->si_errno]); |
| 561 | } |
| 562 | #ifdef SI_FROMUSER |
| 563 | if (SI_FROMUSER(sip)) { |
Dmitry V. Levin | 6d9e8e8 | 2011-03-10 22:18:56 +0000 | [diff] [blame] | 564 | tprintf(", si_pid=%lu, si_uid=%lu", |
| 565 | (unsigned long) sip->si_pid, |
| 566 | (unsigned long) sip->si_uid); |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 567 | switch (sip->si_code) { |
Dmitry V. Levin | 6d9e8e8 | 2011-03-10 22:18:56 +0000 | [diff] [blame] | 568 | #ifdef SI_USER |
| 569 | case SI_USER: |
| 570 | break; |
| 571 | #endif |
| 572 | #ifdef SI_TKILL |
| 573 | case SI_TKILL: |
| 574 | break; |
| 575 | #endif |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 576 | #ifdef SI_TIMER |
| 577 | case SI_TIMER: |
Dmitry V. Levin | 6d9e8e8 | 2011-03-10 22:18:56 +0000 | [diff] [blame] | 578 | tprintf(", si_value=%d", sip->si_int); |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 579 | break; |
Dmitry V. Levin | 6d9e8e8 | 2011-03-10 22:18:56 +0000 | [diff] [blame] | 580 | #endif |
Dmitry V. Levin | 6d9e8e8 | 2011-03-10 22:18:56 +0000 | [diff] [blame] | 581 | default: |
Dmitry V. Levin | b41e1c9 | 2011-03-10 23:14:47 +0000 | [diff] [blame] | 582 | if (!sip->si_ptr) |
| 583 | break; |
Dmitry V. Levin | 6d9e8e8 | 2011-03-10 22:18:56 +0000 | [diff] [blame] | 584 | if (!verbose) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 585 | tprints(", ..."); |
Dmitry V. Levin | 6d9e8e8 | 2011-03-10 22:18:56 +0000 | [diff] [blame] | 586 | else |
| 587 | tprintf(", si_value={int=%u, ptr=%#lx}", |
| 588 | sip->si_int, |
| 589 | (unsigned long) sip->si_ptr); |
| 590 | break; |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 591 | } |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 592 | } |
| 593 | else |
| 594 | #endif /* SI_FROMUSER */ |
| 595 | { |
| 596 | switch (sip->si_signo) { |
| 597 | case SIGCHLD: |
| 598 | tprintf(", si_pid=%ld, si_status=", |
| 599 | (long) sip->si_pid); |
| 600 | if (sip->si_code == CLD_EXITED) |
| 601 | tprintf("%d", sip->si_status); |
| 602 | else |
| 603 | printsignal(sip->si_status); |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 604 | if (!verbose) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 605 | tprints(", ..."); |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 606 | else |
H.J. Lu | 2bb4581 | 2012-04-15 11:17:13 -0700 | [diff] [blame] | 607 | tprintf(", si_utime=%llu, si_stime=%llu", |
| 608 | (unsigned long long) sip->si_utime, |
| 609 | (unsigned long long) sip->si_stime); |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 610 | break; |
| 611 | case SIGILL: case SIGFPE: |
| 612 | case SIGSEGV: case SIGBUS: |
| 613 | tprintf(", si_addr=%#lx", |
| 614 | (unsigned long) sip->si_addr); |
| 615 | break; |
| 616 | case SIGPOLL: |
| 617 | switch (sip->si_code) { |
| 618 | case POLL_IN: case POLL_OUT: case POLL_MSG: |
| 619 | tprintf(", si_band=%ld", |
| 620 | (long) sip->si_band); |
| 621 | break; |
| 622 | } |
| 623 | break; |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 624 | default: |
Dmitry V. Levin | b41e1c9 | 2011-03-10 23:14:47 +0000 | [diff] [blame] | 625 | if (sip->si_pid || sip->si_uid) |
| 626 | tprintf(", si_pid=%lu, si_uid=%lu", |
| 627 | (unsigned long) sip->si_pid, |
| 628 | (unsigned long) sip->si_uid); |
| 629 | if (!sip->si_ptr) |
| 630 | break; |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 631 | if (!verbose) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 632 | tprints(", ..."); |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 633 | else { |
Dmitry V. Levin | b41e1c9 | 2011-03-10 23:14:47 +0000 | [diff] [blame] | 634 | tprintf(", si_value={int=%u, ptr=%#lx}", |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 635 | sip->si_int, |
| 636 | (unsigned long) sip->si_ptr); |
| 637 | } |
Roland McGrath | a39c5a1 | 2002-12-17 05:10:37 +0000 | [diff] [blame] | 638 | |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 639 | } |
| 640 | } |
| 641 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 642 | tprints("}"); |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 643 | } |
| 644 | |
Denys Vlasenko | d4d3ede | 2013-02-13 16:31:32 +0100 | [diff] [blame] | 645 | void |
| 646 | printsiginfo_at(struct tcb *tcp, long addr) |
| 647 | { |
| 648 | siginfo_t si; |
| 649 | if (!addr) { |
| 650 | tprints("NULL"); |
| 651 | return; |
| 652 | } |
| 653 | if (syserror(tcp)) { |
| 654 | tprintf("%#lx", addr); |
| 655 | return; |
| 656 | } |
| 657 | if (umove(tcp, addr, &si) < 0) { |
| 658 | tprints("{???}"); |
| 659 | return; |
| 660 | } |
| 661 | printsiginfo(&si, verbose(tcp)); |
| 662 | } |
| 663 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 664 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 665 | sys_sigsetmask(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 666 | { |
| 667 | if (entering(tcp)) { |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 668 | tprintsigmask_val("", tcp->u_arg[0]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 669 | } |
| 670 | else if (!syserror(tcp)) { |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 671 | tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 672 | return RVAL_HEX | RVAL_STR; |
| 673 | } |
| 674 | return 0; |
| 675 | } |
| 676 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 677 | #ifdef HAVE_SIGACTION |
| 678 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 679 | struct old_sigaction { |
Denys Vlasenko | 86d9484 | 2013-02-08 12:59:13 +0100 | [diff] [blame] | 680 | /* sa_handler may be a libc #define, need to use other name: */ |
Chris Dearman | 2b4bb1c | 2013-12-09 19:58:42 -0800 | [diff] [blame] | 681 | #ifdef MIPS |
| 682 | unsigned int sa_flags; |
| 683 | void (*__sa_handler)(int); |
| 684 | /* Kernel treats sa_mask as an array of longs. */ |
| 685 | unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1]; |
| 686 | #else |
Denys Vlasenko | 86d9484 | 2013-02-08 12:59:13 +0100 | [diff] [blame] | 687 | void (*__sa_handler)(int); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 688 | unsigned long sa_mask; |
| 689 | unsigned long sa_flags; |
| 690 | void (*sa_restorer)(void); |
Chris Dearman | 2b4bb1c | 2013-12-09 19:58:42 -0800 | [diff] [blame] | 691 | #endif /* !MIPS */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 692 | }; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 693 | |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 694 | static void |
| 695 | decode_old_sigaction(struct tcb *tcp, long addr) |
| 696 | { |
| 697 | struct old_sigaction sa; |
| 698 | |
| 699 | if (!addr) { |
| 700 | tprints("NULL"); |
| 701 | return; |
| 702 | } |
| 703 | if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) { |
| 704 | tprintf("%#lx", addr); |
| 705 | return; |
| 706 | } |
| 707 | if (umove(tcp, addr, &sa) < 0) { |
| 708 | tprints("{...}"); |
| 709 | return; |
| 710 | } |
| 711 | |
| 712 | /* Architectures using function pointers, like |
| 713 | * hppa, may need to manipulate the function pointer |
| 714 | * to compute the result of a comparison. However, |
| 715 | * the __sa_handler function pointer exists only in |
| 716 | * the address space of the traced process, and can't |
| 717 | * be manipulated by strace. In order to prevent the |
| 718 | * compiler from generating code to manipulate |
| 719 | * __sa_handler we cast the function pointers to long. */ |
| 720 | if ((long)sa.__sa_handler == (long)SIG_ERR) |
| 721 | tprints("{SIG_ERR, "); |
| 722 | else if ((long)sa.__sa_handler == (long)SIG_DFL) |
| 723 | tprints("{SIG_DFL, "); |
| 724 | else if ((long)sa.__sa_handler == (long)SIG_IGN) |
| 725 | tprints("{SIG_IGN, "); |
| 726 | else |
| 727 | tprintf("{%#lx, ", (long) sa.__sa_handler); |
Chris Dearman | 2b4bb1c | 2013-12-09 19:58:42 -0800 | [diff] [blame] | 728 | #ifdef MIPS |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 729 | tprintsigmask_addr("", sa.sa_mask); |
Chris Dearman | 2b4bb1c | 2013-12-09 19:58:42 -0800 | [diff] [blame] | 730 | #else |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 731 | tprintsigmask_val("", sa.sa_mask); |
Chris Dearman | 2b4bb1c | 2013-12-09 19:58:42 -0800 | [diff] [blame] | 732 | #endif |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 733 | tprints(", "); |
| 734 | printflags(sigact_flags, sa.sa_flags, "SA_???"); |
| 735 | #ifdef SA_RESTORER |
| 736 | if (sa.sa_flags & SA_RESTORER) |
| 737 | tprintf(", %p", sa.sa_restorer); |
| 738 | #endif |
| 739 | tprints("}"); |
| 740 | } |
| 741 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 742 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 743 | sys_sigaction(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 744 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 745 | if (entering(tcp)) { |
| 746 | printsignal(tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 747 | tprints(", "); |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 748 | decode_old_sigaction(tcp, tcp->u_arg[1]); |
| 749 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 750 | } else |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 751 | decode_old_sigaction(tcp, tcp->u_arg[2]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 752 | return 0; |
| 753 | } |
| 754 | |
| 755 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 756 | sys_signal(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 757 | { |
| 758 | if (entering(tcp)) { |
| 759 | printsignal(tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 760 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 761 | switch (tcp->u_arg[1]) { |
Jan Kratochvil | 1f94271 | 2008-08-06 21:38:52 +0000 | [diff] [blame] | 762 | case (long) SIG_ERR: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 763 | tprints("SIG_ERR"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 764 | break; |
Jan Kratochvil | 1f94271 | 2008-08-06 21:38:52 +0000 | [diff] [blame] | 765 | case (long) SIG_DFL: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 766 | tprints("SIG_DFL"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 767 | break; |
Jan Kratochvil | 1f94271 | 2008-08-06 21:38:52 +0000 | [diff] [blame] | 768 | case (long) SIG_IGN: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 769 | tprints("SIG_IGN"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 770 | break; |
| 771 | default: |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 772 | tprintf("%#lx", tcp->u_arg[1]); |
| 773 | } |
Wichert Akkerman | 16a03d2 | 2000-08-10 02:14:04 +0000 | [diff] [blame] | 774 | return 0; |
| 775 | } |
Dmitry V. Levin | 21a7534 | 2008-09-03 01:22:18 +0000 | [diff] [blame] | 776 | else if (!syserror(tcp)) { |
Wichert Akkerman | 16a03d2 | 2000-08-10 02:14:04 +0000 | [diff] [blame] | 777 | switch (tcp->u_rval) { |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 778 | case (long) SIG_ERR: |
Wichert Akkerman | 16a03d2 | 2000-08-10 02:14:04 +0000 | [diff] [blame] | 779 | tcp->auxstr = "SIG_ERR"; break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 780 | case (long) SIG_DFL: |
Wichert Akkerman | 16a03d2 | 2000-08-10 02:14:04 +0000 | [diff] [blame] | 781 | tcp->auxstr = "SIG_DFL"; break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 782 | case (long) SIG_IGN: |
Wichert Akkerman | 16a03d2 | 2000-08-10 02:14:04 +0000 | [diff] [blame] | 783 | tcp->auxstr = "SIG_IGN"; break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 784 | default: |
Wichert Akkerman | 16a03d2 | 2000-08-10 02:14:04 +0000 | [diff] [blame] | 785 | tcp->auxstr = NULL; |
| 786 | } |
| 787 | return RVAL_HEX | RVAL_STR; |
| 788 | } |
Dmitry V. Levin | 21a7534 | 2008-09-03 01:22:18 +0000 | [diff] [blame] | 789 | return 0; |
Wichert Akkerman | 16a03d2 | 2000-08-10 02:14:04 +0000 | [diff] [blame] | 790 | } |
| 791 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 792 | #endif /* HAVE_SIGACTION */ |
| 793 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 794 | int |
Denys Vlasenko | ea0e6e8 | 2009-02-25 17:08:40 +0000 | [diff] [blame] | 795 | sys_sigreturn(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 796 | { |
Denys Vlasenko | ea0e6e8 | 2009-02-25 17:08:40 +0000 | [diff] [blame] | 797 | #if defined(ARM) |
Roland McGrath | 0f87c49 | 2003-06-03 23:29:04 +0000 | [diff] [blame] | 798 | if (entering(tcp)) { |
Denys Vlasenko | 670b21b | 2013-07-17 17:26:56 +0200 | [diff] [blame] | 799 | struct arm_sigcontext { |
| 800 | unsigned long trap_no; |
| 801 | unsigned long error_code; |
| 802 | unsigned long oldmask; |
| 803 | unsigned long arm_r0; |
| 804 | unsigned long arm_r1; |
| 805 | unsigned long arm_r2; |
| 806 | unsigned long arm_r3; |
| 807 | unsigned long arm_r4; |
| 808 | unsigned long arm_r5; |
| 809 | unsigned long arm_r6; |
| 810 | unsigned long arm_r7; |
| 811 | unsigned long arm_r8; |
| 812 | unsigned long arm_r9; |
| 813 | unsigned long arm_r10; |
| 814 | unsigned long arm_fp; |
| 815 | unsigned long arm_ip; |
| 816 | unsigned long arm_sp; |
| 817 | unsigned long arm_lr; |
| 818 | unsigned long arm_pc; |
| 819 | unsigned long arm_cpsr; |
| 820 | unsigned long fault_address; |
| 821 | }; |
| 822 | struct arm_ucontext { |
| 823 | unsigned long uc_flags; |
| 824 | unsigned long uc_link; /* struct ucontext* */ |
| 825 | /* The next three members comprise stack_t struct: */ |
| 826 | unsigned long ss_sp; /* void* */ |
| 827 | unsigned long ss_flags; /* int */ |
| 828 | unsigned long ss_size; /* size_t */ |
| 829 | struct arm_sigcontext sc; |
| 830 | /* These two members are sigset_t: */ |
| 831 | unsigned long uc_sigmask[2]; |
| 832 | /* more fields follow, which we aren't interested in */ |
| 833 | }; |
| 834 | struct arm_ucontext uc; |
Denys Vlasenko | 670b21b | 2013-07-17 17:26:56 +0200 | [diff] [blame] | 835 | if (umove(tcp, arm_regs.ARM_sp, &uc) < 0) |
Roland McGrath | 0f87c49 | 2003-06-03 23:29:04 +0000 | [diff] [blame] | 836 | return 0; |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 837 | /* |
| 838 | * Kernel fills out uc.sc.oldmask too when it sets up signal stack, |
Denys Vlasenko | 670b21b | 2013-07-17 17:26:56 +0200 | [diff] [blame] | 839 | * but for sigmask restore, sigreturn syscall uses uc.uc_sigmask instead. |
Denys Vlasenko | 670b21b | 2013-07-17 17:26:56 +0200 | [diff] [blame] | 840 | */ |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 841 | tprintsigmask_addr(") (mask ", uc.uc_sigmask); |
Roland McGrath | 0f87c49 | 2003-06-03 23:29:04 +0000 | [diff] [blame] | 842 | } |
Roland McGrath | 0f87c49 | 2003-06-03 23:29:04 +0000 | [diff] [blame] | 843 | #elif defined(S390) || defined(S390X) |
Roland McGrath | 0f87c49 | 2003-06-03 23:29:04 +0000 | [diff] [blame] | 844 | if (entering(tcp)) { |
Denys Vlasenko | 56a5298 | 2011-06-09 01:36:29 +0200 | [diff] [blame] | 845 | long usp; |
Dmitry V. Levin | e2de3bd | 2013-11-12 15:27:38 +0000 | [diff] [blame] | 846 | struct sigcontext sc; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 847 | if (upeek(tcp->pid, PT_GPR15, &usp) < 0) |
Roland McGrath | 0f87c49 | 2003-06-03 23:29:04 +0000 | [diff] [blame] | 848 | return 0; |
Denys Vlasenko | b11322f | 2012-01-10 16:40:35 +0100 | [diff] [blame] | 849 | if (umove(tcp, usp + __SIGNAL_FRAMESIZE, &sc) < 0) |
Roland McGrath | 0f87c49 | 2003-06-03 23:29:04 +0000 | [diff] [blame] | 850 | return 0; |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 851 | tprintsigmask_addr(") (mask ", sc.oldmask); |
Roland McGrath | 0f87c49 | 2003-06-03 23:29:04 +0000 | [diff] [blame] | 852 | } |
Denys Vlasenko | b51f364 | 2013-07-16 12:06:25 +0200 | [diff] [blame] | 853 | #elif defined(I386) || defined(X86_64) |
| 854 | # if defined(X86_64) |
| 855 | if (current_personality == 0) /* 64-bit */ |
| 856 | return 0; |
| 857 | # endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 858 | if (entering(tcp)) { |
Denys Vlasenko | 670b21b | 2013-07-17 17:26:56 +0200 | [diff] [blame] | 859 | struct i386_sigcontext_struct { |
| 860 | uint16_t gs, __gsh; |
| 861 | uint16_t fs, __fsh; |
| 862 | uint16_t es, __esh; |
| 863 | uint16_t ds, __dsh; |
| 864 | uint32_t edi; |
| 865 | uint32_t esi; |
| 866 | uint32_t ebp; |
| 867 | uint32_t esp; |
| 868 | uint32_t ebx; |
| 869 | uint32_t edx; |
| 870 | uint32_t ecx; |
| 871 | uint32_t eax; |
| 872 | uint32_t trapno; |
| 873 | uint32_t err; |
| 874 | uint32_t eip; |
| 875 | uint16_t cs, __csh; |
| 876 | uint32_t eflags; |
| 877 | uint32_t esp_at_signal; |
| 878 | uint16_t ss, __ssh; |
| 879 | uint32_t i387; |
| 880 | uint32_t oldmask; |
| 881 | uint32_t cr2; |
| 882 | }; |
| 883 | struct i386_fpstate { |
| 884 | uint32_t cw; |
| 885 | uint32_t sw; |
| 886 | uint32_t tag; |
| 887 | uint32_t ipoff; |
| 888 | uint32_t cssel; |
| 889 | uint32_t dataoff; |
| 890 | uint32_t datasel; |
| 891 | uint8_t st[8][10]; /* 8*10 bytes: FP regs */ |
| 892 | uint16_t status; |
| 893 | uint16_t magic; |
| 894 | uint32_t fxsr_env[6]; |
| 895 | uint32_t mxcsr; |
| 896 | uint32_t reserved; |
| 897 | uint8_t stx[8][16]; /* 8*16 bytes: FP regs, each padded to 16 bytes */ |
| 898 | uint8_t xmm[8][16]; /* 8 XMM regs */ |
| 899 | uint32_t padding1[44]; |
| 900 | uint32_t padding2[12]; /* union with struct _fpx_sw_bytes */ |
| 901 | }; |
Denys Vlasenko | b51f364 | 2013-07-16 12:06:25 +0200 | [diff] [blame] | 902 | struct { |
| 903 | struct i386_sigcontext_struct sc; |
| 904 | struct i386_fpstate fp; |
| 905 | uint32_t extramask[1]; |
| 906 | } signal_stack; |
| 907 | /* On i386, sc is followed on stack by struct fpstate |
Denys Vlasenko | b11322f | 2012-01-10 16:40:35 +0100 | [diff] [blame] | 908 | * and after it an additional u32 extramask[1] which holds |
Denys Vlasenko | b51f364 | 2013-07-16 12:06:25 +0200 | [diff] [blame] | 909 | * upper half of the mask. |
Denys Vlasenko | b11322f | 2012-01-10 16:40:35 +0100 | [diff] [blame] | 910 | */ |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 911 | uint32_t sigmask[2]; |
Denys Vlasenko | b51f364 | 2013-07-16 12:06:25 +0200 | [diff] [blame] | 912 | if (umove(tcp, *i386_esp_ptr, &signal_stack) < 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 913 | return 0; |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 914 | sigmask[0] = signal_stack.sc.oldmask; |
| 915 | sigmask[1] = signal_stack.extramask[0]; |
| 916 | tprintsigmask_addr(") (mask ", sigmask); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 917 | } |
Denys Vlasenko | ea0e6e8 | 2009-02-25 17:08:40 +0000 | [diff] [blame] | 918 | #elif defined(IA64) |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame] | 919 | if (entering(tcp)) { |
Denys Vlasenko | 56a5298 | 2011-06-09 01:36:29 +0200 | [diff] [blame] | 920 | struct sigcontext sc; |
| 921 | long sp; |
Wichert Akkerman | 5ae21ea | 2000-05-01 01:53:59 +0000 | [diff] [blame] | 922 | /* offset of sigcontext in the kernel's sigframe structure: */ |
| 923 | # define SIGFRAME_SC_OFFSET 0x90 |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 924 | if (upeek(tcp->pid, PT_R12, &sp) < 0) |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame] | 925 | return 0; |
Wichert Akkerman | 5ae21ea | 2000-05-01 01:53:59 +0000 | [diff] [blame] | 926 | if (umove(tcp, sp + 16 + SIGFRAME_SC_OFFSET, &sc) < 0) |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame] | 927 | return 0; |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 928 | tprintsigmask_val(") (mask ", sc.sc_mask); |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame] | 929 | } |
Denys Vlasenko | ea0e6e8 | 2009-02-25 17:08:40 +0000 | [diff] [blame] | 930 | #elif defined(POWERPC) |
Roland McGrath | 0f87c49 | 2003-06-03 23:29:04 +0000 | [diff] [blame] | 931 | if (entering(tcp)) { |
Denys Vlasenko | 56a5298 | 2011-06-09 01:36:29 +0200 | [diff] [blame] | 932 | long esp; |
Dmitry V. Levin | e2de3bd | 2013-11-12 15:27:38 +0000 | [diff] [blame] | 933 | struct sigcontext sc; |
Anton Blanchard | ce6e33b | 2013-06-26 15:53:33 +0200 | [diff] [blame] | 934 | |
| 935 | esp = ppc_regs.gpr[1]; |
| 936 | |
Andreas Schwab | edb3934 | 2010-02-23 00:18:51 +0100 | [diff] [blame] | 937 | /* Skip dummy stack frame. */ |
Andreas Schwab | d69fa49 | 2010-07-12 21:39:57 +0200 | [diff] [blame] | 938 | #ifdef POWERPC64 |
| 939 | if (current_personality == 0) |
| 940 | esp += 128; |
| 941 | else |
| 942 | esp += 64; |
Andreas Schwab | edb3934 | 2010-02-23 00:18:51 +0100 | [diff] [blame] | 943 | #else |
| 944 | esp += 64; |
| 945 | #endif |
Roland McGrath | 0f87c49 | 2003-06-03 23:29:04 +0000 | [diff] [blame] | 946 | if (umove(tcp, esp, &sc) < 0) |
| 947 | return 0; |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 948 | tprintsigmask_val(") (mask ", sc.oldmask); |
Roland McGrath | 0f87c49 | 2003-06-03 23:29:04 +0000 | [diff] [blame] | 949 | } |
Denys Vlasenko | ea0e6e8 | 2009-02-25 17:08:40 +0000 | [diff] [blame] | 950 | #elif defined(M68K) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 951 | if (entering(tcp)) { |
Denys Vlasenko | 56a5298 | 2011-06-09 01:36:29 +0200 | [diff] [blame] | 952 | long usp; |
| 953 | struct sigcontext sc; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 954 | if (upeek(tcp->pid, 4*PT_USP, &usp) < 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 955 | return 0; |
Roland McGrath | 0f87c49 | 2003-06-03 23:29:04 +0000 | [diff] [blame] | 956 | if (umove(tcp, usp, &sc) < 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 957 | return 0; |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 958 | tprintsigmask_val(") (mask ", sc.sc_mask); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 959 | } |
Denys Vlasenko | ea0e6e8 | 2009-02-25 17:08:40 +0000 | [diff] [blame] | 960 | #elif defined(ALPHA) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 961 | if (entering(tcp)) { |
Denys Vlasenko | 56a5298 | 2011-06-09 01:36:29 +0200 | [diff] [blame] | 962 | long fp; |
Dmitry V. Levin | e2de3bd | 2013-11-12 15:27:38 +0000 | [diff] [blame] | 963 | struct sigcontext sc; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 964 | if (upeek(tcp->pid, REG_FP, &fp) < 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 965 | return 0; |
Roland McGrath | 0f87c49 | 2003-06-03 23:29:04 +0000 | [diff] [blame] | 966 | if (umove(tcp, fp, &sc) < 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 967 | return 0; |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 968 | tprintsigmask_val(") (mask ", sc.sc_mask); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 969 | } |
Denys Vlasenko | c36c352 | 2012-02-25 02:47:15 +0100 | [diff] [blame] | 970 | #elif defined(SPARC) || defined(SPARC64) |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 971 | if (entering(tcp)) { |
Denys Vlasenko | 56a5298 | 2011-06-09 01:36:29 +0200 | [diff] [blame] | 972 | long i1; |
Denys Vlasenko | 56a5298 | 2011-06-09 01:36:29 +0200 | [diff] [blame] | 973 | m_siginfo_t si; |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 974 | i1 = sparc_regs.u_regs[U_REG_O1]; |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 975 | if (umove(tcp, i1, &si) < 0) { |
Denys Vlasenko | 905e8e0 | 2013-02-26 12:30:09 +0100 | [diff] [blame] | 976 | perror_msg("sigreturn: umove"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 977 | return 0; |
| 978 | } |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 979 | tprintsigmask_val(") (mask ", si.si_mask); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 980 | } |
Denys Vlasenko | c36c352 | 2012-02-25 02:47:15 +0100 | [diff] [blame] | 981 | #elif defined(LINUX_MIPSN32) || defined(LINUX_MIPSN64) |
Roland McGrath | 542c2c6 | 2008-05-20 01:11:56 +0000 | [diff] [blame] | 982 | /* This decodes rt_sigreturn. The 64-bit ABIs do not have |
| 983 | sigreturn. */ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 984 | if (entering(tcp)) { |
Denys Vlasenko | 56a5298 | 2011-06-09 01:36:29 +0200 | [diff] [blame] | 985 | long sp; |
| 986 | struct ucontext uc; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 987 | if (upeek(tcp->pid, REG_SP, &sp) < 0) |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 988 | return 0; |
Roland McGrath | 542c2c6 | 2008-05-20 01:11:56 +0000 | [diff] [blame] | 989 | /* There are six words followed by a 128-byte siginfo. */ |
| 990 | sp = sp + 6 * 4 + 128; |
| 991 | if (umove(tcp, sp, &uc) < 0) |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 992 | return 0; |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 993 | tprintsigmask_val(") (mask ", uc.uc_sigmask); |
Roland McGrath | 542c2c6 | 2008-05-20 01:11:56 +0000 | [diff] [blame] | 994 | } |
Denys Vlasenko | ea0e6e8 | 2009-02-25 17:08:40 +0000 | [diff] [blame] | 995 | #elif defined(MIPS) |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 996 | if (entering(tcp)) { |
Denys Vlasenko | 56a5298 | 2011-06-09 01:36:29 +0200 | [diff] [blame] | 997 | long sp; |
| 998 | struct pt_regs regs; |
| 999 | m_siginfo_t si; |
Denys Vlasenko | 56a5298 | 2011-06-09 01:36:29 +0200 | [diff] [blame] | 1000 | if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)®s, 0) < 0) { |
Denys Vlasenko | 905e8e0 | 2013-02-26 12:30:09 +0100 | [diff] [blame] | 1001 | perror_msg("sigreturn: PTRACE_GETREGS"); |
Denys Vlasenko | 56a5298 | 2011-06-09 01:36:29 +0200 | [diff] [blame] | 1002 | return 0; |
| 1003 | } |
Roland McGrath | 576b784 | 2007-11-04 00:00:00 +0000 | [diff] [blame] | 1004 | sp = regs.regs[29]; |
| 1005 | if (umove(tcp, sp, &si) < 0) |
Denys Vlasenko | facd45b | 2011-06-09 01:22:10 +0200 | [diff] [blame] | 1006 | return 0; |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 1007 | tprintsigmask_val(") (mask ", si.si_mask); |
Wichert Akkerman | f90da01 | 1999-10-31 21:15:38 +0000 | [diff] [blame] | 1008 | } |
Denys Vlasenko | ea0e6e8 | 2009-02-25 17:08:40 +0000 | [diff] [blame] | 1009 | #elif defined(CRISV10) || defined(CRISV32) |
Denys Vlasenko | ea0e6e8 | 2009-02-25 17:08:40 +0000 | [diff] [blame] | 1010 | if (entering(tcp)) { |
Denys Vlasenko | 56a5298 | 2011-06-09 01:36:29 +0200 | [diff] [blame] | 1011 | struct sigcontext sc; |
Denys Vlasenko | ea0e6e8 | 2009-02-25 17:08:40 +0000 | [diff] [blame] | 1012 | long regs[PT_MAX+1]; |
Denys Vlasenko | ea0e6e8 | 2009-02-25 17:08:40 +0000 | [diff] [blame] | 1013 | if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) { |
Denys Vlasenko | 905e8e0 | 2013-02-26 12:30:09 +0100 | [diff] [blame] | 1014 | perror_msg("sigreturn: PTRACE_GETREGS"); |
Denys Vlasenko | ea0e6e8 | 2009-02-25 17:08:40 +0000 | [diff] [blame] | 1015 | return 0; |
| 1016 | } |
| 1017 | if (umove(tcp, regs[PT_USP], &sc) < 0) |
| 1018 | return 0; |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 1019 | tprintsigmask_val(") (mask ", sc.oldmask); |
Denys Vlasenko | ea0e6e8 | 2009-02-25 17:08:40 +0000 | [diff] [blame] | 1020 | } |
Chris Metcalf | c8c6698 | 2009-12-28 10:00:15 -0500 | [diff] [blame] | 1021 | #elif defined(TILE) |
Chris Metcalf | c8c6698 | 2009-12-28 10:00:15 -0500 | [diff] [blame] | 1022 | if (entering(tcp)) { |
Denys Vlasenko | 56a5298 | 2011-06-09 01:36:29 +0200 | [diff] [blame] | 1023 | struct ucontext uc; |
Denys Vlasenko | 56a5298 | 2011-06-09 01:36:29 +0200 | [diff] [blame] | 1024 | |
| 1025 | /* offset of ucontext in the kernel's sigframe structure */ |
Chris Metcalf | 5c0796f | 2013-05-21 20:25:22 -0400 | [diff] [blame] | 1026 | # define SIGFRAME_UC_OFFSET C_ABI_SAVE_AREA_SIZE + sizeof(siginfo_t) |
Chris Metcalf | 0b99a8a | 2013-02-05 17:48:33 +0100 | [diff] [blame] | 1027 | if (umove(tcp, tile_regs.sp + SIGFRAME_UC_OFFSET, &uc) < 0) |
Chris Metcalf | c8c6698 | 2009-12-28 10:00:15 -0500 | [diff] [blame] | 1028 | return 0; |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 1029 | tprintsigmask_val(") (mask ", uc.uc_sigmask); |
Chris Metcalf | c8c6698 | 2009-12-28 10:00:15 -0500 | [diff] [blame] | 1030 | } |
Edgar E. Iglesias | 939caba | 2010-07-06 14:21:07 +0200 | [diff] [blame] | 1031 | #elif defined(MICROBLAZE) |
Edgar E. Iglesias | 939caba | 2010-07-06 14:21:07 +0200 | [diff] [blame] | 1032 | /* TODO: Verify that this is correct... */ |
| 1033 | if (entering(tcp)) { |
Denys Vlasenko | 56a5298 | 2011-06-09 01:36:29 +0200 | [diff] [blame] | 1034 | struct sigcontext sc; |
Edgar E. Iglesias | 939caba | 2010-07-06 14:21:07 +0200 | [diff] [blame] | 1035 | long sp; |
Edgar E. Iglesias | 939caba | 2010-07-06 14:21:07 +0200 | [diff] [blame] | 1036 | /* Read r1, the stack pointer. */ |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1037 | if (upeek(tcp->pid, 1 * 4, &sp) < 0) |
Edgar E. Iglesias | 939caba | 2010-07-06 14:21:07 +0200 | [diff] [blame] | 1038 | return 0; |
| 1039 | if (umove(tcp, sp, &sc) < 0) |
| 1040 | return 0; |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 1041 | tprintsigmask_val(") (mask ", sc.oldmask); |
Edgar E. Iglesias | 939caba | 2010-07-06 14:21:07 +0200 | [diff] [blame] | 1042 | } |
Chris Zankel | 8f636ed | 2013-03-25 10:22:07 -0700 | [diff] [blame] | 1043 | #elif defined(XTENSA) |
| 1044 | /* Xtensa only has rt_sys_sigreturn */ |
Vineet Gupta | 7daacbb | 2013-08-16 12:47:06 +0530 | [diff] [blame] | 1045 | #elif defined(ARC) |
| 1046 | /* ARC syscall ABI only supports rt_sys_sigreturn */ |
Wichert Akkerman | c1652e2 | 2001-03-27 12:17:16 +0000 | [diff] [blame] | 1047 | #else |
Dmitry V. Levin | f112d07 | 2012-05-15 00:13:59 +0000 | [diff] [blame] | 1048 | # warning No sys_sigreturn() for this architecture |
| 1049 | # warning (no problem, just a reminder :-) |
Denys Vlasenko | ea0e6e8 | 2009-02-25 17:08:40 +0000 | [diff] [blame] | 1050 | #endif |
Dmitry V. Levin | f112d07 | 2012-05-15 00:13:59 +0000 | [diff] [blame] | 1051 | return 0; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 1055 | sys_siggetmask(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1056 | { |
| 1057 | if (exiting(tcp)) { |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 1058 | tcp->auxstr = sprintsigmask_val("mask ", tcp->u_rval); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1059 | } |
| 1060 | return RVAL_HEX | RVAL_STR; |
| 1061 | } |
| 1062 | |
| 1063 | int |
Dmitry V. Levin | e5e6085 | 2009-12-31 22:50:49 +0000 | [diff] [blame] | 1064 | sys_sigsuspend(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1065 | { |
| 1066 | if (entering(tcp)) { |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 1067 | tprintsigmask_val("", tcp->u_arg[2]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1068 | } |
| 1069 | return 0; |
| 1070 | } |
| 1071 | |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 1072 | #if !defined SS_ONSTACK |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1073 | #define SS_ONSTACK 1 |
| 1074 | #define SS_DISABLE 2 |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1075 | #endif |
| 1076 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 1077 | static const struct xlat sigaltstack_flags[] = { |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 1078 | XLAT(SS_ONSTACK), |
| 1079 | XLAT(SS_DISABLE), |
Dmitry V. Levin | 5945273 | 2014-02-05 02:20:51 +0000 | [diff] [blame] | 1080 | XLAT_END |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1081 | }; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1082 | |
Dmitry V. Levin | 338c069 | 2013-02-09 02:03:04 +0000 | [diff] [blame] | 1083 | static void |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 1084 | print_stack_t(struct tcb *tcp, unsigned long addr) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1085 | { |
| 1086 | stack_t ss; |
Dmitry V. Levin | d153bfc | 2014-02-26 22:29:27 +0000 | [diff] [blame^] | 1087 | int r; |
Dmitry V. Levin | 338c069 | 2013-02-09 02:03:04 +0000 | [diff] [blame] | 1088 | |
| 1089 | if (!addr) { |
| 1090 | tprints("NULL"); |
Dmitry V. Levin | d153bfc | 2014-02-26 22:29:27 +0000 | [diff] [blame^] | 1091 | return; |
| 1092 | } |
| 1093 | |
| 1094 | #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 |
| 1095 | if (current_wordsize != sizeof(ss.ss_sp) && current_wordsize == 4) { |
| 1096 | struct { |
| 1097 | uint32_t ss_sp; |
| 1098 | int32_t ss_flags; |
| 1099 | uint32_t ss_size; |
| 1100 | } ss32; |
| 1101 | r = umove(tcp, addr, &ss32); |
| 1102 | if (r >= 0) { |
| 1103 | memset(&ss, 0, sizeof(ss)); |
| 1104 | ss.ss_sp = (void*)(unsigned long) ss32.ss_sp; |
| 1105 | ss.ss_flags = ss32.ss_flags; |
| 1106 | ss.ss_size = (unsigned long) ss32.ss_size; |
| 1107 | } |
| 1108 | } else |
| 1109 | #endif |
| 1110 | { |
| 1111 | r = umove(tcp, addr, &ss); |
| 1112 | } |
| 1113 | if (r < 0) { |
Dmitry V. Levin | 338c069 | 2013-02-09 02:03:04 +0000 | [diff] [blame] | 1114 | tprintf("%#lx", addr); |
| 1115 | } else { |
| 1116 | tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp); |
| 1117 | printflags(sigaltstack_flags, ss.ss_flags, "SS_???"); |
| 1118 | tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size); |
| 1119 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 1123 | sys_sigaltstack(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1124 | { |
| 1125 | if (entering(tcp)) { |
Dmitry V. Levin | 338c069 | 2013-02-09 02:03:04 +0000 | [diff] [blame] | 1126 | print_stack_t(tcp, tcp->u_arg[0]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1127 | } |
| 1128 | else { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1129 | tprints(", "); |
Dmitry V. Levin | 338c069 | 2013-02-09 02:03:04 +0000 | [diff] [blame] | 1130 | print_stack_t(tcp, tcp->u_arg[1]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1131 | } |
| 1132 | return 0; |
| 1133 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1134 | |
| 1135 | #ifdef HAVE_SIGACTION |
| 1136 | |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 1137 | /* "Old" sigprocmask, which operates with word-sized signal masks */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1138 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 1139 | sys_sigprocmask(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1140 | { |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 1141 | # ifdef ALPHA |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1142 | if (entering(tcp)) { |
Mike Frysinger | dde045c | 2012-03-15 00:45:33 -0400 | [diff] [blame] | 1143 | /* |
| 1144 | * Alpha/OSF is different: it doesn't pass in two pointers, |
| 1145 | * but rather passes in the new bitmask as an argument and |
| 1146 | * then returns the old bitmask. This "works" because we |
| 1147 | * only have 64 signals to worry about. If you want more, |
| 1148 | * use of the rt_sigprocmask syscall is required. |
| 1149 | * Alpha: |
| 1150 | * old = osf_sigprocmask(how, new); |
| 1151 | * Everyone else: |
| 1152 | * ret = sigprocmask(how, &new, &old, ...); |
| 1153 | */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1154 | printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???"); |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 1155 | tprintsigmask_val(", ", tcp->u_arg[1]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1156 | } |
| 1157 | else if (!syserror(tcp)) { |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 1158 | tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1159 | return RVAL_HEX | RVAL_STR; |
| 1160 | } |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 1161 | # else /* !ALPHA */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1162 | if (entering(tcp)) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1163 | printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1164 | tprints(", "); |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 1165 | print_sigset_addr_len(tcp, tcp->u_arg[1], current_wordsize); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1166 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1167 | } |
| 1168 | else { |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 1169 | if (syserror(tcp)) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1170 | tprintf("%#lx", tcp->u_arg[2]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1171 | else |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 1172 | print_sigset_addr_len(tcp, tcp->u_arg[2], current_wordsize); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1173 | } |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 1174 | # endif /* !ALPHA */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1175 | return 0; |
| 1176 | } |
| 1177 | |
| 1178 | #endif /* HAVE_SIGACTION */ |
| 1179 | |
| 1180 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 1181 | sys_kill(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1182 | { |
| 1183 | if (entering(tcp)) { |
Denys Vlasenko | e015d2d | 2013-02-15 14:58:52 +0100 | [diff] [blame] | 1184 | tprintf("%ld, %s", |
| 1185 | widen_to_long(tcp->u_arg[0]), |
| 1186 | signame(tcp->u_arg[1]) |
| 1187 | ); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1188 | } |
| 1189 | return 0; |
| 1190 | } |
| 1191 | |
Roland McGrath | 8ffc352 | 2003-07-09 09:47:49 +0000 | [diff] [blame] | 1192 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 1193 | sys_tgkill(struct tcb *tcp) |
Roland McGrath | 8ffc352 | 2003-07-09 09:47:49 +0000 | [diff] [blame] | 1194 | { |
| 1195 | if (entering(tcp)) { |
| 1196 | tprintf("%ld, %ld, %s", |
Denys Vlasenko | e015d2d | 2013-02-15 14:58:52 +0100 | [diff] [blame] | 1197 | widen_to_long(tcp->u_arg[0]), |
| 1198 | widen_to_long(tcp->u_arg[1]), |
| 1199 | signame(tcp->u_arg[2]) |
| 1200 | ); |
Roland McGrath | 8ffc352 | 2003-07-09 09:47:49 +0000 | [diff] [blame] | 1201 | } |
| 1202 | return 0; |
| 1203 | } |
Roland McGrath | 8ffc352 | 2003-07-09 09:47:49 +0000 | [diff] [blame] | 1204 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1205 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 1206 | sys_sigpending(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1207 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1208 | if (exiting(tcp)) { |
| 1209 | if (syserror(tcp)) |
| 1210 | tprintf("%#lx", tcp->u_arg[0]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1211 | else |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 1212 | print_sigset_addr_len(tcp, tcp->u_arg[0], current_wordsize); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1213 | } |
| 1214 | return 0; |
| 1215 | } |
| 1216 | |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 1217 | int |
| 1218 | sys_rt_sigprocmask(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1219 | { |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 1220 | /* Note: arg[3] is the length of the sigset. Kernel requires NSIG / 8 */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1221 | if (entering(tcp)) { |
| 1222 | printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1223 | tprints(", "); |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 1224 | print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[3]); |
| 1225 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1226 | } |
| 1227 | else { |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 1228 | if (syserror(tcp)) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1229 | tprintf("%#lx", tcp->u_arg[2]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1230 | else |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 1231 | print_sigset_addr_len(tcp, tcp->u_arg[2], tcp->u_arg[3]); |
Nate Sammons | dab325a | 1999-03-29 23:33:35 +0000 | [diff] [blame] | 1232 | tprintf(", %lu", tcp->u_arg[3]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1233 | } |
| 1234 | return 0; |
| 1235 | } |
| 1236 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1237 | /* Structure describing the action to be taken when a signal arrives. */ |
| 1238 | struct new_sigaction |
| 1239 | { |
Denys Vlasenko | 86d9484 | 2013-02-08 12:59:13 +0100 | [diff] [blame] | 1240 | /* sa_handler may be a libc #define, need to use other name: */ |
Chris Dearman | 2b4bb1c | 2013-12-09 19:58:42 -0800 | [diff] [blame] | 1241 | #ifdef MIPS |
| 1242 | unsigned int sa_flags; |
| 1243 | void (*__sa_handler)(int); |
| 1244 | #else |
Denys Vlasenko | 86d9484 | 2013-02-08 12:59:13 +0100 | [diff] [blame] | 1245 | void (*__sa_handler)(int); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1246 | unsigned long sa_flags; |
Denys Vlasenko | 86d9484 | 2013-02-08 12:59:13 +0100 | [diff] [blame] | 1247 | void (*sa_restorer)(void); |
Chris Dearman | 2b4bb1c | 2013-12-09 19:58:42 -0800 | [diff] [blame] | 1248 | #endif /* !MIPS */ |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 1249 | /* Kernel treats sa_mask as an array of longs. */ |
| 1250 | unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1]; |
| 1251 | }; |
| 1252 | /* Same for i386-on-x86_64 and similar cases */ |
| 1253 | struct new_sigaction32 |
| 1254 | { |
| 1255 | uint32_t __sa_handler; |
| 1256 | uint32_t sa_flags; |
| 1257 | uint32_t sa_restorer; |
| 1258 | uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)]; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1259 | }; |
| 1260 | |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 1261 | static void |
| 1262 | decode_new_sigaction(struct tcb *tcp, long addr) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1263 | { |
| 1264 | struct new_sigaction sa; |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 1265 | int r; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1266 | |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 1267 | if (!addr) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1268 | tprints("NULL"); |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 1269 | return; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1270 | } |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 1271 | if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) { |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 1272 | tprintf("%#lx", addr); |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 1273 | return; |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 1274 | } |
Denys Vlasenko | d4d3ede | 2013-02-13 16:31:32 +0100 | [diff] [blame] | 1275 | #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 1276 | if (current_wordsize != sizeof(sa.sa_flags) && current_wordsize == 4) { |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 1277 | struct new_sigaction32 sa32; |
| 1278 | r = umove(tcp, addr, &sa32); |
| 1279 | if (r >= 0) { |
| 1280 | memset(&sa, 0, sizeof(sa)); |
| 1281 | sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler; |
| 1282 | sa.sa_flags = sa32.sa_flags; |
| 1283 | sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer; |
| 1284 | /* Kernel treats sa_mask as an array of longs. |
| 1285 | * For 32-bit process, "long" is uint32_t, thus, for example, |
| 1286 | * 32th bit in sa_mask will end up as bit 0 in sa_mask[1]. |
| 1287 | * But for (64-bit) kernel, 32th bit in sa_mask is |
| 1288 | * 32th bit in 0th (64-bit) long! |
| 1289 | * For little-endian, it's the same. |
| 1290 | * For big-endian, we swap 32-bit words. |
| 1291 | */ |
| 1292 | sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32); |
| 1293 | } |
| 1294 | } else |
| 1295 | #endif |
| 1296 | { |
| 1297 | r = umove(tcp, addr, &sa); |
| 1298 | } |
| 1299 | if (r < 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1300 | tprints("{...}"); |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 1301 | return; |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 1302 | } |
Carlos O'Donell | 4677c8a | 2009-09-09 18:13:19 +0000 | [diff] [blame] | 1303 | /* Architectures using function pointers, like |
| 1304 | * hppa, may need to manipulate the function pointer |
| 1305 | * to compute the result of a comparison. However, |
Denys Vlasenko | 86d9484 | 2013-02-08 12:59:13 +0100 | [diff] [blame] | 1306 | * the __sa_handler function pointer exists only in |
Carlos O'Donell | 4677c8a | 2009-09-09 18:13:19 +0000 | [diff] [blame] | 1307 | * the address space of the traced process, and can't |
| 1308 | * be manipulated by strace. In order to prevent the |
| 1309 | * compiler from generating code to manipulate |
Denys Vlasenko | 86d9484 | 2013-02-08 12:59:13 +0100 | [diff] [blame] | 1310 | * __sa_handler we cast the function pointers to long. */ |
Carlos O'Donell | 4677c8a | 2009-09-09 18:13:19 +0000 | [diff] [blame] | 1311 | if ((long)sa.__sa_handler == (long)SIG_ERR) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1312 | tprints("{SIG_ERR, "); |
Carlos O'Donell | 4677c8a | 2009-09-09 18:13:19 +0000 | [diff] [blame] | 1313 | else if ((long)sa.__sa_handler == (long)SIG_DFL) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1314 | tprints("{SIG_DFL, "); |
Carlos O'Donell | 4677c8a | 2009-09-09 18:13:19 +0000 | [diff] [blame] | 1315 | else if ((long)sa.__sa_handler == (long)SIG_IGN) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1316 | tprints("{SIG_IGN, "); |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 1317 | else |
| 1318 | tprintf("{%#lx, ", (long) sa.__sa_handler); |
Denys Vlasenko | 80b73a2 | 2013-07-18 10:10:46 +0200 | [diff] [blame] | 1319 | /* |
| 1320 | * Sigset size is in tcp->u_arg[4] (SPARC) |
| 1321 | * or in tcp->u_arg[3] (all other), |
| 1322 | * but kernel won't handle sys_rt_sigaction |
| 1323 | * with wrong sigset size (just returns EINVAL instead). |
| 1324 | * We just fetch the right size, which is NSIG / 8. |
| 1325 | */ |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 1326 | tprintsigmask_val("", sa.sa_mask); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1327 | tprints(", "); |
Denys Vlasenko | 80b73a2 | 2013-07-18 10:10:46 +0200 | [diff] [blame] | 1328 | |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 1329 | printflags(sigact_flags, sa.sa_flags, "SA_???"); |
| 1330 | #ifdef SA_RESTORER |
| 1331 | if (sa.sa_flags & SA_RESTORER) |
| 1332 | tprintf(", %p", sa.sa_restorer); |
| 1333 | #endif |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1334 | tprints("}"); |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 1335 | } |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 1336 | |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 1337 | int |
| 1338 | sys_rt_sigaction(struct tcb *tcp) |
| 1339 | { |
| 1340 | if (entering(tcp)) { |
| 1341 | printsignal(tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1342 | tprints(", "); |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 1343 | decode_new_sigaction(tcp, tcp->u_arg[1]); |
| 1344 | tprints(", "); |
| 1345 | } else { |
| 1346 | decode_new_sigaction(tcp, tcp->u_arg[2]); |
Denys Vlasenko | 9472a27 | 2013-02-12 11:43:46 +0100 | [diff] [blame] | 1347 | #if defined(SPARC) || defined(SPARC64) |
Wichert Akkerman | dacfb6e | 1999-06-03 14:21:07 +0000 | [diff] [blame] | 1348 | tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]); |
| 1349 | #elif defined(ALPHA) |
| 1350 | tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]); |
| 1351 | #else |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 1352 | tprintf(", %lu", tcp->u_arg[3]); |
Wichert Akkerman | dacfb6e | 1999-06-03 14:21:07 +0000 | [diff] [blame] | 1353 | #endif |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 1354 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1355 | return 0; |
| 1356 | } |
| 1357 | |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 1358 | int |
| 1359 | sys_rt_sigpending(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1360 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1361 | if (exiting(tcp)) { |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 1362 | /* |
| 1363 | * One of the few syscalls where sigset size (arg[1]) |
| 1364 | * is allowed to be <= NSIG / 8, not strictly ==. |
| 1365 | * This allows non-rt sigpending() syscall |
| 1366 | * to reuse rt_sigpending() code in kernel. |
| 1367 | */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1368 | if (syserror(tcp)) |
| 1369 | tprintf("%#lx", tcp->u_arg[0]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1370 | else |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 1371 | print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]); |
| 1372 | tprintf(", %lu", tcp->u_arg[1]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1373 | } |
| 1374 | return 0; |
| 1375 | } |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 1376 | |
| 1377 | int |
| 1378 | sys_rt_sigsuspend(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1379 | { |
| 1380 | if (entering(tcp)) { |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 1381 | /* NB: kernel requires arg[1] == NSIG / 8 */ |
| 1382 | print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]); |
| 1383 | tprintf(", %lu", tcp->u_arg[1]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1384 | } |
| 1385 | return 0; |
| 1386 | } |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 1387 | |
Dmitry V. Levin | 297632b | 2012-03-13 15:51:13 +0000 | [diff] [blame] | 1388 | static void |
| 1389 | print_sigqueueinfo(struct tcb *tcp, int sig, unsigned long uinfo) |
| 1390 | { |
Dmitry V. Levin | 297632b | 2012-03-13 15:51:13 +0000 | [diff] [blame] | 1391 | printsignal(sig); |
| 1392 | tprints(", "); |
Denys Vlasenko | d4d3ede | 2013-02-13 16:31:32 +0100 | [diff] [blame] | 1393 | printsiginfo_at(tcp, uinfo); |
Dmitry V. Levin | 297632b | 2012-03-13 15:51:13 +0000 | [diff] [blame] | 1394 | } |
| 1395 | |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 1396 | int |
| 1397 | sys_rt_sigqueueinfo(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1398 | { |
| 1399 | if (entering(tcp)) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1400 | tprintf("%lu, ", tcp->u_arg[0]); |
Dmitry V. Levin | 297632b | 2012-03-13 15:51:13 +0000 | [diff] [blame] | 1401 | print_sigqueueinfo(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 1402 | } |
| 1403 | return 0; |
| 1404 | } |
| 1405 | |
| 1406 | int |
| 1407 | sys_rt_tgsigqueueinfo(struct tcb *tcp) |
| 1408 | { |
| 1409 | if (entering(tcp)) { |
| 1410 | tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]); |
| 1411 | print_sigqueueinfo(tcp, tcp->u_arg[2], tcp->u_arg[3]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1412 | } |
| 1413 | return 0; |
| 1414 | } |
| 1415 | |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 1416 | int sys_rt_sigtimedwait(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1417 | { |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 1418 | /* NB: kernel requires arg[3] == NSIG / 8 */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1419 | if (entering(tcp)) { |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 1420 | print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[3]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1421 | tprints(", "); |
Denys Vlasenko | b1a78cf | 2009-04-15 13:31:59 +0000 | [diff] [blame] | 1422 | /* This is the only "return" parameter, */ |
| 1423 | if (tcp->u_arg[1] != 0) |
| 1424 | return 0; |
| 1425 | /* ... if it's NULL, can decode all on entry */ |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1426 | tprints("NULL, "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1427 | } |
Denys Vlasenko | b1a78cf | 2009-04-15 13:31:59 +0000 | [diff] [blame] | 1428 | else if (tcp->u_arg[1] != 0) { |
| 1429 | /* syscall exit, and u_arg[1] wasn't NULL */ |
Denys Vlasenko | d4d3ede | 2013-02-13 16:31:32 +0100 | [diff] [blame] | 1430 | printsiginfo_at(tcp, tcp->u_arg[1]); |
| 1431 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1432 | } |
Denys Vlasenko | b1a78cf | 2009-04-15 13:31:59 +0000 | [diff] [blame] | 1433 | else { |
| 1434 | /* syscall exit, and u_arg[1] was NULL */ |
| 1435 | return 0; |
| 1436 | } |
| 1437 | print_timespec(tcp, tcp->u_arg[2]); |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 1438 | tprintf(", %lu", tcp->u_arg[3]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1439 | return 0; |
| 1440 | }; |
| 1441 | |
Roland McGrath | 79dcd7a | 2006-01-12 22:34:50 +0000 | [diff] [blame] | 1442 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 1443 | sys_restart_syscall(struct tcb *tcp) |
Roland McGrath | 79dcd7a | 2006-01-12 22:34:50 +0000 | [diff] [blame] | 1444 | { |
| 1445 | if (entering(tcp)) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1446 | tprints("<... resuming interrupted call ...>"); |
Roland McGrath | 79dcd7a | 2006-01-12 22:34:50 +0000 | [diff] [blame] | 1447 | return 0; |
| 1448 | } |
| 1449 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 1450 | static int |
| 1451 | do_signalfd(struct tcb *tcp, int flags_arg) |
Roland McGrath | f46ccd3 | 2007-08-02 01:15:59 +0000 | [diff] [blame] | 1452 | { |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 1453 | /* NB: kernel requires arg[2] == NSIG / 8 */ |
Roland McGrath | f46ccd3 | 2007-08-02 01:15:59 +0000 | [diff] [blame] | 1454 | if (entering(tcp)) { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 1455 | printfd(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1456 | tprints(", "); |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 1457 | print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
Dmitry V. Levin | 9d2ee3d | 2009-10-05 13:45:19 +0000 | [diff] [blame] | 1458 | tprintf(", %lu", tcp->u_arg[2]); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 1459 | if (flags_arg >= 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1460 | tprints(", "); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 1461 | printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???"); |
| 1462 | } |
Roland McGrath | f46ccd3 | 2007-08-02 01:15:59 +0000 | [diff] [blame] | 1463 | } |
| 1464 | return 0; |
| 1465 | } |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 1466 | |
| 1467 | int |
| 1468 | sys_signalfd(struct tcb *tcp) |
| 1469 | { |
| 1470 | return do_signalfd(tcp, -1); |
| 1471 | } |
| 1472 | |
| 1473 | int |
| 1474 | sys_signalfd4(struct tcb *tcp) |
| 1475 | { |
| 1476 | return do_signalfd(tcp, 3); |
| 1477 | } |