cpu: Constify CPUState::cc (cached CPUClass pointer)
Various CPUState can share the same CPUClass parent, and must not update its fields. Protect the CPUClass by marking the CPUState pointer const. Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Reviewed-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com> Message-ID: <20260705215729.62196-2-philmd@oss.qualcomm.com>
Philippe Mathieu-Daudé committed
Jun 27, 2026 at 18:05 UTC
65339110b74b80757a209b78a9af1a3550737fed
4 files changed
+4
-5
accel/tcg/cpu-exec.c
+1
-1
@@ -460,7 +460,7 @@ cpu_tb_exec(CPUState *cpu, TranslationBlock *itb, int *tb_exit)
460
* counter hit zero); we must restore the guest PC to the address
461
* of the start of the TB.
462
*/
463
- CPUClass *cc = cpu->cc;
463
+ const CPUClass *cc = cpu->cc;
464
const TCGCPUOps *tcg_ops = cc->tcg_ops;
465
466
if (tcg_ops->synchronize_from_tb) {
accel/tcg/translate-all.c
+1
-2
@@ -575,7 +575,7 @@ void tb_check_watchpoint(CPUState *cpu, uintptr_t retaddr)
575
void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr)
576
{
577
TranslationBlock *tb;
578
- CPUClass *cc;
578
+ const CPUClass *cc = cpu->cc;
579
uint32_t n;
580
581
tb = tcg_tb_lookup(retaddr);
@@ -591,7 +591,6 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr)
591
* to account for the re-execution of the branch.
592
*/
593
n = 1;
594
- cc = cpu->cc;
594
if (cc->tcg_ops->io_recompile_replay_branch &&
595
cc->tcg_ops->io_recompile_replay_branch(cpu, tb)) {
596
cpu->neg.icount_decr.u16.low++;
gdbstub/gdbstub.c
+1
-1
@@ -578,7 +578,7 @@ static void gdb_register_feature(CPUState *cpu, int base_reg,
578
579
static const char *gdb_get_core_xml_file(CPUState *cpu)
580
{
581
- CPUClass *cc = cpu->cc;
581
+ const CPUClass *cc = cpu->cc;
582
583
/*
584
* The CPU class can provide the XML filename via a method,
include/hw/core/cpu.h
+1
-1
@@ -480,7 +480,7 @@ struct CPUState {
480
/*< private >*/
481
DeviceState parent_obj;
482
/* cache to avoid expensive CPU_GET_CLASS */
483
- CPUClass *cc;
483
+ const CPUClass *cc;
484
/*< public >*/
485
486
int nr_threads;