]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
cpu: Constify CPUState::cc (cached CPUClass pointer)
authorPhilippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Sat, 27 Jun 2026 16:05:43 +0000 (18:05 +0200)
committerPhilippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Mon, 6 Jul 2026 12:57:00 +0000 (14:57 +0200)
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>

accel/tcg/cpu-exec.c
accel/tcg/translate-all.c
gdbstub/gdbstub.c
include/hw/core/cpu.h

index 9c754b036566c9de622bc0daf7183a4577ce55fd..d7f91dce9db5ab11ae56f690124850ec7e52bc63 100644 (file)
@@ -460,7 +460,7 @@ cpu_tb_exec(CPUState *cpu, TranslationBlock *itb, int *tb_exit)
          * counter hit zero); we must restore the guest PC to the address
          * of the start of the TB.
          */
-        CPUClass *cc = cpu->cc;
+        const CPUClass *cc = cpu->cc;
         const TCGCPUOps *tcg_ops = cc->tcg_ops;
 
         if (tcg_ops->synchronize_from_tb) {
index 3f1a3a28438ba220a8bfc82adc096d23098d064f..328d96aba306a50309ba94f65a8db3527d83b26f 100644 (file)
@@ -575,7 +575,7 @@ void tb_check_watchpoint(CPUState *cpu, uintptr_t retaddr)
 void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr)
 {
     TranslationBlock *tb;
-    CPUClass *cc;
+    const CPUClass *cc = cpu->cc;
     uint32_t n;
 
     tb = tcg_tb_lookup(retaddr);
@@ -591,7 +591,6 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr)
      * to account for the re-execution of the branch.
      */
     n = 1;
-    cc = cpu->cc;
     if (cc->tcg_ops->io_recompile_replay_branch &&
         cc->tcg_ops->io_recompile_replay_branch(cpu, tb)) {
         cpu->neg.icount_decr.u16.low++;
index c3c944e965b9cc7dac0107ee133817a2bab79896..26366acb674a37b1eda11b5acff3c1ee2017c93a 100644 (file)
@@ -578,7 +578,7 @@ static void gdb_register_feature(CPUState *cpu, int base_reg,
 
 static const char *gdb_get_core_xml_file(CPUState *cpu)
 {
-    CPUClass *cc = cpu->cc;
+    const CPUClass *cc = cpu->cc;
 
     /*
      * The CPU class can provide the XML filename via a method,
index 59d601465b4c6944b7b105d2be7d2e435152fe92..60a23d6f38bf24307c4b15e470019f689d7243e4 100644 (file)
@@ -480,7 +480,7 @@ struct CPUState {
     /*< private >*/
     DeviceState parent_obj;
     /* cache to avoid expensive CPU_GET_CLASS */
-    CPUClass *cc;
+    const CPUClass *cc;
     /*< public >*/
 
     int nr_threads;