linux-user: fix bug about incorrect base addresss of idt and gdt on i386 and x86_64
PATCH 1/1 linux-user: fix bug about incorrect base addresss of idt and gdt on i386 and x86_64
From: fanwenjie <[email protected]>
On linux user mode, CPUX86State::idt::base and CPUX86State::gdt::base from Different CPUX86State Objects have same value, It is incorrect! Every CPUX86State::idt::base and Every CPUX86State::gdt::base Must points to independent memory space.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1405
Signed-off-by fanwenjie <[email protected]>
--- linux-user/i386/cpu_loop.c | 10 ++++++++++ linux-user/main.c | 11 +++++++++++ 2 files changed, 21 insertions(+)
linux-user/i386/cpu_loop.c +10 -0
@@ -314,8 +314,18 @@ void cpu_loop(CPUX86State *env) } } +static void target_cpu_free (void *obj) +{ +CPUArchState * env = ((CPUState *)obj)->env_ptr; +target_munmap (env->idt.base,sizeof (uint64_t ) * (env->idt.limit +1 )); +target_munmap (env->gdt.base,sizeof (uint64_t ) *TARGET_GDT_ENTRIES ); +g_free (obj); +} +void target_cpu_copy_regs (CPUArchState *env,struct target_pt_regs *regs) { +CPUState * cpu =env_cpu (env); +OBJECT (cpu)->free = target_cpu_free; env->cr[0 ] =CR0_PG_MASK |CR0_WP_MASK |CR0_PE_MASK ; env->hflags |=HF_PE_MASK |HF_CPL_MASK ;if (env->features[FEAT_1_EDX ] &CPUID_SSE ) {
linux-user/main.c +11 -0
@@ -234,6 +234,17 @@ CPUArchState *cpu_copy(CPUArchState *env) new_cpu->tcg_cflags = cpu->tcg_cflags;memcpy (new_env, env,sizeof (CPUArchState)); +#if defined(TARGET_I386 ) || defined(TARGET_X86_64 ) + new_env->gdt.base =target_mmap (0 ,sizeof (uint64_t ) *TARGET_GDT_ENTRIES , +PROT_READ |PROT_WRITE , +MAP_ANONYMOUS |MAP_PRIVATE ,-1 ,0 ); + new_env->idt.base =target_mmap (0 ,sizeof (uint64_t ) * (env->idt.limit +1 ), +PROT_READ |PROT_WRITE , +MAP_ANONYMOUS |MAP_PRIVATE ,-1 ,0 ); +memcpy ((void *)new_env->gdt.base, (void *)env->gdt.base,sizeof (uint64_t ) *TARGET_GDT_ENTRIES ); +memcpy ((void *)new_env->idt.base, (void *)env->idt.base,sizeof (uint64_t ) * (env->idt.limit +1 )); +OBJECT (new_cpu)->free =OBJECT (cpu)->free; +#endif /* Clone all break/watchpoints. Note: Once we support ptrace with hw-debug register access, make sure
Signature · 1 line
2.34.1