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