Skip to contentSkip to conversation

user-mode: Rename CPUState::opaque as CPUState::task_state

PATCH In review Philippe Mathieu-Daudé 2 participants 6 messages Mar 4, 2021 RISC-V

lore
Share & tools
lore
#0 lore raw

cover user-mode: Rename CPUState::opaque as CPUState::task_state

Yet another series trying to clarify CPUState fields. Here we change 'void *opaque' by 'TaskState *task_state' to remove confusion regarding when this 'opaque' field can be used.

Philippe Mathieu-Daudé (3):
user-mode: Use QEMU_ALIGNED() on TaskState structure
cpu: Forward-declare user-mode TaskState structure
user-mode: Rename CPUState::opaque as CPUState::task_state

 bsd-user/qemu.h                  |  4 ++--
 include/hw/core/cpu.h            |  7 ++++--
 linux-user/m68k/target_cpu.h     |  3 +--
 linux-user/qemu.h                |  6 ++---
 bsd-user/main.c                  |  2 +-
 gdbstub.c                        | 13 ++++------
 hw/semihosting/arm-compat-semi.c | 12 ++++------
 linux-user/aarch64/cpu_loop.c    |  2 +-
 linux-user/arm/cpu_loop.c        |  4 ++--
 linux-user/arm/signal.c          |  2 +-
 linux-user/cris/cpu_loop.c       |  3 +--
 linux-user/elfload.c             |  8 +++----
 linux-user/hppa/signal.c         |  3 +--
 linux-user/linuxload.c           |  2 +-
 linux-user/m68k/cpu_loop.c       |  2 +-
 linux-user/main.c                |  2 +-
 linux-user/mips/cpu_loop.c       |  3 +--
 linux-user/ppc/signal.c          |  7 +++---
 linux-user/riscv/cpu_loop.c      |  3 +--
 linux-user/signal.c              | 34 ++++++++++++--------------
 linux-user/syscall.c             | 41 +++++++++++++-------------------
 linux-user/vm86.c                | 19 +++++++--------
 target/m68k/m68k-semi.c          |  2 +-
 23 files changed, 80 insertions(+), 104 deletions(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/3 user-mode: Use QEMU_ALIGNED() on TaskState structure

The rest of the codebase uses the QEMU_ALIGNED() introduced in commit 911a4d2215b ("compiler.h: add QEMU_ALIGNED() to enforce struct alignment"). Use it for the TaskState structure too.

---
 bsd-user/qemu.h   | 2 +-
 linux-user/qemu.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
bsd-user/qemu.h +1 -1
index d2bcaab7413..1ec14010216 100644
@@ -96,7 +96,7 @@ typedef struct TaskState {
     int signal_pending; /* non zero if a signal may be pending */
 
     uint8_t stack[];
-} __attribute__((aligned(16))) TaskState;
+} QEMU_ALIGNED(16) TaskState;
 
 void init_task_state(TaskState *ts);
 extern const char *qemu_uname_release;
linux-user/qemu.h +1 -1
index 52c981710b4..d7815bfb845 100644
@@ -157,7 +157,7 @@ typedef struct TaskState {
 
     /* This thread's sigaltstack, if it has one */
     struct target_sigaltstack sigaltstack_used;
-} __attribute__((aligned(16))) TaskState;
+} QEMU_ALIGNED(16) TaskState;
 
 extern char *exec_path;
 void init_task_state(TaskState *ts);
Signature · 1 line
2.26.2
#2 lore raw

Re: [PATCH 1/3] user-mode: Use QEMU_ALIGNED() on TaskState structure

Quoted 29 lines · Philippe Mathieu-Daudé

The rest of the codebase uses the QEMU_ALIGNED() introduced in commit 911a4d2215b ("compiler.h: add QEMU_ALIGNED() to enforce struct alignment"). Use it for the TaskState structure too.

---
 bsd-user/qemu.h   | 2 +-
 linux-user/qemu.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
bsd-user/qemu.h +1 -1
index d2bcaab7413..1ec14010216 100644
@@ -96,7 +96,7 @@ typedef struct TaskState {
     int signal_pending; /* non zero if a signal may be pending */
 
     uint8_t stack[];
-} __attribute__((aligned(16))) TaskState;
+} QEMU_ALIGNED(16) TaskState;
 
 void init_task_state(TaskState *ts);
 extern const char *qemu_uname_release;
linux-user/qemu.h +0 -0
index 52c981710b4..d7815bfb845 100644

linux-user/qemu.h typedef struct TaskState { · line 160

Quoted 5 lines
linux-user/qemu.h +1 -1
@@ -157,7 +157,7 @@ typedef struct TaskState {
 
     /* This thread's sigaltstack, if it has one */
     struct target_sigaltstack sigaltstack_used;
-} __attribute__((aligned(16))) TaskState;
+} QEMU_ALIGNED(16) TaskState;

Does this struct need to be 16-aligned these days? When it was first added in commit 851e67a1b46f in 2003, there was
a justification in a comment (still present in the source today):
/* NOTE: we force a big alignment so that the stack stored after is
aligned too */
because the final field in the struct was "uint8_t stack[0];" But that field was removed in commit 48e15fc2d in 2010 which switched us to allocating the stack and the TaskState separately.

So I think that at least for linux-user the alignment attribute is no longer needed.

bsd-user's struct still has the 'stack' field but as far as I can tell it is never used, so it and the alignment could be deleted there too. (bsd-user is missing the changes that 48e15fc2d makes for linux-user, but less harmfully since it appears not to implement either threads or fork (?!). In any case the plan at the moment is to blow away bsd-user/ entirely so spending much thought on it is wasted effort.)

thanks
-- PMM

#3 lore raw

PATCH 2/3 cpu: Forward-declare user-mode TaskState structure

In reply to Philippe Mathieu-Daudé

The TaskState structure is only used by user emulation. Currently it is hold in CPUState as a void pointer and casted in user-specific code. In order to simplify by
- renaming this generic field
- remove the casts
in the next commit, forward-declare the type in "cpu.h".

---
 bsd-user/qemu.h       | 4 ++--
 include/hw/core/cpu.h | 7 +++++--
 linux-user/qemu.h     | 4 ++--
 3 files changed, 9 insertions(+), 6 deletions(-)
bsd-user/qemu.h +2 -2
index 1ec14010216..00e76ad856e 100644
@@ -83,7 +83,7 @@ struct emulated_sigtable {
 
 /* NOTE: we force a big alignment so that the stack stored after is
    aligned too */
-typedef struct TaskState {
+struct TaskState {
     pid_t ts_tid;     /* tid (or pid) of this task */
 
     struct TaskState *next;
@@ -96,7 +96,7 @@ typedef struct TaskState {
     int signal_pending; /* non zero if a signal may be pending */
 
     uint8_t stack[];
-} QEMU_ALIGNED(16) TaskState;
+} QEMU_ALIGNED(16);
 
 void init_task_state(TaskState *ts);
 extern const char *qemu_uname_release;
include/hw/core/cpu.h +5 -2
index c005d3dc2d8..f4d2169cc8e 100644
@@ -274,6 +274,9 @@ struct qemu_work_item;
 #define CPU_UNSET_NUMA_NODE_ID -1
 #define CPU_TRACE_DSTATE_MAX_EVENTS 32
 
+/* See bsd-user/qemu.h and linux-user/qemu.h */
+typedef struct TaskState TaskState;
+
 /**
  * CPUState:
  * @cpu_index: CPU index (informative).
@@ -310,7 +313,7 @@ struct qemu_work_item;
  * @gdb_num_regs: Number of total registers accessible to GDB.
  * @gdb_num_g_regs: Number of registers in GDB 'g' packets.
  * @next_cpu: Next CPU sharing TB cache.
- * @opaque: User data.
+ * @opaque: User task data.
  * @mem_io_pc: Host Program Counter at which the memory was accessed.
  * @kvm_fd: vCPU file descriptor for KVM.
  * @work_mutex: Lock to prevent multiple access to @work_list.
@@ -386,7 +389,7 @@ struct CPUState {
     QTAILQ_HEAD(, CPUWatchpoint) watchpoints;
     CPUWatchpoint *watchpoint_hit;
 
-    void *opaque;
+    TaskState *opaque;
 
     /* In order to avoid passing too many arguments to the MMIO helpers,
      * we store some rarely used information in the CPU context.
linux-user/qemu.h +2 -2
index d7815bfb845..5394f726892 100644
@@ -100,7 +100,7 @@ struct emulated_sigtable {
 
 /* NOTE: we force a big alignment so that the stack stored after is
    aligned too */
-typedef struct TaskState {
+struct TaskState {
     pid_t ts_tid;     /* tid (or pid) of this task */
 #ifdef TARGET_ARM
 # ifdef TARGET_ABI32
@@ -157,7 +157,7 @@ typedef struct TaskState {
 
     /* This thread's sigaltstack, if it has one */
     struct target_sigaltstack sigaltstack_used;
-} QEMU_ALIGNED(16) TaskState;
+} QEMU_ALIGNED(16);
 
 extern char *exec_path;
 void init_task_state(TaskState *ts);
Signature · 1 line
2.26.2
#4 lore raw

Re: [PATCH 2/3] cpu: Forward-declare user-mode TaskState structure

Quoted 38 lines · Philippe Mathieu-Daudé

The TaskState structure is only used by user emulation. Currently it is hold in CPUState as a void pointer and casted in user-specific code. In order to simplify by
- renaming this generic field
- remove the casts
in the next commit, forward-declare the type in "cpu.h".

---
 bsd-user/qemu.h       | 4 ++--
 include/hw/core/cpu.h | 7 +++++--
 linux-user/qemu.h     | 4 ++--
 3 files changed, 9 insertions(+), 6 deletions(-)
include/hw/core/cpu.h +4 -1
index c005d3dc2d8..f4d2169cc8e 100644
@@ -274,6 +274,9 @@ struct qemu_work_item;
 #define CPU_UNSET_NUMA_NODE_ID -1
 #define CPU_TRACE_DSTATE_MAX_EVENTS 32
 
+/* See bsd-user/qemu.h and linux-user/qemu.h */
+typedef struct TaskState TaskState;
+
 /**
  * CPUState:
  * @cpu_index: CPU index (informative).
@@ -310,7 +313,7 @@ struct qemu_work_item;
  * @gdb_num_regs: Number of total registers accessible to GDB.
  * @gdb_num_g_regs: Number of registers in GDB 'g' packets.
  * @next_cpu: Next CPU sharing TB cache.
- * @opaque: User data.
+ * @opaque: User task data.
  * @mem_io_pc: Host Program Counter at which the memory was accessed.
  * @kvm_fd: vCPU file descriptor for KVM.
  * @work_mutex: Lock to prevent multiple access to @work_list.

include/hw/core/cpu.h struct CPUState { · line 392

Quoted 5 lines
include/hw/core/cpu.h +1 -1
@@ -386,7 +389,7 @@ struct CPUState {
     QTAILQ_HEAD(, CPUWatchpoint) watchpoints;
     CPUWatchpoint *watchpoint_hit;
 
-    void *opaque;
+    TaskState *opaque;

FYI Paolo said on IRC:

"having multiple definition of the same type is not very good taste, void* or union are both better".

#5 lore raw

PATCH 3/3 user-mode: Rename CPUState::opaque as CPUState::task_state

In reply to Philippe Mathieu-Daudé

While the CPUState 'opaque' field sounds generic, it is meant for user-mode emulation. Rename it as 'task_state' (the "task" concept is only meaningful in user-mode) to clarify this field use. Remove various cast while renaming.

---
 include/hw/core/cpu.h            |  4 ++--
 linux-user/m68k/target_cpu.h     |  3 +--
 linux-user/qemu.h                |  2 +-
 bsd-user/main.c                  |  2 +-
 gdbstub.c                        | 13 ++++------
 hw/semihosting/arm-compat-semi.c | 12 ++++------
 linux-user/aarch64/cpu_loop.c    |  2 +-
 linux-user/arm/cpu_loop.c        |  4 ++--
 linux-user/arm/signal.c          |  2 +-
 linux-user/cris/cpu_loop.c       |  3 +--
 linux-user/elfload.c             |  8 +++----
 linux-user/hppa/signal.c         |  3 +--
 linux-user/linuxload.c           |  2 +-
 linux-user/m68k/cpu_loop.c       |  2 +-
 linux-user/main.c                |  2 +-
 linux-user/mips/cpu_loop.c       |  3 +--
 linux-user/ppc/signal.c          |  7 +++---
 linux-user/riscv/cpu_loop.c      |  3 +--
 linux-user/signal.c              | 34 ++++++++++++--------------
 linux-user/syscall.c             | 41 +++++++++++++-------------------
 linux-user/vm86.c                | 19 +++++++--------
 target/m68k/m68k-semi.c          |  2 +-
 22 files changed, 73 insertions(+), 100 deletions(-)
include/hw/core/cpu.h +2 -2
index f4d2169cc8e..c373618f2e9 100644
@@ -313,7 +313,7 @@ typedef struct TaskState TaskState;
  * @gdb_num_regs: Number of total registers accessible to GDB.
  * @gdb_num_g_regs: Number of registers in GDB 'g' packets.
  * @next_cpu: Next CPU sharing TB cache.
- * @opaque: User task data.
+ * @task_state: User task data.
  * @mem_io_pc: Host Program Counter at which the memory was accessed.
  * @kvm_fd: vCPU file descriptor for KVM.
  * @work_mutex: Lock to prevent multiple access to @work_list.
@@ -389,7 +389,7 @@ struct CPUState {
     QTAILQ_HEAD(, CPUWatchpoint) watchpoints;
     CPUWatchpoint *watchpoint_hit;
 
-    TaskState *opaque;
+    TaskState *task_state;
 
     /* In order to avoid passing too many arguments to the MMIO helpers,
      * we store some rarely used information in the CPU context.
linux-user/m68k/target_cpu.h +1 -2
index c3f288dfe83..bb252f90ba7 100644
@@ -37,9 +37,8 @@ static inline void cpu_clone_regs_parent(CPUM68KState *env, unsigned flags)
 static inline void cpu_set_tls(CPUM68KState *env, target_ulong newtls)
 {
     CPUState *cs = env_cpu(env);
-    TaskState *ts = cs->opaque;
 
-    ts->tp_value = newtls;
+    cs->task_state->tp_value = newtls;
 }
 
 static inline abi_ulong get_sp_from_cpustate(CPUM68KState *state)
linux-user/qemu.h +1 -1
index 5394f726892..59949676c6a 100644
@@ -381,7 +381,7 @@ extern long safe_syscall_base(int *pending, long number, ...);
 #define safe_syscall(...)                                               \
     ({                                                                  \
         long ret_;                                                      \
-        int *psp_ = &((TaskState *)thread_cpu->opaque)->signal_pending; \
+        int *psp_ = &thread_cpu->task_state->signal_pending; \
         ret_ = safe_syscall_base(psp_, __VA_ARGS__);                    \
         if (is_error(ret_)) {                                           \
             errno = -ret_;                                              \
bsd-user/main.c +1 -1
index 798aba512c1..625d440ab31 100644
@@ -1000,7 +1000,7 @@ int main(int argc, char **argv)
     memset(ts, 0, sizeof(TaskState));
     init_task_state(ts);
     ts->info = info;
-    cpu->opaque = ts;
+    cpu->task_state = ts;
 
 #if defined(TARGET_I386)
     env->cr[0] = CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK;
gdbstub.c +5 -8
index 3ee40479b69..406241ee3fa 100644
@@ -94,8 +94,7 @@ static inline int target_memory_rw_debug(CPUState *cpu, target_ulong addr,
 static inline int cpu_gdb_index(CPUState *cpu)
 {
 #if defined(CONFIG_USER_ONLY)
-    TaskState *ts = (TaskState *) cpu->opaque;
-    return ts->ts_tid;
+    return cpu->task_state->ts_tid;
 #else
     return cpu->cpu_index + 1;
 #endif
@@ -2121,7 +2120,7 @@ static void handle_query_offsets(GdbCmdContext *gdb_ctx, void *user_ctx)
 {
     TaskState *ts;
 
-    ts = gdbserver_state.c_cpu->opaque;
+    ts = gdbserver_state.c_cpu->task_state;
     g_string_printf(gdbserver_state.str_buf,
                     "Text=" TARGET_ABI_FMT_lx
                     ";Data=" TARGET_ABI_FMT_lx
@@ -2174,7 +2173,7 @@ static void handle_query_supported(GdbCmdContext *gdb_ctx, void *user_ctx)
     }
 
 #ifdef CONFIG_USER_ONLY
-    if (gdbserver_state.c_cpu->opaque) {
+    if (gdbserver_state.c_cpu->task_state) {
         g_string_append(gdbserver_state.str_buf, ";qXfer:auxv:read+");
     }
 #endif
@@ -2243,7 +2242,6 @@ static void handle_query_xfer_features(GdbCmdContext *gdb_ctx, void *user_ctx)
 #if defined(CONFIG_USER_ONLY) && defined(CONFIG_LINUX_USER)
 static void handle_query_xfer_auxv(GdbCmdContext *gdb_ctx, void *user_ctx)
 {
-    TaskState *ts;
     unsigned long offset, len, saved_auxv, auxv_len;
 
     if (gdb_ctx->num_params < 2) {
@@ -2253,9 +2251,8 @@ static void handle_query_xfer_auxv(GdbCmdContext *gdb_ctx, void *user_ctx)
 
     offset = gdb_ctx->params[0].val_ul;
     len = gdb_ctx->params[1].val_ul;
-    ts = gdbserver_state.c_cpu->opaque;
-    saved_auxv = ts->info->saved_auxv;
-    auxv_len = ts->info->auxv_len;
+    saved_auxv = gdbserver_state.c_cpu->task_state->info->saved_auxv;
+    auxv_len = gdbserver_state.c_cpu->task_state->info->auxv_len;
 
     if (offset >= auxv_len) {
         put_packet("E00");
hw/semihosting/arm-compat-semi.c +4 -8
index 23c6e3edcb6..5e5724d18fb 100644
@@ -375,9 +375,7 @@ static inline uint32_t set_swi_errno(CPUState *cs, uint32_t code)
 {
     if (code == (uint32_t)-1) {
 #ifdef CONFIG_USER_ONLY
-        TaskState *ts = cs->opaque;
-
-        ts->swi_errno = errno;
+        cs->task_state->swi_errno = errno;
 #else
         syscall_err = errno;
 #endif
@@ -388,9 +386,7 @@ static inline uint32_t set_swi_errno(CPUState *cs, uint32_t code)
 static inline uint32_t get_swi_errno(CPUState *cs)
 {
 #ifdef CONFIG_USER_ONLY
-    TaskState *ts = cs->opaque;
-
-    return ts->swi_errno;
+    return cs->task_state->swi_errno;
 #else
     return syscall_err;
 #endif
@@ -1107,7 +1103,7 @@ target_ulong do_common_semihosting(CPUState *cs)
 #if !defined(CONFIG_USER_ONLY)
             const char *cmdline;
 #else
-            TaskState *ts = cs->opaque;
+            TaskState *ts = cs->task_state;
 #endif
             GET_ARG(0);
             GET_ARG(1);
@@ -1188,7 +1184,7 @@ target_ulong do_common_semihosting(CPUState *cs)
             target_ulong limit;
             int i;
 #ifdef CONFIG_USER_ONLY
-            TaskState *ts = cs->opaque;
+            TaskState *ts = cs->task_state;
 #else
             target_ulong rambase = common_semi_rambase(cs);
 #endif
linux-user/aarch64/cpu_loop.c +1 -1
index 7c42f657068..e8e2f17b34b 100644
@@ -187,7 +187,7 @@ void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)
 {
     ARMCPU *cpu = env_archcpu(env);
     CPUState *cs = env_cpu(env);
-    TaskState *ts = cs->opaque;
+    TaskState *ts = cs->task_state;
     struct image_info *info = ts->info;
     int i;
 
linux-user/arm/cpu_loop.c +2 -2
index cadfb7fa439..a1c1d7e20eb 100644
@@ -244,7 +244,7 @@ void cpu_loop(CPUARMState *env)
         case EXCP_NOCP:
         case EXCP_INVSTATE:
             {
-                TaskState *ts = cs->opaque;
+                TaskState *ts = cs->task_state;
                 uint32_t opcode;
                 int rc;
 
@@ -470,7 +470,7 @@ void cpu_loop(CPUARMState *env)
 void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)
 {
     CPUState *cpu = env_cpu(env);
-    TaskState *ts = cpu->opaque;
+    TaskState *ts = cpu->task_state;
     struct image_info *info = ts->info;
     int i;
 
linux-user/arm/signal.c +1 -1
index f21d1535e4d..fe20add8029 100644
@@ -214,7 +214,7 @@ setup_return(CPUARMState *env, struct target_sigaction *ka,
     abi_ulong retcode;
 
     int thumb;
-    int is_fdpic = info_is_fdpic(((TaskState *)thread_cpu->opaque)->info);
+    int is_fdpic = info_is_fdpic(thread_cpu->task_state->info);
 
     if (is_fdpic) {
         /* In FDPIC mode, ka->_sa_handler points to a function
linux-user/cris/cpu_loop.c +1 -2
index 334edddd1e2..2c9081360de 100644
@@ -85,8 +85,7 @@ void cpu_loop(CPUCRISState *env)
 void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)
 {
     CPUState *cpu = env_cpu(env);
-    TaskState *ts = cpu->opaque;
-    struct image_info *info = ts->info;
+    struct image_info *info = cpu->task_state->info;
 
     env->regs[0] = regs->r0;
     env->regs[1] = regs->r1;
linux-user/elfload.c +3 -5
index bab4237e90f..1984226e0db 100644
@@ -3805,12 +3805,11 @@ static int write_note(struct memelfnote *men, int fd)
 static void fill_thread_info(struct elf_note_info *info, const CPUArchState *env)
 {
     CPUState *cpu = env_cpu((CPUArchState *)env);
-    TaskState *ts = (TaskState *)cpu->opaque;
     struct elf_thread_status *ets;
 
     ets = g_malloc0(sizeof (*ets));
     ets->num_notes = 1; /* only prstatus is dumped */
-    fill_prstatus(&ets->prstatus, ts, 0);
+    fill_prstatus(&ets->prstatus, cpu->task_state, 0);
     elf_core_copy_regs(&ets->prstatus.pr_reg, env);
     fill_note(&ets->notes[0], "CORE", NT_PRSTATUS, sizeof (ets->prstatus),
               &ets->prstatus);
@@ -3835,7 +3834,7 @@ static int fill_note_info(struct elf_note_info *info,
 {
 #define NUMNOTES 3
     CPUState *cpu = env_cpu((CPUArchState *)env);
-    TaskState *ts = (TaskState *)cpu->opaque;
+    TaskState *ts = cpu->task_state;
     int i;
 
     info->notes = g_new0(struct memelfnote, NUMNOTES);
@@ -3959,7 +3958,6 @@ static int write_note_info(struct elf_note_info *info, int fd)
 static int elf_core_dump(int signr, const CPUArchState *env)
 {
     const CPUState *cpu = env_cpu((CPUArchState *)env);
-    const TaskState *ts = (const TaskState *)cpu->opaque;
     struct vm_area_struct *vma = NULL;
     char corefile[PATH_MAX];
     struct elf_note_info info;
@@ -3978,7 +3976,7 @@ static int elf_core_dump(int signr, const CPUArchState *env)
     if (dumpsize.rlim_cur == 0)
         return 0;
 
-    if (core_dump_filename(ts, corefile, sizeof (corefile)) < 0)
+    if (core_dump_filename(cpu->task_state, corefile, sizeof(corefile)) < 0)
         return (-errno);
 
     if ((fd = open(corefile, O_WRONLY | O_CREAT,
linux-user/hppa/signal.c +1 -2
index d1a58feeb36..76b68e817bc 100644
@@ -111,11 +111,10 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
     abi_ulong frame_addr, sp, haddr;
     struct target_rt_sigframe *frame;
     int i;
-    TaskState *ts = (TaskState *)thread_cpu->opaque;
 
     sp = get_sp_from_cpustate(env);
     if ((ka->sa_flags & TARGET_SA_ONSTACK) && !sas_ss_flags(sp)) {
-        sp = (ts->sigaltstack_used.ss_sp + 0x7f) & ~0x3f;
+        sp = (thread_cpu->task_state->sigaltstack_used.ss_sp + 0x7f) & ~0x3f;
     }
     frame_addr = QEMU_ALIGN_UP(sp, 64);
     sp = frame_addr + PARISC_RT_SIGFRAME_SIZE32;
linux-user/linuxload.c +1 -1
index a27e1d0d8bc..263bf6aed73 100644
@@ -83,7 +83,7 @@ static int prepare_binprm(struct linux_binprm *bprm)
 abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,
                               abi_ulong stringp, int push_ptr)
 {
-    TaskState *ts = (TaskState *)thread_cpu->opaque;
+    TaskState *ts = thread_cpu->task_state;
     int n = sizeof(abi_ulong);
     abi_ulong envp;
     abi_ulong argv;
linux-user/m68k/cpu_loop.c +1 -1
index c7a500b58c4..74674562fa6 100644
@@ -118,7 +118,7 @@ void cpu_loop(CPUM68KState *env)
 void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)
 {
     CPUState *cpu = env_cpu(env);
-    TaskState *ts = cpu->opaque;
+    TaskState *ts = cpu->task_state;
     struct image_info *info = ts->info;
 
     env->pc = regs->pc;
linux-user/main.c +1 -1
index 81f48ff54ed..53542df7556 100644
@@ -807,7 +807,7 @@ int main(int argc, char **argv, char **envp)
     /* build Task State */
     ts->info = info;
     ts->bprm = &bprm;
-    cpu->opaque = ts;
+    cpu->task_state = ts;
     task_settid(ts);
 
     ret = loader_exec(execfd, exec_path, target_argv, target_environ, regs,
linux-user/mips/cpu_loop.c +1 -2
index 9d813ece4e7..932b77e4023 100644
@@ -322,8 +322,7 @@ error:
 void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)
 {
     CPUState *cpu = env_cpu(env);
-    TaskState *ts = cpu->opaque;
-    struct image_info *info = ts->info;
+    struct image_info *info = cpu->task_state->info;
     int i;
 
     struct mode_req {
linux-user/ppc/signal.c +3 -4
index b78613f7c86..4474981a2fb 100644
@@ -491,7 +491,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
 #if defined(TARGET_PPC64)
     struct target_sigcontext *sc = 0;
 #if !defined(TARGET_ABI32)
-    struct image_info *image = ((TaskState *)thread_cpu->opaque)->info;
+    struct image_info *image = thread_cpu->task_state->info;
 #endif
 #endif
 
@@ -684,8 +684,6 @@ abi_long do_swapcontext(CPUArchState *env, abi_ulong uold_ctx,
     }
 
     if (uold_ctx) {
-        TaskState *ts = (TaskState *)thread_cpu->opaque;
-
         if (!lock_user_struct(VERIFY_WRITE, uctx, uold_ctx, 1)) {
             return -TARGET_EFAULT;
         }
@@ -701,7 +699,8 @@ abi_long do_swapcontext(CPUArchState *env, abi_ulong uold_ctx,
 #endif
 
         save_user_regs(env, mctx);
-        host_to_target_sigset(&uctx->tuc_sigmask, &ts->signal_mask);
+        host_to_target_sigset(&uctx->tuc_sigmask,
+                              &thread_cpu->task_state->signal_mask);
 
         unlock_user_struct(uctx, uold_ctx, 1);
     }
linux-user/riscv/cpu_loop.c +1 -2
index 9665dabb096..66860b27a92 100644
@@ -124,8 +124,7 @@ void cpu_loop(CPURISCVState *env)
 void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)
 {
     CPUState *cpu = env_cpu(env);
-    TaskState *ts = cpu->opaque;
-    struct image_info *info = ts->info;
+    struct image_info *info = cpu->task_state->info;
 
     env->pc = regs->sepc;
     env->gpr[xSP] = regs->sp;
linux-user/signal.c +15 -19
index 7eecec46c40..01f50ea0eef 100644
@@ -185,7 +185,6 @@ void target_to_host_old_sigset(sigset_t *sigset,
 
 int block_signals(void)
 {
-    TaskState *ts = (TaskState *)thread_cpu->opaque;
     sigset_t set;
 
     /* It's OK to block everything including SIGSEGV, because we won't
@@ -195,7 +194,7 @@ int block_signals(void)
     sigfillset(&set);
     sigprocmask(SIG_SETMASK, &set, 0);
 
-    return qatomic_xchg(&ts->signal_pending, 1);
+    return qatomic_xchg(&thread_cpu->task_state->signal_pending, 1);
 }
 
 /* Wrapper for sigprocmask function
@@ -207,7 +206,7 @@ int block_signals(void)
  */
 int do_sigprocmask(int how, const sigset_t *set, sigset_t *oldset)
 {
-    TaskState *ts = (TaskState *)thread_cpu->opaque;
+    TaskState *ts = thread_cpu->task_state;
 
     if (oldset) {
         *oldset = ts->signal_mask;
@@ -251,9 +250,7 @@ int do_sigprocmask(int how, const sigset_t *set, sigset_t *oldset)
  */
 void set_sigmask(const sigset_t *set)
 {
-    TaskState *ts = (TaskState *)thread_cpu->opaque;
-
-    ts->signal_mask = *set;
+    thread_cpu->task_state->signal_mask = *set;
 }
 #endif
 
@@ -261,7 +258,7 @@ void set_sigmask(const sigset_t *set)
 
 int on_sig_stack(unsigned long sp)
 {
-    TaskState *ts = (TaskState *)thread_cpu->opaque;
+    TaskState *ts = thread_cpu->task_state;
 
     return (sp - ts->sigaltstack_used.ss_sp
             < ts->sigaltstack_used.ss_size);
@@ -269,7 +266,7 @@ int on_sig_stack(unsigned long sp)
 
 int sas_ss_flags(unsigned long sp)
 {
-    TaskState *ts = (TaskState *)thread_cpu->opaque;
+    TaskState *ts = thread_cpu->task_state;
 
     return (ts->sigaltstack_used.ss_size == 0 ? SS_DISABLE
             : on_sig_stack(sp) ? SS_ONSTACK : 0);
@@ -280,7 +277,7 @@ abi_ulong target_sigsp(abi_ulong sp, struct target_sigaction *ka)
     /*
      * This is the X/Open sanctioned signal stack switching.
      */
-    TaskState *ts = (TaskState *)thread_cpu->opaque;
+    TaskState *ts = thread_cpu->task_state;
 
     if ((ka->sa_flags & TARGET_SA_ONSTACK) && !sas_ss_flags(sp)) {
         return ts->sigaltstack_used.ss_sp + ts->sigaltstack_used.ss_size;
@@ -290,7 +287,7 @@ abi_ulong target_sigsp(abi_ulong sp, struct target_sigaction *ka)
 
 void target_save_altstack(target_stack_t *uss, CPUArchState *env)
 {
-    TaskState *ts = (TaskState *)thread_cpu->opaque;
+    TaskState *ts = thread_cpu->task_state;
 
     __put_user(ts->sigaltstack_used.ss_sp, &uss->ss_sp);
     __put_user(sas_ss_flags(get_sp_from_cpustate(env)), &uss->ss_flags);
@@ -543,7 +540,6 @@ static void signal_table_init(void)
 
 void signal_init(void)
 {
-    TaskState *ts = (TaskState *)thread_cpu->opaque;
     struct sigaction act;
     struct sigaction oact;
     int i;
@@ -553,7 +549,7 @@ void signal_init(void)
     signal_table_init();
 
     /* Set the signal mask from the host mask. */
-    sigprocmask(0, 0, &ts->signal_mask);
+    sigprocmask(0, 0, &thread_cpu->task_state->signal_mask);
 
     sigfillset(&act.sa_mask);
     act.sa_flags = SA_SIGINFO;
@@ -623,7 +619,7 @@ static void QEMU_NORETURN dump_core_and_abort(int target_sig)
 {
     CPUState *cpu = thread_cpu;
     CPUArchState *env = cpu->env_ptr;
-    TaskState *ts = (TaskState *)cpu->opaque;
+    TaskState *ts = cpu->task_state;
     int host_sig, core_dumped = 0;
     struct sigaction act;
 
@@ -678,7 +674,7 @@ int queue_signal(CPUArchState *env, int sig, int si_type,
                  target_siginfo_t *info)
 {
     CPUState *cpu = env_cpu(env);
-    TaskState *ts = cpu->opaque;
+    TaskState *ts = cpu->task_state;
 
     trace_user_queue_signal(env, sig);
 
@@ -703,7 +699,7 @@ static void host_signal_handler(int host_signum, siginfo_t *info,
 {
     CPUArchState *env = thread_cpu->env_ptr;
     CPUState *cpu = env_cpu(env);
-    TaskState *ts = cpu->opaque;
+    TaskState *ts = cpu->task_state;
 
     int sig;
     target_siginfo_t tinfo;
@@ -760,7 +756,7 @@ abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp)
 {
     int ret;
     struct target_sigaltstack oss;
-    TaskState *ts = (TaskState *)thread_cpu->opaque;
+    TaskState *ts = thread_cpu->task_state;
 
     /* XXX: test errors */
     if(uoss_addr)
@@ -778,7 +774,7 @@ abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp)
 
 #if defined(TARGET_PPC64)
         /* ELF V2 for PPC64 has a 4K minimum stack size for signal handlers */
-        struct image_info *image = ((TaskState *)thread_cpu->opaque)->info;
+        struct image_info *image = thread_cpu->task_state->info;
         if (get_ppc64_abi(image) > 1) {
             minstacksize = 4096;
         }
@@ -918,7 +914,7 @@ static void handle_pending_signal(CPUArchState *cpu_env, int sig,
     sigset_t set;
     target_sigset_t target_old_set;
     struct target_sigaction *sa;
-    TaskState *ts = cpu->opaque;
+    TaskState *ts = cpu->task_state;
 
     trace_user_handle_signal(cpu_env, sig);
     /* dequeue signal */
@@ -1000,7 +996,7 @@ void process_pending_signals(CPUArchState *cpu_env)
 {
     CPUState *cpu = env_cpu(cpu_env);
     int sig;
-    TaskState *ts = cpu->opaque;
+    TaskState *ts = cpu->task_state;
     sigset_t set;
     sigset_t *blocked_set;
 
linux-user/syscall.c +17 -24

153 lines not on this page · raw message

linux-user/vm86.c +9 -10
index 4412522c4c4..2efb4227716 100644
@@ -73,7 +73,7 @@ static inline unsigned int vm_getl(CPUX86State *env,
 void save_v86_state(CPUX86State *env)
 {
     CPUState *cs = env_cpu(env);
-    TaskState *ts = cs->opaque;
+    TaskState *ts = cs->task_state;
     struct target_vm86plus_struct * target_v86;
 
     if (!lock_user_struct(VERIFY_WRITE, target_v86, ts->target_v86, 0))
@@ -133,7 +133,7 @@ static inline void return_to_32bit(CPUX86State *env, int retval)
 static inline int set_IF(CPUX86State *env)
 {
     CPUState *cs = env_cpu(env);
-    TaskState *ts = cs->opaque;
+    TaskState *ts = cs->task_state;
 
     ts->v86flags |= VIF_MASK;
     if (ts->v86flags & VIP_MASK) {
@@ -146,9 +146,8 @@ static inline int set_IF(CPUX86State *env)
 static inline void clear_IF(CPUX86State *env)
 {
     CPUState *cs = env_cpu(env);
-    TaskState *ts = cs->opaque;
 
-    ts->v86flags &= ~VIF_MASK;
+    cs->task_state->v86flags &= ~VIF_MASK;
 }
 
 static inline void clear_TF(CPUX86State *env)
@@ -164,7 +163,7 @@ static inline void clear_AC(CPUX86State *env)
 static inline int set_vflags_long(unsigned long eflags, CPUX86State *env)
 {
     CPUState *cs = env_cpu(env);
-    TaskState *ts = cs->opaque;
+    TaskState *ts = cs->task_state;
 
     set_flags(ts->v86flags, eflags, ts->v86mask);
     set_flags(env->eflags, eflags, SAFE_MASK);
@@ -178,7 +177,7 @@ static inline int set_vflags_long(unsigned long eflags, CPUX86State *env)
 static inline int set_vflags_short(unsigned short flags, CPUX86State *env)
 {
     CPUState *cs = env_cpu(env);
-    TaskState *ts = cs->opaque;
+    TaskState *ts = cs->task_state;
 
     set_flags(ts->v86flags, flags, ts->v86mask & 0xffff);
     set_flags(env->eflags, flags, SAFE_MASK);
@@ -192,7 +191,7 @@ static inline int set_vflags_short(unsigned short flags, CPUX86State *env)
 static inline unsigned int get_vflags(CPUX86State *env)
 {
     CPUState *cs = env_cpu(env);
-    TaskState *ts = cs->opaque;
+    TaskState *ts = cs->task_state;
     unsigned int flags;
 
     flags = env->eflags & RETURN_MASK;
@@ -209,7 +208,7 @@ static inline unsigned int get_vflags(CPUX86State *env)
 static void do_int(CPUX86State *env, int intno)
 {
     CPUState *cs = env_cpu(env);
-    TaskState *ts = cs->opaque;
+    TaskState *ts = cs->task_state;
     uint32_t int_addr, segoffs, ssp;
     unsigned int sp;
 
@@ -268,7 +267,7 @@ void handle_vm86_trap(CPUX86State *env, int trapno)
 void handle_vm86_fault(CPUX86State *env)
 {
     CPUState *cs = env_cpu(env);
-    TaskState *ts = cs->opaque;
+    TaskState *ts = cs->task_state;
     uint32_t csp, ssp;
     unsigned int ip, sp, newflags, newip, newcs, opcode, intno;
     int data32, pref_done;
@@ -393,7 +392,7 @@ void handle_vm86_fault(CPUX86State *env)
 int do_vm86(CPUX86State *env, long subfunction, abi_ulong vm86_addr)
 {
     CPUState *cs = env_cpu(env);
-    TaskState *ts = cs->opaque;
+    TaskState *ts = cs->task_state;
     struct target_vm86plus_struct * target_v86;
     int ret;
 
target/m68k/m68k-semi.c +1 -1
index d919245e4f8..217a9b9fc94 100644
@@ -425,7 +425,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr)
 #if defined(CONFIG_USER_ONLY)
         {
         CPUState *cs = env_cpu(env);
-        TaskState *ts = cs->opaque;
+        TaskState *ts = cs->task_state;
         /* Allocate the heap using sbrk.  */
         if (!ts->heap_limit) {
             abi_ulong ret;
Signature · 1 line
2.26.2