panic() cleanup.
[minix.git] / kernel / system / do_runctl.c
blobd3ba0890d0c5e905dab91dd94c480ef68f971f3a
1 /* The kernel call implemented in this file:
2 * m_type: SYS_RUNCTL
4 * The parameters for this kernel call are:
5 * m1_i1: RC_ENDPT process number to control
6 * m1_i2: RC_ACTION stop or resume the process
7 * m1_i3: RC_FLAGS request flags
8 */
10 #include "../system.h"
12 #if USE_RUNCTL
14 /*===========================================================================*
15 * do_runctl *
16 *===========================================================================*/
17 PUBLIC int do_runctl(struct proc * caller, message * m_ptr)
19 /* Control a process's RTS_PROC_STOP flag. Used for process management.
20 * If the process is queued sending a message or stopped for system call
21 * tracing, and the RC_DELAY request flag is given, set MF_SIG_DELAY instead
22 * of RTS_PROC_STOP, and send a SIGNDELAY signal later when the process is done
23 * sending (ending the delay). Used by PM for safe signal delivery.
25 int proc_nr, action, flags, delayed;
26 register struct proc *rp;
28 /* Extract the message parameters and do sanity checking. */
29 if (!isokendpt(m_ptr->RC_ENDPT, &proc_nr)) return(EINVAL);
30 if (iskerneln(proc_nr)) return(EPERM);
31 rp = proc_addr(proc_nr);
33 action = m_ptr->RC_ACTION;
34 flags = m_ptr->RC_FLAGS;
36 /* Is the target sending or syscall-traced? Then set MF_SIG_DELAY instead.
37 * Do this only when the RC_DELAY flag is set in the request flags field.
38 * The process will not become runnable before PM has called SYS_ENDKSIG.
39 * Note that asynchronous messages are not covered: a process using SENDA
40 * should not also install signal handlers *and* expect POSIX compliance.
42 if (action == RC_STOP && (flags & RC_DELAY)) {
43 RTS_SET(rp, RTS_SYS_LOCK);
45 if (RTS_ISSET(rp, RTS_SENDING) || (rp->p_misc_flags & MF_SC_DEFER))
46 rp->p_misc_flags |= MF_SIG_DELAY;
48 delayed = (rp->p_misc_flags & MF_SIG_DELAY);
50 RTS_UNSET(rp, RTS_SYS_LOCK);
52 if (delayed) return(EBUSY);
55 /* Either set or clear the stop flag. */
56 switch (action) {
57 case RC_STOP:
58 RTS_SET(rp, RTS_PROC_STOP);
59 break;
60 case RC_RESUME:
61 RTS_UNSET(rp, RTS_PROC_STOP);
62 break;
63 default:
64 return(EINVAL);
67 return(OK);
70 #endif /* USE_RUNCTL */