]> granicus.if.org Git - strace/log
strace
12 years agox86_64: add getcpu syscall entry
Dmitry V. Levin [Sun, 27 Nov 2011 22:49:04 +0000 (22:49 +0000)]
x86_64: add getcpu syscall entry

* linux/x86_64/syscallent.h: Add syscall entry for getcpu.

12 years agoAdd syscall entries for new linux syscalls
Dmitry V. Levin [Sat, 26 Nov 2011 23:37:23 +0000 (23:37 +0000)]
Add syscall entries for new linux syscalls

* linux/dummy.h: Add printargs parsers for new syscalls.
* linux/arm/syscallent.h: Add entries for sys_clock_adjtime,
sys_name_to_handle_at, sys_open_by_handle_at, sys_sendmmsg, sys_setns
and sys_syncfs.
* linux/i386/syscallent.h: Likewise.
* linux/ia64/syscallent.h: Likewise.
* linux/mips/syscallent.h: Likewise.
* linux/powerpc/syscallent.h: Likewise.
* linux/sh/syscallent.h: Likewise.
* linux/sh64/syscallent.h: Likewise.
* linux/sparc/syscallent.h: Likewise.
* linux/x86_64/syscallent.h: Likewise.
* linux/alpha/syscallent.h: Add entries for sys_clock_adjtime,
sys_name_to_handle_at, sys_open_by_handle_at, sys_setns and sys_syncfs.
* linux/m68k/syscallent.h: Likewise.
* linux/microblaze/syscallent.h: Likewise.
* linux/s390/syscallent.h: Likewise.
* linux/s390x/syscallent.h: Likewise.
* linux/avr32/syscallent.h: Add entry for sys_setns.
* linux/bfin/syscallent.h: Add entries for sys_sendmmsg and sys_setns.
* linux/hppa/syscallent.h: Add entries for sys_clock_adjtime,
fanotify_init, fanotify_mark, sys_name_to_handle_at,
sys_open_by_handle_at, sys_sendmmsg, sys_setns and sys_syncfs.

12 years agoFix prctl syscall entries
Dmitry V. Levin [Sat, 26 Nov 2011 23:14:40 +0000 (23:14 +0000)]
Fix prctl syscall entries

* linux/mips/syscallent.h: Fix prctl handler.
* linux/tile/syscallent.h: Likewise.

12 years agoarm: fix io_* syscall entries
Dmitry V. Levin [Sat, 26 Nov 2011 23:08:14 +0000 (23:08 +0000)]
arm: fix io_* syscall entries

* linux/arm/syscallent.h: Fix handlers for io_setup, io_destroy,
io_getevents, io_submit and io_cancel.

12 years agoFix mincore syscall entries
Dmitry V. Levin [Sat, 26 Nov 2011 23:03:35 +0000 (23:03 +0000)]
Fix mincore syscall entries

* linux/arm/syscallent.h: Fix mincore handler.
* linux/avr32/syscallent.h: Likewise.
* linux/mips/syscallent.h: Likewise.
* linux/sh/syscallent.h: Likewise.
* linux/sh64/syscallent.h: Likewise.

12 years agoFix sendmsg syscall entries
Dmitry V. Levin [Fri, 25 Nov 2011 23:51:53 +0000 (23:51 +0000)]
Fix sendmsg syscall entries

* linux/arm/syscallent.h: Fix number of sendmsg arguments.
* linux/avr32/syscallent.h: Likewise.
* linux/bfin/syscallent.h: Likewise.
* linux/hppa/syscallent.h: Likewise.
* linux/i386/syscallent.h: Likewise.
* linux/m68k/syscallent.h: Likewise.
* linux/microblaze/syscallent.h: Likewise.
* linux/powerpc/syscallent.h: Likewise.
* linux/s390/syscallent.h: Likewise.
* linux/s390x/syscallent.h: Likewise.
* linux/sh/syscallent.h: Likewise.
* linux/sh64/syscallent.h: Likewise.
* linux/sparc/syscallent.h: Likewise.
* linux/tile/syscallent.h: Likewise.
* linux/x86_64/syscallent.h: Likewise.

12 years agoFix epoll_wait syscall entries
Dmitry V. Levin [Fri, 25 Nov 2011 23:45:28 +0000 (23:45 +0000)]
Fix epoll_wait syscall entries

* linux/arm/syscallent.h: Fix epoll_wait flags and handler.
* linux/m68k/syscallent.h: Fix epoll_wait flags.
* linux/microblaze/syscallent.h: Fix number of epoll_wait arguments.
* linux/sh/syscallent.h: Likewise.
* linux/sh64/syscallent.h: Likewise.
* linux/x86_64/syscallent.h: Likewise.

12 years agoFix epoll_ctl syscall entries
Dmitry V. Levin [Fri, 25 Nov 2011 23:40:16 +0000 (23:40 +0000)]
Fix epoll_ctl syscall entries

* linux/arm/syscallent.h: Fix epoll_ctl flags and handler.
* linux/m68k/syscallent.h: Fix epoll_ctl flags.
* linux/x86_64/syscallent.h: Fix number of epoll_ctl arguments.

12 years agoarm: fix epoll_create syscall entry
Dmitry V. Levin [Fri, 25 Nov 2011 23:34:12 +0000 (23:34 +0000)]
arm: fix epoll_create syscall entry

* linux/arm/syscallent.h: Fix epoll_create handler.

12 years agoFix mlockall syscall entries
Dmitry V. Levin [Fri, 25 Nov 2011 23:24:48 +0000 (23:24 +0000)]
Fix mlockall syscall entries

* linux/arm/syscallent.h: Fix number of mlockall arguments.
* linux/avr32/syscallent.h: Likewise.
* linux/bfin/syscallent.h: Likewise.
* linux/i386/syscallent.h: Likewise.
* linux/m68k/syscallent.h: Likewise.
* linux/microblaze/syscallent.h: Likewise.
* linux/s390/syscallent.h: Likewise.
* linux/s390x/syscallent.h: Likewise.
* linux/sh/syscallent.h: Likewise.
* linux/sh64/syscallent.h: Likewise.
* linux/sparc/syscallent.h: Likewise.
* linux/tile/syscallent.h: Likewise.
* linux/x86_64/syscallent.h: Likewise.

12 years agoFix epoll_pwait syscall entries
Dmitry V. Levin [Fri, 25 Nov 2011 23:19:47 +0000 (23:19 +0000)]
Fix epoll_pwait syscall entries

* linux/alpha/syscallent.h: Fix number of epoll_pwait arguments.
* linux/arm/syscallent.h: Likewise.
* linux/avr32/syscallent.h: Likewise.
* linux/bfin/syscallent.h: Likewise.
* linux/i386/syscallent.h: Likewise.
* linux/ia64/syscallent.h: Likewise.
* linux/m68k/syscallent.h: Likewise.
* linux/microblaze/syscallent.h: Likewise.
* linux/mips/syscallent.h: Likewise.
* linux/powerpc/syscallent.h: Likewise.
* linux/s390/syscallent.h: Likewise.
* linux/s390x/syscallent.h: Likewise.
* linux/sh/syscallent.h: Likewise.
* linux/sh64/syscallent.h: Likewise.
* linux/sparc/syscallent.h: Likewise.
* linux/tile/syscallent.h: Likewise.
* linux/x86_64/syscallent.h: Likewise.

12 years agoFix reboot syscall entries
Dmitry V. Levin [Fri, 25 Nov 2011 23:13:15 +0000 (23:13 +0000)]
Fix reboot syscall entries

* linux/alpha/syscallent.h: Fix number of reboot arguments.
* linux/arm/syscallent.h: Likewise.
* linux/avr32/syscallent.h: Likewise.
* linux/bfin/syscallent.h: Likewise.
* linux/hppa/syscallent.h: Likewise.
* linux/i386/syscallent.h: Likewise.
* linux/ia64/syscallent.h: Likewise.
* linux/m68k/syscallent.h: Likewise.
* linux/microblaze/syscallent.h: Likewise.
* linux/mips/syscallent.h: Likewise.
* linux/powerpc/syscallent.h: Likewise.
* linux/s390/syscallent.h: Likewise.
* linux/s390x/syscallent.h: Likewise.
* linux/sh/syscallent.h: Likewise.
* linux/sh64/syscallent.h: Likewise.
* linux/sparc/syscallent.h: Likewise.
* linux/tile/syscallent.h: Likewise.
* linux/x86_64/syscallent.h: Likewise.

12 years agoFix swapon syscall entries
Dmitry V. Levin [Fri, 25 Nov 2011 23:04:04 +0000 (23:04 +0000)]
Fix swapon syscall entries

* linux/arm/syscallent.h: Fix number of swapon arguments.
* linux/avr32/syscallent.h: Likewise.
* linux/bfin/syscallent.h: Likewise.
* linux/i386/syscallent.h: Likewise.
* linux/m68k/syscallent.h: Likewise.
* linux/microblaze/syscallent.h: Likewise.
* linux/mips/syscallent.h: Likewise.
* linux/powerpc/syscallent.h: Likewise.
* linux/s390/syscallent.h: Likewise.
* linux/s390x/syscallent.h: Likewise.
* linux/sh/syscallent.h: Likewise.
* linux/sh64/syscallent.h: Likewise.
* linux/sparc/syscallent.h: Likewise.
* linux/tile/syscallent.h: Likewise.
* linux/x86_64/syscallent.h: Likewise.
* linux/alpha/syscallent.h: Fix number of swapon arguments, add TF flag.
* linux/hppa/syscallent.h: Likewise.
* linux/ia64/syscallent.h: Likewise.

12 years agoFix sgetmask and ssetmask syscall entries
Dmitry V. Levin [Fri, 25 Nov 2011 21:57:31 +0000 (21:57 +0000)]
Fix sgetmask and ssetmask syscall entries

* linux/hppa/syscallent.h: Fix sgetmask and ssetmask entries.
* linux/powerpc/syscallent.h: Likewise.
* linux/sparc/syscallent.h: Likewise.
* linux/tile/syscallent.h: Likewise.

12 years agoRename siggetmask to sgetmask and sigsetmask to ssetmask
Dmitry V. Levin [Fri, 25 Nov 2011 21:43:01 +0000 (21:43 +0000)]
Rename siggetmask to sgetmask and sigsetmask to ssetmask

* linux/arm/syscallent.h: Rename siggetmask to sgetmask and
sigsetmask to ssetmask.
* linux/bfin/syscallent.h: Likewise.
* linux/i386/syscallent.h: Likewise.
* linux/m68k/syscallent.h: Likewise.
* linux/microblaze/syscallent.h: Likewise.
* linux/mips/syscallent.h: Likewise.
* linux/sh/syscallent.h: Likewise.
* linux/sh64/syscallent.h: Likewise.
* linux/ia64/syscallent.h: Rename sys_sgetmask to sys_siggetmask,
sys_ssetmask to sys_sigsetmask.

12 years agoAdd TRACE_IPC flag to sys_ipc syscall entries
Dmitry V. Levin [Fri, 25 Nov 2011 19:27:23 +0000 (19:27 +0000)]
Add TRACE_IPC flag to sys_ipc syscall entries

* linux/arm/syscallent.h: Add TI flag to sys_ipc entry.
* linux/avr32/syscallent.h: Likewise.
* linux/bfin/syscallent.h: Likewise.
* linux/i386/syscallent.h: Likewise.
* linux/m68k/syscallent.h: Likewise.
* linux/microblaze/syscallent.h: Likewise.
* linux/mips/syscallent.h: Likewise.
* linux/powerpc/syscallent.h: Likewise.
* linux/s390/syscallent.h: Likewise.
* linux/s390x/syscallent.h: Likewise.
* linux/sh/syscallent.h: Likewise.
* linux/sh64/syscallent.h: Likewise.
* linux/sparc/syscallent.h: Likewise.

12 years agogitlog-to-changelog: update from gnulib
Dmitry V. Levin [Sat, 5 Nov 2011 13:32:27 +0000 (13:32 +0000)]
gitlog-to-changelog: update from gnulib

* gitlog-to-changelog: Update from gnulib.
* Makefile.am: Add --append-dot to gitlog-to-changelog invocation.

12 years agoDecode TIOCSCTTY's third parameter
Denys Vlasenko [Sat, 22 Oct 2011 02:52:18 +0000 (04:52 +0200)]
Decode TIOCSCTTY's third parameter

* term.c (term_ioctl): Decode TIOCSCTTY's third parameter.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoRemove useless and obsolete "#if DONE" sections. No code changes
Dmitry V. Levin [Wed, 12 Oct 2011 23:22:06 +0000 (23:22 +0000)]
Remove useless and obsolete "#if DONE" sections.  No code changes

* linux/dummy.h: Remove "#if DONE" section.
* linux/sparc/dummy2.h: Likewise.
* linux/sparc64/dummy2.h: Likewise.
* sunos4/dummy.h: Likewise.
* svr4/dummy.h: Likewise.

12 years agoAdd names for dummy parsers. No code changes
Dmitry V. Levin [Wed, 12 Oct 2011 19:03:29 +0000 (19:03 +0000)]
Add names for dummy parsers.  No code changes

* linux/dummy.h: Add aliases to printargs() for those of dummy parsers
that had no own names before.
* linux/*/syscallent.h: Use these new names instead of printargs.

12 years agoSort definitions of dummy parsers. No code changes
Dmitry V. Levin [Wed, 12 Oct 2011 16:40:17 +0000 (16:40 +0000)]
Sort definitions of dummy parsers.  No code changes

* linux/dummy.h: Sort definitions of parsers implemented as aliases
to printargs().

12 years agosys_epoll_create1: decode flag arguments correctly
Mike Frysinger [Fri, 14 Oct 2011 02:33:45 +0000 (22:33 -0400)]
sys_epoll_create1: decode flag arguments correctly

* desc.c (epollflags): Define.
(sys_epoll_create1): Use epollflags to printflags. Change "O" to "EPOLL".

Reported-by: Марк Коренберг <socketpair@gmail.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
12 years agoImplement decoding of splice, tee and vmsplice(2) syscalls
Dmitry V. Levin [Tue, 11 Oct 2011 17:07:05 +0000 (17:07 +0000)]
Implement decoding of splice, tee and vmsplice(2) syscalls

* io.c (print_loff_t): New function.
(sys_sendfile64): Use it.
(splice_flags): New xlat structure.
(sys_tee, sys_splice, sys_vmsplice): New functions.
* linux/syscall.h (sys_tee, sys_splice, sys_vmsplice): Declare them.
* linux/*/syscallent.h: Use them.

12 years agoFix epoll_wait and epoll_pwait decoding
Dmitry V. Levin [Tue, 11 Oct 2011 16:05:57 +0000 (16:05 +0000)]
Fix epoll_wait and epoll_pwait decoding

* desc.c (epoll_wait_common): Print "maxevents" and "timeout" arguments
as integers.

Reported-by: Марк Коренберг <socketpair@gmail.com>
12 years agoDecode EPOLLRDHUP
Dmitry V. Levin [Tue, 11 Oct 2011 15:55:40 +0000 (15:55 +0000)]
Decode EPOLLRDHUP

* desc.c (epollevents): Add EPOLLRDHUP.

Reported-by: Марк Коренберг <socketpair@gmail.com>
12 years agoRemove unreachable code in umoven() and umovestr().
Dmitry V. Levin [Tue, 11 Oct 2011 15:26:15 +0000 (15:26 +0000)]
Remove unreachable code in umoven() and umovestr().

* util.c (umoven, umovestr): Remove unreachable code.

Reported-by: Weichuan Yan <wchyan@marvell.com>
12 years agoDo post-attach initialization earlier; fix "we ignore SIGSTOP on NOMMU" bug
Denys Vlasenko [Mon, 5 Sep 2011 12:05:46 +0000 (14:05 +0200)]
Do post-attach initialization earlier; fix "we ignore SIGSTOP on NOMMU" bug

We set ptrace options when we see post-attach SIGSTOP.
This is wrong: it's better to set them right away on the very first
stop (whichever it will be). It also will make adding SEIZE support easier,
since SEIZE has no post-attach SIGSTOP.

We do it by adding a new bit, TCB_IGNORE_ONE_SIGSTOP, and treating
TCB_STARTUP and TCB_IGNORE_ONE_SIGSTOP as two slightly different things.

* defs.h: Add a new flag bit, TCB_IGNORE_ONE_SIGSTOP.
* process.c (internal_fork): Set TCB_IGNORE_ONE_SIGSTOP on a newly added child.
* strace.c (startup_attach): Set TCB_IGNORE_ONE_SIGSTOP after attach.
Fix a case when "strace -p PID" found PID dead but sone other of its threads
still alive.
(startup_child): Set TCB_IGNORE_ONE_SIGSTOP after attach, _if needed_.
This fixes a bogus case where we can ignore a _real_ SIGSTOP on NOMMU.
(detach): Perform anti-SIGSTOP dance only if TCB_IGNORE_ONE_SIGSTOP is set,
not if TCB_STARTUP is set.
(trace): Set TCB_IGNORE_ONE_SIGSTOP after attach.
Clear TCB_STARTUP and initialize tracee on the very first tracee stop.
Clear TCB_IGNORE_ONE_SIGSTOP when SIGSTOP is seen.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoGet rid of TCB_ATTACH_DONE
Denys Vlasenko [Mon, 5 Sep 2011 12:01:33 +0000 (14:01 +0200)]
Get rid of TCB_ATTACH_DONE

* defs.h: Remove TCB_ATTACH_DONE constant.
* strace.c (startup_attach): Use TCB_STARTUP instead of TCB_ATTACH_DONE
to distinquish attached from not-yet-attached threads.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoSet TCB_STARTUP only _after_ we attached.
Denys Vlasenko [Mon, 5 Sep 2011 11:59:39 +0000 (13:59 +0200)]
Set TCB_STARTUP only _after_ we attached.

This fixes logic in detach() which thinks that TCB_STARTUP
means that we are already attached, but did not see SIGSTOP yet.
This also allows to get rid of TCB_ATTACH_DONE flag.

* process.c (internal_fork): Set TCB_STARTUP after attach.
* strace.c (startup_attach): Likewise.
(startup_child): Likewise.
(alloc_tcb): Do not set TCB_STARTUP on tcb allocation - we are
not attached yet.
(trace): Set TCB_STARTUP when we detech an auto-attached child.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoSimple optimizations in trace()
Denys Vlasenko [Fri, 2 Sep 2011 14:23:53 +0000 (16:23 +0200)]
Simple optimizations in trace()

* strace.c (trace): Calculate WSTOPSIG(status) once,
unify code paths to ptrace(PTRACE_SYSCALL).

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoTrivial fixes on error paths
Denys Vlasenko [Fri, 2 Sep 2011 14:19:30 +0000 (16:19 +0200)]
Trivial fixes on error paths

* strace.c (startup_attach): Emit message on fork() failure.
(startup_child): Remove non-informative comment.
* util.c (ptrace_restart): use perror_msg() on error instead of fprintf().

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoFix compile failure introduced by last commit
Denys Vlasenko [Thu, 1 Sep 2011 16:18:04 +0000 (18:18 +0200)]
Fix compile failure introduced by last commit

* desc.c (decode_select): Fix double definition of nfds.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoRoll back "die on malloc failure" behaviour a bit
Denys Vlasenko [Thu, 1 Sep 2011 14:35:44 +0000 (16:35 +0200)]
Roll back "die on malloc failure" behaviour a bit

After recent change, select(2^31-1, NULL, NULL, NULL)
would make strace exit. This change caps fdsize so that
it is always in [0, 1025*1024], IOW: we will try to allocate at most
1 megabyte, which in practice will almost always work,
unlike malloc(2Gig).

* desc.c (decode_select): Cap fdsize to 1024*1024.
* pathtrace.c (pathtrace_match): Cap fdsize to 1024*1024.
* file.c (sys_getdents): Cap len to 1024*1024.
(sys_getdents64): Cap len to 1024*1024.
* util.c (dumpiov): Refuse to process iov with more than 1024*1024
elements. Don't die on malloc failure.
(dumpstr): Don't die on malloc failure.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoAdd stpcpy to autoconf machinery
Denys Vlasenko [Thu, 1 Sep 2011 14:31:48 +0000 (16:31 +0200)]
Add stpcpy to autoconf machinery

* configure.ac: Add stpcpy to AC_CHECK_FUNCS.
* defs.h: Frame stpcpy with "if !defined HAVE_STPCPY".
* util.c: Likewise.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoSimplify sprinttv()
Denys Vlasenko [Thu, 1 Sep 2011 09:40:40 +0000 (11:40 +0200)]
Simplify sprinttv()

* time.c (sprinttv): Trivial simplifications.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years ago* desc.c (decode_select): Set tcp->auxstr as late as possible.
Denys Vlasenko [Thu, 1 Sep 2011 09:27:37 +0000 (11:27 +0200)]
* desc.c (decode_select): Set tcp->auxstr as late as possible.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoReformat setuid-ing code in startup_child()
Denys Vlasenko [Thu, 1 Sep 2011 08:27:42 +0000 (10:27 +0200)]
Reformat setuid-ing code in startup_child()

New code does the same as old one, but is more readable (I hope).

* strace.c (startup_child): Reformat setuid-ing code.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoMinor tweaks in startup_child(). Logic isn't changed (but code is)
Denys Vlasenko [Thu, 1 Sep 2011 08:23:09 +0000 (10:23 +0200)]
Minor tweaks in startup_child(). Logic isn't changed (but code is)

* strace.c (startup_attach): Tweak comment.
(startup_child): Move common code out of ifdef.
Indent nested ifdefs. Tweak comments. Remove two
unnecessary calls to getpid().

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoUse tprints with literal strings, it may be faster than tprintf
Denys Vlasenko [Thu, 1 Sep 2011 08:00:28 +0000 (10:00 +0200)]
Use tprints with literal strings, it may be faster than tprintf

* bjm.c: Replace tprintf("str") with tprints("str").
* block.c: Likewise.
* desc.c: Likewise.
* file.c: Likewise.
* io.c: Likewise.
* ipc.c: Likewise.
* mem.c: Likewise.
* net.c: Likewise.
* proc.c: Likewise.
* process.c: Likewise.
* quota.c: Likewise.
* resource.c: Likewise.
* scsi.c: Likewise.
* signal.c: Likewise.
* sock.c: Likewise.
* strace.c: Likewise.
* stream.c: Likewise.
* syscall.c: Likewise.
* system.c: Likewise.
* term.c: Likewise.
* time.c: Likewise.
* util.c: Likewise.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoFix "format not a string literal" warning caused by tprintf(str)
Denys Vlasenko [Thu, 1 Sep 2011 07:55:05 +0000 (09:55 +0200)]
Fix "format not a string literal" warning caused by tprintf(str)

* defs.h: Declare tprints().
* strace.c: Define tprints().
(tabto): Use tprints(str), since tprintf(str) was throwing a warning.
* desc.c: Use tprints(str) instead of tprintf("%s", str).
* file.c: Likewise.
* io.c: Likewise.
* net.c: Likewise.
* process.c: Likewise.
* signal.c: Likewise.
* syscall.c: Likewise.
* util.c: Likewise.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoAdd README-linux-ptrace file
Denys Vlasenko [Wed, 31 Aug 2011 13:58:06 +0000 (15:58 +0200)]
Add README-linux-ptrace file

I tried to push this doc to Michael Kerrisk <mtk.manpages@gmail.com>,
but got no reply. To avoid losing the document, let it live
in strace tree for now.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoMake out-of-memory handling more uniform
Denys Vlasenko [Wed, 31 Aug 2011 12:00:02 +0000 (14:00 +0200)]
Make out-of-memory handling more uniform

This fixes one real bug in dumpstr().

* defs.h: Declare die_out_of_memory().
* strace.c (die_out_of_memory): New function.
(strace_popen): If allocation fails, call die_out_of_memory().
(main): Likewise.
(expand_tcbtab): Likewise.
(rebuild_pollv): Likewise.
* count.c (count_syscall): Likewise.
(call_summary_pers): Likewise.
* desc.c (decode_select): Likewise.
* file.c (sys_getdents): Likewise.
(sys_getdents64): Likewise.
(sys_getdirentries): Likewise.
* pathtrace.c (pathtrace_match): Likewise.
* syscall.c (qualify): Likewise.
* util.c (printstr): Likewise.
(dumpiov): Likewise.
(dumpstr): Likewise.
(fixvfork): Likewise.
* mem.c (sys_mincore): Don't check free() parameter for NULL.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoOptimization: eliminate all remaining usages of strcat()
Denys Vlasenko [Wed, 31 Aug 2011 10:26:03 +0000 (12:26 +0200)]
Optimization: eliminate all remaining usages of strcat()

After this change, we don't use strcat() anywhere.

* defs.h: Change sprinttv() return type to char *.
* time.c (sprinttv): Return pointer past last stored char.
* desc.c (decode_select): Change printing logic in order to eliminate
usage of strcat() - use stpcpy(), *outptr++ = ch, sprintf() instead.
Also reduce usage of strlen().
* stream.c (decode_poll): Likewise.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoOptimize string_quote() for speed
Denys Vlasenko [Wed, 31 Aug 2011 10:22:56 +0000 (12:22 +0200)]
Optimize string_quote() for speed

* util.c (string_quote): Speed up check for terminating NUL.
Replace strintf() with open-coded binary to hex/oct conversions -
we potentially do them for every single byte, need to be fast.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoOptimization: eliminate some usages of strcat()
Denys Vlasenko [Wed, 31 Aug 2011 10:07:38 +0000 (12:07 +0200)]
Optimization: eliminate some usages of strcat()

* defs.h: Declare stpcpy().
* util.c: Define stpcpy().
* file.c: Remove static str_append().
(sprint_open_modes): Use stpcpy() instead of str_append().
(sprintflags): Use stpcpy() instead of strcat().
(printpathn): Eliminate usage of strcat().
(printstr): Eliminate usage of strcat().

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoSmall optimization on AVR32
Denys Vlasenko [Tue, 30 Aug 2011 17:04:54 +0000 (19:04 +0200)]
Small optimization on AVR32

* syscall.c (syscall_enter): Optimize tcp->u_arg[i] setting
from regs.FOO for AVR32.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoOn X86_64 and I386, use PTRACE_GETREGS to fetch all registers
Denys Vlasenko [Tue, 30 Aug 2011 16:53:49 +0000 (18:53 +0200)]
On X86_64 and I386, use PTRACE_GETREGS to fetch all registers

Before this change, registers were read with PTRACE_PEEKUSER
ptrace operation, one per register. This is slower than
fetching them all in one ptrace operation.

* defs.h: include asm/ptrace.h on X86_64 and I386.
* syscall.c: New static variables i386_regs and x86_64_regs.
Remove static eax/rax variables.
(get_scno): Fetch all registers with single PTRACE_GETREGS operation.
(get_syscall_result): Likewise.
(syscall_fixup_on_sysenter): Use PTRACE_GETREGS results in i386/x86_64_regs.
(syscall_enter): Set tcp->u_arg[i] from PTRACE_GETREGS results.
(get_error): Set tcp->u_rval, tcp->u_error from PTRACE_GETREGS results.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoDo not include <limits.h>
Dmitry V. Levin [Tue, 30 Aug 2011 16:07:01 +0000 (16:07 +0000)]
Do not include <limits.h>

* strace.c: Do not include <limits.h> explicitly, it is already included
implicitly by <sys/param.h>.

12 years agoInclude <sys/param.h> to get PATH_MAX definition
Dmitry V. Levin [Tue, 30 Aug 2011 16:05:26 +0000 (16:05 +0000)]
Include <sys/param.h> to get PATH_MAX definition

* pathtrace.c: Include <sys/param.h> instead of <limits.h> to get
PATH_MAX definition.

Reported-by: Steve Bennett <steveb@workware.net.au>
12 years agoIndent a large set of nested ifdefs/endifs. No code changes
Denys Vlasenko [Fri, 26 Aug 2011 17:25:09 +0000 (19:25 +0200)]
Indent a large set of nested ifdefs/endifs. No code changes

* defs.h: Indent a large set of nested ifdefs/endifs

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoRename syscall_fixup to syscall_fixup_on_sysenter
Denys Vlasenko [Thu, 25 Aug 2011 08:40:14 +0000 (10:40 +0200)]
Rename syscall_fixup to syscall_fixup_on_sysenter

* defs.h: Tweak comment.
* syscall.c: Rename syscall_fixup to syscall_fixup_on_sysenter.
(trace_syscall_entering): Use new finction name.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoMake syscall result reading more consistent among different arches
Denys Vlasenko [Thu, 25 Aug 2011 08:31:24 +0000 (10:31 +0200)]
Make syscall result reading more consistent among different arches

* syscall.c: Eliminate static flags variable for POWERPC.
(syscall_fixup): Don't fetch syscall results. Affected arches:
POWERPC, BFIN, HPPA.
(syscall_fixup_on_sysexit): Move syscall results fetching code
for this function to get_syscall_result. Affected arches:
S390X, POWERPC, BFIN, M68K, HPPA, CRIS, MICROBLAZE.
(get_syscall_result): Add syscall results fetching.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoSimplify syscall_fixup[_on_sysexit]
Denys Vlasenko [Thu, 25 Aug 2011 08:25:35 +0000 (10:25 +0200)]
Simplify syscall_fixup[_on_sysexit]

* syscall.c (syscall_fixup): Remove checks for entering(tcp).
Remove code which executes if exiting(tcp).
(syscall_fixup_on_sysexit): Remove code which executes
if entering(tcp). Remove checks for exiting(tcp).

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoSplit syscall_fixup into enter/exit pair of functions
Denys Vlasenko [Thu, 25 Aug 2011 08:23:00 +0000 (10:23 +0200)]
Split syscall_fixup into enter/exit pair of functions

* syscall.c: Create syscall_fixup_on_sysexit() which is a copy of
syscall_fixup().
(trace_syscall_exiting): Call syscall_fixup_on_sysexit() instead of
syscall_fixup().

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoRemove stray commas in struct initializers. No code changes
Denys Vlasenko [Thu, 25 Aug 2011 08:21:13 +0000 (10:21 +0200)]
Remove stray commas in struct initializers. No code changes

* process.c: Remove stray commas in struct initializers.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoOptimize tabto()
Denys Vlasenko [Wed, 24 Aug 2011 23:27:59 +0000 (01:27 +0200)]
Optimize tabto()

tabto is used in many lines of strace output.
On glibc, tprintf("%*s", col - curcol, "") is noticeably slow
compared to tprintf("                 "). Use the latter.
Observed ~15% reduction of time spent in userspace.

* defs.h: Drop extern declaration of acolumn. Make tabto()
take no parameters.
* process.c (sys_exit): Call tabto() with no parameters.
* syscall.c (trace_syscall_exiting): Call tabto() with no parameters.
* strace.c: Make acolumn static, add static char *acolumn_spaces.
(main): Allocate acolumn_spaces as a string of spaces.
(printleader): Call tabto() with no parameters.
(tabto): Use simpler method to print lots of spaces.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years ago* syscall.c (sys_indir): Use %ld for printing long, not %u.
Denys Vlasenko [Wed, 24 Aug 2011 23:23:10 +0000 (01:23 +0200)]
* syscall.c (sys_indir): Use %ld for printing long, not %u.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoOpotimize "scno >= 0 && scno < nsyscalls" check
Denys Vlasenko [Wed, 24 Aug 2011 23:13:43 +0000 (01:13 +0200)]
Opotimize "scno >= 0 && scno < nsyscalls" check

gcc can't figure out on its own that this check can be done with
single compare, and does two compares. We can help it by casting
scno to unsigned long: ((unsigned long)(scno) < nsyscalls)

* defs.h: New macro SCNO_IN_RANGE(long_var).
* count.c (count_syscall): Use SCNO_IN_RANGE() instead of open-coded check.
* syscall.c (getrval2): Use SCNO_IN_RANGE() instead of open-coded check.
This fixes a bug: missing check for scno < 0 and scno > nsyscalls
instead of scno >= nsyscalls.
(get_scno): Use SCNO_IN_RANGE() instead of open-coded check.
This fixes a bug: scno > nsyscalls instead of scno >= nsyscalls.
(known_scno): Use SCNO_IN_RANGE() instead of open-coded check.
(internal_syscall): Likewise.
(syscall_enter): Likewise.
(trace_syscall_entering): Likewise.
(get_error): Likewise.
(trace_syscall_exiting): Likewise.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoRemove scno_good logic in syscall exit
Denys Vlasenko [Wed, 24 Aug 2011 22:29:56 +0000 (00:29 +0200)]
Remove scno_good logic in syscall exit

* syscall.c (trace_syscall_exiting): Remove scno_good logic,
it can't trigger in syscall exit.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoRemove redundant assignments
Denys Vlasenko [Wed, 24 Aug 2011 22:26:38 +0000 (00:26 +0200)]
Remove redundant assignments

* syscall.c (get_error): Remove redundant "u_error = 0" and redundant
and unclear comments.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoGroup int-sized fields together in struct tcb
Denys Vlasenko [Wed, 24 Aug 2011 22:25:08 +0000 (00:25 +0200)]
Group int-sized fields together in struct tcb

* defs.h: Group int-sized fields together in struct tcb.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoReorder functions in syscall.c. No code changes.
Denys Vlasenko [Wed, 24 Aug 2011 16:07:22 +0000 (18:07 +0200)]
Reorder functions in syscall.c. No code changes.

Old order (basically "in no particular order"):
    dumpio
    decode_subcall
    internal_syscall
    get_scno
    get_syscall_result
    known_scno
    syscall_fixup
    is_negated_errno
    get_error
    syscall_enter
    trace_syscall_entering
    trace_syscall_exiting
    trace_syscall
    printargs
    getrval2
    sys_indir
    is_restart_error

New order:
various utility functions:
    decode_subcall
    printargs
    getrval2
    sys_indir
    is_restart_error
syscall enter handling functions:
    get_scno
    known_scno
    syscall_fixup (also used in syscall exit code)
    internal_syscall (also used in syscall exit code)
    syscall_enter
    trace_syscall_entering
syscall exit handling functions:
    get_syscall_result
    is_negated_errno
    get_error
    dumpio
    trace_syscall_exiting
main syscall enter/exit function:
    trace_syscall

* syscall.c: Reorder functions so that related ones are closer
in the source.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoRename some functions, delete unused one. No code changes
Denys Vlasenko [Wed, 24 Aug 2011 15:53:52 +0000 (17:53 +0200)]
Rename some functions, delete unused one. No code changes

* defs.h: Rename get_scno_on_sysenter() to get_scno();
delete force_result() declaration.
* strace.c (proc_open): Rename get_scno_on_sysenter() to get_scno().
* syscall.c: Rename get_scno_on_sysenter() to get_scno().
Rename get_scno_on_sysexit() to get_syscall_result().
Delete unused force_result().

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoUnify per-architecture post-execve SIGTRAP check.
Denys Vlasenko [Wed, 24 Aug 2011 15:25:32 +0000 (17:25 +0200)]
Unify per-architecture post-execve SIGTRAP check.

Move post-execve SIGTRAP check from get_scno_on_sysenter
(multitude of places on many architectures) to a single location
in trace_syscall_entering. This loosens the logic for some arches,
since many of them had additional checks such as scno == 0.
However, on non-ancient Linux kernels we should never have post-execve
SIGTRAP in the first place, by virtue of using PTRACE_O_TRACEEXEC.

* syscall.c (get_scno_on_sysenter): Remove tcp->flags & TCB_WAITEXECVE checks.
(trace_syscall_entering): Do tcp->flags & TCB_WAITEXECVE check here.
(get_scno_on_sysexit): Tweak comment.
(syscall_fixup): Likewise.
(trace_syscall_exiting): Likewise.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoSpeed up x86 by avoiding EAX read on syscall entry
Denys Vlasenko [Wed, 24 Aug 2011 14:59:23 +0000 (16:59 +0200)]
Speed up x86 by avoiding EAX read on syscall entry

on x86, EAX read on syscall entry is not necessary if we know
that post-execve SIGTRAP is disabled by PTRACE_O_TRACEEXEC ptrace option.
This patch (a) moves EAX retrieval from syscall_fixup
to get_scno_on_sysexit, and (b) perform EAX retrieval in syscall_fixup
only if we are in syscall entry and PTRACE_O_TRACEEXEC option is not on.

* syscall.c (get_scno_on_sysexit): On I386 and X86_64, read eax/rax
which contain syscall return value.
(syscall_fixup): On I386 and X86_64, read eax/rax only on syscall enter
and only if PTRACE_O_TRACEEXEC is not in effect.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoDo not read syscall no in get_scno_on_sysexit
Denys Vlasenko [Wed, 24 Aug 2011 14:56:03 +0000 (16:56 +0200)]
Do not read syscall no in get_scno_on_sysexit

* syscall.c (get_scno_on_sysexit): Remove scno retrieval code, since
we don't save it anyway. This is the first real logic change
which should make strace faster: for example, on x64 ORIG_EAX
is no longer read in each syscall exit.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoSimplify get_scno_on_sysenter/sysexit
Denys Vlasenko [Wed, 24 Aug 2011 14:52:57 +0000 (16:52 +0200)]
Simplify get_scno_on_sysenter/sysexit

* syscall.c (get_scno_on_sysenter): Remove "if (exiting(tcp))" code,
make "if (entering(tcp))" code unconditional.
(get_scno_on_sysexit): Remove "if (entering(tcp))" code,
make "if (exiting(tcp))" code unconditional.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoget_scno is an unholy mess, make it less horrible
Denys Vlasenko [Wed, 24 Aug 2011 14:47:32 +0000 (16:47 +0200)]
get_scno is an unholy mess, make it less horrible

Currently, get_scno does *much* more than "get syscall no".
It checks for post-execve SIGTRAP. It checks for changes
in personality. It retrieves params on entry and registers on exit.
Worse still, it is different in different architectures: for example,
for AVR32 regs are fetched in get_scno(), while for e.g. I386
it is done in syscall_enter().

Another problem is that get_scno() is called on both syscall entry and
syscall exit, which is stupid: we don't need to know scno on syscall
exit, it is already known from last syscall entry and stored in
tcp->scno! In essence, get_scno() does two completely different things
on syscall entry and on exit, they are just mixed into one bottle, like
shampoo and conditioner.

The following patches will try to improve this situation.

This change duplicates get_scno into identical get_scno_on_sysenter,
get_scno_on_sysexit functions. Call them in syscall enter and syscall
exit, correspondingly.

* defs.h: Rename get_scno to get_scno_on_sysenter; declare it only
if USE_PROCFS.
* strace.c (proc_open): Call get_scno_on_sysenter instead of get_scno.
* syscall.c (get_scno): Split into two (so far identical) functions
get_scno_on_sysenter and get_scno_on_sysexit.
(trace_syscall_entering): Call get_scno_on_sysenter instead of get_scno.
(trace_syscall_exiting): Call get_scno_on_sysexit instead of get_scno.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoReduce code redundancy in syscall_enter()
Dmitry V. Levin [Tue, 23 Aug 2011 16:24:20 +0000 (16:24 +0000)]
Reduce code redundancy in syscall_enter()

* syscall.c [LINUX] (syscall_enter): Move tcp->u_nargs initialization
from arch-specific ifdefs to common code.  Always cache tcp->u_nargs in
a local variable and use it in for() loops.
[IA64, AVR32] Rewrite tcp->u_arg[] initialization using a loop.

12 years agoDefine MAX_ARGS to 6 for all Linux arches
Denys Vlasenko [Tue, 23 Aug 2011 16:04:25 +0000 (18:04 +0200)]
Define MAX_ARGS to 6 for all Linux arches

* defs.h: Define MAX_ARGS to 6 for all Linux arches.
* linux/ia64/syscallent.h: Change all 8-argument printargs
to MA (MAX_ARGS).
linux/mips/syscallent.h: Change all two 7-argument printargs
to MA (MAX_ARGS).

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoFix argument printing in sys_mmap64
Denys Vlasenko [Tue, 23 Aug 2011 15:51:58 +0000 (17:51 +0200)]
Fix argument printing in sys_mmap64

* mem.c (sys_mmap64): Fix a bug where we used tcp->u_args[i]
instead of argument values copied from memory.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoCache tcp->u_nargs in a local variable for for() loops
Denys Vlasenko [Tue, 23 Aug 2011 11:32:38 +0000 (13:32 +0200)]
Cache tcp->u_nargs in a local variable for for() loops

Loops of the form "for (i = 0; i < tcp->u_nargs; i++) ..."
need to fetch tcp->u_nargs from memory on every iteration
if "..." part has a function call (gcc doesn't know that
tcp->u_nargs won't change). This can be sped up
by putting tcp->u_nargs in a local variable, which might
go into a CPU register.

* syscall.c (decode_subcall): Cache tcp->u_nargs in a local variable
as for() loop limit value.
(syscall_enter): Likewise.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoDrop checks for sysent[i].nargs == -1
Denys Vlasenko [Tue, 23 Aug 2011 11:29:01 +0000 (13:29 +0200)]
Drop checks for sysent[i].nargs == -1

* defs.h: Declare nsyscalls, nerrnos, nioctlents, nsignals as unsigned.
* syscall.c: Define nsyscalls, nerrnos, nioctlents, nsignals as unsigned.
(decode_subcall): Drop checks for sysent[i].nargs == -1.
(syscall_enter): Likewise.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoStop using nargs == -1 in syscallent tables
Denys Vlasenko [Tue, 23 Aug 2011 11:24:17 +0000 (13:24 +0200)]
Stop using nargs == -1 in syscallent tables

Usage -1 as argument count in syscallent tables
necessitates the check for it, a-la:
if (sysent[tcp->scno].nargs != -1)
    tcp->u_nargs = sysent[tcp->scno].nargs;
else
    tcp->u_nargs = MAX_ARGS;
which is stupid: we waste cycles checking something which
is constant and known at compile time.

* defs.h: Make struct sysent::nargs unsigned.
* freebsd/i386/syscallent.h: Replace nargs of -1 with MA.
* linux/s390/syscallent.h: Likewise.
* linux/s390x/syscallent.h: Likewise.
* svr4/syscallent.h: Likewise.
* freebsd/syscalls.pl: Likewise in generator script.
* syscallent.sh: Likewise in generator script.
* syscall.c: Add define MA MAX_ARGS / undef MA around includes
of syscallent[N].h.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoMove trace_syscall_exiting below trace_syscall_entering. No code changes.
Denys Vlasenko [Mon, 22 Aug 2011 09:54:06 +0000 (11:54 +0200)]
Move trace_syscall_exiting below trace_syscall_entering. No code changes.

Syscall enter happens before syscall exit. Having functions
in opposite order in the source is confusing.

* syscall.c: Move trace_syscall_exiting below trace_syscall_entering.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoFix -z display.
Denys Vlasenko [Mon, 22 Aug 2011 00:06:35 +0000 (02:06 +0200)]
Fix -z display.

Before this patch, the following:
    open("qwerty", O_RDONLY)    = -1 ENOENT
    write(2, "wc: qwerty: No such file or dire"..., 38) = 38
was shown totally wrongly with -z:
    open("qwerty", O_RDONLY)    = 38
(yes, that's right, write syscall is lost!)
Now it is shown "less wrongly" as:
    open("qwerty", O_RDONLY <unfinished ...>
    write(2, "wc: qwerty: No such file or dire"..., 38) = 38

* syscall.c (trace_syscall_exiting): Use common TCB_INSYSCALL clearing
via "goto ret". This fixes totally broken display of -z, but even now
it is not working as intended. Add a comment about that.
(trace_syscall_entering): Use common TCB_INSYSCALL setting
via "goto ret".

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoStraighten up confused comments/messages about post-execve SIGTRAP handling
Denys Vlasenko [Sun, 21 Aug 2011 16:03:23 +0000 (18:03 +0200)]
Straighten up confused comments/messages about post-execve SIGTRAP handling

* defs.h: Explain TCB_INSYSCALL and TCB_WAITEXECVE bits in detail.
* strace.c (choose_pfd): Use entering/exiting macros instead of direct check
for TCB_INSYSCALL.
* syscall.c (get_scno): Use entering/exiting macros instead of direct check
for TCB_INSYSCALL. Fix comments about post-execve SIGTRAP.
(syscall_fixup): Use entering/exiting instead of direct check
for TCB_INSYSCALL. Add a comment what "not a syscall entry" message
usually means. Change wrong "stray syscall exit" messages into
"not a syscall entry" ones.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agocount_syscall() always returns 0, optimize it
Denys Vlasenko [Sun, 21 Aug 2011 15:47:40 +0000 (17:47 +0200)]
count_syscall() always returns 0, optimize it

* defs.h (count_syscall): Change return type from int to void.
* count.c (count_syscall): Change return type from int to void.
* syscall.c (trace_syscall_exiting): Change code around call
to count_syscall accordingly.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoOptimize out dummy PC printing on signal delivery
Denys Vlasenko [Sun, 21 Aug 2011 15:35:39 +0000 (17:35 +0200)]
Optimize out dummy PC printing on signal delivery

* strace.c (trace): Optimize out dummy PC printing on signal delivery.
While at it, tweak comments.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoConditionally optimize out unused code
Denys Vlasenko [Sun, 21 Aug 2011 15:26:55 +0000 (17:26 +0200)]
Conditionally optimize out unused code

* syscall.c (internal_syscall): Call internal_exec only if
SUNOS4 || (LINUX && TCB_WAITEXECVE).
* process.c (internal_exec): Define this function only if
SUNOS4 || (LINUX && TCB_WAITEXECVE).
(printwaitn): Don't check wordsize if SUPPORTED_PERSONALITIES == 1.
* signal.c (sys_kill): Likewise.
* syscall.c (is_negated_errno): Likewise.
(trace_syscall_exiting): Fold a tprintf into tprintfs which follow it.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoCosmetic improvement in ifdefs. No code changes
Denys Vlasenko [Sat, 20 Aug 2011 22:10:45 +0000 (00:10 +0200)]
Cosmetic improvement in ifdefs. No code changes

* strace.c (proc_open): Change ifdefs so that braces are properly paired.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoExclude tcp->pfd from non-procfs systems
Denys Vlasenko [Sat, 20 Aug 2011 11:44:56 +0000 (13:44 +0200)]
Exclude tcp->pfd from non-procfs systems

* defs.h: Make struct tcb::pfd fields conditional on USE_PROCFS.
* strace.c (alloc_tcb): Use tcp->pfd only if USE_PROCFS.
(droptcb): Likewise.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoSmall optimizations related to memory allocation
Denys Vlasenko [Sat, 20 Aug 2011 11:41:13 +0000 (13:41 +0200)]
Small optimizations related to memory allocation

* strace (expand_tcbtab): Shorten "out of memory" message.
(rebuild_pollv): Remove unnecessary NULL check before free().
* util.c (dumpstr): Add a comment about likely bug.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoImprove code readability by avoiding assignments inside if()
Denys Vlasenko [Sat, 20 Aug 2011 10:48:18 +0000 (12:48 +0200)]
Improve code readability by avoiding assignments inside if()

* desc.c (decode_select): Move assignment out of if() condition.
* file.c (sprinttime): Likewise.
(sys_getdirentries): Likewise.
* io.c (sys_ioctl): Likewise.
* strace.c (test_ptrace_setoptions_followfork): Likewise.
(main): Likewise.
(proc_open): Likewise.
(detach): Likewise.
(proc_poll): Likewise.
(trace): Likewise.
* syscall.c (qualify): Likewise.
(sys_indir): Likewise.
* test/procpollable.c (main): Likewise.
* test/sfd.c (main): Likewise.
* time.c (printtv_bitness): Likewise.
(sprinttv): Likewise.
(print_timespec): Likewise.
(void sprint_timespec): Likewise.
(printitv_bitness): Likewise.
* util.c (dumpstr): Likewise.
(umovestr): Likewise.
(fixvfork): Likewise.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoConvert ioctl_next_match() to new-style C function definition
Denys Vlasenko [Sat, 20 Aug 2011 00:27:18 +0000 (02:27 +0200)]
Convert ioctl_next_match() to new-style C function definition

* ioctl.c (ioctl_next_match): Convert to new-style C function definition.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoSmall optimization in signal and ioctl tables
Denys Vlasenko [Sat, 20 Aug 2011 00:12:33 +0000 (02:12 +0200)]
Small optimization in signal and ioctl tables

Trivial shuffling of data tables puts them all in one file,
allowing gcc to see their sizes and eliminate variables
which store these sizes.

Surprisingly, in C mode gcc does not optimize out static const int
variables. Help it by using enums instead.

* defs.h: Stop exporting ioctlent{0,1,2}, nioctlents{0,1,2},
signalent{0,1,2}, nsignals{0,1,2}.
* ioctl.c: Remove definitions of ioctlent{,0,1,2} and nioctlents{,0,1,2}.
* signal.c: Remove definitions of signalent{,0,1,2} and nsignals{,0,1,2}.
* syscall.c: Move above definitions to this file. Make them static const
or enums if suitable.

12 years agoDon't return int from set_personality(), no one checks it.
Denys Vlasenko [Fri, 19 Aug 2011 23:50:09 +0000 (01:50 +0200)]
Don't return int from set_personality(), no one checks it.

* defs.h (set_personality): Change return type to void.
* syscall.c (set_personality): Change return type to void.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoRemove unused declaration
Denys Vlasenko [Fri, 19 Aug 2011 23:43:32 +0000 (01:43 +0200)]
Remove unused declaration

* defs.h: Remove unused declaration of handle_new_child().

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoUse natural-sized integer field for tcb::flags
Denys Vlasenko [Fri, 19 Aug 2011 23:39:05 +0000 (01:39 +0200)]
Use natural-sized integer field for tcb::flags

* defs: Change struct tcb::flags type from short to int.
This results in smaller code at least on x86.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoMake needlessly static data local
Denys Vlasenko [Fri, 19 Aug 2011 22:03:10 +0000 (00:03 +0200)]
Make needlessly static data local

* syscall.c (get_scno): For POWERPC64 and X86-64, variable currpers
is declared static. But its old data is never used. Convert it
to ordinary local variable.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoOptimize get_scno function
Denys Vlasenko [Fri, 19 Aug 2011 17:46:32 +0000 (19:46 +0200)]
Optimize get_scno function

* syscall.c (get_scno): Make gpr_offset[] array static const.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoOptimize iocb_cmd_lookup
Denys Vlasenko [Fri, 19 Aug 2011 17:44:17 +0000 (19:44 +0200)]
Optimize iocb_cmd_lookup

* desc.c (iocb_cmd_lookup): Make command table constant.
Reduce size of static char buffer.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoCorrect sys_sendfile[64] type and nargs
Denys Vlasenko [Fri, 19 Aug 2011 17:01:26 +0000 (19:01 +0200)]
Correct sys_sendfile[64] type and nargs

* freebsd/i386/syscallent.h: Correct sys_sendfile nargs 7->8
* linux/mips/syscallent.h: Correct sys_sendfile64 nargs 5->4
* linux/sh/syscallent.h: Correct sys_sendfile64 nargs 5->4
* linux/sh64/syscallent.h: Correct sys_sendfile64 nargs 5->4
* linux/m68k/syscallent.h: Correct sys_sendfile64 type TF->TD|TN
* linux/microblaze/syscallent.h: Correct sys_sendfile64 type TF->TD|TN
* linux/tile/syscallent.h: Correct sys_sendfile and sys_sendfile64 type TD->TD|TN

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoMake addflags return void
Denys Vlasenko [Fri, 19 Aug 2011 16:06:46 +0000 (18:06 +0200)]
Make addflags return void

* defs.h (addflags): Change return type from int to void.
* util.c (addflags): Change return type from int to void.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoSet saner MAX_ARGS (6 or 8) for X86_64 and I386
Denys Vlasenko [Fri, 19 Aug 2011 15:41:28 +0000 (17:41 +0200)]
Set saner MAX_ARGS (6 or 8) for X86_64 and I386

I noticed that tcp->u_args[MAX_ARGS] array is way larger than
I'd expect: for all arches except HPPA it has 32 (!) elements.

I looked at the code and so far I spotted only one abuser of
this fact: sys_sigreturn. On several arches, it saves sigset_t
into tcp->u_args[1...N] on entry and prints it on exit, a-la

memcpy(&tcp->u_arg[1], &sc.oldmask[0], sizeof(sigset_t))

The problem here is that in glibc sigset_t is insanely large:
128 bytes, and using sizeof(sigset_t) in memcpy will overrun
&tcp->u_args[1] even with MAX_ARGS == 32:
On 32 bits, sizeof(tcp->u_args) == 32*4 == 128 bytes!
We may already have a bug there!

This commit changes the code to save NSIG / 8 bytes only.
NSIG can't ever be > 256, and in practice is <= 129,
thus NSIG / 8 is <= 16 bytes == 4 32-bit words,
and even MAX_ARGS == 5 should be enough for saving signal masks.

* defs.h: Reduce MAX_ARGS for X86_64 and I386 from 32 to 8
for FreeBSD and to 6 for everyone else. Add comment about current
state of needed MAX_ARGS.
* signal.c: Add comment about size of sigset_t.
(sprintsigmask): Reduce static string buffer from 8k to 2k.
(sys_sigreturn): Fix sigset saving to save only NSIG / 8 bytes,
not sizeof(sigset_t) bytes.
* linux/mips/syscallent.h: Reduce nargs of printargs-type syscall to 7.
* linux/arm/syscallent.h: Reduce nargs of printargs-type syscall to 6.
* linux/i386/syscallent.h: Likewise.
* linux/m68k/syscallent.h: Likewise.
* linux/powerpc/syscallent.h: Likewise.
* linux/s390/syscallent.h: Likewise.
* linux/s390x/syscallent.h: Likewise.
* linux/sh/syscallent.h: Likewise.
* linux/sh64/syscallent.h: Likewise.
* linux/sparc/syscallent.h: Likewise.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoOptimize sys_old_mmap
Denys Vlasenko [Fri, 19 Aug 2011 15:07:38 +0000 (17:07 +0200)]
Optimize sys_old_mmap

* mem.c (sys_old_mmap): For Ia64 and 32-bit personality of x86-64,
copy narrow parameters from userspace by single umove, not by six
separate ones; then assign them to long u_arg[i]. For SH[64],
avoid copying of tcp->u_arg.
(sys_mmap): Add FIXME comment - SH64 and i386 seem to be handled
differently for no apparent reason.
* test/mmap_offset_decode.c: New test program, illustrates FIXME.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoUntangle ifdef forest in sys_mmap64. No code changes
Denys Vlasenko [Fri, 19 Aug 2011 14:11:07 +0000 (16:11 +0200)]
Untangle ifdef forest in sys_mmap64. No code changes

After careful analysis, it looks like !LINUX and ALPHA
pass all seven parameters in registers; and in all other cases
parameters are on stack (pointed to by tcp->u_arg[0]).
In light of this, reorganize ifdefs, making them simpler,
without changing any logic.
After this, it's apparent we use tcp->u_arg[4,5,6] and possibly
[7] without checking that it's valid to do so.
So far, just add a comment about this.

* mem.c (sys_mmap64): Rewrite ifdefs in a much simpler way.
Add comments about apparent bugs.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoStyle and comment fixes, no code changes
Denys Vlasenko [Fri, 19 Aug 2011 14:01:51 +0000 (16:01 +0200)]
Style and comment fixes, no code changes

* mem.c: Indent includes to show nesting better.
  (addtileflags): Fix style of this function definition;
  correct wrong endif comment, add another endif comment.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoUse simpler rounding up to next multiple of 2.
Denys Vlasenko [Fri, 19 Aug 2011 13:58:24 +0000 (15:58 +0200)]
Use simpler rounding up to next multiple of 2.

* util.c (printllval): simpler rounding up to next multiple of 2.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoCosmetic fixes, no code changes
Denys Vlasenko [Thu, 18 Aug 2011 10:48:56 +0000 (12:48 +0200)]
Cosmetic fixes, no code changes

* defs.h: Add/reformat comments.
* signal.c: Remove wrong comment. Add warning directive
when we detect that NSIG is undefined. Add comment about
NSIG on ARM. Fix typo in comment.
(signame): Reformat code a bit without changes to logic.
Shorten static buffer.
(sys_rt_sigprocmask): Remove stray empty line.
* syscall.c: Add warning directive when we detect that
NSIG is undefined. Add comment about NSIG on ARM.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>