From 382022929e97e5c5eeebea9e3bab9105e59f1bed Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Sun, 4 Mar 2018 12:16:29 -0500 Subject: [PATCH] cpu: cpu_by_arch_id() helper The helper can be used for CPU object lookup using the CPU's arch-specific ID (the one returned by CPUClass::get_arch_id()). Backports commit 5ce46cb34eecec0bc94a4b1394763f9a1bbe20c3 from qemu --- qemu/include/qom/cpu.h | 10 ++++++++++ qemu/qom/cpu.c | 11 ++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) 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)