From 5503dd28c6cab61af949f592e8bfcdaf1380cfef Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Fri, 13 Feb 2015 02:12:14 +0000 Subject: [PATCH] Move regs-related macros and declarations from defs.h to regs.h * regs.h: New file. * Makefile.am (strace_SOURCES): Add it. * linux/arch_regs.h: New file. * linux/alpha/arch_regs.h: Likewise. * linux/arm/arch_regs.h: Likewise. * linux/hppa/arch_regs.h: Likewise. * linux/i386/arch_regs.h: Likewise. * linux/ia64/arch_regs.h: Likewise. * linux/mips/arch_regs.h: Likewise. * linux/powerpc/arch_regs.h: Likewise. * linux/sh64/arch_regs.h: Likewise. * linux/sparc/arch_regs.h: Likewise. * linux/sparc64/arch_regs.h: Likewise. * linux/tile/arch_regs.h: Likewise. * linux/x86_64/arch_regs.h: Likewise. * Makefile.am (EXTRA_DIST): Add them. * defs.h: Remove definitions of PTRACE_*, REG_*, PT_*, U_REG_*, and ARM_* macros. Remove declarations of struct pt_regs variables. [SPARC]: Do not include . [SPARC64]: Do not include . * bjm.c: Do not include . * process.c: Include "regs.h". Do not include and . [IA64]: Do not include and . * util.c: Likewise. * syscall.c: Likewise. [AARCH64]: Define struct arm_pt_regs and ARM_* macros. [SPARC]: Include . [SPARC64]: Include . * signal.c: Include "regs.h". Do not include and . [IA64]: Do not include . * strace.c [IA64]: Do not include . --- Makefile.am | 14 +++++++ bjm.c | 1 - defs.h | 82 --------------------------------------- linux/alpha/arch_regs.h | 5 +++ linux/arch_regs.h | 1 + linux/arm/arch_regs.h | 1 + linux/hppa/arch_regs.h | 5 +++ linux/i386/arch_regs.h | 1 + linux/ia64/arch_regs.h | 4 ++ linux/mips/arch_regs.h | 5 +++ linux/powerpc/arch_regs.h | 1 + linux/sh64/arch_regs.h | 15 +++++++ linux/sparc/arch_regs.h | 6 +++ linux/sparc64/arch_regs.h | 1 + linux/tile/arch_regs.h | 1 + linux/x86_64/arch_regs.h | 1 + process.c | 19 +-------- regs.h | 7 ++++ signal.c | 10 +---- strace.c | 3 -- syscall.c | 43 ++++++++++++++------ util.c | 11 +----- 22 files changed, 102 insertions(+), 135 deletions(-) create mode 100644 linux/alpha/arch_regs.h create mode 100644 linux/arch_regs.h create mode 100644 linux/arm/arch_regs.h create mode 100644 linux/hppa/arch_regs.h create mode 100644 linux/i386/arch_regs.h create mode 100644 linux/ia64/arch_regs.h create mode 100644 linux/mips/arch_regs.h create mode 100644 linux/powerpc/arch_regs.h create mode 100644 linux/sh64/arch_regs.h create mode 100644 linux/sparc/arch_regs.h create mode 100644 linux/sparc64/arch_regs.h create mode 100644 linux/tile/arch_regs.h create mode 100644 linux/x86_64/arch_regs.h create mode 100644 regs.h diff --git a/Makefile.am b/Makefile.am index d169a784..ac6df197 100644 --- a/Makefile.am +++ b/Makefile.am @@ -83,6 +83,7 @@ strace_SOURCES = \ readahead.c \ readlink.c \ reboot.c \ + regs.h \ renameat.c \ resource.c \ sched.c \ @@ -168,6 +169,7 @@ EXTRA_DIST = \ linux/aarch64/signalent1.h \ linux/aarch64/syscallent.h \ linux/aarch64/syscallent1.h \ + linux/alpha/arch_regs.h \ linux/alpha/errnoent.h \ linux/alpha/ioctls_arch0.h \ linux/alpha/ioctls_inc0.h \ @@ -177,6 +179,8 @@ EXTRA_DIST = \ linux/arc/ioctls_arch0.h \ linux/arc/ioctls_inc0.h \ linux/arc/syscallent.h \ + linux/arch_regs.h \ + linux/arm/arch_regs.h \ linux/arm/ioctls_arch0.h \ linux/arm/ioctls_inc0.h \ linux/arm/syscallent.h \ @@ -194,16 +198,19 @@ EXTRA_DIST = \ linux/dummy.h \ linux/errnoent.h \ linux/fanotify.h \ + linux/hppa/arch_regs.h \ linux/hppa/errnoent.h \ linux/hppa/ioctls_arch0.h \ linux/hppa/ioctls_inc0.h \ linux/hppa/signalent.h \ linux/hppa/syscallent.h \ + linux/i386/arch_regs.h \ linux/i386/ioctls_arch0.h \ linux/i386/ioctls_inc0.h \ linux/i386/syscallent.h \ linux/i386/userent.h \ linux/i386/userent0.h \ + linux/ia64/arch_regs.h \ linux/ia64/ioctls_arch0.h \ linux/ia64/ioctls_inc0.h \ linux/ia64/signalent.h \ @@ -224,6 +231,7 @@ EXTRA_DIST = \ linux/microblaze/ioctls_inc0.h \ linux/microblaze/syscallent.h \ linux/microblaze/userent.h \ + linux/mips/arch_regs.h \ linux/mips/errnoent.h \ linux/mips/genstub.sh \ linux/mips/ioctls_arch0.h \ @@ -241,6 +249,7 @@ EXTRA_DIST = \ linux/or1k/syscallent.h \ linux/or1k/userent.h \ linux/personality.h \ + linux/powerpc/arch_regs.h \ linux/powerpc/ioctls_arch0.h \ linux/powerpc/ioctls_inc0.h \ linux/powerpc/syscallent.h \ @@ -271,12 +280,14 @@ EXTRA_DIST = \ linux/sh/syscallent.h \ linux/sh/userent.h \ linux/sh/userent0.h \ + linux/sh64/arch_regs.h \ linux/sh64/ioctls_arch0.h \ linux/sh64/ioctls_inc0.h \ linux/sh64/syscallent.h \ linux/sh64/userent.h \ linux/signalent.h \ linux/sock_diag.h \ + linux/sparc/arch_regs.h \ linux/sparc/dummy2.h \ linux/sparc/errnoent.h \ linux/sparc/errnoent1.h \ @@ -290,6 +301,7 @@ EXTRA_DIST = \ linux/sparc/syscallent.h \ linux/sparc/syscallent1.h \ linux/sparc/userent.h \ + linux/sparc64/arch_regs.h \ linux/sparc64/dummy2.h \ linux/sparc64/errnoent.h \ linux/sparc64/errnoent1.h \ @@ -309,6 +321,7 @@ EXTRA_DIST = \ linux/sparc64/userent.h \ linux/subcall.h \ linux/syscall.h \ + linux/tile/arch_regs.h \ linux/tile/errnoent1.h \ linux/tile/ioctls_arch0.h \ linux/tile/ioctls_arch1.h \ @@ -333,6 +346,7 @@ EXTRA_DIST = \ linux/x32/syscallent.h \ linux/x32/syscallent1.h \ linux/x32/userent.h \ + linux/x86_64/arch_regs.h \ linux/x86_64/errnoent1.h \ linux/x86_64/errnoent2.h \ linux/x86_64/gentab.pl \ diff --git a/bjm.c b/bjm.c index b34c6ed7..c8d72a30 100644 --- a/bjm.c +++ b/bjm.c @@ -34,7 +34,6 @@ #include #include #include -#include /* Bits of module.flags. */ diff --git a/defs.h b/defs.h index 642f1de0..49ef2ac8 100644 --- a/defs.h +++ b/defs.h @@ -163,81 +163,13 @@ extern char *stpcpy(char *dst, const char *src); # define ERESTART_RESTARTBLOCK 516 #endif -#ifdef ALPHA -# define REG_R0 0 -# define REG_A0 16 -# define REG_A3 19 -# define REG_FP 30 -# define REG_PC 64 -#endif /* ALPHA */ -#ifdef MIPS -# define REG_V0 2 -# define REG_A0 4 -# define REG_A3 7 -# define REG_SP 29 -# define REG_EPC 64 -#endif /* MIPS */ -#ifdef HPPA -# define PT_GR20 (20*4) -# define PT_GR26 (26*4) -# define PT_GR28 (28*4) -# define PT_IAOQ0 (106*4) -# define PT_IAOQ1 (107*4) -#endif /* HPPA */ -#ifdef SH64 - /* SH64 Linux - this code assumes the following kernel API for system calls: - PC Offset 0 - System Call Offset 16 (actually, (syscall no.) | (0x1n << 16), - where n = no. of parameters. - Other regs Offset 24+ - - On entry: R2-7 = parameters 1-6 (as many as necessary) - On return: R9 = result. */ - - /* Offset for peeks of registers */ -# define REG_OFFSET (24) -# define REG_GENERAL(x) (8*(x)+REG_OFFSET) -# define REG_PC (0*8) -# define REG_SYSCALL (2*8) -#endif /* SH64 */ -#ifdef AARCH64 -struct arm_pt_regs { - int uregs[18]; -}; -# define ARM_cpsr uregs[16] -# define ARM_pc uregs[15] -# define ARM_lr uregs[14] -# define ARM_sp uregs[13] -# define ARM_ip uregs[12] -# define ARM_fp uregs[11] -# define ARM_r10 uregs[10] -# define ARM_r9 uregs[9] -# define ARM_r8 uregs[8] -# define ARM_r7 uregs[7] -# define ARM_r6 uregs[6] -# define ARM_r5 uregs[5] -# define ARM_r4 uregs[4] -# define ARM_r3 uregs[3] -# define ARM_r2 uregs[2] -# define ARM_r1 uregs[1] -# define ARM_r0 uregs[0] -# define ARM_ORIG_r0 uregs[17] -#endif /* AARCH64 */ - #if defined(SPARC) || defined(SPARC64) -/* Indexes into the pt_regs.u_reg[] array -- UREG_XX from kernel are all off - * by 1 and use Ix instead of Ox. These work for both 32 and 64 bit Linux. */ -# define U_REG_G1 0 -# define U_REG_O0 7 -# define U_REG_O1 8 # define PERSONALITY0_WORDSIZE 4 # define PERSONALITY1_WORDSIZE 4 # if defined(SPARC64) -# include # define SUPPORTED_PERSONALITIES 3 # define PERSONALITY2_WORDSIZE 8 # else -# include # define SUPPORTED_PERSONALITIES 2 # endif /* SPARC64 */ #endif /* SPARC[64] */ @@ -292,20 +224,6 @@ struct arm_pt_regs { # define PERSONALITY0_WORDSIZE SIZEOF_LONG #endif -#if defined(I386) || defined(X86_64) -extern uint32_t *const i386_esp_ptr; -#elif defined(IA64) -extern bool ia64_ia32mode; -#elif defined(SPARC) || defined(SPARC64) -extern struct pt_regs sparc_regs; -#elif defined(ARM) -extern struct pt_regs arm_regs; -#elif defined(TILE) -extern struct pt_regs tile_regs; -#elif defined(POWERPC) -extern struct pt_regs ppc_regs; -#endif - typedef struct sysent { unsigned nargs; int sys_flags; diff --git a/linux/alpha/arch_regs.h b/linux/alpha/arch_regs.h new file mode 100644 index 00000000..66277fd8 --- /dev/null +++ b/linux/alpha/arch_regs.h @@ -0,0 +1,5 @@ +#define REG_R0 0 +#define REG_A0 16 +#define REG_A3 19 +#define REG_FP 30 +#define REG_PC 64 diff --git a/linux/arch_regs.h b/linux/arch_regs.h new file mode 100644 index 00000000..da84fa5f --- /dev/null +++ b/linux/arch_regs.h @@ -0,0 +1 @@ +/* nothing */ diff --git a/linux/arm/arch_regs.h b/linux/arm/arch_regs.h new file mode 100644 index 00000000..b7638aeb --- /dev/null +++ b/linux/arm/arch_regs.h @@ -0,0 +1 @@ +extern struct pt_regs arm_regs; diff --git a/linux/hppa/arch_regs.h b/linux/hppa/arch_regs.h new file mode 100644 index 00000000..d42fc149 --- /dev/null +++ b/linux/hppa/arch_regs.h @@ -0,0 +1,5 @@ +#define PT_GR20 (20*4) +#define PT_GR26 (26*4) +#define PT_GR28 (28*4) +#define PT_IAOQ0 (106*4) +#define PT_IAOQ1 (107*4) diff --git a/linux/i386/arch_regs.h b/linux/i386/arch_regs.h new file mode 100644 index 00000000..eeb4ebea --- /dev/null +++ b/linux/i386/arch_regs.h @@ -0,0 +1 @@ +extern uint32_t *const i386_esp_ptr; diff --git a/linux/ia64/arch_regs.h b/linux/ia64/arch_regs.h new file mode 100644 index 00000000..519b24f7 --- /dev/null +++ b/linux/ia64/arch_regs.h @@ -0,0 +1,4 @@ +#include +#include + +extern bool ia64_ia32mode; diff --git a/linux/mips/arch_regs.h b/linux/mips/arch_regs.h new file mode 100644 index 00000000..59039c65 --- /dev/null +++ b/linux/mips/arch_regs.h @@ -0,0 +1,5 @@ +#define REG_V0 2 +#define REG_A0 4 +#define REG_A3 7 +#define REG_SP 29 +#define REG_EPC 64 diff --git a/linux/powerpc/arch_regs.h b/linux/powerpc/arch_regs.h new file mode 100644 index 00000000..1296e83e --- /dev/null +++ b/linux/powerpc/arch_regs.h @@ -0,0 +1 @@ +extern struct pt_regs ppc_regs; diff --git a/linux/sh64/arch_regs.h b/linux/sh64/arch_regs.h new file mode 100644 index 00000000..7f64b497 --- /dev/null +++ b/linux/sh64/arch_regs.h @@ -0,0 +1,15 @@ +/* SH64 Linux - this code assumes the following kernel API for system calls: + PC Offset 0 + System Call Offset 16 (actually, (syscall no.) | (0x1n << 16), + where n = no. of parameters. + Other regs Offset 24+ + + On entry: R2-7 = parameters 1-6 (as many as necessary) + On return: R9 = result. +*/ + +/* Offset for peeks of registers */ +#define REG_OFFSET (24) +#define REG_GENERAL(x) (8*(x)+REG_OFFSET) +#define REG_PC (0*8) +#define REG_SYSCALL (2*8) diff --git a/linux/sparc/arch_regs.h b/linux/sparc/arch_regs.h new file mode 100644 index 00000000..4dcae3bb --- /dev/null +++ b/linux/sparc/arch_regs.h @@ -0,0 +1,6 @@ +extern struct pt_regs sparc_regs; +/* Indexes into the pt_regs.u_reg[] array -- UREG_XX from kernel are all off + * by 1 and use Ix instead of Ox. These work for both 32 and 64 bit Linux. */ +#define U_REG_G1 0 +#define U_REG_O0 7 +#define U_REG_O1 8 diff --git a/linux/sparc64/arch_regs.h b/linux/sparc64/arch_regs.h new file mode 100644 index 00000000..a49ad539 --- /dev/null +++ b/linux/sparc64/arch_regs.h @@ -0,0 +1 @@ +#include "sparc/arch_regs.h" diff --git a/linux/tile/arch_regs.h b/linux/tile/arch_regs.h new file mode 100644 index 00000000..cd3f72b3 --- /dev/null +++ b/linux/tile/arch_regs.h @@ -0,0 +1 @@ +extern struct pt_regs tile_regs; diff --git a/linux/x86_64/arch_regs.h b/linux/x86_64/arch_regs.h new file mode 100644 index 00000000..ced226ff --- /dev/null +++ b/linux/x86_64/arch_regs.h @@ -0,0 +1 @@ +#include "i386/arch_regs.h" diff --git a/process.c b/process.c index 677c603c..72c09b78 100644 --- a/process.c +++ b/process.c @@ -42,28 +42,11 @@ #include "xlat/nt_descriptor_types.h" -#include -#ifdef HAVE_SYS_REG_H -# include -#endif - #include "ptrace.h" - -#if defined(SPARC64) -# define r_pc r_tpc -# undef PTRACE_GETREGS -# define PTRACE_GETREGS PTRACE_GETREGS64 -# undef PTRACE_SETREGS -# define PTRACE_SETREGS PTRACE_SETREGS64 -#endif - #include "xlat/ptrace_cmds.h" #include "xlat/ptrace_setoptions_flags.h" -#if defined(IA64) -# include -# include -#endif +#include "regs.h" #define uoff(member) offsetof(struct user, member) #define XLAT_UOFF(member) { uoff(member), "offsetof(struct user, " #member ")" } diff --git a/regs.h b/regs.h new file mode 100644 index 00000000..9b0746cd --- /dev/null +++ b/regs.h @@ -0,0 +1,7 @@ +#include + +#ifdef HAVE_SYS_REG_H +# include +#endif + +#include "arch_regs.h" diff --git a/signal.c b/signal.c index 8fd91b67..b1a486a6 100644 --- a/signal.c +++ b/signal.c @@ -33,17 +33,9 @@ #include "defs.h" #include -#include - -#ifdef HAVE_SYS_REG_H -# include -#endif #include "ptrace.h" - -#ifdef IA64 -# include -#endif +#include "regs.h" #if defined(SPARC) || defined(SPARC64) || defined(MIPS) typedef struct { diff --git a/strace.c b/strace.c index a02ab040..250f49c2 100644 --- a/strace.c +++ b/strace.c @@ -42,9 +42,6 @@ #ifdef HAVE_PRCTL # include #endif -#if defined(IA64) -# include -#endif #include "ptrace.h" diff --git a/syscall.c b/syscall.c index adc17857..e2b1626f 100644 --- a/syscall.c +++ b/syscall.c @@ -32,11 +32,13 @@ */ #include "defs.h" -#include #include -#ifdef HAVE_SYS_REG_H -# include +/* for struct iovec */ +#include +/* for NT_PRSTATUS */ +#ifdef HAVE_ELF_H +# include #endif #include "ptrace.h" @@ -48,16 +50,12 @@ # define PTRACE_SETREGS PTRACE_SETREGS64 #endif -#if defined(IA64) -# include -# include -#endif +#include "regs.h" -/* for struct iovec */ -#include -/* for NT_PRSTATUS */ -#ifdef HAVE_ELF_H -# include +#if defined SPARC64 +# include +#elif defined SPARC +# include #endif #ifndef NSIG @@ -715,6 +713,27 @@ static long bfin_r0; struct pt_regs arm_regs; /* not static */ # define ARCH_REGS_FOR_GETREGSET arm_regs #elif defined(AARCH64) +struct arm_pt_regs { + int uregs[18]; +}; +# define ARM_cpsr uregs[16] +# define ARM_pc uregs[15] +# define ARM_lr uregs[14] +# define ARM_sp uregs[13] +# define ARM_ip uregs[12] +# define ARM_fp uregs[11] +# define ARM_r10 uregs[10] +# define ARM_r9 uregs[9] +# define ARM_r8 uregs[8] +# define ARM_r7 uregs[7] +# define ARM_r6 uregs[6] +# define ARM_r5 uregs[5] +# define ARM_r4 uregs[4] +# define ARM_r3 uregs[3] +# define ARM_r2 uregs[2] +# define ARM_r1 uregs[1] +# define ARM_r0 uregs[0] +# define ARM_ORIG_r0 uregs[17] static union { struct user_pt_regs aarch64_r; struct arm_pt_regs arm_r; diff --git a/util.c b/util.c index c96ccdac..caca556d 100644 --- a/util.c +++ b/util.c @@ -32,7 +32,6 @@ */ #include "defs.h" -#include #include #include #if HAVE_SYS_XATTR_H @@ -40,16 +39,8 @@ #endif #include -#if defined(IA64) -# include -# include -#endif - -#ifdef HAVE_SYS_REG_H -# include -#endif - #include "ptrace.h" +#include "regs.h" int string_to_uint(const char *str) -- 2.40.0