2015-12-17 20:56:48 +03:00
/*
* Copyright ( c ) 1991 , 1992 Paul Kranenburg < pk @ cs . few . eur . nl >
* Copyright ( c ) 1993 Branko Lankester < branko @ hacktic . nl >
* Copyright ( c ) 1993 - 1996 Rick Sladkey < jrs @ world . std . com >
* Copyright ( c ) 1996 - 1999 Wichert Akkerman < wichert @ cistron . nl >
* Copyright ( c ) 2001 John Hughes < john @ Calva . COM >
* Copyright ( c ) 2013 Denys Vlasenko < vda . linux @ googlemail . com >
* Copyright ( c ) 2011 - 2015 Dmitry V . Levin < ldv @ altlinux . org >
* Copyright ( c ) 2015 Elvira Khabirova < lineprinter0 @ gmail . com >
2017-05-22 20:14:52 +03:00
* Copyright ( c ) 2015 - 2017 The strace developers .
2015-12-17 20:56:48 +03:00
* All rights reserved .
*
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions
* are met :
* 1. Redistributions of source code must retain the above copyright
* notice , this list of conditions and the following disclaimer .
* 2. Redistributions in binary form must reproduce the above copyright
* notice , this list of conditions and the following disclaimer in the
* documentation and / or other materials provided with the distribution .
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission .
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ` ` AS IS ' ' AND ANY EXPRESS OR
* IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED .
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT , INDIRECT ,
* INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT
* NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE ,
* DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
* ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
*/
2015-03-28 02:28:15 +03:00
# include "defs.h"
2015-08-04 02:16:40 +03:00
# include DEF_MPERS_TYPE(siginfo_t)
2015-07-18 02:56:54 +03:00
# include <signal.h>
2015-08-18 10:24:59 +03:00
# include <linux/audit.h>
2015-07-18 02:56:54 +03:00
2015-08-04 02:16:40 +03:00
# include MPERS_DEFS
# ifndef IN_MPERS
2015-07-18 02:56:54 +03:00
# include "printsiginfo.h"
2015-08-04 02:16:40 +03:00
# endif
2015-07-18 02:56:54 +03:00
2015-08-18 10:24:59 +03:00
# include "xlat/audit_arch.h"
2015-03-28 02:28:15 +03:00
# include "xlat/sigbus_codes.h"
# include "xlat/sigchld_codes.h"
# include "xlat/sigfpe_codes.h"
# include "xlat/sigill_codes.h"
# include "xlat/siginfo_codes.h"
# include "xlat/sigpoll_codes.h"
# include "xlat/sigprof_codes.h"
# include "xlat/sigsegv_codes.h"
# include "xlat/sigsys_codes.h"
# include "xlat/sigtrap_codes.h"
# ifdef SIGEMT
# include "xlat / sigemt_codes.h"
# endif
# ifndef SI_FROMUSER
# define SI_FROMUSER(sip) ((sip)->si_code <= 0)
# endif
static void
printsigsource ( const siginfo_t * sip )
{
2015-08-21 20:46:35 +03:00
tprintf ( " , si_pid=%u, si_uid=%u " ,
( unsigned int ) sip - > si_pid ,
( unsigned int ) sip - > si_uid ) ;
2015-03-28 02:28:15 +03:00
}
static void
2016-05-13 17:16:12 +03:00
printsigval ( const siginfo_t * sip )
2015-03-28 02:28:15 +03:00
{
2016-06-11 04:28:21 +03:00
tprintf ( " , si_value={int=%d, ptr= " , sip - > si_int ) ;
2016-12-26 04:37:21 +03:00
printaddr ( ptr_to_kulong ( sip - > si_ptr ) ) ;
2016-06-11 04:28:21 +03:00
tprints ( " } " ) ;
2015-03-28 02:28:15 +03:00
}
static void
2016-05-15 00:46:05 +03:00
print_si_code ( int si_signo , unsigned int si_code )
2015-03-28 02:28:15 +03:00
{
const char * code = xlookup ( siginfo_codes , si_code ) ;
if ( ! code ) {
switch ( si_signo ) {
case SIGTRAP :
code = xlookup ( sigtrap_codes , si_code ) ;
break ;
case SIGCHLD :
code = xlookup ( sigchld_codes , si_code ) ;
break ;
case SIGPOLL :
code = xlookup ( sigpoll_codes , si_code ) ;
break ;
case SIGPROF :
code = xlookup ( sigprof_codes , si_code ) ;
break ;
case SIGILL :
code = xlookup ( sigill_codes , si_code ) ;
break ;
# ifdef SIGEMT
case SIGEMT :
code = xlookup ( sigemt_codes , si_code ) ;
break ;
# endif
case SIGFPE :
code = xlookup ( sigfpe_codes , si_code ) ;
break ;
case SIGSEGV :
code = xlookup ( sigsegv_codes , si_code ) ;
break ;
case SIGBUS :
code = xlookup ( sigbus_codes , si_code ) ;
break ;
case SIGSYS :
code = xlookup ( sigsys_codes , si_code ) ;
break ;
}
}
if ( code )
tprints ( code ) ;
else
tprintf ( " %#x " , si_code ) ;
}
static void
2016-05-13 17:16:12 +03:00
print_si_info ( const siginfo_t * sip )
2015-03-28 02:28:15 +03:00
{
if ( sip - > si_errno ) {
tprints ( " , si_errno= " ) ;
if ( ( unsigned ) sip - > si_errno < nerrnos
& & errnoent [ sip - > si_errno ] )
tprints ( errnoent [ sip - > si_errno ] ) ;
else
tprintf ( " %d " , sip - > si_errno ) ;
}
if ( SI_FROMUSER ( sip ) ) {
switch ( sip - > si_code ) {
case SI_USER :
printsigsource ( sip ) ;
break ;
case SI_TKILL :
printsigsource ( sip ) ;
break ;
# if defined HAVE_SIGINFO_T_SI_TIMERID && defined HAVE_SIGINFO_T_SI_OVERRUN
case SI_TIMER :
tprintf ( " , si_timerid=%#x, si_overrun=%d " ,
sip - > si_timerid , sip - > si_overrun ) ;
2016-05-13 17:16:12 +03:00
printsigval ( sip ) ;
2015-03-28 02:28:15 +03:00
break ;
# endif
default :
printsigsource ( sip ) ;
if ( sip - > si_ptr )
2016-05-13 17:16:12 +03:00
printsigval ( sip ) ;
2015-03-28 02:28:15 +03:00
break ;
}
} else {
switch ( sip - > si_signo ) {
case SIGCHLD :
printsigsource ( sip ) ;
tprints ( " , si_status= " ) ;
if ( sip - > si_code = = CLD_EXITED )
tprintf ( " %d " , sip - > si_status ) ;
else
printsignal ( sip - > si_status ) ;
2016-05-13 17:16:12 +03:00
tprintf ( " , si_utime=%llu, si_stime=%llu " ,
2016-08-23 03:24:10 +03:00
zero_extend_signed_to_ull ( sip - > si_utime ) ,
zero_extend_signed_to_ull ( sip - > si_stime ) ) ;
2015-03-28 02:28:15 +03:00
break ;
case SIGILL : case SIGFPE :
case SIGSEGV : case SIGBUS :
2016-06-11 04:28:21 +03:00
tprints ( " , si_addr= " ) ;
2016-12-26 04:37:21 +03:00
printaddr ( ptr_to_kulong ( sip - > si_addr ) ) ;
2015-03-28 02:28:15 +03:00
break ;
case SIGPOLL :
switch ( sip - > si_code ) {
case POLL_IN : case POLL_OUT : case POLL_MSG :
tprintf ( " , si_band=%ld " ,
( long ) sip - > si_band ) ;
break ;
}
break ;
# ifdef HAVE_SIGINFO_T_SI_SYSCALL
2016-11-30 23:43:51 +03:00
case SIGSYS : {
2018-02-01 13:46:57 +03:00
/*
* Note that we can safely use the personlity set in
* current_personality here ( and don ' t have to guess it
* based on X32_SYSCALL_BIT and si_arch , for example ) :
* - The signal is delivered as a result of seccomp
* filtering to the process executing forbidden
* syscall .
* - We have set the personality for the tracee during
* the syscall entering .
* - The current_personality is reliably switched in
* the next_event routine , it is set to the
* personality of the last call made ( the one that
* triggered the signal delivery ) .
* - Looks like there are no other cases where SIGSYS
* is delivered from the kernel so far .
*/
2016-11-30 23:43:51 +03:00
const char * scname =
syscall_name ( ( unsigned ) sip - > si_syscall ) ;
2016-06-11 04:28:21 +03:00
tprints ( " , si_call_addr= " ) ;
2016-12-26 04:37:21 +03:00
printaddr ( ptr_to_kulong ( sip - > si_call_addr ) ) ;
2016-11-30 23:43:51 +03:00
tprints ( " , si_syscall= " ) ;
if ( scname )
tprintf ( " __NR_%s " , scname ) ;
else
tprintf ( " %u " , ( unsigned ) sip - > si_syscall ) ;
tprints ( " , si_arch= " ) ;
2015-08-18 10:24:59 +03:00
printxval ( audit_arch , sip - > si_arch , " AUDIT_ARCH_??? " ) ;
2015-03-28 02:28:15 +03:00
break ;
2016-11-30 23:43:51 +03:00
}
2015-03-28 02:28:15 +03:00
# endif
default :
if ( sip - > si_pid | | sip - > si_uid )
printsigsource ( sip ) ;
if ( sip - > si_ptr )
2016-05-13 17:16:12 +03:00
printsigval ( sip ) ;
2015-03-28 02:28:15 +03:00
}
}
}
2015-08-04 02:16:40 +03:00
# ifdef IN_MPERS
static
# endif
2015-03-28 02:28:15 +03:00
void
2016-05-13 17:16:12 +03:00
printsiginfo ( const siginfo_t * sip )
2015-03-28 02:28:15 +03:00
{
if ( sip - > si_signo = = 0 ) {
tprints ( " {} " ) ;
return ;
}
tprints ( " {si_signo= " ) ;
printsignal ( sip - > si_signo ) ;
tprints ( " , si_code= " ) ;
print_si_code ( sip - > si_signo , sip - > si_code ) ;
# ifdef SI_NOINFO
if ( sip - > si_code ! = SI_NOINFO )
# endif
2016-05-13 17:16:12 +03:00
print_si_info ( sip ) ;
2015-03-28 02:28:15 +03:00
tprints ( " } " ) ;
}
2016-05-22 01:53:06 +03:00
MPERS_PRINTER_DECL ( void , printsiginfo_at ,
2016-12-26 13:26:03 +03:00
struct tcb * const tcp , const kernel_ulong_t addr )
2015-03-28 02:28:15 +03:00
{
siginfo_t si ;
2015-07-18 00:58:18 +03:00
if ( ! umove_or_printaddr ( tcp , addr , & si ) )
2016-05-13 17:16:12 +03:00
printsiginfo ( & si ) ;
2015-03-28 02:28:15 +03:00
}
2016-05-13 05:33:33 +03:00
static bool
print_siginfo_t ( struct tcb * tcp , void * elem_buf , size_t elem_size , void * data )
{
2016-05-13 17:16:12 +03:00
printsiginfo ( ( const siginfo_t * ) elem_buf ) ;
2016-05-13 05:33:33 +03:00
return true ;
}
2016-12-22 23:44:44 +03:00
MPERS_PRINTER_DECL ( void , print_siginfo_array , struct tcb * const tcp ,
2016-12-26 13:26:03 +03:00
const kernel_ulong_t addr , const kernel_ulong_t len )
2016-05-13 05:33:33 +03:00
{
siginfo_t si ;
print_array ( tcp , addr , len , & si , sizeof ( si ) ,
umoven_or_printaddr , print_siginfo_t , 0 ) ;
}