2011-04-08 00:25:40 +04:00
/*
* Copyright ( c ) 2011 , Comtrol Corp .
* 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"
2011-08-30 20:05:26 +04:00
# include <sys/param.h>
2015-07-30 19:23:58 +03:00
# include <poll.h>
2011-04-08 00:25:40 +04:00
# include "syscall.h"
2013-03-05 19:01:53 +04:00
const char * * paths_selected = NULL ;
2013-03-05 18:46:34 +04:00
static unsigned num_selected = 0 ;
2011-04-08 00:25:40 +04:00
/*
* Return true if specified path matches one that we ' re tracing .
*/
static int
pathmatch ( const char * path )
{
2013-03-05 18:46:34 +04:00
unsigned i ;
2011-04-08 00:25:40 +04:00
2013-03-05 18:46:34 +04:00
for ( i = 0 ; i < num_selected ; + + i ) {
2013-03-05 19:01:53 +04:00
if ( strcmp ( path , paths_selected [ i ] ) = = 0 )
2011-04-08 00:25:40 +04:00
return 1 ;
}
return 0 ;
}
/*
* Return true if specified path ( in user - space ) matches .
*/
static int
upathmatch ( struct tcb * tcp , unsigned long upath )
{
2011-06-22 16:32:43 +04:00
char path [ PATH_MAX + 1 ] ;
2011-04-08 00:25:40 +04:00
2013-02-26 23:23:27 +04:00
return umovestr ( tcp , upath , sizeof path , path ) > 0 & &
2011-04-08 00:25:40 +04:00
pathmatch ( path ) ;
}
/*
* Return true if specified fd maps to a path we ' re tracing .
*/
static int
fdmatch ( struct tcb * tcp , int fd )
{
2013-03-06 21:24:34 +04:00
char path [ PATH_MAX + 1 ] ;
int n = getfdpath ( tcp , fd , path , sizeof ( path ) ) ;
2011-04-08 00:25:40 +04:00
2013-03-06 21:24:34 +04:00
return n > = 0 & & pathmatch ( path ) ;
2011-04-08 00:25:40 +04:00
}
/*
* Add a path to the set we ' re tracing .
Add decoding of sockets descriptor 'paths' for network calls
* net.c (sys_bind, sys_listen, do_accept, sys_send, sys_sendto,
sys_sendmsg, sys_sendmmsg, sys_recv, sys_recvfrom, sys_recvmsg,
sys_recvmmsg, sys_shutdown, sys_getsockopt, sys_setsockopt): Decode
socket descriptor arguments using printfd.
* pathtrace.c (pathtrace_match): Also check TRACE_NETWORK syscalls
that take socket descriptor arguments.
* tests/net-fd.test: New test for socket descriptor arguments decoding.
* tests/Makefile.am (TESTS): Add net-fd.test.
(net-fd.log): New dependency on net.log.
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-02-01 21:57:45 +04:00
* Specifying NULL will delete all paths .
2011-04-08 00:25:40 +04:00
*/
2013-03-05 18:46:34 +04:00
static void
2011-04-08 00:25:40 +04:00
storepath ( const char * path )
{
2013-03-05 18:46:34 +04:00
unsigned i ;
2011-04-08 00:25:40 +04:00
2013-03-05 18:46:34 +04:00
if ( pathmatch ( path ) )
return ; /* already in table */
2011-04-08 00:25:40 +04:00
2013-03-05 18:46:34 +04:00
i = num_selected + + ;
Introduce memory allocation wrappers
Introduce wrappers to the following functions that do memory allocation:
malloc, calloc, realloc, strdup.
This commit is a follow-up to the related discussions in strace-devel ML:
http://sourceforge.net/p/strace/mailman/message/33618180/
http://sourceforge.net/p/strace/mailman/message/33733470/
* defs.h (xmalloc, xcalloc, xreallocarray, xstrdup): New prototypes.
* xmalloc.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* count.c (count_syscall, call_summary_pers): Use xcalloc.
* desc.c (decode_select): Use xmalloc.
* dirent.c (sys_getdents, sys_getdents64): Likewise.
* net.c (sys_recvmmsg): Use xstrdup.
* pathtrace.c (storepath): Use xreallocarray.
(pathtrace_match): Use xmalloc.
* strace.c (die_out_of_memory): Move to xmalloc.c.
(expand_tcbtab): Use xcalloc and xreallocarray.
(startup_child): Use xstrdup.
(init): Use xmalloc, xcalloc, and xstrdup.
* syscall.c (reallocate_qual): Use xreallocarray.
(qualify): Use xstrdup.
* unwind.c (unwind_tcb_init): Use xmalloc.
(build_mmap_cache): Use xcalloc, xreallocarray, and xstrdup.
(get_symbol_name): Use xreallocarray.
(stacktrace_walk, queue_put): Use xmalloc.
* util.c (printstr): Use xmalloc.
* vsprintf.c (strace_vfprintf): Likewise.
2015-05-25 23:41:02 +03:00
paths_selected = xreallocarray ( paths_selected , num_selected ,
sizeof ( paths_selected [ 0 ] ) ) ;
2013-03-05 19:01:53 +04:00
paths_selected [ i ] = path ;
2011-04-08 00:25:40 +04:00
}
/*
* Get path associated with fd .
*/
2013-03-06 21:24:34 +04:00
int
getfdpath ( struct tcb * tcp , int fd , char * buf , unsigned bufsize )
2011-04-08 00:25:40 +04:00
{
2012-03-15 21:11:51 +04:00
char linkpath [ sizeof ( " /proc/%u/fd/%u " ) + 2 * sizeof ( int ) * 3 ] ;
2011-04-08 00:25:40 +04:00
ssize_t n ;
if ( fd < 0 )
2013-03-06 21:24:34 +04:00
return - 1 ;
2011-04-08 00:25:40 +04:00
2012-03-15 21:03:56 +04:00
sprintf ( linkpath , " /proc/%u/fd/%u " , tcp - > pid , fd ) ;
2013-03-06 21:24:34 +04:00
n = readlink ( linkpath , buf , bufsize - 1 ) ;
/*
* NB : if buf is too small , readlink doesn ' t fail ,
* it returns truncated result ( IOW : n = = bufsize - 1 ) .
*/
if ( n > = 0 )
buf [ n ] = ' \0 ' ;
return n ;
2011-04-08 00:25:40 +04:00
}
/*
* Add a path to the set we ' re tracing . Also add the canonicalized
* version of the path . Secifying NULL will delete all paths .
*/
2013-03-05 18:46:34 +04:00
void
2011-04-08 00:25:40 +04:00
pathtrace_select ( const char * path )
{
2012-03-15 21:03:56 +04:00
char * rpath ;
2011-04-08 00:25:40 +04:00
2013-03-05 18:46:34 +04:00
storepath ( path ) ;
2011-04-08 00:25:40 +04:00
rpath = realpath ( path , NULL ) ;
if ( rpath = = NULL )
2013-03-05 18:46:34 +04:00
return ;
2011-04-08 00:25:40 +04:00
/* if realpath and specified path are same, we're done */
2012-03-15 21:03:56 +04:00
if ( strcmp ( path , rpath ) = = 0 ) {
2011-04-08 00:25:40 +04:00
free ( rpath ) ;
2013-03-05 18:46:34 +04:00
return ;
2011-04-08 00:25:40 +04:00
}
Consistently use error_msg instead of fprintf(stderr)
* linux/alpha/get_scno.c: Use error_msg.
* linux/arm/get_scno.c: Likewise.
* linux/mips/get_scno.c: Likewise.
* linux/sh/get_scno.c: Likewise.
* linux/x86_64/get_scno.c: Likewise.
* exit.c (sys_exit): Likewise.
* pathtrace.c (pathtrace_select, pathtrace_match): Likewise.
* strace.c (alloctcb, droptcb, detach, startup_attach,
test_ptrace_seize, init, cleanup, print_debug_info,
maybe_allocate_tcb, startup_tcb, trace): Likewise.
* syscall.c (update_personality, trace_syscall_exiting,
get_scno): Likewise.
* unwind.c (DPRINTF): Likewise.
* tests/bexecve.test: Update patterns.
* tests/detach-stopped.test: Likewise.
2015-05-26 01:51:19 +03:00
error_msg ( " Requested path '%s' resolved into '%s' " , path , rpath ) ;
2013-03-05 18:46:34 +04:00
storepath ( rpath ) ;
2011-04-08 00:25:40 +04:00
}
/*
* Return true if syscall accesses a selected path
* ( or if no paths have been specified for tracing ) .
*/
int
pathtrace_match ( struct tcb * tcp )
{
2013-02-22 16:26:10 +04:00
const struct_sysent * s ;
2011-04-08 00:25:40 +04:00
2013-02-21 19:13:47 +04:00
s = tcp - > s_ent ;
2011-04-08 00:25:40 +04:00
Add decoding of sockets descriptor 'paths' for network calls
* net.c (sys_bind, sys_listen, do_accept, sys_send, sys_sendto,
sys_sendmsg, sys_sendmmsg, sys_recv, sys_recvfrom, sys_recvmsg,
sys_recvmmsg, sys_shutdown, sys_getsockopt, sys_setsockopt): Decode
socket descriptor arguments using printfd.
* pathtrace.c (pathtrace_match): Also check TRACE_NETWORK syscalls
that take socket descriptor arguments.
* tests/net-fd.test: New test for socket descriptor arguments decoding.
* tests/Makefile.am (TESTS): Add net-fd.test.
(net-fd.log): New dependency on net.log.
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-02-01 21:57:45 +04:00
if ( ! ( s - > sys_flags & ( TRACE_FILE | TRACE_DESC | TRACE_NETWORK ) ) )
2011-04-08 00:25:40 +04:00
return 0 ;
/*
* Check for special cases where we need to do something
* other than test arg [ 0 ] .
*/
2015-07-10 22:24:58 +03:00
switch ( s - > sen ) {
case SEN_dup2 :
case SEN_dup3 :
2015-11-22 21:51:05 +03:00
case SEN_kexec_file_load :
2015-07-10 22:24:58 +03:00
case SEN_sendfile :
case SEN_sendfile64 :
case SEN_tee :
2011-04-08 00:25:40 +04:00
/* fd, fd */
return fdmatch ( tcp , tcp - > u_arg [ 0 ] ) | |
fdmatch ( tcp , tcp - > u_arg [ 1 ] ) ;
2015-07-10 22:24:58 +03:00
case SEN_faccessat :
case SEN_fchmodat :
case SEN_fchownat :
case SEN_futimesat :
case SEN_inotify_add_watch :
case SEN_mkdirat :
case SEN_mknodat :
2015-11-23 00:29:32 +03:00
case SEN_name_to_handle_at :
2015-07-10 22:24:58 +03:00
case SEN_newfstatat :
case SEN_openat :
case SEN_pipe2 :
case SEN_readlinkat :
case SEN_unlinkat :
case SEN_utimensat :
2011-04-08 00:25:40 +04:00
/* fd, path */
return fdmatch ( tcp , tcp - > u_arg [ 0 ] ) | |
upathmatch ( tcp , tcp - > u_arg [ 1 ] ) ;
2015-07-10 22:24:58 +03:00
case SEN_link :
case SEN_mount :
case SEN_pivotroot :
2011-04-08 00:25:40 +04:00
/* path, path */
return upathmatch ( tcp , tcp - > u_arg [ 0 ] ) | |
upathmatch ( tcp , tcp - > u_arg [ 1 ] ) ;
2015-07-10 22:24:58 +03:00
case SEN_quotactl :
2012-10-27 03:43:13 +04:00
/* x, path */
return upathmatch ( tcp , tcp - > u_arg [ 1 ] ) ;
2015-07-10 22:24:58 +03:00
case SEN_linkat :
case SEN_renameat2 :
case SEN_renameat :
2011-04-08 00:25:40 +04:00
/* fd, path, fd, path */
return fdmatch ( tcp , tcp - > u_arg [ 0 ] ) | |
fdmatch ( tcp , tcp - > u_arg [ 2 ] ) | |
upathmatch ( tcp , tcp - > u_arg [ 1 ] ) | |
upathmatch ( tcp , tcp - > u_arg [ 3 ] ) ;
2015-07-10 22:24:58 +03:00
case SEN_old_mmap :
Clean up mmap decoding
Previous code merges too many similar, but different ways
of decoding mmap. For example, sys_old_mmap is "params in memory"
API... except SH[64], where it is "params in regs",
i.e. what sys_mmap ("new mmap") function does on other arches!
It's much simpler when every mmap handler has same API regardless
of arch. Where API means whether params are in regs or in memory,
and whether offset is in bytes, pages, or 4k blocks.
Then we just insert correct function pointers into
arch syscall tables.
It turns out there are four common mmap APIs over
all architectures which exist in Linux kernel,
and one outlier for S390.
A number of mmap decoders were plain wrong in arch tables.
For example, BFIN has no old_mmap. It returns ENOSYS.
I checked kernel sources for all arches nad fixed the tables.
There was dead code for x86_64 for old_mmap:
x86_64 has no old_mmap.
* mem.c: Refactor mmap functions so that we have five mmap syscall
handlers, each with the fixed API (not varying by arch).
* pathtrace.c (pathtrace_match): Adjust sys_func == mmap_func checks.
* linux/syscall.h: Declare new mmap syscall handler functions.
* linux/arm/syscallent.h: mmap2 is sys_mmap_pgoff.
* linux/avr32/syscallent.h: mmap is sys_mmap_pgoff.
* linux/bfin/syscallent.h: old_mmap is ENOSYS, mmap2 is sys_mmap_pgoff.
* linux/hppa/syscallent.h: mmap2 is sys_mmap_4koff.
* linux/i386/syscallent.h: mmap2 is sys_mmap_pgoff.
* linux/ia64/syscallent.h: mmap2 is sys_mmap_pgoff.
* linux/m68k/syscallent.h: mmap2 is sys_mmap_pgoff.
* linux/microblaze/syscallent.h: old_mmap is sys_mmap, mmap2 is sys_mmap_pgoff.
* linux/mips/syscallent.h: mmap is sys_mmap_4kgoff.
* linux/or1k/syscallent.h: mmap2 is sys_mmap_pgoff.
* linux/powerpc/syscallent.h: mmap2 is sys_mmap_4kgoff.
* linux/s390/syscallent.h: mmap2 is sys_old_mmap_pgoff.
* linux/s390x/syscallent.h: mmap is sys_old_mmap and thus has 1 arg.
* linux/sh/syscallent.h: old_mmap2 is sys_mmap, mmap2 is sys_mmap_4koff.
* linux/sh64/syscallent.h: Likewise.
* linux/sparc/syscallent1.h: mmap is TD|TM.
* linux/tile/syscallent1.h: mmap2 is sys_mmap_4koff.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-02-19 14:28:20 +04:00
# if defined(S390)
2015-07-10 22:24:58 +03:00
case SEN_old_mmap_pgoff :
Clean up mmap decoding
Previous code merges too many similar, but different ways
of decoding mmap. For example, sys_old_mmap is "params in memory"
API... except SH[64], where it is "params in regs",
i.e. what sys_mmap ("new mmap") function does on other arches!
It's much simpler when every mmap handler has same API regardless
of arch. Where API means whether params are in regs or in memory,
and whether offset is in bytes, pages, or 4k blocks.
Then we just insert correct function pointers into
arch syscall tables.
It turns out there are four common mmap APIs over
all architectures which exist in Linux kernel,
and one outlier for S390.
A number of mmap decoders were plain wrong in arch tables.
For example, BFIN has no old_mmap. It returns ENOSYS.
I checked kernel sources for all arches nad fixed the tables.
There was dead code for x86_64 for old_mmap:
x86_64 has no old_mmap.
* mem.c: Refactor mmap functions so that we have five mmap syscall
handlers, each with the fixed API (not varying by arch).
* pathtrace.c (pathtrace_match): Adjust sys_func == mmap_func checks.
* linux/syscall.h: Declare new mmap syscall handler functions.
* linux/arm/syscallent.h: mmap2 is sys_mmap_pgoff.
* linux/avr32/syscallent.h: mmap is sys_mmap_pgoff.
* linux/bfin/syscallent.h: old_mmap is ENOSYS, mmap2 is sys_mmap_pgoff.
* linux/hppa/syscallent.h: mmap2 is sys_mmap_4koff.
* linux/i386/syscallent.h: mmap2 is sys_mmap_pgoff.
* linux/ia64/syscallent.h: mmap2 is sys_mmap_pgoff.
* linux/m68k/syscallent.h: mmap2 is sys_mmap_pgoff.
* linux/microblaze/syscallent.h: old_mmap is sys_mmap, mmap2 is sys_mmap_pgoff.
* linux/mips/syscallent.h: mmap is sys_mmap_4kgoff.
* linux/or1k/syscallent.h: mmap2 is sys_mmap_pgoff.
* linux/powerpc/syscallent.h: mmap2 is sys_mmap_4kgoff.
* linux/s390/syscallent.h: mmap2 is sys_old_mmap_pgoff.
* linux/s390x/syscallent.h: mmap is sys_old_mmap and thus has 1 arg.
* linux/sh/syscallent.h: old_mmap2 is sys_mmap, mmap2 is sys_mmap_4koff.
* linux/sh64/syscallent.h: Likewise.
* linux/sparc/syscallent1.h: mmap is TD|TM.
* linux/tile/syscallent1.h: mmap2 is sys_mmap_4koff.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-02-19 14:28:20 +04:00
# endif
2015-07-10 22:24:58 +03:00
case SEN_mmap :
case SEN_mmap_4koff :
case SEN_mmap_pgoff :
2015-12-24 18:40:55 +03:00
case SEN_ARCH_mmap :
2011-04-08 00:25:40 +04:00
/* x, x, x, x, fd */
return fdmatch ( tcp , tcp - > u_arg [ 4 ] ) ;
2015-07-10 22:24:58 +03:00
case SEN_symlinkat :
2011-04-08 00:25:40 +04:00
/* path, fd, path */
return fdmatch ( tcp , tcp - > u_arg [ 1 ] ) | |
upathmatch ( tcp , tcp - > u_arg [ 0 ] ) | |
2011-06-07 14:13:24 +04:00
upathmatch ( tcp , tcp - > u_arg [ 2 ] ) ;
2011-04-08 00:25:40 +04:00
2015-07-10 22:24:58 +03:00
case SEN_splice :
2011-04-08 00:25:40 +04:00
/* fd, x, fd, x, x */
return fdmatch ( tcp , tcp - > u_arg [ 0 ] ) | |
fdmatch ( tcp , tcp - > u_arg [ 2 ] ) ;
2015-07-10 22:24:58 +03:00
case SEN_epoll_ctl :
2011-04-08 00:25:40 +04:00
/* x, x, fd, x */
return fdmatch ( tcp , tcp - > u_arg [ 2 ] ) ;
2015-07-10 22:24:58 +03:00
case SEN_fanotify_mark :
2014-02-05 08:13:18 +04:00
/* x, x, x, fd, path */
return fdmatch ( tcp , tcp - > u_arg [ 3 ] ) | |
upathmatch ( tcp , tcp - > u_arg [ 4 ] ) ;
2015-07-10 22:24:58 +03:00
case SEN_oldselect :
case SEN_pselect6 :
case SEN_select :
2011-04-08 00:25:40 +04:00
{
2011-09-01 18:35:44 +04:00
int i , j ;
2013-11-09 23:46:55 +04:00
int nfds ;
2011-04-08 00:25:40 +04:00
long * args , oldargs [ 5 ] ;
unsigned fdsize ;
fd_set * fds ;
2013-11-09 23:46:55 +04:00
args = tcp - > u_arg ;
2015-07-10 22:24:58 +03:00
if ( SEN_oldselect = = s - > sen ) {
2011-04-08 00:25:40 +04:00
if ( umoven ( tcp , tcp - > u_arg [ 0 ] , sizeof oldargs ,
2015-03-21 21:50:53 +03:00
oldargs ) < 0 )
2011-04-08 00:25:40 +04:00
{
Consistently use error_msg instead of fprintf(stderr)
* linux/alpha/get_scno.c: Use error_msg.
* linux/arm/get_scno.c: Likewise.
* linux/mips/get_scno.c: Likewise.
* linux/sh/get_scno.c: Likewise.
* linux/x86_64/get_scno.c: Likewise.
* exit.c (sys_exit): Likewise.
* pathtrace.c (pathtrace_select, pathtrace_match): Likewise.
* strace.c (alloctcb, droptcb, detach, startup_attach,
test_ptrace_seize, init, cleanup, print_debug_info,
maybe_allocate_tcb, startup_tcb, trace): Likewise.
* syscall.c (update_personality, trace_syscall_exiting,
get_scno): Likewise.
* unwind.c (DPRINTF): Likewise.
* tests/bexecve.test: Update patterns.
* tests/detach-stopped.test: Likewise.
2015-05-26 01:51:19 +03:00
error_msg ( " umoven() failed " ) ;
2011-04-08 00:25:40 +04:00
return 0 ;
}
args = oldargs ;
2013-11-09 23:46:55 +04:00
}
2011-04-08 00:25:40 +04:00
2013-11-09 23:46:55 +04:00
/* Kernel truncates arg[0] to int, we do the same. */
nfds = ( int ) args [ 0 ] ;
/* Kernel rejects negative nfds, so we don't parse it either. */
if ( nfds < = 0 )
return 0 ;
2011-09-01 18:35:44 +04:00
/* Beware of select(2^31-1, NULL, NULL, NULL) and similar... */
2013-11-09 23:46:55 +04:00
if ( nfds > 1024 * 1024 )
2011-09-01 18:35:44 +04:00
nfds = 1024 * 1024 ;
2013-11-09 23:46:55 +04:00
fdsize = ( ( ( nfds + 7 ) / 8 ) + current_wordsize - 1 ) & - current_wordsize ;
Introduce memory allocation wrappers
Introduce wrappers to the following functions that do memory allocation:
malloc, calloc, realloc, strdup.
This commit is a follow-up to the related discussions in strace-devel ML:
http://sourceforge.net/p/strace/mailman/message/33618180/
http://sourceforge.net/p/strace/mailman/message/33733470/
* defs.h (xmalloc, xcalloc, xreallocarray, xstrdup): New prototypes.
* xmalloc.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* count.c (count_syscall, call_summary_pers): Use xcalloc.
* desc.c (decode_select): Use xmalloc.
* dirent.c (sys_getdents, sys_getdents64): Likewise.
* net.c (sys_recvmmsg): Use xstrdup.
* pathtrace.c (storepath): Use xreallocarray.
(pathtrace_match): Use xmalloc.
* strace.c (die_out_of_memory): Move to xmalloc.c.
(expand_tcbtab): Use xcalloc and xreallocarray.
(startup_child): Use xstrdup.
(init): Use xmalloc, xcalloc, and xstrdup.
* syscall.c (reallocate_qual): Use xreallocarray.
(qualify): Use xstrdup.
* unwind.c (unwind_tcb_init): Use xmalloc.
(build_mmap_cache): Use xcalloc, xreallocarray, and xstrdup.
(get_symbol_name): Use xreallocarray.
(stacktrace_walk, queue_put): Use xmalloc.
* util.c (printstr): Use xmalloc.
* vsprintf.c (strace_vfprintf): Likewise.
2015-05-25 23:41:02 +03:00
fds = xmalloc ( fdsize ) ;
2011-04-08 00:25:40 +04:00
2011-06-22 16:32:43 +04:00
for ( i = 1 ; i < = 3 ; + + i ) {
2011-04-08 00:25:40 +04:00
if ( args [ i ] = = 0 )
continue ;
2015-03-21 21:50:53 +03:00
if ( umoven ( tcp , args [ i ] , fdsize , fds ) < 0 ) {
Consistently use error_msg instead of fprintf(stderr)
* linux/alpha/get_scno.c: Use error_msg.
* linux/arm/get_scno.c: Likewise.
* linux/mips/get_scno.c: Likewise.
* linux/sh/get_scno.c: Likewise.
* linux/x86_64/get_scno.c: Likewise.
* exit.c (sys_exit): Likewise.
* pathtrace.c (pathtrace_select, pathtrace_match): Likewise.
* strace.c (alloctcb, droptcb, detach, startup_attach,
test_ptrace_seize, init, cleanup, print_debug_info,
maybe_allocate_tcb, startup_tcb, trace): Likewise.
* syscall.c (update_personality, trace_syscall_exiting,
get_scno): Likewise.
* unwind.c (DPRINTF): Likewise.
* tests/bexecve.test: Update patterns.
* tests/detach-stopped.test: Likewise.
2015-05-26 01:51:19 +03:00
error_msg ( " umoven() failed " ) ;
2011-04-08 00:25:40 +04:00
continue ;
}
2013-11-09 23:46:55 +04:00
for ( j = 0 ; ; j + + ) {
j = next_set_bit ( fds , j , nfds ) ;
if ( j < 0 )
break ;
if ( fdmatch ( tcp , j ) ) {
2011-04-08 00:25:40 +04:00
free ( fds ) ;
return 1 ;
}
2013-11-09 23:46:55 +04:00
}
2011-04-08 00:25:40 +04:00
}
free ( fds ) ;
return 0 ;
}
2015-07-10 22:24:58 +03:00
case SEN_poll :
case SEN_ppoll :
2011-04-08 00:25:40 +04:00
{
struct pollfd fds ;
unsigned nfds ;
unsigned long start , cur , end ;
start = tcp - > u_arg [ 0 ] ;
nfds = tcp - > u_arg [ 1 ] ;
end = start + sizeof ( fds ) * nfds ;
if ( nfds = = 0 | | end < start )
return 0 ;
for ( cur = start ; cur < end ; cur + = sizeof ( fds ) )
2015-03-21 21:50:53 +03:00
if ( ( umoven ( tcp , cur , sizeof fds , & fds ) = = 0 )
2011-04-08 00:25:40 +04:00
& & fdmatch ( tcp , fds . fd ) )
return 1 ;
return 0 ;
}
2015-07-26 02:55:51 +03:00
case SEN_bpf :
2015-07-10 22:24:58 +03:00
case SEN_epoll_create :
2015-08-02 02:07:19 +03:00
case SEN_epoll_create1 :
2015-07-10 22:24:58 +03:00
case SEN_eventfd2 :
case SEN_eventfd :
case SEN_fanotify_init :
case SEN_inotify_init1 :
2015-07-29 02:03:41 +03:00
case SEN_memfd_create :
2015-07-10 22:24:58 +03:00
case SEN_perf_event_open :
case SEN_pipe :
case SEN_printargs :
case SEN_socket :
case SEN_socketpair :
case SEN_timerfd_create :
case SEN_timerfd_gettime :
case SEN_timerfd_settime :
2015-11-22 22:56:00 +03:00
case SEN_userfaultfd :
2011-04-08 00:25:40 +04:00
/*
Add decoding of sockets descriptor 'paths' for network calls
* net.c (sys_bind, sys_listen, do_accept, sys_send, sys_sendto,
sys_sendmsg, sys_sendmmsg, sys_recv, sys_recvfrom, sys_recvmsg,
sys_recvmmsg, sys_shutdown, sys_getsockopt, sys_setsockopt): Decode
socket descriptor arguments using printfd.
* pathtrace.c (pathtrace_match): Also check TRACE_NETWORK syscalls
that take socket descriptor arguments.
* tests/net-fd.test: New test for socket descriptor arguments decoding.
* tests/Makefile.am (TESTS): Add net-fd.test.
(net-fd.log): New dependency on net.log.
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-02-01 21:57:45 +04:00
* These have TRACE_FILE or TRACE_DESCRIPTOR or TRACE_NETWORK set ,
* but they don ' t have any file descriptor or path args to test .
2011-04-08 00:25:40 +04:00
*/
return 0 ;
}
/*
* Our fallback position for calls that haven ' t already
* been handled is to just check arg [ 0 ] .
*/
if ( s - > sys_flags & TRACE_FILE )
return upathmatch ( tcp , tcp - > u_arg [ 0 ] ) ;
Add decoding of sockets descriptor 'paths' for network calls
* net.c (sys_bind, sys_listen, do_accept, sys_send, sys_sendto,
sys_sendmsg, sys_sendmmsg, sys_recv, sys_recvfrom, sys_recvmsg,
sys_recvmmsg, sys_shutdown, sys_getsockopt, sys_setsockopt): Decode
socket descriptor arguments using printfd.
* pathtrace.c (pathtrace_match): Also check TRACE_NETWORK syscalls
that take socket descriptor arguments.
* tests/net-fd.test: New test for socket descriptor arguments decoding.
* tests/Makefile.am (TESTS): Add net-fd.test.
(net-fd.log): New dependency on net.log.
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-02-01 21:57:45 +04:00
if ( s - > sys_flags & ( TRACE_DESC | TRACE_NETWORK ) )
2011-04-08 00:25:40 +04:00
return fdmatch ( tcp , tcp - > u_arg [ 0 ] ) ;
return 0 ;
}