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
= pfind(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
))
1145 psignal(p
, uap
->signum
);
1149 case -1: /* broadcast signal */
1150 return (killpg1(cp
, uap
->signum
, 0, 1));
1151 case 0: /* signal own process group */
1152 return (killpg1(cp
, uap
->signum
, 0, 0));
1153 default: /* negative explicit process group */
1154 return (killpg1(cp
, uap
->signum
, -(uap
->pid
), 0));
1161 * Common code for kill process group/broadcast kill.
1162 * cp is calling process.
1165 killpg1(cp
, signum
, pgid
, all
)
1166 register struct proc
*cp
;
1167 int signum
, pgid
, all
;
1169 register struct proc
*p
;
1170 kauth_cred_t uc
= cp
->p_ucred
;
1178 for (p
= allproc
.lh_first
; p
!= 0; p
= p
->p_list
.le_next
) {
1179 if (p
->p_pid
<= 1 || p
->p_flag
& P_SYSTEM
||
1180 p
== cp
|| !cansignal(cp
, uc
, p
, signum
))
1189 * zero pgid means send to my process group.
1193 pgrp
= pgfind(pgid
);
1197 for (p
= pgrp
->pg_members
.lh_first
; p
!= 0;
1198 p
= p
->p_pglist
.le_next
) {
1199 if (p
->p_pid
<= 1 || p
->p_flag
& P_SYSTEM
||
1200 p
->p_stat
== SZOMB
||
1201 !cansignal(cp
, uc
, p
, signum
))
1208 return (nfound
? 0 : ESRCH
);
1212 * Send a signal to a process group.
1215 gsignal(pgid
, signum
)
1220 if (pgid
&& (pgrp
= pgfind(pgid
)))
1221 pgsignal(pgrp
, signum
, 0);
1225 * Send a signal to a process group. If checktty is 1,
1226 * limit to members which have a controlling terminal.
1229 pgsignal(pgrp
, signum
, checkctty
)
1231 int signum
, checkctty
;
1233 register struct proc
*p
;
1236 for (p
= pgrp
->pg_members
.lh_first
; p
!= 0;
1237 p
= p
->p_pglist
.le_next
)
1238 if (checkctty
== 0 || p
->p_flag
& P_CONTROLT
)
1243 * Send signal to a backgrounded process blocked due to tty access
1244 * In FreeBSD, the backgrounded process wakes up every second and
1245 * discovers whether it is foregounded or not. In our case, we block
1246 * the thread in tsleep as we want to avoid storm of processes as well
1247 * as the suspend is only at AST level
1250 tty_pgsignal(pgrp
, signum
)
1254 register struct proc
*p
;
1257 for (p
= pgrp
->pg_members
.lh_first
; p
!= 0;
1258 p
= p
->p_pglist
.le_next
)
1259 if ((p
->p_flag
& P_TTYSLEEP
) && (p
->p_flag
& P_CONTROLT
))
1264 * Send a signal caused by a trap to a specific thread.
1267 threadsignal(thread_t sig_actthread
, int signum
, u_long code
)
1269 register struct uthread
*uth
;
1270 register struct task
* sig_task
;
1271 register struct proc
*p
;
1274 if ((u_int
)signum
>= NSIG
|| signum
== 0)
1277 mask
= sigmask(signum
);
1278 if ((mask
& threadmask
) == 0)
1280 sig_task
= get_threadtask(sig_actthread
);
1281 p
= (struct proc
*)(get_bsdtask_info(sig_task
));
1283 uth
= get_bsdthread_info(sig_actthread
);
1284 if (uth
&& (uth
->uu_flag
& UT_VFORK
))
1287 if (!(p
->p_flag
& P_TRACED
) && (p
->p_sigignore
& mask
))
1290 uth
->uu_siglist
|= mask
;
1291 p
->p_siglist
|= mask
; /* just for lame ones looking here */
1292 uth
->uu_code
= code
;
1293 /* mark on process as well */
1294 signal_setast(sig_actthread
);
1300 register struct proc
*p
;
1301 register int signum
;
1303 psignal_lock(p
, signum
, 1);
1307 psignal_vfork(struct proc
*p
, task_t new_task
, thread_t thr_act
, int signum
)
1310 register sig_t action
;
1312 struct uthread
*uth
;
1314 if ((u_int
)signum
>= NSIG
|| signum
== 0)
1315 panic("psignal signal number");
1316 mask
= sigmask(signum
);
1317 prop
= sigprop
[signum
];
1320 if(rdebug_proc
&& (p
== rdebug_proc
)) {
1323 #endif /* SIGNAL_DEBUG */
1325 if ((new_task
== TASK_NULL
) || (thr_act
== (thread_t
)NULL
) || is_kerneltask(new_task
))
1329 uth
= get_bsdthread_info(thr_act
);
1333 * proc is traced, always give parent a chance.
1337 if (p
->p_nice
> NZERO
&& action
== SIG_DFL
&& (prop
& SA_KILL
) &&
1338 (p
->p_flag
& P_TRACED
) == 0)
1341 if (prop
& SA_CONT
) {
1342 p
->p_siglist
&= ~stopsigmask
;
1343 uth
->uu_siglist
&= ~stopsigmask
;
1346 if (prop
& SA_STOP
) {
1348 * If sending a tty stop signal to a member of an orphaned
1349 * process group, discard the signal here if the action
1350 * is default; don't stop the process below if sleeping,
1351 * and don't clear any pending SIGCONT.
1353 if (prop
& SA_TTYSTOP
&& p
->p_pgrp
->pg_jobc
== 0 &&
1356 uth
->uu_siglist
&= ~contsigmask
;
1357 p
->p_siglist
&= ~contsigmask
;
1359 uth
->uu_siglist
|= mask
;
1360 p
->p_siglist
|= mask
; /* just for lame ones looking here */
1362 /* Deliver signal to the activation passed in */
1363 act_set_astbsd(thr_act
);
1366 * SIGKILL priority twiddling moved here from above because
1367 * it needs sig_thread. Could merge it into large switch
1368 * below if we didn't care about priority for tracing
1369 * as SIGKILL's action is always SIG_DFL.
1371 if ((signum
== SIGKILL
) && (p
->p_nice
> NZERO
)) {
1376 * This Process is traced - wake it up (if not already
1377 * stopped) so that it can discover the signal in
1378 * issig() and stop for the parent.
1380 if (p
->p_flag
& P_TRACED
) {
1381 if (p
->p_stat
!= SSTOP
)
1388 * If we're being traced (possibly because someone attached us
1389 * while we were stopped), check for a signal from the debugger.
1391 if (p
->p_stat
== SSTOP
) {
1392 if ((p
->p_flag
& P_TRACED
) != 0 && p
->p_xstat
!= 0) {
1393 uth
->uu_siglist
|= sigmask(p
->p_xstat
);
1394 p
->p_siglist
|= mask
; /* just for lame ones looking here */
1399 * setrunnable(p) in BSD
1408 get_signalthread(struct proc
*p
, int signum
)
1410 struct uthread
*uth
;
1412 sigset_t mask
= sigmask(signum
);
1413 thread_t sig_thread_act
;
1414 struct task
* sig_task
= p
->task
;
1417 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
1418 sig_thread_act
= p
->p_vforkact
;
1419 kret
= check_actforsig(sig_task
, sig_thread_act
, 1);
1420 if (kret
== KERN_SUCCESS
)
1421 return(sig_thread_act
);
1423 return(THREAD_NULL
);
1426 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
1427 if(((uth
->uu_flag
& UT_NO_SIGMASK
)== 0) &&
1428 (((uth
->uu_sigmask
& mask
) == 0) || (uth
->uu_sigwait
& mask
))) {
1429 if (check_actforsig(p
->task
, uth
->uu_act
, 1) == KERN_SUCCESS
)
1430 return(uth
->uu_act
);
1433 if (get_signalact(p
->task
, &thr_act
, 1) == KERN_SUCCESS
) {
1437 return(THREAD_NULL
);
1441 * Send the signal to the process. If the signal has an action, the action
1442 * is usually performed by the target process rather than the caller; we add
1443 * the signal to the set of pending signals for the process.
1446 * o When a stop signal is sent to a sleeping process that takes the
1447 * default action, the process is stopped without awakening it.
1448 * o SIGCONT restarts stopped processes (or puts them back to sleep)
1449 * regardless of the signal action (eg, blocked or ignored).
1451 * Other ignored signals are discarded immediately.
1454 psignal_lock(p
, signum
, withlock
)
1455 register struct proc
*p
;
1456 register int signum
;
1457 register int withlock
;
1459 register int s
, prop
;
1460 register sig_t action
;
1461 thread_t sig_thread_act
;
1462 register task_t sig_task
;
1464 struct uthread
*uth
;
1465 boolean_t funnel_state
= FALSE
;
1468 if ((u_int
)signum
>= NSIG
|| signum
== 0)
1469 panic("psignal signal number");
1470 mask
= sigmask(signum
);
1471 prop
= sigprop
[signum
];
1474 if(rdebug_proc
&& (p
== rdebug_proc
)) {
1477 #endif /* SIGNAL_DEBUG */
1479 if (thread_funnel_get() == (funnel_t
*)0) {
1481 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
1484 * We will need the task pointer later. Grab it now to
1485 * check for a zombie process. Also don't send signals
1486 * to kernel internal tasks.
1488 if (((sig_task
= p
->task
) == TASK_NULL
) || is_kerneltask(sig_task
)) {
1490 thread_funnel_set(kernel_flock
, funnel_state
);
1495 KNOTE(&p
->p_klist
, NOTE_SIGNAL
| signum
);
1499 * do not send signals to the process that has the thread
1500 * doing a reboot(). Not doing so will mark that thread aborted
1501 * and can cause IO failures wich will cause data loss.
1503 if (ISSET(p
->p_flag
, P_REBOOT
)) {
1505 thread_funnel_set(kernel_flock
, funnel_state
);
1513 * Deliver the signal to the first thread in the task. This
1514 * allows single threaded applications which use signals to
1515 * be able to be linked with multithreaded libraries. We have
1516 * an implicit reference to the current thread, but need
1517 * an explicit one otherwise. The thread reference keeps
1518 * the corresponding task data structures around too. This
1519 * reference is released by thread_deallocate.
1522 if (((p
->p_flag
& P_TRACED
) == 0) && (p
->p_sigignore
& mask
))
1525 /* If successful return with ast set */
1526 sig_thread_act
= get_signalthread(p
, signum
);
1528 if (sig_thread_act
== THREAD_NULL
) {
1530 * if it is sigkill, may be we should
1531 * inject a thread to terminate
1535 #endif /* SIGNAL_DEBUG */
1539 uth
= get_bsdthread_info(sig_thread_act
);
1542 * If proc is traced, always give parent a chance.
1544 if (p
->p_flag
& P_TRACED
)
1548 * If the signal is being ignored,
1549 * then we forget about it immediately.
1550 * (Note: we don't set SIGCONT in p_sigignore,
1551 * and if it is set to SIG_IGN,
1552 * action will be SIG_DFL here.)
1554 if (p
->p_sigignore
& mask
)
1556 /* sigwait takes precedence */
1557 if (uth
->uu_sigwait
& mask
)
1558 action
= KERN_SIG_WAIT
;
1559 else if (uth
->uu_sigmask
& mask
)
1560 action
= KERN_SIG_HOLD
;
1561 else if (p
->p_sigcatch
& mask
)
1562 action
= KERN_SIG_CATCH
;
1567 if (p
->p_nice
> NZERO
&& action
== SIG_DFL
&& (prop
& SA_KILL
) &&
1568 (p
->p_flag
& P_TRACED
) == 0)
1571 if (prop
& SA_CONT
) {
1572 uth
->uu_siglist
&= ~stopsigmask
;
1573 p
->p_siglist
&= ~stopsigmask
;
1576 if (prop
& SA_STOP
) {
1578 * If sending a tty stop signal to a member of an orphaned
1579 * process group, discard the signal here if the action
1580 * is default; don't stop the process below if sleeping,
1581 * and don't clear any pending SIGCONT.
1583 if (prop
& SA_TTYSTOP
&& p
->p_pgrp
->pg_jobc
== 0 &&
1586 uth
->uu_siglist
&= ~contsigmask
;
1587 p
->p_siglist
&= ~contsigmask
;
1589 uth
->uu_siglist
|= mask
;
1590 p
->p_siglist
|= mask
; /* just for lame ones looking here */
1594 * Defer further processing for signals which are held,
1595 * except that stopped processes must be continued by SIGCONT.
1597 if (action
== KERN_SIG_HOLD
&& ((prop
& SA_CONT
) == 0 || p
->p_stat
!= SSTOP
)) {
1601 * SIGKILL priority twiddling moved here from above because
1602 * it needs sig_thread. Could merge it into large switch
1603 * below if we didn't care about priority for tracing
1604 * as SIGKILL's action is always SIG_DFL.
1606 if ((signum
== SIGKILL
) && (p
->p_nice
> NZERO
)) {
1611 * Process is traced - wake it up (if not already
1612 * stopped) so that it can discover the signal in
1613 * issig() and stop for the parent.
1615 if (p
->p_flag
& P_TRACED
) {
1616 if (p
->p_stat
!= SSTOP
)
1622 if (action
== KERN_SIG_WAIT
) {
1623 uth
->uu_sigwait
= mask
;
1624 uth
->uu_siglist
&= ~mask
;
1625 p
->p_siglist
&= ~mask
;
1626 wakeup(&uth
->uu_sigwait
);
1627 /* if it is SIGCONT resume whole process */
1628 if (prop
& SA_CONT
) {
1629 p
->p_flag
|= P_CONTINUED
;
1630 (void) task_resume(sig_task
);
1635 if (action
!= SIG_DFL
) {
1637 * User wants to catch the signal.
1638 * Wake up the thread, but don't un-suspend it
1639 * (except for SIGCONT).
1641 if (prop
& SA_CONT
) {
1642 if (p
->p_flag
& P_TTYSLEEP
) {
1643 p
->p_flag
&= ~P_TTYSLEEP
;
1644 wakeup(&p
->p_siglist
);
1646 p
->p_flag
|= P_CONTINUED
;
1647 (void) task_resume(sig_task
);
1650 } else if (p
->p_stat
== SSTOP
)
1654 /* Default action - varies */
1655 if (mask
& stopsigmask
) {
1657 * These are the signals which by default
1660 * Don't clog system with children of init
1661 * stopped from the keyboard.
1663 if (!(prop
& SA_STOP
) && p
->p_pptr
== initproc
) {
1664 psignal_lock(p
, SIGKILL
, 0);
1665 uth
->uu_siglist
&= ~mask
;
1666 p
->p_siglist
&= ~mask
;
1672 * if task hasn't already been stopped by
1675 uth
->uu_siglist
&= ~mask
;
1676 p
->p_siglist
&= ~mask
;
1677 if (p
->p_stat
!= SSTOP
) {
1678 p
->p_xstat
= signum
;
1680 if ((p
->p_pptr
->p_flag
& P_NOCLDSTOP
) == 0) {
1681 struct proc
*pp
= p
->p_pptr
;
1683 pp
->si_pid
= p
->p_pid
;
1684 pp
->si_status
= p
->p_xstat
;
1685 pp
->si_code
= CLD_STOPPED
;
1686 pp
->si_uid
= p
->p_ucred
->cr_ruid
;
1687 psignal(pp
, SIGCHLD
);
1695 * Signals ignored by default have been dealt
1696 * with already, since their bits are on in
1702 * Kill signal always sets process running and
1706 * Process will be running after 'run'
1710 thread_abort(sig_thread_act
);
1716 * Let the process run. If it's sleeping on an
1717 * event, it remains so.
1719 if (p
->p_flag
& P_TTYSLEEP
) {
1720 p
->p_flag
&= ~P_TTYSLEEP
;
1721 wakeup(&p
->p_siglist
);
1723 p
->p_flag
|= P_CONTINUED
;
1724 (void) task_resume(sig_task
);
1726 uth
->uu_siglist
&= ~mask
;
1727 p
->p_siglist
&= ~mask
;
1734 * All other signals wake up the process, but don't
1737 if (p
->p_stat
== SSTOP
)
1745 * If we're being traced (possibly because someone attached us
1746 * while we were stopped), check for a signal from the debugger.
1748 if (p
->p_stat
== SSTOP
) {
1749 if ((p
->p_flag
& P_TRACED
) != 0 && p
->p_xstat
!= 0)
1750 uth
->uu_siglist
|= sigmask(p
->p_xstat
);
1753 * setrunnable(p) in BSD and
1754 * Wake up the thread if it is interruptible.
1757 thread_abort_safely(sig_thread_act
);
1763 thread_funnel_set(kernel_flock
, funnel_state
);
1767 /* psignal_lock(p, signum, withlock ) */
1769 psignal_uthread(thr_act
, signum
)
1775 register sig_t action
;
1776 thread_t sig_thread_act
;
1777 register task_t sig_task
;
1779 struct uthread
*uth
;
1783 p
= (struct proc
*)get_bsdtask_info(get_threadtask(thr_act
));
1784 if ((u_int
)signum
>= NSIG
|| signum
== 0)
1785 panic("Invalid signal number in psignal_uthread");
1786 mask
= sigmask(signum
);
1787 prop
= sigprop
[signum
];
1790 if(rdebug_proc
&& (p
== rdebug_proc
)) {
1793 #endif /* SIGNAL_DEBUG */
1796 * We will need the task pointer later. Grab it now to
1797 * check for a zombie process. Also don't send signals
1798 * to kernel internal tasks.
1800 if (((sig_task
= p
->task
) == TASK_NULL
) || is_kerneltask(sig_task
)) {
1804 sig_thread_act
= thr_act
;
1806 * do not send signals to the process that has the thread
1807 * doing a reboot(). Not doing so will mark that thread aborted
1808 * and can cause IO failures wich will cause data loss.
1810 if (ISSET(p
->p_flag
, P_REBOOT
)) {
1817 * Deliver the signal to the first thread in the task. This
1818 * allows single threaded applications which use signals to
1819 * be able to be linked with multithreaded libraries. We have
1820 * an implicit reference to the current thread, but need
1821 * an explicit one otherwise. The thread reference keeps
1822 * the corresponding task data structures around too. This
1823 * reference is released by thread_deallocate.
1826 if (((p
->p_flag
& P_TRACED
) == 0) && (p
->p_sigignore
& mask
))
1829 kret
= check_actforsig(sig_task
, sig_thread_act
, 1);
1831 if (kret
!= KERN_SUCCESS
) {
1837 uth
= get_bsdthread_info(sig_thread_act
);
1840 * If proc is traced, always give parent a chance.
1842 if (p
->p_flag
& P_TRACED
)
1846 * If the signal is being ignored,
1847 * then we forget about it immediately.
1848 * (Note: we don't set SIGCONT in p_sigignore,
1849 * and if it is set to SIG_IGN,
1850 * action will be SIG_DFL here.)
1852 if (p
->p_sigignore
& mask
)
1854 /* sigwait takes precedence */
1855 if (uth
->uu_sigwait
& mask
)
1856 action
= KERN_SIG_WAIT
;
1857 else if (uth
->uu_sigmask
& mask
)
1858 action
= KERN_SIG_HOLD
;
1859 else if (p
->p_sigcatch
& mask
)
1860 action
= KERN_SIG_CATCH
;
1865 if (p
->p_nice
> NZERO
&& action
== SIG_DFL
&& (prop
& SA_KILL
) &&
1866 (p
->p_flag
& P_TRACED
) == 0)
1869 if (prop
& SA_CONT
) {
1870 uth
->uu_siglist
&= ~stopsigmask
;
1871 p
->p_siglist
&= ~stopsigmask
;
1874 if (prop
& SA_STOP
) {
1876 * If sending a tty stop signal to a member of an orphaned
1877 * process group, discard the signal here if the action
1878 * is default; don't stop the process below if sleeping,
1879 * and don't clear any pending SIGCONT.
1881 if (prop
& SA_TTYSTOP
&& p
->p_pgrp
->pg_jobc
== 0 &&
1884 uth
->uu_siglist
&= ~contsigmask
;
1885 p
->p_siglist
&= ~contsigmask
;
1887 uth
->uu_siglist
|= mask
;
1888 p
->p_siglist
|= mask
; /* just for lame ones looking here */
1891 * Defer further processing for signals which are held,
1892 * except that stopped processes must be continued by SIGCONT.
1894 if (action
== KERN_SIG_HOLD
&& ((prop
& SA_CONT
) == 0 || p
->p_stat
!= SSTOP
))
1898 * SIGKILL priority twiddling moved here from above because
1899 * it needs sig_thread. Could merge it into large switch
1900 * below if we didn't care about priority for tracing
1901 * as SIGKILL's action is always SIG_DFL.
1903 if ((signum
== SIGKILL
) && (p
->p_nice
> NZERO
)) {
1908 * Process is traced - wake it up (if not already
1909 * stopped) so that it can discover the signal in
1910 * issig() and stop for the parent.
1912 if (p
->p_flag
& P_TRACED
) {
1913 if (p
->p_stat
!= SSTOP
)
1919 if (action
== KERN_SIG_WAIT
) {
1920 uth
->uu_sigwait
= mask
;
1921 uth
->uu_siglist
&= ~mask
;
1922 p
->p_siglist
&= ~mask
;
1923 wakeup(&uth
->uu_sigwait
);
1924 /* if it is SIGCONT resume whole process */
1925 if (prop
& SA_CONT
) {
1926 p
->p_flag
|= P_CONTINUED
;
1927 (void) task_resume(sig_task
);
1932 if (action
!= SIG_DFL
) {
1934 * User wants to catch the signal.
1935 * Wake up the thread, but don't un-suspend it
1936 * (except for SIGCONT).
1938 if (prop
& SA_CONT
) {
1939 p
->p_flag
|= P_CONTINUED
;
1940 (void) task_resume(sig_task
);
1944 /* Default action - varies */
1945 if (mask
& stopsigmask
) {
1947 * These are the signals which by default
1950 * Don't clog system with children of init
1951 * stopped from the keyboard.
1953 if (!(prop
& SA_STOP
) && p
->p_pptr
== initproc
) {
1954 psignal_lock(p
, SIGKILL
, 0);
1955 uth
->uu_siglist
&= ~mask
;
1956 p
->p_siglist
&= ~mask
;
1962 * if task hasn't already been stopped by
1965 uth
->uu_siglist
&= ~mask
;
1966 p
->p_siglist
&= ~mask
;
1967 if (p
->p_stat
!= SSTOP
) {
1968 p
->p_xstat
= signum
;
1969 if ((p
->p_pptr
->p_flag
& P_NOCLDSTOP
) == 0) {
1970 struct proc
*pp
= p
->p_pptr
;
1972 pp
->si_pid
= p
->p_pid
;
1973 pp
->si_status
= p
->p_xstat
;
1974 pp
->si_code
= CLD_STOPPED
;
1975 pp
->si_uid
= p
->p_ucred
->cr_ruid
;
1976 psignal(pp
, SIGCHLD
);
1985 * Signals ignored by default have been dealt
1986 * with already, since their bits are on in
1992 * Kill signal always sets process running and
1996 * Process will be running after 'run'
2000 thread_abort(sig_thread_act
);
2006 * Let the process run. If it's sleeping on an
2007 * event, it remains so.
2009 if (p
->p_flag
& P_TTYSLEEP
) {
2010 p
->p_flag
&= ~P_TTYSLEEP
;
2011 wakeup(&p
->p_siglist
);
2013 p
->p_flag
|= P_CONTINUED
;
2014 (void) task_resume(sig_task
);
2016 uth
->uu_siglist
&= ~mask
;
2017 p
->p_siglist
&= ~mask
;
2023 * All other signals wake up the process, but don't
2032 * If we're being traced (possibly because someone attached us
2033 * while we were stopped), check for a signal from the debugger.
2035 if (p
->p_stat
== SSTOP
) {
2036 if ((p
->p_flag
& P_TRACED
) != 0 && p
->p_xstat
!= 0) {
2037 uth
->uu_siglist
|= sigmask(p
->p_xstat
);
2038 p
->p_siglist
|= sigmask(p
->p_xstat
);
2042 * setrunnable(p) in BSD and
2043 * Wake up the thread if it is interruptible.
2046 thread_abort_safely(sig_thread_act
);
2055 sig_lock_to_exit(struct proc
*p
)
2057 thread_t self
= current_thread();
2059 p
->exit_thread
= self
;
2060 (void) task_suspend(p
->task
);
2064 sig_try_locked(struct proc
*p
)
2066 thread_t self
= current_thread();
2068 while (p
->sigwait
|| p
->exit_thread
) {
2069 if (p
->exit_thread
) {
2070 if (p
->exit_thread
!= self
) {
2072 * Already exiting - no signals.
2078 if(assert_wait_possible()) {
2079 assert_wait((caddr_t
)&p
->sigwait_thread
,
2080 (THREAD_INTERRUPTIBLE
));
2083 thread_block(THREAD_CONTINUE_NULL
);
2085 if (thread_should_abort(self
)) {
2087 * Terminate request - clean up.
2096 * If the current process has received a signal (should be caught or cause
2097 * termination, should interrupt current syscall), return the signal number.
2098 * Stop signals with default action are processed immediately, then cleared;
2099 * they aren't returned. This is checked after each entry to the system for
2100 * a syscall or trap (though this can usually be done without calling issignal
2101 * by checking the pending signal masks in the CURSIG macro.) The normal call
2104 * while (signum = CURSIG(curproc))
2109 register struct proc
*p
;
2111 register int signum
, mask
, prop
, sigbits
;
2113 struct uthread
* ut
;
2116 cur_act
= current_thread();
2119 if(rdebug_proc
&& (p
== rdebug_proc
)) {
2122 #endif /* SIGNAL_DEBUG */
2126 * Try to grab the signal lock.
2128 if (sig_try_locked(p
) <= 0) {
2133 ut
= get_bsdthread_info(cur_act
);
2135 sigbits
= ut
->uu_siglist
& ~ut
->uu_sigmask
;
2137 if (p
->p_flag
& P_PPWAIT
)
2138 sigbits
&= ~stopsigmask
;
2139 if (sigbits
== 0) { /* no signal to send */
2143 signum
= ffs((long)sigbits
);
2144 mask
= sigmask(signum
);
2145 prop
= sigprop
[signum
];
2148 * We should see pending but ignored signals
2149 * only if P_TRACED was on when they were posted.
2151 if (mask
& p
->p_sigignore
&& (p
->p_flag
& P_TRACED
) == 0) {
2152 ut
->uu_siglist
&= ~mask
; /* take the signal! */
2153 p
->p_siglist
&= ~mask
; /* take the signal! */
2156 if (p
->p_flag
& P_TRACED
&& (p
->p_flag
& P_PPWAIT
) == 0) {
2157 register task_t task
;
2159 * If traced, always stop, and stay
2160 * stopped until released by the debugger.
2162 /* ptrace debugging */
2163 p
->p_xstat
= signum
;
2165 if (p
->p_flag
& P_SIGEXC
) {
2167 p
->sigwait_thread
= cur_act
;
2169 p
->p_flag
&= ~(P_WAITED
|P_CONTINUED
);
2170 ut
->uu_siglist
&= ~mask
; /* clear the old signal */
2171 p
->p_siglist
&= ~mask
; /* clear the old signal */
2173 do_bsdexception(EXC_SOFTWARE
, EXC_SOFT_SIGNAL
, signum
);
2176 // panic("Unsupportef gdb option \n");;
2177 pp
->si_pid
= p
->p_pid
;
2178 pp
->si_status
= p
->p_xstat
;
2179 pp
->si_code
= CLD_TRAPPED
;
2180 pp
->si_uid
= p
->p_ucred
->cr_ruid
;
2181 psignal(pp
, SIGCHLD
);
2183 * XXX Have to really stop for debuggers;
2184 * XXX stop() doesn't do the right thing.
2185 * XXX Inline the task_suspend because we
2186 * XXX have to diddle Unix state in the
2192 p
->sigwait_thread
= cur_act
;
2194 p
->p_flag
&= ~(P_WAITED
|P_CONTINUED
);
2195 ut
->uu_siglist
&= ~mask
; /* clear the old signal */
2196 p
->p_siglist
&= ~mask
; /* clear the old signal */
2198 wakeup((caddr_t
)p
->p_pptr
);
2200 assert_wait((caddr_t
)&p
->sigwait
, (THREAD_INTERRUPTIBLE
));
2201 thread_block(THREAD_CONTINUE_NULL
);
2206 p
->sigwait_thread
= NULL
;
2207 wakeup((caddr_t
)&p
->sigwait_thread
);
2210 * This code is to detect when gdb is killed
2211 * even as the traced program is attached.
2212 * pgsignal would get the SIGKILL to traced program
2213 * That's what we are trying to see (I hope)
2215 if (ut
->uu_siglist
& sigmask(SIGKILL
)) {
2217 * Wait event may still be outstanding;
2218 * clear it, since sig_lock_to_exit will
2221 clear_wait(current_thread(), THREAD_INTERRUPTED
);
2222 sig_lock_to_exit(p
);
2224 * Since this thread will be resumed
2225 * to allow the current syscall to
2226 * be completed, must save u_qsave
2227 * before calling exit(). (Since exit()
2228 * calls closef() which can trash u_qsave.)
2231 exit1(p
,signum
, (int *)NULL
);
2236 * We may have to quit
2238 if (thread_should_abort(current_thread())) {
2243 * If parent wants us to take the signal,
2244 * then it will leave it in p->p_xstat;
2245 * otherwise we just look for signals again.
2247 signum
= p
->p_xstat
;
2251 * Put the new signal into p_siglist. If the
2252 * signal is being masked, look for other signals.
2254 mask
= sigmask(signum
);
2255 ut
->uu_siglist
|= mask
;
2256 p
->p_siglist
|= mask
; /* just for lame ones looking here */
2257 if (ut
->uu_sigmask
& mask
)
2262 * Decide whether the signal should be returned.
2263 * Return the signal's number, or fall through
2264 * to clear it from the pending mask.
2267 switch ((long)p
->p_sigacts
->ps_sigact
[signum
]) {
2271 * Don't take default actions on system processes.
2273 if (p
->p_pptr
->p_pid
== 0) {
2276 * Are you sure you want to ignore SIGSEGV
2279 printf("Process (pid %d) got signal %d\n",
2282 break; /* == ignore */
2286 * If there is a pending stop signal to process
2287 * with default action, stop here,
2288 * then clear the signal. However,
2289 * if process is member of an orphaned
2290 * process group, ignore tty stop signals.
2292 if (prop
& SA_STOP
) {
2293 if (p
->p_flag
& P_TRACED
||
2294 (p
->p_pgrp
->pg_jobc
== 0 &&
2296 break; /* == ignore */
2297 if (p
->p_stat
!= SSTOP
) {
2298 p
->p_xstat
= signum
;
2300 if ((p
->p_pptr
->p_flag
& P_NOCLDSTOP
) == 0) {
2302 pp
->si_pid
= p
->p_pid
;
2303 pp
->si_status
= p
->p_xstat
;
2304 pp
->si_code
= CLD_STOPPED
;
2305 pp
->si_uid
= p
->p_ucred
->cr_ruid
;
2306 psignal(pp
, SIGCHLD
);
2310 } else if (prop
& SA_IGNORE
) {
2312 * Except for SIGCONT, shouldn't get here.
2313 * Default action is to ignore; drop it.
2315 break; /* == ignore */
2317 ut
->uu_siglist
&= ~mask
; /* take the signal! */
2318 p
->p_siglist
&= ~mask
; /* take the signal! */
2326 * Masking above should prevent us ever trying
2327 * to take action on an ignored signal other
2328 * than SIGCONT, unless process is traced.
2330 if ((prop
& SA_CONT
) == 0 &&
2331 (p
->p_flag
& P_TRACED
) == 0)
2332 printf("issignal\n");
2333 break; /* == ignore */
2337 * This signal has an action, let
2338 * postsig() process it.
2340 ut
->uu_siglist
&= ~mask
; /* take the signal! */
2341 p
->p_siglist
&= ~mask
; /* take the signal! */
2345 ut
->uu_siglist
&= ~mask
; /* take the signal! */
2346 p
->p_siglist
&= ~mask
; /* take the signal! */
2351 /* called from _sleep */
2354 register struct proc
*p
;
2356 register int signum
, mask
, prop
, sigbits
;
2358 struct uthread
* ut
;
2362 cur_act
= current_thread();
2364 ut
= get_bsdthread_info(cur_act
);
2366 if (ut
->uu_siglist
== 0)
2369 if (((ut
->uu_siglist
& ~ut
->uu_sigmask
) == 0) && ((p
->p_flag
& P_TRACED
) == 0))
2372 sigbits
= ut
->uu_siglist
& ~ut
->uu_sigmask
;
2375 if (p
->p_flag
& P_PPWAIT
)
2376 sigbits
&= ~stopsigmask
;
2377 if (sigbits
== 0) { /* no signal to send */
2381 signum
= ffs((long)sigbits
);
2382 mask
= sigmask(signum
);
2383 prop
= sigprop
[signum
];
2386 * We should see pending but ignored signals
2387 * only if P_TRACED was on when they were posted.
2389 if (mask
& p
->p_sigignore
&& (p
->p_flag
& P_TRACED
) == 0) {
2392 if (p
->p_flag
& P_TRACED
&& (p
->p_flag
& P_PPWAIT
) == 0) {
2394 * Put the new signal into p_siglist. If the
2395 * signal is being masked, look for other signals.
2397 mask
= sigmask(signum
);
2398 if (ut
->uu_sigmask
& mask
)
2404 * Decide whether the signal should be returned.
2405 * Return the signal's number, or fall through
2406 * to clear it from the pending mask.
2409 switch ((long)p
->p_sigacts
->ps_sigact
[signum
]) {
2413 * Don't take default actions on system processes.
2415 if (p
->p_pptr
->p_pid
== 0) {
2418 * Are you sure you want to ignore SIGSEGV
2421 printf("Process (pid %d) got signal %d\n",
2424 break; /* == ignore */
2428 * If there is a pending stop signal to process
2429 * with default action, stop here,
2430 * then clear the signal. However,
2431 * if process is member of an orphaned
2432 * process group, ignore tty stop signals.
2434 if (prop
& SA_STOP
) {
2435 if (p
->p_flag
& P_TRACED
||
2436 (p
->p_pgrp
->pg_jobc
== 0 &&
2438 break; /* == ignore */
2441 } else if (prop
& SA_IGNORE
) {
2443 * Except for SIGCONT, shouldn't get here.
2444 * Default action is to ignore; drop it.
2446 break; /* == ignore */
2454 * Masking above should prevent us ever trying
2455 * to take action on an ignored signal other
2456 * than SIGCONT, unless process is traced.
2458 if ((prop
& SA_CONT
) == 0 &&
2459 (p
->p_flag
& P_TRACED
) == 0)
2460 printf("issignal\n");
2461 break; /* == ignore */
2465 * This signal has an action, let
2466 * postsig() process it.
2470 sigbits
&= ~mask
; /* take the signal! */
2476 * Put the argument process into the stopped state and notify the parent
2477 * via wakeup. Signals are handled elsewhere. The process must not be
2482 register struct proc
*p
;
2485 p
->p_flag
&= ~(P_WAITED
|P_CONTINUED
);
2486 if (p
->p_pptr
->p_stat
!= SSTOP
)
2487 wakeup((caddr_t
)p
->p_pptr
);
2488 (void) task_suspend(p
->task
); /*XXX*/
2492 * Take the action for the specified signal
2493 * from the current set of pending signals.
2498 struct proc
*p
= current_proc();
2499 struct sigacts
*ps
= p
->p_sigacts
;
2500 user_addr_t catcher
;
2502 int mask
, returnmask
;
2503 struct uthread
* ut
;
2509 * This must be called on master cpu
2511 if (cpu_number() != master_cpu
)
2512 panic("psig not on master");
2517 * Try to grab the signal lock.
2519 if (sig_try_locked(p
) <= 0) {
2524 ut
= (struct uthread
*)get_bsdthread_info(current_thread());
2525 mask
= sigmask(signum
);
2526 ut
->uu_siglist
&= ~mask
;
2527 p
->p_siglist
&= ~mask
;
2528 catcher
= ps
->ps_sigact
[signum
];
2530 //LP64: catcher argument is a 64 bit user space handler address
2531 if (KTRPOINT(p
, KTR_PSIG
))
2532 ktrpsig(p
->p_tracep
,
2533 signum
, CAST_DOWN(void *,catcher
), ut
->uu_flag
& UT_SAS_OLDMASK
?
2534 &ut
->uu_oldmask
: &ut
->uu_sigmask
, 0);
2536 if (catcher
== SIG_DFL
) {
2538 * Default catcher, where the default is to kill
2539 * the process. (Other cases were ignored above.)
2541 /* called with signal_lock() held */
2542 sigexit_locked(p
, signum
);
2547 * If we get here, the signal must be caught.
2550 if (catcher
== SIG_IGN
|| (ut
->uu_sigmask
& mask
))
2552 "postsig: processing masked or ignored signal\n");
2555 * Set the new mask value and also defer further
2556 * occurences of this signal.
2558 * Special case: user has done a sigpause. Here the
2559 * current mask is not of interest, but rather the
2560 * mask from before the sigpause is what we want
2561 * restored after the signal processing is completed.
2563 if (ut
->uu_flag
& UT_SAS_OLDMASK
) {
2564 returnmask
= ut
->uu_oldmask
;
2565 ut
->uu_flag
&= ~UT_SAS_OLDMASK
;
2568 returnmask
= ut
->uu_sigmask
;
2569 ut
->uu_sigmask
|= ps
->ps_catchmask
[signum
];
2570 if ((ps
->ps_signodefer
& mask
) == 0)
2571 ut
->uu_sigmask
|= mask
;
2572 if ((signum
!= SIGILL
) && (signum
!= SIGTRAP
) && (ps
->ps_sigreset
& mask
)) {
2573 if ((signum
!= SIGCONT
) && (sigprop
[signum
] & SA_IGNORE
))
2574 p
->p_sigignore
|= mask
;
2575 ps
->ps_sigact
[signum
] = SIG_DFL
;
2576 ps
->ps_siginfo
&= ~mask
;
2577 ps
->ps_signodefer
&= ~mask
;
2580 /* Needs to disable to run in user mode */
2581 if (signum
== SIGFPE
) {
2582 thread_enable_fpe(current_thread(), 0);
2584 #endif /* __ppc__ */
2586 if (ps
->ps_sig
!= signum
) {
2592 p
->p_stats
->p_ru
.ru_nsignals
++;
2593 sendsig(p
, catcher
, signum
, returnmask
, code
);
2599 * Force the current process to exit with the specified signal, dumping core
2600 * if appropriate. We bypass the normal tests for masked and caught signals,
2601 * allowing unrecoverable failures to terminate the process without changing
2602 * signal state. Mark the accounting record with the signal termination.
2603 * If dumping core, save the signal number for the debugger. Calls exit and
2606 /* called with signal lock */
2608 sigexit_locked(p
, signum
)
2609 register struct proc
*p
;
2613 sig_lock_to_exit(p
);
2614 p
->p_acflag
|= AXSIG
;
2615 if (sigprop
[signum
] & SA_CORE
) {
2616 p
->p_sigacts
->ps_sig
= signum
;
2618 if (coredump(p
) == 0)
2619 signum
|= WCOREFLAG
;
2623 exit1(p
, W_EXITCODE(0, signum
), (int *)NULL
);
2629 filt_sigattach(struct knote
*kn
)
2631 struct proc
*p
= current_proc();
2633 kn
->kn_ptr
.p_proc
= p
;
2634 kn
->kn_flags
|= EV_CLEAR
; /* automatically set */
2636 /* XXX lock the proc here while adding to the list? */
2637 KNOTE_ATTACH(&p
->p_klist
, kn
);
2643 filt_sigdetach(struct knote
*kn
)
2645 struct proc
*p
= kn
->kn_ptr
.p_proc
;
2647 KNOTE_DETACH(&p
->p_klist
, kn
);
2651 * signal knotes are shared with proc knotes, so we apply a mask to
2652 * the hint in order to differentiate them from process hints. This
2653 * could be avoided by using a signal-specific knote list, but probably
2654 * isn't worth the trouble.
2657 filt_signal(struct knote
*kn
, long hint
)
2660 if (hint
& NOTE_SIGNAL
) {
2661 hint
&= ~NOTE_SIGNAL
;
2663 if (kn
->kn_id
== (unsigned int)hint
)
2666 return (kn
->kn_data
!= 0);
2671 bsd_ast(thread_t thr_act
)
2673 struct proc
*p
= current_proc();
2674 struct uthread
*ut
= get_bsdthread_info(thr_act
);
2677 boolean_t funnel_state
;
2678 static int bsd_init_done
= 0;
2683 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
2685 if ((p
->p_flag
& P_OWEUPC
) && (p
->p_flag
& P_PROFIL
)) {
2686 pc
= get_useraddr();
2687 addupc_task(p
, pc
, 1);
2688 p
->p_flag
&= ~P_OWEUPC
;
2691 if (CHECK_SIGNALS(p
, current_thread(), ut
)) {
2692 while ( (signum
= issignal(p
)) )
2695 if (!bsd_init_done
) {
2700 (void) thread_funnel_set(kernel_flock
, FALSE
);
2704 * Follwing routines are called using callout from bsd_hardclock
2705 * so that psignals are called in a thread context and are funneled
2708 psignal_vtalarm(struct proc
*p
)
2710 boolean_t funnel_state
;
2714 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
2715 psignal_lock(p
, SIGVTALRM
, 1);
2716 (void) thread_funnel_set(kernel_flock
, FALSE
);
2720 psignal_xcpu(struct proc
*p
)
2722 boolean_t funnel_state
;
2726 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
2727 psignal_lock(p
, SIGXCPU
, 1);
2728 (void) thread_funnel_set(kernel_flock
, FALSE
);
2732 psignal_sigprof(struct proc
*p
)
2734 boolean_t funnel_state
;
2738 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
2739 psignal_lock(p
, SIGPROF
, 1);
2740 (void) thread_funnel_set(kernel_flock
, FALSE
);
2743 /* ptrace set runnalbe */
2745 pt_setrunnable(struct proc
*p
)
2751 if (p
->p_flag
& P_TRACED
) {
2754 wakeup((caddr_t
)&(p
->sigwait
));
2767 exception_data_type_t codes
[EXCEPTION_CODE_MAX
];
2771 return(bsd_exception(exc
, codes
, 2));
2775 proc_pendingsignals(struct proc
*p
, sigset_t mask
)
2777 struct uthread
* uth
;
2782 /* If the process is in proc exit return no signal info */
2783 if (p
->p_lflag
& P_LPEXIT
)
2786 /* duplicate the signal lock code to enable recursion; as exit
2787 * holds the lock too long. All this code is being reworked
2788 * this is just a workaround for regressions till new code
2792 error
= lockmgr((struct lock__bsd__
*)&p
->signal_lock
[0], (LK_EXCLUSIVE
| LK_CANRECURSE
), 0, (struct proc
*)0);
2796 if ((p
->p_flag
& P_INVFORK
) && p
->p_vforkact
) {
2798 uth
= (struct uthread
*)get_bsdthread_info(th
);
2800 bits
= (((uth
->uu_siglist
& ~uth
->uu_sigmask
) & ~p
->p_sigignore
) & mask
);
2806 TAILQ_FOREACH(uth
, &p
->p_uthlist
, uu_list
) {
2807 bits
|= (((uth
->uu_siglist
& ~uth
->uu_sigmask
) & ~p
->p_sigignore
) & mask
);
2815 thread_issignal(proc_t p
, thread_t th
, sigset_t mask
)
2817 struct uthread
* uth
;
2821 uth
= (struct uthread
*)get_bsdthread_info(th
);
2823 bits
= (((uth
->uu_siglist
& ~uth
->uu_sigmask
) & ~p
->p_sigignore
) & mask
);