linux-cvs-patches
[Top] [All Lists]

CVS Update@linux-mips.org: linux

To: linux-cvs-patches@linux-mips.org
Subject: CVS Update@linux-mips.org: linux
From: ths@linux-mips.org
Date: Fri, 07 Jan 2005 19:19:46 +0000
Reply-to: linux-mips@linux-mips.org
Sender: linux-cvs-patches-bounce@linux-mips.org
CVSROOT:        /home/cvs
Module name:    linux
Changes by:     ths@ftp.linux-mips.org  05/01/07 19:19:40

Modified files:
        arch/mips/kernel: signal.c signal_n32.c 
Added files:
        arch/mips/kernel: signal-common.h 

Log message:
        Save a bit of copy&paste by separating out common parts in the signal 
handling.

diff -urN linux/arch/mips/kernel/signal-common.h 
linux/arch/mips/kernel/signal-common.h
--- linux/arch/mips/kernel/signal-common.h      1970/01/01 00:00:00
+++ linux/arch/mips/kernel/signal-common.h      Fri Jan  7 19:19:40 2005        
1.1
@@ -0,0 +1,135 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 1991, 1992  Linus Torvalds
+ * Copyright (C) 1994 - 2000  Ralf Baechle
+ * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
+ */
+
+extern inline int
+setup_sigcontext(struct pt_regs *regs, struct sigcontext *sc)
+{
+       int err = 0;
+
+       err |= __put_user(regs->cp0_epc, &sc->sc_pc);
+       err |= __put_user(regs->cp0_status, &sc->sc_status);
+
+#define save_gp_reg(i) do {                                            \
+       err |= __put_user(regs->regs[i], &sc->sc_regs[i]);              \
+} while(0)
+       __put_user(0, &sc->sc_regs[0]); save_gp_reg(1); save_gp_reg(2);
+       save_gp_reg(3); save_gp_reg(4); save_gp_reg(5); save_gp_reg(6);
+       save_gp_reg(7); save_gp_reg(8); save_gp_reg(9); save_gp_reg(10);
+       save_gp_reg(11); save_gp_reg(12); save_gp_reg(13); save_gp_reg(14);
+       save_gp_reg(15); save_gp_reg(16); save_gp_reg(17); save_gp_reg(18);
+       save_gp_reg(19); save_gp_reg(20); save_gp_reg(21); save_gp_reg(22);
+       save_gp_reg(23); save_gp_reg(24); save_gp_reg(25); save_gp_reg(26);
+       save_gp_reg(27); save_gp_reg(28); save_gp_reg(29); save_gp_reg(30);
+       save_gp_reg(31);
+#undef save_gp_reg
+
+       err |= __put_user(regs->hi, &sc->sc_mdhi);
+       err |= __put_user(regs->lo, &sc->sc_mdlo);
+       err |= __put_user(regs->cp0_cause, &sc->sc_cause);
+       err |= __put_user(regs->cp0_badvaddr, &sc->sc_badvaddr);
+
+       err |= __put_user(current->used_math, &sc->sc_used_math);
+
+       if (!current->used_math)
+               goto out;
+
+       /*
+        * Save FPU state to signal context.  Signal handler will "inherit"
+        * current FPU state.
+        */
+       preempt_disable();
+
+       if (!is_fpu_owner()) {
+               own_fpu();
+               restore_fp(current);
+       }
+       err |= save_fp_context(sc);
+
+       preempt_enable();
+
+out:
+       return err;
+}
+
+extern inline int
+restore_sigcontext(struct pt_regs *regs, struct sigcontext *sc)
+{
+       int err = 0;
+
+       /* Always make any pending restarted system calls return -EINTR */
+       current_thread_info()->restart_block.fn = do_no_restart_syscall;
+
+       err |= __get_user(regs->cp0_epc, &sc->sc_pc);
+       err |= __get_user(regs->hi, &sc->sc_mdhi);
+       err |= __get_user(regs->lo, &sc->sc_mdlo);
+
+#define restore_gp_reg(i) do {                                         \
+       err |= __get_user(regs->regs[i], &sc->sc_regs[i]);              \
+} while(0)
+       restore_gp_reg( 1); restore_gp_reg( 2); restore_gp_reg( 3);
+       restore_gp_reg( 4); restore_gp_reg( 5); restore_gp_reg( 6);
+       restore_gp_reg( 7); restore_gp_reg( 8); restore_gp_reg( 9);
+       restore_gp_reg(10); restore_gp_reg(11); restore_gp_reg(12);
+       restore_gp_reg(13); restore_gp_reg(14); restore_gp_reg(15);
+       restore_gp_reg(16); restore_gp_reg(17); restore_gp_reg(18);
+       restore_gp_reg(19); restore_gp_reg(20); restore_gp_reg(21);
+       restore_gp_reg(22); restore_gp_reg(23); restore_gp_reg(24);
+       restore_gp_reg(25); restore_gp_reg(26); restore_gp_reg(27);
+       restore_gp_reg(28); restore_gp_reg(29); restore_gp_reg(30);
+       restore_gp_reg(31);
+#undef restore_gp_reg
+
+       err |= __get_user(current->used_math, &sc->sc_used_math);
+
+       preempt_disable();
+
+       if (current->used_math) {
+               /* restore fpu context if we have used it before */
+               own_fpu();
+               err |= restore_fp_context(sc);
+       } else {
+               /* signal handler may have used FPU.  Give it up. */
+               lose_fpu();
+       }
+
+       preempt_enable();
+
+       return err;
+}
+
+/*
+ * Determine which stack to use..
+ */
+extern inline void *
+get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size)
+{
+       unsigned long sp, almask;
+
+       /* Default to using normal stack */
+       sp = regs->regs[29];
+
+       /*
+        * FPU emulator may have it's own trampoline active just
+        * above the user stack, 16-bytes before the next lowest
+        * 16 byte boundary.  Try to avoid trashing it.
+        */
+       sp -= 32;
+
+       /* This is the X/Open sanctioned signal stack switching.  */
+       if ((ka->sa.sa_flags & SA_ONSTACK) && (sas_ss_flags (sp) == 0))
+               sp = current->sas_ss_sp + current->sas_ss_size;
+
+       if (PLAT_TRAMPOLINE_STUFF_LINE)
+               almask = ~(PLAT_TRAMPOLINE_STUFF_LINE - 1);
+       else
+               almask = ALMASK;
+
+       return (void *)((sp - frame_size) & almask);
+}
diff -urN linux/arch/mips/kernel/signal.c linux/arch/mips/kernel/signal.c
--- linux/arch/mips/kernel/signal.c     2004/12/10 12:43:09     1.83
+++ linux/arch/mips/kernel/signal.c     2005/01/07 19:19:40     1.84
@@ -31,6 +31,8 @@
 #include <asm/ucontext.h>
 #include <asm/cpu-features.h>
 
+#include "signal-common.h"
+
 #define DEBUG_SIG 0
 
 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
@@ -303,85 +305,6 @@
        force_sig(SIGSEGV, current);
 }
 
-inline int setup_sigcontext(struct pt_regs *regs, struct sigcontext *sc)
-{
-       int err = 0;
-
-       err |= __put_user(regs->cp0_epc, &sc->sc_pc);
-       err |= __put_user(regs->cp0_status, &sc->sc_status);
-
-#define save_gp_reg(i) do {                                            \
-       err |= __put_user(regs->regs[i], &sc->sc_regs[i]);              \
-} while(0)
-       __put_user(0, &sc->sc_regs[0]); save_gp_reg(1); save_gp_reg(2);
-       save_gp_reg(3); save_gp_reg(4); save_gp_reg(5); save_gp_reg(6);
-       save_gp_reg(7); save_gp_reg(8); save_gp_reg(9); save_gp_reg(10);
-       save_gp_reg(11); save_gp_reg(12); save_gp_reg(13); save_gp_reg(14);
-       save_gp_reg(15); save_gp_reg(16); save_gp_reg(17); save_gp_reg(18);
-       save_gp_reg(19); save_gp_reg(20); save_gp_reg(21); save_gp_reg(22);
-       save_gp_reg(23); save_gp_reg(24); save_gp_reg(25); save_gp_reg(26);
-       save_gp_reg(27); save_gp_reg(28); save_gp_reg(29); save_gp_reg(30);
-       save_gp_reg(31);
-#undef save_gp_reg
-
-       err |= __put_user(regs->hi, &sc->sc_mdhi);
-       err |= __put_user(regs->lo, &sc->sc_mdlo);
-       err |= __put_user(regs->cp0_cause, &sc->sc_cause);
-       err |= __put_user(regs->cp0_badvaddr, &sc->sc_badvaddr);
-
-       err |= __put_user(current->used_math, &sc->sc_used_math);
-
-       if (!current->used_math)
-               goto out;
-
-       /*
-        * Save FPU state to signal context.  Signal handler will "inherit"
-        * current FPU state.
-        */
-       preempt_disable();
-
-       if (!is_fpu_owner()) {
-               own_fpu();
-               restore_fp(current);
-       }
-       err |= save_fp_context(sc);
-
-       preempt_enable();
-
-out:
-       return err;
-}
-
-/*
- * Determine which stack to use..
- */
-static inline void *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
-       size_t frame_size)
-{
-       unsigned long sp, almask;
-
-       /* Default to using normal stack */
-       sp = regs->regs[29];
-
-       /*
-        * FPU emulator may have it's own trampoline active just
-        * above the user stack, 16-bytes before the next lowest
-        * 16 byte boundary.  Try to avoid trashing it.
-        */
-       sp -= 32;
-
-       /* This is the X/Open sanctioned signal stack switching.  */
-       if ((ka->sa.sa_flags & SA_ONSTACK) && (sas_ss_flags (sp) == 0))
-               sp = current->sas_ss_sp + current->sas_ss_size;
-
-       if (PLAT_TRAMPOLINE_STUFF_LINE)
-               almask = ~(PLAT_TRAMPOLINE_STUFF_LINE - 1);
-       else
-               almask = ALMASK;
-
-       return (void *)((sp - frame_size) & almask);
-}
-
 #ifdef CONFIG_TRAD_SIGNALS
 static void inline setup_frame(struct k_sigaction * ka, struct pt_regs *regs,
        int signr, sigset_t *set)
@@ -634,7 +557,7 @@
                }
 #endif
 #ifdef CONFIG_BINFMT_IRIX
-               if (unlikely(current->personality != PER_LINUX)) {
+               if (unlikely(current->personality != PER_LINUX) {
                        do_irix_signal(oldset, regs);
                        return;
                }
diff -urN linux/arch/mips/kernel/signal_n32.c 
linux/arch/mips/kernel/signal_n32.c
--- linux/arch/mips/kernel/signal_n32.c 2004/12/10 12:43:09     1.11
+++ linux/arch/mips/kernel/signal_n32.c 2005/01/07 19:19:40     1.12
@@ -37,8 +37,10 @@
 #include <asm/fpu.h>
 #include <asm/cpu-features.h>
 
+#include "signal-common.h"
+
 /*
- * Including <asm/unistd.h would give use the 64-bit syscall numbers ...
+ * Including <asm/unistd.h> would give use the 64-bit syscall numbers ...
  */
 #define __NR_N32_rt_sigreturn          6211
 #define __NR_N32_restart_syscall       6214
@@ -127,36 +129,6 @@
        force_sig(SIGSEGV, current);
 }
 
-/*
- * Determine which stack to use..
- */
-static inline void *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
-       size_t frame_size)
-{
-       unsigned long sp, almask;
-
-       /* Default to using normal stack */
-       sp = regs->regs[29];
-
-       /*
-        * FPU emulator may have it's own trampoline active just
-        * above the user stack, 16-bytes before the next lowest
-        * 16 byte boundary.  Try to avoid trashing it.
-        */
-       sp -= 32;
-
-       /* This is the X/Open sanctioned signal stack switching.  */
-       if ((ka->sa.sa_flags & SA_ONSTACK) && (sas_ss_flags (sp) == 0))
-               sp = current->sas_ss_sp + current->sas_ss_size;
-
-       if (PLAT_TRAMPOLINE_STUFF_LINE)
-               almask = ~(PLAT_TRAMPOLINE_STUFF_LINE - 1);
-       else
-               almask = ALMASK;
-
-       return (void *)((sp - frame_size) & almask);
-}
-
 void setup_rt_frame_n32(struct k_sigaction * ka,
        struct pt_regs *regs, int signr, sigset_t *set, siginfo_t *info)
 {

<Prev in Thread] Current Thread [Next in Thread>