summary refs log tree commit diff stats
path: root/linux-user/main.c
diff options
context:
space:
mode:
authorfanwj@mail.ustc.edu.cn <fanwj@mail.ustc.edu.cn>2023-02-08 23:49:12 +0800
committerLaurent Vivier <laurent@vivier.eu>2023-03-10 20:50:11 +0100
commit2732c739d846fc7a1972e984d71a3de0d3eef77b (patch)
tree4e8e5b28b84e36479583e41b8ca0cecc07ae4533 /linux-user/main.c
parente64c6d42b652b4acf10d83e1bc86d4fd4ce28ef2 (diff)
downloadfocaccia-qemu-2732c739d846fc7a1972e984d71a3de0d3eef77b.tar.gz
focaccia-qemu-2732c739d846fc7a1972e984d71a3de0d3eef77b.zip
linux-user: fix bug about incorrect base addresss of gdt on i386 and x86_64
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>
Diffstat (limited to 'linux-user/main.c')
-rw-r--r--linux-user/main.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/linux-user/main.c b/linux-user/main.c
index 798fdc0bce..47b0c0fc43 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