{linux,bsd}-user: Introduce get_task_state()
A CPU's TaskState is stored in the CPUState's void *opaque field,
accessing which is somewhat awkward due to having to use a cast.
Introduce a wrapper and use it everywhere.
Suggested-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Reviewed-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20240219141628.246823-3-iii@linux.ibm.com>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20240305121005.3528075-4-alex.bennee@linaro.org>
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index bc8c065..c233d4e 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6515,7 +6515,7 @@
env = info->env;
cpu = env_cpu(env);
thread_cpu = cpu;
- ts = (TaskState *)cpu->opaque;
+ ts = get_task_state(cpu);
info->tid = sys_gettid();
task_settid(ts);
if (info->child_tidptr)
@@ -6557,7 +6557,7 @@
flags &= ~(CLONE_VFORK | CLONE_VM);
if (flags & CLONE_VM) {
- TaskState *parent_ts = (TaskState *)cpu->opaque;
+ TaskState *parent_ts = get_task_state(cpu);
new_thread_info info;
pthread_attr_t attr;
@@ -6680,7 +6680,7 @@
put_user_u32(sys_gettid(), child_tidptr);
if (flags & CLONE_PARENT_SETTID)
put_user_u32(sys_gettid(), parent_tidptr);
- ts = (TaskState *)cpu->opaque;
+ ts = get_task_state(cpu);
if (flags & CLONE_SETTLS)
cpu_set_tls (env, newtls);
if (flags & CLONE_CHILD_CLEARTID)
@@ -7946,7 +7946,7 @@
static int open_self_cmdline(CPUArchState *cpu_env, int fd)
{
CPUState *cpu = env_cpu(cpu_env);
- struct linux_binprm *bprm = ((TaskState *)cpu->opaque)->bprm;
+ struct linux_binprm *bprm = get_task_state(cpu)->bprm;
int i;
for (i = 0; i < bprm->argc; i++) {
@@ -8146,7 +8146,7 @@
static int open_self_stat(CPUArchState *cpu_env, int fd)
{
CPUState *cpu = env_cpu(cpu_env);
- TaskState *ts = cpu->opaque;
+ TaskState *ts = get_task_state(cpu);
g_autoptr(GString) buf = g_string_new(NULL);
int i;
@@ -8187,7 +8187,7 @@
static int open_self_auxv(CPUArchState *cpu_env, int fd)
{
CPUState *cpu = env_cpu(cpu_env);
- TaskState *ts = cpu->opaque;
+ TaskState *ts = get_task_state(cpu);
abi_ulong auxv = ts->info->saved_auxv;
abi_ulong len = ts->info->auxv_len;
char *ptr;
@@ -9012,7 +9012,7 @@
pthread_mutex_lock(&clone_lock);
if (CPU_NEXT(first_cpu)) {
- TaskState *ts = cpu->opaque;
+ TaskState *ts = get_task_state(cpu);
if (ts->child_tidptr) {
put_user_u32(0, ts->child_tidptr);
@@ -9439,7 +9439,7 @@
#ifdef TARGET_NR_pause /* not on alpha */
case TARGET_NR_pause:
if (!block_signals()) {
- sigsuspend(&((TaskState *)cpu->opaque)->signal_mask);
+ sigsuspend(&get_task_state(cpu)->signal_mask);
}
return -TARGET_EINTR;
#endif
@@ -10005,7 +10005,7 @@
sigset_t *set;
#if defined(TARGET_ALPHA)
- TaskState *ts = cpu->opaque;
+ TaskState *ts = get_task_state(cpu);
/* target_to_host_old_sigset will bswap back */
abi_ulong mask = tswapal(arg1);
set = &ts->sigsuspend_mask;
@@ -10406,7 +10406,7 @@
case TARGET_NR_mprotect:
arg1 = cpu_untagged_addr(cpu, arg1);
{
- TaskState *ts = cpu->opaque;
+ TaskState *ts = get_task_state(cpu);
/* Special hack to detect libc making the stack executable. */
if ((arg3 & PROT_GROWSDOWN)
&& arg1 >= ts->info->stack_limit
@@ -12537,7 +12537,7 @@
return do_set_thread_area(cpu_env, arg1);
#elif defined(TARGET_M68K)
{
- TaskState *ts = cpu->opaque;
+ TaskState *ts = get_task_state(cpu);
ts->tp_value = arg1;
return 0;
}
@@ -12551,7 +12551,7 @@
return do_get_thread_area(cpu_env, arg1);
#elif defined(TARGET_M68K)
{
- TaskState *ts = cpu->opaque;
+ TaskState *ts = get_task_state(cpu);
return ts->tp_value;
}
#else
@@ -12676,7 +12676,7 @@
#if defined(TARGET_NR_set_tid_address)
case TARGET_NR_set_tid_address:
{
- TaskState *ts = cpu->opaque;
+ TaskState *ts = get_task_state(cpu);
ts->child_tidptr = arg1;
/* do not call host set_tid_address() syscall, instead return tid() */
return get_errno(sys_gettid());