Skip to content

Commit

Permalink
linux-user: Introduce host_signal_mask
Browse files Browse the repository at this point in the history
Do not directly access the uc_sigmask member.
This is preparation for a sparc64 fix.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
  • Loading branch information
rth7680 committed Feb 8, 2022
1 parent 620d0b4 commit c8c89a6
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 10 deletions.
5 changes: 5 additions & 0 deletions linux-user/include/host/aarch64/host-signal.h
Expand Up @@ -40,6 +40,11 @@ static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
uc->uc_mcontext.pc = pc;
}

static inline void *host_signal_mask(ucontext_t *uc)
{
return &uc->uc_sigmask;
}

static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
{
struct _aarch64_ctx *hdr;
Expand Down
5 changes: 5 additions & 0 deletions linux-user/include/host/alpha/host-signal.h
Expand Up @@ -21,6 +21,11 @@ static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
uc->uc_mcontext.sc_pc = pc;
}

static inline void *host_signal_mask(ucontext_t *uc)
{
return &uc->uc_sigmask;
}

static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
{
uint32_t *pc = (uint32_t *)host_signal_pc(uc);
Expand Down
5 changes: 5 additions & 0 deletions linux-user/include/host/arm/host-signal.h
Expand Up @@ -21,6 +21,11 @@ static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
uc->uc_mcontext.arm_pc = pc;
}

static inline void *host_signal_mask(ucontext_t *uc)
{
return &uc->uc_sigmask;
}

static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
{
/*
Expand Down
5 changes: 5 additions & 0 deletions linux-user/include/host/i386/host-signal.h
Expand Up @@ -21,6 +21,11 @@ static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
uc->uc_mcontext.gregs[REG_EIP] = pc;
}

static inline void *host_signal_mask(ucontext_t *uc)
{
return &uc->uc_sigmask;
}

static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
{
return uc->uc_mcontext.gregs[REG_TRAPNO] == 0xe
Expand Down
5 changes: 5 additions & 0 deletions linux-user/include/host/loongarch64/host-signal.h
Expand Up @@ -21,6 +21,11 @@ static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
uc->uc_mcontext.__pc = pc;
}

static inline void *host_signal_mask(ucontext_t *uc)
{
return &uc->uc_sigmask;
}

static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
{
const uint32_t *pinsn = (const uint32_t *)host_signal_pc(uc);
Expand Down
5 changes: 5 additions & 0 deletions linux-user/include/host/mips/host-signal.h
Expand Up @@ -21,6 +21,11 @@ static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
uc->uc_mcontext.pc = pc;
}

static inline void *host_signal_mask(ucontext_t *uc)
{
return &uc->uc_sigmask;
}

#if defined(__misp16) || defined(__mips_micromips)
#error "Unsupported encoding"
#endif
Expand Down
5 changes: 5 additions & 0 deletions linux-user/include/host/ppc/host-signal.h
Expand Up @@ -21,6 +21,11 @@ static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
uc->uc_mcontext.regs->nip = pc;
}

static inline void *host_signal_mask(ucontext_t *uc)
{
return &uc->uc_sigmask;
}

static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
{
return uc->uc_mcontext.regs->trap != 0x400
Expand Down
5 changes: 5 additions & 0 deletions linux-user/include/host/riscv/host-signal.h
Expand Up @@ -21,6 +21,11 @@ static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
uc->uc_mcontext.__gregs[REG_PC] = pc;
}

static inline void *host_signal_mask(ucontext_t *uc)
{
return &uc->uc_sigmask;
}

static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
{
/*
Expand Down
5 changes: 5 additions & 0 deletions linux-user/include/host/s390/host-signal.h
Expand Up @@ -21,6 +21,11 @@ static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
uc->uc_mcontext.psw.addr = pc;
}

static inline void *host_signal_mask(ucontext_t *uc)
{
return &uc->uc_sigmask;
}

static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
{
uint16_t *pinsn = (uint16_t *)host_signal_pc(uc);
Expand Down
5 changes: 5 additions & 0 deletions linux-user/include/host/sparc/host-signal.h
Expand Up @@ -29,6 +29,11 @@ static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
#endif
}

static inline void *host_signal_mask(ucontext_t *uc)
{
return &uc->uc_sigmask;
}

static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
{
uint32_t insn = *(uint32_t *)host_signal_pc(uc);
Expand Down
5 changes: 5 additions & 0 deletions linux-user/include/host/x86_64/host-signal.h
Expand Up @@ -20,6 +20,11 @@ static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
uc->uc_mcontext.gregs[REG_RIP] = pc;
}

static inline void *host_signal_mask(ucontext_t *uc)
{
return &uc->uc_sigmask;
}

static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
{
return uc->uc_mcontext.gregs[REG_TRAPNO] == 0xe
Expand Down
18 changes: 8 additions & 10 deletions linux-user/signal.c
Expand Up @@ -820,6 +820,7 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc)
int guest_sig;
uintptr_t pc = 0;
bool sync_sig = false;
void *sigmask = host_signal_mask(uc);

/*
* Non-spoofed SIGSEGV and SIGBUS are synchronous, and need special
Expand Down Expand Up @@ -849,8 +850,7 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc)
if (info->si_code == SEGV_ACCERR && h2g_valid(host_addr)) {
/* If this was a write to a TB protected page, restart. */
if (is_write &&
handle_sigsegv_accerr_write(cpu, &uc->uc_sigmask,
pc, guest_addr)) {
handle_sigsegv_accerr_write(cpu, sigmask, pc, guest_addr)) {
return;
}

Expand All @@ -865,10 +865,10 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc)
}
}

sigprocmask(SIG_SETMASK, &uc->uc_sigmask, NULL);
sigprocmask(SIG_SETMASK, sigmask, NULL);
cpu_loop_exit_sigsegv(cpu, guest_addr, access_type, maperr, pc);
} else {
sigprocmask(SIG_SETMASK, &uc->uc_sigmask, NULL);
sigprocmask(SIG_SETMASK, sigmask, NULL);
if (info->si_code == BUS_ADRALN) {
cpu_loop_exit_sigbus(cpu, guest_addr, access_type, pc);
}
Expand Down Expand Up @@ -909,17 +909,15 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc)
* now and it getting out to the main loop. Signals will be
* unblocked again in process_pending_signals().
*
* WARNING: we cannot use sigfillset() here because the uc_sigmask
* WARNING: we cannot use sigfillset() here because the sigmask
* field is a kernel sigset_t, which is much smaller than the
* libc sigset_t which sigfillset() operates on. Using sigfillset()
* would write 0xff bytes off the end of the structure and trash
* data on the struct.
* We can't use sizeof(uc->uc_sigmask) either, because the libc
* headers define the struct field with the wrong (too large) type.
*/
memset(&uc->uc_sigmask, 0xff, SIGSET_T_SIZE);
sigdelset(&uc->uc_sigmask, SIGSEGV);
sigdelset(&uc->uc_sigmask, SIGBUS);
memset(sigmask, 0xff, SIGSET_T_SIZE);
sigdelset(sigmask, SIGSEGV);
sigdelset(sigmask, SIGBUS);

/* interrupt the virtual CPU as soon as possible */
cpu_exit(thread_cpu);
Expand Down

0 comments on commit c8c89a6

Please sign in to comment.