Skip to contentSkip to conversation

linux-user: Fix MIPS16/microMIPS signal handling

PATCH New Kwok Cheung Yeung 1 participant 1 message Apr 30, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: Fix MIPS16/microMIPS signal handling

Signal handlers written using a compressed MIPS instruction set will segfault when invoked. This patch fixes this.

Switch the ISA mode on cores supporting the MIPS16/microMIPS ISAs according to bit 0 of the signal handler address. Clear bit 0 of the address assigned to the PC.

---
 linux-user/signal.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
linux-user/signal.c +10 -0
index 1055507..abfb382 100644
@@ -2662,6 +2662,11 @@ static void setup_frame(int sig, struct target_sigaction * ka,
     * since it returns to userland using eret
     * we cannot do this here, and we must set PC directly */
     regs->active_tc.PC = regs->active_tc.gpr[25] = ka->_sa_handler;
+    if (regs->insn_flags & (ASE_MIPS16 | ASE_MICROMIPS)) {
+        regs->hflags &= ~MIPS_HFLAG_M16;
+        regs->hflags |= (ka->_sa_handler & 1) << MIPS_HFLAG_M16_SHIFT;
+        regs->active_tc.PC &= ~(target_ulong) 1;
+    }
     unlock_user_struct(frame, frame_addr, 1);
     return;
 
@@ -2771,6 +2776,11 @@ static void setup_rt_frame(int sig, struct target_sigaction *ka,
     * since it returns to userland using eret
     * we cannot do this here, and we must set PC directly */
     env->active_tc.PC = env->active_tc.gpr[25] = ka->_sa_handler;
+    if (env->insn_flags & (ASE_MIPS16 | ASE_MICROMIPS)) {
+        env->hflags &= ~MIPS_HFLAG_M16;
+        env->hflags |= (ka->_sa_handler & 1) << MIPS_HFLAG_M16_SHIFT;
+        env->active_tc.PC &= ~(target_ulong) 1;
+    }
     unlock_user_struct(frame, frame_addr, 1);
     return;
 
Signature · 1 line
1.8.2.2