1 /* 2 * Copyright (c) 2005 David Xu <davidxu@freebsd.org> 3 * Copyright (C) 2003 Daniel M. Eischen <deischen@freebsd.org> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice unmodified, this list of conditions, and the following 11 * disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * 27 * $FreeBSD$ 28 */ 29 30 #include <sys/types.h> 31 #include <sys/signalvar.h> 32 #include <pthread.h> 33 34 #include "thr_private.h" 35 36 /*#define DEBUG_THREAD_KERN */ 37 #ifdef DEBUG_THREAD_KERN 38 #define DBG_MSG stdout_debug 39 #else 40 #define DBG_MSG(x...) 41 #endif 42 43 /* 44 * This is called when the first thread (other than the initial 45 * thread) is created. 46 */ 47 int 48 _thr_setthreaded(int threaded) 49 { 50 if (((threaded == 0) ^ (__isthreaded == 0)) == 0) 51 return (0); 52 53 __isthreaded = threaded; 54 #if 0 55 if (threaded != 0) { 56 _thr_rtld_init(); 57 } else { 58 _thr_rtld_fini(); 59 } 60 #endif 61 return (0); 62 } 63 64 void 65 _thr_signal_block(struct pthread *curthread) 66 { 67 sigset_t set; 68 69 if (curthread->sigblock > 0) { 70 curthread->sigblock++; 71 return; 72 } 73 SIGFILLSET(set); 74 SIGDELSET(set, SIGBUS); 75 SIGDELSET(set, SIGILL); 76 SIGDELSET(set, SIGFPE); 77 SIGDELSET(set, SIGSEGV); 78 SIGDELSET(set, SIGTRAP); 79 __sys_sigprocmask(SIG_BLOCK, &set, &curthread->sigmask); 80 curthread->sigblock++; 81 } 82 83 void 84 _thr_signal_unblock(struct pthread *curthread) 85 { 86 if (--curthread->sigblock == 0) 87 __sys_sigprocmask(SIG_SETMASK, &curthread->sigmask, NULL); 88 } 89 90 int 91 _thr_send_sig(struct pthread *thread, int sig) 92 { 93 return thr_kill(thread->tid, sig); 94 } 95 96 void 97 _thr_assert_lock_level() 98 { 99 PANIC("locklevel <= 0"); 100 } 101