diff --git a/qemu/include/qom/cpu.h b/qemu/include/qom/cpu.h index fc19efc2..a5520898 100644 --- a/qemu/include/qom/cpu.h +++ b/qemu/include/qom/cpu.h @@ -606,6 +606,16 @@ CPUState *qemu_get_cpu(struct uc_struct *uc, int index); */ bool cpu_exists(struct uc_struct* uc, int64_t id); +/** + * cpu_by_arch_id: + * @id: Guest-exposed CPU ID of the CPU to obtain. + * + * Get a CPU with matching @id. + * + * Returns: The CPU or %NULL if there is no matching CPU. + */ +CPUState *cpu_by_arch_id(struct uc_struct *uc, int64_t id); + #ifndef CONFIG_USER_ONLY typedef void (*CPUInterruptHandler)(CPUState *, int); diff --git a/qemu/qom/cpu.c b/qemu/qom/cpu.c index 265be07c..585df6cb 100644 --- a/qemu/qom/cpu.c +++ b/qemu/qom/cpu.c @@ -24,15 +24,20 @@ #include "qemu/log.h" #include "uc_priv.h" -bool cpu_exists(struct uc_struct* uc, int64_t id) +CPUState *cpu_by_arch_id(struct uc_struct *uc, int64_t id) { CPUState *cpu = uc->cpu; CPUClass *cc = CPU_GET_CLASS(uc, cpu); if (cc->get_arch_id(cpu) == id) { - return true; + return cpu; } - return false; + return NULL; +} + +bool cpu_exists(struct uc_struct *uc, int64_t id) +{ + return !!cpu_by_arch_id(uc, id); } CPUState *cpu_generic_init(struct uc_struct *uc, const char *typename, const char *cpu_model)