linux-user/i386: Split out gen_signal

This is a bit tidier than open-coding the 5 lines necessary
to initialize the target_siginfo_t.  In addition, this zeros
the remaining bytes of the target_siginfo_t, rather than
passing in garbage.

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20200213032223.14643-3-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
This commit is contained in:
Richard Henderson 2020-02-12 19:22:20 -08:00 committed by Laurent Vivier
parent 628460891d
commit acf768a904

View File

@ -81,13 +81,23 @@ static void set_idt(int n, unsigned int dpl)
} }
#endif #endif
static void gen_signal(CPUX86State *env, int sig, int code, abi_ptr addr)
{
target_siginfo_t info = {
.si_signo = sig,
.si_code = code,
._sifields._sigfault._addr = addr
};
queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
}
void cpu_loop(CPUX86State *env) void cpu_loop(CPUX86State *env)
{ {
CPUState *cs = env_cpu(env); CPUState *cs = env_cpu(env);
int trapnr; int trapnr;
abi_ulong pc; abi_ulong pc;
abi_ulong ret; abi_ulong ret;
target_siginfo_t info;
for(;;) { for(;;) {
cpu_exec_start(cs); cpu_exec_start(cs);
@ -134,70 +144,45 @@ void cpu_loop(CPUX86State *env)
#endif #endif
case EXCP0B_NOSEG: case EXCP0B_NOSEG:
case EXCP0C_STACK: case EXCP0C_STACK:
info.si_signo = TARGET_SIGBUS; gen_signal(env, TARGET_SIGBUS, TARGET_SI_KERNEL, 0);
info.si_errno = 0;
info.si_code = TARGET_SI_KERNEL;
info._sifields._sigfault._addr = 0;
queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
break; break;
case EXCP0D_GPF: case EXCP0D_GPF:
/* XXX: potential problem if ABI32 */ /* XXX: potential problem if ABI32 */
#ifndef TARGET_X86_64 #ifndef TARGET_X86_64
if (env->eflags & VM_MASK) { if (env->eflags & VM_MASK) {
handle_vm86_fault(env); handle_vm86_fault(env);
} else break;
#endif
{
info.si_signo = TARGET_SIGSEGV;
info.si_errno = 0;
info.si_code = TARGET_SI_KERNEL;
info._sifields._sigfault._addr = 0;
queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
} }
#endif
gen_signal(env, TARGET_SIGSEGV, TARGET_SI_KERNEL, 0);
break; break;
case EXCP0E_PAGE: case EXCP0E_PAGE:
info.si_signo = TARGET_SIGSEGV; gen_signal(env, TARGET_SIGSEGV,
info.si_errno = 0; (env->error_code & 1 ?
if (!(env->error_code & 1)) TARGET_SEGV_ACCERR : TARGET_SEGV_MAPERR),
info.si_code = TARGET_SEGV_MAPERR; env->cr[2]);
else
info.si_code = TARGET_SEGV_ACCERR;
info._sifields._sigfault._addr = env->cr[2];
queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
break; break;
case EXCP00_DIVZ: case EXCP00_DIVZ:
#ifndef TARGET_X86_64 #ifndef TARGET_X86_64
if (env->eflags & VM_MASK) { if (env->eflags & VM_MASK) {
handle_vm86_trap(env, trapnr); handle_vm86_trap(env, trapnr);
} else break;
#endif
{
/* division by zero */
info.si_signo = TARGET_SIGFPE;
info.si_errno = 0;
info.si_code = TARGET_FPE_INTDIV;
info._sifields._sigfault._addr = env->eip;
queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
} }
#endif
gen_signal(env, TARGET_SIGFPE, TARGET_FPE_INTDIV, env->eip);
break; break;
case EXCP01_DB: case EXCP01_DB:
case EXCP03_INT3: case EXCP03_INT3:
#ifndef TARGET_X86_64 #ifndef TARGET_X86_64
if (env->eflags & VM_MASK) { if (env->eflags & VM_MASK) {
handle_vm86_trap(env, trapnr); handle_vm86_trap(env, trapnr);
} else break;
#endif
{
info.si_signo = TARGET_SIGTRAP;
info.si_errno = 0;
if (trapnr == EXCP01_DB) {
info.si_code = TARGET_TRAP_BRKPT;
info._sifields._sigfault._addr = env->eip;
} else {
info.si_code = TARGET_SI_KERNEL;
info._sifields._sigfault._addr = 0;
} }
queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); #endif
if (trapnr == EXCP01_DB) {
gen_signal(env, TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->eip);
} else {
gen_signal(env, TARGET_SIGTRAP, TARGET_SI_KERNEL, 0);
} }
break; break;
case EXCP04_INTO: case EXCP04_INTO:
@ -205,31 +190,19 @@ void cpu_loop(CPUX86State *env)
#ifndef TARGET_X86_64 #ifndef TARGET_X86_64
if (env->eflags & VM_MASK) { if (env->eflags & VM_MASK) {
handle_vm86_trap(env, trapnr); handle_vm86_trap(env, trapnr);
} else break;
#endif
{
info.si_signo = TARGET_SIGSEGV;
info.si_errno = 0;
info.si_code = TARGET_SI_KERNEL;
info._sifields._sigfault._addr = 0;
queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
} }
#endif
gen_signal(env, TARGET_SIGSEGV, TARGET_SI_KERNEL, 0);
break; break;
case EXCP06_ILLOP: case EXCP06_ILLOP:
info.si_signo = TARGET_SIGILL; gen_signal(env, TARGET_SIGILL, TARGET_ILL_ILLOPN, env->eip);
info.si_errno = 0;
info.si_code = TARGET_ILL_ILLOPN;
info._sifields._sigfault._addr = env->eip;
queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
break; break;
case EXCP_INTERRUPT: case EXCP_INTERRUPT:
/* just indicate that signals should be handled asap */ /* just indicate that signals should be handled asap */
break; break;
case EXCP_DEBUG: case EXCP_DEBUG:
info.si_signo = TARGET_SIGTRAP; gen_signal(env, TARGET_SIGTRAP, TARGET_TRAP_BRKPT, 0);
info.si_errno = 0;
info.si_code = TARGET_TRAP_BRKPT;
queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
break; break;
case EXCP_ATOMIC: case EXCP_ATOMIC:
cpu_exec_step_atomic(cs); cpu_exec_step_atomic(cs);