From gbeauchesne@mandriva.com Tue Mar 13 17:01:17 2007 Date: Tue, 20 Feb 2007 01:44:37 +0100 (CET) From: Gwenole Beauchesne Reply-To: qemu-devel@nongnu.org To: qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH] Fix CPU chaining in linux-user emulation Hi, This patch fixes chaining of CPU instances. It was simply trashed with the memcpy() thus causing problems in threaded programs (N > 2): an infinite loop in next cpu_init(). ================================================================================ --- qemu-0.9.0/cpu-all.h +++ qemu-0.9.0/cpu-all.h @@ -760,6 +760,8 @@ #endif /* SINGLE_CPU_DEFINES */ +CPUState *cpu_copy(CPUState *env); + void cpu_dump_state(CPUState *env, FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...), int flags); --- qemu-0.9.0/exec.c +++ qemu-0.9.0/exec.c @@ -1221,6 +1221,18 @@ abort(); } +CPUState *cpu_copy(CPUState *env) +{ + CPUState *new_env = cpu_init(); + /* preserve chaining and index */ + CPUState *next_cpu = new_env->next_cpu; + int cpu_index = new_env->cpu_index; + memcpy(new_env, env, sizeof(CPUState)); + new_env->next_cpu = next_cpu; + new_env->cpu_index = cpu_index; + return new_env; +} + #if !defined(CONFIG_USER_ONLY) /* NOTE: if flush_global is true, also flush global entries (not