linux-user: Add host_signal_set_pc to set pc in mcontext

Add a new function host_signal_set_pc to set the next pc in an
mcontext. The caller should ensure this is a valid PC for execution.

Acked-by: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20211113045603.60391-2-imp@bsdimp.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
Warner Losh 2021-11-12 21:55:59 -07:00 committed by Richard Henderson
parent 6d9c9603ad
commit c6cda6a44a
10 changed files with 54 additions and 0 deletions

View File

@ -35,6 +35,11 @@ static inline uintptr_t host_signal_pc(ucontext_t *uc)
return uc->uc_mcontext.pc;
}
static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
{
uc->uc_mcontext.pc = pc;
}
static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
{
struct _aarch64_ctx *hdr;

View File

@ -16,6 +16,11 @@ static inline uintptr_t host_signal_pc(ucontext_t *uc)
return uc->uc_mcontext.sc_pc;
}
static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
{
uc->uc_mcontext.sc_pc = pc;
}
static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
{
uint32_t *pc = (uint32_t *)host_signal_pc(uc);

View File

@ -16,6 +16,11 @@ static inline uintptr_t host_signal_pc(ucontext_t *uc)
return uc->uc_mcontext.arm_pc;
}
static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
{
uc->uc_mcontext.arm_pc = pc;
}
static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
{
/*

View File

@ -16,6 +16,11 @@ static inline uintptr_t host_signal_pc(ucontext_t *uc)
return uc->uc_mcontext.gregs[REG_EIP];
}
static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
{
uc->uc_mcontext.gregs[REG_EIP] = pc;
}
static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
{
return uc->uc_mcontext.gregs[REG_TRAPNO] == 0xe

View File

@ -16,6 +16,11 @@ static inline uintptr_t host_signal_pc(ucontext_t *uc)
return uc->uc_mcontext.pc;
}
static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
{
uc->uc_mcontext.pc = pc;
}
#if defined(__misp16) || defined(__mips_micromips)
#error "Unsupported encoding"
#endif

View File

@ -16,6 +16,11 @@ static inline uintptr_t host_signal_pc(ucontext_t *uc)
return uc->uc_mcontext.regs->nip;
}
static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
{
uc->uc_mcontext.regs->nip = pc;
}
static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
{
return uc->uc_mcontext.regs->trap != 0x400

View File

@ -16,6 +16,11 @@ static inline uintptr_t host_signal_pc(ucontext_t *uc)
return uc->uc_mcontext.__gregs[REG_PC];
}
static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
{
uc->uc_mcontext.__gregs[REG_PC] = pc;
}
static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
{
/*

View File

@ -16,6 +16,11 @@ static inline uintptr_t host_signal_pc(ucontext_t *uc)
return uc->uc_mcontext.psw.addr;
}
static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
{
uc->uc_mcontext.psw.addr = pc;
}
static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
{
uint16_t *pinsn = (uint16_t *)host_signal_pc(uc);

View File

@ -20,6 +20,15 @@ static inline uintptr_t host_signal_pc(ucontext_t *uc)
#endif
}
static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
{
#ifdef __arch64__
uc->uc_mcontext.mc_gregs[MC_PC] = pc;
#else
uc->uc_mcontext.gregs[REG_PC] = pc;
#endif
}
static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
{
uint32_t insn = *(uint32_t *)host_signal_pc(uc);

View File

@ -15,6 +15,11 @@ static inline uintptr_t host_signal_pc(ucontext_t *uc)
return uc->uc_mcontext.gregs[REG_RIP];
}
static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
{
uc->uc_mcontext.gregs[REG_RIP] = pc;
}
static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
{
return uc->uc_mcontext.gregs[REG_TRAPNO] == 0xe