linux-user: Fix MIPS16/microMIPS signal handling
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
@@ -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
Quoted 6 lines · Kwok Cheung Yeung
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.
Don't you also need to handle bit-0-set in restore_sigcontext when returning from the signal? (I guess that might cause a crash if you have a non-compressed-instruction-set signal handler invoked while running compressed-instruction--set code.)
Quoted 35 lines
Signed-off-by Kwok Cheung Yeung <[email protected]>--- linux-user/signal.c | 10 ++++++++++ 1 file changed, 10 insertions(+)linux-user/signal.c +10
-1@@ -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 ; --
Quoted 3 lines
1.8.2.2
-- PMM