source: trunk/minix/kernel/system/do_sigsend.c@ 11

Last change on this file since 11 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 2.7 KB
Line 
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_ENDPT # 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 *===========================================================================*/
21PUBLIC int do_sigsend(m_ptr)
22message *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 int proc;
32
33 if (!isokendpt(m_ptr->SIG_ENDPT, &proc)) return(EINVAL);
34 if (iskerneln(proc)) return(EPERM);
35 rp = proc_addr(proc);
36
37 /* Get the sigmsg structure into our address space. */
38 src_phys = umap_local(proc_addr(PM_PROC_NR), D, (vir_bytes)
39 m_ptr->SIG_CTXT_PTR, (vir_bytes) sizeof(struct sigmsg));
40 if (src_phys == 0) return(EFAULT);
41 phys_copy(src_phys,vir2phys(&smsg),(phys_bytes) sizeof(struct sigmsg));
42
43 /* Compute the user stack pointer where sigcontext will be stored. */
44 scp = (struct sigcontext *) smsg.sm_stkptr - 1;
45
46 /* Copy the registers to the sigcontext structure. */
47 memcpy(&sc.sc_regs, (char *) &rp->p_reg, sizeof(struct sigregs));
48
49 /* Finish the sigcontext initialization. */
50 sc.sc_flags = SC_SIGCONTEXT;
51 sc.sc_mask = smsg.sm_mask;
52
53 /* Copy the sigcontext structure to the user's stack. */
54 dst_phys = umap_local(rp, D, (vir_bytes) scp,
55 (vir_bytes) sizeof(struct sigcontext));
56 if (dst_phys == 0) return(EFAULT);
57 phys_copy(vir2phys(&sc), dst_phys, (phys_bytes) sizeof(struct sigcontext));
58
59 /* Initialize the sigframe structure. */
60 frp = (struct sigframe *) scp - 1;
61 fr.sf_scpcopy = scp;
62 fr.sf_retadr2= (void (*)()) rp->p_reg.pc;
63 fr.sf_fp = rp->p_reg.fp;
64 rp->p_reg.fp = (reg_t) &frp->sf_fp;
65 fr.sf_scp = scp;
66 fr.sf_code = 0; /* XXX - should be used for type of FP exception */
67 fr.sf_signo = smsg.sm_signo;
68 fr.sf_retadr = (void (*)()) smsg.sm_sigreturn;
69
70 /* Copy the sigframe structure to the user's stack. */
71 dst_phys = umap_local(rp, D, (vir_bytes) frp,
72 (vir_bytes) sizeof(struct sigframe));
73 if (dst_phys == 0) return(EFAULT);
74 phys_copy(vir2phys(&fr), dst_phys, (phys_bytes) sizeof(struct sigframe));
75
76 /* Reset user registers to execute the signal handler. */
77 rp->p_reg.sp = (reg_t) frp;
78 rp->p_reg.pc = (reg_t) smsg.sm_sighandler;
79
80 return(OK);
81}
82
83#endif /* USE_SIGSEND */
84
Note: See TracBrowser for help on using the repository browser.