2 * Copyright (c) 2000-2001 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 /* Copyright (c) 1995-1998 Apple Computer, Inc. All Rights Reserved */
32 * Copyright (c) 1982, 1986, 1989, 1991, 1993
33 * The Regents of the University of California. All rights reserved.
34 * (c) UNIX System Laboratories, Inc.
35 * All or some portions of this file are derived from material licensed
36 * to the University of California by American Telephone and Telegraph
37 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
38 * the permission of UNIX System Laboratories, Inc.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
48 * 3. All advertising materials mentioning features or use of this software
49 * must display the following acknowledgement:
50 * This product includes software developed by the University of
51 * California, Berkeley and its contributors.
52 * 4. Neither the name of the University nor the names of its contributors
53 * may be used to endorse or promote products derived from this software
54 * without specific prior written permission.
56 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
57 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
59 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
60 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
61 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
62 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
64 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
65 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * @(#)kern_sig.c 8.7 (Berkeley) 4/18/94
71 #define SIGPROP /* include signal properties table */
72 #include <sys/param.h>
73 #include <sys/resourcevar.h>
74 #include <sys/proc_internal.h>
75 #include <sys/kauth.h>
76 #include <sys/systm.h>
77 #include <sys/timeb.h>
78 #include <sys/times.h>
80 #include <sys/file_internal.h>
81 #include <sys/kernel.h>
83 #include <sys/signalvar.h>
85 #include <sys/ktrace.h>
87 #include <sys/syslog.h>
90 #include <sys/kdebug.h>
92 #include <sys/mount.h>
93 #include <sys/sysproto.h>
95 #include <bsm/audit_kernel.h>
97 #include <machine/spl.h>
99 #include <kern/cpu_number.h>
102 #include <sys/user.h> /* for coredump */
103 #include <kern/ast.h> /* for APC support */
104 #include <kern/lock.h>
105 #include <kern/task.h> /* extern void *get_bsdtask_info(task_t); */
106 #include <kern/thread.h>
107 #include <kern/sched_prim.h>
108 #include <kern/thread_call.h>
109 #include <mach/exception.h>
110 #include <mach/task.h>
111 #include <mach/thread_act.h>
114 * Missing prototypes that Mach should export
118 extern int thread_enable_fpe(thread_t act
, int onoff
);
119 extern void unix_syscall_return(int error
);
120 extern thread_t
port_name_to_thread(mach_port_name_t port_name
);
121 extern kern_return_t
check_actforsig(task_t task
, thread_t thread
, int setast
);
122 extern kern_return_t
get_signalact(task_t
, thread_t
*, int);
123 extern boolean_t
thread_should_abort(thread_t
);
124 extern unsigned int get_useraddr(void);
130 extern void doexception(int exc
, int code
, int sub
);
132 void stop(struct proc
*p
);
133 int cansignal(struct proc
*, kauth_cred_t
, struct proc
*, int);
134 int killpg1(struct proc
*, int, int, int);
135 void sigexit_locked(struct proc
*, int);
136 int setsigvec(struct proc
*, int, struct __user_sigaction
*);
137 void exit1(struct proc
*, int, int *);
138 void psignal_uthread(thread_t
, int);
139 kern_return_t
do_bsdexception(int, int, int);
140 void __posix_sem_syscall_return(kern_return_t
);
142 /* implementations in osfmk/kern/sync_sema.c. We do not want port.h in this scope, so void * them */
143 kern_return_t
semaphore_timedwait_signal_trap_internal(void *, void *,time_t, int32_t, void (*)(int));
144 kern_return_t
semaphore_timedwait_trap_internal(void *, time_t, int32_t, void (*)(int));
145 kern_return_t
semaphore_wait_signal_trap_internal(void *, void *, void (*)(int));
146 kern_return_t
semaphore_wait_trap_internal(void *, void (*)(int));
148 static int filt_sigattach(struct knote
*kn
);
149 static void filt_sigdetach(struct knote
*kn
);
150 static int filt_signal(struct knote
*kn
, long hint
);
152 struct filterops sig_filtops
=
153 { 0, filt_sigattach
, filt_sigdetach
, filt_signal
};
157 * NOTE: Source and target may *NOT* overlap! (target is smaller)
160 sigaltstack_64to32(struct user_sigaltstack
*in
, struct sigaltstack
*out
)
162 out
->ss_sp
= CAST_DOWN(void *,in
->ss_sp
);
163 out
->ss_size
= in
->ss_size
;
164 out
->ss_flags
= in
->ss_flags
;
168 * NOTE: Source and target may are permitted to overlap! (source is smaller);
169 * this works because we copy fields in order from the end of the struct to
173 sigaltstack_32to64(struct sigaltstack
*in
, struct user_sigaltstack
*out
)
175 out
->ss_flags
= in
->ss_flags
;
176 out
->ss_size
= in
->ss_size
;
177 out
->ss_sp
= CAST_USER_ADDR_T(in
->ss_sp
);
181 sigaction_64to32(struct user_sigaction
*in
, struct sigaction
*out
)
183 /* This assumes 32 bit __sa_handler is of type sig_t */
184 out
->__sigaction_u
.__sa_handler
= CAST_DOWN(sig_t
,in
->__sigaction_u
.__sa_handler
);
185 out
->sa_mask
= in
->sa_mask
;
186 out
->sa_flags
= in
->sa_flags
;
190 __sigaction_32to64(struct __sigaction
*in
, struct __user_sigaction
*out
)
192 out
->__sigaction_u
.__sa_handler
= CAST_USER_ADDR_T(in
->__sigaction_u
.__sa_handler
);
193 out
->sa_tramp
= CAST_USER_ADDR_T(in
->sa_tramp
);
194 out
->sa_mask
= in
->sa_mask
;
195 out
->sa_flags
= in
->sa_flags
;
200 void ram_printf(int);
202 unsigned int rdebug_proc
=0;
209 #endif /* SIGNAL_DEBUG */
212 signal_lock(struct proc
*p
)
219 int register sp
, *fp
, numsaved
;
221 __asm__
volatile("mr %0,r1" : "=r" (sp
));
223 fp
= (int *)*((int *)sp
);
224 for (numsaved
= 0; numsaved
< 3; numsaved
++) {
225 p
->lockpc
[numsaved
] = fp
[2];
232 #endif /* SIGNAL_DEBUG */
233 #endif /* DIAGNOSTIC */
236 error
= lockmgr((struct lock__bsd__
*)&p
->signal_lock
[0], LK_EXCLUSIVE
, 0, (struct proc
*)0);
243 signal_unlock(struct proc
*p
)
249 int register sp
, *fp
, numsaved
;
251 __asm__
volatile("mr %0,r1" : "=r" (sp
));
253 fp
= (int *)*((int *)sp
);
254 for (numsaved
= 0; numsaved
< 3; numsaved
++) {
255 p
->unlockpc
[numsaved
] = fp
[2];
262 #endif /* SIGNAL_DEBUG */
263 #endif /* DIAGNOSTIC */
265 /* TBD: check p last arg */
266 return(lockmgr((struct lock__bsd__
*)&p
->signal_lock
[0], LK_RELEASE
, (simple_lock_t
)0, (struct proc
*)0));
270 signal_setast(sig_actthread
)
271 thread_t sig_actthread
;
273 act_set_astbsd(sig_actthread
);
277 * Can process p, with ucred uc, send the signal signum to process q?
280 cansignal(p
, uc
, q
, signum
)
286 /* you can signal yourself */
290 if (!suser(uc
, NULL
))
291 return (1); /* root can always signal */
293 if (signum
== SIGCONT
&& q
->p_session
== p
->p_session
)
294 return (1); /* SIGCONT in session */
297 * Using kill(), only certain signals can be sent to setugid
300 if (q
->p_flag
& P_SUGID
) {
313 if (uc
->cr_ruid
== q
->p_ucred
->cr_ruid
||
314 kauth_cred_getuid(uc
) == q
->p_ucred
->cr_ruid
||
315 uc
->cr_ruid
== kauth_cred_getuid(q
->p_ucred
) ||
316 kauth_cred_getuid(uc
) == kauth_cred_getuid(q
->p_ucred
))
323 * because the P_SUGID test exists, this has extra tests which
326 if (uc
->cr_ruid
== q
->p_ucred
->cr_ruid
||
327 uc
->cr_ruid
== q
->p_ucred
->cr_svuid
||
328 kauth_cred_getuid(uc
) == q
->p_ucred
->cr_ruid
||
329 kauth_cred_getuid(uc
) == q
->p_ucred
->cr_svuid
||
330 uc
->cr_ruid
== kauth_cred_getuid(q
->p_ucred
) ||
331 kauth_cred_getuid(uc
) == kauth_cred_getuid(q
->p_ucred
))
339 sigaction(struct proc
*p
, register struct sigaction_args
*uap
, __unused register_t
*retval
)
341 struct user_sigaction vec
;
342 struct __user_sigaction __vec
;
344 struct user_sigaction
*sa
= &vec
;
345 register struct sigacts
*ps
= p
->p_sigacts
;
350 signum
= uap
->signum
;
351 if (signum
<= 0 || signum
>= NSIG
||
352 signum
== SIGKILL
|| signum
== SIGSTOP
)
356 sa
->sa_handler
= ps
->ps_sigact
[signum
];
357 sa
->sa_mask
= ps
->ps_catchmask
[signum
];
358 bit
= sigmask(signum
);
360 if ((ps
->ps_sigonstack
& bit
) != 0)
361 sa
->sa_flags
|= SA_ONSTACK
;
362 if ((ps
->ps_sigintr
& bit
) == 0)
363 sa
->sa_flags
|= SA_RESTART
;
364 if (ps
->ps_siginfo
& bit
)
365 sa
->sa_flags
|= SA_SIGINFO
;
366 if (ps
->ps_signodefer
& bit
)
367 sa
->sa_flags
|= SA_NODEFER
;
368 if (ps
->ps_64regset
& bit
)
369 sa
->sa_flags
|= SA_64REGSET
;
370 if ((signum
== SIGCHLD
) && (p
->p_flag
& P_NOCLDSTOP
))
371 sa
->sa_flags
|= SA_NOCLDSTOP
;
372 if ((signum
== SIGCHLD
) && (p
->p_flag
& P_NOCLDWAIT
))
373 sa
->sa_flags
|= SA_NOCLDWAIT
;
375 if (IS_64BIT_PROCESS(p
)) {
376 error
= copyout(sa
, uap
->osa
, sizeof(struct user_sigaction
));
378 struct sigaction vec32
;
379 sigaction_64to32(sa
, &vec32
);
380 error
= copyout(&vec32
, uap
->osa
, sizeof(struct sigaction
));
386 if (IS_64BIT_PROCESS(p
)) {
387 error
= copyin(uap
->nsa
, &__vec
, sizeof(struct __user_sigaction
));
389 struct __sigaction __vec32
;
390 error
= copyin(uap
->nsa
, &__vec32
, sizeof(struct __sigaction
));
391 __sigaction_32to64(&__vec32
, &__vec
);
395 error
= setsigvec(p
, signum
, &__vec
);
400 /* Routines to manipulate bits on all threads */
402 clear_procsiglist(struct proc
*p
, int bit
)
404 struct uthread
* uth
;
409 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
410 thact
= p
->p_vforkact
;
411 uth
= (struct uthread
*)get_bsdthread_info(thact
);
413 uth
->uu_siglist
&= ~bit
;
415 p
->p_siglist
&= ~bit
;
420 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
421 uth
->uu_siglist
&= ~bit
;
423 p
->p_siglist
&= ~bit
;
430 unblock_procsigmask(struct proc
*p
, int bit
)
432 struct uthread
* uth
;
436 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
437 thact
= p
->p_vforkact
;
438 uth
= (struct uthread
*)get_bsdthread_info(thact
);
440 uth
->uu_sigmask
&= ~bit
;
442 p
->p_sigmask
&= ~bit
;
446 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
447 uth
->uu_sigmask
&= ~bit
;
449 p
->p_sigmask
&= ~bit
;
456 block_procsigmask(struct proc
*p
, int bit
)
458 struct uthread
* uth
;
462 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
463 thact
= p
->p_vforkact
;
464 uth
= (struct uthread
*)get_bsdthread_info(thact
);
466 uth
->uu_sigmask
|= bit
;
472 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
473 uth
->uu_sigmask
|= bit
;
481 set_procsigmask(struct proc
*p
, int bit
)
483 struct uthread
* uth
;
487 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
488 thact
= p
->p_vforkact
;
489 uth
= (struct uthread
*)get_bsdthread_info(thact
);
491 uth
->uu_sigmask
= bit
;
497 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
498 uth
->uu_sigmask
= bit
;
505 /* XXX should be static? */
507 setsigvec(struct proc
*p
, int signum
, struct __user_sigaction
*sa
)
509 register struct sigacts
*ps
= p
->p_sigacts
;
512 if ((signum
== SIGKILL
|| signum
== SIGSTOP
) &&
513 sa
->sa_handler
!= SIG_DFL
)
515 bit
= sigmask(signum
);
517 * Change setting atomically.
519 ps
->ps_sigact
[signum
] = sa
->sa_handler
;
520 ps
->ps_trampact
[signum
] = sa
->sa_tramp
;
521 ps
->ps_catchmask
[signum
] = sa
->sa_mask
&~ sigcantmask
;
522 if (sa
->sa_flags
& SA_SIGINFO
)
523 ps
->ps_siginfo
|= bit
;
525 ps
->ps_siginfo
&= ~bit
;
526 if (sa
->sa_flags
& SA_64REGSET
)
527 ps
->ps_64regset
|= bit
;
529 ps
->ps_64regset
&= ~bit
;
530 if ((sa
->sa_flags
& SA_RESTART
) == 0)
531 ps
->ps_sigintr
|= bit
;
533 ps
->ps_sigintr
&= ~bit
;
534 if (sa
->sa_flags
& SA_ONSTACK
)
535 ps
->ps_sigonstack
|= bit
;
537 ps
->ps_sigonstack
&= ~bit
;
538 if (sa
->sa_flags
& SA_USERTRAMP
)
539 ps
->ps_usertramp
|= bit
;
541 ps
->ps_usertramp
&= ~bit
;
542 if (sa
->sa_flags
& SA_RESETHAND
)
543 ps
->ps_sigreset
|= bit
;
545 ps
->ps_sigreset
&= ~bit
;
546 if (sa
->sa_flags
& SA_NODEFER
)
547 ps
->ps_signodefer
|= bit
;
549 ps
->ps_signodefer
&= ~bit
;
550 if (signum
== SIGCHLD
) {
551 if (sa
->sa_flags
& SA_NOCLDSTOP
)
552 p
->p_flag
|= P_NOCLDSTOP
;
554 p
->p_flag
&= ~P_NOCLDSTOP
;
555 if ((sa
->sa_flags
& SA_NOCLDWAIT
) || (sa
->sa_handler
== SIG_IGN
))
556 p
->p_flag
|= P_NOCLDWAIT
;
558 p
->p_flag
&= ~P_NOCLDWAIT
;
562 if (signum
== SIGFPE
) {
563 if (sa
->sa_handler
== SIG_DFL
|| sa
->sa_handler
== SIG_IGN
)
564 thread_enable_fpe(current_thread(), 0);
566 thread_enable_fpe(current_thread(), 1);
570 * Set bit in p_sigignore for signals that are set to SIG_IGN,
571 * and for signals set to SIG_DFL where the default is to ignore.
572 * However, don't put SIGCONT in p_sigignore,
573 * as we have to restart the process.
575 if (sa
->sa_handler
== SIG_IGN
||
576 (sigprop
[signum
] & SA_IGNORE
&& sa
->sa_handler
== SIG_DFL
)) {
578 clear_procsiglist(p
, bit
);
579 if (signum
!= SIGCONT
)
580 p
->p_sigignore
|= bit
; /* easier in psignal */
581 p
->p_sigcatch
&= ~bit
;
583 p
->p_sigignore
&= ~bit
;
584 if (sa
->sa_handler
== SIG_DFL
)
585 p
->p_sigcatch
&= ~bit
;
587 p
->p_sigcatch
|= bit
;
593 * Initialize signal state for process 0;
594 * set to ignore signals that are ignored by default.
602 for (i
= 0; i
< NSIG
; i
++)
603 if (sigprop
[i
] & SA_IGNORE
&& i
!= SIGCONT
)
604 p
->p_sigignore
|= sigmask(i
);
608 * Reset signals for an exec of the specified process.
612 register struct proc
*p
;
613 register thread_t thr_act
;
615 register struct sigacts
*ps
= p
->p_sigacts
;
616 register int nc
, mask
;
620 * Reset caught signals. Held signals remain held
621 * through p_sigmask (unless they were caught,
622 * and are now ignored by default).
624 while (p
->p_sigcatch
) {
625 nc
= ffs((long)p
->p_sigcatch
);
627 p
->p_sigcatch
&= ~mask
;
628 if (sigprop
[nc
] & SA_IGNORE
) {
630 p
->p_sigignore
|= mask
;
632 ut
= (struct uthread
*)get_bsdthread_info(thr_act
);
633 ut
->uu_siglist
&= ~mask
;
634 p
->p_siglist
&= ~mask
;
636 clear_procsiglist(p
, mask
);
638 ps
->ps_sigact
[nc
] = SIG_DFL
;
641 * Reset stack state to the user stack.
642 * Clear set of signals caught on the signal stack.
644 ps
->ps_sigstk
.ss_flags
= SA_DISABLE
;
645 ps
->ps_sigstk
.ss_size
= 0;
646 ps
->ps_sigstk
.ss_sp
= USER_ADDR_NULL
;
651 * Manipulate signal mask.
652 * Note that we receive new mask, not pointer,
653 * and return old mask as return value;
654 * the library stub does the rest.
657 sigprocmask(register struct proc
*p
, struct sigprocmask_args
*uap
, __unused register_t
*retval
)
660 sigset_t oldmask
, nmask
;
661 user_addr_t omask
= uap
->omask
;
664 ut
= (struct uthread
*)get_bsdthread_info(current_thread());
665 oldmask
= ut
->uu_sigmask
;
667 if (uap
->mask
== USER_ADDR_NULL
) {
668 /* just want old mask */
671 error
= copyin(uap
->mask
, &nmask
, sizeof(sigset_t
));
677 block_procsigmask(p
, (nmask
& ~sigcantmask
));
678 signal_setast(current_thread());
682 unblock_procsigmask(p
, (nmask
& ~sigcantmask
));
683 signal_setast(current_thread());
687 set_procsigmask(p
, (nmask
& ~sigcantmask
));
688 signal_setast(current_thread());
696 if (!error
&& omask
!= USER_ADDR_NULL
)
697 copyout(&oldmask
, omask
, sizeof(sigset_t
));
702 sigpending(__unused
struct proc
*p
, register struct sigpending_args
*uap
, __unused register_t
*retval
)
707 ut
= (struct uthread
*)get_bsdthread_info(current_thread());
708 pendlist
= ut
->uu_siglist
;
711 copyout(&pendlist
, uap
->osv
, sizeof(sigset_t
));
717 * Suspend process until signal, providing mask to be set
718 * in the meantime. Note nonstandard calling convention:
719 * libc stub passes mask, not pointer, to save a copyin.
723 sigcontinue(__unused
int error
)
725 // struct uthread *ut = get_bsdthread_info(current_thread());
726 unix_syscall_return(EINTR
);
730 sigsuspend(register struct proc
*p
, struct sigsuspend_args
*uap
, __unused register_t
*retval
)
734 ut
= (struct uthread
*)get_bsdthread_info(current_thread());
737 * When returning from sigpause, we want
738 * the old mask to be restored after the
739 * signal handler has finished. Thus, we
740 * save it here and mark the sigacts structure
743 ut
->uu_oldmask
= ut
->uu_sigmask
;
744 ut
->uu_flag
|= UT_SAS_OLDMASK
;
745 ut
->uu_sigmask
= (uap
->mask
& ~sigcantmask
);
746 (void) tsleep0((caddr_t
) p
, PPAUSE
|PCATCH
, "pause", 0, sigcontinue
);
747 /* always return EINTR rather than ERESTART... */
753 __disable_threadsignal(struct proc
*p
,
754 __unused
register struct __disable_threadsignal_args
*uap
,
755 __unused register_t
*retval
)
759 uth
= (struct uthread
*)get_bsdthread_info(current_thread());
761 /* No longer valid to have any signal delivered */
763 uth
->uu_flag
|= UT_NO_SIGMASK
;
772 __pthread_markcancel(p
, uap
, retval
)
774 register struct __pthread_markcancel_args
*uap
;
777 thread_act_t target_act
;
781 target_act
= (thread_act_t
)port_name_to_thread(uap
->thread_port
);
783 if (target_act
== THR_ACT_NULL
)
786 uth
= (struct uthread
*)get_bsdthread_info(target_act
);
788 /* if the thread is in vfork do not cancel */
789 if ((uth
->uu_flag
& (P_VFORK
| UT_CANCEL
| UT_CANCELED
)) == 0) {
790 uth
->uu_flag
|= (UT_CANCEL
| UT_NO_SIGMASK
);
791 if (((uth
->uu_flag
& UT_NOTCANCELPT
) == 0)
792 && ((uth
->uu_flag
& UT_CANCELDISABLE
) == 0))
793 thread_abort_safely(target_act
);
796 thread_deallocate(target_act
);
800 /* if action =0 ; return the cancellation state ,
801 * if marked for cancellation, make the thread canceled
802 * if action = 1 ; Enable the cancel handling
803 * if action = 2; Disable the cancel handling
806 __pthread_canceled(p
, uap
, retval
)
808 register struct __pthread_canceled_args
*uap
;
811 thread_act_t thr_act
;
813 int action
= uap
->action
;
815 thr_act
= current_act();
816 uth
= (struct uthread
*)get_bsdthread_info(thr_act
);
820 uth
->uu_flag
&= ~UT_CANCELDISABLE
;
823 uth
->uu_flag
|= UT_CANCELDISABLE
;
827 /* if the thread is in vfork do not cancel */
828 if((uth
->uu_flag
& ( UT_CANCELDISABLE
| UT_CANCEL
| UT_CANCELED
)) == UT_CANCEL
) {
829 uth
->uu_flag
&= ~UT_CANCEL
;
830 uth
->uu_flag
|= (UT_CANCELED
| UT_NO_SIGMASK
);
839 __posix_sem_syscall_return(kern_return_t kern_result
)
843 if (kern_result
== KERN_SUCCESS
)
845 else if (kern_result
== KERN_ABORTED
)
847 else if (kern_result
== KERN_OPERATION_TIMED_OUT
)
851 unix_syscall_return(error
);
852 /* does not return */
857 __semwait_signal(p
, uap
, retval
)
859 register struct __semwait_signal_args
*uap
;
863 kern_return_t kern_result
;
864 mach_timespec_t then
;
870 then
.tv_sec
= uap
->tv_sec
;
871 then
.tv_nsec
= uap
->tv_nsec
;
874 then
.tv_sec
= uap
->tv_sec
- now
.tv_sec
;
875 then
.tv_nsec
= uap
->tv_nsec
- now
.tv_nsec
;
876 if (then
.tv_nsec
< 0) {
877 then
.tv_nsec
+= NSEC_PER_SEC
;
882 if (uap
->mutex_sem
== (void *)NULL
)
883 kern_result
= semaphore_timedwait_trap_internal(uap
->cond_sem
, then
.tv_sec
, then
.tv_nsec
, __posix_sem_syscall_return
);
885 kern_result
= semaphore_timedwait_signal_trap_internal(uap
->cond_sem
, uap
->mutex_sem
, then
.tv_sec
, then
.tv_nsec
, __posix_sem_syscall_return
);
889 if (uap
->mutex_sem
== (void *)NULL
)
890 kern_result
= semaphore_wait_trap_internal(uap
->cond_sem
, __posix_sem_syscall_return
);
893 kern_result
= semaphore_wait_signal_trap_internal(uap
->cond_sem
, uap
->mutex_sem
, __posix_sem_syscall_return
);
897 if (kern_result
== KERN_SUCCESS
)
899 else if (kern_result
== KERN_ABORTED
)
901 else if (kern_result
== KERN_OPERATION_TIMED_OUT
)
909 __pthread_kill(__unused
struct proc
*p
,
910 register struct __pthread_kill_args
*uap
,
911 __unused register_t
*retval
)
915 int signum
= uap
->sig
;
918 target_act
= (thread_t
)port_name_to_thread(uap
->thread_port
);
920 if (target_act
== THREAD_NULL
)
922 if ((u_int
)signum
>= NSIG
) {
927 uth
= (struct uthread
*)get_bsdthread_info(target_act
);
929 if (uth
->uu_flag
& UT_NO_SIGMASK
) {
935 psignal_uthread(target_act
, signum
);
937 thread_deallocate(target_act
);
943 pthread_sigmask(__unused
register struct proc
*p
,
944 register struct pthread_sigmask_args
*uap
,
945 __unused register_t
*retval
)
947 user_addr_t set
= uap
->set
;
948 user_addr_t oset
= uap
->oset
;
954 ut
= (struct uthread
*)get_bsdthread_info(current_thread());
955 oldset
= ut
->uu_sigmask
;
957 if (set
== USER_ADDR_NULL
) {
958 /* need only old mask */
962 error
= copyin(set
, &nset
, sizeof(sigset_t
));
968 ut
->uu_sigmask
|= (nset
& ~sigcantmask
);
972 ut
->uu_sigmask
&= ~(nset
);
973 signal_setast(current_thread());
977 ut
->uu_sigmask
= (nset
& ~sigcantmask
);
978 signal_setast(current_thread());
986 if (!error
&& oset
!= USER_ADDR_NULL
)
987 copyout(&oldset
, oset
, sizeof(sigset_t
));
994 sigwait(register struct proc
*p
, register struct sigwait_args
*uap
, __unused register_t
*retval
)
1004 ut
= (struct uthread
*)get_bsdthread_info(current_thread());
1006 if (uap
->set
== USER_ADDR_NULL
)
1009 error
= copyin(uap
->set
, &mask
, sizeof(sigset_t
));
1013 siglist
= (mask
& ~sigcantmask
);
1019 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
1023 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
1024 if ( (sigw
= uth
->uu_siglist
& siglist
) ) {
1031 /* The signal was pending on a thread */
1035 * When returning from sigwait, we want
1036 * the old mask to be restored after the
1037 * signal handler has finished. Thus, we
1038 * save it here and mark the sigacts structure
1041 ut
->uu_oldmask
= ut
->uu_sigmask
;
1042 ut
->uu_flag
|= UT_SAS_OLDMASK
;
1043 if (siglist
== (sigset_t
)0)
1045 /* SIGKILL and SIGSTOP are not maskable as well */
1046 ut
->uu_sigmask
= ~(siglist
|sigcantmask
);
1047 ut
->uu_sigwait
= siglist
;
1048 /* No Continuations for now */
1049 error
= tsleep((caddr_t
)&ut
->uu_sigwait
, PPAUSE
|PCATCH
, "pause", 0);
1051 if ((error
== EINTR
) || (error
== ERESTART
))
1054 sigw
= (ut
->uu_sigwait
& siglist
);
1055 ut
->uu_sigmask
= ut
->uu_oldmask
;
1057 ut
->uu_flag
&= ~UT_SAS_OLDMASK
;
1061 signum
= ffs((unsigned int)sigw
);
1063 panic("sigwait with no signal wakeup");
1064 ut
->uu_siglist
&= ~(sigmask(signum
));
1065 if (uap
->sig
!= USER_ADDR_NULL
)
1066 error
= copyout(&signum
, uap
->sig
, sizeof(int));
1075 sigaltstack(struct proc
*p
, register struct sigaltstack_args
*uap
, __unused register_t
*retval
)
1077 struct sigacts
*psp
;
1078 struct user_sigaltstack ss
;
1082 if ((psp
->ps_flags
& SAS_ALTSTACK
) == 0)
1083 psp
->ps_sigstk
.ss_flags
|= SA_DISABLE
;
1085 if (IS_64BIT_PROCESS(p
)) {
1086 error
= copyout(&psp
->ps_sigstk
, uap
->oss
, sizeof(struct user_sigaltstack
));
1088 struct sigaltstack ss32
;
1089 sigaltstack_64to32(&psp
->ps_sigstk
, &ss32
);
1090 error
= copyout(&ss32
, uap
->oss
, sizeof(struct sigaltstack
));
1095 if (uap
->nss
== USER_ADDR_NULL
)
1097 if (IS_64BIT_PROCESS(p
)) {
1098 error
= copyin(uap
->nss
, &ss
, sizeof(struct user_sigaltstack
));
1100 struct sigaltstack ss32
;
1101 error
= copyin(uap
->nss
, &ss32
, sizeof(struct sigaltstack
));
1102 sigaltstack_32to64(&ss32
,&ss
);
1106 if ((ss
.ss_flags
& ~SA_DISABLE
) != 0) {
1110 if (ss
.ss_flags
& SA_DISABLE
) {
1111 if (psp
->ps_sigstk
.ss_flags
& SA_ONSTACK
)
1113 psp
->ps_flags
&= ~SAS_ALTSTACK
;
1114 psp
->ps_sigstk
.ss_flags
= ss
.ss_flags
;
1117 /* The older stacksize was 8K, enforce that one so no compat problems */
1118 #define OLDMINSIGSTKSZ 8*1024
1119 if (ss
.ss_size
< OLDMINSIGSTKSZ
)
1121 psp
->ps_flags
|= SAS_ALTSTACK
;
1127 kill(struct proc
*cp
, struct kill_args
*uap
, __unused register_t
*retval
)
1129 register struct proc
*p
;
1130 kauth_cred_t uc
= kauth_cred_get();
1132 AUDIT_ARG(pid
, uap
->pid
);
1133 AUDIT_ARG(signum
, uap
->signum
);
1135 if ((u_int
)uap
->signum
>= NSIG
)
1138 /* kill single process */
1139 if ((p
= proc_findref(uap
->pid
)) == NULL
) {
1140 if ((p
= pzfind(uap
->pid
)) != NULL
) {
1142 * IEEE Std 1003.1-2001: return success
1143 * when killing a zombie.
1149 AUDIT_ARG(process
, p
);
1150 if (!cansignal(cp
, uc
, p
, uap
->signum
)) {
1155 psignal(p
, uap
->signum
);
1160 case -1: /* broadcast signal */
1161 return (killpg1(cp
, uap
->signum
, 0, 1));
1162 case 0: /* signal own process group */
1163 return (killpg1(cp
, uap
->signum
, 0, 0));
1164 default: /* negative explicit process group */
1165 return (killpg1(cp
, uap
->signum
, -(uap
->pid
), 0));
1172 * Common code for kill process group/broadcast kill.
1173 * cp is calling process.
1176 killpg1(cp
, signum
, pgid
, all
)
1177 register struct proc
*cp
;
1178 int signum
, pgid
, all
;
1180 register struct proc
*p
;
1181 kauth_cred_t uc
= cp
->p_ucred
;
1189 for (p
= allproc
.lh_first
; p
!= 0; p
= p
->p_list
.le_next
) {
1190 if (p
->p_pid
<= 1 || p
->p_flag
& P_SYSTEM
||
1191 p
== cp
|| !cansignal(cp
, uc
, p
, signum
))
1200 * zero pgid means send to my process group.
1204 pgrp
= pgfind(pgid
);
1208 for (p
= pgrp
->pg_members
.lh_first
; p
!= 0;
1209 p
= p
->p_pglist
.le_next
) {
1210 if (p
->p_pid
<= 1 || p
->p_flag
& P_SYSTEM
||
1211 p
->p_stat
== SZOMB
||
1212 !cansignal(cp
, uc
, p
, signum
))
1219 return (nfound
? 0 : ESRCH
);
1223 * Send a signal to a process group.
1226 gsignal(pgid
, signum
)
1231 if (pgid
&& (pgrp
= pgfind(pgid
)))
1232 pgsignal(pgrp
, signum
, 0);
1236 * Send a signal to a process group. If checktty is 1,
1237 * limit to members which have a controlling terminal.
1240 pgsignal(pgrp
, signum
, checkctty
)
1242 int signum
, checkctty
;
1244 register struct proc
*p
;
1247 for (p
= pgrp
->pg_members
.lh_first
; p
!= 0;
1248 p
= p
->p_pglist
.le_next
)
1249 if (checkctty
== 0 || p
->p_flag
& P_CONTROLT
)
1254 * Send signal to a backgrounded process blocked due to tty access
1255 * In FreeBSD, the backgrounded process wakes up every second and
1256 * discovers whether it is foregounded or not. In our case, we block
1257 * the thread in tsleep as we want to avoid storm of processes as well
1258 * as the suspend is only at AST level
1261 tty_pgsignal(pgrp
, signum
)
1265 register struct proc
*p
;
1268 for (p
= pgrp
->pg_members
.lh_first
; p
!= 0;
1269 p
= p
->p_pglist
.le_next
)
1270 if ((p
->p_flag
& P_TTYSLEEP
) && (p
->p_flag
& P_CONTROLT
))
1275 * Send a signal caused by a trap to a specific thread.
1278 threadsignal(thread_t sig_actthread
, int signum
, u_long code
)
1280 register struct uthread
*uth
;
1281 register struct task
* sig_task
;
1282 register struct proc
*p
;
1285 if ((u_int
)signum
>= NSIG
|| signum
== 0)
1288 mask
= sigmask(signum
);
1289 if ((mask
& threadmask
) == 0)
1291 sig_task
= get_threadtask(sig_actthread
);
1292 p
= (struct proc
*)(get_bsdtask_info(sig_task
));
1294 uth
= get_bsdthread_info(sig_actthread
);
1295 if (uth
&& (uth
->uu_flag
& UT_VFORK
))
1298 if (!(p
->p_flag
& P_TRACED
) && (p
->p_sigignore
& mask
))
1301 uth
->uu_siglist
|= mask
;
1302 p
->p_siglist
|= mask
; /* just for lame ones looking here */
1303 uth
->uu_code
= code
;
1304 /* mark on process as well */
1305 signal_setast(sig_actthread
);
1311 register struct proc
*p
;
1312 register int signum
;
1314 psignal_lock(p
, signum
, 1);
1318 psignal_vfork(struct proc
*p
, task_t new_task
, thread_t thr_act
, int signum
)
1321 register sig_t action
;
1323 struct uthread
*uth
;
1325 if ((u_int
)signum
>= NSIG
|| signum
== 0)
1326 panic("psignal signal number");
1327 mask
= sigmask(signum
);
1328 prop
= sigprop
[signum
];
1331 if(rdebug_proc
&& (p
== rdebug_proc
)) {
1334 #endif /* SIGNAL_DEBUG */
1336 if ((new_task
== TASK_NULL
) || (thr_act
== (thread_t
)NULL
) || is_kerneltask(new_task
))
1340 uth
= get_bsdthread_info(thr_act
);
1344 * proc is traced, always give parent a chance.
1348 if (p
->p_nice
> NZERO
&& action
== SIG_DFL
&& (prop
& SA_KILL
) &&
1349 (p
->p_flag
& P_TRACED
) == 0)
1352 if (prop
& SA_CONT
) {
1353 p
->p_siglist
&= ~stopsigmask
;
1354 uth
->uu_siglist
&= ~stopsigmask
;
1357 if (prop
& SA_STOP
) {
1359 * If sending a tty stop signal to a member of an orphaned
1360 * process group, discard the signal here if the action
1361 * is default; don't stop the process below if sleeping,
1362 * and don't clear any pending SIGCONT.
1364 if (prop
& SA_TTYSTOP
&& p
->p_pgrp
->pg_jobc
== 0 &&
1367 uth
->uu_siglist
&= ~contsigmask
;
1368 p
->p_siglist
&= ~contsigmask
;
1370 uth
->uu_siglist
|= mask
;
1371 p
->p_siglist
|= mask
; /* just for lame ones looking here */
1373 /* Deliver signal to the activation passed in */
1374 act_set_astbsd(thr_act
);
1377 * SIGKILL priority twiddling moved here from above because
1378 * it needs sig_thread. Could merge it into large switch
1379 * below if we didn't care about priority for tracing
1380 * as SIGKILL's action is always SIG_DFL.
1382 if ((signum
== SIGKILL
) && (p
->p_nice
> NZERO
)) {
1387 * This Process is traced - wake it up (if not already
1388 * stopped) so that it can discover the signal in
1389 * issig() and stop for the parent.
1391 if (p
->p_flag
& P_TRACED
) {
1392 if (p
->p_stat
!= SSTOP
)
1399 * If we're being traced (possibly because someone attached us
1400 * while we were stopped), check for a signal from the debugger.
1402 if (p
->p_stat
== SSTOP
) {
1403 if ((p
->p_flag
& P_TRACED
) != 0 && p
->p_xstat
!= 0) {
1404 uth
->uu_siglist
|= sigmask(p
->p_xstat
);
1405 p
->p_siglist
|= mask
; /* just for lame ones looking here */
1410 * setrunnable(p) in BSD
1419 get_signalthread(struct proc
*p
, int signum
)
1421 struct uthread
*uth
;
1423 sigset_t mask
= sigmask(signum
);
1424 thread_t sig_thread_act
;
1425 struct task
* sig_task
= p
->task
;
1428 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
1429 sig_thread_act
= p
->p_vforkact
;
1430 kret
= check_actforsig(sig_task
, sig_thread_act
, 1);
1431 if (kret
== KERN_SUCCESS
)
1432 return(sig_thread_act
);
1434 return(THREAD_NULL
);
1437 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
1438 if(((uth
->uu_flag
& UT_NO_SIGMASK
)== 0) &&
1439 (((uth
->uu_sigmask
& mask
) == 0) || (uth
->uu_sigwait
& mask
))) {
1440 if (check_actforsig(p
->task
, uth
->uu_act
, 1) == KERN_SUCCESS
)
1441 return(uth
->uu_act
);
1444 if (get_signalact(p
->task
, &thr_act
, 1) == KERN_SUCCESS
) {
1448 return(THREAD_NULL
);
1452 * Send the signal to the process. If the signal has an action, the action
1453 * is usually performed by the target process rather than the caller; we add
1454 * the signal to the set of pending signals for the process.
1457 * o When a stop signal is sent to a sleeping process that takes the
1458 * default action, the process is stopped without awakening it.
1459 * o SIGCONT restarts stopped processes (or puts them back to sleep)
1460 * regardless of the signal action (eg, blocked or ignored).
1462 * Other ignored signals are discarded immediately.
1465 psignal_lock(p
, signum
, withlock
)
1466 register struct proc
*p
;
1467 register int signum
;
1468 register int withlock
;
1470 register int s
, prop
;
1471 register sig_t action
;
1472 thread_t sig_thread_act
;
1473 register task_t sig_task
;
1475 struct uthread
*uth
;
1476 boolean_t funnel_state
= FALSE
;
1479 if ((u_int
)signum
>= NSIG
|| signum
== 0)
1480 panic("psignal signal number");
1481 mask
= sigmask(signum
);
1482 prop
= sigprop
[signum
];
1485 if(rdebug_proc
&& (p
== rdebug_proc
)) {
1488 #endif /* SIGNAL_DEBUG */
1490 if (thread_funnel_get() == (funnel_t
*)0) {
1492 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
1495 * We will need the task pointer later. Grab it now to
1496 * check for a zombie process. Also don't send signals
1497 * to kernel internal tasks.
1499 if (((sig_task
= p
->task
) == TASK_NULL
) || is_kerneltask(sig_task
)) {
1501 thread_funnel_set(kernel_flock
, funnel_state
);
1506 KNOTE(&p
->p_klist
, NOTE_SIGNAL
| signum
);
1510 * do not send signals to the process that has the thread
1511 * doing a reboot(). Not doing so will mark that thread aborted
1512 * and can cause IO failures wich will cause data loss.
1514 if (ISSET(p
->p_flag
, P_REBOOT
)) {
1516 thread_funnel_set(kernel_flock
, funnel_state
);
1524 * Deliver the signal to the first thread in the task. This
1525 * allows single threaded applications which use signals to
1526 * be able to be linked with multithreaded libraries. We have
1527 * an implicit reference to the current thread, but need
1528 * an explicit one otherwise. The thread reference keeps
1529 * the corresponding task data structures around too. This
1530 * reference is released by thread_deallocate.
1533 if (((p
->p_flag
& P_TRACED
) == 0) && (p
->p_sigignore
& mask
))
1536 /* If successful return with ast set */
1537 sig_thread_act
= get_signalthread(p
, signum
);
1539 if (sig_thread_act
== THREAD_NULL
) {
1541 * if it is sigkill, may be we should
1542 * inject a thread to terminate
1546 #endif /* SIGNAL_DEBUG */
1550 uth
= get_bsdthread_info(sig_thread_act
);
1553 * If proc is traced, always give parent a chance.
1555 if (p
->p_flag
& P_TRACED
)
1559 * If the signal is being ignored,
1560 * then we forget about it immediately.
1561 * (Note: we don't set SIGCONT in p_sigignore,
1562 * and if it is set to SIG_IGN,
1563 * action will be SIG_DFL here.)
1565 if (p
->p_sigignore
& mask
)
1567 /* sigwait takes precedence */
1568 if (uth
->uu_sigwait
& mask
)
1569 action
= KERN_SIG_WAIT
;
1570 else if (uth
->uu_sigmask
& mask
)
1571 action
= KERN_SIG_HOLD
;
1572 else if (p
->p_sigcatch
& mask
)
1573 action
= KERN_SIG_CATCH
;
1578 if (p
->p_nice
> NZERO
&& action
== SIG_DFL
&& (prop
& SA_KILL
) &&
1579 (p
->p_flag
& P_TRACED
) == 0)
1582 if (prop
& SA_CONT
) {
1583 uth
->uu_siglist
&= ~stopsigmask
;
1584 p
->p_siglist
&= ~stopsigmask
;
1587 if (prop
& SA_STOP
) {
1589 * If sending a tty stop signal to a member of an orphaned
1590 * process group, discard the signal here if the action
1591 * is default; don't stop the process below if sleeping,
1592 * and don't clear any pending SIGCONT.
1594 if (prop
& SA_TTYSTOP
&& p
->p_pgrp
->pg_jobc
== 0 &&
1597 uth
->uu_siglist
&= ~contsigmask
;
1598 p
->p_siglist
&= ~contsigmask
;
1600 uth
->uu_siglist
|= mask
;
1601 p
->p_siglist
|= mask
; /* just for lame ones looking here */
1605 * Defer further processing for signals which are held,
1606 * except that stopped processes must be continued by SIGCONT.
1608 if (action
== KERN_SIG_HOLD
&& ((prop
& SA_CONT
) == 0 || p
->p_stat
!= SSTOP
)) {
1612 * SIGKILL priority twiddling moved here from above because
1613 * it needs sig_thread. Could merge it into large switch
1614 * below if we didn't care about priority for tracing
1615 * as SIGKILL's action is always SIG_DFL.
1617 if ((signum
== SIGKILL
) && (p
->p_nice
> NZERO
)) {
1622 * Process is traced - wake it up (if not already
1623 * stopped) so that it can discover the signal in
1624 * issig() and stop for the parent.
1626 if (p
->p_flag
& P_TRACED
) {
1627 if (p
->p_stat
!= SSTOP
)
1633 if (action
== KERN_SIG_WAIT
) {
1634 uth
->uu_sigwait
= mask
;
1635 uth
->uu_siglist
&= ~mask
;
1636 p
->p_siglist
&= ~mask
;
1637 wakeup(&uth
->uu_sigwait
);
1638 /* if it is SIGCONT resume whole process */
1639 if (prop
& SA_CONT
) {
1640 p
->p_flag
|= P_CONTINUED
;
1641 (void) task_resume(sig_task
);
1646 if (action
!= SIG_DFL
) {
1648 * User wants to catch the signal.
1649 * Wake up the thread, but don't un-suspend it
1650 * (except for SIGCONT).
1652 if (prop
& SA_CONT
) {
1653 if (p
->p_flag
& P_TTYSLEEP
) {
1654 p
->p_flag
&= ~P_TTYSLEEP
;
1655 wakeup(&p
->p_siglist
);
1657 p
->p_flag
|= P_CONTINUED
;
1658 (void) task_resume(sig_task
);
1661 } else if (p
->p_stat
== SSTOP
)
1665 /* Default action - varies */
1666 if (mask
& stopsigmask
) {
1668 * These are the signals which by default
1671 * Don't clog system with children of init
1672 * stopped from the keyboard.
1674 if (!(prop
& SA_STOP
) && p
->p_pptr
== initproc
) {
1675 psignal_lock(p
, SIGKILL
, 0);
1676 uth
->uu_siglist
&= ~mask
;
1677 p
->p_siglist
&= ~mask
;
1683 * if task hasn't already been stopped by
1686 uth
->uu_siglist
&= ~mask
;
1687 p
->p_siglist
&= ~mask
;
1688 if (p
->p_stat
!= SSTOP
) {
1689 p
->p_xstat
= signum
;
1691 if ((p
->p_pptr
->p_flag
& P_NOCLDSTOP
) == 0) {
1692 struct proc
*pp
= p
->p_pptr
;
1694 pp
->si_pid
= p
->p_pid
;
1695 pp
->si_status
= p
->p_xstat
;
1696 pp
->si_code
= CLD_STOPPED
;
1697 pp
->si_uid
= p
->p_ucred
->cr_ruid
;
1698 psignal(pp
, SIGCHLD
);
1706 * Signals ignored by default have been dealt
1707 * with already, since their bits are on in
1713 * Kill signal always sets process running and
1717 * Process will be running after 'run'
1721 thread_abort(sig_thread_act
);
1727 * Let the process run. If it's sleeping on an
1728 * event, it remains so.
1730 if (p
->p_flag
& P_TTYSLEEP
) {
1731 p
->p_flag
&= ~P_TTYSLEEP
;
1732 wakeup(&p
->p_siglist
);
1734 p
->p_flag
|= P_CONTINUED
;
1735 (void) task_resume(sig_task
);
1737 uth
->uu_siglist
&= ~mask
;
1738 p
->p_siglist
&= ~mask
;
1745 * All other signals wake up the process, but don't
1748 if (p
->p_stat
== SSTOP
)
1756 * If we're being traced (possibly because someone attached us
1757 * while we were stopped), check for a signal from the debugger.
1759 if (p
->p_stat
== SSTOP
) {
1760 if ((p
->p_flag
& P_TRACED
) != 0 && p
->p_xstat
!= 0)
1761 uth
->uu_siglist
|= sigmask(p
->p_xstat
);
1764 * setrunnable(p) in BSD and
1765 * Wake up the thread if it is interruptible.
1768 thread_abort_safely(sig_thread_act
);
1774 thread_funnel_set(kernel_flock
, funnel_state
);
1778 /* psignal_lock(p, signum, withlock ) */
1780 psignal_uthread(thr_act
, signum
)
1786 register sig_t action
;
1787 thread_t sig_thread_act
;
1788 register task_t sig_task
;
1790 struct uthread
*uth
;
1794 p
= (struct proc
*)get_bsdtask_info(get_threadtask(thr_act
));
1795 if ((u_int
)signum
>= NSIG
|| signum
== 0)
1796 panic("Invalid signal number in psignal_uthread");
1797 mask
= sigmask(signum
);
1798 prop
= sigprop
[signum
];
1801 if(rdebug_proc
&& (p
== rdebug_proc
)) {
1804 #endif /* SIGNAL_DEBUG */
1807 * We will need the task pointer later. Grab it now to
1808 * check for a zombie process. Also don't send signals
1809 * to kernel internal tasks.
1811 if (((sig_task
= p
->task
) == TASK_NULL
) || is_kerneltask(sig_task
)) {
1815 sig_thread_act
= thr_act
;
1817 * do not send signals to the process that has the thread
1818 * doing a reboot(). Not doing so will mark that thread aborted
1819 * and can cause IO failures wich will cause data loss.
1821 if (ISSET(p
->p_flag
, P_REBOOT
)) {
1828 * Deliver the signal to the first thread in the task. This
1829 * allows single threaded applications which use signals to
1830 * be able to be linked with multithreaded libraries. We have
1831 * an implicit reference to the current thread, but need
1832 * an explicit one otherwise. The thread reference keeps
1833 * the corresponding task data structures around too. This
1834 * reference is released by thread_deallocate.
1837 if (((p
->p_flag
& P_TRACED
) == 0) && (p
->p_sigignore
& mask
))
1840 kret
= check_actforsig(sig_task
, sig_thread_act
, 1);
1842 if (kret
!= KERN_SUCCESS
) {
1848 uth
= get_bsdthread_info(sig_thread_act
);
1851 * If proc is traced, always give parent a chance.
1853 if (p
->p_flag
& P_TRACED
)
1857 * If the signal is being ignored,
1858 * then we forget about it immediately.
1859 * (Note: we don't set SIGCONT in p_sigignore,
1860 * and if it is set to SIG_IGN,
1861 * action will be SIG_DFL here.)
1863 if (p
->p_sigignore
& mask
)
1865 /* sigwait takes precedence */
1866 if (uth
->uu_sigwait
& mask
)
1867 action
= KERN_SIG_WAIT
;
1868 else if (uth
->uu_sigmask
& mask
)
1869 action
= KERN_SIG_HOLD
;
1870 else if (p
->p_sigcatch
& mask
)
1871 action
= KERN_SIG_CATCH
;
1876 if (p
->p_nice
> NZERO
&& action
== SIG_DFL
&& (prop
& SA_KILL
) &&
1877 (p
->p_flag
& P_TRACED
) == 0)
1880 if (prop
& SA_CONT
) {
1881 uth
->uu_siglist
&= ~stopsigmask
;
1882 p
->p_siglist
&= ~stopsigmask
;
1885 if (prop
& SA_STOP
) {
1887 * If sending a tty stop signal to a member of an orphaned
1888 * process group, discard the signal here if the action
1889 * is default; don't stop the process below if sleeping,
1890 * and don't clear any pending SIGCONT.
1892 if (prop
& SA_TTYSTOP
&& p
->p_pgrp
->pg_jobc
== 0 &&
1895 uth
->uu_siglist
&= ~contsigmask
;
1896 p
->p_siglist
&= ~contsigmask
;
1898 uth
->uu_siglist
|= mask
;
1899 p
->p_siglist
|= mask
; /* just for lame ones looking here */
1902 * Defer further processing for signals which are held,
1903 * except that stopped processes must be continued by SIGCONT.
1905 if (action
== KERN_SIG_HOLD
&& ((prop
& SA_CONT
) == 0 || p
->p_stat
!= SSTOP
))
1909 * SIGKILL priority twiddling moved here from above because
1910 * it needs sig_thread. Could merge it into large switch
1911 * below if we didn't care about priority for tracing
1912 * as SIGKILL's action is always SIG_DFL.
1914 if ((signum
== SIGKILL
) && (p
->p_nice
> NZERO
)) {
1919 * Process is traced - wake it up (if not already
1920 * stopped) so that it can discover the signal in
1921 * issig() and stop for the parent.
1923 if (p
->p_flag
& P_TRACED
) {
1924 if (p
->p_stat
!= SSTOP
)
1930 if (action
== KERN_SIG_WAIT
) {
1931 uth
->uu_sigwait
= mask
;
1932 uth
->uu_siglist
&= ~mask
;
1933 p
->p_siglist
&= ~mask
;
1934 wakeup(&uth
->uu_sigwait
);
1935 /* if it is SIGCONT resume whole process */
1936 if (prop
& SA_CONT
) {
1937 p
->p_flag
|= P_CONTINUED
;
1938 (void) task_resume(sig_task
);
1943 if (action
!= SIG_DFL
) {
1945 * User wants to catch the signal.
1946 * Wake up the thread, but don't un-suspend it
1947 * (except for SIGCONT).
1949 if (prop
& SA_CONT
) {
1950 p
->p_flag
|= P_CONTINUED
;
1951 (void) task_resume(sig_task
);
1955 /* Default action - varies */
1956 if (mask
& stopsigmask
) {
1958 * These are the signals which by default
1961 * Don't clog system with children of init
1962 * stopped from the keyboard.
1964 if (!(prop
& SA_STOP
) && p
->p_pptr
== initproc
) {
1965 psignal_lock(p
, SIGKILL
, 0);
1966 uth
->uu_siglist
&= ~mask
;
1967 p
->p_siglist
&= ~mask
;
1973 * if task hasn't already been stopped by
1976 uth
->uu_siglist
&= ~mask
;
1977 p
->p_siglist
&= ~mask
;
1978 if (p
->p_stat
!= SSTOP
) {
1979 p
->p_xstat
= signum
;
1980 if ((p
->p_pptr
->p_flag
& P_NOCLDSTOP
) == 0) {
1981 struct proc
*pp
= p
->p_pptr
;
1983 pp
->si_pid
= p
->p_pid
;
1984 pp
->si_status
= p
->p_xstat
;
1985 pp
->si_code
= CLD_STOPPED
;
1986 pp
->si_uid
= p
->p_ucred
->cr_ruid
;
1987 psignal(pp
, SIGCHLD
);
1996 * Signals ignored by default have been dealt
1997 * with already, since their bits are on in
2003 * Kill signal always sets process running and
2007 * Process will be running after 'run'
2011 thread_abort(sig_thread_act
);
2017 * Let the process run. If it's sleeping on an
2018 * event, it remains so.
2020 if (p
->p_flag
& P_TTYSLEEP
) {
2021 p
->p_flag
&= ~P_TTYSLEEP
;
2022 wakeup(&p
->p_siglist
);
2024 p
->p_flag
|= P_CONTINUED
;
2025 (void) task_resume(sig_task
);
2027 uth
->uu_siglist
&= ~mask
;
2028 p
->p_siglist
&= ~mask
;
2034 * All other signals wake up the process, but don't
2043 * If we're being traced (possibly because someone attached us
2044 * while we were stopped), check for a signal from the debugger.
2046 if (p
->p_stat
== SSTOP
) {
2047 if ((p
->p_flag
& P_TRACED
) != 0 && p
->p_xstat
!= 0) {
2048 uth
->uu_siglist
|= sigmask(p
->p_xstat
);
2049 p
->p_siglist
|= sigmask(p
->p_xstat
);
2053 * setrunnable(p) in BSD and
2054 * Wake up the thread if it is interruptible.
2057 thread_abort_safely(sig_thread_act
);
2066 sig_lock_to_exit(struct proc
*p
)
2068 thread_t self
= current_thread();
2070 p
->exit_thread
= self
;
2071 (void) task_suspend(p
->task
);
2075 sig_try_locked(struct proc
*p
)
2077 thread_t self
= current_thread();
2079 while (p
->sigwait
|| p
->exit_thread
) {
2080 if (p
->exit_thread
) {
2081 if (p
->exit_thread
!= self
) {
2083 * Already exiting - no signals.
2089 if(assert_wait_possible()) {
2090 assert_wait((caddr_t
)&p
->sigwait_thread
,
2091 (THREAD_INTERRUPTIBLE
));
2094 thread_block(THREAD_CONTINUE_NULL
);
2096 if (thread_should_abort(self
)) {
2098 * Terminate request - clean up.
2107 * If the current process has received a signal (should be caught or cause
2108 * termination, should interrupt current syscall), return the signal number.
2109 * Stop signals with default action are processed immediately, then cleared;
2110 * they aren't returned. This is checked after each entry to the system for
2111 * a syscall or trap (though this can usually be done without calling issignal
2112 * by checking the pending signal masks in the CURSIG macro.) The normal call
2115 * while (signum = CURSIG(curproc))
2120 register struct proc
*p
;
2122 register int signum
, mask
, prop
, sigbits
;
2124 struct uthread
* ut
;
2127 cur_act
= current_thread();
2130 if(rdebug_proc
&& (p
== rdebug_proc
)) {
2133 #endif /* SIGNAL_DEBUG */
2137 * Try to grab the signal lock.
2139 if (sig_try_locked(p
) <= 0) {
2144 ut
= get_bsdthread_info(cur_act
);
2146 sigbits
= ut
->uu_siglist
& ~ut
->uu_sigmask
;
2148 if (p
->p_flag
& P_PPWAIT
)
2149 sigbits
&= ~stopsigmask
;
2150 if (sigbits
== 0) { /* no signal to send */
2154 signum
= ffs((long)sigbits
);
2155 mask
= sigmask(signum
);
2156 prop
= sigprop
[signum
];
2159 * We should see pending but ignored signals
2160 * only if P_TRACED was on when they were posted.
2162 if (mask
& p
->p_sigignore
&& (p
->p_flag
& P_TRACED
) == 0) {
2163 ut
->uu_siglist
&= ~mask
; /* take the signal! */
2164 p
->p_siglist
&= ~mask
; /* take the signal! */
2167 if (p
->p_flag
& P_TRACED
&& (p
->p_flag
& P_PPWAIT
) == 0) {
2168 register task_t task
;
2170 * If traced, always stop, and stay
2171 * stopped until released by the debugger.
2173 /* ptrace debugging */
2174 p
->p_xstat
= signum
;
2176 if (p
->p_flag
& P_SIGEXC
) {
2178 p
->sigwait_thread
= cur_act
;
2180 p
->p_flag
&= ~(P_WAITED
|P_CONTINUED
);
2181 ut
->uu_siglist
&= ~mask
; /* clear the old signal */
2182 p
->p_siglist
&= ~mask
; /* clear the old signal */
2184 do_bsdexception(EXC_SOFTWARE
, EXC_SOFT_SIGNAL
, signum
);
2187 // panic("Unsupportef gdb option \n");;
2188 pp
->si_pid
= p
->p_pid
;
2189 pp
->si_status
= p
->p_xstat
;
2190 pp
->si_code
= CLD_TRAPPED
;
2191 pp
->si_uid
= p
->p_ucred
->cr_ruid
;
2192 psignal(pp
, SIGCHLD
);
2194 * XXX Have to really stop for debuggers;
2195 * XXX stop() doesn't do the right thing.
2196 * XXX Inline the task_suspend because we
2197 * XXX have to diddle Unix state in the
2203 p
->sigwait_thread
= cur_act
;
2205 p
->p_flag
&= ~(P_WAITED
|P_CONTINUED
);
2206 ut
->uu_siglist
&= ~mask
; /* clear the old signal */
2207 p
->p_siglist
&= ~mask
; /* clear the old signal */
2209 wakeup((caddr_t
)p
->p_pptr
);
2211 assert_wait((caddr_t
)&p
->sigwait
, (THREAD_INTERRUPTIBLE
));
2212 thread_block(THREAD_CONTINUE_NULL
);
2217 p
->sigwait_thread
= NULL
;
2218 wakeup((caddr_t
)&p
->sigwait_thread
);
2221 * This code is to detect when gdb is killed
2222 * even as the traced program is attached.
2223 * pgsignal would get the SIGKILL to traced program
2224 * That's what we are trying to see (I hope)
2226 if (ut
->uu_siglist
& sigmask(SIGKILL
)) {
2228 * Wait event may still be outstanding;
2229 * clear it, since sig_lock_to_exit will
2232 clear_wait(current_thread(), THREAD_INTERRUPTED
);
2233 sig_lock_to_exit(p
);
2235 * Since this thread will be resumed
2236 * to allow the current syscall to
2237 * be completed, must save u_qsave
2238 * before calling exit(). (Since exit()
2239 * calls closef() which can trash u_qsave.)
2242 exit1(p
,signum
, (int *)NULL
);
2247 * We may have to quit
2249 if (thread_should_abort(current_thread())) {
2254 * If parent wants us to take the signal,
2255 * then it will leave it in p->p_xstat;
2256 * otherwise we just look for signals again.
2258 signum
= p
->p_xstat
;
2262 * Put the new signal into p_siglist. If the
2263 * signal is being masked, look for other signals.
2265 mask
= sigmask(signum
);
2266 ut
->uu_siglist
|= mask
;
2267 p
->p_siglist
|= mask
; /* just for lame ones looking here */
2268 if (ut
->uu_sigmask
& mask
)
2273 * Decide whether the signal should be returned.
2274 * Return the signal's number, or fall through
2275 * to clear it from the pending mask.
2278 switch ((long)p
->p_sigacts
->ps_sigact
[signum
]) {
2282 * Don't take default actions on system processes.
2284 if (p
->p_pptr
->p_pid
== 0) {
2287 * Are you sure you want to ignore SIGSEGV
2290 printf("Process (pid %d) got signal %d\n",
2293 break; /* == ignore */
2297 * If there is a pending stop signal to process
2298 * with default action, stop here,
2299 * then clear the signal. However,
2300 * if process is member of an orphaned
2301 * process group, ignore tty stop signals.
2303 if (prop
& SA_STOP
) {
2304 if (p
->p_flag
& P_TRACED
||
2305 (p
->p_pgrp
->pg_jobc
== 0 &&
2307 break; /* == ignore */
2308 if (p
->p_stat
!= SSTOP
) {
2309 p
->p_xstat
= signum
;
2311 if ((p
->p_pptr
->p_flag
& P_NOCLDSTOP
) == 0) {
2313 pp
->si_pid
= p
->p_pid
;
2314 pp
->si_status
= p
->p_xstat
;
2315 pp
->si_code
= CLD_STOPPED
;
2316 pp
->si_uid
= p
->p_ucred
->cr_ruid
;
2317 psignal(pp
, SIGCHLD
);
2321 } else if (prop
& SA_IGNORE
) {
2323 * Except for SIGCONT, shouldn't get here.
2324 * Default action is to ignore; drop it.
2326 break; /* == ignore */
2328 ut
->uu_siglist
&= ~mask
; /* take the signal! */
2329 p
->p_siglist
&= ~mask
; /* take the signal! */
2337 * Masking above should prevent us ever trying
2338 * to take action on an ignored signal other
2339 * than SIGCONT, unless process is traced.
2341 if ((prop
& SA_CONT
) == 0 &&
2342 (p
->p_flag
& P_TRACED
) == 0)
2343 printf("issignal\n");
2344 break; /* == ignore */
2348 * This signal has an action, let
2349 * postsig() process it.
2351 ut
->uu_siglist
&= ~mask
; /* take the signal! */
2352 p
->p_siglist
&= ~mask
; /* take the signal! */
2356 ut
->uu_siglist
&= ~mask
; /* take the signal! */
2357 p
->p_siglist
&= ~mask
; /* take the signal! */
2362 /* called from _sleep */
2365 register struct proc
*p
;
2367 register int signum
, mask
, prop
, sigbits
;
2369 struct uthread
* ut
;
2373 cur_act
= current_thread();
2375 ut
= get_bsdthread_info(cur_act
);
2377 if (ut
->uu_siglist
== 0)
2380 if (((ut
->uu_siglist
& ~ut
->uu_sigmask
) == 0) && ((p
->p_flag
& P_TRACED
) == 0))
2383 sigbits
= ut
->uu_siglist
& ~ut
->uu_sigmask
;
2386 if (p
->p_flag
& P_PPWAIT
)
2387 sigbits
&= ~stopsigmask
;
2388 if (sigbits
== 0) { /* no signal to send */
2392 signum
= ffs((long)sigbits
);
2393 mask
= sigmask(signum
);
2394 prop
= sigprop
[signum
];
2397 * We should see pending but ignored signals
2398 * only if P_TRACED was on when they were posted.
2400 if (mask
& p
->p_sigignore
&& (p
->p_flag
& P_TRACED
) == 0) {
2403 if (p
->p_flag
& P_TRACED
&& (p
->p_flag
& P_PPWAIT
) == 0) {
2405 * Put the new signal into p_siglist. If the
2406 * signal is being masked, look for other signals.
2408 mask
= sigmask(signum
);
2409 if (ut
->uu_sigmask
& mask
)
2415 * Decide whether the signal should be returned.
2416 * Return the signal's number, or fall through
2417 * to clear it from the pending mask.
2420 switch ((long)p
->p_sigacts
->ps_sigact
[signum
]) {
2424 * Don't take default actions on system processes.
2426 if (p
->p_pptr
->p_pid
== 0) {
2429 * Are you sure you want to ignore SIGSEGV
2432 printf("Process (pid %d) got signal %d\n",
2435 break; /* == ignore */
2439 * If there is a pending stop signal to process
2440 * with default action, stop here,
2441 * then clear the signal. However,
2442 * if process is member of an orphaned
2443 * process group, ignore tty stop signals.
2445 if (prop
& SA_STOP
) {
2446 if (p
->p_flag
& P_TRACED
||
2447 (p
->p_pgrp
->pg_jobc
== 0 &&
2449 break; /* == ignore */
2452 } else if (prop
& SA_IGNORE
) {
2454 * Except for SIGCONT, shouldn't get here.
2455 * Default action is to ignore; drop it.
2457 break; /* == ignore */
2465 * Masking above should prevent us ever trying
2466 * to take action on an ignored signal other
2467 * than SIGCONT, unless process is traced.
2469 if ((prop
& SA_CONT
) == 0 &&
2470 (p
->p_flag
& P_TRACED
) == 0)
2471 printf("issignal\n");
2472 break; /* == ignore */
2476 * This signal has an action, let
2477 * postsig() process it.
2481 sigbits
&= ~mask
; /* take the signal! */
2487 * Put the argument process into the stopped state and notify the parent
2488 * via wakeup. Signals are handled elsewhere. The process must not be
2493 register struct proc
*p
;
2496 p
->p_flag
&= ~(P_WAITED
|P_CONTINUED
);
2497 if (p
->p_pptr
->p_stat
!= SSTOP
)
2498 wakeup((caddr_t
)p
->p_pptr
);
2499 (void) task_suspend(p
->task
); /*XXX*/
2503 * Take the action for the specified signal
2504 * from the current set of pending signals.
2509 struct proc
*p
= current_proc();
2510 struct sigacts
*ps
= p
->p_sigacts
;
2511 user_addr_t catcher
;
2513 int mask
, returnmask
;
2514 struct uthread
* ut
;
2520 * This must be called on master cpu
2522 if (cpu_number() != master_cpu
)
2523 panic("psig not on master");
2528 * Try to grab the signal lock.
2530 if (sig_try_locked(p
) <= 0) {
2535 ut
= (struct uthread
*)get_bsdthread_info(current_thread());
2536 mask
= sigmask(signum
);
2537 ut
->uu_siglist
&= ~mask
;
2538 p
->p_siglist
&= ~mask
;
2539 catcher
= ps
->ps_sigact
[signum
];
2541 //LP64: catcher argument is a 64 bit user space handler address
2542 if (KTRPOINT(p
, KTR_PSIG
))
2543 ktrpsig(p
->p_tracep
,
2544 signum
, CAST_DOWN(void *,catcher
), ut
->uu_flag
& UT_SAS_OLDMASK
?
2545 &ut
->uu_oldmask
: &ut
->uu_sigmask
, 0);
2547 if (catcher
== SIG_DFL
) {
2549 * Default catcher, where the default is to kill
2550 * the process. (Other cases were ignored above.)
2552 /* called with signal_lock() held */
2553 sigexit_locked(p
, signum
);
2558 * If we get here, the signal must be caught.
2561 if (catcher
== SIG_IGN
|| (ut
->uu_sigmask
& mask
))
2563 "postsig: processing masked or ignored signal\n");
2566 * Set the new mask value and also defer further
2567 * occurences of this signal.
2569 * Special case: user has done a sigpause. Here the
2570 * current mask is not of interest, but rather the
2571 * mask from before the sigpause is what we want
2572 * restored after the signal processing is completed.
2574 if (ut
->uu_flag
& UT_SAS_OLDMASK
) {
2575 returnmask
= ut
->uu_oldmask
;
2576 ut
->uu_flag
&= ~UT_SAS_OLDMASK
;
2579 returnmask
= ut
->uu_sigmask
;
2580 ut
->uu_sigmask
|= ps
->ps_catchmask
[signum
];
2581 if ((ps
->ps_signodefer
& mask
) == 0)
2582 ut
->uu_sigmask
|= mask
;
2583 if ((signum
!= SIGILL
) && (signum
!= SIGTRAP
) && (ps
->ps_sigreset
& mask
)) {
2584 if ((signum
!= SIGCONT
) && (sigprop
[signum
] & SA_IGNORE
))
2585 p
->p_sigignore
|= mask
;
2586 ps
->ps_sigact
[signum
] = SIG_DFL
;
2587 ps
->ps_siginfo
&= ~mask
;
2588 ps
->ps_signodefer
&= ~mask
;
2591 /* Needs to disable to run in user mode */
2592 if (signum
== SIGFPE
) {
2593 thread_enable_fpe(current_thread(), 0);
2595 #endif /* __ppc__ */
2597 if (ps
->ps_sig
!= signum
) {
2603 p
->p_stats
->p_ru
.ru_nsignals
++;
2604 sendsig(p
, catcher
, signum
, returnmask
, code
);
2610 * Force the current process to exit with the specified signal, dumping core
2611 * if appropriate. We bypass the normal tests for masked and caught signals,
2612 * allowing unrecoverable failures to terminate the process without changing
2613 * signal state. Mark the accounting record with the signal termination.
2614 * If dumping core, save the signal number for the debugger. Calls exit and
2617 /* called with signal lock */
2619 sigexit_locked(p
, signum
)
2620 register struct proc
*p
;
2624 sig_lock_to_exit(p
);
2625 p
->p_acflag
|= AXSIG
;
2626 if (sigprop
[signum
] & SA_CORE
) {
2627 p
->p_sigacts
->ps_sig
= signum
;
2629 if (coredump(p
) == 0)
2630 signum
|= WCOREFLAG
;
2634 exit1(p
, W_EXITCODE(0, signum
), (int *)NULL
);
2640 filt_sigattach(struct knote
*kn
)
2642 struct proc
*p
= current_proc();
2644 kn
->kn_ptr
.p_proc
= p
;
2645 kn
->kn_flags
|= EV_CLEAR
; /* automatically set */
2647 /* XXX lock the proc here while adding to the list? */
2648 KNOTE_ATTACH(&p
->p_klist
, kn
);
2654 filt_sigdetach(struct knote
*kn
)
2656 struct proc
*p
= kn
->kn_ptr
.p_proc
;
2658 KNOTE_DETACH(&p
->p_klist
, kn
);
2662 * signal knotes are shared with proc knotes, so we apply a mask to
2663 * the hint in order to differentiate them from process hints. This
2664 * could be avoided by using a signal-specific knote list, but probably
2665 * isn't worth the trouble.
2668 filt_signal(struct knote
*kn
, long hint
)
2671 if (hint
& NOTE_SIGNAL
) {
2672 hint
&= ~NOTE_SIGNAL
;
2674 if (kn
->kn_id
== (unsigned int)hint
)
2677 return (kn
->kn_data
!= 0);
2682 bsd_ast(thread_t thr_act
)
2684 struct proc
*p
= current_proc();
2685 struct uthread
*ut
= get_bsdthread_info(thr_act
);
2688 boolean_t funnel_state
;
2689 static int bsd_init_done
= 0;
2694 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
2696 if ((p
->p_flag
& P_OWEUPC
) && (p
->p_flag
& P_PROFIL
)) {
2697 pc
= get_useraddr();
2698 addupc_task(p
, pc
, 1);
2699 p
->p_flag
&= ~P_OWEUPC
;
2702 if (CHECK_SIGNALS(p
, current_thread(), ut
)) {
2703 while ( (signum
= issignal(p
)) )
2706 if (!bsd_init_done
) {
2711 (void) thread_funnel_set(kernel_flock
, FALSE
);
2715 * Follwing routines are called using callout from bsd_hardclock
2716 * so that psignals are called in a thread context and are funneled
2719 psignal_vtalarm(struct proc
*p
)
2721 boolean_t funnel_state
;
2725 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
2726 psignal_lock(p
, SIGVTALRM
, 1);
2727 (void) thread_funnel_set(kernel_flock
, FALSE
);
2731 psignal_xcpu(struct proc
*p
)
2733 boolean_t funnel_state
;
2737 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
2738 psignal_lock(p
, SIGXCPU
, 1);
2739 (void) thread_funnel_set(kernel_flock
, FALSE
);
2743 psignal_sigprof(struct proc
*p
)
2745 boolean_t funnel_state
;
2749 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
2750 psignal_lock(p
, SIGPROF
, 1);
2751 (void) thread_funnel_set(kernel_flock
, FALSE
);
2754 /* ptrace set runnalbe */
2756 pt_setrunnable(struct proc
*p
)
2762 if (p
->p_flag
& P_TRACED
) {
2765 wakeup((caddr_t
)&(p
->sigwait
));
2778 exception_data_type_t codes
[EXCEPTION_CODE_MAX
];
2782 return(bsd_exception(exc
, codes
, 2));
2786 proc_pendingsignals(struct proc
*p
, sigset_t mask
)
2788 struct uthread
* uth
;
2793 /* If the process is in proc exit return no signal info */
2794 if (p
->p_lflag
& P_LPEXIT
)
2797 /* duplicate the signal lock code to enable recursion; as exit
2798 * holds the lock too long. All this code is being reworked
2799 * this is just a workaround for regressions till new code
2803 error
= lockmgr((struct lock__bsd__
*)&p
->signal_lock
[0], (LK_EXCLUSIVE
| LK_CANRECURSE
), 0, (struct proc
*)0);
2807 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
2809 uth
= (struct uthread
*)get_bsdthread_info(th
);
2811 bits
= (((uth
->uu_siglist
& ~uth
->uu_sigmask
) & ~p
->p_sigignore
) & mask
);
2817 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
2818 bits
|= (((uth
->uu_siglist
& ~uth
->uu_sigmask
) & ~p
->p_sigignore
) & mask
);
2826 thread_issignal(proc_t p
, thread_t th
, sigset_t mask
)
2828 struct uthread
* uth
;
2832 uth
= (struct uthread
*)get_bsdthread_info(th
);
2834 bits
= (((uth
->uu_siglist
& ~uth
->uu_sigmask
) & ~p
->p_sigignore
) & mask
);