1*433d6423SLionel Sambuc /* The kernel call implemented in this file:
2*433d6423SLionel Sambuc * m_type: SYS_RUNCTL
3*433d6423SLionel Sambuc *
4*433d6423SLionel Sambuc * The parameters for this kernel call are:
5*433d6423SLionel Sambuc * m1_i1: RC_ENDPT process number to control
6*433d6423SLionel Sambuc * m1_i2: RC_ACTION stop or resume the process
7*433d6423SLionel Sambuc * m1_i3: RC_FLAGS request flags
8*433d6423SLionel Sambuc */
9*433d6423SLionel Sambuc
10*433d6423SLionel Sambuc #include "kernel/system.h"
11*433d6423SLionel Sambuc #include <assert.h>
12*433d6423SLionel Sambuc
13*433d6423SLionel Sambuc #if USE_RUNCTL
14*433d6423SLionel Sambuc
15*433d6423SLionel Sambuc /*===========================================================================*
16*433d6423SLionel Sambuc * do_runctl *
17*433d6423SLionel Sambuc *===========================================================================*/
do_runctl(struct proc * caller,message * m_ptr)18*433d6423SLionel Sambuc int do_runctl(struct proc * caller, message * m_ptr)
19*433d6423SLionel Sambuc {
20*433d6423SLionel Sambuc /* Control a process's RTS_PROC_STOP flag. Used for process management.
21*433d6423SLionel Sambuc * If the process is queued sending a message or stopped for system call
22*433d6423SLionel Sambuc * tracing, and the RC_DELAY request flag is given, set MF_SIG_DELAY instead
23*433d6423SLionel Sambuc * of RTS_PROC_STOP, and send a SIGSNDELAY signal later when the process is done
24*433d6423SLionel Sambuc * sending (ending the delay). Used by PM for safe signal delivery.
25*433d6423SLionel Sambuc */
26*433d6423SLionel Sambuc int proc_nr, action, flags;
27*433d6423SLionel Sambuc register struct proc *rp;
28*433d6423SLionel Sambuc
29*433d6423SLionel Sambuc /* Extract the message parameters and do sanity checking. */
30*433d6423SLionel Sambuc if (!isokendpt(m_ptr->RC_ENDPT, &proc_nr)) return(EINVAL);
31*433d6423SLionel Sambuc if (iskerneln(proc_nr)) return(EPERM);
32*433d6423SLionel Sambuc rp = proc_addr(proc_nr);
33*433d6423SLionel Sambuc
34*433d6423SLionel Sambuc action = m_ptr->RC_ACTION;
35*433d6423SLionel Sambuc flags = m_ptr->RC_FLAGS;
36*433d6423SLionel Sambuc
37*433d6423SLionel Sambuc /* Is the target sending or syscall-traced? Then set MF_SIG_DELAY instead.
38*433d6423SLionel Sambuc * Do this only when the RC_DELAY flag is set in the request flags field.
39*433d6423SLionel Sambuc * The process will not become runnable before PM has called SYS_ENDKSIG.
40*433d6423SLionel Sambuc * Note that asynchronous messages are not covered: a process using SENDA
41*433d6423SLionel Sambuc * should not also install signal handlers *and* expect POSIX compliance.
42*433d6423SLionel Sambuc */
43*433d6423SLionel Sambuc
44*433d6423SLionel Sambuc if (action == RC_STOP && (flags & RC_DELAY)) {
45*433d6423SLionel Sambuc if (RTS_ISSET(rp, RTS_SENDING) || (rp->p_misc_flags & MF_SC_DEFER))
46*433d6423SLionel Sambuc rp->p_misc_flags |= MF_SIG_DELAY;
47*433d6423SLionel Sambuc
48*433d6423SLionel Sambuc if (rp->p_misc_flags & MF_SIG_DELAY)
49*433d6423SLionel Sambuc return (EBUSY);
50*433d6423SLionel Sambuc }
51*433d6423SLionel Sambuc
52*433d6423SLionel Sambuc /* Either set or clear the stop flag. */
53*433d6423SLionel Sambuc switch (action) {
54*433d6423SLionel Sambuc case RC_STOP:
55*433d6423SLionel Sambuc #if CONFIG_SMP
56*433d6423SLionel Sambuc /* check if we must stop a process on a different CPU */
57*433d6423SLionel Sambuc if (rp->p_cpu != cpuid) {
58*433d6423SLionel Sambuc smp_schedule_stop_proc(rp);
59*433d6423SLionel Sambuc break;
60*433d6423SLionel Sambuc }
61*433d6423SLionel Sambuc #endif
62*433d6423SLionel Sambuc RTS_SET(rp, RTS_PROC_STOP);
63*433d6423SLionel Sambuc break;
64*433d6423SLionel Sambuc case RC_RESUME:
65*433d6423SLionel Sambuc assert(RTS_ISSET(rp, RTS_PROC_STOP));
66*433d6423SLionel Sambuc RTS_UNSET(rp, RTS_PROC_STOP);
67*433d6423SLionel Sambuc break;
68*433d6423SLionel Sambuc default:
69*433d6423SLionel Sambuc return(EINVAL);
70*433d6423SLionel Sambuc }
71*433d6423SLionel Sambuc
72*433d6423SLionel Sambuc return(OK);
73*433d6423SLionel Sambuc }
74*433d6423SLionel Sambuc
75*433d6423SLionel Sambuc #endif /* USE_RUNCTL */
76*433d6423SLionel Sambuc
77