Dmitry V. Levin [Sun, 6 Dec 2015 05:28:11 +0000 (05:28 +0000)]
times.test: workaround buggy libc
* tests/times.c: Include <sys/syscall.h>.
(main): On systems where user's and kernel's long types are the same,
prefer direct times syscall over libc's times function because
the latter is more prone to return value truncation.
Dmitry V. Levin [Sun, 6 Dec 2015 04:51:57 +0000 (04:51 +0000)]
times.test: reduce cpu time consumption, increase struct tms diversity
* tests/times.c (main): Reduce cpu time consumption fourfold,
make the parent process consume less cpu time than the child process
so that members of the structure returned by times syscall would be
more likely to contain different values.
Dmitry V. Levin [Sat, 5 Dec 2015 00:03:49 +0000 (00:03 +0000)]
tests: replace old stat tests with stat.test and stat64.test
* tests/stat.c: Replace with a wrapper around lstatx.c
* tests/stat.test: Replace with a wrapper around statx.sh.
* tests/stat32-v.test: Remove.
* tests/stat32.c: Remove.
* tests/stat64-v.test: Remove.
* tests/stat64.c: New file.
* tests/stat64.test: New test.
* tests/Makefile.am (check_PROGRAMS): Replace stat32 with stat64.
(stat_CFLAGS): Rename to stat64_CFLAGS.
(TESTS): Replace stat32-v.test and stat64-v.test with stat64.test.
* tests/.gitignore: Replace stat32 with stat64.
Dmitry V. Levin [Sat, 5 Dec 2015 00:01:56 +0000 (00:01 +0000)]
tests: prepare for detailed testing of stat family syscalls
Parametrize code from fstatat.c to support <asm/stat.h>
as an alternative to <sys/stat.h> and move it to a separate file.
* tests/statx.sh: New file, based on fstatat64.test.
* tests/fstatat64.test: Use it.
* tests/newfstatat.test: Likewise.
* tests/xstatx.c: New file, based on fstatat.c.
* tests/fstatat.c: Use it.
* tests/Makefile.am (EXTRA_DIST): Add statx.sh and xstatx.c.
* tests/fstatat64.c (FSTATAT_NAME): Change to TEST_SYSCALL_NAME.
* tests/newfstatat.c: Likewise.
Gabriel Laskar [Fri, 4 Dec 2015 00:07:33 +0000 (01:07 +0100)]
ioctl: allow to stop decoding number
For some ioctls, like from drm, the identification of the correct ioctl
is done by custom code. Specifying IOCTL_NUMBER_STOP_LOOKUP on
return of ioctl_decode_command_number() disables further calls to
ioctl_lookup().
* defs.h (IOCTL_NUMBER_UNKNOWN, IOCTL_NUMBER_HANDLED,
IOCTL_NUMBER_STOP_LOOKUP): Add macros representing ioctl number state
decoding.
* ioctl.c (SYS_FUNC(ioctl)): Skip ioctl_lookup() when
ioctl_decode_command_number() returns a value with
IOCTL_NUMBER_STOP_LOOKUP flag is set.
Suggested-by: Patrik Jakobsson <patrik.r.jakobsson@gmail.com> Signed-off-by: Gabriel Laskar <gabriel@lse.epita.fr> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Dmitry V. Levin [Fri, 4 Dec 2015 16:51:11 +0000 (16:51 +0000)]
tests: skip restart_syscall.test on x32
The syscall number of restart_syscall returned by the kernel in case
of ERESTART_RESTARTBLOCK is broken on x32 from the beginning, see
https://lkml.org/lkml/2015/11/30/790
Dmitry V. Levin [Fri, 4 Dec 2015 15:00:37 +0000 (15:00 +0000)]
x86_64, x32: add a replacement for <asm/stat.h>
Some old kernel headers, Ubuntu 14.04 in particular, provide
<asm/stat.h> editions that are completely wrong for x32.
Workaround this issue by providing a replacement.
Dmitry V. Levin [Thu, 3 Dec 2015 15:48:43 +0000 (15:48 +0000)]
fstatat64.test: lift /proc requirement
While -P option needs /proc to match descriptors, it does not use
/proc to match pathnames. As this test does not need descriptor
match, the /proc requirement can be safely lifted.
Dmitry V. Levin [Mon, 30 Nov 2015 13:57:51 +0000 (13:57 +0000)]
syscall.c: move inclusion of arch specific files to the end of file
Move inclusion of arch specific files that define static functions to
the end of syscall.c.
* syscall.c (get_syscall_result_regs, get_error, getregs_old):
New forward declarations.
(arch_get_scno): Move forward.
Move inclusion of "get_scno.c", "get_syscall_args.c",
"get_syscall_result.c", "get_error.c", and "getregs_old.c"
to the end of file.
Dmitry V. Levin [Mon, 30 Nov 2015 03:30:51 +0000 (03:30 +0000)]
Cleanup print_pc
Apparently, there are only two types of instruction pointer printers
depending on the architecture: those that print a register that was
fetched earlier, and those that fetch a register themselves using upeek.
With this change, architectures of the first type have ARCH_PC_REG
defined in their arch_regs.c file, architectures of the first type
have ARCH_PC_PEEK_ADDR defined there, and the common code in syscall.c
uses these macros to print the instruction pointer.
Dmitry V. Levin [Mon, 30 Nov 2015 01:46:52 +0000 (01:46 +0000)]
cleanup: make get_scno.c files more readable
Make get_scno.c files more self-contained. While they are still
being included by syscall.c, the latter no longer provides
a function framework for them.
Dmitry V. Levin [Mon, 30 Nov 2015 00:57:14 +0000 (00:57 +0000)]
cleanup: make get_syscall_args.c files more readable
Make get_syscall_args.c files more self-contained. While they are
still being included by syscall.c, the latter no longer defines
get_syscall_args function.
Dmitry V. Levin [Mon, 30 Nov 2015 00:01:01 +0000 (00:01 +0000)]
cleanup: make get_syscall_result.c files more readable
Make get_syscall_result.c files more self-contained. While they are
still being included by syscall.c, the latter no longer provides
a function framework for them.
Dmitry V. Levin [Sat, 28 Nov 2015 02:58:29 +0000 (02:58 +0000)]
cleanup: make arch_sigreturn.c files more readable
Make arch_sigreturn.c files more self-sustained. While they are
still being included by sigreturn.c, the latter no longer defines
arch_sigreturn function.
* linux/alpha/arch_sigreturn.c (arch_sigreturn): Define.
* linux/arm/arch_sigreturn.c: Likewise.
* linux/crisv10/arch_sigreturn.c: Likewise.
* linux/i386/arch_sigreturn.c: Likewise.
* linux/ia64/arch_sigreturn.c: Likewise.
* linux/m68k/arch_sigreturn.c: Likewise.
* linux/microblaze/arch_sigreturn.c: Likewise.
* linux/mips/arch_sigreturn.c: Likewise.
* linux/powerpc/arch_sigreturn.c: Likewise.
* linux/s390/arch_sigreturn.c: Likewise.
* linux/sparc/arch_sigreturn.c: Likewise.
* linux/tile/arch_sigreturn.c: Likewise.
* linux/x32/arch_sigreturn.c: Remove code.
Include "x86_64/arch_sigreturn.c".
* linux/x86_64/arch_sigreturn.c: Stop including "x32/arch_sigreturn.c".
Include "i386/arch_sigreturn.c" with arch_sigreturn temporarily defined
to i386_arch_sigreturn.
(arch_sigreturn): Define. Add x32 personality support there.
* sigreturn.c: Remove arch_sigreturn header and footer.
Dmitry V. Levin [Fri, 27 Nov 2015 01:51:22 +0000 (01:51 +0000)]
x32: fix struct dirent decoding
* kernel_types.h: New file.
* Makefile.am (strace_SOURCES): Add it.
* configure.ac (AC_CHECK_TYPES): Check for __kernel_long_t
and __kernel_ulong_t in <asm/posix_types.h>.
* dirent.c: Stop including <dirent.h>.
(kernel_dirent): Remove.
Include "kernel_types.h".
(print_old_dirent, SYS_FUNC(getdents)): Print variables
of kernel_ulong_t type using %Lu format.
* syscall.c (kernel_long_t, kernel_ulong_t): Remove.
Include "kernel_types.h".
* tests/getdents.c (kernel_dirent): Remove.
Include "kernel_types.h".
(print_dirent): Print variables of kernel_ulong_t type using %Lu format.
Elvira Khabirova [Thu, 26 Nov 2015 14:18:00 +0000 (17:18 +0300)]
Refer to -h on incorrect usage
* defs.h (error_msg_and_help): New prototype.
* strace.c (error_msg_and_help): New function.
(error_opt_arg, init): Use it.
(usage): Remove unnecessary arguments.
* count.c: Use the new function.
Convert parsers of flock structures to new mpers infrastructure
* fetch_struct_flock.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* fcntl.c (print_struct_flock64): New function.
(printflock64): Use fetch_struct_flock64 and print_struct_flock64.
(printflock): Use fetch_struct_flock and print_struct_flock64.
Dmitry V. Levin [Fri, 9 Oct 2015 20:10:31 +0000 (20:10 +0000)]
fcntl.c: remove redundant ifdefs
* fcntl.c (USE_PRINTFLOCK64): Remove macro.
(printflock64): Define unconditionally.
(SYS_FUNC(fcntl)): Do not check for USE_PRINTFLOCK64,
F_DUPFD_CLOEXEC, F_NOTIFY, F_SETLEASE, and F_GETLEASE macros.
Dmitry V. Levin [Fri, 9 Oct 2015 01:38:07 +0000 (01:38 +0000)]
fcntl.c: use <linux/fcntl.h> instead of <fcntl.h>
Include <linux/fcntl.h> for proper definitions of F_* constants
and flock structures.
* configure.ac (AC_CHECK_TYPES): Check for struct flock, struct flock64,
struct __kernel_flock, and struct __kernel_flock64 in <linux/fcntl.h>.
* flock.h: New file.
* Makefile.am (strace_SOURCES): Add it.
* fcntl.c: Include it instead of <fcntl.h>.
(struct flock64): Remove.
(printflock): Use struct_kernel_flock instead of struct flock.
(printflock64): Use struct_kernel_flock64 instead of struct flock64.
Mike Frysinger [Sat, 31 Oct 2015 04:47:53 +0000 (00:47 -0400)]
Support C libraries without System V shared memory/ipc
Some systems (like Bionic) omit support for SysV related code. That
means no C library headers for strace to include. Add configure tests
to probe the headers from the kernel and use them when they are
available.
It might make more sense to never rely on the C library's headers as
there is no guarantee or requirement that the structure layout between
apps and the C library match that what is passed to the kernel.
* configure.ac (AC_CHECK_HEADERS): Check for linux/ipc.h,
linux/mqueue.h, linux/msg.h, linux/sem.h, linux/shm.h,
sys/ipc.h, sys/msg.h, sys/sem.h, and sys/shm.h.
* ipc_defs.h: Include <sys/ipc.h> or <linux/ipc.h> depending
on what is available.
* ipc_msg.c: Replace <sys/ipc.h> with "ipc_defs.h".
Fallback to <linux/msg.h> when available.
* ipc_msgctl.c: Include <sys/msg.h>, <asm/msgbuf.h>, or <linux/msg.h>
based on what is available. Note missing support for old ipc structs.
* ipc_sem.c: Include <sys/sem.h> or <linux/sem.h> depending
on what is available. Only decode sembuf when available.
* ipc_shm.c: Fallback to <linux/shm.h> when available.
* ipc_shmctl.c: Include <sys/shm.h>, <asm/shmbuf.h>, or <linux/shm.h>
based on what is available. Note missing support for old ipc structs.
* print_mq_attr.c: Fallback to <linux/mqueue.h> when available.
Dmitry V. Levin [Tue, 24 Nov 2015 02:30:45 +0000 (02:30 +0000)]
Remove parser of query_module syscall
Since query_module syscall is present only in kernels before Linux 2.6
and strace does not support those kernels, there is no use to keep this
parser any longer.
* bjm.c: Do not include <sys/*>, "xlat/qm_which.h",
and "xlat/modflags.h".
(MOD_*, QM_*, module_symbol, module_info, SYS_FUNC(query_module)):
Remove.
* linux/dummy.h (sys_query_module): Add stub alias.
* xlat/modflags.in: Remove.
* xlat/qm_which.in: Remove.
Dmitry V. Levin [Sat, 21 Nov 2015 03:59:09 +0000 (03:59 +0000)]
Simplify control messages printers
Do not pass sizeof(struct cmsghdr) to every cmsg printer.
* net.c (printcmsghdr): Pass pointer to cmsg_data and length
of cmsg_data to print_cmsg_type_data.
(print_cmsg_type_data): Update prototype. Pass pointer to cmsg_data
and length of cmsg_data to cmsg printers.
(print_scm_rights, print_scm_creds, print_scm_security): Update.
Dmitry V. Levin [Fri, 20 Nov 2015 01:43:12 +0000 (01:43 +0000)]
mpers: skip xlat struct definitions in mpers mode
Avoid duplicate definitions of xlat structures in files
compiled in mpers mode.
Each xlat file defines the corresponding xlat struct with
either global or local visibility using the following rules:
- if xlat struct declaration is available in defs.h,
a global definition is provided in regular mode,
and nothing is provided in mpers mode;
- otherwise, if xlat file is included by a mpers source file,
a global definition is provided in regular mode
(unless no mpers mode is supported on this architecture,
in that case, a local definition is provided instead),
and a declaration is provided in mpers mode;
- otherwise, a local definition is provided in regular mode,
and an error message is printed in mpers mode.
Fallback definitions of constants provided by xlat files
remain available in all modes.
* bootstrap: Invoke generate_mpers_am.sh before xlat/gen.sh.
* defs.h (adjtimex_modes, adjtimex_status, sigev_value): Remove.
* generate_mpers_am.sh: Generate mpers_xlat.h.
* Makefile.am (EXTRA_DIST): Add mpers_xlat.h.
* print_sigevent.c: Include "xlat/sigev_value.h" unconditionally.
* print_timex.c: Include "xlat/adjtimex_modes.h" and
"xlat/adjtimex_status.h" unconditionally.
* xlat/gen.sh (cond_xlat): Move printing of fallback definitions ...
(cond_def): ... here.
(gen_header): Check also mpers_xlat.h for global declarations
of xlat structures.
Process input file twice, first time print directives
only, second time print everything.
Wrap struct xlat into #ifdef IN_MPERS ... #else ... #endif.
* xlat/getrandom_flags.in: Cleanup.
Dmitry V. Levin [Thu, 19 Nov 2015 18:13:53 +0000 (18:13 +0000)]
Mpersify parsers of readdir and getdents syscalls
* defs.h (dirent_types): New xlat prototype.
* dirent.c: Stop including "xlat/direnttypes.h".
(kernel_dirent): New typedef. Mpersify it.
(print_old_dirent): Use it instead of old_dirent_t.
(SYS_FUNC(getdents)): Use it instead of struct kernel_dirent.
Rename direnttypes to dirent_types.
(SYS_FUNC(getdents64)): Move ...
* dirent64.c: ... here. Rename direnttypes to dirent_types.
Include "xlat/dirent_types.h".
* Makefile.am (strace_SOURCES): Add dirent64.c.
* xlat/direnttypes.in: Rename to xlat/dirent_types.in.
Dmitry V. Levin [Thu, 19 Nov 2015 00:29:19 +0000 (00:29 +0000)]
printcmsghdr: move type and data decoders to a separate function
* net.c (print_scm_rights, print_scm_creds, print_scm_security): Change
to return void. Move printing of struct cmsghdr closing '}' ...
(printcmsghdr): ... here. Move type and data decoders to ...
(print_cmsg_type_data): ... new function.
Dmitry V. Levin [Wed, 18 Nov 2015 23:18:17 +0000 (23:18 +0000)]
Assume that libc provides sendmsg
Starting with commit v4.6-281-g7af9f35, we implicitly assume that
HAVE_SENDMSG is always defined. Therefore, the check for sendmsg
availability is redundant and could be safely removed.