2005-10-14 10:58:59 +02:00
|
|
|
/* The kernel call that is implemented in this file:
|
2013-11-28 19:22:37 +01:00
|
|
|
* m_type: SYS_SIGSEND
|
2005-07-14 17:12:12 +02:00
|
|
|
*
|
2005-10-14 10:58:59 +02:00
|
|
|
* The parameters for this kernel call are:
|
2013-11-28 19:22:37 +01:00
|
|
|
* m_sigcalls.endpt # process to call signal handler
|
|
|
|
* m_sigcalls.sigctx # pointer to sigcontext structure
|
2005-07-14 17:12:12 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-04-02 00:22:33 +02:00
|
|
|
#include "kernel/system.h"
|
2005-07-14 17:12:12 +02:00
|
|
|
#include <signal.h>
|
2005-07-19 17:01:47 +02:00
|
|
|
#include <string.h>
|
2005-07-14 17:12:12 +02:00
|
|
|
|
|
|
|
#if USE_SIGSEND
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_sigsend *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int do_sigsend(struct proc * caller, message * m_ptr)
|
2005-07-14 17:12:12 +02:00
|
|
|
{
|
|
|
|
/* Handle sys_sigsend, POSIX-style signal handling. */
|
|
|
|
|
|
|
|
struct sigmsg smsg;
|
|
|
|
register struct proc *rp;
|
2013-12-11 00:47:22 +01:00
|
|
|
struct sigframe_sigcontext fr, *frp;
|
2009-09-15 11:57:22 +02:00
|
|
|
int proc_nr, r;
|
2014-02-27 18:30:45 +01:00
|
|
|
#if defined(__i386__)
|
|
|
|
reg_t new_fp;
|
|
|
|
#endif
|
2005-07-14 17:12:12 +02:00
|
|
|
|
2013-11-28 19:22:37 +01:00
|
|
|
if (!isokendpt(m_ptr->m_sigcalls.endpt, &proc_nr)) return EINVAL;
|
|
|
|
if (iskerneln(proc_nr)) return EPERM;
|
2009-09-15 11:57:22 +02:00
|
|
|
rp = proc_addr(proc_nr);
|
2005-07-14 17:12:12 +02:00
|
|
|
|
|
|
|
/* Get the sigmsg structure into our address space. */
|
2013-11-28 19:22:37 +01:00
|
|
|
if ((r = data_copy_vmcheck(caller, caller->p_endpoint,
|
|
|
|
(vir_bytes)m_ptr->m_sigcalls.sigctx, KERNEL,
|
|
|
|
(vir_bytes)&smsg, (phys_bytes) sizeof(struct sigmsg))) != OK)
|
2008-11-19 13:26:10 +01:00
|
|
|
return r;
|
2005-07-14 17:12:12 +02:00
|
|
|
|
2014-02-27 18:30:45 +01:00
|
|
|
/* WARNING: the following code may be run more than once even for a single
|
|
|
|
* signal delivery. Do not change registers here. See the comment below.
|
|
|
|
*/
|
|
|
|
|
2013-12-11 00:47:22 +01:00
|
|
|
/* Compute the user stack pointer where sigframe will start. */
|
2012-08-29 17:31:38 +02:00
|
|
|
smsg.sm_stkptr = arch_get_sp(rp);
|
2013-12-11 00:47:22 +01:00
|
|
|
frp = (struct sigframe_sigcontext *) smsg.sm_stkptr - 1;
|
2005-07-14 17:12:12 +02:00
|
|
|
|
|
|
|
/* Copy the registers to the sigcontext structure. */
|
2013-12-11 00:47:22 +01:00
|
|
|
memset(&fr, 0, sizeof(fr));
|
|
|
|
fr.sf_scp = &frp->sf_sc;
|
2013-01-06 19:18:41 +01:00
|
|
|
|
|
|
|
#if defined(__i386__)
|
2013-12-11 00:47:22 +01:00
|
|
|
fr.sf_sc.sc_gs = rp->p_reg.gs;
|
|
|
|
fr.sf_sc.sc_fs = rp->p_reg.fs;
|
|
|
|
fr.sf_sc.sc_es = rp->p_reg.es;
|
|
|
|
fr.sf_sc.sc_ds = rp->p_reg.ds;
|
|
|
|
fr.sf_sc.sc_edi = rp->p_reg.di;
|
|
|
|
fr.sf_sc.sc_esi = rp->p_reg.si;
|
|
|
|
fr.sf_sc.sc_ebp = rp->p_reg.fp;
|
|
|
|
fr.sf_sc.sc_ebx = rp->p_reg.bx;
|
|
|
|
fr.sf_sc.sc_edx = rp->p_reg.dx;
|
|
|
|
fr.sf_sc.sc_ecx = rp->p_reg.cx;
|
|
|
|
fr.sf_sc.sc_eax = rp->p_reg.retreg;
|
|
|
|
fr.sf_sc.sc_eip = rp->p_reg.pc;
|
|
|
|
fr.sf_sc.sc_cs = rp->p_reg.cs;
|
|
|
|
fr.sf_sc.sc_eflags = rp->p_reg.psw;
|
|
|
|
fr.sf_sc.sc_esp = rp->p_reg.sp;
|
|
|
|
fr.sf_sc.sc_ss = rp->p_reg.ss;
|
|
|
|
fr.sf_fp = rp->p_reg.fp;
|
|
|
|
fr.sf_signum = smsg.sm_signo;
|
2014-02-27 18:30:45 +01:00
|
|
|
new_fp = (reg_t) &frp->sf_fp;
|
2013-12-11 00:47:22 +01:00
|
|
|
fr.sf_scpcopy = fr.sf_scp;
|
|
|
|
fr.sf_ra_sigreturn = smsg.sm_sigreturn;
|
|
|
|
fr.sf_ra= rp->p_reg.pc;
|
|
|
|
|
|
|
|
fr.sf_sc.trap_style = rp->p_seg.p_kern_trap_style;
|
2013-01-06 19:18:41 +01:00
|
|
|
|
2013-12-11 00:47:22 +01:00
|
|
|
if (fr.sf_sc.trap_style == KTS_NONE) {
|
2013-01-06 19:18:41 +01:00
|
|
|
printf("do_sigsend: sigsend an unsaved process\n");
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
2014-02-27 18:30:45 +01:00
|
|
|
if (proc_used_fpu(rp)) {
|
|
|
|
/* save the FPU context before saving it to the sig context */
|
|
|
|
save_fpu(rp);
|
|
|
|
memcpy(&fr.sf_sc.sc_fpu_state, rp->p_seg.fpu_state, FPU_XFP_SIZE);
|
|
|
|
}
|
2013-01-06 19:18:41 +01:00
|
|
|
#endif
|
2005-07-14 17:12:12 +02:00
|
|
|
|
2013-12-11 00:47:22 +01:00
|
|
|
#if defined(__arm__)
|
|
|
|
fr.sf_sc.sc_spsr = rp->p_reg.psr;
|
|
|
|
fr.sf_sc.sc_r0 = rp->p_reg.retreg;
|
|
|
|
fr.sf_sc.sc_r1 = rp->p_reg.r1;
|
|
|
|
fr.sf_sc.sc_r2 = rp->p_reg.r2;
|
|
|
|
fr.sf_sc.sc_r3 = rp->p_reg.r3;
|
|
|
|
fr.sf_sc.sc_r4 = rp->p_reg.r4;
|
|
|
|
fr.sf_sc.sc_r5 = rp->p_reg.r5;
|
|
|
|
fr.sf_sc.sc_r6 = rp->p_reg.r6;
|
|
|
|
fr.sf_sc.sc_r7 = rp->p_reg.r7;
|
|
|
|
fr.sf_sc.sc_r8 = rp->p_reg.r8;
|
|
|
|
fr.sf_sc.sc_r9 = rp->p_reg.r9;
|
|
|
|
fr.sf_sc.sc_r10 = rp->p_reg.r10;
|
|
|
|
fr.sf_sc.sc_r11 = rp->p_reg.fp;
|
|
|
|
fr.sf_sc.sc_r12 = rp->p_reg.r12;
|
|
|
|
fr.sf_sc.sc_usr_sp = rp->p_reg.sp;
|
|
|
|
fr.sf_sc.sc_usr_lr = rp->p_reg.lr;
|
|
|
|
fr.sf_sc.sc_svc_lr = 0; /* ? */
|
|
|
|
fr.sf_sc.sc_pc = rp->p_reg.pc; /* R15 */
|
|
|
|
#endif
|
2005-07-14 17:12:12 +02:00
|
|
|
|
2013-12-11 00:47:22 +01:00
|
|
|
/* Finish the sigcontext initialization. */
|
|
|
|
fr.sf_sc.sc_mask = smsg.sm_mask;
|
|
|
|
fr.sf_sc.sc_flags = rp->p_misc_flags & MF_FPU_INITIALIZED;
|
|
|
|
fr.sf_sc.sc_magic = SC_MAGIC;
|
2005-07-14 17:12:12 +02:00
|
|
|
|
|
|
|
/* Initialize the sigframe structure. */
|
2013-12-11 00:47:22 +01:00
|
|
|
fpu_sigcontext(rp, &fr, &fr.sf_sc);
|
2005-07-14 17:12:12 +02:00
|
|
|
|
2014-02-27 18:30:45 +01:00
|
|
|
/* Copy the sigframe structure to the user's stack. */
|
|
|
|
if ((r = data_copy_vmcheck(caller, KERNEL, (vir_bytes)&fr,
|
|
|
|
m_ptr->m_sigcalls.endpt, (vir_bytes)frp,
|
|
|
|
(vir_bytes)sizeof(struct sigframe_sigcontext))) != OK)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
/* WARNING: up to the statement above, the code may run multiple times, since
|
|
|
|
* copying out the frame/context may fail with VMSUSPEND the first time. For
|
|
|
|
* that reason, changes to process registers *MUST* be deferred until after
|
|
|
|
* this last copy -- otherwise, these changes will be made several times,
|
|
|
|
* possibly leading to corrupted process state.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Reset user registers to execute the signal handler. */
|
|
|
|
rp->p_reg.sp = (reg_t) frp;
|
|
|
|
rp->p_reg.pc = (reg_t) smsg.sm_sighandler;
|
|
|
|
|
|
|
|
#if defined(__i386__)
|
|
|
|
rp->p_reg.fp = new_fp;
|
|
|
|
#elif defined(__arm__)
|
2013-01-30 03:13:24 +01:00
|
|
|
/* use the ARM link register to set the return address from the signal
|
|
|
|
* handler
|
|
|
|
*/
|
2013-12-11 00:47:22 +01:00
|
|
|
rp->p_reg.lr = (reg_t) smsg.sm_sigreturn;
|
2013-02-04 04:08:12 +01:00
|
|
|
if(rp->p_reg.lr & 1) { printf("sigsend: LSB LR makes no sense.\n"); }
|
|
|
|
|
|
|
|
/* pass signal handler parameters in registers */
|
2013-12-11 00:47:22 +01:00
|
|
|
rp->p_reg.retreg = (reg_t) smsg.sm_signo;
|
|
|
|
rp->p_reg.r1 = 0; /* sf_code */
|
2013-02-04 04:08:12 +01:00
|
|
|
rp->p_reg.r2 = (reg_t) fr.sf_scp;
|
2013-02-05 17:17:19 +01:00
|
|
|
rp->p_misc_flags |= MF_CONTEXT_SET;
|
2013-01-30 03:13:24 +01:00
|
|
|
#endif
|
|
|
|
|
2009-12-02 14:01:48 +01:00
|
|
|
/* Signal handler should get clean FPU. */
|
|
|
|
rp->p_misc_flags &= ~MF_FPU_INITIALIZED;
|
|
|
|
|
2009-11-10 10:11:13 +01:00
|
|
|
if(!RTS_ISSET(rp, RTS_PROC_STOP)) {
|
2010-03-03 16:45:01 +01:00
|
|
|
printf("system: warning: sigsend a running process\n");
|
|
|
|
printf("caller stack: ");
|
2008-11-19 13:26:10 +01:00
|
|
|
proc_stacktrace(caller);
|
|
|
|
}
|
2006-10-25 15:38:31 +02:00
|
|
|
|
2013-11-28 19:22:37 +01:00
|
|
|
return OK;
|
2005-07-14 17:12:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* USE_SIGSEND */
|
|
|
|
|