From 917c2ccf3a677ab183d6a5f19dc801669ac2cc51 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Tue, 4 Dec 2018 22:31:41 +0000 Subject: [PATCH] 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. --- Makefile.am | 39 +-------------------------- defs.h | 1 + linux/aarch64/arch_regs.c | 7 ++--- linux/aarch64/arch_regs.h | 2 -- linux/aarch64/arch_rt_sigframe.c | 41 ----------------------------- linux/alpha/arch_regs.c | 8 ++++++ linux/alpha/arch_regs.h | 5 ---- linux/alpha/arch_rt_sigframe.c | 33 ----------------------- linux/alpha/arch_sigreturn.c | 2 +- linux/arc/arch_regs.c | 2 +- linux/arc/arch_regs.h | 1 - linux/arc/arch_rt_sigframe.c | 31 ---------------------- linux/{bfin => }/arch_rt_sigframe.c | 9 ++++--- linux/arm/arch_regs.c | 2 +- linux/arm/arch_regs.h | 1 - linux/arm/arch_rt_sigframe.c | 31 ---------------------- linux/arm/arch_sigreturn.c | 11 +++++--- linux/avr32/arch_regs.c | 2 +- linux/avr32/arch_regs.h | 1 - linux/avr32/arch_rt_sigframe.c | 31 ---------------------- linux/bfin/arch_regs.c | 1 + linux/hppa/arch_regs.c | 9 +++++++ linux/hppa/arch_regs.h | 5 ---- linux/hppa/arch_rt_sigframe.c | 6 ++--- linux/i386/arch_regs.c | 2 +- linux/i386/arch_regs.h | 1 - linux/i386/arch_rt_sigframe.c | 5 ++-- linux/i386/arch_sigreturn.c | 6 ++--- linux/ia64/arch_regs.c | 2 +- linux/ia64/arch_regs.h | 1 - linux/ia64/arch_rt_sigframe.c | 5 ++-- linux/m68k/arch_regs.c | 4 +-- linux/m68k/arch_regs.h | 1 - linux/m68k/arch_rt_sigframe.c | 32 +--------------------- linux/m68k/arch_sigreturn.c | 9 ++++--- linux/metag/arch_regs.c | 2 +- linux/metag/arch_regs.h | 1 - linux/metag/arch_rt_sigframe.c | 6 +++-- linux/microblaze/arch_regs.c | 1 + linux/microblaze/arch_rt_sigframe.c | 33 ----------------------- linux/mips/arch_regs.c | 19 ++++++++++++- linux/mips/arch_regs.h | 18 ------------- linux/mips/arch_rt_sigframe.c | 31 ---------------------- linux/mips/arch_sigreturn.c | 6 +++-- linux/nios2/arch_regs.c | 2 +- linux/nios2/arch_regs.h | 1 - linux/nios2/arch_rt_sigframe.c | 31 ---------------------- linux/or1k/arch_regs.c | 2 +- linux/or1k/arch_regs.h | 1 - linux/or1k/arch_rt_sigframe.c | 31 ---------------------- linux/powerpc/arch_regs.c | 3 ++- linux/powerpc/arch_regs.h | 1 - linux/powerpc/arch_rt_sigframe.c | 5 ++-- linux/powerpc/arch_sigreturn.c | 10 ++++--- linux/powerpc64/arch_regs.h | 1 - linux/powerpc64/arch_rt_sigframe.c | 8 +++--- linux/riscv/arch_regs.c | 2 +- linux/riscv/arch_regs.h | 1 - linux/riscv/arch_rt_sigframe.c | 31 ---------------------- linux/s390/arch_regs.c | 2 +- linux/s390/arch_regs.h | 1 - linux/s390/arch_rt_sigframe.c | 31 ---------------------- linux/s390/arch_sigreturn.c | 15 +++++------ linux/s390x/arch_regs.c | 6 ++--- linux/s390x/arch_regs.h | 2 -- linux/s390x/arch_rt_sigframe.c | 4 --- linux/s390x/arch_sigreturn.c | 3 --- linux/sh/arch_regs.c | 1 + linux/sh/arch_rt_sigframe.c | 33 ----------------------- linux/sh64/arch_regs.c | 1 + linux/sh64/arch_rt_sigframe.c | 1 - linux/sparc/arch_regs.c | 11 +++++++- linux/sparc/arch_regs.h | 7 ----- linux/sparc/arch_rt_sigframe.c | 31 ---------------------- linux/sparc/arch_sigreturn.c | 10 +++---- linux/sparc64/arch_regs.h | 1 - linux/sparc64/arch_rt_sigframe.c | 9 ++++--- linux/tile/arch_regs.c | 3 ++- linux/tile/arch_regs.h | 1 - linux/tile/arch_rt_sigframe.c | 31 ---------------------- linux/tile/arch_sigreturn.c | 7 +++-- linux/x86_64/arch_regs.c | 7 ++--- linux/x86_64/arch_regs.h | 2 -- linux/x86_64/arch_rt_sigframe.c | 40 ---------------------------- linux/xtensa/arch_regs.c | 1 + linux/xtensa/arch_rt_sigframe.c | 33 ----------------------- syscall.c | 17 ++++++++++++ 87 files changed, 172 insertions(+), 735 deletions(-) delete mode 100644 linux/aarch64/arch_regs.h delete mode 100644 linux/aarch64/arch_rt_sigframe.c delete mode 100644 linux/alpha/arch_regs.h delete mode 100644 linux/alpha/arch_rt_sigframe.c delete mode 100644 linux/arc/arch_regs.h delete mode 100644 linux/arc/arch_rt_sigframe.c rename linux/{bfin => }/arch_rt_sigframe.c (88%) delete mode 100644 linux/arm/arch_regs.h delete mode 100644 linux/arm/arch_rt_sigframe.c delete mode 100644 linux/avr32/arch_regs.h delete mode 100644 linux/avr32/arch_rt_sigframe.c delete mode 100644 linux/hppa/arch_regs.h delete mode 100644 linux/i386/arch_regs.h delete mode 100644 linux/m68k/arch_regs.h delete mode 100644 linux/metag/arch_regs.h delete mode 100644 linux/microblaze/arch_rt_sigframe.c delete mode 100644 linux/mips/arch_regs.h delete mode 100644 linux/mips/arch_rt_sigframe.c delete mode 100644 linux/nios2/arch_regs.h delete mode 100644 linux/nios2/arch_rt_sigframe.c delete mode 100644 linux/or1k/arch_regs.h delete mode 100644 linux/or1k/arch_rt_sigframe.c delete mode 100644 linux/powerpc/arch_regs.h delete mode 100644 linux/powerpc64/arch_regs.h delete mode 100644 linux/riscv/arch_regs.h delete mode 100644 linux/riscv/arch_rt_sigframe.c delete mode 100644 linux/s390/arch_regs.h delete mode 100644 linux/s390/arch_rt_sigframe.c delete mode 100644 linux/s390x/arch_regs.h delete mode 100644 linux/s390x/arch_rt_sigframe.c delete mode 100644 linux/sh/arch_rt_sigframe.c delete mode 100644 linux/sh64/arch_rt_sigframe.c delete mode 100644 linux/sparc/arch_regs.h delete mode 100644 linux/sparc/arch_rt_sigframe.c delete mode 100644 linux/sparc64/arch_regs.h delete mode 100644 linux/tile/arch_regs.h delete mode 100644 linux/tile/arch_rt_sigframe.c delete mode 100644 linux/xtensa/arch_rt_sigframe.c diff --git a/Makefile.am b/Makefile.am index 66111cee..7da98a36 100644 --- a/Makefile.am +++ b/Makefile.am @@ -434,8 +434,6 @@ EXTRA_DIST = \ linux/64/syscallent.h \ linux/aarch64/arch_defs_.h \ linux/aarch64/arch_regs.c \ - linux/aarch64/arch_regs.h \ - linux/aarch64/arch_rt_sigframe.c \ linux/aarch64/arch_sigreturn.c \ linux/aarch64/get_error.c \ linux/aarch64/get_scno.c \ @@ -454,8 +452,6 @@ EXTRA_DIST = \ linux/alpha/arch_defs_.h \ linux/alpha/arch_getrval2.c \ linux/alpha/arch_regs.c \ - linux/alpha/arch_regs.h \ - linux/alpha/arch_rt_sigframe.c \ linux/alpha/arch_sigreturn.c \ linux/alpha/errnoent.h \ linux/alpha/get_error.c \ @@ -471,8 +467,6 @@ EXTRA_DIST = \ linux/alpha/syscallent.h \ linux/alpha/userent.h \ linux/arc/arch_regs.c \ - linux/arc/arch_regs.h \ - linux/arc/arch_rt_sigframe.c \ linux/arc/get_error.c \ linux/arc/get_scno.c \ linux/arc/get_syscall_args.c \ @@ -485,11 +479,10 @@ EXTRA_DIST = \ linux/arch_defs_.h \ linux/arch_kvm.c \ linux/arch_regs.h \ + linux/arch_rt_sigframe.c \ linux/arch_sigreturn.c \ linux/arm/arch_defs_.h \ linux/arm/arch_regs.c \ - linux/arm/arch_regs.h \ - linux/arm/arch_rt_sigframe.c \ linux/arm/arch_sigreturn.c \ linux/arm/get_error.c \ linux/arm/get_scno.c \ @@ -504,8 +497,6 @@ EXTRA_DIST = \ linux/arm/syscallent.h \ linux/arm/userent.h \ linux/avr32/arch_regs.c \ - linux/avr32/arch_regs.h \ - linux/avr32/arch_rt_sigframe.c \ linux/avr32/get_error.c \ linux/avr32/get_scno.c \ linux/avr32/get_syscall_args.c \ @@ -518,7 +509,6 @@ EXTRA_DIST = \ linux/avr32/userent.h \ linux/bfin/arch_defs_.h \ linux/bfin/arch_regs.c \ - linux/bfin/arch_rt_sigframe.c \ linux/bfin/get_error.c \ linux/bfin/get_scno.c \ linux/bfin/get_syscall_args.c \ @@ -536,7 +526,6 @@ EXTRA_DIST = \ linux/getregs_old.h \ linux/hppa/arch_defs_.h \ linux/hppa/arch_regs.c \ - linux/hppa/arch_regs.h \ linux/hppa/arch_rt_sigframe.c \ linux/hppa/errnoent.h \ linux/hppa/get_error.c \ @@ -554,7 +543,6 @@ EXTRA_DIST = \ linux/i386/arch_kvm.c \ linux/i386/arch_defs_.h \ linux/i386/arch_regs.c \ - linux/i386/arch_regs.h \ linux/i386/arch_rt_sigframe.c \ linux/i386/arch_sigreturn.c \ linux/i386/get_error.c \ @@ -588,7 +576,6 @@ EXTRA_DIST = \ linux/inet_diag.h \ linux/m68k/arch_defs_.h \ linux/m68k/arch_regs.c \ - linux/m68k/arch_regs.h \ linux/m68k/arch_rt_sigframe.c \ linux/m68k/arch_sigreturn.c \ linux/m68k/get_error.c \ @@ -603,7 +590,6 @@ EXTRA_DIST = \ linux/m68k/syscallent.h \ linux/m68k/userent.h \ linux/metag/arch_regs.c \ - linux/metag/arch_regs.h \ linux/metag/arch_rt_sigframe.c \ linux/metag/get_error.c \ linux/metag/get_scno.c \ @@ -616,7 +602,6 @@ EXTRA_DIST = \ linux/metag/syscallent.h \ linux/microblaze/arch_defs_.h \ linux/microblaze/arch_regs.c \ - linux/microblaze/arch_rt_sigframe.c \ linux/microblaze/arch_sigreturn.c \ linux/microblaze/get_error.c \ linux/microblaze/get_scno.c \ @@ -632,8 +617,6 @@ EXTRA_DIST = \ linux/mips/arch_defs_.h \ linux/mips/arch_getrval2.c \ linux/mips/arch_regs.c \ - linux/mips/arch_regs.h \ - linux/mips/arch_rt_sigframe.c \ linux/mips/arch_sigreturn.c \ linux/mips/errnoent.h \ linux/mips/genstub.sh \ @@ -656,8 +639,6 @@ EXTRA_DIST = \ linux/netlink_diag.h \ linux/nios2/arch_defs_.h \ linux/nios2/arch_regs.c \ - linux/nios2/arch_regs.h \ - linux/nios2/arch_rt_sigframe.c \ linux/nios2/get_error.c \ linux/nios2/get_scno.c \ linux/nios2/get_syscall_args.c \ @@ -669,8 +650,6 @@ EXTRA_DIST = \ linux/nios2/syscallent.h \ linux/nr_prefix.c \ linux/or1k/arch_regs.c \ - linux/or1k/arch_regs.h \ - linux/or1k/arch_rt_sigframe.c \ linux/or1k/get_error.c \ linux/or1k/get_scno.c \ linux/or1k/get_syscall_args.c \ @@ -684,7 +663,6 @@ EXTRA_DIST = \ linux/packet_diag.h \ linux/powerpc/arch_defs_.h \ linux/powerpc/arch_regs.c \ - linux/powerpc/arch_regs.h \ linux/powerpc/arch_rt_sigframe.c \ linux/powerpc/arch_sigreturn.c \ linux/powerpc/errnoent.h \ @@ -702,7 +680,6 @@ EXTRA_DIST = \ linux/powerpc/userent.h \ linux/powerpc64/arch_defs_.h \ linux/powerpc64/arch_regs.c \ - linux/powerpc64/arch_regs.h \ linux/powerpc64/arch_rt_sigframe.c \ linux/powerpc64/arch_sigreturn.c \ linux/powerpc64/errnoent.h \ @@ -725,8 +702,6 @@ EXTRA_DIST = \ linux/raw_syscall.h \ linux/riscv/arch_defs_.h \ linux/riscv/arch_regs.c \ - linux/riscv/arch_regs.h \ - linux/riscv/arch_rt_sigframe.c \ linux/riscv/get_error.c \ linux/riscv/get_scno.c \ linux/riscv/get_syscall_args.c \ @@ -742,8 +717,6 @@ EXTRA_DIST = \ linux/rt_sigframe.h \ linux/s390/arch_defs_.h \ linux/s390/arch_regs.c \ - linux/s390/arch_regs.h \ - linux/s390/arch_rt_sigframe.c \ linux/s390/arch_sigreturn.c \ linux/s390/get_error.c \ linux/s390/get_scno.c \ @@ -760,8 +733,6 @@ EXTRA_DIST = \ linux/s390/userent1.h \ linux/s390x/arch_defs_.h \ linux/s390x/arch_regs.c \ - linux/s390x/arch_regs.h \ - linux/s390x/arch_rt_sigframe.c \ linux/s390x/arch_sigreturn.c \ linux/s390x/get_error.c \ linux/s390x/get_scno.c \ @@ -780,7 +751,6 @@ EXTRA_DIST = \ linux/sh/arch_defs_.h \ linux/sh/arch_getrval2.c \ linux/sh/arch_regs.c \ - linux/sh/arch_rt_sigframe.c \ linux/sh/get_error.c \ linux/sh/get_scno.c \ linux/sh/get_syscall_args.c \ @@ -796,7 +766,6 @@ EXTRA_DIST = \ linux/sh64/arch_defs_.h \ linux/sh64/arch_regs.c \ linux/sh64/arch_regs.h \ - linux/sh64/arch_rt_sigframe.c \ linux/sh64/get_error.c \ linux/sh64/get_scno.c \ linux/sh64/get_syscall_args.c \ @@ -817,8 +786,6 @@ EXTRA_DIST = \ linux/sparc/arch_defs_.h \ linux/sparc/arch_getrval2.c \ linux/sparc/arch_regs.c \ - linux/sparc/arch_regs.h \ - linux/sparc/arch_rt_sigframe.c \ linux/sparc/arch_sigreturn.c \ linux/sparc/errnoent.h \ linux/sparc/get_error.c \ @@ -836,7 +803,6 @@ EXTRA_DIST = \ linux/sparc64/arch_defs_.h \ linux/sparc64/arch_getrval2.c \ linux/sparc64/arch_regs.c \ - linux/sparc64/arch_regs.h \ linux/sparc64/arch_rt_sigframe.c \ linux/sparc64/arch_sigreturn.c \ linux/sparc64/errnoent.h \ @@ -859,8 +825,6 @@ EXTRA_DIST = \ linux/syscall.h \ linux/tile/arch_defs_.h \ linux/tile/arch_regs.c \ - linux/tile/arch_regs.h \ - linux/tile/arch_rt_sigframe.c \ linux/tile/arch_sigreturn.c \ linux/tile/get_error.c \ linux/tile/get_scno.c \ @@ -927,7 +891,6 @@ EXTRA_DIST = \ linux/x86_64/syscallent2.h \ linux/x86_64/userent.h \ linux/xtensa/arch_regs.c \ - linux/xtensa/arch_rt_sigframe.c \ linux/xtensa/get_error.c \ linux/xtensa/get_scno.c \ linux/xtensa/get_syscall_args.c \ diff --git a/defs.h b/defs.h index 3003a556..25c9f4db 100644 --- a/defs.h +++ b/defs.h @@ -443,6 +443,7 @@ extern void set_sortby(const char *); extern void set_overhead(int); extern bool get_instruction_pointer(struct tcb *, kernel_ulong_t *); +extern bool get_stack_pointer(struct tcb *, kernel_ulong_t *); extern void print_instruction_pointer(struct tcb *); extern int syscall_entering_decode(struct tcb *); diff --git a/linux/aarch64/arch_regs.c b/linux/aarch64/arch_regs.c index 234d8c3b..03cd7d4c 100644 --- a/linux/aarch64/arch_regs.c +++ b/linux/aarch64/arch_regs.c @@ -27,15 +27,16 @@ static union { #define aarch64_regs arm_regs_union.aarch64_r #define arm_regs arm_regs_union.arm_r -uint64_t *const aarch64_sp_ptr = (uint64_t *) &aarch64_regs.sp; -uint32_t *const arm_sp_ptr = &arm_regs.ARM_sp; static struct iovec aarch64_io = { .iov_base = &arm_regs_union }; #define ARCH_REGS_FOR_GETREGSET arm_regs_union #define ARCH_IOVEC_FOR_GETREGSET aarch64_io -#define ARCH_PC_REG ((aarch64_io.iov_len == sizeof(arm_regs)) ? arm_regs.ARM_pc : aarch64_regs.pc) +#define ARCH_PC_REG \ + ((aarch64_io.iov_len == sizeof(arm_regs)) ? arm_regs.ARM_pc : aarch64_regs.pc) +#define ARCH_SP_REG \ + ((aarch64_io.iov_len == sizeof(arm_regs)) ? arm_regs.ARM_sp : aarch64_regs.sp) #define ARCH_PERSONALITY_0_IOV_SIZE sizeof(aarch64_regs) #define ARCH_PERSONALITY_1_IOV_SIZE sizeof(arm_regs) diff --git a/linux/aarch64/arch_regs.h b/linux/aarch64/arch_regs.h deleted file mode 100644 index 9a5e33e0..00000000 --- a/linux/aarch64/arch_regs.h +++ /dev/null @@ -1,2 +0,0 @@ -extern uint64_t *const aarch64_sp_ptr; -extern uint32_t *const arm_sp_ptr; diff --git a/linux/aarch64/arch_rt_sigframe.c b/linux/aarch64/arch_rt_sigframe.c deleted file mode 100644 index 5400a523..00000000 --- a/linux/aarch64/arch_rt_sigframe.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2017 Dmitry V. Levin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#undef FUNC_GET_RT_SIGFRAME_ADDR -#define FUNC_GET_RT_SIGFRAME_ADDR \ - static kernel_ulong_t arm_get_rt_sigframe_addr(struct tcb *tcp) - -#include "arm/arch_rt_sigframe.c" - -#undef FUNC_GET_RT_SIGFRAME_ADDR -#define FUNC_GET_RT_SIGFRAME_ADDR DEF_FUNC_GET_RT_SIGFRAME_ADDR - -FUNC_GET_RT_SIGFRAME_ADDR -{ - return tcp->currpers == 1 ? arm_get_rt_sigframe_addr(tcp) - : *aarch64_sp_ptr; -} diff --git a/linux/alpha/arch_regs.c b/linux/alpha/arch_regs.c index 4d397996..a35e8651 100644 --- a/linux/alpha/arch_regs.c +++ b/linux/alpha/arch_regs.c @@ -1,3 +1,11 @@ static unsigned long alpha_r0; static unsigned long alpha_a3; + +#define REG_R0 0 +#define REG_A0 16 +#define REG_A3 19 +#define REG_SP 30 +#define REG_PC 64 + #define ARCH_PC_PEEK_ADDR REG_PC +#define ARCH_SP_PEEK_ADDR REG_SP diff --git a/linux/alpha/arch_regs.h b/linux/alpha/arch_regs.h deleted file mode 100644 index 66277fd8..00000000 --- a/linux/alpha/arch_regs.h +++ /dev/null @@ -1,5 +0,0 @@ -#define REG_R0 0 -#define REG_A0 16 -#define REG_A3 19 -#define REG_FP 30 -#define REG_PC 64 diff --git a/linux/alpha/arch_rt_sigframe.c b/linux/alpha/arch_rt_sigframe.c deleted file mode 100644 index d341be13..00000000 --- a/linux/alpha/arch_rt_sigframe.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2017 Dmitry V. Levin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -FUNC_GET_RT_SIGFRAME_ADDR -{ - unsigned long addr; - - return upeek(tcp, REG_FP, &addr) ? 0 : addr; -} diff --git a/linux/alpha/arch_sigreturn.c b/linux/alpha/arch_sigreturn.c index 396187ab..b8b7716e 100644 --- a/linux/alpha/arch_sigreturn.c +++ b/linux/alpha/arch_sigreturn.c @@ -3,7 +3,7 @@ arch_sigreturn(struct tcb *tcp) { unsigned long addr; - if (upeek(tcp, REG_FP, &addr) < 0) + if (!get_stack_pointer(tcp, &addr)) return; addr += offsetof(struct sigcontext, sc_mask); diff --git a/linux/arc/arch_regs.c b/linux/arc/arch_regs.c index 88bb7998..07849a3c 100644 --- a/linux/arc/arch_regs.c +++ b/linux/arc/arch_regs.c @@ -1,4 +1,4 @@ static struct user_regs_struct arc_regs; -unsigned long *const arc_sp_ptr = &arc_regs.scratch.sp; #define ARCH_REGS_FOR_GETREGSET arc_regs #define ARCH_PC_REG arc_regs.efa +#define ARCH_SP_REG arc_regs.scratch.sp diff --git a/linux/arc/arch_regs.h b/linux/arc/arch_regs.h deleted file mode 100644 index 75c850a8..00000000 --- a/linux/arc/arch_regs.h +++ /dev/null @@ -1 +0,0 @@ -extern unsigned long *const arc_sp_ptr; diff --git a/linux/arc/arch_rt_sigframe.c b/linux/arc/arch_rt_sigframe.c deleted file mode 100644 index a735d046..00000000 --- a/linux/arc/arch_rt_sigframe.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2017 Dmitry V. Levin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -FUNC_GET_RT_SIGFRAME_ADDR -{ - return *arc_sp_ptr; -} diff --git a/linux/bfin/arch_rt_sigframe.c b/linux/arch_rt_sigframe.c similarity index 88% rename from linux/bfin/arch_rt_sigframe.c rename to linux/arch_rt_sigframe.c index 1692685c..31030915 100644 --- a/linux/bfin/arch_rt_sigframe.c +++ b/linux/arch_rt_sigframe.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Dmitry V. Levin + * Copyright (c) 2017-2018 Dmitry V. Levin * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,9 +25,10 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/* This is a generic definition for compatible architectures. */ + FUNC_GET_RT_SIGFRAME_ADDR { - unsigned long addr; - - return upeek(tcp, PT_USP, &addr) ? 0 : addr; + kernel_ulong_t sp; + return get_stack_pointer(tcp, &sp) ? sp : 0; } diff --git a/linux/arm/arch_regs.c b/linux/arm/arch_regs.c index 8b73cb86..1a8269c1 100644 --- a/linux/arm/arch_regs.c +++ b/linux/arm/arch_regs.c @@ -1,5 +1,5 @@ static struct pt_regs arm_regs; -unsigned long *const arm_sp_ptr = (unsigned long *) &arm_regs.ARM_sp; #define ARCH_REGS_FOR_GETREGS arm_regs #define ARCH_PC_REG arm_regs.ARM_pc +#define ARCH_SP_REG arm_regs.ARM_sp diff --git a/linux/arm/arch_regs.h b/linux/arm/arch_regs.h deleted file mode 100644 index 4edd50c7..00000000 --- a/linux/arm/arch_regs.h +++ /dev/null @@ -1 +0,0 @@ -extern unsigned long *const arm_sp_ptr; diff --git a/linux/arm/arch_rt_sigframe.c b/linux/arm/arch_rt_sigframe.c deleted file mode 100644 index 0282bd37..00000000 --- a/linux/arm/arch_rt_sigframe.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2017 Dmitry V. Levin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -FUNC_GET_RT_SIGFRAME_ADDR -{ - return *arm_sp_ptr; -} diff --git a/linux/arm/arch_sigreturn.c b/linux/arm/arch_sigreturn.c index a2b71004..6edc7649 100644 --- a/linux/arm/arch_sigreturn.c +++ b/linux/arm/arch_sigreturn.c @@ -1,18 +1,21 @@ static void arch_sigreturn(struct tcb *tcp) { + kernel_ulong_t sp; + if (!get_stack_pointer(tcp, &sp)) + return; + #define SIZEOF_STRUCT_SIGINFO 128 #define SIZEOF_STRUCT_SIGCONTEXT (21 * 4) #define OFFSETOF_STRUCT_UCONTEXT_UC_SIGMASK (5 * 4 + SIZEOF_STRUCT_SIGCONTEXT) - const unsigned long addr = + const kernel_ulong_t addr = #ifdef AARCH64 tcp->currpers == 0 ? - (*aarch64_sp_ptr + SIZEOF_STRUCT_SIGINFO + + (sp + SIZEOF_STRUCT_SIGINFO + offsetof(ucontext_t, uc_sigmask)) : #endif - (*arm_sp_ptr + - OFFSETOF_STRUCT_UCONTEXT_UC_SIGMASK); + (sp + OFFSETOF_STRUCT_UCONTEXT_UC_SIGMASK); tprints("{mask="); print_sigset_addr(tcp, addr); tprints("}"); diff --git a/linux/avr32/arch_regs.c b/linux/avr32/arch_regs.c index 2f88d8f0..578e2acb 100644 --- a/linux/avr32/arch_regs.c +++ b/linux/avr32/arch_regs.c @@ -1,4 +1,4 @@ static struct pt_regs avr32_regs; -unsigned long *const avr32_sp_ptr = &avr32_regs.sp; #define ARCH_REGS_FOR_GETREGS avr32_regs #define ARCH_PC_REG avr32_regs.pc +#define ARCH_SP_REG avr32_regs.sp diff --git a/linux/avr32/arch_regs.h b/linux/avr32/arch_regs.h deleted file mode 100644 index 4ed62ddb..00000000 --- a/linux/avr32/arch_regs.h +++ /dev/null @@ -1 +0,0 @@ -extern unsigned long *const avr32_sp_ptr; diff --git a/linux/avr32/arch_rt_sigframe.c b/linux/avr32/arch_rt_sigframe.c deleted file mode 100644 index 6650f8e7..00000000 --- a/linux/avr32/arch_rt_sigframe.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2017 Dmitry V. Levin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -FUNC_GET_RT_SIGFRAME_ADDR -{ - return *avr32_sp_ptr; -} diff --git a/linux/bfin/arch_regs.c b/linux/bfin/arch_regs.c index ea76cb98..6017f67d 100644 --- a/linux/bfin/arch_regs.c +++ b/linux/bfin/arch_regs.c @@ -1,2 +1,3 @@ static unsigned long bfin_r0; #define ARCH_PC_PEEK_ADDR PT_PC +#define ARCH_SP_PEEK_ADDR PT_USP diff --git a/linux/hppa/arch_regs.c b/linux/hppa/arch_regs.c index 7113bdb6..2a19ddab 100644 --- a/linux/hppa/arch_regs.c +++ b/linux/hppa/arch_regs.c @@ -1,2 +1,11 @@ static unsigned long hppa_r28; + +#define PT_GR20 (20*4) +#define PT_GR26 (26*4) +#define PT_GR28 (28*4) +#define PT_GR30 (30*4) +#define PT_IAOQ0 (106*4) +#define PT_IAOQ1 (107*4) + #define ARCH_PC_PEEK_ADDR PT_IAOQ0 +#define ARCH_SP_PEEK_ADDR PT_GR30 diff --git a/linux/hppa/arch_regs.h b/linux/hppa/arch_regs.h deleted file mode 100644 index d42fc149..00000000 --- a/linux/hppa/arch_regs.h +++ /dev/null @@ -1,5 +0,0 @@ -#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/hppa/arch_rt_sigframe.c b/linux/hppa/arch_rt_sigframe.c index aaf2ffe7..b340f207 100644 --- a/linux/hppa/arch_rt_sigframe.c +++ b/linux/hppa/arch_rt_sigframe.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Dmitry V. Levin + * Copyright (c) 2017-2018 Dmitry V. Levin * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -36,6 +36,6 @@ FUNC_GET_RT_SIGFRAME_ADDR { unsigned long addr; - return upeek(tcp, 4 * 30, &addr) - ? 0 : (addr & ~1UL) - RT_SIGFRAME_SIZE; + return get_stack_pointer(tcp, &addr) + ? (addr & ~1UL) - RT_SIGFRAME_SIZE : 0; } diff --git a/linux/i386/arch_regs.c b/linux/i386/arch_regs.c index 0dcea1f0..a5cf9e90 100644 --- a/linux/i386/arch_regs.c +++ b/linux/i386/arch_regs.c @@ -1,5 +1,5 @@ static struct user_regs_struct i386_regs; -unsigned long *const i386_esp_ptr = (unsigned long *) &i386_regs.esp; #define ARCH_REGS_FOR_GETREGS i386_regs #define ARCH_PC_REG i386_regs.eip +#define ARCH_SP_REG i386_regs.esp diff --git a/linux/i386/arch_regs.h b/linux/i386/arch_regs.h deleted file mode 100644 index 6f622092..00000000 --- a/linux/i386/arch_regs.h +++ /dev/null @@ -1 +0,0 @@ -extern unsigned long *const i386_esp_ptr; diff --git a/linux/i386/arch_rt_sigframe.c b/linux/i386/arch_rt_sigframe.c index b5084082..7b611e93 100644 --- a/linux/i386/arch_rt_sigframe.c +++ b/linux/i386/arch_rt_sigframe.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Dmitry V. Levin + * Copyright (c) 2017-2018 Dmitry V. Levin * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -27,5 +27,6 @@ FUNC_GET_RT_SIGFRAME_ADDR { - return *i386_esp_ptr - 4; + kernel_ulong_t sp; + return get_stack_pointer(tcp, &sp) ? sp - current_klongsize : 0; } diff --git a/linux/i386/arch_sigreturn.c b/linux/i386/arch_sigreturn.c index 9446994e..058a4a6e 100644 --- a/linux/i386/arch_sigreturn.c +++ b/linux/i386/arch_sigreturn.c @@ -13,10 +13,10 @@ arch_sigreturn(struct tcb *tcp) uint32_t struct_fpstate_padding[156]; uint32_t extramask; } frame; + kernel_ulong_t sp; - if (umove(tcp, *i386_esp_ptr, &frame) < 0) { - tprintf("{mask=%#lx}", (unsigned long) *i386_esp_ptr); - } else { + if (get_stack_pointer(tcp, &sp) && + !umove_or_printaddr(tcp, sp, &frame)) { uint32_t mask[2] = { frame.oldmask, frame.extramask }; tprintsigmask_addr("{mask=", mask); tprints("}"); diff --git a/linux/ia64/arch_regs.c b/linux/ia64/arch_regs.c index b79918e3..9251eaae 100644 --- a/linux/ia64/arch_regs.c +++ b/linux/ia64/arch_regs.c @@ -1,5 +1,5 @@ static struct pt_all_user_regs ia64_regs; -unsigned long *const ia64_frame_ptr = &ia64_regs.gr[12]; #define ARCH_REGS_FOR_GETREGS ia64_regs #define ARCH_PC_REG ia64_regs.br[0] +#define ARCH_SP_REG ia64_regs.gr[12] diff --git a/linux/ia64/arch_regs.h b/linux/ia64/arch_regs.h index 7ad969c8..2dcdc414 100644 --- a/linux/ia64/arch_regs.h +++ b/linux/ia64/arch_regs.h @@ -1,2 +1 @@ #include -extern unsigned long *const ia64_frame_ptr; diff --git a/linux/ia64/arch_rt_sigframe.c b/linux/ia64/arch_rt_sigframe.c index f6e660c0..542febe5 100644 --- a/linux/ia64/arch_rt_sigframe.c +++ b/linux/ia64/arch_rt_sigframe.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Dmitry V. Levin + * Copyright (c) 2017-2018 Dmitry V. Levin * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -27,5 +27,6 @@ FUNC_GET_RT_SIGFRAME_ADDR { - return *ia64_frame_ptr + 16; + kernel_ulong_t sp; + return get_stack_pointer(tcp, &sp) ? sp + 16 : 0; } diff --git a/linux/m68k/arch_regs.c b/linux/m68k/arch_regs.c index 3d4c3d9e..08489580 100644 --- a/linux/m68k/arch_regs.c +++ b/linux/m68k/arch_regs.c @@ -1,4 +1,4 @@ static struct user_regs_struct m68k_regs; -unsigned long *const m68k_usp_ptr = (unsigned long *) &m68k_regs.usp; -#define ARCH_PC_REG m68k_regs.pc #define ARCH_REGS_FOR_GETREGS m68k_regs +#define ARCH_PC_REG m68k_regs.pc +#define ARCH_SP_REG m68k_regs.usp diff --git a/linux/m68k/arch_regs.h b/linux/m68k/arch_regs.h deleted file mode 100644 index 424ec11c..00000000 --- a/linux/m68k/arch_regs.h +++ /dev/null @@ -1 +0,0 @@ -extern unsigned long *const m68k_usp_ptr; diff --git a/linux/m68k/arch_rt_sigframe.c b/linux/m68k/arch_rt_sigframe.c index 9ba26e1b..bb60b44d 100644 --- a/linux/m68k/arch_rt_sigframe.c +++ b/linux/m68k/arch_rt_sigframe.c @@ -1,31 +1 @@ -/* - * Copyright (c) 2017 Dmitry V. Levin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -FUNC_GET_RT_SIGFRAME_ADDR -{ - return *m68k_usp_ptr - 4; -} +#include "i386/arch_rt_sigframe.c" diff --git a/linux/m68k/arch_sigreturn.c b/linux/m68k/arch_sigreturn.c index b1402683..382815cd 100644 --- a/linux/m68k/arch_sigreturn.c +++ b/linux/m68k/arch_sigreturn.c @@ -1,20 +1,21 @@ static void arch_sigreturn(struct tcb *tcp) { - unsigned long addr; + unsigned long addr, sp; /* Fetch pointer to struct sigcontext. */ - if (umove(tcp, *m68k_usp_ptr + 2 * sizeof(int), &addr) < 0) + if (!get_stack_pointer(tcp, &sp) || + umove_or_printaddr(tcp, sp + 2 * sizeof(int), &addr)) return; unsigned long mask[NSIG_BYTES / sizeof(long)]; /* Fetch first word of signal mask. */ - if (umove(tcp, addr, &mask[0]) < 0) + if (umove_or_printaddr(tcp, addr, &mask[0])) return; /* Fetch remaining words of signal mask, located immediately before. */ addr -= sizeof(mask) - sizeof(long); - if (umoven(tcp, addr, sizeof(mask) - sizeof(long), &mask[1]) < 0) + if (umoven_or_printaddr(tcp, addr, sizeof(mask) - sizeof(long), &mask[1])) return; tprintsigmask_addr("{mask=", mask); diff --git a/linux/metag/arch_regs.c b/linux/metag/arch_regs.c index 5944723a..08179fae 100644 --- a/linux/metag/arch_regs.c +++ b/linux/metag/arch_regs.c @@ -1,4 +1,4 @@ static struct user_gp_regs metag_regs; -unsigned long *const metag_sp_ptr = &metag_regs.ax[0][0]; #define ARCH_REGS_FOR_GETREGSET metag_regs #define ARCH_PC_REG metag_regs.pc +#define ARCH_SP_REG metag_regs.ax[0][0] diff --git a/linux/metag/arch_regs.h b/linux/metag/arch_regs.h deleted file mode 100644 index 3344c92b..00000000 --- a/linux/metag/arch_regs.h +++ /dev/null @@ -1 +0,0 @@ -extern unsigned long *const metag_sp_ptr; diff --git a/linux/metag/arch_rt_sigframe.c b/linux/metag/arch_rt_sigframe.c index 898c5d24..0e415234 100644 --- a/linux/metag/arch_rt_sigframe.c +++ b/linux/metag/arch_rt_sigframe.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Dmitry V. Levin + * Copyright (c) 2017-2018 Dmitry V. Levin * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,5 +29,7 @@ FUNC_GET_RT_SIGFRAME_ADDR { - return *metag_sp_ptr - sizeof(struct_rt_sigframe); + kernel_ulong_t sp; + return get_stack_pointer(tcp, &sp) + ? sp - sizeof(struct_rt_sigframe) : 0; } diff --git a/linux/microblaze/arch_regs.c b/linux/microblaze/arch_regs.c index a5fec611..79f2dda0 100644 --- a/linux/microblaze/arch_regs.c +++ b/linux/microblaze/arch_regs.c @@ -1,2 +1,3 @@ static unsigned long microblaze_r3; #define ARCH_PC_PEEK_ADDR PT_PC +#define ARCH_SP_PEEK_ADDR PT_GPR(1) diff --git a/linux/microblaze/arch_rt_sigframe.c b/linux/microblaze/arch_rt_sigframe.c deleted file mode 100644 index dcecd1a4..00000000 --- a/linux/microblaze/arch_rt_sigframe.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2017 Dmitry V. Levin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -FUNC_GET_RT_SIGFRAME_ADDR -{ - unsigned long addr; - - return upeek(tcp, 4 * 1, &addr) ? 0 : addr; -} diff --git a/linux/mips/arch_regs.c b/linux/mips/arch_regs.c index 44f6bd5e..2f604d83 100644 --- a/linux/mips/arch_regs.c +++ b/linux/mips/arch_regs.c @@ -1,4 +1,21 @@ -struct mips_regs mips_regs; /* not static */ +static struct { + uint64_t uregs[38]; +} mips_regs; + +#define REG_V0 2 +#define REG_A0 4 + +#define mips_REG_V0 mips_regs.uregs[REG_V0] +#define mips_REG_A0 mips_regs.uregs[REG_A0 + 0] +#define mips_REG_A1 mips_regs.uregs[REG_A0 + 1] +#define mips_REG_A2 mips_regs.uregs[REG_A0 + 2] +#define mips_REG_A3 mips_regs.uregs[REG_A0 + 3] +#define mips_REG_A4 mips_regs.uregs[REG_A0 + 4] +#define mips_REG_A5 mips_regs.uregs[REG_A0 + 5] +#define mips_REG_SP mips_regs.uregs[29] +#define mips_REG_EPC mips_regs.uregs[34] + /* PTRACE_GETREGS on MIPS is available since linux v2.6.15. */ #define ARCH_REGS_FOR_GETREGS mips_regs #define ARCH_PC_REG mips_REG_EPC +#define ARCH_SP_REG mips_REG_SP diff --git a/linux/mips/arch_regs.h b/linux/mips/arch_regs.h deleted file mode 100644 index 6372badc..00000000 --- a/linux/mips/arch_regs.h +++ /dev/null @@ -1,18 +0,0 @@ -struct mips_regs { - uint64_t uregs[38]; -}; - -extern struct mips_regs mips_regs; - -#define REG_V0 2 -#define REG_A0 4 - -#define mips_REG_V0 mips_regs.uregs[REG_V0] -#define mips_REG_A0 mips_regs.uregs[REG_A0 + 0] -#define mips_REG_A1 mips_regs.uregs[REG_A0 + 1] -#define mips_REG_A2 mips_regs.uregs[REG_A0 + 2] -#define mips_REG_A3 mips_regs.uregs[REG_A0 + 3] -#define mips_REG_A4 mips_regs.uregs[REG_A0 + 4] -#define mips_REG_A5 mips_regs.uregs[REG_A0 + 5] -#define mips_REG_SP mips_regs.uregs[29] -#define mips_REG_EPC mips_regs.uregs[34] diff --git a/linux/mips/arch_rt_sigframe.c b/linux/mips/arch_rt_sigframe.c deleted file mode 100644 index 03acc73f..00000000 --- a/linux/mips/arch_rt_sigframe.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2017 Dmitry V. Levin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -FUNC_GET_RT_SIGFRAME_ADDR -{ - return mips_REG_SP; -} diff --git a/linux/mips/arch_sigreturn.c b/linux/mips/arch_sigreturn.c index 522b7315..aeac7c21 100644 --- a/linux/mips/arch_sigreturn.c +++ b/linux/mips/arch_sigreturn.c @@ -3,12 +3,14 @@ arch_sigreturn(struct tcb *tcp) { /* 64-bit ABIs do not have old sigreturn. */ #ifdef LINUX_MIPSO32 + kernel_ulong_t addr; + if (!get_stack_pointer(tcp, &addr)) + return; /* * offsetof(struct sigframe, sf_mask) == * sizeof(sf_ass) + sizeof(sf_pad) + sizeof(struct sigcontext) */ - const kernel_ulong_t addr = mips_REG_SP + 6 * 4 + - sizeof(struct sigcontext); + addr += 6 * 4 + sizeof(struct sigcontext); tprints("{mask="); print_sigset_addr(tcp, addr); diff --git a/linux/nios2/arch_regs.c b/linux/nios2/arch_regs.c index c18a3aa5..ecbef0ee 100644 --- a/linux/nios2/arch_regs.c +++ b/linux/nios2/arch_regs.c @@ -1,4 +1,4 @@ static struct user_pt_regs nios2_regs; -unsigned int *const nios2_sp_ptr = &nios2_regs.regs[PTR_SP]; # define ARCH_REGS_FOR_GETREGSET nios2_regs #define ARCH_PC_REG nios2_regs.regs[PTR_EA] +#define ARCH_SP_REG nios2_regs.regs[PTR_SP] diff --git a/linux/nios2/arch_regs.h b/linux/nios2/arch_regs.h deleted file mode 100644 index c4230eda..00000000 --- a/linux/nios2/arch_regs.h +++ /dev/null @@ -1 +0,0 @@ -extern unsigned int *const nios2_sp_ptr; diff --git a/linux/nios2/arch_rt_sigframe.c b/linux/nios2/arch_rt_sigframe.c deleted file mode 100644 index 7359f116..00000000 --- a/linux/nios2/arch_rt_sigframe.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2017 Dmitry V. Levin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -FUNC_GET_RT_SIGFRAME_ADDR -{ - return *nios2_sp_ptr; -} diff --git a/linux/or1k/arch_regs.c b/linux/or1k/arch_regs.c index 80ce7639..efdef989 100644 --- a/linux/or1k/arch_regs.c +++ b/linux/or1k/arch_regs.c @@ -1,4 +1,4 @@ static struct user_regs_struct or1k_regs; -unsigned long *const or1k_sp_ptr = &or1k_regs.gpr[1]; #define ARCH_REGS_FOR_GETREGSET or1k_regs #define ARCH_PC_REG or1k_regs.pc +#define ARCH_SP_REG or1k_regs.gpr[1] diff --git a/linux/or1k/arch_regs.h b/linux/or1k/arch_regs.h deleted file mode 100644 index 44a78ec5..00000000 --- a/linux/or1k/arch_regs.h +++ /dev/null @@ -1 +0,0 @@ -extern unsigned long *const or1k_sp_ptr; diff --git a/linux/or1k/arch_rt_sigframe.c b/linux/or1k/arch_rt_sigframe.c deleted file mode 100644 index 4f8cbbe4..00000000 --- a/linux/or1k/arch_rt_sigframe.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2017 Dmitry V. Levin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -FUNC_GET_RT_SIGFRAME_ADDR -{ - return *or1k_sp_ptr; -} diff --git a/linux/powerpc/arch_regs.c b/linux/powerpc/arch_regs.c index dd573f71..37cddc57 100644 --- a/linux/powerpc/arch_regs.c +++ b/linux/powerpc/arch_regs.c @@ -1,4 +1,5 @@ -struct pt_regs ppc_regs; /* not static */ +static struct pt_regs ppc_regs; #define ARCH_REGS_FOR_GETREGS ppc_regs #define ARCH_PC_REG ppc_regs.nip +#define ARCH_SP_REG ppc_regs.gpr[1] diff --git a/linux/powerpc/arch_regs.h b/linux/powerpc/arch_regs.h deleted file mode 100644 index 1296e83e..00000000 --- a/linux/powerpc/arch_regs.h +++ /dev/null @@ -1 +0,0 @@ -extern struct pt_regs ppc_regs; diff --git a/linux/powerpc/arch_rt_sigframe.c b/linux/powerpc/arch_rt_sigframe.c index 4a1c4315..b9d40470 100644 --- a/linux/powerpc/arch_rt_sigframe.c +++ b/linux/powerpc/arch_rt_sigframe.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Dmitry V. Levin + * Copyright (c) 2017-2018 Dmitry V. Levin * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,5 +29,6 @@ FUNC_GET_RT_SIGFRAME_ADDR { - return ppc_regs.gpr[1] + SIGNAL_FRAMESIZE32 + 16; + kernel_ulong_t sp; + return get_stack_pointer(tcp, &sp) ? sp + SIGNAL_FRAMESIZE32 + 16 : 0; } diff --git a/linux/powerpc/arch_sigreturn.c b/linux/powerpc/arch_sigreturn.c index 5a5ca3ae..227a7970 100644 --- a/linux/powerpc/arch_sigreturn.c +++ b/linux/powerpc/arch_sigreturn.c @@ -1,8 +1,12 @@ static void arch_sigreturn(struct tcb *tcp) { + kernel_ulong_t addr; + if (!get_stack_pointer(tcp, &addr)) + return; + /* Skip dummy stack frame. */ - const unsigned long addr = ppc_regs.gpr[1] + 64; + addr += 64; #ifdef POWERPC64 /* The only sigreturn on ppc64 is compat_sys_sigreturn. */ @@ -19,9 +23,7 @@ arch_sigreturn(struct tcb *tcp) sigreturn_context sc; - if (umove(tcp, addr, &sc) < 0) { - tprintf("{mask=%#lx}", addr); - } else { + if (!umove_or_printaddr(tcp, addr, &sc)) { const unsigned int mask[NSIG_BYTES / sizeof(int)] = { sc.oldmask, sc._unused[3] diff --git a/linux/powerpc64/arch_regs.h b/linux/powerpc64/arch_regs.h deleted file mode 100644 index 05e4fe19..00000000 --- a/linux/powerpc64/arch_regs.h +++ /dev/null @@ -1 +0,0 @@ -#include "powerpc/arch_regs.h" diff --git a/linux/powerpc64/arch_rt_sigframe.c b/linux/powerpc64/arch_rt_sigframe.c index 333f7080..444b163a 100644 --- a/linux/powerpc64/arch_rt_sigframe.c +++ b/linux/powerpc64/arch_rt_sigframe.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Dmitry V. Levin + * Copyright (c) 2017-2018 Dmitry V. Levin * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -36,6 +36,8 @@ FUNC_GET_RT_SIGFRAME_ADDR { - return tcp->currpers == 1 - ? ppc_get_rt_sigframe_addr(tcp) : ppc_regs.gpr[1]; + if (tcp->currpers == 1) + return ppc_get_rt_sigframe_addr(tcp); + kernel_ulong_t sp; + return get_stack_pointer(tcp, &sp) ? sp : 0; } diff --git a/linux/riscv/arch_regs.c b/linux/riscv/arch_regs.c index 58010df2..b6c08bc9 100644 --- a/linux/riscv/arch_regs.c +++ b/linux/riscv/arch_regs.c @@ -1,4 +1,4 @@ static struct user_regs_struct riscv_regs; -unsigned long *const riscv_sp_ptr = &riscv_regs.sp; #define ARCH_REGS_FOR_GETREGSET riscv_regs #define ARCH_PC_REG riscv_regs.pc +#define ARCH_SP_REG riscv_regs.sp diff --git a/linux/riscv/arch_regs.h b/linux/riscv/arch_regs.h deleted file mode 100644 index f2702819..00000000 --- a/linux/riscv/arch_regs.h +++ /dev/null @@ -1 +0,0 @@ -extern unsigned long *const riscv_sp_ptr; diff --git a/linux/riscv/arch_rt_sigframe.c b/linux/riscv/arch_rt_sigframe.c deleted file mode 100644 index 54526c49..00000000 --- a/linux/riscv/arch_rt_sigframe.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2017 Dmitry V. Levin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -FUNC_GET_RT_SIGFRAME_ADDR -{ - return *riscv_sp_ptr; -} diff --git a/linux/s390/arch_regs.c b/linux/s390/arch_regs.c index fefb7630..414123e4 100644 --- a/linux/s390/arch_regs.c +++ b/linux/s390/arch_regs.c @@ -1,5 +1,5 @@ /* PTRACE_GETREGSET on S390 is available since linux v2.6.27. */ static struct user_regs_struct s390_regset; -unsigned long *const s390_frame_ptr = &s390_regset.gprs[15]; #define ARCH_REGS_FOR_GETREGSET s390_regset #define ARCH_PC_REG s390_regset.psw.addr +#define ARCH_SP_REG s390_regset.gprs[15] diff --git a/linux/s390/arch_regs.h b/linux/s390/arch_regs.h deleted file mode 100644 index 586326ff..00000000 --- a/linux/s390/arch_regs.h +++ /dev/null @@ -1 +0,0 @@ -extern unsigned long *const s390_frame_ptr; diff --git a/linux/s390/arch_rt_sigframe.c b/linux/s390/arch_rt_sigframe.c deleted file mode 100644 index 2cd468b9..00000000 --- a/linux/s390/arch_rt_sigframe.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2017 Dmitry V. Levin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -FUNC_GET_RT_SIGFRAME_ADDR -{ - return *s390_frame_ptr; -} diff --git a/linux/s390/arch_sigreturn.c b/linux/s390/arch_sigreturn.c index 9c9e0ddf..f63ef132 100644 --- a/linux/s390/arch_sigreturn.c +++ b/linux/s390/arch_sigreturn.c @@ -1,6 +1,3 @@ -#ifndef S390_FRAME_PTR -# define S390_FRAME_PTR s390_frame_ptr -#endif #ifndef SIGNAL_FRAMESIZE # define SIGNAL_FRAMESIZE __SIGNAL_FRAMESIZE #endif @@ -11,12 +8,14 @@ static void arch_sigreturn(struct tcb *tcp) { - PTR_TYPE mask[NSIG_BYTES / sizeof(PTR_TYPE)]; - const PTR_TYPE addr = *S390_FRAME_PTR + SIGNAL_FRAMESIZE; + kernel_ulong_t addr; - if (umove(tcp, addr, &mask) < 0) { - tprintf("{mask=%#llx}", zero_extend_signed_to_ull(addr)); - } else { + if (!get_stack_pointer(tcp, &addr)) + return; + addr += SIGNAL_FRAMESIZE; + + PTR_TYPE mask[NSIG_BYTES / sizeof(PTR_TYPE)]; + if (!umove_or_printaddr(tcp, addr, &mask)) { tprintsigmask_addr("{mask=", mask); tprints("}"); } diff --git a/linux/s390x/arch_regs.c b/linux/s390x/arch_regs.c index 58f7b782..1dd35dbb 100644 --- a/linux/s390x/arch_regs.c +++ b/linux/s390x/arch_regs.c @@ -20,9 +20,6 @@ static union { #define s390_regset s390x_regs_union.s390_regs #define s390x_regset s390x_regs_union.s390x_regs -uint32_t *const s390_frame_ptr = &s390_regset.gprs[15]; -unsigned long *const s390x_frame_ptr = &s390x_regset.gprs[15]; - static struct iovec s390x_io = { .iov_base = &s390x_regs_union, }; @@ -33,6 +30,9 @@ static struct iovec s390x_io = { #define ARCH_PC_REG \ (s390x_io.iov_len == sizeof(s390_regset) ? \ s390_regset.psw.addr : s390x_regset.psw.addr) +#define ARCH_SP_REG \ + (s390x_io.iov_len == sizeof(s390_regset) ? \ + s390_regset.gprs[15] : s390x_regset.gprs[15]) #define ARCH_PERSONALITY_0_IOV_SIZE sizeof(s390x_regset) #define ARCH_PERSONALITY_1_IOV_SIZE sizeof(s390_regset) diff --git a/linux/s390x/arch_regs.h b/linux/s390x/arch_regs.h deleted file mode 100644 index 1f8b57a1..00000000 --- a/linux/s390x/arch_regs.h +++ /dev/null @@ -1,2 +0,0 @@ -extern uint32_t *const s390_frame_ptr; -extern unsigned long *const s390x_frame_ptr; diff --git a/linux/s390x/arch_rt_sigframe.c b/linux/s390x/arch_rt_sigframe.c deleted file mode 100644 index 9c0255f8..00000000 --- a/linux/s390x/arch_rt_sigframe.c +++ /dev/null @@ -1,4 +0,0 @@ -FUNC_GET_RT_SIGFRAME_ADDR -{ - return tcp->currpers == 1 ? *s390_frame_ptr : *s390x_frame_ptr; -} diff --git a/linux/s390x/arch_sigreturn.c b/linux/s390x/arch_sigreturn.c index edc9edd5..4065e064 100644 --- a/linux/s390x/arch_sigreturn.c +++ b/linux/s390x/arch_sigreturn.c @@ -4,15 +4,12 @@ #define SIGNAL_FRAMESIZE S390_SIGNAL_FRAMESIZE #define PTR_TYPE uint32_t -#define S390_FRAME_PTR s390_frame_ptr #define arch_sigreturn s390_arch_sigreturn #include "s390/arch_sigreturn.c" #undef arch_sigreturn -#undef S390_FRAME_PTR #undef PTR_TYPE #undef SIGNAL_FRAMESIZE -#define S390_FRAME_PTR s390x_frame_ptr #define arch_sigreturn s390x_arch_sigreturn #include "s390/arch_sigreturn.c" #undef arch_sigreturn diff --git a/linux/sh/arch_regs.c b/linux/sh/arch_regs.c index 5429b4f5..8ea0fc40 100644 --- a/linux/sh/arch_regs.c +++ b/linux/sh/arch_regs.c @@ -1,2 +1,3 @@ static unsigned long sh_r0; #define ARCH_PC_PEEK_ADDR (4 * REG_PC) +#define ARCH_SP_PEEK_ADDR (4 * 15) diff --git a/linux/sh/arch_rt_sigframe.c b/linux/sh/arch_rt_sigframe.c deleted file mode 100644 index 3c4f6f2b..00000000 --- a/linux/sh/arch_rt_sigframe.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2017 Dmitry V. Levin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -FUNC_GET_RT_SIGFRAME_ADDR -{ - unsigned long addr; - - return upeek(tcp, sizeof(long) * 15, &addr) ? 0 : addr; -} diff --git a/linux/sh64/arch_regs.c b/linux/sh64/arch_regs.c index 8b3202a8..787ae22f 100644 --- a/linux/sh64/arch_regs.c +++ b/linux/sh64/arch_regs.c @@ -1,2 +1,3 @@ static unsigned long sh64_r9; #define ARCH_PC_PEEK_ADDR REG_PC +#define ARCH_SP_PEEK_ADDR REG_GENERAL(15) diff --git a/linux/sh64/arch_rt_sigframe.c b/linux/sh64/arch_rt_sigframe.c deleted file mode 100644 index 21204e3b..00000000 --- a/linux/sh64/arch_rt_sigframe.c +++ /dev/null @@ -1 +0,0 @@ -#include "sh/arch_rt_sigframe.c" diff --git a/linux/sparc/arch_regs.c b/linux/sparc/arch_regs.c index c0f22e6c..7a28d464 100644 --- a/linux/sparc/arch_regs.c +++ b/linux/sparc/arch_regs.c @@ -1,3 +1,12 @@ -struct pt_regs sparc_regs; /* not static */ +static 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 +#define U_REG_FP 13 + #define ARCH_REGS_FOR_GETREGS sparc_regs #define ARCH_PC_REG sparc_regs.pc +#define ARCH_SP_REG sparc_regs.u_regs[U_REG_FP] diff --git a/linux/sparc/arch_regs.h b/linux/sparc/arch_regs.h deleted file mode 100644 index ac11a1df..00000000 --- a/linux/sparc/arch_regs.h +++ /dev/null @@ -1,7 +0,0 @@ -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 -#define U_REG_FP 13 diff --git a/linux/sparc/arch_rt_sigframe.c b/linux/sparc/arch_rt_sigframe.c deleted file mode 100644 index 418443ea..00000000 --- a/linux/sparc/arch_rt_sigframe.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2017 Dmitry V. Levin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -FUNC_GET_RT_SIGFRAME_ADDR -{ - return sparc_regs.u_regs[U_REG_FP]; -} diff --git a/linux/sparc/arch_sigreturn.c b/linux/sparc/arch_sigreturn.c index 2170a7ba..13edd425 100644 --- a/linux/sparc/arch_sigreturn.c +++ b/linux/sparc/arch_sigreturn.c @@ -11,8 +11,10 @@ static void arch_sigreturn(struct tcb *tcp) { - unsigned long addr = sparc_regs.u_regs[U_REG_FP] + - SIZEOF_STRUCT_SPARC_STACKF + SIZEOF_STRUCT_PT_REGS; + kernel_ulong_t addr; + if (!get_stack_pointer(tcp, &addr)) + return; + addr += SIZEOF_STRUCT_SPARC_STACKF + SIZEOF_STRUCT_PT_REGS; struct { unsigned int mask; char fpu_save[PERSONALITY_WORDSIZE]; @@ -20,9 +22,7 @@ arch_sigreturn(struct tcb *tcp) unsigned int extramask[NSIG_BYTES / sizeof(int) - 1]; } frame; - if (umove(tcp, addr, &frame) < 0) { - tprintf("{mask=%#lx}", addr); - } else { + if (!umove_or_printaddr(tcp, addr, &frame)) { unsigned int mask[NSIG_BYTES / sizeof(int)]; mask[0] = frame.mask; diff --git a/linux/sparc64/arch_regs.h b/linux/sparc64/arch_regs.h deleted file mode 100644 index a49ad539..00000000 --- a/linux/sparc64/arch_regs.h +++ /dev/null @@ -1 +0,0 @@ -#include "sparc/arch_regs.h" diff --git a/linux/sparc64/arch_rt_sigframe.c b/linux/sparc64/arch_rt_sigframe.c index 0bad84da..58e5eca8 100644 --- a/linux/sparc64/arch_rt_sigframe.c +++ b/linux/sparc64/arch_rt_sigframe.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Dmitry V. Levin + * Copyright (c) 2017-2018 Dmitry V. Levin * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,6 +29,9 @@ FUNC_GET_RT_SIGFRAME_ADDR { - return tcp->currpers == 1 ? sparc_regs.u_regs[U_REG_FP] & 0xffffffffUL - : sparc_regs.u_regs[U_REG_FP] + STACK_BIAS; + kernel_ulong_t sp; + if (!get_stack_pointer(tcp, &sp)) + return 0; + return tcp->currpers == 1 ? sp & 0xffffffffUL + : sp + STACK_BIAS; } diff --git a/linux/tile/arch_regs.c b/linux/tile/arch_regs.c index 6a7309d2..cd048baa 100644 --- a/linux/tile/arch_regs.c +++ b/linux/tile/arch_regs.c @@ -1,3 +1,4 @@ -struct pt_regs tile_regs; /* not static */ +static struct pt_regs tile_regs; #define ARCH_REGS_FOR_GETREGS tile_regs #define ARCH_PC_REG tile_regs.pc +#define ARCH_SP_REG tile_regs.sp diff --git a/linux/tile/arch_regs.h b/linux/tile/arch_regs.h deleted file mode 100644 index cd3f72b3..00000000 --- a/linux/tile/arch_regs.h +++ /dev/null @@ -1 +0,0 @@ -extern struct pt_regs tile_regs; diff --git a/linux/tile/arch_rt_sigframe.c b/linux/tile/arch_rt_sigframe.c deleted file mode 100644 index 8d15e5c2..00000000 --- a/linux/tile/arch_rt_sigframe.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2017 Dmitry V. Levin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -FUNC_GET_RT_SIGFRAME_ADDR -{ - return tile_regs.sp; -} diff --git a/linux/tile/arch_sigreturn.c b/linux/tile/arch_sigreturn.c index 7042cfd5..92631f4d 100644 --- a/linux/tile/arch_sigreturn.c +++ b/linux/tile/arch_sigreturn.c @@ -1,10 +1,13 @@ static void arch_sigreturn(struct tcb *tcp) { + kernel_ulong_t addr; + if (!get_stack_pointer(tcp, &addr)) + return; + /* offset of ucontext in the kernel's sigframe structure */ #define SIGFRAME_UC_OFFSET C_ABI_SAVE_AREA_SIZE + sizeof(siginfo_t) - const unsigned long addr = tile_regs.sp + SIGFRAME_UC_OFFSET + - offsetof(ucontext_t, uc_sigmask); + addr += SIGFRAME_UC_OFFSET + offsetof(ucontext_t, uc_sigmask); tprints("{mask="); print_sigset_addr(tcp, addr); diff --git a/linux/x86_64/arch_regs.c b/linux/x86_64/arch_regs.c index daee69f9..ac719b6b 100644 --- a/linux/x86_64/arch_regs.c +++ b/linux/x86_64/arch_regs.c @@ -30,12 +30,13 @@ static union { #define x86_64_regs x86_regs_union.x86_64_r #define i386_regs x86_regs_union.i386_r -uint32_t *const i386_esp_ptr = &i386_regs.esp; -uint64_t *const x86_64_rsp_ptr = (uint64_t *) &x86_64_regs.rsp; static struct iovec x86_io = { .iov_base = &x86_regs_union }; #define ARCH_REGS_FOR_GETREGSET x86_regs_union #define ARCH_IOVEC_FOR_GETREGSET x86_io -#define ARCH_PC_REG (x86_io.iov_len == sizeof(i386_regs) ? i386_regs.eip : x86_64_regs.rip) +#define ARCH_PC_REG \ + (x86_io.iov_len == sizeof(i386_regs) ? i386_regs.eip : x86_64_regs.rip) +#define ARCH_SP_REG \ + (x86_io.iov_len == sizeof(i386_regs) ? i386_regs.esp : x86_64_regs.rsp) diff --git a/linux/x86_64/arch_regs.h b/linux/x86_64/arch_regs.h index d502ca4b..6676bb8d 100644 --- a/linux/x86_64/arch_regs.h +++ b/linux/x86_64/arch_regs.h @@ -1,5 +1,3 @@ -extern uint32_t *const i386_esp_ptr; -extern uint64_t *const x86_64_rsp_ptr; /* does not provide these definitions. */ #define R15 0 diff --git a/linux/x86_64/arch_rt_sigframe.c b/linux/x86_64/arch_rt_sigframe.c index d2c7867f..bb60b44d 100644 --- a/linux/x86_64/arch_rt_sigframe.c +++ b/linux/x86_64/arch_rt_sigframe.c @@ -1,41 +1 @@ -/* - * Copyright (c) 2017 Dmitry V. Levin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#undef FUNC_GET_RT_SIGFRAME_ADDR -#define FUNC_GET_RT_SIGFRAME_ADDR \ - static kernel_ulong_t i386_get_rt_sigframe_addr(struct tcb *tcp) - #include "i386/arch_rt_sigframe.c" - -#undef FUNC_GET_RT_SIGFRAME_ADDR -#define FUNC_GET_RT_SIGFRAME_ADDR DEF_FUNC_GET_RT_SIGFRAME_ADDR - -FUNC_GET_RT_SIGFRAME_ADDR -{ - return tcp->currpers == 1 ? i386_get_rt_sigframe_addr(tcp) - : *x86_64_rsp_ptr - sizeof(kernel_ulong_t); -} diff --git a/linux/xtensa/arch_regs.c b/linux/xtensa/arch_regs.c index 67e5f010..5b85fda9 100644 --- a/linux/xtensa/arch_regs.c +++ b/linux/xtensa/arch_regs.c @@ -1,2 +1,3 @@ static unsigned long xtensa_a2; #define ARCH_PC_PEEK_ADDR REG_PC +#define ARCH_SP_PEEK_ADDR (REG_A_BASE + 1) diff --git a/linux/xtensa/arch_rt_sigframe.c b/linux/xtensa/arch_rt_sigframe.c deleted file mode 100644 index 97ffe6ca..00000000 --- a/linux/xtensa/arch_rt_sigframe.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2017 Dmitry V. Levin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -FUNC_GET_RT_SIGFRAME_ADDR -{ - unsigned long addr; - - return upeek(tcp, REG_A_BASE + 3, &addr) ? 0 : addr; -} diff --git a/syscall.c b/syscall.c index e1b2f20e..9107fe50 100644 --- a/syscall.c +++ b/syscall.c @@ -1195,6 +1195,23 @@ get_instruction_pointer(struct tcb *tcp, kernel_ulong_t *ip) #endif } +bool +get_stack_pointer(struct tcb *tcp, kernel_ulong_t *sp) +{ +#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 +} + /* * Returns: * 0: "ignore this ptrace stop", syscall_entering_decode() should return a "bail -- 2.40.0