]> granicus.if.org Git - strace/log
strace
11 years agoDo not use off_t in sendfile decoding
Dmitry V. Levin [Wed, 20 Mar 2013 09:48:44 +0000 (09:48 +0000)]
Do not use off_t in sendfile decoding

sendfile parser used to decode off_t* parameter as a pointer to host
off_t type.  With this change, it is decoded as a pointer to target long
type.

* io.c (print_off_t): New function.
(sys_sendfile): Use it.
* linux/aarch64/syscallent1.h: Use sys_sendfile64 for sendfile decoding.
* linux/tile/syscallent.h: Likewise.
* linux/x32/syscallent.h: Likewise.
* linux/x86_64/syscallent.h: Likewise.
* linux/hppa/syscallent.h: Use sys_sendfile64 for sendfile64 decoding.
* linux/metag/syscallent.h: Correct sendfile syscall name.
* linux/or1k/syscallent.h: Likewise.

11 years agoFix build with older versions of libaio.h
Dmitry V. Levin [Mon, 18 Mar 2013 23:28:29 +0000 (23:28 +0000)]
Fix build with older versions of libaio.h

* configure.ac: When libaio.h is available, check for
struct iocb.u.c.flags, IO_CMD_PWRITE and IO_CMD_PWRITEV.
* desc.c (print_common_flags): Check for HAVE_STRUCT_IOCB_U_C_FLAGS.
(sys_io_submit): Check for HAVE_DECL_IO_CMD_PWRITE and
HAVE_DECL_IO_CMD_PWRITEV.

11 years agoFix io_submit decoding
Dmitry V. Levin [Mon, 18 Mar 2013 22:58:28 +0000 (22:58 +0000)]
Fix io_submit decoding

* desc.c (print_common_flags, sys_io_submit): Add missing ", " to
SUB_COMMON output, remove extra ", " from SUB_VECTOR output.

11 years agotests: relax check_prog to allow timeout command provided by busybox
Maxin B. John [Mon, 18 Mar 2013 10:35:06 +0000 (11:35 +0100)]
tests: relax check_prog to allow timeout command provided by busybox

Busybox version of timeout doesn't have --version option.
Relax check_prog to handle those cases.

* tests/init.sh (check_prog): Use type builtin to check program
availability.

Signed-off-by: Maxin B. John <maxin.john@enea.com>
11 years agoReorganize get_regs code, hopefully without functional changes
Dmitry V. Levin [Mon, 18 Mar 2013 10:17:14 +0000 (10:17 +0000)]
Reorganize get_regs code, hopefully without functional changes

* syscall.c [I386 || ARM || OR1K || METAG] (ARCH_REGS_FOR_GETREGSET):
New macro.
(get_regset): Implement for AARCH64, METAG, OR1K and X32.
(get_regs) [AARCH64 || METAG || OR1K || X32]: Use it.

11 years agoarm, i386: use PTRACE_GETREGSET if available
Dmitry V. Levin [Sun, 17 Mar 2013 23:48:45 +0000 (23:48 +0000)]
arm, i386: use PTRACE_GETREGSET if available

* syscall.c [ARM || I386 || X86_64] (get_regset): New function.
(get_regs) [ARM || I386 || X86_64]: Use it.

11 years agoInclude <sys/uio.h> and <elf.h> on all architectures
Dmitry V. Levin [Mon, 18 Mar 2013 00:59:27 +0000 (00:59 +0000)]
Include <sys/uio.h> and <elf.h> on all architectures

* syscall.c: Include <sys/uio.h> and <elf.h> on all architectures.

11 years agox86-64: enhance PTRACE_GETREGSET test
Dmitry V. Levin [Sun, 17 Mar 2013 23:18:35 +0000 (23:18 +0000)]
x86-64: enhance PTRACE_GETREGSET test

* syscall.c (get_regs) [X86_64]: Check whether PTRACE_GETREGSET
works regardless of the kernel version.

11 years agox32: use PTRACE_GETREGSET unconditionally
Dmitry V. Levin [Sun, 17 Mar 2013 23:15:18 +0000 (23:15 +0000)]
x32: use PTRACE_GETREGSET unconditionally

* syscall.c (get_regs) [X32]: Assume that PTRACE_GETREGSET always works
regardless of the kernel version.

11 years agox86-64, x32: do not include linux/ptrace.h unnecessarily
Dmitry V. Levin [Mon, 18 Mar 2013 00:27:33 +0000 (00:27 +0000)]
x86-64, x32: do not include linux/ptrace.h unnecessarily

* syscall.c [X86_64 || X32]: Stop including linux/ptrace.h.

11 years agoi386, tile, x32: do not redefine ptrace prototype
Dmitry V. Levin [Mon, 18 Mar 2013 00:19:06 +0000 (00:19 +0000)]
i386, tile, x32: do not redefine ptrace prototype

* defs.h [I386 || TILE || X32]: Use ptrace prototype from sys/ptrace.h.

11 years agoptrace: decode note segment descriptor types
Dmitry V. Levin [Mon, 18 Mar 2013 00:52:29 +0000 (00:52 +0000)]
ptrace: decode note segment descriptor types

* configure.ac (AC_CHECK_HEADERS): Add elf.h.
* process.c: Include elf.h.
(nt_descriptor_types): New xlat structure.
(sys_ptrace): Use it.

11 years agoUpdate MADV_* constants
Dmitry V. Levin [Thu, 14 Mar 2013 18:55:26 +0000 (18:55 +0000)]
Update MADV_* constants

* mem.c (madvise_cmds): Add more MADV_* constants from
asm-generic/mman-common.h

Reported-by: Robin Hack <hack.robin@gmail.com>
11 years agoTweaks for -c: fixed setitimer/getitimer hack; optimized call_summary_pers()
Denys Vlasenko [Thu, 7 Mar 2013 11:27:40 +0000 (12:27 +0100)]
Tweaks for -c: fixed setitimer/getitimer hack; optimized call_summary_pers()

count_syscall() was calling setitimer/getitimer once in order to find
smallest "tick" OS uses in time accounting, in order to use it
for syscalls which apparently spent less than that time in syscall.
The code assumed that this "tick" is not zero... but it is zero
on linux-3.6.11. Which means that this hack doesn't work...

At least this change prevents this measurement from being done
_repeatedly_, by initializing one_tick to -1, not 0.

While at it, added comments in count_syscall() explaining what we are doing.

Optimized call_summary_pers() a bit, by eliminating redundant tv -> float
conversions, and prevented 0.0/0.0 which was resulting in "% time"
being shown as "-nan" if total CPU time spent was 0.000000
(try "strace -c /bin/true").

The code seems to seriously underestimate CPU usage:
"strace -c ls -lR /usr/share >/dev/null" shows total time spent
in syscalls to be only ~10..20% of what "time ls -lR /usr/share >/dev/null"
shows.

It might be useful to have a mode where we show wall clock time
spent in syscalls, not CPU time. It might also be more accurate.

   text    data     bss     dec     hex filename
 245019     676    5708  251403   3d60b strace_old
 244923     684    5676  251283   3d593 strace

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoOpen-code isprint(c) and isspace(c)
Denys Vlasenko [Wed, 6 Mar 2013 22:44:23 +0000 (23:44 +0100)]
Open-code isprint(c) and isspace(c)

We don't call setlocale, thus we always use C locale.
But libc supports various other locales, and therefore
its ctype interface is general and at times inefficient.
For example, in glibc these macros result in function call,
whereas for e.g. isprint(c) just c >= ' ' && c <= 0x7e
suffices.

By open-coding ctype checks (we have only 4 of them)
we avoid function calls, we get smaller code:

   text    data     bss     dec     hex filename
 245127     680    5708  251515   3d67b strace_old
 245019     676    5708  251403   3d60b strace

and we don't link in ctype tables (beneficial for static builds).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoMakefile: add commented-out tweak to generate link map
Denys Vlasenko [Wed, 6 Mar 2013 17:59:09 +0000 (18:59 +0100)]
Makefile: add commented-out tweak to generate link map

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoStop using a large static buffer in getfdpath
Denys Vlasenko [Wed, 6 Mar 2013 17:24:34 +0000 (18:24 +0100)]
Stop using a large static buffer in getfdpath

   text    data     bss     dec     hex filename
 245075     680    9836  255591   3e667 strace_old
 245143     680    5708  251531   3d68b strace

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoFix wrongly indented closing curly brace. No code changes
Denys Vlasenko [Tue, 5 Mar 2013 16:46:19 +0000 (17:46 +0100)]
Fix wrongly indented closing curly brace. No code changes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agostrace_vfprintf: if malloc fails, exit gracefully
Denys Vlasenko [Tue, 5 Mar 2013 16:29:18 +0000 (17:29 +0100)]
strace_vfprintf: if malloc fails, exit gracefully

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoUse sysconf(_SC_PAGESIZE) instead of hardcoded PAGE_SHIFT
Dmitry V. Levin [Tue, 5 Mar 2013 14:58:24 +0000 (14:58 +0000)]
Use sysconf(_SC_PAGESIZE) instead of hardcoded PAGE_SHIFT

PAGE_SHIFT couldn't be reliably obtained at compile time,
thanks to Chris Metcalf for the hint.

* mem.c: Do not include <sys/user.h>.
[SH64] Do not include <asm/page.h>.
(get_pagesize): New function.
(sys_mmap_pgoff, sys_old_mmap_pgoff): Use it.

11 years agoEmit better message for ERESTARTNOHAND return
Denys Vlasenko [Tue, 5 Mar 2013 15:56:35 +0000 (16:56 +0100)]
Emit better message for ERESTARTNOHAND return

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoDisable STREAMS syscalls for non-SPARC
Denys Vlasenko [Tue, 5 Mar 2013 15:50:12 +0000 (16:50 +0100)]
Disable STREAMS syscalls for non-SPARC

   text    data     bss     dec     hex filename
   3002       0    1024    4026     fba stream.o.old
   1729       0    1024    2753     ac1 stream.o

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoFix printstrbufarg's address argument to be long, not int
Denys Vlasenko [Tue, 5 Mar 2013 15:17:46 +0000 (16:17 +0100)]
Fix printstrbufarg's address argument to be long, not int

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoRemove variable tracing_paths and check in pathtrace_match
Denys Vlasenko [Tue, 5 Mar 2013 15:01:53 +0000 (16:01 +0100)]
Remove variable tracing_paths and check in pathtrace_match

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoUse dynamically-sized selected[] array for -P PATH
Denys Vlasenko [Tue, 5 Mar 2013 14:46:34 +0000 (15:46 +0100)]
Use dynamically-sized selected[] array for -P PATH

While at it, added a small optimization of not remembering
the path twice if it happens to be the same.

   text    data     bss     dec     hex filename
 245111     680   10860  256651   3ea8b strace_old
 245075     680    9804  255559   3e647 strace

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agometag,or1k: whitesace style fix. no code changes
Denys Vlasenko [Tue, 5 Mar 2013 13:03:07 +0000 (14:03 +0100)]
metag,or1k: whitesace style fix. no code changes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoAssorted fixes to syscallent.h
Denys Vlasenko [Tue, 5 Mar 2013 12:59:45 +0000 (13:59 +0100)]
Assorted fixes to syscallent.h

or1k was missing TM on many memory-related syscalls
sys_lookup_dcookie is 3-arg on 64-bit arches, and isn't TF
sys_recvmsg is 3-arg on all arches
sys_nfsservctl is 3-arg on all arches
sys_timerfd_create is 2-arg on all arches
sys_[f]truncate64 is 4-arg or 3-arg, never 5-arg
truncate64 is TF
sys_[l]lseek is TD
fstat[64] is TD

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoAdd support for Imagination Technologies Meta
James Hogan [Fri, 22 Feb 2013 14:44:10 +0000 (14:44 +0000)]
Add support for Imagination Technologies Meta

Add support for Imagination Technologies Meta architecture (the
architecture/ABI is usually referred to as metag in code). The Meta
Linux kernel port is in the process of being upstreamed for v3.9 so it
uses generic system call numbers.

sys_lookup_dcookie writes a filename to buffer argument, so I've set
TF flag.
nfsservctl appears to be set to sys_ni_syscall in asm-generic/unistd.h
so I've left it blank.
truncate64/ftruncate64/pread64/pwrite64/readahead have unaligned 64bit
args which are packed tightly on metag, so less arguments on metag.
fchdir/llseek takes a file descriptor so s/TF/TD/
sync_file_range has 2 64bit args so uses 6 args, so s/4/6/
timerfd_create/msgget/msgctl/msgrcv/semget/segtimedop/semop/shmget/
shmctl/shmat/shmdt/recvmsg/migrate_pages have different number of args.
oldgetrlimit is just getrlimit for metag.
add TM flag to various memory syscalls.
metag doesn't directly use sys_mmap_pgoff for mmap2.
prlimit64/process_vm_readv/process_vm_writev take a pid so add TP flag.
fanotify_init doesn't appear to take a file descriptor so remove TD.
Add kcmp syscall.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Christian Svensson <blue@cmd.nu>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoumovestr: speed up check for NUL byte in the fetched word
Denys Vlasenko [Fri, 1 Mar 2013 17:52:59 +0000 (18:52 +0100)]
umovestr: speed up check for NUL byte in the fetched word

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoFix trace=set regression introduced by commit v4.7-111-g9cbc15b
Dmitry V. Levin [Fri, 1 Mar 2013 15:50:22 +0000 (15:50 +0000)]
Fix trace=set regression introduced by commit v4.7-111-g9cbc15b

* syscall.c (qual_syscall, qualify): Pass personality down to
qualify_one.
* tests/qual_syscall: New test.
* tests/Makefile.am (TESTS): Add qual_syscall.

11 years agotile: handle printllval like x86_64 or powerpc64
Chris Metcalf [Fri, 1 Mar 2013 09:41:02 +0000 (10:41 +0100)]
tile: handle printllval like x86_64 or powerpc64

Without this fix the tilegx build fails when it hits the new #error
about SIZEOF_LONG > 4.

* util.c (printllval): Fix printing of long long values on TILE.

Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoMake -b take SYSCALL param, document it in --help and in manpage.
Denys Vlasenko [Wed, 27 Feb 2013 11:15:19 +0000 (12:15 +0100)]
Make -b take SYSCALL param, document it in --help and in manpage.

To not waste an option letter for just one trick,
extend -b to take a parameter:
"on which syscalls do you want to detach?".
Currently supports only execve.

While at it, fixed (by removing non-Linux and stale info)
and extended manpage text about -f.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoCleanup umoven and umovestr
Dmitry V. Levin [Tue, 26 Feb 2013 21:16:22 +0000 (21:16 +0000)]
Cleanup umoven and umovestr

Cleanup sloppy error handling.

First, EFAULT kind of errors from process_vm_readv by itself is not
something unusual, so a warning message will not be issued unless a
short read is detected.

Second, clients of umoven and umovestr are not prepared to detect and
handle short reads that can happen in these functions.  The most safe
way to handle them is to return an error code.

* util.c (umoven, umovestr): Cleanup handling of errors coming from
process_vm_readv and PTRACE_PEEKDATA.

11 years agopathtrace: fix umovestr return code check
Dmitry V. Levin [Tue, 26 Feb 2013 19:23:27 +0000 (19:23 +0000)]
pathtrace: fix umovestr return code check

* pathtrace.c (upathmatch): Only NUL-terminated strings can be
path-matched, so fix the umovestr return code check to filter out
unsuitable strings.

11 years agoFix compilation errors uncovered by -Werror=enum-compare
Dmitry V. Levin [Tue, 26 Feb 2013 22:02:30 +0000 (22:02 +0000)]
Fix compilation errors uncovered by -Werror=enum-compare

This fixes regression introduced by commit v4.7-111-g9cbc15b.

* syscall.c: Merge all nsyscalls* enums into single enum.
Likewise merge nerrnos*, nsignals*, and nioctlents* into single enums.

11 years agoMass replace error_msg("%s", "literal") -> error_msg("literal")
Denys Vlasenko [Tue, 26 Feb 2013 11:30:09 +0000 (12:30 +0100)]
Mass replace error_msg("%s", "literal") -> error_msg("literal")

There is no need to print literal strings through "%s".
Only untrusted strings such as filenames need that.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoMake umoven report success as 0, not >=0, stop returning success on partial reads
Ben Noordhuis [Tue, 26 Feb 2013 11:24:25 +0000 (12:24 +0100)]
Make umoven report success as 0, not >=0, stop returning success on partial reads

umoven() uses process_vm_readv() when available but it returns the
return value of that syscall, which is the number of bytes copied,
while its callers expect it to simply return zero on success.

It was causing syscalls that take a user-space argument to print
the abbreviated version, e.g.:

  epoll_ctl(5, EPOLL_CTL_ADD, 10, {...})

Instead of:

  epoll_ctl(5, EPOLL_CTL_ADD, 10, {EPOLLIN, {u32=10, u64=10}})

* util.c (umoven): Make umove[n] report success as 0, not >=0,
stop returning "success" on partial reads.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoAssorted NOMMU fixes
Denys Vlasenko [Tue, 26 Feb 2013 11:00:34 +0000 (12:00 +0100)]
Assorted NOMMU fixes

With -D, strdup'ing of pathname is necessary only on NOMMU.

Don't set skip_startup_execve to 1 if NOMMU and not in daemonized mode
(try "strace [-D] -b env echo HI" to see whether we detach on correct execve).

Fix test_ptrace_FOO shortcuts on NOMMU to always assume success
and _properly_ set all variables.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoShorten help text - no need to show deprecated option -F
Denys Vlasenko [Tue, 26 Feb 2013 10:33:54 +0000 (11:33 +0100)]
Shorten help text - no need to show deprecated option -F

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoMerge adjacent tprint's
Denys Vlasenko [Sat, 23 Feb 2013 19:07:44 +0000 (20:07 +0100)]
Merge adjacent tprint's

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoCorrect i > MAX_NSYSCALLS commparison: should be i >= MAX_NSYSCALLS
Denys Vlasenko [Sat, 23 Feb 2013 17:19:28 +0000 (18:19 +0100)]
Correct i > MAX_NSYSCALLS commparison: should be i >= MAX_NSYSCALLS

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoFix wrong offset display in dumpstr
Denys Vlasenko [Fri, 22 Feb 2013 14:00:11 +0000 (15:00 +0100)]
Fix wrong offset display in dumpstr

BTW, the new code from prev commit is 5 times faster
than old one :)

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoFix a bug in dumpstr (no null termination). Essentially rewrote dumpstr
Denys Vlasenko [Fri, 22 Feb 2013 13:47:39 +0000 (14:47 +0100)]
Fix a bug in dumpstr (no null termination). Essentially rewrote dumpstr

This is a 14 year old bug (!).

It wasn't biting us merely because outstr[80] was static, thus ended up
in bss and whatever was after it "accidentally" provided the NUL byte.
When dumpstr was changed to use on-stack buffer, the bug reared its ugly head.

This is a rewrite which is smaller and should be significantly faster
for _long_ strings.

   text    data     bss     dec     hex filename
 244627     680   10860  256167   3e8a7 strace.t9/strace
 244563     680   10860  256103   3e867 strace.ta/strace

* util.c (dumpstr): Rewrite to be faster and smaller.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoEliminate MAX_QUALS, make qualifier array dynamic
Denys Vlasenko [Fri, 22 Feb 2013 12:37:36 +0000 (13:37 +0100)]
Eliminate MAX_QUALS, make qualifier array dynamic

MAX_QUALS was 2048, even though most arches used less than 500 entries
in it. MAX_QUALS had to be maintained by hand to be higher than syscall
count. It also limited the highest possible fd to track.

This change makes qual_flagsN[] arrays start sized to the required minimum
(number of syscalls) and grow dynamically if user requested
-e read=BIGNUM. As a precaution, BIGNUM should be < 2^15, but this limit
can be raised with no cost for normal strace invocations.

qual_flags is now a define to qual_vec[current_personality].

As a bonus, this patch aliases sysent, errnoent, signalent, ioctlent
names in one-personality arches to their corresponding <foo>0 arrays,
removing one indirection level.

  text   data    bss    dec    hex filename
244471    700  12928 258099  3f033 strace.t7/strace
244627    680  10860 256167  3e8a7 strace.t8/strace

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoCreate and use struct_sysent and struct_ioctlent typedefs.
Denys Vlasenko [Fri, 22 Feb 2013 12:26:10 +0000 (13:26 +0100)]
Create and use struct_sysent and struct_ioctlent typedefs.

This is a preparatory mass replace patch with no code changes.

The future change will need to typedef sysent to sysent0,
which results in compile failures when "struct sysent" string
gets mangled into "struct sysent0".

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoUse tcp->qual_flg instead of qual_flags[] in verbose() and abbrev()
Denys Vlasenko [Fri, 22 Feb 2013 12:23:38 +0000 (13:23 +0100)]
Use tcp->qual_flg instead of qual_flags[] in verbose() and abbrev()

We have hundreds of uses of these macros.
Result is more efficient and 1.1 kbyte shorter code:

  text    data     bss     dec     hex filename
245579     700   12928  259207   3f487 strace.t5/strace
244471     700   12928  258099   3f033 strace.t6/strace

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoRemove unused QUAL_FAULT code (was used by non-Linux code only).
Denys Vlasenko [Thu, 21 Feb 2013 15:17:08 +0000 (16:17 +0100)]
Remove unused QUAL_FAULT code (was used by non-Linux code only).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoUse uint8_t for qual_flags[] instead of ints.
Denys Vlasenko [Thu, 21 Feb 2013 15:15:43 +0000 (16:15 +0100)]
Use uint8_t for qual_flags[] instead of ints.

Resulting bss reduction is ~6kbytes:

   text    data     bss     dec     hex filename
 245703     700   19072  265475   40d03 strace.t4/strace
 245687     700   12928  259315   3f4f3 strace.t5/strace

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoEliminate many SCNO_IS_VALID checks
Denys Vlasenko [Thu, 21 Feb 2013 15:13:47 +0000 (16:13 +0100)]
Eliminate many SCNO_IS_VALID checks

By adding tcp->s_ent pointer tot syscall table entry,
we can replace sysent[tcp->scno] references by tcp->s_ent.
More importantly, we may ensure that tcp->s_ent is always valid,
regardless of tcp->scno value. This allows us to drop
SCNO_IS_VALID(tcp->scno) checks before we access syscall
table entry.

We can optimize (qual_flags[tcp->scno] & QUAL_foo) checks
with a similar technique.

Resulting code shrink:
   text    data     bss     dec     hex filename
 245975     700   19072  265747   40e13 strace.t3/strace
 245703     700   19072  265475   40d03 strace.t4/strace

* count.c (count_syscall): Use cheaper SCNO_IN_RANGE() check.
* defs.h: Add "int qual_flg" and "const struct sysent *s_ent"
to struct tcb. Remove "int u_nargs" from it.
Add UNDEFINED_SCNO constant which will mark undefined scnos
in tcp->qual_flg.
* pathtrace.c (pathtrace_match): Drop SCNO_IS_VALID check.
Use tcp->s_ent instead of sysent[tcp->scno].
* process.c (sys_prctl): Use tcp->s_ent->nargs instead of tcp->u_nargs.
(sys_waitid): Likewise.
* strace.c (init): Add compile-time check that DEFAULT_QUAL_FLAGS
constant is consistent with init code.
* syscall.c (decode_socket_subcall): Use tcp->s_ent->nargs
instead of tcp->u_nargs. Set tcp->qual_flg and tcp->s_ent.
(decode_ipc_subcall): Likewise.
(printargs): Use tcp->s_ent->nargs instead of tcp->u_nargs.
(printargs_lu): Likewise.
(printargs_ld): Likewise.
(get_scno): [MIPS,ALPHA] Use cheaper SCNO_IN_RANGE() check.
If !SCNO_IS_VALID, set tcp->s_ent and tcp->qual_flg to default values.
(internal_fork): Use tcp->s_ent instead of sysent[tcp->scno].
(syscall_fixup_for_fork_exec): Remove SCNO_IS_VALID check.
Use tcp->s_ent instead of sysent[tcp->scno].
(get_syscall_args): Likewise.
(get_error): Drop SCNO_IS_VALID check where it is redundant.
(dumpio): Drop SCNO_IS_VALID check where it is redundant.
Use tcp->s_ent instead of sysent[tcp->scno].
(trace_syscall_entering): Use (tcp->qual_flg & UNDEFINED_SCNO) instead
of SCNO_IS_VALID check. Use tcp->s_ent instead of sysent[tcp->scno].
Drop SCNO_IS_VALID check where it is redundant.
Print undefined syscall name with undefined_scno_name(tcp).
(trace_syscall_exiting): Likewise.
* util.c (setbpt): Use tcp->s_ent instead of sysent[tcp->scno].

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoARM: make it one-personality arch
Denys Vlasenko [Thu, 21 Feb 2013 14:46:34 +0000 (15:46 +0100)]
ARM: make it one-personality arch

ARM in fact _is_ one personality.

We had two personalities for it because it has a handful of
syscalls with huge scnos (0x000f00xx).

Extending syscall table to have [0x000f0005] index is of course
not a good idea.

Someone decided to handle that by having a separate personality
just for these syscalls.

But multi-personality arch does a bit more work in other parts.

This patch is another alternative: "move" 0x000f00nn syscalls
down to the entries just above last ordinary syscall,
by manipulating scno if it falls into the 0x000f00xx range.

In order to not worsen genuine undefined scnos' printing,
the code remaps scno back to actual value before printing
"syscall_NNN" string.

* defs.h: Remove multi-reprsonality defines from ARM.
* syscall.c (shuffle_scno): New function.
(undefined_scno_name): New function.
(get_scno): [ARM] Replace personality setting with scno shuffling.
(trace_syscall_entering): Print unknown syscall name using
undefined_scno_name().
(trace_syscall_exiting): Likewise.
* linux/arm/syscallent.h: Add ARM specific syscalls at the end.
* linux/arm/errnoent1.h: Deleted.
* linux/arm/ioctlent1.h: Deleted.
* linux/arm/signalent1.h: Deleted.
* linux/arm/syscallent1.h: Deleted.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoarm: shorten syscall table for EABI - no point in storing NULL entries
Denys Vlasenko [Wed, 20 Feb 2013 17:08:25 +0000 (18:08 +0100)]
arm: shorten syscall table for EABI - no point in storing NULL entries

Also, reformatted ARM code in get_scno(), mostly improved comments,
without code changes.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoUse the same style of includes in linux/*/* files
Denys Vlasenko [Wed, 20 Feb 2013 11:38:14 +0000 (12:38 +0100)]
Use the same style of includes in linux/*/* files

While at it, fix some comments which say
"we use i386 syscalls/ioctls/errnos" but in reality
common ones are used.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoFix compiler warnings
Denys Vlasenko [Tue, 19 Feb 2013 16:39:56 +0000 (17:39 +0100)]
Fix compiler warnings

With constant current_wordsize == 4 and 32-bit longs,
gcc was spooked by "1ul << (8 * current_wordsize)" = "1ul << 32".

Make such places conditional on SIZEOF_LONG > 4.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoImprove comment text. No code changes
Denys Vlasenko [Tue, 19 Feb 2013 15:59:26 +0000 (16:59 +0100)]
Improve comment text. No code changes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoFix NOMMU + daemonized tracer SEGV
Denys Vlasenko [Tue, 19 Feb 2013 15:30:31 +0000 (16:30 +0100)]
Fix NOMMU + daemonized tracer SEGV

pathname[] was getting destroyed, execve of garbage pathname
failing, and to top it off, the tracer's stack was also
smashed and trecer segfaulted.

* strace.c (exec_or_die): New function.
(startup_child): Don't use pathname[] contents after vfork,
make a malloced copy instead. Explain "NOMMU + -D bug"
and how we work around it.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoMake it possible to to do test builds for NOMMU architectures
Denys Vlasenko [Tue, 19 Feb 2013 14:30:12 +0000 (15:30 +0100)]
Make it possible to to do test builds for NOMMU architectures

And while using it, I discovered that -D doesn't work too well
on NOMMU. Added a comment about it.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoClean up mmap decoding
Denys Vlasenko [Tue, 19 Feb 2013 10:28:20 +0000 (11:28 +0100)]
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>
11 years agoRemove unused function sys_mmap64
Denys Vlasenko [Mon, 18 Feb 2013 14:49:57 +0000 (15:49 +0100)]
Remove unused function sys_mmap64

No wonder that it is unused.
It's code looked quite questionable.

* mem.c (sys_mmap64): Remove this function.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoRemove code which supports systems with long long off_t.
Denys Vlasenko [Mon, 18 Feb 2013 14:47:57 +0000 (15:47 +0100)]
Remove code which supports systems with long long off_t.

While looking at mmap mess, did experimenting in order
to figure out what gets used when.

Tried building armv4tl, armv5l, armv6l, mips, mipsel, i686,
x86_64 and none of they have long long off_t,
which isn't suprprising: we aren't using glibc defines
which enable that.

Moreover, we SHOULD NOT use off_t in syscall decode!
Its size depends on libc, not on arch! I.e. it is essentially
unpredictable and can even in theory vary on the same arch
with different libc.

We should use longs or long longs, in a way which matches
architectural ABI for the given syscall. There are usually
*at most* two permutations, no need to add yet another variable
(sizeof(off_t)) to the mix.

This change removes almost all HAVE_LONG_LONG_OFF_T conditionals,
which will reveal further possible simplifications.

* mem.c: Remove code conditional on HAVE_LONG_LONG_OFF_T.
As a result, never remap sys_mmap64 to sys_mmap.
(print_mmap): Compile unconditionally.
(sys_old_mmap): Compile unconditionally.
(sys_mmap): Compile unconditionally.
* io.c (sys_sendfile): Add a FIXME comment.
* file.c: Remove code conditional on HAVE_LONG_LONG_OFF_T.
As a result, never remap sys_*stat64 to sys_*stat etc.
(sys_truncate): Compile unconditionally.
(realprintstat): Likewise.
(sys_stat): Likewise.
(sys_fstat): Likewise.
(sys_lstat): Likewise.
* desc.c (printflock): Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoFixes in "new" mmap
Denys Vlasenko [Mon, 18 Feb 2013 02:13:07 +0000 (03:13 +0100)]
Fixes in "new" mmap

* mem.c (sys_mmap): Ensure unsigned expansion of tcp->u_arg[5].
Add page shift of offset for I386.
Use tcp->ext_arg[5] as offset for X32.
(sys_old_mmap): [X32] Remove this function, X32 doesn't use is.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoPreliminary simplifications in mmap functions
Denys Vlasenko [Mon, 18 Feb 2013 01:36:36 +0000 (02:36 +0100)]
Preliminary simplifications in mmap functions

* mem.c: Move "define sys_mmap64 sys_mmap" from the top
to the only place it affects.
(print_mmap): Make offset argument unsigned, for safer implicit conversions.
(sys_old_mmap): [IA64] use unsigned narrow_arg[].
Cast u_arg[5] (offset param) to unsigned long, to prevent erroneous signed
expansion.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoRemove broken HAVE_LONG_LONG conditionals
Denys Vlasenko [Sun, 17 Feb 2013 21:41:33 +0000 (22:41 +0100)]
Remove broken HAVE_LONG_LONG conditionals

We use printllval without HAVE_LONG_LONG guards in many places,
but define it only if HAVE_LONG_LONG. This means that
on !HAVE_LONG_LONG systems we won't build for some time now.

* defs.h: Remove HAVE_LONG_LONG guard around LONG_LONG() macro
and printllval() function declaration.
* util.c: Remove HAVE_LONG_LONG guard around printllval()
function definition.
(printllval): Add compile-time error check for using wrong
if branch. Explain places where we deliberately use mismatched
types for printf formats.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoUse explicit long type instead of off_t
Denys Vlasenko [Sun, 17 Feb 2013 19:08:50 +0000 (20:08 +0100)]
Use explicit long type instead of off_t

* file.c (sys_lseek): Use long instead of off_t.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoMerge two identical tables
Denys Vlasenko [Sun, 17 Feb 2013 13:31:55 +0000 (14:31 +0100)]
Merge two identical tables

* defs.h: Declare whence_codes[].
* desc.c: Delete static whence[].
(printflock[64]): Use whence_codes.
* file.c: Make whence_codes[] non-static.
Add SEEK_DATA and SEEK_HOLE to them.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoRemove wrong x32-specific lseek
Denys Vlasenko [Sun, 17 Feb 2013 12:17:49 +0000 (13:17 +0100)]
Remove wrong x32-specific lseek

Testing confirmed what I suspected: x32 lseek uses kernel-sized
(i.e. wide) long for offset parameter.

* file.c: Delete sys_lseek32.
* linux/syscall.h: Likewise.
* linux/x32/syscallent1.h: Likewise.
* test/x32_lseek.c: New file.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoFix SEGV in lseek
Denys Vlasenko [Sun, 17 Feb 2013 11:47:44 +0000 (12:47 +0100)]
Fix SEGV in lseek

I found hard way why the code was using "_whence" name.

* file.c: Rename whence[] to whence_codes[].
(sys_lseek): Fix printxval() to use whence_codes[].
(sys_lseek32): Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoComment inner workings of sys_[l]lseek
Denys Vlasenko [Sun, 17 Feb 2013 00:38:14 +0000 (01:38 +0100)]
Comment inner workings of sys_[l]lseek

The code doesn't look fully correct to me, but I need to experiment
on actual x32 machine before I start "fixing" things.
For now, add comments, and optimize out one tprints() call...

* file.c (sys_lseek): Rename '_whence' as 'whence'.
Merge printing of ", " into subsequent tprintf.
(sys_lseek32): Likewise.
(sys_llseek): Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoCosmetic fixes to syscall tables, no code changes
Denys Vlasenko [Sun, 17 Feb 2013 00:37:35 +0000 (01:37 +0100)]
Cosmetic fixes to syscall tables, no code changes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoMake linux/mips/syscallent.h smaller
Denys Vlasenko [Sat, 16 Feb 2013 13:44:31 +0000 (14:44 +0100)]
Make linux/mips/syscallent.h smaller

* linux/mips/syscallent.h: Remove trailing empty elements.
Compactify huge stretches of NULL elements in the middle.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoSimple optimization in get_error
Denys Vlasenko [Sat, 16 Feb 2013 13:25:56 +0000 (14:25 +0100)]
Simple optimization in get_error

* defs.h: Define SCNO_IN_RANGE(scno) macro.
* syscall.c (get_error): Change return type to void.
Use SCNO_IN_RANGE instead of SCNO_IS_VALID.
(trace_syscall_exiting): Stop checking get_error() return value.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoMass rename of SCNO_IN_RANGE define to SCNO_IS_VALID
Denys Vlasenko [Sat, 16 Feb 2013 12:22:38 +0000 (13:22 +0100)]
Mass rename of SCNO_IN_RANGE define to SCNO_IS_VALID

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoFinish prefixing regs struct names with arch_
Denys Vlasenko [Sat, 16 Feb 2013 07:23:40 +0000 (08:23 +0100)]
Finish prefixing regs struct names with arch_

* defs: Rename regs -> sparc_regs.
* signal.c (sys_sigreturn): Use new variable name.
* syscall.c: Rename regs -> sparc_regs, regs -> avr32_regs.
(getrval2): Use new variable names.
(printcall): Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoUse the same type for i386_regs on 32-bit and 64-bit x86.
Denys Vlasenko [Fri, 15 Feb 2013 20:04:28 +0000 (21:04 +0100)]
Use the same type for i386_regs on 32-bit and 64-bit x86.

* defs.h: Stop including <asm/ptrace.h> for x86.
Change i386_regs from "struct pt_regs" to "struct user_regs_struct".
* syscall.c: Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoFix build error on Tile
Denys Vlasenko [Fri, 15 Feb 2013 14:25:37 +0000 (15:25 +0100)]
Fix build error on Tile

* syscall.c (get_scno): [TILE] Remove TCB_WAITEXECVE check,
it is never true on Tile, and stopped compiling when
TCB_WAITEXECVE define was removed for Tile.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agox86: zero-extend 32-bit args in syscall entry instead of sign-extension
Denys Vlasenko [Fri, 15 Feb 2013 14:01:38 +0000 (15:01 +0100)]
x86: zero-extend 32-bit args in syscall entry instead of sign-extension

Zero-extension is slightly more common that sign-extension:
all pointers are zero-extended, and some other params are unsigned.

Whereas signed ones (fds, pids, etc) are often treated as
_32-bit ints_ even by kernel, so just unconditionally casting
such tcp->u_arg[N] to int works.

* syscall.c (get_syscall_args): [X86] Zero-extend 32-bit args
instead of sign-extension.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoMacroize conditional signed widening operation
Denys Vlasenko [Fri, 15 Feb 2013 13:58:52 +0000 (14:58 +0100)]
Macroize conditional signed widening operation

* defs.h: Define widen_to_long() macro.
* signal.c (sys_kill): Use it instead of open-coding it.
(sys_tgkill): Use widen_to_long() on pids.
* resource.c (decode_rlimit): Formatting fix.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoA better handling of current_wordsize
Denys Vlasenko [Fri, 15 Feb 2013 13:55:14 +0000 (14:55 +0100)]
A better handling of current_wordsize

On x86_64:
  text    data     bss     dec     hex filename
435661   26628   47424  509713   7c711 strace_old
435501   26612   47440  509553   7c671 strace_new_clever_wordsize

On x32 and arm it should be even better, current_wordsize becomes
a constant there.

* defs.h: Declare current_wordsize as a variable if needed,
else declare as a constant define.
Remove declatation of personality_wordsize[].
* syscall.c: Make personality_wordsize[] static.
Declare current_wordsize as a variable if needed.
(set_personality): Set current_wordsize only if non-constant.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoRemove unnecessary "return 0" statements
Denys Vlasenko [Fri, 15 Feb 2013 10:43:08 +0000 (11:43 +0100)]
Remove unnecessary "return 0" statements

* util.c (change_syscall): Remove dummy "return 0"s.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agox86: fix required kernel version for GETREGSET
Denys Vlasenko [Thu, 14 Feb 2013 23:24:19 +0000 (00:24 +0100)]
x86: fix required kernel version for GETREGSET

* syscall.c (get_regs): [X86] Use GETREGSET only if kernel >= 2.6.35

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoWhitespace fix, no code changes
Denys Vlasenko [Thu, 14 Feb 2013 12:39:53 +0000 (13:39 +0100)]
Whitespace fix, no code changes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoAdd support for the OpenRISC 1000 platform
Christian Svensson [Thu, 14 Feb 2013 12:26:27 +0000 (13:26 +0100)]
Add support for the OpenRISC 1000 platform

* configure.ac: Added or1k architecture..
* defs.h: Added or1k to use register reading system.
* linux/or1k/ioctlent.h.in: Use i386 ioctls.
* linux/or1k/syscallent.h: New file.
* process.c: Added or1k register defs to struct_user_offsets[].
* syscall.c: Added or1k_io iovec for or1k GETREGSET,
  regset structure for or1k.
  (printcall): Added handling for or1k.
  (get_regs): Likewise.
  (get_scno): Likewise.
  (get_syscall_args): Likewise.
  (get_syscall_result): Likewise.
  (get_error): Likewise.
* util.c (change_syscall): Added dummy handling for or1k.
* system.c (sys_or1k_atomic): New function (or1k specific syscall).

Signed-off-by: Christian Svensson <blue@cmd.nu>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years ago[X86] Use ptrace(PTRACE_GETREGSET, NT_PRSTATUS) to get registers.
Denys Vlasenko [Thu, 14 Feb 2013 02:29:48 +0000 (03:29 +0100)]
[X86] Use ptrace(PTRACE_GETREGSET, NT_PRSTATUS) to get registers.

Unlike PTRACE_GETREGS, this new method detects 32-bit processes
reliably, without checking segment register values which
are undocumented and aren't part of any sort of API.
While at it, also fixed x32 detection to use __X32_SYSCALL_BIT,
as it should have been from the beginning.

* defs.h: Declare os_release and KERNEL_VERSION.
* strace.c: Make os_release non-static, remove KERNEL_VERSION define.
* syscall.c: New struct i386_user_regs_struct,
static union x86_regs_union and struct iovec x86_io.
(printcall): Use i386_regs or x86_64_regs depending on x86_io.iov_len.
(get_regs): On x86 and kernels 2.6.30+, use PTRACE_GETREGSET,
on earlier kernels fall back to old method.
(get_scno): [X86] Determine personality based on regset size
on scno & __X32_SYSCALL_BIT.
(syscall_fixup_on_sysenter): Use i386_regs or x86_64_regs depending
on x86_io.iov_len.
(get_syscall_args): Likewise.
(get_error): Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoRename some register statics by prefixing their names with arch.
Denys Vlasenko [Wed, 13 Feb 2013 16:52:31 +0000 (17:52 +0100)]
Rename some register statics by prefixing their names with arch.

This makes it easier to grep for them.

* syscall.c: Rename variables:
r0 -> bfin_r0,alpha_r0,sh_r0.
a3 -> mips_a3.
r2 -> mips_r2.
(get_scno): Use new variable names.
(get_syscall_result): Likewise.
(get_error): Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoFactor out code to check addr, fetch and print siginfo
Denys Vlasenko [Wed, 13 Feb 2013 15:31:32 +0000 (16:31 +0100)]
Factor out code to check addr, fetch and print siginfo

* defs.h: Declare new function printsiginfo_at(tcp, addr).
* process.c (sys_waitid): Use printsiginfo_at().
(sys_ptrace): Likewise.
* signal.c: (printsiginfo_at): Implement this new function.
(sys_rt_sigsuspend): Use printsiginfo_at().
(sys_rt_sigtimedwait): Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoDecode struct iov in PTRACE_GET/SETREGSET
Denys Vlasenko [Wed, 13 Feb 2013 15:10:10 +0000 (16:10 +0100)]
Decode struct iov in PTRACE_GET/SETREGSET

* process.c (sys_ptrace): Decode struct iov in PTRACE_GET/SETREGSET.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoUnify representations of struct user fields for subarchitectures
Denys Vlasenko [Tue, 12 Feb 2013 16:15:19 +0000 (17:15 +0100)]
Unify representations of struct user fields for subarchitectures

* process.c: Unify MIPS and LINUX_MIPSN32, and SH and SH64 parts of
struct_user_offsets[].

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoAdd start_code and start_data members of struct user
Denys Vlasenko [Tue, 12 Feb 2013 16:10:05 +0000 (17:10 +0100)]
Add start_code and start_data members of struct user

* process.c: Add start_code and start_data members of struct user
in struct_user_offsets[], where appropriate.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoRemove hacks for old kernels for architectures which require new kernels
Denys Vlasenko [Tue, 12 Feb 2013 15:07:54 +0000 (16:07 +0100)]
Remove hacks for old kernels for architectures which require new kernels

* util.c (change_syscall): For MICROBLAZE, replace code
with dummy "return 0" and a comment explaining why that is ok
for this architecture.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoRemove stray syscall result reading code on syscall entry for s390
Denys Vlasenko [Tue, 12 Feb 2013 14:57:37 +0000 (15:57 +0100)]
Remove stray syscall result reading code on syscall entry for s390

This is a leftover from sysenter/sysexit split.
I can't run-test it, but from code inspection it seems to be correct.

* syscall.c (get_scno): Remove stray syscall result reading for s390[x].

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoDeobfuscate definitions of struct user offsets
Denys Vlasenko [Tue, 12 Feb 2013 14:51:58 +0000 (15:51 +0100)]
Deobfuscate definitions of struct user offsets

The maze of ifdefs/ifndefs was scaring new contributors.
Format it so that every arch has its own ifdef block.

* process.c: Deobfuscate definitions of struct user offsets.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoRemove hacks for old kernels for architectures which require new kernels
Denys Vlasenko [Tue, 12 Feb 2013 12:06:51 +0000 (13:06 +0100)]
Remove hacks for old kernels for architectures which require new kernels

* defs.h: Do not define TCB_WAITEXECVE for AARCH64.
* util.c (change_syscall): For AARCH64 and X32, replace code
with dummy "return 0" and a comment explaining why that is ok
for these architectures.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoRemove old kernel hacks for architectures which require new kernels
Denys Vlasenko [Tue, 12 Feb 2013 11:50:10 +0000 (12:50 +0100)]
Remove old kernel hacks for architectures which require new kernels

* defs.h: Do not define TCB_WAITEXECVE for AVR32, BFIN and TILE.
* util.c (change_syscall): For AVR32, BFIN and TILE, replace code
with dummy "return 0" and a comment explaining why that is ok
for these architectures.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoHandle recv[m]msg for non-native 32-bit personality syscalls
Denys Vlasenko [Tue, 12 Feb 2013 10:57:48 +0000 (11:57 +0100)]
Handle recv[m]msg for non-native 32-bit personality syscalls

* net.c (printmsghdr): If current_wordsize is 4 and long is wider than it,
read 32-bit struct msghdr and expand it into a native one before using it.
(printmmsghdr): Likewise for struct mmsghdr.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoFix is_negated_errno() check for X32
Denys Vlasenko [Tue, 12 Feb 2013 10:52:35 +0000 (11:52 +0100)]
Fix is_negated_errno() check for X32

X32's return value is 64-bit. We were truncating it to 32-bit long
before checking for -errno.

* syscall.c (is_negated_errno_x32): New function.
(get_error): Use is_negated_errno_x32 for X32 architecture.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoRemove unused / ambiguously used defines
Denys Vlasenko [Tue, 12 Feb 2013 10:43:46 +0000 (11:43 +0100)]
Remove unused / ambiguously used defines

We sometimes use LINUXSPARC and sometimes (more often)
use "defined(SPARC) || defined(SPARC64)". Better to use
one construct consistently.
LINUX_MIPS64 is altogether unused.

* defs.h: Remove LINUXSPARC and LINUX_MIPS64 defines.
Move PTRACE_xxx compat defines up, before arch-specific
machinery. Use defined(SPARC) || defined(SPARC64)
instead of LINUXSPARC.
* file.c: Use defined(SPARC) || defined(SPARC64) instead of LINUXSPARC.
* signal.c: Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoPreparatory patch for "new" x86 personality detection
Denys Vlasenko [Mon, 11 Feb 2013 11:29:36 +0000 (12:29 +0100)]
Preparatory patch for "new" x86 personality detection

* syscall.c: Move PT_FLAGS_COMPAT define to its only user, get_scno().
Rename arm_regs_union's fields to names less likely to collide with
system defines.
(get_regs): Use sizeof(arm_regs_union) instead of sizeof(aarch64_regs).
This should be the same, but htis way it's cleaner.
Remove __X32_SYSCALL_MASK and use __X32_SYSCALL_BIT instead.
Explain 64-bit check in X32 build better.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoFix sigaltstack decoder
Dmitry V. Levin [Sat, 9 Feb 2013 02:03:04 +0000 (02:03 +0000)]
Fix sigaltstack decoder

strace used to hang when decoding sigaltstack called with invalid
stack_t pointers because of mishandling umove() return code.

* signal.c (print_stack_t): Handle unfetchable stack_t properly.
Change return type to void.
(sys_sigaltstack): Update print_stack_t() usage.

Reported-by: kawillia@ucalgary.ca
11 years agoFix decoding of sysctl() when oldval fields are NULL
Mike Frysinger [Sat, 9 Feb 2013 00:10:07 +0000 (19:10 -0500)]
Fix decoding of sysctl() when oldval fields are NULL

If you call glibc's syscall wrapper like so:
static int name[] = { CTL_NET, NET_IPV4, NET_IPV4_LOCAL_PORT_RANGE };
int buffer[2] = { 32768, 61000 };
size_t size = sizeof(buffer);
sysctl(name, 3, 0, 0, buffer, size);
(note that oldval/oldlenp are NULL).

The current strace code complains like so:
_sysctl({{CTL_NET, NET_IPV4, NET_IPV4_LOCAL_PORT_RANGE, 38}, 3, process_vm_readv: Bad address
(nil), 0, 0x7fffe23c3960, 8}) = -1 EACCES (Permission denied)

Since passing NULL for the old values is valid, handle that explicitly.
This also simplifies the code a bit by splitting up the handling of the
new and old args so that we only handle the new args once.

Now the output looks like:
_sysctl({{CTL_NET, NET_IPV4, NET_IPV4_LOCAL_PORT_RANGE, 38}, 3, NULL, 0, 0x7fff8c0c91b0, 8) = -1 EACCES (Permission denied)

* system.c (sys_sysctl): Check if info.oldval is NULL first.  Move the
processing of oldlen/info.newval/info.newlen out so they always get
executed.  Fix the format strings so we use %lu for unsigned long rather
than a mix of %ld and %lu.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
11 years agoIf we are on a glibc system, assume it's at least glibc 2.1
Denys Vlasenko [Fri, 8 Feb 2013 17:49:06 +0000 (18:49 +0100)]
If we are on a glibc system, assume it's at least glibc 2.1

It is not likely anyone uses glibc older that that:
glibc 2.1.1 was released in 1999

* net.c: Remove test for glibc >= 2.1.
* signal.c: Remove code which is compiled only for glibc < 2.1.
* util.c: Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 years agoS390: stop using needlessly static long pc variable
Denys Vlasenko [Fri, 8 Feb 2013 14:50:05 +0000 (15:50 +0100)]
S390: stop using needlessly static long pc variable

* syscall.c: Remove "static long pc" variable.
(get_scno): Use an automatic long variable instead of a static.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>