tty: don't use custom kputc; this fixes tty printf()s.
[minix.git] / servers / pm / signal.c
blob53d30d1f5c9183e00f5eefb072f61aca8848c1fc
1 /* This file handles signals, which are asynchronous events and are generally
2 * a messy and unpleasant business. Signals can be generated by the KILL
3 * system call, or from the keyboard (SIGINT) or from the clock (SIGALRM).
4 * In all cases control eventually passes to check_sig() to see which processes
5 * can be signaled. The actual signaling is done by sig_proc().
7 * The entry points into this file are:
8 * do_sigaction: perform the SIGACTION system call
9 * do_sigpending: perform the SIGPENDING system call
10 * do_sigprocmask: perform the SIGPROCMASK system call
11 * do_sigreturn: perform the SIGRETURN system call
12 * do_sigsuspend: perform the SIGSUSPEND system call
13 * do_kill: perform the KILL system call
14 * do_pause: perform the PAUSE system call
15 * process_ksig: process a signal an behalf of the kernel
16 * sig_proc: interrupt or terminate a signaled process
17 * check_sig: check which processes to signal with sig_proc()
18 * check_pending: check if a pending signal can now be delivered
19 * restart_sigs: restart signal work after finishing a FS call
22 #include "pm.h"
23 #include <sys/stat.h>
24 #include <sys/ptrace.h>
25 #include <minix/callnr.h>
26 #include <minix/endpoint.h>
27 #include <minix/com.h>
28 #include <minix/vm.h>
29 #include <signal.h>
30 #include <sys/resource.h>
31 #include <sys/sigcontext.h>
32 #include <string.h>
33 #include "mproc.h"
34 #include "param.h"
36 FORWARD _PROTOTYPE( void unpause, (struct mproc *rmp) );
37 FORWARD _PROTOTYPE( int sig_send, (struct mproc *rmp, int signo) );
38 FORWARD _PROTOTYPE( void sig_proc_exit, (struct mproc *rmp, int signo) );
40 /*===========================================================================*
41 * do_sigaction *
42 *===========================================================================*/
43 PUBLIC int do_sigaction()
45 int r;
46 struct sigaction svec;
47 struct sigaction *svp;
49 if (m_in.sig_nr == SIGKILL) return(OK);
50 if (m_in.sig_nr < 1 || m_in.sig_nr >= _NSIG) return(EINVAL);
52 svp = &mp->mp_sigact[m_in.sig_nr];
53 if ((struct sigaction *) m_in.sig_osa != (struct sigaction *) NULL) {
54 r = sys_datacopy(PM_PROC_NR,(vir_bytes) svp,
55 who_e, (vir_bytes) m_in.sig_osa, (phys_bytes) sizeof(svec));
56 if (r != OK) return(r);
59 if ((struct sigaction *) m_in.sig_nsa == (struct sigaction *) NULL)
60 return(OK);
62 /* Read in the sigaction structure. */
63 r = sys_datacopy(who_e, (vir_bytes) m_in.sig_nsa,
64 PM_PROC_NR, (vir_bytes) &svec, (phys_bytes) sizeof(svec));
65 if (r != OK) return(r);
67 if (svec.sa_handler == SIG_IGN) {
68 sigaddset(&mp->mp_ignore, m_in.sig_nr);
69 sigdelset(&mp->mp_sigpending, m_in.sig_nr);
70 sigdelset(&mp->mp_catch, m_in.sig_nr);
71 } else if (svec.sa_handler == SIG_DFL) {
72 sigdelset(&mp->mp_ignore, m_in.sig_nr);
73 sigdelset(&mp->mp_catch, m_in.sig_nr);
74 } else {
75 sigdelset(&mp->mp_ignore, m_in.sig_nr);
76 sigaddset(&mp->mp_catch, m_in.sig_nr);
78 mp->mp_sigact[m_in.sig_nr].sa_handler = svec.sa_handler;
79 sigdelset(&svec.sa_mask, SIGKILL);
80 sigdelset(&svec.sa_mask, SIGSTOP);
81 mp->mp_sigact[m_in.sig_nr].sa_mask = svec.sa_mask;
82 mp->mp_sigact[m_in.sig_nr].sa_flags = svec.sa_flags;
83 mp->mp_sigreturn = (vir_bytes) m_in.sig_ret;
84 return(OK);
87 /*===========================================================================*
88 * do_sigpending *
89 *===========================================================================*/
90 PUBLIC int do_sigpending()
92 mp->mp_reply.reply_mask = (long) mp->mp_sigpending;
93 return OK;
96 /*===========================================================================*
97 * do_sigprocmask *
98 *===========================================================================*/
99 PUBLIC int do_sigprocmask()
101 /* Note that the library interface passes the actual mask in sigmask_set,
102 * not a pointer to the mask, in order to save a copy. Similarly,
103 * the old mask is placed in the return message which the library
104 * interface copies (if requested) to the user specified address.
106 * The library interface must set SIG_INQUIRE if the 'act' argument
107 * is NULL.
109 * KILL and STOP can't be masked.
112 int i;
114 mp->mp_reply.reply_mask = (long) mp->mp_sigmask;
116 switch (m_in.sig_how) {
117 case SIG_BLOCK:
118 sigdelset((sigset_t *)&m_in.sig_set, SIGKILL);
119 sigdelset((sigset_t *)&m_in.sig_set, SIGSTOP);
120 for (i = 1; i < _NSIG; i++) {
121 if (sigismember((sigset_t *)&m_in.sig_set, i))
122 sigaddset(&mp->mp_sigmask, i);
124 break;
126 case SIG_UNBLOCK:
127 for (i = 1; i < _NSIG; i++) {
128 if (sigismember((sigset_t *)&m_in.sig_set, i))
129 sigdelset(&mp->mp_sigmask, i);
131 check_pending(mp);
132 break;
134 case SIG_SETMASK:
135 sigdelset((sigset_t *) &m_in.sig_set, SIGKILL);
136 sigdelset((sigset_t *) &m_in.sig_set, SIGSTOP);
137 mp->mp_sigmask = (sigset_t) m_in.sig_set;
138 check_pending(mp);
139 break;
141 case SIG_INQUIRE:
142 break;
144 default:
145 return(EINVAL);
146 break;
148 return OK;
151 /*===========================================================================*
152 * do_sigsuspend *
153 *===========================================================================*/
154 PUBLIC int do_sigsuspend()
156 mp->mp_sigmask2 = mp->mp_sigmask; /* save the old mask */
157 mp->mp_sigmask = (sigset_t) m_in.sig_set;
158 sigdelset(&mp->mp_sigmask, SIGKILL);
159 sigdelset(&mp->mp_sigmask, SIGSTOP);
160 mp->mp_flags |= SIGSUSPENDED;
161 check_pending(mp);
162 return(SUSPEND);
165 /*===========================================================================*
166 * do_sigreturn *
167 *===========================================================================*/
168 PUBLIC int do_sigreturn()
170 /* A user signal handler is done. Restore context and check for
171 * pending unblocked signals.
174 int r;
176 mp->mp_sigmask = (sigset_t) m_in.sig_set;
177 sigdelset(&mp->mp_sigmask, SIGKILL);
178 sigdelset(&mp->mp_sigmask, SIGSTOP);
180 r = sys_sigreturn(who_e, (struct sigmsg *) m_in.sig_context);
181 check_pending(mp);
182 return(r);
185 /*===========================================================================*
186 * do_kill *
187 *===========================================================================*/
188 PUBLIC int do_kill()
190 /* Perform the kill(pid, signo) system call. */
192 return check_sig(m_in.pid, m_in.sig_nr, FALSE /* ksig */);
195 /*===========================================================================*
196 * do_srv_kill *
197 *===========================================================================*/
198 PUBLIC int do_srv_kill()
200 /* Perform the srv_kill(pid, signo) system call. */
202 /* Only RS is allowed to use srv_kill. */
203 if (mp->mp_endpoint != RS_PROC_NR)
204 return EPERM;
206 /* Pretend the signal comes from the kernel when RS wants to deliver a signal
207 * to a system process. RS sends a SIGKILL when it wants to perform cleanup.
208 * In that case, ksig == TRUE forces PM to exit the process immediately.
210 return check_sig(m_in.pid, m_in.sig_nr, TRUE /* ksig */);
213 /*===========================================================================*
214 * process_ksig *
215 *===========================================================================*/
216 PUBLIC int process_ksig(int proc_nr_e, int signo)
218 register struct mproc *rmp;
219 int proc_nr;
220 pid_t proc_id, id;
222 if(pm_isokendpt(proc_nr_e, &proc_nr) != OK || proc_nr < 0) {
223 printf("PM: process_ksig: %d?? not ok\n", proc_nr_e);
224 return EDEADSRCDST; /* process is gone. */
226 rmp = &mproc[proc_nr];
227 if ((rmp->mp_flags & (IN_USE | EXITING)) != IN_USE) {
228 #if 0
229 printf("PM: process_ksig: %d?? exiting / not in use\n", proc_nr_e);
230 #endif
231 return EDEADSRCDST; /* process is gone. */
233 proc_id = rmp->mp_pid;
234 mp = &mproc[0]; /* pretend signals are from PM */
235 mp->mp_procgrp = rmp->mp_procgrp; /* get process group right */
237 /* For SIGVTALRM and SIGPROF, see if we need to restart a
238 * virtual timer. For SIGINT, SIGWINCH and SIGQUIT, use proc_id 0
239 * to indicate a broadcast to the recipient's process group. For
240 * SIGKILL, use proc_id -1 to indicate a systemwide broadcast.
242 switch (signo) {
243 case SIGINT:
244 case SIGQUIT:
245 case SIGWINCH:
246 id = 0; break; /* broadcast to process group */
247 case SIGVTALRM:
248 case SIGPROF:
249 check_vtimer(proc_nr, signo);
250 /* fall-through */
251 default:
252 id = proc_id;
253 break;
255 check_sig(id, signo, TRUE /* ksig */);
257 /* If SIGSNDELAY is set, an earlier sys_stop() failed because the process was
258 * still sending, and the kernel hereby tells us that the process is now done
259 * with that. We can now try to resume what we planned to do in the first
260 * place: set up a signal handler. However, the process's message may have
261 * been a call to PM, in which case the process may have changed any of its
262 * signal settings. The process may also have forked, exited etcetera.
264 if (signo == SIGSNDELAY && (rmp->mp_flags & DELAY_CALL)) {
265 rmp->mp_flags &= ~DELAY_CALL;
267 if (rmp->mp_flags & (FS_CALL | PM_SIG_PENDING))
268 panic("process_ksig: bad process state");
270 /* Process as many normal signals as possible. */
271 check_pending(rmp);
273 if (rmp->mp_flags & DELAY_CALL)
274 panic("process_ksig: multiple delay calls?");
277 /* See if the process is still alive */
278 if ((mproc[proc_nr].mp_flags & (IN_USE | EXITING)) == IN_USE) {
279 return OK; /* signal has been delivered */
281 else {
282 return EDEADSRCDST; /* process is gone */
286 /*===========================================================================*
287 * do_pause *
288 *===========================================================================*/
289 PUBLIC int do_pause()
291 /* Perform the pause() system call. */
293 mp->mp_flags |= PAUSED;
294 return(SUSPEND);
297 /*===========================================================================*
298 * sig_proc *
299 *===========================================================================*/
300 PUBLIC void sig_proc(rmp, signo, trace, ksig)
301 register struct mproc *rmp; /* pointer to the process to be signaled */
302 int signo; /* signal to send to process (1 to _NSIG-1) */
303 int trace; /* pass signal to tracer first? */
304 int ksig; /* non-zero means signal comes from kernel */
306 /* Send a signal to a process. Check to see if the signal is to be caught,
307 * ignored, tranformed into a message (for system processes) or blocked.
308 * - If the signal is to be transformed into a message, request the KERNEL to
309 * send the target process a system notification with the pending signal as an
310 * argument.
311 * - If the signal is to be caught, request the KERNEL to push a sigcontext
312 * structure and a sigframe structure onto the catcher's stack. Also, KERNEL
313 * will reset the program counter and stack pointer, so that when the process
314 * next runs, it will be executing the signal handler. When the signal handler
315 * returns, sigreturn(2) will be called. Then KERNEL will restore the signal
316 * context from the sigcontext structure.
317 * If there is insufficient stack space, kill the process.
319 int r, slot, badignore;
321 slot = (int) (rmp - mproc);
322 if ((rmp->mp_flags & (IN_USE | EXITING)) != IN_USE) {
323 printf("PM: signal %d sent to exiting process %d\n", signo, slot);
324 panic("");
327 if (trace == TRUE && rmp->mp_tracer != NO_TRACER && signo != SIGKILL) {
328 /* Signal should be passed to the debugger first.
329 * This happens before any checks on block/ignore masks; otherwise,
330 * the process itself could block/ignore debugger signals.
333 sigaddset(&rmp->mp_sigtrace, signo);
335 if (!(rmp->mp_flags & STOPPED))
336 stop_proc(rmp, signo); /* a signal causes it to stop */
338 return;
341 if (rmp->mp_flags & FS_CALL) {
342 sigaddset(&rmp->mp_sigpending, signo);
344 if (!(rmp->mp_flags & PM_SIG_PENDING)) {
345 /* No delay calls: FS_CALL implies the process called us. */
346 if ((r = sys_stop(rmp->mp_endpoint)) != OK)
347 panic("sys_stop failed: %d", r);
349 rmp->mp_flags |= PM_SIG_PENDING;
352 return;
355 /* Handle system signals for system processes first. */
356 if(rmp->mp_flags & PRIV_PROC) {
357 /* System signals have always to go through the kernel first to let it
358 * pick the right signal manager. If PM is the assigned signal manager,
359 * the signal will come back and will actually be processed.
361 if(!ksig) {
362 sys_kill(rmp->mp_endpoint, signo);
363 return;
366 /* Print stacktrace if necessary. */
367 if(SIGS_IS_STACKTRACE(signo)) {
368 sys_sysctl_stacktrace(rmp->mp_endpoint);
371 if(!SIGS_IS_TERMINATION(signo)) {
372 /* Translate every non-termination sys signal into a message. */
373 message m;
374 m.m_type = SIGS_SIGNAL_RECEIVED;
375 m.SIGS_SIG_NUM = signo;
376 asynsend3(rmp->mp_endpoint, &m, AMF_NOREPLY);
378 else {
379 /* Exit the process in case of termination system signal. */
380 sig_proc_exit(rmp, signo);
382 return;
385 /* Handle user processes now. See if the signal cannot be safely ignored. */
386 badignore = ksig && sigismember(&noign_sset, signo) && (
387 sigismember(&rmp->mp_ignore, signo) ||
388 sigismember(&rmp->mp_sigmask, signo));
390 if (!badignore && sigismember(&rmp->mp_ignore, signo)) {
391 /* Signal should be ignored. */
392 return;
394 if (!badignore && sigismember(&rmp->mp_sigmask, signo)) {
395 /* Signal should be blocked. */
396 sigaddset(&rmp->mp_sigpending, signo);
397 return;
400 if ((rmp->mp_flags & STOPPED) && signo != SIGKILL) {
401 /* If the process is stopped for a debugger, do not deliver any signals
402 * (except SIGKILL) in order not to confuse the debugger. The signals
403 * will be delivered using the check_pending() calls in do_trace().
405 sigaddset(&rmp->mp_sigpending, signo);
406 return;
408 if (!badignore && sigismember(&rmp->mp_catch, signo)) {
409 /* Signal is caught. First interrupt the process's current call, if
410 * applicable. This may involve a roundtrip to FS, in which case we'll
411 * have to check back later.
413 if (!(rmp->mp_flags & UNPAUSED)) {
414 unpause(rmp);
416 if (!(rmp->mp_flags & UNPAUSED)) {
417 /* not yet unpaused; continue later */
418 sigaddset(&rmp->mp_sigpending, signo);
420 return;
424 /* Then send the actual signal to the process, by setting up a signal
425 * handler.
427 if (sig_send(rmp, signo))
428 return;
430 /* We were unable to spawn a signal handler. Kill the process. */
432 else if (!badignore && sigismember(&ign_sset, signo)) {
433 /* Signal defaults to being ignored. */
434 return;
437 /* Terminate process */
438 sig_proc_exit(rmp, signo);
441 /*===========================================================================*
442 * sig_proc_exit *
443 *===========================================================================*/
444 PRIVATE void sig_proc_exit(rmp, signo)
445 struct mproc *rmp; /* process that must exit */
446 int signo; /* signal that caused termination */
448 rmp->mp_sigstatus = (char) signo;
449 if (sigismember(&core_sset, signo)) {
450 if(!(rmp->mp_flags & PRIV_PROC)) {
451 printf("PM: coredump signal %d for %d / %s\n", signo,
452 rmp->mp_pid, rmp->mp_name);
453 sys_sysctl_stacktrace(rmp->mp_endpoint);
455 exit_proc(rmp, 0, TRUE /*dump_core*/);
457 else {
458 exit_proc(rmp, 0, FALSE /*dump_core*/);
462 /*===========================================================================*
463 * check_sig *
464 *===========================================================================*/
465 PUBLIC int check_sig(proc_id, signo, ksig)
466 pid_t proc_id; /* pid of proc to sig, or 0 or -1, or -pgrp */
467 int signo; /* signal to send to process (0 to _NSIG-1) */
468 int ksig; /* non-zero means signal comes from kernel */
470 /* Check to see if it is possible to send a signal. The signal may have to be
471 * sent to a group of processes. This routine is invoked by the KILL system
472 * call, and also when the kernel catches a DEL or other signal.
475 register struct mproc *rmp;
476 int count; /* count # of signals sent */
477 int error_code;
479 if (signo < 0 || signo >= _NSIG) return(EINVAL);
481 /* Return EINVAL for attempts to send SIGKILL to INIT alone. */
482 if (proc_id == INIT_PID && signo == SIGKILL) return(EINVAL);
484 /* Signal RS first when broadcasting SIGTERM. */
485 if (proc_id == -1 && signo == SIGTERM)
486 sys_kill(RS_PROC_NR, signo);
488 /* Search the proc table for processes to signal. Start from the end of the
489 * table to analyze core system processes at the end when broadcasting.
490 * (See forkexit.c about pid magic.)
492 count = 0;
493 error_code = ESRCH;
494 for (rmp = &mproc[NR_PROCS-1]; rmp >= &mproc[0]; rmp--) {
495 if (!(rmp->mp_flags & IN_USE)) continue;
497 /* Check for selection. */
498 if (proc_id > 0 && proc_id != rmp->mp_pid) continue;
499 if (proc_id == 0 && mp->mp_procgrp != rmp->mp_procgrp) continue;
500 if (proc_id == -1 && rmp->mp_pid <= INIT_PID) continue;
501 if (proc_id < -1 && rmp->mp_procgrp != -proc_id) continue;
503 /* Do not kill servers and drivers when broadcasting SIGKILL. */
504 if (proc_id == -1 && signo == SIGKILL &&
505 (rmp->mp_flags & PRIV_PROC)) continue;
507 /* Disallow lethal signals sent by user processes to sys processes. */
508 if (!ksig && SIGS_IS_LETHAL(signo) && (rmp->mp_flags & PRIV_PROC)) {
509 error_code = EPERM;
510 continue;
513 /* Check for permission. */
514 if (mp->mp_effuid != SUPER_USER
515 && mp->mp_realuid != rmp->mp_realuid
516 && mp->mp_effuid != rmp->mp_realuid
517 && mp->mp_realuid != rmp->mp_effuid
518 && mp->mp_effuid != rmp->mp_effuid) {
519 error_code = EPERM;
520 continue;
523 count++;
524 if (signo == 0 || (rmp->mp_flags & EXITING)) continue;
526 /* 'sig_proc' will handle the disposition of the signal. The
527 * signal may be caught, blocked, ignored, or cause process
528 * termination, possibly with core dump.
530 sig_proc(rmp, signo, TRUE /*trace*/, ksig);
532 if (proc_id > 0) break; /* only one process being signaled */
535 /* If the calling process has killed itself, don't reply. */
536 if ((mp->mp_flags & (IN_USE | EXITING)) != IN_USE) return(SUSPEND);
537 return(count > 0 ? OK : error_code);
540 /*===========================================================================*
541 * check_pending *
542 *===========================================================================*/
543 PUBLIC void check_pending(rmp)
544 register struct mproc *rmp;
546 /* Check to see if any pending signals have been unblocked. Deliver as many
547 * of them as we can, until we have to wait for a reply from VFS first.
549 * There are several places in this file where the signal mask is
550 * changed. At each such place, check_pending() should be called to
551 * check for newly unblocked signals.
554 int i;
556 for (i = 1; i < _NSIG; i++) {
557 if (sigismember(&rmp->mp_sigpending, i) &&
558 !sigismember(&rmp->mp_sigmask, i)) {
559 sigdelset(&rmp->mp_sigpending, i);
560 sig_proc(rmp, i, FALSE /*trace*/, FALSE /* ksig */);
562 if (rmp->mp_flags & FS_CALL)
563 break;
568 /*===========================================================================*
569 * restart_sigs *
570 *===========================================================================*/
571 PUBLIC void restart_sigs(rmp)
572 struct mproc *rmp;
574 /* FS has replied to a request from us; do signal-related work.
576 int r;
578 if (rmp->mp_flags & (FS_CALL | EXITING)) return;
580 if (rmp->mp_flags & TRACE_EXIT) {
581 /* Tracer requested exit with specific exit value */
582 exit_proc(rmp, rmp->mp_exitstatus, FALSE /*dump_core*/);
584 else if (rmp->mp_flags & PM_SIG_PENDING) {
585 /* We saved signal(s) for after finishing a FS call. Deal with this.
586 * PM_SIG_PENDING remains set to indicate the process is still stopped.
588 check_pending(rmp);
590 /* The process may now be FS-blocked again, because a signal exited the
591 * process or was caught. Restart the process only when this is NOT the
592 * case.
594 if (!(rmp->mp_flags & FS_CALL)) {
595 rmp->mp_flags &= ~(PM_SIG_PENDING | UNPAUSED);
597 if ((r = sys_resume(rmp->mp_endpoint)) != OK)
598 panic("sys_resume failed: %d", r);
603 /*===========================================================================*
604 * unpause *
605 *===========================================================================*/
606 PRIVATE void unpause(rmp)
607 struct mproc *rmp; /* which process */
609 /* A signal is to be sent to a process. If that process is hanging on a
610 * system call, the system call must be terminated with EINTR. Possible
611 * calls are PAUSE, WAIT, READ and WRITE, the latter two for pipes and ttys.
612 * First check if the process is hanging on an PM call. If not, tell FS,
613 * so it can check for READs and WRITEs from pipes, ttys and the like.
615 message m;
616 int r;
618 /* If we're already waiting for a delayed call, don't do anything now. */
619 if (rmp->mp_flags & DELAY_CALL)
620 return;
622 /* Check to see if process is hanging on a PAUSE, WAIT or SIGSUSPEND call. */
623 if (rmp->mp_flags & (PAUSED | WAITING | SIGSUSPENDED)) {
624 /* Stop process from running. No delay calls: it called us. */
625 if ((r = sys_stop(rmp->mp_endpoint)) != OK)
626 panic("sys_stop failed: %d", r);
628 rmp->mp_flags |= UNPAUSED;
630 /* We interrupt the actual call from sig_send() below. */
631 return;
634 /* Not paused in PM. Let FS try to unpause the process. */
635 if (!(rmp->mp_flags & PM_SIG_PENDING)) {
636 /* Stop process from running. */
637 r = sys_delay_stop(rmp->mp_endpoint);
639 /* If the process is still busy sending a message, the kernel will give
640 * us EBUSY now and send a SIGSNDELAY to the process as soon as sending
641 * is done.
643 if (r == EBUSY) {
644 rmp->mp_flags |= DELAY_CALL;
646 return;
648 else if (r != OK) panic("sys_stop failed: %d", r);
650 rmp->mp_flags |= PM_SIG_PENDING;
653 m.m_type = PM_UNPAUSE;
654 m.PM_PROC = rmp->mp_endpoint;
656 tell_fs(rmp, &m);
658 /* Also tell VM. */
659 vm_notify_sig_wrapper(rmp->mp_endpoint);
662 /*===========================================================================*
663 * sig_send *
664 *===========================================================================*/
665 PRIVATE int sig_send(rmp, signo)
666 struct mproc *rmp; /* what process to spawn a signal handler in */
667 int signo; /* signal to send to process (1 to _NSIG-1) */
669 /* The process is supposed to catch this signal. Spawn a signal handler.
670 * Return TRUE if this succeeded, FALSE otherwise.
672 struct sigmsg sigmsg;
673 vir_bytes cur_sp;
674 int r, sigflags, slot;
676 if (!(rmp->mp_flags & UNPAUSED))
677 panic("sig_send: process not unpaused");
679 sigflags = rmp->mp_sigact[signo].sa_flags;
680 slot = (int) (rmp - mproc);
682 if (rmp->mp_flags & SIGSUSPENDED)
683 sigmsg.sm_mask = rmp->mp_sigmask2;
684 else
685 sigmsg.sm_mask = rmp->mp_sigmask;
686 sigmsg.sm_signo = signo;
687 sigmsg.sm_sighandler =
688 (vir_bytes) rmp->mp_sigact[signo].sa_handler;
689 sigmsg.sm_sigreturn = rmp->mp_sigreturn;
690 rmp->mp_sigmask |= rmp->mp_sigact[signo].sa_mask;
692 if (sigflags & SA_NODEFER)
693 sigdelset(&rmp->mp_sigmask, signo);
694 else
695 sigaddset(&rmp->mp_sigmask, signo);
697 if (sigflags & SA_RESETHAND) {
698 sigdelset(&rmp->mp_catch, signo);
699 rmp->mp_sigact[signo].sa_handler = SIG_DFL;
701 sigdelset(&rmp->mp_sigpending, signo);
703 if(vm_push_sig(rmp->mp_endpoint, &cur_sp) != OK)
704 return(FALSE);
706 sigmsg.sm_stkptr = cur_sp;
708 /* Ask the kernel to deliver the signal */
709 r = sys_sigsend(rmp->mp_endpoint, &sigmsg);
710 if (r != OK)
711 panic("sys_sigsend failed: %d", r);
713 /* Was the process suspended in PM? Then interrupt the blocking call. */
714 if (rmp->mp_flags & (PAUSED | WAITING | SIGSUSPENDED)) {
715 rmp->mp_flags &= ~(PAUSED | WAITING | SIGSUSPENDED);
717 setreply(slot, EINTR);
720 /* Was the process stopped just for this signal? Then resume it. */
721 if ((rmp->mp_flags & (PM_SIG_PENDING | UNPAUSED)) == UNPAUSED) {
722 rmp->mp_flags &= ~UNPAUSED;
724 if ((r = sys_resume(rmp->mp_endpoint)) != OK)
725 panic("sys_resume failed: %d", r);
728 return(TRUE);
731 /*===========================================================================*
732 * vm_notify_sig_wrapper *
733 *===========================================================================*/
734 PUBLIC void vm_notify_sig_wrapper(endpoint_t ep)
736 /* get IPC's endpoint,
737 * the reason that we directly get the endpoint
738 * instead of from DS server is that otherwise
739 * it will cause deadlock between PM, VM and DS.
741 struct mproc *rmp;
742 endpoint_t ipc_ep = 0;
744 for (rmp = &mproc[0]; rmp < &mproc[NR_PROCS]; rmp++) {
745 if (!(rmp->mp_flags & IN_USE))
746 continue;
747 if (!strcmp(rmp->mp_name, "ipc")) {
748 ipc_ep = rmp->mp_endpoint;
749 vm_notify_sig(ep, ipc_ep);
751 return;