linux-user: Introduce cpu_clone_regs_parent

We will need a target-specific hook for adjusting registers
in the parent during clone.  Add an empty inline function for
each target, and invoke it from the proper places.

Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20191106113318.10226-11-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
This commit is contained in:
Richard Henderson 2019-11-06 12:33:16 +01:00 committed by Laurent Vivier
parent 608999d17c
commit 07a6ecf48f
19 changed files with 74 additions and 0 deletions

View File

@ -28,6 +28,10 @@ static inline void cpu_clone_regs_child(CPUARMState *env, target_ulong newsp,
env->xregs[0] = 0; env->xregs[0] = 0;
} }
static inline void cpu_clone_regs_parent(CPUARMState *env, unsigned flags)
{
}
static inline void cpu_set_tls(CPUARMState *env, target_ulong newtls) static inline void cpu_set_tls(CPUARMState *env, target_ulong newtls)
{ {
/* Note that AArch64 Linux keeps the TLS pointer in TPIDR; this is /* Note that AArch64 Linux keeps the TLS pointer in TPIDR; this is

View File

@ -29,6 +29,10 @@ static inline void cpu_clone_regs_child(CPUAlphaState *env, target_ulong newsp,
env->ir[IR_A3] = 0; env->ir[IR_A3] = 0;
} }
static inline void cpu_clone_regs_parent(CPUAlphaState *env, unsigned flags)
{
}
static inline void cpu_set_tls(CPUAlphaState *env, target_ulong newtls) static inline void cpu_set_tls(CPUAlphaState *env, target_ulong newtls)
{ {
env->unique = newtls; env->unique = newtls;

View File

@ -50,6 +50,10 @@ static inline void cpu_clone_regs_child(CPUARMState *env, target_ulong newsp,
env->regs[0] = 0; env->regs[0] = 0;
} }
static inline void cpu_clone_regs_parent(CPUARMState *env, unsigned flags)
{
}
static inline void cpu_set_tls(CPUARMState *env, target_ulong newtls) static inline void cpu_set_tls(CPUARMState *env, target_ulong newtls)
{ {
if (access_secure_reg(env)) { if (access_secure_reg(env)) {

View File

@ -29,6 +29,10 @@ static inline void cpu_clone_regs_child(CPUCRISState *env, target_ulong newsp,
env->regs[10] = 0; env->regs[10] = 0;
} }
static inline void cpu_clone_regs_parent(CPUCRISState *env, unsigned flags)
{
}
static inline void cpu_set_tls(CPUCRISState *env, target_ulong newtls) static inline void cpu_set_tls(CPUCRISState *env, target_ulong newtls)
{ {
env->pregs[PR_PID] = (env->pregs[PR_PID] & 0xff) | newtls; env->pregs[PR_PID] = (env->pregs[PR_PID] & 0xff) | newtls;

View File

@ -32,6 +32,10 @@ static inline void cpu_clone_regs_child(CPUHPPAState *env, target_ulong newsp,
env->iaoq_b = env->gr[31] + 4; env->iaoq_b = env->gr[31] + 4;
} }
static inline void cpu_clone_regs_parent(CPUHPPAState *env, unsigned flags)
{
}
static inline void cpu_set_tls(CPUHPPAState *env, target_ulong newtls) static inline void cpu_set_tls(CPUHPPAState *env, target_ulong newtls)
{ {
env->cr[27] = newtls; env->cr[27] = newtls;

View File

@ -29,6 +29,10 @@ static inline void cpu_clone_regs_child(CPUX86State *env, target_ulong newsp,
env->regs[R_EAX] = 0; env->regs[R_EAX] = 0;
} }
static inline void cpu_clone_regs_parent(CPUX86State *env, unsigned flags)
{
}
#if defined(TARGET_ABI32) #if defined(TARGET_ABI32)
abi_long do_set_thread_area(CPUX86State *env, abi_ulong ptr); abi_long do_set_thread_area(CPUX86State *env, abi_ulong ptr);

View File

@ -30,6 +30,10 @@ static inline void cpu_clone_regs_child(CPUM68KState *env, target_ulong newsp,
env->dregs[0] = 0; env->dregs[0] = 0;
} }
static inline void cpu_clone_regs_parent(CPUM68KState *env, unsigned flags)
{
}
static inline void cpu_set_tls(CPUM68KState *env, target_ulong newtls) static inline void cpu_set_tls(CPUM68KState *env, target_ulong newtls)
{ {
CPUState *cs = env_cpu(env); CPUState *cs = env_cpu(env);

View File

@ -28,6 +28,10 @@ static inline void cpu_clone_regs_child(CPUMBState *env, target_ulong newsp,
env->regs[3] = 0; env->regs[3] = 0;
} }
static inline void cpu_clone_regs_parent(CPUMBState *env, unsigned flags)
{
}
static inline void cpu_set_tls(CPUMBState *env, target_ulong newtls) static inline void cpu_set_tls(CPUMBState *env, target_ulong newtls)
{ {
env->regs[21] = newtls; env->regs[21] = newtls;

View File

@ -29,6 +29,10 @@ static inline void cpu_clone_regs_child(CPUMIPSState *env, target_ulong newsp,
env->active_tc.gpr[2] = 0; env->active_tc.gpr[2] = 0;
} }
static inline void cpu_clone_regs_parent(CPUMIPSState *env, unsigned flags)
{
}
static inline void cpu_set_tls(CPUMIPSState *env, target_ulong newtls) static inline void cpu_set_tls(CPUMIPSState *env, target_ulong newtls)
{ {
env->active_tc.CP0_UserLocal = newtls; env->active_tc.CP0_UserLocal = newtls;

View File

@ -29,6 +29,10 @@ static inline void cpu_clone_regs_child(CPUNios2State *env, target_ulong newsp,
env->regs[R_RET0] = 0; env->regs[R_RET0] = 0;
} }
static inline void cpu_clone_regs_parent(CPUNios2State *env, unsigned flags)
{
}
static inline void cpu_set_tls(CPUNios2State *env, target_ulong newtls) static inline void cpu_set_tls(CPUNios2State *env, target_ulong newtls)
{ {
/* /*

View File

@ -30,6 +30,10 @@ static inline void cpu_clone_regs_child(CPUOpenRISCState *env,
cpu_set_gpr(env, 11, 0); cpu_set_gpr(env, 11, 0);
} }
static inline void cpu_clone_regs_parent(CPUOpenRISCState *env, unsigned flags)
{
}
static inline void cpu_set_tls(CPUOpenRISCState *env, target_ulong newtls) static inline void cpu_set_tls(CPUOpenRISCState *env, target_ulong newtls)
{ {
cpu_set_gpr(env, 10, newtls); cpu_set_gpr(env, 10, newtls);

View File

@ -28,6 +28,10 @@ static inline void cpu_clone_regs_child(CPUPPCState *env, target_ulong newsp,
env->gpr[3] = 0; env->gpr[3] = 0;
} }
static inline void cpu_clone_regs_parent(CPUPPCState *env, unsigned flags)
{
}
static inline void cpu_set_tls(CPUPPCState *env, target_ulong newtls) static inline void cpu_set_tls(CPUPPCState *env, target_ulong newtls)
{ {
#if defined(TARGET_PPC64) #if defined(TARGET_PPC64)

View File

@ -11,6 +11,10 @@ static inline void cpu_clone_regs_child(CPURISCVState *env, target_ulong newsp,
env->gpr[xA0] = 0; env->gpr[xA0] = 0;
} }
static inline void cpu_clone_regs_parent(CPURISCVState *env, unsigned flags)
{
}
static inline void cpu_set_tls(CPURISCVState *env, target_ulong newtls) static inline void cpu_set_tls(CPURISCVState *env, target_ulong newtls)
{ {
env->gpr[xTP] = newtls; env->gpr[xTP] = newtls;

View File

@ -28,6 +28,10 @@ static inline void cpu_clone_regs_child(CPUS390XState *env, target_ulong newsp,
env->regs[2] = 0; env->regs[2] = 0;
} }
static inline void cpu_clone_regs_parent(CPUS390XState *env, unsigned flags)
{
}
static inline void cpu_set_tls(CPUS390XState *env, target_ulong newtls) static inline void cpu_set_tls(CPUS390XState *env, target_ulong newtls)
{ {
env->aregs[0] = newtls >> 32; env->aregs[0] = newtls >> 32;

View File

@ -28,6 +28,10 @@ static inline void cpu_clone_regs_child(CPUSH4State *env, target_ulong newsp,
env->gregs[0] = 0; env->gregs[0] = 0;
} }
static inline void cpu_clone_regs_parent(CPUSH4State *env, unsigned flags)
{
}
static inline void cpu_set_tls(CPUSH4State *env, target_ulong newtls) static inline void cpu_set_tls(CPUSH4State *env, target_ulong newtls)
{ {
env->gbr = newtls; env->gbr = newtls;

View File

@ -37,6 +37,10 @@ static inline void cpu_clone_regs_child(CPUSPARCState *env, target_ulong newsp,
#endif #endif
} }
static inline void cpu_clone_regs_parent(CPUSPARCState *env, unsigned flags)
{
}
static inline void cpu_set_tls(CPUSPARCState *env, target_ulong newtls) static inline void cpu_set_tls(CPUSPARCState *env, target_ulong newtls)
{ {
env->gregs[7] = newtls; env->gregs[7] = newtls;

View File

@ -5821,6 +5821,7 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp,
new_env = cpu_copy(env); new_env = cpu_copy(env);
/* Init regs that differ from the parent. */ /* Init regs that differ from the parent. */
cpu_clone_regs_child(new_env, newsp, flags); cpu_clone_regs_child(new_env, newsp, flags);
cpu_clone_regs_parent(env, flags);
new_cpu = env_cpu(new_env); new_cpu = env_cpu(new_env);
new_cpu->opaque = ts; new_cpu->opaque = ts;
ts->bprm = parent_ts->bprm; ts->bprm = parent_ts->bprm;
@ -5917,6 +5918,7 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp,
if (flags & CLONE_CHILD_CLEARTID) if (flags & CLONE_CHILD_CLEARTID)
ts->child_tidptr = child_tidptr; ts->child_tidptr = child_tidptr;
} else { } else {
cpu_clone_regs_parent(env, flags);
fork_end(0); fork_end(0);
} }
} }

View File

@ -28,6 +28,10 @@ static inline void cpu_clone_regs_child(CPUTLGState *env, target_ulong newsp,
env->regs[TILEGX_R_RE] = 0; env->regs[TILEGX_R_RE] = 0;
} }
static inline void cpu_clone_regs_parent(CPUTLGState *env, unsigned flags)
{
}
static inline void cpu_set_tls(CPUTLGState *env, target_ulong newtls) static inline void cpu_set_tls(CPUTLGState *env, target_ulong newtls)
{ {
env->regs[TILEGX_R_TP] = newtls; env->regs[TILEGX_R_TP] = newtls;

View File

@ -16,6 +16,10 @@ static inline void cpu_clone_regs_child(CPUXtensaState *env,
env->regs[2] = 0; env->regs[2] = 0;
} }
static inline void cpu_clone_regs_parent(CPUXtensaState *env, unsigned flags)
{
}
static inline void cpu_set_tls(CPUXtensaState *env, target_ulong newtls) static inline void cpu_set_tls(CPUXtensaState *env, target_ulong newtls)
{ {
env->uregs[THREADPTR] = newtls; env->uregs[THREADPTR] = newtls;