qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] linux-user: fix bug about incorrect base addresss of gdt on


From: Laurent Vivier
Subject: Re: [PATCH] linux-user: fix bug about incorrect base addresss of gdt on i386 and x86_64
Date: Tue, 7 Mar 2023 19:45:56 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0

Le 08/02/2023 à 16:49, fanwj@mail.ustc.edu.cn a écrit :
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>
---
  linux-user/i386/cpu_loop.c | 9 +++++++++
  linux-user/main.c          | 7 +++++++
  2 files changed, 16 insertions(+)

diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c
index 865413c..48511cd 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 a17fed0..3acd9b4 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -234,6 +234,13 @@ 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((void*)g2h_untagged(new_env->gdt.base), 
(void*)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

Applied to my linux-user-for-8.0 branch.

Thanks,
Laurent




reply via email to

[Prev in Thread] Current Thread [Next in Thread]