OSDN Git Service

powerpc/signal: Use code patching instead of hardcoding
authorChristophe Leroy <christophe.leroy@c-s.fr>
Fri, 9 Nov 2018 17:33:28 +0000 (17:33 +0000)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 19 Dec 2018 07:56:32 +0000 (18:56 +1100)
Instead of hardcoding code modifications, use code patching functions.

Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/include/asm/ppc-opcode.h
arch/powerpc/kernel/signal_32.c
arch/powerpc/kernel/signal_64.c

index a6e9e31..7f693e0 100644 (file)
 #define PPC_INST_MTSPR_DSCR_USER_MASK  0xfc1ffffe
 #define PPC_INST_MFVSRD                        0x7c000066
 #define PPC_INST_MTVSRD                        0x7c000166
+#define PPC_INST_SC                    0x44000002
 #define PPC_INST_SLBFEE                        0x7c0007a7
 #define PPC_INST_SLBIA                 0x7c0003e4
 
index e6474a4..9d39e0e 100644 (file)
@@ -470,9 +470,9 @@ static int save_user_regs(struct pt_regs *regs, struct mcontext __user *frame,
                return 1;
 
        if (sigret) {
-               /* Set up the sigreturn trampoline: li r0,sigret; sc */
-               if (__put_user(0x38000000UL + sigret, &frame->tramp[0])
-                   || __put_user(0x44000002UL, &frame->tramp[1]))
+               /* Set up the sigreturn trampoline: li 0,sigret; sc */
+               if (__put_user(PPC_INST_ADDI + sigret, &frame->tramp[0])
+                   || __put_user(PPC_INST_SC, &frame->tramp[1]))
                        return 1;
                flush_icache_range((unsigned long) &frame->tramp[0],
                                   (unsigned long) &frame->tramp[2]);
@@ -619,9 +619,9 @@ static int save_tm_user_regs(struct pt_regs *regs,
        if (__put_user(msr, &frame->mc_gregs[PT_MSR]))
                return 1;
        if (sigret) {
-               /* Set up the sigreturn trampoline: li r0,sigret; sc */
-               if (__put_user(0x38000000UL + sigret, &frame->tramp[0])
-                   || __put_user(0x44000002UL, &frame->tramp[1]))
+               /* Set up the sigreturn trampoline: li 0,sigret; sc */
+               if (__put_user(PPC_INST_ADDI + sigret, &frame->tramp[0])
+                   || __put_user(PPC_INST_SC, &frame->tramp[1]))
                        return 1;
                flush_icache_range((unsigned long) &frame->tramp[0],
                                   (unsigned long) &frame->tramp[2]);
index 83d51bf..e53ad11 100644 (file)
@@ -598,11 +598,12 @@ static long setup_trampoline(unsigned int syscall, unsigned int __user *tramp)
        long err = 0;
 
        /* addi r1, r1, __SIGNAL_FRAMESIZE  # Pop the dummy stackframe */
-       err |= __put_user(0x38210000UL | (__SIGNAL_FRAMESIZE & 0xffff), &tramp[0]);
+       err |= __put_user(PPC_INST_ADDI | __PPC_RT(R1) | __PPC_RA(R1) |
+                         (__SIGNAL_FRAMESIZE & 0xffff), &tramp[0]);
        /* li r0, __NR_[rt_]sigreturn| */
-       err |= __put_user(0x38000000UL | (syscall & 0xffff), &tramp[1]);
+       err |= __put_user(PPC_INST_ADDI | (syscall & 0xffff), &tramp[1]);
        /* sc */
-       err |= __put_user(0x44000002UL, &tramp[2]);
+       err |= __put_user(PPC_INST_SC, &tramp[2]);
 
        /* Minimal traceback info */
        for (i=TRAMP_TRACEBACK; i < TRAMP_SIZE ;i++)