2 * Copyright (c) 2000-2001 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1995-1998 Apple Computer, Inc. All Rights Reserved */
24 * Copyright (c) 1982, 1986, 1989, 1991, 1993
25 * The Regents of the University of California. All rights reserved.
26 * (c) UNIX System Laboratories, Inc.
27 * All or some portions of this file are derived from material licensed
28 * to the University of California by American Telephone and Telegraph
29 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
30 * the permission of UNIX System Laboratories, Inc.
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by the University of
43 * California, Berkeley and its contributors.
44 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * @(#)kern_sig.c 8.7 (Berkeley) 4/18/94
63 #define SIGPROP /* include signal properties table */
64 #include <sys/param.h>
65 #include <sys/resourcevar.h>
66 #include <sys/proc_internal.h>
67 #include <sys/kauth.h>
68 #include <sys/systm.h>
69 #include <sys/timeb.h>
70 #include <sys/times.h>
72 #include <sys/file_internal.h>
73 #include <sys/kernel.h>
75 #include <sys/signalvar.h>
77 #include <sys/ktrace.h>
79 #include <sys/syslog.h>
82 #include <sys/kdebug.h>
84 #include <sys/mount.h>
85 #include <sys/sysproto.h>
87 #include <bsm/audit_kernel.h>
89 #include <machine/spl.h>
91 #include <kern/cpu_number.h>
94 #include <sys/user.h> /* for coredump */
95 #include <kern/ast.h> /* for APC support */
96 #include <kern/lock.h>
97 #include <kern/task.h> /* extern void *get_bsdtask_info(task_t); */
98 #include <kern/thread.h>
99 #include <kern/sched_prim.h>
100 #include <kern/thread_call.h>
101 #include <mach/exception.h>
102 #include <mach/task.h>
103 #include <mach/thread_act.h>
106 * Missing prototypes that Mach should export
110 extern int thread_enable_fpe(thread_t act
, int onoff
);
111 extern void unix_syscall_return(int error
);
112 extern thread_t
port_name_to_thread(mach_port_name_t port_name
);
113 extern kern_return_t
check_actforsig(task_t task
, thread_t thread
, int setast
);
114 extern kern_return_t
get_signalact(task_t
, thread_t
*, int);
115 extern boolean_t
thread_should_abort(thread_t
);
116 extern unsigned int get_useraddr(void);
122 extern void doexception(int exc
, int code
, int sub
);
124 void stop(struct proc
*p
);
125 int cansignal(struct proc
*, kauth_cred_t
, struct proc
*, int);
126 int killpg1(struct proc
*, int, int, int);
127 void sigexit_locked(struct proc
*, int);
128 int setsigvec(struct proc
*, int, struct __user_sigaction
*);
129 void exit1(struct proc
*, int, int *);
130 void psignal_uthread(thread_t
, int);
131 kern_return_t
do_bsdexception(int, int, int);
132 void __posix_sem_syscall_return(kern_return_t
);
134 /* implementations in osfmk/kern/sync_sema.c. We do not want port.h in this scope, so void * them */
135 kern_return_t
semaphore_timedwait_signal_trap_internal(void *, void *,time_t, int32_t, void (*)(int));
136 kern_return_t
semaphore_timedwait_trap_internal(void *, time_t, int32_t, void (*)(int));
137 kern_return_t
semaphore_wait_signal_trap_internal(void *, void *, void (*)(int));
138 kern_return_t
semaphore_wait_trap_internal(void *, void (*)(int));
140 static int filt_sigattach(struct knote
*kn
);
141 static void filt_sigdetach(struct knote
*kn
);
142 static int filt_signal(struct knote
*kn
, long hint
);
144 struct filterops sig_filtops
=
145 { 0, filt_sigattach
, filt_sigdetach
, filt_signal
};
149 * NOTE: Source and target may *NOT* overlap! (target is smaller)
152 sigaltstack_64to32(struct user_sigaltstack
*in
, struct sigaltstack
*out
)
154 out
->ss_sp
= CAST_DOWN(void *,in
->ss_sp
);
155 out
->ss_size
= in
->ss_size
;
156 out
->ss_flags
= in
->ss_flags
;
160 * NOTE: Source and target may are permitted to overlap! (source is smaller);
161 * this works because we copy fields in order from the end of the struct to
165 sigaltstack_32to64(struct sigaltstack
*in
, struct user_sigaltstack
*out
)
167 out
->ss_flags
= in
->ss_flags
;
168 out
->ss_size
= in
->ss_size
;
169 out
->ss_sp
= CAST_USER_ADDR_T(in
->ss_sp
);
173 sigaction_64to32(struct user_sigaction
*in
, struct sigaction
*out
)
175 /* This assumes 32 bit __sa_handler is of type sig_t */
176 out
->__sigaction_u
.__sa_handler
= CAST_DOWN(sig_t
,in
->__sigaction_u
.__sa_handler
);
177 out
->sa_mask
= in
->sa_mask
;
178 out
->sa_flags
= in
->sa_flags
;
182 __sigaction_32to64(struct __sigaction
*in
, struct __user_sigaction
*out
)
184 out
->__sigaction_u
.__sa_handler
= CAST_USER_ADDR_T(in
->__sigaction_u
.__sa_handler
);
185 out
->sa_tramp
= CAST_USER_ADDR_T(in
->sa_tramp
);
186 out
->sa_mask
= in
->sa_mask
;
187 out
->sa_flags
= in
->sa_flags
;
192 void ram_printf(int);
194 unsigned int rdebug_proc
=0;
201 #endif /* SIGNAL_DEBUG */
204 signal_lock(struct proc
*p
)
211 int register sp
, *fp
, numsaved
;
213 __asm__
volatile("mr %0,r1" : "=r" (sp
));
215 fp
= (int *)*((int *)sp
);
216 for (numsaved
= 0; numsaved
< 3; numsaved
++) {
217 p
->lockpc
[numsaved
] = fp
[2];
224 #endif /* SIGNAL_DEBUG */
225 #endif /* DIAGNOSTIC */
228 error
= lockmgr((struct lock__bsd__
*)&p
->signal_lock
[0], LK_EXCLUSIVE
, 0, (struct proc
*)0);
235 signal_unlock(struct proc
*p
)
241 int register sp
, *fp
, numsaved
;
243 __asm__
volatile("mr %0,r1" : "=r" (sp
));
245 fp
= (int *)*((int *)sp
);
246 for (numsaved
= 0; numsaved
< 3; numsaved
++) {
247 p
->unlockpc
[numsaved
] = fp
[2];
254 #endif /* SIGNAL_DEBUG */
255 #endif /* DIAGNOSTIC */
257 /* TBD: check p last arg */
258 return(lockmgr((struct lock__bsd__
*)&p
->signal_lock
[0], LK_RELEASE
, (simple_lock_t
)0, (struct proc
*)0));
262 signal_setast(sig_actthread
)
263 thread_t sig_actthread
;
265 act_set_astbsd(sig_actthread
);
269 * Can process p, with ucred uc, send the signal signum to process q?
272 cansignal(p
, uc
, q
, signum
)
278 /* you can signal yourself */
282 if (!suser(uc
, NULL
))
283 return (1); /* root can always signal */
285 if (signum
== SIGCONT
&& q
->p_session
== p
->p_session
)
286 return (1); /* SIGCONT in session */
289 * Using kill(), only certain signals can be sent to setugid
292 if (q
->p_flag
& P_SUGID
) {
305 if (uc
->cr_ruid
== q
->p_ucred
->cr_ruid
||
306 kauth_cred_getuid(uc
) == q
->p_ucred
->cr_ruid
||
307 uc
->cr_ruid
== kauth_cred_getuid(q
->p_ucred
) ||
308 kauth_cred_getuid(uc
) == kauth_cred_getuid(q
->p_ucred
))
315 * because the P_SUGID test exists, this has extra tests which
318 if (uc
->cr_ruid
== q
->p_ucred
->cr_ruid
||
319 uc
->cr_ruid
== q
->p_ucred
->cr_svuid
||
320 kauth_cred_getuid(uc
) == q
->p_ucred
->cr_ruid
||
321 kauth_cred_getuid(uc
) == q
->p_ucred
->cr_svuid
||
322 uc
->cr_ruid
== kauth_cred_getuid(q
->p_ucred
) ||
323 kauth_cred_getuid(uc
) == kauth_cred_getuid(q
->p_ucred
))
331 sigaction(struct proc
*p
, register struct sigaction_args
*uap
, __unused register_t
*retval
)
333 struct user_sigaction vec
;
334 struct __user_sigaction __vec
;
336 struct user_sigaction
*sa
= &vec
;
337 register struct sigacts
*ps
= p
->p_sigacts
;
342 signum
= uap
->signum
;
343 if (signum
<= 0 || signum
>= NSIG
||
344 signum
== SIGKILL
|| signum
== SIGSTOP
)
348 sa
->sa_handler
= ps
->ps_sigact
[signum
];
349 sa
->sa_mask
= ps
->ps_catchmask
[signum
];
350 bit
= sigmask(signum
);
352 if ((ps
->ps_sigonstack
& bit
) != 0)
353 sa
->sa_flags
|= SA_ONSTACK
;
354 if ((ps
->ps_sigintr
& bit
) == 0)
355 sa
->sa_flags
|= SA_RESTART
;
356 if (ps
->ps_siginfo
& bit
)
357 sa
->sa_flags
|= SA_SIGINFO
;
358 if (ps
->ps_signodefer
& bit
)
359 sa
->sa_flags
|= SA_NODEFER
;
360 if (ps
->ps_64regset
& bit
)
361 sa
->sa_flags
|= SA_64REGSET
;
362 if ((signum
== SIGCHLD
) && (p
->p_flag
& P_NOCLDSTOP
))
363 sa
->sa_flags
|= SA_NOCLDSTOP
;
364 if ((signum
== SIGCHLD
) && (p
->p_flag
& P_NOCLDWAIT
))
365 sa
->sa_flags
|= SA_NOCLDWAIT
;
367 if (IS_64BIT_PROCESS(p
)) {
368 error
= copyout(sa
, uap
->osa
, sizeof(struct user_sigaction
));
370 struct sigaction vec32
;
371 sigaction_64to32(sa
, &vec32
);
372 error
= copyout(&vec32
, uap
->osa
, sizeof(struct sigaction
));
378 if (IS_64BIT_PROCESS(p
)) {
379 error
= copyin(uap
->nsa
, &__vec
, sizeof(struct __user_sigaction
));
381 struct __sigaction __vec32
;
382 error
= copyin(uap
->nsa
, &__vec32
, sizeof(struct __sigaction
));
383 __sigaction_32to64(&__vec32
, &__vec
);
387 error
= setsigvec(p
, signum
, &__vec
);
392 /* Routines to manipulate bits on all threads */
394 clear_procsiglist(struct proc
*p
, int bit
)
396 struct uthread
* uth
;
401 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
402 thact
= p
->p_vforkact
;
403 uth
= (struct uthread
*)get_bsdthread_info(thact
);
405 uth
->uu_siglist
&= ~bit
;
407 p
->p_siglist
&= ~bit
;
412 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
413 uth
->uu_siglist
&= ~bit
;
415 p
->p_siglist
&= ~bit
;
422 unblock_procsigmask(struct proc
*p
, int bit
)
424 struct uthread
* uth
;
428 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
429 thact
= p
->p_vforkact
;
430 uth
= (struct uthread
*)get_bsdthread_info(thact
);
432 uth
->uu_sigmask
&= ~bit
;
434 p
->p_sigmask
&= ~bit
;
438 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
439 uth
->uu_sigmask
&= ~bit
;
441 p
->p_sigmask
&= ~bit
;
448 block_procsigmask(struct proc
*p
, int bit
)
450 struct uthread
* uth
;
454 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
455 thact
= p
->p_vforkact
;
456 uth
= (struct uthread
*)get_bsdthread_info(thact
);
458 uth
->uu_sigmask
|= bit
;
464 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
465 uth
->uu_sigmask
|= bit
;
473 set_procsigmask(struct proc
*p
, int bit
)
475 struct uthread
* uth
;
479 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
480 thact
= p
->p_vforkact
;
481 uth
= (struct uthread
*)get_bsdthread_info(thact
);
483 uth
->uu_sigmask
= bit
;
489 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
490 uth
->uu_sigmask
= bit
;
497 /* XXX should be static? */
499 setsigvec(struct proc
*p
, int signum
, struct __user_sigaction
*sa
)
501 register struct sigacts
*ps
= p
->p_sigacts
;
504 if ((signum
== SIGKILL
|| signum
== SIGSTOP
) &&
505 sa
->sa_handler
!= SIG_DFL
)
507 bit
= sigmask(signum
);
509 * Change setting atomically.
511 ps
->ps_sigact
[signum
] = sa
->sa_handler
;
512 ps
->ps_trampact
[signum
] = sa
->sa_tramp
;
513 ps
->ps_catchmask
[signum
] = sa
->sa_mask
&~ sigcantmask
;
514 if (sa
->sa_flags
& SA_SIGINFO
)
515 ps
->ps_siginfo
|= bit
;
517 ps
->ps_siginfo
&= ~bit
;
518 if (sa
->sa_flags
& SA_64REGSET
)
519 ps
->ps_64regset
|= bit
;
521 ps
->ps_64regset
&= ~bit
;
522 if ((sa
->sa_flags
& SA_RESTART
) == 0)
523 ps
->ps_sigintr
|= bit
;
525 ps
->ps_sigintr
&= ~bit
;
526 if (sa
->sa_flags
& SA_ONSTACK
)
527 ps
->ps_sigonstack
|= bit
;
529 ps
->ps_sigonstack
&= ~bit
;
530 if (sa
->sa_flags
& SA_USERTRAMP
)
531 ps
->ps_usertramp
|= bit
;
533 ps
->ps_usertramp
&= ~bit
;
534 if (sa
->sa_flags
& SA_RESETHAND
)
535 ps
->ps_sigreset
|= bit
;
537 ps
->ps_sigreset
&= ~bit
;
538 if (sa
->sa_flags
& SA_NODEFER
)
539 ps
->ps_signodefer
|= bit
;
541 ps
->ps_signodefer
&= ~bit
;
542 if (signum
== SIGCHLD
) {
543 if (sa
->sa_flags
& SA_NOCLDSTOP
)
544 p
->p_flag
|= P_NOCLDSTOP
;
546 p
->p_flag
&= ~P_NOCLDSTOP
;
547 if ((sa
->sa_flags
& SA_NOCLDWAIT
) || (sa
->sa_handler
== SIG_IGN
))
548 p
->p_flag
|= P_NOCLDWAIT
;
550 p
->p_flag
&= ~P_NOCLDWAIT
;
554 if (signum
== SIGFPE
) {
555 if (sa
->sa_handler
== SIG_DFL
|| sa
->sa_handler
== SIG_IGN
)
556 thread_enable_fpe(current_thread(), 0);
558 thread_enable_fpe(current_thread(), 1);
562 * Set bit in p_sigignore for signals that are set to SIG_IGN,
563 * and for signals set to SIG_DFL where the default is to ignore.
564 * However, don't put SIGCONT in p_sigignore,
565 * as we have to restart the process.
567 if (sa
->sa_handler
== SIG_IGN
||
568 (sigprop
[signum
] & SA_IGNORE
&& sa
->sa_handler
== SIG_DFL
)) {
570 clear_procsiglist(p
, bit
);
571 if (signum
!= SIGCONT
)
572 p
->p_sigignore
|= bit
; /* easier in psignal */
573 p
->p_sigcatch
&= ~bit
;
575 p
->p_sigignore
&= ~bit
;
576 if (sa
->sa_handler
== SIG_DFL
)
577 p
->p_sigcatch
&= ~bit
;
579 p
->p_sigcatch
|= bit
;
585 * Initialize signal state for process 0;
586 * set to ignore signals that are ignored by default.
594 for (i
= 0; i
< NSIG
; i
++)
595 if (sigprop
[i
] & SA_IGNORE
&& i
!= SIGCONT
)
596 p
->p_sigignore
|= sigmask(i
);
600 * Reset signals for an exec of the specified process.
604 register struct proc
*p
;
605 register thread_t thr_act
;
607 register struct sigacts
*ps
= p
->p_sigacts
;
608 register int nc
, mask
;
612 * Reset caught signals. Held signals remain held
613 * through p_sigmask (unless they were caught,
614 * and are now ignored by default).
616 while (p
->p_sigcatch
) {
617 nc
= ffs((long)p
->p_sigcatch
);
619 p
->p_sigcatch
&= ~mask
;
620 if (sigprop
[nc
] & SA_IGNORE
) {
622 p
->p_sigignore
|= mask
;
624 ut
= (struct uthread
*)get_bsdthread_info(thr_act
);
625 ut
->uu_siglist
&= ~mask
;
626 p
->p_siglist
&= ~mask
;
628 clear_procsiglist(p
, mask
);
630 ps
->ps_sigact
[nc
] = SIG_DFL
;
633 * Reset stack state to the user stack.
634 * Clear set of signals caught on the signal stack.
636 ps
->ps_sigstk
.ss_flags
= SA_DISABLE
;
637 ps
->ps_sigstk
.ss_size
= 0;
638 ps
->ps_sigstk
.ss_sp
= USER_ADDR_NULL
;
643 * Manipulate signal mask.
644 * Note that we receive new mask, not pointer,
645 * and return old mask as return value;
646 * the library stub does the rest.
649 sigprocmask(register struct proc
*p
, struct sigprocmask_args
*uap
, __unused register_t
*retval
)
652 sigset_t oldmask
, nmask
;
653 user_addr_t omask
= uap
->omask
;
656 ut
= (struct uthread
*)get_bsdthread_info(current_thread());
657 oldmask
= ut
->uu_sigmask
;
659 if (uap
->mask
== USER_ADDR_NULL
) {
660 /* just want old mask */
663 error
= copyin(uap
->mask
, &nmask
, sizeof(sigset_t
));
669 block_procsigmask(p
, (nmask
& ~sigcantmask
));
670 signal_setast(current_thread());
674 unblock_procsigmask(p
, (nmask
& ~sigcantmask
));
675 signal_setast(current_thread());
679 set_procsigmask(p
, (nmask
& ~sigcantmask
));
680 signal_setast(current_thread());
688 if (!error
&& omask
!= USER_ADDR_NULL
)
689 copyout(&oldmask
, omask
, sizeof(sigset_t
));
694 sigpending(__unused
struct proc
*p
, register struct sigpending_args
*uap
, __unused register_t
*retval
)
699 ut
= (struct uthread
*)get_bsdthread_info(current_thread());
700 pendlist
= ut
->uu_siglist
;
703 copyout(&pendlist
, uap
->osv
, sizeof(sigset_t
));
709 * Suspend process until signal, providing mask to be set
710 * in the meantime. Note nonstandard calling convention:
711 * libc stub passes mask, not pointer, to save a copyin.
715 sigcontinue(__unused
int error
)
717 // struct uthread *ut = get_bsdthread_info(current_thread());
718 unix_syscall_return(EINTR
);
722 sigsuspend(register struct proc
*p
, struct sigsuspend_args
*uap
, __unused register_t
*retval
)
726 ut
= (struct uthread
*)get_bsdthread_info(current_thread());
729 * When returning from sigpause, we want
730 * the old mask to be restored after the
731 * signal handler has finished. Thus, we
732 * save it here and mark the sigacts structure
735 ut
->uu_oldmask
= ut
->uu_sigmask
;
736 ut
->uu_flag
|= UT_SAS_OLDMASK
;
737 ut
->uu_sigmask
= (uap
->mask
& ~sigcantmask
);
738 (void) tsleep0((caddr_t
) p
, PPAUSE
|PCATCH
, "pause", 0, sigcontinue
);
739 /* always return EINTR rather than ERESTART... */
745 __disable_threadsignal(struct proc
*p
,
746 __unused
register struct __disable_threadsignal_args
*uap
,
747 __unused register_t
*retval
)
751 uth
= (struct uthread
*)get_bsdthread_info(current_thread());
753 /* No longer valid to have any signal delivered */
755 uth
->uu_flag
|= UT_NO_SIGMASK
;
764 __pthread_markcancel(p
, uap
, retval
)
766 register struct __pthread_markcancel_args
*uap
;
769 thread_act_t target_act
;
773 target_act
= (thread_act_t
)port_name_to_thread(uap
->thread_port
);
775 if (target_act
== THR_ACT_NULL
)
778 uth
= (struct uthread
*)get_bsdthread_info(target_act
);
780 /* if the thread is in vfork do not cancel */
781 if ((uth
->uu_flag
& (P_VFORK
| UT_CANCEL
| UT_CANCELED
)) == 0) {
782 uth
->uu_flag
|= (UT_CANCEL
| UT_NO_SIGMASK
);
783 if (((uth
->uu_flag
& UT_NOTCANCELPT
) == 0)
784 && ((uth
->uu_flag
& UT_CANCELDISABLE
) == 0))
785 thread_abort_safely(target_act
);
788 thread_deallocate(target_act
);
792 /* if action =0 ; return the cancellation state ,
793 * if marked for cancellation, make the thread canceled
794 * if action = 1 ; Enable the cancel handling
795 * if action = 2; Disable the cancel handling
798 __pthread_canceled(p
, uap
, retval
)
800 register struct __pthread_canceled_args
*uap
;
803 thread_act_t thr_act
;
805 int action
= uap
->action
;
807 thr_act
= current_act();
808 uth
= (struct uthread
*)get_bsdthread_info(thr_act
);
812 uth
->uu_flag
&= ~UT_CANCELDISABLE
;
815 uth
->uu_flag
|= UT_CANCELDISABLE
;
819 /* if the thread is in vfork do not cancel */
820 if((uth
->uu_flag
& ( UT_CANCELDISABLE
| UT_CANCEL
| UT_CANCELED
)) == UT_CANCEL
) {
821 uth
->uu_flag
&= ~UT_CANCEL
;
822 uth
->uu_flag
|= (UT_CANCELED
| UT_NO_SIGMASK
);
831 __posix_sem_syscall_return(kern_return_t kern_result
)
835 if (kern_result
== KERN_SUCCESS
)
837 else if (kern_result
== KERN_ABORTED
)
839 else if (kern_result
== KERN_OPERATION_TIMED_OUT
)
843 unix_syscall_return(error
);
844 /* does not return */
849 __semwait_signal(p
, uap
, retval
)
851 register struct __semwait_signal_args
*uap
;
855 kern_return_t kern_result
;
856 mach_timespec_t then
;
862 then
.tv_sec
= uap
->tv_sec
;
863 then
.tv_nsec
= uap
->tv_nsec
;
866 then
.tv_sec
= uap
->tv_sec
- now
.tv_sec
;
867 then
.tv_nsec
= uap
->tv_nsec
- now
.tv_nsec
;
868 if (then
.tv_nsec
< 0) {
869 then
.tv_nsec
+= NSEC_PER_SEC
;
874 if (uap
->mutex_sem
== (void *)NULL
)
875 kern_result
= semaphore_timedwait_trap_internal(uap
->cond_sem
, then
.tv_sec
, then
.tv_nsec
, __posix_sem_syscall_return
);
877 kern_result
= semaphore_timedwait_signal_trap_internal(uap
->cond_sem
, uap
->mutex_sem
, then
.tv_sec
, then
.tv_nsec
, __posix_sem_syscall_return
);
881 if (uap
->mutex_sem
== (void *)NULL
)
882 kern_result
= semaphore_wait_trap_internal(uap
->cond_sem
, __posix_sem_syscall_return
);
885 kern_result
= semaphore_wait_signal_trap_internal(uap
->cond_sem
, uap
->mutex_sem
, __posix_sem_syscall_return
);
889 if (kern_result
== KERN_SUCCESS
)
891 else if (kern_result
== KERN_ABORTED
)
893 else if (kern_result
== KERN_OPERATION_TIMED_OUT
)
901 __pthread_kill(__unused
struct proc
*p
,
902 register struct __pthread_kill_args
*uap
,
903 __unused register_t
*retval
)
907 int signum
= uap
->sig
;
910 target_act
= (thread_t
)port_name_to_thread(uap
->thread_port
);
912 if (target_act
== THREAD_NULL
)
914 if ((u_int
)signum
>= NSIG
) {
919 uth
= (struct uthread
*)get_bsdthread_info(target_act
);
921 if (uth
->uu_flag
& UT_NO_SIGMASK
) {
927 psignal_uthread(target_act
, signum
);
929 thread_deallocate(target_act
);
935 pthread_sigmask(__unused
register struct proc
*p
,
936 register struct pthread_sigmask_args
*uap
,
937 __unused register_t
*retval
)
939 user_addr_t set
= uap
->set
;
940 user_addr_t oset
= uap
->oset
;
946 ut
= (struct uthread
*)get_bsdthread_info(current_thread());
947 oldset
= ut
->uu_sigmask
;
949 if (set
== USER_ADDR_NULL
) {
950 /* need only old mask */
954 error
= copyin(set
, &nset
, sizeof(sigset_t
));
960 ut
->uu_sigmask
|= (nset
& ~sigcantmask
);
964 ut
->uu_sigmask
&= ~(nset
);
965 signal_setast(current_thread());
969 ut
->uu_sigmask
= (nset
& ~sigcantmask
);
970 signal_setast(current_thread());
978 if (!error
&& oset
!= USER_ADDR_NULL
)
979 copyout(&oldset
, oset
, sizeof(sigset_t
));
986 sigwait(register struct proc
*p
, register struct sigwait_args
*uap
, __unused register_t
*retval
)
996 ut
= (struct uthread
*)get_bsdthread_info(current_thread());
998 if (uap
->set
== USER_ADDR_NULL
)
1001 error
= copyin(uap
->set
, &mask
, sizeof(sigset_t
));
1005 siglist
= (mask
& ~sigcantmask
);
1011 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
1015 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
1016 if ( (sigw
= uth
->uu_siglist
& siglist
) ) {
1023 /* The signal was pending on a thread */
1027 * When returning from sigwait, we want
1028 * the old mask to be restored after the
1029 * signal handler has finished. Thus, we
1030 * save it here and mark the sigacts structure
1033 ut
->uu_oldmask
= ut
->uu_sigmask
;
1034 ut
->uu_flag
|= UT_SAS_OLDMASK
;
1035 if (siglist
== (sigset_t
)0)
1037 /* SIGKILL and SIGSTOP are not maskable as well */
1038 ut
->uu_sigmask
= ~(siglist
|sigcantmask
);
1039 ut
->uu_sigwait
= siglist
;
1040 /* No Continuations for now */
1041 error
= tsleep((caddr_t
)&ut
->uu_sigwait
, PPAUSE
|PCATCH
, "pause", 0);
1043 if ((error
== EINTR
) || (error
== ERESTART
))
1046 sigw
= (ut
->uu_sigwait
& siglist
);
1047 ut
->uu_sigmask
= ut
->uu_oldmask
;
1049 ut
->uu_flag
&= ~UT_SAS_OLDMASK
;
1053 signum
= ffs((unsigned int)sigw
);
1055 panic("sigwait with no signal wakeup");
1056 ut
->uu_siglist
&= ~(sigmask(signum
));
1057 if (uap
->sig
!= USER_ADDR_NULL
)
1058 error
= copyout(&signum
, uap
->sig
, sizeof(int));
1067 sigaltstack(struct proc
*p
, register struct sigaltstack_args
*uap
, __unused register_t
*retval
)
1069 struct sigacts
*psp
;
1070 struct user_sigaltstack ss
;
1074 if ((psp
->ps_flags
& SAS_ALTSTACK
) == 0)
1075 psp
->ps_sigstk
.ss_flags
|= SA_DISABLE
;
1077 if (IS_64BIT_PROCESS(p
)) {
1078 error
= copyout(&psp
->ps_sigstk
, uap
->oss
, sizeof(struct user_sigaltstack
));
1080 struct sigaltstack ss32
;
1081 sigaltstack_64to32(&psp
->ps_sigstk
, &ss32
);
1082 error
= copyout(&ss32
, uap
->oss
, sizeof(struct sigaltstack
));
1087 if (uap
->nss
== USER_ADDR_NULL
)
1089 if (IS_64BIT_PROCESS(p
)) {
1090 error
= copyin(uap
->nss
, &ss
, sizeof(struct user_sigaltstack
));
1092 struct sigaltstack ss32
;
1093 error
= copyin(uap
->nss
, &ss32
, sizeof(struct sigaltstack
));
1094 sigaltstack_32to64(&ss32
,&ss
);
1098 if ((ss
.ss_flags
& ~SA_DISABLE
) != 0) {
1102 if (ss
.ss_flags
& SA_DISABLE
) {
1103 if (psp
->ps_sigstk
.ss_flags
& SA_ONSTACK
)
1105 psp
->ps_flags
&= ~SAS_ALTSTACK
;
1106 psp
->ps_sigstk
.ss_flags
= ss
.ss_flags
;
1109 /* The older stacksize was 8K, enforce that one so no compat problems */
1110 #define OLDMINSIGSTKSZ 8*1024
1111 if (ss
.ss_size
< OLDMINSIGSTKSZ
)
1113 psp
->ps_flags
|= SAS_ALTSTACK
;
1119 kill(struct proc
*cp
, struct kill_args
*uap
, __unused register_t
*retval
)
1121 register struct proc
*p
;
1122 kauth_cred_t uc
= kauth_cred_get();
1124 AUDIT_ARG(pid
, uap
->pid
);
1125 AUDIT_ARG(signum
, uap
->signum
);
1127 if ((u_int
)uap
->signum
>= NSIG
)
1130 /* kill single process */
1131 if ((p
= proc_findref(uap
->pid
)) == NULL
) {
1132 if ((p
= pzfind(uap
->pid
)) != NULL
) {
1134 * IEEE Std 1003.1-2001: return success
1135 * when killing a zombie.
1141 AUDIT_ARG(process
, p
);
1142 if (!cansignal(cp
, uc
, p
, uap
->signum
)) {
1147 psignal(p
, uap
->signum
);
1152 case -1: /* broadcast signal */
1153 return (killpg1(cp
, uap
->signum
, 0, 1));
1154 case 0: /* signal own process group */
1155 return (killpg1(cp
, uap
->signum
, 0, 0));
1156 default: /* negative explicit process group */
1157 return (killpg1(cp
, uap
->signum
, -(uap
->pid
), 0));
1164 * Common code for kill process group/broadcast kill.
1165 * cp is calling process.
1168 killpg1(cp
, signum
, pgid
, all
)
1169 register struct proc
*cp
;
1170 int signum
, pgid
, all
;
1172 register struct proc
*p
;
1173 kauth_cred_t uc
= cp
->p_ucred
;
1181 for (p
= allproc
.lh_first
; p
!= 0; p
= p
->p_list
.le_next
) {
1182 if (p
->p_pid
<= 1 || p
->p_flag
& P_SYSTEM
||
1183 p
== cp
|| !cansignal(cp
, uc
, p
, signum
))
1192 * zero pgid means send to my process group.
1196 pgrp
= pgfind(pgid
);
1200 for (p
= pgrp
->pg_members
.lh_first
; p
!= 0;
1201 p
= p
->p_pglist
.le_next
) {
1202 if (p
->p_pid
<= 1 || p
->p_flag
& P_SYSTEM
||
1203 p
->p_stat
== SZOMB
||
1204 !cansignal(cp
, uc
, p
, signum
))
1211 return (nfound
? 0 : ESRCH
);
1215 * Send a signal to a process group.
1218 gsignal(pgid
, signum
)
1223 if (pgid
&& (pgrp
= pgfind(pgid
)))
1224 pgsignal(pgrp
, signum
, 0);
1228 * Send a signal to a process group. If checktty is 1,
1229 * limit to members which have a controlling terminal.
1232 pgsignal(pgrp
, signum
, checkctty
)
1234 int signum
, checkctty
;
1236 register struct proc
*p
;
1239 for (p
= pgrp
->pg_members
.lh_first
; p
!= 0;
1240 p
= p
->p_pglist
.le_next
)
1241 if (checkctty
== 0 || p
->p_flag
& P_CONTROLT
)
1246 * Send signal to a backgrounded process blocked due to tty access
1247 * In FreeBSD, the backgrounded process wakes up every second and
1248 * discovers whether it is foregounded or not. In our case, we block
1249 * the thread in tsleep as we want to avoid storm of processes as well
1250 * as the suspend is only at AST level
1253 tty_pgsignal(pgrp
, signum
)
1257 register struct proc
*p
;
1260 for (p
= pgrp
->pg_members
.lh_first
; p
!= 0;
1261 p
= p
->p_pglist
.le_next
)
1262 if ((p
->p_flag
& P_TTYSLEEP
) && (p
->p_flag
& P_CONTROLT
))
1267 * Send a signal caused by a trap to a specific thread.
1270 threadsignal(thread_t sig_actthread
, int signum
, u_long code
)
1272 register struct uthread
*uth
;
1273 register struct task
* sig_task
;
1274 register struct proc
*p
;
1277 if ((u_int
)signum
>= NSIG
|| signum
== 0)
1280 mask
= sigmask(signum
);
1281 if ((mask
& threadmask
) == 0)
1283 sig_task
= get_threadtask(sig_actthread
);
1284 p
= (struct proc
*)(get_bsdtask_info(sig_task
));
1286 uth
= get_bsdthread_info(sig_actthread
);
1287 if (uth
&& (uth
->uu_flag
& UT_VFORK
))
1290 if (!(p
->p_flag
& P_TRACED
) && (p
->p_sigignore
& mask
))
1293 uth
->uu_siglist
|= mask
;
1294 p
->p_siglist
|= mask
; /* just for lame ones looking here */
1295 uth
->uu_code
= code
;
1296 /* mark on process as well */
1297 signal_setast(sig_actthread
);
1303 register struct proc
*p
;
1304 register int signum
;
1306 psignal_lock(p
, signum
, 1);
1310 psignal_vfork(struct proc
*p
, task_t new_task
, thread_t thr_act
, int signum
)
1313 register sig_t action
;
1315 struct uthread
*uth
;
1317 if ((u_int
)signum
>= NSIG
|| signum
== 0)
1318 panic("psignal signal number");
1319 mask
= sigmask(signum
);
1320 prop
= sigprop
[signum
];
1323 if(rdebug_proc
&& (p
== rdebug_proc
)) {
1326 #endif /* SIGNAL_DEBUG */
1328 if ((new_task
== TASK_NULL
) || (thr_act
== (thread_t
)NULL
) || is_kerneltask(new_task
))
1332 uth
= get_bsdthread_info(thr_act
);
1336 * proc is traced, always give parent a chance.
1340 if (p
->p_nice
> NZERO
&& action
== SIG_DFL
&& (prop
& SA_KILL
) &&
1341 (p
->p_flag
& P_TRACED
) == 0)
1344 if (prop
& SA_CONT
) {
1345 p
->p_siglist
&= ~stopsigmask
;
1346 uth
->uu_siglist
&= ~stopsigmask
;
1349 if (prop
& SA_STOP
) {
1351 * If sending a tty stop signal to a member of an orphaned
1352 * process group, discard the signal here if the action
1353 * is default; don't stop the process below if sleeping,
1354 * and don't clear any pending SIGCONT.
1356 if (prop
& SA_TTYSTOP
&& p
->p_pgrp
->pg_jobc
== 0 &&
1359 uth
->uu_siglist
&= ~contsigmask
;
1360 p
->p_siglist
&= ~contsigmask
;
1362 uth
->uu_siglist
|= mask
;
1363 p
->p_siglist
|= mask
; /* just for lame ones looking here */
1365 /* Deliver signal to the activation passed in */
1366 act_set_astbsd(thr_act
);
1369 * SIGKILL priority twiddling moved here from above because
1370 * it needs sig_thread. Could merge it into large switch
1371 * below if we didn't care about priority for tracing
1372 * as SIGKILL's action is always SIG_DFL.
1374 if ((signum
== SIGKILL
) && (p
->p_nice
> NZERO
)) {
1379 * This Process is traced - wake it up (if not already
1380 * stopped) so that it can discover the signal in
1381 * issig() and stop for the parent.
1383 if (p
->p_flag
& P_TRACED
) {
1384 if (p
->p_stat
!= SSTOP
)
1391 * If we're being traced (possibly because someone attached us
1392 * while we were stopped), check for a signal from the debugger.
1394 if (p
->p_stat
== SSTOP
) {
1395 if ((p
->p_flag
& P_TRACED
) != 0 && p
->p_xstat
!= 0) {
1396 uth
->uu_siglist
|= sigmask(p
->p_xstat
);
1397 p
->p_siglist
|= mask
; /* just for lame ones looking here */
1402 * setrunnable(p) in BSD
1411 get_signalthread(struct proc
*p
, int signum
)
1413 struct uthread
*uth
;
1415 sigset_t mask
= sigmask(signum
);
1416 thread_t sig_thread_act
;
1417 struct task
* sig_task
= p
->task
;
1420 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
1421 sig_thread_act
= p
->p_vforkact
;
1422 kret
= check_actforsig(sig_task
, sig_thread_act
, 1);
1423 if (kret
== KERN_SUCCESS
)
1424 return(sig_thread_act
);
1426 return(THREAD_NULL
);
1429 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
1430 if(((uth
->uu_flag
& UT_NO_SIGMASK
)== 0) &&
1431 (((uth
->uu_sigmask
& mask
) == 0) || (uth
->uu_sigwait
& mask
))) {
1432 if (check_actforsig(p
->task
, uth
->uu_act
, 1) == KERN_SUCCESS
)
1433 return(uth
->uu_act
);
1436 if (get_signalact(p
->task
, &thr_act
, 1) == KERN_SUCCESS
) {
1440 return(THREAD_NULL
);
1444 * Send the signal to the process. If the signal has an action, the action
1445 * is usually performed by the target process rather than the caller; we add
1446 * the signal to the set of pending signals for the process.
1449 * o When a stop signal is sent to a sleeping process that takes the
1450 * default action, the process is stopped without awakening it.
1451 * o SIGCONT restarts stopped processes (or puts them back to sleep)
1452 * regardless of the signal action (eg, blocked or ignored).
1454 * Other ignored signals are discarded immediately.
1457 psignal_lock(p
, signum
, withlock
)
1458 register struct proc
*p
;
1459 register int signum
;
1460 register int withlock
;
1462 register int s
, prop
;
1463 register sig_t action
;
1464 thread_t sig_thread_act
;
1465 register task_t sig_task
;
1467 struct uthread
*uth
;
1468 boolean_t funnel_state
= FALSE
;
1471 if ((u_int
)signum
>= NSIG
|| signum
== 0)
1472 panic("psignal signal number");
1473 mask
= sigmask(signum
);
1474 prop
= sigprop
[signum
];
1477 if(rdebug_proc
&& (p
== rdebug_proc
)) {
1480 #endif /* SIGNAL_DEBUG */
1482 if (thread_funnel_get() == (funnel_t
*)0) {
1484 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
1487 * We will need the task pointer later. Grab it now to
1488 * check for a zombie process. Also don't send signals
1489 * to kernel internal tasks.
1491 if (((sig_task
= p
->task
) == TASK_NULL
) || is_kerneltask(sig_task
)) {
1493 thread_funnel_set(kernel_flock
, funnel_state
);
1498 KNOTE(&p
->p_klist
, NOTE_SIGNAL
| signum
);
1502 * do not send signals to the process that has the thread
1503 * doing a reboot(). Not doing so will mark that thread aborted
1504 * and can cause IO failures wich will cause data loss.
1506 if (ISSET(p
->p_flag
, P_REBOOT
)) {
1508 thread_funnel_set(kernel_flock
, funnel_state
);
1516 * Deliver the signal to the first thread in the task. This
1517 * allows single threaded applications which use signals to
1518 * be able to be linked with multithreaded libraries. We have
1519 * an implicit reference to the current thread, but need
1520 * an explicit one otherwise. The thread reference keeps
1521 * the corresponding task data structures around too. This
1522 * reference is released by thread_deallocate.
1525 if (((p
->p_flag
& P_TRACED
) == 0) && (p
->p_sigignore
& mask
))
1528 /* If successful return with ast set */
1529 sig_thread_act
= get_signalthread(p
, signum
);
1531 if (sig_thread_act
== THREAD_NULL
) {
1533 * if it is sigkill, may be we should
1534 * inject a thread to terminate
1538 #endif /* SIGNAL_DEBUG */
1542 uth
= get_bsdthread_info(sig_thread_act
);
1545 * If proc is traced, always give parent a chance.
1547 if (p
->p_flag
& P_TRACED
)
1551 * If the signal is being ignored,
1552 * then we forget about it immediately.
1553 * (Note: we don't set SIGCONT in p_sigignore,
1554 * and if it is set to SIG_IGN,
1555 * action will be SIG_DFL here.)
1557 if (p
->p_sigignore
& mask
)
1559 /* sigwait takes precedence */
1560 if (uth
->uu_sigwait
& mask
)
1561 action
= KERN_SIG_WAIT
;
1562 else if (uth
->uu_sigmask
& mask
)
1563 action
= KERN_SIG_HOLD
;
1564 else if (p
->p_sigcatch
& mask
)
1565 action
= KERN_SIG_CATCH
;
1570 if (p
->p_nice
> NZERO
&& action
== SIG_DFL
&& (prop
& SA_KILL
) &&
1571 (p
->p_flag
& P_TRACED
) == 0)
1574 if (prop
& SA_CONT
) {
1575 uth
->uu_siglist
&= ~stopsigmask
;
1576 p
->p_siglist
&= ~stopsigmask
;
1579 if (prop
& SA_STOP
) {
1581 * If sending a tty stop signal to a member of an orphaned
1582 * process group, discard the signal here if the action
1583 * is default; don't stop the process below if sleeping,
1584 * and don't clear any pending SIGCONT.
1586 if (prop
& SA_TTYSTOP
&& p
->p_pgrp
->pg_jobc
== 0 &&
1589 uth
->uu_siglist
&= ~contsigmask
;
1590 p
->p_siglist
&= ~contsigmask
;
1592 uth
->uu_siglist
|= mask
;
1593 p
->p_siglist
|= mask
; /* just for lame ones looking here */
1597 * Defer further processing for signals which are held,
1598 * except that stopped processes must be continued by SIGCONT.
1600 if (action
== KERN_SIG_HOLD
&& ((prop
& SA_CONT
) == 0 || p
->p_stat
!= SSTOP
)) {
1604 * SIGKILL priority twiddling moved here from above because
1605 * it needs sig_thread. Could merge it into large switch
1606 * below if we didn't care about priority for tracing
1607 * as SIGKILL's action is always SIG_DFL.
1609 if ((signum
== SIGKILL
) && (p
->p_nice
> NZERO
)) {
1614 * Process is traced - wake it up (if not already
1615 * stopped) so that it can discover the signal in
1616 * issig() and stop for the parent.
1618 if (p
->p_flag
& P_TRACED
) {
1619 if (p
->p_stat
!= SSTOP
)
1625 if (action
== KERN_SIG_WAIT
) {
1626 uth
->uu_sigwait
= mask
;
1627 uth
->uu_siglist
&= ~mask
;
1628 p
->p_siglist
&= ~mask
;
1629 wakeup(&uth
->uu_sigwait
);
1630 /* if it is SIGCONT resume whole process */
1631 if (prop
& SA_CONT
) {
1632 p
->p_flag
|= P_CONTINUED
;
1633 (void) task_resume(sig_task
);
1638 if (action
!= SIG_DFL
) {
1640 * User wants to catch the signal.
1641 * Wake up the thread, but don't un-suspend it
1642 * (except for SIGCONT).
1644 if (prop
& SA_CONT
) {
1645 if (p
->p_flag
& P_TTYSLEEP
) {
1646 p
->p_flag
&= ~P_TTYSLEEP
;
1647 wakeup(&p
->p_siglist
);
1649 p
->p_flag
|= P_CONTINUED
;
1650 (void) task_resume(sig_task
);
1653 } else if (p
->p_stat
== SSTOP
)
1657 /* Default action - varies */
1658 if (mask
& stopsigmask
) {
1660 * These are the signals which by default
1663 * Don't clog system with children of init
1664 * stopped from the keyboard.
1666 if (!(prop
& SA_STOP
) && p
->p_pptr
== initproc
) {
1667 psignal_lock(p
, SIGKILL
, 0);
1668 uth
->uu_siglist
&= ~mask
;
1669 p
->p_siglist
&= ~mask
;
1675 * if task hasn't already been stopped by
1678 uth
->uu_siglist
&= ~mask
;
1679 p
->p_siglist
&= ~mask
;
1680 if (p
->p_stat
!= SSTOP
) {
1681 p
->p_xstat
= signum
;
1683 if ((p
->p_pptr
->p_flag
& P_NOCLDSTOP
) == 0) {
1684 struct proc
*pp
= p
->p_pptr
;
1686 pp
->si_pid
= p
->p_pid
;
1687 pp
->si_status
= p
->p_xstat
;
1688 pp
->si_code
= CLD_STOPPED
;
1689 pp
->si_uid
= p
->p_ucred
->cr_ruid
;
1690 psignal(pp
, SIGCHLD
);
1698 * Signals ignored by default have been dealt
1699 * with already, since their bits are on in
1705 * Kill signal always sets process running and
1709 * Process will be running after 'run'
1713 thread_abort(sig_thread_act
);
1719 * Let the process run. If it's sleeping on an
1720 * event, it remains so.
1722 if (p
->p_flag
& P_TTYSLEEP
) {
1723 p
->p_flag
&= ~P_TTYSLEEP
;
1724 wakeup(&p
->p_siglist
);
1726 p
->p_flag
|= P_CONTINUED
;
1727 (void) task_resume(sig_task
);
1729 uth
->uu_siglist
&= ~mask
;
1730 p
->p_siglist
&= ~mask
;
1737 * All other signals wake up the process, but don't
1740 if (p
->p_stat
== SSTOP
)
1748 * If we're being traced (possibly because someone attached us
1749 * while we were stopped), check for a signal from the debugger.
1751 if (p
->p_stat
== SSTOP
) {
1752 if ((p
->p_flag
& P_TRACED
) != 0 && p
->p_xstat
!= 0)
1753 uth
->uu_siglist
|= sigmask(p
->p_xstat
);
1756 * setrunnable(p) in BSD and
1757 * Wake up the thread if it is interruptible.
1760 thread_abort_safely(sig_thread_act
);
1766 thread_funnel_set(kernel_flock
, funnel_state
);
1770 /* psignal_lock(p, signum, withlock ) */
1772 psignal_uthread(thr_act
, signum
)
1778 register sig_t action
;
1779 thread_t sig_thread_act
;
1780 register task_t sig_task
;
1782 struct uthread
*uth
;
1786 p
= (struct proc
*)get_bsdtask_info(get_threadtask(thr_act
));
1787 if ((u_int
)signum
>= NSIG
|| signum
== 0)
1788 panic("Invalid signal number in psignal_uthread");
1789 mask
= sigmask(signum
);
1790 prop
= sigprop
[signum
];
1793 if(rdebug_proc
&& (p
== rdebug_proc
)) {
1796 #endif /* SIGNAL_DEBUG */
1799 * We will need the task pointer later. Grab it now to
1800 * check for a zombie process. Also don't send signals
1801 * to kernel internal tasks.
1803 if (((sig_task
= p
->task
) == TASK_NULL
) || is_kerneltask(sig_task
)) {
1807 sig_thread_act
= thr_act
;
1809 * do not send signals to the process that has the thread
1810 * doing a reboot(). Not doing so will mark that thread aborted
1811 * and can cause IO failures wich will cause data loss.
1813 if (ISSET(p
->p_flag
, P_REBOOT
)) {
1820 * Deliver the signal to the first thread in the task. This
1821 * allows single threaded applications which use signals to
1822 * be able to be linked with multithreaded libraries. We have
1823 * an implicit reference to the current thread, but need
1824 * an explicit one otherwise. The thread reference keeps
1825 * the corresponding task data structures around too. This
1826 * reference is released by thread_deallocate.
1829 if (((p
->p_flag
& P_TRACED
) == 0) && (p
->p_sigignore
& mask
))
1832 kret
= check_actforsig(sig_task
, sig_thread_act
, 1);
1834 if (kret
!= KERN_SUCCESS
) {
1840 uth
= get_bsdthread_info(sig_thread_act
);
1843 * If proc is traced, always give parent a chance.
1845 if (p
->p_flag
& P_TRACED
)
1849 * If the signal is being ignored,
1850 * then we forget about it immediately.
1851 * (Note: we don't set SIGCONT in p_sigignore,
1852 * and if it is set to SIG_IGN,
1853 * action will be SIG_DFL here.)
1855 if (p
->p_sigignore
& mask
)
1857 /* sigwait takes precedence */
1858 if (uth
->uu_sigwait
& mask
)
1859 action
= KERN_SIG_WAIT
;
1860 else if (uth
->uu_sigmask
& mask
)
1861 action
= KERN_SIG_HOLD
;
1862 else if (p
->p_sigcatch
& mask
)
1863 action
= KERN_SIG_CATCH
;
1868 if (p
->p_nice
> NZERO
&& action
== SIG_DFL
&& (prop
& SA_KILL
) &&
1869 (p
->p_flag
& P_TRACED
) == 0)
1872 if (prop
& SA_CONT
) {
1873 uth
->uu_siglist
&= ~stopsigmask
;
1874 p
->p_siglist
&= ~stopsigmask
;
1877 if (prop
& SA_STOP
) {
1879 * If sending a tty stop signal to a member of an orphaned
1880 * process group, discard the signal here if the action
1881 * is default; don't stop the process below if sleeping,
1882 * and don't clear any pending SIGCONT.
1884 if (prop
& SA_TTYSTOP
&& p
->p_pgrp
->pg_jobc
== 0 &&
1887 uth
->uu_siglist
&= ~contsigmask
;
1888 p
->p_siglist
&= ~contsigmask
;
1890 uth
->uu_siglist
|= mask
;
1891 p
->p_siglist
|= mask
; /* just for lame ones looking here */
1894 * Defer further processing for signals which are held,
1895 * except that stopped processes must be continued by SIGCONT.
1897 if (action
== KERN_SIG_HOLD
&& ((prop
& SA_CONT
) == 0 || p
->p_stat
!= SSTOP
))
1901 * SIGKILL priority twiddling moved here from above because
1902 * it needs sig_thread. Could merge it into large switch
1903 * below if we didn't care about priority for tracing
1904 * as SIGKILL's action is always SIG_DFL.
1906 if ((signum
== SIGKILL
) && (p
->p_nice
> NZERO
)) {
1911 * Process is traced - wake it up (if not already
1912 * stopped) so that it can discover the signal in
1913 * issig() and stop for the parent.
1915 if (p
->p_flag
& P_TRACED
) {
1916 if (p
->p_stat
!= SSTOP
)
1922 if (action
== KERN_SIG_WAIT
) {
1923 uth
->uu_sigwait
= mask
;
1924 uth
->uu_siglist
&= ~mask
;
1925 p
->p_siglist
&= ~mask
;
1926 wakeup(&uth
->uu_sigwait
);
1927 /* if it is SIGCONT resume whole process */
1928 if (prop
& SA_CONT
) {
1929 p
->p_flag
|= P_CONTINUED
;
1930 (void) task_resume(sig_task
);
1935 if (action
!= SIG_DFL
) {
1937 * User wants to catch the signal.
1938 * Wake up the thread, but don't un-suspend it
1939 * (except for SIGCONT).
1941 if (prop
& SA_CONT
) {
1942 p
->p_flag
|= P_CONTINUED
;
1943 (void) task_resume(sig_task
);
1947 /* Default action - varies */
1948 if (mask
& stopsigmask
) {
1950 * These are the signals which by default
1953 * Don't clog system with children of init
1954 * stopped from the keyboard.
1956 if (!(prop
& SA_STOP
) && p
->p_pptr
== initproc
) {
1957 psignal_lock(p
, SIGKILL
, 0);
1958 uth
->uu_siglist
&= ~mask
;
1959 p
->p_siglist
&= ~mask
;
1965 * if task hasn't already been stopped by
1968 uth
->uu_siglist
&= ~mask
;
1969 p
->p_siglist
&= ~mask
;
1970 if (p
->p_stat
!= SSTOP
) {
1971 p
->p_xstat
= signum
;
1972 if ((p
->p_pptr
->p_flag
& P_NOCLDSTOP
) == 0) {
1973 struct proc
*pp
= p
->p_pptr
;
1975 pp
->si_pid
= p
->p_pid
;
1976 pp
->si_status
= p
->p_xstat
;
1977 pp
->si_code
= CLD_STOPPED
;
1978 pp
->si_uid
= p
->p_ucred
->cr_ruid
;
1979 psignal(pp
, SIGCHLD
);
1988 * Signals ignored by default have been dealt
1989 * with already, since their bits are on in
1995 * Kill signal always sets process running and
1999 * Process will be running after 'run'
2003 thread_abort(sig_thread_act
);
2009 * Let the process run. If it's sleeping on an
2010 * event, it remains so.
2012 if (p
->p_flag
& P_TTYSLEEP
) {
2013 p
->p_flag
&= ~P_TTYSLEEP
;
2014 wakeup(&p
->p_siglist
);
2016 p
->p_flag
|= P_CONTINUED
;
2017 (void) task_resume(sig_task
);
2019 uth
->uu_siglist
&= ~mask
;
2020 p
->p_siglist
&= ~mask
;
2026 * All other signals wake up the process, but don't
2035 * If we're being traced (possibly because someone attached us
2036 * while we were stopped), check for a signal from the debugger.
2038 if (p
->p_stat
== SSTOP
) {
2039 if ((p
->p_flag
& P_TRACED
) != 0 && p
->p_xstat
!= 0) {
2040 uth
->uu_siglist
|= sigmask(p
->p_xstat
);
2041 p
->p_siglist
|= sigmask(p
->p_xstat
);
2045 * setrunnable(p) in BSD and
2046 * Wake up the thread if it is interruptible.
2049 thread_abort_safely(sig_thread_act
);
2058 sig_lock_to_exit(struct proc
*p
)
2060 thread_t self
= current_thread();
2062 p
->exit_thread
= self
;
2063 (void) task_suspend(p
->task
);
2067 sig_try_locked(struct proc
*p
)
2069 thread_t self
= current_thread();
2071 while (p
->sigwait
|| p
->exit_thread
) {
2072 if (p
->exit_thread
) {
2073 if (p
->exit_thread
!= self
) {
2075 * Already exiting - no signals.
2081 if(assert_wait_possible()) {
2082 assert_wait((caddr_t
)&p
->sigwait_thread
,
2083 (THREAD_INTERRUPTIBLE
));
2086 thread_block(THREAD_CONTINUE_NULL
);
2088 if (thread_should_abort(self
)) {
2090 * Terminate request - clean up.
2099 * If the current process has received a signal (should be caught or cause
2100 * termination, should interrupt current syscall), return the signal number.
2101 * Stop signals with default action are processed immediately, then cleared;
2102 * they aren't returned. This is checked after each entry to the system for
2103 * a syscall or trap (though this can usually be done without calling issignal
2104 * by checking the pending signal masks in the CURSIG macro.) The normal call
2107 * while (signum = CURSIG(curproc))
2112 register struct proc
*p
;
2114 register int signum
, mask
, prop
, sigbits
;
2116 struct uthread
* ut
;
2119 cur_act
= current_thread();
2122 if(rdebug_proc
&& (p
== rdebug_proc
)) {
2125 #endif /* SIGNAL_DEBUG */
2129 * Try to grab the signal lock.
2131 if (sig_try_locked(p
) <= 0) {
2136 ut
= get_bsdthread_info(cur_act
);
2138 sigbits
= ut
->uu_siglist
& ~ut
->uu_sigmask
;
2140 if (p
->p_flag
& P_PPWAIT
)
2141 sigbits
&= ~stopsigmask
;
2142 if (sigbits
== 0) { /* no signal to send */
2146 signum
= ffs((long)sigbits
);
2147 mask
= sigmask(signum
);
2148 prop
= sigprop
[signum
];
2151 * We should see pending but ignored signals
2152 * only if P_TRACED was on when they were posted.
2154 if (mask
& p
->p_sigignore
&& (p
->p_flag
& P_TRACED
) == 0) {
2155 ut
->uu_siglist
&= ~mask
; /* take the signal! */
2156 p
->p_siglist
&= ~mask
; /* take the signal! */
2159 if (p
->p_flag
& P_TRACED
&& (p
->p_flag
& P_PPWAIT
) == 0) {
2160 register task_t task
;
2162 * If traced, always stop, and stay
2163 * stopped until released by the debugger.
2165 /* ptrace debugging */
2166 p
->p_xstat
= signum
;
2168 if (p
->p_flag
& P_SIGEXC
) {
2170 p
->sigwait_thread
= cur_act
;
2172 p
->p_flag
&= ~(P_WAITED
|P_CONTINUED
);
2173 ut
->uu_siglist
&= ~mask
; /* clear the old signal */
2174 p
->p_siglist
&= ~mask
; /* clear the old signal */
2176 do_bsdexception(EXC_SOFTWARE
, EXC_SOFT_SIGNAL
, signum
);
2179 // panic("Unsupportef gdb option \n");;
2180 pp
->si_pid
= p
->p_pid
;
2181 pp
->si_status
= p
->p_xstat
;
2182 pp
->si_code
= CLD_TRAPPED
;
2183 pp
->si_uid
= p
->p_ucred
->cr_ruid
;
2184 psignal(pp
, SIGCHLD
);
2186 * XXX Have to really stop for debuggers;
2187 * XXX stop() doesn't do the right thing.
2188 * XXX Inline the task_suspend because we
2189 * XXX have to diddle Unix state in the
2195 p
->sigwait_thread
= cur_act
;
2197 p
->p_flag
&= ~(P_WAITED
|P_CONTINUED
);
2198 ut
->uu_siglist
&= ~mask
; /* clear the old signal */
2199 p
->p_siglist
&= ~mask
; /* clear the old signal */
2201 wakeup((caddr_t
)p
->p_pptr
);
2203 assert_wait((caddr_t
)&p
->sigwait
, (THREAD_INTERRUPTIBLE
));
2204 thread_block(THREAD_CONTINUE_NULL
);
2209 p
->sigwait_thread
= NULL
;
2210 wakeup((caddr_t
)&p
->sigwait_thread
);
2213 * This code is to detect when gdb is killed
2214 * even as the traced program is attached.
2215 * pgsignal would get the SIGKILL to traced program
2216 * That's what we are trying to see (I hope)
2218 if (ut
->uu_siglist
& sigmask(SIGKILL
)) {
2220 * Wait event may still be outstanding;
2221 * clear it, since sig_lock_to_exit will
2224 clear_wait(current_thread(), THREAD_INTERRUPTED
);
2225 sig_lock_to_exit(p
);
2227 * Since this thread will be resumed
2228 * to allow the current syscall to
2229 * be completed, must save u_qsave
2230 * before calling exit(). (Since exit()
2231 * calls closef() which can trash u_qsave.)
2234 exit1(p
,signum
, (int *)NULL
);
2239 * We may have to quit
2241 if (thread_should_abort(current_thread())) {
2246 * If parent wants us to take the signal,
2247 * then it will leave it in p->p_xstat;
2248 * otherwise we just look for signals again.
2250 signum
= p
->p_xstat
;
2254 * Put the new signal into p_siglist. If the
2255 * signal is being masked, look for other signals.
2257 mask
= sigmask(signum
);
2258 ut
->uu_siglist
|= mask
;
2259 p
->p_siglist
|= mask
; /* just for lame ones looking here */
2260 if (ut
->uu_sigmask
& mask
)
2265 * Decide whether the signal should be returned.
2266 * Return the signal's number, or fall through
2267 * to clear it from the pending mask.
2270 switch ((long)p
->p_sigacts
->ps_sigact
[signum
]) {
2274 * Don't take default actions on system processes.
2276 if (p
->p_pptr
->p_pid
== 0) {
2279 * Are you sure you want to ignore SIGSEGV
2282 printf("Process (pid %d) got signal %d\n",
2285 break; /* == ignore */
2289 * If there is a pending stop signal to process
2290 * with default action, stop here,
2291 * then clear the signal. However,
2292 * if process is member of an orphaned
2293 * process group, ignore tty stop signals.
2295 if (prop
& SA_STOP
) {
2296 if (p
->p_flag
& P_TRACED
||
2297 (p
->p_pgrp
->pg_jobc
== 0 &&
2299 break; /* == ignore */
2300 if (p
->p_stat
!= SSTOP
) {
2301 p
->p_xstat
= signum
;
2303 if ((p
->p_pptr
->p_flag
& P_NOCLDSTOP
) == 0) {
2305 pp
->si_pid
= p
->p_pid
;
2306 pp
->si_status
= p
->p_xstat
;
2307 pp
->si_code
= CLD_STOPPED
;
2308 pp
->si_uid
= p
->p_ucred
->cr_ruid
;
2309 psignal(pp
, SIGCHLD
);
2313 } else if (prop
& SA_IGNORE
) {
2315 * Except for SIGCONT, shouldn't get here.
2316 * Default action is to ignore; drop it.
2318 break; /* == ignore */
2320 ut
->uu_siglist
&= ~mask
; /* take the signal! */
2321 p
->p_siglist
&= ~mask
; /* take the signal! */
2329 * Masking above should prevent us ever trying
2330 * to take action on an ignored signal other
2331 * than SIGCONT, unless process is traced.
2333 if ((prop
& SA_CONT
) == 0 &&
2334 (p
->p_flag
& P_TRACED
) == 0)
2335 printf("issignal\n");
2336 break; /* == ignore */
2340 * This signal has an action, let
2341 * postsig() process it.
2343 ut
->uu_siglist
&= ~mask
; /* take the signal! */
2344 p
->p_siglist
&= ~mask
; /* take the signal! */
2348 ut
->uu_siglist
&= ~mask
; /* take the signal! */
2349 p
->p_siglist
&= ~mask
; /* take the signal! */
2354 /* called from _sleep */
2357 register struct proc
*p
;
2359 register int signum
, mask
, prop
, sigbits
;
2361 struct uthread
* ut
;
2365 cur_act
= current_thread();
2367 ut
= get_bsdthread_info(cur_act
);
2369 if (ut
->uu_siglist
== 0)
2372 if (((ut
->uu_siglist
& ~ut
->uu_sigmask
) == 0) && ((p
->p_flag
& P_TRACED
) == 0))
2375 sigbits
= ut
->uu_siglist
& ~ut
->uu_sigmask
;
2378 if (p
->p_flag
& P_PPWAIT
)
2379 sigbits
&= ~stopsigmask
;
2380 if (sigbits
== 0) { /* no signal to send */
2384 signum
= ffs((long)sigbits
);
2385 mask
= sigmask(signum
);
2386 prop
= sigprop
[signum
];
2389 * We should see pending but ignored signals
2390 * only if P_TRACED was on when they were posted.
2392 if (mask
& p
->p_sigignore
&& (p
->p_flag
& P_TRACED
) == 0) {
2395 if (p
->p_flag
& P_TRACED
&& (p
->p_flag
& P_PPWAIT
) == 0) {
2397 * Put the new signal into p_siglist. If the
2398 * signal is being masked, look for other signals.
2400 mask
= sigmask(signum
);
2401 if (ut
->uu_sigmask
& mask
)
2407 * Decide whether the signal should be returned.
2408 * Return the signal's number, or fall through
2409 * to clear it from the pending mask.
2412 switch ((long)p
->p_sigacts
->ps_sigact
[signum
]) {
2416 * Don't take default actions on system processes.
2418 if (p
->p_pptr
->p_pid
== 0) {
2421 * Are you sure you want to ignore SIGSEGV
2424 printf("Process (pid %d) got signal %d\n",
2427 break; /* == ignore */
2431 * If there is a pending stop signal to process
2432 * with default action, stop here,
2433 * then clear the signal. However,
2434 * if process is member of an orphaned
2435 * process group, ignore tty stop signals.
2437 if (prop
& SA_STOP
) {
2438 if (p
->p_flag
& P_TRACED
||
2439 (p
->p_pgrp
->pg_jobc
== 0 &&
2441 break; /* == ignore */
2444 } else if (prop
& SA_IGNORE
) {
2446 * Except for SIGCONT, shouldn't get here.
2447 * Default action is to ignore; drop it.
2449 break; /* == ignore */
2457 * Masking above should prevent us ever trying
2458 * to take action on an ignored signal other
2459 * than SIGCONT, unless process is traced.
2461 if ((prop
& SA_CONT
) == 0 &&
2462 (p
->p_flag
& P_TRACED
) == 0)
2463 printf("issignal\n");
2464 break; /* == ignore */
2468 * This signal has an action, let
2469 * postsig() process it.
2473 sigbits
&= ~mask
; /* take the signal! */
2479 * Put the argument process into the stopped state and notify the parent
2480 * via wakeup. Signals are handled elsewhere. The process must not be
2485 register struct proc
*p
;
2488 p
->p_flag
&= ~(P_WAITED
|P_CONTINUED
);
2489 if (p
->p_pptr
->p_stat
!= SSTOP
)
2490 wakeup((caddr_t
)p
->p_pptr
);
2491 (void) task_suspend(p
->task
); /*XXX*/
2495 * Take the action for the specified signal
2496 * from the current set of pending signals.
2501 struct proc
*p
= current_proc();
2502 struct sigacts
*ps
= p
->p_sigacts
;
2503 user_addr_t catcher
;
2505 int mask
, returnmask
;
2506 struct uthread
* ut
;
2512 * This must be called on master cpu
2514 if (cpu_number() != master_cpu
)
2515 panic("psig not on master");
2520 * Try to grab the signal lock.
2522 if (sig_try_locked(p
) <= 0) {
2527 ut
= (struct uthread
*)get_bsdthread_info(current_thread());
2528 mask
= sigmask(signum
);
2529 ut
->uu_siglist
&= ~mask
;
2530 p
->p_siglist
&= ~mask
;
2531 catcher
= ps
->ps_sigact
[signum
];
2533 //LP64: catcher argument is a 64 bit user space handler address
2534 if (KTRPOINT(p
, KTR_PSIG
))
2535 ktrpsig(p
->p_tracep
,
2536 signum
, CAST_DOWN(void *,catcher
), ut
->uu_flag
& UT_SAS_OLDMASK
?
2537 &ut
->uu_oldmask
: &ut
->uu_sigmask
, 0);
2539 if (catcher
== SIG_DFL
) {
2541 * Default catcher, where the default is to kill
2542 * the process. (Other cases were ignored above.)
2544 /* called with signal_lock() held */
2545 sigexit_locked(p
, signum
);
2550 * If we get here, the signal must be caught.
2553 if (catcher
== SIG_IGN
|| (ut
->uu_sigmask
& mask
))
2555 "postsig: processing masked or ignored signal\n");
2558 * Set the new mask value and also defer further
2559 * occurences of this signal.
2561 * Special case: user has done a sigpause. Here the
2562 * current mask is not of interest, but rather the
2563 * mask from before the sigpause is what we want
2564 * restored after the signal processing is completed.
2566 if (ut
->uu_flag
& UT_SAS_OLDMASK
) {
2567 returnmask
= ut
->uu_oldmask
;
2568 ut
->uu_flag
&= ~UT_SAS_OLDMASK
;
2571 returnmask
= ut
->uu_sigmask
;
2572 ut
->uu_sigmask
|= ps
->ps_catchmask
[signum
];
2573 if ((ps
->ps_signodefer
& mask
) == 0)
2574 ut
->uu_sigmask
|= mask
;
2575 if ((signum
!= SIGILL
) && (signum
!= SIGTRAP
) && (ps
->ps_sigreset
& mask
)) {
2576 if ((signum
!= SIGCONT
) && (sigprop
[signum
] & SA_IGNORE
))
2577 p
->p_sigignore
|= mask
;
2578 ps
->ps_sigact
[signum
] = SIG_DFL
;
2579 ps
->ps_siginfo
&= ~mask
;
2580 ps
->ps_signodefer
&= ~mask
;
2583 /* Needs to disable to run in user mode */
2584 if (signum
== SIGFPE
) {
2585 thread_enable_fpe(current_thread(), 0);
2587 #endif /* __ppc__ */
2589 if (ps
->ps_sig
!= signum
) {
2595 p
->p_stats
->p_ru
.ru_nsignals
++;
2596 sendsig(p
, catcher
, signum
, returnmask
, code
);
2602 * Force the current process to exit with the specified signal, dumping core
2603 * if appropriate. We bypass the normal tests for masked and caught signals,
2604 * allowing unrecoverable failures to terminate the process without changing
2605 * signal state. Mark the accounting record with the signal termination.
2606 * If dumping core, save the signal number for the debugger. Calls exit and
2609 /* called with signal lock */
2611 sigexit_locked(p
, signum
)
2612 register struct proc
*p
;
2616 sig_lock_to_exit(p
);
2617 p
->p_acflag
|= AXSIG
;
2618 if (sigprop
[signum
] & SA_CORE
) {
2619 p
->p_sigacts
->ps_sig
= signum
;
2621 if (coredump(p
) == 0)
2622 signum
|= WCOREFLAG
;
2626 exit1(p
, W_EXITCODE(0, signum
), (int *)NULL
);
2632 filt_sigattach(struct knote
*kn
)
2634 struct proc
*p
= current_proc();
2636 kn
->kn_ptr
.p_proc
= p
;
2637 kn
->kn_flags
|= EV_CLEAR
; /* automatically set */
2639 /* XXX lock the proc here while adding to the list? */
2640 KNOTE_ATTACH(&p
->p_klist
, kn
);
2646 filt_sigdetach(struct knote
*kn
)
2648 struct proc
*p
= kn
->kn_ptr
.p_proc
;
2650 KNOTE_DETACH(&p
->p_klist
, kn
);
2654 * signal knotes are shared with proc knotes, so we apply a mask to
2655 * the hint in order to differentiate them from process hints. This
2656 * could be avoided by using a signal-specific knote list, but probably
2657 * isn't worth the trouble.
2660 filt_signal(struct knote
*kn
, long hint
)
2663 if (hint
& NOTE_SIGNAL
) {
2664 hint
&= ~NOTE_SIGNAL
;
2666 if (kn
->kn_id
== (unsigned int)hint
)
2669 return (kn
->kn_data
!= 0);
2674 bsd_ast(thread_t thr_act
)
2676 struct proc
*p
= current_proc();
2677 struct uthread
*ut
= get_bsdthread_info(thr_act
);
2680 boolean_t funnel_state
;
2681 static int bsd_init_done
= 0;
2686 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
2688 if ((p
->p_flag
& P_OWEUPC
) && (p
->p_flag
& P_PROFIL
)) {
2689 pc
= get_useraddr();
2690 addupc_task(p
, pc
, 1);
2691 p
->p_flag
&= ~P_OWEUPC
;
2694 if (CHECK_SIGNALS(p
, current_thread(), ut
)) {
2695 while ( (signum
= issignal(p
)) )
2698 if (!bsd_init_done
) {
2703 (void) thread_funnel_set(kernel_flock
, FALSE
);
2707 * Follwing routines are called using callout from bsd_hardclock
2708 * so that psignals are called in a thread context and are funneled
2711 psignal_vtalarm(struct proc
*p
)
2713 boolean_t funnel_state
;
2717 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
2718 psignal_lock(p
, SIGVTALRM
, 1);
2719 (void) thread_funnel_set(kernel_flock
, FALSE
);
2723 psignal_xcpu(struct proc
*p
)
2725 boolean_t funnel_state
;
2729 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
2730 psignal_lock(p
, SIGXCPU
, 1);
2731 (void) thread_funnel_set(kernel_flock
, FALSE
);
2735 psignal_sigprof(struct proc
*p
)
2737 boolean_t funnel_state
;
2741 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
2742 psignal_lock(p
, SIGPROF
, 1);
2743 (void) thread_funnel_set(kernel_flock
, FALSE
);
2746 /* ptrace set runnalbe */
2748 pt_setrunnable(struct proc
*p
)
2754 if (p
->p_flag
& P_TRACED
) {
2757 wakeup((caddr_t
)&(p
->sigwait
));
2770 exception_data_type_t codes
[EXCEPTION_CODE_MAX
];
2774 return(bsd_exception(exc
, codes
, 2));
2778 proc_pendingsignals(struct proc
*p
, sigset_t mask
)
2780 struct uthread
* uth
;
2785 /* If the process is in proc exit return no signal info */
2786 if (p
->p_lflag
& P_LPEXIT
)
2789 /* duplicate the signal lock code to enable recursion; as exit
2790 * holds the lock too long. All this code is being reworked
2791 * this is just a workaround for regressions till new code
2795 error
= lockmgr((struct lock__bsd__
*)&p
->signal_lock
[0], (LK_EXCLUSIVE
| LK_CANRECURSE
), 0, (struct proc
*)0);
2799 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
2801 uth
= (struct uthread
*)get_bsdthread_info(th
);
2803 bits
= (((uth
->uu_siglist
& ~uth
->uu_sigmask
) & ~p
->p_sigignore
) & mask
);
2809 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
2810 bits
|= (((uth
->uu_siglist
& ~uth
->uu_sigmask
) & ~p
->p_sigignore
) & mask
);
2818 thread_issignal(proc_t p
, thread_t th
, sigset_t mask
)
2820 struct uthread
* uth
;
2824 uth
= (struct uthread
*)get_bsdthread_info(th
);
2826 bits
= (((uth
->uu_siglist
& ~uth
->uu_sigmask
) & ~p
->p_sigignore
) & mask
);