From a0577d2aa9bd42d5d584fa03649a166ba45c2f3d Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Sun, 27 Sep 2015 14:26:04 -0700 Subject: target-tilegx: Use TILEGX_EXCP_SIGNAL instead of TILEGX_EXCP_SEGV Consolidate signal handling under a single exception. Signed-off-by: Richard Henderson --- linux-user/main.c | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'linux-user') diff --git a/linux-user/main.c b/linux-user/main.c index 9e8b92b03c..1f60ff2a1f 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -3414,17 +3414,6 @@ void cpu_loop(CPUS390XState *env) #ifdef TARGET_TILEGX -static void gen_sigsegv_maperr(CPUTLGState *env, target_ulong addr) -{ - target_siginfo_t info; - - info.si_signo = TARGET_SIGSEGV; - info.si_errno = 0; - info.si_code = TARGET_SEGV_MAPERR; - info._sifields._sigfault._addr = addr; - queue_signal(env, info.si_signo, &info); -} - static void gen_sigill_reg(CPUTLGState *env) { target_siginfo_t info; @@ -3436,17 +3425,36 @@ static void gen_sigill_reg(CPUTLGState *env) queue_signal(env, info.si_signo, &info); } -static void do_signal(CPUTLGState *env) +static void do_signal(CPUTLGState *env, int signo, int sigcode) { target_siginfo_t info; - info.si_signo = env->signo; + info.si_signo = signo; info.si_errno = 0; - info.si_code = env->sigcode; info._sifields._sigfault._addr = env->pc; + + if (signo == TARGET_SIGSEGV) { + /* The passed in sigcode is a dummy; check for a page mapping + and pass either MAPERR or ACCERR. */ + target_ulong addr = env->excaddr; + info._sifields._sigfault._addr = addr; + if (page_check_range(addr, 1, PAGE_VALID) < 0) { + sigcode = TARGET_SEGV_MAPERR; + } else { + sigcode = TARGET_SEGV_ACCERR; + } + } + info.si_code = sigcode; + queue_signal(env, info.si_signo, &info); } +static void gen_sigsegv_maperr(CPUTLGState *env, target_ulong addr) +{ + env->excaddr = addr; + do_signal(env, TARGET_SIGSEGV, 0); +} + static void set_regval(CPUTLGState *env, uint8_t reg, uint64_t val) { if (unlikely(reg >= TILEGX_R_COUNT)) { @@ -3634,15 +3642,12 @@ void cpu_loop(CPUTLGState *env) do_fetch(env, trapnr, false); break; case TILEGX_EXCP_SIGNAL: - do_signal(env); + do_signal(env, env->signo, env->sigcode); break; case TILEGX_EXCP_REG_IDN_ACCESS: case TILEGX_EXCP_REG_UDN_ACCESS: gen_sigill_reg(env); break; - case TILEGX_EXCP_SEGV: - gen_sigsegv_maperr(env, env->excaddr); - break; default: fprintf(stderr, "trapnr is %d[0x%x].\n", trapnr, trapnr); g_assert_not_reached(); -- cgit v1.2.3