PERFORCE change 162167 for review
Ulf Lilleengen
lulf at FreeBSD.org
Sat May 16 18:15:58 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=162167
Change 162167 by lulf at lulf_carrot on 2009/05/16 18:15:26
- First try at implementing sendsig().
Affected files ...
.. //depot/projects/avr32/src/sys/avr32/avr32/pm_machdep.c#8 edit
Differences ...
==== //depot/projects/avr32/src/sys/avr32/avr32/pm_machdep.c#8 (text+ko) ====
@@ -29,8 +29,13 @@
#include <sys/param.h>
#include <sys/systm.h>
+#include <sys/sysent.h>
+#include <sys/proc.h>
+#include <sys/signalvar.h>
+#include <sys/exec.h>
+#include <sys/imgact.h>
+#include <sys/ucontext.h>
#include <sys/malloc.h>
-#include <sys/proc.h>
#include <sys/buf.h>
#include <sys/vnode.h>
#include <sys/vmmeter.h>
@@ -41,6 +46,9 @@
#include <sys/uio.h>
#include <sys/ptrace.h>
#include <sys/sysproto.h>
+#ifdef KTRACE
+#include <sys/ktrace.h>
+#endif
#include <sys/imgact.h>
#include <vm/vm.h>
#include <vm/pmap.h>
@@ -49,6 +57,8 @@
#include <machine/cpu.h>
#include <machine/reg.h>
+#include <machine/sigframe.h>
+#include <machine/vmparam.h>
#include <machine/reg_sys.h>
#include <machine/debug.h>
@@ -115,8 +125,84 @@
void
sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
{
- panic("sendsig");
- avr32_impl();
+ struct thread *td;
+ struct proc *p;
+ struct sigframe sf, *sfp;
+ struct sigacts *psp;
+ struct trapframe *tf;
+ struct reg *regs;
+ int sig;
+ int oonstack;
+
+ td = curthread;
+ p = td->td_proc;
+ PROC_LOCK_ASSERT(p, MA_OWNED);
+ sig = ksi->ksi_signo;
+ psp = p->p_sigacts;
+ mtx_assert(&psp->ps_mtx, MA_OWNED);
+ tf = td->td_frame;
+ regs = &tf->regs;
+ oonstack = sigonstack(regs->sp);
+
+ /* Save user context. */
+ bzero(&sf, sizeof(sf));
+ sf.sf_uc.uc_sigmask = *mask;
+ sf.sf_uc.uc_stack = td->td_sigstk;
+ sf.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK)
+ ? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
+ sf.sf_uc.uc_mcontext.mc_onstack = (oonstack) ? 1 : 0;
+ bcopy(regs, &sf.sf_uc.uc_mcontext.mc_regs,
+ sizeof(sf.sf_uc.uc_mcontext.mc_regs));
+ sf.sf_uc.uc_mcontext.mc_len = sizeof(sf.sf_uc.uc_mcontext);
+
+ /* Allocate and validate space for the signal handler context. */
+ if ((td->td_pflags & TDP_ALTSTACK) != 0 && !oonstack &&
+ SIGISMEMBER(psp->ps_sigonstack, sig)) {
+ sfp = (struct sigframe *)((vm_offset_t)(td->td_sigstk.ss_sp +
+ td->td_sigstk.ss_size - sizeof(struct sigframe))
+ & ~(sizeof(register_t) - 1));
+ } else {
+ sfp = (struct sigframe *)((vm_offset_t)(regs->sp -
+ sizeof(struct sigframe)) & ~(sizeof(register_t) - 1));
+ }
+
+ /* Translate the signal is appropriate */
+ if (p->p_sysent->sv_sigtbl && sig <= p->p_sysent->sv_sigsize) {
+ sig = p->p_sysent->sv_sigtbl[_SIG_IDX(sig)];
+ }
+
+ /* POSIX parts */
+ sf.sf_si = ksi->ksi_info;
+ sf.sf_si.si_signo = sig; /* May have changed. */
+
+ /* Build context. */
+ regs->r12 = sig;
+ regs->r11 = (register_t)&sfp->sf_si;
+ regs->r10 = (register_t)&sfp->sf_uc;
+ mtx_unlock(&psp->ps_mtx);
+ PROC_UNLOCK(p);
+
+ /*
+ * Copy the sigframe out to the user's stack.
+ */
+ if (copyout(&sf, sfp, sizeof(struct sigframe)) != 0) {
+ /* Problems with trashed stack. */
+ CTR2(KTR_SIG, "sendsig: sigexit td=%p sfp=%p", td, sfp);
+ PROC_LOCK(p);
+ sigexit(td, SIGILL);
+ }
+
+ regs->pc = (register_t)catcher;
+ regs->sp = (register_t)sfp;
+
+ /*
+ * Signal trampoline code is at base of user stack.
+ */
+ regs->lr = PS_STRINGS - *(p->p_sysent->sv_szsigcode);
+ CTR3(KTR_SIG, "sendsig: return td=%p pc=%#x sp=%#x", td, regs->lr,
+ regs->sp);
+ PROC_LOCK(p);
+ mtx_lock(&psp->ps_mtx);
}
/*
More information about the p4-projects
mailing list