[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 1/2] cpus: Introduce const_cpu_env() and const_env_archcpu()
From: |
Philippe Mathieu-Daudé |
Subject: |
[RFC PATCH 1/2] cpus: Introduce const_cpu_env() and const_env_archcpu() |
Date: |
Fri, 17 Jan 2025 00:04:34 +0100 |
const_cpu_env() is similar to cpu_env() but return a const
CPU 'env' state.
Same for const_env_archcpu() w.r.t. env_archcpu().
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/exec/cpu-common.h | 5 +++++
include/hw/core/cpu.h | 6 ++++++
2 files changed, 11 insertions(+)
diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index b1d76d69850..f765e97a973 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -250,6 +250,11 @@ static inline ArchCPU *env_archcpu(CPUArchState *env)
return (void *)env - sizeof(CPUState);
}
+static inline const ArchCPU *const_env_archcpu(const CPUArchState *env)
+{
+ return (const void *)env - sizeof(CPUState);
+}
+
/**
* env_cpu_const(env)
* @env: The architecture environment
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index c3ca0babcb3..ecb31221b26 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -588,6 +588,12 @@ static inline CPUArchState *cpu_env(CPUState *cpu)
return (CPUArchState *)(cpu + 1);
}
+static inline const CPUArchState *const_cpu_env(const CPUState *cpu)
+{
+ /* We validate that CPUArchState follows CPUState in cpu-all.h. */
+ return (const CPUArchState *)(cpu + 1);
+}
+
typedef QTAILQ_HEAD(CPUTailQ, CPUState) CPUTailQ;
extern CPUTailQ cpus_queue;
--
2.47.1