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" |
Denys Vlasenko | 041b3ee | 2011-08-18 12:48:56 +0200 | [diff] [blame] | 35 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 36 | #ifndef NSIG |
Dmitry V. Levin | 74219ea | 2015-03-06 01:47:18 +0000 | [diff] [blame] | 37 | # warning NSIG is not defined, using 32 |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 38 | # define NSIG 32 |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 39 | #elif NSIG < 32 |
Dmitry V. Levin | 74219ea | 2015-03-06 01:47:18 +0000 | [diff] [blame] | 40 | # error NSIG < 32 |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 41 | #endif |
Denys Vlasenko | 041b3ee | 2011-08-18 12:48:56 +0200 | [diff] [blame] | 42 | |
Roland McGrath | 2638cb4 | 2002-12-15 23:58:41 +0000 | [diff] [blame] | 43 | /* 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] | 44 | used by the implementation. So we define it here. */ |
Dmitry V. Levin | 5c7f627 | 2014-02-08 00:26:06 +0000 | [diff] [blame] | 45 | #ifndef SA_RESTORER |
| 46 | # ifdef ASM_SA_RESTORER |
| 47 | # define SA_RESTORER ASM_SA_RESTORER |
Roland McGrath | 2638cb4 | 2002-12-15 23:58:41 +0000 | [diff] [blame] | 48 | # endif |
| 49 | #endif |
| 50 | |
Dmitry V. Levin | 24b8eb0 | 2015-02-28 17:17:09 +0000 | [diff] [blame] | 51 | /* |
| 52 | * Some architectures define SA_RESTORER in their headers, |
| 53 | * but do not actually have sa_restorer. |
| 54 | * |
| 55 | * Some architectures, otherwise, do not define SA_RESTORER in their headers, |
| 56 | * but actually have sa_restorer. |
| 57 | */ |
| 58 | #ifdef SA_RESTORER |
| 59 | # if defined HPPA || defined IA64 |
| 60 | # define HAVE_SA_RESTORER 0 |
| 61 | # else |
| 62 | # define HAVE_SA_RESTORER 1 |
| 63 | # endif |
| 64 | #else /* !SA_RESTORER */ |
Andreas Schwab | a897136 | 2015-03-11 14:15:34 +0100 | [diff] [blame] | 65 | # if defined SPARC || defined SPARC64 || defined M68K |
Dmitry V. Levin | 24b8eb0 | 2015-02-28 17:17:09 +0000 | [diff] [blame] | 66 | # define HAVE_SA_RESTORER 1 |
| 67 | # else |
| 68 | # define HAVE_SA_RESTORER 0 |
| 69 | # endif |
Mike Frysinger | d632e10 | 2014-08-09 09:04:18 -0400 | [diff] [blame] | 70 | #endif |
| 71 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 72 | #include "xlat/sigact_flags.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 73 | #include "xlat/sigprocmaskcmds.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 74 | |
Nate Sammons | ce780fc | 1999-03-29 23:23:13 +0000 | [diff] [blame] | 75 | /* Anonymous realtime signals. */ |
Dmitry V. Levin | 59f63d3 | 2015-03-05 05:03:41 +0000 | [diff] [blame] | 76 | #ifndef ASM_SIGRTMIN |
| 77 | /* Linux kernel >= 3.18 defines SIGRTMIN to 32 on all architectures. */ |
| 78 | # define ASM_SIGRTMIN 32 |
Nate Sammons | ce780fc | 1999-03-29 23:23:13 +0000 | [diff] [blame] | 79 | #endif |
Dmitry V. Levin | 59f63d3 | 2015-03-05 05:03:41 +0000 | [diff] [blame] | 80 | #ifndef ASM_SIGRTMAX |
| 81 | /* Under glibc 2.1, SIGRTMAX et al are functions, but __SIGRTMAX is a |
| 82 | constant. This is what we want. Otherwise, just use SIGRTMAX. */ |
| 83 | # ifdef SIGRTMAX |
| 84 | # ifndef __SIGRTMAX |
| 85 | # define __SIGRTMAX SIGRTMAX |
| 86 | # endif |
| 87 | # endif |
| 88 | # ifdef __SIGRTMAX |
| 89 | # define ASM_SIGRTMAX __SIGRTMAX |
| 90 | # endif |
Nate Sammons | ce780fc | 1999-03-29 23:23:13 +0000 | [diff] [blame] | 91 | #endif |
| 92 | |
Denys Vlasenko | d9560c1 | 2011-08-19 17:41:28 +0200 | [diff] [blame] | 93 | /* Note on the size of sigset_t: |
| 94 | * |
| 95 | * In glibc, sigset_t is an array with space for 1024 bits (!), |
| 96 | * even though all arches supported by Linux have only 64 signals |
| 97 | * except MIPS, which has 128. IOW, it is 128 bytes long. |
| 98 | * |
| 99 | * In-kernel sigset_t is sized correctly (it is either 64 or 128 bit long). |
| 100 | * However, some old syscall return only 32 lower bits (one word). |
| 101 | * Example: sys_sigpending vs sys_rt_sigpending. |
| 102 | * |
| 103 | * Be aware of this fact when you try to |
| 104 | * memcpy(&tcp->u_arg[1], &something, sizeof(sigset_t)) |
| 105 | * - sizeof(sigset_t) is much bigger than you think, |
| 106 | * it may overflow tcp->u_arg[] array, and it may try to copy more data |
| 107 | * than is really available in <something>. |
| 108 | * Similarly, |
| 109 | * umoven(tcp, addr, sizeof(sigset_t), &sigset) |
| 110 | * may be a bad idea: it'll try to read much more data than needed |
| 111 | * to fetch a sigset_t. |
| 112 | * Use (NSIG / 8) as a size instead. |
| 113 | */ |
| 114 | |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 115 | const char * |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 116 | signame(const int sig) |
Nate Sammons | ce780fc | 1999-03-29 23:23:13 +0000 | [diff] [blame] | 117 | { |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 118 | static char buf[sizeof("SIGRT_%u") + sizeof(int)*3]; |
Denys Vlasenko | 041b3ee | 2011-08-18 12:48:56 +0200 | [diff] [blame] | 119 | |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 120 | if (sig >= 0) { |
| 121 | const unsigned int s = sig; |
| 122 | |
| 123 | if (s < nsignals) |
| 124 | return signalent[s]; |
Dmitry V. Levin | 59f63d3 | 2015-03-05 05:03:41 +0000 | [diff] [blame] | 125 | #ifdef ASM_SIGRTMAX |
| 126 | if (s >= ASM_SIGRTMIN && s <= ASM_SIGRTMAX) { |
| 127 | sprintf(buf, "SIGRT_%u", s - ASM_SIGRTMIN); |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 128 | return buf; |
| 129 | } |
Denys Vlasenko | 041b3ee | 2011-08-18 12:48:56 +0200 | [diff] [blame] | 130 | #endif |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 131 | } |
Denys Vlasenko | 041b3ee | 2011-08-18 12:48:56 +0200 | [diff] [blame] | 132 | sprintf(buf, "%d", sig); |
| 133 | return buf; |
Nate Sammons | ce780fc | 1999-03-29 23:23:13 +0000 | [diff] [blame] | 134 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 135 | |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 136 | static unsigned int |
| 137 | popcount32(const uint32_t *a, unsigned int size) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 138 | { |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 139 | unsigned int count = 0; |
Denys Vlasenko | d9560c1 | 2011-08-19 17:41:28 +0200 | [diff] [blame] | 140 | |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 141 | for (; size; ++a, --size) { |
| 142 | uint32_t x = *a; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 143 | |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 144 | #ifdef HAVE___BUILTIN_POPCOUNT |
| 145 | count += __builtin_popcount(x); |
Denys Vlasenko | a877379 | 2013-07-18 20:42:41 +0200 | [diff] [blame] | 146 | #else |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 147 | for (; x; ++count) |
| 148 | x &= x - 1; |
Nate Sammons | 4a12143 | 1999-04-06 01:19:39 +0000 | [diff] [blame] | 149 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 150 | } |
Denys Vlasenko | 4f3df07 | 2012-01-29 22:38:35 +0100 | [diff] [blame] | 151 | |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 152 | return count; |
| 153 | } |
| 154 | |
Dmitry V. Levin | 74219ea | 2015-03-06 01:47:18 +0000 | [diff] [blame] | 155 | const char * |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 156 | sprintsigmask_n(const char *prefix, const void *sig_mask, unsigned int bytes) |
| 157 | { |
| 158 | /* |
| 159 | * The maximum number of signal names to be printed is NSIG * 2 / 3. |
| 160 | * Most of signal names have length 7, |
| 161 | * average length of signal names is less than 7. |
| 162 | * The length of prefix string does not exceed 16. |
| 163 | */ |
| 164 | static char outstr[128 + 8 * (NSIG * 2 / 3)]; |
| 165 | |
| 166 | char *s; |
| 167 | const uint32_t *mask; |
| 168 | uint32_t inverted_mask[NSIG / 32]; |
| 169 | unsigned int size; |
| 170 | int i; |
| 171 | char sep; |
| 172 | |
| 173 | s = stpcpy(outstr, prefix); |
| 174 | |
| 175 | mask = sig_mask; |
| 176 | /* length of signal mask in 4-byte words */ |
| 177 | size = (bytes >= NSIG / 8) ? NSIG / 32 : (bytes + 3) / 4; |
| 178 | |
| 179 | /* check whether 2/3 or more bits are set */ |
| 180 | if (popcount32(mask, size) >= size * 32 * 2 / 3) { |
| 181 | /* show those signals that are NOT in the mask */ |
| 182 | unsigned int j; |
| 183 | for (j = 0; j < size; ++j) |
| 184 | inverted_mask[j] = ~mask[j]; |
| 185 | mask = inverted_mask; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 186 | *s++ = '~'; |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 187 | } |
Denys Vlasenko | 4f3df07 | 2012-01-29 22:38:35 +0100 | [diff] [blame] | 188 | |
| 189 | sep = '['; |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 190 | for (i = 0; (i = next_set_bit(mask, i, size * 32)) >= 0; ) { |
| 191 | ++i; |
| 192 | *s++ = sep; |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 193 | if ((unsigned) i < nsignals) { |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 194 | s = stpcpy(s, signalent[i] + 3); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 195 | } |
Dmitry V. Levin | 59f63d3 | 2015-03-05 05:03:41 +0000 | [diff] [blame] | 196 | #ifdef ASM_SIGRTMAX |
| 197 | else if (i >= ASM_SIGRTMIN && i <= ASM_SIGRTMAX) { |
| 198 | s += sprintf(s, "RT_%u", i - ASM_SIGRTMIN); |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 199 | } |
| 200 | #endif |
| 201 | else { |
| 202 | s += sprintf(s, "%u", i); |
| 203 | } |
| 204 | sep = ' '; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 205 | } |
Denys Vlasenko | 4f3df07 | 2012-01-29 22:38:35 +0100 | [diff] [blame] | 206 | if (sep == '[') |
| 207 | *s++ = sep; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 208 | *s++ = ']'; |
| 209 | *s = '\0'; |
| 210 | return outstr; |
| 211 | } |
| 212 | |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 213 | #define sprintsigmask_val(prefix, mask) \ |
| 214 | sprintsigmask_n((prefix), &(mask), sizeof(mask)) |
| 215 | |
| 216 | #define tprintsigmask_val(prefix, mask) \ |
| 217 | tprints(sprintsigmask_n((prefix), &(mask), sizeof(mask))) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 218 | |
| 219 | void |
Denys Vlasenko | eccc48c | 2011-06-09 01:28:11 +0200 | [diff] [blame] | 220 | printsignal(int nr) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 221 | { |
Denys Vlasenko | 5940e65 | 2011-09-01 09:55:05 +0200 | [diff] [blame] | 222 | tprints(signame(nr)); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 225 | void |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 226 | print_sigset_addr_len(struct tcb *tcp, long addr, long len) |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 227 | { |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 228 | char mask[NSIG / 8]; |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 229 | |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 230 | if (!addr) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 231 | tprints("NULL"); |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 232 | return; |
| 233 | } |
| 234 | /* Here len is usually equals NSIG / 8 or current_wordsize. |
| 235 | * But we code this defensively: |
| 236 | */ |
| 237 | if (len < 0) { |
| 238 | bad: |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 239 | tprintf("%#lx", addr); |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 240 | return; |
| 241 | } |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 242 | if (len >= NSIG / 8) |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 243 | len = NSIG / 8; |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 244 | else |
| 245 | len = (len + 3) & ~3; |
| 246 | |
| 247 | if (umoven(tcp, addr, len, mask) < 0) |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 248 | goto bad; |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 249 | tprints(sprintsigmask_n("", mask, len)); |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 250 | } |
| 251 | |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 252 | #ifndef ILL_ILLOPC |
| 253 | #define ILL_ILLOPC 1 /* illegal opcode */ |
| 254 | #define ILL_ILLOPN 2 /* illegal operand */ |
| 255 | #define ILL_ILLADR 3 /* illegal addressing mode */ |
| 256 | #define ILL_ILLTRP 4 /* illegal trap */ |
| 257 | #define ILL_PRVOPC 5 /* privileged opcode */ |
| 258 | #define ILL_PRVREG 6 /* privileged register */ |
| 259 | #define ILL_COPROC 7 /* coprocessor error */ |
| 260 | #define ILL_BADSTK 8 /* internal stack error */ |
| 261 | #define FPE_INTDIV 1 /* integer divide by zero */ |
| 262 | #define FPE_INTOVF 2 /* integer overflow */ |
| 263 | #define FPE_FLTDIV 3 /* floating point divide by zero */ |
| 264 | #define FPE_FLTOVF 4 /* floating point overflow */ |
| 265 | #define FPE_FLTUND 5 /* floating point underflow */ |
| 266 | #define FPE_FLTRES 6 /* floating point inexact result */ |
| 267 | #define FPE_FLTINV 7 /* floating point invalid operation */ |
| 268 | #define FPE_FLTSUB 8 /* subscript out of range */ |
| 269 | #define SEGV_MAPERR 1 /* address not mapped to object */ |
| 270 | #define SEGV_ACCERR 2 /* invalid permissions for mapped object */ |
| 271 | #define BUS_ADRALN 1 /* invalid address alignment */ |
| 272 | #define BUS_ADRERR 2 /* non-existant physical address */ |
| 273 | #define BUS_OBJERR 3 /* object specific hardware error */ |
Dmitry V. Levin | bc091e3 | 2014-03-11 22:18:40 +0000 | [diff] [blame] | 274 | #define SYS_SECCOMP 1 /* seccomp triggered */ |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 275 | #define TRAP_BRKPT 1 /* process breakpoint */ |
| 276 | #define TRAP_TRACE 2 /* process trace trap */ |
| 277 | #define CLD_EXITED 1 /* child has exited */ |
| 278 | #define CLD_KILLED 2 /* child was killed */ |
| 279 | #define CLD_DUMPED 3 /* child terminated abnormally */ |
| 280 | #define CLD_TRAPPED 4 /* traced child has trapped */ |
| 281 | #define CLD_STOPPED 5 /* child has stopped */ |
| 282 | #define CLD_CONTINUED 6 /* stopped child has continued */ |
| 283 | #define POLL_IN 1 /* data input available */ |
| 284 | #define POLL_OUT 2 /* output buffers available */ |
| 285 | #define POLL_MSG 3 /* input message available */ |
| 286 | #define POLL_ERR 4 /* i/o error */ |
| 287 | #define POLL_PRI 5 /* high priority input available */ |
| 288 | #define POLL_HUP 6 /* device disconnected */ |
Dmitry V. Levin | 7d4bff1 | 2011-03-10 21:41:34 +0000 | [diff] [blame] | 289 | #define SI_KERNEL 0x80 /* sent by kernel */ |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 290 | #define SI_USER 0 /* sent by kill, sigsend, raise */ |
| 291 | #define SI_QUEUE -1 /* sent by sigqueue */ |
| 292 | #define SI_TIMER -2 /* sent by timer expiration */ |
| 293 | #define SI_MESGQ -3 /* sent by real time mesq state change */ |
| 294 | #define SI_ASYNCIO -4 /* sent by AIO completion */ |
Dmitry V. Levin | 7d4bff1 | 2011-03-10 21:41:34 +0000 | [diff] [blame] | 295 | #define SI_SIGIO -5 /* sent by SIGIO */ |
| 296 | #define SI_TKILL -6 /* sent by tkill */ |
Dmitry V. Levin | b9d4d21 | 2014-03-11 01:57:02 +0000 | [diff] [blame] | 297 | #define SI_DETHREAD -7 /* sent by execve killing subsidiary threads */ |
Dmitry V. Levin | 7d4bff1 | 2011-03-10 21:41:34 +0000 | [diff] [blame] | 298 | #define SI_ASYNCNL -60 /* sent by asynch name lookup completion */ |
Denys Vlasenko | 2c4fb90 | 2012-03-15 17:24:49 +0100 | [diff] [blame] | 299 | #endif |
Dmitry V. Levin | 6d9e8e8 | 2011-03-10 22:18:56 +0000 | [diff] [blame] | 300 | |
Denys Vlasenko | 2c4fb90 | 2012-03-15 17:24:49 +0100 | [diff] [blame] | 301 | #ifndef SI_FROMUSER |
| 302 | # define SI_FROMUSER(sip) ((sip)->si_code <= 0) |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 303 | #endif |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 304 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 305 | #include "xlat/siginfo_codes.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 306 | #include "xlat/sigill_codes.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 307 | #include "xlat/sigfpe_codes.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 308 | #include "xlat/sigtrap_codes.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 309 | #include "xlat/sigchld_codes.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 310 | #include "xlat/sigpoll_codes.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 311 | #include "xlat/sigprof_codes.h" |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 312 | |
| 313 | #ifdef SIGEMT |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 314 | #include "xlat/sigemt_codes.h" |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 315 | #endif |
| 316 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 317 | #include "xlat/sigsegv_codes.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 318 | #include "xlat/sigbus_codes.h" |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 319 | |
Dmitry V. Levin | bc091e3 | 2014-03-11 22:18:40 +0000 | [diff] [blame] | 320 | #ifndef SYS_SECCOMP |
| 321 | # define SYS_SECCOMP 1 |
| 322 | #endif |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 323 | #include "xlat/sigsys_codes.h" |
Dmitry V. Levin | bc091e3 | 2014-03-11 22:18:40 +0000 | [diff] [blame] | 324 | |
Elliott Hughes | 4dd1e89 | 2014-03-10 19:27:22 +0000 | [diff] [blame] | 325 | static void |
Dmitry V. Levin | 4a524db | 2014-03-11 00:05:19 +0000 | [diff] [blame] | 326 | printsigsource(const siginfo_t *sip) |
| 327 | { |
| 328 | tprintf(", si_pid=%lu, si_uid=%lu", |
| 329 | (unsigned long) sip->si_pid, |
| 330 | (unsigned long) sip->si_uid); |
| 331 | } |
| 332 | |
| 333 | static void |
| 334 | printsigval(const siginfo_t *sip, int verbose) |
Elliott Hughes | 4dd1e89 | 2014-03-10 19:27:22 +0000 | [diff] [blame] | 335 | { |
| 336 | if (!verbose) |
| 337 | tprints(", ..."); |
| 338 | else |
| 339 | tprintf(", si_value={int=%u, ptr=%#lx}", |
| 340 | sip->si_int, |
| 341 | (unsigned long) sip->si_ptr); |
| 342 | } |
| 343 | |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 344 | void |
Dmitry V. Levin | d8890b5 | 2015-02-07 15:47:24 +0000 | [diff] [blame] | 345 | printsiginfo(const siginfo_t *sip, int verbose) |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 346 | { |
Roland McGrath | f9c49b2 | 2004-10-06 22:11:54 +0000 | [diff] [blame] | 347 | const char *code; |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 348 | |
| 349 | if (sip->si_signo == 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 350 | tprints("{}"); |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 351 | return; |
| 352 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 353 | tprints("{si_signo="); |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 354 | printsignal(sip->si_signo); |
| 355 | code = xlookup(siginfo_codes, sip->si_code); |
| 356 | if (!code) { |
| 357 | switch (sip->si_signo) { |
| 358 | case SIGTRAP: |
| 359 | code = xlookup(sigtrap_codes, sip->si_code); |
| 360 | break; |
| 361 | case SIGCHLD: |
| 362 | code = xlookup(sigchld_codes, sip->si_code); |
| 363 | break; |
| 364 | case SIGPOLL: |
| 365 | code = xlookup(sigpoll_codes, sip->si_code); |
| 366 | break; |
| 367 | case SIGPROF: |
| 368 | code = xlookup(sigprof_codes, sip->si_code); |
| 369 | break; |
| 370 | case SIGILL: |
| 371 | code = xlookup(sigill_codes, sip->si_code); |
| 372 | break; |
| 373 | #ifdef SIGEMT |
| 374 | case SIGEMT: |
| 375 | code = xlookup(sigemt_codes, sip->si_code); |
| 376 | break; |
| 377 | #endif |
| 378 | case SIGFPE: |
| 379 | code = xlookup(sigfpe_codes, sip->si_code); |
| 380 | break; |
| 381 | case SIGSEGV: |
| 382 | code = xlookup(sigsegv_codes, sip->si_code); |
| 383 | break; |
| 384 | case SIGBUS: |
| 385 | code = xlookup(sigbus_codes, sip->si_code); |
| 386 | break; |
Dmitry V. Levin | bc091e3 | 2014-03-11 22:18:40 +0000 | [diff] [blame] | 387 | case SIGSYS: |
| 388 | code = xlookup(sigsys_codes, sip->si_code); |
| 389 | break; |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 390 | } |
| 391 | } |
| 392 | if (code) |
| 393 | tprintf(", si_code=%s", code); |
| 394 | else |
| 395 | tprintf(", si_code=%#x", sip->si_code); |
| 396 | #ifdef SI_NOINFO |
| 397 | if (sip->si_code != SI_NOINFO) |
| 398 | #endif |
| 399 | { |
| 400 | if (sip->si_errno) { |
Dmitry V. Levin | b2f8c77 | 2015-02-23 03:10:25 +0000 | [diff] [blame] | 401 | tprints(", si_errno="); |
| 402 | if ((unsigned) sip->si_errno < nerrnos |
| 403 | && errnoent[sip->si_errno]) |
| 404 | tprints(errnoent[sip->si_errno]); |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 405 | else |
Dmitry V. Levin | b2f8c77 | 2015-02-23 03:10:25 +0000 | [diff] [blame] | 406 | tprintf("%d", sip->si_errno); |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 407 | } |
| 408 | #ifdef SI_FROMUSER |
| 409 | if (SI_FROMUSER(sip)) { |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 410 | switch (sip->si_code) { |
Dmitry V. Levin | 6d9e8e8 | 2011-03-10 22:18:56 +0000 | [diff] [blame] | 411 | #ifdef SI_USER |
| 412 | case SI_USER: |
Dmitry V. Levin | 4a524db | 2014-03-11 00:05:19 +0000 | [diff] [blame] | 413 | printsigsource(sip); |
Dmitry V. Levin | 6d9e8e8 | 2011-03-10 22:18:56 +0000 | [diff] [blame] | 414 | break; |
| 415 | #endif |
| 416 | #ifdef SI_TKILL |
| 417 | case SI_TKILL: |
Dmitry V. Levin | 4a524db | 2014-03-11 00:05:19 +0000 | [diff] [blame] | 418 | printsigsource(sip); |
Dmitry V. Levin | 6d9e8e8 | 2011-03-10 22:18:56 +0000 | [diff] [blame] | 419 | break; |
| 420 | #endif |
Dmitry V. Levin | 36ab3d5 | 2015-01-13 09:24:04 +0300 | [diff] [blame] | 421 | #if defined SI_TIMER \ |
| 422 | && defined HAVE_SIGINFO_T_SI_TIMERID && defined HAVE_SIGINFO_T_SI_OVERRUN |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 423 | case SI_TIMER: |
Elliott Hughes | 4dd1e89 | 2014-03-10 19:27:22 +0000 | [diff] [blame] | 424 | tprintf(", si_timerid=%#x, si_overrun=%d", |
| 425 | sip->si_timerid, sip->si_overrun); |
| 426 | printsigval(sip, verbose); |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 427 | break; |
Dmitry V. Levin | 6d9e8e8 | 2011-03-10 22:18:56 +0000 | [diff] [blame] | 428 | #endif |
Dmitry V. Levin | 6d9e8e8 | 2011-03-10 22:18:56 +0000 | [diff] [blame] | 429 | default: |
Dmitry V. Levin | 4a524db | 2014-03-11 00:05:19 +0000 | [diff] [blame] | 430 | printsigsource(sip); |
| 431 | if (sip->si_ptr) |
| 432 | printsigval(sip, verbose); |
Dmitry V. Levin | 6d9e8e8 | 2011-03-10 22:18:56 +0000 | [diff] [blame] | 433 | break; |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 434 | } |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 435 | } |
| 436 | else |
| 437 | #endif /* SI_FROMUSER */ |
| 438 | { |
| 439 | switch (sip->si_signo) { |
| 440 | case SIGCHLD: |
Dmitry V. Levin | 4a524db | 2014-03-11 00:05:19 +0000 | [diff] [blame] | 441 | printsigsource(sip); |
| 442 | tprints(", si_status="); |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 443 | if (sip->si_code == CLD_EXITED) |
| 444 | tprintf("%d", sip->si_status); |
| 445 | else |
| 446 | printsignal(sip->si_status); |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 447 | if (!verbose) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 448 | tprints(", ..."); |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 449 | else |
H.J. Lu | 2bb4581 | 2012-04-15 11:17:13 -0700 | [diff] [blame] | 450 | tprintf(", si_utime=%llu, si_stime=%llu", |
| 451 | (unsigned long long) sip->si_utime, |
| 452 | (unsigned long long) sip->si_stime); |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 453 | break; |
| 454 | case SIGILL: case SIGFPE: |
| 455 | case SIGSEGV: case SIGBUS: |
| 456 | tprintf(", si_addr=%#lx", |
| 457 | (unsigned long) sip->si_addr); |
| 458 | break; |
| 459 | case SIGPOLL: |
| 460 | switch (sip->si_code) { |
| 461 | case POLL_IN: case POLL_OUT: case POLL_MSG: |
| 462 | tprintf(", si_band=%ld", |
| 463 | (long) sip->si_band); |
| 464 | break; |
| 465 | } |
| 466 | break; |
Dmitry V. Levin | bc091e3 | 2014-03-11 22:18:40 +0000 | [diff] [blame] | 467 | #ifdef HAVE_SIGINFO_T_SI_SYSCALL |
| 468 | case SIGSYS: |
| 469 | tprintf(", si_call_addr=%#lx, si_syscall=%d, si_arch=%u", |
| 470 | (unsigned long) sip->si_call_addr, |
| 471 | sip->si_syscall, sip->si_arch); |
| 472 | break; |
| 473 | #endif |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 474 | default: |
Dmitry V. Levin | b41e1c9 | 2011-03-10 23:14:47 +0000 | [diff] [blame] | 475 | if (sip->si_pid || sip->si_uid) |
Dmitry V. Levin | 4a524db | 2014-03-11 00:05:19 +0000 | [diff] [blame] | 476 | printsigsource(sip); |
| 477 | if (sip->si_ptr) |
| 478 | printsigval(sip, verbose); |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 479 | } |
| 480 | } |
| 481 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 482 | tprints("}"); |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 483 | } |
| 484 | |
Denys Vlasenko | d4d3ede | 2013-02-13 16:31:32 +0100 | [diff] [blame] | 485 | void |
| 486 | printsiginfo_at(struct tcb *tcp, long addr) |
| 487 | { |
| 488 | siginfo_t si; |
| 489 | if (!addr) { |
| 490 | tprints("NULL"); |
| 491 | return; |
| 492 | } |
| 493 | if (syserror(tcp)) { |
| 494 | tprintf("%#lx", addr); |
| 495 | return; |
| 496 | } |
| 497 | if (umove(tcp, addr, &si) < 0) { |
| 498 | tprints("{???}"); |
| 499 | return; |
| 500 | } |
| 501 | printsiginfo(&si, verbose(tcp)); |
| 502 | } |
| 503 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 504 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 505 | sys_sigsetmask(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 506 | { |
| 507 | if (entering(tcp)) { |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 508 | tprintsigmask_val("", tcp->u_arg[0]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 509 | } |
| 510 | else if (!syserror(tcp)) { |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 511 | tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 512 | return RVAL_HEX | RVAL_STR; |
| 513 | } |
| 514 | return 0; |
| 515 | } |
| 516 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 517 | #ifdef HAVE_SIGACTION |
| 518 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 519 | struct old_sigaction { |
Denys Vlasenko | 86d9484 | 2013-02-08 12:59:13 +0100 | [diff] [blame] | 520 | /* sa_handler may be a libc #define, need to use other name: */ |
Chris Dearman | 2b4bb1c | 2013-12-09 19:58:42 -0800 | [diff] [blame] | 521 | #ifdef MIPS |
| 522 | unsigned int sa_flags; |
| 523 | void (*__sa_handler)(int); |
| 524 | /* Kernel treats sa_mask as an array of longs. */ |
| 525 | unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1]; |
| 526 | #else |
Denys Vlasenko | 86d9484 | 2013-02-08 12:59:13 +0100 | [diff] [blame] | 527 | void (*__sa_handler)(int); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 528 | unsigned long sa_mask; |
| 529 | unsigned long sa_flags; |
Chris Dearman | 2b4bb1c | 2013-12-09 19:58:42 -0800 | [diff] [blame] | 530 | #endif /* !MIPS */ |
Dmitry V. Levin | 24b8eb0 | 2015-02-28 17:17:09 +0000 | [diff] [blame] | 531 | #if HAVE_SA_RESTORER |
Vicente Olivert Riera | c3a5c01 | 2014-09-11 20:05:18 +0100 | [diff] [blame] | 532 | void (*sa_restorer)(void); |
| 533 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 534 | }; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 535 | |
Elliott Hughes | 458b3f2 | 2014-02-28 23:21:35 +0000 | [diff] [blame] | 536 | struct old_sigaction32 { |
| 537 | /* sa_handler may be a libc #define, need to use other name: */ |
| 538 | uint32_t __sa_handler; |
| 539 | uint32_t sa_mask; |
| 540 | uint32_t sa_flags; |
Dmitry V. Levin | 24b8eb0 | 2015-02-28 17:17:09 +0000 | [diff] [blame] | 541 | #if HAVE_SA_RESTORER |
Elliott Hughes | 458b3f2 | 2014-02-28 23:21:35 +0000 | [diff] [blame] | 542 | uint32_t sa_restorer; |
Vicente Olivert Riera | c3a5c01 | 2014-09-11 20:05:18 +0100 | [diff] [blame] | 543 | #endif |
Elliott Hughes | 458b3f2 | 2014-02-28 23:21:35 +0000 | [diff] [blame] | 544 | }; |
| 545 | |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 546 | static void |
| 547 | decode_old_sigaction(struct tcb *tcp, long addr) |
| 548 | { |
| 549 | struct old_sigaction sa; |
Elliott Hughes | 458b3f2 | 2014-02-28 23:21:35 +0000 | [diff] [blame] | 550 | int r; |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 551 | |
| 552 | if (!addr) { |
| 553 | tprints("NULL"); |
| 554 | return; |
| 555 | } |
| 556 | if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) { |
| 557 | tprintf("%#lx", addr); |
| 558 | return; |
| 559 | } |
Elliott Hughes | 458b3f2 | 2014-02-28 23:21:35 +0000 | [diff] [blame] | 560 | |
| 561 | #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 |
| 562 | if (current_wordsize != sizeof(sa.__sa_handler) && current_wordsize == 4) { |
| 563 | struct old_sigaction32 sa32; |
| 564 | r = umove(tcp, addr, &sa32); |
| 565 | if (r >= 0) { |
| 566 | memset(&sa, 0, sizeof(sa)); |
| 567 | sa.__sa_handler = (void*)(uintptr_t)sa32.__sa_handler; |
| 568 | sa.sa_flags = sa32.sa_flags; |
Dmitry V. Levin | 24b8eb0 | 2015-02-28 17:17:09 +0000 | [diff] [blame] | 569 | #if HAVE_SA_RESTORER && defined SA_RESTORER |
Elliott Hughes | 458b3f2 | 2014-02-28 23:21:35 +0000 | [diff] [blame] | 570 | sa.sa_restorer = (void*)(uintptr_t)sa32.sa_restorer; |
Vicente Olivert Riera | c3a5c01 | 2014-09-11 20:05:18 +0100 | [diff] [blame] | 571 | #endif |
Elliott Hughes | 458b3f2 | 2014-02-28 23:21:35 +0000 | [diff] [blame] | 572 | sa.sa_mask = sa32.sa_mask; |
| 573 | } |
| 574 | } else |
| 575 | #endif |
| 576 | { |
| 577 | r = umove(tcp, addr, &sa); |
| 578 | } |
| 579 | if (r < 0) { |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 580 | tprints("{...}"); |
| 581 | return; |
| 582 | } |
| 583 | |
| 584 | /* Architectures using function pointers, like |
| 585 | * hppa, may need to manipulate the function pointer |
| 586 | * to compute the result of a comparison. However, |
| 587 | * the __sa_handler function pointer exists only in |
| 588 | * the address space of the traced process, and can't |
| 589 | * be manipulated by strace. In order to prevent the |
| 590 | * compiler from generating code to manipulate |
| 591 | * __sa_handler we cast the function pointers to long. */ |
| 592 | if ((long)sa.__sa_handler == (long)SIG_ERR) |
| 593 | tprints("{SIG_ERR, "); |
| 594 | else if ((long)sa.__sa_handler == (long)SIG_DFL) |
| 595 | tprints("{SIG_DFL, "); |
| 596 | else if ((long)sa.__sa_handler == (long)SIG_IGN) |
| 597 | tprints("{SIG_IGN, "); |
| 598 | else |
| 599 | tprintf("{%#lx, ", (long) sa.__sa_handler); |
Chris Dearman | 2b4bb1c | 2013-12-09 19:58:42 -0800 | [diff] [blame] | 600 | #ifdef MIPS |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 601 | tprintsigmask_addr("", sa.sa_mask); |
Chris Dearman | 2b4bb1c | 2013-12-09 19:58:42 -0800 | [diff] [blame] | 602 | #else |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 603 | tprintsigmask_val("", sa.sa_mask); |
Chris Dearman | 2b4bb1c | 2013-12-09 19:58:42 -0800 | [diff] [blame] | 604 | #endif |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 605 | tprints(", "); |
| 606 | printflags(sigact_flags, sa.sa_flags, "SA_???"); |
Dmitry V. Levin | 24b8eb0 | 2015-02-28 17:17:09 +0000 | [diff] [blame] | 607 | #if HAVE_SA_RESTORER && defined SA_RESTORER |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 608 | if (sa.sa_flags & SA_RESTORER) |
| 609 | tprintf(", %p", sa.sa_restorer); |
| 610 | #endif |
| 611 | tprints("}"); |
| 612 | } |
| 613 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 614 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 615 | sys_sigaction(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 616 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 617 | if (entering(tcp)) { |
| 618 | printsignal(tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 619 | tprints(", "); |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 620 | decode_old_sigaction(tcp, tcp->u_arg[1]); |
| 621 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 622 | } else |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 623 | decode_old_sigaction(tcp, tcp->u_arg[2]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 624 | return 0; |
| 625 | } |
| 626 | |
| 627 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 628 | sys_signal(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 629 | { |
| 630 | if (entering(tcp)) { |
| 631 | printsignal(tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 632 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 633 | switch (tcp->u_arg[1]) { |
Jan Kratochvil | 1f94271 | 2008-08-06 21:38:52 +0000 | [diff] [blame] | 634 | case (long) SIG_ERR: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 635 | tprints("SIG_ERR"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 636 | break; |
Jan Kratochvil | 1f94271 | 2008-08-06 21:38:52 +0000 | [diff] [blame] | 637 | case (long) SIG_DFL: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 638 | tprints("SIG_DFL"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 639 | break; |
Jan Kratochvil | 1f94271 | 2008-08-06 21:38:52 +0000 | [diff] [blame] | 640 | case (long) SIG_IGN: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 641 | tprints("SIG_IGN"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 642 | break; |
| 643 | default: |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 644 | tprintf("%#lx", tcp->u_arg[1]); |
| 645 | } |
Wichert Akkerman | 16a03d2 | 2000-08-10 02:14:04 +0000 | [diff] [blame] | 646 | return 0; |
| 647 | } |
Dmitry V. Levin | 21a7534 | 2008-09-03 01:22:18 +0000 | [diff] [blame] | 648 | else if (!syserror(tcp)) { |
Wichert Akkerman | 16a03d2 | 2000-08-10 02:14:04 +0000 | [diff] [blame] | 649 | switch (tcp->u_rval) { |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 650 | case (long) SIG_ERR: |
Wichert Akkerman | 16a03d2 | 2000-08-10 02:14:04 +0000 | [diff] [blame] | 651 | tcp->auxstr = "SIG_ERR"; break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 652 | case (long) SIG_DFL: |
Wichert Akkerman | 16a03d2 | 2000-08-10 02:14:04 +0000 | [diff] [blame] | 653 | tcp->auxstr = "SIG_DFL"; break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 654 | case (long) SIG_IGN: |
Wichert Akkerman | 16a03d2 | 2000-08-10 02:14:04 +0000 | [diff] [blame] | 655 | tcp->auxstr = "SIG_IGN"; break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 656 | default: |
Wichert Akkerman | 16a03d2 | 2000-08-10 02:14:04 +0000 | [diff] [blame] | 657 | tcp->auxstr = NULL; |
| 658 | } |
| 659 | return RVAL_HEX | RVAL_STR; |
| 660 | } |
Dmitry V. Levin | 21a7534 | 2008-09-03 01:22:18 +0000 | [diff] [blame] | 661 | return 0; |
Wichert Akkerman | 16a03d2 | 2000-08-10 02:14:04 +0000 | [diff] [blame] | 662 | } |
| 663 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 664 | #endif /* HAVE_SIGACTION */ |
| 665 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 666 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 667 | sys_siggetmask(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 668 | { |
| 669 | if (exiting(tcp)) { |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 670 | tcp->auxstr = sprintsigmask_val("mask ", tcp->u_rval); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 671 | } |
| 672 | return RVAL_HEX | RVAL_STR; |
| 673 | } |
| 674 | |
| 675 | int |
Dmitry V. Levin | e5e6085 | 2009-12-31 22:50:49 +0000 | [diff] [blame] | 676 | sys_sigsuspend(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 677 | { |
| 678 | if (entering(tcp)) { |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 679 | tprintsigmask_val("", tcp->u_arg[2]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 680 | } |
| 681 | return 0; |
| 682 | } |
| 683 | |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 684 | #if !defined SS_ONSTACK |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 685 | #define SS_ONSTACK 1 |
| 686 | #define SS_DISABLE 2 |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 687 | #endif |
| 688 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 689 | #include "xlat/sigaltstack_flags.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 690 | |
Dmitry V. Levin | 338c069 | 2013-02-09 02:03:04 +0000 | [diff] [blame] | 691 | static void |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 692 | print_stack_t(struct tcb *tcp, unsigned long addr) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 693 | { |
| 694 | stack_t ss; |
Dmitry V. Levin | d153bfc | 2014-02-26 22:29:27 +0000 | [diff] [blame] | 695 | int r; |
Dmitry V. Levin | 338c069 | 2013-02-09 02:03:04 +0000 | [diff] [blame] | 696 | |
| 697 | if (!addr) { |
| 698 | tprints("NULL"); |
Dmitry V. Levin | d153bfc | 2014-02-26 22:29:27 +0000 | [diff] [blame] | 699 | return; |
| 700 | } |
| 701 | |
| 702 | #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 |
| 703 | if (current_wordsize != sizeof(ss.ss_sp) && current_wordsize == 4) { |
| 704 | struct { |
| 705 | uint32_t ss_sp; |
| 706 | int32_t ss_flags; |
| 707 | uint32_t ss_size; |
| 708 | } ss32; |
| 709 | r = umove(tcp, addr, &ss32); |
| 710 | if (r >= 0) { |
| 711 | memset(&ss, 0, sizeof(ss)); |
| 712 | ss.ss_sp = (void*)(unsigned long) ss32.ss_sp; |
| 713 | ss.ss_flags = ss32.ss_flags; |
| 714 | ss.ss_size = (unsigned long) ss32.ss_size; |
| 715 | } |
| 716 | } else |
| 717 | #endif |
| 718 | { |
| 719 | r = umove(tcp, addr, &ss); |
| 720 | } |
| 721 | if (r < 0) { |
Dmitry V. Levin | 338c069 | 2013-02-09 02:03:04 +0000 | [diff] [blame] | 722 | tprintf("%#lx", addr); |
| 723 | } else { |
| 724 | tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp); |
| 725 | printflags(sigaltstack_flags, ss.ss_flags, "SS_???"); |
| 726 | tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size); |
| 727 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 731 | sys_sigaltstack(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 732 | { |
| 733 | if (entering(tcp)) { |
Dmitry V. Levin | 338c069 | 2013-02-09 02:03:04 +0000 | [diff] [blame] | 734 | print_stack_t(tcp, tcp->u_arg[0]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 735 | } |
| 736 | else { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 737 | tprints(", "); |
Dmitry V. Levin | 338c069 | 2013-02-09 02:03:04 +0000 | [diff] [blame] | 738 | print_stack_t(tcp, tcp->u_arg[1]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 739 | } |
| 740 | return 0; |
| 741 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 742 | |
| 743 | #ifdef HAVE_SIGACTION |
| 744 | |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 745 | /* "Old" sigprocmask, which operates with word-sized signal masks */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 746 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 747 | sys_sigprocmask(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 748 | { |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 749 | # ifdef ALPHA |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 750 | if (entering(tcp)) { |
Mike Frysinger | dde045c | 2012-03-15 00:45:33 -0400 | [diff] [blame] | 751 | /* |
| 752 | * Alpha/OSF is different: it doesn't pass in two pointers, |
| 753 | * but rather passes in the new bitmask as an argument and |
| 754 | * then returns the old bitmask. This "works" because we |
| 755 | * only have 64 signals to worry about. If you want more, |
| 756 | * use of the rt_sigprocmask syscall is required. |
| 757 | * Alpha: |
| 758 | * old = osf_sigprocmask(how, new); |
| 759 | * Everyone else: |
| 760 | * ret = sigprocmask(how, &new, &old, ...); |
| 761 | */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 762 | printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???"); |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 763 | tprintsigmask_val(", ", tcp->u_arg[1]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 764 | } |
| 765 | else if (!syserror(tcp)) { |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 766 | tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 767 | return RVAL_HEX | RVAL_STR; |
| 768 | } |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 769 | # else /* !ALPHA */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 770 | if (entering(tcp)) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 771 | printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 772 | tprints(", "); |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 773 | print_sigset_addr_len(tcp, tcp->u_arg[1], current_wordsize); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 774 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 775 | } |
| 776 | else { |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 777 | if (syserror(tcp)) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 778 | tprintf("%#lx", tcp->u_arg[2]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 779 | else |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 780 | print_sigset_addr_len(tcp, tcp->u_arg[2], current_wordsize); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 781 | } |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 782 | # endif /* !ALPHA */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 783 | return 0; |
| 784 | } |
| 785 | |
| 786 | #endif /* HAVE_SIGACTION */ |
| 787 | |
| 788 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 789 | sys_kill(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 790 | { |
| 791 | if (entering(tcp)) { |
Denys Vlasenko | e015d2d | 2013-02-15 14:58:52 +0100 | [diff] [blame] | 792 | tprintf("%ld, %s", |
| 793 | widen_to_long(tcp->u_arg[0]), |
| 794 | signame(tcp->u_arg[1]) |
| 795 | ); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 796 | } |
| 797 | return 0; |
| 798 | } |
| 799 | |
Roland McGrath | 8ffc352 | 2003-07-09 09:47:49 +0000 | [diff] [blame] | 800 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 801 | sys_tgkill(struct tcb *tcp) |
Roland McGrath | 8ffc352 | 2003-07-09 09:47:49 +0000 | [diff] [blame] | 802 | { |
| 803 | if (entering(tcp)) { |
| 804 | tprintf("%ld, %ld, %s", |
Denys Vlasenko | e015d2d | 2013-02-15 14:58:52 +0100 | [diff] [blame] | 805 | widen_to_long(tcp->u_arg[0]), |
| 806 | widen_to_long(tcp->u_arg[1]), |
| 807 | signame(tcp->u_arg[2]) |
| 808 | ); |
Roland McGrath | 8ffc352 | 2003-07-09 09:47:49 +0000 | [diff] [blame] | 809 | } |
| 810 | return 0; |
| 811 | } |
Roland McGrath | 8ffc352 | 2003-07-09 09:47:49 +0000 | [diff] [blame] | 812 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 813 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 814 | sys_sigpending(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 815 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 816 | if (exiting(tcp)) { |
| 817 | if (syserror(tcp)) |
| 818 | tprintf("%#lx", tcp->u_arg[0]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 819 | else |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 820 | print_sigset_addr_len(tcp, tcp->u_arg[0], current_wordsize); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 821 | } |
| 822 | return 0; |
| 823 | } |
| 824 | |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 825 | int |
| 826 | sys_rt_sigprocmask(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 827 | { |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 828 | /* 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] | 829 | if (entering(tcp)) { |
| 830 | printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 831 | tprints(", "); |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 832 | print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[3]); |
| 833 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 834 | } |
| 835 | else { |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 836 | if (syserror(tcp)) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 837 | tprintf("%#lx", tcp->u_arg[2]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 838 | else |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 839 | 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] | 840 | tprintf(", %lu", tcp->u_arg[3]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 841 | } |
| 842 | return 0; |
| 843 | } |
| 844 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 845 | /* Structure describing the action to be taken when a signal arrives. */ |
| 846 | struct new_sigaction |
| 847 | { |
Denys Vlasenko | 86d9484 | 2013-02-08 12:59:13 +0100 | [diff] [blame] | 848 | /* sa_handler may be a libc #define, need to use other name: */ |
Chris Dearman | 2b4bb1c | 2013-12-09 19:58:42 -0800 | [diff] [blame] | 849 | #ifdef MIPS |
| 850 | unsigned int sa_flags; |
| 851 | void (*__sa_handler)(int); |
| 852 | #else |
Denys Vlasenko | 86d9484 | 2013-02-08 12:59:13 +0100 | [diff] [blame] | 853 | void (*__sa_handler)(int); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 854 | unsigned long sa_flags; |
Chris Dearman | 2b4bb1c | 2013-12-09 19:58:42 -0800 | [diff] [blame] | 855 | #endif /* !MIPS */ |
Dmitry V. Levin | 24b8eb0 | 2015-02-28 17:17:09 +0000 | [diff] [blame] | 856 | #if HAVE_SA_RESTORER |
Vicente Olivert Riera | c3a5c01 | 2014-09-11 20:05:18 +0100 | [diff] [blame] | 857 | void (*sa_restorer)(void); |
| 858 | #endif |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 859 | /* Kernel treats sa_mask as an array of longs. */ |
| 860 | unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1]; |
| 861 | }; |
| 862 | /* Same for i386-on-x86_64 and similar cases */ |
| 863 | struct new_sigaction32 |
| 864 | { |
| 865 | uint32_t __sa_handler; |
| 866 | uint32_t sa_flags; |
Dmitry V. Levin | 24b8eb0 | 2015-02-28 17:17:09 +0000 | [diff] [blame] | 867 | #if HAVE_SA_RESTORER |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 868 | uint32_t sa_restorer; |
Vicente Olivert Riera | c3a5c01 | 2014-09-11 20:05:18 +0100 | [diff] [blame] | 869 | #endif |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 870 | uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)]; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 871 | }; |
| 872 | |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 873 | static void |
| 874 | decode_new_sigaction(struct tcb *tcp, long addr) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 875 | { |
| 876 | struct new_sigaction sa; |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 877 | int r; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 878 | |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 879 | if (!addr) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 880 | tprints("NULL"); |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 881 | return; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 882 | } |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 883 | if (!verbose(tcp) || (exiting(tcp) && syserror(tcp))) { |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 884 | tprintf("%#lx", addr); |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 885 | return; |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 886 | } |
Denys Vlasenko | d4d3ede | 2013-02-13 16:31:32 +0100 | [diff] [blame] | 887 | #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 888 | if (current_wordsize != sizeof(sa.sa_flags) && current_wordsize == 4) { |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 889 | struct new_sigaction32 sa32; |
| 890 | r = umove(tcp, addr, &sa32); |
| 891 | if (r >= 0) { |
| 892 | memset(&sa, 0, sizeof(sa)); |
| 893 | sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler; |
| 894 | sa.sa_flags = sa32.sa_flags; |
Dmitry V. Levin | 24b8eb0 | 2015-02-28 17:17:09 +0000 | [diff] [blame] | 895 | #if HAVE_SA_RESTORER && defined SA_RESTORER |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 896 | sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer; |
Vicente Olivert Riera | c3a5c01 | 2014-09-11 20:05:18 +0100 | [diff] [blame] | 897 | #endif |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 898 | /* Kernel treats sa_mask as an array of longs. |
| 899 | * For 32-bit process, "long" is uint32_t, thus, for example, |
| 900 | * 32th bit in sa_mask will end up as bit 0 in sa_mask[1]. |
| 901 | * But for (64-bit) kernel, 32th bit in sa_mask is |
| 902 | * 32th bit in 0th (64-bit) long! |
| 903 | * For little-endian, it's the same. |
| 904 | * For big-endian, we swap 32-bit words. |
| 905 | */ |
| 906 | sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32); |
| 907 | } |
| 908 | } else |
| 909 | #endif |
| 910 | { |
| 911 | r = umove(tcp, addr, &sa); |
| 912 | } |
| 913 | if (r < 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 914 | tprints("{...}"); |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 915 | return; |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 916 | } |
Carlos O'Donell | 4677c8a | 2009-09-09 18:13:19 +0000 | [diff] [blame] | 917 | /* Architectures using function pointers, like |
| 918 | * hppa, may need to manipulate the function pointer |
| 919 | * to compute the result of a comparison. However, |
Denys Vlasenko | 86d9484 | 2013-02-08 12:59:13 +0100 | [diff] [blame] | 920 | * the __sa_handler function pointer exists only in |
Carlos O'Donell | 4677c8a | 2009-09-09 18:13:19 +0000 | [diff] [blame] | 921 | * the address space of the traced process, and can't |
| 922 | * be manipulated by strace. In order to prevent the |
| 923 | * compiler from generating code to manipulate |
Denys Vlasenko | 86d9484 | 2013-02-08 12:59:13 +0100 | [diff] [blame] | 924 | * __sa_handler we cast the function pointers to long. */ |
Carlos O'Donell | 4677c8a | 2009-09-09 18:13:19 +0000 | [diff] [blame] | 925 | if ((long)sa.__sa_handler == (long)SIG_ERR) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 926 | tprints("{SIG_ERR, "); |
Carlos O'Donell | 4677c8a | 2009-09-09 18:13:19 +0000 | [diff] [blame] | 927 | else if ((long)sa.__sa_handler == (long)SIG_DFL) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 928 | tprints("{SIG_DFL, "); |
Carlos O'Donell | 4677c8a | 2009-09-09 18:13:19 +0000 | [diff] [blame] | 929 | else if ((long)sa.__sa_handler == (long)SIG_IGN) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 930 | tprints("{SIG_IGN, "); |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 931 | else |
| 932 | tprintf("{%#lx, ", (long) sa.__sa_handler); |
Denys Vlasenko | 80b73a2 | 2013-07-18 10:10:46 +0200 | [diff] [blame] | 933 | /* |
| 934 | * Sigset size is in tcp->u_arg[4] (SPARC) |
| 935 | * or in tcp->u_arg[3] (all other), |
| 936 | * but kernel won't handle sys_rt_sigaction |
| 937 | * with wrong sigset size (just returns EINVAL instead). |
| 938 | * We just fetch the right size, which is NSIG / 8. |
| 939 | */ |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 940 | tprintsigmask_val("", sa.sa_mask); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 941 | tprints(", "); |
Denys Vlasenko | 80b73a2 | 2013-07-18 10:10:46 +0200 | [diff] [blame] | 942 | |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 943 | printflags(sigact_flags, sa.sa_flags, "SA_???"); |
Dmitry V. Levin | 24b8eb0 | 2015-02-28 17:17:09 +0000 | [diff] [blame] | 944 | #if HAVE_SA_RESTORER && defined SA_RESTORER |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 945 | if (sa.sa_flags & SA_RESTORER) |
| 946 | tprintf(", %p", sa.sa_restorer); |
| 947 | #endif |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 948 | tprints("}"); |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 949 | } |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 950 | |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 951 | int |
| 952 | sys_rt_sigaction(struct tcb *tcp) |
| 953 | { |
| 954 | if (entering(tcp)) { |
| 955 | printsignal(tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 956 | tprints(", "); |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 957 | decode_new_sigaction(tcp, tcp->u_arg[1]); |
| 958 | tprints(", "); |
| 959 | } else { |
| 960 | decode_new_sigaction(tcp, tcp->u_arg[2]); |
Denys Vlasenko | 9472a27 | 2013-02-12 11:43:46 +0100 | [diff] [blame] | 961 | #if defined(SPARC) || defined(SPARC64) |
Wichert Akkerman | dacfb6e | 1999-06-03 14:21:07 +0000 | [diff] [blame] | 962 | tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]); |
| 963 | #elif defined(ALPHA) |
| 964 | tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]); |
| 965 | #else |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 966 | tprintf(", %lu", tcp->u_arg[3]); |
Wichert Akkerman | dacfb6e | 1999-06-03 14:21:07 +0000 | [diff] [blame] | 967 | #endif |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 968 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 969 | return 0; |
| 970 | } |
| 971 | |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 972 | int |
| 973 | sys_rt_sigpending(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 974 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 975 | if (exiting(tcp)) { |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 976 | /* |
| 977 | * One of the few syscalls where sigset size (arg[1]) |
| 978 | * is allowed to be <= NSIG / 8, not strictly ==. |
| 979 | * This allows non-rt sigpending() syscall |
| 980 | * to reuse rt_sigpending() code in kernel. |
| 981 | */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 982 | if (syserror(tcp)) |
| 983 | tprintf("%#lx", tcp->u_arg[0]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 984 | else |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 985 | print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]); |
| 986 | tprintf(", %lu", tcp->u_arg[1]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 987 | } |
| 988 | return 0; |
| 989 | } |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 990 | |
| 991 | int |
| 992 | sys_rt_sigsuspend(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 993 | { |
| 994 | if (entering(tcp)) { |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 995 | /* NB: kernel requires arg[1] == NSIG / 8 */ |
| 996 | print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]); |
| 997 | tprintf(", %lu", tcp->u_arg[1]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 998 | } |
| 999 | return 0; |
| 1000 | } |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 1001 | |
Dmitry V. Levin | 297632b | 2012-03-13 15:51:13 +0000 | [diff] [blame] | 1002 | static void |
| 1003 | print_sigqueueinfo(struct tcb *tcp, int sig, unsigned long uinfo) |
| 1004 | { |
Dmitry V. Levin | 297632b | 2012-03-13 15:51:13 +0000 | [diff] [blame] | 1005 | printsignal(sig); |
| 1006 | tprints(", "); |
Denys Vlasenko | d4d3ede | 2013-02-13 16:31:32 +0100 | [diff] [blame] | 1007 | printsiginfo_at(tcp, uinfo); |
Dmitry V. Levin | 297632b | 2012-03-13 15:51:13 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 1010 | int |
| 1011 | sys_rt_sigqueueinfo(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1012 | { |
| 1013 | if (entering(tcp)) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1014 | tprintf("%lu, ", tcp->u_arg[0]); |
Dmitry V. Levin | 297632b | 2012-03-13 15:51:13 +0000 | [diff] [blame] | 1015 | print_sigqueueinfo(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 1016 | } |
| 1017 | return 0; |
| 1018 | } |
| 1019 | |
| 1020 | int |
| 1021 | sys_rt_tgsigqueueinfo(struct tcb *tcp) |
| 1022 | { |
| 1023 | if (entering(tcp)) { |
| 1024 | tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]); |
| 1025 | print_sigqueueinfo(tcp, tcp->u_arg[2], tcp->u_arg[3]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1026 | } |
| 1027 | return 0; |
| 1028 | } |
| 1029 | |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 1030 | int sys_rt_sigtimedwait(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1031 | { |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 1032 | /* NB: kernel requires arg[3] == NSIG / 8 */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1033 | if (entering(tcp)) { |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 1034 | 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] | 1035 | tprints(", "); |
Denys Vlasenko | b1a78cf | 2009-04-15 13:31:59 +0000 | [diff] [blame] | 1036 | /* This is the only "return" parameter, */ |
| 1037 | if (tcp->u_arg[1] != 0) |
| 1038 | return 0; |
| 1039 | /* ... if it's NULL, can decode all on entry */ |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1040 | tprints("NULL, "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1041 | } |
Denys Vlasenko | b1a78cf | 2009-04-15 13:31:59 +0000 | [diff] [blame] | 1042 | else if (tcp->u_arg[1] != 0) { |
| 1043 | /* syscall exit, and u_arg[1] wasn't NULL */ |
Denys Vlasenko | d4d3ede | 2013-02-13 16:31:32 +0100 | [diff] [blame] | 1044 | printsiginfo_at(tcp, tcp->u_arg[1]); |
| 1045 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1046 | } |
Denys Vlasenko | b1a78cf | 2009-04-15 13:31:59 +0000 | [diff] [blame] | 1047 | else { |
| 1048 | /* syscall exit, and u_arg[1] was NULL */ |
| 1049 | return 0; |
| 1050 | } |
| 1051 | print_timespec(tcp, tcp->u_arg[2]); |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 1052 | tprintf(", %lu", tcp->u_arg[3]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1053 | return 0; |
| 1054 | }; |
| 1055 | |
Roland McGrath | 79dcd7a | 2006-01-12 22:34:50 +0000 | [diff] [blame] | 1056 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 1057 | sys_restart_syscall(struct tcb *tcp) |
Roland McGrath | 79dcd7a | 2006-01-12 22:34:50 +0000 | [diff] [blame] | 1058 | { |
| 1059 | if (entering(tcp)) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1060 | tprints("<... resuming interrupted call ...>"); |
Roland McGrath | 79dcd7a | 2006-01-12 22:34:50 +0000 | [diff] [blame] | 1061 | return 0; |
| 1062 | } |
| 1063 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 1064 | static int |
| 1065 | do_signalfd(struct tcb *tcp, int flags_arg) |
Roland McGrath | f46ccd3 | 2007-08-02 01:15:59 +0000 | [diff] [blame] | 1066 | { |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 1067 | /* NB: kernel requires arg[2] == NSIG / 8 */ |
Roland McGrath | f46ccd3 | 2007-08-02 01:15:59 +0000 | [diff] [blame] | 1068 | if (entering(tcp)) { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 1069 | printfd(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1070 | tprints(", "); |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 1071 | 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] | 1072 | tprintf(", %lu", tcp->u_arg[2]); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 1073 | if (flags_arg >= 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1074 | tprints(", "); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 1075 | printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???"); |
| 1076 | } |
Roland McGrath | f46ccd3 | 2007-08-02 01:15:59 +0000 | [diff] [blame] | 1077 | } |
| 1078 | return 0; |
| 1079 | } |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 1080 | |
| 1081 | int |
| 1082 | sys_signalfd(struct tcb *tcp) |
| 1083 | { |
| 1084 | return do_signalfd(tcp, -1); |
| 1085 | } |
| 1086 | |
| 1087 | int |
| 1088 | sys_signalfd4(struct tcb *tcp) |
| 1089 | { |
| 1090 | return do_signalfd(tcp, 3); |
| 1091 | } |