qemu-devel
[Top][All Lists]
Advanced

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

[PATCH 04/17] bsd-user: Implement cpu_copy()


From: Warner Losh
Subject: [PATCH 04/17] bsd-user: Implement cpu_copy()
Date: Fri, 2 Aug 2024 17:56:04 -0600

From: Stacey Son <sson@FreeBSD.org>

Catch up with 30ba0ee52d15 and implement cpu_copy(). It's needed for
threading. Stacey's original code, with bug fixes from Jessica, Justin
and myself.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Jessica Clarke <jrtc27@jrtc27.com>
Signed-off-by: Justin Hibbits <chmeeedalf@gmail.com>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/main.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/bsd-user/main.c b/bsd-user/main.c
index 1533fd51168..9ad31bd1efe 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -224,6 +224,37 @@ void init_task_state(TaskState *ts)
     };
 }
 
+CPUArchState *cpu_copy(CPUArchState *env)
+{
+    CPUState *cpu = env_cpu(env);
+    CPUState *new_cpu = cpu_create(cpu_type);
+    CPUArchState *new_env = cpu_env(new_cpu);
+    CPUBreakpoint *bp;
+    CPUWatchpoint *wp;
+
+    /* Reset non arch specific state */
+    cpu_reset(new_cpu);
+
+    new_cpu->tcg_cflags = cpu->tcg_cflags;
+    memcpy(new_env, env, sizeof(CPUArchState));
+
+    /*
+     * Clone all break/watchpoints.
+     * Note: Once we support ptrace with hw-debug register access, make sure
+     * BP_CPU break/watchpoints are handled correctly on clone.
+     */
+    QTAILQ_INIT(&cpu->breakpoints);
+    QTAILQ_INIT(&cpu->watchpoints);
+    QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) {
+        cpu_breakpoint_insert(new_cpu, bp->pc, bp->flags, NULL);
+    }
+    QTAILQ_FOREACH(wp, &cpu->watchpoints, entry) {
+        cpu_watchpoint_insert(new_cpu, wp->vaddr, wp->len, wp->flags, NULL);
+    }
+
+    return new_env;
+}
+
 void gemu_log(const char *fmt, ...)
 {
     va_list ap;
-- 
2.45.1




reply via email to

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