[4] | 1 | /* The kernel call that is implemented in this file:
|
---|
| 2 | * m_type: SYS_SIGSEND
|
---|
| 3 | *
|
---|
| 4 | * The parameters for this kernel call are:
|
---|
| 5 | * m2_i1: SIG_PROC # process to call signal handler
|
---|
| 6 | * m2_p1: SIG_CTXT_PTR # pointer to sigcontext structure
|
---|
| 7 | * m2_i3: SIG_FLAGS # flags for S_SIGRETURN call
|
---|
| 8 | *
|
---|
| 9 | */
|
---|
| 10 |
|
---|
| 11 | #include "../system.h"
|
---|
| 12 | #include <signal.h>
|
---|
| 13 | #include <string.h>
|
---|
| 14 | #include <sys/sigcontext.h>
|
---|
| 15 |
|
---|
| 16 | #if USE_SIGSEND
|
---|
| 17 |
|
---|
| 18 | /*===========================================================================*
|
---|
| 19 | * do_sigsend *
|
---|
| 20 | *===========================================================================*/
|
---|
| 21 | PUBLIC int do_sigsend(m_ptr)
|
---|
| 22 | message *m_ptr; /* pointer to request message */
|
---|
| 23 | {
|
---|
| 24 | /* Handle sys_sigsend, POSIX-style signal handling. */
|
---|
| 25 |
|
---|
| 26 | struct sigmsg smsg;
|
---|
| 27 | register struct proc *rp;
|
---|
| 28 | phys_bytes src_phys, dst_phys;
|
---|
| 29 | struct sigcontext sc, *scp;
|
---|
| 30 | struct sigframe fr, *frp;
|
---|
| 31 |
|
---|
| 32 | if (! isokprocn(m_ptr->SIG_PROC)) return(EINVAL);
|
---|
| 33 | if (iskerneln(m_ptr->SIG_PROC)) return(EPERM);
|
---|
| 34 | rp = proc_addr(m_ptr->SIG_PROC);
|
---|
| 35 |
|
---|
| 36 | /* Get the sigmsg structure into our address space. */
|
---|
| 37 | src_phys = umap_local(proc_addr(PM_PROC_NR), D, (vir_bytes)
|
---|
| 38 | m_ptr->SIG_CTXT_PTR, (vir_bytes) sizeof(struct sigmsg));
|
---|
| 39 | if (src_phys == 0) return(EFAULT);
|
---|
| 40 | phys_copy(src_phys,vir2phys(&smsg),(phys_bytes) sizeof(struct sigmsg));
|
---|
| 41 |
|
---|
| 42 | /* Compute the user stack pointer where sigcontext will be stored. */
|
---|
| 43 | scp = (struct sigcontext *) smsg.sm_stkptr - 1;
|
---|
| 44 |
|
---|
| 45 | /* Copy the registers to the sigcontext structure. */
|
---|
| 46 | memcpy(&sc.sc_regs, (char *) &rp->p_reg, sizeof(struct sigregs));
|
---|
| 47 |
|
---|
| 48 | /* Finish the sigcontext initialization. */
|
---|
| 49 | sc.sc_flags = SC_SIGCONTEXT;
|
---|
| 50 | sc.sc_mask = smsg.sm_mask;
|
---|
| 51 |
|
---|
| 52 | /* Copy the sigcontext structure to the user's stack. */
|
---|
| 53 | dst_phys = umap_local(rp, D, (vir_bytes) scp,
|
---|
| 54 | (vir_bytes) sizeof(struct sigcontext));
|
---|
| 55 | if (dst_phys == 0) return(EFAULT);
|
---|
| 56 | phys_copy(vir2phys(&sc), dst_phys, (phys_bytes) sizeof(struct sigcontext));
|
---|
| 57 |
|
---|
| 58 | /* Initialize the sigframe structure. */
|
---|
| 59 | frp = (struct sigframe *) scp - 1;
|
---|
| 60 | fr.sf_scpcopy = scp;
|
---|
| 61 | fr.sf_retadr2= (void (*)()) rp->p_reg.pc;
|
---|
| 62 | fr.sf_fp = rp->p_reg.fp;
|
---|
| 63 | rp->p_reg.fp = (reg_t) &frp->sf_fp;
|
---|
| 64 | fr.sf_scp = scp;
|
---|
| 65 | fr.sf_code = 0; /* XXX - should be used for type of FP exception */
|
---|
| 66 | fr.sf_signo = smsg.sm_signo;
|
---|
| 67 | fr.sf_retadr = (void (*)()) smsg.sm_sigreturn;
|
---|
| 68 |
|
---|
| 69 | /* Copy the sigframe structure to the user's stack. */
|
---|
| 70 | dst_phys = umap_local(rp, D, (vir_bytes) frp,
|
---|
| 71 | (vir_bytes) sizeof(struct sigframe));
|
---|
| 72 | if (dst_phys == 0) return(EFAULT);
|
---|
| 73 | phys_copy(vir2phys(&fr), dst_phys, (phys_bytes) sizeof(struct sigframe));
|
---|
| 74 |
|
---|
| 75 | /* Reset user registers to execute the signal handler. */
|
---|
| 76 | rp->p_reg.sp = (reg_t) frp;
|
---|
| 77 | rp->p_reg.pc = (reg_t) smsg.sm_sighandler;
|
---|
| 78 |
|
---|
| 79 | return(OK);
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | #endif /* USE_SIGSEND */
|
---|
| 83 |
|
---|