4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 * Copyright (c) 2014, Joyent, Inc. All rights reserved.
28 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
29 /* All Rights Reserved */
31 #include <sys/param.h>
32 #include <sys/types.h>
33 #include <sys/bitmap.h>
34 #include <sys/sysmacros.h>
35 #include <sys/systm.h>
38 #include <sys/errno.h>
40 #include <sys/poll_impl.h> /* only needed for kludge in sigwaiting_send() */
41 #include <sys/signal.h>
42 #include <sys/siginfo.h>
43 #include <sys/fault.h>
44 #include <sys/ucontext.h>
45 #include <sys/procfs.h>
47 #include <sys/class.h>
49 #include <sys/procset.h>
51 #include <sys/cpuvar.h>
52 #include <sys/prsystm.h>
53 #include <sys/debug.h>
55 #include <sys/bitmap.h>
58 #include <sys/schedctl.h>
59 #include <sys/contract/process_impl.h>
60 #include <sys/cyclic.h>
61 #include <sys/dtrace.h>
63 #include <sys/signalfd.h>
65 const k_sigset_t nullsmask
= {0, 0, 0};
67 const k_sigset_t fillset
= /* MUST be contiguous */
68 {FILLSET0
, FILLSET1
, FILLSET2
};
70 const k_sigset_t cantmask
=
71 {CANTMASK0
, CANTMASK1
, CANTMASK2
};
73 const k_sigset_t cantreset
=
74 {(sigmask(SIGILL
)|sigmask(SIGTRAP
)|sigmask(SIGPWR
)), 0, 0};
76 const k_sigset_t ignoredefault
=
77 {(sigmask(SIGCONT
)|sigmask(SIGCLD
)|sigmask(SIGPWR
)
78 |sigmask(SIGWINCH
)|sigmask(SIGURG
)|sigmask(SIGWAITING
)),
79 (sigmask(SIGLWP
)|sigmask(SIGCANCEL
)|sigmask(SIGFREEZE
)
80 |sigmask(SIGTHAW
)|sigmask(SIGXRES
)|sigmask(SIGJVM1
)
81 |sigmask(SIGJVM2
)|sigmask(SIGINFO
)), 0};
83 const k_sigset_t stopdefault
=
84 {(sigmask(SIGSTOP
)|sigmask(SIGTSTP
)|sigmask(SIGTTOU
)|sigmask(SIGTTIN
)),
87 const k_sigset_t coredefault
=
88 {(sigmask(SIGQUIT
)|sigmask(SIGILL
)|sigmask(SIGTRAP
)|sigmask(SIGIOT
)
89 |sigmask(SIGEMT
)|sigmask(SIGFPE
)|sigmask(SIGBUS
)|sigmask(SIGSEGV
)
90 |sigmask(SIGSYS
)|sigmask(SIGXCPU
)|sigmask(SIGXFSZ
)), 0, 0};
92 const k_sigset_t holdvfork
=
93 {(sigmask(SIGTTOU
)|sigmask(SIGTTIN
)|sigmask(SIGTSTP
)), 0, 0};
95 static int isjobstop(int);
96 static void post_sigcld(proc_t
*, sigqueue_t
*);
100 * signalfd helper function which is set when the signalfd driver loads.
102 void (*sigfd_exit_helper
)();
105 * Internal variables for counting number of user thread stop requests posted.
106 * They may not be accurate at some special situation such as that a virtually
107 * stopped thread starts to run.
109 static int num_utstop
;
111 * Internal variables for broadcasting an event when all thread stop requests
114 static kcondvar_t utstop_cv
;
116 static kmutex_t thread_stop_lock
;
117 void del_one_utstop(void);
120 * Send the specified signal to the specified process.
123 psignal(proc_t
*p
, int sig
)
125 mutex_enter(&p
->p_lock
);
126 sigtoproc(p
, NULL
, sig
);
127 mutex_exit(&p
->p_lock
);
131 * Send the specified signal to the specified thread.
134 tsignal(kthread_t
*t
, int sig
)
136 proc_t
*p
= ttoproc(t
);
138 mutex_enter(&p
->p_lock
);
139 sigtoproc(p
, t
, sig
);
140 mutex_exit(&p
->p_lock
);
144 signal_is_blocked(kthread_t
*t
, int sig
)
146 return (sigismember(&t
->t_hold
, sig
) ||
147 (schedctl_sigblock(t
) && !sigismember(&cantmask
, sig
)));
151 * Return true if the signal can safely be discarded on generation.
152 * That is, if there is no need for the signal on the receiving end.
153 * The answer is true if the process is a zombie or
154 * if all of these conditions are true:
155 * the signal is being ignored
156 * the process is single-threaded
157 * the signal is not being traced by /proc
158 * the signal is not blocked by the process
159 * the signal is not being accepted via sigwait()
162 sig_discardable(proc_t
*p
, int sig
)
164 kthread_t
*t
= p
->p_tlist
;
166 return (t
== NULL
|| /* if zombie or ... */
167 (sigismember(&p
->p_ignore
, sig
) && /* signal is ignored */
168 t
->t_forw
== t
&& /* and single-threaded */
169 !tracing(p
, sig
) && /* and no /proc tracing */
170 !signal_is_blocked(t
, sig
) && /* and signal not blocked */
171 !sigismember(&t
->t_sigwait
, sig
))); /* and not being accepted */
175 * Return true if this thread is going to eat this signal soon.
176 * Note that, if the signal is SIGKILL, we force stopped threads to be
177 * set running (to make SIGKILL be a sure kill), but only if the process
178 * is not currently locked by /proc (the P_PR_LOCK flag). Code in /proc
179 * relies on the fact that a process will not change shape while P_PR_LOCK
180 * is set (it drops and reacquires p->p_lock while leaving P_PR_LOCK set).
181 * We wish that we could simply call prbarrier() below, in sigtoproc(), to
182 * ensure that the process is not locked by /proc, but prbarrier() drops
183 * and reacquires p->p_lock and dropping p->p_lock here would be damaging.
186 eat_signal(kthread_t
*t
, int sig
)
189 ASSERT(THREAD_LOCK_HELD(t
));
192 * Do not do anything if the target thread has the signal blocked.
194 if (!signal_is_blocked(t
, sig
)) {
195 t
->t_sig_check
= 1; /* have thread do an issig */
196 if (ISWAKEABLE(t
) || ISWAITING(t
)) {
199 } else if (t
->t_state
== TS_STOPPED
&& sig
== SIGKILL
&&
200 !(ttoproc(t
)->p_proc_flag
& P_PR_LOCK
)) {
201 ttoproc(t
)->p_stopsig
= 0;
202 t
->t_dtrace_stop
= 0;
203 t
->t_schedflag
|= TS_XSTART
| TS_PSTART
;
205 } else if (t
!= curthread
&& t
->t_state
== TS_ONPROC
) {
206 aston(t
); /* make it do issig promptly */
208 poke_cpu(t
->t_cpu
->cpu_id
);
210 } else if (t
->t_state
== TS_RUN
) {
220 * If a non-null thread pointer is passed, then post the signal
221 * to the thread/lwp, otherwise post the signal to the process.
224 sigtoproc(proc_t
*p
, kthread_t
*t
, int sig
)
227 int ext
= !(curproc
->p_flag
& SSYS
) &&
228 (curproc
->p_ct_process
!= p
->p_ct_process
);
230 ASSERT(MUTEX_HELD(&p
->p_lock
));
232 /* System processes don't get signals */
233 if (sig
<= 0 || sig
>= NSIG
|| (p
->p_flag
& SSYS
))
237 * Regardless of origin or directedness,
238 * SIGKILL kills all lwps in the process immediately
239 * and jobcontrol signals affect all lwps in the process.
241 if (sig
== SIGKILL
) {
242 p
->p_flag
|= SKILLED
| (ext
? SEXTKILLED
: 0);
244 } else if (sig
== SIGCONT
) {
246 * The SSCONT flag will remain set until a stopping
247 * signal comes in (below). This is harmless.
250 sigdelq(p
, NULL
, SIGSTOP
);
251 sigdelq(p
, NULL
, SIGTSTP
);
252 sigdelq(p
, NULL
, SIGTTOU
);
253 sigdelq(p
, NULL
, SIGTTIN
);
254 sigdiffset(&p
->p_sig
, &stopdefault
);
255 sigdiffset(&p
->p_extsig
, &stopdefault
);
257 if ((tt
= p
->p_tlist
) != NULL
) {
259 sigdelq(p
, tt
, SIGSTOP
);
260 sigdelq(p
, tt
, SIGTSTP
);
261 sigdelq(p
, tt
, SIGTTOU
);
262 sigdelq(p
, tt
, SIGTTIN
);
263 sigdiffset(&tt
->t_sig
, &stopdefault
);
264 sigdiffset(&tt
->t_extsig
, &stopdefault
);
265 } while ((tt
= tt
->t_forw
) != p
->p_tlist
);
267 if ((tt
= p
->p_tlist
) != NULL
) {
270 if (tt
->t_state
== TS_STOPPED
&&
271 tt
->t_whystop
== PR_JOBCONTROL
) {
272 tt
->t_schedflag
|= TS_XSTART
;
276 } while ((tt
= tt
->t_forw
) != p
->p_tlist
);
278 } else if (sigismember(&stopdefault
, sig
)) {
280 * This test has a race condition which we can't fix:
281 * By the time the stopping signal is received by
282 * the target process/thread, the signal handler
283 * and/or the detached state might have changed.
285 if (PTOU(p
)->u_signal
[sig
-1] == SIG_DFL
&&
286 (sig
== SIGSTOP
|| !p
->p_pgidp
->pid_pgorphaned
))
287 p
->p_flag
&= ~SSCONT
;
288 sigdelq(p
, NULL
, SIGCONT
);
289 sigdelset(&p
->p_sig
, SIGCONT
);
290 sigdelset(&p
->p_extsig
, SIGCONT
);
291 if ((tt
= p
->p_tlist
) != NULL
) {
293 sigdelq(p
, tt
, SIGCONT
);
294 sigdelset(&tt
->t_sig
, SIGCONT
);
295 sigdelset(&tt
->t_extsig
, SIGCONT
);
296 } while ((tt
= tt
->t_forw
) != p
->p_tlist
);
300 if (sig_discardable(p
, sig
)) {
301 DTRACE_PROC3(signal__discard
, kthread_t
*, p
->p_tlist
,
302 proc_t
*, p
, int, sig
);
308 * This is a directed signal, wake up the lwp.
310 sigaddset(&t
->t_sig
, sig
);
312 sigaddset(&t
->t_extsig
, sig
);
314 (void) eat_signal(t
, sig
);
316 DTRACE_PROC2(signal__send
, kthread_t
*, t
, int, sig
);
317 if (p
->p_sigfd
!= NULL
&& ((sigfd_proc_state_t
*)
318 (p
->p_sigfd
))->sigfd_pollwake_cb
!= NULL
)
319 (*((sigfd_proc_state_t
*)(p
->p_sigfd
))->
320 sigfd_pollwake_cb
)(p
, sig
);
322 } else if ((tt
= p
->p_tlist
) != NULL
) {
324 * Make sure that some lwp that already exists
325 * in the process fields the signal soon.
326 * Wake up an interruptibly sleeping lwp if necessary.
327 * For SIGKILL make all of the lwps see the signal;
328 * This is needed to guarantee a sure kill for processes
329 * with a mix of realtime and non-realtime threads.
333 sigaddset(&p
->p_sig
, sig
);
335 sigaddset(&p
->p_extsig
, sig
);
338 if (eat_signal(tt
, sig
) && sig
!= SIGKILL
) {
345 } while ((tt
= tt
->t_forw
) != p
->p_tlist
);
347 * If the process is deadlocked, make somebody run and die.
349 if (sig
== SIGKILL
&& p
->p_stat
!= SIDL
&&
350 p
->p_lwprcnt
== 0 && p
->p_lwpcnt
== su
&&
351 !(p
->p_proc_flag
& P_PR_LOCK
)) {
354 tt
->t_schedflag
|= TS_CSTART
;
359 DTRACE_PROC2(signal__send
, kthread_t
*, tt
, int, sig
);
360 if (p
->p_sigfd
!= NULL
&& ((sigfd_proc_state_t
*)
361 (p
->p_sigfd
))->sigfd_pollwake_cb
!= NULL
)
362 (*((sigfd_proc_state_t
*)(p
->p_sigfd
))->
363 sigfd_pollwake_cb
)(p
, sig
);
370 proc_t
*p
= ttoproc(curthread
);
372 ASSERT(MUTEX_HELD(&p
->p_lock
));
374 if (PTOU(curproc
)->u_signal
[sig
-1] == SIG_DFL
&&
375 sigismember(&stopdefault
, sig
)) {
377 * If SIGCONT has been posted since we promoted this signal
378 * from pending to current, then don't do a jobcontrol stop.
380 if (!(p
->p_flag
& SSCONT
) &&
381 (sig
== SIGSTOP
|| !p
->p_pgidp
->pid_pgorphaned
) &&
382 curthread
!= p
->p_agenttp
) {
385 stop(PR_JOBCONTROL
, sig
);
386 mutex_exit(&p
->p_lock
);
387 sqp
= kmem_zalloc(sizeof (sigqueue_t
), KM_SLEEP
);
388 mutex_enter(&pidlock
);
390 * Only the first lwp to continue notifies the parent.
392 if (p
->p_pidflag
& CLDCONT
)
395 p
->p_pidflag
|= CLDCONT
;
396 p
->p_wcode
= CLD_CONTINUED
;
397 p
->p_wdata
= SIGCONT
;
400 mutex_exit(&pidlock
);
401 mutex_enter(&p
->p_lock
);
409 * Returns true if the current process has a signal to process, and
410 * the signal is not held. The signal to process is put in p_cursig.
411 * This is asked at least once each time a process enters the system
412 * (though this can usually be done without actually calling issig by
413 * checking the pending signal masks). A signal does not do anything
414 * directly to a process; it sets a flag that asks the process to do
415 * something to itself.
417 * The "why" argument indicates the allowable side-effects of the call:
419 * FORREAL: Extract the next pending signal from p_sig into p_cursig;
420 * stop the process if a stop has been requested or if a traced signal
423 * JUSTLOOKING: Don't stop the process, just indicate whether or not
424 * a signal might be pending (FORREAL is needed to tell for sure).
426 * XXX: Changes to the logic in these routines should be propagated
427 * to lm_sigispending(). See bug 1201594.
430 static int issig_forreal(void);
431 static int issig_justlooking(void);
436 ASSERT(why
== FORREAL
|| why
== JUSTLOOKING
);
438 return ((why
== FORREAL
)? issig_forreal() : issig_justlooking());
443 issig_justlooking(void)
445 kthread_t
*t
= curthread
;
446 klwp_t
*lwp
= ttolwp(t
);
447 proc_t
*p
= ttoproc(t
);
451 * This function answers the question:
452 * "Is there any reason to call issig_forreal()?"
454 * We have to answer the question w/o grabbing any locks
455 * because we are (most likely) being called after we
456 * put ourselves on the sleep queue.
459 if (t
->t_dtrace_stop
| t
->t_dtrace_sig
)
463 * Another piece of complexity in this process. When single-stepping a
464 * process, we don't want an intervening signal or TP_PAUSE request to
465 * suspend the current thread. Otherwise, the controlling process will
466 * hang beacuse we will be stopped with TS_PSTART set in t_schedflag.
467 * We will trigger any remaining signals when we re-enter the kernel on
468 * the single step trap.
470 if (lwp
->lwp_pcb
.pcb_flags
& NORMAL_STEP
)
473 if ((lwp
->lwp_asleep
&& MUSTRETURN(p
, t
)) ||
474 (p
->p_flag
& (SEXITLWPS
|SKILLED
)) ||
475 (lwp
->lwp_nostop
== 0 &&
476 (p
->p_stopsig
| (p
->p_flag
& (SHOLDFORK1
|SHOLDWATCH
)) |
478 (TP_PRSTOP
|TP_HOLDLWP
|TP_CHKPT
|TP_PAUSE
)))) ||
482 if (p
->p_flag
& SVFWAIT
)
485 sigorset(&set
, &t
->t_sig
);
486 if (schedctl_sigblock(t
)) /* all blockable signals blocked */
487 sigandset(&set
, &cantmask
);
489 sigdiffset(&set
, &t
->t_hold
);
490 if (p
->p_flag
& SVFORK
)
491 sigdiffset(&set
, &holdvfork
);
493 if (!sigisempty(&set
)) {
496 for (sig
= 1; sig
< NSIG
; sig
++) {
497 if (sigismember(&set
, sig
) &&
499 sigismember(&t
->t_sigwait
, sig
) ||
500 !sigismember(&p
->p_ignore
, sig
))) {
502 * Don't promote a signal that will stop
503 * the process when lwp_nostop is set.
505 if (!lwp
->lwp_nostop
||
506 PTOU(p
)->u_signal
[sig
-1] != SIG_DFL
||
507 !sigismember(&stopdefault
, sig
))
519 int sig
= 0, ext
= 0;
520 kthread_t
*t
= curthread
;
521 klwp_t
*lwp
= ttolwp(t
);
522 proc_t
*p
= ttoproc(t
);
524 int sigcld_found
= 0;
525 int nostop_break
= 0;
527 ASSERT(t
->t_state
== TS_ONPROC
);
529 mutex_enter(&p
->p_lock
);
530 schedctl_finish_sigblock(t
);
532 if (t
->t_dtrace_stop
| t
->t_dtrace_sig
) {
533 if (t
->t_dtrace_stop
) {
535 * If DTrace's "stop" action has been invoked on us,
538 t
->t_proc_flag
|= TP_PRSTOP
;
541 if (t
->t_dtrace_sig
!= 0) {
545 * Post the signal generated as the result of
546 * DTrace's "raise" action as a normal signal before
547 * the full-fledged signal checking begins.
549 bzero(&info
, sizeof (info
));
550 info
.si_signo
= t
->t_dtrace_sig
;
551 info
.si_code
= SI_DTRACE
;
553 sigaddq(p
, NULL
, &info
, KM_NOSLEEP
);
560 if (p
->p_flag
& (SEXITLWPS
|SKILLED
)) {
561 lwp
->lwp_cursig
= sig
= SIGKILL
;
562 lwp
->lwp_extsig
= ext
= (p
->p_flag
& SEXTKILLED
) != 0;
568 * Another piece of complexity in this process. When
569 * single-stepping a process, we don't want an intervening
570 * signal or TP_PAUSE request to suspend the current thread.
571 * Otherwise, the controlling process will hang beacuse we will
572 * be stopped with TS_PSTART set in t_schedflag. We will
573 * trigger any remaining signals when we re-enter the kernel on
574 * the single step trap.
576 if (lwp
->lwp_pcb
.pcb_flags
& NORMAL_STEP
) {
582 * Hold the lwp here for watchpoint manipulation.
584 if ((t
->t_proc_flag
& TP_PAUSE
) && !lwp
->lwp_nostop
) {
585 stop(PR_SUSPENDED
, SUSPEND_PAUSE
);
589 if (lwp
->lwp_asleep
&& MUSTRETURN(p
, t
)) {
590 if ((sig
= lwp
->lwp_cursig
) != 0) {
592 * Make sure we call ISSIG() in post_syscall()
593 * to re-validate this current signal.
601 * If the request is PR_CHECKPOINT, ignore the rest of signals
602 * or requests. Honor other stop requests or signals later.
603 * Go back to top of loop here to check if an exit or hold
604 * event has occurred while stopped.
606 if ((t
->t_proc_flag
& TP_CHKPT
) && !lwp
->lwp_nostop
) {
607 stop(PR_CHECKPOINT
, 0);
612 * Honor SHOLDFORK1, SHOLDWATCH, and TP_HOLDLWP before dealing
613 * with signals or /proc. Another lwp is executing fork1(),
614 * or is undergoing watchpoint activity (remapping a page),
615 * or is executing lwp_suspend() on this lwp.
616 * Again, go back to top of loop to check if an exit
617 * or hold event has occurred while stopped.
619 if (((p
->p_flag
& (SHOLDFORK1
|SHOLDWATCH
)) ||
620 (t
->t_proc_flag
& TP_HOLDLWP
)) && !lwp
->lwp_nostop
) {
621 stop(PR_SUSPENDED
, SUSPEND_NORMAL
);
626 * Honor requested stop before dealing with the
627 * current signal; a debugger may change it.
628 * Do not want to go back to loop here since this is a special
629 * stop that means: make incremental progress before the next
630 * stop. The danger is that returning to top of loop would most
631 * likely drop the thread right back here to stop soon after it
632 * was continued, violating the incremental progress request.
634 if ((t
->t_proc_flag
& TP_PRSTOP
) && !lwp
->lwp_nostop
)
635 stop(PR_REQUESTED
, 0);
638 * If a debugger wants us to take a signal it will have
639 * left it in lwp->lwp_cursig. If lwp_cursig has been cleared
640 * or if it's being ignored, we continue on looking for another
641 * signal. Otherwise we return the specified signal, provided
642 * it's not a signal that causes a job control stop.
644 * When stopped on PR_JOBCONTROL, there is no current
645 * signal; we cancel lwp->lwp_cursig temporarily before
646 * calling isjobstop(). The current signal may be reset
647 * by a debugger while we are stopped in isjobstop().
649 * If the current thread is accepting the signal
650 * (via sigwait(), sigwaitinfo(), or sigtimedwait()),
651 * we allow the signal to be accepted, even if it is
652 * being ignored, and without causing a job control stop.
654 if ((sig
= lwp
->lwp_cursig
) != 0) {
655 ext
= lwp
->lwp_extsig
;
658 if (sigismember(&t
->t_sigwait
, sig
) ||
659 (!sigismember(&p
->p_ignore
, sig
) &&
661 if (p
->p_flag
& (SEXITLWPS
|SKILLED
)) {
663 ext
= (p
->p_flag
& SEXTKILLED
) != 0;
665 lwp
->lwp_cursig
= (uchar_t
)sig
;
666 lwp
->lwp_extsig
= (uchar_t
)ext
;
670 * The signal is being ignored or it caused a
671 * job-control stop. If another current signal
672 * has not been established, return the current
673 * siginfo, if any, to the memory manager.
675 if (lwp
->lwp_cursig
== 0 && lwp
->lwp_curinfo
!= NULL
) {
676 siginfofree(lwp
->lwp_curinfo
);
677 lwp
->lwp_curinfo
= NULL
;
680 * Loop around again in case we were stopped
681 * on a job control signal and a /proc stop
682 * request was posted or another current signal
683 * was established while we were stopped.
688 if (p
->p_stopsig
&& !lwp
->lwp_nostop
&&
689 curthread
!= p
->p_agenttp
) {
691 * Some lwp in the process has already stopped
692 * showing PR_JOBCONTROL. This is a stop in
693 * sympathy with the other lwp, even if this
694 * lwp is blocking the stopping signal.
696 stop(PR_JOBCONTROL
, p
->p_stopsig
);
701 * Loop on the pending signals until we find a
702 * non-held signal that is traced or not ignored.
703 * First check the signals pending for the lwp,
704 * then the signals pending for the process as a whole.
707 if ((sig
= fsig(&t
->t_sig
, t
)) != 0) {
709 if (tracing(p
, sig
) ||
710 sigismember(&t
->t_sigwait
, sig
) ||
711 !sigismember(&p
->p_ignore
, sig
)) {
712 if (sigismember(&t
->t_extsig
, sig
))
716 sigdelset(&t
->t_sig
, sig
);
717 sigdelset(&t
->t_extsig
, sig
);
719 } else if ((sig
= fsig(&p
->p_sig
, t
)) != 0) {
723 if (tracing(p
, sig
) ||
724 sigismember(&t
->t_sigwait
, sig
) ||
725 !sigismember(&p
->p_ignore
, sig
)) {
726 if (sigismember(&p
->p_extsig
, sig
))
730 sigdelset(&p
->p_sig
, sig
);
731 sigdelset(&p
->p_extsig
, sig
);
732 sigdelq(p
, NULL
, sig
);
734 /* no signal was found */
739 if (sig
== 0) { /* no signal was found */
740 if (p
->p_flag
& (SEXITLWPS
|SKILLED
)) {
741 lwp
->lwp_cursig
= SIGKILL
;
743 ext
= (p
->p_flag
& SEXTKILLED
) != 0;
749 * If we have been informed not to stop (i.e., we are being
750 * called from within a network operation), then don't promote
751 * the signal at this time, just return the signal number.
752 * We will call issig() again later when it is safe.
754 * fsig() does not return a jobcontrol stopping signal
755 * with a default action of stopping the process if
756 * lwp_nostop is set, so we won't be causing a bogus
757 * EINTR by this action. (Such a signal is eaten by
758 * isjobstop() when we loop around to do final checks.)
760 if (lwp
->lwp_nostop
) {
766 * Promote the signal from pending to current.
768 * Note that sigdeq() will set lwp->lwp_curinfo to NULL
769 * if no siginfo_t exists for this signal.
771 lwp
->lwp_cursig
= (uchar_t
)sig
;
772 lwp
->lwp_extsig
= (uchar_t
)ext
;
773 t
->t_sig_check
= 1; /* so post_syscall will see signal */
774 ASSERT(lwp
->lwp_curinfo
== NULL
);
775 sigdeq(p
, toproc
? NULL
: t
, sig
, &lwp
->lwp_curinfo
);
778 stop(PR_SIGNALLED
, sig
);
781 * Loop around to check for requested stop before
782 * performing the usual current-signal actions.
786 mutex_exit(&p
->p_lock
);
789 * If SIGCLD was dequeued from the process's signal queue,
790 * search for other pending SIGCLD's from the list of children.
796 (void) undo_watch_step(NULL
);
799 * If we have been blocked since the p_lock was dropped off
800 * above, then this promoted signal might have been handled
801 * already when we were on the way back from sleep queue, so
803 * If we have been informed not to stop, just return the signal
804 * number. Also see comments above.
807 sig
= lwp
->lwp_cursig
;
814 * Return true if the process is currently stopped showing PR_JOBCONTROL.
815 * This is true only if all of the process's lwp's are so stopped.
816 * If this is asked by one of the lwps in the process, exclude that lwp.
819 jobstopped(proc_t
*p
)
823 ASSERT(MUTEX_HELD(&p
->p_lock
));
825 if ((t
= p
->p_tlist
) == NULL
)
830 /* ignore current, zombie and suspended lwps in the test */
831 if (!(t
== curthread
|| t
->t_state
== TS_ZOMB
||
833 (t
->t_state
!= TS_STOPPED
||
834 t
->t_whystop
!= PR_JOBCONTROL
)) {
839 } while ((t
= t
->t_forw
) != p
->p_tlist
);
845 * Put ourself (curthread) into the stopped state and notify tracers.
848 stop(int why
, int what
)
850 kthread_t
*t
= curthread
;
851 proc_t
*p
= ttoproc(t
);
852 klwp_t
*lwp
= ttolwp(t
);
856 int flags
= TS_ALLSTART
;
860 * Can't stop a system process.
862 if (p
== NULL
|| lwp
== NULL
|| (p
->p_flag
& SSYS
) || p
->p_as
== &kas
)
865 ASSERT(MUTEX_HELD(&p
->p_lock
));
867 if (why
!= PR_SUSPENDED
&& why
!= PR_CHECKPOINT
) {
869 * Don't stop an lwp with SIGKILL pending.
870 * Don't stop if the process or lwp is exiting.
872 if (lwp
->lwp_cursig
== SIGKILL
||
873 sigismember(&t
->t_sig
, SIGKILL
) ||
874 sigismember(&p
->p_sig
, SIGKILL
) ||
875 (t
->t_proc_flag
& TP_LWPEXIT
) ||
876 (p
->p_flag
& (SEXITLWPS
|SKILLED
))) {
878 t
->t_proc_flag
&= ~(TP_PRSTOP
|TP_PRVSTOP
);
884 * Make sure we don't deadlock on a recursive call to prstop().
885 * prstop() sets the lwp_nostop flag.
891 * Make sure the lwp is in an orderly state for inspection
892 * by a debugger through /proc or for dumping via core().
894 schedctl_finish_sigblock(t
);
895 t
->t_proc_flag
|= TP_STOPPING
; /* must set before dropping p_lock */
896 mutex_exit(&p
->p_lock
);
897 stoptime
= gethrtime();
899 (void) undo_watch_step(NULL
);
900 mutex_enter(&p
->p_lock
);
901 ASSERT(t
->t_state
== TS_ONPROC
);
906 * The situation may have changed since we dropped
907 * and reacquired p->p_lock. Double-check now
908 * whether we should stop or not.
910 if (!(t
->t_proc_flag
& TP_CHKPT
)) {
911 t
->t_proc_flag
&= ~TP_STOPPING
;
914 t
->t_proc_flag
&= ~TP_CHKPT
;
919 ASSERT(what
== SIGSTOP
|| what
== SIGTSTP
||
920 what
== SIGTTIN
|| what
== SIGTTOU
);
925 ASSERT(what
== SUSPEND_NORMAL
|| what
== SUSPEND_PAUSE
);
927 * The situation may have changed since we dropped
928 * and reacquired p->p_lock. Double-check now
929 * whether we should stop or not.
931 if (what
== SUSPEND_PAUSE
) {
932 if (!(t
->t_proc_flag
& TP_PAUSE
)) {
933 t
->t_proc_flag
&= ~TP_STOPPING
;
936 flags
&= ~TS_UNPAUSE
;
938 if (!((t
->t_proc_flag
& TP_HOLDLWP
) ||
939 (p
->p_flag
& (SHOLDFORK
|SHOLDFORK1
|SHOLDWATCH
)))) {
940 t
->t_proc_flag
&= ~TP_STOPPING
;
944 * If SHOLDFORK is in effect and we are stopping
945 * while asleep (not at the top of the stack),
946 * we return now to allow the hold to take effect
947 * when we reach the top of the kernel stack.
949 if (lwp
->lwp_asleep
&& (p
->p_flag
& SHOLDFORK
)) {
950 t
->t_proc_flag
&= ~TP_STOPPING
;
957 default: /* /proc stop */
960 * Do synchronous stop unless the async-stop flag is set.
961 * If why is PR_REQUESTED and t->t_dtrace_stop flag is set,
962 * then no debugger is present and we also do synchronous stop.
964 if ((why
!= PR_REQUESTED
|| t
->t_dtrace_stop
) &&
965 !(p
->p_proc_flag
& P_PR_ASYNC
)) {
968 for (tx
= t
->t_forw
; tx
!= t
; tx
= tx
->t_forw
) {
972 (tx
->t_proc_flag
& TP_PRSTOP
)) {
976 tx
->t_proc_flag
|= TP_PRSTOP
;
978 if (tx
->t_state
== TS_SLEEP
&&
979 (tx
->t_flag
& T_WAKEABLE
)) {
981 * Don't actually wake it up if it's
982 * in one of the lwp_*() syscalls.
983 * Mark it virtually stopped and
984 * notify /proc waiters (below).
986 if (tx
->t_wchan0
== NULL
)
989 tx
->t_proc_flag
|= TP_PRVSTOP
;
990 tx
->t_stoptime
= stoptime
;
995 /* Move waiting thread to run queue */
1000 * force the thread into the kernel
1001 * if it is not already there.
1003 if (tx
->t_state
== TS_ONPROC
&&
1005 poke_cpu(tx
->t_cpu
->cpu_id
);
1007 lep
= p
->p_lwpdir
[tx
->t_dslot
].ld_entry
;
1008 if (notify
&& lep
->le_trace
)
1009 prnotify(lep
->le_trace
);
1012 * We do this just in case one of the threads we asked
1013 * to stop is in holdlwps() (called from cfork()) or
1016 cv_broadcast(&p
->p_holdlwps
);
1021 t
->t_stoptime
= stoptime
;
1023 if (why
== PR_JOBCONTROL
|| (why
== PR_SUSPENDED
&& p
->p_stopsig
)) {
1025 * Determine if the whole process is jobstopped.
1027 if (jobstopped(p
)) {
1031 if ((sig
= p
->p_stopsig
) == 0)
1032 p
->p_stopsig
= (uchar_t
)(sig
= what
);
1033 mutex_exit(&p
->p_lock
);
1034 sqp
= kmem_zalloc(sizeof (sigqueue_t
), KM_SLEEP
);
1035 mutex_enter(&pidlock
);
1037 * The last lwp to stop notifies the parent.
1038 * Turn off the CLDCONT flag now so the first
1039 * lwp to continue knows what to do.
1041 p
->p_pidflag
&= ~CLDCONT
;
1042 p
->p_wcode
= CLD_STOPPED
;
1046 * Grab p->p_lock before releasing pidlock so the
1047 * parent and the child don't have a race condition.
1049 mutex_enter(&p
->p_lock
);
1050 mutex_exit(&pidlock
);
1052 } else if (why
== PR_JOBCONTROL
&& p
->p_stopsig
== 0) {
1054 * Set p->p_stopsig and wake up sleeping lwps
1055 * so they will stop in sympathy with this lwp.
1057 p
->p_stopsig
= (uchar_t
)what
;
1060 * We do this just in case one of the threads we asked
1061 * to stop is in holdlwps() (called from cfork()) or
1064 cv_broadcast(&p
->p_holdlwps
);
1068 if (why
!= PR_JOBCONTROL
&& why
!= PR_CHECKPOINT
) {
1070 * Do process-level notification when all lwps are
1071 * either stopped on events of interest to /proc
1072 * or are stopped showing PR_SUSPENDED or are zombies.
1075 for (tx
= t
->t_forw
; procstop
&& tx
!= t
; tx
= tx
->t_forw
) {
1079 switch (tx
->t_state
) {
1083 /* neither ISTOPPED nor SUSPENDED? */
1084 if ((tx
->t_schedflag
&
1085 (TS_CSTART
| TS_UNPAUSE
| TS_PSTART
)) ==
1086 (TS_CSTART
| TS_UNPAUSE
| TS_PSTART
))
1090 /* not paused for watchpoints? */
1091 if (!(tx
->t_flag
& T_WAKEABLE
) ||
1092 tx
->t_wchan0
== NULL
||
1093 !(tx
->t_proc_flag
& TP_PAUSE
))
1103 /* there must not be any remapped watched pages now */
1104 ASSERT(p
->p_mapcnt
== 0);
1105 if (p
->p_proc_flag
& P_PR_PTRACE
) {
1106 /* ptrace() compatibility */
1107 mutex_exit(&p
->p_lock
);
1108 mutex_enter(&pidlock
);
1109 p
->p_wcode
= CLD_TRAPPED
;
1110 p
->p_wdata
= (why
== PR_SIGNALLED
)?
1112 cv_broadcast(&p
->p_parent
->p_cv
);
1114 * Grab p->p_lock before releasing pidlock so
1115 * parent and child don't have a race condition.
1117 mutex_enter(&p
->p_lock
);
1118 mutex_exit(&pidlock
);
1120 if (p
->p_trace
) /* /proc */
1121 prnotify(p
->p_trace
);
1122 cv_broadcast(&pr_pid_cv
[p
->p_slot
]); /* pauselwps() */
1123 cv_broadcast(&p
->p_holdlwps
); /* holdwatch() */
1125 if (why
!= PR_SUSPENDED
) {
1126 lep
= p
->p_lwpdir
[t
->t_dslot
].ld_entry
;
1127 if (lep
->le_trace
) /* /proc */
1128 prnotify(lep
->le_trace
);
1130 * Special notification for creation of the agent lwp.
1132 if (t
== p
->p_agenttp
&&
1133 (t
->t_proc_flag
& TP_PRSTOP
) &&
1135 prnotify(p
->p_trace
);
1137 * The situation may have changed since we dropped
1138 * and reacquired p->p_lock. Double-check now
1139 * whether we should stop or not.
1141 if (!(t
->t_proc_flag
& TP_STOPPING
)) {
1142 if (t
->t_proc_flag
& TP_PRSTOP
)
1143 t
->t_proc_flag
|= TP_STOPPING
;
1145 t
->t_proc_flag
&= ~(TP_PRSTOP
|TP_PRVSTOP
);
1150 if (why
== PR_SUSPENDED
) {
1153 * We always broadcast in the case of SUSPEND_PAUSE. This is
1154 * because checks for TP_PAUSE take precedence over checks for
1155 * SHOLDWATCH. If a thread is trying to stop because of
1156 * SUSPEND_PAUSE and tries to do a holdwatch(), it will be
1157 * waiting for the rest of the threads to enter a stopped state.
1158 * If we are stopping for a SUSPEND_PAUSE, we may be the last
1159 * lwp and not know it, so broadcast just in case.
1161 if (what
== SUSPEND_PAUSE
||
1162 --p
->p_lwprcnt
== 0 || (t
->t_proc_flag
& TP_HOLDLWP
))
1163 cv_broadcast(&p
->p_holdlwps
);
1168 * Need to do this here (rather than after the thread is officially
1169 * stopped) because we can't call mutex_enter from a stopped thread.
1171 if (why
== PR_CHECKPOINT
)
1175 ASSERT((t
->t_schedflag
& TS_ALLSTART
) == 0);
1176 t
->t_schedflag
|= flags
;
1177 t
->t_whystop
= (short)why
;
1178 t
->t_whatstop
= (short)what
;
1179 CL_STOP(t
, why
, what
);
1180 (void) new_mstate(t
, LMS_STOPPED
);
1181 thread_stop(t
); /* set stop state and drop lock */
1183 if (why
!= PR_SUSPENDED
&& why
!= PR_CHECKPOINT
) {
1185 * We may have gotten a SIGKILL or a SIGCONT when
1186 * we released p->p_lock; make one last check.
1187 * Also check for a /proc run-on-last-close.
1189 if (sigismember(&t
->t_sig
, SIGKILL
) ||
1190 sigismember(&p
->p_sig
, SIGKILL
) ||
1191 (t
->t_proc_flag
& TP_LWPEXIT
) ||
1192 (p
->p_flag
& (SEXITLWPS
|SKILLED
))) {
1195 t
->t_schedflag
|= TS_XSTART
| TS_PSTART
;
1197 thread_unlock_nopreempt(t
);
1198 } else if (why
== PR_JOBCONTROL
) {
1199 if (p
->p_flag
& SSCONT
) {
1201 * This resulted from a SIGCONT posted
1202 * while we were not holding p->p_lock.
1206 t
->t_schedflag
|= TS_XSTART
;
1208 thread_unlock_nopreempt(t
);
1210 } else if (!(t
->t_proc_flag
& TP_STOPPING
)) {
1212 * This resulted from a /proc run-on-last-close.
1215 t
->t_schedflag
|= TS_PSTART
;
1217 thread_unlock_nopreempt(t
);
1221 t
->t_proc_flag
&= ~TP_STOPPING
;
1222 mutex_exit(&p
->p_lock
);
1225 setallwatch(); /* reestablish any watchpoints set while stopped */
1226 mutex_enter(&p
->p_lock
);
1227 prbarrier(p
); /* barrier against /proc locking */
1230 /* Interface for resetting user thread stop count. */
1234 mutex_enter(&thread_stop_lock
);
1236 mutex_exit(&thread_stop_lock
);
1239 /* Interface for registering a user thread stop request. */
1241 add_one_utstop(void)
1243 mutex_enter(&thread_stop_lock
);
1245 mutex_exit(&thread_stop_lock
);
1248 /* Interface for cancelling a user thread stop request */
1250 del_one_utstop(void)
1252 mutex_enter(&thread_stop_lock
);
1254 if (num_utstop
== 0)
1255 cv_broadcast(&utstop_cv
);
1256 mutex_exit(&thread_stop_lock
);
1259 /* Interface to wait for all user threads to be stopped */
1261 utstop_timedwait(clock_t ticks
)
1263 mutex_enter(&thread_stop_lock
);
1265 (void) cv_reltimedwait(&utstop_cv
, &thread_stop_lock
, ticks
,
1267 mutex_exit(&thread_stop_lock
);
1271 * Perform the action specified by the current signal.
1272 * The usual sequence is:
1275 * The signal bit has already been cleared by issig(),
1276 * the current signal number has been stored in lwp_cursig,
1277 * and the current siginfo is now referenced by lwp_curinfo.
1282 kthread_t
*t
= curthread
;
1283 proc_t
*p
= ttoproc(t
);
1284 klwp_t
*lwp
= ttolwp(t
);
1286 int sig
, rc
, code
, ext
;
1289 zoneid_t zoneid
= -1;
1290 sigqueue_t
*sqp
= NULL
;
1291 uint32_t auditing
= AU_AUDITING();
1293 mutex_enter(&p
->p_lock
);
1294 schedctl_finish_sigblock(t
);
1297 if (p
->p_flag
& SEXITLWPS
) {
1299 return; /* not reached */
1301 sig
= lwp
->lwp_cursig
;
1302 ext
= lwp
->lwp_extsig
;
1307 * Re-check lwp_cursig after we acquire p_lock. Since p_lock was
1308 * dropped between issig() and psig(), a debugger may have cleared
1309 * lwp_cursig via /proc in the intervening window.
1312 if (lwp
->lwp_curinfo
) {
1313 siginfofree(lwp
->lwp_curinfo
);
1314 lwp
->lwp_curinfo
= NULL
;
1316 if (t
->t_flag
& T_TOMASK
) { /* sigsuspend or pollsys */
1317 t
->t_flag
&= ~T_TOMASK
;
1318 t
->t_hold
= lwp
->lwp_sigoldmask
;
1320 mutex_exit(&p
->p_lock
);
1323 func
= PTOU(curproc
)->u_signal
[sig
-1];
1326 * The signal disposition could have changed since we promoted
1327 * this signal from pending to current (we dropped p->p_lock).
1328 * This can happen only in a multi-threaded process.
1330 if (sigismember(&p
->p_ignore
, sig
) ||
1331 (func
== SIG_DFL
&& sigismember(&stopdefault
, sig
))) {
1332 lwp
->lwp_cursig
= 0;
1333 lwp
->lwp_extsig
= 0;
1334 if (lwp
->lwp_curinfo
) {
1335 siginfofree(lwp
->lwp_curinfo
);
1336 lwp
->lwp_curinfo
= NULL
;
1338 if (t
->t_flag
& T_TOMASK
) { /* sigsuspend or pollsys */
1339 t
->t_flag
&= ~T_TOMASK
;
1340 t
->t_hold
= lwp
->lwp_sigoldmask
;
1342 mutex_exit(&p
->p_lock
);
1347 * We check lwp_curinfo first since pr_setsig can actually
1348 * stuff a sigqueue_t there for SIGKILL.
1350 if (lwp
->lwp_curinfo
) {
1351 sqp
= lwp
->lwp_curinfo
;
1352 } else if (sig
== SIGKILL
&& p
->p_killsqp
) {
1357 if (SI_FROMUSER(&sqp
->sq_info
)) {
1358 pid
= sqp
->sq_info
.si_pid
;
1359 ctid
= sqp
->sq_info
.si_ctid
;
1360 zoneid
= sqp
->sq_info
.si_zoneid
;
1363 * If we have a sigqueue_t, its sq_external value
1364 * trumps the lwp_extsig value. It is theoretically
1365 * possible to make lwp_extsig reflect reality, but it
1366 * would unnecessarily complicate things elsewhere.
1368 ext
= sqp
->sq_external
;
1371 if (func
== SIG_DFL
) {
1372 mutex_exit(&p
->p_lock
);
1373 DTRACE_PROC3(signal__handle
, int, sig
, k_siginfo_t
*,
1374 NULL
, void (*)(void), func
);
1376 k_siginfo_t
*sip
= NULL
;
1379 * If DTrace user-land tracing is active, give DTrace a
1380 * chance to defer the signal until after tracing is
1383 if (t
->t_dtrace_on
&& dtrace_safe_defer_signal()) {
1384 mutex_exit(&p
->p_lock
);
1389 * save siginfo pointer here, in case the
1390 * the signal's reset bit is on
1392 * The presence of a current signal prevents paging
1393 * from succeeding over a network. We copy the current
1394 * signal information to the side and cancel the current
1395 * signal so that sendsig() will succeed.
1397 if (sigismember(&p
->p_siginfo
, sig
)) {
1398 sip
= &lwp
->lwp_siginfo
;
1400 bcopy(&sqp
->sq_info
, sip
, sizeof (*sip
));
1402 * If we were interrupted out of a system call
1403 * due to pthread_cancel(), inform libc.
1405 if (sig
== SIGCANCEL
&&
1406 sip
->si_code
== SI_LWP
&&
1408 schedctl_cancel_eintr();
1409 } else if (sig
== SIGPROF
&& sip
->si_signo
== SIGPROF
&&
1410 t
->t_rprof
!= NULL
&& t
->t_rprof
->rp_anystate
) {
1413 bzero(sip
, sizeof (*sip
));
1414 sip
->si_signo
= sig
;
1415 sip
->si_code
= SI_NOINFO
;
1419 if (t
->t_flag
& T_TOMASK
)
1420 t
->t_flag
&= ~T_TOMASK
;
1422 lwp
->lwp_sigoldmask
= t
->t_hold
;
1423 sigorset(&t
->t_hold
, &PTOU(curproc
)->u_sigmask
[sig
-1]);
1424 if (!sigismember(&PTOU(curproc
)->u_signodefer
, sig
))
1425 sigaddset(&t
->t_hold
, sig
);
1426 if (sigismember(&PTOU(curproc
)->u_sigresethand
, sig
))
1427 setsigact(sig
, SIG_DFL
, &nullsmask
, 0);
1429 DTRACE_PROC3(signal__handle
, int, sig
, k_siginfo_t
*,
1430 sip
, void (*)(void), func
);
1432 lwp
->lwp_cursig
= 0;
1433 lwp
->lwp_extsig
= 0;
1434 if (lwp
->lwp_curinfo
) {
1435 /* p->p_killsqp is freed by freeproc */
1436 siginfofree(lwp
->lwp_curinfo
);
1437 lwp
->lwp_curinfo
= NULL
;
1439 mutex_exit(&p
->p_lock
);
1440 lwp
->lwp_ru
.nsignals
++;
1442 if (p
->p_model
== DATAMODEL_NATIVE
)
1443 rc
= sendsig(sig
, sip
, func
);
1444 #ifdef _SYSCALL32_IMPL
1446 rc
= sendsig32(sig
, sip
, func
);
1447 #endif /* _SYSCALL32_IMPL */
1450 sig
= lwp
->lwp_cursig
= SIGSEGV
;
1451 ext
= 0; /* lwp_extsig was set above */
1456 if (sigismember(&coredefault
, sig
)) {
1458 * Terminate all LWPs but don't discard them.
1459 * If another lwp beat us to the punch by calling exit(),
1463 if (exitlwps(1) != 0) {
1464 mutex_enter(&p
->p_lock
);
1467 /* if we got a SIGKILL from anywhere, no core dump */
1468 if (p
->p_flag
& SKILLED
) {
1470 ext
= (p
->p_flag
& SEXTKILLED
) != 0;
1472 if (auditing
) /* audit core dump */
1473 audit_core_start(sig
);
1474 if (core(sig
, ext
) == 0)
1476 if (auditing
) /* audit core dump */
1477 audit_core_finish(code
);
1482 * Generate a contract event once if the process is killed
1487 if (exitlwps(0) != 0) {
1488 mutex_enter(&p
->p_lock
);
1491 contract_process_sig(p
->p_ct_process
, p
, sig
, pid
, ctid
,
1499 * Find next unheld signal in ssp for thread t.
1502 fsig(k_sigset_t
*ssp
, kthread_t
*t
)
1504 proc_t
*p
= ttoproc(t
);
1505 user_t
*up
= PTOU(p
);
1509 ASSERT(MUTEX_HELD(&p
->p_lock
));
1512 * Don't promote any signals for the parent of a vfork()d
1513 * child that hasn't yet released the parent's memory.
1515 if (p
->p_flag
& SVFWAIT
)
1519 sigdiffset(&temp
, &t
->t_hold
);
1522 * Don't promote stopping signals (except SIGSTOP) for a child
1523 * of vfork() that hasn't yet released the parent's memory.
1525 if (p
->p_flag
& SVFORK
)
1526 sigdiffset(&temp
, &holdvfork
);
1529 * Don't promote a signal that will stop
1530 * the process when lwp_nostop is set.
1532 if (ttolwp(t
)->lwp_nostop
) {
1533 sigdelset(&temp
, SIGSTOP
);
1534 if (!p
->p_pgidp
->pid_pgorphaned
) {
1535 if (up
->u_signal
[SIGTSTP
-1] == SIG_DFL
)
1536 sigdelset(&temp
, SIGTSTP
);
1537 if (up
->u_signal
[SIGTTIN
-1] == SIG_DFL
)
1538 sigdelset(&temp
, SIGTTIN
);
1539 if (up
->u_signal
[SIGTTOU
-1] == SIG_DFL
)
1540 sigdelset(&temp
, SIGTTOU
);
1545 * Choose SIGKILL and SIGPROF before all other pending signals.
1546 * The rest are promoted in signal number order.
1548 if (sigismember(&temp
, SIGKILL
))
1550 if (sigismember(&temp
, SIGPROF
))
1553 for (i
= 0; i
< sizeof (temp
) / sizeof (temp
.__sigbits
[0]); i
++) {
1554 if (temp
.__sigbits
[i
])
1555 return ((i
* NBBY
* sizeof (temp
.__sigbits
[0])) +
1556 lowbit(temp
.__sigbits
[i
]));
1563 setsigact(int sig
, void (*disp
)(), const k_sigset_t
*mask
, int flags
)
1565 proc_t
*p
= ttoproc(curthread
);
1568 ASSERT(MUTEX_HELD(&p
->p_lock
));
1570 PTOU(curproc
)->u_signal
[sig
- 1] = disp
;
1573 * Honor the SA_SIGINFO flag if the signal is being caught.
1574 * Force the SA_SIGINFO flag if the signal is not being caught.
1575 * This is necessary to make sigqueue() and sigwaitinfo() work
1576 * properly together when the signal is set to default or is
1577 * being temporarily ignored.
1579 if ((flags
& SA_SIGINFO
) || disp
== SIG_DFL
|| disp
== SIG_IGN
)
1580 sigaddset(&p
->p_siginfo
, sig
);
1582 sigdelset(&p
->p_siginfo
, sig
);
1584 if (disp
!= SIG_DFL
&& disp
!= SIG_IGN
) {
1585 sigdelset(&p
->p_ignore
, sig
);
1586 PTOU(curproc
)->u_sigmask
[sig
- 1] = *mask
;
1587 if (!sigismember(&cantreset
, sig
)) {
1588 if (flags
& SA_RESETHAND
)
1589 sigaddset(&PTOU(curproc
)->u_sigresethand
, sig
);
1591 sigdelset(&PTOU(curproc
)->u_sigresethand
, sig
);
1593 if (flags
& SA_NODEFER
)
1594 sigaddset(&PTOU(curproc
)->u_signodefer
, sig
);
1596 sigdelset(&PTOU(curproc
)->u_signodefer
, sig
);
1597 if (flags
& SA_RESTART
)
1598 sigaddset(&PTOU(curproc
)->u_sigrestart
, sig
);
1600 sigdelset(&PTOU(curproc
)->u_sigrestart
, sig
);
1601 if (flags
& SA_ONSTACK
)
1602 sigaddset(&PTOU(curproc
)->u_sigonstack
, sig
);
1604 sigdelset(&PTOU(curproc
)->u_sigonstack
, sig
);
1605 } else if (disp
== SIG_IGN
||
1606 (disp
== SIG_DFL
&& sigismember(&ignoredefault
, sig
))) {
1608 * Setting the signal action to SIG_IGN results in the
1609 * discarding of all pending signals of that signal number.
1610 * Setting the signal action to SIG_DFL does the same *only*
1611 * if the signal's default behavior is to be ignored.
1613 sigaddset(&p
->p_ignore
, sig
);
1614 sigdelset(&p
->p_sig
, sig
);
1615 sigdelset(&p
->p_extsig
, sig
);
1616 sigdelq(p
, NULL
, sig
);
1619 sigdelset(&t
->t_sig
, sig
);
1620 sigdelset(&t
->t_extsig
, sig
);
1622 } while ((t
= t
->t_forw
) != p
->p_tlist
);
1625 * The signal action is being set to SIG_DFL and the default
1626 * behavior is to do something: make sure it is not ignored.
1628 sigdelset(&p
->p_ignore
, sig
);
1631 if (sig
== SIGCLD
) {
1632 if (flags
& SA_NOCLDWAIT
)
1633 p
->p_flag
|= SNOWAIT
;
1635 p
->p_flag
&= ~SNOWAIT
;
1637 if (flags
& SA_NOCLDSTOP
)
1638 p
->p_flag
&= ~SJCTL
;
1642 if ((p
->p_flag
& SNOWAIT
) || disp
== SIG_IGN
) {
1645 mutex_exit(&p
->p_lock
);
1646 mutex_enter(&pidlock
);
1647 for (cp
= p
->p_child
; cp
!= NULL
; cp
= tp
) {
1649 if (cp
->p_stat
== SZOMB
&&
1650 !(cp
->p_pidflag
& CLDWAITPID
))
1653 mutex_exit(&pidlock
);
1654 mutex_enter(&p
->p_lock
);
1660 * Set all signal actions not already set to SIG_DFL or SIG_IGN to SIG_DFL.
1661 * Called from exec_common() for a process undergoing execve()
1662 * and from cfork() for a newly-created child of vfork().
1663 * In the vfork() case, 'p' is not the current process.
1664 * In both cases, there is only one thread in the process.
1667 sigdefault(proc_t
*p
)
1669 kthread_t
*t
= p
->p_tlist
;
1670 struct user
*up
= PTOU(p
);
1673 ASSERT(MUTEX_HELD(&p
->p_lock
));
1675 for (sig
= 1; sig
< NSIG
; sig
++) {
1676 if (up
->u_signal
[sig
- 1] != SIG_DFL
&&
1677 up
->u_signal
[sig
- 1] != SIG_IGN
) {
1678 up
->u_signal
[sig
- 1] = SIG_DFL
;
1679 sigemptyset(&up
->u_sigmask
[sig
- 1]);
1680 if (sigismember(&ignoredefault
, sig
)) {
1681 sigdelq(p
, NULL
, sig
);
1685 p
->p_flag
&= ~(SNOWAIT
|SJCTL
);
1688 sigorset(&p
->p_ignore
, &ignoredefault
);
1689 sigfillset(&p
->p_siginfo
);
1690 sigdiffset(&p
->p_siginfo
, &cantmask
);
1691 sigdiffset(&p
->p_sig
, &ignoredefault
);
1692 sigdiffset(&p
->p_extsig
, &ignoredefault
);
1693 sigdiffset(&t
->t_sig
, &ignoredefault
);
1694 sigdiffset(&t
->t_extsig
, &ignoredefault
);
1698 sigcld(proc_t
*cp
, sigqueue_t
*sqp
)
1700 proc_t
*pp
= cp
->p_parent
;
1702 ASSERT(MUTEX_HELD(&pidlock
));
1704 switch (cp
->p_wcode
) {
1708 ASSERT(cp
->p_stat
== SZOMB
);
1710 * The broadcast on p_srwchan_cv is a kludge to
1711 * wakeup a possible thread in uadmin(A_SHUTDOWN).
1713 cv_broadcast(&cp
->p_srwchan_cv
);
1716 * Add to newstate list of the parent
1720 cv_broadcast(&pp
->p_cv
);
1721 if ((pp
->p_flag
& SNOWAIT
) ||
1722 PTOU(pp
)->u_signal
[SIGCLD
- 1] == SIG_IGN
) {
1723 if (!(cp
->p_pidflag
& CLDWAITPID
))
1725 } else if (!(cp
->p_pidflag
& CLDNOSIGCHLD
)) {
1726 post_sigcld(cp
, sqp
);
1733 cv_broadcast(&pp
->p_cv
);
1734 if (pp
->p_flag
& SJCTL
) {
1735 post_sigcld(cp
, sqp
);
1746 * Common code called from sigcld() and from
1747 * waitid() and issig_forreal() via sigcld_repost().
1748 * Give the parent process a SIGCLD if it does not have one pending,
1749 * else mark the child process so a SIGCLD can be posted later.
1752 post_sigcld(proc_t
*cp
, sigqueue_t
*sqp
)
1754 proc_t
*pp
= cp
->p_parent
;
1757 ASSERT(MUTEX_HELD(&pidlock
));
1758 mutex_enter(&pp
->p_lock
);
1761 * If a SIGCLD is pending, then just mark the child process
1762 * so that its SIGCLD will be posted later, when the first
1763 * SIGCLD is taken off the queue or when the parent is ready
1764 * to receive it or accept it, if ever.
1766 if (sigismember(&pp
->p_sig
, SIGCLD
)) {
1767 cp
->p_pidflag
|= CLDPEND
;
1769 cp
->p_pidflag
&= ~CLDPEND
;
1772 * This can only happen when the parent is init.
1773 * (See call to sigcld(q, NULL) in exit().)
1774 * Use KM_NOSLEEP to avoid deadlock.
1776 ASSERT(pp
== proc_init
);
1777 winfo(cp
, &info
, 0);
1778 sigaddq(pp
, NULL
, &info
, KM_NOSLEEP
);
1780 winfo(cp
, &sqp
->sq_info
, 0);
1781 sigaddqa(pp
, NULL
, sqp
);
1786 mutex_exit(&pp
->p_lock
);
1793 * Search for a child that has a pending SIGCLD for us, the parent.
1794 * The queue of SIGCLD signals is implied by the list of children.
1795 * We post the SIGCLD signals one at a time so they don't get lost.
1796 * When one is dequeued, another is enqueued, until there are no more.
1801 proc_t
*pp
= curproc
;
1805 sqp
= kmem_zalloc(sizeof (sigqueue_t
), KM_SLEEP
);
1806 mutex_enter(&pidlock
);
1807 for (cp
= pp
->p_child
; cp
; cp
= cp
->p_sibling
) {
1808 if (cp
->p_pidflag
& CLDPEND
) {
1809 post_sigcld(cp
, sqp
);
1810 mutex_exit(&pidlock
);
1814 mutex_exit(&pidlock
);
1815 kmem_free(sqp
, sizeof (sigqueue_t
));
1819 * count number of sigqueue send by sigaddqa()
1822 sigqsend(int cmd
, proc_t
*p
, kthread_t
*t
, sigqueue_t
*sigqp
)
1826 sqh
= (sigqhdr_t
*)sigqp
->sq_backptr
;
1829 mutex_enter(&sqh
->sqb_lock
);
1831 mutex_exit(&sqh
->sqb_lock
);
1834 sigaddqa(p
, t
, sigqp
);
1840 sigsendproc(proc_t
*p
, sigsend_t
*pv
)
1843 proc_t
*myprocp
= curproc
;
1845 ASSERT(MUTEX_HELD(&pidlock
));
1847 if (p
->p_pid
== 1 && pv
->sig
&& sigismember(&cantmask
, pv
->sig
))
1852 if (pv
->checkperm
== 0 ||
1853 (pv
->sig
== SIGCONT
&& p
->p_sessp
== myprocp
->p_sessp
) ||
1854 prochasprocperm(p
, myprocp
, cr
)) {
1857 /* Make sure we should be setting si_pid and friends */
1858 ASSERT(pv
->sicode
<= 0);
1859 if (SI_CANQUEUE(pv
->sicode
)) {
1862 mutex_enter(&myprocp
->p_lock
);
1863 sqp
= sigqalloc(myprocp
->p_sigqhdr
);
1864 mutex_exit(&myprocp
->p_lock
);
1867 sqp
->sq_info
.si_signo
= pv
->sig
;
1868 sqp
->sq_info
.si_code
= pv
->sicode
;
1869 sqp
->sq_info
.si_pid
= myprocp
->p_pid
;
1870 sqp
->sq_info
.si_ctid
= PRCTID(myprocp
);
1871 sqp
->sq_info
.si_zoneid
= getzoneid();
1872 sqp
->sq_info
.si_uid
= crgetruid(cr
);
1873 sqp
->sq_info
.si_value
= pv
->value
;
1874 mutex_enter(&p
->p_lock
);
1875 sigqsend(SN_SEND
, p
, NULL
, sqp
);
1876 mutex_exit(&p
->p_lock
);
1879 bzero(&info
, sizeof (info
));
1880 info
.si_signo
= pv
->sig
;
1881 info
.si_code
= pv
->sicode
;
1882 info
.si_pid
= myprocp
->p_pid
;
1883 info
.si_ctid
= PRCTID(myprocp
);
1884 info
.si_zoneid
= getzoneid();
1885 info
.si_uid
= crgetruid(cr
);
1886 mutex_enter(&p
->p_lock
);
1888 * XXX: Should be KM_SLEEP but
1889 * we have to avoid deadlock.
1891 sigaddq(p
, NULL
, &info
, KM_NOSLEEP
);
1892 mutex_exit(&p
->p_lock
);
1901 sigsendset(procset_t
*psp
, sigsend_t
*pv
)
1905 error
= dotoprocs(psp
, sigsendproc
, (char *)pv
);
1906 if (error
== 0 && pv
->perm
== 0)
1913 * Dequeue a queued siginfo structure.
1914 * If a non-null thread pointer is passed then dequeue from
1915 * the thread queue, otherwise dequeue from the process queue.
1918 sigdeq(proc_t
*p
, kthread_t
*t
, int sig
, sigqueue_t
**qpp
)
1920 sigqueue_t
**psqp
, *sqp
;
1922 ASSERT(MUTEX_HELD(&p
->p_lock
));
1927 sigdelset(&t
->t_sig
, sig
);
1928 sigdelset(&t
->t_extsig
, sig
);
1929 psqp
= &t
->t_sigqueue
;
1931 sigdelset(&p
->p_sig
, sig
);
1932 sigdelset(&p
->p_extsig
, sig
);
1933 psqp
= &p
->p_sigqueue
;
1937 if ((sqp
= *psqp
) == NULL
)
1939 if (sqp
->sq_info
.si_signo
== sig
)
1942 psqp
= &sqp
->sq_next
;
1945 *psqp
= sqp
->sq_next
;
1946 for (sqp
= *psqp
; sqp
; sqp
= sqp
->sq_next
) {
1947 if (sqp
->sq_info
.si_signo
== sig
) {
1949 sigaddset(&t
->t_sig
, sig
);
1952 sigaddset(&p
->p_sig
, sig
);
1961 * Delete a queued SIGCLD siginfo structure matching the k_siginfo_t argument.
1964 sigcld_delete(k_siginfo_t
*ip
)
1966 proc_t
*p
= curproc
;
1967 int another_sigcld
= 0;
1968 sigqueue_t
**psqp
, *sqp
;
1970 ASSERT(ip
->si_signo
== SIGCLD
);
1972 mutex_enter(&p
->p_lock
);
1974 if (!sigismember(&p
->p_sig
, SIGCLD
)) {
1975 mutex_exit(&p
->p_lock
);
1979 psqp
= &p
->p_sigqueue
;
1981 if ((sqp
= *psqp
) == NULL
) {
1982 mutex_exit(&p
->p_lock
);
1985 if (sqp
->sq_info
.si_signo
== SIGCLD
) {
1986 if (sqp
->sq_info
.si_pid
== ip
->si_pid
&&
1987 sqp
->sq_info
.si_code
== ip
->si_code
&&
1988 sqp
->sq_info
.si_status
== ip
->si_status
)
1992 psqp
= &sqp
->sq_next
;
1994 *psqp
= sqp
->sq_next
;
1998 for (sqp
= *psqp
; !another_sigcld
&& sqp
; sqp
= sqp
->sq_next
) {
1999 if (sqp
->sq_info
.si_signo
== SIGCLD
)
2003 if (!another_sigcld
) {
2004 sigdelset(&p
->p_sig
, SIGCLD
);
2005 sigdelset(&p
->p_extsig
, SIGCLD
);
2008 mutex_exit(&p
->p_lock
);
2012 * Delete queued siginfo structures.
2013 * If a non-null thread pointer is passed then delete from
2014 * the thread queue, otherwise delete from the process queue.
2017 sigdelq(proc_t
*p
, kthread_t
*t
, int sig
)
2019 sigqueue_t
**psqp
, *sqp
;
2022 * We must be holding p->p_lock unless the process is
2023 * being reaped or has failed to get started on fork.
2025 ASSERT(MUTEX_HELD(&p
->p_lock
) ||
2026 p
->p_stat
== SIDL
|| p
->p_stat
== SZOMB
);
2029 psqp
= &t
->t_sigqueue
;
2031 psqp
= &p
->p_sigqueue
;
2035 if (sig
== 0 || sqp
->sq_info
.si_signo
== sig
) {
2036 *psqp
= sqp
->sq_next
;
2039 psqp
= &sqp
->sq_next
;
2044 * Insert a siginfo structure into a queue.
2045 * If a non-null thread pointer is passed then add to the thread queue,
2046 * otherwise add to the process queue.
2048 * The function sigaddqins() is called with sigqueue already allocated.
2049 * It is called from sigaddqa() and sigaddq() below.
2051 * The value of si_code implicitly indicates whether sigp is to be
2052 * explicitly queued, or to be queued to depth one.
2055 sigaddqins(proc_t
*p
, kthread_t
*t
, sigqueue_t
*sigqp
)
2058 int sig
= sigqp
->sq_info
.si_signo
;
2060 sigqp
->sq_external
= (curproc
!= &p0
) &&
2061 (curproc
->p_ct_process
!= p
->p_ct_process
);
2064 * issig_forreal() doesn't bother dequeueing signals if SKILLED
2065 * is set, and even if it did, we would want to avoid situation
2066 * (which would be unique to SIGKILL) where one thread dequeued
2067 * the sigqueue_t and another executed psig(). So we create a
2068 * separate stash for SIGKILL's sigqueue_t. Because a second
2069 * SIGKILL can set SEXTKILLED, we overwrite the existing entry
2070 * if (and only if) it was non-extracontractual.
2072 if (sig
== SIGKILL
) {
2073 if (p
->p_killsqp
== NULL
|| !p
->p_killsqp
->sq_external
) {
2074 if (p
->p_killsqp
!= NULL
)
2075 siginfofree(p
->p_killsqp
);
2076 p
->p_killsqp
= sigqp
;
2077 sigqp
->sq_next
= NULL
;
2084 ASSERT(sig
>= 1 && sig
< NSIG
);
2085 if (t
!= NULL
) /* directed to a thread */
2086 psqp
= &t
->t_sigqueue
;
2087 else /* directed to a process */
2088 psqp
= &p
->p_sigqueue
;
2089 if (SI_CANQUEUE(sigqp
->sq_info
.si_code
) &&
2090 sigismember(&p
->p_siginfo
, sig
)) {
2091 for (; *psqp
!= NULL
; psqp
= &(*psqp
)->sq_next
)
2094 for (; *psqp
!= NULL
; psqp
= &(*psqp
)->sq_next
) {
2095 if ((*psqp
)->sq_info
.si_signo
== sig
) {
2102 sigqp
->sq_next
= NULL
;
2106 * The function sigaddqa() is called with sigqueue already allocated.
2107 * If signal is ignored, discard but guarantee KILL and generation semantics.
2108 * It is called from sigqueue() and other places.
2111 sigaddqa(proc_t
*p
, kthread_t
*t
, sigqueue_t
*sigqp
)
2113 int sig
= sigqp
->sq_info
.si_signo
;
2115 ASSERT(MUTEX_HELD(&p
->p_lock
));
2116 ASSERT(sig
>= 1 && sig
< NSIG
);
2118 if (sig_discardable(p
, sig
))
2121 sigaddqins(p
, t
, sigqp
);
2123 sigtoproc(p
, t
, sig
);
2127 * Allocate the sigqueue_t structure and call sigaddqins().
2130 sigaddq(proc_t
*p
, kthread_t
*t
, k_siginfo_t
*infop
, int km_flags
)
2133 int sig
= infop
->si_signo
;
2135 ASSERT(MUTEX_HELD(&p
->p_lock
));
2136 ASSERT(sig
>= 1 && sig
< NSIG
);
2139 * If the signal will be discarded by sigtoproc() or
2140 * if the process isn't requesting siginfo and it isn't
2141 * blocking the signal (it *could* change it's mind while
2142 * the signal is pending) then don't bother creating one.
2144 if (!sig_discardable(p
, sig
) &&
2145 (sigismember(&p
->p_siginfo
, sig
) ||
2146 (curproc
->p_ct_process
!= p
->p_ct_process
) ||
2147 (sig
== SIGCLD
&& SI_FROMKERNEL(infop
))) &&
2148 ((sqp
= kmem_alloc(sizeof (sigqueue_t
), km_flags
)) != NULL
)) {
2149 bcopy(infop
, &sqp
->sq_info
, sizeof (k_siginfo_t
));
2150 sqp
->sq_func
= NULL
;
2151 sqp
->sq_next
= NULL
;
2152 sigaddqins(p
, t
, sqp
);
2154 sigtoproc(p
, t
, sig
);
2158 * Handle stop-on-fault processing for the debugger. Returns 0
2159 * if the fault is cleared during the stop, nonzero if it isn't.
2162 stop_on_fault(uint_t fault
, k_siginfo_t
*sip
)
2164 proc_t
*p
= ttoproc(curthread
);
2165 klwp_t
*lwp
= ttolwp(curthread
);
2167 ASSERT(prismember(&p
->p_fltmask
, fault
));
2170 * Record current fault and siginfo structure so debugger can
2173 mutex_enter(&p
->p_lock
);
2174 lwp
->lwp_curflt
= (uchar_t
)fault
;
2175 lwp
->lwp_siginfo
= *sip
;
2177 stop(PR_FAULTED
, fault
);
2179 fault
= lwp
->lwp_curflt
;
2180 lwp
->lwp_curflt
= 0;
2181 mutex_exit(&p
->p_lock
);
2186 sigorset(k_sigset_t
*s1
, const k_sigset_t
*s2
)
2188 s1
->__sigbits
[0] |= s2
->__sigbits
[0];
2189 s1
->__sigbits
[1] |= s2
->__sigbits
[1];
2190 s1
->__sigbits
[2] |= s2
->__sigbits
[2];
2194 sigandset(k_sigset_t
*s1
, const k_sigset_t
*s2
)
2196 s1
->__sigbits
[0] &= s2
->__sigbits
[0];
2197 s1
->__sigbits
[1] &= s2
->__sigbits
[1];
2198 s1
->__sigbits
[2] &= s2
->__sigbits
[2];
2202 sigdiffset(k_sigset_t
*s1
, const k_sigset_t
*s2
)
2204 s1
->__sigbits
[0] &= ~(s2
->__sigbits
[0]);
2205 s1
->__sigbits
[1] &= ~(s2
->__sigbits
[1]);
2206 s1
->__sigbits
[2] &= ~(s2
->__sigbits
[2]);
2210 * Return non-zero if curthread->t_sig_check should be set to 1, that is,
2211 * if there are any signals the thread might take on return from the kernel.
2212 * If ksigset_t's were a single word, we would do:
2213 * return (((p->p_sig | t->t_sig) & ~t->t_hold) & fillset);
2216 sigcheck(proc_t
*p
, kthread_t
*t
)
2218 sc_shared_t
*tdp
= t
->t_schedctl
;
2221 * If signals are blocked via the schedctl interface
2222 * then we only check for the unmaskable signals.
2223 * The unmaskable signal numbers should all be contained
2224 * in __sigbits[0] and we assume this for speed.
2226 #if (CANTMASK1 == 0 && CANTMASK2 == 0)
2227 if (tdp
!= NULL
&& tdp
->sc_sigblock
)
2228 return ((p
->p_sig
.__sigbits
[0] | t
->t_sig
.__sigbits
[0]) &
2231 #error "fix me: CANTMASK1 and CANTMASK2 are not zero"
2234 /* see include/sys/signal.h for why this must be true */
2235 #if ((MAXSIG > (2 * 32)) && (MAXSIG <= (3 * 32)))
2236 return (((p
->p_sig
.__sigbits
[0] | t
->t_sig
.__sigbits
[0]) &
2237 ~t
->t_hold
.__sigbits
[0]) |
2238 ((p
->p_sig
.__sigbits
[1] | t
->t_sig
.__sigbits
[1]) &
2239 ~t
->t_hold
.__sigbits
[1]) |
2240 (((p
->p_sig
.__sigbits
[2] | t
->t_sig
.__sigbits
[2]) &
2241 ~t
->t_hold
.__sigbits
[2]) & FILLSET2
));
2243 #error "fix me: MAXSIG out of bounds"
2248 sigintr(k_sigset_t
*smask
, int intable
)
2252 k_sigset_t lmask
; /* local copy of cantmask */
2253 klwp_t
*lwp
= ttolwp(curthread
);
2256 * Mask out all signals except SIGHUP, SIGINT, SIGQUIT
2257 * and SIGTERM. (Preserving the existing masks).
2258 * This function supports the -intr nfs and ufs mount option.
2262 * don't do kernel threads
2268 * get access to signal mask
2270 p
= ttoproc(curthread
);
2271 owned
= mutex_owned(&p
->p_lock
); /* this is filthy */
2273 mutex_enter(&p
->p_lock
);
2276 * remember the current mask
2278 schedctl_finish_sigblock(curthread
);
2279 *smask
= curthread
->t_hold
;
2282 * mask out all signals
2284 sigfillset(&curthread
->t_hold
);
2287 * Unmask the non-maskable signals (e.g., KILL), as long as
2288 * they aren't already masked (which could happen at exit).
2289 * The first sigdiffset sets lmask to (cantmask & ~curhold). The
2290 * second sets the current hold mask to (~0 & ~lmask), which reduces
2291 * to (~cantmask | curhold).
2294 sigdiffset(&lmask
, smask
);
2295 sigdiffset(&curthread
->t_hold
, &lmask
);
2298 * Re-enable HUP, QUIT, and TERM iff they were originally enabled
2299 * Re-enable INT if it's originally enabled and the NFS mount option
2300 * nointr is not set.
2302 if (!sigismember(smask
, SIGHUP
))
2303 sigdelset(&curthread
->t_hold
, SIGHUP
);
2304 if (!sigismember(smask
, SIGINT
) && intable
)
2305 sigdelset(&curthread
->t_hold
, SIGINT
);
2306 if (!sigismember(smask
, SIGQUIT
))
2307 sigdelset(&curthread
->t_hold
, SIGQUIT
);
2308 if (!sigismember(smask
, SIGTERM
))
2309 sigdelset(&curthread
->t_hold
, SIGTERM
);
2312 * release access to signal mask
2315 mutex_exit(&p
->p_lock
);
2318 * Indicate that this lwp is not to be stopped.
2325 sigunintr(k_sigset_t
*smask
)
2329 klwp_t
*lwp
= ttolwp(curthread
);
2332 * Reset previous mask (See sigintr() above)
2335 lwp
->lwp_nostop
--; /* restore lwp stoppability */
2336 p
= ttoproc(curthread
);
2337 owned
= mutex_owned(&p
->p_lock
); /* this is filthy */
2339 mutex_enter(&p
->p_lock
);
2340 curthread
->t_hold
= *smask
;
2341 /* so unmasked signals will be seen */
2342 curthread
->t_sig_check
= 1;
2344 mutex_exit(&p
->p_lock
);
2349 sigreplace(k_sigset_t
*newmask
, k_sigset_t
*oldmask
)
2354 * Save current signal mask in oldmask, then
2355 * set it to newmask.
2357 if (ttolwp(curthread
) != NULL
) {
2358 p
= ttoproc(curthread
);
2359 owned
= mutex_owned(&p
->p_lock
); /* this is filthy */
2361 mutex_enter(&p
->p_lock
);
2362 schedctl_finish_sigblock(curthread
);
2363 if (oldmask
!= NULL
)
2364 *oldmask
= curthread
->t_hold
;
2365 curthread
->t_hold
= *newmask
;
2366 curthread
->t_sig_check
= 1;
2368 mutex_exit(&p
->p_lock
);
2373 * Return true if the signal number is in range
2374 * and the signal code specifies signal queueing.
2377 sigwillqueue(int sig
, int code
)
2379 if (sig
>= 0 && sig
< NSIG
) {
2392 * The pre-allocated pool (with _SIGQUEUE_PREALLOC entries) is
2393 * allocated at the first sigqueue/signotify call.
2396 sigqhdralloc(size_t size
, uint_t maxcount
)
2399 sigqueue_t
*sq
, *next
;
2403 * Before the introduction of process.max-sigqueue-size
2404 * _SC_SIGQUEUE_MAX had this static value.
2406 #define _SIGQUEUE_PREALLOC 32
2408 i
= (_SIGQUEUE_PREALLOC
* size
) + sizeof (sigqhdr_t
);
2409 ASSERT(maxcount
<= INT_MAX
);
2410 sqh
= kmem_alloc(i
, KM_SLEEP
);
2411 sqh
->sqb_count
= maxcount
;
2412 sqh
->sqb_maxcount
= maxcount
;
2414 sqh
->sqb_pexited
= 0;
2416 sqh
->sqb_free
= sq
= (sigqueue_t
*)(sqh
+ 1);
2417 for (i
= _SIGQUEUE_PREALLOC
- 1; i
!= 0; i
--) {
2418 next
= (sigqueue_t
*)((uintptr_t)sq
+ size
);
2423 cv_init(&sqh
->sqb_cv
, NULL
, CV_DEFAULT
, NULL
);
2424 mutex_init(&sqh
->sqb_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
2428 static void sigqrel(sigqueue_t
*);
2431 * Allocate a sigqueue/signotify structure from the per process
2432 * pre-allocated pool or allocate a new sigqueue/signotify structure
2433 * if the pre-allocated pool is exhausted.
2436 sigqalloc(sigqhdr_t
*sqh
)
2438 sigqueue_t
*sq
= NULL
;
2440 ASSERT(MUTEX_HELD(&curproc
->p_lock
));
2443 mutex_enter(&sqh
->sqb_lock
);
2444 if (sqh
->sqb_count
> 0) {
2446 if (sqh
->sqb_free
== NULL
) {
2448 * The pre-allocated pool is exhausted.
2450 sq
= kmem_alloc(sizeof (sigqueue_t
), KM_SLEEP
);
2454 sq
->sq_func
= sigqrel
;
2455 sqh
->sqb_free
= sq
->sq_next
;
2457 mutex_exit(&sqh
->sqb_lock
);
2458 bzero(&sq
->sq_info
, sizeof (k_siginfo_t
));
2459 sq
->sq_backptr
= sqh
;
2461 sq
->sq_external
= 0;
2463 mutex_exit(&sqh
->sqb_lock
);
2470 * Return a sigqueue structure back to the pre-allocated pool.
2473 sigqrel(sigqueue_t
*sq
)
2477 /* make sure that p_lock of the affected process is held */
2479 sqh
= (sigqhdr_t
*)sq
->sq_backptr
;
2480 mutex_enter(&sqh
->sqb_lock
);
2481 if (sqh
->sqb_pexited
&& sqh
->sqb_sent
== 1) {
2482 mutex_exit(&sqh
->sqb_lock
);
2483 cv_destroy(&sqh
->sqb_cv
);
2484 mutex_destroy(&sqh
->sqb_lock
);
2485 kmem_free(sqh
, sqh
->sqb_size
);
2489 sq
->sq_next
= sqh
->sqb_free
;
2490 sq
->sq_backptr
= NULL
;
2492 cv_signal(&sqh
->sqb_cv
);
2493 mutex_exit(&sqh
->sqb_lock
);
2498 * Free up the pre-allocated sigqueue headers of sigqueue pool
2499 * and signotify pool, if possible.
2500 * Called only by the owning process during exec() and exit().
2505 ASSERT(MUTEX_HELD(&p
->p_lock
));
2507 if (p
->p_sigqhdr
!= NULL
) { /* sigqueue pool */
2508 sigqhdrfree(p
->p_sigqhdr
);
2509 p
->p_sigqhdr
= NULL
;
2511 if (p
->p_signhdr
!= NULL
) { /* signotify pool */
2512 sigqhdrfree(p
->p_signhdr
);
2513 p
->p_signhdr
= NULL
;
2518 * Free up the pre-allocated header and sigq pool if possible.
2521 sigqhdrfree(sigqhdr_t
*sqh
)
2523 mutex_enter(&sqh
->sqb_lock
);
2524 if (sqh
->sqb_sent
== 0) {
2525 mutex_exit(&sqh
->sqb_lock
);
2526 cv_destroy(&sqh
->sqb_cv
);
2527 mutex_destroy(&sqh
->sqb_lock
);
2528 kmem_free(sqh
, sqh
->sqb_size
);
2530 sqh
->sqb_pexited
= 1;
2531 mutex_exit(&sqh
->sqb_lock
);
2536 * Free up a single sigqueue structure.
2537 * No other code should free a sigqueue directly.
2540 siginfofree(sigqueue_t
*sqp
)
2543 if (sqp
->sq_func
!= NULL
)
2544 (sqp
->sq_func
)(sqp
);
2546 kmem_free(sqp
, sizeof (sigqueue_t
));
2551 * Generate a synchronous signal caused by a hardware
2552 * condition encountered by an lwp. Called from trap().
2555 trapsig(k_siginfo_t
*ip
, int restartable
)
2557 proc_t
*p
= ttoproc(curthread
);
2558 int sig
= ip
->si_signo
;
2559 sigqueue_t
*sqp
= kmem_zalloc(sizeof (sigqueue_t
), KM_SLEEP
);
2561 ASSERT(sig
> 0 && sig
< NSIG
);
2563 if (curthread
->t_dtrace_on
)
2564 dtrace_safe_synchronous_signal();
2566 mutex_enter(&p
->p_lock
);
2567 schedctl_finish_sigblock(curthread
);
2569 * Avoid a possible infinite loop if the lwp is holding the
2570 * signal generated by a trap of a restartable instruction or
2571 * if the signal so generated is being ignored by the process.
2574 (sigismember(&curthread
->t_hold
, sig
) ||
2575 p
->p_user
.u_signal
[sig
-1] == SIG_IGN
)) {
2576 sigdelset(&curthread
->t_hold
, sig
);
2577 p
->p_user
.u_signal
[sig
-1] = SIG_DFL
;
2578 sigdelset(&p
->p_ignore
, sig
);
2580 bcopy(ip
, &sqp
->sq_info
, sizeof (k_siginfo_t
));
2581 sigaddqa(p
, curthread
, sqp
);
2582 mutex_exit(&p
->p_lock
);
2586 * Dispatch the real time profiling signal in the traditional way,
2587 * honoring all of the /proc tracing mechanism built into issig().
2590 realsigprof_slow(int sysnum
, int nsysarg
, int error
)
2592 kthread_t
*t
= curthread
;
2593 proc_t
*p
= ttoproc(t
);
2594 klwp_t
*lwp
= ttolwp(t
);
2595 k_siginfo_t
*sip
= &lwp
->lwp_siginfo
;
2598 mutex_enter(&p
->p_lock
);
2599 func
= PTOU(p
)->u_signal
[SIGPROF
- 1];
2600 if (p
->p_rprof_cyclic
== CYCLIC_NONE
||
2601 func
== SIG_DFL
|| func
== SIG_IGN
) {
2602 bzero(t
->t_rprof
, sizeof (*t
->t_rprof
));
2603 mutex_exit(&p
->p_lock
);
2606 if (sigismember(&t
->t_hold
, SIGPROF
)) {
2607 mutex_exit(&p
->p_lock
);
2610 sip
->si_signo
= SIGPROF
;
2611 sip
->si_code
= PROF_SIG
;
2612 sip
->si_errno
= error
;
2613 hrt2ts(gethrtime(), &sip
->si_tstamp
);
2614 sip
->si_syscall
= sysnum
;
2615 sip
->si_nsysarg
= nsysarg
;
2616 sip
->si_fault
= lwp
->lwp_lastfault
;
2617 sip
->si_faddr
= lwp
->lwp_lastfaddr
;
2618 lwp
->lwp_lastfault
= 0;
2619 lwp
->lwp_lastfaddr
= NULL
;
2620 sigtoproc(p
, t
, SIGPROF
);
2621 mutex_exit(&p
->p_lock
);
2622 ASSERT(lwp
->lwp_cursig
== 0);
2626 bzero(t
->t_rprof
, sizeof (*t
->t_rprof
));
2630 * We are not tracing the SIGPROF signal, or doing any other unnatural
2631 * acts, like watchpoints, so dispatch the real time profiling signal
2632 * directly, bypassing all of the overhead built into issig().
2635 realsigprof_fast(int sysnum
, int nsysarg
, int error
)
2637 kthread_t
*t
= curthread
;
2638 proc_t
*p
= ttoproc(t
);
2639 klwp_t
*lwp
= ttolwp(t
);
2640 k_siginfo_t
*sip
= &lwp
->lwp_siginfo
;
2646 * We don't need to acquire p->p_lock here;
2647 * we are manipulating thread-private data.
2649 func
= PTOU(p
)->u_signal
[SIGPROF
- 1];
2650 if (p
->p_rprof_cyclic
== CYCLIC_NONE
||
2651 func
== SIG_DFL
|| func
== SIG_IGN
) {
2652 bzero(t
->t_rprof
, sizeof (*t
->t_rprof
));
2655 if (lwp
->lwp_cursig
!= 0 ||
2656 lwp
->lwp_curinfo
!= NULL
||
2657 sigismember(&t
->t_hold
, SIGPROF
)) {
2660 sip
->si_signo
= SIGPROF
;
2661 sip
->si_code
= PROF_SIG
;
2662 sip
->si_errno
= error
;
2663 hrt2ts(gethrtime(), &sip
->si_tstamp
);
2664 sip
->si_syscall
= sysnum
;
2665 sip
->si_nsysarg
= nsysarg
;
2666 sip
->si_fault
= lwp
->lwp_lastfault
;
2667 sip
->si_faddr
= lwp
->lwp_lastfaddr
;
2668 lwp
->lwp_lastfault
= 0;
2669 lwp
->lwp_lastfaddr
= NULL
;
2670 if (t
->t_flag
& T_TOMASK
)
2671 t
->t_flag
&= ~T_TOMASK
;
2673 lwp
->lwp_sigoldmask
= t
->t_hold
;
2674 sigorset(&t
->t_hold
, &PTOU(p
)->u_sigmask
[SIGPROF
- 1]);
2675 if (!sigismember(&PTOU(p
)->u_signodefer
, SIGPROF
))
2676 sigaddset(&t
->t_hold
, SIGPROF
);
2677 lwp
->lwp_extsig
= 0;
2678 lwp
->lwp_ru
.nsignals
++;
2679 if (p
->p_model
== DATAMODEL_NATIVE
)
2680 rc
= sendsig(SIGPROF
, sip
, func
);
2681 #ifdef _SYSCALL32_IMPL
2683 rc
= sendsig32(SIGPROF
, sip
, func
);
2684 #endif /* _SYSCALL32_IMPL */
2686 bzero(t
->t_rprof
, sizeof (*t
->t_rprof
));
2689 * sendsig() failed; we must dump core with a SIGSEGV.
2690 * See psig(). This code is copied from there.
2692 lwp
->lwp_cursig
= SIGSEGV
;
2695 if (exitlwps(1) != 0) {
2696 mutex_enter(&p
->p_lock
);
2699 if (audit_active
== C2AUDIT_LOADED
)
2700 audit_core_start(SIGSEGV
);
2701 if (core(SIGSEGV
, 0) == 0)
2703 if (audit_active
== C2AUDIT_LOADED
)
2704 audit_core_finish(code
);
2705 exit(code
, SIGSEGV
);
2710 * Arrange for the real time profiling signal to be dispatched.
2713 realsigprof(int sysnum
, int nsysarg
, int error
)
2715 kthread_t
*t
= curthread
;
2716 proc_t
*p
= ttoproc(t
);
2718 if (t
->t_rprof
->rp_anystate
== 0)
2721 schedctl_finish_sigblock(t
);
2723 /* test for any activity that requires p->p_lock */
2724 if (tracing(p
, SIGPROF
) || pr_watch_active(p
) ||
2725 sigismember(&PTOU(p
)->u_sigresethand
, SIGPROF
)) {
2726 /* do it the classic slow way */
2727 realsigprof_slow(sysnum
, nsysarg
, error
);
2729 /* do it the cheating-a-little fast way */
2730 realsigprof_fast(sysnum
, nsysarg
, error
);
2734 #ifdef _SYSCALL32_IMPL
2737 * It's tricky to transmit a sigval between 32-bit and 64-bit
2738 * process, since in the 64-bit world, a pointer and an integer
2739 * are different sizes. Since we're constrained by the standards
2740 * world not to change the types, and it's unclear how useful it is
2741 * to send pointers between address spaces this way, we preserve
2742 * the 'int' interpretation for 32-bit processes interoperating
2743 * with 64-bit processes. The full semantics (pointers or integers)
2744 * are available for N-bit processes interoperating with N-bit
2748 siginfo_kto32(const k_siginfo_t
*src
, siginfo32_t
*dest
)
2750 bzero(dest
, sizeof (*dest
));
2753 * The absolute minimum content is si_signo and si_code.
2755 dest
->si_signo
= src
->si_signo
;
2756 if ((dest
->si_code
= src
->si_code
) == SI_NOINFO
)
2760 * A siginfo generated by user level is structured
2761 * differently from one generated by the kernel.
2763 if (SI_FROMUSER(src
)) {
2764 dest
->si_pid
= src
->si_pid
;
2765 dest
->si_ctid
= src
->si_ctid
;
2766 dest
->si_zoneid
= src
->si_zoneid
;
2767 dest
->si_uid
= src
->si_uid
;
2768 if (SI_CANQUEUE(src
->si_code
))
2769 dest
->si_value
.sival_int
=
2770 (int32_t)src
->si_value
.sival_int
;
2774 dest
->si_errno
= src
->si_errno
;
2776 switch (src
->si_signo
) {
2778 dest
->si_pid
= src
->si_pid
;
2779 dest
->si_ctid
= src
->si_ctid
;
2780 dest
->si_zoneid
= src
->si_zoneid
;
2781 dest
->si_uid
= src
->si_uid
;
2782 dest
->si_value
.sival_int
= (int32_t)src
->si_value
.sival_int
;
2785 dest
->si_pid
= src
->si_pid
;
2786 dest
->si_ctid
= src
->si_ctid
;
2787 dest
->si_zoneid
= src
->si_zoneid
;
2788 dest
->si_status
= src
->si_status
;
2789 dest
->si_stime
= src
->si_stime
;
2790 dest
->si_utime
= src
->si_utime
;
2798 dest
->si_addr
= (caddr32_t
)(uintptr_t)src
->si_addr
;
2799 dest
->si_trapno
= src
->si_trapno
;
2800 dest
->si_pc
= (caddr32_t
)(uintptr_t)src
->si_pc
;
2804 dest
->si_fd
= src
->si_fd
;
2805 dest
->si_band
= src
->si_band
;
2808 dest
->si_faddr
= (caddr32_t
)(uintptr_t)src
->si_faddr
;
2809 dest
->si_tstamp
.tv_sec
= src
->si_tstamp
.tv_sec
;
2810 dest
->si_tstamp
.tv_nsec
= src
->si_tstamp
.tv_nsec
;
2811 dest
->si_syscall
= src
->si_syscall
;
2812 dest
->si_nsysarg
= src
->si_nsysarg
;
2813 dest
->si_fault
= src
->si_fault
;
2819 siginfo_32tok(const siginfo32_t
*src
, k_siginfo_t
*dest
)
2821 bzero(dest
, sizeof (*dest
));
2824 * The absolute minimum content is si_signo and si_code.
2826 dest
->si_signo
= src
->si_signo
;
2827 if ((dest
->si_code
= src
->si_code
) == SI_NOINFO
)
2831 * A siginfo generated by user level is structured
2832 * differently from one generated by the kernel.
2834 if (SI_FROMUSER(src
)) {
2835 dest
->si_pid
= src
->si_pid
;
2836 dest
->si_ctid
= src
->si_ctid
;
2837 dest
->si_zoneid
= src
->si_zoneid
;
2838 dest
->si_uid
= src
->si_uid
;
2839 if (SI_CANQUEUE(src
->si_code
))
2840 dest
->si_value
.sival_int
=
2841 (int)src
->si_value
.sival_int
;
2845 dest
->si_errno
= src
->si_errno
;
2847 switch (src
->si_signo
) {
2849 dest
->si_pid
= src
->si_pid
;
2850 dest
->si_ctid
= src
->si_ctid
;
2851 dest
->si_zoneid
= src
->si_zoneid
;
2852 dest
->si_uid
= src
->si_uid
;
2853 dest
->si_value
.sival_int
= (int)src
->si_value
.sival_int
;
2856 dest
->si_pid
= src
->si_pid
;
2857 dest
->si_ctid
= src
->si_ctid
;
2858 dest
->si_zoneid
= src
->si_zoneid
;
2859 dest
->si_status
= src
->si_status
;
2860 dest
->si_stime
= src
->si_stime
;
2861 dest
->si_utime
= src
->si_utime
;
2869 dest
->si_addr
= (void *)(uintptr_t)src
->si_addr
;
2870 dest
->si_trapno
= src
->si_trapno
;
2871 dest
->si_pc
= (void *)(uintptr_t)src
->si_pc
;
2875 dest
->si_fd
= src
->si_fd
;
2876 dest
->si_band
= src
->si_band
;
2879 dest
->si_faddr
= (void *)(uintptr_t)src
->si_faddr
;
2880 dest
->si_tstamp
.tv_sec
= src
->si_tstamp
.tv_sec
;
2881 dest
->si_tstamp
.tv_nsec
= src
->si_tstamp
.tv_nsec
;
2882 dest
->si_syscall
= src
->si_syscall
;
2883 dest
->si_nsysarg
= src
->si_nsysarg
;
2884 dest
->si_fault
= src
->si_fault
;
2889 #endif /* _SYSCALL32_IMPL */