Skip to content

Commit 30ba0ee

Browse files
committed
cpu: Move cpu_copy() into linux-user
It is only used there and is deemed very fragile if not incorrect in its current memcpy() form. Moving it into linux-user will allow to move parts into target_cpu.h headers and only copy what the ABI mandates. Signed-off-by: Andreas Färber <[email protected]>
1 parent 8125864 commit 30ba0ee

File tree

2 files changed

+31
-32
lines changed

2 files changed

+31
-32
lines changed

exec.c

-32
Original file line numberDiff line numberDiff line change
@@ -625,38 +625,6 @@ void cpu_abort(CPUArchState *env, const char *fmt, ...)
625625
abort();
626626
}
627627

628-
CPUArchState *cpu_copy(CPUArchState *env)
629-
{
630-
CPUArchState *new_env = cpu_init(env->cpu_model_str);
631-
#if defined(TARGET_HAS_ICE)
632-
CPUBreakpoint *bp;
633-
CPUWatchpoint *wp;
634-
#endif
635-
636-
/* Reset non arch specific state */
637-
cpu_reset(ENV_GET_CPU(new_env));
638-
639-
/* Copy arch specific state into the new CPU */
640-
memcpy(new_env, env, sizeof(CPUArchState));
641-
642-
/* Clone all break/watchpoints.
643-
Note: Once we support ptrace with hw-debug register access, make sure
644-
BP_CPU break/watchpoints are handled correctly on clone. */
645-
QTAILQ_INIT(&env->breakpoints);
646-
QTAILQ_INIT(&env->watchpoints);
647-
#if defined(TARGET_HAS_ICE)
648-
QTAILQ_FOREACH(bp, &env->breakpoints, entry) {
649-
cpu_breakpoint_insert(new_env, bp->pc, bp->flags, NULL);
650-
}
651-
QTAILQ_FOREACH(wp, &env->watchpoints, entry) {
652-
cpu_watchpoint_insert(new_env, wp->vaddr, (~wp->len_mask) + 1,
653-
wp->flags, NULL);
654-
}
655-
#endif
656-
657-
return new_env;
658-
}
659-
660628
#if !defined(CONFIG_USER_ONLY)
661629
static void tlb_reset_dirty_range_all(ram_addr_t start, ram_addr_t end,
662630
uintptr_t length)

linux-user/main.c

+31
Original file line numberDiff line numberDiff line change
@@ -3285,6 +3285,37 @@ void init_task_state(TaskState *ts)
32853285
ts->sigqueue_table[i].next = NULL;
32863286
}
32873287

3288+
CPUArchState *cpu_copy(CPUArchState *env)
3289+
{
3290+
CPUArchState *new_env = cpu_init(env->cpu_model_str);
3291+
#if defined(TARGET_HAS_ICE)
3292+
CPUBreakpoint *bp;
3293+
CPUWatchpoint *wp;
3294+
#endif
3295+
3296+
/* Reset non arch specific state */
3297+
cpu_reset(ENV_GET_CPU(new_env));
3298+
3299+
memcpy(new_env, env, sizeof(CPUArchState));
3300+
3301+
/* Clone all break/watchpoints.
3302+
Note: Once we support ptrace with hw-debug register access, make sure
3303+
BP_CPU break/watchpoints are handled correctly on clone. */
3304+
QTAILQ_INIT(&env->breakpoints);
3305+
QTAILQ_INIT(&env->watchpoints);
3306+
#if defined(TARGET_HAS_ICE)
3307+
QTAILQ_FOREACH(bp, &env->breakpoints, entry) {
3308+
cpu_breakpoint_insert(new_env, bp->pc, bp->flags, NULL);
3309+
}
3310+
QTAILQ_FOREACH(wp, &env->watchpoints, entry) {
3311+
cpu_watchpoint_insert(new_env, wp->vaddr, (~wp->len_mask) + 1,
3312+
wp->flags, NULL);
3313+
}
3314+
#endif
3315+
3316+
return new_env;
3317+
}
3318+
32883319
static void handle_arg_help(const char *arg)
32893320
{
32903321
usage();

0 commit comments

Comments
 (0)