diff --git a/qemu/target/i386/cpu.c b/qemu/target/i386/cpu.c index 469b1b0a..b3dab8a4 100644 --- a/qemu/target/i386/cpu.c +++ b/qemu/target/i386/cpu.c @@ -4776,27 +4776,29 @@ static void x86_cpu_common_class_init(struct uc_struct *uc, CPUClass *oc, void * cc->tlb_fill = x86_cpu_tlb_fill; } -X86CPU *cpu_x86_init(struct uc_struct *uc, const char *cpu_model) +X86CPU *cpu_x86_init(struct uc_struct *uc) { - int i; X86CPU *cpu; CPUState *cs; CPUClass *cc; X86CPUClass *xcc; - if (cpu_model == NULL) { -#ifdef TARGET_X86_64 - cpu_model = "qemu64"; -#else - cpu_model = "qemu32"; -#endif - } - cpu = calloc(1, sizeof(*cpu)); if (cpu == NULL) { return NULL; } + if (uc->cpu_model == INT_MAX) { +#ifdef TARGET_X86_64 + uc->cpu_model = 0; // qemu64 +#else + uc->cpu_model = 4; // qemu32 +#endif + } else if (uc->cpu_model >= ARRAY_SIZE(builtin_x86_defs)) { + free(cpu); + return NULL; + } + cs = (CPUState *)cpu; cc = (CPUClass *)&cpu->cc; cs->cc = cc; @@ -4822,12 +4824,7 @@ X86CPU *cpu_x86_init(struct uc_struct *uc, const char *cpu_model) } xcc->model->version = CPU_VERSION_AUTO; - for (i = 0; i < ARRAY_SIZE(builtin_x86_defs); i++) { - if (strcmp(cpu_model, builtin_x86_defs[i].name) == 0) { - xcc->model->cpudef = &builtin_x86_defs[i]; - break; - } - } + xcc->model->cpudef = &builtin_x86_defs[uc->cpu_model]; if (xcc->model->cpudef == NULL) { free(xcc->model); diff --git a/qemu/target/i386/cpu.h b/qemu/target/i386/cpu.h index 2d78d756..b16ebd29 100644 --- a/qemu/target/i386/cpu.h +++ b/qemu/target/i386/cpu.h @@ -2129,6 +2129,6 @@ void x86_cpu_xsave_all_areas(X86CPU *cpu, X86XSaveArea *buf); void x86_update_hflags(CPUX86State* env); int uc_check_cpu_x86_load_seg(CPUX86State *env, int seg_reg, int sel); -X86CPU *cpu_x86_init(struct uc_struct *uc, const char *cpu_model); +X86CPU *cpu_x86_init(struct uc_struct *uc); #endif /* I386_CPU_H */ diff --git a/qemu/target/i386/unicorn.c b/qemu/target/i386/unicorn.c index e7534ec1..d6d74d92 100644 --- a/qemu/target/i386/unicorn.c +++ b/qemu/target/i386/unicorn.c @@ -1596,7 +1596,7 @@ static int x86_cpus_init(struct uc_struct *uc, const char *cpu_model) X86CPU *cpu; - cpu = cpu_x86_init(uc, cpu_model); + cpu = cpu_x86_init(uc); if (cpu == NULL) { return -1; }