Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/pgoyette-compat]: src/sys/arch/mips/mips Put netbsd32_sendsig_siginfo() ...



details:   https://anonhg.NetBSD.org/src/rev/32f2665e7b5f
branches:  pgoyette-compat
changeset: 830836:32f2665e7b5f
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Sat Sep 29 09:45:51 2018 +0000

description:
Put netbsd32_sendsig_siginfo() here, where it belongs.

diffstat:

 sys/arch/mips/mips/netbsd32_machdep.c |  96 ++++++++++++++++++++++++++++++++--
 1 files changed, 88 insertions(+), 8 deletions(-)

diffs (124 lines):

diff -r 7e2a9f7265d6 -r 32f2665e7b5f sys/arch/mips/mips/netbsd32_machdep.c
--- a/sys/arch/mips/mips/netbsd32_machdep.c     Sat Sep 29 09:44:53 2018 +0000
+++ b/sys/arch/mips/mips/netbsd32_machdep.c     Sat Sep 29 09:45:51 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netbsd32_machdep.c,v 1.15.2.4 2018/09/29 08:38:45 pgoyette Exp $       */
+/*     $NetBSD: netbsd32_machdep.c,v 1.15.2.5 2018/09/29 09:45:51 pgoyette Exp $       */
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.15.2.4 2018/09/29 08:38:45 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.15.2.5 2018/09/29 09:45:51 pgoyette Exp $");
 
 #include "opt_compat_netbsd.h"
 #include "opt_coredump.h"
@@ -75,6 +75,92 @@
 netbsd32_vm_default_addr
 #endif
 
+static int netbsd32_sendsig_siginfo(const ksiginfo_t *, const sigset_t *);
+
+struct sigframe_siginfo32 {
+       siginfo32_t sf_si;
+       ucontext32_t sf_uc;
+};
+
+/*
+ * Send a signal to process.
+ */
+static int
+netbsd32_sendsig_siginfo(const ksiginfo_t *ksi, const sigset_t *mask)
+{
+       struct lwp * const l = curlwp;
+       struct proc * const p = l->l_proc;
+       struct sigacts * const ps = p->p_sigacts;
+       int onstack, error;
+       int sig = ksi->ksi_signo;
+       struct sigframe_siginfo32 *sfp = getframe(l, sig, &onstack);
+       struct sigframe_siginfo32 sf;
+       struct trapframe * const tf = l->l_md.md_utf;
+       size_t sfsz;
+       sig_t catcher = SIGACTION(p, sig).sa_handler;
+
+       sfp--;
+
+       netbsd32_si_to_si32(&sf.sf_si, (const siginfo_t *)&ksi->ksi_info);
+
+        /* Build stack frame for signal trampoline. */
+        switch (ps->sa_sigdesc[sig].sd_vers) {
+        case 0:         /* handled by sendsig_sigcontext */
+        case 1:         /* handled by sendsig_sigcontext */
+        default:        /* unknown version */
+                printf("sendsig_siginfo: bad version %d\n",
+                    ps->sa_sigdesc[sig].sd_vers);
+                sigexit(l, SIGILL);
+        case 2:
+                break;
+        }
+
+       sf.sf_uc.uc_flags = _UC_SIGMASK
+           | ((l->l_sigstk.ss_flags & SS_ONSTACK)
+           ? _UC_SETSTACK : _UC_CLRSTACK);
+       sf.sf_uc.uc_sigmask = *mask;
+       sf.sf_uc.uc_link = (intptr_t)l->l_ctxlink;
+       memset(&sf.sf_uc.uc_stack, 0, sizeof(sf.sf_uc.uc_stack));
+       sfsz = offsetof(struct sigframe_siginfo32, sf_uc.uc_mcontext);
+       if (p->p_md.md_abi == _MIPS_BSD_API_O32)
+               sfsz += sizeof(mcontext_o32_t);
+       else
+               sfsz += sizeof(mcontext32_t);
+       sendsig_reset(l, sig);
+       mutex_exit(p->p_lock);
+       cpu_getmcontext32(l, &sf.sf_uc.uc_mcontext, &sf.sf_uc.uc_flags);
+       error = copyout(&sf, sfp, sfsz);
+       mutex_enter(p->p_lock);
+       if (error != 0) {
+               /*
+                * Process has trashed its stack; give it an illegal
+                * instruction to halt it in its tracks.
+                */
+               sigexit(l, SIGILL);
+               /* NOTREACHED */
+       }
+
+       /*
+        * Set up the registers to directly invoke the signal
+        * handler.  The return address will be set up to point
+        * to the signal trampoline to bounce us back.
+        */
+       tf->tf_regs[_R_A0] = sig;
+       tf->tf_regs[_R_A1] = (intptr_t)&sfp->sf_si;
+       tf->tf_regs[_R_A2] = (intptr_t)&sfp->sf_uc;
+
+       tf->tf_regs[_R_PC] = (intptr_t)catcher;
+       tf->tf_regs[_R_T9] = (intptr_t)catcher;
+       tf->tf_regs[_R_SP] = (intptr_t)sfp;
+       tf->tf_regs[_R_RA] = (intptr_t)ps->sa_sigdesc[sig].sd_tramp;
+
+       /* Remember that we're now on the signal stack. */
+       if (onstack)
+               l->l_sigstk.ss_flags |= SS_ONSTACK;
+
+       return 0;
+}
+
 int
 netbsd32_sysarch(struct lwp *l, const struct netbsd32_sysarch_args *uap,
        register_t *retval)
@@ -124,12 +210,6 @@
                return VM_DEFAULT_ADDRESS32_BOTTOMUP(base, size);
 }
 
-
-struct sigframe_siginfo32 {
-       siginfo32_t sf_si;
-       ucontext32_t sf_uc;
-};
-
 void
 cpu_getmcontext32(struct lwp *l, mcontext32_t *mc32, unsigned int *flagsp)
 {



Home | Main Index | Thread Index | Old Index