linux-user: i386: Use trapnr which returns from cpu_exec() instead of exception_index
PATCH 1/1 linux-user: i386: Use trapnr which returns from cpu_exec() instead of exception_index
From: Chen Gang <[email protected]>
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 <[email protected]>
--- 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(-)
include/hw/core/cpu.h +2 -0
@@ -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;
linux-user/i386/cpu_loop.c +7 -8
@@ -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);
linux-user/i386/signal.c +2 -2
@@ -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);
Signature · 1 line
2.24.0.308.g228f53135a
include/hw/core/cpu.h struct CPUState { · line 462
Quoted 7 lines · On 9/26/20 3:39 AM, [email protected] wrote:
+++
b/include/hw/core/cpu.hinclude/hw/core/cpu.h +2
-0@@ -458,6 +458,8 @@ struct CPUState {/* track IOMMUs whose translations we've cached in the TCG TLB */ GArray *iommu_notifiers; + +int trapnr;
Don't put this here. It belongs in CPUX86State, possibly with #ifdef CONFIG_USER_ONLY.
linux-user/i386/cpu_loop.c static void emulate_vsyscall(CPUX86State *env) · line 201
Quoted 4 lines
linux-user/i386/cpu_loop.c +0
-1void cpu_loop (CPUX86State *env) {CPUState *cs =env_cpu (env); -int trapnr;
Why are you removing the local variable?
r~