]> granicus.if.org Git - strace/commitdiff
cleanup: make arch_sigreturn.c files more readable
authorDmitry V. Levin <ldv@altlinux.org>
Sat, 28 Nov 2015 02:58:29 +0000 (02:58 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sat, 28 Nov 2015 02:58:29 +0000 (02:58 +0000)
Make arch_sigreturn.c files more self-sustained.  While they are
still being included by sigreturn.c, the latter no longer defines
arch_sigreturn function.

* linux/alpha/arch_sigreturn.c (arch_sigreturn): Define.
* linux/arm/arch_sigreturn.c: Likewise.
* linux/crisv10/arch_sigreturn.c: Likewise.
* linux/i386/arch_sigreturn.c: Likewise.
* linux/ia64/arch_sigreturn.c: Likewise.
* linux/m68k/arch_sigreturn.c: Likewise.
* linux/microblaze/arch_sigreturn.c: Likewise.
* linux/mips/arch_sigreturn.c: Likewise.
* linux/powerpc/arch_sigreturn.c: Likewise.
* linux/s390/arch_sigreturn.c: Likewise.
* linux/sparc/arch_sigreturn.c: Likewise.
* linux/tile/arch_sigreturn.c: Likewise.
* linux/x32/arch_sigreturn.c: Remove code.
Include "x86_64/arch_sigreturn.c".
* linux/x86_64/arch_sigreturn.c: Stop including "x32/arch_sigreturn.c".
Include "i386/arch_sigreturn.c" with arch_sigreturn temporarily defined
to i386_arch_sigreturn.
(arch_sigreturn): Define.  Add x32 personality support there.
* sigreturn.c: Remove arch_sigreturn header and footer.

Requested-by: Denys Vlasenko <dvlasenk@redhat.com>
15 files changed:
linux/alpha/arch_sigreturn.c
linux/arm/arch_sigreturn.c
linux/crisv10/arch_sigreturn.c
linux/i386/arch_sigreturn.c
linux/ia64/arch_sigreturn.c
linux/m68k/arch_sigreturn.c
linux/microblaze/arch_sigreturn.c
linux/mips/arch_sigreturn.c
linux/powerpc/arch_sigreturn.c
linux/s390/arch_sigreturn.c
linux/sparc/arch_sigreturn.c
linux/tile/arch_sigreturn.c
linux/x32/arch_sigreturn.c
linux/x86_64/arch_sigreturn.c
sigreturn.c

index b70eb1d73527326c658c30a87d26dd89b81f522f..71a84ef2ead709b645699059c25da0ddf5039eed 100644 (file)
@@ -1,9 +1,13 @@
-long addr;
+static void
+arch_sigreturn(struct tcb *tcp)
+{
+       long addr;
 
-if (upeek(tcp->pid, REG_FP, &addr) < 0)
-       return;
-addr += offsetof(struct sigcontext, sc_mask);
+       if (upeek(tcp->pid, REG_FP, &addr) < 0)
+               return;
+       addr += offsetof(struct sigcontext, sc_mask);
 
-tprints("{mask=");
-print_sigset_addr_len(tcp, addr, NSIG / 8);
-tprints("}");
+       tprints("{mask=");
+       print_sigset_addr_len(tcp, addr, NSIG / 8);
+       tprints("}");
+}
index 046e19a18ae2c66e0227526743258cb2bacf0098..6d32ac5d2719dd2403c933ec68ad80a998ebe2d8 100644 (file)
@@ -1,15 +1,19 @@
+static void
+arch_sigreturn(struct tcb *tcp)
+{
 #define SIZEOF_STRUCT_SIGINFO 128
 #define SIZEOF_STRUCT_SIGCONTEXT (21 * 4)
 #define OFFSETOF_STRUCT_UCONTEXT_UC_SIGMASK (5 * 4 + SIZEOF_STRUCT_SIGCONTEXT)
 
-const long addr =
+       const long addr =
 #ifdef AARCH64
-       current_personality == 1 ?
-               (*aarch64_sp_ptr + SIZEOF_STRUCT_SIGINFO +
-                offsetof(struct ucontext, uc_sigmask)) :
+               current_personality == 1 ?
+                       (*aarch64_sp_ptr + SIZEOF_STRUCT_SIGINFO +
+                        offsetof(struct ucontext, uc_sigmask)) :
 #endif
-               (*arm_sp_ptr +
-                OFFSETOF_STRUCT_UCONTEXT_UC_SIGMASK);
-tprints("{mask=");
-print_sigset_addr_len(tcp, addr, NSIG / 8);
-tprints("}");
+                       (*arm_sp_ptr +
+                        OFFSETOF_STRUCT_UCONTEXT_UC_SIGMASK);
+       tprints("{mask=");
+       print_sigset_addr_len(tcp, addr, NSIG / 8);
+       tprints("}");
+}
index 9dc09f344fbc41e02fdaf0ac571eeae845a26444..9086d5336dd3a453955cfcb080454497588c2ef9 100644 (file)
@@ -1,11 +1,15 @@
-long regs[PT_MAX + 1];
+static void
+arch_sigreturn(struct tcb *tcp)
+{
+       long regs[PT_MAX + 1];
 
-if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
-       perror_msg("sigreturn: PTRACE_GETREGS");
-       return;
-}
-const long addr = regs[PT_USP] + offsetof(struct sigcontext, oldmask);
+       if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
+               perror_msg("sigreturn: PTRACE_GETREGS");
+               return;
+       }
+       const long addr = regs[PT_USP] + offsetof(struct sigcontext, oldmask);
 
-tprints("{mask=");
-print_sigset_addr_len(tcp, addr, NSIG / 8);
-tprints("}");
+       tprints("{mask=");
+       print_sigset_addr_len(tcp, addr, NSIG / 8);
+       tprints("}");
+}
index e726bf1adebdc363bc1e02d247241a4f110fd4c6..9446994ef1cca3dc7da732f28722ee99ed8d1ec5 100644 (file)
@@ -1,20 +1,24 @@
-/*
- * On i386, sigcontext is followed on stack by struct fpstate
- * and after it an additional u32 extramask which holds
- * upper half of the mask.
- */
-struct {
-       uint32_t struct_sigcontext_padding1[20];
-       uint32_t oldmask;
-       uint32_t struct_sigcontext_padding2;
-       uint32_t struct_fpstate_padding[156];
-       uint32_t extramask;
-} frame;
+static void
+arch_sigreturn(struct tcb *tcp)
+{
+       /*
+        * On i386, sigcontext is followed on stack by struct fpstate
+        * and after it an additional u32 extramask which holds
+        * upper half of the mask.
+        */
+       struct {
+               uint32_t struct_sigcontext_padding1[20];
+               uint32_t oldmask;
+               uint32_t struct_sigcontext_padding2;
+               uint32_t struct_fpstate_padding[156];
+               uint32_t extramask;
+       } frame;
 
-if (umove(tcp, *i386_esp_ptr, &frame) < 0) {
-       tprintf("{mask=%#lx}", (unsigned long) *i386_esp_ptr);
-} else {
-       uint32_t mask[2] = { frame.oldmask, frame.extramask };
-       tprintsigmask_addr("{mask=", mask);
-       tprints("}");
+       if (umove(tcp, *i386_esp_ptr, &frame) < 0) {
+               tprintf("{mask=%#lx}", (unsigned long) *i386_esp_ptr);
+       } else {
+               uint32_t mask[2] = { frame.oldmask, frame.extramask };
+               tprintsigmask_addr("{mask=", mask);
+               tprints("}");
+       }
 }
index 94e89cfac5d0b03190c3901ca5a7c8c262ed0bd5..8b54d6c15a1367bc1dd12b7a10bf0ebc92b77b2d 100644 (file)
@@ -1,8 +1,12 @@
-/* offsetof(struct sigframe, sc) */
+static void
+arch_sigreturn(struct tcb *tcp)
+{
+       /* offsetof(struct sigframe, sc) */
 #define OFFSETOF_STRUCT_SIGFRAME_SC    0xA0
-const long addr = *ia64_frame_ptr + 16 +
-                 OFFSETOF_STRUCT_SIGFRAME_SC +
-                 offsetof(struct sigcontext, sc_mask);
-tprints("{mask=");
-print_sigset_addr_len(tcp, addr, NSIG / 8);
-tprints("}");
+       const long addr = *ia64_frame_ptr + 16 +
+                         OFFSETOF_STRUCT_SIGFRAME_SC +
+                         offsetof(struct sigcontext, sc_mask);
+       tprints("{mask=");
+       print_sigset_addr_len(tcp, addr, NSIG / 8);
+       tprints("}");
+}
index a2ccac64e06e047e44247745087de965789a15e7..0011c1748f0e0fe56c7e837701fafd6af085f9e4 100644 (file)
@@ -1,20 +1,24 @@
-long addr;
+static void
+arch_sigreturn(struct tcb *tcp)
+{
+       long addr;
 
-if (upeek(tcp->pid, 4*PT_USP, &addr) < 0)
-       return;
-/* Fetch pointer to struct sigcontext.  */
-if (umove(tcp, addr + 2 * sizeof(int), &addr) < 0)
-       return;
+       if (upeek(tcp->pid, 4*PT_USP, &addr) < 0)
+               return;
+       /* Fetch pointer to struct sigcontext.  */
+       if (umove(tcp, addr + 2 * sizeof(int), &addr) < 0)
+               return;
 
-unsigned long mask[NSIG / 8 / sizeof(long)];
-/* Fetch first word of signal mask.  */
-if (umove(tcp, addr, &mask[0]) < 0)
-       return;
+       unsigned long mask[NSIG / 8 / sizeof(long)];
+       /* Fetch first word of signal mask.  */
+       if (umove(tcp, addr, &mask[0]) < 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)
-       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)
+               return;
 
-tprintsigmask_addr("{mask=", mask);
-tprints("}");
+       tprintsigmask_addr("{mask=", mask);
+       tprints("}");
+}
index 0c7f99cd86a78198b5566c9a5fa2965c9fd7e765..839c8057831bdcafb6118fd34fdbb23a0ce4e4db 100644 (file)
@@ -1,12 +1,16 @@
-/* TODO: Verify that this is correct...  */
+static void
+arch_sigreturn(struct tcb *tcp)
+{
+       /* TODO: Verify that this is correct...  */
 
-long addr;
+       long addr;
 
-/* Read r1, the stack pointer.  */
-if (upeek(tcp->pid, 1 * 4, &addr) < 0)
-       return;
-addr += offsetof(struct sigcontext, oldmask);
+       /* Read r1, the stack pointer.  */
+       if (upeek(tcp->pid, 1 * 4, &addr) < 0)
+               return;
+       addr += offsetof(struct sigcontext, oldmask);
 
-tprints("{mask=");
-print_sigset_addr_len(tcp, addr, NSIG / 8);
-tprints("}");
+       tprints("{mask=");
+       print_sigset_addr_len(tcp, addr, NSIG / 8);
+       tprints("}");
+}
index 687f871dbe605c8e3aa29f39e78e544a921541db..3095fe59131c90d2587b54ab1e03523d9b806a27 100644 (file)
@@ -1,22 +1,26 @@
+static void
+arch_sigreturn(struct tcb *tcp)
+{
 #if defined LINUX_MIPSO32
-/*
- * offsetof(struct sigframe, sf_mask) ==
- * sizeof(sf_ass) + sizeof(sf_pad) + sizeof(struct sigcontext)
- */
-const long addr = mips_REG_SP + 6 * 4 +
-                 sizeof(struct sigcontext);
+       /*
       * offsetof(struct sigframe, sf_mask) ==
       * sizeof(sf_ass) + sizeof(sf_pad) + sizeof(struct sigcontext)
       */
+       const long addr = mips_REG_SP + 6 * 4 +
+                         sizeof(struct sigcontext);
 #else
-/*
- * This decodes rt_sigreturn.
- * The 64-bit ABIs do not have sigreturn.
- *
- * offsetof(struct rt_sigframe, rs_uc) ==
- * sizeof(sf_ass) + sizeof(sf_pad) + sizeof(struct siginfo)
- */
-const long addr = mips_REG_SP + 6 * 4 + 128 +
-                 offsetof(struct ucontext, uc_sigmask);
+       /*
       * This decodes rt_sigreturn.
       * The 64-bit ABIs do not have sigreturn.
       *
       * offsetof(struct rt_sigframe, rs_uc) ==
       * sizeof(sf_ass) + sizeof(sf_pad) + sizeof(struct siginfo)
       */
+       const long addr = mips_REG_SP + 6 * 4 + 128 +
+                         offsetof(struct ucontext, uc_sigmask);
 #endif
 
-tprints("{mask=");
-print_sigset_addr_len(tcp, addr, NSIG / 8);
-tprints("}");
+       tprints("{mask=");
+       print_sigset_addr_len(tcp, addr, NSIG / 8);
+       tprints("}");
+}
index bc4802ac62f0e5d55e40f1b20d5b2c378c175b74..c28a196215ae6e0c077b4446d3134f494435177b 100644 (file)
@@ -1,24 +1,28 @@
-long esp = ppc_regs.gpr[1];
-struct sigcontext sc;
+static void
+arch_sigreturn(struct tcb *tcp)
+{
+       long esp = ppc_regs.gpr[1];
+       struct sigcontext sc;
 
-/* Skip dummy stack frame. */
+       /* Skip dummy stack frame. */
 #ifdef POWERPC64
-if (current_personality == 0)
-       esp += 128;
-else
+       if (current_personality == 0)
+               esp += 128;
+       else
 #endif
-       esp += 64;
+               esp += 64;
 
-if (umove(tcp, esp, &sc) < 0) {
-       tprintf("{mask=%#lx}", esp);
-} else {
-       unsigned long mask[NSIG / 8 / sizeof(long)];
+       if (umove(tcp, esp, &sc) < 0) {
+               tprintf("{mask=%#lx}", esp);
+       } else {
+               unsigned long mask[NSIG / 8 / sizeof(long)];
 #ifdef POWERPC64
-       mask[0] = sc.oldmask | (sc._unused[3] << 32);
+               mask[0] = sc.oldmask | (sc._unused[3] << 32);
 #else
-       mask[0] = sc.oldmask;
-       mask[1] = sc._unused[3];
+               mask[0] = sc.oldmask;
+               mask[1] = sc._unused[3];
 #endif
-       tprintsigmask_addr("{mask=", mask);
-       tprints("}");
+               tprintsigmask_addr("{mask=", mask);
+               tprints("}");
+       }
 }
index 43afd954521845b7ca5c37aadbf02f489ea19c9c..6baf035c06dfe9ac99700663f8abfbc91d0cdf57 100644 (file)
@@ -1,14 +1,18 @@
-long mask[NSIG / 8 / sizeof(long)];
-const long addr = *s390_frame_ptr + __SIGNAL_FRAMESIZE;
+static void
+arch_sigreturn(struct tcb *tcp)
+{
+       long mask[NSIG / 8 / sizeof(long)];
+       const long addr = *s390_frame_ptr + __SIGNAL_FRAMESIZE;
 
-if (umove(tcp, addr, &mask) < 0) {
-       tprintf("{mask=%#lx}", addr);
-} else {
+       if (umove(tcp, addr, &mask) < 0) {
+               tprintf("{mask=%#lx}", addr);
+       } else {
 #ifdef S390
-       long v = mask[0];
-       mask[0] = mask[1];
-       mask[1] = v;
+               long v = mask[0];
+               mask[0] = mask[1];
+               mask[1] = v;
 #endif
-       tprintsigmask_addr("{mask=", mask);
-       tprints("}");
+               tprintsigmask_addr("{mask=", mask);
+               tprints("}");
+       }
 }
index 144b3a6d98d5e313b1b953bf8d7336962f95e9d8..9e86efa91eb88ea6c54096e851a558e8cec77ac7 100644 (file)
@@ -1,19 +1,23 @@
-long fp = sparc_regs.u_regs[U_REG_FP] + sizeof(struct sparc_stackf);
-struct {
-       struct pt_regs si_regs;
-       int si_mask;
-       void *fpu_save;
-       long insns[2] ATTRIBUTE_ALIGNED(8);
-       unsigned int extramask[NSIG / 8 / sizeof(int) - 1];
-} frame;
+static void
+arch_sigreturn(struct tcb *tcp)
+{
+       long fp = sparc_regs.u_regs[U_REG_FP] + sizeof(struct sparc_stackf);
+       struct {
+               struct pt_regs si_regs;
+               int si_mask;
+               void *fpu_save;
+               long insns[2] ATTRIBUTE_ALIGNED(8);
+               unsigned int extramask[NSIG / 8 / sizeof(int) - 1];
+       } frame;
 
-if (umove(tcp, fp, &frame) < 0) {
-       tprintf("{mask=%#lx}", fp);
-} else {
-       unsigned int mask[NSIG / 8 / sizeof(int)];
+       if (umove(tcp, fp, &frame) < 0) {
+               tprintf("{mask=%#lx}", fp);
+       } else {
+               unsigned int mask[NSIG / 8 / sizeof(int)];
 
-       mask[0] = frame.si_mask;
-       memcpy(mask + 1, frame.extramask, sizeof(frame.extramask));
-       tprintsigmask_addr("{mask=", mask);
-       tprints("}");
+               mask[0] = frame.si_mask;
+               memcpy(mask + 1, frame.extramask, sizeof(frame.extramask));
+               tprintsigmask_addr("{mask=", mask);
+               tprints("}");
+       }
 }
index 99e2bf8f3159e1d3b4ff1d27d92fa9862e4fbc6a..b1182fced2f5f1fd49986ff617128d13f62492e2 100644 (file)
@@ -1,8 +1,12 @@
-/* offset of ucontext in the kernel's sigframe structure */
-# define SIGFRAME_UC_OFFSET C_ABI_SAVE_AREA_SIZE + sizeof(siginfo_t)
-const long addr = tile_regs.sp + SIGFRAME_UC_OFFSET +
-                 offsetof(struct ucontext, uc_sigmask);
+static void
+arch_sigreturn(struct tcb *tcp)
+{
+       /* offset of ucontext in the kernel's sigframe structure */
+#define SIGFRAME_UC_OFFSET C_ABI_SAVE_AREA_SIZE + sizeof(siginfo_t)
+       const long addr = tile_regs.sp + SIGFRAME_UC_OFFSET +
+                         offsetof(struct ucontext, uc_sigmask);
 
-tprints("{mask=");
-print_sigset_addr_len(tcp, addr, NSIG / 8);
-tprints("}");
+       tprints("{mask=");
+       print_sigset_addr_len(tcp, addr, NSIG / 8);
+       tprints("}");
+}
index fd7359ff0d793a359fb01268fe486e40867cecc8..9a778fc766838786153e45b1931402c18c98efec 100644 (file)
@@ -1,15 +1 @@
-if (current_personality != 1) {
-       typedef struct {
-               uint32_t flags, link, stack[3], pad;
-               struct sigcontext mcontext;
-       } ucontext_x32_header;
-
-       const unsigned long addr =
-               (unsigned long) *x86_64_rsp_ptr +
-               sizeof(ucontext_x32_header);
-       tprints("{mask=");
-       print_sigset_addr_len(tcp, addr, NSIG / 8);
-       tprints("}");
-       return;
-}
-#include "i386/arch_sigreturn.c"
+#include "x86_64/arch_sigreturn.c"
index 4c1448b8ee27df3f87c5e9a7771e7e7e7712174f..1de0a0ad258c2d462b9e7046e1d7a4545b9fee4f 100644 (file)
@@ -1,10 +1,32 @@
-if (current_personality == 0) {
-       const unsigned long addr =
-               (unsigned long) *x86_64_rsp_ptr +
-               offsetof(struct ucontext, uc_sigmask);
+#define        arch_sigreturn  i386_arch_sigreturn
+#include "i386/arch_sigreturn.c"
+#undef arch_sigreturn
+
+static void
+arch_sigreturn(struct tcb *tcp)
+{
+       if (current_personality == 1) {
+               i386_arch_sigreturn(tcp);
+               return;
+       }
+
+       typedef struct {
+               uint32_t flags, link, stack[3], pad;
+               struct sigcontext mcontext;
+       } ucontext_x32_header;
+
+#define        X86_64_SIGMASK_OFFSET   offsetof(struct ucontext, uc_sigmask)
+#define        X32_SIGMASK_OFFSET      sizeof(ucontext_x32_header)
+
+       const unsigned long offset =
+#ifdef X32
+               X32_SIGMASK_OFFSET;
+#else
+               current_personality == 2 ? X32_SIGMASK_OFFSET :
+                                          X86_64_SIGMASK_OFFSET;
+#endif
+       const unsigned long addr = (unsigned long) *x86_64_rsp_ptr + offset;
        tprints("{mask=");
        print_sigset_addr_len(tcp, addr, NSIG / 8);
        tprints("}");
-       return;
 }
-#include "x32/arch_sigreturn.c"
index 9f2e32de223d52a4592259d4a4322c96195ff0e0..f0dab0da9adbcad6d59c0cebc5931b9a7126a939 100644 (file)
 # error NSIG < 32
 #endif
 
-static void
-arch_sigreturn(struct tcb *tcp)
-{
 #include "arch_sigreturn.c"
-}
 
 SYS_FUNC(sigreturn)
 {