strace/syscall.c

1427 lines
33 KiB
C
Raw Permalink Normal View History

1999-02-19 03:21:36 +03:00
/*
* Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
* Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
* Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
1999-12-23 17:20:14 +03:00
* Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
* Copyright (c) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
* Linux for s390 port by D.J. Barrow
* <barrow_dj@mail.yahoo.com,djbarrow@de.ibm.com>
* Copyright (c) 1999-2018 The strace developers.
1999-02-19 03:21:36 +03:00
* All rights reserved.
*
* SPDX-License-Identifier: LGPL-2.1-or-later
1999-02-19 03:21:36 +03:00
*/
#include "defs.h"
Introduce PTRACE_GET_SYSCALL_INFO support When PTRACE_GET_SYSCALL_INFO API works, use it instead of traditional upeek/get_regs API. Tested on x86_64 and x86. * get_personality.c: New file. * get_personality.h: Likewise. * Makefile.am (strace_SOURCES): Add them. * linux/aarch64/arch_get_personality.c: New file. * linux/powerpc64/arch_get_personality.c: Likewise. * linux/riscv/arch_get_personality.c: Likewise. * linux/s390x/arch_get_personality.c: Likewise. * linux/sparc64/arch_get_personality.c: Likewise. * linux/tile/arch_get_personality.c: Likewise. * linux/x32/arch_get_personality.c: Likewise. * linux/x86_64/arch_get_personality.c: Likewise. * linux/check_scno.c: Likewise. * linux/x32/check_scno.c: Likewise. * Makefile.am (EXTRA_DIST): Add them. * linux/ia64/arch_getrval2.c (getrval2): Invoke get_regs() if ptrace_syscall_info is in use. * linux/mips/arch_getrval2.c: Likewise. * linux/sparc/arch_getrval2.c: Likewise. * defs.h (get_personality_from_syscall_info): New prototype. * syscall.c: Include "get_personality.h" and "ptrace_syscall_info.h". (get_regs_error): Define unconditionally. (ptrace_sci): New static variable. (clear_regs): Reset ptrace_sci.op. (ptrace_syscall_info_is_valid, ptrace_get_syscall_info, get_syscall_regs): New functions. (get_syscall_result_regs): Change to get_syscall_regs. (get_instruction_pointer, get_stack_pointer, get_scno, get_syscall_args, get_error, set_error, set_success): Add ptrace_syscall_info support. * tests/int_0x80.test: New test. * tests/Makefile.am (DECODER_TESTS): Add int_0x80.test. (XFAIL_TESTS_x86_64, XFAIL_TESTS_x32): Remove. * tests/gen_tests.in (int_0x80): Remove.
2018-11-21 04:44:16 +03:00
#include "get_personality.h"
#include "mmap_notify.h"
#include "native_defs.h"
#include "ptrace.h"
Introduce PTRACE_GET_SYSCALL_INFO support When PTRACE_GET_SYSCALL_INFO API works, use it instead of traditional upeek/get_regs API. Tested on x86_64 and x86. * get_personality.c: New file. * get_personality.h: Likewise. * Makefile.am (strace_SOURCES): Add them. * linux/aarch64/arch_get_personality.c: New file. * linux/powerpc64/arch_get_personality.c: Likewise. * linux/riscv/arch_get_personality.c: Likewise. * linux/s390x/arch_get_personality.c: Likewise. * linux/sparc64/arch_get_personality.c: Likewise. * linux/tile/arch_get_personality.c: Likewise. * linux/x32/arch_get_personality.c: Likewise. * linux/x86_64/arch_get_personality.c: Likewise. * linux/check_scno.c: Likewise. * linux/x32/check_scno.c: Likewise. * Makefile.am (EXTRA_DIST): Add them. * linux/ia64/arch_getrval2.c (getrval2): Invoke get_regs() if ptrace_syscall_info is in use. * linux/mips/arch_getrval2.c: Likewise. * linux/sparc/arch_getrval2.c: Likewise. * defs.h (get_personality_from_syscall_info): New prototype. * syscall.c: Include "get_personality.h" and "ptrace_syscall_info.h". (get_regs_error): Define unconditionally. (ptrace_sci): New static variable. (clear_regs): Reset ptrace_sci.op. (ptrace_syscall_info_is_valid, ptrace_get_syscall_info, get_syscall_regs): New functions. (get_syscall_result_regs): Change to get_syscall_regs. (get_instruction_pointer, get_stack_pointer, get_scno, get_syscall_args, get_error, set_error, set_success): Add ptrace_syscall_info support. * tests/int_0x80.test: New test. * tests/Makefile.am (DECODER_TESTS): Add int_0x80.test. (XFAIL_TESTS_x86_64, XFAIL_TESTS_x32): Remove. * tests/gen_tests.in (int_0x80): Remove.
2018-11-21 04:44:16 +03:00
#include "ptrace_syscall_info.h"
#include "nsig.h"
#include "number_set.h"
#include "delay.h"
#include "retval.h"
#include <limits.h>
/* for struct iovec */
#include <sys/uio.h>
/* for __X32_SYSCALL_BIT */
#include <asm/unistd.h>
#include "regs.h"
#if defined(SPARC64)
2004-07-07 David S. Miller <davem@nuts.davemloft.net> * linux/sparc/syscallent.h: Sync with reality. * linux/sparc/syscall.h (sys_sendfile64, sys_futex, sys_gettid, sys_sched_setaffinity, sys_sched_getaffinity, sys_setxattr, sys_lsetxattr, sys_fsetxattr, sys_getxattr, sys_lgetxattr, sys_fgetxattr, sys_listxattr, sys_llistxattr, sys_flistxattr, sys_removexattr, sys_lremovexattr, sys_fremovexattr, sys_remap_file_pages, sys_readahead, sys_tgkill, sys_statfs64, sys_fstatfs64, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep, sys_timer_create, sys_timer_settime, sys_timer_gettime): New declarations. * linux/sparc64/dummy2.h, linux/sparc64/syscallent2.h, linux/sparc64/syscall.h, linux/sparc64/errnoent.h, linux/sparc64/errnoent1.h, linux/sparc64/errnoent2.h, linux/sparc64/ioctlent.h, linux/sparc64/ioctlent1.h, linux/sparc64/ioctlent2.h, linux/sparc64/signalent.h, linux/sparc64/signalent.h, linux/sparc64/signalent.h, linux/sparc64/signalent1.h, linux/sparc64/signalent2.h, linux/sparc64/syscall1.h, linux/sparc64/syscallent.h, linux/sparc64/syscallent1.h: New files. * defs.h (LINUXSPARC): Define also when SPARC64. (LINUX && SPARC64): Set SUPPORTED_PERSONALITIES to 3. Ignore SIGTRAP after execve by defining TCB_WAITEXECVE. Define possibly missing __NR_exit_group. Declare getrval2. * configure.ac (sparc64): New architecture case. * config.h.in (SPARC64): New define. * file.c (stat_sparc64): New structure. (printstat_sparc64): New output routine for that. (printstat): Call it, if personality is 2. (printstat64): Likewise. * util.c: Conditionalize ptrace defines on LINUXSPARC not LINUX && SPARC. (SPARC64 && LINUX): Define r_pc to r_tpc, and PTRACE_FOOREGS to PTRACE_FOOREGS64 so that more sparc code can be shared between 64-bit and 32-bit. (_hack_syscall5): Correct trap number when SPARC64. (PTRACE_WRITE{TEXT,DATA}): Add SPARC64 to ifdef guard. (getpc): Handle SPARC64 && LINUX. (printcall): Likewise. (arg fetching/setting): Use same code for SPARC64 LINUX as for SPARC. (setbpt): Handle SPARC64 && LINUX. (clearbpt): Likewise. * signal.c: Conditionalize ptrace defines on SPARC and SPARC64. (SPARC64 && LINUX): Define r_pc to r_tpc, and PTRACE_FOOREGS to PTRACE_FOOREGS64 so that more sparc code can be shared between 64-bit and 32-bit. (m_siginfo): Use same definition on SPARC64 as SPARC. (sys_sigreturn): Handle LINUX && SPARC64. * syscall.c: Conditionalize ptrace defines on SPARC and SPARC64. (SPARC64 && LINUX): Define r_pc to r_tpc, and PTRACE_FOOREGS to PTRACE_FOOREGS64 so that more sparc code can be shared between 64-bit and 32-bit. (getscno): Use same static state on SPARC64 as SPARC, and add SPARC64 handling. (get_error): Handle LINUX && SPARC64. (force_result): Likewise. (syscall_enter): Likewise. (trace_syscall): Handle sys_socketcall and sys_ipc on SPARC64 just like SPARC. (getrval2): Handle LINUX && SPARC64. * process.c: Conditionalize ptrace defines on SPARC and SPARC64. (SPARC64 && LINUX): Define r_pc to r_tpc, and PTRACE_FOOREGS to PTRACE_FOOREGS64 so that more sparc code can be shared between 64-bit and 32-bit. (change_syscall): Handle LINUX && SPARC64. (struct_user_offsets): Ifdef out those which do not exist on SPARC64. * net.c (sys_pipe): Handle LINUX && SPARC64. * ioctl.c: Fix initializer typo for nioctlents2, was nioctlents1 by accident.
2004-07-12 11:44:08 +04:00
# undef PTRACE_GETREGS
# define PTRACE_GETREGS PTRACE_GETREGS64
# undef PTRACE_SETREGS
# define PTRACE_SETREGS PTRACE_SETREGS64
#endif
2004-07-07 David S. Miller <davem@nuts.davemloft.net> * linux/sparc/syscallent.h: Sync with reality. * linux/sparc/syscall.h (sys_sendfile64, sys_futex, sys_gettid, sys_sched_setaffinity, sys_sched_getaffinity, sys_setxattr, sys_lsetxattr, sys_fsetxattr, sys_getxattr, sys_lgetxattr, sys_fgetxattr, sys_listxattr, sys_llistxattr, sys_flistxattr, sys_removexattr, sys_lremovexattr, sys_fremovexattr, sys_remap_file_pages, sys_readahead, sys_tgkill, sys_statfs64, sys_fstatfs64, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep, sys_timer_create, sys_timer_settime, sys_timer_gettime): New declarations. * linux/sparc64/dummy2.h, linux/sparc64/syscallent2.h, linux/sparc64/syscall.h, linux/sparc64/errnoent.h, linux/sparc64/errnoent1.h, linux/sparc64/errnoent2.h, linux/sparc64/ioctlent.h, linux/sparc64/ioctlent1.h, linux/sparc64/ioctlent2.h, linux/sparc64/signalent.h, linux/sparc64/signalent.h, linux/sparc64/signalent.h, linux/sparc64/signalent1.h, linux/sparc64/signalent2.h, linux/sparc64/syscall1.h, linux/sparc64/syscallent.h, linux/sparc64/syscallent1.h: New files. * defs.h (LINUXSPARC): Define also when SPARC64. (LINUX && SPARC64): Set SUPPORTED_PERSONALITIES to 3. Ignore SIGTRAP after execve by defining TCB_WAITEXECVE. Define possibly missing __NR_exit_group. Declare getrval2. * configure.ac (sparc64): New architecture case. * config.h.in (SPARC64): New define. * file.c (stat_sparc64): New structure. (printstat_sparc64): New output routine for that. (printstat): Call it, if personality is 2. (printstat64): Likewise. * util.c: Conditionalize ptrace defines on LINUXSPARC not LINUX && SPARC. (SPARC64 && LINUX): Define r_pc to r_tpc, and PTRACE_FOOREGS to PTRACE_FOOREGS64 so that more sparc code can be shared between 64-bit and 32-bit. (_hack_syscall5): Correct trap number when SPARC64. (PTRACE_WRITE{TEXT,DATA}): Add SPARC64 to ifdef guard. (getpc): Handle SPARC64 && LINUX. (printcall): Likewise. (arg fetching/setting): Use same code for SPARC64 LINUX as for SPARC. (setbpt): Handle SPARC64 && LINUX. (clearbpt): Likewise. * signal.c: Conditionalize ptrace defines on SPARC and SPARC64. (SPARC64 && LINUX): Define r_pc to r_tpc, and PTRACE_FOOREGS to PTRACE_FOOREGS64 so that more sparc code can be shared between 64-bit and 32-bit. (m_siginfo): Use same definition on SPARC64 as SPARC. (sys_sigreturn): Handle LINUX && SPARC64. * syscall.c: Conditionalize ptrace defines on SPARC and SPARC64. (SPARC64 && LINUX): Define r_pc to r_tpc, and PTRACE_FOOREGS to PTRACE_FOOREGS64 so that more sparc code can be shared between 64-bit and 32-bit. (getscno): Use same static state on SPARC64 as SPARC, and add SPARC64 handling. (get_error): Handle LINUX && SPARC64. (force_result): Likewise. (syscall_enter): Likewise. (trace_syscall): Handle sys_socketcall and sys_ipc on SPARC64 just like SPARC. (getrval2): Handle LINUX && SPARC64. * process.c: Conditionalize ptrace defines on SPARC and SPARC64. (SPARC64 && LINUX): Define r_pc to r_tpc, and PTRACE_FOOREGS to PTRACE_FOOREGS64 so that more sparc code can be shared between 64-bit and 32-bit. (change_syscall): Handle LINUX && SPARC64. (struct_user_offsets): Ifdef out those which do not exist on SPARC64. * net.c (sys_pipe): Handle LINUX && SPARC64. * ioctl.c: Fix initializer typo for nioctlents2, was nioctlents1 by accident.
2004-07-12 11:44:08 +04:00
1999-02-19 03:21:36 +03:00
#include "syscall.h"
#include "xstring.h"
1999-02-19 03:21:36 +03:00
/* Define these shorthand notations to simplify the syscallent files. */
#include "sysent_shorthand_defs.h"
1999-02-19 03:21:36 +03:00
#define SEN(syscall_name) SEN_ ## syscall_name, SYS_FUNC_NAME(sys_ ## syscall_name)
const struct_sysent sysent0[] = {
1999-02-19 03:21:36 +03:00
#include "syscallent.h"
};
#if SUPPORTED_PERSONALITIES > 1
Add mpers support Add a subsystem for semi-automatical definition of how parsers should work with personality-dependent (mpers) types of tracee's data. Create auxiliary libraries containing mpers syscall parsers and printer functions, one library for each possible nonnative target personality. Currently some parsers do not handle differences in definitions of data types between personalities, namely LP64 and ILP32. When this is the case, long integers, pointers, and all compound types containing long and pointer members may be printed incorrectly, because of differences in sizes, offsets and alignments. Since in most cases these are the only differences in desired behaviour of parsers and printers for different personalities, a correct way would be to compile one source code into multiple parsers, differing only in definitions of mpers types. To get a definition of a given type for nonnative personality a very basic .c file containing a declaration of a variable of this type is being compiled for this personality (using -m32 or -mx32 compiler flag). Information about the type is then being extracted from this binary's DWARF debug info with an awk script and put into a corresponding header file. Resulting headers are being used to compile mpers variations of syscall parsers and printer functions. In addition to syscall parsers, there can occur a need to create mpers printing functions, which then can be called from many places in the code (for example, printsiginfo_at). Such functions (printers) are marked in a special manner. For each possible nonnative target personality a library is being created, containing mpers variations of syscall parsers and printers. Only syscall parsers from files marked in a special manner and specially marked functions from such files are being recompiled and included in these libraries. generate_mpers_am.sh is called by bootstrap to find the files from strace_SOURCES which include MPERS_DEFS. During compilation, these files are being inspected for inclusions of DEF_MPERS_TYPE, and nonnative variations of each included type are being generated by an awk script. Mpers parser names are being modified during inclusions of syscallent headers for nonnative personalities. Pointers to printers are being stored in structs struct_printers, and a master pointer printers is being updated on every set_personality. * README-mpers: New README explaining how to use mpers support. * empty.h: New empty file. * generate_mpers_am.sh: New file. * mpers.awk: Likewise. * mpers.sh: Likewise. * mpers_test.sh: Likewise. * mpers_type.h: Likewise. * Makefile.am (strace_SOURCES): Add empty.h and mpers_type.h. (strace_CPPFLAGS, strace_LDFLAGS, strace_LDADD): Move to the beginning of the file. (strace_LDADD, noinst_LIBRARIES): Add libmpers-%.a. (EXTRA_DIST): Add mpers.awk, mpers.sh, mpers_test.sh. (BUILT_SOURCES, CLEANFILES): Add new generated files: native_printer_decls.h, native_printer_defs.h, printers.h, [HAVE_M32_MPERS] $(mpers_m32_targets), and [HAVE_MX32_MPERS] $(mpers_mx32_targets). (mpers_NAME, mpers_PREFIX, mpers_DEFS, mpers_INCLUDES, mpers_CPPFLAGS, mpers_sh_opts, libmpers_CPPFLAGS, libmpers_m[x]32_a_SOURCES, libmpers_m[x]32_a_CPPFLAGS, mpers_m[x]32_targets): New variables. (mpers-m[x]32.stamp, m[x]32_defs.h, m[x]32_funcs.h, printers.h, %_printer_decls.h, %_printer_defs.h, clean-local, native_printer_decls.h, native_printer_defs.h, $mpers_m[x]32_targets): New targets. * bootstrap: Add generate_mpers_am.sh. * configure.ac: Add AC_PROG_RANLIB. * m4/mpers.m4: Add HAVE_MPERS variable. Add $st_cv_mpers checks. * defs.h: Include mpers_type.h. Include printers.h, native_printer_decls.h, define MPERS_PRINTER_NAME. Redefine SYS_FUNC_NAME. Define MPERS_PRINTER_DECL. [HAVE_M32_MPERS]: define PERSONALITY1_INCLUDE_FUNCS, PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS for X86_64, X32. [HAVE_MX32_MPERS]: define PERSONALITY2_INCLUDE_FUNCS, PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS for X86_64. Add fallback definitions of PERSONALITY1_INCLUDE_FUNCS, PERSONALITY2_INCLUDE_FUNCS, PERSONALITY0_INCLUDE_PRINTERS_DECLS, PERSONALITY0_INCLUDE_PRINTERS_DEFS, PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS, PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS. * syscall.c: Include PERSONALITY1_INCLUDE_FUNCS, PERSONALITY2_INCLUDE_FUNCS, PERSONALITY0_INCLUDE_PRINTERS_DECLS, PERSONALITY0_INCLUDE_PRINTERS_DEFS, PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS, PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS. (printers): New struct. Update it when needed. * .gitignore: Add libmpers-m32.a, libmpers-mx32.a, m32_defs.h, m32_funcs.h, m32_printer_decls.h, m32_printer_defs.h, mpers-m32, mpers-m32.stamp, mpers-mx32, mpers-mx32.stamp, mpers.am, mx32_defs.h, mx32_funcs.h, mx32_printer_decls.h, mx32_printer_defs.h, native_printer_decls.h, native_printer_defs.h, and printers.h.
2015-08-04 01:47:02 +03:00
# include PERSONALITY1_INCLUDE_FUNCS
static const struct_sysent sysent1[] = {
# include "syscallent1.h"
1999-02-19 03:21:36 +03:00
};
#endif
1999-02-19 03:21:36 +03:00
#if SUPPORTED_PERSONALITIES > 2
Add mpers support Add a subsystem for semi-automatical definition of how parsers should work with personality-dependent (mpers) types of tracee's data. Create auxiliary libraries containing mpers syscall parsers and printer functions, one library for each possible nonnative target personality. Currently some parsers do not handle differences in definitions of data types between personalities, namely LP64 and ILP32. When this is the case, long integers, pointers, and all compound types containing long and pointer members may be printed incorrectly, because of differences in sizes, offsets and alignments. Since in most cases these are the only differences in desired behaviour of parsers and printers for different personalities, a correct way would be to compile one source code into multiple parsers, differing only in definitions of mpers types. To get a definition of a given type for nonnative personality a very basic .c file containing a declaration of a variable of this type is being compiled for this personality (using -m32 or -mx32 compiler flag). Information about the type is then being extracted from this binary's DWARF debug info with an awk script and put into a corresponding header file. Resulting headers are being used to compile mpers variations of syscall parsers and printer functions. In addition to syscall parsers, there can occur a need to create mpers printing functions, which then can be called from many places in the code (for example, printsiginfo_at). Such functions (printers) are marked in a special manner. For each possible nonnative target personality a library is being created, containing mpers variations of syscall parsers and printers. Only syscall parsers from files marked in a special manner and specially marked functions from such files are being recompiled and included in these libraries. generate_mpers_am.sh is called by bootstrap to find the files from strace_SOURCES which include MPERS_DEFS. During compilation, these files are being inspected for inclusions of DEF_MPERS_TYPE, and nonnative variations of each included type are being generated by an awk script. Mpers parser names are being modified during inclusions of syscallent headers for nonnative personalities. Pointers to printers are being stored in structs struct_printers, and a master pointer printers is being updated on every set_personality. * README-mpers: New README explaining how to use mpers support. * empty.h: New empty file. * generate_mpers_am.sh: New file. * mpers.awk: Likewise. * mpers.sh: Likewise. * mpers_test.sh: Likewise. * mpers_type.h: Likewise. * Makefile.am (strace_SOURCES): Add empty.h and mpers_type.h. (strace_CPPFLAGS, strace_LDFLAGS, strace_LDADD): Move to the beginning of the file. (strace_LDADD, noinst_LIBRARIES): Add libmpers-%.a. (EXTRA_DIST): Add mpers.awk, mpers.sh, mpers_test.sh. (BUILT_SOURCES, CLEANFILES): Add new generated files: native_printer_decls.h, native_printer_defs.h, printers.h, [HAVE_M32_MPERS] $(mpers_m32_targets), and [HAVE_MX32_MPERS] $(mpers_mx32_targets). (mpers_NAME, mpers_PREFIX, mpers_DEFS, mpers_INCLUDES, mpers_CPPFLAGS, mpers_sh_opts, libmpers_CPPFLAGS, libmpers_m[x]32_a_SOURCES, libmpers_m[x]32_a_CPPFLAGS, mpers_m[x]32_targets): New variables. (mpers-m[x]32.stamp, m[x]32_defs.h, m[x]32_funcs.h, printers.h, %_printer_decls.h, %_printer_defs.h, clean-local, native_printer_decls.h, native_printer_defs.h, $mpers_m[x]32_targets): New targets. * bootstrap: Add generate_mpers_am.sh. * configure.ac: Add AC_PROG_RANLIB. * m4/mpers.m4: Add HAVE_MPERS variable. Add $st_cv_mpers checks. * defs.h: Include mpers_type.h. Include printers.h, native_printer_decls.h, define MPERS_PRINTER_NAME. Redefine SYS_FUNC_NAME. Define MPERS_PRINTER_DECL. [HAVE_M32_MPERS]: define PERSONALITY1_INCLUDE_FUNCS, PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS for X86_64, X32. [HAVE_MX32_MPERS]: define PERSONALITY2_INCLUDE_FUNCS, PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS for X86_64. Add fallback definitions of PERSONALITY1_INCLUDE_FUNCS, PERSONALITY2_INCLUDE_FUNCS, PERSONALITY0_INCLUDE_PRINTERS_DECLS, PERSONALITY0_INCLUDE_PRINTERS_DEFS, PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS, PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS. * syscall.c: Include PERSONALITY1_INCLUDE_FUNCS, PERSONALITY2_INCLUDE_FUNCS, PERSONALITY0_INCLUDE_PRINTERS_DECLS, PERSONALITY0_INCLUDE_PRINTERS_DEFS, PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS, PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS. (printers): New struct. Update it when needed. * .gitignore: Add libmpers-m32.a, libmpers-mx32.a, m32_defs.h, m32_funcs.h, m32_printer_decls.h, m32_printer_defs.h, mpers-m32, mpers-m32.stamp, mpers-mx32, mpers-mx32.stamp, mpers.am, mx32_defs.h, mx32_funcs.h, mx32_printer_decls.h, mx32_printer_defs.h, native_printer_decls.h, native_printer_defs.h, and printers.h.
2015-08-04 01:47:02 +03:00
# include PERSONALITY2_INCLUDE_FUNCS
static const struct_sysent sysent2[] = {
# include "syscallent2.h"
1999-02-19 03:21:36 +03:00
};
#endif
1999-02-19 03:21:36 +03:00
/* Now undef them since short defines cause wicked namespace pollution. */
#include "sysent_shorthand_undefs.h"
1999-02-19 03:21:36 +03:00
const char *const errnoent[] = {
#include "errnoent.h"
};
const char *const signalent[] = {
#include "signalent.h"
};
/*
ioctl: take all 32 bits of ioctl commands into account Historically, only 16 bits (8-bit number and 8-bit type) of 32-bit ioctl commands were used for decoding, which was the source for numerous annoying collisions like this: ioctl(0, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B38400 opost isig icanon echo ...}) = 0 ioctl(0, MGSL_IOCGPARAMS or MMTIMER_GETRES or MTIOCTOP or SNDCTL_MIDI_MPUMODE, 0x7fffd47f7338) = -1 ENOTTY (Inappropriate ioctl for device) The solution is to use all 32 bits for decoding, not just "number" and "type", but also "size" and "direction". As some architectures override defaults that come from asm-generic/ and provide alternative definitions for some ioctl commands, we support per-architecture ioctl definitions and merge them with common definitions at build time. During the merge, we used to keep both generic and architecture-specific definitions, now architecture-specific definitions have precedence over generic ones -- ioctlsort omits definitions from asm-generic/ for those ioctl names that have different definitions in asm/. Additional bits of "direction" are architecture specific -- the number of bits and their values differ between architectures. To reduce architecture differences in the source code, we keep "direction" in symbolic form and compile it in ioctlsort. Additional bits of "size" are also architecture specific -- not only the number of bits differ between architectures, but sizes of many types depend on sizeof(long). To reduce architecture differences in the source code, we keep 32-bit and 64-bit versions of common ioctl definitions, and use the appropriate version for each architecture and personality. To implement this, the tools for generating ioctl definitions from kernel headers have been rewritten, and the source format of ioctl definitions has been extended. The final ioctlent*.h files that are included by syscall.c are now generated from source ioctls_inc*.h and ioctls_arch*.h files at build time with ioctlsort. * ioctl.c (ioctl_lookup): Use all 32 bits of ioctl command code. * ioctlsort.c: Rewritten. * linux/32/ioctls_inc.h: New file. * linux/64/ioctls_inc.h: New file. * linux/aarch64/ioctls_arch0.h: New file. * linux/aarch64/ioctls_arch1.h: New file. * linux/aarch64/ioctls_inc0.h: New file. * linux/aarch64/ioctls_inc1.h: New file. * linux/alpha/ioctls_arch0.h: New file. * linux/alpha/ioctls_inc0.h: New file. * linux/arc/ioctls_arch0.h: New file. * linux/arc/ioctls_inc0.h: New file. * linux/arm/ioctls_arch0.h: New file. * linux/arm/ioctls_inc0.h: New file. * linux/avr32/ioctls_arch0.h: New file. * linux/avr32/ioctls_inc0.h: New file. * linux/bfin/ioctls_arch0.h: New file. * linux/bfin/ioctls_inc0.h: New file. * linux/hppa/ioctls_arch0.h: New file. * linux/hppa/ioctls_inc0.h: New file. * linux/i386/ioctls_arch0.h: New file. * linux/i386/ioctls_inc0.h: New file. * linux/ia64/ioctls_arch0.h: New file. * linux/ia64/ioctls_inc0.h: New file. * linux/m68k/ioctls_arch0.h: New file. * linux/m68k/ioctls_inc0.h: New file. * linux/metag/ioctls_arch0.h: New file. * linux/metag/ioctls_inc0.h: New file. * linux/microblaze/ioctls_arch0.h: New file. * linux/microblaze/ioctls_inc0.h: New file. * linux/mips/ioctls_arch0.h: New file. * linux/mips/ioctls_inc0.h: New file. * linux/or1k/ioctls_arch0.h: New file. * linux/or1k/ioctls_inc0.h: New file. * linux/powerpc/ioctls_arch0.h: New file. * linux/powerpc/ioctls_inc0.h: New file. * linux/powerpc64/ioctls_arch0.h: New file. * linux/powerpc64/ioctls_arch1.h: New file. * linux/powerpc64/ioctls_inc0.h: New file. * linux/powerpc64/ioctls_inc1.h: New file. * linux/s390/ioctls_arch0.h: New file. * linux/s390/ioctls_inc0.h: New file. * linux/s390x/ioctls_arch0.h: New file. * linux/s390x/ioctls_inc0.h: New file. * linux/sh/ioctls_arch0.h: New file. * linux/sh/ioctls_inc0.h: New file. * linux/sh64/ioctls_arch0.h: New file. * linux/sh64/ioctls_inc0.h: New file. * linux/sparc/ioctls_arch0.h: New file. * linux/sparc/ioctls_inc0.h: New file. * linux/sparc64/ioctls_arch0.h: New file. * linux/sparc64/ioctls_arch2.h: New file. * linux/sparc64/ioctls_inc0.h: New file. * linux/sparc64/ioctls_inc2.h: New file. * linux/tile/ioctls_arch0.h: New file. * linux/tile/ioctls_arch1.h: New file. * linux/tile/ioctls_inc0.h: New file. * linux/tile/ioctls_inc1.h: New file. * linux/x32/ioctls_arch0.h: New file. * linux/x32/ioctls_arch1.h: New file. * linux/x32/ioctls_inc0.h: New file. * linux/x32/ioctls_inc1.h: New file. * linux/x86_64/ioctls_arch0.h: New file. * linux/x86_64/ioctls_arch1.h: New file. * linux/x86_64/ioctls_inc0.h: New file. * linux/x86_64/ioctls_inc1.h: New file. * linux/xtensa/ioctls_arch0.h: New file. * linux/xtensa/ioctls_inc0.h: New file. * linux/aarch64/ioctlent.h.in: Remove. * linux/aarch64/ioctlent1.h: Remove. * linux/alpha/ioctlent.h.in: Remove. * linux/arc/ioctlent.h.in: Remove. * linux/arm/ioctlent.h.in: Remove. * linux/avr32/ioctlent.h.in: Remove. * linux/bfin/ioctlent.h.in: Remove. * linux/hppa/ioctlent.h.in: Remove. * linux/i386/ioctlent.h.in: Remove. * linux/ia64/ioctlent.h.in: Remove. * linux/ioctlent.h.in: Remove. * linux/ioctlent.sh: Remove. * linux/m68k/ioctlent.h.in: Remove. * linux/metag/ioctlent.h.in: Remove. * linux/microblaze/ioctlent.h.in: Remove. * linux/mips/ioctlent.h.in: Remove. * linux/mips/ioctlent.sh: Remove. * linux/or1k/ioctlent.h.in: Remove. * linux/powerpc/ioctlent.h.in: Remove. * linux/powerpc64/ioctlent.h: Remove. * linux/powerpc64/ioctlent1.h: Remove. * linux/s390/ioctlent.h.in: Remove. * linux/s390x/ioctlent.h.in: Remove. * linux/sh/ioctlent.h.in: Remove. * linux/sh64/ioctlent.h.in: Remove. * linux/sparc/ioctlent.h.in: Remove. * linux/sparc64/ioctlent.h.in: Remove. * linux/sparc64/ioctlent2.h: Remove. * linux/tile/ioctlent.h.in: Remove. * linux/tile/ioctlent1.h: Remove. * linux/x32/ioctlent.h.in: Remove. * linux/x32/ioctlent1.h: Remove. * linux/x86_64/ioctlent.h.in: Remove. * linux/x86_64/ioctlent1.h: Remove. * linux/xtensa/ioctlent.h.in: Remove. * linux/x86_64/ioctlent2.h: Include ioctlent0.h instead of ioctlent.h. * syscall.c (struct_ioctlent ioctlent0): Likewise. * Makefile.am: Remove all ioctlent-related definitions. Define the list of ioctlent*.h files that have to be generated by presence of $(srcdir)/$(OS)/$(ARCH)/ioctls_inc*.h files. Add rules for ioctlent*.h files generation. (EXTRA_DIST): Update. * maint/ioctls_gen.sh: New file. * maint/ioctls_hex.sh: New file. * maint/ioctls_sym.sh: New file. * maint/print_ioctlent.c: New file. * HACKING-scripts: Update for ioctlent.sh -> ioctls_gen.sh migration. * .gitignore: Add ioctlent[012].h and ioctls_all[012].h. * configure.ac (AC_CHECK_HEADERS): Add linux/hiddev.h and linux/mmtimer.h for tests. * tests/ioctl.c: New file. * tests/ioctl.test: New test. * tests/Makefile.am (check_PROGRAMS): Add ioctl. (TESTS): Add ioctl.test. * tests/.gitignore: Add ioctl.
2015-01-19 20:02:16 +03:00
* `ioctlent[012].h' files are automatically generated by the auxiliary
* program `ioctlsort', such that the list is sorted by the `code' field.
* This has the side-effect of resolving the _IO.. macros into
* plain integers, eliminating the need to include here everything
* in "/usr/include".
*/
const struct_ioctlent ioctlent0[] = {
ioctl: take all 32 bits of ioctl commands into account Historically, only 16 bits (8-bit number and 8-bit type) of 32-bit ioctl commands were used for decoding, which was the source for numerous annoying collisions like this: ioctl(0, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B38400 opost isig icanon echo ...}) = 0 ioctl(0, MGSL_IOCGPARAMS or MMTIMER_GETRES or MTIOCTOP or SNDCTL_MIDI_MPUMODE, 0x7fffd47f7338) = -1 ENOTTY (Inappropriate ioctl for device) The solution is to use all 32 bits for decoding, not just "number" and "type", but also "size" and "direction". As some architectures override defaults that come from asm-generic/ and provide alternative definitions for some ioctl commands, we support per-architecture ioctl definitions and merge them with common definitions at build time. During the merge, we used to keep both generic and architecture-specific definitions, now architecture-specific definitions have precedence over generic ones -- ioctlsort omits definitions from asm-generic/ for those ioctl names that have different definitions in asm/. Additional bits of "direction" are architecture specific -- the number of bits and their values differ between architectures. To reduce architecture differences in the source code, we keep "direction" in symbolic form and compile it in ioctlsort. Additional bits of "size" are also architecture specific -- not only the number of bits differ between architectures, but sizes of many types depend on sizeof(long). To reduce architecture differences in the source code, we keep 32-bit and 64-bit versions of common ioctl definitions, and use the appropriate version for each architecture and personality. To implement this, the tools for generating ioctl definitions from kernel headers have been rewritten, and the source format of ioctl definitions has been extended. The final ioctlent*.h files that are included by syscall.c are now generated from source ioctls_inc*.h and ioctls_arch*.h files at build time with ioctlsort. * ioctl.c (ioctl_lookup): Use all 32 bits of ioctl command code. * ioctlsort.c: Rewritten. * linux/32/ioctls_inc.h: New file. * linux/64/ioctls_inc.h: New file. * linux/aarch64/ioctls_arch0.h: New file. * linux/aarch64/ioctls_arch1.h: New file. * linux/aarch64/ioctls_inc0.h: New file. * linux/aarch64/ioctls_inc1.h: New file. * linux/alpha/ioctls_arch0.h: New file. * linux/alpha/ioctls_inc0.h: New file. * linux/arc/ioctls_arch0.h: New file. * linux/arc/ioctls_inc0.h: New file. * linux/arm/ioctls_arch0.h: New file. * linux/arm/ioctls_inc0.h: New file. * linux/avr32/ioctls_arch0.h: New file. * linux/avr32/ioctls_inc0.h: New file. * linux/bfin/ioctls_arch0.h: New file. * linux/bfin/ioctls_inc0.h: New file. * linux/hppa/ioctls_arch0.h: New file. * linux/hppa/ioctls_inc0.h: New file. * linux/i386/ioctls_arch0.h: New file. * linux/i386/ioctls_inc0.h: New file. * linux/ia64/ioctls_arch0.h: New file. * linux/ia64/ioctls_inc0.h: New file. * linux/m68k/ioctls_arch0.h: New file. * linux/m68k/ioctls_inc0.h: New file. * linux/metag/ioctls_arch0.h: New file. * linux/metag/ioctls_inc0.h: New file. * linux/microblaze/ioctls_arch0.h: New file. * linux/microblaze/ioctls_inc0.h: New file. * linux/mips/ioctls_arch0.h: New file. * linux/mips/ioctls_inc0.h: New file. * linux/or1k/ioctls_arch0.h: New file. * linux/or1k/ioctls_inc0.h: New file. * linux/powerpc/ioctls_arch0.h: New file. * linux/powerpc/ioctls_inc0.h: New file. * linux/powerpc64/ioctls_arch0.h: New file. * linux/powerpc64/ioctls_arch1.h: New file. * linux/powerpc64/ioctls_inc0.h: New file. * linux/powerpc64/ioctls_inc1.h: New file. * linux/s390/ioctls_arch0.h: New file. * linux/s390/ioctls_inc0.h: New file. * linux/s390x/ioctls_arch0.h: New file. * linux/s390x/ioctls_inc0.h: New file. * linux/sh/ioctls_arch0.h: New file. * linux/sh/ioctls_inc0.h: New file. * linux/sh64/ioctls_arch0.h: New file. * linux/sh64/ioctls_inc0.h: New file. * linux/sparc/ioctls_arch0.h: New file. * linux/sparc/ioctls_inc0.h: New file. * linux/sparc64/ioctls_arch0.h: New file. * linux/sparc64/ioctls_arch2.h: New file. * linux/sparc64/ioctls_inc0.h: New file. * linux/sparc64/ioctls_inc2.h: New file. * linux/tile/ioctls_arch0.h: New file. * linux/tile/ioctls_arch1.h: New file. * linux/tile/ioctls_inc0.h: New file. * linux/tile/ioctls_inc1.h: New file. * linux/x32/ioctls_arch0.h: New file. * linux/x32/ioctls_arch1.h: New file. * linux/x32/ioctls_inc0.h: New file. * linux/x32/ioctls_inc1.h: New file. * linux/x86_64/ioctls_arch0.h: New file. * linux/x86_64/ioctls_arch1.h: New file. * linux/x86_64/ioctls_inc0.h: New file. * linux/x86_64/ioctls_inc1.h: New file. * linux/xtensa/ioctls_arch0.h: New file. * linux/xtensa/ioctls_inc0.h: New file. * linux/aarch64/ioctlent.h.in: Remove. * linux/aarch64/ioctlent1.h: Remove. * linux/alpha/ioctlent.h.in: Remove. * linux/arc/ioctlent.h.in: Remove. * linux/arm/ioctlent.h.in: Remove. * linux/avr32/ioctlent.h.in: Remove. * linux/bfin/ioctlent.h.in: Remove. * linux/hppa/ioctlent.h.in: Remove. * linux/i386/ioctlent.h.in: Remove. * linux/ia64/ioctlent.h.in: Remove. * linux/ioctlent.h.in: Remove. * linux/ioctlent.sh: Remove. * linux/m68k/ioctlent.h.in: Remove. * linux/metag/ioctlent.h.in: Remove. * linux/microblaze/ioctlent.h.in: Remove. * linux/mips/ioctlent.h.in: Remove. * linux/mips/ioctlent.sh: Remove. * linux/or1k/ioctlent.h.in: Remove. * linux/powerpc/ioctlent.h.in: Remove. * linux/powerpc64/ioctlent.h: Remove. * linux/powerpc64/ioctlent1.h: Remove. * linux/s390/ioctlent.h.in: Remove. * linux/s390x/ioctlent.h.in: Remove. * linux/sh/ioctlent.h.in: Remove. * linux/sh64/ioctlent.h.in: Remove. * linux/sparc/ioctlent.h.in: Remove. * linux/sparc64/ioctlent.h.in: Remove. * linux/sparc64/ioctlent2.h: Remove. * linux/tile/ioctlent.h.in: Remove. * linux/tile/ioctlent1.h: Remove. * linux/x32/ioctlent.h.in: Remove. * linux/x32/ioctlent1.h: Remove. * linux/x86_64/ioctlent.h.in: Remove. * linux/x86_64/ioctlent1.h: Remove. * linux/xtensa/ioctlent.h.in: Remove. * linux/x86_64/ioctlent2.h: Include ioctlent0.h instead of ioctlent.h. * syscall.c (struct_ioctlent ioctlent0): Likewise. * Makefile.am: Remove all ioctlent-related definitions. Define the list of ioctlent*.h files that have to be generated by presence of $(srcdir)/$(OS)/$(ARCH)/ioctls_inc*.h files. Add rules for ioctlent*.h files generation. (EXTRA_DIST): Update. * maint/ioctls_gen.sh: New file. * maint/ioctls_hex.sh: New file. * maint/ioctls_sym.sh: New file. * maint/print_ioctlent.c: New file. * HACKING-scripts: Update for ioctlent.sh -> ioctls_gen.sh migration. * .gitignore: Add ioctlent[012].h and ioctls_all[012].h. * configure.ac (AC_CHECK_HEADERS): Add linux/hiddev.h and linux/mmtimer.h for tests. * tests/ioctl.c: New file. * tests/ioctl.test: New test. * tests/Makefile.am (check_PROGRAMS): Add ioctl. (TESTS): Add ioctl.test. * tests/.gitignore: Add ioctl.
2015-01-19 20:02:16 +03:00
#include "ioctlent0.h"
};
1999-02-19 03:21:36 +03:00
#if SUPPORTED_PERSONALITIES > 1
static const struct_ioctlent ioctlent1[] = {
# include "ioctlent1.h"
};
Add mpers support Add a subsystem for semi-automatical definition of how parsers should work with personality-dependent (mpers) types of tracee's data. Create auxiliary libraries containing mpers syscall parsers and printer functions, one library for each possible nonnative target personality. Currently some parsers do not handle differences in definitions of data types between personalities, namely LP64 and ILP32. When this is the case, long integers, pointers, and all compound types containing long and pointer members may be printed incorrectly, because of differences in sizes, offsets and alignments. Since in most cases these are the only differences in desired behaviour of parsers and printers for different personalities, a correct way would be to compile one source code into multiple parsers, differing only in definitions of mpers types. To get a definition of a given type for nonnative personality a very basic .c file containing a declaration of a variable of this type is being compiled for this personality (using -m32 or -mx32 compiler flag). Information about the type is then being extracted from this binary's DWARF debug info with an awk script and put into a corresponding header file. Resulting headers are being used to compile mpers variations of syscall parsers and printer functions. In addition to syscall parsers, there can occur a need to create mpers printing functions, which then can be called from many places in the code (for example, printsiginfo_at). Such functions (printers) are marked in a special manner. For each possible nonnative target personality a library is being created, containing mpers variations of syscall parsers and printers. Only syscall parsers from files marked in a special manner and specially marked functions from such files are being recompiled and included in these libraries. generate_mpers_am.sh is called by bootstrap to find the files from strace_SOURCES which include MPERS_DEFS. During compilation, these files are being inspected for inclusions of DEF_MPERS_TYPE, and nonnative variations of each included type are being generated by an awk script. Mpers parser names are being modified during inclusions of syscallent headers for nonnative personalities. Pointers to printers are being stored in structs struct_printers, and a master pointer printers is being updated on every set_personality. * README-mpers: New README explaining how to use mpers support. * empty.h: New empty file. * generate_mpers_am.sh: New file. * mpers.awk: Likewise. * mpers.sh: Likewise. * mpers_test.sh: Likewise. * mpers_type.h: Likewise. * Makefile.am (strace_SOURCES): Add empty.h and mpers_type.h. (strace_CPPFLAGS, strace_LDFLAGS, strace_LDADD): Move to the beginning of the file. (strace_LDADD, noinst_LIBRARIES): Add libmpers-%.a. (EXTRA_DIST): Add mpers.awk, mpers.sh, mpers_test.sh. (BUILT_SOURCES, CLEANFILES): Add new generated files: native_printer_decls.h, native_printer_defs.h, printers.h, [HAVE_M32_MPERS] $(mpers_m32_targets), and [HAVE_MX32_MPERS] $(mpers_mx32_targets). (mpers_NAME, mpers_PREFIX, mpers_DEFS, mpers_INCLUDES, mpers_CPPFLAGS, mpers_sh_opts, libmpers_CPPFLAGS, libmpers_m[x]32_a_SOURCES, libmpers_m[x]32_a_CPPFLAGS, mpers_m[x]32_targets): New variables. (mpers-m[x]32.stamp, m[x]32_defs.h, m[x]32_funcs.h, printers.h, %_printer_decls.h, %_printer_defs.h, clean-local, native_printer_decls.h, native_printer_defs.h, $mpers_m[x]32_targets): New targets. * bootstrap: Add generate_mpers_am.sh. * configure.ac: Add AC_PROG_RANLIB. * m4/mpers.m4: Add HAVE_MPERS variable. Add $st_cv_mpers checks. * defs.h: Include mpers_type.h. Include printers.h, native_printer_decls.h, define MPERS_PRINTER_NAME. Redefine SYS_FUNC_NAME. Define MPERS_PRINTER_DECL. [HAVE_M32_MPERS]: define PERSONALITY1_INCLUDE_FUNCS, PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS for X86_64, X32. [HAVE_MX32_MPERS]: define PERSONALITY2_INCLUDE_FUNCS, PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS for X86_64. Add fallback definitions of PERSONALITY1_INCLUDE_FUNCS, PERSONALITY2_INCLUDE_FUNCS, PERSONALITY0_INCLUDE_PRINTERS_DECLS, PERSONALITY0_INCLUDE_PRINTERS_DEFS, PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS, PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS. * syscall.c: Include PERSONALITY1_INCLUDE_FUNCS, PERSONALITY2_INCLUDE_FUNCS, PERSONALITY0_INCLUDE_PRINTERS_DECLS, PERSONALITY0_INCLUDE_PRINTERS_DEFS, PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS, PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS. (printers): New struct. Update it when needed. * .gitignore: Add libmpers-m32.a, libmpers-mx32.a, m32_defs.h, m32_funcs.h, m32_printer_decls.h, m32_printer_defs.h, mpers-m32, mpers-m32.stamp, mpers-mx32, mpers-mx32.stamp, mpers.am, mx32_defs.h, mx32_funcs.h, mx32_printer_decls.h, mx32_printer_defs.h, native_printer_decls.h, native_printer_defs.h, and printers.h.
2015-08-04 01:47:02 +03:00
# include PERSONALITY0_INCLUDE_PRINTERS_DECLS
static const struct_printers printers0 = {
# include PERSONALITY0_INCLUDE_PRINTERS_DEFS
};
# include PERSONALITY1_INCLUDE_PRINTERS_DECLS
static const struct_printers printers1 = {
# include PERSONALITY1_INCLUDE_PRINTERS_DEFS
};
#endif
1999-02-19 03:21:36 +03:00
#if SUPPORTED_PERSONALITIES > 2
static const struct_ioctlent ioctlent2[] = {
# include "ioctlent2.h"
};
Add mpers support Add a subsystem for semi-automatical definition of how parsers should work with personality-dependent (mpers) types of tracee's data. Create auxiliary libraries containing mpers syscall parsers and printer functions, one library for each possible nonnative target personality. Currently some parsers do not handle differences in definitions of data types between personalities, namely LP64 and ILP32. When this is the case, long integers, pointers, and all compound types containing long and pointer members may be printed incorrectly, because of differences in sizes, offsets and alignments. Since in most cases these are the only differences in desired behaviour of parsers and printers for different personalities, a correct way would be to compile one source code into multiple parsers, differing only in definitions of mpers types. To get a definition of a given type for nonnative personality a very basic .c file containing a declaration of a variable of this type is being compiled for this personality (using -m32 or -mx32 compiler flag). Information about the type is then being extracted from this binary's DWARF debug info with an awk script and put into a corresponding header file. Resulting headers are being used to compile mpers variations of syscall parsers and printer functions. In addition to syscall parsers, there can occur a need to create mpers printing functions, which then can be called from many places in the code (for example, printsiginfo_at). Such functions (printers) are marked in a special manner. For each possible nonnative target personality a library is being created, containing mpers variations of syscall parsers and printers. Only syscall parsers from files marked in a special manner and specially marked functions from such files are being recompiled and included in these libraries. generate_mpers_am.sh is called by bootstrap to find the files from strace_SOURCES which include MPERS_DEFS. During compilation, these files are being inspected for inclusions of DEF_MPERS_TYPE, and nonnative variations of each included type are being generated by an awk script. Mpers parser names are being modified during inclusions of syscallent headers for nonnative personalities. Pointers to printers are being stored in structs struct_printers, and a master pointer printers is being updated on every set_personality. * README-mpers: New README explaining how to use mpers support. * empty.h: New empty file. * generate_mpers_am.sh: New file. * mpers.awk: Likewise. * mpers.sh: Likewise. * mpers_test.sh: Likewise. * mpers_type.h: Likewise. * Makefile.am (strace_SOURCES): Add empty.h and mpers_type.h. (strace_CPPFLAGS, strace_LDFLAGS, strace_LDADD): Move to the beginning of the file. (strace_LDADD, noinst_LIBRARIES): Add libmpers-%.a. (EXTRA_DIST): Add mpers.awk, mpers.sh, mpers_test.sh. (BUILT_SOURCES, CLEANFILES): Add new generated files: native_printer_decls.h, native_printer_defs.h, printers.h, [HAVE_M32_MPERS] $(mpers_m32_targets), and [HAVE_MX32_MPERS] $(mpers_mx32_targets). (mpers_NAME, mpers_PREFIX, mpers_DEFS, mpers_INCLUDES, mpers_CPPFLAGS, mpers_sh_opts, libmpers_CPPFLAGS, libmpers_m[x]32_a_SOURCES, libmpers_m[x]32_a_CPPFLAGS, mpers_m[x]32_targets): New variables. (mpers-m[x]32.stamp, m[x]32_defs.h, m[x]32_funcs.h, printers.h, %_printer_decls.h, %_printer_defs.h, clean-local, native_printer_decls.h, native_printer_defs.h, $mpers_m[x]32_targets): New targets. * bootstrap: Add generate_mpers_am.sh. * configure.ac: Add AC_PROG_RANLIB. * m4/mpers.m4: Add HAVE_MPERS variable. Add $st_cv_mpers checks. * defs.h: Include mpers_type.h. Include printers.h, native_printer_decls.h, define MPERS_PRINTER_NAME. Redefine SYS_FUNC_NAME. Define MPERS_PRINTER_DECL. [HAVE_M32_MPERS]: define PERSONALITY1_INCLUDE_FUNCS, PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS for X86_64, X32. [HAVE_MX32_MPERS]: define PERSONALITY2_INCLUDE_FUNCS, PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS for X86_64. Add fallback definitions of PERSONALITY1_INCLUDE_FUNCS, PERSONALITY2_INCLUDE_FUNCS, PERSONALITY0_INCLUDE_PRINTERS_DECLS, PERSONALITY0_INCLUDE_PRINTERS_DEFS, PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS, PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS. * syscall.c: Include PERSONALITY1_INCLUDE_FUNCS, PERSONALITY2_INCLUDE_FUNCS, PERSONALITY0_INCLUDE_PRINTERS_DECLS, PERSONALITY0_INCLUDE_PRINTERS_DEFS, PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS, PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS. (printers): New struct. Update it when needed. * .gitignore: Add libmpers-m32.a, libmpers-mx32.a, m32_defs.h, m32_funcs.h, m32_printer_decls.h, m32_printer_defs.h, mpers-m32, mpers-m32.stamp, mpers-mx32, mpers-mx32.stamp, mpers.am, mx32_defs.h, mx32_funcs.h, mx32_printer_decls.h, mx32_printer_defs.h, native_printer_decls.h, native_printer_defs.h, and printers.h.
2015-08-04 01:47:02 +03:00
# include PERSONALITY2_INCLUDE_PRINTERS_DECLS
static const struct_printers printers2 = {
# include PERSONALITY2_INCLUDE_PRINTERS_DEFS
};
#endif
enum {
nsyscalls0 = ARRAY_SIZE(sysent0)
#if SUPPORTED_PERSONALITIES > 1
, nsyscalls1 = ARRAY_SIZE(sysent1)
# if SUPPORTED_PERSONALITIES > 2
, nsyscalls2 = ARRAY_SIZE(sysent2)
# endif
#endif
};
enum {
nioctlents0 = ARRAY_SIZE(ioctlent0)
#if SUPPORTED_PERSONALITIES > 1
, nioctlents1 = ARRAY_SIZE(ioctlent1)
# if SUPPORTED_PERSONALITIES > 2
, nioctlents2 = ARRAY_SIZE(ioctlent2)
# endif
#endif
};
#if SUPPORTED_PERSONALITIES > 1
const struct_sysent *sysent = sysent0;
const struct_ioctlent *ioctlent = ioctlent0;
Add mpers support Add a subsystem for semi-automatical definition of how parsers should work with personality-dependent (mpers) types of tracee's data. Create auxiliary libraries containing mpers syscall parsers and printer functions, one library for each possible nonnative target personality. Currently some parsers do not handle differences in definitions of data types between personalities, namely LP64 and ILP32. When this is the case, long integers, pointers, and all compound types containing long and pointer members may be printed incorrectly, because of differences in sizes, offsets and alignments. Since in most cases these are the only differences in desired behaviour of parsers and printers for different personalities, a correct way would be to compile one source code into multiple parsers, differing only in definitions of mpers types. To get a definition of a given type for nonnative personality a very basic .c file containing a declaration of a variable of this type is being compiled for this personality (using -m32 or -mx32 compiler flag). Information about the type is then being extracted from this binary's DWARF debug info with an awk script and put into a corresponding header file. Resulting headers are being used to compile mpers variations of syscall parsers and printer functions. In addition to syscall parsers, there can occur a need to create mpers printing functions, which then can be called from many places in the code (for example, printsiginfo_at). Such functions (printers) are marked in a special manner. For each possible nonnative target personality a library is being created, containing mpers variations of syscall parsers and printers. Only syscall parsers from files marked in a special manner and specially marked functions from such files are being recompiled and included in these libraries. generate_mpers_am.sh is called by bootstrap to find the files from strace_SOURCES which include MPERS_DEFS. During compilation, these files are being inspected for inclusions of DEF_MPERS_TYPE, and nonnative variations of each included type are being generated by an awk script. Mpers parser names are being modified during inclusions of syscallent headers for nonnative personalities. Pointers to printers are being stored in structs struct_printers, and a master pointer printers is being updated on every set_personality. * README-mpers: New README explaining how to use mpers support. * empty.h: New empty file. * generate_mpers_am.sh: New file. * mpers.awk: Likewise. * mpers.sh: Likewise. * mpers_test.sh: Likewise. * mpers_type.h: Likewise. * Makefile.am (strace_SOURCES): Add empty.h and mpers_type.h. (strace_CPPFLAGS, strace_LDFLAGS, strace_LDADD): Move to the beginning of the file. (strace_LDADD, noinst_LIBRARIES): Add libmpers-%.a. (EXTRA_DIST): Add mpers.awk, mpers.sh, mpers_test.sh. (BUILT_SOURCES, CLEANFILES): Add new generated files: native_printer_decls.h, native_printer_defs.h, printers.h, [HAVE_M32_MPERS] $(mpers_m32_targets), and [HAVE_MX32_MPERS] $(mpers_mx32_targets). (mpers_NAME, mpers_PREFIX, mpers_DEFS, mpers_INCLUDES, mpers_CPPFLAGS, mpers_sh_opts, libmpers_CPPFLAGS, libmpers_m[x]32_a_SOURCES, libmpers_m[x]32_a_CPPFLAGS, mpers_m[x]32_targets): New variables. (mpers-m[x]32.stamp, m[x]32_defs.h, m[x]32_funcs.h, printers.h, %_printer_decls.h, %_printer_defs.h, clean-local, native_printer_decls.h, native_printer_defs.h, $mpers_m[x]32_targets): New targets. * bootstrap: Add generate_mpers_am.sh. * configure.ac: Add AC_PROG_RANLIB. * m4/mpers.m4: Add HAVE_MPERS variable. Add $st_cv_mpers checks. * defs.h: Include mpers_type.h. Include printers.h, native_printer_decls.h, define MPERS_PRINTER_NAME. Redefine SYS_FUNC_NAME. Define MPERS_PRINTER_DECL. [HAVE_M32_MPERS]: define PERSONALITY1_INCLUDE_FUNCS, PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS for X86_64, X32. [HAVE_MX32_MPERS]: define PERSONALITY2_INCLUDE_FUNCS, PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS for X86_64. Add fallback definitions of PERSONALITY1_INCLUDE_FUNCS, PERSONALITY2_INCLUDE_FUNCS, PERSONALITY0_INCLUDE_PRINTERS_DECLS, PERSONALITY0_INCLUDE_PRINTERS_DEFS, PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS, PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS. * syscall.c: Include PERSONALITY1_INCLUDE_FUNCS, PERSONALITY2_INCLUDE_FUNCS, PERSONALITY0_INCLUDE_PRINTERS_DECLS, PERSONALITY0_INCLUDE_PRINTERS_DEFS, PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS, PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS. (printers): New struct. Update it when needed. * .gitignore: Add libmpers-m32.a, libmpers-mx32.a, m32_defs.h, m32_funcs.h, m32_printer_decls.h, m32_printer_defs.h, mpers-m32, mpers-m32.stamp, mpers-mx32, mpers-mx32.stamp, mpers.am, mx32_defs.h, mx32_funcs.h, mx32_printer_decls.h, mx32_printer_defs.h, native_printer_decls.h, native_printer_defs.h, and printers.h.
2015-08-04 01:47:02 +03:00
const struct_printers *printers = &printers0;
#endif
Add mpers support Add a subsystem for semi-automatical definition of how parsers should work with personality-dependent (mpers) types of tracee's data. Create auxiliary libraries containing mpers syscall parsers and printer functions, one library for each possible nonnative target personality. Currently some parsers do not handle differences in definitions of data types between personalities, namely LP64 and ILP32. When this is the case, long integers, pointers, and all compound types containing long and pointer members may be printed incorrectly, because of differences in sizes, offsets and alignments. Since in most cases these are the only differences in desired behaviour of parsers and printers for different personalities, a correct way would be to compile one source code into multiple parsers, differing only in definitions of mpers types. To get a definition of a given type for nonnative personality a very basic .c file containing a declaration of a variable of this type is being compiled for this personality (using -m32 or -mx32 compiler flag). Information about the type is then being extracted from this binary's DWARF debug info with an awk script and put into a corresponding header file. Resulting headers are being used to compile mpers variations of syscall parsers and printer functions. In addition to syscall parsers, there can occur a need to create mpers printing functions, which then can be called from many places in the code (for example, printsiginfo_at). Such functions (printers) are marked in a special manner. For each possible nonnative target personality a library is being created, containing mpers variations of syscall parsers and printers. Only syscall parsers from files marked in a special manner and specially marked functions from such files are being recompiled and included in these libraries. generate_mpers_am.sh is called by bootstrap to find the files from strace_SOURCES which include MPERS_DEFS. During compilation, these files are being inspected for inclusions of DEF_MPERS_TYPE, and nonnative variations of each included type are being generated by an awk script. Mpers parser names are being modified during inclusions of syscallent headers for nonnative personalities. Pointers to printers are being stored in structs struct_printers, and a master pointer printers is being updated on every set_personality. * README-mpers: New README explaining how to use mpers support. * empty.h: New empty file. * generate_mpers_am.sh: New file. * mpers.awk: Likewise. * mpers.sh: Likewise. * mpers_test.sh: Likewise. * mpers_type.h: Likewise. * Makefile.am (strace_SOURCES): Add empty.h and mpers_type.h. (strace_CPPFLAGS, strace_LDFLAGS, strace_LDADD): Move to the beginning of the file. (strace_LDADD, noinst_LIBRARIES): Add libmpers-%.a. (EXTRA_DIST): Add mpers.awk, mpers.sh, mpers_test.sh. (BUILT_SOURCES, CLEANFILES): Add new generated files: native_printer_decls.h, native_printer_defs.h, printers.h, [HAVE_M32_MPERS] $(mpers_m32_targets), and [HAVE_MX32_MPERS] $(mpers_mx32_targets). (mpers_NAME, mpers_PREFIX, mpers_DEFS, mpers_INCLUDES, mpers_CPPFLAGS, mpers_sh_opts, libmpers_CPPFLAGS, libmpers_m[x]32_a_SOURCES, libmpers_m[x]32_a_CPPFLAGS, mpers_m[x]32_targets): New variables. (mpers-m[x]32.stamp, m[x]32_defs.h, m[x]32_funcs.h, printers.h, %_printer_decls.h, %_printer_defs.h, clean-local, native_printer_decls.h, native_printer_defs.h, $mpers_m[x]32_targets): New targets. * bootstrap: Add generate_mpers_am.sh. * configure.ac: Add AC_PROG_RANLIB. * m4/mpers.m4: Add HAVE_MPERS variable. Add $st_cv_mpers checks. * defs.h: Include mpers_type.h. Include printers.h, native_printer_decls.h, define MPERS_PRINTER_NAME. Redefine SYS_FUNC_NAME. Define MPERS_PRINTER_DECL. [HAVE_M32_MPERS]: define PERSONALITY1_INCLUDE_FUNCS, PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS for X86_64, X32. [HAVE_MX32_MPERS]: define PERSONALITY2_INCLUDE_FUNCS, PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS for X86_64. Add fallback definitions of PERSONALITY1_INCLUDE_FUNCS, PERSONALITY2_INCLUDE_FUNCS, PERSONALITY0_INCLUDE_PRINTERS_DECLS, PERSONALITY0_INCLUDE_PRINTERS_DEFS, PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS, PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS. * syscall.c: Include PERSONALITY1_INCLUDE_FUNCS, PERSONALITY2_INCLUDE_FUNCS, PERSONALITY0_INCLUDE_PRINTERS_DECLS, PERSONALITY0_INCLUDE_PRINTERS_DEFS, PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS, PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS. (printers): New struct. Update it when needed. * .gitignore: Add libmpers-m32.a, libmpers-mx32.a, m32_defs.h, m32_funcs.h, m32_printer_decls.h, m32_printer_defs.h, mpers-m32, mpers-m32.stamp, mpers-mx32, mpers-mx32.stamp, mpers.am, mx32_defs.h, mx32_funcs.h, mx32_printer_decls.h, mx32_printer_defs.h, native_printer_decls.h, native_printer_defs.h, and printers.h.
2015-08-04 01:47:02 +03:00
const unsigned int nerrnos = ARRAY_SIZE(errnoent);
const unsigned int nsignals = ARRAY_SIZE(signalent);
unsigned nsyscalls = nsyscalls0;
unsigned nioctlents = nioctlents0;
Rewrite remaining qual_* parsers using bit sets * defs.h (struct fault_opts): Replace forward declaration with a definition. (qualbits_t, qualify_read, qualify_write, qualify_signals): Remove. (qual_flags): New function prototype. (nsyscall_vec, sysent_vec, fault_vec): New variable prototypes. * qualify.c (abbrev_set, fault_set, raw_set, trace_set, verbose_set): New variables. (qualify_read, qualify_write, qualify_signals): Add static qualifier. (find_errno_by_name, lookup_class, parse_fault_expression, parse_fault_token, qual_flags, qualify, qualify_abbrev, qualify_fault, qualify_raw, qualify_syscall, qualify_syscall_class, qualify_syscall_name, qualify_syscall_number, qualify_syscall_tokens, qualify_trace, qualify_verbose, strip_prefix): New functions. * syscall.c (nsyscall_vec, nsysent_vec): Remove static qualifier. (MAX_NSYSCALLS1, MAX_NSYSCALLS2, MAX_NSYSCALLS, qual_vec, qual_flags, qual_fault, qual_syscall, qual_options, fault_opts, qualify_one, qualify_scno, lookup_class, qualify_syscall_class, qualify_syscall_name, qual_syscall_ex, qual_syscall, strip_prefix, find_errno_by_name, parse_fault_token, parse_fault_expression, qual_fault, qualify): Remove. (decode_socket_subcall, decode_ipc_subcall, decode_mips_subcall, get_scno): Update use of qual_flags. (inject_syscall_fault_entering): Update per-personality allocation of tcp->fault_vec. * tests/fault_injection-exit_group.test: Check parsing of inversed fault sets. * tests/fault_injection.test: Check parsing of -efault=none. * tests/options-syntax.test: Check parsing of invalid syscall numbers.
2016-12-04 17:39:48 +03:00
const unsigned int nsyscall_vec[SUPPORTED_PERSONALITIES] = {
nsyscalls0,
#if SUPPORTED_PERSONALITIES > 1
nsyscalls1,
#endif
#if SUPPORTED_PERSONALITIES > 2
nsyscalls2,
#endif
};
Rewrite remaining qual_* parsers using bit sets * defs.h (struct fault_opts): Replace forward declaration with a definition. (qualbits_t, qualify_read, qualify_write, qualify_signals): Remove. (qual_flags): New function prototype. (nsyscall_vec, sysent_vec, fault_vec): New variable prototypes. * qualify.c (abbrev_set, fault_set, raw_set, trace_set, verbose_set): New variables. (qualify_read, qualify_write, qualify_signals): Add static qualifier. (find_errno_by_name, lookup_class, parse_fault_expression, parse_fault_token, qual_flags, qualify, qualify_abbrev, qualify_fault, qualify_raw, qualify_syscall, qualify_syscall_class, qualify_syscall_name, qualify_syscall_number, qualify_syscall_tokens, qualify_trace, qualify_verbose, strip_prefix): New functions. * syscall.c (nsyscall_vec, nsysent_vec): Remove static qualifier. (MAX_NSYSCALLS1, MAX_NSYSCALLS2, MAX_NSYSCALLS, qual_vec, qual_flags, qual_fault, qual_syscall, qual_options, fault_opts, qualify_one, qualify_scno, lookup_class, qualify_syscall_class, qualify_syscall_name, qual_syscall_ex, qual_syscall, strip_prefix, find_errno_by_name, parse_fault_token, parse_fault_expression, qual_fault, qualify): Remove. (decode_socket_subcall, decode_ipc_subcall, decode_mips_subcall, get_scno): Update use of qual_flags. (inject_syscall_fault_entering): Update per-personality allocation of tcp->fault_vec. * tests/fault_injection-exit_group.test: Check parsing of inversed fault sets. * tests/fault_injection.test: Check parsing of -efault=none. * tests/options-syntax.test: Check parsing of invalid syscall numbers.
2016-12-04 17:39:48 +03:00
const struct_sysent *const sysent_vec[SUPPORTED_PERSONALITIES] = {
sysent0,
#if SUPPORTED_PERSONALITIES > 1
sysent1,
#endif
#if SUPPORTED_PERSONALITIES > 2
sysent2,
#endif
};
const char *const personality_names[] =
#if defined X86_64
{"64 bit", "32 bit", "x32"}
#elif defined X32
{"x32", "32 bit"}
#elif SUPPORTED_PERSONALITIES == 2
{"64 bit", "32 bit"}
#else
{STRINGIFY_VAL(__WORDSIZE) " bit"}
#endif
;
const char *const personality_designators[] =
#if defined X86_64
{ "64", "32", "x32" }
#elif defined X32
{ "x32", "32" }
#elif SUPPORTED_PERSONALITIES == 2
{ "64", "32" }
#else
{ STRINGIFY_VAL(__WORDSIZE) }
#endif
;
#if SUPPORTED_PERSONALITIES > 1
unsigned current_personality;
1999-02-19 03:21:36 +03:00
# ifndef current_wordsize
unsigned current_wordsize = PERSONALITY0_WORDSIZE;
static const int personality_wordsize[SUPPORTED_PERSONALITIES] = {
PERSONALITY0_WORDSIZE,
PERSONALITY1_WORDSIZE,
# if SUPPORTED_PERSONALITIES > 2
PERSONALITY2_WORDSIZE,
# endif
};
# endif
# ifndef current_klongsize
unsigned current_klongsize = PERSONALITY0_KLONGSIZE;
static const int personality_klongsize[SUPPORTED_PERSONALITIES] = {
PERSONALITY0_KLONGSIZE,
PERSONALITY1_KLONGSIZE,
# if SUPPORTED_PERSONALITIES > 2
PERSONALITY2_KLONGSIZE,
# endif
};
# endif
void
set_personality(unsigned int personality)
1999-02-19 03:21:36 +03:00
{
if (personality == current_personality)
return;
if (personality >= SUPPORTED_PERSONALITIES)
error_msg_and_die("Requested switch to unsupported personality "
"%u", personality);
nsyscalls = nsyscall_vec[personality];
sysent = sysent_vec[personality];
1999-02-19 03:21:36 +03:00
switch (personality) {
case 0:
ioctlent = ioctlent0;
nioctlents = nioctlents0;
Add mpers support Add a subsystem for semi-automatical definition of how parsers should work with personality-dependent (mpers) types of tracee's data. Create auxiliary libraries containing mpers syscall parsers and printer functions, one library for each possible nonnative target personality. Currently some parsers do not handle differences in definitions of data types between personalities, namely LP64 and ILP32. When this is the case, long integers, pointers, and all compound types containing long and pointer members may be printed incorrectly, because of differences in sizes, offsets and alignments. Since in most cases these are the only differences in desired behaviour of parsers and printers for different personalities, a correct way would be to compile one source code into multiple parsers, differing only in definitions of mpers types. To get a definition of a given type for nonnative personality a very basic .c file containing a declaration of a variable of this type is being compiled for this personality (using -m32 or -mx32 compiler flag). Information about the type is then being extracted from this binary's DWARF debug info with an awk script and put into a corresponding header file. Resulting headers are being used to compile mpers variations of syscall parsers and printer functions. In addition to syscall parsers, there can occur a need to create mpers printing functions, which then can be called from many places in the code (for example, printsiginfo_at). Such functions (printers) are marked in a special manner. For each possible nonnative target personality a library is being created, containing mpers variations of syscall parsers and printers. Only syscall parsers from files marked in a special manner and specially marked functions from such files are being recompiled and included in these libraries. generate_mpers_am.sh is called by bootstrap to find the files from strace_SOURCES which include MPERS_DEFS. During compilation, these files are being inspected for inclusions of DEF_MPERS_TYPE, and nonnative variations of each included type are being generated by an awk script. Mpers parser names are being modified during inclusions of syscallent headers for nonnative personalities. Pointers to printers are being stored in structs struct_printers, and a master pointer printers is being updated on every set_personality. * README-mpers: New README explaining how to use mpers support. * empty.h: New empty file. * generate_mpers_am.sh: New file. * mpers.awk: Likewise. * mpers.sh: Likewise. * mpers_test.sh: Likewise. * mpers_type.h: Likewise. * Makefile.am (strace_SOURCES): Add empty.h and mpers_type.h. (strace_CPPFLAGS, strace_LDFLAGS, strace_LDADD): Move to the beginning of the file. (strace_LDADD, noinst_LIBRARIES): Add libmpers-%.a. (EXTRA_DIST): Add mpers.awk, mpers.sh, mpers_test.sh. (BUILT_SOURCES, CLEANFILES): Add new generated files: native_printer_decls.h, native_printer_defs.h, printers.h, [HAVE_M32_MPERS] $(mpers_m32_targets), and [HAVE_MX32_MPERS] $(mpers_mx32_targets). (mpers_NAME, mpers_PREFIX, mpers_DEFS, mpers_INCLUDES, mpers_CPPFLAGS, mpers_sh_opts, libmpers_CPPFLAGS, libmpers_m[x]32_a_SOURCES, libmpers_m[x]32_a_CPPFLAGS, mpers_m[x]32_targets): New variables. (mpers-m[x]32.stamp, m[x]32_defs.h, m[x]32_funcs.h, printers.h, %_printer_decls.h, %_printer_defs.h, clean-local, native_printer_decls.h, native_printer_defs.h, $mpers_m[x]32_targets): New targets. * bootstrap: Add generate_mpers_am.sh. * configure.ac: Add AC_PROG_RANLIB. * m4/mpers.m4: Add HAVE_MPERS variable. Add $st_cv_mpers checks. * defs.h: Include mpers_type.h. Include printers.h, native_printer_decls.h, define MPERS_PRINTER_NAME. Redefine SYS_FUNC_NAME. Define MPERS_PRINTER_DECL. [HAVE_M32_MPERS]: define PERSONALITY1_INCLUDE_FUNCS, PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS for X86_64, X32. [HAVE_MX32_MPERS]: define PERSONALITY2_INCLUDE_FUNCS, PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS for X86_64. Add fallback definitions of PERSONALITY1_INCLUDE_FUNCS, PERSONALITY2_INCLUDE_FUNCS, PERSONALITY0_INCLUDE_PRINTERS_DECLS, PERSONALITY0_INCLUDE_PRINTERS_DEFS, PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS, PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS. * syscall.c: Include PERSONALITY1_INCLUDE_FUNCS, PERSONALITY2_INCLUDE_FUNCS, PERSONALITY0_INCLUDE_PRINTERS_DECLS, PERSONALITY0_INCLUDE_PRINTERS_DEFS, PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS, PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS. (printers): New struct. Update it when needed. * .gitignore: Add libmpers-m32.a, libmpers-mx32.a, m32_defs.h, m32_funcs.h, m32_printer_decls.h, m32_printer_defs.h, mpers-m32, mpers-m32.stamp, mpers-mx32, mpers-mx32.stamp, mpers.am, mx32_defs.h, mx32_funcs.h, mx32_printer_decls.h, mx32_printer_defs.h, native_printer_decls.h, native_printer_defs.h, and printers.h.
2015-08-04 01:47:02 +03:00
printers = &printers0;
1999-02-19 03:21:36 +03:00
break;
case 1:
ioctlent = ioctlent1;
nioctlents = nioctlents1;
Add mpers support Add a subsystem for semi-automatical definition of how parsers should work with personality-dependent (mpers) types of tracee's data. Create auxiliary libraries containing mpers syscall parsers and printer functions, one library for each possible nonnative target personality. Currently some parsers do not handle differences in definitions of data types between personalities, namely LP64 and ILP32. When this is the case, long integers, pointers, and all compound types containing long and pointer members may be printed incorrectly, because of differences in sizes, offsets and alignments. Since in most cases these are the only differences in desired behaviour of parsers and printers for different personalities, a correct way would be to compile one source code into multiple parsers, differing only in definitions of mpers types. To get a definition of a given type for nonnative personality a very basic .c file containing a declaration of a variable of this type is being compiled for this personality (using -m32 or -mx32 compiler flag). Information about the type is then being extracted from this binary's DWARF debug info with an awk script and put into a corresponding header file. Resulting headers are being used to compile mpers variations of syscall parsers and printer functions. In addition to syscall parsers, there can occur a need to create mpers printing functions, which then can be called from many places in the code (for example, printsiginfo_at). Such functions (printers) are marked in a special manner. For each possible nonnative target personality a library is being created, containing mpers variations of syscall parsers and printers. Only syscall parsers from files marked in a special manner and specially marked functions from such files are being recompiled and included in these libraries. generate_mpers_am.sh is called by bootstrap to find the files from strace_SOURCES which include MPERS_DEFS. During compilation, these files are being inspected for inclusions of DEF_MPERS_TYPE, and nonnative variations of each included type are being generated by an awk script. Mpers parser names are being modified during inclusions of syscallent headers for nonnative personalities. Pointers to printers are being stored in structs struct_printers, and a master pointer printers is being updated on every set_personality. * README-mpers: New README explaining how to use mpers support. * empty.h: New empty file. * generate_mpers_am.sh: New file. * mpers.awk: Likewise. * mpers.sh: Likewise. * mpers_test.sh: Likewise. * mpers_type.h: Likewise. * Makefile.am (strace_SOURCES): Add empty.h and mpers_type.h. (strace_CPPFLAGS, strace_LDFLAGS, strace_LDADD): Move to the beginning of the file. (strace_LDADD, noinst_LIBRARIES): Add libmpers-%.a. (EXTRA_DIST): Add mpers.awk, mpers.sh, mpers_test.sh. (BUILT_SOURCES, CLEANFILES): Add new generated files: native_printer_decls.h, native_printer_defs.h, printers.h, [HAVE_M32_MPERS] $(mpers_m32_targets), and [HAVE_MX32_MPERS] $(mpers_mx32_targets). (mpers_NAME, mpers_PREFIX, mpers_DEFS, mpers_INCLUDES, mpers_CPPFLAGS, mpers_sh_opts, libmpers_CPPFLAGS, libmpers_m[x]32_a_SOURCES, libmpers_m[x]32_a_CPPFLAGS, mpers_m[x]32_targets): New variables. (mpers-m[x]32.stamp, m[x]32_defs.h, m[x]32_funcs.h, printers.h, %_printer_decls.h, %_printer_defs.h, clean-local, native_printer_decls.h, native_printer_defs.h, $mpers_m[x]32_targets): New targets. * bootstrap: Add generate_mpers_am.sh. * configure.ac: Add AC_PROG_RANLIB. * m4/mpers.m4: Add HAVE_MPERS variable. Add $st_cv_mpers checks. * defs.h: Include mpers_type.h. Include printers.h, native_printer_decls.h, define MPERS_PRINTER_NAME. Redefine SYS_FUNC_NAME. Define MPERS_PRINTER_DECL. [HAVE_M32_MPERS]: define PERSONALITY1_INCLUDE_FUNCS, PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS for X86_64, X32. [HAVE_MX32_MPERS]: define PERSONALITY2_INCLUDE_FUNCS, PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS for X86_64. Add fallback definitions of PERSONALITY1_INCLUDE_FUNCS, PERSONALITY2_INCLUDE_FUNCS, PERSONALITY0_INCLUDE_PRINTERS_DECLS, PERSONALITY0_INCLUDE_PRINTERS_DEFS, PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS, PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS. * syscall.c: Include PERSONALITY1_INCLUDE_FUNCS, PERSONALITY2_INCLUDE_FUNCS, PERSONALITY0_INCLUDE_PRINTERS_DECLS, PERSONALITY0_INCLUDE_PRINTERS_DEFS, PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS, PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS. (printers): New struct. Update it when needed. * .gitignore: Add libmpers-m32.a, libmpers-mx32.a, m32_defs.h, m32_funcs.h, m32_printer_decls.h, m32_printer_defs.h, mpers-m32, mpers-m32.stamp, mpers-mx32, mpers-mx32.stamp, mpers.am, mx32_defs.h, mx32_funcs.h, mx32_printer_decls.h, mx32_printer_defs.h, native_printer_decls.h, native_printer_defs.h, and printers.h.
2015-08-04 01:47:02 +03:00
printers = &printers1;
1999-02-19 03:21:36 +03:00
break;
# if SUPPORTED_PERSONALITIES > 2
1999-02-19 03:21:36 +03:00
case 2:
ioctlent = ioctlent2;
nioctlents = nioctlents2;
Add mpers support Add a subsystem for semi-automatical definition of how parsers should work with personality-dependent (mpers) types of tracee's data. Create auxiliary libraries containing mpers syscall parsers and printer functions, one library for each possible nonnative target personality. Currently some parsers do not handle differences in definitions of data types between personalities, namely LP64 and ILP32. When this is the case, long integers, pointers, and all compound types containing long and pointer members may be printed incorrectly, because of differences in sizes, offsets and alignments. Since in most cases these are the only differences in desired behaviour of parsers and printers for different personalities, a correct way would be to compile one source code into multiple parsers, differing only in definitions of mpers types. To get a definition of a given type for nonnative personality a very basic .c file containing a declaration of a variable of this type is being compiled for this personality (using -m32 or -mx32 compiler flag). Information about the type is then being extracted from this binary's DWARF debug info with an awk script and put into a corresponding header file. Resulting headers are being used to compile mpers variations of syscall parsers and printer functions. In addition to syscall parsers, there can occur a need to create mpers printing functions, which then can be called from many places in the code (for example, printsiginfo_at). Such functions (printers) are marked in a special manner. For each possible nonnative target personality a library is being created, containing mpers variations of syscall parsers and printers. Only syscall parsers from files marked in a special manner and specially marked functions from such files are being recompiled and included in these libraries. generate_mpers_am.sh is called by bootstrap to find the files from strace_SOURCES which include MPERS_DEFS. During compilation, these files are being inspected for inclusions of DEF_MPERS_TYPE, and nonnative variations of each included type are being generated by an awk script. Mpers parser names are being modified during inclusions of syscallent headers for nonnative personalities. Pointers to printers are being stored in structs struct_printers, and a master pointer printers is being updated on every set_personality. * README-mpers: New README explaining how to use mpers support. * empty.h: New empty file. * generate_mpers_am.sh: New file. * mpers.awk: Likewise. * mpers.sh: Likewise. * mpers_test.sh: Likewise. * mpers_type.h: Likewise. * Makefile.am (strace_SOURCES): Add empty.h and mpers_type.h. (strace_CPPFLAGS, strace_LDFLAGS, strace_LDADD): Move to the beginning of the file. (strace_LDADD, noinst_LIBRARIES): Add libmpers-%.a. (EXTRA_DIST): Add mpers.awk, mpers.sh, mpers_test.sh. (BUILT_SOURCES, CLEANFILES): Add new generated files: native_printer_decls.h, native_printer_defs.h, printers.h, [HAVE_M32_MPERS] $(mpers_m32_targets), and [HAVE_MX32_MPERS] $(mpers_mx32_targets). (mpers_NAME, mpers_PREFIX, mpers_DEFS, mpers_INCLUDES, mpers_CPPFLAGS, mpers_sh_opts, libmpers_CPPFLAGS, libmpers_m[x]32_a_SOURCES, libmpers_m[x]32_a_CPPFLAGS, mpers_m[x]32_targets): New variables. (mpers-m[x]32.stamp, m[x]32_defs.h, m[x]32_funcs.h, printers.h, %_printer_decls.h, %_printer_defs.h, clean-local, native_printer_decls.h, native_printer_defs.h, $mpers_m[x]32_targets): New targets. * bootstrap: Add generate_mpers_am.sh. * configure.ac: Add AC_PROG_RANLIB. * m4/mpers.m4: Add HAVE_MPERS variable. Add $st_cv_mpers checks. * defs.h: Include mpers_type.h. Include printers.h, native_printer_decls.h, define MPERS_PRINTER_NAME. Redefine SYS_FUNC_NAME. Define MPERS_PRINTER_DECL. [HAVE_M32_MPERS]: define PERSONALITY1_INCLUDE_FUNCS, PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS for X86_64, X32. [HAVE_MX32_MPERS]: define PERSONALITY2_INCLUDE_FUNCS, PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS for X86_64. Add fallback definitions of PERSONALITY1_INCLUDE_FUNCS, PERSONALITY2_INCLUDE_FUNCS, PERSONALITY0_INCLUDE_PRINTERS_DECLS, PERSONALITY0_INCLUDE_PRINTERS_DEFS, PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS, PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS. * syscall.c: Include PERSONALITY1_INCLUDE_FUNCS, PERSONALITY2_INCLUDE_FUNCS, PERSONALITY0_INCLUDE_PRINTERS_DECLS, PERSONALITY0_INCLUDE_PRINTERS_DEFS, PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS, PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS. (printers): New struct. Update it when needed. * .gitignore: Add libmpers-m32.a, libmpers-mx32.a, m32_defs.h, m32_funcs.h, m32_printer_decls.h, m32_printer_defs.h, mpers-m32, mpers-m32.stamp, mpers-mx32, mpers-mx32.stamp, mpers.am, mx32_defs.h, mx32_funcs.h, mx32_printer_decls.h, mx32_printer_defs.h, native_printer_decls.h, native_printer_defs.h, and printers.h.
2015-08-04 01:47:02 +03:00
printers = &printers2;
1999-02-19 03:21:36 +03:00
break;
# endif
1999-02-19 03:21:36 +03:00
}
current_personality = personality;
# ifndef current_wordsize
current_wordsize = personality_wordsize[personality];
# endif
# ifndef current_klongsize
current_klongsize = personality_klongsize[personality];
# endif
1999-02-19 03:21:36 +03:00
}
static void
Fix compilation warnings reported by gcc -Wsign-compare * configure.ac (gl_WARN_ADD): Add -Wsign-compare. * defs.h (struct tcb): Change 'currpers' type to unsigned. (struct xlat): Change 'val' type to unsigned (signame): Add 'const' qualifier to its argument. (xlookup, printxval): Add 'const' qualifier to the 2nd argument and change its type to unsigned. (printpathn): Change the 3rd argument type to unsigned. (ioctl_lookup): Change 1st argument type to unsigned. * count.c (call_summary_pers, call_summary): Change 'i' type to unsigned. * file.c (print_xattr_list): Fix comparisons between signed and unsigned long values. * ioctl.c (compare): Fix cast. (ioctl_lookup): Change 1st argument type to to unsigned. (ioctl_next_match): Change 'code' type to unsigned. * mem.c (sys_move_pages): Change 'i' type to unsigned. * mtd.c (mtd_ioctl): Change 'i' and 'j' types to unsigned. Print 'i' using %u format string. * process.c (sys_prctl): Change 'i' type to unsigned. (printargv): Change 'n' type to unsigned. (sys_ptrace): Change 'addr' type to unsigned. * scsi.c (print_sg_io_buffer): Add 'const' qualifier to 'len' argument and change its type to unsigned. Change 'i' and 'allocated' types to unsigned. * signal.c (signame): Add 'const' qualifier to its argument. Fix comparisons between signed and unsigned values. (sprintsigmask_n, printsiginfo): Fix comparisons between signed and unsigned values. * sock.c (sock_ioctl): Change 'i' and 'nifra' types to unsigned. * strace.c (expand_tcbtab, alloctcb): Change 'i' type to unsigned. (detach): Change 'sig' type to unsigned. (startup_attach): Change 'tcbi' type to unsigned. (startup_child): Change 'm', 'n', and 'len' types to unsigned. (init): Use new variable to iterate 'tcbtab'. (pid2tcb): Change 'i' type to unsigned. (cleanup): Change 'i' and 'sig' types to unsigned. * syscall.c (update_personality): Change 'personality' argument type to unsigned. (struct qual_options): Change 'bitflag' type to unsigned. (reallocate_qual): Add 'const' qualifier to its argument and change its type to unsigned. (qualify_one): Change 'n' and 'bitflag' arguments types to unsigned. Add 'const' qualifier to 'n', 'not', and 'pers' arguments. Change 'p' type to signed int. (qual_syscall): Change 'bitflag' argument type to unsigned. Add 'const' qualifier to 'bitflag' and 'not' arguments. Change 'p' type to signed int. (qual_signal): Change 'bitflag' argument type to unsigned. Add 'const' qualifier to 'bitflag' and 'not' arguments. Change 'i' type to unsigned. (qual_desc): Change 'bitflag' argument type to unsigned. Add 'const' qualifier to 'bitflag' and 'not' arguments. (qualify): Change 'i' type to unsigned. (get_scno): Change 'currpers' type to unsigned. Fix a comparison between signed and unsigned values. * system.c (sys_sysctl): Change 'cnt' and 'max_cnt' types to unsigned. Fix comparisons between signed and unsigned values. * util.c (xlookup, printxval): Add 'const' qualifier to 'val' argument and change its type to unsigned. (printuid): Fix a comparison between signed and unsigned values. (printpathn): Change 'n' argument type to unsigned. (printstr): Change 'size' type to unsigned. Fix a comparison between signed and unsigned values. (setbpt): Change 'i' type to unsigned. * net.c (printsock): Silence a compilation warning. * reboot.c (sys_reboot): Likewise.
2014-09-10 17:46:04 +04:00
update_personality(struct tcb *tcp, unsigned int personality)
{
static bool need_mpers_warning[] =
{ false, !HAVE_PERSONALITY_1_MPERS, !HAVE_PERSONALITY_2_MPERS };
set_personality(personality);
if (personality == tcp->currpers)
return;
tcp->currpers = personality;
Add tilegx support to strace tilegx support has been in the kernel since 3.0. In addition, fix some issues with the tilepro support already present in strace, primarily the decision to use the <asm/unistd.h> numbering space for system calls. * defs.h [TILE]: Include <asm/ptrace.h> and provide an extern struct pt_regs tile_regs for efficiency. Provide compat 32-bit personality via SUPPORTED_PERSONALITIES, PERSONALITY0_WORDSIZE, PERSONALITY1_WORDSIZE, and DEFAULT_PERSONALITY. * linux/tile/errnoent1.h: New file, includes linux/errnoent.h. * linux/tile/ioctlent1.h: New file, includes linux/ioctlent.h. * linux/tile/signalent1.h: New file, includes linux/signalent.h. * linux/tile/syscallent.h: Update with new asm-generic syscalls. The version previously committed was the from the first tile patch to LKML, which subsequently was changed to use <asm-generic/unistd.h>. * linux/tile/syscallent1.h: Copy from linux/tile/syscallent.h. * mem.c (addtileflags) [TILE]: use %ld properly for a "long" variable. * process.c [TILE]: Choose clone arguments correctly and properly suppress all "struct user" related offsets in user_struct_offsets. * signal.c [TILE]: Use tile_regs not upeek. * syscall.c (update_personality) [TILE]: Print mode. (PT_FLAGS_COMPAT) [TILE]: Provide if not in system headers. (tile_regs) [TILE]: Define 'struct pt_regs' variable to hold state. (get_regs) [TILE]: use PTRACE_GETREGS to set tile_regs rather than using upeek. (get_scno) [TILE]: Set personality. (get_syscall_args) [TILE]: Use tile_regs. (get_syscall_result) [TILE]: Update tile_regs. (get_error) [TILE]: Use tile_regs. (printcall) [TILE]: Print pc. (arg0_offset, arg1_offset, restore_arg0, restore_arg1) [TILE]: Properly handle tile call semantics and support tilegx. Signed-off-by: Chris Metcalf <cmetcalf@tilera.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-02-05 20:48:33 +04:00
if (!qflag) {
error_msg("[ Process PID=%d runs in %s mode. ]",
tcp->pid, personality_names[personality]);
Add tilegx support to strace tilegx support has been in the kernel since 3.0. In addition, fix some issues with the tilepro support already present in strace, primarily the decision to use the <asm/unistd.h> numbering space for system calls. * defs.h [TILE]: Include <asm/ptrace.h> and provide an extern struct pt_regs tile_regs for efficiency. Provide compat 32-bit personality via SUPPORTED_PERSONALITIES, PERSONALITY0_WORDSIZE, PERSONALITY1_WORDSIZE, and DEFAULT_PERSONALITY. * linux/tile/errnoent1.h: New file, includes linux/errnoent.h. * linux/tile/ioctlent1.h: New file, includes linux/ioctlent.h. * linux/tile/signalent1.h: New file, includes linux/signalent.h. * linux/tile/syscallent.h: Update with new asm-generic syscalls. The version previously committed was the from the first tile patch to LKML, which subsequently was changed to use <asm-generic/unistd.h>. * linux/tile/syscallent1.h: Copy from linux/tile/syscallent.h. * mem.c (addtileflags) [TILE]: use %ld properly for a "long" variable. * process.c [TILE]: Choose clone arguments correctly and properly suppress all "struct user" related offsets in user_struct_offsets. * signal.c [TILE]: Use tile_regs not upeek. * syscall.c (update_personality) [TILE]: Print mode. (PT_FLAGS_COMPAT) [TILE]: Provide if not in system headers. (tile_regs) [TILE]: Define 'struct pt_regs' variable to hold state. (get_regs) [TILE]: use PTRACE_GETREGS to set tile_regs rather than using upeek. (get_scno) [TILE]: Set personality. (get_syscall_args) [TILE]: Use tile_regs. (get_syscall_result) [TILE]: Update tile_regs. (get_error) [TILE]: Use tile_regs. (printcall) [TILE]: Print pc. (arg0_offset, arg1_offset, restore_arg0, restore_arg1) [TILE]: Properly handle tile call semantics and support tilegx. Signed-off-by: Chris Metcalf <cmetcalf@tilera.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-02-05 20:48:33 +04:00
}
if (need_mpers_warning[personality]) {
error_msg("WARNING: Proper structure decoding for this "
"personality is not supported, please consider "
"building strace with mpers support enabled.");
need_mpers_warning[personality] = false;
}
}
#endif
#ifdef SYS_socket_subcall
static void
decode_socket_subcall(struct tcb *tcp)
1999-02-19 03:21:36 +03:00
{
const int call = tcp->u_arg[0];
if (call < 1 || call >= SYS_socket_nsubcalls)
return;
const kernel_ulong_t scno = SYS_socket_subcall + call;
const unsigned int nargs = sysent[scno].nargs;
uint64_t buf[nargs];
if (umoven(tcp, tcp->u_arg[1], nargs * current_wordsize, buf) < 0)
return;
tcp->scno = scno;
Rewrite remaining qual_* parsers using bit sets * defs.h (struct fault_opts): Replace forward declaration with a definition. (qualbits_t, qualify_read, qualify_write, qualify_signals): Remove. (qual_flags): New function prototype. (nsyscall_vec, sysent_vec, fault_vec): New variable prototypes. * qualify.c (abbrev_set, fault_set, raw_set, trace_set, verbose_set): New variables. (qualify_read, qualify_write, qualify_signals): Add static qualifier. (find_errno_by_name, lookup_class, parse_fault_expression, parse_fault_token, qual_flags, qualify, qualify_abbrev, qualify_fault, qualify_raw, qualify_syscall, qualify_syscall_class, qualify_syscall_name, qualify_syscall_number, qualify_syscall_tokens, qualify_trace, qualify_verbose, strip_prefix): New functions. * syscall.c (nsyscall_vec, nsysent_vec): Remove static qualifier. (MAX_NSYSCALLS1, MAX_NSYSCALLS2, MAX_NSYSCALLS, qual_vec, qual_flags, qual_fault, qual_syscall, qual_options, fault_opts, qualify_one, qualify_scno, lookup_class, qualify_syscall_class, qualify_syscall_name, qual_syscall_ex, qual_syscall, strip_prefix, find_errno_by_name, parse_fault_token, parse_fault_expression, qual_fault, qualify): Remove. (decode_socket_subcall, decode_ipc_subcall, decode_mips_subcall, get_scno): Update use of qual_flags. (inject_syscall_fault_entering): Update per-personality allocation of tcp->fault_vec. * tests/fault_injection-exit_group.test: Check parsing of inversed fault sets. * tests/fault_injection.test: Check parsing of -efault=none. * tests/options-syntax.test: Check parsing of invalid syscall numbers.
2016-12-04 17:39:48 +03:00
tcp->qual_flg = qual_flags(scno);
tcp->s_ent = &sysent[scno];
unsigned int i;
for (i = 0; i < nargs; ++i)
tcp->u_arg[i] = (sizeof(uint32_t) == current_wordsize)
? ((uint32_t *) (void *) buf)[i] : buf[i];
1999-02-19 03:21:36 +03:00
}
#endif /* SYS_socket_subcall */
#ifdef SYS_ipc_subcall
static void
decode_ipc_subcall(struct tcb *tcp)
{
unsigned int call = tcp->u_arg[0];
const unsigned int version = call >> 16;
if (version) {
# if defined S390 || defined S390X
return;
# else
# ifdef SPARC64
if (current_wordsize == 8)
return;
# endif
set_tcb_priv_ulong(tcp, version);
call &= 0xffff;
# endif
}
switch (call) {
case 1: case 2: case 3: case 4:
case 11: case 12: case 13: case 14:
case 21: case 22: case 23: case 24:
break;
default:
return;
}
tcp->scno = SYS_ipc_subcall + call;
Rewrite remaining qual_* parsers using bit sets * defs.h (struct fault_opts): Replace forward declaration with a definition. (qualbits_t, qualify_read, qualify_write, qualify_signals): Remove. (qual_flags): New function prototype. (nsyscall_vec, sysent_vec, fault_vec): New variable prototypes. * qualify.c (abbrev_set, fault_set, raw_set, trace_set, verbose_set): New variables. (qualify_read, qualify_write, qualify_signals): Add static qualifier. (find_errno_by_name, lookup_class, parse_fault_expression, parse_fault_token, qual_flags, qualify, qualify_abbrev, qualify_fault, qualify_raw, qualify_syscall, qualify_syscall_class, qualify_syscall_name, qualify_syscall_number, qualify_syscall_tokens, qualify_trace, qualify_verbose, strip_prefix): New functions. * syscall.c (nsyscall_vec, nsysent_vec): Remove static qualifier. (MAX_NSYSCALLS1, MAX_NSYSCALLS2, MAX_NSYSCALLS, qual_vec, qual_flags, qual_fault, qual_syscall, qual_options, fault_opts, qualify_one, qualify_scno, lookup_class, qualify_syscall_class, qualify_syscall_name, qual_syscall_ex, qual_syscall, strip_prefix, find_errno_by_name, parse_fault_token, parse_fault_expression, qual_fault, qualify): Remove. (decode_socket_subcall, decode_ipc_subcall, decode_mips_subcall, get_scno): Update use of qual_flags. (inject_syscall_fault_entering): Update per-personality allocation of tcp->fault_vec. * tests/fault_injection-exit_group.test: Check parsing of inversed fault sets. * tests/fault_injection.test: Check parsing of -efault=none. * tests/options-syntax.test: Check parsing of invalid syscall numbers.
2016-12-04 17:39:48 +03:00
tcp->qual_flg = qual_flags(tcp->scno);
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>
2013-02-21 19:13:47 +04:00
tcp->s_ent = &sysent[tcp->scno];
const unsigned int n = tcp->s_ent->nargs;
unsigned int i;
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>
2013-02-21 19:13:47 +04:00
for (i = 0; i < n; i++)
tcp->u_arg[i] = tcp->u_arg[i + 1];
}
#endif /* SYS_ipc_subcall */
1999-02-19 03:21:36 +03:00
#ifdef SYS_syscall_subcall
/* The implementation is architecture specific. */
static void decode_syscall_subcall(struct tcb *);
#endif /* SYS_syscall_subcall */
static void
dumpio(struct tcb *tcp)
{
int fd = tcp->u_arg[0];
if (fd < 0)
return;
if (is_number_in_set(fd, write_set)) {
switch (tcp->s_ent->sen) {
case SEN_write:
case SEN_pwrite:
case SEN_send:
case SEN_sendto:
case SEN_mq_timedsend:
dumpstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
break;
case SEN_writev:
case SEN_pwritev:
case SEN_pwritev2:
case SEN_vmsplice:
dumpiov_upto(tcp, tcp->u_arg[2], tcp->u_arg[1], -1);
break;
case SEN_sendmsg:
dumpiov_in_msghdr(tcp, tcp->u_arg[1], -1);
break;
case SEN_sendmmsg:
dumpiov_in_mmsghdr(tcp, tcp->u_arg[1]);
break;
}
}
if (syserror(tcp))
return;
if (is_number_in_set(fd, read_set)) {
switch (tcp->s_ent->sen) {
case SEN_read:
case SEN_pread:
case SEN_recv:
case SEN_recvfrom:
case SEN_mq_timedreceive:
dumpstr(tcp, tcp->u_arg[1], tcp->u_rval);
return;
case SEN_readv:
case SEN_preadv:
case SEN_preadv2:
dumpiov_upto(tcp, tcp->u_arg[2], tcp->u_arg[1],
tcp->u_rval);
return;
case SEN_recvmsg:
dumpiov_in_msghdr(tcp, tcp->u_arg[1], tcp->u_rval);
return;
case SEN_recvmmsg:
dumpiov_in_mmsghdr(tcp, tcp->u_arg[1]);
return;
}
}
}
const char *
err_name(unsigned long err)
{
if ((err < nerrnos) && errnoent[err])
return errnoent[err];
return NULL;
}
static void
print_err_ret(kernel_ulong_t ret, unsigned long u_error)
{
const char *u_error_str = err_name(u_error);
if (u_error_str)
tprintf("= %" PRI_kld " %s (%s)",
ret, u_error_str, strerror(u_error));
else
tprintf("= %" PRI_kld " (errno %lu)", ret, u_error);
}
static long get_regs(struct tcb *);
static int get_syscall_args(struct tcb *);
static int get_syscall_result(struct tcb *);
static void get_error(struct tcb *, bool);
static void set_error(struct tcb *, unsigned long);
static void set_success(struct tcb *, kernel_long_t);
static int arch_get_scno(struct tcb *);
Introduce PTRACE_GET_SYSCALL_INFO support When PTRACE_GET_SYSCALL_INFO API works, use it instead of traditional upeek/get_regs API. Tested on x86_64 and x86. * get_personality.c: New file. * get_personality.h: Likewise. * Makefile.am (strace_SOURCES): Add them. * linux/aarch64/arch_get_personality.c: New file. * linux/powerpc64/arch_get_personality.c: Likewise. * linux/riscv/arch_get_personality.c: Likewise. * linux/s390x/arch_get_personality.c: Likewise. * linux/sparc64/arch_get_personality.c: Likewise. * linux/tile/arch_get_personality.c: Likewise. * linux/x32/arch_get_personality.c: Likewise. * linux/x86_64/arch_get_personality.c: Likewise. * linux/check_scno.c: Likewise. * linux/x32/check_scno.c: Likewise. * Makefile.am (EXTRA_DIST): Add them. * linux/ia64/arch_getrval2.c (getrval2): Invoke get_regs() if ptrace_syscall_info is in use. * linux/mips/arch_getrval2.c: Likewise. * linux/sparc/arch_getrval2.c: Likewise. * defs.h (get_personality_from_syscall_info): New prototype. * syscall.c: Include "get_personality.h" and "ptrace_syscall_info.h". (get_regs_error): Define unconditionally. (ptrace_sci): New static variable. (clear_regs): Reset ptrace_sci.op. (ptrace_syscall_info_is_valid, ptrace_get_syscall_info, get_syscall_regs): New functions. (get_syscall_result_regs): Change to get_syscall_regs. (get_instruction_pointer, get_stack_pointer, get_scno, get_syscall_args, get_error, set_error, set_success): Add ptrace_syscall_info support. * tests/int_0x80.test: New test. * tests/Makefile.am (DECODER_TESTS): Add int_0x80.test. (XFAIL_TESTS_x86_64, XFAIL_TESTS_x32): Remove. * tests/gen_tests.in (int_0x80): Remove.
2018-11-21 04:44:16 +03:00
static int arch_check_scno(struct tcb *);
static int arch_set_scno(struct tcb *, kernel_ulong_t);
static int arch_get_syscall_args(struct tcb *);
static void arch_get_error(struct tcb *, bool);
Implement syscall fault injection Introduce new -e fault=EXPR syntax that can be used to specify a subset of syscalls that are subject of syscall fault injection, an error code that has to be injected, and a frequency of injection. The expression specifying syscall fault injection has the following format: SET[:error=ERRNO][:when=FIRST[+[STEP]]] where only SET is a required part and all the rest is optional. The method used to implement syscall fault injection is the following: on entering syscall the syscall number is substituted by an invalid syscall number -1, and on exiting syscall the error code returned by the kernel is substituted with the error code specified in the fault expression. This implementaion is based on the prototype developed by Nahim El Atmani as a part of his GSoC 2016 strace project. * defs.h (struct fault_opts): New forward declaration. (struct tcb): Add fault_vec field. (TCB_FAULT_INJ, QUAL_FAULT): New macros. * strace.1: Document -e fault expression syntax. * strace.c (usage): Mention -e fault expression. (droptcb): Deallocate fault_vec member. * syscall.c (qual_fault, arch_set_scno, arch_set_error): New prototypes. (qual_options): Add "fault" option. (struct fault_opts): New structure. (num_faults): New variable. (fault_vec): New array. (syscall_fault_injected, tcb_fault_opts, reallocate_fault, find_errno_by_name, qual_syscall_ex, strip_prefix, parse_fault_token, parse_fault_expression, qual_fault, inject_syscall_fault_entering, update_syscall_fault_exiting): New functions. (qual_syscall): Use qual_syscall_ex. (qualify_one): Add argument: a pointer to struct fault_opts, all callers changed. Copy struct fault_opts from the pointer to fault_vec. Use reallocate_fault. (qualify_scno, qualify_syscall_class, qualify_syscall_name): Add argument: a pointer to struct fault_opts. (qualify): Use reallocate_fault. Do not check "all" class for QUAL_FAULT qualifier. (lookup_class): Check for "all" class. (trace_syscall_entering): Use inject_syscall_fault_entering. (trace_syscall_exiting): Use update_syscall_fault_exiting. Clear TCB_FAULT_INJ flag along with TCB_INSYSCALL. Print " (INJECTED)" suffix when the syscall has been injected successfully. [ARCH_REGS_FOR_GETREGSET && !HAVE_GETREGS_OLD] (ptrace_setregset): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregset. [ARCH_REGS_FOR_GETREGS && !HAVE_GETREGS_OLD] (ptrace_setregs): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregs. [ptrace_setregset_or_setregs] (set_regs): New function. Include "set_scno.c" and "set_error.c" * NEWS: Mention this enhancement.
2016-11-16 20:26:58 +03:00
static int arch_set_error(struct tcb *);
Implement success injection This extends fault injection syntax with :retval= option. When :retval=VALUE is specified, the syscall number is replaced by -1 and a bogus success VALUE is returned to the callee. * defs.h (fault_opts): Remove err field, add rval field. (MAX_ERRNO_VALUE, FAULT_OPTS_RVAL_DEFAULT, FAULT_OPTS_RVAL_DISABLE): New macros. * qualify.c (parse_fault_token): Handle retval= token. (qualify_fault): Update fault_opts initialization after the move from struct fault_opts.err to struct fault_opts.rval. * syscall.c (arch_set_success): New prototype. (inject_syscall_fault_entering): Check opts->rval instead of opts->err. (update_syscall_fault_exiting): Implement retval injection. * strace.1: Update the section on fault injection. * NEWS: Mention retval= option. * linux/aarch64/set_error.c (arch_set_success): New function. * linux/alpha/set_error.c: Likewise. * linux/arc/set_error.c: Likewise. * linux/arm/set_error.c: Likewise. * linux/avr32/set_error.c: Likewise. * linux/bfin/set_error.c: Likewise. * linux/crisv10/set_error.c: Likewise. * linux/hppa/set_error.c: Likewise. * linux/i386/set_error.c: Likewise. * linux/ia64/set_error.c: Likewise. * linux/m68k/set_error.c: Likewise. * linux/metag/set_error.c: Likewise. * linux/microblaze/set_error.c: Likewise. * linux/mips/set_error.c: Likewise. * linux/nios2/set_error.c: Likewise. * linux/or1k/set_error.c: Likewise. * linux/powerpc/set_error.c: Likewise. * linux/riscv/set_error.c: Likewise. * linux/s390/set_error.c: Likewise. * linux/sh/set_error.c: Likewise. * linux/sh64/set_error.c: Likewise. * linux/sparc/set_error.c: Likewise. * linux/sparc64/set_error.c: Likewise. * linux/tile/set_error.c: Likewise. * linux/x86_64/set_error.c: Likewise. * linux/xtensa/set_error.c: Likewise. Closes: https://github.com/strace/strace/issues/3
2017-01-25 02:59:16 +03:00
static int arch_set_success(struct tcb *);
Implement syscall fault injection Introduce new -e fault=EXPR syntax that can be used to specify a subset of syscalls that are subject of syscall fault injection, an error code that has to be injected, and a frequency of injection. The expression specifying syscall fault injection has the following format: SET[:error=ERRNO][:when=FIRST[+[STEP]]] where only SET is a required part and all the rest is optional. The method used to implement syscall fault injection is the following: on entering syscall the syscall number is substituted by an invalid syscall number -1, and on exiting syscall the error code returned by the kernel is substituted with the error code specified in the fault expression. This implementaion is based on the prototype developed by Nahim El Atmani as a part of his GSoC 2016 strace project. * defs.h (struct fault_opts): New forward declaration. (struct tcb): Add fault_vec field. (TCB_FAULT_INJ, QUAL_FAULT): New macros. * strace.1: Document -e fault expression syntax. * strace.c (usage): Mention -e fault expression. (droptcb): Deallocate fault_vec member. * syscall.c (qual_fault, arch_set_scno, arch_set_error): New prototypes. (qual_options): Add "fault" option. (struct fault_opts): New structure. (num_faults): New variable. (fault_vec): New array. (syscall_fault_injected, tcb_fault_opts, reallocate_fault, find_errno_by_name, qual_syscall_ex, strip_prefix, parse_fault_token, parse_fault_expression, qual_fault, inject_syscall_fault_entering, update_syscall_fault_exiting): New functions. (qual_syscall): Use qual_syscall_ex. (qualify_one): Add argument: a pointer to struct fault_opts, all callers changed. Copy struct fault_opts from the pointer to fault_vec. Use reallocate_fault. (qualify_scno, qualify_syscall_class, qualify_syscall_name): Add argument: a pointer to struct fault_opts. (qualify): Use reallocate_fault. Do not check "all" class for QUAL_FAULT qualifier. (lookup_class): Check for "all" class. (trace_syscall_entering): Use inject_syscall_fault_entering. (trace_syscall_exiting): Use update_syscall_fault_exiting. Clear TCB_FAULT_INJ flag along with TCB_INSYSCALL. Print " (INJECTED)" suffix when the syscall has been injected successfully. [ARCH_REGS_FOR_GETREGSET && !HAVE_GETREGS_OLD] (ptrace_setregset): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregset. [ARCH_REGS_FOR_GETREGS && !HAVE_GETREGS_OLD] (ptrace_setregs): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregs. [ptrace_setregset_or_setregs] (set_regs): New function. Include "set_scno.c" and "set_error.c" * NEWS: Mention this enhancement.
2016-11-16 20:26:58 +03:00
struct inject_opts *inject_vec[SUPPORTED_PERSONALITIES];
Rewrite remaining qual_* parsers using bit sets * defs.h (struct fault_opts): Replace forward declaration with a definition. (qualbits_t, qualify_read, qualify_write, qualify_signals): Remove. (qual_flags): New function prototype. (nsyscall_vec, sysent_vec, fault_vec): New variable prototypes. * qualify.c (abbrev_set, fault_set, raw_set, trace_set, verbose_set): New variables. (qualify_read, qualify_write, qualify_signals): Add static qualifier. (find_errno_by_name, lookup_class, parse_fault_expression, parse_fault_token, qual_flags, qualify, qualify_abbrev, qualify_fault, qualify_raw, qualify_syscall, qualify_syscall_class, qualify_syscall_name, qualify_syscall_number, qualify_syscall_tokens, qualify_trace, qualify_verbose, strip_prefix): New functions. * syscall.c (nsyscall_vec, nsysent_vec): Remove static qualifier. (MAX_NSYSCALLS1, MAX_NSYSCALLS2, MAX_NSYSCALLS, qual_vec, qual_flags, qual_fault, qual_syscall, qual_options, fault_opts, qualify_one, qualify_scno, lookup_class, qualify_syscall_class, qualify_syscall_name, qual_syscall_ex, qual_syscall, strip_prefix, find_errno_by_name, parse_fault_token, parse_fault_expression, qual_fault, qualify): Remove. (decode_socket_subcall, decode_ipc_subcall, decode_mips_subcall, get_scno): Update use of qual_flags. (inject_syscall_fault_entering): Update per-personality allocation of tcp->fault_vec. * tests/fault_injection-exit_group.test: Check parsing of inversed fault sets. * tests/fault_injection.test: Check parsing of -efault=none. * tests/options-syntax.test: Check parsing of invalid syscall numbers.
2016-12-04 17:39:48 +03:00
static struct inject_opts *
tcb_inject_opts(struct tcb *tcp)
Implement syscall fault injection Introduce new -e fault=EXPR syntax that can be used to specify a subset of syscalls that are subject of syscall fault injection, an error code that has to be injected, and a frequency of injection. The expression specifying syscall fault injection has the following format: SET[:error=ERRNO][:when=FIRST[+[STEP]]] where only SET is a required part and all the rest is optional. The method used to implement syscall fault injection is the following: on entering syscall the syscall number is substituted by an invalid syscall number -1, and on exiting syscall the error code returned by the kernel is substituted with the error code specified in the fault expression. This implementaion is based on the prototype developed by Nahim El Atmani as a part of his GSoC 2016 strace project. * defs.h (struct fault_opts): New forward declaration. (struct tcb): Add fault_vec field. (TCB_FAULT_INJ, QUAL_FAULT): New macros. * strace.1: Document -e fault expression syntax. * strace.c (usage): Mention -e fault expression. (droptcb): Deallocate fault_vec member. * syscall.c (qual_fault, arch_set_scno, arch_set_error): New prototypes. (qual_options): Add "fault" option. (struct fault_opts): New structure. (num_faults): New variable. (fault_vec): New array. (syscall_fault_injected, tcb_fault_opts, reallocate_fault, find_errno_by_name, qual_syscall_ex, strip_prefix, parse_fault_token, parse_fault_expression, qual_fault, inject_syscall_fault_entering, update_syscall_fault_exiting): New functions. (qual_syscall): Use qual_syscall_ex. (qualify_one): Add argument: a pointer to struct fault_opts, all callers changed. Copy struct fault_opts from the pointer to fault_vec. Use reallocate_fault. (qualify_scno, qualify_syscall_class, qualify_syscall_name): Add argument: a pointer to struct fault_opts. (qualify): Use reallocate_fault. Do not check "all" class for QUAL_FAULT qualifier. (lookup_class): Check for "all" class. (trace_syscall_entering): Use inject_syscall_fault_entering. (trace_syscall_exiting): Use update_syscall_fault_exiting. Clear TCB_FAULT_INJ flag along with TCB_INSYSCALL. Print " (INJECTED)" suffix when the syscall has been injected successfully. [ARCH_REGS_FOR_GETREGSET && !HAVE_GETREGS_OLD] (ptrace_setregset): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregset. [ARCH_REGS_FOR_GETREGS && !HAVE_GETREGS_OLD] (ptrace_setregs): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregs. [ptrace_setregset_or_setregs] (set_regs): New function. Include "set_scno.c" and "set_error.c" * NEWS: Mention this enhancement.
2016-11-16 20:26:58 +03:00
{
return (scno_in_range(tcp->scno) && tcp->inject_vec[current_personality])
? &tcp->inject_vec[current_personality][tcp->scno] : NULL;
Implement syscall fault injection Introduce new -e fault=EXPR syntax that can be used to specify a subset of syscalls that are subject of syscall fault injection, an error code that has to be injected, and a frequency of injection. The expression specifying syscall fault injection has the following format: SET[:error=ERRNO][:when=FIRST[+[STEP]]] where only SET is a required part and all the rest is optional. The method used to implement syscall fault injection is the following: on entering syscall the syscall number is substituted by an invalid syscall number -1, and on exiting syscall the error code returned by the kernel is substituted with the error code specified in the fault expression. This implementaion is based on the prototype developed by Nahim El Atmani as a part of his GSoC 2016 strace project. * defs.h (struct fault_opts): New forward declaration. (struct tcb): Add fault_vec field. (TCB_FAULT_INJ, QUAL_FAULT): New macros. * strace.1: Document -e fault expression syntax. * strace.c (usage): Mention -e fault expression. (droptcb): Deallocate fault_vec member. * syscall.c (qual_fault, arch_set_scno, arch_set_error): New prototypes. (qual_options): Add "fault" option. (struct fault_opts): New structure. (num_faults): New variable. (fault_vec): New array. (syscall_fault_injected, tcb_fault_opts, reallocate_fault, find_errno_by_name, qual_syscall_ex, strip_prefix, parse_fault_token, parse_fault_expression, qual_fault, inject_syscall_fault_entering, update_syscall_fault_exiting): New functions. (qual_syscall): Use qual_syscall_ex. (qualify_one): Add argument: a pointer to struct fault_opts, all callers changed. Copy struct fault_opts from the pointer to fault_vec. Use reallocate_fault. (qualify_scno, qualify_syscall_class, qualify_syscall_name): Add argument: a pointer to struct fault_opts. (qualify): Use reallocate_fault. Do not check "all" class for QUAL_FAULT qualifier. (lookup_class): Check for "all" class. (trace_syscall_entering): Use inject_syscall_fault_entering. (trace_syscall_exiting): Use update_syscall_fault_exiting. Clear TCB_FAULT_INJ flag along with TCB_INSYSCALL. Print " (INJECTED)" suffix when the syscall has been injected successfully. [ARCH_REGS_FOR_GETREGSET && !HAVE_GETREGS_OLD] (ptrace_setregset): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregset. [ARCH_REGS_FOR_GETREGS && !HAVE_GETREGS_OLD] (ptrace_setregs): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregs. [ptrace_setregset_or_setregs] (set_regs): New function. Include "set_scno.c" and "set_error.c" * NEWS: Mention this enhancement.
2016-11-16 20:26:58 +03:00
}
static long
tamper_with_syscall_entering(struct tcb *tcp, unsigned int *signo)
Implement syscall fault injection Introduce new -e fault=EXPR syntax that can be used to specify a subset of syscalls that are subject of syscall fault injection, an error code that has to be injected, and a frequency of injection. The expression specifying syscall fault injection has the following format: SET[:error=ERRNO][:when=FIRST[+[STEP]]] where only SET is a required part and all the rest is optional. The method used to implement syscall fault injection is the following: on entering syscall the syscall number is substituted by an invalid syscall number -1, and on exiting syscall the error code returned by the kernel is substituted with the error code specified in the fault expression. This implementaion is based on the prototype developed by Nahim El Atmani as a part of his GSoC 2016 strace project. * defs.h (struct fault_opts): New forward declaration. (struct tcb): Add fault_vec field. (TCB_FAULT_INJ, QUAL_FAULT): New macros. * strace.1: Document -e fault expression syntax. * strace.c (usage): Mention -e fault expression. (droptcb): Deallocate fault_vec member. * syscall.c (qual_fault, arch_set_scno, arch_set_error): New prototypes. (qual_options): Add "fault" option. (struct fault_opts): New structure. (num_faults): New variable. (fault_vec): New array. (syscall_fault_injected, tcb_fault_opts, reallocate_fault, find_errno_by_name, qual_syscall_ex, strip_prefix, parse_fault_token, parse_fault_expression, qual_fault, inject_syscall_fault_entering, update_syscall_fault_exiting): New functions. (qual_syscall): Use qual_syscall_ex. (qualify_one): Add argument: a pointer to struct fault_opts, all callers changed. Copy struct fault_opts from the pointer to fault_vec. Use reallocate_fault. (qualify_scno, qualify_syscall_class, qualify_syscall_name): Add argument: a pointer to struct fault_opts. (qualify): Use reallocate_fault. Do not check "all" class for QUAL_FAULT qualifier. (lookup_class): Check for "all" class. (trace_syscall_entering): Use inject_syscall_fault_entering. (trace_syscall_exiting): Use update_syscall_fault_exiting. Clear TCB_FAULT_INJ flag along with TCB_INSYSCALL. Print " (INJECTED)" suffix when the syscall has been injected successfully. [ARCH_REGS_FOR_GETREGSET && !HAVE_GETREGS_OLD] (ptrace_setregset): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregset. [ARCH_REGS_FOR_GETREGS && !HAVE_GETREGS_OLD] (ptrace_setregs): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregs. [ptrace_setregset_or_setregs] (set_regs): New function. Include "set_scno.c" and "set_error.c" * NEWS: Mention this enhancement.
2016-11-16 20:26:58 +03:00
{
if (!tcp->inject_vec[current_personality]) {
tcp->inject_vec[current_personality] =
xcalloc(nsyscalls, sizeof(**inject_vec));
memcpy(tcp->inject_vec[current_personality],
inject_vec[current_personality],
nsyscalls * sizeof(**inject_vec));
Implement syscall fault injection Introduce new -e fault=EXPR syntax that can be used to specify a subset of syscalls that are subject of syscall fault injection, an error code that has to be injected, and a frequency of injection. The expression specifying syscall fault injection has the following format: SET[:error=ERRNO][:when=FIRST[+[STEP]]] where only SET is a required part and all the rest is optional. The method used to implement syscall fault injection is the following: on entering syscall the syscall number is substituted by an invalid syscall number -1, and on exiting syscall the error code returned by the kernel is substituted with the error code specified in the fault expression. This implementaion is based on the prototype developed by Nahim El Atmani as a part of his GSoC 2016 strace project. * defs.h (struct fault_opts): New forward declaration. (struct tcb): Add fault_vec field. (TCB_FAULT_INJ, QUAL_FAULT): New macros. * strace.1: Document -e fault expression syntax. * strace.c (usage): Mention -e fault expression. (droptcb): Deallocate fault_vec member. * syscall.c (qual_fault, arch_set_scno, arch_set_error): New prototypes. (qual_options): Add "fault" option. (struct fault_opts): New structure. (num_faults): New variable. (fault_vec): New array. (syscall_fault_injected, tcb_fault_opts, reallocate_fault, find_errno_by_name, qual_syscall_ex, strip_prefix, parse_fault_token, parse_fault_expression, qual_fault, inject_syscall_fault_entering, update_syscall_fault_exiting): New functions. (qual_syscall): Use qual_syscall_ex. (qualify_one): Add argument: a pointer to struct fault_opts, all callers changed. Copy struct fault_opts from the pointer to fault_vec. Use reallocate_fault. (qualify_scno, qualify_syscall_class, qualify_syscall_name): Add argument: a pointer to struct fault_opts. (qualify): Use reallocate_fault. Do not check "all" class for QUAL_FAULT qualifier. (lookup_class): Check for "all" class. (trace_syscall_entering): Use inject_syscall_fault_entering. (trace_syscall_exiting): Use update_syscall_fault_exiting. Clear TCB_FAULT_INJ flag along with TCB_INSYSCALL. Print " (INJECTED)" suffix when the syscall has been injected successfully. [ARCH_REGS_FOR_GETREGSET && !HAVE_GETREGS_OLD] (ptrace_setregset): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregset. [ARCH_REGS_FOR_GETREGS && !HAVE_GETREGS_OLD] (ptrace_setregs): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregs. [ptrace_setregset_or_setregs] (set_regs): New function. Include "set_scno.c" and "set_error.c" * NEWS: Mention this enhancement.
2016-11-16 20:26:58 +03:00
}
struct inject_opts *opts = tcb_inject_opts(tcp);
Implement syscall fault injection Introduce new -e fault=EXPR syntax that can be used to specify a subset of syscalls that are subject of syscall fault injection, an error code that has to be injected, and a frequency of injection. The expression specifying syscall fault injection has the following format: SET[:error=ERRNO][:when=FIRST[+[STEP]]] where only SET is a required part and all the rest is optional. The method used to implement syscall fault injection is the following: on entering syscall the syscall number is substituted by an invalid syscall number -1, and on exiting syscall the error code returned by the kernel is substituted with the error code specified in the fault expression. This implementaion is based on the prototype developed by Nahim El Atmani as a part of his GSoC 2016 strace project. * defs.h (struct fault_opts): New forward declaration. (struct tcb): Add fault_vec field. (TCB_FAULT_INJ, QUAL_FAULT): New macros. * strace.1: Document -e fault expression syntax. * strace.c (usage): Mention -e fault expression. (droptcb): Deallocate fault_vec member. * syscall.c (qual_fault, arch_set_scno, arch_set_error): New prototypes. (qual_options): Add "fault" option. (struct fault_opts): New structure. (num_faults): New variable. (fault_vec): New array. (syscall_fault_injected, tcb_fault_opts, reallocate_fault, find_errno_by_name, qual_syscall_ex, strip_prefix, parse_fault_token, parse_fault_expression, qual_fault, inject_syscall_fault_entering, update_syscall_fault_exiting): New functions. (qual_syscall): Use qual_syscall_ex. (qualify_one): Add argument: a pointer to struct fault_opts, all callers changed. Copy struct fault_opts from the pointer to fault_vec. Use reallocate_fault. (qualify_scno, qualify_syscall_class, qualify_syscall_name): Add argument: a pointer to struct fault_opts. (qualify): Use reallocate_fault. Do not check "all" class for QUAL_FAULT qualifier. (lookup_class): Check for "all" class. (trace_syscall_entering): Use inject_syscall_fault_entering. (trace_syscall_exiting): Use update_syscall_fault_exiting. Clear TCB_FAULT_INJ flag along with TCB_INSYSCALL. Print " (INJECTED)" suffix when the syscall has been injected successfully. [ARCH_REGS_FOR_GETREGSET && !HAVE_GETREGS_OLD] (ptrace_setregset): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregset. [ARCH_REGS_FOR_GETREGS && !HAVE_GETREGS_OLD] (ptrace_setregs): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregs. [ptrace_setregset_or_setregs] (set_regs): New function. Include "set_scno.c" and "set_error.c" * NEWS: Mention this enhancement.
2016-11-16 20:26:58 +03:00
Rewrite remaining qual_* parsers using bit sets * defs.h (struct fault_opts): Replace forward declaration with a definition. (qualbits_t, qualify_read, qualify_write, qualify_signals): Remove. (qual_flags): New function prototype. (nsyscall_vec, sysent_vec, fault_vec): New variable prototypes. * qualify.c (abbrev_set, fault_set, raw_set, trace_set, verbose_set): New variables. (qualify_read, qualify_write, qualify_signals): Add static qualifier. (find_errno_by_name, lookup_class, parse_fault_expression, parse_fault_token, qual_flags, qualify, qualify_abbrev, qualify_fault, qualify_raw, qualify_syscall, qualify_syscall_class, qualify_syscall_name, qualify_syscall_number, qualify_syscall_tokens, qualify_trace, qualify_verbose, strip_prefix): New functions. * syscall.c (nsyscall_vec, nsysent_vec): Remove static qualifier. (MAX_NSYSCALLS1, MAX_NSYSCALLS2, MAX_NSYSCALLS, qual_vec, qual_flags, qual_fault, qual_syscall, qual_options, fault_opts, qualify_one, qualify_scno, lookup_class, qualify_syscall_class, qualify_syscall_name, qual_syscall_ex, qual_syscall, strip_prefix, find_errno_by_name, parse_fault_token, parse_fault_expression, qual_fault, qualify): Remove. (decode_socket_subcall, decode_ipc_subcall, decode_mips_subcall, get_scno): Update use of qual_flags. (inject_syscall_fault_entering): Update per-personality allocation of tcp->fault_vec. * tests/fault_injection-exit_group.test: Check parsing of inversed fault sets. * tests/fault_injection.test: Check parsing of -efault=none. * tests/options-syntax.test: Check parsing of invalid syscall numbers.
2016-12-04 17:39:48 +03:00
if (!opts || opts->first == 0)
Implement syscall fault injection Introduce new -e fault=EXPR syntax that can be used to specify a subset of syscalls that are subject of syscall fault injection, an error code that has to be injected, and a frequency of injection. The expression specifying syscall fault injection has the following format: SET[:error=ERRNO][:when=FIRST[+[STEP]]] where only SET is a required part and all the rest is optional. The method used to implement syscall fault injection is the following: on entering syscall the syscall number is substituted by an invalid syscall number -1, and on exiting syscall the error code returned by the kernel is substituted with the error code specified in the fault expression. This implementaion is based on the prototype developed by Nahim El Atmani as a part of his GSoC 2016 strace project. * defs.h (struct fault_opts): New forward declaration. (struct tcb): Add fault_vec field. (TCB_FAULT_INJ, QUAL_FAULT): New macros. * strace.1: Document -e fault expression syntax. * strace.c (usage): Mention -e fault expression. (droptcb): Deallocate fault_vec member. * syscall.c (qual_fault, arch_set_scno, arch_set_error): New prototypes. (qual_options): Add "fault" option. (struct fault_opts): New structure. (num_faults): New variable. (fault_vec): New array. (syscall_fault_injected, tcb_fault_opts, reallocate_fault, find_errno_by_name, qual_syscall_ex, strip_prefix, parse_fault_token, parse_fault_expression, qual_fault, inject_syscall_fault_entering, update_syscall_fault_exiting): New functions. (qual_syscall): Use qual_syscall_ex. (qualify_one): Add argument: a pointer to struct fault_opts, all callers changed. Copy struct fault_opts from the pointer to fault_vec. Use reallocate_fault. (qualify_scno, qualify_syscall_class, qualify_syscall_name): Add argument: a pointer to struct fault_opts. (qualify): Use reallocate_fault. Do not check "all" class for QUAL_FAULT qualifier. (lookup_class): Check for "all" class. (trace_syscall_entering): Use inject_syscall_fault_entering. (trace_syscall_exiting): Use update_syscall_fault_exiting. Clear TCB_FAULT_INJ flag along with TCB_INSYSCALL. Print " (INJECTED)" suffix when the syscall has been injected successfully. [ARCH_REGS_FOR_GETREGSET && !HAVE_GETREGS_OLD] (ptrace_setregset): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregset. [ARCH_REGS_FOR_GETREGS && !HAVE_GETREGS_OLD] (ptrace_setregs): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregs. [ptrace_setregset_or_setregs] (set_regs): New function. Include "set_scno.c" and "set_error.c" * NEWS: Mention this enhancement.
2016-11-16 20:26:58 +03:00
return 0;
--opts->first;
if (opts->first != 0)
return 0;
opts->first = opts->step;
if (!recovering(tcp)) {
if (opts->data.flags & INJECT_F_SIGNAL)
*signo = opts->data.signo;
if (opts->data.flags & (INJECT_F_ERROR | INJECT_F_RETVAL)) {
kernel_long_t scno =
(opts->data.flags & INJECT_F_SYSCALL)
? (kernel_long_t) shuffle_scno(opts->data.scno)
: -1;
if (!arch_set_scno(tcp, scno)) {
tcp->flags |= TCB_TAMPERED;
if (scno != -1)
tcp->flags |= TCB_TAMPERED_NO_FAIL;
}
}
Implement delay injection Add -e inject=SET:delay_enter= and -e inject=SET:delay_exit= options. * configure.ac (AC_SEARCH_LIBS): Check for timer_create -lrt. * delay.c: New file. * Makefile.am (strace_SOURCES): Add it. (strace_LDADD): Add $(timer_LIBS). * defs.h (INJECT_F_DELAY_ENTER, INJECT_F_DELAY_EXIT, TCB_INJECT_DELAY_EXIT, TCB_DELAYED, inject_delay_exit, syscall_delayed): New macros. (alloc_delay_data, fill_delay_data, is_delay_timer_created, arm_delay_timer, delay_tcb): New prototypes. (struct inject_data): Replace reserved field with delay_idx. (struct tcb): Add delay_expiration_time field. * filter_qualify.c (parse_delay_token): New function. (parse_inject_token): Use it. (qualify_inject_common): Initialize struct inject_opts.data.delay_idx. * strace.c: Include <setjmp.h> (timer_jmp_buf, timer_set): New static variables. (timer_sighandler, restart_delayed_tcb, restart_delayed_tcbs): New functions. (init): Block SIGALRM, set SIGALRM handler. (dispatch_event): Do not restart delayed syscalls. (next_event): Unblock SIGALRM during wait4 invocation. * syscall.c (tamper_with_syscall_entering): Arm delay timer if INJECT_F_DELAY_ENTER injection flag is set, set TCB_INJECT_DELAY_EXIT flag if INJECT_F_DELAY_EXIT injection flag is set. tamper_with_syscall_exiting): Arm delay timer if inject_delay_exit. (syscall_exiting_trace): Call tamper_with_syscall_exiting in case of inject_delay_exit. (syscall_exiting_finish): Clear TCB_INJECT_DELAY_EXIT flag. * strace.1.in: Document delay injection. * NEWS: Mention this improvement. Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-02-18 23:21:48 +03:00
if (opts->data.flags & INJECT_F_DELAY_ENTER)
delay_tcb(tcp, opts->data.delay_idx, true);
if (opts->data.flags & INJECT_F_DELAY_EXIT)
tcp->flags |= TCB_INJECT_DELAY_EXIT;
}
Implement syscall fault injection Introduce new -e fault=EXPR syntax that can be used to specify a subset of syscalls that are subject of syscall fault injection, an error code that has to be injected, and a frequency of injection. The expression specifying syscall fault injection has the following format: SET[:error=ERRNO][:when=FIRST[+[STEP]]] where only SET is a required part and all the rest is optional. The method used to implement syscall fault injection is the following: on entering syscall the syscall number is substituted by an invalid syscall number -1, and on exiting syscall the error code returned by the kernel is substituted with the error code specified in the fault expression. This implementaion is based on the prototype developed by Nahim El Atmani as a part of his GSoC 2016 strace project. * defs.h (struct fault_opts): New forward declaration. (struct tcb): Add fault_vec field. (TCB_FAULT_INJ, QUAL_FAULT): New macros. * strace.1: Document -e fault expression syntax. * strace.c (usage): Mention -e fault expression. (droptcb): Deallocate fault_vec member. * syscall.c (qual_fault, arch_set_scno, arch_set_error): New prototypes. (qual_options): Add "fault" option. (struct fault_opts): New structure. (num_faults): New variable. (fault_vec): New array. (syscall_fault_injected, tcb_fault_opts, reallocate_fault, find_errno_by_name, qual_syscall_ex, strip_prefix, parse_fault_token, parse_fault_expression, qual_fault, inject_syscall_fault_entering, update_syscall_fault_exiting): New functions. (qual_syscall): Use qual_syscall_ex. (qualify_one): Add argument: a pointer to struct fault_opts, all callers changed. Copy struct fault_opts from the pointer to fault_vec. Use reallocate_fault. (qualify_scno, qualify_syscall_class, qualify_syscall_name): Add argument: a pointer to struct fault_opts. (qualify): Use reallocate_fault. Do not check "all" class for QUAL_FAULT qualifier. (lookup_class): Check for "all" class. (trace_syscall_entering): Use inject_syscall_fault_entering. (trace_syscall_exiting): Use update_syscall_fault_exiting. Clear TCB_FAULT_INJ flag along with TCB_INSYSCALL. Print " (INJECTED)" suffix when the syscall has been injected successfully. [ARCH_REGS_FOR_GETREGSET && !HAVE_GETREGS_OLD] (ptrace_setregset): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregset. [ARCH_REGS_FOR_GETREGS && !HAVE_GETREGS_OLD] (ptrace_setregs): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregs. [ptrace_setregset_or_setregs] (set_regs): New function. Include "set_scno.c" and "set_error.c" * NEWS: Mention this enhancement.
2016-11-16 20:26:58 +03:00
return 0;
}
static long
tamper_with_syscall_exiting(struct tcb *tcp)
Implement syscall fault injection Introduce new -e fault=EXPR syntax that can be used to specify a subset of syscalls that are subject of syscall fault injection, an error code that has to be injected, and a frequency of injection. The expression specifying syscall fault injection has the following format: SET[:error=ERRNO][:when=FIRST[+[STEP]]] where only SET is a required part and all the rest is optional. The method used to implement syscall fault injection is the following: on entering syscall the syscall number is substituted by an invalid syscall number -1, and on exiting syscall the error code returned by the kernel is substituted with the error code specified in the fault expression. This implementaion is based on the prototype developed by Nahim El Atmani as a part of his GSoC 2016 strace project. * defs.h (struct fault_opts): New forward declaration. (struct tcb): Add fault_vec field. (TCB_FAULT_INJ, QUAL_FAULT): New macros. * strace.1: Document -e fault expression syntax. * strace.c (usage): Mention -e fault expression. (droptcb): Deallocate fault_vec member. * syscall.c (qual_fault, arch_set_scno, arch_set_error): New prototypes. (qual_options): Add "fault" option. (struct fault_opts): New structure. (num_faults): New variable. (fault_vec): New array. (syscall_fault_injected, tcb_fault_opts, reallocate_fault, find_errno_by_name, qual_syscall_ex, strip_prefix, parse_fault_token, parse_fault_expression, qual_fault, inject_syscall_fault_entering, update_syscall_fault_exiting): New functions. (qual_syscall): Use qual_syscall_ex. (qualify_one): Add argument: a pointer to struct fault_opts, all callers changed. Copy struct fault_opts from the pointer to fault_vec. Use reallocate_fault. (qualify_scno, qualify_syscall_class, qualify_syscall_name): Add argument: a pointer to struct fault_opts. (qualify): Use reallocate_fault. Do not check "all" class for QUAL_FAULT qualifier. (lookup_class): Check for "all" class. (trace_syscall_entering): Use inject_syscall_fault_entering. (trace_syscall_exiting): Use update_syscall_fault_exiting. Clear TCB_FAULT_INJ flag along with TCB_INSYSCALL. Print " (INJECTED)" suffix when the syscall has been injected successfully. [ARCH_REGS_FOR_GETREGSET && !HAVE_GETREGS_OLD] (ptrace_setregset): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregset. [ARCH_REGS_FOR_GETREGS && !HAVE_GETREGS_OLD] (ptrace_setregs): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregs. [ptrace_setregset_or_setregs] (set_regs): New function. Include "set_scno.c" and "set_error.c" * NEWS: Mention this enhancement.
2016-11-16 20:26:58 +03:00
{
Implement delay injection Add -e inject=SET:delay_enter= and -e inject=SET:delay_exit= options. * configure.ac (AC_SEARCH_LIBS): Check for timer_create -lrt. * delay.c: New file. * Makefile.am (strace_SOURCES): Add it. (strace_LDADD): Add $(timer_LIBS). * defs.h (INJECT_F_DELAY_ENTER, INJECT_F_DELAY_EXIT, TCB_INJECT_DELAY_EXIT, TCB_DELAYED, inject_delay_exit, syscall_delayed): New macros. (alloc_delay_data, fill_delay_data, is_delay_timer_created, arm_delay_timer, delay_tcb): New prototypes. (struct inject_data): Replace reserved field with delay_idx. (struct tcb): Add delay_expiration_time field. * filter_qualify.c (parse_delay_token): New function. (parse_inject_token): Use it. (qualify_inject_common): Initialize struct inject_opts.data.delay_idx. * strace.c: Include <setjmp.h> (timer_jmp_buf, timer_set): New static variables. (timer_sighandler, restart_delayed_tcb, restart_delayed_tcbs): New functions. (init): Block SIGALRM, set SIGALRM handler. (dispatch_event): Do not restart delayed syscalls. (next_event): Unblock SIGALRM during wait4 invocation. * syscall.c (tamper_with_syscall_entering): Arm delay timer if INJECT_F_DELAY_ENTER injection flag is set, set TCB_INJECT_DELAY_EXIT flag if INJECT_F_DELAY_EXIT injection flag is set. tamper_with_syscall_exiting): Arm delay timer if inject_delay_exit. (syscall_exiting_trace): Call tamper_with_syscall_exiting in case of inject_delay_exit. (syscall_exiting_finish): Clear TCB_INJECT_DELAY_EXIT flag. * strace.1.in: Document delay injection. * NEWS: Mention this improvement. Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-02-18 23:21:48 +03:00
struct inject_opts *opts = tcb_inject_opts(tcp);
if (!opts)
return 0;
if (inject_delay_exit(tcp))
delay_tcb(tcp, opts->data.delay_idx, false);
if (!syscall_tampered(tcp))
return 0;
if (!syserror(tcp) ^ !!syscall_tampered_nofail(tcp)) {
error_msg("Failed to tamper with process %d: unexpectedly got"
" %serror (return value %#" PRI_klx ", error %lu)",
tcp->pid, syscall_tampered_nofail(tcp) ? "" : "no ",
tcp->u_rval, tcp->u_error);
2018-02-07 04:16:50 +03:00
return 1;
}
if (opts->data.flags & INJECT_F_RETVAL)
set_success(tcp, retval_get(opts->data.rval_idx));
else
set_error(tcp, retval_get(opts->data.rval_idx));
Implement syscall fault injection Introduce new -e fault=EXPR syntax that can be used to specify a subset of syscalls that are subject of syscall fault injection, an error code that has to be injected, and a frequency of injection. The expression specifying syscall fault injection has the following format: SET[:error=ERRNO][:when=FIRST[+[STEP]]] where only SET is a required part and all the rest is optional. The method used to implement syscall fault injection is the following: on entering syscall the syscall number is substituted by an invalid syscall number -1, and on exiting syscall the error code returned by the kernel is substituted with the error code specified in the fault expression. This implementaion is based on the prototype developed by Nahim El Atmani as a part of his GSoC 2016 strace project. * defs.h (struct fault_opts): New forward declaration. (struct tcb): Add fault_vec field. (TCB_FAULT_INJ, QUAL_FAULT): New macros. * strace.1: Document -e fault expression syntax. * strace.c (usage): Mention -e fault expression. (droptcb): Deallocate fault_vec member. * syscall.c (qual_fault, arch_set_scno, arch_set_error): New prototypes. (qual_options): Add "fault" option. (struct fault_opts): New structure. (num_faults): New variable. (fault_vec): New array. (syscall_fault_injected, tcb_fault_opts, reallocate_fault, find_errno_by_name, qual_syscall_ex, strip_prefix, parse_fault_token, parse_fault_expression, qual_fault, inject_syscall_fault_entering, update_syscall_fault_exiting): New functions. (qual_syscall): Use qual_syscall_ex. (qualify_one): Add argument: a pointer to struct fault_opts, all callers changed. Copy struct fault_opts from the pointer to fault_vec. Use reallocate_fault. (qualify_scno, qualify_syscall_class, qualify_syscall_name): Add argument: a pointer to struct fault_opts. (qualify): Use reallocate_fault. Do not check "all" class for QUAL_FAULT qualifier. (lookup_class): Check for "all" class. (trace_syscall_entering): Use inject_syscall_fault_entering. (trace_syscall_exiting): Use update_syscall_fault_exiting. Clear TCB_FAULT_INJ flag along with TCB_INSYSCALL. Print " (INJECTED)" suffix when the syscall has been injected successfully. [ARCH_REGS_FOR_GETREGSET && !HAVE_GETREGS_OLD] (ptrace_setregset): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregset. [ARCH_REGS_FOR_GETREGS && !HAVE_GETREGS_OLD] (ptrace_setregs): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregs. [ptrace_setregset_or_setregs] (set_regs): New function. Include "set_scno.c" and "set_error.c" * NEWS: Mention this enhancement.
2016-11-16 20:26:58 +03:00
return 0;
}
/*
* Returns:
* 0: "ignore this ptrace stop", bail out silently.
* 1: ok, decoded; call
* syscall_entering_finish(tcp, syscall_entering_trace(tcp, ...)).
* other: error; call syscall_entering_finish(tcp, res), where res is the value
* returned.
*/
int
syscall_entering_decode(struct tcb *tcp)
{
int res = get_scno(tcp);
if (res == 0)
return res;
int scno_good = res;
if (res != 1 || (res = get_syscall_args(tcp)) != 1) {
printleader(tcp);
tprintf("%s(", scno_good == 1 ? tcp->s_ent->sys_name : "????");
/*
* " <unavailable>" will be added later by the code which
* detects ptrace errors.
*/
return res;
}
#if defined SYS_ipc_subcall \
|| defined SYS_socket_subcall \
|| defined SYS_syscall_subcall
for (;;) {
switch (tcp->s_ent->sen) {
# ifdef SYS_ipc_subcall
case SEN_ipc:
decode_ipc_subcall(tcp);
break;
# endif
# ifdef SYS_socket_subcall
case SEN_socketcall:
decode_socket_subcall(tcp);
break;
# endif
# ifdef SYS_syscall_subcall
case SEN_syscall:
decode_syscall_subcall(tcp);
if (tcp->s_ent->sen != SEN_syscall)
continue;
break;
# endif
}
break;
}
#endif
return 1;
}
int
syscall_entering_trace(struct tcb *tcp, unsigned int *sig)
{
if (hide_log(tcp)) {
/*
* Restrain from fault injection
* while the trace executes strace code.
*/
tcp->qual_flg &= ~QUAL_INJECT;
switch (tcp->s_ent->sen) {
case SEN_execve:
case SEN_execveat:
#if defined SPARC || defined SPARC64
case SEN_execv:
#endif
/*
* First exec* syscall makes the log visible.
*/
tcp->flags &= ~TCB_HIDE_LOG;
/*
* Check whether this exec* syscall succeeds.
*/
tcp->flags |= TCB_CHECK_EXEC_SYSCALL;
break;
}
}
if (hide_log(tcp) || !traced(tcp) || (tracing_paths && !pathtrace_match(tcp))) {
tcp->flags |= TCB_FILTERED;
return 0;
}
tcp->flags &= ~TCB_FILTERED;
if (inject(tcp))
tamper_with_syscall_entering(tcp, sig);
Implement syscall fault injection Introduce new -e fault=EXPR syntax that can be used to specify a subset of syscalls that are subject of syscall fault injection, an error code that has to be injected, and a frequency of injection. The expression specifying syscall fault injection has the following format: SET[:error=ERRNO][:when=FIRST[+[STEP]]] where only SET is a required part and all the rest is optional. The method used to implement syscall fault injection is the following: on entering syscall the syscall number is substituted by an invalid syscall number -1, and on exiting syscall the error code returned by the kernel is substituted with the error code specified in the fault expression. This implementaion is based on the prototype developed by Nahim El Atmani as a part of his GSoC 2016 strace project. * defs.h (struct fault_opts): New forward declaration. (struct tcb): Add fault_vec field. (TCB_FAULT_INJ, QUAL_FAULT): New macros. * strace.1: Document -e fault expression syntax. * strace.c (usage): Mention -e fault expression. (droptcb): Deallocate fault_vec member. * syscall.c (qual_fault, arch_set_scno, arch_set_error): New prototypes. (qual_options): Add "fault" option. (struct fault_opts): New structure. (num_faults): New variable. (fault_vec): New array. (syscall_fault_injected, tcb_fault_opts, reallocate_fault, find_errno_by_name, qual_syscall_ex, strip_prefix, parse_fault_token, parse_fault_expression, qual_fault, inject_syscall_fault_entering, update_syscall_fault_exiting): New functions. (qual_syscall): Use qual_syscall_ex. (qualify_one): Add argument: a pointer to struct fault_opts, all callers changed. Copy struct fault_opts from the pointer to fault_vec. Use reallocate_fault. (qualify_scno, qualify_syscall_class, qualify_syscall_name): Add argument: a pointer to struct fault_opts. (qualify): Use reallocate_fault. Do not check "all" class for QUAL_FAULT qualifier. (lookup_class): Check for "all" class. (trace_syscall_entering): Use inject_syscall_fault_entering. (trace_syscall_exiting): Use update_syscall_fault_exiting. Clear TCB_FAULT_INJ flag along with TCB_INSYSCALL. Print " (INJECTED)" suffix when the syscall has been injected successfully. [ARCH_REGS_FOR_GETREGSET && !HAVE_GETREGS_OLD] (ptrace_setregset): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregset. [ARCH_REGS_FOR_GETREGS && !HAVE_GETREGS_OLD] (ptrace_setregs): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregs. [ptrace_setregset_or_setregs] (set_regs): New function. Include "set_scno.c" and "set_error.c" * NEWS: Mention this enhancement.
2016-11-16 20:26:58 +03:00
if (cflag == CFLAG_ONLY_STATS) {
return 0;
}
#ifdef ENABLE_STACKTRACE
if (stack_trace_enabled) {
if (tcp->s_ent->sys_flags & STACKTRACE_CAPTURE_ON_ENTER)
unwind_tcb_capture(tcp);
}
#endif
printleader(tcp);
tprintf("%s(", tcp->s_ent->sys_name);
int res = raw(tcp) ? printargs(tcp) : tcp->s_ent->sys_func(tcp);
fflush(tcp->outf);
return res;
}
void
syscall_entering_finish(struct tcb *tcp, int res)
{
tcp->flags |= TCB_INSYSCALL;
tcp->sys_func_rval = res;
/* Measure the entrance time as late as possible to avoid errors. */
if ((Tflag || cflag) && !filtered(tcp))
Replace struct timeval with struct timespec in time measurements This is required to implement more precise time measurements. * Makefile.am (strace_LDADD): Add $(clock_LIBS). * defs.h (struct tcb): Change the type of stime, dtime, and etime fields from struct timeval to struct timespec, all users updated. (syscall_exiting_decode, syscall_exiting_trace, count_syscall): Change the type of "struct timeval *" argument to "struct timespec *", all users updated. (tv_nz, tv_cmp, tv_float, tv_add, tv_sub, tv_div, tv_mul): Rename to ts_nz, ts_cmp, ts_float, ts_add, ts_sub, ts_div, and ts_mul. Change the type of all "struct timeval *" arguments to "struct timespec *", all users updated. * util.c (tv_nz, tv_cmp, tv_float, tv_add, tv_sub, tv_div, tv_mul): Rename to ts_nz, ts_cmp, ts_float, ts_add, ts_sub, ts_div, and ts_mul. Change the type of all "struct timeval *" arguments to "struct timespec *". * count.c (struct call_counts): Change the type of "time" field from struct timeval to struct timespec, all users updated. (overhead): Change type from struct timeval to struct timespec, all users updated. (count_syscall): Change the type of "struct timeval *" argument to "struct timespec *". * strace.c (printleader): Change the type of struct timeval variables to struct timespec, call clock_gettime instead of gettimeofday. (next_event, trace_syscall): Change the type of struct timeval variables to struct timespec. * syscall.c (syscall_entering_finish, syscall_exiting_decode): Call clock_gettime instead of gettimeofday.
2018-03-16 03:55:58 +03:00
clock_gettime(CLOCK_MONOTONIC, &tcp->etime);
}
/* Returns:
* 0: "bail out".
* 1: ok.
* -1: error in one of ptrace ops.
*
* If not 0, call syscall_exiting_trace(tcp, res), where res is the return
* value. Anyway, call syscall_exiting_finish(tcp) then.
*/
int
Replace struct timeval with struct timespec in time measurements This is required to implement more precise time measurements. * Makefile.am (strace_LDADD): Add $(clock_LIBS). * defs.h (struct tcb): Change the type of stime, dtime, and etime fields from struct timeval to struct timespec, all users updated. (syscall_exiting_decode, syscall_exiting_trace, count_syscall): Change the type of "struct timeval *" argument to "struct timespec *", all users updated. (tv_nz, tv_cmp, tv_float, tv_add, tv_sub, tv_div, tv_mul): Rename to ts_nz, ts_cmp, ts_float, ts_add, ts_sub, ts_div, and ts_mul. Change the type of all "struct timeval *" arguments to "struct timespec *", all users updated. * util.c (tv_nz, tv_cmp, tv_float, tv_add, tv_sub, tv_div, tv_mul): Rename to ts_nz, ts_cmp, ts_float, ts_add, ts_sub, ts_div, and ts_mul. Change the type of all "struct timeval *" arguments to "struct timespec *". * count.c (struct call_counts): Change the type of "time" field from struct timeval to struct timespec, all users updated. (overhead): Change type from struct timeval to struct timespec, all users updated. (count_syscall): Change the type of "struct timeval *" argument to "struct timespec *". * strace.c (printleader): Change the type of struct timeval variables to struct timespec, call clock_gettime instead of gettimeofday. (next_event, trace_syscall): Change the type of struct timeval variables to struct timespec. * syscall.c (syscall_entering_finish, syscall_exiting_decode): Call clock_gettime instead of gettimeofday.
2018-03-16 03:55:58 +03:00
syscall_exiting_decode(struct tcb *tcp, struct timespec *pts)
{
/* Measure the exit time as early as possible to avoid errors. */
if ((Tflag || cflag) && !filtered(tcp))
Replace struct timeval with struct timespec in time measurements This is required to implement more precise time measurements. * Makefile.am (strace_LDADD): Add $(clock_LIBS). * defs.h (struct tcb): Change the type of stime, dtime, and etime fields from struct timeval to struct timespec, all users updated. (syscall_exiting_decode, syscall_exiting_trace, count_syscall): Change the type of "struct timeval *" argument to "struct timespec *", all users updated. (tv_nz, tv_cmp, tv_float, tv_add, tv_sub, tv_div, tv_mul): Rename to ts_nz, ts_cmp, ts_float, ts_add, ts_sub, ts_div, and ts_mul. Change the type of all "struct timeval *" arguments to "struct timespec *", all users updated. * util.c (tv_nz, tv_cmp, tv_float, tv_add, tv_sub, tv_div, tv_mul): Rename to ts_nz, ts_cmp, ts_float, ts_add, ts_sub, ts_div, and ts_mul. Change the type of all "struct timeval *" arguments to "struct timespec *". * count.c (struct call_counts): Change the type of "time" field from struct timeval to struct timespec, all users updated. (overhead): Change type from struct timeval to struct timespec, all users updated. (count_syscall): Change the type of "struct timeval *" argument to "struct timespec *". * strace.c (printleader): Change the type of struct timeval variables to struct timespec, call clock_gettime instead of gettimeofday. (next_event, trace_syscall): Change the type of struct timeval variables to struct timespec. * syscall.c (syscall_entering_finish, syscall_exiting_decode): Call clock_gettime instead of gettimeofday.
2018-03-16 03:55:58 +03:00
clock_gettime(CLOCK_MONOTONIC, pts);
if (tcp->s_ent->sys_flags & MEMORY_MAPPING_CHANGE)
mmap_notify_report(tcp);
if (filtered(tcp))
return 0;
if (check_exec_syscall(tcp)) {
/* The check failed, hide the log. */
tcp->flags |= TCB_HIDE_LOG;
}
#if SUPPORTED_PERSONALITIES > 1
update_personality(tcp, tcp->currpers);
#endif
return get_syscall_result(tcp);
}
int
Replace struct timeval with struct timespec in time measurements This is required to implement more precise time measurements. * Makefile.am (strace_LDADD): Add $(clock_LIBS). * defs.h (struct tcb): Change the type of stime, dtime, and etime fields from struct timeval to struct timespec, all users updated. (syscall_exiting_decode, syscall_exiting_trace, count_syscall): Change the type of "struct timeval *" argument to "struct timespec *", all users updated. (tv_nz, tv_cmp, tv_float, tv_add, tv_sub, tv_div, tv_mul): Rename to ts_nz, ts_cmp, ts_float, ts_add, ts_sub, ts_div, and ts_mul. Change the type of all "struct timeval *" arguments to "struct timespec *", all users updated. * util.c (tv_nz, tv_cmp, tv_float, tv_add, tv_sub, tv_div, tv_mul): Rename to ts_nz, ts_cmp, ts_float, ts_add, ts_sub, ts_div, and ts_mul. Change the type of all "struct timeval *" arguments to "struct timespec *". * count.c (struct call_counts): Change the type of "time" field from struct timeval to struct timespec, all users updated. (overhead): Change type from struct timeval to struct timespec, all users updated. (count_syscall): Change the type of "struct timeval *" argument to "struct timespec *". * strace.c (printleader): Change the type of struct timeval variables to struct timespec, call clock_gettime instead of gettimeofday. (next_event, trace_syscall): Change the type of struct timeval variables to struct timespec. * syscall.c (syscall_entering_finish, syscall_exiting_decode): Call clock_gettime instead of gettimeofday.
2018-03-16 03:55:58 +03:00
syscall_exiting_trace(struct tcb *tcp, struct timespec *ts, int res)
{
Implement delay injection Add -e inject=SET:delay_enter= and -e inject=SET:delay_exit= options. * configure.ac (AC_SEARCH_LIBS): Check for timer_create -lrt. * delay.c: New file. * Makefile.am (strace_SOURCES): Add it. (strace_LDADD): Add $(timer_LIBS). * defs.h (INJECT_F_DELAY_ENTER, INJECT_F_DELAY_EXIT, TCB_INJECT_DELAY_EXIT, TCB_DELAYED, inject_delay_exit, syscall_delayed): New macros. (alloc_delay_data, fill_delay_data, is_delay_timer_created, arm_delay_timer, delay_tcb): New prototypes. (struct inject_data): Replace reserved field with delay_idx. (struct tcb): Add delay_expiration_time field. * filter_qualify.c (parse_delay_token): New function. (parse_inject_token): Use it. (qualify_inject_common): Initialize struct inject_opts.data.delay_idx. * strace.c: Include <setjmp.h> (timer_jmp_buf, timer_set): New static variables. (timer_sighandler, restart_delayed_tcb, restart_delayed_tcbs): New functions. (init): Block SIGALRM, set SIGALRM handler. (dispatch_event): Do not restart delayed syscalls. (next_event): Unblock SIGALRM during wait4 invocation. * syscall.c (tamper_with_syscall_entering): Arm delay timer if INJECT_F_DELAY_ENTER injection flag is set, set TCB_INJECT_DELAY_EXIT flag if INJECT_F_DELAY_EXIT injection flag is set. tamper_with_syscall_exiting): Arm delay timer if inject_delay_exit. (syscall_exiting_trace): Call tamper_with_syscall_exiting in case of inject_delay_exit. (syscall_exiting_finish): Clear TCB_INJECT_DELAY_EXIT flag. * strace.1.in: Document delay injection. * NEWS: Mention this improvement. Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-02-18 23:21:48 +03:00
if (syscall_tampered(tcp) || inject_delay_exit(tcp))
tamper_with_syscall_exiting(tcp);
Implement syscall fault injection Introduce new -e fault=EXPR syntax that can be used to specify a subset of syscalls that are subject of syscall fault injection, an error code that has to be injected, and a frequency of injection. The expression specifying syscall fault injection has the following format: SET[:error=ERRNO][:when=FIRST[+[STEP]]] where only SET is a required part and all the rest is optional. The method used to implement syscall fault injection is the following: on entering syscall the syscall number is substituted by an invalid syscall number -1, and on exiting syscall the error code returned by the kernel is substituted with the error code specified in the fault expression. This implementaion is based on the prototype developed by Nahim El Atmani as a part of his GSoC 2016 strace project. * defs.h (struct fault_opts): New forward declaration. (struct tcb): Add fault_vec field. (TCB_FAULT_INJ, QUAL_FAULT): New macros. * strace.1: Document -e fault expression syntax. * strace.c (usage): Mention -e fault expression. (droptcb): Deallocate fault_vec member. * syscall.c (qual_fault, arch_set_scno, arch_set_error): New prototypes. (qual_options): Add "fault" option. (struct fault_opts): New structure. (num_faults): New variable. (fault_vec): New array. (syscall_fault_injected, tcb_fault_opts, reallocate_fault, find_errno_by_name, qual_syscall_ex, strip_prefix, parse_fault_token, parse_fault_expression, qual_fault, inject_syscall_fault_entering, update_syscall_fault_exiting): New functions. (qual_syscall): Use qual_syscall_ex. (qualify_one): Add argument: a pointer to struct fault_opts, all callers changed. Copy struct fault_opts from the pointer to fault_vec. Use reallocate_fault. (qualify_scno, qualify_syscall_class, qualify_syscall_name): Add argument: a pointer to struct fault_opts. (qualify): Use reallocate_fault. Do not check "all" class for QUAL_FAULT qualifier. (lookup_class): Check for "all" class. (trace_syscall_entering): Use inject_syscall_fault_entering. (trace_syscall_exiting): Use update_syscall_fault_exiting. Clear TCB_FAULT_INJ flag along with TCB_INSYSCALL. Print " (INJECTED)" suffix when the syscall has been injected successfully. [ARCH_REGS_FOR_GETREGSET && !HAVE_GETREGS_OLD] (ptrace_setregset): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregset. [ARCH_REGS_FOR_GETREGS && !HAVE_GETREGS_OLD] (ptrace_setregs): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregs. [ptrace_setregset_or_setregs] (set_regs): New function. Include "set_scno.c" and "set_error.c" * NEWS: Mention this enhancement.
2016-11-16 20:26:58 +03:00
if (cflag) {
Replace struct timeval with struct timespec in time measurements This is required to implement more precise time measurements. * Makefile.am (strace_LDADD): Add $(clock_LIBS). * defs.h (struct tcb): Change the type of stime, dtime, and etime fields from struct timeval to struct timespec, all users updated. (syscall_exiting_decode, syscall_exiting_trace, count_syscall): Change the type of "struct timeval *" argument to "struct timespec *", all users updated. (tv_nz, tv_cmp, tv_float, tv_add, tv_sub, tv_div, tv_mul): Rename to ts_nz, ts_cmp, ts_float, ts_add, ts_sub, ts_div, and ts_mul. Change the type of all "struct timeval *" arguments to "struct timespec *", all users updated. * util.c (tv_nz, tv_cmp, tv_float, tv_add, tv_sub, tv_div, tv_mul): Rename to ts_nz, ts_cmp, ts_float, ts_add, ts_sub, ts_div, and ts_mul. Change the type of all "struct timeval *" arguments to "struct timespec *". * count.c (struct call_counts): Change the type of "time" field from struct timeval to struct timespec, all users updated. (overhead): Change type from struct timeval to struct timespec, all users updated. (count_syscall): Change the type of "struct timeval *" argument to "struct timespec *". * strace.c (printleader): Change the type of struct timeval variables to struct timespec, call clock_gettime instead of gettimeofday. (next_event, trace_syscall): Change the type of struct timeval variables to struct timespec. * syscall.c (syscall_entering_finish, syscall_exiting_decode): Call clock_gettime instead of gettimeofday.
2018-03-16 03:55:58 +03:00
count_syscall(tcp, ts);
if (cflag == CFLAG_ONLY_STATS) {
return 0;
}
}
/* If not in -ff mode, and printing_tcp != tcp,
* then the log currently does not end with output
* of _our syscall entry_, but with something else.
* We need to say which syscall's return is this.
*
* Forced reprinting via TCB_REPRINT is used only by
* "strace -ff -oLOG test/threaded_execve" corner case.
* It's the only case when -ff mode needs reprinting.
*/
if ((followfork < 2 && printing_tcp != tcp) || (tcp->flags & TCB_REPRINT)) {
tcp->flags &= ~TCB_REPRINT;
printleader(tcp);
tprintf("<... %s resumed> ", tcp->s_ent->sys_name);
}
printing_tcp = tcp;
tcp->s_prev_ent = NULL;
if (res != 1) {
/* There was error in one of prior ptrace ops */
tprints(") ");
tabto();
tprints("= ? <unavailable>\n");
line_ended();
return res;
}
tcp->s_prev_ent = tcp->s_ent;
int sys_res = 0;
if (raw(tcp)) {
/* sys_res = printargs(tcp); - but it's nop on sysexit */
} else {
/* FIXME: not_failing_only (IOW, option -z) is broken:
* failure of syscall is known only after syscall return.
* Thus we end up with something like this on, say, ENOENT:
* open("does_not_exist", O_RDONLY <unfinished ...>
* {next syscall decode}
* whereas the intended result is that open(...) line
* is not shown at all.
*/
if (not_failing_only && tcp->u_error)
return 0; /* ignore failed syscalls */
if (tcp->sys_func_rval & RVAL_DECODED)
sys_res = tcp->sys_func_rval;
else
sys_res = tcp->s_ent->sys_func(tcp);
}
tprints(") ");
tabto();
Implement syscall fault injection Introduce new -e fault=EXPR syntax that can be used to specify a subset of syscalls that are subject of syscall fault injection, an error code that has to be injected, and a frequency of injection. The expression specifying syscall fault injection has the following format: SET[:error=ERRNO][:when=FIRST[+[STEP]]] where only SET is a required part and all the rest is optional. The method used to implement syscall fault injection is the following: on entering syscall the syscall number is substituted by an invalid syscall number -1, and on exiting syscall the error code returned by the kernel is substituted with the error code specified in the fault expression. This implementaion is based on the prototype developed by Nahim El Atmani as a part of his GSoC 2016 strace project. * defs.h (struct fault_opts): New forward declaration. (struct tcb): Add fault_vec field. (TCB_FAULT_INJ, QUAL_FAULT): New macros. * strace.1: Document -e fault expression syntax. * strace.c (usage): Mention -e fault expression. (droptcb): Deallocate fault_vec member. * syscall.c (qual_fault, arch_set_scno, arch_set_error): New prototypes. (qual_options): Add "fault" option. (struct fault_opts): New structure. (num_faults): New variable. (fault_vec): New array. (syscall_fault_injected, tcb_fault_opts, reallocate_fault, find_errno_by_name, qual_syscall_ex, strip_prefix, parse_fault_token, parse_fault_expression, qual_fault, inject_syscall_fault_entering, update_syscall_fault_exiting): New functions. (qual_syscall): Use qual_syscall_ex. (qualify_one): Add argument: a pointer to struct fault_opts, all callers changed. Copy struct fault_opts from the pointer to fault_vec. Use reallocate_fault. (qualify_scno, qualify_syscall_class, qualify_syscall_name): Add argument: a pointer to struct fault_opts. (qualify): Use reallocate_fault. Do not check "all" class for QUAL_FAULT qualifier. (lookup_class): Check for "all" class. (trace_syscall_entering): Use inject_syscall_fault_entering. (trace_syscall_exiting): Use update_syscall_fault_exiting. Clear TCB_FAULT_INJ flag along with TCB_INSYSCALL. Print " (INJECTED)" suffix when the syscall has been injected successfully. [ARCH_REGS_FOR_GETREGSET && !HAVE_GETREGS_OLD] (ptrace_setregset): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregset. [ARCH_REGS_FOR_GETREGS && !HAVE_GETREGS_OLD] (ptrace_setregs): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregs. [ptrace_setregset_or_setregs] (set_regs): New function. Include "set_scno.c" and "set_error.c" * NEWS: Mention this enhancement.
2016-11-16 20:26:58 +03:00
if (raw(tcp)) {
if (tcp->u_error)
print_err_ret(tcp->u_rval, tcp->u_error);
else
tprintf("= %#" PRI_klx, tcp->u_rval);
if (syscall_tampered(tcp))
Implement success injection This extends fault injection syntax with :retval= option. When :retval=VALUE is specified, the syscall number is replaced by -1 and a bogus success VALUE is returned to the callee. * defs.h (fault_opts): Remove err field, add rval field. (MAX_ERRNO_VALUE, FAULT_OPTS_RVAL_DEFAULT, FAULT_OPTS_RVAL_DISABLE): New macros. * qualify.c (parse_fault_token): Handle retval= token. (qualify_fault): Update fault_opts initialization after the move from struct fault_opts.err to struct fault_opts.rval. * syscall.c (arch_set_success): New prototype. (inject_syscall_fault_entering): Check opts->rval instead of opts->err. (update_syscall_fault_exiting): Implement retval injection. * strace.1: Update the section on fault injection. * NEWS: Mention retval= option. * linux/aarch64/set_error.c (arch_set_success): New function. * linux/alpha/set_error.c: Likewise. * linux/arc/set_error.c: Likewise. * linux/arm/set_error.c: Likewise. * linux/avr32/set_error.c: Likewise. * linux/bfin/set_error.c: Likewise. * linux/crisv10/set_error.c: Likewise. * linux/hppa/set_error.c: Likewise. * linux/i386/set_error.c: Likewise. * linux/ia64/set_error.c: Likewise. * linux/m68k/set_error.c: Likewise. * linux/metag/set_error.c: Likewise. * linux/microblaze/set_error.c: Likewise. * linux/mips/set_error.c: Likewise. * linux/nios2/set_error.c: Likewise. * linux/or1k/set_error.c: Likewise. * linux/powerpc/set_error.c: Likewise. * linux/riscv/set_error.c: Likewise. * linux/s390/set_error.c: Likewise. * linux/sh/set_error.c: Likewise. * linux/sh64/set_error.c: Likewise. * linux/sparc/set_error.c: Likewise. * linux/sparc64/set_error.c: Likewise. * linux/tile/set_error.c: Likewise. * linux/x86_64/set_error.c: Likewise. * linux/xtensa/set_error.c: Likewise. Closes: https://github.com/strace/strace/issues/3
2017-01-25 02:59:16 +03:00
tprints(" (INJECTED)");
} else if (!(sys_res & RVAL_NONE) && tcp->u_error) {
switch (tcp->u_error) {
/* Blocked signals do not interrupt any syscalls.
* In this case syscalls don't return ERESTARTfoo codes.
*
* Deadly signals set to SIG_DFL interrupt syscalls
* and kill the process regardless of which of the codes below
* is returned by the interrupted syscall.
* In some cases, kernel forces a kernel-generated deadly
* signal to be unblocked and set to SIG_DFL (and thus cause
* death) if it is blocked or SIG_IGNed: for example, SIGSEGV
* or SIGILL. (The alternative is to leave process spinning
* forever on the faulty instruction - not useful).
*
* SIG_IGNed signals and non-deadly signals set to SIG_DFL
* (for example, SIGCHLD, SIGWINCH) interrupt syscalls,
* but kernel will always restart them.
*/
case ERESTARTSYS:
/* Most common type of signal-interrupted syscall exit code.
* The system call will be restarted with the same arguments
* if SA_RESTART is set; otherwise, it will fail with EINTR.
*/
tprints("= ? ERESTARTSYS (To be restarted if SA_RESTART is set)");
break;
case ERESTARTNOINTR:
/* Rare. For example, fork() returns this if interrupted.
* SA_RESTART is ignored (assumed set): the restart is unconditional.
*/
tprints("= ? ERESTARTNOINTR (To be restarted)");
break;
case ERESTARTNOHAND:
/* pause(), rt_sigsuspend() etc use this code.
* SA_RESTART is ignored (assumed not set):
* syscall won't restart (will return EINTR instead)
* even after signal with SA_RESTART set. However,
* after SIG_IGN or SIG_DFL signal it will restart
* (thus the name "restart only if has no handler").
*/
tprints("= ? ERESTARTNOHAND (To be restarted if no handler)");
break;
case ERESTART_RESTARTBLOCK:
/* Syscalls like nanosleep(), poll() which can't be
* restarted with their original arguments use this
* code. Kernel will execute restart_syscall() instead,
* which changes arguments before restarting syscall.
* SA_RESTART is ignored (assumed not set) similarly
* to ERESTARTNOHAND. (Kernel can't honor SA_RESTART
* since restart data is saved in "restart block"
* in task struct, and if signal handler uses a syscall
* which in turn saves another such restart block,
* old data is lost and restart becomes impossible)
*/
tprints("= ? ERESTART_RESTARTBLOCK (Interrupted by signal)");
break;
default:
print_err_ret(tcp->u_rval, tcp->u_error);
break;
}
if (syscall_tampered(tcp))
tprints(" (INJECTED)");
if ((sys_res & RVAL_STR) && tcp->auxstr)
tprintf(" (%s)", tcp->auxstr);
} else {
if (sys_res & RVAL_NONE)
tprints("= ?");
else {
switch (sys_res & RVAL_MASK) {
case RVAL_HEX:
#if ANY_WORDSIZE_LESS_THAN_KERNEL_LONG
if (current_klongsize < sizeof(tcp->u_rval)) {
tprintf("= %#x",
(unsigned int) tcp->u_rval);
} else
#endif
{
tprintf("= %#" PRI_klx, tcp->u_rval);
}
break;
case RVAL_OCTAL:
Fix printing of mode_t, umode_t, and umask types Print numeric umode_t type using %#03ho format. Print return value of umask syscall using %#03lo format. When printing symbolic mode_t type, always print lower 9 bits, and print the numeric part using %#03o format. * defs.h (sprintmode): Remove. (print_symbolic_mode_t, print_numeric_umode_t, print_numeric_long_umask): New prototypes. * printmode.c (sprintmode): Remove. (print_symbolic_mode_t, print_numeric_umode_t, print_numeric_long_umask): New functions. * chmod.c (decode_chmod): Use print_numeric_umode_t. * ipc_msg.c (SYS_FUNC(msgget)): Likewise. * ipc_msgctl.c (print_msqid_ds): Likewise. * ipc_sem.c (SYS_FUNC(semget)): Likewise. * ipc_shm.c (SYS_FUNC(shmget)): Likewise. * ipc_shmctl.c (print_shmid_ds): Likewise. * mq.c (SYS_FUNC(mq_open)): Likewise. * open.c (decode_open, SYS_FUNC(creat)): Likewise. * umask.c (SYS_FUNC(umask)): Likewise. * mknod.c (decode_mknod): Use print_symbolic_mode_t. * printstat.h (DO_PRINTSTAT): Likewise. * syscall.c (trace_syscall_exiting): Use print_numeric_long_umask. * tests/umode_t.c: New file. * tests/Makefile.am (EXTRA_DIST): Add it. * tests/creat.c: Rewrite as a thin wrapper around umode_t.c * tests/mkdir.c: Likewise. * tests/mkdirat.c: Likewise. * tests/mknod.c: Extend test coverage of mknod syscall. * tests/mknodat.c: Extend test coverage of mknodat syscall. * tests/umask.c: Extend test coverage of umask syscall. * tests/creat.test: Update the value specified for strace -a parameter. * tests/mkdir.test: Likewise. * tests/mkdirat.test: Likewise. * tests/mknodat.test: Likewise.
2016-08-03 17:05:39 +03:00
tprints("= ");
print_numeric_long_umask(tcp->u_rval);
break;
case RVAL_UDECIMAL:
#if ANY_WORDSIZE_LESS_THAN_KERNEL_LONG
if (current_klongsize < sizeof(tcp->u_rval)) {
tprintf("= %u",
(unsigned int) tcp->u_rval);
} else
#endif
{
tprintf("= %" PRI_klu, tcp->u_rval);
}
break;
case RVAL_FD:
if (show_fd_path) {
tprints("= ");
printfd(tcp, tcp->u_rval);
} else
tprintf("= %" PRI_kld, tcp->u_rval);
break;
default:
error_msg("invalid rval format");
break;
}
}
if ((sys_res & RVAL_STR) && tcp->auxstr)
tprintf(" (%s)", tcp->auxstr);
if (syscall_tampered(tcp))
Implement success injection This extends fault injection syntax with :retval= option. When :retval=VALUE is specified, the syscall number is replaced by -1 and a bogus success VALUE is returned to the callee. * defs.h (fault_opts): Remove err field, add rval field. (MAX_ERRNO_VALUE, FAULT_OPTS_RVAL_DEFAULT, FAULT_OPTS_RVAL_DISABLE): New macros. * qualify.c (parse_fault_token): Handle retval= token. (qualify_fault): Update fault_opts initialization after the move from struct fault_opts.err to struct fault_opts.rval. * syscall.c (arch_set_success): New prototype. (inject_syscall_fault_entering): Check opts->rval instead of opts->err. (update_syscall_fault_exiting): Implement retval injection. * strace.1: Update the section on fault injection. * NEWS: Mention retval= option. * linux/aarch64/set_error.c (arch_set_success): New function. * linux/alpha/set_error.c: Likewise. * linux/arc/set_error.c: Likewise. * linux/arm/set_error.c: Likewise. * linux/avr32/set_error.c: Likewise. * linux/bfin/set_error.c: Likewise. * linux/crisv10/set_error.c: Likewise. * linux/hppa/set_error.c: Likewise. * linux/i386/set_error.c: Likewise. * linux/ia64/set_error.c: Likewise. * linux/m68k/set_error.c: Likewise. * linux/metag/set_error.c: Likewise. * linux/microblaze/set_error.c: Likewise. * linux/mips/set_error.c: Likewise. * linux/nios2/set_error.c: Likewise. * linux/or1k/set_error.c: Likewise. * linux/powerpc/set_error.c: Likewise. * linux/riscv/set_error.c: Likewise. * linux/s390/set_error.c: Likewise. * linux/sh/set_error.c: Likewise. * linux/sh64/set_error.c: Likewise. * linux/sparc/set_error.c: Likewise. * linux/sparc64/set_error.c: Likewise. * linux/tile/set_error.c: Likewise. * linux/x86_64/set_error.c: Likewise. * linux/xtensa/set_error.c: Likewise. Closes: https://github.com/strace/strace/issues/3
2017-01-25 02:59:16 +03:00
tprints(" (INJECTED)");
}
if (Tflag) {
Replace struct timeval with struct timespec in time measurements This is required to implement more precise time measurements. * Makefile.am (strace_LDADD): Add $(clock_LIBS). * defs.h (struct tcb): Change the type of stime, dtime, and etime fields from struct timeval to struct timespec, all users updated. (syscall_exiting_decode, syscall_exiting_trace, count_syscall): Change the type of "struct timeval *" argument to "struct timespec *", all users updated. (tv_nz, tv_cmp, tv_float, tv_add, tv_sub, tv_div, tv_mul): Rename to ts_nz, ts_cmp, ts_float, ts_add, ts_sub, ts_div, and ts_mul. Change the type of all "struct timeval *" arguments to "struct timespec *", all users updated. * util.c (tv_nz, tv_cmp, tv_float, tv_add, tv_sub, tv_div, tv_mul): Rename to ts_nz, ts_cmp, ts_float, ts_add, ts_sub, ts_div, and ts_mul. Change the type of all "struct timeval *" arguments to "struct timespec *". * count.c (struct call_counts): Change the type of "time" field from struct timeval to struct timespec, all users updated. (overhead): Change type from struct timeval to struct timespec, all users updated. (count_syscall): Change the type of "struct timeval *" argument to "struct timespec *". * strace.c (printleader): Change the type of struct timeval variables to struct timespec, call clock_gettime instead of gettimeofday. (next_event, trace_syscall): Change the type of struct timeval variables to struct timespec. * syscall.c (syscall_entering_finish, syscall_exiting_decode): Call clock_gettime instead of gettimeofday.
2018-03-16 03:55:58 +03:00
ts_sub(ts, ts, &tcp->etime);
tprintf(" <%ld.%06ld>",
Replace struct timeval with struct timespec in time measurements This is required to implement more precise time measurements. * Makefile.am (strace_LDADD): Add $(clock_LIBS). * defs.h (struct tcb): Change the type of stime, dtime, and etime fields from struct timeval to struct timespec, all users updated. (syscall_exiting_decode, syscall_exiting_trace, count_syscall): Change the type of "struct timeval *" argument to "struct timespec *", all users updated. (tv_nz, tv_cmp, tv_float, tv_add, tv_sub, tv_div, tv_mul): Rename to ts_nz, ts_cmp, ts_float, ts_add, ts_sub, ts_div, and ts_mul. Change the type of all "struct timeval *" arguments to "struct timespec *", all users updated. * util.c (tv_nz, tv_cmp, tv_float, tv_add, tv_sub, tv_div, tv_mul): Rename to ts_nz, ts_cmp, ts_float, ts_add, ts_sub, ts_div, and ts_mul. Change the type of all "struct timeval *" arguments to "struct timespec *". * count.c (struct call_counts): Change the type of "time" field from struct timeval to struct timespec, all users updated. (overhead): Change type from struct timeval to struct timespec, all users updated. (count_syscall): Change the type of "struct timeval *" argument to "struct timespec *". * strace.c (printleader): Change the type of struct timeval variables to struct timespec, call clock_gettime instead of gettimeofday. (next_event, trace_syscall): Change the type of struct timeval variables to struct timespec. * syscall.c (syscall_entering_finish, syscall_exiting_decode): Call clock_gettime instead of gettimeofday.
2018-03-16 03:55:58 +03:00
(long) ts->tv_sec, (long) ts->tv_nsec / 1000);
}
tprints("\n");
dumpio(tcp);
line_ended();
#ifdef ENABLE_STACKTRACE
if (stack_trace_enabled)
unwind_tcb_print(tcp);
#endif
return 0;
}
void
syscall_exiting_finish(struct tcb *tcp)
{
Implement delay injection Add -e inject=SET:delay_enter= and -e inject=SET:delay_exit= options. * configure.ac (AC_SEARCH_LIBS): Check for timer_create -lrt. * delay.c: New file. * Makefile.am (strace_SOURCES): Add it. (strace_LDADD): Add $(timer_LIBS). * defs.h (INJECT_F_DELAY_ENTER, INJECT_F_DELAY_EXIT, TCB_INJECT_DELAY_EXIT, TCB_DELAYED, inject_delay_exit, syscall_delayed): New macros. (alloc_delay_data, fill_delay_data, is_delay_timer_created, arm_delay_timer, delay_tcb): New prototypes. (struct inject_data): Replace reserved field with delay_idx. (struct tcb): Add delay_expiration_time field. * filter_qualify.c (parse_delay_token): New function. (parse_inject_token): Use it. (qualify_inject_common): Initialize struct inject_opts.data.delay_idx. * strace.c: Include <setjmp.h> (timer_jmp_buf, timer_set): New static variables. (timer_sighandler, restart_delayed_tcb, restart_delayed_tcbs): New functions. (init): Block SIGALRM, set SIGALRM handler. (dispatch_event): Do not restart delayed syscalls. (next_event): Unblock SIGALRM during wait4 invocation. * syscall.c (tamper_with_syscall_entering): Arm delay timer if INJECT_F_DELAY_ENTER injection flag is set, set TCB_INJECT_DELAY_EXIT flag if INJECT_F_DELAY_EXIT injection flag is set. tamper_with_syscall_exiting): Arm delay timer if inject_delay_exit. (syscall_exiting_trace): Call tamper_with_syscall_exiting in case of inject_delay_exit. (syscall_exiting_finish): Clear TCB_INJECT_DELAY_EXIT flag. * strace.1.in: Document delay injection. * NEWS: Mention this improvement. Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-02-18 23:21:48 +03:00
tcp->flags &= ~(TCB_INSYSCALL | TCB_TAMPERED | TCB_INJECT_DELAY_EXIT);
tcp->sys_func_rval = 0;
free_tcb_priv_data(tcp);
}
bool
is_erestart(struct tcb *tcp)
{
switch (tcp->u_error) {
case ERESTARTSYS:
case ERESTARTNOINTR:
case ERESTARTNOHAND:
case ERESTART_RESTARTBLOCK:
return true;
default:
return false;
}
}
static unsigned long saved_u_error;
void
temporarily_clear_syserror(struct tcb *tcp)
{
saved_u_error = tcp->u_error;
tcp->u_error = 0;
}
void
restore_cleared_syserror(struct tcb *tcp)
{
tcp->u_error = saved_u_error;
}
Introduce PTRACE_GET_SYSCALL_INFO support When PTRACE_GET_SYSCALL_INFO API works, use it instead of traditional upeek/get_regs API. Tested on x86_64 and x86. * get_personality.c: New file. * get_personality.h: Likewise. * Makefile.am (strace_SOURCES): Add them. * linux/aarch64/arch_get_personality.c: New file. * linux/powerpc64/arch_get_personality.c: Likewise. * linux/riscv/arch_get_personality.c: Likewise. * linux/s390x/arch_get_personality.c: Likewise. * linux/sparc64/arch_get_personality.c: Likewise. * linux/tile/arch_get_personality.c: Likewise. * linux/x32/arch_get_personality.c: Likewise. * linux/x86_64/arch_get_personality.c: Likewise. * linux/check_scno.c: Likewise. * linux/x32/check_scno.c: Likewise. * Makefile.am (EXTRA_DIST): Add them. * linux/ia64/arch_getrval2.c (getrval2): Invoke get_regs() if ptrace_syscall_info is in use. * linux/mips/arch_getrval2.c: Likewise. * linux/sparc/arch_getrval2.c: Likewise. * defs.h (get_personality_from_syscall_info): New prototype. * syscall.c: Include "get_personality.h" and "ptrace_syscall_info.h". (get_regs_error): Define unconditionally. (ptrace_sci): New static variable. (clear_regs): Reset ptrace_sci.op. (ptrace_syscall_info_is_valid, ptrace_get_syscall_info, get_syscall_regs): New functions. (get_syscall_result_regs): Change to get_syscall_regs. (get_instruction_pointer, get_stack_pointer, get_scno, get_syscall_args, get_error, set_error, set_success): Add ptrace_syscall_info support. * tests/int_0x80.test: New test. * tests/Makefile.am (DECODER_TESTS): Add int_0x80.test. (XFAIL_TESTS_x86_64, XFAIL_TESTS_x32): Remove. * tests/gen_tests.in (int_0x80): Remove.
2018-11-21 04:44:16 +03:00
static struct ptrace_syscall_info ptrace_sci;
static bool
ptrace_syscall_info_is_valid(void)
{
return ptrace_get_syscall_info_supported &&
ptrace_sci.op <= PTRACE_SYSCALL_INFO_SECCOMP;
}
#define XLAT_MACROS_ONLY
#include "xlat/nt_descriptor_types.h"
#undef XLAT_MACROS_ONLY
#define ARCH_MIGHT_USE_SET_REGS 1
Introduce PTRACE_GET_SYSCALL_INFO support When PTRACE_GET_SYSCALL_INFO API works, use it instead of traditional upeek/get_regs API. Tested on x86_64 and x86. * get_personality.c: New file. * get_personality.h: Likewise. * Makefile.am (strace_SOURCES): Add them. * linux/aarch64/arch_get_personality.c: New file. * linux/powerpc64/arch_get_personality.c: Likewise. * linux/riscv/arch_get_personality.c: Likewise. * linux/s390x/arch_get_personality.c: Likewise. * linux/sparc64/arch_get_personality.c: Likewise. * linux/tile/arch_get_personality.c: Likewise. * linux/x32/arch_get_personality.c: Likewise. * linux/x86_64/arch_get_personality.c: Likewise. * linux/check_scno.c: Likewise. * linux/x32/check_scno.c: Likewise. * Makefile.am (EXTRA_DIST): Add them. * linux/ia64/arch_getrval2.c (getrval2): Invoke get_regs() if ptrace_syscall_info is in use. * linux/mips/arch_getrval2.c: Likewise. * linux/sparc/arch_getrval2.c: Likewise. * defs.h (get_personality_from_syscall_info): New prototype. * syscall.c: Include "get_personality.h" and "ptrace_syscall_info.h". (get_regs_error): Define unconditionally. (ptrace_sci): New static variable. (clear_regs): Reset ptrace_sci.op. (ptrace_syscall_info_is_valid, ptrace_get_syscall_info, get_syscall_regs): New functions. (get_syscall_result_regs): Change to get_syscall_regs. (get_instruction_pointer, get_stack_pointer, get_scno, get_syscall_args, get_error, set_error, set_success): Add ptrace_syscall_info support. * tests/int_0x80.test: New test. * tests/Makefile.am (DECODER_TESTS): Add int_0x80.test. (XFAIL_TESTS_x86_64, XFAIL_TESTS_x32): Remove. * tests/gen_tests.in (int_0x80): Remove.
2018-11-21 04:44:16 +03:00
#include "arch_regs.c"
#if HAVE_ARCH_GETRVAL2
# include "arch_getrval2.c"
#endif
#include "getregs_old.h"
#ifdef HAVE_GETREGS_OLD
/* Either getregs_old() or set_regs() */
# undef ARCH_MIGHT_USE_SET_REGS
# define ARCH_MIGHT_USE_SET_REGS 0
#endif
#undef ptrace_getregset_or_getregs
Implement syscall fault injection Introduce new -e fault=EXPR syntax that can be used to specify a subset of syscalls that are subject of syscall fault injection, an error code that has to be injected, and a frequency of injection. The expression specifying syscall fault injection has the following format: SET[:error=ERRNO][:when=FIRST[+[STEP]]] where only SET is a required part and all the rest is optional. The method used to implement syscall fault injection is the following: on entering syscall the syscall number is substituted by an invalid syscall number -1, and on exiting syscall the error code returned by the kernel is substituted with the error code specified in the fault expression. This implementaion is based on the prototype developed by Nahim El Atmani as a part of his GSoC 2016 strace project. * defs.h (struct fault_opts): New forward declaration. (struct tcb): Add fault_vec field. (TCB_FAULT_INJ, QUAL_FAULT): New macros. * strace.1: Document -e fault expression syntax. * strace.c (usage): Mention -e fault expression. (droptcb): Deallocate fault_vec member. * syscall.c (qual_fault, arch_set_scno, arch_set_error): New prototypes. (qual_options): Add "fault" option. (struct fault_opts): New structure. (num_faults): New variable. (fault_vec): New array. (syscall_fault_injected, tcb_fault_opts, reallocate_fault, find_errno_by_name, qual_syscall_ex, strip_prefix, parse_fault_token, parse_fault_expression, qual_fault, inject_syscall_fault_entering, update_syscall_fault_exiting): New functions. (qual_syscall): Use qual_syscall_ex. (qualify_one): Add argument: a pointer to struct fault_opts, all callers changed. Copy struct fault_opts from the pointer to fault_vec. Use reallocate_fault. (qualify_scno, qualify_syscall_class, qualify_syscall_name): Add argument: a pointer to struct fault_opts. (qualify): Use reallocate_fault. Do not check "all" class for QUAL_FAULT qualifier. (lookup_class): Check for "all" class. (trace_syscall_entering): Use inject_syscall_fault_entering. (trace_syscall_exiting): Use update_syscall_fault_exiting. Clear TCB_FAULT_INJ flag along with TCB_INSYSCALL. Print " (INJECTED)" suffix when the syscall has been injected successfully. [ARCH_REGS_FOR_GETREGSET && !HAVE_GETREGS_OLD] (ptrace_setregset): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregset. [ARCH_REGS_FOR_GETREGS && !HAVE_GETREGS_OLD] (ptrace_setregs): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregs. [ptrace_setregset_or_setregs] (set_regs): New function. Include "set_scno.c" and "set_error.c" * NEWS: Mention this enhancement.
2016-11-16 20:26:58 +03:00
#undef ptrace_setregset_or_setregs
#ifdef ARCH_REGS_FOR_GETREGSET
# define ptrace_getregset_or_getregs ptrace_getregset
static long
ptrace_getregset(pid_t pid)
{
# ifdef ARCH_IOVEC_FOR_GETREGSET
/* variable iovec */
ARCH_IOVEC_FOR_GETREGSET.iov_len = sizeof(ARCH_REGS_FOR_GETREGSET);
return ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS,
&ARCH_IOVEC_FOR_GETREGSET);
# else
/* constant iovec */
static struct iovec io = {
.iov_base = &ARCH_REGS_FOR_GETREGSET,
.iov_len = sizeof(ARCH_REGS_FOR_GETREGSET)
};
return ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &io);
# endif
}
# if ARCH_MIGHT_USE_SET_REGS
Implement syscall fault injection Introduce new -e fault=EXPR syntax that can be used to specify a subset of syscalls that are subject of syscall fault injection, an error code that has to be injected, and a frequency of injection. The expression specifying syscall fault injection has the following format: SET[:error=ERRNO][:when=FIRST[+[STEP]]] where only SET is a required part and all the rest is optional. The method used to implement syscall fault injection is the following: on entering syscall the syscall number is substituted by an invalid syscall number -1, and on exiting syscall the error code returned by the kernel is substituted with the error code specified in the fault expression. This implementaion is based on the prototype developed by Nahim El Atmani as a part of his GSoC 2016 strace project. * defs.h (struct fault_opts): New forward declaration. (struct tcb): Add fault_vec field. (TCB_FAULT_INJ, QUAL_FAULT): New macros. * strace.1: Document -e fault expression syntax. * strace.c (usage): Mention -e fault expression. (droptcb): Deallocate fault_vec member. * syscall.c (qual_fault, arch_set_scno, arch_set_error): New prototypes. (qual_options): Add "fault" option. (struct fault_opts): New structure. (num_faults): New variable. (fault_vec): New array. (syscall_fault_injected, tcb_fault_opts, reallocate_fault, find_errno_by_name, qual_syscall_ex, strip_prefix, parse_fault_token, parse_fault_expression, qual_fault, inject_syscall_fault_entering, update_syscall_fault_exiting): New functions. (qual_syscall): Use qual_syscall_ex. (qualify_one): Add argument: a pointer to struct fault_opts, all callers changed. Copy struct fault_opts from the pointer to fault_vec. Use reallocate_fault. (qualify_scno, qualify_syscall_class, qualify_syscall_name): Add argument: a pointer to struct fault_opts. (qualify): Use reallocate_fault. Do not check "all" class for QUAL_FAULT qualifier. (lookup_class): Check for "all" class. (trace_syscall_entering): Use inject_syscall_fault_entering. (trace_syscall_exiting): Use update_syscall_fault_exiting. Clear TCB_FAULT_INJ flag along with TCB_INSYSCALL. Print " (INJECTED)" suffix when the syscall has been injected successfully. [ARCH_REGS_FOR_GETREGSET && !HAVE_GETREGS_OLD] (ptrace_setregset): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregset. [ARCH_REGS_FOR_GETREGS && !HAVE_GETREGS_OLD] (ptrace_setregs): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregs. [ptrace_setregset_or_setregs] (set_regs): New function. Include "set_scno.c" and "set_error.c" * NEWS: Mention this enhancement.
2016-11-16 20:26:58 +03:00
# define ptrace_setregset_or_setregs ptrace_setregset
static int
ptrace_setregset(pid_t pid)
{
# ifdef ARCH_IOVEC_FOR_GETREGSET
/* variable iovec */
return ptrace(PTRACE_SETREGSET, pid, NT_PRSTATUS,
&ARCH_IOVEC_FOR_GETREGSET);
# else
/* constant iovec */
static struct iovec io = {
.iov_base = &ARCH_REGS_FOR_GETREGSET,
.iov_len = sizeof(ARCH_REGS_FOR_GETREGSET)
};
return ptrace(PTRACE_SETREGSET, pid, NT_PRSTATUS, &io);
# endif
}
# endif /* ARCH_MIGHT_USE_SET_REGS */
Implement syscall fault injection Introduce new -e fault=EXPR syntax that can be used to specify a subset of syscalls that are subject of syscall fault injection, an error code that has to be injected, and a frequency of injection. The expression specifying syscall fault injection has the following format: SET[:error=ERRNO][:when=FIRST[+[STEP]]] where only SET is a required part and all the rest is optional. The method used to implement syscall fault injection is the following: on entering syscall the syscall number is substituted by an invalid syscall number -1, and on exiting syscall the error code returned by the kernel is substituted with the error code specified in the fault expression. This implementaion is based on the prototype developed by Nahim El Atmani as a part of his GSoC 2016 strace project. * defs.h (struct fault_opts): New forward declaration. (struct tcb): Add fault_vec field. (TCB_FAULT_INJ, QUAL_FAULT): New macros. * strace.1: Document -e fault expression syntax. * strace.c (usage): Mention -e fault expression. (droptcb): Deallocate fault_vec member. * syscall.c (qual_fault, arch_set_scno, arch_set_error): New prototypes. (qual_options): Add "fault" option. (struct fault_opts): New structure. (num_faults): New variable. (fault_vec): New array. (syscall_fault_injected, tcb_fault_opts, reallocate_fault, find_errno_by_name, qual_syscall_ex, strip_prefix, parse_fault_token, parse_fault_expression, qual_fault, inject_syscall_fault_entering, update_syscall_fault_exiting): New functions. (qual_syscall): Use qual_syscall_ex. (qualify_one): Add argument: a pointer to struct fault_opts, all callers changed. Copy struct fault_opts from the pointer to fault_vec. Use reallocate_fault. (qualify_scno, qualify_syscall_class, qualify_syscall_name): Add argument: a pointer to struct fault_opts. (qualify): Use reallocate_fault. Do not check "all" class for QUAL_FAULT qualifier. (lookup_class): Check for "all" class. (trace_syscall_entering): Use inject_syscall_fault_entering. (trace_syscall_exiting): Use update_syscall_fault_exiting. Clear TCB_FAULT_INJ flag along with TCB_INSYSCALL. Print " (INJECTED)" suffix when the syscall has been injected successfully. [ARCH_REGS_FOR_GETREGSET && !HAVE_GETREGS_OLD] (ptrace_setregset): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregset. [ARCH_REGS_FOR_GETREGS && !HAVE_GETREGS_OLD] (ptrace_setregs): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregs. [ptrace_setregset_or_setregs] (set_regs): New function. Include "set_scno.c" and "set_error.c" * NEWS: Mention this enhancement.
2016-11-16 20:26:58 +03:00
#elif defined ARCH_REGS_FOR_GETREGS
# define ptrace_getregset_or_getregs ptrace_getregs
static long
ptrace_getregs(pid_t pid)
{
# if defined SPARC || defined SPARC64
/* SPARC systems have the meaning of data and addr reversed */
return ptrace(PTRACE_GETREGS, pid, (void *) &ARCH_REGS_FOR_GETREGS, 0);
# else
return ptrace(PTRACE_GETREGS, pid, NULL, &ARCH_REGS_FOR_GETREGS);
# endif
}
# if ARCH_MIGHT_USE_SET_REGS
Implement syscall fault injection Introduce new -e fault=EXPR syntax that can be used to specify a subset of syscalls that are subject of syscall fault injection, an error code that has to be injected, and a frequency of injection. The expression specifying syscall fault injection has the following format: SET[:error=ERRNO][:when=FIRST[+[STEP]]] where only SET is a required part and all the rest is optional. The method used to implement syscall fault injection is the following: on entering syscall the syscall number is substituted by an invalid syscall number -1, and on exiting syscall the error code returned by the kernel is substituted with the error code specified in the fault expression. This implementaion is based on the prototype developed by Nahim El Atmani as a part of his GSoC 2016 strace project. * defs.h (struct fault_opts): New forward declaration. (struct tcb): Add fault_vec field. (TCB_FAULT_INJ, QUAL_FAULT): New macros. * strace.1: Document -e fault expression syntax. * strace.c (usage): Mention -e fault expression. (droptcb): Deallocate fault_vec member. * syscall.c (qual_fault, arch_set_scno, arch_set_error): New prototypes. (qual_options): Add "fault" option. (struct fault_opts): New structure. (num_faults): New variable. (fault_vec): New array. (syscall_fault_injected, tcb_fault_opts, reallocate_fault, find_errno_by_name, qual_syscall_ex, strip_prefix, parse_fault_token, parse_fault_expression, qual_fault, inject_syscall_fault_entering, update_syscall_fault_exiting): New functions. (qual_syscall): Use qual_syscall_ex. (qualify_one): Add argument: a pointer to struct fault_opts, all callers changed. Copy struct fault_opts from the pointer to fault_vec. Use reallocate_fault. (qualify_scno, qualify_syscall_class, qualify_syscall_name): Add argument: a pointer to struct fault_opts. (qualify): Use reallocate_fault. Do not check "all" class for QUAL_FAULT qualifier. (lookup_class): Check for "all" class. (trace_syscall_entering): Use inject_syscall_fault_entering. (trace_syscall_exiting): Use update_syscall_fault_exiting. Clear TCB_FAULT_INJ flag along with TCB_INSYSCALL. Print " (INJECTED)" suffix when the syscall has been injected successfully. [ARCH_REGS_FOR_GETREGSET && !HAVE_GETREGS_OLD] (ptrace_setregset): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregset. [ARCH_REGS_FOR_GETREGS && !HAVE_GETREGS_OLD] (ptrace_setregs): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregs. [ptrace_setregset_or_setregs] (set_regs): New function. Include "set_scno.c" and "set_error.c" * NEWS: Mention this enhancement.
2016-11-16 20:26:58 +03:00
# define ptrace_setregset_or_setregs ptrace_setregs
static int
ptrace_setregs(pid_t pid)
{
# if defined SPARC || defined SPARC64
/* SPARC systems have the meaning of data and addr reversed */
return ptrace(PTRACE_SETREGS, pid, (void *) &ARCH_REGS_FOR_GETREGS, 0);
# else
return ptrace(PTRACE_SETREGS, pid, NULL, &ARCH_REGS_FOR_GETREGS);
# endif
}
# endif /* ARCH_MIGHT_USE_SET_REGS */
Implement syscall fault injection Introduce new -e fault=EXPR syntax that can be used to specify a subset of syscalls that are subject of syscall fault injection, an error code that has to be injected, and a frequency of injection. The expression specifying syscall fault injection has the following format: SET[:error=ERRNO][:when=FIRST[+[STEP]]] where only SET is a required part and all the rest is optional. The method used to implement syscall fault injection is the following: on entering syscall the syscall number is substituted by an invalid syscall number -1, and on exiting syscall the error code returned by the kernel is substituted with the error code specified in the fault expression. This implementaion is based on the prototype developed by Nahim El Atmani as a part of his GSoC 2016 strace project. * defs.h (struct fault_opts): New forward declaration. (struct tcb): Add fault_vec field. (TCB_FAULT_INJ, QUAL_FAULT): New macros. * strace.1: Document -e fault expression syntax. * strace.c (usage): Mention -e fault expression. (droptcb): Deallocate fault_vec member. * syscall.c (qual_fault, arch_set_scno, arch_set_error): New prototypes. (qual_options): Add "fault" option. (struct fault_opts): New structure. (num_faults): New variable. (fault_vec): New array. (syscall_fault_injected, tcb_fault_opts, reallocate_fault, find_errno_by_name, qual_syscall_ex, strip_prefix, parse_fault_token, parse_fault_expression, qual_fault, inject_syscall_fault_entering, update_syscall_fault_exiting): New functions. (qual_syscall): Use qual_syscall_ex. (qualify_one): Add argument: a pointer to struct fault_opts, all callers changed. Copy struct fault_opts from the pointer to fault_vec. Use reallocate_fault. (qualify_scno, qualify_syscall_class, qualify_syscall_name): Add argument: a pointer to struct fault_opts. (qualify): Use reallocate_fault. Do not check "all" class for QUAL_FAULT qualifier. (lookup_class): Check for "all" class. (trace_syscall_entering): Use inject_syscall_fault_entering. (trace_syscall_exiting): Use update_syscall_fault_exiting. Clear TCB_FAULT_INJ flag along with TCB_INSYSCALL. Print " (INJECTED)" suffix when the syscall has been injected successfully. [ARCH_REGS_FOR_GETREGSET && !HAVE_GETREGS_OLD] (ptrace_setregset): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregset. [ARCH_REGS_FOR_GETREGS && !HAVE_GETREGS_OLD] (ptrace_setregs): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregs. [ptrace_setregset_or_setregs] (set_regs): New function. Include "set_scno.c" and "set_error.c" * NEWS: Mention this enhancement.
2016-11-16 20:26:58 +03:00
#endif /* ARCH_REGS_FOR_GETREGSET || ARCH_REGS_FOR_GETREGS */
Introduce PTRACE_GET_SYSCALL_INFO support When PTRACE_GET_SYSCALL_INFO API works, use it instead of traditional upeek/get_regs API. Tested on x86_64 and x86. * get_personality.c: New file. * get_personality.h: Likewise. * Makefile.am (strace_SOURCES): Add them. * linux/aarch64/arch_get_personality.c: New file. * linux/powerpc64/arch_get_personality.c: Likewise. * linux/riscv/arch_get_personality.c: Likewise. * linux/s390x/arch_get_personality.c: Likewise. * linux/sparc64/arch_get_personality.c: Likewise. * linux/tile/arch_get_personality.c: Likewise. * linux/x32/arch_get_personality.c: Likewise. * linux/x86_64/arch_get_personality.c: Likewise. * linux/check_scno.c: Likewise. * linux/x32/check_scno.c: Likewise. * Makefile.am (EXTRA_DIST): Add them. * linux/ia64/arch_getrval2.c (getrval2): Invoke get_regs() if ptrace_syscall_info is in use. * linux/mips/arch_getrval2.c: Likewise. * linux/sparc/arch_getrval2.c: Likewise. * defs.h (get_personality_from_syscall_info): New prototype. * syscall.c: Include "get_personality.h" and "ptrace_syscall_info.h". (get_regs_error): Define unconditionally. (ptrace_sci): New static variable. (clear_regs): Reset ptrace_sci.op. (ptrace_syscall_info_is_valid, ptrace_get_syscall_info, get_syscall_regs): New functions. (get_syscall_result_regs): Change to get_syscall_regs. (get_instruction_pointer, get_stack_pointer, get_scno, get_syscall_args, get_error, set_error, set_success): Add ptrace_syscall_info support. * tests/int_0x80.test: New test. * tests/Makefile.am (DECODER_TESTS): Add int_0x80.test. (XFAIL_TESTS_x86_64, XFAIL_TESTS_x32): Remove. * tests/gen_tests.in (int_0x80): Remove.
2018-11-21 04:44:16 +03:00
static long get_regs_error = -1;
void
clear_regs(struct tcb *tcp)
{
Introduce PTRACE_GET_SYSCALL_INFO support When PTRACE_GET_SYSCALL_INFO API works, use it instead of traditional upeek/get_regs API. Tested on x86_64 and x86. * get_personality.c: New file. * get_personality.h: Likewise. * Makefile.am (strace_SOURCES): Add them. * linux/aarch64/arch_get_personality.c: New file. * linux/powerpc64/arch_get_personality.c: Likewise. * linux/riscv/arch_get_personality.c: Likewise. * linux/s390x/arch_get_personality.c: Likewise. * linux/sparc64/arch_get_personality.c: Likewise. * linux/tile/arch_get_personality.c: Likewise. * linux/x32/arch_get_personality.c: Likewise. * linux/x86_64/arch_get_personality.c: Likewise. * linux/check_scno.c: Likewise. * linux/x32/check_scno.c: Likewise. * Makefile.am (EXTRA_DIST): Add them. * linux/ia64/arch_getrval2.c (getrval2): Invoke get_regs() if ptrace_syscall_info is in use. * linux/mips/arch_getrval2.c: Likewise. * linux/sparc/arch_getrval2.c: Likewise. * defs.h (get_personality_from_syscall_info): New prototype. * syscall.c: Include "get_personality.h" and "ptrace_syscall_info.h". (get_regs_error): Define unconditionally. (ptrace_sci): New static variable. (clear_regs): Reset ptrace_sci.op. (ptrace_syscall_info_is_valid, ptrace_get_syscall_info, get_syscall_regs): New functions. (get_syscall_result_regs): Change to get_syscall_regs. (get_instruction_pointer, get_stack_pointer, get_scno, get_syscall_args, get_error, set_error, set_success): Add ptrace_syscall_info support. * tests/int_0x80.test: New test. * tests/Makefile.am (DECODER_TESTS): Add int_0x80.test. (XFAIL_TESTS_x86_64, XFAIL_TESTS_x32): Remove. * tests/gen_tests.in (int_0x80): Remove.
2018-11-21 04:44:16 +03:00
ptrace_sci.op = 0xff;
get_regs_error = -1;
}
static long
get_regs(struct tcb *const tcp)
{
#ifdef ptrace_getregset_or_getregs
if (get_regs_error != -1)
return get_regs_error;
# ifdef HAVE_GETREGS_OLD
/*
* Try PTRACE_GETREGSET/PTRACE_GETREGS first,
* fallback to getregs_old.
*/
static int use_getregs_old;
if (use_getregs_old < 0) {
return get_regs_error = ptrace_getregset_or_getregs(tcp->pid);
} else if (use_getregs_old == 0) {
get_regs_error = ptrace_getregset_or_getregs(tcp->pid);
if (get_regs_error >= 0) {
use_getregs_old = -1;
return get_regs_error;
}
if (errno == EPERM || errno == ESRCH)
return get_regs_error;
use_getregs_old = 1;
}
return get_regs_error = getregs_old(tcp);
# else /* !HAVE_GETREGS_OLD */
/* Assume that PTRACE_GETREGSET/PTRACE_GETREGS works. */
get_regs_error = ptrace_getregset_or_getregs(tcp->pid);
# if defined ARCH_PERSONALITY_0_IOV_SIZE
if (get_regs_error)
return get_regs_error;
switch (ARCH_IOVEC_FOR_GETREGSET.iov_len) {
case ARCH_PERSONALITY_0_IOV_SIZE:
update_personality(tcp, 0);
break;
case ARCH_PERSONALITY_1_IOV_SIZE:
update_personality(tcp, 1);
break;
default: {
static bool printed = false;
if (!printed) {
error_msg("Unsupported regset size returned by "
"PTRACE_GETREGSET: %zu",
ARCH_IOVEC_FOR_GETREGSET.iov_len);
printed = true;
}
update_personality(tcp, 0);
}
}
# endif /* ARCH_PERSONALITY_0_IOV_SIZE */
return get_regs_error;
# endif /* !HAVE_GETREGS_OLD */
#else /* !ptrace_getregset_or_getregs */
# warning get_regs is not implemented for this architecture yet
return 0;
#endif /* !ptrace_getregset_or_getregs */
}
Implement syscall fault injection Introduce new -e fault=EXPR syntax that can be used to specify a subset of syscalls that are subject of syscall fault injection, an error code that has to be injected, and a frequency of injection. The expression specifying syscall fault injection has the following format: SET[:error=ERRNO][:when=FIRST[+[STEP]]] where only SET is a required part and all the rest is optional. The method used to implement syscall fault injection is the following: on entering syscall the syscall number is substituted by an invalid syscall number -1, and on exiting syscall the error code returned by the kernel is substituted with the error code specified in the fault expression. This implementaion is based on the prototype developed by Nahim El Atmani as a part of his GSoC 2016 strace project. * defs.h (struct fault_opts): New forward declaration. (struct tcb): Add fault_vec field. (TCB_FAULT_INJ, QUAL_FAULT): New macros. * strace.1: Document -e fault expression syntax. * strace.c (usage): Mention -e fault expression. (droptcb): Deallocate fault_vec member. * syscall.c (qual_fault, arch_set_scno, arch_set_error): New prototypes. (qual_options): Add "fault" option. (struct fault_opts): New structure. (num_faults): New variable. (fault_vec): New array. (syscall_fault_injected, tcb_fault_opts, reallocate_fault, find_errno_by_name, qual_syscall_ex, strip_prefix, parse_fault_token, parse_fault_expression, qual_fault, inject_syscall_fault_entering, update_syscall_fault_exiting): New functions. (qual_syscall): Use qual_syscall_ex. (qualify_one): Add argument: a pointer to struct fault_opts, all callers changed. Copy struct fault_opts from the pointer to fault_vec. Use reallocate_fault. (qualify_scno, qualify_syscall_class, qualify_syscall_name): Add argument: a pointer to struct fault_opts. (qualify): Use reallocate_fault. Do not check "all" class for QUAL_FAULT qualifier. (lookup_class): Check for "all" class. (trace_syscall_entering): Use inject_syscall_fault_entering. (trace_syscall_exiting): Use update_syscall_fault_exiting. Clear TCB_FAULT_INJ flag along with TCB_INSYSCALL. Print " (INJECTED)" suffix when the syscall has been injected successfully. [ARCH_REGS_FOR_GETREGSET && !HAVE_GETREGS_OLD] (ptrace_setregset): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregset. [ARCH_REGS_FOR_GETREGS && !HAVE_GETREGS_OLD] (ptrace_setregs): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregs. [ptrace_setregset_or_setregs] (set_regs): New function. Include "set_scno.c" and "set_error.c" * NEWS: Mention this enhancement.
2016-11-16 20:26:58 +03:00
#ifdef ptrace_setregset_or_setregs
static int
set_regs(pid_t pid)
{
return ptrace_setregset_or_setregs(pid);
}
#endif /* ptrace_setregset_or_setregs */
struct sysent_buf {
struct tcb *tcp;
struct_sysent ent;
char buf[sizeof("syscall_0x") + sizeof(kernel_ulong_t) * 2];
};
static void
free_sysent_buf(void *ptr)
{
struct sysent_buf *s = ptr;
s->tcp->s_prev_ent = s->tcp->s_ent = NULL;
free(ptr);
}
Introduce PTRACE_GET_SYSCALL_INFO support When PTRACE_GET_SYSCALL_INFO API works, use it instead of traditional upeek/get_regs API. Tested on x86_64 and x86. * get_personality.c: New file. * get_personality.h: Likewise. * Makefile.am (strace_SOURCES): Add them. * linux/aarch64/arch_get_personality.c: New file. * linux/powerpc64/arch_get_personality.c: Likewise. * linux/riscv/arch_get_personality.c: Likewise. * linux/s390x/arch_get_personality.c: Likewise. * linux/sparc64/arch_get_personality.c: Likewise. * linux/tile/arch_get_personality.c: Likewise. * linux/x32/arch_get_personality.c: Likewise. * linux/x86_64/arch_get_personality.c: Likewise. * linux/check_scno.c: Likewise. * linux/x32/check_scno.c: Likewise. * Makefile.am (EXTRA_DIST): Add them. * linux/ia64/arch_getrval2.c (getrval2): Invoke get_regs() if ptrace_syscall_info is in use. * linux/mips/arch_getrval2.c: Likewise. * linux/sparc/arch_getrval2.c: Likewise. * defs.h (get_personality_from_syscall_info): New prototype. * syscall.c: Include "get_personality.h" and "ptrace_syscall_info.h". (get_regs_error): Define unconditionally. (ptrace_sci): New static variable. (clear_regs): Reset ptrace_sci.op. (ptrace_syscall_info_is_valid, ptrace_get_syscall_info, get_syscall_regs): New functions. (get_syscall_result_regs): Change to get_syscall_regs. (get_instruction_pointer, get_stack_pointer, get_scno, get_syscall_args, get_error, set_error, set_success): Add ptrace_syscall_info support. * tests/int_0x80.test: New test. * tests/Makefile.am (DECODER_TESTS): Add int_0x80.test. (XFAIL_TESTS_x86_64, XFAIL_TESTS_x32): Remove. * tests/gen_tests.in (int_0x80): Remove.
2018-11-21 04:44:16 +03:00
static bool
ptrace_get_syscall_info(struct tcb *tcp)
{
/*
* ptrace_get_syscall_info_supported should have been checked
* by the caller.
*/
if (ptrace_sci.op == 0xff) {
const size_t size = sizeof(ptrace_sci);
if (ptrace(PTRACE_GET_SYSCALL_INFO, tcp->pid,
(void *) size, &ptrace_sci) < 0) {
get_regs_error = -2;
return false;
}
#if SUPPORTED_PERSONALITIES > 1
int newpers = get_personality_from_syscall_info(&ptrace_sci);
if (newpers >= 0)
update_personality(tcp, newpers);
#endif
}
if (entering(tcp)) {
if (ptrace_sci.op == PTRACE_SYSCALL_INFO_EXIT) {
error_msg("pid %d: entering"
", ptrace_syscall_info.op == %u",
tcp->pid, ptrace_sci.op);
/* TODO: handle this. */
}
} else {
if (ptrace_sci.op == PTRACE_SYSCALL_INFO_ENTRY) {
error_msg("pid %d: exiting"
", ptrace_syscall_info.op == %u",
tcp->pid, ptrace_sci.op);
/* TODO: handle this. */
}
}
return true;
}
bool
get_instruction_pointer(struct tcb *tcp, kernel_ulong_t *ip)
{
Introduce PTRACE_GET_SYSCALL_INFO support When PTRACE_GET_SYSCALL_INFO API works, use it instead of traditional upeek/get_regs API. Tested on x86_64 and x86. * get_personality.c: New file. * get_personality.h: Likewise. * Makefile.am (strace_SOURCES): Add them. * linux/aarch64/arch_get_personality.c: New file. * linux/powerpc64/arch_get_personality.c: Likewise. * linux/riscv/arch_get_personality.c: Likewise. * linux/s390x/arch_get_personality.c: Likewise. * linux/sparc64/arch_get_personality.c: Likewise. * linux/tile/arch_get_personality.c: Likewise. * linux/x32/arch_get_personality.c: Likewise. * linux/x86_64/arch_get_personality.c: Likewise. * linux/check_scno.c: Likewise. * linux/x32/check_scno.c: Likewise. * Makefile.am (EXTRA_DIST): Add them. * linux/ia64/arch_getrval2.c (getrval2): Invoke get_regs() if ptrace_syscall_info is in use. * linux/mips/arch_getrval2.c: Likewise. * linux/sparc/arch_getrval2.c: Likewise. * defs.h (get_personality_from_syscall_info): New prototype. * syscall.c: Include "get_personality.h" and "ptrace_syscall_info.h". (get_regs_error): Define unconditionally. (ptrace_sci): New static variable. (clear_regs): Reset ptrace_sci.op. (ptrace_syscall_info_is_valid, ptrace_get_syscall_info, get_syscall_regs): New functions. (get_syscall_result_regs): Change to get_syscall_regs. (get_instruction_pointer, get_stack_pointer, get_scno, get_syscall_args, get_error, set_error, set_success): Add ptrace_syscall_info support. * tests/int_0x80.test: New test. * tests/Makefile.am (DECODER_TESTS): Add int_0x80.test. (XFAIL_TESTS_x86_64, XFAIL_TESTS_x32): Remove. * tests/gen_tests.in (int_0x80): Remove.
2018-11-21 04:44:16 +03:00
if (get_regs_error < -1)
return false;
if (ptrace_get_syscall_info_supported) {
if (!ptrace_get_syscall_info(tcp))
return false;
*ip = (kernel_ulong_t) ptrace_sci.instruction_pointer;
return true;
}
#if defined ARCH_PC_REG
if (get_regs(tcp) < 0)
return false;
*ip = (kernel_ulong_t) ARCH_PC_REG;
return true;
#elif defined ARCH_PC_PEEK_ADDR
if (upeek(tcp, ARCH_PC_PEEK_ADDR, ip) < 0)
return false;
return true;
#else
# error Neither ARCH_PC_REG nor ARCH_PC_PEEK_ADDR is defined
#endif
}
Refactor stack pointers Change all linux/*/arch_regs.c to provide either ARCH_SP_REG or ARCH_SP_PEEK_ADDR. Introduce get_stack_pointer(), rewrite all code accessing stack pointers to use get_stack_pointer(). On some architectures stack pointers were referred to as frame pointers, clean up this confusion. * defs.h (get_stack_pointer): New prototype. * syscall.c (get_stack_pointer): New function. * linux/arch_rt_sigframe.c: New file. * linux/aarch64/arch_regs.c (aarch64_sp_ptr, arm_sp_ptr): Remove. (ARCH_SP_REG): New macro. * linux/alpha/arch_regs.c: Import linux/alpha/arch_regs.h. (REG_FP): Rename to REG_SP. (ARCH_SP_PEEK_ADDR): New macro. * linux/alpha/arch_sigreturn.c (arch_sigreturn): Use get_stack_pointer. * linux/arc/arch_regs.c (arc_sp_ptr): Remove. (ARCH_SP_REG): New macro. * linux/arm/arch_regs.c (arm_sp_ptr): Remove. (ARCH_SP_REG): New macro. * linux/arm/arch_sigreturn.c (arch_sigreturn): Use get_stack_pointer. * linux/avr32/arch_regs.c (avr32_sp_ptr): Remove. (ARCH_SP_REG): New macro. * linux/bfin/arch_regs.c (ARCH_SP_PEEK_ADDR): New macro. * linux/hppa/arch_regs.c: Import linux/hppa/arch_regs.h. (PT_GR30, ARCH_SP_PEEK_ADDR): New macros. * linux/hppa/arch_rt_sigframe.c (FUNC_GET_RT_SIGFRAME_ADDR): Use get_stack_pointer. * linux/i386/arch_regs.c (i386_esp_ptr): Remove. (ARCH_SP_REG): New macro. * linux/i386/arch_rt_sigframe.c (FUNC_GET_RT_SIGFRAME_ADDR): Use get_stack_pointer. * linux/i386/arch_sigreturn.c (arch_sigreturn): Likewise. * linux/ia64/arch_regs.c (ia64_frame_ptr): Remove. (ARCH_SP_REG): New macro. * linux/ia64/arch_regs.h (ia64_frame_ptr): Remove. * linux/ia64/arch_rt_sigframe.c (FUNC_GET_RT_SIGFRAME_ADDR): Use get_stack_pointer. * linux/m68k/arch_regs.c (m68k_usp_ptr): Remove. (ARCH_SP_REG): New macro. * linux/m68k/arch_rt_sigframe.c: Link to i386/arch_rt_sigframe.c. * linux/m68k/arch_sigreturn.c (arch_sigreturn): Use get_stack_pointer. * linux/metag/arch_regs.c (metag_sp_ptr): Remove. (ARCH_SP_REG): New macro. * linux/metag/arch_rt_sigframe.c (FUNC_GET_RT_SIGFRAME_ADDR): Use get_stack_pointer. * linux/microblaze/arch_regs.c (ARCH_SP_PEEK_ADDR): New macro. * linux/mips/arch_regs.c: Import linux/mips/arch_regs.h. (mips_regs): Add static qualifier. (ARCH_SP_REG): New macro. * linux/mips/arch_sigreturn.c (arch_sigreturn): Use get_stack_pointer. * linux/nios2/arch_regs.c (nios2_sp_ptr): Remove. (ARCH_SP_REG): New macro. * linux/or1k/arch_regs.c (or1k_sp_ptr): Remove. (ARCH_SP_REG): New macro. * linux/powerpc/arch_regs.c (ppc_regs): Add static qualifier. (ARCH_SP_REG): New macro. * linux/powerpc/arch_rt_sigframe.c (FUNC_GET_RT_SIGFRAME_ADDR): Use get_stack_pointer. * linux/powerpc/arch_sigreturn.c (arch_sigreturn): Use get_stack_pointer. * linux/powerpc64/arch_rt_sigframe.c (FUNC_GET_RT_SIGFRAME_ADDR): Use get_stack_pointer. * linux/riscv/arch_regs.c (riscv_sp_ptr): Remove. (ARCH_SP_REG): New macro. * linux/s390/arch_regs.c (s390_frame_ptr): Remove. (ARCH_SP_REG): New macro. * linux/s390/arch_sigreturn.c (S390_FRAME_PTR): Remove. (arch_sigreturn): Use get_stack_pointer. * linux/s390x/arch_regs.c (s390_frame_ptr, s390x_frame_ptr): Remove. (ARCH_SP_REG): New macro. * linux/s390x/arch_sigreturn.c (S390_FRAME_PTR): Remove. * linux/sh/arch_regs.c (ARCH_SP_PEEK_ADDR): New macro. * linux/sh64/arch_regs.c: Likewise. * linux/sparc/arch_regs.c: Import linux/sparc/arch_regs.h. (sparc_regs): Add static qualifier. (ARCH_SP_REG): New macro. * linux/sparc/arch_sigreturn.c (arch_sigreturn): Use get_stack_pointer. * linux/sparc64/arch_rt_sigframe.c (FUNC_GET_RT_SIGFRAME_ADDR): Use get_stack_pointer. * linux/tile/arch_regs.c (tile_regs): Add static qualifier. (ARCH_SP_REG): New macro. * linux/tile/arch_sigreturn.c (arch_sigreturn): Use get_stack_pointer. * linux/x86_64/arch_regs.c (i386_esp_ptr, x86_64_rsp_ptr): Remove. (ARCH_SP_REG): New macro. * linux/x86_64/arch_regs.h (i386_esp_ptr, x86_64_rsp_ptr): Remove. * linux/x86_64/arch_rt_sigframe.c: Link to i386/arch_rt_sigframe.c. * linux/xtensa/arch_regs.c (ARCH_SP_PEEK_ADDR): New macro. * linux/aarch64/arch_regs.h: Remove. * linux/aarch64/arch_rt_sigframe.c: Remove. * linux/alpha/arch_regs.h: Remove. * linux/alpha/arch_rt_sigframe.c: Remove. * linux/arc/arch_regs.h: Remove. * linux/arc/arch_rt_sigframe.c: Remove. * linux/arm/arch_regs.h: Remove. * linux/arm/arch_rt_sigframe.c: Remove. * linux/avr32/arch_regs.h: Remove. * linux/avr32/arch_rt_sigframe.c: Remove. * linux/bfin/arch_rt_sigframe.c: Remove. * linux/hppa/arch_regs.h: Remove. * linux/i386/arch_regs.h: Remove. * linux/m68k/arch_regs.h: Remove. * linux/metag/arch_regs.h: Remove. * linux/microblaze/arch_rt_sigframe.c: Remove. * linux/mips/arch_regs.h: Remove. * linux/mips/arch_rt_sigframe.c: Remove. * linux/nios2/arch_regs.h: Remove. * linux/nios2/arch_rt_sigframe.c: Remove. * linux/or1k/arch_regs.h: Remove. * linux/or1k/arch_rt_sigframe.c: Remove. * linux/powerpc/arch_regs.h: Remove. * linux/powerpc64/arch_regs.h: Remove. * linux/riscv/arch_regs.h: Remove. * linux/riscv/arch_rt_sigframe.c: Remove. * linux/s390/arch_regs.h: Remove. * linux/s390/arch_rt_sigframe.c: Remove. * linux/s390x/arch_regs.h: Remove. * linux/s390x/arch_rt_sigframe.c: Remove. * linux/sh/arch_rt_sigframe.c: Remove. * linux/sh64/arch_rt_sigframe.c: Remove. * linux/sparc/arch_regs.h: Remove. * linux/sparc/arch_rt_sigframe.c: Remove. * linux/sparc64/arch_regs.h: Remove. * linux/tile/arch_regs.h: Remove. * linux/tile/arch_rt_sigframe.c: Remove. * linux/xtensa/arch_rt_sigframe.c: Remove. * Makefile.am (EXTRA_DIST): Remove them, add linux/arch_rt_sigframe.c.
2018-12-05 01:31:41 +03:00
bool
get_stack_pointer(struct tcb *tcp, kernel_ulong_t *sp)
{
Introduce PTRACE_GET_SYSCALL_INFO support When PTRACE_GET_SYSCALL_INFO API works, use it instead of traditional upeek/get_regs API. Tested on x86_64 and x86. * get_personality.c: New file. * get_personality.h: Likewise. * Makefile.am (strace_SOURCES): Add them. * linux/aarch64/arch_get_personality.c: New file. * linux/powerpc64/arch_get_personality.c: Likewise. * linux/riscv/arch_get_personality.c: Likewise. * linux/s390x/arch_get_personality.c: Likewise. * linux/sparc64/arch_get_personality.c: Likewise. * linux/tile/arch_get_personality.c: Likewise. * linux/x32/arch_get_personality.c: Likewise. * linux/x86_64/arch_get_personality.c: Likewise. * linux/check_scno.c: Likewise. * linux/x32/check_scno.c: Likewise. * Makefile.am (EXTRA_DIST): Add them. * linux/ia64/arch_getrval2.c (getrval2): Invoke get_regs() if ptrace_syscall_info is in use. * linux/mips/arch_getrval2.c: Likewise. * linux/sparc/arch_getrval2.c: Likewise. * defs.h (get_personality_from_syscall_info): New prototype. * syscall.c: Include "get_personality.h" and "ptrace_syscall_info.h". (get_regs_error): Define unconditionally. (ptrace_sci): New static variable. (clear_regs): Reset ptrace_sci.op. (ptrace_syscall_info_is_valid, ptrace_get_syscall_info, get_syscall_regs): New functions. (get_syscall_result_regs): Change to get_syscall_regs. (get_instruction_pointer, get_stack_pointer, get_scno, get_syscall_args, get_error, set_error, set_success): Add ptrace_syscall_info support. * tests/int_0x80.test: New test. * tests/Makefile.am (DECODER_TESTS): Add int_0x80.test. (XFAIL_TESTS_x86_64, XFAIL_TESTS_x32): Remove. * tests/gen_tests.in (int_0x80): Remove.
2018-11-21 04:44:16 +03:00
if (get_regs_error < -1)
return false;
if (ptrace_get_syscall_info_supported) {
if (!ptrace_get_syscall_info(tcp))
return false;
*sp = (kernel_ulong_t) ptrace_sci.stack_pointer;
return true;
}
Refactor stack pointers Change all linux/*/arch_regs.c to provide either ARCH_SP_REG or ARCH_SP_PEEK_ADDR. Introduce get_stack_pointer(), rewrite all code accessing stack pointers to use get_stack_pointer(). On some architectures stack pointers were referred to as frame pointers, clean up this confusion. * defs.h (get_stack_pointer): New prototype. * syscall.c (get_stack_pointer): New function. * linux/arch_rt_sigframe.c: New file. * linux/aarch64/arch_regs.c (aarch64_sp_ptr, arm_sp_ptr): Remove. (ARCH_SP_REG): New macro. * linux/alpha/arch_regs.c: Import linux/alpha/arch_regs.h. (REG_FP): Rename to REG_SP. (ARCH_SP_PEEK_ADDR): New macro. * linux/alpha/arch_sigreturn.c (arch_sigreturn): Use get_stack_pointer. * linux/arc/arch_regs.c (arc_sp_ptr): Remove. (ARCH_SP_REG): New macro. * linux/arm/arch_regs.c (arm_sp_ptr): Remove. (ARCH_SP_REG): New macro. * linux/arm/arch_sigreturn.c (arch_sigreturn): Use get_stack_pointer. * linux/avr32/arch_regs.c (avr32_sp_ptr): Remove. (ARCH_SP_REG): New macro. * linux/bfin/arch_regs.c (ARCH_SP_PEEK_ADDR): New macro. * linux/hppa/arch_regs.c: Import linux/hppa/arch_regs.h. (PT_GR30, ARCH_SP_PEEK_ADDR): New macros. * linux/hppa/arch_rt_sigframe.c (FUNC_GET_RT_SIGFRAME_ADDR): Use get_stack_pointer. * linux/i386/arch_regs.c (i386_esp_ptr): Remove. (ARCH_SP_REG): New macro. * linux/i386/arch_rt_sigframe.c (FUNC_GET_RT_SIGFRAME_ADDR): Use get_stack_pointer. * linux/i386/arch_sigreturn.c (arch_sigreturn): Likewise. * linux/ia64/arch_regs.c (ia64_frame_ptr): Remove. (ARCH_SP_REG): New macro. * linux/ia64/arch_regs.h (ia64_frame_ptr): Remove. * linux/ia64/arch_rt_sigframe.c (FUNC_GET_RT_SIGFRAME_ADDR): Use get_stack_pointer. * linux/m68k/arch_regs.c (m68k_usp_ptr): Remove. (ARCH_SP_REG): New macro. * linux/m68k/arch_rt_sigframe.c: Link to i386/arch_rt_sigframe.c. * linux/m68k/arch_sigreturn.c (arch_sigreturn): Use get_stack_pointer. * linux/metag/arch_regs.c (metag_sp_ptr): Remove. (ARCH_SP_REG): New macro. * linux/metag/arch_rt_sigframe.c (FUNC_GET_RT_SIGFRAME_ADDR): Use get_stack_pointer. * linux/microblaze/arch_regs.c (ARCH_SP_PEEK_ADDR): New macro. * linux/mips/arch_regs.c: Import linux/mips/arch_regs.h. (mips_regs): Add static qualifier. (ARCH_SP_REG): New macro. * linux/mips/arch_sigreturn.c (arch_sigreturn): Use get_stack_pointer. * linux/nios2/arch_regs.c (nios2_sp_ptr): Remove. (ARCH_SP_REG): New macro. * linux/or1k/arch_regs.c (or1k_sp_ptr): Remove. (ARCH_SP_REG): New macro. * linux/powerpc/arch_regs.c (ppc_regs): Add static qualifier. (ARCH_SP_REG): New macro. * linux/powerpc/arch_rt_sigframe.c (FUNC_GET_RT_SIGFRAME_ADDR): Use get_stack_pointer. * linux/powerpc/arch_sigreturn.c (arch_sigreturn): Use get_stack_pointer. * linux/powerpc64/arch_rt_sigframe.c (FUNC_GET_RT_SIGFRAME_ADDR): Use get_stack_pointer. * linux/riscv/arch_regs.c (riscv_sp_ptr): Remove. (ARCH_SP_REG): New macro. * linux/s390/arch_regs.c (s390_frame_ptr): Remove. (ARCH_SP_REG): New macro. * linux/s390/arch_sigreturn.c (S390_FRAME_PTR): Remove. (arch_sigreturn): Use get_stack_pointer. * linux/s390x/arch_regs.c (s390_frame_ptr, s390x_frame_ptr): Remove. (ARCH_SP_REG): New macro. * linux/s390x/arch_sigreturn.c (S390_FRAME_PTR): Remove. * linux/sh/arch_regs.c (ARCH_SP_PEEK_ADDR): New macro. * linux/sh64/arch_regs.c: Likewise. * linux/sparc/arch_regs.c: Import linux/sparc/arch_regs.h. (sparc_regs): Add static qualifier. (ARCH_SP_REG): New macro. * linux/sparc/arch_sigreturn.c (arch_sigreturn): Use get_stack_pointer. * linux/sparc64/arch_rt_sigframe.c (FUNC_GET_RT_SIGFRAME_ADDR): Use get_stack_pointer. * linux/tile/arch_regs.c (tile_regs): Add static qualifier. (ARCH_SP_REG): New macro. * linux/tile/arch_sigreturn.c (arch_sigreturn): Use get_stack_pointer. * linux/x86_64/arch_regs.c (i386_esp_ptr, x86_64_rsp_ptr): Remove. (ARCH_SP_REG): New macro. * linux/x86_64/arch_regs.h (i386_esp_ptr, x86_64_rsp_ptr): Remove. * linux/x86_64/arch_rt_sigframe.c: Link to i386/arch_rt_sigframe.c. * linux/xtensa/arch_regs.c (ARCH_SP_PEEK_ADDR): New macro. * linux/aarch64/arch_regs.h: Remove. * linux/aarch64/arch_rt_sigframe.c: Remove. * linux/alpha/arch_regs.h: Remove. * linux/alpha/arch_rt_sigframe.c: Remove. * linux/arc/arch_regs.h: Remove. * linux/arc/arch_rt_sigframe.c: Remove. * linux/arm/arch_regs.h: Remove. * linux/arm/arch_rt_sigframe.c: Remove. * linux/avr32/arch_regs.h: Remove. * linux/avr32/arch_rt_sigframe.c: Remove. * linux/bfin/arch_rt_sigframe.c: Remove. * linux/hppa/arch_regs.h: Remove. * linux/i386/arch_regs.h: Remove. * linux/m68k/arch_regs.h: Remove. * linux/metag/arch_regs.h: Remove. * linux/microblaze/arch_rt_sigframe.c: Remove. * linux/mips/arch_regs.h: Remove. * linux/mips/arch_rt_sigframe.c: Remove. * linux/nios2/arch_regs.h: Remove. * linux/nios2/arch_rt_sigframe.c: Remove. * linux/or1k/arch_regs.h: Remove. * linux/or1k/arch_rt_sigframe.c: Remove. * linux/powerpc/arch_regs.h: Remove. * linux/powerpc64/arch_regs.h: Remove. * linux/riscv/arch_regs.h: Remove. * linux/riscv/arch_rt_sigframe.c: Remove. * linux/s390/arch_regs.h: Remove. * linux/s390/arch_rt_sigframe.c: Remove. * linux/s390x/arch_regs.h: Remove. * linux/s390x/arch_rt_sigframe.c: Remove. * linux/sh/arch_rt_sigframe.c: Remove. * linux/sh64/arch_rt_sigframe.c: Remove. * linux/sparc/arch_regs.h: Remove. * linux/sparc/arch_rt_sigframe.c: Remove. * linux/sparc64/arch_regs.h: Remove. * linux/tile/arch_regs.h: Remove. * linux/tile/arch_rt_sigframe.c: Remove. * linux/xtensa/arch_rt_sigframe.c: Remove. * Makefile.am (EXTRA_DIST): Remove them, add linux/arch_rt_sigframe.c.
2018-12-05 01:31:41 +03:00
#if defined ARCH_SP_REG
if (get_regs(tcp) < 0)
return false;
*sp = (kernel_ulong_t) ARCH_SP_REG;
return true;
#elif defined ARCH_SP_PEEK_ADDR
if (upeek(tcp, ARCH_SP_PEEK_ADDR, sp) < 0)
return false;
return true;
#else
return false;
#endif
}
Introduce PTRACE_GET_SYSCALL_INFO support When PTRACE_GET_SYSCALL_INFO API works, use it instead of traditional upeek/get_regs API. Tested on x86_64 and x86. * get_personality.c: New file. * get_personality.h: Likewise. * Makefile.am (strace_SOURCES): Add them. * linux/aarch64/arch_get_personality.c: New file. * linux/powerpc64/arch_get_personality.c: Likewise. * linux/riscv/arch_get_personality.c: Likewise. * linux/s390x/arch_get_personality.c: Likewise. * linux/sparc64/arch_get_personality.c: Likewise. * linux/tile/arch_get_personality.c: Likewise. * linux/x32/arch_get_personality.c: Likewise. * linux/x86_64/arch_get_personality.c: Likewise. * linux/check_scno.c: Likewise. * linux/x32/check_scno.c: Likewise. * Makefile.am (EXTRA_DIST): Add them. * linux/ia64/arch_getrval2.c (getrval2): Invoke get_regs() if ptrace_syscall_info is in use. * linux/mips/arch_getrval2.c: Likewise. * linux/sparc/arch_getrval2.c: Likewise. * defs.h (get_personality_from_syscall_info): New prototype. * syscall.c: Include "get_personality.h" and "ptrace_syscall_info.h". (get_regs_error): Define unconditionally. (ptrace_sci): New static variable. (clear_regs): Reset ptrace_sci.op. (ptrace_syscall_info_is_valid, ptrace_get_syscall_info, get_syscall_regs): New functions. (get_syscall_result_regs): Change to get_syscall_regs. (get_instruction_pointer, get_stack_pointer, get_scno, get_syscall_args, get_error, set_error, set_success): Add ptrace_syscall_info support. * tests/int_0x80.test: New test. * tests/Makefile.am (DECODER_TESTS): Add int_0x80.test. (XFAIL_TESTS_x86_64, XFAIL_TESTS_x32): Remove. * tests/gen_tests.in (int_0x80): Remove.
2018-11-21 04:44:16 +03:00
static int
get_syscall_regs(struct tcb *tcp)
{
if (get_regs_error != -1)
return get_regs_error;
if (ptrace_get_syscall_info_supported)
return ptrace_get_syscall_info(tcp) ? 0 : get_regs_error;
return get_regs(tcp);
}
/*
* Returns:
* 0: "ignore this ptrace stop", syscall_entering_decode() should return a "bail
* out silently" code.
* 1: ok, continue in syscall_entering_decode().
* other: error, syscall_entering_decode() should print error indicator
* ("????" etc) and return an appropriate code.
*/
int
get_scno(struct tcb *tcp)
1999-02-19 03:21:36 +03:00
{
Introduce PTRACE_GET_SYSCALL_INFO support When PTRACE_GET_SYSCALL_INFO API works, use it instead of traditional upeek/get_regs API. Tested on x86_64 and x86. * get_personality.c: New file. * get_personality.h: Likewise. * Makefile.am (strace_SOURCES): Add them. * linux/aarch64/arch_get_personality.c: New file. * linux/powerpc64/arch_get_personality.c: Likewise. * linux/riscv/arch_get_personality.c: Likewise. * linux/s390x/arch_get_personality.c: Likewise. * linux/sparc64/arch_get_personality.c: Likewise. * linux/tile/arch_get_personality.c: Likewise. * linux/x32/arch_get_personality.c: Likewise. * linux/x86_64/arch_get_personality.c: Likewise. * linux/check_scno.c: Likewise. * linux/x32/check_scno.c: Likewise. * Makefile.am (EXTRA_DIST): Add them. * linux/ia64/arch_getrval2.c (getrval2): Invoke get_regs() if ptrace_syscall_info is in use. * linux/mips/arch_getrval2.c: Likewise. * linux/sparc/arch_getrval2.c: Likewise. * defs.h (get_personality_from_syscall_info): New prototype. * syscall.c: Include "get_personality.h" and "ptrace_syscall_info.h". (get_regs_error): Define unconditionally. (ptrace_sci): New static variable. (clear_regs): Reset ptrace_sci.op. (ptrace_syscall_info_is_valid, ptrace_get_syscall_info, get_syscall_regs): New functions. (get_syscall_result_regs): Change to get_syscall_regs. (get_instruction_pointer, get_stack_pointer, get_scno, get_syscall_args, get_error, set_error, set_success): Add ptrace_syscall_info support. * tests/int_0x80.test: New test. * tests/Makefile.am (DECODER_TESTS): Add int_0x80.test. (XFAIL_TESTS_x86_64, XFAIL_TESTS_x32): Remove. * tests/gen_tests.in (int_0x80): Remove.
2018-11-21 04:44:16 +03:00
if (get_syscall_regs(tcp) < 0)
return -1;
Introduce PTRACE_GET_SYSCALL_INFO support When PTRACE_GET_SYSCALL_INFO API works, use it instead of traditional upeek/get_regs API. Tested on x86_64 and x86. * get_personality.c: New file. * get_personality.h: Likewise. * Makefile.am (strace_SOURCES): Add them. * linux/aarch64/arch_get_personality.c: New file. * linux/powerpc64/arch_get_personality.c: Likewise. * linux/riscv/arch_get_personality.c: Likewise. * linux/s390x/arch_get_personality.c: Likewise. * linux/sparc64/arch_get_personality.c: Likewise. * linux/tile/arch_get_personality.c: Likewise. * linux/x32/arch_get_personality.c: Likewise. * linux/x86_64/arch_get_personality.c: Likewise. * linux/check_scno.c: Likewise. * linux/x32/check_scno.c: Likewise. * Makefile.am (EXTRA_DIST): Add them. * linux/ia64/arch_getrval2.c (getrval2): Invoke get_regs() if ptrace_syscall_info is in use. * linux/mips/arch_getrval2.c: Likewise. * linux/sparc/arch_getrval2.c: Likewise. * defs.h (get_personality_from_syscall_info): New prototype. * syscall.c: Include "get_personality.h" and "ptrace_syscall_info.h". (get_regs_error): Define unconditionally. (ptrace_sci): New static variable. (clear_regs): Reset ptrace_sci.op. (ptrace_syscall_info_is_valid, ptrace_get_syscall_info, get_syscall_regs): New functions. (get_syscall_result_regs): Change to get_syscall_regs. (get_instruction_pointer, get_stack_pointer, get_scno, get_syscall_args, get_error, set_error, set_success): Add ptrace_syscall_info support. * tests/int_0x80.test: New test. * tests/Makefile.am (DECODER_TESTS): Add int_0x80.test. (XFAIL_TESTS_x86_64, XFAIL_TESTS_x32): Remove. * tests/gen_tests.in (int_0x80): Remove.
2018-11-21 04:44:16 +03:00
if (ptrace_syscall_info_is_valid()) {
/*
* So far it's just a workaround for x32,
* but let's pretend it could be used elsewhere.
*/
int rc = arch_check_scno(tcp);
if (rc != 1)
return rc;
tcp->scno = ptrace_sci.entry.nr;
} else {
int rc = arch_get_scno(tcp);
if (rc != 1)
return rc;
}
tcp->scno = shuffle_scno(tcp->scno);
if (scno_is_valid(tcp->scno)) {
tcp->s_ent = &sysent[tcp->scno];
Rewrite remaining qual_* parsers using bit sets * defs.h (struct fault_opts): Replace forward declaration with a definition. (qualbits_t, qualify_read, qualify_write, qualify_signals): Remove. (qual_flags): New function prototype. (nsyscall_vec, sysent_vec, fault_vec): New variable prototypes. * qualify.c (abbrev_set, fault_set, raw_set, trace_set, verbose_set): New variables. (qualify_read, qualify_write, qualify_signals): Add static qualifier. (find_errno_by_name, lookup_class, parse_fault_expression, parse_fault_token, qual_flags, qualify, qualify_abbrev, qualify_fault, qualify_raw, qualify_syscall, qualify_syscall_class, qualify_syscall_name, qualify_syscall_number, qualify_syscall_tokens, qualify_trace, qualify_verbose, strip_prefix): New functions. * syscall.c (nsyscall_vec, nsysent_vec): Remove static qualifier. (MAX_NSYSCALLS1, MAX_NSYSCALLS2, MAX_NSYSCALLS, qual_vec, qual_flags, qual_fault, qual_syscall, qual_options, fault_opts, qualify_one, qualify_scno, lookup_class, qualify_syscall_class, qualify_syscall_name, qual_syscall_ex, qual_syscall, strip_prefix, find_errno_by_name, parse_fault_token, parse_fault_expression, qual_fault, qualify): Remove. (decode_socket_subcall, decode_ipc_subcall, decode_mips_subcall, get_scno): Update use of qual_flags. (inject_syscall_fault_entering): Update per-personality allocation of tcp->fault_vec. * tests/fault_injection-exit_group.test: Check parsing of inversed fault sets. * tests/fault_injection.test: Check parsing of -efault=none. * tests/options-syntax.test: Check parsing of invalid syscall numbers.
2016-12-04 17:39:48 +03:00
tcp->qual_flg = qual_flags(tcp->scno);
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>
2013-02-21 19:13:47 +04:00
} else {
struct sysent_buf *s = xcalloc(1, sizeof(*s));
s->tcp = tcp;
s->ent.nargs = MAX_ARGS;
s->ent.sen = SEN_printargs;
s->ent.sys_func = printargs;
s->ent.sys_name = s->buf;
xsprintf(s->buf, "syscall_%#" PRI_klx, shuffle_scno(tcp->scno));
tcp->s_ent = &s->ent;
tcp->qual_flg = QUAL_RAW | DEFAULT_QUAL_FLAGS;
set_tcb_priv_data(tcp, s, free_sysent_buf);
debug_msg("pid %d invalid syscall %#" PRI_klx,
tcp->pid, shuffle_scno(tcp->scno));
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>
2013-02-21 19:13:47 +04:00
}
/*
* We refrain from argument decoding during recovering
* as tracee memory mappings has changed and the registers
* are very likely pointing to garbage already.
*/
if (recovering(tcp))
tcp->qual_flg |= QUAL_RAW;
return 1;
}
static int
get_syscall_args(struct tcb *tcp)
{
Introduce PTRACE_GET_SYSCALL_INFO support When PTRACE_GET_SYSCALL_INFO API works, use it instead of traditional upeek/get_regs API. Tested on x86_64 and x86. * get_personality.c: New file. * get_personality.h: Likewise. * Makefile.am (strace_SOURCES): Add them. * linux/aarch64/arch_get_personality.c: New file. * linux/powerpc64/arch_get_personality.c: Likewise. * linux/riscv/arch_get_personality.c: Likewise. * linux/s390x/arch_get_personality.c: Likewise. * linux/sparc64/arch_get_personality.c: Likewise. * linux/tile/arch_get_personality.c: Likewise. * linux/x32/arch_get_personality.c: Likewise. * linux/x86_64/arch_get_personality.c: Likewise. * linux/check_scno.c: Likewise. * linux/x32/check_scno.c: Likewise. * Makefile.am (EXTRA_DIST): Add them. * linux/ia64/arch_getrval2.c (getrval2): Invoke get_regs() if ptrace_syscall_info is in use. * linux/mips/arch_getrval2.c: Likewise. * linux/sparc/arch_getrval2.c: Likewise. * defs.h (get_personality_from_syscall_info): New prototype. * syscall.c: Include "get_personality.h" and "ptrace_syscall_info.h". (get_regs_error): Define unconditionally. (ptrace_sci): New static variable. (clear_regs): Reset ptrace_sci.op. (ptrace_syscall_info_is_valid, ptrace_get_syscall_info, get_syscall_regs): New functions. (get_syscall_result_regs): Change to get_syscall_regs. (get_instruction_pointer, get_stack_pointer, get_scno, get_syscall_args, get_error, set_error, set_success): Add ptrace_syscall_info support. * tests/int_0x80.test: New test. * tests/Makefile.am (DECODER_TESTS): Add int_0x80.test. (XFAIL_TESTS_x86_64, XFAIL_TESTS_x32): Remove. * tests/gen_tests.in (int_0x80): Remove.
2018-11-21 04:44:16 +03:00
if (ptrace_syscall_info_is_valid()) {
for (unsigned int i = 0; i < ARRAY_SIZE(tcp->u_arg); ++i)
tcp->u_arg[i] = ptrace_sci.entry.args[i];
#if SUPPORTED_PERSONALITIES > 1
if (tcp->s_ent->sys_flags & COMPAT_SYSCALL_TYPES) {
for (unsigned int i = 0; i < ARRAY_SIZE(tcp->u_arg); ++i)
tcp->u_arg[i] = (uint32_t) tcp->u_arg[i];
}
#endif
return 1;
}
return arch_get_syscall_args(tcp);
}
#ifdef ptrace_getregset_or_getregs
Introduce PTRACE_GET_SYSCALL_INFO support When PTRACE_GET_SYSCALL_INFO API works, use it instead of traditional upeek/get_regs API. Tested on x86_64 and x86. * get_personality.c: New file. * get_personality.h: Likewise. * Makefile.am (strace_SOURCES): Add them. * linux/aarch64/arch_get_personality.c: New file. * linux/powerpc64/arch_get_personality.c: Likewise. * linux/riscv/arch_get_personality.c: Likewise. * linux/s390x/arch_get_personality.c: Likewise. * linux/sparc64/arch_get_personality.c: Likewise. * linux/tile/arch_get_personality.c: Likewise. * linux/x32/arch_get_personality.c: Likewise. * linux/x86_64/arch_get_personality.c: Likewise. * linux/check_scno.c: Likewise. * linux/x32/check_scno.c: Likewise. * Makefile.am (EXTRA_DIST): Add them. * linux/ia64/arch_getrval2.c (getrval2): Invoke get_regs() if ptrace_syscall_info is in use. * linux/mips/arch_getrval2.c: Likewise. * linux/sparc/arch_getrval2.c: Likewise. * defs.h (get_personality_from_syscall_info): New prototype. * syscall.c: Include "get_personality.h" and "ptrace_syscall_info.h". (get_regs_error): Define unconditionally. (ptrace_sci): New static variable. (clear_regs): Reset ptrace_sci.op. (ptrace_syscall_info_is_valid, ptrace_get_syscall_info, get_syscall_regs): New functions. (get_syscall_result_regs): Change to get_syscall_regs. (get_instruction_pointer, get_stack_pointer, get_scno, get_syscall_args, get_error, set_error, set_success): Add ptrace_syscall_info support. * tests/int_0x80.test: New test. * tests/Makefile.am (DECODER_TESTS): Add int_0x80.test. (XFAIL_TESTS_x86_64, XFAIL_TESTS_x32): Remove. * tests/gen_tests.in (int_0x80): Remove.
2018-11-21 04:44:16 +03:00
# define get_syscall_result_regs get_syscall_regs
#else
static int get_syscall_result_regs(struct tcb *);
#endif
/* Returns:
* 1: ok, continue in syscall_exiting_trace().
* -1: error, syscall_exiting_trace() should print error indicator
* ("????" etc) and bail out.
*/
static int
get_syscall_result(struct tcb *tcp)
{
if (get_syscall_result_regs(tcp) < 0)
return -1;
get_error(tcp,
(!(tcp->s_ent->sys_flags & SYSCALL_NEVER_FAILS)
|| syscall_tampered(tcp))
&& !syscall_tampered_nofail(tcp));
return 1;
}
static void
get_error(struct tcb *tcp, const bool check_errno)
{
Introduce PTRACE_GET_SYSCALL_INFO support When PTRACE_GET_SYSCALL_INFO API works, use it instead of traditional upeek/get_regs API. Tested on x86_64 and x86. * get_personality.c: New file. * get_personality.h: Likewise. * Makefile.am (strace_SOURCES): Add them. * linux/aarch64/arch_get_personality.c: New file. * linux/powerpc64/arch_get_personality.c: Likewise. * linux/riscv/arch_get_personality.c: Likewise. * linux/s390x/arch_get_personality.c: Likewise. * linux/sparc64/arch_get_personality.c: Likewise. * linux/tile/arch_get_personality.c: Likewise. * linux/x32/arch_get_personality.c: Likewise. * linux/x86_64/arch_get_personality.c: Likewise. * linux/check_scno.c: Likewise. * linux/x32/check_scno.c: Likewise. * Makefile.am (EXTRA_DIST): Add them. * linux/ia64/arch_getrval2.c (getrval2): Invoke get_regs() if ptrace_syscall_info is in use. * linux/mips/arch_getrval2.c: Likewise. * linux/sparc/arch_getrval2.c: Likewise. * defs.h (get_personality_from_syscall_info): New prototype. * syscall.c: Include "get_personality.h" and "ptrace_syscall_info.h". (get_regs_error): Define unconditionally. (ptrace_sci): New static variable. (clear_regs): Reset ptrace_sci.op. (ptrace_syscall_info_is_valid, ptrace_get_syscall_info, get_syscall_regs): New functions. (get_syscall_result_regs): Change to get_syscall_regs. (get_instruction_pointer, get_stack_pointer, get_scno, get_syscall_args, get_error, set_error, set_success): Add ptrace_syscall_info support. * tests/int_0x80.test: New test. * tests/Makefile.am (DECODER_TESTS): Add int_0x80.test. (XFAIL_TESTS_x86_64, XFAIL_TESTS_x32): Remove. * tests/gen_tests.in (int_0x80): Remove.
2018-11-21 04:44:16 +03:00
if (ptrace_syscall_info_is_valid()) {
if (ptrace_sci.exit.is_error) {
tcp->u_rval = -1;
tcp->u_error = -ptrace_sci.exit.rval;
} else {
tcp->u_error = 0;
tcp->u_rval = ptrace_sci.exit.rval;
}
} else {
tcp->u_error = 0;
arch_get_error(tcp, check_errno);
}
}
static void
set_error(struct tcb *tcp, unsigned long new_error)
{
const unsigned long old_error = tcp->u_error;
if (new_error == old_error || new_error > MAX_ERRNO_VALUE)
return;
Introduce PTRACE_GET_SYSCALL_INFO support When PTRACE_GET_SYSCALL_INFO API works, use it instead of traditional upeek/get_regs API. Tested on x86_64 and x86. * get_personality.c: New file. * get_personality.h: Likewise. * Makefile.am (strace_SOURCES): Add them. * linux/aarch64/arch_get_personality.c: New file. * linux/powerpc64/arch_get_personality.c: Likewise. * linux/riscv/arch_get_personality.c: Likewise. * linux/s390x/arch_get_personality.c: Likewise. * linux/sparc64/arch_get_personality.c: Likewise. * linux/tile/arch_get_personality.c: Likewise. * linux/x32/arch_get_personality.c: Likewise. * linux/x86_64/arch_get_personality.c: Likewise. * linux/check_scno.c: Likewise. * linux/x32/check_scno.c: Likewise. * Makefile.am (EXTRA_DIST): Add them. * linux/ia64/arch_getrval2.c (getrval2): Invoke get_regs() if ptrace_syscall_info is in use. * linux/mips/arch_getrval2.c: Likewise. * linux/sparc/arch_getrval2.c: Likewise. * defs.h (get_personality_from_syscall_info): New prototype. * syscall.c: Include "get_personality.h" and "ptrace_syscall_info.h". (get_regs_error): Define unconditionally. (ptrace_sci): New static variable. (clear_regs): Reset ptrace_sci.op. (ptrace_syscall_info_is_valid, ptrace_get_syscall_info, get_syscall_regs): New functions. (get_syscall_result_regs): Change to get_syscall_regs. (get_instruction_pointer, get_stack_pointer, get_scno, get_syscall_args, get_error, set_error, set_success): Add ptrace_syscall_info support. * tests/int_0x80.test: New test. * tests/Makefile.am (DECODER_TESTS): Add int_0x80.test. (XFAIL_TESTS_x86_64, XFAIL_TESTS_x32): Remove. * tests/gen_tests.in (int_0x80): Remove.
2018-11-21 04:44:16 +03:00
#ifdef ptrace_setregset_or_setregs
/* if we are going to invoke set_regs, call get_regs first */
if (get_regs(tcp) < 0)
return;
#endif
tcp->u_error = new_error;
if (arch_set_error(tcp)) {
tcp->u_error = old_error;
/* arch_set_error does not update u_rval */
} else {
Introduce PTRACE_GET_SYSCALL_INFO support When PTRACE_GET_SYSCALL_INFO API works, use it instead of traditional upeek/get_regs API. Tested on x86_64 and x86. * get_personality.c: New file. * get_personality.h: Likewise. * Makefile.am (strace_SOURCES): Add them. * linux/aarch64/arch_get_personality.c: New file. * linux/powerpc64/arch_get_personality.c: Likewise. * linux/riscv/arch_get_personality.c: Likewise. * linux/s390x/arch_get_personality.c: Likewise. * linux/sparc64/arch_get_personality.c: Likewise. * linux/tile/arch_get_personality.c: Likewise. * linux/x32/arch_get_personality.c: Likewise. * linux/x86_64/arch_get_personality.c: Likewise. * linux/check_scno.c: Likewise. * linux/x32/check_scno.c: Likewise. * Makefile.am (EXTRA_DIST): Add them. * linux/ia64/arch_getrval2.c (getrval2): Invoke get_regs() if ptrace_syscall_info is in use. * linux/mips/arch_getrval2.c: Likewise. * linux/sparc/arch_getrval2.c: Likewise. * defs.h (get_personality_from_syscall_info): New prototype. * syscall.c: Include "get_personality.h" and "ptrace_syscall_info.h". (get_regs_error): Define unconditionally. (ptrace_sci): New static variable. (clear_regs): Reset ptrace_sci.op. (ptrace_syscall_info_is_valid, ptrace_get_syscall_info, get_syscall_regs): New functions. (get_syscall_result_regs): Change to get_syscall_regs. (get_instruction_pointer, get_stack_pointer, get_scno, get_syscall_args, get_error, set_error, set_success): Add ptrace_syscall_info support. * tests/int_0x80.test: New test. * tests/Makefile.am (DECODER_TESTS): Add int_0x80.test. (XFAIL_TESTS_x86_64, XFAIL_TESTS_x32): Remove. * tests/gen_tests.in (int_0x80): Remove.
2018-11-21 04:44:16 +03:00
if (ptrace_syscall_info_is_valid())
tcp->u_rval = -1;
else
get_error(tcp, !(tcp->s_ent->sys_flags &
SYSCALL_NEVER_FAILS));
}
}
static void
set_success(struct tcb *tcp, kernel_long_t new_rval)
{
const kernel_long_t old_rval = tcp->u_rval;
Introduce PTRACE_GET_SYSCALL_INFO support When PTRACE_GET_SYSCALL_INFO API works, use it instead of traditional upeek/get_regs API. Tested on x86_64 and x86. * get_personality.c: New file. * get_personality.h: Likewise. * Makefile.am (strace_SOURCES): Add them. * linux/aarch64/arch_get_personality.c: New file. * linux/powerpc64/arch_get_personality.c: Likewise. * linux/riscv/arch_get_personality.c: Likewise. * linux/s390x/arch_get_personality.c: Likewise. * linux/sparc64/arch_get_personality.c: Likewise. * linux/tile/arch_get_personality.c: Likewise. * linux/x32/arch_get_personality.c: Likewise. * linux/x86_64/arch_get_personality.c: Likewise. * linux/check_scno.c: Likewise. * linux/x32/check_scno.c: Likewise. * Makefile.am (EXTRA_DIST): Add them. * linux/ia64/arch_getrval2.c (getrval2): Invoke get_regs() if ptrace_syscall_info is in use. * linux/mips/arch_getrval2.c: Likewise. * linux/sparc/arch_getrval2.c: Likewise. * defs.h (get_personality_from_syscall_info): New prototype. * syscall.c: Include "get_personality.h" and "ptrace_syscall_info.h". (get_regs_error): Define unconditionally. (ptrace_sci): New static variable. (clear_regs): Reset ptrace_sci.op. (ptrace_syscall_info_is_valid, ptrace_get_syscall_info, get_syscall_regs): New functions. (get_syscall_result_regs): Change to get_syscall_regs. (get_instruction_pointer, get_stack_pointer, get_scno, get_syscall_args, get_error, set_error, set_success): Add ptrace_syscall_info support. * tests/int_0x80.test: New test. * tests/Makefile.am (DECODER_TESTS): Add int_0x80.test. (XFAIL_TESTS_x86_64, XFAIL_TESTS_x32): Remove. * tests/gen_tests.in (int_0x80): Remove.
2018-11-21 04:44:16 +03:00
#ifdef ptrace_setregset_or_setregs
/* if we are going to invoke set_regs, call get_regs first */
if (get_regs(tcp) < 0)
return;
#endif
tcp->u_rval = new_rval;
if (arch_set_success(tcp)) {
tcp->u_rval = old_rval;
Introduce PTRACE_GET_SYSCALL_INFO support When PTRACE_GET_SYSCALL_INFO API works, use it instead of traditional upeek/get_regs API. Tested on x86_64 and x86. * get_personality.c: New file. * get_personality.h: Likewise. * Makefile.am (strace_SOURCES): Add them. * linux/aarch64/arch_get_personality.c: New file. * linux/powerpc64/arch_get_personality.c: Likewise. * linux/riscv/arch_get_personality.c: Likewise. * linux/s390x/arch_get_personality.c: Likewise. * linux/sparc64/arch_get_personality.c: Likewise. * linux/tile/arch_get_personality.c: Likewise. * linux/x32/arch_get_personality.c: Likewise. * linux/x86_64/arch_get_personality.c: Likewise. * linux/check_scno.c: Likewise. * linux/x32/check_scno.c: Likewise. * Makefile.am (EXTRA_DIST): Add them. * linux/ia64/arch_getrval2.c (getrval2): Invoke get_regs() if ptrace_syscall_info is in use. * linux/mips/arch_getrval2.c: Likewise. * linux/sparc/arch_getrval2.c: Likewise. * defs.h (get_personality_from_syscall_info): New prototype. * syscall.c: Include "get_personality.h" and "ptrace_syscall_info.h". (get_regs_error): Define unconditionally. (ptrace_sci): New static variable. (clear_regs): Reset ptrace_sci.op. (ptrace_syscall_info_is_valid, ptrace_get_syscall_info, get_syscall_regs): New functions. (get_syscall_result_regs): Change to get_syscall_regs. (get_instruction_pointer, get_stack_pointer, get_scno, get_syscall_args, get_error, set_error, set_success): Add ptrace_syscall_info support. * tests/int_0x80.test: New test. * tests/Makefile.am (DECODER_TESTS): Add int_0x80.test. (XFAIL_TESTS_x86_64, XFAIL_TESTS_x32): Remove. * tests/gen_tests.in (int_0x80): Remove.
2018-11-21 04:44:16 +03:00
/* arch_set_success does not update u_error */
} else {
Introduce PTRACE_GET_SYSCALL_INFO support When PTRACE_GET_SYSCALL_INFO API works, use it instead of traditional upeek/get_regs API. Tested on x86_64 and x86. * get_personality.c: New file. * get_personality.h: Likewise. * Makefile.am (strace_SOURCES): Add them. * linux/aarch64/arch_get_personality.c: New file. * linux/powerpc64/arch_get_personality.c: Likewise. * linux/riscv/arch_get_personality.c: Likewise. * linux/s390x/arch_get_personality.c: Likewise. * linux/sparc64/arch_get_personality.c: Likewise. * linux/tile/arch_get_personality.c: Likewise. * linux/x32/arch_get_personality.c: Likewise. * linux/x86_64/arch_get_personality.c: Likewise. * linux/check_scno.c: Likewise. * linux/x32/check_scno.c: Likewise. * Makefile.am (EXTRA_DIST): Add them. * linux/ia64/arch_getrval2.c (getrval2): Invoke get_regs() if ptrace_syscall_info is in use. * linux/mips/arch_getrval2.c: Likewise. * linux/sparc/arch_getrval2.c: Likewise. * defs.h (get_personality_from_syscall_info): New prototype. * syscall.c: Include "get_personality.h" and "ptrace_syscall_info.h". (get_regs_error): Define unconditionally. (ptrace_sci): New static variable. (clear_regs): Reset ptrace_sci.op. (ptrace_syscall_info_is_valid, ptrace_get_syscall_info, get_syscall_regs): New functions. (get_syscall_result_regs): Change to get_syscall_regs. (get_instruction_pointer, get_stack_pointer, get_scno, get_syscall_args, get_error, set_error, set_success): Add ptrace_syscall_info support. * tests/int_0x80.test: New test. * tests/Makefile.am (DECODER_TESTS): Add int_0x80.test. (XFAIL_TESTS_x86_64, XFAIL_TESTS_x32): Remove. * tests/gen_tests.in (int_0x80): Remove.
2018-11-21 04:44:16 +03:00
if (ptrace_syscall_info_is_valid())
tcp->u_error = 0;
else
get_error(tcp, !(tcp->s_ent->sys_flags &
SYSCALL_NEVER_FAILS));
}
}
#include "get_scno.c"
Introduce PTRACE_GET_SYSCALL_INFO support When PTRACE_GET_SYSCALL_INFO API works, use it instead of traditional upeek/get_regs API. Tested on x86_64 and x86. * get_personality.c: New file. * get_personality.h: Likewise. * Makefile.am (strace_SOURCES): Add them. * linux/aarch64/arch_get_personality.c: New file. * linux/powerpc64/arch_get_personality.c: Likewise. * linux/riscv/arch_get_personality.c: Likewise. * linux/s390x/arch_get_personality.c: Likewise. * linux/sparc64/arch_get_personality.c: Likewise. * linux/tile/arch_get_personality.c: Likewise. * linux/x32/arch_get_personality.c: Likewise. * linux/x86_64/arch_get_personality.c: Likewise. * linux/check_scno.c: Likewise. * linux/x32/check_scno.c: Likewise. * Makefile.am (EXTRA_DIST): Add them. * linux/ia64/arch_getrval2.c (getrval2): Invoke get_regs() if ptrace_syscall_info is in use. * linux/mips/arch_getrval2.c: Likewise. * linux/sparc/arch_getrval2.c: Likewise. * defs.h (get_personality_from_syscall_info): New prototype. * syscall.c: Include "get_personality.h" and "ptrace_syscall_info.h". (get_regs_error): Define unconditionally. (ptrace_sci): New static variable. (clear_regs): Reset ptrace_sci.op. (ptrace_syscall_info_is_valid, ptrace_get_syscall_info, get_syscall_regs): New functions. (get_syscall_result_regs): Change to get_syscall_regs. (get_instruction_pointer, get_stack_pointer, get_scno, get_syscall_args, get_error, set_error, set_success): Add ptrace_syscall_info support. * tests/int_0x80.test: New test. * tests/Makefile.am (DECODER_TESTS): Add int_0x80.test. (XFAIL_TESTS_x86_64, XFAIL_TESTS_x32): Remove. * tests/gen_tests.in (int_0x80): Remove.
2018-11-21 04:44:16 +03:00
#include "check_scno.c"
Implement syscall fault injection Introduce new -e fault=EXPR syntax that can be used to specify a subset of syscalls that are subject of syscall fault injection, an error code that has to be injected, and a frequency of injection. The expression specifying syscall fault injection has the following format: SET[:error=ERRNO][:when=FIRST[+[STEP]]] where only SET is a required part and all the rest is optional. The method used to implement syscall fault injection is the following: on entering syscall the syscall number is substituted by an invalid syscall number -1, and on exiting syscall the error code returned by the kernel is substituted with the error code specified in the fault expression. This implementaion is based on the prototype developed by Nahim El Atmani as a part of his GSoC 2016 strace project. * defs.h (struct fault_opts): New forward declaration. (struct tcb): Add fault_vec field. (TCB_FAULT_INJ, QUAL_FAULT): New macros. * strace.1: Document -e fault expression syntax. * strace.c (usage): Mention -e fault expression. (droptcb): Deallocate fault_vec member. * syscall.c (qual_fault, arch_set_scno, arch_set_error): New prototypes. (qual_options): Add "fault" option. (struct fault_opts): New structure. (num_faults): New variable. (fault_vec): New array. (syscall_fault_injected, tcb_fault_opts, reallocate_fault, find_errno_by_name, qual_syscall_ex, strip_prefix, parse_fault_token, parse_fault_expression, qual_fault, inject_syscall_fault_entering, update_syscall_fault_exiting): New functions. (qual_syscall): Use qual_syscall_ex. (qualify_one): Add argument: a pointer to struct fault_opts, all callers changed. Copy struct fault_opts from the pointer to fault_vec. Use reallocate_fault. (qualify_scno, qualify_syscall_class, qualify_syscall_name): Add argument: a pointer to struct fault_opts. (qualify): Use reallocate_fault. Do not check "all" class for QUAL_FAULT qualifier. (lookup_class): Check for "all" class. (trace_syscall_entering): Use inject_syscall_fault_entering. (trace_syscall_exiting): Use update_syscall_fault_exiting. Clear TCB_FAULT_INJ flag along with TCB_INSYSCALL. Print " (INJECTED)" suffix when the syscall has been injected successfully. [ARCH_REGS_FOR_GETREGSET && !HAVE_GETREGS_OLD] (ptrace_setregset): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregset. [ARCH_REGS_FOR_GETREGS && !HAVE_GETREGS_OLD] (ptrace_setregs): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregs. [ptrace_setregset_or_setregs] (set_regs): New function. Include "set_scno.c" and "set_error.c" * NEWS: Mention this enhancement.
2016-11-16 20:26:58 +03:00
#include "set_scno.c"
#include "get_syscall_args.c"
#ifndef ptrace_getregset_or_getregs
# include "get_syscall_result.c"
#endif
#include "get_error.c"
Implement syscall fault injection Introduce new -e fault=EXPR syntax that can be used to specify a subset of syscalls that are subject of syscall fault injection, an error code that has to be injected, and a frequency of injection. The expression specifying syscall fault injection has the following format: SET[:error=ERRNO][:when=FIRST[+[STEP]]] where only SET is a required part and all the rest is optional. The method used to implement syscall fault injection is the following: on entering syscall the syscall number is substituted by an invalid syscall number -1, and on exiting syscall the error code returned by the kernel is substituted with the error code specified in the fault expression. This implementaion is based on the prototype developed by Nahim El Atmani as a part of his GSoC 2016 strace project. * defs.h (struct fault_opts): New forward declaration. (struct tcb): Add fault_vec field. (TCB_FAULT_INJ, QUAL_FAULT): New macros. * strace.1: Document -e fault expression syntax. * strace.c (usage): Mention -e fault expression. (droptcb): Deallocate fault_vec member. * syscall.c (qual_fault, arch_set_scno, arch_set_error): New prototypes. (qual_options): Add "fault" option. (struct fault_opts): New structure. (num_faults): New variable. (fault_vec): New array. (syscall_fault_injected, tcb_fault_opts, reallocate_fault, find_errno_by_name, qual_syscall_ex, strip_prefix, parse_fault_token, parse_fault_expression, qual_fault, inject_syscall_fault_entering, update_syscall_fault_exiting): New functions. (qual_syscall): Use qual_syscall_ex. (qualify_one): Add argument: a pointer to struct fault_opts, all callers changed. Copy struct fault_opts from the pointer to fault_vec. Use reallocate_fault. (qualify_scno, qualify_syscall_class, qualify_syscall_name): Add argument: a pointer to struct fault_opts. (qualify): Use reallocate_fault. Do not check "all" class for QUAL_FAULT qualifier. (lookup_class): Check for "all" class. (trace_syscall_entering): Use inject_syscall_fault_entering. (trace_syscall_exiting): Use update_syscall_fault_exiting. Clear TCB_FAULT_INJ flag along with TCB_INSYSCALL. Print " (INJECTED)" suffix when the syscall has been injected successfully. [ARCH_REGS_FOR_GETREGSET && !HAVE_GETREGS_OLD] (ptrace_setregset): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregset. [ARCH_REGS_FOR_GETREGS && !HAVE_GETREGS_OLD] (ptrace_setregs): New function. (ptrace_setregset_or_setregs): Define to ptrace_setregs. [ptrace_setregset_or_setregs] (set_regs): New function. Include "set_scno.c" and "set_error.c" * NEWS: Mention this enhancement.
2016-11-16 20:26:58 +03:00
#include "set_error.c"
#ifdef HAVE_GETREGS_OLD
# include "getregs_old.c"
#endif
#include "shuffle_scno.c"
const char *
syscall_name(kernel_ulong_t scno)
{
return scno_is_valid(scno) ? sysent[scno].sys_name : NULL;
}