diff mbox series

[1/5] include/exec: Introduce env_cpu_const()

Message ID 20240802095942.34565-2-iii@linux.ibm.com (mailing list archive)
State New, archived
Headers show
Series linux-user/i386: Emulate orig_ax | expand

Commit Message

Ilya Leoshkevich Aug. 2, 2024, 9:59 a.m. UTC
It's the same as env_cpu(), but for const objects.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 include/exec/cpu-common.h | 13 ++++++++++++-
 linux-user/elfload.c      |  2 +-
 2 files changed, 13 insertions(+), 2 deletions(-)

Comments

Richard Henderson Sept. 8, 2024, 7:46 p.m. UTC | #1
On 8/2/24 02:59, Ilya Leoshkevich wrote:
> It's the same as env_cpu(), but for const objects.
> 
> Signed-off-by: Ilya Leoshkevich<iii@linux.ibm.com>
> ---
>   include/exec/cpu-common.h | 13 ++++++++++++-
>   linux-user/elfload.c      |  2 +-
>   2 files changed, 13 insertions(+), 2 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~
diff mbox series

Patch

diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index 2e1b499cb71..638dc806a5f 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -238,6 +238,17 @@  static inline ArchCPU *env_archcpu(CPUArchState *env)
     return (void *)env - sizeof(CPUState);
 }
 
+/**
+ * env_cpu_const(env)
+ * @env: The architecture environment
+ *
+ * Return the CPUState associated with the environment.
+ */
+static inline const CPUState *env_cpu_const(const CPUArchState *env)
+{
+    return (void *)env - sizeof(CPUState);
+}
+
 /**
  * env_cpu(env)
  * @env: The architecture environment
@@ -246,7 +257,7 @@  static inline ArchCPU *env_archcpu(CPUArchState *env)
  */
 static inline CPUState *env_cpu(CPUArchState *env)
 {
-    return (void *)env - sizeof(CPUState);
+    return (CPUState *)env_cpu_const(env);
 }
 
 #ifndef CONFIG_USER_ONLY
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 0861f115fc4..05292c27776 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -4329,7 +4329,7 @@  static int wmr_write_region(void *opaque, target_ulong start,
  */
 static int elf_core_dump(int signr, const CPUArchState *env)
 {
-    const CPUState *cpu = env_cpu((CPUArchState *)env);
+    const CPUState *cpu = env_cpu_const(env);
     const TaskState *ts = (const TaskState *)get_task_state((CPUState *)cpu);
     struct rlimit dumpsize;
     CountAndSizeRegions css;