Skip to content

Commit

Permalink
more remove nommu ifdef part
Browse files Browse the repository at this point in the history
  • Loading branch information
thehajime committed Dec 16, 2024
1 parent 9edb5c0 commit 92546d5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
4 changes: 4 additions & 0 deletions arch/um/include/shared/kern_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ void kasan_map_memory(void *start, size_t len);
static inline void arch_sigsys_handler(int sig, struct siginfo *si, void *mc)
{
}
static inline void arch_sigsegv_handler(int sig, struct siginfo *unused_si, void *mc)
{
}
#else
extern void arch_sigsys_handler(int sig, struct siginfo *si, void *mc);
extern void arch_sigsegv_handler(int sig, struct siginfo *si, void *mc);
#endif

#endif
13 changes: 13 additions & 0 deletions arch/um/nommu/os-Linux/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <os.h>
#include <sysdep/mcontext.h>
#include <sys/ucontext.h>
#include <as-layout.h>

void arch_sigsys_handler(int sig, struct siginfo *si, void *ptr)
{
Expand All @@ -13,3 +14,15 @@ void arch_sigsys_handler(int sig, struct siginfo *si, void *ptr)
/* hook syscall via SIGSYS */
mc_set_sigsys_hook(mc);
}

void arch_sigsegv_handler(int sig, struct siginfo *si, void *ptr)
{
mcontext_t *mc = (mcontext_t *) ptr;

/* !MMU specific part; detection of userspace */
if (mc->gregs[REG_RIP] > uml_reserved &&
mc->gregs[REG_RIP] < high_physmem) {
/* !MMU: force handle signals after rt_sigreturn() */
mc_set_regs_ip_relay(mc);
}
}
2 changes: 1 addition & 1 deletion arch/um/nommu/trap.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void segv_handler(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs)
if (UPT_IP(regs) > uml_reserved && UPT_IP(regs) < high_physmem)
regs->is_user = 1;

if (UPT_IS_USER(regs) && !SEGV_IS_FIXABLE(fi)) {
if (UPT_IS_USER(regs) && !SEGV_IS_FIXABLE(fi)) {
show_segv_info(regs);
bad_segv(*fi, UPT_IP(regs));
return;
Expand Down
31 changes: 18 additions & 13 deletions arch/um/os-Linux/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,13 @@ static void sig_handler_common(int sig, struct siginfo *si, mcontext_t *mc)
int save_errno = errno;

r.is_user = 0;
if (sig == SIGSEGV) {
/* For segfaults, we want the data from the sigcontext. */
get_regs_from_mc(&r, mc);
GET_FAULTINFO_FROM_MC(r.faultinfo, mc);
}

/* enable signals if sig isn't IRQ signal */
if ((sig != SIGIO) && (sig != SIGWINCH))
unblock_signals_trace();

(*sig_info[sig])(sig, si, &r);

errno = save_errno;

#ifndef CONFIG_MMU
/* !MMU: force handle signals after rt_sigreturn() */
if (r.is_user && sig == SIGSEGV)
mc_set_regs_ip_relay(mc);
#endif
}

/*
Expand Down Expand Up @@ -183,8 +171,25 @@ static void sigsys_handler(int sig, struct siginfo *unused_si, mcontext_t *mc)
arch_sigsys_handler(sig, unused_si, mc);
}

static void sigsegv_handler(int sig, struct siginfo *unused_si, mcontext_t *mc)
{
struct uml_pt_regs r;
int save_errno = errno;

r.is_user = 0;

/* For segfaults, we want the data from the sigcontext. */
get_regs_from_mc(&r, mc);
GET_FAULTINFO_FROM_MC(r.faultinfo, mc);

segv_handler(sig, unused_si, &r);
arch_sigsegv_handler(sig, unused_si, mc);

errno = save_errno;
}

static void (*handlers[_NSIG])(int sig, struct siginfo *si, mcontext_t *mc) = {
[SIGSEGV] = sig_handler,
[SIGSEGV] = sigsegv_handler,
[SIGBUS] = sig_handler,
[SIGILL] = sig_handler,
[SIGFPE] = sig_handler,
Expand Down

0 comments on commit 92546d5

Please sign in to comment.