tests: add more tests for sched_getscheduler and sched_xetscheduler
* tests/sched_xetscheduler.c (main): Check for decoding of invalid PID
in sched_getscheduler and sched_setscheduler, invalid address
of sched_param structure, and invalid policy value.
struct iocb contains two fields with fd semantics: aio_fildes and
aio_resfd. It is quite reasonable to use the appropriate function for
printing them (apart from just "%d").
* aio.c (print_common_flags): Add struct tcb pointer to parameter list;
use printfd for printing aio_resfd field.
(print_iocb_header): Add struct tcb pointer to parameter list;
use printfd for printing aio_fildes field.
(print_iocb): Provide tcp argument to print_iocb_header
and print_common_flags.
(SYS_FUNC(io_cancel)): Likewise.
Dmitry V. Levin [Wed, 31 Aug 2016 16:31:53 +0000 (16:31 +0000)]
tests/xstatx.c: use zero_extend_signed_to_ull/sign_extend_unsigned_to_ll
Use zero_extend_signed_to_ull and sign_extend_unsigned_to_ll macros
instead of explicit casts with unpredictable sign extension semantics.
* tests/xstatx.c (print_time, main): Use zero_extend_signed_to_ull
instead of explicit cast.
(print_stat): Use zero_extend_signed_to_ull and
sign_extend_unsigned_to_ll instead of explicit casts.
* xlat/sa_handler_values.in: New file.
* signal.c: Include "xlat/sa_handler_values.h".
(get_sa_handler_str, print_sa_handler): New functions.
(SYS_FUNC(sigsetmask), SYS_FUNC(signal), decode_new_sigaction): Use them.
Dmitry V. Levin [Tue, 30 Aug 2016 18:22:41 +0000 (18:22 +0000)]
Update SCTP_* constants
* xlat/socksctpoptions.in: Add SCTP_PR_SUPPORTED, SCTP_DEFAULT_PRINFO,
and SCTP_PR_ASSOC_STATUS introduced by linux kernel commits
v4.8-rc1~140^2~148^2~5, v4.8-rc1~140^2~148^2~4, and
v4.8-rc1~140^2~148^2~3, respectively.
Dmitry V. Levin [Tue, 30 Aug 2016 18:01:50 +0000 (18:01 +0000)]
Update BPF_* constants
* xlat/bpf_map_types.in: Add BPF_MAP_TYPE_CGROUP_ARRAY introduced
by linux kernel commit v4.8-rc1~140^2~212^2~2.
* xlat/bpf_prog_types.in: Add BPF_PROG_TYPE_XDP introduced
by linux kernel commit v4.8-rc1~140^2~64^2~10.
As configure.ac does not check for linux/futex.h, HAVE_LINUX_FUTEX_H is
never defined and therefore the inclusion of <linux/futex.h> guarded by
HAVE_LINUX_FUTEX_H makes no sense.
Moreover, <linux/futex.h> used to have an incorrect definition
of FUTEX_WAIT_BITSET_PRIVATE and FUTEX_WAKE_BITSET_PRIVATE:
since kernel commit v2.6.24-6320-gcd68998 where these definitions
were initially introduced and up to v2.6.31-7082-gf8d1e54 where they
were finally fixed these macros had been incorrectly defined via
FUTEX_WAIT_BITS and FUTEX_WAKE_BITS instead of FUTEX_WAIT_BITSET
and FUTEX_WAKE_BITSET, and these incorrect definitions made their way
into some distributions still in use.
futex: avoid printing val when it is not used by the futex command
This is analogous to timeout argument omitting in FUTEX_WAKE_BITSET
command.
* futex.c (SYS_FUNC(futex)): Remove common printing of val argument.
Add printing of val argument for all futex commands except
FUTEX_LOCK_PI, FUTEX_UNLOCK_PI, and FUTEX_TRYLOCK_PI.
xlat: add FUTEX_WAIT* commands with FUTEX_CLOCK_REALTIME bit set
* xlat/futexops.in: Add FUTEX_WAIT|FUTEX_CLOCK_REALTIME and
FUTEX_WAIT_PRIVATE|FUTEX_CLOCK_REALTIME values supported by linux kernel
since commit v4.5-rc1~172^2.
Use alternate form for printing hexadecimal numbers to avoid confusion.
Use printaddr to print uaddr as the latter is interpreted as a pointer
in all currently supported futex operations.
* futex.c (SYS_FUNC(futex)): Fix formatting of unknown command
argument.
According to the initial and current (v4.7) kernel implementations,
in FUTEX_WAKE_OP case the compare function does not have
FUTEX_OP_OPARG_SHIFT flag and occupies 4 bits starting with bit 24.
* futex.c (SYS_FUNC(futex)): Do not print FUTEX_OP_OPARG_SHIFT
for 27th bit of val3 in FUTEX_WAKE_OP case.
James Clarke [Mon, 29 Aug 2016 23:50:33 +0000 (00:50 +0100)]
Use PTRACE_SUNDETACH everywhere on SPARC and SPARC64
SPARC has a different PTRACE_DETACH value correctly defined in
sys/ptrace.h, but linux/ptrace.h clobbers it with the standard one.
PTRACE_SUNDETACH is also defined to the correct value by sys/ptrace.h,
so use that instead.
* strace.c (detach) [SPARC]: Move redefinition of PTRACE_DETACH
to PTRACE_SUNDETACH ...
* ptrace.h [SPARC || SPARC64]: ... here.
Dmitry V. Levin [Fri, 26 Aug 2016 21:32:53 +0000 (21:32 +0000)]
Do not use AC_HEADER_MAJOR, include <sys/sysmacros.h> unconditionally
glibc, starting with commit glibc-2.24-28-gdbab657, has deprecated
inclusion of <sys/sysmacros.h> by <sys/types.h>. The method used
for deprecation breaks AC_HEADER_MAJOR: this autoconf macro no longer
defines MAJOR_IN_SYSMACROS, which consequently breaks build.
Let's assume that all systems supported by strace provide major, minor,
and makedev macros via <sys/sysmacros.h>.
* btrfs.c (struct_btrfs_ioctl_vol_args_v2): New type. Mpersify it.
(btrfs_print_qgroup_inherit): Change qgi_addr type to unsigned long.
(btrfs_ioctl): Replace struct btrfs_ioctl_vol_args_v2 with
struct_btrfs_ioctl_vol_args_v2.
Dmitry V. Levin [Wed, 24 Aug 2016 00:29:47 +0000 (00:29 +0000)]
Revert "tests/xstatx.c: fix stat syscall tests on mips64"
Previous commit effectively changed types of st_atime, st_ctime, and
st_mtime members of struct stat and struct stat64 to signed integers,
making the mips64 workaround obsolete.
Dmitry V. Levin [Wed, 24 Aug 2016 00:29:40 +0000 (00:29 +0000)]
Mpersify parsers of struct stat and struct stat64
On many architectures that support multiple personalities,
struct stat differ between personalities. While old code could handle
these differences, there are some architectures, e.g. sparc64, that also
have different struct stat64. Rewrite parsers using mpers functionality
to fix these issues.
Dmitry V. Levin [Tue, 23 Aug 2016 23:39:45 +0000 (23:39 +0000)]
Move redefinition of stat types to asm_stat.h
* file.c: Move redefinition of types that might be used
to define struct stat ...
* linux/asm_stat.h: ... here.
* tests/xstatx.c: Remove redefinition of stat types.
Dmitry V. Levin [Tue, 23 Aug 2016 14:49:20 +0000 (14:49 +0000)]
x86_64: provide a replacement of <asm/stat.h> for x32 personality
For the reason described in commit v4.10-517-gcfde1e3, a correct
definition of struct stat for x32 personality is necessary to enable
"asm_stat.h" with -mx32 on x86_64.
* linux/x32/asm_stat.h: Rename to ...
* linux/x86_64/asm_stat.h: ... new file.
* Makefile.am (strace_SOURCES): Add it.
* linux/x32/asm_stat.h: New file, include "x86_64/asm_stat.h".
Dmitry V. Levin [Mon, 22 Aug 2016 09:34:54 +0000 (09:34 +0000)]
sparc64: fix decoding of struct stat64 related syscalls
For some reason, struct stat and struct stat64 are different on sparc64.
This change fixes decoding of struct stat64 related syscalls for sparc64
personality, sparc32 personality on sparc64 needs more work.
* file.c (printstat64) [SPARC64]: Do not use printstat.
(SYS_FUNC(newfstatat)): Likewise.
tests: fill old_value argument in timer{,fd}_xettime tests
This is needed in order to differentiate it from the value returned
by the call. As a consequence, it enables revealing possible bugs
in syscall parsers, for example, when the value read on syscall
entering and not on syscall exiting, as it was the case with
timerfd_settime parser.
* tests/timer_xettime.c (main): Fill old.its field with value different
from the expected one upon call return.
* tests/timerfd_xettime.c: Likewise.
Fix old_value argument retrieval in timerfd_settime parser
This is done similar to timer_settime syscall parser.
* time.c (SYS_FUNC(timerfd_settime)): Retrieve old_value argument
on exiting and not on entering. Return 0 instead of RVAL_DECODED
since the call hasn't been decoded in full on entering.
Move SH-specific argument number calculation to getllval
This change prevents scattering of ll-related hacks and simplifies
pread/pwrite syscalls parsers' logic a bit.
* util.c (getllval): Add fixup for arg_no for SuperH when argument
number is equal to 3.
* io.c (PREAD_OFFSET_ARG): Remove.
(SYS_FUNC(pread)): Always use argument number 3 for "count" argument
printing.
(SYS_FUNC(pwrite)): Likewise.
Dmitry V. Levin [Sun, 21 Aug 2016 22:02:09 +0000 (22:02 +0000)]
sparc64: fix sigreturn decoding for sparc personality
* linux/sparc/arch_sigreturn.c (arch_sigreturn): Parametrize
member types of struct signal_frame.
* linux/sparc64/arch_sigreturn.c (sparc64_arch_sigreturn,
sparc32_arch_sigreturn): New functions.
(arch_sigreturn): Use them.
Dmitry V. Levin [Mon, 15 Aug 2016 18:33:47 +0000 (18:33 +0000)]
Drop support of dummy members of struct stat
As st_flags, st_fstype, and st_gen members of struct stat are not filled
by the kernel, there is no use supporting them.
* configure.ac (AC_CHECK_MEMBERS): Remove struct stat.st_flags,
struct stat.st_fstype, and struct stat.st_gen.
* file.c [STAT32_PERSONALITY, HAVE_STRUCT_STAT64]: Do not undefine
HAVE_STRUCT_STAT_ST_FLAGS, HAVE_STRUCT_STAT_ST_FSTYPE,
and HAVE_STRUCT_STAT_ST_GEN.
* printstat.h (DO_PRINTSTAT): Do not check for
HAVE_STRUCT_STAT_ST_FLAGS, HAVE_STRUCT_STAT_ST_FSTYPE,
and HAVE_STRUCT_STAT_ST_GEN.
Dmitry V. Levin [Mon, 15 Aug 2016 17:33:25 +0000 (17:33 +0000)]
Assume that struct stat contains st_blksize, st_blocks, and st_rdev
Our test suite already assumes that struct stat contains st_blksize,
st_blocks, and st_rdev members, and there haven't been any complaints.
* configure.ac (AC_CHECK_MEMBERS): Remove struct stat.st_blksize,
struct stat.st_blocks, and struct stat.st_rdev.
* printstat.h (DO_PRINTSTAT): Do not check for
HAVE_STRUCT_STAT_ST_BLKSIZE, HAVE_STRUCT_STAT_ST_BLOCKS,
and HAVE_STRUCT_STAT_ST_RDEV.
Dmitry V. Levin [Sun, 14 Aug 2016 00:02:55 +0000 (00:02 +0000)]
s390x, x32: remove redundant definitions of ARCH_PC_REG
* linux/s390x/arch_regs.c (ARCH_PC_REG): Remove, it is already defined
in just included linux/s390/arch_regs.c.
* linux/x32/arch_regs.c (ARCH_PC_REG): Remove, it is already defined
in just included linux/x86_64/arch_regs.c.
Dmitry V. Levin [Sat, 13 Aug 2016 22:05:20 +0000 (22:05 +0000)]
tests/init.sh: print exit code of failed commands
* init.sh (run_prog, run_prog_skip_if_failed): When the program fails,
add its exit code to the diagnostic message.
(run_strace): When strace fails, add its exit code to the diagnostic
message.
(run_strace_merge): When strace-log-merge fails, add its exit code
to the diagnostic message.
Dmitry V. Levin [Sat, 13 Aug 2016 22:04:59 +0000 (22:04 +0000)]
Fix leakage of placeholder descriptors to tracees
As a side effect of commit v4.11-211-g0736d4e, strace used to leak
placeholders for standard descriptors to tracees thus affecting their
behaviour. Fix this by setting close-on-exec flag on placeholder
descriptors.
* strace.c (open_dummy_desc): Set close-on-exec flag on the descriptor
that is going to be returned to the caller.
(fd_is_placeholder): New array.
(ensure_standard_fds_opened, redirect_standard_fds): New functions.
(startup_child): Use redirect_standard_fds.
(init): Use ensure_standard_fds_opened.
Dmitry V. Levin [Thu, 11 Aug 2016 22:31:08 +0000 (22:31 +0000)]
tests: fix *stat64 tests on alpha
On some architectures including alpha, <asm/stat.h> provides a
definition of struct stat that has no st_atime_nsec, st_mtime_nsec, and
st_ctime_nsec fields. At the same time, struct stat64 always has these
fields. Fix tests to take this difference into account.
* tests/fstat64.c (STRUCT_STAT_IS_STAT64): New macro, defined to 1.
* tests/lstat64.c (STRUCT_STAT_IS_STAT64): Likewise.
* tests/stat64.c (STRUCT_STAT_IS_STAT64): Likewise.
* tests/xstatx.c [!STRUCT_STAT] (STRUCT_STAT_IS_STAT64): New macro,
defined to 0.
[USE_ASM_STAT && STRUCT_STAT_IS_STAT64]:
(HAVE_STRUCT_STAT_ST_ATIME_NSEC, HAVE_STRUCT_STAT_ST_CTIME_NSEC,
HAVE_STRUCT_STAT_ST_MTIME_NSEC): Redefine to 1.
James Cowgill [Thu, 11 Aug 2016 16:33:02 +0000 (16:33 +0000)]
tests/nsyscalls.test: only trace the "syscall" syscall on mips o32
The "syscall" syscall only exists on o32 and causes strace to error out on
64-bit mips ABIs. Pass MIPS_ABI from the configure script through to
nsyscalls.test so the MIPS ABI can be checked.
* configure.ac (MIPS_ABI): Substitute into output files.
* tests/Makefile.am (MIPS_ABI): Export via AM_TEST_LOG_FLAGS.
* tests/nsyscalls.test: Restrict special mips handling to mips o32.
James Cowgill [Thu, 11 Aug 2016 16:33:01 +0000 (16:33 +0000)]
tests/xstatx.c: fix stat syscall tests on mips64
For historical reasons the kernel struct stat represents times as unsigned
32-bit integers on mips64. Therefore, while it's possible to give a file a
timestamp before 1970 with futimens, reading the same timestamp through
struct stat will give a positive time (around 2106).
Workaround by using positive timestamps for testing on mips64.
* tests/xstatx.c (create_sample): Use positive timestamps on mips64.
Dmitry V. Levin [Tue, 9 Aug 2016 00:07:53 +0000 (00:07 +0000)]
Fix decoding of invalid syscalls mapped to indirect subcalls
When the syscall number returned by arch_get_scno is a mapped indirect
subcall (i.e. mapped subcall of socketcall or ipc syscall), do not
mistakenly treat it as a valid indirect subcall.
* defs.h (SCNO_IS_VALID): Treat scno with TRACE_INDIRECT_SUBCALL flag
as invalid.
* syscall.c (syscall_name): Do no shuffle scno.
(trace_syscall_entering, trace_syscall_exiting): Use
tcp->s_ent->sys_name instead of syscall_name.
(get_scno): In case of invalid syscall, allocate a dynamic struct sysent
containing an appropriate .sys_name.
* tests/nsyscalls.c (main) [SYS_socket_subcall]: Check decoding
of direct syscall number SYS_socket_subcall+1.
(main) [SYS_ipc_subcall]: Check decoding of direct syscall number
SYS_ipc_subcall+1.