linux-user/openrisc: Implement setup_sigtramp

Create and record the rt signal trampoline.

Reviewed-by: Stafford Horne <shorne@gmail.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20210929130553.121567-18-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
This commit is contained in:
Richard Henderson 2021-09-29 09:05:44 -04:00 committed by Laurent Vivier
parent f32d3b6793
commit 9ce3ad4452
2 changed files with 16 additions and 8 deletions

View File

@ -38,7 +38,6 @@ typedef struct target_ucontext {
typedef struct target_rt_sigframe {
struct target_siginfo info;
target_ucontext uc;
uint32_t retcode[4]; /* trampoline code */
} target_rt_sigframe;
static void restore_sigcontext(CPUOpenRISCState *env, target_sigcontext *sc)
@ -116,14 +115,8 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
__put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i]);
}
/* This is l.ori r11,r0,__NR_sigreturn; l.sys 1; l.nop; l.nop */
__put_user(0xa9600000 | TARGET_NR_rt_sigreturn, frame->retcode + 0);
__put_user(0x20000001, frame->retcode + 1);
__put_user(0x15000000, frame->retcode + 2);
__put_user(0x15000000, frame->retcode + 3);
/* Set up registers for signal handler */
cpu_set_gpr(env, 9, frame_addr + offsetof(target_rt_sigframe, retcode));
cpu_set_gpr(env, 9, default_rt_sigreturn);
cpu_set_gpr(env, 3, sig);
cpu_set_gpr(env, 4, frame_addr + offsetof(target_rt_sigframe, info));
cpu_set_gpr(env, 5, frame_addr + offsetof(target_rt_sigframe, uc));
@ -169,3 +162,16 @@ long do_rt_sigreturn(CPUOpenRISCState *env)
force_sig(TARGET_SIGSEGV);
return 0;
}
void setup_sigtramp(abi_ulong sigtramp_page)
{
uint32_t *tramp = lock_user(VERIFY_WRITE, sigtramp_page, 8, 0);
assert(tramp != NULL);
/* This is l.ori r11,r0,__NR_sigreturn; l.sys 1 */
__put_user(0xa9600000 | TARGET_NR_rt_sigreturn, tramp + 0);
__put_user(0x20000001, tramp + 1);
default_rt_sigreturn = sigtramp_page;
unlock_user(tramp, sigtramp_page, 8);
}

View File

@ -26,4 +26,6 @@ typedef struct target_sigaltstack {
#include "../generic/signal.h"
#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 1
#endif /* OPENRISC_TARGET_SIGNAL_H */