LCOV - code coverage report
Current view: top level - strace - signal.c (source / functions) Hit Total Coverage
Test: strace-4.18.0.129.97bbb Code Coverage Lines: 208 218 95.4 %
Date: 2017-07-31 03:46:08 Functions: 26 27 96.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 73 86 84.9 %

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

Generated by: LCOV version 1.11