1999-02-19 03:21:36 +03:00
/*
* Copyright ( c ) 1991 , 1992 Paul Kranenburg < pk @ cs . few . eur . nl >
* Copyright ( c ) 1993 Branko Lankester < branko @ hacktic . nl >
* Copyright ( c ) 1993 , 1994 , 1995 , 1996 Rick Sladkey < jrs @ world . std . com >
1999-12-23 17:20:14 +03:00
* Copyright ( c ) 1996 - 1999 Wichert Akkerman < wichert @ cistron . nl >
* Copyright ( c ) 1999 IBM Deutschland Entwicklung GmbH , IBM Corporation
* Linux for s390 port by D . J . Barrow
* < barrow_dj @ mail . yahoo . com , djbarrow @ de . ibm . com >
2002-05-01 20:39:22 +04:00
* Copyright ( c ) 2000 PocketPenguins Inc . Linux for Hitachi SuperH
* port by Greg Banks < gbanks @ pocketpenguins . com >
1999-12-23 17:20:14 +03:00
*
1999-02-19 03:21:36 +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 .
*/
# include "defs.h"
2014-12-11 22:25:02 +03:00
2013-03-18 04:52:29 +04:00
# ifdef HAVE_ELF_H
# include <elf.h>
# endif
1999-02-19 03:21:36 +03:00
2014-12-11 22:25:02 +03:00
# include "xlat/nt_descriptor_types.h"
2015-02-28 15:20:21 +03:00
# include "regs.h"
2015-02-13 03:26:38 +03:00
# include "ptrace.h"
2014-12-11 22:25:02 +03:00
# include "xlat/ptrace_cmds.h"
# include "xlat/ptrace_setoptions_flags.h"
2016-05-12 18:45:24 +03:00
# include "xlat/ptrace_peeksiginfo_flags.h"
2014-12-11 22:25:02 +03:00
2012-03-21 17:39:22 +04:00
# define uoff(member) offsetof(struct user, member)
2014-12-11 22:25:02 +03:00
# define XLAT_UOFF(member) { uoff(member), "offsetof(struct user, " #member ")" }
2012-03-21 17:39:22 +04:00
2014-12-11 22:25:02 +03:00
static const struct xlat struct_user_offsets [ ] = {
process.c: split struct_user_offsets into architecture-specific include files
* Makefile.am (EXTRA_DIST): Add linux/alpha/userent.h,
linux/arm/userent.h, linux/avr32/userent.h, linux/bfin/userent.h,
linux/crisv10/userent.h, linux/crisv32/userent.h,
linux/i386/userent.h, linux/i386/userent0.h, linux/ia64/userent.h,
linux/m68k/userent.h, linux/microblaze/userent.h,
linux/mips/userent.h, linux/or1k/userent.h, linux/powerpc/userent.h,
linux/s390/userent.h, linux/s390/userent0.h, linux/s390/userent1.h,
linux/s390x/userent.h, linux/sh/userent.h, linux/sh/userent0.h,
linux/sh64/userent.h, linux/sparc/userent.h, linux/sparc64/userent.h,
linux/tile/userent.h, linux/userent.h, linux/userent0.h,
linux/x32/userent.h, linux/x86_64/userent.h, and
linux/xtensa/userent.h.
* process.c (struct_user_offsets): Split into architecture-specific
include files, inculde userent.h.
2014-12-11 22:25:02 +03:00
# include "userent.h"
2014-02-05 06:20:51 +04:00
XLAT_END
1999-02-19 03:21:36 +03:00
} ;
2016-04-01 03:28:33 +03:00
static void
print_user_offset_addr ( const unsigned long addr )
1999-02-19 03:21:36 +03:00
{
2004-09-04 07:39:20 +04:00
const struct xlat * x ;
2016-04-01 03:28:33 +03:00
for ( x = struct_user_offsets ; x - > str ; + + x ) {
if ( x - > val > = addr )
break ;
}
if ( ! x - > str ) {
printaddr ( addr ) ;
} else if ( x - > val > addr ) {
if ( x = = struct_user_offsets ) {
printaddr ( addr ) ;
} else {
- - x ;
tprintf ( " %s + %lu " ,
x - > str , addr - ( unsigned long ) x - > val ) ;
}
} else {
tprints ( x - > str ) ;
}
}
SYS_FUNC ( ptrace )
{
2016-05-12 17:45:38 +03:00
const unsigned long request = tcp - > u_arg [ 0 ] ;
2016-04-01 03:28:33 +03:00
const int pid = tcp - > u_arg [ 1 ] ;
const unsigned long addr = tcp - > u_arg [ 2 ] ;
const unsigned long data = tcp - > u_arg [ 3 ] ;
1999-02-19 03:21:36 +03:00
2003-01-14 12:46:21 +03:00
if ( entering ( tcp ) ) {
2016-05-12 17:45:38 +03:00
/* request */
printxval64 ( ptrace_cmds , request , " PTRACE_??? " ) ;
2016-05-12 18:03:58 +03:00
if ( request = = PTRACE_TRACEME ) {
/* pid, addr, and data are ignored. */
return RVAL_DECODED ;
}
2016-05-12 17:45:38 +03:00
/* pid */
2016-05-12 18:10:41 +03:00
tprintf ( " , %d " , pid ) ;
2013-02-13 19:10:10 +04:00
2016-05-12 17:45:38 +03:00
/* addr */
2016-04-01 03:28:33 +03:00
switch ( request ) {
2016-05-12 18:10:41 +03:00
case PTRACE_ATTACH :
case PTRACE_INTERRUPT :
case PTRACE_KILL :
case PTRACE_LISTEN :
/* addr and data are ignored */
return RVAL_DECODED ;
2016-04-01 03:28:33 +03:00
case PTRACE_PEEKUSER :
case PTRACE_POKEUSER :
2016-05-12 18:10:41 +03:00
tprints ( " , " ) ;
2016-04-01 03:28:33 +03:00
print_user_offset_addr ( addr ) ;
break ;
case PTRACE_GETREGSET :
case PTRACE_SETREGSET :
2016-05-12 18:10:41 +03:00
tprints ( " , " ) ;
2016-04-01 03:28:33 +03:00
printxval ( nt_descriptor_types , addr , " NT_??? " ) ;
break ;
2016-05-12 18:38:35 +03:00
case PTRACE_GETSIGMASK :
case PTRACE_SETSIGMASK :
case PTRACE_SECCOMP_GET_FILTER :
tprintf ( " , %lu " , addr ) ;
break ;
2016-05-12 18:45:24 +03:00
case PTRACE_PEEKSIGINFO : {
tprints ( " , " ) ;
struct {
uint64_t off ;
uint32_t flags ;
uint32_t nr ;
} psi ;
if ( umove_or_printaddr ( tcp , addr , & psi ) ) {
tprints ( " , " ) ;
printaddr ( data ) ;
return RVAL_DECODED ;
}
tprintf ( " {off=% " PRIu64 " , flags= " , psi . off ) ;
printflags ( ptrace_peeksiginfo_flags , psi . flags ,
" PTRACE_PEEKSIGINFO_??? " ) ;
tprintf ( " , nr=%u} " , psi . nr ) ;
break ;
}
2016-05-12 18:18:05 +03:00
# if defined SPARC || defined SPARC64
case PTRACE_GETREGS :
case PTRACE_SETREGS :
case PTRACE_GETFPREGS :
case PTRACE_SETFPREGS :
tprints ( " , " ) ;
printaddr ( addr ) ;
/* data is ignored */
return RVAL_DECODED ;
# endif
2016-04-01 03:28:33 +03:00
default :
2016-05-12 18:10:41 +03:00
tprints ( " , " ) ;
2015-07-18 00:12:05 +03:00
printaddr ( addr ) ;
2016-04-01 03:28:33 +03:00
}
2015-07-18 00:12:05 +03:00
tprints ( " , " ) ;
2013-02-13 19:10:10 +04:00
2016-05-12 18:10:41 +03:00
/* data */
2016-04-01 03:28:33 +03:00
switch ( request ) {
2012-03-17 04:27:37 +04:00
# ifndef IA64
1999-02-19 03:21:36 +03:00
case PTRACE_PEEKDATA :
case PTRACE_PEEKTEXT :
case PTRACE_PEEKUSER :
break ;
2012-03-17 04:27:37 +04:00
# endif
1999-02-19 03:21:36 +03:00
case PTRACE_CONT :
case PTRACE_SINGLESTEP :
case PTRACE_SYSCALL :
case PTRACE_DETACH :
2016-04-01 03:28:33 +03:00
printsignal ( data ) ;
1999-02-19 03:21:36 +03:00
break ;
2009-01-13 21:30:55 +03:00
case PTRACE_SETOPTIONS :
2016-04-01 03:28:33 +03:00
printflags ( ptrace_setoptions_flags , data , " PTRACE_O_??? " ) ;
2009-01-13 21:30:55 +03:00
break ;
2016-04-01 03:28:33 +03:00
case PTRACE_SETSIGINFO :
printsiginfo_at ( tcp , data ) ;
2009-01-13 21:30:55 +03:00
break ;
2013-02-13 19:10:10 +04:00
case PTRACE_SETREGSET :
2016-04-01 03:28:33 +03:00
tprint_iov ( tcp , /*len:*/ 1 , data , /*as string:*/ 0 ) ;
2013-02-13 19:10:10 +04:00
break ;
2015-02-13 03:26:38 +03:00
case PTRACE_GETSIGINFO :
case PTRACE_GETREGSET :
/* Don't print anything, do it at syscall return. */
break ;
1999-02-19 03:21:36 +03:00
default :
2016-04-01 03:28:33 +03:00
printaddr ( data ) ;
1999-02-19 03:21:36 +03:00
break ;
}
} else {
2016-04-01 03:28:33 +03:00
switch ( request ) {
1999-02-19 03:21:36 +03:00
case PTRACE_PEEKDATA :
case PTRACE_PEEKTEXT :
case PTRACE_PEEKUSER :
2012-03-17 04:27:37 +04:00
# ifdef IA64
2007-11-20 01:11:45 +03:00
return RVAL_HEX ;
2012-03-17 04:27:37 +04:00
# else
2016-04-01 03:28:33 +03:00
printnum_ptr ( tcp , data ) ;
1999-02-19 03:21:36 +03:00
break ;
2012-03-17 04:27:37 +04:00
# endif
2016-04-01 03:28:33 +03:00
case PTRACE_GETSIGINFO :
printsiginfo_at ( tcp , data ) ;
2009-01-13 21:30:55 +03:00
break ;
2013-02-13 19:10:10 +04:00
case PTRACE_GETREGSET :
2016-04-01 03:28:33 +03:00
tprint_iov ( tcp , /*len:*/ 1 , data , /*as string:*/ 0 ) ;
2013-02-13 19:10:10 +04:00
break ;
1999-02-19 03:21:36 +03:00
}
}
return 0 ;
}