LCOV - code coverage report
Current view: top level - strace - printsiginfo.c (source / functions) Hit Total Coverage
Test: strace-4.18.0.129.97bbb Code Coverage Lines: 102 102 100.0 %
Date: 2017-07-31 03:46:08 Functions: 9 11 81.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 44 49 89.8 %

           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-1996 Rick Sladkey <jrs@world.std.com>
       5                 :            :  * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
       6                 :            :  * Copyright (c) 2001 John Hughes <john@Calva.COM>
       7                 :            :  * Copyright (c) 2013 Denys Vlasenko <vda.linux@googlemail.com>
       8                 :            :  * Copyright (c) 2011-2015 Dmitry V. Levin <ldv@altlinux.org>
       9                 :            :  * Copyright (c) 2015 Elvira Khabirova <lineprinter0@gmail.com>
      10                 :            :  * Copyright (c) 2015-2017 The strace developers.
      11                 :            :  * All rights reserved.
      12                 :            :  *
      13                 :            :  * Redistribution and use in source and binary forms, with or without
      14                 :            :  * modification, are permitted provided that the following conditions
      15                 :            :  * are met:
      16                 :            :  * 1. Redistributions of source code must retain the above copyright
      17                 :            :  *    notice, this list of conditions and the following disclaimer.
      18                 :            :  * 2. Redistributions in binary form must reproduce the above copyright
      19                 :            :  *    notice, this list of conditions and the following disclaimer in the
      20                 :            :  *    documentation and/or other materials provided with the distribution.
      21                 :            :  * 3. The name of the author may not be used to endorse or promote products
      22                 :            :  *    derived from this software without specific prior written permission.
      23                 :            :  *
      24                 :            :  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
      25                 :            :  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
      26                 :            :  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
      27                 :            :  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
      28                 :            :  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
      29                 :            :  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      30                 :            :  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      31                 :            :  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      32                 :            :  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
      33                 :            :  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      34                 :            :  */
      35                 :            : 
      36                 :            : #include "defs.h"
      37                 :            : 
      38                 :            : #include DEF_MPERS_TYPE(siginfo_t)
      39                 :            : 
      40                 :            : #include <signal.h>
      41                 :            : #include <linux/audit.h>
      42                 :            : 
      43                 :            : #include MPERS_DEFS
      44                 :            : 
      45                 :            : #ifndef IN_MPERS
      46                 :            : #include "printsiginfo.h"
      47                 :            : #endif
      48                 :            : 
      49                 :            : #include "xlat/audit_arch.h"
      50                 :            : #include "xlat/sigbus_codes.h"
      51                 :            : #include "xlat/sigchld_codes.h"
      52                 :            : #include "xlat/sigfpe_codes.h"
      53                 :            : #include "xlat/sigill_codes.h"
      54                 :            : #include "xlat/siginfo_codes.h"
      55                 :            : #include "xlat/sigpoll_codes.h"
      56                 :            : #include "xlat/sigprof_codes.h"
      57                 :            : #include "xlat/sigsegv_codes.h"
      58                 :            : #include "xlat/sigsys_codes.h"
      59                 :            : #include "xlat/sigtrap_codes.h"
      60                 :            : 
      61                 :            : #ifdef SIGEMT
      62                 :            : # include "xlat/sigemt_codes.h"
      63                 :            : #endif
      64                 :            : 
      65                 :            : #ifndef SI_FROMUSER
      66                 :            : # define SI_FROMUSER(sip)       ((sip)->si_code <= 0)
      67                 :            : #endif
      68                 :            : 
      69                 :            : static void
      70                 :            : printsigsource(const siginfo_t *sip)
      71                 :            : {
      72                 :       3341 :         tprintf(", si_pid=%u, si_uid=%u",
      73                 :         17 :                 (unsigned int) sip->si_pid,
      74                 :            :                 (unsigned int) sip->si_uid);
      75                 :            : }
      76                 :            : 
      77                 :            : static void
      78                 :          8 : printsigval(const siginfo_t *sip)
      79                 :            : {
      80                 :          8 :         tprintf(", si_value={int=%d, ptr=", sip->si_int);
      81                 :          8 :         printaddr(ptr_to_kulong(sip->si_ptr));
      82                 :          8 :         tprints("}");
      83                 :          8 : }
      84                 :            : 
      85                 :            : static void
      86                 :       3381 : print_si_code(int si_signo, unsigned int si_code)
      87                 :            : {
      88                 :       3381 :         const char *code = xlookup(siginfo_codes, si_code);
      89                 :            : 
      90         [ +  + ]:       3381 :         if (!code) {
      91   [ +  +  +  +  :       3109 :                 switch (si_signo) {
          +  +  +  +  +  
                      - ]
      92                 :            :                 case SIGTRAP:
      93                 :          2 :                         code = xlookup(sigtrap_codes, si_code);
      94                 :          2 :                         break;
      95                 :            :                 case SIGCHLD:
      96                 :       3091 :                         code = xlookup(sigchld_codes, si_code);
      97                 :       3091 :                         break;
      98                 :            :                 case SIGPOLL:
      99                 :          2 :                         code = xlookup(sigpoll_codes, si_code);
     100                 :          2 :                         break;
     101                 :            :                 case SIGPROF:
     102                 :          2 :                         code = xlookup(sigprof_codes, si_code);
     103                 :          2 :                         break;
     104                 :            :                 case SIGILL:
     105                 :          2 :                         code = xlookup(sigill_codes, si_code);
     106                 :          2 :                         break;
     107                 :            : #ifdef SIGEMT
     108                 :            :                 case SIGEMT:
     109                 :            :                         code = xlookup(sigemt_codes, si_code);
     110                 :            :                         break;
     111                 :            : #endif
     112                 :            :                 case SIGFPE:
     113                 :          2 :                         code = xlookup(sigfpe_codes, si_code);
     114                 :          2 :                         break;
     115                 :            :                 case SIGSEGV:
     116                 :          2 :                         code = xlookup(sigsegv_codes, si_code);
     117                 :          2 :                         break;
     118                 :            :                 case SIGBUS:
     119                 :          2 :                         code = xlookup(sigbus_codes, si_code);
     120                 :          2 :                         break;
     121                 :            :                 case SIGSYS:
     122                 :          4 :                         code = xlookup(sigsys_codes, si_code);
     123                 :          4 :                         break;
     124                 :            :                 }
     125                 :            :         }
     126                 :            : 
     127         [ +  + ]:       3381 :         if (code)
     128                 :       3379 :                 tprints(code);
     129                 :            :         else
     130                 :          2 :                 tprintf("%#x", si_code);
     131                 :       3381 : }
     132                 :            : 
     133                 :            : static void
     134                 :       3381 : print_si_info(const siginfo_t *sip)
     135                 :            : {
     136         [ +  + ]:       3381 :         if (sip->si_errno) {
     137                 :         20 :                 tprints(", si_errno=");
     138         [ +  + ]:         20 :                 if ((unsigned) sip->si_errno < nerrnos
     139         [ +  - ]:         14 :                     && errnoent[sip->si_errno])
     140                 :         14 :                         tprints(errnoent[sip->si_errno]);
     141                 :            :                 else
     142                 :          6 :                         tprintf("%d", sip->si_errno);
     143                 :            :         }
     144                 :            : 
     145         [ +  + ]:       3381 :         if (SI_FROMUSER(sip)) {
     146   [ +  +  +  + ]:        250 :                 switch (sip->si_code) {
     147                 :            :                 case SI_USER:
     148                 :        234 :                         printsigsource(sip);
     149                 :            :                         break;
     150                 :            :                 case SI_TKILL:
     151                 :          4 :                         printsigsource(sip);
     152                 :            :                         break;
     153                 :            : #if defined HAVE_SIGINFO_T_SI_TIMERID && defined HAVE_SIGINFO_T_SI_OVERRUN
     154                 :            :                 case SI_TIMER:
     155                 :          2 :                         tprintf(", si_timerid=%#x, si_overrun=%d",
     156                 :            :                                 sip->si_timerid, sip->si_overrun);
     157                 :          2 :                         printsigval(sip);
     158                 :          2 :                         break;
     159                 :            : #endif
     160                 :            :                 default:
     161                 :          3 :                         printsigsource(sip);
     162         [ +  + ]:          6 :                         if (sip->si_ptr)
     163                 :          4 :                                 printsigval(sip);
     164                 :            :                         break;
     165                 :            :                 }
     166                 :            :         } else {
     167   [ +  +  +  +  :       3131 :                 switch (sip->si_signo) {
                      + ]
     168                 :            :                 case SIGCHLD:
     169                 :       3081 :                         printsigsource(sip);
     170                 :       3091 :                         tprints(", si_status=");
     171         [ +  + ]:       3091 :                         if (sip->si_code == CLD_EXITED)
     172                 :       3071 :                                 tprintf("%d", sip->si_status);
     173                 :            :                         else
     174                 :         20 :                                 printsignal(sip->si_status);
     175                 :       3091 :                         tprintf(", si_utime=%llu, si_stime=%llu",
     176                 :       3091 :                                 zero_extend_signed_to_ull(sip->si_utime),
     177                 :       3091 :                                 zero_extend_signed_to_ull(sip->si_stime));
     178                 :       3091 :                         break;
     179                 :            :                 case SIGILL: case SIGFPE:
     180                 :            :                 case SIGSEGV: case SIGBUS:
     181                 :          8 :                         tprints(", si_addr=");
     182                 :          8 :                         printaddr(ptr_to_kulong(sip->si_addr));
     183                 :          8 :                         break;
     184                 :            :                 case SIGPOLL:
     185         [ +  - ]:          2 :                         switch (sip->si_code) {
     186                 :            :                         case POLL_IN: case POLL_OUT: case POLL_MSG:
     187                 :          2 :                                 tprintf(", si_band=%ld",
     188                 :          1 :                                         (long) sip->si_band);
     189                 :          2 :                                 break;
     190                 :            :                         }
     191                 :            :                         break;
     192                 :            : #ifdef HAVE_SIGINFO_T_SI_SYSCALL
     193                 :            :                 case SIGSYS: {
     194                 :          4 :                         const char *scname =
     195                 :          4 :                                 syscall_name((unsigned) sip->si_syscall);
     196                 :            : 
     197                 :          4 :                         tprints(", si_call_addr=");
     198                 :          4 :                         printaddr(ptr_to_kulong(sip->si_call_addr));
     199                 :          4 :                         tprints(", si_syscall=");
     200         [ +  + ]:          4 :                         if (scname)
     201                 :          2 :                                 tprintf("__NR_%s", scname);
     202                 :            :                         else
     203                 :          2 :                                 tprintf("%u", (unsigned) sip->si_syscall);
     204                 :          4 :                         tprints(", si_arch=");
     205                 :          4 :                         printxval(audit_arch, sip->si_arch, "AUDIT_ARCH_???");
     206                 :            :                         break;
     207                 :            :                 }
     208                 :            : #endif
     209                 :            :                 default:
     210 [ +  + ][ #  # ]:         26 :                         if (sip->si_pid || sip->si_uid)
     211                 :          1 :                                 printsigsource(sip);
     212         [ +  + ]:         26 :                         if (sip->si_ptr)
     213                 :          2 :                                 printsigval(sip);
     214                 :            :                 }
     215                 :            :         }
     216                 :       3381 : }
     217                 :            : 
     218                 :            : #ifdef IN_MPERS
     219                 :            : static
     220                 :            : #endif
     221                 :            : void
     222                 :       3385 : printsiginfo(const siginfo_t *sip)
     223                 :            : {
     224         [ +  + ]:       3385 :         if (sip->si_signo == 0) {
     225                 :          4 :                 tprints("{}");
     226                 :          4 :                 return;
     227                 :            :         }
     228                 :       3381 :         tprints("{si_signo=");
     229                 :       3381 :         printsignal(sip->si_signo);
     230                 :            : 
     231                 :       3381 :         tprints(", si_code=");
     232                 :       3381 :         print_si_code(sip->si_signo, sip->si_code);
     233                 :            : 
     234                 :            : #ifdef SI_NOINFO
     235                 :            :         if (sip->si_code != SI_NOINFO)
     236                 :            : #endif
     237                 :       3381 :                 print_si_info(sip);
     238                 :            : 
     239                 :       3381 :         tprints("}");
     240                 :            : }
     241                 :            : 
     242                 :         68 : MPERS_PRINTER_DECL(void, printsiginfo_at,
     243                 :            :                    struct tcb *const tcp, const kernel_ulong_t addr)
     244                 :            : {
     245                 :            :         siginfo_t si;
     246                 :            : 
     247         [ +  + ]:         68 :         if (!umove_or_printaddr(tcp, addr, &si))
     248                 :         48 :                 printsiginfo(&si);
     249                 :         68 : }
     250                 :            : 
     251                 :            : static bool
     252                 :          6 : print_siginfo_t(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
     253                 :            : {
     254                 :          6 :         printsiginfo((const siginfo_t *) elem_buf);
     255                 :          6 :         return true;
     256                 :            : }
     257                 :            : 
     258                 :          4 : MPERS_PRINTER_DECL(void, print_siginfo_array, struct tcb *const tcp,
     259                 :            :                    const kernel_ulong_t addr, const kernel_ulong_t len)
     260                 :            : {
     261                 :            :         siginfo_t si;
     262                 :            : 
     263                 :          4 :         print_array(tcp, addr, len, &si, sizeof(si),
     264                 :            :                     umoven_or_printaddr, print_siginfo_t, 0);
     265                 :          4 : }

Generated by: LCOV version 1.11