2 * Copyright (c) 2000-2001 Apple Computer, Inc. All rights reserved.
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
23 /* Copyright (c) 1995-1998 Apple Computer, Inc. All Rights Reserved */
25 * Copyright (c) 1982, 1986, 1989, 1991, 1993
26 * The Regents of the University of California. All rights reserved.
27 * (c) UNIX System Laboratories, Inc.
28 * All or some portions of this file are derived from material licensed
29 * to the University of California by American Telephone and Telegraph
30 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
31 * the permission of UNIX System Laboratories, Inc.
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. All advertising materials mentioning features or use of this software
42 * must display the following acknowledgement:
43 * This product includes software developed by the University of
44 * California, Berkeley and its contributors.
45 * 4. Neither the name of the University nor the names of its contributors
46 * may be used to endorse or promote products derived from this software
47 * without specific prior written permission.
49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * @(#)kern_sig.c 8.7 (Berkeley) 4/18/94
64 #define SIGPROP /* include signal properties table */
65 #include <sys/param.h>
66 #include <sys/resourcevar.h>
67 #include <sys/proc_internal.h>
68 #include <sys/kauth.h>
69 #include <sys/systm.h>
70 #include <sys/timeb.h>
71 #include <sys/times.h>
73 #include <sys/file_internal.h>
74 #include <sys/kernel.h>
76 #include <sys/signalvar.h>
78 #include <sys/ktrace.h>
80 #include <sys/syslog.h>
83 #include <sys/kdebug.h>
85 #include <sys/mount.h>
86 #include <sys/sysproto.h>
88 #include <bsm/audit_kernel.h>
90 #include <machine/spl.h>
92 #include <kern/cpu_number.h>
95 #include <sys/user.h> /* for coredump */
96 #include <kern/ast.h> /* for APC support */
97 #include <kern/lock.h>
98 #include <kern/task.h> /* extern void *get_bsdtask_info(task_t); */
99 #include <kern/thread.h>
100 #include <kern/sched_prim.h>
101 #include <kern/thread_call.h>
102 #include <mach/exception.h>
103 #include <mach/task.h>
104 #include <mach/thread_act.h>
107 * Missing prototypes that Mach should export
111 extern int thread_enable_fpe(thread_t act
, int onoff
);
112 extern void unix_syscall_return(int error
);
113 extern thread_t
port_name_to_thread(mach_port_name_t port_name
);
114 extern kern_return_t
check_actforsig(task_t task
, thread_t thread
, int setast
);
115 extern kern_return_t
get_signalact(task_t
, thread_t
*, int);
116 extern boolean_t
thread_should_abort(thread_t
);
117 extern unsigned int get_useraddr(void);
123 extern void doexception(int exc
, int code
, int sub
);
125 void stop(struct proc
*p
);
126 int cansignal(struct proc
*, kauth_cred_t
, struct proc
*, int);
127 int killpg1(struct proc
*, int, int, int);
128 void sigexit_locked(struct proc
*, int);
129 int setsigvec(struct proc
*, int, struct __user_sigaction
*);
130 void exit1(struct proc
*, int, int *);
131 void psignal_uthread(thread_t
, int);
132 kern_return_t
do_bsdexception(int, int, int);
133 void __posix_sem_syscall_return(kern_return_t
);
135 /* implementations in osfmk/kern/sync_sema.c. We do not want port.h in this scope, so void * them */
136 kern_return_t
semaphore_timedwait_signal_trap_internal(void *, void *,time_t, int32_t, void (*)(int));
137 kern_return_t
semaphore_timedwait_trap_internal(void *, time_t, int32_t, void (*)(int));
138 kern_return_t
semaphore_wait_signal_trap_internal(void *, void *, void (*)(int));
139 kern_return_t
semaphore_wait_trap_internal(void *, void (*)(int));
141 static int filt_sigattach(struct knote
*kn
);
142 static void filt_sigdetach(struct knote
*kn
);
143 static int filt_signal(struct knote
*kn
, long hint
);
145 struct filterops sig_filtops
=
146 { 0, filt_sigattach
, filt_sigdetach
, filt_signal
};
150 * NOTE: Source and target may *NOT* overlap! (target is smaller)
153 sigaltstack_64to32(struct user_sigaltstack
*in
, struct sigaltstack
*out
)
155 out
->ss_sp
= CAST_DOWN(void *,in
->ss_sp
);
156 out
->ss_size
= in
->ss_size
;
157 out
->ss_flags
= in
->ss_flags
;
161 * NOTE: Source and target may are permitted to overlap! (source is smaller);
162 * this works because we copy fields in order from the end of the struct to
166 sigaltstack_32to64(struct sigaltstack
*in
, struct user_sigaltstack
*out
)
168 out
->ss_flags
= in
->ss_flags
;
169 out
->ss_size
= in
->ss_size
;
170 out
->ss_sp
= CAST_USER_ADDR_T(in
->ss_sp
);
174 sigaction_64to32(struct user_sigaction
*in
, struct sigaction
*out
)
176 /* This assumes 32 bit __sa_handler is of type sig_t */
177 out
->__sigaction_u
.__sa_handler
= CAST_DOWN(sig_t
,in
->__sigaction_u
.__sa_handler
);
178 out
->sa_mask
= in
->sa_mask
;
179 out
->sa_flags
= in
->sa_flags
;
183 __sigaction_32to64(struct __sigaction
*in
, struct __user_sigaction
*out
)
185 out
->__sigaction_u
.__sa_handler
= CAST_USER_ADDR_T(in
->__sigaction_u
.__sa_handler
);
186 out
->sa_tramp
= CAST_USER_ADDR_T(in
->sa_tramp
);
187 out
->sa_mask
= in
->sa_mask
;
188 out
->sa_flags
= in
->sa_flags
;
193 void ram_printf(int);
195 unsigned int rdebug_proc
=0;
202 #endif /* SIGNAL_DEBUG */
205 signal_lock(struct proc
*p
)
212 int register sp
, *fp
, numsaved
;
214 __asm__
volatile("mr %0,r1" : "=r" (sp
));
216 fp
= (int *)*((int *)sp
);
217 for (numsaved
= 0; numsaved
< 3; numsaved
++) {
218 p
->lockpc
[numsaved
] = fp
[2];
225 #endif /* SIGNAL_DEBUG */
226 #endif /* DIAGNOSTIC */
229 error
= lockmgr((struct lock__bsd__
*)&p
->signal_lock
[0], LK_EXCLUSIVE
, 0, (struct proc
*)0);
236 signal_unlock(struct proc
*p
)
242 int register sp
, *fp
, numsaved
;
244 __asm__
volatile("mr %0,r1" : "=r" (sp
));
246 fp
= (int *)*((int *)sp
);
247 for (numsaved
= 0; numsaved
< 3; numsaved
++) {
248 p
->unlockpc
[numsaved
] = fp
[2];
255 #endif /* SIGNAL_DEBUG */
256 #endif /* DIAGNOSTIC */
258 /* TBD: check p last arg */
259 return(lockmgr((struct lock__bsd__
*)&p
->signal_lock
[0], LK_RELEASE
, (simple_lock_t
)0, (struct proc
*)0));
263 signal_setast(sig_actthread
)
264 thread_t sig_actthread
;
266 act_set_astbsd(sig_actthread
);
270 * Can process p, with ucred uc, send the signal signum to process q?
273 cansignal(p
, uc
, q
, signum
)
279 /* you can signal yourself */
283 if (!suser(uc
, NULL
))
284 return (1); /* root can always signal */
286 if (signum
== SIGCONT
&& q
->p_session
== p
->p_session
)
287 return (1); /* SIGCONT in session */
290 * Using kill(), only certain signals can be sent to setugid
293 if (q
->p_flag
& P_SUGID
) {
306 if (uc
->cr_ruid
== q
->p_ucred
->cr_ruid
||
307 kauth_cred_getuid(uc
) == q
->p_ucred
->cr_ruid
||
308 uc
->cr_ruid
== kauth_cred_getuid(q
->p_ucred
) ||
309 kauth_cred_getuid(uc
) == kauth_cred_getuid(q
->p_ucred
))
316 * because the P_SUGID test exists, this has extra tests which
319 if (uc
->cr_ruid
== q
->p_ucred
->cr_ruid
||
320 uc
->cr_ruid
== q
->p_ucred
->cr_svuid
||
321 kauth_cred_getuid(uc
) == q
->p_ucred
->cr_ruid
||
322 kauth_cred_getuid(uc
) == q
->p_ucred
->cr_svuid
||
323 uc
->cr_ruid
== kauth_cred_getuid(q
->p_ucred
) ||
324 kauth_cred_getuid(uc
) == kauth_cred_getuid(q
->p_ucred
))
332 sigaction(struct proc
*p
, register struct sigaction_args
*uap
, __unused register_t
*retval
)
334 struct user_sigaction vec
;
335 struct __user_sigaction __vec
;
337 struct user_sigaction
*sa
= &vec
;
338 register struct sigacts
*ps
= p
->p_sigacts
;
343 signum
= uap
->signum
;
344 if (signum
<= 0 || signum
>= NSIG
||
345 signum
== SIGKILL
|| signum
== SIGSTOP
)
349 sa
->sa_handler
= ps
->ps_sigact
[signum
];
350 sa
->sa_mask
= ps
->ps_catchmask
[signum
];
351 bit
= sigmask(signum
);
353 if ((ps
->ps_sigonstack
& bit
) != 0)
354 sa
->sa_flags
|= SA_ONSTACK
;
355 if ((ps
->ps_sigintr
& bit
) == 0)
356 sa
->sa_flags
|= SA_RESTART
;
357 if (ps
->ps_siginfo
& bit
)
358 sa
->sa_flags
|= SA_SIGINFO
;
359 if (ps
->ps_signodefer
& bit
)
360 sa
->sa_flags
|= SA_NODEFER
;
361 if (ps
->ps_64regset
& bit
)
362 sa
->sa_flags
|= SA_64REGSET
;
363 if ((signum
== SIGCHLD
) && (p
->p_flag
& P_NOCLDSTOP
))
364 sa
->sa_flags
|= SA_NOCLDSTOP
;
365 if ((signum
== SIGCHLD
) && (p
->p_flag
& P_NOCLDWAIT
))
366 sa
->sa_flags
|= SA_NOCLDWAIT
;
368 if (IS_64BIT_PROCESS(p
)) {
369 error
= copyout(sa
, uap
->osa
, sizeof(struct user_sigaction
));
371 struct sigaction vec32
;
372 sigaction_64to32(sa
, &vec32
);
373 error
= copyout(&vec32
, uap
->osa
, sizeof(struct sigaction
));
379 if (IS_64BIT_PROCESS(p
)) {
380 error
= copyin(uap
->nsa
, &__vec
, sizeof(struct __user_sigaction
));
382 struct __sigaction __vec32
;
383 error
= copyin(uap
->nsa
, &__vec32
, sizeof(struct __sigaction
));
384 __sigaction_32to64(&__vec32
, &__vec
);
388 error
= setsigvec(p
, signum
, &__vec
);
393 /* Routines to manipulate bits on all threads */
395 clear_procsiglist(struct proc
*p
, int bit
)
397 struct uthread
* uth
;
402 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
403 thact
= p
->p_vforkact
;
404 uth
= (struct uthread
*)get_bsdthread_info(thact
);
406 uth
->uu_siglist
&= ~bit
;
408 p
->p_siglist
&= ~bit
;
413 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
414 uth
->uu_siglist
&= ~bit
;
416 p
->p_siglist
&= ~bit
;
423 unblock_procsigmask(struct proc
*p
, int bit
)
425 struct uthread
* uth
;
429 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
430 thact
= p
->p_vforkact
;
431 uth
= (struct uthread
*)get_bsdthread_info(thact
);
433 uth
->uu_sigmask
&= ~bit
;
435 p
->p_sigmask
&= ~bit
;
439 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
440 uth
->uu_sigmask
&= ~bit
;
442 p
->p_sigmask
&= ~bit
;
449 block_procsigmask(struct proc
*p
, int bit
)
451 struct uthread
* uth
;
455 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
456 thact
= p
->p_vforkact
;
457 uth
= (struct uthread
*)get_bsdthread_info(thact
);
459 uth
->uu_sigmask
|= bit
;
465 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
466 uth
->uu_sigmask
|= bit
;
474 set_procsigmask(struct proc
*p
, int bit
)
476 struct uthread
* uth
;
480 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
481 thact
= p
->p_vforkact
;
482 uth
= (struct uthread
*)get_bsdthread_info(thact
);
484 uth
->uu_sigmask
= bit
;
490 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
491 uth
->uu_sigmask
= bit
;
498 /* XXX should be static? */
500 setsigvec(struct proc
*p
, int signum
, struct __user_sigaction
*sa
)
502 register struct sigacts
*ps
= p
->p_sigacts
;
505 if ((signum
== SIGKILL
|| signum
== SIGSTOP
) &&
506 sa
->sa_handler
!= SIG_DFL
)
508 bit
= sigmask(signum
);
510 * Change setting atomically.
512 ps
->ps_sigact
[signum
] = sa
->sa_handler
;
513 ps
->ps_trampact
[signum
] = sa
->sa_tramp
;
514 ps
->ps_catchmask
[signum
] = sa
->sa_mask
&~ sigcantmask
;
515 if (sa
->sa_flags
& SA_SIGINFO
)
516 ps
->ps_siginfo
|= bit
;
518 ps
->ps_siginfo
&= ~bit
;
519 if (sa
->sa_flags
& SA_64REGSET
)
520 ps
->ps_64regset
|= bit
;
522 ps
->ps_64regset
&= ~bit
;
523 if ((sa
->sa_flags
& SA_RESTART
) == 0)
524 ps
->ps_sigintr
|= bit
;
526 ps
->ps_sigintr
&= ~bit
;
527 if (sa
->sa_flags
& SA_ONSTACK
)
528 ps
->ps_sigonstack
|= bit
;
530 ps
->ps_sigonstack
&= ~bit
;
531 if (sa
->sa_flags
& SA_USERTRAMP
)
532 ps
->ps_usertramp
|= bit
;
534 ps
->ps_usertramp
&= ~bit
;
535 if (sa
->sa_flags
& SA_RESETHAND
)
536 ps
->ps_sigreset
|= bit
;
538 ps
->ps_sigreset
&= ~bit
;
539 if (sa
->sa_flags
& SA_NODEFER
)
540 ps
->ps_signodefer
|= bit
;
542 ps
->ps_signodefer
&= ~bit
;
543 if (signum
== SIGCHLD
) {
544 if (sa
->sa_flags
& SA_NOCLDSTOP
)
545 p
->p_flag
|= P_NOCLDSTOP
;
547 p
->p_flag
&= ~P_NOCLDSTOP
;
548 if ((sa
->sa_flags
& SA_NOCLDWAIT
) || (sa
->sa_handler
== SIG_IGN
))
549 p
->p_flag
|= P_NOCLDWAIT
;
551 p
->p_flag
&= ~P_NOCLDWAIT
;
555 if (signum
== SIGFPE
) {
556 if (sa
->sa_handler
== SIG_DFL
|| sa
->sa_handler
== SIG_IGN
)
557 thread_enable_fpe(current_thread(), 0);
559 thread_enable_fpe(current_thread(), 1);
563 * Set bit in p_sigignore for signals that are set to SIG_IGN,
564 * and for signals set to SIG_DFL where the default is to ignore.
565 * However, don't put SIGCONT in p_sigignore,
566 * as we have to restart the process.
568 if (sa
->sa_handler
== SIG_IGN
||
569 (sigprop
[signum
] & SA_IGNORE
&& sa
->sa_handler
== SIG_DFL
)) {
571 clear_procsiglist(p
, bit
);
572 if (signum
!= SIGCONT
)
573 p
->p_sigignore
|= bit
; /* easier in psignal */
574 p
->p_sigcatch
&= ~bit
;
576 p
->p_sigignore
&= ~bit
;
577 if (sa
->sa_handler
== SIG_DFL
)
578 p
->p_sigcatch
&= ~bit
;
580 p
->p_sigcatch
|= bit
;
586 * Initialize signal state for process 0;
587 * set to ignore signals that are ignored by default.
595 for (i
= 0; i
< NSIG
; i
++)
596 if (sigprop
[i
] & SA_IGNORE
&& i
!= SIGCONT
)
597 p
->p_sigignore
|= sigmask(i
);
601 * Reset signals for an exec of the specified process.
605 register struct proc
*p
;
606 register thread_t thr_act
;
608 register struct sigacts
*ps
= p
->p_sigacts
;
609 register int nc
, mask
;
613 * Reset caught signals. Held signals remain held
614 * through p_sigmask (unless they were caught,
615 * and are now ignored by default).
617 while (p
->p_sigcatch
) {
618 nc
= ffs((long)p
->p_sigcatch
);
620 p
->p_sigcatch
&= ~mask
;
621 if (sigprop
[nc
] & SA_IGNORE
) {
623 p
->p_sigignore
|= mask
;
625 ut
= (struct uthread
*)get_bsdthread_info(thr_act
);
626 ut
->uu_siglist
&= ~mask
;
627 p
->p_siglist
&= ~mask
;
629 clear_procsiglist(p
, mask
);
631 ps
->ps_sigact
[nc
] = SIG_DFL
;
634 * Reset stack state to the user stack.
635 * Clear set of signals caught on the signal stack.
637 ps
->ps_sigstk
.ss_flags
= SA_DISABLE
;
638 ps
->ps_sigstk
.ss_size
= 0;
639 ps
->ps_sigstk
.ss_sp
= USER_ADDR_NULL
;
644 * Manipulate signal mask.
645 * Note that we receive new mask, not pointer,
646 * and return old mask as return value;
647 * the library stub does the rest.
650 sigprocmask(register struct proc
*p
, struct sigprocmask_args
*uap
, __unused register_t
*retval
)
653 sigset_t oldmask
, nmask
;
654 user_addr_t omask
= uap
->omask
;
657 ut
= (struct uthread
*)get_bsdthread_info(current_thread());
658 oldmask
= ut
->uu_sigmask
;
660 if (uap
->mask
== USER_ADDR_NULL
) {
661 /* just want old mask */
664 error
= copyin(uap
->mask
, &nmask
, sizeof(sigset_t
));
670 block_procsigmask(p
, (nmask
& ~sigcantmask
));
671 signal_setast(current_thread());
675 unblock_procsigmask(p
, (nmask
& ~sigcantmask
));
676 signal_setast(current_thread());
680 set_procsigmask(p
, (nmask
& ~sigcantmask
));
681 signal_setast(current_thread());
689 if (!error
&& omask
!= USER_ADDR_NULL
)
690 copyout(&oldmask
, omask
, sizeof(sigset_t
));
695 sigpending(__unused
struct proc
*p
, register struct sigpending_args
*uap
, __unused register_t
*retval
)
700 ut
= (struct uthread
*)get_bsdthread_info(current_thread());
701 pendlist
= ut
->uu_siglist
;
704 copyout(&pendlist
, uap
->osv
, sizeof(sigset_t
));
710 * Suspend process until signal, providing mask to be set
711 * in the meantime. Note nonstandard calling convention:
712 * libc stub passes mask, not pointer, to save a copyin.
716 sigcontinue(__unused
int error
)
718 // struct uthread *ut = get_bsdthread_info(current_thread());
719 unix_syscall_return(EINTR
);
723 sigsuspend(register struct proc
*p
, struct sigsuspend_args
*uap
, __unused register_t
*retval
)
727 ut
= (struct uthread
*)get_bsdthread_info(current_thread());
730 * When returning from sigpause, we want
731 * the old mask to be restored after the
732 * signal handler has finished. Thus, we
733 * save it here and mark the sigacts structure
736 ut
->uu_oldmask
= ut
->uu_sigmask
;
737 ut
->uu_flag
|= UT_SAS_OLDMASK
;
738 ut
->uu_sigmask
= (uap
->mask
& ~sigcantmask
);
739 (void) tsleep0((caddr_t
) p
, PPAUSE
|PCATCH
, "pause", 0, sigcontinue
);
740 /* always return EINTR rather than ERESTART... */
746 __disable_threadsignal(struct proc
*p
,
747 __unused
register struct __disable_threadsignal_args
*uap
,
748 __unused register_t
*retval
)
752 uth
= (struct uthread
*)get_bsdthread_info(current_thread());
754 /* No longer valid to have any signal delivered */
756 uth
->uu_flag
|= UT_NO_SIGMASK
;
765 __pthread_markcancel(p
, uap
, retval
)
767 register struct __pthread_markcancel_args
*uap
;
770 thread_act_t target_act
;
774 target_act
= (thread_act_t
)port_name_to_thread(uap
->thread_port
);
776 if (target_act
== THR_ACT_NULL
)
779 uth
= (struct uthread
*)get_bsdthread_info(target_act
);
781 /* if the thread is in vfork do not cancel */
782 if ((uth
->uu_flag
& (P_VFORK
| UT_CANCEL
| UT_CANCELED
)) == 0) {
783 uth
->uu_flag
|= (UT_CANCEL
| UT_NO_SIGMASK
);
784 if (((uth
->uu_flag
& UT_NOTCANCELPT
) == 0)
785 && ((uth
->uu_flag
& UT_CANCELDISABLE
) == 0))
786 thread_abort_safely(target_act
);
789 thread_deallocate(target_act
);
793 /* if action =0 ; return the cancellation state ,
794 * if marked for cancellation, make the thread canceled
795 * if action = 1 ; Enable the cancel handling
796 * if action = 2; Disable the cancel handling
799 __pthread_canceled(p
, uap
, retval
)
801 register struct __pthread_canceled_args
*uap
;
804 thread_act_t thr_act
;
806 int action
= uap
->action
;
808 thr_act
= current_act();
809 uth
= (struct uthread
*)get_bsdthread_info(thr_act
);
813 uth
->uu_flag
&= ~UT_CANCELDISABLE
;
816 uth
->uu_flag
|= UT_CANCELDISABLE
;
820 /* if the thread is in vfork do not cancel */
821 if((uth
->uu_flag
& ( UT_CANCELDISABLE
| UT_CANCEL
| UT_CANCELED
)) == UT_CANCEL
) {
822 uth
->uu_flag
&= ~UT_CANCEL
;
823 uth
->uu_flag
|= (UT_CANCELED
| UT_NO_SIGMASK
);
832 __posix_sem_syscall_return(kern_return_t kern_result
)
836 if (kern_result
== KERN_SUCCESS
)
838 else if (kern_result
== KERN_ABORTED
)
840 else if (kern_result
== KERN_OPERATION_TIMED_OUT
)
844 unix_syscall_return(error
);
845 /* does not return */
850 __semwait_signal(p
, uap
, retval
)
852 register struct __semwait_signal_args
*uap
;
856 kern_return_t kern_result
;
857 mach_timespec_t then
;
863 then
.tv_sec
= uap
->tv_sec
;
864 then
.tv_nsec
= uap
->tv_nsec
;
867 then
.tv_sec
= uap
->tv_sec
- now
.tv_sec
;
868 then
.tv_nsec
= uap
->tv_nsec
- now
.tv_nsec
;
869 if (then
.tv_nsec
< 0) {
870 then
.tv_nsec
+= NSEC_PER_SEC
;
875 if (uap
->mutex_sem
== (void *)NULL
)
876 kern_result
= semaphore_timedwait_trap_internal(uap
->cond_sem
, then
.tv_sec
, then
.tv_nsec
, __posix_sem_syscall_return
);
878 kern_result
= semaphore_timedwait_signal_trap_internal(uap
->cond_sem
, uap
->mutex_sem
, then
.tv_sec
, then
.tv_nsec
, __posix_sem_syscall_return
);
882 if (uap
->mutex_sem
== (void *)NULL
)
883 kern_result
= semaphore_wait_trap_internal(uap
->cond_sem
, __posix_sem_syscall_return
);
886 kern_result
= semaphore_wait_signal_trap_internal(uap
->cond_sem
, uap
->mutex_sem
, __posix_sem_syscall_return
);
890 if (kern_result
== KERN_SUCCESS
)
892 else if (kern_result
== KERN_ABORTED
)
894 else if (kern_result
== KERN_OPERATION_TIMED_OUT
)
902 __pthread_kill(__unused
struct proc
*p
,
903 register struct __pthread_kill_args
*uap
,
904 __unused register_t
*retval
)
908 int signum
= uap
->sig
;
911 target_act
= (thread_t
)port_name_to_thread(uap
->thread_port
);
913 if (target_act
== THREAD_NULL
)
915 if ((u_int
)signum
>= NSIG
) {
920 uth
= (struct uthread
*)get_bsdthread_info(target_act
);
922 if (uth
->uu_flag
& UT_NO_SIGMASK
) {
928 psignal_uthread(target_act
, signum
);
930 thread_deallocate(target_act
);
936 pthread_sigmask(__unused
register struct proc
*p
,
937 register struct pthread_sigmask_args
*uap
,
938 __unused register_t
*retval
)
940 user_addr_t set
= uap
->set
;
941 user_addr_t oset
= uap
->oset
;
947 ut
= (struct uthread
*)get_bsdthread_info(current_thread());
948 oldset
= ut
->uu_sigmask
;
950 if (set
== USER_ADDR_NULL
) {
951 /* need only old mask */
955 error
= copyin(set
, &nset
, sizeof(sigset_t
));
961 ut
->uu_sigmask
|= (nset
& ~sigcantmask
);
965 ut
->uu_sigmask
&= ~(nset
);
966 signal_setast(current_thread());
970 ut
->uu_sigmask
= (nset
& ~sigcantmask
);
971 signal_setast(current_thread());
979 if (!error
&& oset
!= USER_ADDR_NULL
)
980 copyout(&oldset
, oset
, sizeof(sigset_t
));
987 sigwait(register struct proc
*p
, register struct sigwait_args
*uap
, __unused register_t
*retval
)
997 ut
= (struct uthread
*)get_bsdthread_info(current_thread());
999 if (uap
->set
== USER_ADDR_NULL
)
1002 error
= copyin(uap
->set
, &mask
, sizeof(sigset_t
));
1006 siglist
= (mask
& ~sigcantmask
);
1012 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
1016 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
1017 if ( (sigw
= uth
->uu_siglist
& siglist
) ) {
1024 /* The signal was pending on a thread */
1028 * When returning from sigwait, we want
1029 * the old mask to be restored after the
1030 * signal handler has finished. Thus, we
1031 * save it here and mark the sigacts structure
1034 ut
->uu_oldmask
= ut
->uu_sigmask
;
1035 ut
->uu_flag
|= UT_SAS_OLDMASK
;
1036 if (siglist
== (sigset_t
)0)
1038 /* SIGKILL and SIGSTOP are not maskable as well */
1039 ut
->uu_sigmask
= ~(siglist
|sigcantmask
);
1040 ut
->uu_sigwait
= siglist
;
1041 /* No Continuations for now */
1042 error
= tsleep((caddr_t
)&ut
->uu_sigwait
, PPAUSE
|PCATCH
, "pause", 0);
1044 if ((error
== EINTR
) || (error
== ERESTART
))
1047 sigw
= (ut
->uu_sigwait
& siglist
);
1048 ut
->uu_sigmask
= ut
->uu_oldmask
;
1050 ut
->uu_flag
&= ~UT_SAS_OLDMASK
;
1054 signum
= ffs((unsigned int)sigw
);
1056 panic("sigwait with no signal wakeup");
1057 ut
->uu_siglist
&= ~(sigmask(signum
));
1058 if (uap
->sig
!= USER_ADDR_NULL
)
1059 error
= copyout(&signum
, uap
->sig
, sizeof(int));
1068 sigaltstack(struct proc
*p
, register struct sigaltstack_args
*uap
, __unused register_t
*retval
)
1070 struct sigacts
*psp
;
1071 struct user_sigaltstack ss
;
1075 if ((psp
->ps_flags
& SAS_ALTSTACK
) == 0)
1076 psp
->ps_sigstk
.ss_flags
|= SA_DISABLE
;
1078 if (IS_64BIT_PROCESS(p
)) {
1079 error
= copyout(&psp
->ps_sigstk
, uap
->oss
, sizeof(struct user_sigaltstack
));
1081 struct sigaltstack ss32
;
1082 sigaltstack_64to32(&psp
->ps_sigstk
, &ss32
);
1083 error
= copyout(&ss32
, uap
->oss
, sizeof(struct sigaltstack
));
1088 if (uap
->nss
== USER_ADDR_NULL
)
1090 if (IS_64BIT_PROCESS(p
)) {
1091 error
= copyin(uap
->nss
, &ss
, sizeof(struct user_sigaltstack
));
1093 struct sigaltstack ss32
;
1094 error
= copyin(uap
->nss
, &ss32
, sizeof(struct sigaltstack
));
1095 sigaltstack_32to64(&ss32
,&ss
);
1099 if ((ss
.ss_flags
& ~SA_DISABLE
) != 0) {
1103 if (ss
.ss_flags
& SA_DISABLE
) {
1104 if (psp
->ps_sigstk
.ss_flags
& SA_ONSTACK
)
1106 psp
->ps_flags
&= ~SAS_ALTSTACK
;
1107 psp
->ps_sigstk
.ss_flags
= ss
.ss_flags
;
1110 /* The older stacksize was 8K, enforce that one so no compat problems */
1111 #define OLDMINSIGSTKSZ 8*1024
1112 if (ss
.ss_size
< OLDMINSIGSTKSZ
)
1114 psp
->ps_flags
|= SAS_ALTSTACK
;
1120 kill(struct proc
*cp
, struct kill_args
*uap
, __unused register_t
*retval
)
1122 register struct proc
*p
;
1123 kauth_cred_t uc
= kauth_cred_get();
1125 AUDIT_ARG(pid
, uap
->pid
);
1126 AUDIT_ARG(signum
, uap
->signum
);
1128 if ((u_int
)uap
->signum
>= NSIG
)
1131 /* kill single process */
1132 if ((p
= proc_findref(uap
->pid
)) == NULL
) {
1133 if ((p
= pzfind(uap
->pid
)) != NULL
) {
1135 * IEEE Std 1003.1-2001: return success
1136 * when killing a zombie.
1142 AUDIT_ARG(process
, p
);
1143 if (!cansignal(cp
, uc
, p
, uap
->signum
)) {
1148 psignal(p
, uap
->signum
);
1153 case -1: /* broadcast signal */
1154 return (killpg1(cp
, uap
->signum
, 0, 1));
1155 case 0: /* signal own process group */
1156 return (killpg1(cp
, uap
->signum
, 0, 0));
1157 default: /* negative explicit process group */
1158 return (killpg1(cp
, uap
->signum
, -(uap
->pid
), 0));
1165 * Common code for kill process group/broadcast kill.
1166 * cp is calling process.
1169 killpg1(cp
, signum
, pgid
, all
)
1170 register struct proc
*cp
;
1171 int signum
, pgid
, all
;
1173 register struct proc
*p
;
1174 kauth_cred_t uc
= cp
->p_ucred
;
1182 for (p
= allproc
.lh_first
; p
!= 0; p
= p
->p_list
.le_next
) {
1183 if (p
->p_pid
<= 1 || p
->p_flag
& P_SYSTEM
||
1184 p
== cp
|| !cansignal(cp
, uc
, p
, signum
))
1193 * zero pgid means send to my process group.
1197 pgrp
= pgfind(pgid
);
1201 for (p
= pgrp
->pg_members
.lh_first
; p
!= 0;
1202 p
= p
->p_pglist
.le_next
) {
1203 if (p
->p_pid
<= 1 || p
->p_flag
& P_SYSTEM
||
1204 p
->p_stat
== SZOMB
||
1205 !cansignal(cp
, uc
, p
, signum
))
1212 return (nfound
? 0 : ESRCH
);
1216 * Send a signal to a process group.
1219 gsignal(pgid
, signum
)
1224 if (pgid
&& (pgrp
= pgfind(pgid
)))
1225 pgsignal(pgrp
, signum
, 0);
1229 * Send a signal to a process group. If checktty is 1,
1230 * limit to members which have a controlling terminal.
1233 pgsignal(pgrp
, signum
, checkctty
)
1235 int signum
, checkctty
;
1237 register struct proc
*p
;
1240 for (p
= pgrp
->pg_members
.lh_first
; p
!= 0;
1241 p
= p
->p_pglist
.le_next
)
1242 if (checkctty
== 0 || p
->p_flag
& P_CONTROLT
)
1247 * Send signal to a backgrounded process blocked due to tty access
1248 * In FreeBSD, the backgrounded process wakes up every second and
1249 * discovers whether it is foregounded or not. In our case, we block
1250 * the thread in tsleep as we want to avoid storm of processes as well
1251 * as the suspend is only at AST level
1254 tty_pgsignal(pgrp
, signum
)
1258 register struct proc
*p
;
1261 for (p
= pgrp
->pg_members
.lh_first
; p
!= 0;
1262 p
= p
->p_pglist
.le_next
)
1263 if ((p
->p_flag
& P_TTYSLEEP
) && (p
->p_flag
& P_CONTROLT
))
1268 * Send a signal caused by a trap to a specific thread.
1271 threadsignal(thread_t sig_actthread
, int signum
, u_long code
)
1273 register struct uthread
*uth
;
1274 register struct task
* sig_task
;
1275 register struct proc
*p
;
1278 if ((u_int
)signum
>= NSIG
|| signum
== 0)
1281 mask
= sigmask(signum
);
1282 if ((mask
& threadmask
) == 0)
1284 sig_task
= get_threadtask(sig_actthread
);
1285 p
= (struct proc
*)(get_bsdtask_info(sig_task
));
1287 uth
= get_bsdthread_info(sig_actthread
);
1288 if (uth
&& (uth
->uu_flag
& UT_VFORK
))
1291 if (!(p
->p_flag
& P_TRACED
) && (p
->p_sigignore
& mask
))
1294 uth
->uu_siglist
|= mask
;
1295 p
->p_siglist
|= mask
; /* just for lame ones looking here */
1296 uth
->uu_code
= code
;
1297 /* mark on process as well */
1298 signal_setast(sig_actthread
);
1304 register struct proc
*p
;
1305 register int signum
;
1307 psignal_lock(p
, signum
, 1);
1311 psignal_vfork(struct proc
*p
, task_t new_task
, thread_t thr_act
, int signum
)
1314 register sig_t action
;
1316 struct uthread
*uth
;
1318 if ((u_int
)signum
>= NSIG
|| signum
== 0)
1319 panic("psignal signal number");
1320 mask
= sigmask(signum
);
1321 prop
= sigprop
[signum
];
1324 if(rdebug_proc
&& (p
== rdebug_proc
)) {
1327 #endif /* SIGNAL_DEBUG */
1329 if ((new_task
== TASK_NULL
) || (thr_act
== (thread_t
)NULL
) || is_kerneltask(new_task
))
1333 uth
= get_bsdthread_info(thr_act
);
1337 * proc is traced, always give parent a chance.
1341 if (p
->p_nice
> NZERO
&& action
== SIG_DFL
&& (prop
& SA_KILL
) &&
1342 (p
->p_flag
& P_TRACED
) == 0)
1345 if (prop
& SA_CONT
) {
1346 p
->p_siglist
&= ~stopsigmask
;
1347 uth
->uu_siglist
&= ~stopsigmask
;
1350 if (prop
& SA_STOP
) {
1352 * If sending a tty stop signal to a member of an orphaned
1353 * process group, discard the signal here if the action
1354 * is default; don't stop the process below if sleeping,
1355 * and don't clear any pending SIGCONT.
1357 if (prop
& SA_TTYSTOP
&& p
->p_pgrp
->pg_jobc
== 0 &&
1360 uth
->uu_siglist
&= ~contsigmask
;
1361 p
->p_siglist
&= ~contsigmask
;
1363 uth
->uu_siglist
|= mask
;
1364 p
->p_siglist
|= mask
; /* just for lame ones looking here */
1366 /* Deliver signal to the activation passed in */
1367 act_set_astbsd(thr_act
);
1370 * SIGKILL priority twiddling moved here from above because
1371 * it needs sig_thread. Could merge it into large switch
1372 * below if we didn't care about priority for tracing
1373 * as SIGKILL's action is always SIG_DFL.
1375 if ((signum
== SIGKILL
) && (p
->p_nice
> NZERO
)) {
1380 * This Process is traced - wake it up (if not already
1381 * stopped) so that it can discover the signal in
1382 * issig() and stop for the parent.
1384 if (p
->p_flag
& P_TRACED
) {
1385 if (p
->p_stat
!= SSTOP
)
1392 * If we're being traced (possibly because someone attached us
1393 * while we were stopped), check for a signal from the debugger.
1395 if (p
->p_stat
== SSTOP
) {
1396 if ((p
->p_flag
& P_TRACED
) != 0 && p
->p_xstat
!= 0) {
1397 uth
->uu_siglist
|= sigmask(p
->p_xstat
);
1398 p
->p_siglist
|= mask
; /* just for lame ones looking here */
1403 * setrunnable(p) in BSD
1412 get_signalthread(struct proc
*p
, int signum
)
1414 struct uthread
*uth
;
1416 sigset_t mask
= sigmask(signum
);
1417 thread_t sig_thread_act
;
1418 struct task
* sig_task
= p
->task
;
1421 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
1422 sig_thread_act
= p
->p_vforkact
;
1423 kret
= check_actforsig(sig_task
, sig_thread_act
, 1);
1424 if (kret
== KERN_SUCCESS
)
1425 return(sig_thread_act
);
1427 return(THREAD_NULL
);
1430 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
1431 if(((uth
->uu_flag
& UT_NO_SIGMASK
)== 0) &&
1432 (((uth
->uu_sigmask
& mask
) == 0) || (uth
->uu_sigwait
& mask
))) {
1433 if (check_actforsig(p
->task
, uth
->uu_act
, 1) == KERN_SUCCESS
)
1434 return(uth
->uu_act
);
1437 if (get_signalact(p
->task
, &thr_act
, 1) == KERN_SUCCESS
) {
1441 return(THREAD_NULL
);
1445 * Send the signal to the process. If the signal has an action, the action
1446 * is usually performed by the target process rather than the caller; we add
1447 * the signal to the set of pending signals for the process.
1450 * o When a stop signal is sent to a sleeping process that takes the
1451 * default action, the process is stopped without awakening it.
1452 * o SIGCONT restarts stopped processes (or puts them back to sleep)
1453 * regardless of the signal action (eg, blocked or ignored).
1455 * Other ignored signals are discarded immediately.
1458 psignal_lock(p
, signum
, withlock
)
1459 register struct proc
*p
;
1460 register int signum
;
1461 register int withlock
;
1463 register int s
, prop
;
1464 register sig_t action
;
1465 thread_t sig_thread_act
;
1466 register task_t sig_task
;
1468 struct uthread
*uth
;
1469 boolean_t funnel_state
= FALSE
;
1472 if ((u_int
)signum
>= NSIG
|| signum
== 0)
1473 panic("psignal signal number");
1474 mask
= sigmask(signum
);
1475 prop
= sigprop
[signum
];
1478 if(rdebug_proc
&& (p
== rdebug_proc
)) {
1481 #endif /* SIGNAL_DEBUG */
1483 if (thread_funnel_get() == (funnel_t
*)0) {
1485 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
1488 * We will need the task pointer later. Grab it now to
1489 * check for a zombie process. Also don't send signals
1490 * to kernel internal tasks.
1492 if (((sig_task
= p
->task
) == TASK_NULL
) || is_kerneltask(sig_task
)) {
1494 thread_funnel_set(kernel_flock
, funnel_state
);
1499 KNOTE(&p
->p_klist
, NOTE_SIGNAL
| signum
);
1503 * do not send signals to the process that has the thread
1504 * doing a reboot(). Not doing so will mark that thread aborted
1505 * and can cause IO failures wich will cause data loss.
1507 if (ISSET(p
->p_flag
, P_REBOOT
)) {
1509 thread_funnel_set(kernel_flock
, funnel_state
);
1517 * Deliver the signal to the first thread in the task. This
1518 * allows single threaded applications which use signals to
1519 * be able to be linked with multithreaded libraries. We have
1520 * an implicit reference to the current thread, but need
1521 * an explicit one otherwise. The thread reference keeps
1522 * the corresponding task data structures around too. This
1523 * reference is released by thread_deallocate.
1526 if (((p
->p_flag
& P_TRACED
) == 0) && (p
->p_sigignore
& mask
))
1529 /* If successful return with ast set */
1530 sig_thread_act
= get_signalthread(p
, signum
);
1532 if (sig_thread_act
== THREAD_NULL
) {
1534 * if it is sigkill, may be we should
1535 * inject a thread to terminate
1539 #endif /* SIGNAL_DEBUG */
1543 uth
= get_bsdthread_info(sig_thread_act
);
1546 * If proc is traced, always give parent a chance.
1548 if (p
->p_flag
& P_TRACED
)
1552 * If the signal is being ignored,
1553 * then we forget about it immediately.
1554 * (Note: we don't set SIGCONT in p_sigignore,
1555 * and if it is set to SIG_IGN,
1556 * action will be SIG_DFL here.)
1558 if (p
->p_sigignore
& mask
)
1560 /* sigwait takes precedence */
1561 if (uth
->uu_sigwait
& mask
)
1562 action
= KERN_SIG_WAIT
;
1563 else if (uth
->uu_sigmask
& mask
)
1564 action
= KERN_SIG_HOLD
;
1565 else if (p
->p_sigcatch
& mask
)
1566 action
= KERN_SIG_CATCH
;
1571 if (p
->p_nice
> NZERO
&& action
== SIG_DFL
&& (prop
& SA_KILL
) &&
1572 (p
->p_flag
& P_TRACED
) == 0)
1575 if (prop
& SA_CONT
) {
1576 uth
->uu_siglist
&= ~stopsigmask
;
1577 p
->p_siglist
&= ~stopsigmask
;
1580 if (prop
& SA_STOP
) {
1582 * If sending a tty stop signal to a member of an orphaned
1583 * process group, discard the signal here if the action
1584 * is default; don't stop the process below if sleeping,
1585 * and don't clear any pending SIGCONT.
1587 if (prop
& SA_TTYSTOP
&& p
->p_pgrp
->pg_jobc
== 0 &&
1590 uth
->uu_siglist
&= ~contsigmask
;
1591 p
->p_siglist
&= ~contsigmask
;
1593 uth
->uu_siglist
|= mask
;
1594 p
->p_siglist
|= mask
; /* just for lame ones looking here */
1598 * Defer further processing for signals which are held,
1599 * except that stopped processes must be continued by SIGCONT.
1601 if (action
== KERN_SIG_HOLD
&& ((prop
& SA_CONT
) == 0 || p
->p_stat
!= SSTOP
)) {
1605 * SIGKILL priority twiddling moved here from above because
1606 * it needs sig_thread. Could merge it into large switch
1607 * below if we didn't care about priority for tracing
1608 * as SIGKILL's action is always SIG_DFL.
1610 if ((signum
== SIGKILL
) && (p
->p_nice
> NZERO
)) {
1615 * Process is traced - wake it up (if not already
1616 * stopped) so that it can discover the signal in
1617 * issig() and stop for the parent.
1619 if (p
->p_flag
& P_TRACED
) {
1620 if (p
->p_stat
!= SSTOP
)
1626 if (action
== KERN_SIG_WAIT
) {
1627 uth
->uu_sigwait
= mask
;
1628 uth
->uu_siglist
&= ~mask
;
1629 p
->p_siglist
&= ~mask
;
1630 wakeup(&uth
->uu_sigwait
);
1631 /* if it is SIGCONT resume whole process */
1632 if (prop
& SA_CONT
) {
1633 p
->p_flag
|= P_CONTINUED
;
1634 (void) task_resume(sig_task
);
1639 if (action
!= SIG_DFL
) {
1641 * User wants to catch the signal.
1642 * Wake up the thread, but don't un-suspend it
1643 * (except for SIGCONT).
1645 if (prop
& SA_CONT
) {
1646 if (p
->p_flag
& P_TTYSLEEP
) {
1647 p
->p_flag
&= ~P_TTYSLEEP
;
1648 wakeup(&p
->p_siglist
);
1650 p
->p_flag
|= P_CONTINUED
;
1651 (void) task_resume(sig_task
);
1654 } else if (p
->p_stat
== SSTOP
)
1658 /* Default action - varies */
1659 if (mask
& stopsigmask
) {
1661 * These are the signals which by default
1664 * Don't clog system with children of init
1665 * stopped from the keyboard.
1667 if (!(prop
& SA_STOP
) && p
->p_pptr
== initproc
) {
1668 psignal_lock(p
, SIGKILL
, 0);
1669 uth
->uu_siglist
&= ~mask
;
1670 p
->p_siglist
&= ~mask
;
1676 * if task hasn't already been stopped by
1679 uth
->uu_siglist
&= ~mask
;
1680 p
->p_siglist
&= ~mask
;
1681 if (p
->p_stat
!= SSTOP
) {
1682 p
->p_xstat
= signum
;
1684 if ((p
->p_pptr
->p_flag
& P_NOCLDSTOP
) == 0) {
1685 struct proc
*pp
= p
->p_pptr
;
1687 pp
->si_pid
= p
->p_pid
;
1688 pp
->si_status
= p
->p_xstat
;
1689 pp
->si_code
= CLD_STOPPED
;
1690 pp
->si_uid
= p
->p_ucred
->cr_ruid
;
1691 psignal(pp
, SIGCHLD
);
1699 * Signals ignored by default have been dealt
1700 * with already, since their bits are on in
1706 * Kill signal always sets process running and
1710 * Process will be running after 'run'
1714 thread_abort(sig_thread_act
);
1720 * Let the process run. If it's sleeping on an
1721 * event, it remains so.
1723 if (p
->p_flag
& P_TTYSLEEP
) {
1724 p
->p_flag
&= ~P_TTYSLEEP
;
1725 wakeup(&p
->p_siglist
);
1727 p
->p_flag
|= P_CONTINUED
;
1728 (void) task_resume(sig_task
);
1730 uth
->uu_siglist
&= ~mask
;
1731 p
->p_siglist
&= ~mask
;
1738 * All other signals wake up the process, but don't
1741 if (p
->p_stat
== SSTOP
)
1749 * If we're being traced (possibly because someone attached us
1750 * while we were stopped), check for a signal from the debugger.
1752 if (p
->p_stat
== SSTOP
) {
1753 if ((p
->p_flag
& P_TRACED
) != 0 && p
->p_xstat
!= 0)
1754 uth
->uu_siglist
|= sigmask(p
->p_xstat
);
1757 * setrunnable(p) in BSD and
1758 * Wake up the thread if it is interruptible.
1761 thread_abort_safely(sig_thread_act
);
1767 thread_funnel_set(kernel_flock
, funnel_state
);
1771 /* psignal_lock(p, signum, withlock ) */
1773 psignal_uthread(thr_act
, signum
)
1779 register sig_t action
;
1780 thread_t sig_thread_act
;
1781 register task_t sig_task
;
1783 struct uthread
*uth
;
1787 p
= (struct proc
*)get_bsdtask_info(get_threadtask(thr_act
));
1788 if ((u_int
)signum
>= NSIG
|| signum
== 0)
1789 panic("Invalid signal number in psignal_uthread");
1790 mask
= sigmask(signum
);
1791 prop
= sigprop
[signum
];
1794 if(rdebug_proc
&& (p
== rdebug_proc
)) {
1797 #endif /* SIGNAL_DEBUG */
1800 * We will need the task pointer later. Grab it now to
1801 * check for a zombie process. Also don't send signals
1802 * to kernel internal tasks.
1804 if (((sig_task
= p
->task
) == TASK_NULL
) || is_kerneltask(sig_task
)) {
1808 sig_thread_act
= thr_act
;
1810 * do not send signals to the process that has the thread
1811 * doing a reboot(). Not doing so will mark that thread aborted
1812 * and can cause IO failures wich will cause data loss.
1814 if (ISSET(p
->p_flag
, P_REBOOT
)) {
1821 * Deliver the signal to the first thread in the task. This
1822 * allows single threaded applications which use signals to
1823 * be able to be linked with multithreaded libraries. We have
1824 * an implicit reference to the current thread, but need
1825 * an explicit one otherwise. The thread reference keeps
1826 * the corresponding task data structures around too. This
1827 * reference is released by thread_deallocate.
1830 if (((p
->p_flag
& P_TRACED
) == 0) && (p
->p_sigignore
& mask
))
1833 kret
= check_actforsig(sig_task
, sig_thread_act
, 1);
1835 if (kret
!= KERN_SUCCESS
) {
1841 uth
= get_bsdthread_info(sig_thread_act
);
1844 * If proc is traced, always give parent a chance.
1846 if (p
->p_flag
& P_TRACED
)
1850 * If the signal is being ignored,
1851 * then we forget about it immediately.
1852 * (Note: we don't set SIGCONT in p_sigignore,
1853 * and if it is set to SIG_IGN,
1854 * action will be SIG_DFL here.)
1856 if (p
->p_sigignore
& mask
)
1858 /* sigwait takes precedence */
1859 if (uth
->uu_sigwait
& mask
)
1860 action
= KERN_SIG_WAIT
;
1861 else if (uth
->uu_sigmask
& mask
)
1862 action
= KERN_SIG_HOLD
;
1863 else if (p
->p_sigcatch
& mask
)
1864 action
= KERN_SIG_CATCH
;
1869 if (p
->p_nice
> NZERO
&& action
== SIG_DFL
&& (prop
& SA_KILL
) &&
1870 (p
->p_flag
& P_TRACED
) == 0)
1873 if (prop
& SA_CONT
) {
1874 uth
->uu_siglist
&= ~stopsigmask
;
1875 p
->p_siglist
&= ~stopsigmask
;
1878 if (prop
& SA_STOP
) {
1880 * If sending a tty stop signal to a member of an orphaned
1881 * process group, discard the signal here if the action
1882 * is default; don't stop the process below if sleeping,
1883 * and don't clear any pending SIGCONT.
1885 if (prop
& SA_TTYSTOP
&& p
->p_pgrp
->pg_jobc
== 0 &&
1888 uth
->uu_siglist
&= ~contsigmask
;
1889 p
->p_siglist
&= ~contsigmask
;
1891 uth
->uu_siglist
|= mask
;
1892 p
->p_siglist
|= mask
; /* just for lame ones looking here */
1895 * Defer further processing for signals which are held,
1896 * except that stopped processes must be continued by SIGCONT.
1898 if (action
== KERN_SIG_HOLD
&& ((prop
& SA_CONT
) == 0 || p
->p_stat
!= SSTOP
))
1902 * SIGKILL priority twiddling moved here from above because
1903 * it needs sig_thread. Could merge it into large switch
1904 * below if we didn't care about priority for tracing
1905 * as SIGKILL's action is always SIG_DFL.
1907 if ((signum
== SIGKILL
) && (p
->p_nice
> NZERO
)) {
1912 * Process is traced - wake it up (if not already
1913 * stopped) so that it can discover the signal in
1914 * issig() and stop for the parent.
1916 if (p
->p_flag
& P_TRACED
) {
1917 if (p
->p_stat
!= SSTOP
)
1923 if (action
== KERN_SIG_WAIT
) {
1924 uth
->uu_sigwait
= mask
;
1925 uth
->uu_siglist
&= ~mask
;
1926 p
->p_siglist
&= ~mask
;
1927 wakeup(&uth
->uu_sigwait
);
1928 /* if it is SIGCONT resume whole process */
1929 if (prop
& SA_CONT
) {
1930 p
->p_flag
|= P_CONTINUED
;
1931 (void) task_resume(sig_task
);
1936 if (action
!= SIG_DFL
) {
1938 * User wants to catch the signal.
1939 * Wake up the thread, but don't un-suspend it
1940 * (except for SIGCONT).
1942 if (prop
& SA_CONT
) {
1943 p
->p_flag
|= P_CONTINUED
;
1944 (void) task_resume(sig_task
);
1948 /* Default action - varies */
1949 if (mask
& stopsigmask
) {
1951 * These are the signals which by default
1954 * Don't clog system with children of init
1955 * stopped from the keyboard.
1957 if (!(prop
& SA_STOP
) && p
->p_pptr
== initproc
) {
1958 psignal_lock(p
, SIGKILL
, 0);
1959 uth
->uu_siglist
&= ~mask
;
1960 p
->p_siglist
&= ~mask
;
1966 * if task hasn't already been stopped by
1969 uth
->uu_siglist
&= ~mask
;
1970 p
->p_siglist
&= ~mask
;
1971 if (p
->p_stat
!= SSTOP
) {
1972 p
->p_xstat
= signum
;
1973 if ((p
->p_pptr
->p_flag
& P_NOCLDSTOP
) == 0) {
1974 struct proc
*pp
= p
->p_pptr
;
1976 pp
->si_pid
= p
->p_pid
;
1977 pp
->si_status
= p
->p_xstat
;
1978 pp
->si_code
= CLD_STOPPED
;
1979 pp
->si_uid
= p
->p_ucred
->cr_ruid
;
1980 psignal(pp
, SIGCHLD
);
1989 * Signals ignored by default have been dealt
1990 * with already, since their bits are on in
1996 * Kill signal always sets process running and
2000 * Process will be running after 'run'
2004 thread_abort(sig_thread_act
);
2010 * Let the process run. If it's sleeping on an
2011 * event, it remains so.
2013 if (p
->p_flag
& P_TTYSLEEP
) {
2014 p
->p_flag
&= ~P_TTYSLEEP
;
2015 wakeup(&p
->p_siglist
);
2017 p
->p_flag
|= P_CONTINUED
;
2018 (void) task_resume(sig_task
);
2020 uth
->uu_siglist
&= ~mask
;
2021 p
->p_siglist
&= ~mask
;
2027 * All other signals wake up the process, but don't
2036 * If we're being traced (possibly because someone attached us
2037 * while we were stopped), check for a signal from the debugger.
2039 if (p
->p_stat
== SSTOP
) {
2040 if ((p
->p_flag
& P_TRACED
) != 0 && p
->p_xstat
!= 0) {
2041 uth
->uu_siglist
|= sigmask(p
->p_xstat
);
2042 p
->p_siglist
|= sigmask(p
->p_xstat
);
2046 * setrunnable(p) in BSD and
2047 * Wake up the thread if it is interruptible.
2050 thread_abort_safely(sig_thread_act
);
2059 sig_lock_to_exit(struct proc
*p
)
2061 thread_t self
= current_thread();
2063 p
->exit_thread
= self
;
2064 (void) task_suspend(p
->task
);
2068 sig_try_locked(struct proc
*p
)
2070 thread_t self
= current_thread();
2072 while (p
->sigwait
|| p
->exit_thread
) {
2073 if (p
->exit_thread
) {
2074 if (p
->exit_thread
!= self
) {
2076 * Already exiting - no signals.
2082 if(assert_wait_possible()) {
2083 assert_wait((caddr_t
)&p
->sigwait_thread
,
2084 (THREAD_INTERRUPTIBLE
));
2087 thread_block(THREAD_CONTINUE_NULL
);
2089 if (thread_should_abort(self
)) {
2091 * Terminate request - clean up.
2100 * If the current process has received a signal (should be caught or cause
2101 * termination, should interrupt current syscall), return the signal number.
2102 * Stop signals with default action are processed immediately, then cleared;
2103 * they aren't returned. This is checked after each entry to the system for
2104 * a syscall or trap (though this can usually be done without calling issignal
2105 * by checking the pending signal masks in the CURSIG macro.) The normal call
2108 * while (signum = CURSIG(curproc))
2113 register struct proc
*p
;
2115 register int signum
, mask
, prop
, sigbits
;
2117 struct uthread
* ut
;
2120 cur_act
= current_thread();
2123 if(rdebug_proc
&& (p
== rdebug_proc
)) {
2126 #endif /* SIGNAL_DEBUG */
2130 * Try to grab the signal lock.
2132 if (sig_try_locked(p
) <= 0) {
2137 ut
= get_bsdthread_info(cur_act
);
2139 sigbits
= ut
->uu_siglist
& ~ut
->uu_sigmask
;
2141 if (p
->p_flag
& P_PPWAIT
)
2142 sigbits
&= ~stopsigmask
;
2143 if (sigbits
== 0) { /* no signal to send */
2147 signum
= ffs((long)sigbits
);
2148 mask
= sigmask(signum
);
2149 prop
= sigprop
[signum
];
2152 * We should see pending but ignored signals
2153 * only if P_TRACED was on when they were posted.
2155 if (mask
& p
->p_sigignore
&& (p
->p_flag
& P_TRACED
) == 0) {
2156 ut
->uu_siglist
&= ~mask
; /* take the signal! */
2157 p
->p_siglist
&= ~mask
; /* take the signal! */
2160 if (p
->p_flag
& P_TRACED
&& (p
->p_flag
& P_PPWAIT
) == 0) {
2161 register task_t task
;
2163 * If traced, always stop, and stay
2164 * stopped until released by the debugger.
2166 /* ptrace debugging */
2167 p
->p_xstat
= signum
;
2169 if (p
->p_flag
& P_SIGEXC
) {
2171 p
->sigwait_thread
= cur_act
;
2173 p
->p_flag
&= ~(P_WAITED
|P_CONTINUED
);
2174 ut
->uu_siglist
&= ~mask
; /* clear the old signal */
2175 p
->p_siglist
&= ~mask
; /* clear the old signal */
2177 do_bsdexception(EXC_SOFTWARE
, EXC_SOFT_SIGNAL
, signum
);
2180 // panic("Unsupportef gdb option \n");;
2181 pp
->si_pid
= p
->p_pid
;
2182 pp
->si_status
= p
->p_xstat
;
2183 pp
->si_code
= CLD_TRAPPED
;
2184 pp
->si_uid
= p
->p_ucred
->cr_ruid
;
2185 psignal(pp
, SIGCHLD
);
2187 * XXX Have to really stop for debuggers;
2188 * XXX stop() doesn't do the right thing.
2189 * XXX Inline the task_suspend because we
2190 * XXX have to diddle Unix state in the
2196 p
->sigwait_thread
= cur_act
;
2198 p
->p_flag
&= ~(P_WAITED
|P_CONTINUED
);
2199 ut
->uu_siglist
&= ~mask
; /* clear the old signal */
2200 p
->p_siglist
&= ~mask
; /* clear the old signal */
2202 wakeup((caddr_t
)p
->p_pptr
);
2204 assert_wait((caddr_t
)&p
->sigwait
, (THREAD_INTERRUPTIBLE
));
2205 thread_block(THREAD_CONTINUE_NULL
);
2210 p
->sigwait_thread
= NULL
;
2211 wakeup((caddr_t
)&p
->sigwait_thread
);
2214 * This code is to detect when gdb is killed
2215 * even as the traced program is attached.
2216 * pgsignal would get the SIGKILL to traced program
2217 * That's what we are trying to see (I hope)
2219 if (ut
->uu_siglist
& sigmask(SIGKILL
)) {
2221 * Wait event may still be outstanding;
2222 * clear it, since sig_lock_to_exit will
2225 clear_wait(current_thread(), THREAD_INTERRUPTED
);
2226 sig_lock_to_exit(p
);
2228 * Since this thread will be resumed
2229 * to allow the current syscall to
2230 * be completed, must save u_qsave
2231 * before calling exit(). (Since exit()
2232 * calls closef() which can trash u_qsave.)
2235 exit1(p
,signum
, (int *)NULL
);
2240 * We may have to quit
2242 if (thread_should_abort(current_thread())) {
2247 * If parent wants us to take the signal,
2248 * then it will leave it in p->p_xstat;
2249 * otherwise we just look for signals again.
2251 signum
= p
->p_xstat
;
2255 * Put the new signal into p_siglist. If the
2256 * signal is being masked, look for other signals.
2258 mask
= sigmask(signum
);
2259 ut
->uu_siglist
|= mask
;
2260 p
->p_siglist
|= mask
; /* just for lame ones looking here */
2261 if (ut
->uu_sigmask
& mask
)
2266 * Decide whether the signal should be returned.
2267 * Return the signal's number, or fall through
2268 * to clear it from the pending mask.
2271 switch ((long)p
->p_sigacts
->ps_sigact
[signum
]) {
2275 * Don't take default actions on system processes.
2277 if (p
->p_pptr
->p_pid
== 0) {
2280 * Are you sure you want to ignore SIGSEGV
2283 printf("Process (pid %d) got signal %d\n",
2286 break; /* == ignore */
2290 * If there is a pending stop signal to process
2291 * with default action, stop here,
2292 * then clear the signal. However,
2293 * if process is member of an orphaned
2294 * process group, ignore tty stop signals.
2296 if (prop
& SA_STOP
) {
2297 if (p
->p_flag
& P_TRACED
||
2298 (p
->p_pgrp
->pg_jobc
== 0 &&
2300 break; /* == ignore */
2301 if (p
->p_stat
!= SSTOP
) {
2302 p
->p_xstat
= signum
;
2304 if ((p
->p_pptr
->p_flag
& P_NOCLDSTOP
) == 0) {
2306 pp
->si_pid
= p
->p_pid
;
2307 pp
->si_status
= p
->p_xstat
;
2308 pp
->si_code
= CLD_STOPPED
;
2309 pp
->si_uid
= p
->p_ucred
->cr_ruid
;
2310 psignal(pp
, SIGCHLD
);
2314 } else if (prop
& SA_IGNORE
) {
2316 * Except for SIGCONT, shouldn't get here.
2317 * Default action is to ignore; drop it.
2319 break; /* == ignore */
2321 ut
->uu_siglist
&= ~mask
; /* take the signal! */
2322 p
->p_siglist
&= ~mask
; /* take the signal! */
2330 * Masking above should prevent us ever trying
2331 * to take action on an ignored signal other
2332 * than SIGCONT, unless process is traced.
2334 if ((prop
& SA_CONT
) == 0 &&
2335 (p
->p_flag
& P_TRACED
) == 0)
2336 printf("issignal\n");
2337 break; /* == ignore */
2341 * This signal has an action, let
2342 * postsig() process it.
2344 ut
->uu_siglist
&= ~mask
; /* take the signal! */
2345 p
->p_siglist
&= ~mask
; /* take the signal! */
2349 ut
->uu_siglist
&= ~mask
; /* take the signal! */
2350 p
->p_siglist
&= ~mask
; /* take the signal! */
2355 /* called from _sleep */
2358 register struct proc
*p
;
2360 register int signum
, mask
, prop
, sigbits
;
2362 struct uthread
* ut
;
2366 cur_act
= current_thread();
2368 ut
= get_bsdthread_info(cur_act
);
2370 if (ut
->uu_siglist
== 0)
2373 if (((ut
->uu_siglist
& ~ut
->uu_sigmask
) == 0) && ((p
->p_flag
& P_TRACED
) == 0))
2376 sigbits
= ut
->uu_siglist
& ~ut
->uu_sigmask
;
2379 if (p
->p_flag
& P_PPWAIT
)
2380 sigbits
&= ~stopsigmask
;
2381 if (sigbits
== 0) { /* no signal to send */
2385 signum
= ffs((long)sigbits
);
2386 mask
= sigmask(signum
);
2387 prop
= sigprop
[signum
];
2390 * We should see pending but ignored signals
2391 * only if P_TRACED was on when they were posted.
2393 if (mask
& p
->p_sigignore
&& (p
->p_flag
& P_TRACED
) == 0) {
2396 if (p
->p_flag
& P_TRACED
&& (p
->p_flag
& P_PPWAIT
) == 0) {
2398 * Put the new signal into p_siglist. If the
2399 * signal is being masked, look for other signals.
2401 mask
= sigmask(signum
);
2402 if (ut
->uu_sigmask
& mask
)
2408 * Decide whether the signal should be returned.
2409 * Return the signal's number, or fall through
2410 * to clear it from the pending mask.
2413 switch ((long)p
->p_sigacts
->ps_sigact
[signum
]) {
2417 * Don't take default actions on system processes.
2419 if (p
->p_pptr
->p_pid
== 0) {
2422 * Are you sure you want to ignore SIGSEGV
2425 printf("Process (pid %d) got signal %d\n",
2428 break; /* == ignore */
2432 * If there is a pending stop signal to process
2433 * with default action, stop here,
2434 * then clear the signal. However,
2435 * if process is member of an orphaned
2436 * process group, ignore tty stop signals.
2438 if (prop
& SA_STOP
) {
2439 if (p
->p_flag
& P_TRACED
||
2440 (p
->p_pgrp
->pg_jobc
== 0 &&
2442 break; /* == ignore */
2445 } else if (prop
& SA_IGNORE
) {
2447 * Except for SIGCONT, shouldn't get here.
2448 * Default action is to ignore; drop it.
2450 break; /* == ignore */
2458 * Masking above should prevent us ever trying
2459 * to take action on an ignored signal other
2460 * than SIGCONT, unless process is traced.
2462 if ((prop
& SA_CONT
) == 0 &&
2463 (p
->p_flag
& P_TRACED
) == 0)
2464 printf("issignal\n");
2465 break; /* == ignore */
2469 * This signal has an action, let
2470 * postsig() process it.
2474 sigbits
&= ~mask
; /* take the signal! */
2480 * Put the argument process into the stopped state and notify the parent
2481 * via wakeup. Signals are handled elsewhere. The process must not be
2486 register struct proc
*p
;
2489 p
->p_flag
&= ~(P_WAITED
|P_CONTINUED
);
2490 if (p
->p_pptr
->p_stat
!= SSTOP
)
2491 wakeup((caddr_t
)p
->p_pptr
);
2492 (void) task_suspend(p
->task
); /*XXX*/
2496 * Take the action for the specified signal
2497 * from the current set of pending signals.
2502 struct proc
*p
= current_proc();
2503 struct sigacts
*ps
= p
->p_sigacts
;
2504 user_addr_t catcher
;
2506 int mask
, returnmask
;
2507 struct uthread
* ut
;
2513 * This must be called on master cpu
2515 if (cpu_number() != master_cpu
)
2516 panic("psig not on master");
2521 * Try to grab the signal lock.
2523 if (sig_try_locked(p
) <= 0) {
2528 ut
= (struct uthread
*)get_bsdthread_info(current_thread());
2529 mask
= sigmask(signum
);
2530 ut
->uu_siglist
&= ~mask
;
2531 p
->p_siglist
&= ~mask
;
2532 catcher
= ps
->ps_sigact
[signum
];
2534 //LP64: catcher argument is a 64 bit user space handler address
2535 if (KTRPOINT(p
, KTR_PSIG
))
2536 ktrpsig(p
->p_tracep
,
2537 signum
, CAST_DOWN(void *,catcher
), ut
->uu_flag
& UT_SAS_OLDMASK
?
2538 &ut
->uu_oldmask
: &ut
->uu_sigmask
, 0);
2540 if (catcher
== SIG_DFL
) {
2542 * Default catcher, where the default is to kill
2543 * the process. (Other cases were ignored above.)
2545 /* called with signal_lock() held */
2546 sigexit_locked(p
, signum
);
2551 * If we get here, the signal must be caught.
2554 if (catcher
== SIG_IGN
|| (ut
->uu_sigmask
& mask
))
2556 "postsig: processing masked or ignored signal\n");
2559 * Set the new mask value and also defer further
2560 * occurences of this signal.
2562 * Special case: user has done a sigpause. Here the
2563 * current mask is not of interest, but rather the
2564 * mask from before the sigpause is what we want
2565 * restored after the signal processing is completed.
2567 if (ut
->uu_flag
& UT_SAS_OLDMASK
) {
2568 returnmask
= ut
->uu_oldmask
;
2569 ut
->uu_flag
&= ~UT_SAS_OLDMASK
;
2572 returnmask
= ut
->uu_sigmask
;
2573 ut
->uu_sigmask
|= ps
->ps_catchmask
[signum
];
2574 if ((ps
->ps_signodefer
& mask
) == 0)
2575 ut
->uu_sigmask
|= mask
;
2576 if ((signum
!= SIGILL
) && (signum
!= SIGTRAP
) && (ps
->ps_sigreset
& mask
)) {
2577 if ((signum
!= SIGCONT
) && (sigprop
[signum
] & SA_IGNORE
))
2578 p
->p_sigignore
|= mask
;
2579 ps
->ps_sigact
[signum
] = SIG_DFL
;
2580 ps
->ps_siginfo
&= ~mask
;
2581 ps
->ps_signodefer
&= ~mask
;
2584 /* Needs to disable to run in user mode */
2585 if (signum
== SIGFPE
) {
2586 thread_enable_fpe(current_thread(), 0);
2588 #endif /* __ppc__ */
2590 if (ps
->ps_sig
!= signum
) {
2596 p
->p_stats
->p_ru
.ru_nsignals
++;
2597 sendsig(p
, catcher
, signum
, returnmask
, code
);
2603 * Force the current process to exit with the specified signal, dumping core
2604 * if appropriate. We bypass the normal tests for masked and caught signals,
2605 * allowing unrecoverable failures to terminate the process without changing
2606 * signal state. Mark the accounting record with the signal termination.
2607 * If dumping core, save the signal number for the debugger. Calls exit and
2610 /* called with signal lock */
2612 sigexit_locked(p
, signum
)
2613 register struct proc
*p
;
2617 sig_lock_to_exit(p
);
2618 p
->p_acflag
|= AXSIG
;
2619 if (sigprop
[signum
] & SA_CORE
) {
2620 p
->p_sigacts
->ps_sig
= signum
;
2622 if (coredump(p
) == 0)
2623 signum
|= WCOREFLAG
;
2627 exit1(p
, W_EXITCODE(0, signum
), (int *)NULL
);
2633 filt_sigattach(struct knote
*kn
)
2635 struct proc
*p
= current_proc();
2637 kn
->kn_ptr
.p_proc
= p
;
2638 kn
->kn_flags
|= EV_CLEAR
; /* automatically set */
2640 /* XXX lock the proc here while adding to the list? */
2641 KNOTE_ATTACH(&p
->p_klist
, kn
);
2647 filt_sigdetach(struct knote
*kn
)
2649 struct proc
*p
= kn
->kn_ptr
.p_proc
;
2651 KNOTE_DETACH(&p
->p_klist
, kn
);
2655 * signal knotes are shared with proc knotes, so we apply a mask to
2656 * the hint in order to differentiate them from process hints. This
2657 * could be avoided by using a signal-specific knote list, but probably
2658 * isn't worth the trouble.
2661 filt_signal(struct knote
*kn
, long hint
)
2664 if (hint
& NOTE_SIGNAL
) {
2665 hint
&= ~NOTE_SIGNAL
;
2667 if (kn
->kn_id
== (unsigned int)hint
)
2670 return (kn
->kn_data
!= 0);
2675 bsd_ast(thread_t thr_act
)
2677 struct proc
*p
= current_proc();
2678 struct uthread
*ut
= get_bsdthread_info(thr_act
);
2681 boolean_t funnel_state
;
2682 static int bsd_init_done
= 0;
2687 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
2689 if ((p
->p_flag
& P_OWEUPC
) && (p
->p_flag
& P_PROFIL
)) {
2690 pc
= get_useraddr();
2691 addupc_task(p
, pc
, 1);
2692 p
->p_flag
&= ~P_OWEUPC
;
2695 if (CHECK_SIGNALS(p
, current_thread(), ut
)) {
2696 while ( (signum
= issignal(p
)) )
2699 if (!bsd_init_done
) {
2704 (void) thread_funnel_set(kernel_flock
, FALSE
);
2708 * Follwing routines are called using callout from bsd_hardclock
2709 * so that psignals are called in a thread context and are funneled
2712 psignal_vtalarm(struct proc
*p
)
2714 boolean_t funnel_state
;
2718 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
2719 psignal_lock(p
, SIGVTALRM
, 1);
2720 (void) thread_funnel_set(kernel_flock
, FALSE
);
2724 psignal_xcpu(struct proc
*p
)
2726 boolean_t funnel_state
;
2730 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
2731 psignal_lock(p
, SIGXCPU
, 1);
2732 (void) thread_funnel_set(kernel_flock
, FALSE
);
2736 psignal_sigprof(struct proc
*p
)
2738 boolean_t funnel_state
;
2742 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
2743 psignal_lock(p
, SIGPROF
, 1);
2744 (void) thread_funnel_set(kernel_flock
, FALSE
);
2747 /* ptrace set runnalbe */
2749 pt_setrunnable(struct proc
*p
)
2755 if (p
->p_flag
& P_TRACED
) {
2758 wakeup((caddr_t
)&(p
->sigwait
));
2771 exception_data_type_t codes
[EXCEPTION_CODE_MAX
];
2775 return(bsd_exception(exc
, codes
, 2));
2779 proc_pendingsignals(struct proc
*p
, sigset_t mask
)
2781 struct uthread
* uth
;
2786 /* If the process is in proc exit return no signal info */
2787 if (p
->p_lflag
& P_LPEXIT
)
2790 /* duplicate the signal lock code to enable recursion; as exit
2791 * holds the lock too long. All this code is being reworked
2792 * this is just a workaround for regressions till new code
2796 error
= lockmgr((struct lock__bsd__
*)&p
->signal_lock
[0], (LK_EXCLUSIVE
| LK_CANRECURSE
), 0, (struct proc
*)0);
2800 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
2802 uth
= (struct uthread
*)get_bsdthread_info(th
);
2804 bits
= (((uth
->uu_siglist
& ~uth
->uu_sigmask
) & ~p
->p_sigignore
) & mask
);
2810 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
2811 bits
|= (((uth
->uu_siglist
& ~uth
->uu_sigmask
) & ~p
->p_sigignore
) & mask
);
2819 thread_issignal(proc_t p
, thread_t th
, sigset_t mask
)
2821 struct uthread
* uth
;
2825 uth
= (struct uthread
*)get_bsdthread_info(th
);
2827 bits
= (((uth
->uu_siglist
& ~uth
->uu_sigmask
) & ~p
->p_sigignore
) & mask
);