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
This commit is contained in:
Eduardo Habkost 2018-03-04 12:16:29 -05:00 committed by Lioncash
parent 75afdffa45
commit 382022929e
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
2 changed files with 18 additions and 3 deletions

View file

@ -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);

View file

@ -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)