From: Chen Gang <cheng...@emindsoft.com.cn> After return from cpu_exec(), the exception_index is already set 0 in cpu_handle_exception(), so we need the trapnr which returns from cpu_exec() for trapno of target sigcontext.
Signed-off-by: Chen Gang <cheng...@emindsoft.com.cn> --- include/hw/core/cpu.h | 2 ++ linux-user/i386/cpu_loop.c | 15 +++++++-------- linux-user/i386/signal.c | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 8f145733ce..390e27d9e1 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -458,6 +458,8 @@ struct CPUState { /* track IOMMUs whose translations we've cached in the TCG TLB */ GArray *iommu_notifiers; + + int trapnr; }; typedef QTAILQ_HEAD(CPUTailQ, CPUState) CPUTailQ; diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c index 70cde417e6..f0db088221 100644 --- a/linux-user/i386/cpu_loop.c +++ b/linux-user/i386/cpu_loop.c @@ -198,17 +198,16 @@ static void emulate_vsyscall(CPUX86State *env) void cpu_loop(CPUX86State *env) { CPUState *cs = env_cpu(env); - int trapnr; abi_ulong pc; abi_ulong ret; for(;;) { cpu_exec_start(cs); - trapnr = cpu_exec(cs); + cs->trapnr = cpu_exec(cs); cpu_exec_end(cs); process_queued_cpu_work(cs); - switch(trapnr) { + switch (cs->trapnr) { case 0x80: /* linux syscall from int $0x80 */ ret = do_syscall(env, @@ -273,7 +272,7 @@ void cpu_loop(CPUX86State *env) case EXCP00_DIVZ: #ifndef TARGET_X86_64 if (env->eflags & VM_MASK) { - handle_vm86_trap(env, trapnr); + handle_vm86_trap(env, cs->trapnr); break; } #endif @@ -283,11 +282,11 @@ void cpu_loop(CPUX86State *env) case EXCP03_INT3: #ifndef TARGET_X86_64 if (env->eflags & VM_MASK) { - handle_vm86_trap(env, trapnr); + handle_vm86_trap(env, cs->trapnr); break; } #endif - if (trapnr == EXCP01_DB) { + if (cs->trapnr == EXCP01_DB) { gen_signal(env, TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->eip); } else { gen_signal(env, TARGET_SIGTRAP, TARGET_SI_KERNEL, 0); @@ -297,7 +296,7 @@ void cpu_loop(CPUX86State *env) case EXCP05_BOUND: #ifndef TARGET_X86_64 if (env->eflags & VM_MASK) { - handle_vm86_trap(env, trapnr); + handle_vm86_trap(env, cs->trapnr); break; } #endif @@ -318,7 +317,7 @@ void cpu_loop(CPUX86State *env) default: pc = env->segs[R_CS].base + env->eip; EXCP_DUMP(env, "qemu: 0x%08lx: unhandled CPU exception 0x%x - aborting\n", - (long)pc, trapnr); + (long)pc, cs->trapnr); abort(); } process_pending_signals(env); diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c index 97a39204cc..c184d28d22 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -215,7 +215,7 @@ static void setup_sigcontext(struct target_sigcontext *sc, __put_user(env->regs[R_EDX], &sc->edx); __put_user(env->regs[R_ECX], &sc->ecx); __put_user(env->regs[R_EAX], &sc->eax); - __put_user(cs->exception_index, &sc->trapno); + __put_user(cs->trapnr, &sc->trapno); __put_user(env->error_code, &sc->err); __put_user(env->eip, &sc->eip); __put_user(env->segs[R_CS].selector, (unsigned int *)&sc->cs); @@ -251,7 +251,7 @@ static void setup_sigcontext(struct target_sigcontext *sc, __put_user(env->regs[14], &sc->r14); __put_user(env->regs[15], &sc->r15); - __put_user(cs->exception_index, &sc->trapno); + __put_user(cs->trapnr, &sc->trapno); __put_user(env->error_code, &sc->err); __put_user(env->eip, &sc->rip); -- 2.24.0.308.g228f53135a