From 33589eb75f057f524dc87db6fdb453fb962d0f50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Benn=C3=A9e?= Date: Mon, 26 Feb 2018 04:53:23 -0500 Subject: [PATCH] cpus: pass CPUState to run_on_cpu helpers CPUState is a fairly common pointer to pass to these helpers. This means if you need other arguments for the async_run_on_cpu case you end up having to do a g_malloc to stuff additional data into the routine. For the current users this isn't a massive deal but for MTTCG this gets cumbersome when the only other parameter is often an address. This adds the typedef run_on_cpu_func for helper functions which has an explicit CPUState * passed as the first parameter. All the users of run_on_cpu and async_run_on_cpu have had their helpers updated to use CPUState where available. Backports commit e0eeb4a21a3ca4b296220ce4449d8acef9de9049 from qemu --- qemu/cpus.c | 4 ++-- qemu/include/qom/cpu.h | 6 ++++-- qemu/target-i386/helper.c | 1 - 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/qemu/cpus.c b/qemu/cpus.c index aeb543cd..e1c924bd 100644 --- a/qemu/cpus.c +++ b/qemu/cpus.c @@ -58,9 +58,9 @@ bool cpu_is_stopped(CPUState *cpu) return cpu->stopped; } -void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data) +void run_on_cpu(CPUState *cpu, run_on_cpu_func func, void *data) { - func(data); + func(cpu, data); } int resume_all_vcpus(struct uc_struct *uc) diff --git a/qemu/include/qom/cpu.h b/qemu/include/qom/cpu.h index a099b8fd..124409e0 100644 --- a/qemu/include/qom/cpu.h +++ b/qemu/include/qom/cpu.h @@ -189,6 +189,8 @@ struct kvm_run; #define TB_JMP_CACHE_BITS 12 #define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS) +typedef void (*run_on_cpu_func)(CPUState *cpu, void *data); + // Unicorn: Moved CPUAddressSpace here from exec.c /** * CPUAddressSpace: all the information a CPU needs about an AddressSpace @@ -545,7 +547,7 @@ bool cpu_is_stopped(CPUState *cpu); * * Schedules the function @func for execution on the vCPU @cpu. */ -void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data); +void run_on_cpu(CPUState *cpu, run_on_cpu_func func, void *data); /** * async_run_on_cpu: @@ -555,7 +557,7 @@ void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data); * * Schedules the function @func for execution on the vCPU @cpu asynchronously. */ -void async_run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data); +void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, void *data); /** * qemu_get_cpu: diff --git a/qemu/target-i386/helper.c b/qemu/target-i386/helper.c index 36238d2a..6837c94f 100644 --- a/qemu/target-i386/helper.c +++ b/qemu/target-i386/helper.c @@ -932,7 +932,6 @@ out: } typedef struct MCEInjectionParams { - X86CPU *cpu; int bank; uint64_t status; uint64_t mcg_status;