From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Philippe Mathieu-Daudé" <philmd@linaro.org>,
qemu-arm@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>,
"Daniel Henrique Barboza" <dbarboza@ventanamicro.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Richard Henderson" <richard.henderson@linaro.org>
Subject: [RFC PATCH 1/2] cpus: Introduce const_cpu_env() and const_env_archcpu()
Date: Fri, 17 Jan 2025 00:04:34 +0100 [thread overview]
Message-ID: <20250116230435.87580-2-philmd@linaro.org> (raw)
In-Reply-To: <20250116230435.87580-1-philmd@linaro.org>
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
next prev parent reply other threads:[~2025-01-16 23:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-16 23:04 [RFC PATCH 0/2] target/arm: Constify helpers taking CPUARMState arg Philippe Mathieu-Daudé
2025-01-16 23:04 ` Philippe Mathieu-Daudé [this message]
2025-01-17 12:39 ` [RFC PATCH 1/2] cpus: Introduce const_cpu_env() and const_env_archcpu() Daniel Henrique Barboza
2025-01-16 23:04 ` [RFC PATCH 2/2] target/arm: Constify lot of helpers taking CPUARMState argument Philippe Mathieu-Daudé
2025-01-17 12:42 ` Daniel Henrique Barboza
2025-01-22 7:07 ` Philippe Mathieu-Daudé
2025-01-17 16:34 ` Philippe Mathieu-Daudé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250116230435.87580-2-philmd@linaro.org \
--to=philmd@linaro.org \
--cc=dbarboza@ventanamicro.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).