[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 28/28] linux-user: fix bug about incorrect base addresss of gdt on
From: |
Laurent Vivier |
Subject: |
[PULL 28/28] linux-user: fix bug about incorrect base addresss of gdt on i386 and x86_64 |
Date: |
Wed, 8 Mar 2023 14:28:57 +0100 |
From: "fanwj@mail.ustc.edu.cn" <fanwj@mail.ustc.edu.cn>
On linux user mode, CPUX86State::gdt::base from Different CPUX86State Objects
have same value, It is incorrect! Every CPUX86State::gdt::base Must points to
independent memory space.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1405
Signed-off-by: fanwenjie <fanwj@mail.ustc.edu.cn>
Message-Id: <4172b90.58b08.18631b77860.Coremail.fanwj@mail.ustc.edu.cn>
[lv: remove unnecessary casts, split overlong line]
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
linux-user/i386/cpu_loop.c | 9 +++++++++
linux-user/main.c | 8 ++++++++
2 files changed, 17 insertions(+)
diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c
index 865413c08f07..48511cd68875 100644
--- a/linux-user/i386/cpu_loop.c
+++ b/linux-user/i386/cpu_loop.c
@@ -314,8 +314,17 @@ void cpu_loop(CPUX86State *env)
}
}
+static void target_cpu_free(void *obj)
+{
+ CPUArchState* env = ((CPUState*)obj)->env_ptr;
+ 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) {
diff --git a/linux-user/main.c b/linux-user/main.c
index 798fdc0bce8e..69ca5a4b9b08 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -238,6 +238,14 @@ 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);
+ memcpy(g2h_untagged(new_env->gdt.base), g2h_untagged(env->gdt.base),
+ sizeof(uint64_t) * TARGET_GDT_ENTRIES);
+ OBJECT(new_cpu)->free = OBJECT(cpu)->free;
+#endif
/* Clone all break/watchpoints.
Note: Once we support ptrace with hw-debug register access, make sure
--
2.39.2
- [PULL 13/28] linux-user: Emulate CLONE_PIDFD flag in clone(), (continued)
- [PULL 13/28] linux-user: Emulate CLONE_PIDFD flag in clone(), Laurent Vivier, 2023/03/08
- [PULL 14/28] linux-user/sparc: Tidy syscall trap, Laurent Vivier, 2023/03/08
- [PULL 17/28] linux-user/sparc: Tidy window spill/fill traps, Laurent Vivier, 2023/03/08
- [PULL 18/28] linux-user/sparc: Fix sparc64_{get, set}_context traps, Laurent Vivier, 2023/03/08
- [PULL 23/28] linux-user/sparc: Handle privilidged action trap, Laurent Vivier, 2023/03/08
- [PULL 15/28] linux-user/sparc: Tidy syscall error return, Laurent Vivier, 2023/03/08
- [PULL 11/28] linux-user: handle netlink flag NLA_F_NESTED, Laurent Vivier, 2023/03/08
- [PULL 10/28] linux-user: fix sockaddr_in6 endianness, Laurent Vivier, 2023/03/08
- [PULL 21/28] linux-user/sparc: Handle getcc, setcc, getpsr traps, Laurent Vivier, 2023/03/08
- [PULL 22/28] linux-user/sparc: Handle priviledged opcode trap, Laurent Vivier, 2023/03/08
- [PULL 28/28] linux-user: fix bug about incorrect base addresss of gdt on i386 and x86_64,
Laurent Vivier <=
- [PULL 12/28] linux-user: Add translation for argument of msync(), Laurent Vivier, 2023/03/08
- [PULL 25/28] linux-user/sparc: Handle unimplemented flush trap, Laurent Vivier, 2023/03/08
- [PULL 24/28] linux-user/sparc: Handle coprocessor disabled trap, Laurent Vivier, 2023/03/08
- [PULL 26/28] linux-user/sparc: Handle floating-point exceptions, Laurent Vivier, 2023/03/08
- [PULL 27/28] linux-user/sparc: Handle tag overflow traps, Laurent Vivier, 2023/03/08
- [PULL 19/28] linux-user/sparc: Handle software breakpoint trap, Laurent Vivier, 2023/03/08
- [PULL 16/28] linux-user/sparc: Use TT_TRAP for flush windows, Laurent Vivier, 2023/03/08
- [PULL 20/28] linux-user/sparc: Handle division by zero traps, Laurent Vivier, 2023/03/08
- Re: [PULL 00/28] Linux user for 8.0 patches, Peter Maydell, 2023/03/10
- [PULL 00/28] Linux user for 8.0 patches, Laurent Vivier, 2023/03/10