2 * Copyright (c) 2000-2001 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* Copyright (c) 1995-1998 Apple Computer, Inc. All Rights Reserved */
30 * Copyright (c) 1982, 1986, 1989, 1991, 1993
31 * The Regents of the University of California. All rights reserved.
32 * (c) UNIX System Laboratories, Inc.
33 * All or some portions of this file are derived from material licensed
34 * to the University of California by American Telephone and Telegraph
35 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
36 * the permission of UNIX System Laboratories, Inc.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by the University of
49 * California, Berkeley and its contributors.
50 * 4. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66 * @(#)kern_sig.c 8.7 (Berkeley) 4/18/94
69 #define SIGPROP /* include signal properties table */
70 #include <sys/param.h>
71 #include <sys/resourcevar.h>
72 #include <sys/proc_internal.h>
73 #include <sys/kauth.h>
74 #include <sys/systm.h>
75 #include <sys/timeb.h>
76 #include <sys/times.h>
78 #include <sys/file_internal.h>
79 #include <sys/kernel.h>
81 #include <sys/signalvar.h>
83 #include <sys/ktrace.h>
85 #include <sys/syslog.h>
88 #include <sys/kdebug.h>
90 #include <sys/mount.h>
91 #include <sys/sysproto.h>
93 #include <bsm/audit_kernel.h>
95 #include <machine/spl.h>
97 #include <kern/cpu_number.h>
100 #include <sys/user.h> /* for coredump */
101 #include <kern/ast.h> /* for APC support */
102 #include <kern/lock.h>
103 #include <kern/task.h> /* extern void *get_bsdtask_info(task_t); */
104 #include <kern/thread.h>
105 #include <kern/sched_prim.h>
106 #include <kern/thread_call.h>
107 #include <mach/exception.h>
108 #include <mach/task.h>
109 #include <mach/thread_act.h>
112 * Missing prototypes that Mach should export
116 extern int thread_enable_fpe(thread_t act
, int onoff
);
117 extern void unix_syscall_return(int error
);
118 extern thread_t
port_name_to_thread(mach_port_name_t port_name
);
119 extern kern_return_t
check_actforsig(task_t task
, thread_t thread
, int setast
);
120 extern kern_return_t
get_signalact(task_t
, thread_t
*, int);
121 extern boolean_t
thread_should_abort(thread_t
);
122 extern unsigned int get_useraddr(void);
128 extern void doexception(int exc
, int code
, int sub
);
130 void stop(struct proc
*p
);
131 int cansignal(struct proc
*, kauth_cred_t
, struct proc
*, int);
132 int killpg1(struct proc
*, int, int, int);
133 void sigexit_locked(struct proc
*, int);
134 int setsigvec(struct proc
*, int, struct __user_sigaction
*);
135 void exit1(struct proc
*, int, int *);
136 void psignal_uthread(thread_t
, int);
137 kern_return_t
do_bsdexception(int, int, int);
138 void __posix_sem_syscall_return(kern_return_t
);
140 /* implementations in osfmk/kern/sync_sema.c. We do not want port.h in this scope, so void * them */
141 kern_return_t
semaphore_timedwait_signal_trap_internal(void *, void *,time_t, int32_t, void (*)(int));
142 kern_return_t
semaphore_timedwait_trap_internal(void *, time_t, int32_t, void (*)(int));
143 kern_return_t
semaphore_wait_signal_trap_internal(void *, void *, void (*)(int));
144 kern_return_t
semaphore_wait_trap_internal(void *, void (*)(int));
146 static int filt_sigattach(struct knote
*kn
);
147 static void filt_sigdetach(struct knote
*kn
);
148 static int filt_signal(struct knote
*kn
, long hint
);
150 struct filterops sig_filtops
=
151 { 0, filt_sigattach
, filt_sigdetach
, filt_signal
};
155 * NOTE: Source and target may *NOT* overlap! (target is smaller)
158 sigaltstack_64to32(struct user_sigaltstack
*in
, struct sigaltstack
*out
)
160 out
->ss_sp
= CAST_DOWN(void *,in
->ss_sp
);
161 out
->ss_size
= in
->ss_size
;
162 out
->ss_flags
= in
->ss_flags
;
166 * NOTE: Source and target may are permitted to overlap! (source is smaller);
167 * this works because we copy fields in order from the end of the struct to
171 sigaltstack_32to64(struct sigaltstack
*in
, struct user_sigaltstack
*out
)
173 out
->ss_flags
= in
->ss_flags
;
174 out
->ss_size
= in
->ss_size
;
175 out
->ss_sp
= CAST_USER_ADDR_T(in
->ss_sp
);
179 sigaction_64to32(struct user_sigaction
*in
, struct sigaction
*out
)
181 /* This assumes 32 bit __sa_handler is of type sig_t */
182 out
->__sigaction_u
.__sa_handler
= CAST_DOWN(sig_t
,in
->__sigaction_u
.__sa_handler
);
183 out
->sa_mask
= in
->sa_mask
;
184 out
->sa_flags
= in
->sa_flags
;
188 __sigaction_32to64(struct __sigaction
*in
, struct __user_sigaction
*out
)
190 out
->__sigaction_u
.__sa_handler
= CAST_USER_ADDR_T(in
->__sigaction_u
.__sa_handler
);
191 out
->sa_tramp
= CAST_USER_ADDR_T(in
->sa_tramp
);
192 out
->sa_mask
= in
->sa_mask
;
193 out
->sa_flags
= in
->sa_flags
;
198 void ram_printf(int);
200 unsigned int rdebug_proc
=0;
207 #endif /* SIGNAL_DEBUG */
210 signal_lock(struct proc
*p
)
217 int register sp
, *fp
, numsaved
;
219 __asm__
volatile("mr %0,r1" : "=r" (sp
));
221 fp
= (int *)*((int *)sp
);
222 for (numsaved
= 0; numsaved
< 3; numsaved
++) {
223 p
->lockpc
[numsaved
] = fp
[2];
230 #endif /* SIGNAL_DEBUG */
231 #endif /* DIAGNOSTIC */
234 error
= lockmgr((struct lock__bsd__
*)&p
->signal_lock
[0], LK_EXCLUSIVE
, 0, (struct proc
*)0);
241 signal_unlock(struct proc
*p
)
247 int register sp
, *fp
, numsaved
;
249 __asm__
volatile("mr %0,r1" : "=r" (sp
));
251 fp
= (int *)*((int *)sp
);
252 for (numsaved
= 0; numsaved
< 3; numsaved
++) {
253 p
->unlockpc
[numsaved
] = fp
[2];
260 #endif /* SIGNAL_DEBUG */
261 #endif /* DIAGNOSTIC */
263 /* TBD: check p last arg */
264 return(lockmgr((struct lock__bsd__
*)&p
->signal_lock
[0], LK_RELEASE
, (simple_lock_t
)0, (struct proc
*)0));
268 signal_setast(sig_actthread
)
269 thread_t sig_actthread
;
271 act_set_astbsd(sig_actthread
);
275 * Can process p, with ucred uc, send the signal signum to process q?
278 cansignal(p
, uc
, q
, signum
)
284 /* you can signal yourself */
288 if (!suser(uc
, NULL
))
289 return (1); /* root can always signal */
291 if (signum
== SIGCONT
&& q
->p_session
== p
->p_session
)
292 return (1); /* SIGCONT in session */
295 * Using kill(), only certain signals can be sent to setugid
298 if (q
->p_flag
& P_SUGID
) {
311 if (uc
->cr_ruid
== q
->p_ucred
->cr_ruid
||
312 kauth_cred_getuid(uc
) == q
->p_ucred
->cr_ruid
||
313 uc
->cr_ruid
== kauth_cred_getuid(q
->p_ucred
) ||
314 kauth_cred_getuid(uc
) == kauth_cred_getuid(q
->p_ucred
))
321 * because the P_SUGID test exists, this has extra tests which
324 if (uc
->cr_ruid
== q
->p_ucred
->cr_ruid
||
325 uc
->cr_ruid
== q
->p_ucred
->cr_svuid
||
326 kauth_cred_getuid(uc
) == q
->p_ucred
->cr_ruid
||
327 kauth_cred_getuid(uc
) == q
->p_ucred
->cr_svuid
||
328 uc
->cr_ruid
== kauth_cred_getuid(q
->p_ucred
) ||
329 kauth_cred_getuid(uc
) == kauth_cred_getuid(q
->p_ucred
))
337 sigaction(struct proc
*p
, register struct sigaction_args
*uap
, __unused register_t
*retval
)
339 struct user_sigaction vec
;
340 struct __user_sigaction __vec
;
342 struct user_sigaction
*sa
= &vec
;
343 register struct sigacts
*ps
= p
->p_sigacts
;
348 signum
= uap
->signum
;
349 if (signum
<= 0 || signum
>= NSIG
||
350 signum
== SIGKILL
|| signum
== SIGSTOP
)
354 sa
->sa_handler
= ps
->ps_sigact
[signum
];
355 sa
->sa_mask
= ps
->ps_catchmask
[signum
];
356 bit
= sigmask(signum
);
358 if ((ps
->ps_sigonstack
& bit
) != 0)
359 sa
->sa_flags
|= SA_ONSTACK
;
360 if ((ps
->ps_sigintr
& bit
) == 0)
361 sa
->sa_flags
|= SA_RESTART
;
362 if (ps
->ps_siginfo
& bit
)
363 sa
->sa_flags
|= SA_SIGINFO
;
364 if (ps
->ps_signodefer
& bit
)
365 sa
->sa_flags
|= SA_NODEFER
;
366 if (ps
->ps_64regset
& bit
)
367 sa
->sa_flags
|= SA_64REGSET
;
368 if ((signum
== SIGCHLD
) && (p
->p_flag
& P_NOCLDSTOP
))
369 sa
->sa_flags
|= SA_NOCLDSTOP
;
370 if ((signum
== SIGCHLD
) && (p
->p_flag
& P_NOCLDWAIT
))
371 sa
->sa_flags
|= SA_NOCLDWAIT
;
373 if (IS_64BIT_PROCESS(p
)) {
374 error
= copyout(sa
, uap
->osa
, sizeof(struct user_sigaction
));
376 struct sigaction vec32
;
377 sigaction_64to32(sa
, &vec32
);
378 error
= copyout(&vec32
, uap
->osa
, sizeof(struct sigaction
));
384 if (IS_64BIT_PROCESS(p
)) {
385 error
= copyin(uap
->nsa
, &__vec
, sizeof(struct __user_sigaction
));
387 struct __sigaction __vec32
;
388 error
= copyin(uap
->nsa
, &__vec32
, sizeof(struct __sigaction
));
389 __sigaction_32to64(&__vec32
, &__vec
);
393 error
= setsigvec(p
, signum
, &__vec
);
398 /* Routines to manipulate bits on all threads */
400 clear_procsiglist(struct proc
*p
, int bit
)
402 struct uthread
* uth
;
407 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
408 thact
= p
->p_vforkact
;
409 uth
= (struct uthread
*)get_bsdthread_info(thact
);
411 uth
->uu_siglist
&= ~bit
;
413 p
->p_siglist
&= ~bit
;
418 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
419 uth
->uu_siglist
&= ~bit
;
421 p
->p_siglist
&= ~bit
;
428 unblock_procsigmask(struct proc
*p
, int bit
)
430 struct uthread
* uth
;
434 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
435 thact
= p
->p_vforkact
;
436 uth
= (struct uthread
*)get_bsdthread_info(thact
);
438 uth
->uu_sigmask
&= ~bit
;
440 p
->p_sigmask
&= ~bit
;
444 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
445 uth
->uu_sigmask
&= ~bit
;
447 p
->p_sigmask
&= ~bit
;
454 block_procsigmask(struct proc
*p
, int bit
)
456 struct uthread
* uth
;
460 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
461 thact
= p
->p_vforkact
;
462 uth
= (struct uthread
*)get_bsdthread_info(thact
);
464 uth
->uu_sigmask
|= bit
;
470 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
471 uth
->uu_sigmask
|= bit
;
479 set_procsigmask(struct proc
*p
, int bit
)
481 struct uthread
* uth
;
485 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
486 thact
= p
->p_vforkact
;
487 uth
= (struct uthread
*)get_bsdthread_info(thact
);
489 uth
->uu_sigmask
= bit
;
495 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
496 uth
->uu_sigmask
= bit
;
503 /* XXX should be static? */
505 setsigvec(struct proc
*p
, int signum
, struct __user_sigaction
*sa
)
507 register struct sigacts
*ps
= p
->p_sigacts
;
510 if ((signum
== SIGKILL
|| signum
== SIGSTOP
) &&
511 sa
->sa_handler
!= SIG_DFL
)
513 bit
= sigmask(signum
);
515 * Change setting atomically.
517 ps
->ps_sigact
[signum
] = sa
->sa_handler
;
518 ps
->ps_trampact
[signum
] = sa
->sa_tramp
;
519 ps
->ps_catchmask
[signum
] = sa
->sa_mask
&~ sigcantmask
;
520 if (sa
->sa_flags
& SA_SIGINFO
)
521 ps
->ps_siginfo
|= bit
;
523 ps
->ps_siginfo
&= ~bit
;
524 if (sa
->sa_flags
& SA_64REGSET
)
525 ps
->ps_64regset
|= bit
;
527 ps
->ps_64regset
&= ~bit
;
528 if ((sa
->sa_flags
& SA_RESTART
) == 0)
529 ps
->ps_sigintr
|= bit
;
531 ps
->ps_sigintr
&= ~bit
;
532 if (sa
->sa_flags
& SA_ONSTACK
)
533 ps
->ps_sigonstack
|= bit
;
535 ps
->ps_sigonstack
&= ~bit
;
536 if (sa
->sa_flags
& SA_USERTRAMP
)
537 ps
->ps_usertramp
|= bit
;
539 ps
->ps_usertramp
&= ~bit
;
540 if (sa
->sa_flags
& SA_RESETHAND
)
541 ps
->ps_sigreset
|= bit
;
543 ps
->ps_sigreset
&= ~bit
;
544 if (sa
->sa_flags
& SA_NODEFER
)
545 ps
->ps_signodefer
|= bit
;
547 ps
->ps_signodefer
&= ~bit
;
548 if (signum
== SIGCHLD
) {
549 if (sa
->sa_flags
& SA_NOCLDSTOP
)
550 p
->p_flag
|= P_NOCLDSTOP
;
552 p
->p_flag
&= ~P_NOCLDSTOP
;
553 if ((sa
->sa_flags
& SA_NOCLDWAIT
) || (sa
->sa_handler
== SIG_IGN
))
554 p
->p_flag
|= P_NOCLDWAIT
;
556 p
->p_flag
&= ~P_NOCLDWAIT
;
560 if (signum
== SIGFPE
) {
561 if (sa
->sa_handler
== SIG_DFL
|| sa
->sa_handler
== SIG_IGN
)
562 thread_enable_fpe(current_thread(), 0);
564 thread_enable_fpe(current_thread(), 1);
568 * Set bit in p_sigignore for signals that are set to SIG_IGN,
569 * and for signals set to SIG_DFL where the default is to ignore.
570 * However, don't put SIGCONT in p_sigignore,
571 * as we have to restart the process.
573 if (sa
->sa_handler
== SIG_IGN
||
574 (sigprop
[signum
] & SA_IGNORE
&& sa
->sa_handler
== SIG_DFL
)) {
576 clear_procsiglist(p
, bit
);
577 if (signum
!= SIGCONT
)
578 p
->p_sigignore
|= bit
; /* easier in psignal */
579 p
->p_sigcatch
&= ~bit
;
581 p
->p_sigignore
&= ~bit
;
582 if (sa
->sa_handler
== SIG_DFL
)
583 p
->p_sigcatch
&= ~bit
;
585 p
->p_sigcatch
|= bit
;
591 * Initialize signal state for process 0;
592 * set to ignore signals that are ignored by default.
600 for (i
= 0; i
< NSIG
; i
++)
601 if (sigprop
[i
] & SA_IGNORE
&& i
!= SIGCONT
)
602 p
->p_sigignore
|= sigmask(i
);
606 * Reset signals for an exec of the specified process.
610 register struct proc
*p
;
611 register thread_t thr_act
;
613 register struct sigacts
*ps
= p
->p_sigacts
;
614 register int nc
, mask
;
618 * Reset caught signals. Held signals remain held
619 * through p_sigmask (unless they were caught,
620 * and are now ignored by default).
622 while (p
->p_sigcatch
) {
623 nc
= ffs((long)p
->p_sigcatch
);
625 p
->p_sigcatch
&= ~mask
;
626 if (sigprop
[nc
] & SA_IGNORE
) {
628 p
->p_sigignore
|= mask
;
630 ut
= (struct uthread
*)get_bsdthread_info(thr_act
);
631 ut
->uu_siglist
&= ~mask
;
632 p
->p_siglist
&= ~mask
;
634 clear_procsiglist(p
, mask
);
636 ps
->ps_sigact
[nc
] = SIG_DFL
;
639 * Reset stack state to the user stack.
640 * Clear set of signals caught on the signal stack.
642 ps
->ps_sigstk
.ss_flags
= SA_DISABLE
;
643 ps
->ps_sigstk
.ss_size
= 0;
644 ps
->ps_sigstk
.ss_sp
= USER_ADDR_NULL
;
649 * Manipulate signal mask.
650 * Note that we receive new mask, not pointer,
651 * and return old mask as return value;
652 * the library stub does the rest.
655 sigprocmask(register struct proc
*p
, struct sigprocmask_args
*uap
, __unused register_t
*retval
)
658 sigset_t oldmask
, nmask
;
659 user_addr_t omask
= uap
->omask
;
662 ut
= (struct uthread
*)get_bsdthread_info(current_thread());
663 oldmask
= ut
->uu_sigmask
;
665 if (uap
->mask
== USER_ADDR_NULL
) {
666 /* just want old mask */
669 error
= copyin(uap
->mask
, &nmask
, sizeof(sigset_t
));
675 block_procsigmask(p
, (nmask
& ~sigcantmask
));
676 signal_setast(current_thread());
680 unblock_procsigmask(p
, (nmask
& ~sigcantmask
));
681 signal_setast(current_thread());
685 set_procsigmask(p
, (nmask
& ~sigcantmask
));
686 signal_setast(current_thread());
694 if (!error
&& omask
!= USER_ADDR_NULL
)
695 copyout(&oldmask
, omask
, sizeof(sigset_t
));
700 sigpending(__unused
struct proc
*p
, register struct sigpending_args
*uap
, __unused register_t
*retval
)
705 ut
= (struct uthread
*)get_bsdthread_info(current_thread());
706 pendlist
= ut
->uu_siglist
;
709 copyout(&pendlist
, uap
->osv
, sizeof(sigset_t
));
715 * Suspend process until signal, providing mask to be set
716 * in the meantime. Note nonstandard calling convention:
717 * libc stub passes mask, not pointer, to save a copyin.
721 sigcontinue(__unused
int error
)
723 // struct uthread *ut = get_bsdthread_info(current_thread());
724 unix_syscall_return(EINTR
);
728 sigsuspend(register struct proc
*p
, struct sigsuspend_args
*uap
, __unused register_t
*retval
)
732 ut
= (struct uthread
*)get_bsdthread_info(current_thread());
735 * When returning from sigpause, we want
736 * the old mask to be restored after the
737 * signal handler has finished. Thus, we
738 * save it here and mark the sigacts structure
741 ut
->uu_oldmask
= ut
->uu_sigmask
;
742 ut
->uu_flag
|= UT_SAS_OLDMASK
;
743 ut
->uu_sigmask
= (uap
->mask
& ~sigcantmask
);
744 (void) tsleep0((caddr_t
) p
, PPAUSE
|PCATCH
, "pause", 0, sigcontinue
);
745 /* always return EINTR rather than ERESTART... */
751 __disable_threadsignal(struct proc
*p
,
752 __unused
register struct __disable_threadsignal_args
*uap
,
753 __unused register_t
*retval
)
757 uth
= (struct uthread
*)get_bsdthread_info(current_thread());
759 /* No longer valid to have any signal delivered */
761 uth
->uu_flag
|= UT_NO_SIGMASK
;
770 __pthread_markcancel(p
, uap
, retval
)
772 register struct __pthread_markcancel_args
*uap
;
775 thread_act_t target_act
;
779 target_act
= (thread_act_t
)port_name_to_thread(uap
->thread_port
);
781 if (target_act
== THR_ACT_NULL
)
784 uth
= (struct uthread
*)get_bsdthread_info(target_act
);
786 /* if the thread is in vfork do not cancel */
787 if ((uth
->uu_flag
& (P_VFORK
| UT_CANCEL
| UT_CANCELED
)) == 0) {
788 uth
->uu_flag
|= (UT_CANCEL
| UT_NO_SIGMASK
);
789 if (((uth
->uu_flag
& UT_NOTCANCELPT
) == 0)
790 && ((uth
->uu_flag
& UT_CANCELDISABLE
) == 0))
791 thread_abort_safely(target_act
);
794 thread_deallocate(target_act
);
798 /* if action =0 ; return the cancellation state ,
799 * if marked for cancellation, make the thread canceled
800 * if action = 1 ; Enable the cancel handling
801 * if action = 2; Disable the cancel handling
804 __pthread_canceled(p
, uap
, retval
)
806 register struct __pthread_canceled_args
*uap
;
809 thread_act_t thr_act
;
811 int action
= uap
->action
;
813 thr_act
= current_act();
814 uth
= (struct uthread
*)get_bsdthread_info(thr_act
);
818 uth
->uu_flag
&= ~UT_CANCELDISABLE
;
821 uth
->uu_flag
|= UT_CANCELDISABLE
;
825 /* if the thread is in vfork do not cancel */
826 if((uth
->uu_flag
& ( UT_CANCELDISABLE
| UT_CANCEL
| UT_CANCELED
)) == UT_CANCEL
) {
827 uth
->uu_flag
&= ~UT_CANCEL
;
828 uth
->uu_flag
|= (UT_CANCELED
| UT_NO_SIGMASK
);
837 __posix_sem_syscall_return(kern_return_t kern_result
)
841 if (kern_result
== KERN_SUCCESS
)
843 else if (kern_result
== KERN_ABORTED
)
845 else if (kern_result
== KERN_OPERATION_TIMED_OUT
)
849 unix_syscall_return(error
);
850 /* does not return */
855 __semwait_signal(p
, uap
, retval
)
857 register struct __semwait_signal_args
*uap
;
861 kern_return_t kern_result
;
862 mach_timespec_t then
;
868 then
.tv_sec
= uap
->tv_sec
;
869 then
.tv_nsec
= uap
->tv_nsec
;
872 then
.tv_sec
= uap
->tv_sec
- now
.tv_sec
;
873 then
.tv_nsec
= uap
->tv_nsec
- now
.tv_nsec
;
874 if (then
.tv_nsec
< 0) {
875 then
.tv_nsec
+= NSEC_PER_SEC
;
880 if (uap
->mutex_sem
== (void *)NULL
)
881 kern_result
= semaphore_timedwait_trap_internal(uap
->cond_sem
, then
.tv_sec
, then
.tv_nsec
, __posix_sem_syscall_return
);
883 kern_result
= semaphore_timedwait_signal_trap_internal(uap
->cond_sem
, uap
->mutex_sem
, then
.tv_sec
, then
.tv_nsec
, __posix_sem_syscall_return
);
887 if (uap
->mutex_sem
== (void *)NULL
)
888 kern_result
= semaphore_wait_trap_internal(uap
->cond_sem
, __posix_sem_syscall_return
);
891 kern_result
= semaphore_wait_signal_trap_internal(uap
->cond_sem
, uap
->mutex_sem
, __posix_sem_syscall_return
);
895 if (kern_result
== KERN_SUCCESS
)
897 else if (kern_result
== KERN_ABORTED
)
899 else if (kern_result
== KERN_OPERATION_TIMED_OUT
)
907 __pthread_kill(__unused
struct proc
*p
,
908 register struct __pthread_kill_args
*uap
,
909 __unused register_t
*retval
)
913 int signum
= uap
->sig
;
916 target_act
= (thread_t
)port_name_to_thread(uap
->thread_port
);
918 if (target_act
== THREAD_NULL
)
920 if ((u_int
)signum
>= NSIG
) {
925 uth
= (struct uthread
*)get_bsdthread_info(target_act
);
927 if (uth
->uu_flag
& UT_NO_SIGMASK
) {
933 psignal_uthread(target_act
, signum
);
935 thread_deallocate(target_act
);
941 pthread_sigmask(__unused
register struct proc
*p
,
942 register struct pthread_sigmask_args
*uap
,
943 __unused register_t
*retval
)
945 user_addr_t set
= uap
->set
;
946 user_addr_t oset
= uap
->oset
;
952 ut
= (struct uthread
*)get_bsdthread_info(current_thread());
953 oldset
= ut
->uu_sigmask
;
955 if (set
== USER_ADDR_NULL
) {
956 /* need only old mask */
960 error
= copyin(set
, &nset
, sizeof(sigset_t
));
966 ut
->uu_sigmask
|= (nset
& ~sigcantmask
);
970 ut
->uu_sigmask
&= ~(nset
);
971 signal_setast(current_thread());
975 ut
->uu_sigmask
= (nset
& ~sigcantmask
);
976 signal_setast(current_thread());
984 if (!error
&& oset
!= USER_ADDR_NULL
)
985 copyout(&oldset
, oset
, sizeof(sigset_t
));
992 sigwait(register struct proc
*p
, register struct sigwait_args
*uap
, __unused register_t
*retval
)
1002 ut
= (struct uthread
*)get_bsdthread_info(current_thread());
1004 if (uap
->set
== USER_ADDR_NULL
)
1007 error
= copyin(uap
->set
, &mask
, sizeof(sigset_t
));
1011 siglist
= (mask
& ~sigcantmask
);
1017 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
1021 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
1022 if ( (sigw
= uth
->uu_siglist
& siglist
) ) {
1029 /* The signal was pending on a thread */
1033 * When returning from sigwait, we want
1034 * the old mask to be restored after the
1035 * signal handler has finished. Thus, we
1036 * save it here and mark the sigacts structure
1039 ut
->uu_oldmask
= ut
->uu_sigmask
;
1040 ut
->uu_flag
|= UT_SAS_OLDMASK
;
1041 if (siglist
== (sigset_t
)0)
1043 /* SIGKILL and SIGSTOP are not maskable as well */
1044 ut
->uu_sigmask
= ~(siglist
|sigcantmask
);
1045 ut
->uu_sigwait
= siglist
;
1046 /* No Continuations for now */
1047 error
= tsleep((caddr_t
)&ut
->uu_sigwait
, PPAUSE
|PCATCH
, "pause", 0);
1049 if ((error
== EINTR
) || (error
== ERESTART
))
1052 sigw
= (ut
->uu_sigwait
& siglist
);
1053 ut
->uu_sigmask
= ut
->uu_oldmask
;
1055 ut
->uu_flag
&= ~UT_SAS_OLDMASK
;
1059 signum
= ffs((unsigned int)sigw
);
1061 panic("sigwait with no signal wakeup");
1062 ut
->uu_siglist
&= ~(sigmask(signum
));
1063 if (uap
->sig
!= USER_ADDR_NULL
)
1064 error
= copyout(&signum
, uap
->sig
, sizeof(int));
1073 sigaltstack(struct proc
*p
, register struct sigaltstack_args
*uap
, __unused register_t
*retval
)
1075 struct sigacts
*psp
;
1076 struct user_sigaltstack ss
;
1080 if ((psp
->ps_flags
& SAS_ALTSTACK
) == 0)
1081 psp
->ps_sigstk
.ss_flags
|= SA_DISABLE
;
1083 if (IS_64BIT_PROCESS(p
)) {
1084 error
= copyout(&psp
->ps_sigstk
, uap
->oss
, sizeof(struct user_sigaltstack
));
1086 struct sigaltstack ss32
;
1087 sigaltstack_64to32(&psp
->ps_sigstk
, &ss32
);
1088 error
= copyout(&ss32
, uap
->oss
, sizeof(struct sigaltstack
));
1093 if (uap
->nss
== USER_ADDR_NULL
)
1095 if (IS_64BIT_PROCESS(p
)) {
1096 error
= copyin(uap
->nss
, &ss
, sizeof(struct user_sigaltstack
));
1098 struct sigaltstack ss32
;
1099 error
= copyin(uap
->nss
, &ss32
, sizeof(struct sigaltstack
));
1100 sigaltstack_32to64(&ss32
,&ss
);
1104 if ((ss
.ss_flags
& ~SA_DISABLE
) != 0) {
1108 if (ss
.ss_flags
& SA_DISABLE
) {
1109 if (psp
->ps_sigstk
.ss_flags
& SA_ONSTACK
)
1111 psp
->ps_flags
&= ~SAS_ALTSTACK
;
1112 psp
->ps_sigstk
.ss_flags
= ss
.ss_flags
;
1115 /* The older stacksize was 8K, enforce that one so no compat problems */
1116 #define OLDMINSIGSTKSZ 8*1024
1117 if (ss
.ss_size
< OLDMINSIGSTKSZ
)
1119 psp
->ps_flags
|= SAS_ALTSTACK
;
1125 kill(struct proc
*cp
, struct kill_args
*uap
, __unused register_t
*retval
)
1127 register struct proc
*p
;
1128 kauth_cred_t uc
= kauth_cred_get();
1130 AUDIT_ARG(pid
, uap
->pid
);
1131 AUDIT_ARG(signum
, uap
->signum
);
1133 if ((u_int
)uap
->signum
>= NSIG
)
1136 /* kill single process */
1137 if ((p
= proc_findref(uap
->pid
)) == NULL
) {
1138 if ((p
= pzfind(uap
->pid
)) != NULL
) {
1140 * IEEE Std 1003.1-2001: return success
1141 * when killing a zombie.
1147 AUDIT_ARG(process
, p
);
1148 if (!cansignal(cp
, uc
, p
, uap
->signum
)) {
1153 psignal(p
, uap
->signum
);
1158 case -1: /* broadcast signal */
1159 return (killpg1(cp
, uap
->signum
, 0, 1));
1160 case 0: /* signal own process group */
1161 return (killpg1(cp
, uap
->signum
, 0, 0));
1162 default: /* negative explicit process group */
1163 return (killpg1(cp
, uap
->signum
, -(uap
->pid
), 0));
1170 * Common code for kill process group/broadcast kill.
1171 * cp is calling process.
1174 killpg1(cp
, signum
, pgid
, all
)
1175 register struct proc
*cp
;
1176 int signum
, pgid
, all
;
1178 register struct proc
*p
;
1179 kauth_cred_t uc
= cp
->p_ucred
;
1187 for (p
= allproc
.lh_first
; p
!= 0; p
= p
->p_list
.le_next
) {
1188 if (p
->p_pid
<= 1 || p
->p_flag
& P_SYSTEM
||
1189 p
== cp
|| !cansignal(cp
, uc
, p
, signum
))
1198 * zero pgid means send to my process group.
1202 pgrp
= pgfind(pgid
);
1206 for (p
= pgrp
->pg_members
.lh_first
; p
!= 0;
1207 p
= p
->p_pglist
.le_next
) {
1208 if (p
->p_pid
<= 1 || p
->p_flag
& P_SYSTEM
||
1209 p
->p_stat
== SZOMB
||
1210 !cansignal(cp
, uc
, p
, signum
))
1217 return (nfound
? 0 : ESRCH
);
1221 * Send a signal to a process group.
1224 gsignal(pgid
, signum
)
1229 if (pgid
&& (pgrp
= pgfind(pgid
)))
1230 pgsignal(pgrp
, signum
, 0);
1234 * Send a signal to a process group. If checktty is 1,
1235 * limit to members which have a controlling terminal.
1238 pgsignal(pgrp
, signum
, checkctty
)
1240 int signum
, checkctty
;
1242 register struct proc
*p
;
1245 for (p
= pgrp
->pg_members
.lh_first
; p
!= 0;
1246 p
= p
->p_pglist
.le_next
)
1247 if (checkctty
== 0 || p
->p_flag
& P_CONTROLT
)
1252 * Send signal to a backgrounded process blocked due to tty access
1253 * In FreeBSD, the backgrounded process wakes up every second and
1254 * discovers whether it is foregounded or not. In our case, we block
1255 * the thread in tsleep as we want to avoid storm of processes as well
1256 * as the suspend is only at AST level
1259 tty_pgsignal(pgrp
, signum
)
1263 register struct proc
*p
;
1266 for (p
= pgrp
->pg_members
.lh_first
; p
!= 0;
1267 p
= p
->p_pglist
.le_next
)
1268 if ((p
->p_flag
& P_TTYSLEEP
) && (p
->p_flag
& P_CONTROLT
))
1273 * Send a signal caused by a trap to a specific thread.
1276 threadsignal(thread_t sig_actthread
, int signum
, u_long code
)
1278 register struct uthread
*uth
;
1279 register struct task
* sig_task
;
1280 register struct proc
*p
;
1283 if ((u_int
)signum
>= NSIG
|| signum
== 0)
1286 mask
= sigmask(signum
);
1287 if ((mask
& threadmask
) == 0)
1289 sig_task
= get_threadtask(sig_actthread
);
1290 p
= (struct proc
*)(get_bsdtask_info(sig_task
));
1292 uth
= get_bsdthread_info(sig_actthread
);
1293 if (uth
&& (uth
->uu_flag
& UT_VFORK
))
1296 if (!(p
->p_flag
& P_TRACED
) && (p
->p_sigignore
& mask
))
1299 uth
->uu_siglist
|= mask
;
1300 p
->p_siglist
|= mask
; /* just for lame ones looking here */
1301 uth
->uu_code
= code
;
1302 /* mark on process as well */
1303 signal_setast(sig_actthread
);
1309 register struct proc
*p
;
1310 register int signum
;
1312 psignal_lock(p
, signum
, 1);
1316 psignal_vfork(struct proc
*p
, task_t new_task
, thread_t thr_act
, int signum
)
1319 register sig_t action
;
1321 struct uthread
*uth
;
1323 if ((u_int
)signum
>= NSIG
|| signum
== 0)
1324 panic("psignal signal number");
1325 mask
= sigmask(signum
);
1326 prop
= sigprop
[signum
];
1329 if(rdebug_proc
&& (p
== rdebug_proc
)) {
1332 #endif /* SIGNAL_DEBUG */
1334 if ((new_task
== TASK_NULL
) || (thr_act
== (thread_t
)NULL
) || is_kerneltask(new_task
))
1338 uth
= get_bsdthread_info(thr_act
);
1342 * proc is traced, always give parent a chance.
1346 if (p
->p_nice
> NZERO
&& action
== SIG_DFL
&& (prop
& SA_KILL
) &&
1347 (p
->p_flag
& P_TRACED
) == 0)
1350 if (prop
& SA_CONT
) {
1351 p
->p_siglist
&= ~stopsigmask
;
1352 uth
->uu_siglist
&= ~stopsigmask
;
1355 if (prop
& SA_STOP
) {
1357 * If sending a tty stop signal to a member of an orphaned
1358 * process group, discard the signal here if the action
1359 * is default; don't stop the process below if sleeping,
1360 * and don't clear any pending SIGCONT.
1362 if (prop
& SA_TTYSTOP
&& p
->p_pgrp
->pg_jobc
== 0 &&
1365 uth
->uu_siglist
&= ~contsigmask
;
1366 p
->p_siglist
&= ~contsigmask
;
1368 uth
->uu_siglist
|= mask
;
1369 p
->p_siglist
|= mask
; /* just for lame ones looking here */
1371 /* Deliver signal to the activation passed in */
1372 act_set_astbsd(thr_act
);
1375 * SIGKILL priority twiddling moved here from above because
1376 * it needs sig_thread. Could merge it into large switch
1377 * below if we didn't care about priority for tracing
1378 * as SIGKILL's action is always SIG_DFL.
1380 if ((signum
== SIGKILL
) && (p
->p_nice
> NZERO
)) {
1385 * This Process is traced - wake it up (if not already
1386 * stopped) so that it can discover the signal in
1387 * issig() and stop for the parent.
1389 if (p
->p_flag
& P_TRACED
) {
1390 if (p
->p_stat
!= SSTOP
)
1397 * If we're being traced (possibly because someone attached us
1398 * while we were stopped), check for a signal from the debugger.
1400 if (p
->p_stat
== SSTOP
) {
1401 if ((p
->p_flag
& P_TRACED
) != 0 && p
->p_xstat
!= 0) {
1402 uth
->uu_siglist
|= sigmask(p
->p_xstat
);
1403 p
->p_siglist
|= mask
; /* just for lame ones looking here */
1408 * setrunnable(p) in BSD
1417 get_signalthread(struct proc
*p
, int signum
)
1419 struct uthread
*uth
;
1421 sigset_t mask
= sigmask(signum
);
1422 thread_t sig_thread_act
;
1423 struct task
* sig_task
= p
->task
;
1426 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
1427 sig_thread_act
= p
->p_vforkact
;
1428 kret
= check_actforsig(sig_task
, sig_thread_act
, 1);
1429 if (kret
== KERN_SUCCESS
)
1430 return(sig_thread_act
);
1432 return(THREAD_NULL
);
1435 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
1436 if(((uth
->uu_flag
& UT_NO_SIGMASK
)== 0) &&
1437 (((uth
->uu_sigmask
& mask
) == 0) || (uth
->uu_sigwait
& mask
))) {
1438 if (check_actforsig(p
->task
, uth
->uu_act
, 1) == KERN_SUCCESS
)
1439 return(uth
->uu_act
);
1442 if (get_signalact(p
->task
, &thr_act
, 1) == KERN_SUCCESS
) {
1446 return(THREAD_NULL
);
1450 * Send the signal to the process. If the signal has an action, the action
1451 * is usually performed by the target process rather than the caller; we add
1452 * the signal to the set of pending signals for the process.
1455 * o When a stop signal is sent to a sleeping process that takes the
1456 * default action, the process is stopped without awakening it.
1457 * o SIGCONT restarts stopped processes (or puts them back to sleep)
1458 * regardless of the signal action (eg, blocked or ignored).
1460 * Other ignored signals are discarded immediately.
1463 psignal_lock(p
, signum
, withlock
)
1464 register struct proc
*p
;
1465 register int signum
;
1466 register int withlock
;
1468 register int s
, prop
;
1469 register sig_t action
;
1470 thread_t sig_thread_act
;
1471 register task_t sig_task
;
1473 struct uthread
*uth
;
1474 boolean_t funnel_state
= FALSE
;
1477 if ((u_int
)signum
>= NSIG
|| signum
== 0)
1478 panic("psignal signal number");
1479 mask
= sigmask(signum
);
1480 prop
= sigprop
[signum
];
1483 if(rdebug_proc
&& (p
== rdebug_proc
)) {
1486 #endif /* SIGNAL_DEBUG */
1488 if (thread_funnel_get() == (funnel_t
*)0) {
1490 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
1493 * We will need the task pointer later. Grab it now to
1494 * check for a zombie process. Also don't send signals
1495 * to kernel internal tasks.
1497 if (((sig_task
= p
->task
) == TASK_NULL
) || is_kerneltask(sig_task
)) {
1499 thread_funnel_set(kernel_flock
, funnel_state
);
1504 KNOTE(&p
->p_klist
, NOTE_SIGNAL
| signum
);
1508 * do not send signals to the process that has the thread
1509 * doing a reboot(). Not doing so will mark that thread aborted
1510 * and can cause IO failures wich will cause data loss.
1512 if (ISSET(p
->p_flag
, P_REBOOT
)) {
1514 thread_funnel_set(kernel_flock
, funnel_state
);
1522 * Deliver the signal to the first thread in the task. This
1523 * allows single threaded applications which use signals to
1524 * be able to be linked with multithreaded libraries. We have
1525 * an implicit reference to the current thread, but need
1526 * an explicit one otherwise. The thread reference keeps
1527 * the corresponding task data structures around too. This
1528 * reference is released by thread_deallocate.
1531 if (((p
->p_flag
& P_TRACED
) == 0) && (p
->p_sigignore
& mask
))
1534 /* If successful return with ast set */
1535 sig_thread_act
= get_signalthread(p
, signum
);
1537 if (sig_thread_act
== THREAD_NULL
) {
1539 * if it is sigkill, may be we should
1540 * inject a thread to terminate
1544 #endif /* SIGNAL_DEBUG */
1548 uth
= get_bsdthread_info(sig_thread_act
);
1551 * If proc is traced, always give parent a chance.
1553 if (p
->p_flag
& P_TRACED
)
1557 * If the signal is being ignored,
1558 * then we forget about it immediately.
1559 * (Note: we don't set SIGCONT in p_sigignore,
1560 * and if it is set to SIG_IGN,
1561 * action will be SIG_DFL here.)
1563 if (p
->p_sigignore
& mask
)
1565 /* sigwait takes precedence */
1566 if (uth
->uu_sigwait
& mask
)
1567 action
= KERN_SIG_WAIT
;
1568 else if (uth
->uu_sigmask
& mask
)
1569 action
= KERN_SIG_HOLD
;
1570 else if (p
->p_sigcatch
& mask
)
1571 action
= KERN_SIG_CATCH
;
1576 if (p
->p_nice
> NZERO
&& action
== SIG_DFL
&& (prop
& SA_KILL
) &&
1577 (p
->p_flag
& P_TRACED
) == 0)
1580 if (prop
& SA_CONT
) {
1581 uth
->uu_siglist
&= ~stopsigmask
;
1582 p
->p_siglist
&= ~stopsigmask
;
1585 if (prop
& SA_STOP
) {
1587 * If sending a tty stop signal to a member of an orphaned
1588 * process group, discard the signal here if the action
1589 * is default; don't stop the process below if sleeping,
1590 * and don't clear any pending SIGCONT.
1592 if (prop
& SA_TTYSTOP
&& p
->p_pgrp
->pg_jobc
== 0 &&
1595 uth
->uu_siglist
&= ~contsigmask
;
1596 p
->p_siglist
&= ~contsigmask
;
1598 uth
->uu_siglist
|= mask
;
1599 p
->p_siglist
|= mask
; /* just for lame ones looking here */
1603 * Defer further processing for signals which are held,
1604 * except that stopped processes must be continued by SIGCONT.
1606 if (action
== KERN_SIG_HOLD
&& ((prop
& SA_CONT
) == 0 || p
->p_stat
!= SSTOP
)) {
1610 * SIGKILL priority twiddling moved here from above because
1611 * it needs sig_thread. Could merge it into large switch
1612 * below if we didn't care about priority for tracing
1613 * as SIGKILL's action is always SIG_DFL.
1615 if ((signum
== SIGKILL
) && (p
->p_nice
> NZERO
)) {
1620 * Process is traced - wake it up (if not already
1621 * stopped) so that it can discover the signal in
1622 * issig() and stop for the parent.
1624 if (p
->p_flag
& P_TRACED
) {
1625 if (p
->p_stat
!= SSTOP
)
1631 if (action
== KERN_SIG_WAIT
) {
1632 uth
->uu_sigwait
= mask
;
1633 uth
->uu_siglist
&= ~mask
;
1634 p
->p_siglist
&= ~mask
;
1635 wakeup(&uth
->uu_sigwait
);
1636 /* if it is SIGCONT resume whole process */
1637 if (prop
& SA_CONT
) {
1638 p
->p_flag
|= P_CONTINUED
;
1639 (void) task_resume(sig_task
);
1644 if (action
!= SIG_DFL
) {
1646 * User wants to catch the signal.
1647 * Wake up the thread, but don't un-suspend it
1648 * (except for SIGCONT).
1650 if (prop
& SA_CONT
) {
1651 if (p
->p_flag
& P_TTYSLEEP
) {
1652 p
->p_flag
&= ~P_TTYSLEEP
;
1653 wakeup(&p
->p_siglist
);
1655 p
->p_flag
|= P_CONTINUED
;
1656 (void) task_resume(sig_task
);
1659 } else if (p
->p_stat
== SSTOP
)
1663 /* Default action - varies */
1664 if (mask
& stopsigmask
) {
1666 * These are the signals which by default
1669 * Don't clog system with children of init
1670 * stopped from the keyboard.
1672 if (!(prop
& SA_STOP
) && p
->p_pptr
== initproc
) {
1673 psignal_lock(p
, SIGKILL
, 0);
1674 uth
->uu_siglist
&= ~mask
;
1675 p
->p_siglist
&= ~mask
;
1681 * if task hasn't already been stopped by
1684 uth
->uu_siglist
&= ~mask
;
1685 p
->p_siglist
&= ~mask
;
1686 if (p
->p_stat
!= SSTOP
) {
1687 p
->p_xstat
= signum
;
1689 if ((p
->p_pptr
->p_flag
& P_NOCLDSTOP
) == 0) {
1690 struct proc
*pp
= p
->p_pptr
;
1692 pp
->si_pid
= p
->p_pid
;
1693 pp
->si_status
= p
->p_xstat
;
1694 pp
->si_code
= CLD_STOPPED
;
1695 pp
->si_uid
= p
->p_ucred
->cr_ruid
;
1696 psignal(pp
, SIGCHLD
);
1704 * Signals ignored by default have been dealt
1705 * with already, since their bits are on in
1711 * Kill signal always sets process running and
1715 * Process will be running after 'run'
1719 thread_abort(sig_thread_act
);
1725 * Let the process run. If it's sleeping on an
1726 * event, it remains so.
1728 if (p
->p_flag
& P_TTYSLEEP
) {
1729 p
->p_flag
&= ~P_TTYSLEEP
;
1730 wakeup(&p
->p_siglist
);
1732 p
->p_flag
|= P_CONTINUED
;
1733 (void) task_resume(sig_task
);
1735 uth
->uu_siglist
&= ~mask
;
1736 p
->p_siglist
&= ~mask
;
1743 * All other signals wake up the process, but don't
1746 if (p
->p_stat
== SSTOP
)
1754 * If we're being traced (possibly because someone attached us
1755 * while we were stopped), check for a signal from the debugger.
1757 if (p
->p_stat
== SSTOP
) {
1758 if ((p
->p_flag
& P_TRACED
) != 0 && p
->p_xstat
!= 0)
1759 uth
->uu_siglist
|= sigmask(p
->p_xstat
);
1762 * setrunnable(p) in BSD and
1763 * Wake up the thread if it is interruptible.
1766 thread_abort_safely(sig_thread_act
);
1772 thread_funnel_set(kernel_flock
, funnel_state
);
1776 /* psignal_lock(p, signum, withlock ) */
1778 psignal_uthread(thr_act
, signum
)
1784 register sig_t action
;
1785 thread_t sig_thread_act
;
1786 register task_t sig_task
;
1788 struct uthread
*uth
;
1792 p
= (struct proc
*)get_bsdtask_info(get_threadtask(thr_act
));
1793 if ((u_int
)signum
>= NSIG
|| signum
== 0)
1794 panic("Invalid signal number in psignal_uthread");
1795 mask
= sigmask(signum
);
1796 prop
= sigprop
[signum
];
1799 if(rdebug_proc
&& (p
== rdebug_proc
)) {
1802 #endif /* SIGNAL_DEBUG */
1805 * We will need the task pointer later. Grab it now to
1806 * check for a zombie process. Also don't send signals
1807 * to kernel internal tasks.
1809 if (((sig_task
= p
->task
) == TASK_NULL
) || is_kerneltask(sig_task
)) {
1813 sig_thread_act
= thr_act
;
1815 * do not send signals to the process that has the thread
1816 * doing a reboot(). Not doing so will mark that thread aborted
1817 * and can cause IO failures wich will cause data loss.
1819 if (ISSET(p
->p_flag
, P_REBOOT
)) {
1826 * Deliver the signal to the first thread in the task. This
1827 * allows single threaded applications which use signals to
1828 * be able to be linked with multithreaded libraries. We have
1829 * an implicit reference to the current thread, but need
1830 * an explicit one otherwise. The thread reference keeps
1831 * the corresponding task data structures around too. This
1832 * reference is released by thread_deallocate.
1835 if (((p
->p_flag
& P_TRACED
) == 0) && (p
->p_sigignore
& mask
))
1838 kret
= check_actforsig(sig_task
, sig_thread_act
, 1);
1840 if (kret
!= KERN_SUCCESS
) {
1846 uth
= get_bsdthread_info(sig_thread_act
);
1849 * If proc is traced, always give parent a chance.
1851 if (p
->p_flag
& P_TRACED
)
1855 * If the signal is being ignored,
1856 * then we forget about it immediately.
1857 * (Note: we don't set SIGCONT in p_sigignore,
1858 * and if it is set to SIG_IGN,
1859 * action will be SIG_DFL here.)
1861 if (p
->p_sigignore
& mask
)
1863 /* sigwait takes precedence */
1864 if (uth
->uu_sigwait
& mask
)
1865 action
= KERN_SIG_WAIT
;
1866 else if (uth
->uu_sigmask
& mask
)
1867 action
= KERN_SIG_HOLD
;
1868 else if (p
->p_sigcatch
& mask
)
1869 action
= KERN_SIG_CATCH
;
1874 if (p
->p_nice
> NZERO
&& action
== SIG_DFL
&& (prop
& SA_KILL
) &&
1875 (p
->p_flag
& P_TRACED
) == 0)
1878 if (prop
& SA_CONT
) {
1879 uth
->uu_siglist
&= ~stopsigmask
;
1880 p
->p_siglist
&= ~stopsigmask
;
1883 if (prop
& SA_STOP
) {
1885 * If sending a tty stop signal to a member of an orphaned
1886 * process group, discard the signal here if the action
1887 * is default; don't stop the process below if sleeping,
1888 * and don't clear any pending SIGCONT.
1890 if (prop
& SA_TTYSTOP
&& p
->p_pgrp
->pg_jobc
== 0 &&
1893 uth
->uu_siglist
&= ~contsigmask
;
1894 p
->p_siglist
&= ~contsigmask
;
1896 uth
->uu_siglist
|= mask
;
1897 p
->p_siglist
|= mask
; /* just for lame ones looking here */
1900 * Defer further processing for signals which are held,
1901 * except that stopped processes must be continued by SIGCONT.
1903 if (action
== KERN_SIG_HOLD
&& ((prop
& SA_CONT
) == 0 || p
->p_stat
!= SSTOP
))
1907 * SIGKILL priority twiddling moved here from above because
1908 * it needs sig_thread. Could merge it into large switch
1909 * below if we didn't care about priority for tracing
1910 * as SIGKILL's action is always SIG_DFL.
1912 if ((signum
== SIGKILL
) && (p
->p_nice
> NZERO
)) {
1917 * Process is traced - wake it up (if not already
1918 * stopped) so that it can discover the signal in
1919 * issig() and stop for the parent.
1921 if (p
->p_flag
& P_TRACED
) {
1922 if (p
->p_stat
!= SSTOP
)
1928 if (action
== KERN_SIG_WAIT
) {
1929 uth
->uu_sigwait
= mask
;
1930 uth
->uu_siglist
&= ~mask
;
1931 p
->p_siglist
&= ~mask
;
1932 wakeup(&uth
->uu_sigwait
);
1933 /* if it is SIGCONT resume whole process */
1934 if (prop
& SA_CONT
) {
1935 p
->p_flag
|= P_CONTINUED
;
1936 (void) task_resume(sig_task
);
1941 if (action
!= SIG_DFL
) {
1943 * User wants to catch the signal.
1944 * Wake up the thread, but don't un-suspend it
1945 * (except for SIGCONT).
1947 if (prop
& SA_CONT
) {
1948 p
->p_flag
|= P_CONTINUED
;
1949 (void) task_resume(sig_task
);
1953 /* Default action - varies */
1954 if (mask
& stopsigmask
) {
1956 * These are the signals which by default
1959 * Don't clog system with children of init
1960 * stopped from the keyboard.
1962 if (!(prop
& SA_STOP
) && p
->p_pptr
== initproc
) {
1963 psignal_lock(p
, SIGKILL
, 0);
1964 uth
->uu_siglist
&= ~mask
;
1965 p
->p_siglist
&= ~mask
;
1971 * if task hasn't already been stopped by
1974 uth
->uu_siglist
&= ~mask
;
1975 p
->p_siglist
&= ~mask
;
1976 if (p
->p_stat
!= SSTOP
) {
1977 p
->p_xstat
= signum
;
1978 if ((p
->p_pptr
->p_flag
& P_NOCLDSTOP
) == 0) {
1979 struct proc
*pp
= p
->p_pptr
;
1981 pp
->si_pid
= p
->p_pid
;
1982 pp
->si_status
= p
->p_xstat
;
1983 pp
->si_code
= CLD_STOPPED
;
1984 pp
->si_uid
= p
->p_ucred
->cr_ruid
;
1985 psignal(pp
, SIGCHLD
);
1994 * Signals ignored by default have been dealt
1995 * with already, since their bits are on in
2001 * Kill signal always sets process running and
2005 * Process will be running after 'run'
2009 thread_abort(sig_thread_act
);
2015 * Let the process run. If it's sleeping on an
2016 * event, it remains so.
2018 if (p
->p_flag
& P_TTYSLEEP
) {
2019 p
->p_flag
&= ~P_TTYSLEEP
;
2020 wakeup(&p
->p_siglist
);
2022 p
->p_flag
|= P_CONTINUED
;
2023 (void) task_resume(sig_task
);
2025 uth
->uu_siglist
&= ~mask
;
2026 p
->p_siglist
&= ~mask
;
2032 * All other signals wake up the process, but don't
2041 * If we're being traced (possibly because someone attached us
2042 * while we were stopped), check for a signal from the debugger.
2044 if (p
->p_stat
== SSTOP
) {
2045 if ((p
->p_flag
& P_TRACED
) != 0 && p
->p_xstat
!= 0) {
2046 uth
->uu_siglist
|= sigmask(p
->p_xstat
);
2047 p
->p_siglist
|= sigmask(p
->p_xstat
);
2051 * setrunnable(p) in BSD and
2052 * Wake up the thread if it is interruptible.
2055 thread_abort_safely(sig_thread_act
);
2064 sig_lock_to_exit(struct proc
*p
)
2066 thread_t self
= current_thread();
2068 p
->exit_thread
= self
;
2069 (void) task_suspend(p
->task
);
2073 sig_try_locked(struct proc
*p
)
2075 thread_t self
= current_thread();
2077 while (p
->sigwait
|| p
->exit_thread
) {
2078 if (p
->exit_thread
) {
2079 if (p
->exit_thread
!= self
) {
2081 * Already exiting - no signals.
2087 if(assert_wait_possible()) {
2088 assert_wait((caddr_t
)&p
->sigwait_thread
,
2089 (THREAD_INTERRUPTIBLE
));
2092 thread_block(THREAD_CONTINUE_NULL
);
2094 if (thread_should_abort(self
)) {
2096 * Terminate request - clean up.
2105 * If the current process has received a signal (should be caught or cause
2106 * termination, should interrupt current syscall), return the signal number.
2107 * Stop signals with default action are processed immediately, then cleared;
2108 * they aren't returned. This is checked after each entry to the system for
2109 * a syscall or trap (though this can usually be done without calling issignal
2110 * by checking the pending signal masks in the CURSIG macro.) The normal call
2113 * while (signum = CURSIG(curproc))
2118 register struct proc
*p
;
2120 register int signum
, mask
, prop
, sigbits
;
2122 struct uthread
* ut
;
2125 cur_act
= current_thread();
2128 if(rdebug_proc
&& (p
== rdebug_proc
)) {
2131 #endif /* SIGNAL_DEBUG */
2135 * Try to grab the signal lock.
2137 if (sig_try_locked(p
) <= 0) {
2142 ut
= get_bsdthread_info(cur_act
);
2144 sigbits
= ut
->uu_siglist
& ~ut
->uu_sigmask
;
2146 if (p
->p_flag
& P_PPWAIT
)
2147 sigbits
&= ~stopsigmask
;
2148 if (sigbits
== 0) { /* no signal to send */
2152 signum
= ffs((long)sigbits
);
2153 mask
= sigmask(signum
);
2154 prop
= sigprop
[signum
];
2157 * We should see pending but ignored signals
2158 * only if P_TRACED was on when they were posted.
2160 if (mask
& p
->p_sigignore
&& (p
->p_flag
& P_TRACED
) == 0) {
2161 ut
->uu_siglist
&= ~mask
; /* take the signal! */
2162 p
->p_siglist
&= ~mask
; /* take the signal! */
2165 if (p
->p_flag
& P_TRACED
&& (p
->p_flag
& P_PPWAIT
) == 0) {
2166 register task_t task
;
2168 * If traced, always stop, and stay
2169 * stopped until released by the debugger.
2171 /* ptrace debugging */
2172 p
->p_xstat
= signum
;
2174 if (p
->p_flag
& P_SIGEXC
) {
2176 p
->sigwait_thread
= cur_act
;
2178 p
->p_flag
&= ~(P_WAITED
|P_CONTINUED
);
2179 ut
->uu_siglist
&= ~mask
; /* clear the old signal */
2180 p
->p_siglist
&= ~mask
; /* clear the old signal */
2182 do_bsdexception(EXC_SOFTWARE
, EXC_SOFT_SIGNAL
, signum
);
2185 // panic("Unsupportef gdb option \n");;
2186 pp
->si_pid
= p
->p_pid
;
2187 pp
->si_status
= p
->p_xstat
;
2188 pp
->si_code
= CLD_TRAPPED
;
2189 pp
->si_uid
= p
->p_ucred
->cr_ruid
;
2190 psignal(pp
, SIGCHLD
);
2192 * XXX Have to really stop for debuggers;
2193 * XXX stop() doesn't do the right thing.
2194 * XXX Inline the task_suspend because we
2195 * XXX have to diddle Unix state in the
2201 p
->sigwait_thread
= cur_act
;
2203 p
->p_flag
&= ~(P_WAITED
|P_CONTINUED
);
2204 ut
->uu_siglist
&= ~mask
; /* clear the old signal */
2205 p
->p_siglist
&= ~mask
; /* clear the old signal */
2207 wakeup((caddr_t
)p
->p_pptr
);
2209 assert_wait((caddr_t
)&p
->sigwait
, (THREAD_INTERRUPTIBLE
));
2210 thread_block(THREAD_CONTINUE_NULL
);
2215 p
->sigwait_thread
= NULL
;
2216 wakeup((caddr_t
)&p
->sigwait_thread
);
2219 * This code is to detect when gdb is killed
2220 * even as the traced program is attached.
2221 * pgsignal would get the SIGKILL to traced program
2222 * That's what we are trying to see (I hope)
2224 if (ut
->uu_siglist
& sigmask(SIGKILL
)) {
2226 * Wait event may still be outstanding;
2227 * clear it, since sig_lock_to_exit will
2230 clear_wait(current_thread(), THREAD_INTERRUPTED
);
2231 sig_lock_to_exit(p
);
2233 * Since this thread will be resumed
2234 * to allow the current syscall to
2235 * be completed, must save u_qsave
2236 * before calling exit(). (Since exit()
2237 * calls closef() which can trash u_qsave.)
2240 exit1(p
,signum
, (int *)NULL
);
2245 * We may have to quit
2247 if (thread_should_abort(current_thread())) {
2252 * If parent wants us to take the signal,
2253 * then it will leave it in p->p_xstat;
2254 * otherwise we just look for signals again.
2256 signum
= p
->p_xstat
;
2260 * Put the new signal into p_siglist. If the
2261 * signal is being masked, look for other signals.
2263 mask
= sigmask(signum
);
2264 ut
->uu_siglist
|= mask
;
2265 p
->p_siglist
|= mask
; /* just for lame ones looking here */
2266 if (ut
->uu_sigmask
& mask
)
2271 * Decide whether the signal should be returned.
2272 * Return the signal's number, or fall through
2273 * to clear it from the pending mask.
2276 switch ((long)p
->p_sigacts
->ps_sigact
[signum
]) {
2280 * Don't take default actions on system processes.
2282 if (p
->p_pptr
->p_pid
== 0) {
2285 * Are you sure you want to ignore SIGSEGV
2288 printf("Process (pid %d) got signal %d\n",
2291 break; /* == ignore */
2295 * If there is a pending stop signal to process
2296 * with default action, stop here,
2297 * then clear the signal. However,
2298 * if process is member of an orphaned
2299 * process group, ignore tty stop signals.
2301 if (prop
& SA_STOP
) {
2302 if (p
->p_flag
& P_TRACED
||
2303 (p
->p_pgrp
->pg_jobc
== 0 &&
2305 break; /* == ignore */
2306 if (p
->p_stat
!= SSTOP
) {
2307 p
->p_xstat
= signum
;
2309 if ((p
->p_pptr
->p_flag
& P_NOCLDSTOP
) == 0) {
2311 pp
->si_pid
= p
->p_pid
;
2312 pp
->si_status
= p
->p_xstat
;
2313 pp
->si_code
= CLD_STOPPED
;
2314 pp
->si_uid
= p
->p_ucred
->cr_ruid
;
2315 psignal(pp
, SIGCHLD
);
2319 } else if (prop
& SA_IGNORE
) {
2321 * Except for SIGCONT, shouldn't get here.
2322 * Default action is to ignore; drop it.
2324 break; /* == ignore */
2326 ut
->uu_siglist
&= ~mask
; /* take the signal! */
2327 p
->p_siglist
&= ~mask
; /* take the signal! */
2335 * Masking above should prevent us ever trying
2336 * to take action on an ignored signal other
2337 * than SIGCONT, unless process is traced.
2339 if ((prop
& SA_CONT
) == 0 &&
2340 (p
->p_flag
& P_TRACED
) == 0)
2341 printf("issignal\n");
2342 break; /* == ignore */
2346 * This signal has an action, let
2347 * postsig() process it.
2349 ut
->uu_siglist
&= ~mask
; /* take the signal! */
2350 p
->p_siglist
&= ~mask
; /* take the signal! */
2354 ut
->uu_siglist
&= ~mask
; /* take the signal! */
2355 p
->p_siglist
&= ~mask
; /* take the signal! */
2360 /* called from _sleep */
2363 register struct proc
*p
;
2365 register int signum
, mask
, prop
, sigbits
;
2367 struct uthread
* ut
;
2371 cur_act
= current_thread();
2373 ut
= get_bsdthread_info(cur_act
);
2375 if (ut
->uu_siglist
== 0)
2378 if (((ut
->uu_siglist
& ~ut
->uu_sigmask
) == 0) && ((p
->p_flag
& P_TRACED
) == 0))
2381 sigbits
= ut
->uu_siglist
& ~ut
->uu_sigmask
;
2384 if (p
->p_flag
& P_PPWAIT
)
2385 sigbits
&= ~stopsigmask
;
2386 if (sigbits
== 0) { /* no signal to send */
2390 signum
= ffs((long)sigbits
);
2391 mask
= sigmask(signum
);
2392 prop
= sigprop
[signum
];
2395 * We should see pending but ignored signals
2396 * only if P_TRACED was on when they were posted.
2398 if (mask
& p
->p_sigignore
&& (p
->p_flag
& P_TRACED
) == 0) {
2401 if (p
->p_flag
& P_TRACED
&& (p
->p_flag
& P_PPWAIT
) == 0) {
2403 * Put the new signal into p_siglist. If the
2404 * signal is being masked, look for other signals.
2406 mask
= sigmask(signum
);
2407 if (ut
->uu_sigmask
& mask
)
2413 * Decide whether the signal should be returned.
2414 * Return the signal's number, or fall through
2415 * to clear it from the pending mask.
2418 switch ((long)p
->p_sigacts
->ps_sigact
[signum
]) {
2422 * Don't take default actions on system processes.
2424 if (p
->p_pptr
->p_pid
== 0) {
2427 * Are you sure you want to ignore SIGSEGV
2430 printf("Process (pid %d) got signal %d\n",
2433 break; /* == ignore */
2437 * If there is a pending stop signal to process
2438 * with default action, stop here,
2439 * then clear the signal. However,
2440 * if process is member of an orphaned
2441 * process group, ignore tty stop signals.
2443 if (prop
& SA_STOP
) {
2444 if (p
->p_flag
& P_TRACED
||
2445 (p
->p_pgrp
->pg_jobc
== 0 &&
2447 break; /* == ignore */
2450 } else if (prop
& SA_IGNORE
) {
2452 * Except for SIGCONT, shouldn't get here.
2453 * Default action is to ignore; drop it.
2455 break; /* == ignore */
2463 * Masking above should prevent us ever trying
2464 * to take action on an ignored signal other
2465 * than SIGCONT, unless process is traced.
2467 if ((prop
& SA_CONT
) == 0 &&
2468 (p
->p_flag
& P_TRACED
) == 0)
2469 printf("issignal\n");
2470 break; /* == ignore */
2474 * This signal has an action, let
2475 * postsig() process it.
2479 sigbits
&= ~mask
; /* take the signal! */
2485 * Put the argument process into the stopped state and notify the parent
2486 * via wakeup. Signals are handled elsewhere. The process must not be
2491 register struct proc
*p
;
2494 p
->p_flag
&= ~(P_WAITED
|P_CONTINUED
);
2495 if (p
->p_pptr
->p_stat
!= SSTOP
)
2496 wakeup((caddr_t
)p
->p_pptr
);
2497 (void) task_suspend(p
->task
); /*XXX*/
2501 * Take the action for the specified signal
2502 * from the current set of pending signals.
2507 struct proc
*p
= current_proc();
2508 struct sigacts
*ps
= p
->p_sigacts
;
2509 user_addr_t catcher
;
2511 int mask
, returnmask
;
2512 struct uthread
* ut
;
2518 * This must be called on master cpu
2520 if (cpu_number() != master_cpu
)
2521 panic("psig not on master");
2526 * Try to grab the signal lock.
2528 if (sig_try_locked(p
) <= 0) {
2533 ut
= (struct uthread
*)get_bsdthread_info(current_thread());
2534 mask
= sigmask(signum
);
2535 ut
->uu_siglist
&= ~mask
;
2536 p
->p_siglist
&= ~mask
;
2537 catcher
= ps
->ps_sigact
[signum
];
2539 //LP64: catcher argument is a 64 bit user space handler address
2540 if (KTRPOINT(p
, KTR_PSIG
))
2541 ktrpsig(p
->p_tracep
,
2542 signum
, CAST_DOWN(void *,catcher
), ut
->uu_flag
& UT_SAS_OLDMASK
?
2543 &ut
->uu_oldmask
: &ut
->uu_sigmask
, 0);
2545 if (catcher
== SIG_DFL
) {
2547 * Default catcher, where the default is to kill
2548 * the process. (Other cases were ignored above.)
2550 /* called with signal_lock() held */
2551 sigexit_locked(p
, signum
);
2556 * If we get here, the signal must be caught.
2559 if (catcher
== SIG_IGN
|| (ut
->uu_sigmask
& mask
))
2561 "postsig: processing masked or ignored signal\n");
2564 * Set the new mask value and also defer further
2565 * occurences of this signal.
2567 * Special case: user has done a sigpause. Here the
2568 * current mask is not of interest, but rather the
2569 * mask from before the sigpause is what we want
2570 * restored after the signal processing is completed.
2572 if (ut
->uu_flag
& UT_SAS_OLDMASK
) {
2573 returnmask
= ut
->uu_oldmask
;
2574 ut
->uu_flag
&= ~UT_SAS_OLDMASK
;
2577 returnmask
= ut
->uu_sigmask
;
2578 ut
->uu_sigmask
|= ps
->ps_catchmask
[signum
];
2579 if ((ps
->ps_signodefer
& mask
) == 0)
2580 ut
->uu_sigmask
|= mask
;
2581 if ((signum
!= SIGILL
) && (signum
!= SIGTRAP
) && (ps
->ps_sigreset
& mask
)) {
2582 if ((signum
!= SIGCONT
) && (sigprop
[signum
] & SA_IGNORE
))
2583 p
->p_sigignore
|= mask
;
2584 ps
->ps_sigact
[signum
] = SIG_DFL
;
2585 ps
->ps_siginfo
&= ~mask
;
2586 ps
->ps_signodefer
&= ~mask
;
2589 /* Needs to disable to run in user mode */
2590 if (signum
== SIGFPE
) {
2591 thread_enable_fpe(current_thread(), 0);
2593 #endif /* __ppc__ */
2595 if (ps
->ps_sig
!= signum
) {
2601 p
->p_stats
->p_ru
.ru_nsignals
++;
2602 sendsig(p
, catcher
, signum
, returnmask
, code
);
2608 * Force the current process to exit with the specified signal, dumping core
2609 * if appropriate. We bypass the normal tests for masked and caught signals,
2610 * allowing unrecoverable failures to terminate the process without changing
2611 * signal state. Mark the accounting record with the signal termination.
2612 * If dumping core, save the signal number for the debugger. Calls exit and
2615 /* called with signal lock */
2617 sigexit_locked(p
, signum
)
2618 register struct proc
*p
;
2622 sig_lock_to_exit(p
);
2623 p
->p_acflag
|= AXSIG
;
2624 if (sigprop
[signum
] & SA_CORE
) {
2625 p
->p_sigacts
->ps_sig
= signum
;
2627 if (coredump(p
) == 0)
2628 signum
|= WCOREFLAG
;
2632 exit1(p
, W_EXITCODE(0, signum
), (int *)NULL
);
2638 filt_sigattach(struct knote
*kn
)
2640 struct proc
*p
= current_proc();
2642 kn
->kn_ptr
.p_proc
= p
;
2643 kn
->kn_flags
|= EV_CLEAR
; /* automatically set */
2645 /* XXX lock the proc here while adding to the list? */
2646 KNOTE_ATTACH(&p
->p_klist
, kn
);
2652 filt_sigdetach(struct knote
*kn
)
2654 struct proc
*p
= kn
->kn_ptr
.p_proc
;
2656 KNOTE_DETACH(&p
->p_klist
, kn
);
2660 * signal knotes are shared with proc knotes, so we apply a mask to
2661 * the hint in order to differentiate them from process hints. This
2662 * could be avoided by using a signal-specific knote list, but probably
2663 * isn't worth the trouble.
2666 filt_signal(struct knote
*kn
, long hint
)
2669 if (hint
& NOTE_SIGNAL
) {
2670 hint
&= ~NOTE_SIGNAL
;
2672 if (kn
->kn_id
== (unsigned int)hint
)
2675 return (kn
->kn_data
!= 0);
2680 bsd_ast(thread_t thr_act
)
2682 struct proc
*p
= current_proc();
2683 struct uthread
*ut
= get_bsdthread_info(thr_act
);
2686 boolean_t funnel_state
;
2687 static int bsd_init_done
= 0;
2692 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
2694 if ((p
->p_flag
& P_OWEUPC
) && (p
->p_flag
& P_PROFIL
)) {
2695 pc
= get_useraddr();
2696 addupc_task(p
, pc
, 1);
2697 p
->p_flag
&= ~P_OWEUPC
;
2700 if (CHECK_SIGNALS(p
, current_thread(), ut
)) {
2701 while ( (signum
= issignal(p
)) )
2704 if (!bsd_init_done
) {
2709 (void) thread_funnel_set(kernel_flock
, FALSE
);
2713 * Follwing routines are called using callout from bsd_hardclock
2714 * so that psignals are called in a thread context and are funneled
2717 psignal_vtalarm(struct proc
*p
)
2719 boolean_t funnel_state
;
2723 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
2724 psignal_lock(p
, SIGVTALRM
, 1);
2725 (void) thread_funnel_set(kernel_flock
, FALSE
);
2729 psignal_xcpu(struct proc
*p
)
2731 boolean_t funnel_state
;
2735 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
2736 psignal_lock(p
, SIGXCPU
, 1);
2737 (void) thread_funnel_set(kernel_flock
, FALSE
);
2741 psignal_sigprof(struct proc
*p
)
2743 boolean_t funnel_state
;
2747 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
2748 psignal_lock(p
, SIGPROF
, 1);
2749 (void) thread_funnel_set(kernel_flock
, FALSE
);
2752 /* ptrace set runnalbe */
2754 pt_setrunnable(struct proc
*p
)
2760 if (p
->p_flag
& P_TRACED
) {
2763 wakeup((caddr_t
)&(p
->sigwait
));
2776 exception_data_type_t codes
[EXCEPTION_CODE_MAX
];
2780 return(bsd_exception(exc
, codes
, 2));
2784 proc_pendingsignals(struct proc
*p
, sigset_t mask
)
2786 struct uthread
* uth
;
2791 /* If the process is in proc exit return no signal info */
2792 if (p
->p_lflag
& P_LPEXIT
)
2795 /* duplicate the signal lock code to enable recursion; as exit
2796 * holds the lock too long. All this code is being reworked
2797 * this is just a workaround for regressions till new code
2801 error
= lockmgr((struct lock__bsd__
*)&p
->signal_lock
[0], (LK_EXCLUSIVE
| LK_CANRECURSE
), 0, (struct proc
*)0);
2805 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
2807 uth
= (struct uthread
*)get_bsdthread_info(th
);
2809 bits
= (((uth
->uu_siglist
& ~uth
->uu_sigmask
) & ~p
->p_sigignore
) & mask
);
2815 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
2816 bits
|= (((uth
->uu_siglist
& ~uth
->uu_sigmask
) & ~p
->p_sigignore
) & mask
);
2824 thread_issignal(proc_t p
, thread_t th
, sigset_t mask
)
2826 struct uthread
* uth
;
2830 uth
= (struct uthread
*)get_bsdthread_info(th
);
2832 bits
= (((uth
->uu_siglist
& ~uth
->uu_sigmask
) & ~p
->p_sigignore
) & mask
);