Deleted Added
full compact
thr_sig.c (118748) thr_sig.c (119063)
1/*
2 * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
1/*
2 * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * $FreeBSD: head/lib/libkse/thread/thr_sig.c 118748 2003-08-10 22:35:46Z davidxu $
32 * $FreeBSD: head/lib/libkse/thread/thr_sig.c 119063 2003-08-18 03:58:29Z davidxu $
33 */
34#include <sys/param.h>
35#include <sys/types.h>
36#include <sys/signalvar.h>
37#include <signal.h>
38#include <errno.h>
39#include <fcntl.h>
40#include <unistd.h>

--- 264 unchanged lines hidden (view full) ---

305 __siginfohandler_t *sigfunc;
306 struct pthread *curthread;
307 struct kse *curkse;
308 struct sigaction act;
309 int sa_flags, err_save, intr_save, timeout_save;
310
311 DBG_MSG(">>> _thr_sig_handler(%d)\n", sig);
312
33 */
34#include <sys/param.h>
35#include <sys/types.h>
36#include <sys/signalvar.h>
37#include <signal.h>
38#include <errno.h>
39#include <fcntl.h>
40#include <unistd.h>

--- 264 unchanged lines hidden (view full) ---

305 __siginfohandler_t *sigfunc;
306 struct pthread *curthread;
307 struct kse *curkse;
308 struct sigaction act;
309 int sa_flags, err_save, intr_save, timeout_save;
310
311 DBG_MSG(">>> _thr_sig_handler(%d)\n", sig);
312
313 curkse = _get_curkse();
314 if ((curkse == NULL) || ((curkse->k_flags & KF_STARTED) == 0)) {
315 /* Upcalls are not yet started; just call the handler. */
316 sigfunc = _thread_sigact[sig - 1].sa_sigaction;
317 if (((__sighandler_t *)sigfunc != SIG_DFL) &&
318 ((__sighandler_t *)sigfunc != SIG_IGN) &&
319 (sigfunc != (__siginfohandler_t *)_thr_sig_handler)) {
320 if (((_thread_sigact[sig - 1].sa_flags & SA_SIGINFO)
321 != 0) || (info == NULL))
322 (*(sigfunc))(sig, info, ucp);
323 else
324 (*(sigfunc))(sig,
325 (siginfo_t*)(intptr_t)info->si_code, ucp);
326 }
327
328 return;
329 }
330
331 curthread = _get_curthread();
332 if (curthread == NULL)
333 PANIC("No current thread.\n");
334 if (!(curthread->attr.flags & PTHREAD_SCOPE_SYSTEM))
335 PANIC("Thread is not system scope.\n");
336 if (curthread->flags & THR_FLAGS_EXITING)
337 return;
338 curkse = _get_curkse();

--- 15 unchanged lines hidden (view full) ---

354 * so kse_release will return from kernel immediately.
355 */
356 if (KSE_IS_IDLE(curkse))
357 kse_wakeup(&curkse->k_kcb->kcb_kmbx);
358 return;
359 }
360
361 /* It is now safe to invoke signal handler */
313 curthread = _get_curthread();
314 if (curthread == NULL)
315 PANIC("No current thread.\n");
316 if (!(curthread->attr.flags & PTHREAD_SCOPE_SYSTEM))
317 PANIC("Thread is not system scope.\n");
318 if (curthread->flags & THR_FLAGS_EXITING)
319 return;
320 curkse = _get_curkse();

--- 15 unchanged lines hidden (view full) ---

336 * so kse_release will return from kernel immediately.
337 */
338 if (KSE_IS_IDLE(curkse))
339 kse_wakeup(&curkse->k_kcb->kcb_kmbx);
340 return;
341 }
342
343 /* It is now safe to invoke signal handler */
362 err_save = curthread->error;
344 err_save = errno;
363 timeout_save = curthread->timeout;
364 intr_save = curthread->interrupted;
345 timeout_save = curthread->timeout;
346 intr_save = curthread->interrupted;
365 /* Get a fresh copy of signal mask from kernel, for thread dump only */
366 __sys_sigprocmask(SIG_SETMASK, NULL, &curthread->sigmask);
347 /* Get a fresh copy of signal mask, for thread dump only */
348 curthread->sigmask = ucp->uc_sigmask;
367 _kse_critical_enter();
368 KSE_LOCK_ACQUIRE(curkse, &_thread_signal_lock);
369 sigfunc = _thread_sigact[sig - 1].sa_sigaction;
370 sa_flags = _thread_sigact[sig - 1].sa_flags & SA_SIGINFO;
371 if (sa_flags & SA_RESETHAND) {
372 act.sa_handler = SIG_DFL;
373 act.sa_flags = SA_RESTART;
374 SIGEMPTYSET(act.sa_mask);

--- 9 unchanged lines hidden (view full) ---

384 (sigfunc != (__siginfohandler_t *)_thr_sig_handler)) {
385 if ((sa_flags & SA_SIGINFO) != 0 || info == NULL)
386 (*(sigfunc))(sig, info, ucp);
387 else
388 (*(sigfunc))(sig, (siginfo_t*)(intptr_t)info->si_code,
389 ucp);
390 } else {
391 if ((__sighandler_t *)sigfunc == SIG_DFL) {
349 _kse_critical_enter();
350 KSE_LOCK_ACQUIRE(curkse, &_thread_signal_lock);
351 sigfunc = _thread_sigact[sig - 1].sa_sigaction;
352 sa_flags = _thread_sigact[sig - 1].sa_flags & SA_SIGINFO;
353 if (sa_flags & SA_RESETHAND) {
354 act.sa_handler = SIG_DFL;
355 act.sa_flags = SA_RESTART;
356 SIGEMPTYSET(act.sa_mask);

--- 9 unchanged lines hidden (view full) ---

366 (sigfunc != (__siginfohandler_t *)_thr_sig_handler)) {
367 if ((sa_flags & SA_SIGINFO) != 0 || info == NULL)
368 (*(sigfunc))(sig, info, ucp);
369 else
370 (*(sigfunc))(sig, (siginfo_t*)(intptr_t)info->si_code,
371 ucp);
372 } else {
373 if ((__sighandler_t *)sigfunc == SIG_DFL) {
392 if (sigprop(sig) & SA_KILL)
393 kse_thr_interrupt(NULL, KSE_INTR_SIGEXIT, sig);
374 if (sigprop(sig) & SA_KILL) {
375 if (_kse_isthreaded())
376 kse_thr_interrupt(NULL,
377 KSE_INTR_SIGEXIT, sig);
378 else
379 kill(getpid(), sig);
380 }
394#ifdef NOTYET
395 else if (sigprop(sig) & SA_STOP)
396 kse_thr_interrupt(NULL, KSE_INTR_JOBSTOP, sig);
397#endif
398 }
399 }
381#ifdef NOTYET
382 else if (sigprop(sig) & SA_STOP)
383 kse_thr_interrupt(NULL, KSE_INTR_JOBSTOP, sig);
384#endif
385 }
386 }
400 curthread->error = err_save;
387 errno = err_save;
401 curthread->timeout = timeout_save;
402 curthread->interrupted = intr_save;
403 _kse_critical_enter();
404 curthread->sigmask = ucp->uc_sigmask;
405 _kse_critical_leave(&curthread->tcb->tcb_tmbx);
406 DBG_MSG("<<< _thr_sig_handler(%d)\n", sig);
407}
408

--- 31 unchanged lines hidden (view full) ---

440 act.sa_handler = SIG_DFL;
441 act.sa_flags = SA_RESTART;
442 SIGEMPTYSET(act.sa_mask);
443 __sys_sigaction(sig, &act, NULL);
444 __sys_sigaction(sig, NULL, &_thread_sigact[sig - 1]);
445 }
446 KSE_LOCK_RELEASE(curkse, &_thread_signal_lock);
447 KSE_SCHED_UNLOCK(curkse, curkse->k_kseg);
388 curthread->timeout = timeout_save;
389 curthread->interrupted = intr_save;
390 _kse_critical_enter();
391 curthread->sigmask = ucp->uc_sigmask;
392 _kse_critical_leave(&curthread->tcb->tcb_tmbx);
393 DBG_MSG("<<< _thr_sig_handler(%d)\n", sig);
394}
395

--- 31 unchanged lines hidden (view full) ---

427 act.sa_handler = SIG_DFL;
428 act.sa_flags = SA_RESTART;
429 SIGEMPTYSET(act.sa_mask);
430 __sys_sigaction(sig, &act, NULL);
431 __sys_sigaction(sig, NULL, &_thread_sigact[sig - 1]);
432 }
433 KSE_LOCK_RELEASE(curkse, &_thread_signal_lock);
434 KSE_SCHED_UNLOCK(curkse, curkse->k_kseg);
448 _kse_critical_leave(&curthread->tcb->tcb_tmbx);
449 /*
450 * We are processing buffered signals, synchronize working
451 * signal mask into kernel.
452 */
453 if (curthread->attr.flags & PTHREAD_SCOPE_SYSTEM)
454 __sys_sigprocmask(SIG_SETMASK, &curthread->sigmask, NULL);
435 /*
436 * We are processing buffered signals, synchronize working
437 * signal mask into kernel.
438 */
439 if (curthread->attr.flags & PTHREAD_SCOPE_SYSTEM)
440 __sys_sigprocmask(SIG_SETMASK, &curthread->sigmask, NULL);
441 _kse_critical_leave(&curthread->tcb->tcb_tmbx);
455 ucp->uc_sigmask = sigmask;
456 if (((__sighandler_t *)sigfunc != SIG_DFL) &&
457 ((__sighandler_t *)sigfunc != SIG_IGN)) {
458 if ((sa_flags & SA_SIGINFO) != 0 || info == NULL)
459 (*(sigfunc))(sig, info, ucp);
460 else
461 (*(sigfunc))(sig, (siginfo_t*)(intptr_t)info->si_code,
462 ucp);
463 } else {
464 if ((__sighandler_t *)sigfunc == SIG_DFL) {
442 ucp->uc_sigmask = sigmask;
443 if (((__sighandler_t *)sigfunc != SIG_DFL) &&
444 ((__sighandler_t *)sigfunc != SIG_IGN)) {
445 if ((sa_flags & SA_SIGINFO) != 0 || info == NULL)
446 (*(sigfunc))(sig, info, ucp);
447 else
448 (*(sigfunc))(sig, (siginfo_t*)(intptr_t)info->si_code,
449 ucp);
450 } else {
451 if ((__sighandler_t *)sigfunc == SIG_DFL) {
465 if (sigprop(sig) & SA_KILL)
466 kse_thr_interrupt(NULL, KSE_INTR_SIGEXIT, sig);
452 if (sigprop(sig) & SA_KILL) {
453 if (_kse_isthreaded())
454 kse_thr_interrupt(NULL,
455 KSE_INTR_SIGEXIT, sig);
456 else
457 kill(getpid(), sig);
458 }
467#ifdef NOTYET
468 else if (sigprop(sig) & SA_STOP)
469 kse_thr_interrupt(NULL, KSE_INTR_JOBSTOP, sig);
470#endif
471 }
472 }
473
474 _kse_critical_enter();

--- 569 unchanged lines hidden (view full) ---

1044
1045static void
1046thr_sigframe_restore(struct pthread *thread, struct pthread_sigframe *psf)
1047{
1048 if (psf->psf_valid == 0)
1049 PANIC("invalid pthread_sigframe\n");
1050 thread->flags = psf->psf_flags;
1051 thread->interrupted = psf->psf_interrupted;
459#ifdef NOTYET
460 else if (sigprop(sig) & SA_STOP)
461 kse_thr_interrupt(NULL, KSE_INTR_JOBSTOP, sig);
462#endif
463 }
464 }
465
466 _kse_critical_enter();

--- 569 unchanged lines hidden (view full) ---

1036
1037static void
1038thr_sigframe_restore(struct pthread *thread, struct pthread_sigframe *psf)
1039{
1040 if (psf->psf_valid == 0)
1041 PANIC("invalid pthread_sigframe\n");
1042 thread->flags = psf->psf_flags;
1043 thread->interrupted = psf->psf_interrupted;
1052 thread->signo = psf->psf_signo;
1053 thread->state = psf->psf_state;
1054 thread->data = psf->psf_wait_data;
1055 thread->wakeup_time = psf->psf_wakeup_time;
1056}
1057
1058static void
1059thr_sigframe_save(struct pthread *thread, struct pthread_sigframe *psf)
1060{
1061 /* This has to initialize all members of the sigframe. */
1062 psf->psf_flags =
1063 thread->flags & (THR_FLAGS_PRIVATE | THR_FLAGS_IN_TDLIST);
1064 psf->psf_interrupted = thread->interrupted;
1044 thread->state = psf->psf_state;
1045 thread->data = psf->psf_wait_data;
1046 thread->wakeup_time = psf->psf_wakeup_time;
1047}
1048
1049static void
1050thr_sigframe_save(struct pthread *thread, struct pthread_sigframe *psf)
1051{
1052 /* This has to initialize all members of the sigframe. */
1053 psf->psf_flags =
1054 thread->flags & (THR_FLAGS_PRIVATE | THR_FLAGS_IN_TDLIST);
1055 psf->psf_interrupted = thread->interrupted;
1065 psf->psf_signo = thread->signo;
1066 psf->psf_state = thread->state;
1067 psf->psf_wait_data = thread->data;
1068 psf->psf_wakeup_time = thread->wakeup_time;
1069}
1070
1071void
1072_thr_signal_init(void)
1073{
1074 struct sigaction act;
1075 __siginfohandler_t *sigfunc;
1076 int i;
1056 psf->psf_state = thread->state;
1057 psf->psf_wait_data = thread->data;
1058 psf->psf_wakeup_time = thread->wakeup_time;
1059}
1060
1061void
1062_thr_signal_init(void)
1063{
1064 struct sigaction act;
1065 __siginfohandler_t *sigfunc;
1066 int i;
1067 sigset_t sigset;
1077
1068
1069 SIGFILLSET(sigset);
1070 __sys_sigprocmask(SIG_SETMASK, &sigset, &_thr_initial->sigmask);
1078 /* Enter a loop to get the existing signal status: */
1079 for (i = 1; i <= _SIG_MAXSIG; i++) {
1080 /* Check for signals which cannot be trapped: */
1081 if (i == SIGKILL || i == SIGSTOP) {
1082 }
1083
1084 /* Get the signal handler details: */
1085 else if (__sys_sigaction(i, NULL,

--- 20 unchanged lines hidden (view full) ---

1106 * really needed, but it is nice to have for debugging
1107 * purposes.
1108 */
1109 _thread_sigact[SIGINFO - 1].sa_flags = SA_SIGINFO | SA_RESTART;
1110 SIGEMPTYSET(act.sa_mask);
1111 act.sa_flags = SA_SIGINFO | SA_RESTART;
1112 act.sa_sigaction = (__siginfohandler_t *)&_thr_sig_handler;
1113 if (__sys_sigaction(SIGINFO, &act, NULL) != 0) {
1071 /* Enter a loop to get the existing signal status: */
1072 for (i = 1; i <= _SIG_MAXSIG; i++) {
1073 /* Check for signals which cannot be trapped: */
1074 if (i == SIGKILL || i == SIGSTOP) {
1075 }
1076
1077 /* Get the signal handler details: */
1078 else if (__sys_sigaction(i, NULL,

--- 20 unchanged lines hidden (view full) ---

1099 * really needed, but it is nice to have for debugging
1100 * purposes.
1101 */
1102 _thread_sigact[SIGINFO - 1].sa_flags = SA_SIGINFO | SA_RESTART;
1103 SIGEMPTYSET(act.sa_mask);
1104 act.sa_flags = SA_SIGINFO | SA_RESTART;
1105 act.sa_sigaction = (__siginfohandler_t *)&_thr_sig_handler;
1106 if (__sys_sigaction(SIGINFO, &act, NULL) != 0) {
1107 __sys_sigprocmask(SIG_SETMASK, &_thr_initial->sigmask, NULL);
1114 /*
1115 * Abort this process if signal initialisation fails:
1116 */
1117 PANIC("Cannot initialize signal handler");
1118 }
1108 /*
1109 * Abort this process if signal initialisation fails:
1110 */
1111 PANIC("Cannot initialize signal handler");
1112 }
1113 __sys_sigprocmask(SIG_SETMASK, &_thr_initial->sigmask, NULL);
1119}
1120
1121void
1122_thr_signal_deinit(void)
1123{
1124 int i;
1125
1126 /* Enter a loop to get the existing signal status: */

--- 17 unchanged lines hidden ---
1114}
1115
1116void
1117_thr_signal_deinit(void)
1118{
1119 int i;
1120
1121 /* Enter a loop to get the existing signal status: */

--- 17 unchanged lines hidden ---