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" |
Dmitry V. Levin | 0e946ab | 2015-07-17 23:56:54 +0000 | [diff] [blame] | 35 | #include <signal.h> |
Denys Vlasenko | 041b3ee | 2011-08-18 12:48:56 +0200 | [diff] [blame] | 36 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 37 | #ifndef NSIG |
Dmitry V. Levin | 74219ea | 2015-03-06 01:47:18 +0000 | [diff] [blame] | 38 | # warning NSIG is not defined, using 32 |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 39 | # define NSIG 32 |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 40 | #elif NSIG < 32 |
Dmitry V. Levin | 74219ea | 2015-03-06 01:47:18 +0000 | [diff] [blame] | 41 | # error NSIG < 32 |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 42 | #endif |
Denys Vlasenko | 041b3ee | 2011-08-18 12:48:56 +0200 | [diff] [blame] | 43 | |
Roland McGrath | 2638cb4 | 2002-12-15 23:58:41 +0000 | [diff] [blame] | 44 | /* 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] | 45 | used by the implementation. So we define it here. */ |
Dmitry V. Levin | 5c7f627 | 2014-02-08 00:26:06 +0000 | [diff] [blame] | 46 | #ifndef SA_RESTORER |
| 47 | # ifdef ASM_SA_RESTORER |
| 48 | # define SA_RESTORER ASM_SA_RESTORER |
Roland McGrath | 2638cb4 | 2002-12-15 23:58:41 +0000 | [diff] [blame] | 49 | # endif |
| 50 | #endif |
| 51 | |
Dmitry V. Levin | 24b8eb0 | 2015-02-28 17:17:09 +0000 | [diff] [blame] | 52 | /* |
| 53 | * Some architectures define SA_RESTORER in their headers, |
| 54 | * but do not actually have sa_restorer. |
| 55 | * |
| 56 | * Some architectures, otherwise, do not define SA_RESTORER in their headers, |
| 57 | * but actually have sa_restorer. |
| 58 | */ |
| 59 | #ifdef SA_RESTORER |
| 60 | # if defined HPPA || defined IA64 |
| 61 | # define HAVE_SA_RESTORER 0 |
| 62 | # else |
| 63 | # define HAVE_SA_RESTORER 1 |
| 64 | # endif |
| 65 | #else /* !SA_RESTORER */ |
Andreas Schwab | a897136 | 2015-03-11 14:15:34 +0100 | [diff] [blame] | 66 | # if defined SPARC || defined SPARC64 || defined M68K |
Dmitry V. Levin | 24b8eb0 | 2015-02-28 17:17:09 +0000 | [diff] [blame] | 67 | # define HAVE_SA_RESTORER 1 |
| 68 | # else |
| 69 | # define HAVE_SA_RESTORER 0 |
| 70 | # endif |
Mike Frysinger | d632e10 | 2014-08-09 09:04:18 -0400 | [diff] [blame] | 71 | #endif |
| 72 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 73 | #include "xlat/sigact_flags.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 74 | #include "xlat/sigprocmaskcmds.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 75 | |
Nate Sammons | ce780fc | 1999-03-29 23:23:13 +0000 | [diff] [blame] | 76 | /* Anonymous realtime signals. */ |
Dmitry V. Levin | 59f63d3 | 2015-03-05 05:03:41 +0000 | [diff] [blame] | 77 | #ifndef ASM_SIGRTMIN |
| 78 | /* Linux kernel >= 3.18 defines SIGRTMIN to 32 on all architectures. */ |
| 79 | # define ASM_SIGRTMIN 32 |
Nate Sammons | ce780fc | 1999-03-29 23:23:13 +0000 | [diff] [blame] | 80 | #endif |
Dmitry V. Levin | 59f63d3 | 2015-03-05 05:03:41 +0000 | [diff] [blame] | 81 | #ifndef ASM_SIGRTMAX |
| 82 | /* Under glibc 2.1, SIGRTMAX et al are functions, but __SIGRTMAX is a |
| 83 | constant. This is what we want. Otherwise, just use SIGRTMAX. */ |
| 84 | # ifdef SIGRTMAX |
| 85 | # ifndef __SIGRTMAX |
| 86 | # define __SIGRTMAX SIGRTMAX |
| 87 | # endif |
| 88 | # endif |
| 89 | # ifdef __SIGRTMAX |
| 90 | # define ASM_SIGRTMAX __SIGRTMAX |
| 91 | # endif |
Nate Sammons | ce780fc | 1999-03-29 23:23:13 +0000 | [diff] [blame] | 92 | #endif |
| 93 | |
Denys Vlasenko | d9560c1 | 2011-08-19 17:41:28 +0200 | [diff] [blame] | 94 | /* Note on the size of sigset_t: |
| 95 | * |
| 96 | * In glibc, sigset_t is an array with space for 1024 bits (!), |
| 97 | * even though all arches supported by Linux have only 64 signals |
| 98 | * except MIPS, which has 128. IOW, it is 128 bytes long. |
| 99 | * |
| 100 | * In-kernel sigset_t is sized correctly (it is either 64 or 128 bit long). |
| 101 | * However, some old syscall return only 32 lower bits (one word). |
| 102 | * Example: sys_sigpending vs sys_rt_sigpending. |
| 103 | * |
| 104 | * Be aware of this fact when you try to |
| 105 | * memcpy(&tcp->u_arg[1], &something, sizeof(sigset_t)) |
| 106 | * - sizeof(sigset_t) is much bigger than you think, |
| 107 | * it may overflow tcp->u_arg[] array, and it may try to copy more data |
| 108 | * than is really available in <something>. |
| 109 | * Similarly, |
| 110 | * umoven(tcp, addr, sizeof(sigset_t), &sigset) |
| 111 | * may be a bad idea: it'll try to read much more data than needed |
| 112 | * to fetch a sigset_t. |
| 113 | * Use (NSIG / 8) as a size instead. |
| 114 | */ |
| 115 | |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 116 | const char * |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 117 | signame(const int sig) |
Nate Sammons | ce780fc | 1999-03-29 23:23:13 +0000 | [diff] [blame] | 118 | { |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 119 | static char buf[sizeof("SIGRT_%u") + sizeof(int)*3]; |
Denys Vlasenko | 041b3ee | 2011-08-18 12:48:56 +0200 | [diff] [blame] | 120 | |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 121 | if (sig >= 0) { |
| 122 | const unsigned int s = sig; |
| 123 | |
| 124 | if (s < nsignals) |
| 125 | return signalent[s]; |
Dmitry V. Levin | 59f63d3 | 2015-03-05 05:03:41 +0000 | [diff] [blame] | 126 | #ifdef ASM_SIGRTMAX |
| 127 | if (s >= ASM_SIGRTMIN && s <= ASM_SIGRTMAX) { |
| 128 | sprintf(buf, "SIGRT_%u", s - ASM_SIGRTMIN); |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 129 | return buf; |
| 130 | } |
Denys Vlasenko | 041b3ee | 2011-08-18 12:48:56 +0200 | [diff] [blame] | 131 | #endif |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 132 | } |
Denys Vlasenko | 041b3ee | 2011-08-18 12:48:56 +0200 | [diff] [blame] | 133 | sprintf(buf, "%d", sig); |
| 134 | return buf; |
Nate Sammons | ce780fc | 1999-03-29 23:23:13 +0000 | [diff] [blame] | 135 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 136 | |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 137 | static unsigned int |
| 138 | popcount32(const uint32_t *a, unsigned int size) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 139 | { |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 140 | unsigned int count = 0; |
Denys Vlasenko | d9560c1 | 2011-08-19 17:41:28 +0200 | [diff] [blame] | 141 | |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 142 | for (; size; ++a, --size) { |
| 143 | uint32_t x = *a; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 144 | |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 145 | #ifdef HAVE___BUILTIN_POPCOUNT |
| 146 | count += __builtin_popcount(x); |
Denys Vlasenko | a877379 | 2013-07-18 20:42:41 +0200 | [diff] [blame] | 147 | #else |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 148 | for (; x; ++count) |
| 149 | x &= x - 1; |
Nate Sammons | 4a12143 | 1999-04-06 01:19:39 +0000 | [diff] [blame] | 150 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 151 | } |
Denys Vlasenko | 4f3df07 | 2012-01-29 22:38:35 +0100 | [diff] [blame] | 152 | |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 153 | return count; |
| 154 | } |
| 155 | |
Dmitry V. Levin | 74219ea | 2015-03-06 01:47:18 +0000 | [diff] [blame] | 156 | const char * |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 157 | sprintsigmask_n(const char *prefix, const void *sig_mask, unsigned int bytes) |
| 158 | { |
| 159 | /* |
| 160 | * The maximum number of signal names to be printed is NSIG * 2 / 3. |
| 161 | * Most of signal names have length 7, |
| 162 | * average length of signal names is less than 7. |
| 163 | * The length of prefix string does not exceed 16. |
| 164 | */ |
| 165 | static char outstr[128 + 8 * (NSIG * 2 / 3)]; |
| 166 | |
| 167 | char *s; |
| 168 | const uint32_t *mask; |
| 169 | uint32_t inverted_mask[NSIG / 32]; |
| 170 | unsigned int size; |
| 171 | int i; |
| 172 | char sep; |
| 173 | |
| 174 | s = stpcpy(outstr, prefix); |
| 175 | |
| 176 | mask = sig_mask; |
| 177 | /* length of signal mask in 4-byte words */ |
| 178 | size = (bytes >= NSIG / 8) ? NSIG / 32 : (bytes + 3) / 4; |
| 179 | |
| 180 | /* check whether 2/3 or more bits are set */ |
| 181 | if (popcount32(mask, size) >= size * 32 * 2 / 3) { |
| 182 | /* show those signals that are NOT in the mask */ |
| 183 | unsigned int j; |
| 184 | for (j = 0; j < size; ++j) |
| 185 | inverted_mask[j] = ~mask[j]; |
| 186 | mask = inverted_mask; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 187 | *s++ = '~'; |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 188 | } |
Denys Vlasenko | 4f3df07 | 2012-01-29 22:38:35 +0100 | [diff] [blame] | 189 | |
| 190 | sep = '['; |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 191 | for (i = 0; (i = next_set_bit(mask, i, size * 32)) >= 0; ) { |
| 192 | ++i; |
| 193 | *s++ = sep; |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 194 | if ((unsigned) i < nsignals) { |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 195 | s = stpcpy(s, signalent[i] + 3); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 196 | } |
Dmitry V. Levin | 59f63d3 | 2015-03-05 05:03:41 +0000 | [diff] [blame] | 197 | #ifdef ASM_SIGRTMAX |
| 198 | else if (i >= ASM_SIGRTMIN && i <= ASM_SIGRTMAX) { |
| 199 | s += sprintf(s, "RT_%u", i - ASM_SIGRTMIN); |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 200 | } |
| 201 | #endif |
| 202 | else { |
| 203 | s += sprintf(s, "%u", i); |
| 204 | } |
| 205 | sep = ' '; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 206 | } |
Denys Vlasenko | 4f3df07 | 2012-01-29 22:38:35 +0100 | [diff] [blame] | 207 | if (sep == '[') |
| 208 | *s++ = sep; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 209 | *s++ = ']'; |
| 210 | *s = '\0'; |
| 211 | return outstr; |
| 212 | } |
| 213 | |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 214 | #define sprintsigmask_val(prefix, mask) \ |
| 215 | sprintsigmask_n((prefix), &(mask), sizeof(mask)) |
| 216 | |
| 217 | #define tprintsigmask_val(prefix, mask) \ |
| 218 | tprints(sprintsigmask_n((prefix), &(mask), sizeof(mask))) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 219 | |
| 220 | void |
Denys Vlasenko | eccc48c | 2011-06-09 01:28:11 +0200 | [diff] [blame] | 221 | printsignal(int nr) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 222 | { |
Denys Vlasenko | 5940e65 | 2011-09-01 09:55:05 +0200 | [diff] [blame] | 223 | tprints(signame(nr)); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 226 | void |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 227 | print_sigset_addr_len(struct tcb *tcp, long addr, long len) |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 228 | { |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 229 | char mask[NSIG / 8]; |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 230 | |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 231 | /* Here len is usually equals NSIG / 8 or current_wordsize. |
| 232 | * But we code this defensively: |
| 233 | */ |
| 234 | if (len < 0) { |
Dmitry V. Levin | 735843e | 2015-07-17 00:37:39 +0000 | [diff] [blame] | 235 | printaddr(addr); |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 236 | return; |
| 237 | } |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 238 | if (len >= NSIG / 8) |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 239 | len = NSIG / 8; |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 240 | else |
| 241 | len = (len + 3) & ~3; |
| 242 | |
Dmitry V. Levin | 735843e | 2015-07-17 00:37:39 +0000 | [diff] [blame] | 243 | if (umoven_or_printaddr(tcp, addr, len, mask)) |
| 244 | return; |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 245 | tprints(sprintsigmask_n("", mask, len)); |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 246 | } |
| 247 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 248 | SYS_FUNC(sigsetmask) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 249 | { |
| 250 | if (entering(tcp)) { |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 251 | tprintsigmask_val("", tcp->u_arg[0]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 252 | } |
| 253 | else if (!syserror(tcp)) { |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 254 | tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 255 | return RVAL_HEX | RVAL_STR; |
| 256 | } |
| 257 | return 0; |
| 258 | } |
| 259 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 260 | #ifdef HAVE_SIGACTION |
| 261 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 262 | struct old_sigaction { |
Denys Vlasenko | 86d9484 | 2013-02-08 12:59:13 +0100 | [diff] [blame] | 263 | /* sa_handler may be a libc #define, need to use other name: */ |
Chris Dearman | 2b4bb1c | 2013-12-09 19:58:42 -0800 | [diff] [blame] | 264 | #ifdef MIPS |
| 265 | unsigned int sa_flags; |
| 266 | void (*__sa_handler)(int); |
| 267 | /* Kernel treats sa_mask as an array of longs. */ |
| 268 | unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1]; |
| 269 | #else |
Denys Vlasenko | 86d9484 | 2013-02-08 12:59:13 +0100 | [diff] [blame] | 270 | void (*__sa_handler)(int); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 271 | unsigned long sa_mask; |
| 272 | unsigned long sa_flags; |
Chris Dearman | 2b4bb1c | 2013-12-09 19:58:42 -0800 | [diff] [blame] | 273 | #endif /* !MIPS */ |
Dmitry V. Levin | 24b8eb0 | 2015-02-28 17:17:09 +0000 | [diff] [blame] | 274 | #if HAVE_SA_RESTORER |
Vicente Olivert Riera | c3a5c01 | 2014-09-11 20:05:18 +0100 | [diff] [blame] | 275 | void (*sa_restorer)(void); |
| 276 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 277 | }; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 278 | |
Elliott Hughes | 458b3f2 | 2014-02-28 23:21:35 +0000 | [diff] [blame] | 279 | struct old_sigaction32 { |
| 280 | /* sa_handler may be a libc #define, need to use other name: */ |
| 281 | uint32_t __sa_handler; |
| 282 | uint32_t sa_mask; |
| 283 | uint32_t sa_flags; |
Dmitry V. Levin | 24b8eb0 | 2015-02-28 17:17:09 +0000 | [diff] [blame] | 284 | #if HAVE_SA_RESTORER |
Elliott Hughes | 458b3f2 | 2014-02-28 23:21:35 +0000 | [diff] [blame] | 285 | uint32_t sa_restorer; |
Vicente Olivert Riera | c3a5c01 | 2014-09-11 20:05:18 +0100 | [diff] [blame] | 286 | #endif |
Elliott Hughes | 458b3f2 | 2014-02-28 23:21:35 +0000 | [diff] [blame] | 287 | }; |
| 288 | |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 289 | static void |
| 290 | decode_old_sigaction(struct tcb *tcp, long addr) |
| 291 | { |
| 292 | struct old_sigaction sa; |
Elliott Hughes | 458b3f2 | 2014-02-28 23:21:35 +0000 | [diff] [blame] | 293 | |
| 294 | #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 |
| 295 | if (current_wordsize != sizeof(sa.__sa_handler) && current_wordsize == 4) { |
| 296 | struct old_sigaction32 sa32; |
Dmitry V. Levin | 735843e | 2015-07-17 00:37:39 +0000 | [diff] [blame] | 297 | |
| 298 | if (umove_or_printaddr(tcp, addr, &sa32)) |
| 299 | return; |
| 300 | |
| 301 | memset(&sa, 0, sizeof(sa)); |
| 302 | sa.__sa_handler = (void*)(uintptr_t)sa32.__sa_handler; |
| 303 | sa.sa_flags = sa32.sa_flags; |
Dmitry V. Levin | 24b8eb0 | 2015-02-28 17:17:09 +0000 | [diff] [blame] | 304 | #if HAVE_SA_RESTORER && defined SA_RESTORER |
Dmitry V. Levin | 735843e | 2015-07-17 00:37:39 +0000 | [diff] [blame] | 305 | sa.sa_restorer = (void*)(uintptr_t)sa32.sa_restorer; |
Vicente Olivert Riera | c3a5c01 | 2014-09-11 20:05:18 +0100 | [diff] [blame] | 306 | #endif |
Dmitry V. Levin | 735843e | 2015-07-17 00:37:39 +0000 | [diff] [blame] | 307 | sa.sa_mask = sa32.sa_mask; |
Elliott Hughes | 458b3f2 | 2014-02-28 23:21:35 +0000 | [diff] [blame] | 308 | } else |
| 309 | #endif |
Dmitry V. Levin | 735843e | 2015-07-17 00:37:39 +0000 | [diff] [blame] | 310 | if (umove_or_printaddr(tcp, addr, &sa)) |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 311 | return; |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 312 | |
| 313 | /* Architectures using function pointers, like |
| 314 | * hppa, may need to manipulate the function pointer |
| 315 | * to compute the result of a comparison. However, |
| 316 | * the __sa_handler function pointer exists only in |
| 317 | * the address space of the traced process, and can't |
| 318 | * be manipulated by strace. In order to prevent the |
| 319 | * compiler from generating code to manipulate |
| 320 | * __sa_handler we cast the function pointers to long. */ |
Dmitry V. Levin | 735843e | 2015-07-17 00:37:39 +0000 | [diff] [blame] | 321 | tprints("{"); |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 322 | if ((long)sa.__sa_handler == (long)SIG_ERR) |
Dmitry V. Levin | 735843e | 2015-07-17 00:37:39 +0000 | [diff] [blame] | 323 | tprints("SIG_ERR"); |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 324 | else if ((long)sa.__sa_handler == (long)SIG_DFL) |
Dmitry V. Levin | 735843e | 2015-07-17 00:37:39 +0000 | [diff] [blame] | 325 | tprints("SIG_DFL"); |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 326 | else if ((long)sa.__sa_handler == (long)SIG_IGN) |
Dmitry V. Levin | 735843e | 2015-07-17 00:37:39 +0000 | [diff] [blame] | 327 | tprints("SIG_IGN"); |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 328 | else |
Dmitry V. Levin | 735843e | 2015-07-17 00:37:39 +0000 | [diff] [blame] | 329 | printaddr((long) sa.__sa_handler); |
| 330 | tprints(", "); |
Chris Dearman | 2b4bb1c | 2013-12-09 19:58:42 -0800 | [diff] [blame] | 331 | #ifdef MIPS |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 332 | tprintsigmask_addr("", sa.sa_mask); |
Chris Dearman | 2b4bb1c | 2013-12-09 19:58:42 -0800 | [diff] [blame] | 333 | #else |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 334 | tprintsigmask_val("", sa.sa_mask); |
Chris Dearman | 2b4bb1c | 2013-12-09 19:58:42 -0800 | [diff] [blame] | 335 | #endif |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 336 | tprints(", "); |
| 337 | printflags(sigact_flags, sa.sa_flags, "SA_???"); |
Dmitry V. Levin | 24b8eb0 | 2015-02-28 17:17:09 +0000 | [diff] [blame] | 338 | #if HAVE_SA_RESTORER && defined SA_RESTORER |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 339 | if (sa.sa_flags & SA_RESTORER) |
| 340 | tprintf(", %p", sa.sa_restorer); |
| 341 | #endif |
| 342 | tprints("}"); |
| 343 | } |
| 344 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 345 | SYS_FUNC(sigaction) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 346 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 347 | if (entering(tcp)) { |
| 348 | printsignal(tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 349 | tprints(", "); |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 350 | decode_old_sigaction(tcp, tcp->u_arg[1]); |
| 351 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 352 | } else |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 353 | decode_old_sigaction(tcp, tcp->u_arg[2]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 354 | return 0; |
| 355 | } |
| 356 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 357 | SYS_FUNC(signal) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 358 | { |
| 359 | if (entering(tcp)) { |
| 360 | printsignal(tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 361 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 362 | switch (tcp->u_arg[1]) { |
Jan Kratochvil | 1f94271 | 2008-08-06 21:38:52 +0000 | [diff] [blame] | 363 | case (long) SIG_ERR: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 364 | tprints("SIG_ERR"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 365 | break; |
Jan Kratochvil | 1f94271 | 2008-08-06 21:38:52 +0000 | [diff] [blame] | 366 | case (long) SIG_DFL: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 367 | tprints("SIG_DFL"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 368 | break; |
Jan Kratochvil | 1f94271 | 2008-08-06 21:38:52 +0000 | [diff] [blame] | 369 | case (long) SIG_IGN: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 370 | tprints("SIG_IGN"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 371 | break; |
| 372 | default: |
Dmitry V. Levin | 735843e | 2015-07-17 00:37:39 +0000 | [diff] [blame] | 373 | printaddr(tcp->u_arg[1]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 374 | } |
Wichert Akkerman | 16a03d2 | 2000-08-10 02:14:04 +0000 | [diff] [blame] | 375 | return 0; |
| 376 | } |
Dmitry V. Levin | 21a7534 | 2008-09-03 01:22:18 +0000 | [diff] [blame] | 377 | else if (!syserror(tcp)) { |
Wichert Akkerman | 16a03d2 | 2000-08-10 02:14:04 +0000 | [diff] [blame] | 378 | switch (tcp->u_rval) { |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 379 | case (long) SIG_ERR: |
Wichert Akkerman | 16a03d2 | 2000-08-10 02:14:04 +0000 | [diff] [blame] | 380 | tcp->auxstr = "SIG_ERR"; break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 381 | case (long) SIG_DFL: |
Wichert Akkerman | 16a03d2 | 2000-08-10 02:14:04 +0000 | [diff] [blame] | 382 | tcp->auxstr = "SIG_DFL"; break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 383 | case (long) SIG_IGN: |
Wichert Akkerman | 16a03d2 | 2000-08-10 02:14:04 +0000 | [diff] [blame] | 384 | tcp->auxstr = "SIG_IGN"; break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 385 | default: |
Wichert Akkerman | 16a03d2 | 2000-08-10 02:14:04 +0000 | [diff] [blame] | 386 | tcp->auxstr = NULL; |
| 387 | } |
| 388 | return RVAL_HEX | RVAL_STR; |
| 389 | } |
Dmitry V. Levin | 21a7534 | 2008-09-03 01:22:18 +0000 | [diff] [blame] | 390 | return 0; |
Wichert Akkerman | 16a03d2 | 2000-08-10 02:14:04 +0000 | [diff] [blame] | 391 | } |
| 392 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 393 | #endif /* HAVE_SIGACTION */ |
| 394 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 395 | SYS_FUNC(siggetmask) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 396 | { |
| 397 | if (exiting(tcp)) { |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 398 | tcp->auxstr = sprintsigmask_val("mask ", tcp->u_rval); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 399 | } |
| 400 | return RVAL_HEX | RVAL_STR; |
| 401 | } |
| 402 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 403 | SYS_FUNC(sigsuspend) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 404 | { |
Dmitry V. Levin | 0e45b50 | 2015-07-17 00:51:45 +0000 | [diff] [blame] | 405 | tprintsigmask_val("", tcp->u_arg[2]); |
| 406 | |
| 407 | return RVAL_DECODED; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 408 | } |
| 409 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 410 | #ifdef HAVE_SIGACTION |
| 411 | |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 412 | /* "Old" sigprocmask, which operates with word-sized signal masks */ |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 413 | SYS_FUNC(sigprocmask) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 414 | { |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 415 | # ifdef ALPHA |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 416 | if (entering(tcp)) { |
Mike Frysinger | dde045c | 2012-03-15 00:45:33 -0400 | [diff] [blame] | 417 | /* |
| 418 | * Alpha/OSF is different: it doesn't pass in two pointers, |
| 419 | * but rather passes in the new bitmask as an argument and |
| 420 | * then returns the old bitmask. This "works" because we |
| 421 | * only have 64 signals to worry about. If you want more, |
| 422 | * use of the rt_sigprocmask syscall is required. |
| 423 | * Alpha: |
| 424 | * old = osf_sigprocmask(how, new); |
| 425 | * Everyone else: |
| 426 | * ret = sigprocmask(how, &new, &old, ...); |
| 427 | */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 428 | printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???"); |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 429 | tprintsigmask_val(", ", tcp->u_arg[1]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 430 | } |
| 431 | else if (!syserror(tcp)) { |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 432 | tcp->auxstr = sprintsigmask_val("old mask ", tcp->u_rval); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 433 | return RVAL_HEX | RVAL_STR; |
| 434 | } |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 435 | # else /* !ALPHA */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 436 | if (entering(tcp)) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 437 | printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 438 | tprints(", "); |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 439 | print_sigset_addr_len(tcp, tcp->u_arg[1], current_wordsize); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 440 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 441 | } |
| 442 | else { |
Dmitry V. Levin | 735843e | 2015-07-17 00:37:39 +0000 | [diff] [blame] | 443 | print_sigset_addr_len(tcp, tcp->u_arg[2], current_wordsize); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 444 | } |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 445 | # endif /* !ALPHA */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 446 | return 0; |
| 447 | } |
| 448 | |
| 449 | #endif /* HAVE_SIGACTION */ |
| 450 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 451 | SYS_FUNC(kill) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 452 | { |
Dmitry V. Levin | 0e45b50 | 2015-07-17 00:51:45 +0000 | [diff] [blame] | 453 | tprintf("%ld, %s", |
| 454 | widen_to_long(tcp->u_arg[0]), |
| 455 | signame(tcp->u_arg[1])); |
| 456 | |
| 457 | return RVAL_DECODED; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 458 | } |
| 459 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 460 | SYS_FUNC(tgkill) |
Roland McGrath | 8ffc352 | 2003-07-09 09:47:49 +0000 | [diff] [blame] | 461 | { |
Dmitry V. Levin | 0e45b50 | 2015-07-17 00:51:45 +0000 | [diff] [blame] | 462 | tprintf("%ld, %ld, %s", |
| 463 | widen_to_long(tcp->u_arg[0]), |
| 464 | widen_to_long(tcp->u_arg[1]), |
| 465 | signame(tcp->u_arg[2])); |
| 466 | |
| 467 | return RVAL_DECODED; |
Roland McGrath | 8ffc352 | 2003-07-09 09:47:49 +0000 | [diff] [blame] | 468 | } |
Roland McGrath | 8ffc352 | 2003-07-09 09:47:49 +0000 | [diff] [blame] | 469 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 470 | SYS_FUNC(sigpending) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 471 | { |
Dmitry V. Levin | 735843e | 2015-07-17 00:37:39 +0000 | [diff] [blame] | 472 | if (exiting(tcp)) |
| 473 | print_sigset_addr_len(tcp, tcp->u_arg[0], current_wordsize); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 474 | return 0; |
| 475 | } |
| 476 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 477 | SYS_FUNC(rt_sigprocmask) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 478 | { |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 479 | /* 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] | 480 | if (entering(tcp)) { |
| 481 | printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 482 | tprints(", "); |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 483 | print_sigset_addr_len(tcp, tcp->u_arg[1], tcp->u_arg[3]); |
| 484 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 485 | } |
| 486 | else { |
Dmitry V. Levin | 735843e | 2015-07-17 00:37:39 +0000 | [diff] [blame] | 487 | 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] | 488 | tprintf(", %lu", tcp->u_arg[3]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 489 | } |
| 490 | return 0; |
| 491 | } |
| 492 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 493 | /* Structure describing the action to be taken when a signal arrives. */ |
| 494 | struct new_sigaction |
| 495 | { |
Denys Vlasenko | 86d9484 | 2013-02-08 12:59:13 +0100 | [diff] [blame] | 496 | /* sa_handler may be a libc #define, need to use other name: */ |
Chris Dearman | 2b4bb1c | 2013-12-09 19:58:42 -0800 | [diff] [blame] | 497 | #ifdef MIPS |
| 498 | unsigned int sa_flags; |
| 499 | void (*__sa_handler)(int); |
| 500 | #else |
Denys Vlasenko | 86d9484 | 2013-02-08 12:59:13 +0100 | [diff] [blame] | 501 | void (*__sa_handler)(int); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 502 | unsigned long sa_flags; |
Chris Dearman | 2b4bb1c | 2013-12-09 19:58:42 -0800 | [diff] [blame] | 503 | #endif /* !MIPS */ |
Dmitry V. Levin | 24b8eb0 | 2015-02-28 17:17:09 +0000 | [diff] [blame] | 504 | #if HAVE_SA_RESTORER |
Vicente Olivert Riera | c3a5c01 | 2014-09-11 20:05:18 +0100 | [diff] [blame] | 505 | void (*sa_restorer)(void); |
| 506 | #endif |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 507 | /* Kernel treats sa_mask as an array of longs. */ |
| 508 | unsigned long sa_mask[NSIG / sizeof(long) ? NSIG / sizeof(long) : 1]; |
| 509 | }; |
| 510 | /* Same for i386-on-x86_64 and similar cases */ |
| 511 | struct new_sigaction32 |
| 512 | { |
| 513 | uint32_t __sa_handler; |
| 514 | uint32_t sa_flags; |
Dmitry V. Levin | 24b8eb0 | 2015-02-28 17:17:09 +0000 | [diff] [blame] | 515 | #if HAVE_SA_RESTORER |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 516 | uint32_t sa_restorer; |
Vicente Olivert Riera | c3a5c01 | 2014-09-11 20:05:18 +0100 | [diff] [blame] | 517 | #endif |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 518 | uint32_t sa_mask[2 * (NSIG / sizeof(long) ? NSIG / sizeof(long) : 1)]; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 519 | }; |
| 520 | |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 521 | static void |
| 522 | decode_new_sigaction(struct tcb *tcp, long addr) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 523 | { |
| 524 | struct new_sigaction sa; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 525 | |
Denys Vlasenko | d4d3ede | 2013-02-13 16:31:32 +0100 | [diff] [blame] | 526 | #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 527 | if (current_wordsize != sizeof(sa.sa_flags) && current_wordsize == 4) { |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 528 | struct new_sigaction32 sa32; |
Dmitry V. Levin | 735843e | 2015-07-17 00:37:39 +0000 | [diff] [blame] | 529 | |
| 530 | if (umove_or_printaddr(tcp, addr, &sa32)) |
| 531 | return; |
| 532 | |
| 533 | memset(&sa, 0, sizeof(sa)); |
| 534 | sa.__sa_handler = (void*)(unsigned long)sa32.__sa_handler; |
| 535 | sa.sa_flags = sa32.sa_flags; |
Dmitry V. Levin | 24b8eb0 | 2015-02-28 17:17:09 +0000 | [diff] [blame] | 536 | #if HAVE_SA_RESTORER && defined SA_RESTORER |
Dmitry V. Levin | 735843e | 2015-07-17 00:37:39 +0000 | [diff] [blame] | 537 | sa.sa_restorer = (void*)(unsigned long)sa32.sa_restorer; |
Vicente Olivert Riera | c3a5c01 | 2014-09-11 20:05:18 +0100 | [diff] [blame] | 538 | #endif |
Dmitry V. Levin | 735843e | 2015-07-17 00:37:39 +0000 | [diff] [blame] | 539 | /* Kernel treats sa_mask as an array of longs. |
| 540 | * For 32-bit process, "long" is uint32_t, thus, for example, |
| 541 | * 32th bit in sa_mask will end up as bit 0 in sa_mask[1]. |
| 542 | * But for (64-bit) kernel, 32th bit in sa_mask is |
| 543 | * 32th bit in 0th (64-bit) long! |
| 544 | * For little-endian, it's the same. |
| 545 | * For big-endian, we swap 32-bit words. |
| 546 | */ |
| 547 | sa.sa_mask[0] = sa32.sa_mask[0] + ((long)(sa32.sa_mask[1]) << 32); |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 548 | } else |
| 549 | #endif |
Dmitry V. Levin | 735843e | 2015-07-17 00:37:39 +0000 | [diff] [blame] | 550 | if (umove_or_printaddr(tcp, addr, &sa)) |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 551 | return; |
Dmitry V. Levin | 735843e | 2015-07-17 00:37:39 +0000 | [diff] [blame] | 552 | |
Carlos O'Donell | 4677c8a | 2009-09-09 18:13:19 +0000 | [diff] [blame] | 553 | /* Architectures using function pointers, like |
| 554 | * hppa, may need to manipulate the function pointer |
| 555 | * to compute the result of a comparison. However, |
Denys Vlasenko | 86d9484 | 2013-02-08 12:59:13 +0100 | [diff] [blame] | 556 | * the __sa_handler function pointer exists only in |
Carlos O'Donell | 4677c8a | 2009-09-09 18:13:19 +0000 | [diff] [blame] | 557 | * the address space of the traced process, and can't |
| 558 | * be manipulated by strace. In order to prevent the |
| 559 | * compiler from generating code to manipulate |
Denys Vlasenko | 86d9484 | 2013-02-08 12:59:13 +0100 | [diff] [blame] | 560 | * __sa_handler we cast the function pointers to long. */ |
Carlos O'Donell | 4677c8a | 2009-09-09 18:13:19 +0000 | [diff] [blame] | 561 | if ((long)sa.__sa_handler == (long)SIG_ERR) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 562 | tprints("{SIG_ERR, "); |
Carlos O'Donell | 4677c8a | 2009-09-09 18:13:19 +0000 | [diff] [blame] | 563 | else if ((long)sa.__sa_handler == (long)SIG_DFL) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 564 | tprints("{SIG_DFL, "); |
Carlos O'Donell | 4677c8a | 2009-09-09 18:13:19 +0000 | [diff] [blame] | 565 | else if ((long)sa.__sa_handler == (long)SIG_IGN) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 566 | tprints("{SIG_IGN, "); |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 567 | else |
| 568 | tprintf("{%#lx, ", (long) sa.__sa_handler); |
Denys Vlasenko | 80b73a2 | 2013-07-18 10:10:46 +0200 | [diff] [blame] | 569 | /* |
| 570 | * Sigset size is in tcp->u_arg[4] (SPARC) |
| 571 | * or in tcp->u_arg[3] (all other), |
| 572 | * but kernel won't handle sys_rt_sigaction |
| 573 | * with wrong sigset size (just returns EINVAL instead). |
| 574 | * We just fetch the right size, which is NSIG / 8. |
| 575 | */ |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 576 | tprintsigmask_val("", sa.sa_mask); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 577 | tprints(", "); |
Denys Vlasenko | 80b73a2 | 2013-07-18 10:10:46 +0200 | [diff] [blame] | 578 | |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 579 | printflags(sigact_flags, sa.sa_flags, "SA_???"); |
Dmitry V. Levin | 24b8eb0 | 2015-02-28 17:17:09 +0000 | [diff] [blame] | 580 | #if HAVE_SA_RESTORER && defined SA_RESTORER |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 581 | if (sa.sa_flags & SA_RESTORER) |
| 582 | tprintf(", %p", sa.sa_restorer); |
| 583 | #endif |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 584 | tprints("}"); |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 585 | } |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 586 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 587 | SYS_FUNC(rt_sigaction) |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 588 | { |
| 589 | if (entering(tcp)) { |
| 590 | printsignal(tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 591 | tprints(", "); |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 592 | decode_new_sigaction(tcp, tcp->u_arg[1]); |
| 593 | tprints(", "); |
| 594 | } else { |
| 595 | decode_new_sigaction(tcp, tcp->u_arg[2]); |
Denys Vlasenko | 9472a27 | 2013-02-12 11:43:46 +0100 | [diff] [blame] | 596 | #if defined(SPARC) || defined(SPARC64) |
Wichert Akkerman | dacfb6e | 1999-06-03 14:21:07 +0000 | [diff] [blame] | 597 | tprintf(", %#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]); |
| 598 | #elif defined(ALPHA) |
| 599 | tprintf(", %lu, %#lx", tcp->u_arg[3], tcp->u_arg[4]); |
| 600 | #else |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 601 | tprintf(", %lu", tcp->u_arg[3]); |
Wichert Akkerman | dacfb6e | 1999-06-03 14:21:07 +0000 | [diff] [blame] | 602 | #endif |
Dmitry V. Levin | ac655a8 | 2014-01-07 22:41:30 +0000 | [diff] [blame] | 603 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 604 | return 0; |
| 605 | } |
| 606 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 607 | SYS_FUNC(rt_sigpending) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 608 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 609 | if (exiting(tcp)) { |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 610 | /* |
| 611 | * One of the few syscalls where sigset size (arg[1]) |
| 612 | * is allowed to be <= NSIG / 8, not strictly ==. |
| 613 | * This allows non-rt sigpending() syscall |
| 614 | * to reuse rt_sigpending() code in kernel. |
| 615 | */ |
Dmitry V. Levin | 735843e | 2015-07-17 00:37:39 +0000 | [diff] [blame] | 616 | print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]); |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 617 | tprintf(", %lu", tcp->u_arg[1]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 618 | } |
| 619 | return 0; |
| 620 | } |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 621 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 622 | SYS_FUNC(rt_sigsuspend) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 623 | { |
Dmitry V. Levin | 0e45b50 | 2015-07-17 00:51:45 +0000 | [diff] [blame] | 624 | /* NB: kernel requires arg[1] == NSIG / 8 */ |
| 625 | print_sigset_addr_len(tcp, tcp->u_arg[0], tcp->u_arg[1]); |
| 626 | tprintf(", %lu", tcp->u_arg[1]); |
| 627 | |
| 628 | return RVAL_DECODED; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 629 | } |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 630 | |
Dmitry V. Levin | 297632b | 2012-03-13 15:51:13 +0000 | [diff] [blame] | 631 | static void |
| 632 | print_sigqueueinfo(struct tcb *tcp, int sig, unsigned long uinfo) |
| 633 | { |
Dmitry V. Levin | 297632b | 2012-03-13 15:51:13 +0000 | [diff] [blame] | 634 | printsignal(sig); |
| 635 | tprints(", "); |
Dmitry V. Levin | e2fb0bb | 2015-09-15 21:51:15 +0000 | [diff] [blame] | 636 | printsiginfo_at(tcp, uinfo); |
Dmitry V. Levin | 297632b | 2012-03-13 15:51:13 +0000 | [diff] [blame] | 637 | } |
| 638 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 639 | SYS_FUNC(rt_sigqueueinfo) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 640 | { |
Dmitry V. Levin | 0e45b50 | 2015-07-17 00:51:45 +0000 | [diff] [blame] | 641 | tprintf("%lu, ", tcp->u_arg[0]); |
| 642 | print_sigqueueinfo(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 643 | |
| 644 | return RVAL_DECODED; |
Dmitry V. Levin | 297632b | 2012-03-13 15:51:13 +0000 | [diff] [blame] | 645 | } |
| 646 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 647 | SYS_FUNC(rt_tgsigqueueinfo) |
Dmitry V. Levin | 297632b | 2012-03-13 15:51:13 +0000 | [diff] [blame] | 648 | { |
Dmitry V. Levin | 0e45b50 | 2015-07-17 00:51:45 +0000 | [diff] [blame] | 649 | tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]); |
| 650 | print_sigqueueinfo(tcp, tcp->u_arg[2], tcp->u_arg[3]); |
| 651 | |
| 652 | return RVAL_DECODED; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 653 | } |
| 654 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 655 | SYS_FUNC(rt_sigtimedwait) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 656 | { |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 657 | /* NB: kernel requires arg[3] == NSIG / 8 */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 658 | if (entering(tcp)) { |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 659 | 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] | 660 | tprints(", "); |
Denys Vlasenko | b1a78cf | 2009-04-15 13:31:59 +0000 | [diff] [blame] | 661 | /* This is the only "return" parameter, */ |
| 662 | if (tcp->u_arg[1] != 0) |
| 663 | return 0; |
| 664 | /* ... if it's NULL, can decode all on entry */ |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 665 | tprints("NULL, "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 666 | } |
Denys Vlasenko | b1a78cf | 2009-04-15 13:31:59 +0000 | [diff] [blame] | 667 | else if (tcp->u_arg[1] != 0) { |
| 668 | /* syscall exit, and u_arg[1] wasn't NULL */ |
Dmitry V. Levin | e2fb0bb | 2015-09-15 21:51:15 +0000 | [diff] [blame] | 669 | printsiginfo_at(tcp, tcp->u_arg[1]); |
Denys Vlasenko | d4d3ede | 2013-02-13 16:31:32 +0100 | [diff] [blame] | 670 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 671 | } |
Denys Vlasenko | b1a78cf | 2009-04-15 13:31:59 +0000 | [diff] [blame] | 672 | else { |
| 673 | /* syscall exit, and u_arg[1] was NULL */ |
| 674 | return 0; |
| 675 | } |
Dmitry V. Levin | 3858b93 | 2015-09-18 01:54:59 +0000 | [diff] [blame] | 676 | |
| 677 | /* |
| 678 | * Since the timeout parameter is read by the kernel |
| 679 | * on entering syscall, it has to be decoded the same way |
| 680 | * whether the syscall has failed or not. |
| 681 | */ |
| 682 | temporarily_clear_syserror(tcp); |
Denys Vlasenko | b1a78cf | 2009-04-15 13:31:59 +0000 | [diff] [blame] | 683 | print_timespec(tcp, tcp->u_arg[2]); |
Dmitry V. Levin | 3858b93 | 2015-09-18 01:54:59 +0000 | [diff] [blame] | 684 | restore_cleared_syserror(tcp); |
| 685 | |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 686 | tprintf(", %lu", tcp->u_arg[3]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 687 | return 0; |
| 688 | }; |
| 689 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 690 | SYS_FUNC(restart_syscall) |
Roland McGrath | 79dcd7a | 2006-01-12 22:34:50 +0000 | [diff] [blame] | 691 | { |
Dmitry V. Levin | 0e45b50 | 2015-07-17 00:51:45 +0000 | [diff] [blame] | 692 | tprintf("<... resuming interrupted %s ...>", |
| 693 | tcp->s_prev_ent ? tcp->s_prev_ent->sys_name : "system call"); |
| 694 | |
| 695 | return RVAL_DECODED; |
Roland McGrath | 79dcd7a | 2006-01-12 22:34:50 +0000 | [diff] [blame] | 696 | } |