Changeset View
Changeset View
Standalone View
Standalone View
lib/libthr/thread/thr_init.c
Show All 31 Lines | |||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
* SUCH DAMAGE. | * SUCH DAMAGE. | ||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include "namespace.h" | #include "namespace.h" | ||||
#include <sys/types.h> | #include <sys/param.h> | ||||
#include <sys/auxv.h> | |||||
#include <sys/signalvar.h> | #include <sys/signalvar.h> | ||||
#include <sys/ioctl.h> | #include <sys/ioctl.h> | ||||
#include <sys/link_elf.h> | #include <sys/link_elf.h> | ||||
#include <sys/resource.h> | #include <sys/resource.h> | ||||
#include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
#include <sys/ttycom.h> | #include <sys/ttycom.h> | ||||
#include <sys/mman.h> | #include <sys/mman.h> | ||||
#include <sys/rtprio.h> | #include <sys/rtprio.h> | ||||
▲ Show 20 Lines • Show All 379 Lines • ▼ Show 20 Lines | |||||
#ifdef _PTHREAD_FORCED_UNWIND | #ifdef _PTHREAD_FORCED_UNWIND | ||||
thread->unwind_stackend = _usrstack; | thread->unwind_stackend = _usrstack; | ||||
#endif | #endif | ||||
/* Others cleared to zero by thr_alloc() */ | /* Others cleared to zero by thr_alloc() */ | ||||
} | } | ||||
static void | bool | ||||
init_private(void) | __thr_get_main_stack_base(char **base) | ||||
{ | { | ||||
struct rlimit rlim; | |||||
size_t len; | size_t len; | ||||
int mib[2]; | int mib[2]; | ||||
if (elf_aux_info(AT_USRSTACKBASE, base, sizeof(*base)) == 0) | |||||
return (true); | |||||
mib[0] = CTL_KERN; | |||||
mib[1] = KERN_USRSTACK; | |||||
len = sizeof(*base); | |||||
if (sysctl(mib, nitems(mib), base, &len, NULL, 0) == 0) | |||||
return (true); | |||||
return (false); | |||||
} | |||||
bool | |||||
__thr_get_main_stack_lim(size_t *lim) | |||||
{ | |||||
struct rlimit rlim; | |||||
if (elf_aux_info(AT_USRSTACKLIM, lim, sizeof(*lim)) == 0) | |||||
return (true); | |||||
if (getrlimit(RLIMIT_STACK, &rlim) == 0) { | |||||
*lim = rlim.rlim_cur; | |||||
return (true); | |||||
} | |||||
return (false); | |||||
} | |||||
static void | |||||
init_private(void) | |||||
{ | |||||
char *env, *env_bigstack, *env_splitstack; | char *env, *env_bigstack, *env_splitstack; | ||||
_thr_umutex_init(&_mutex_static_lock); | _thr_umutex_init(&_mutex_static_lock); | ||||
_thr_umutex_init(&_cond_static_lock); | _thr_umutex_init(&_cond_static_lock); | ||||
_thr_umutex_init(&_rwlock_static_lock); | _thr_umutex_init(&_rwlock_static_lock); | ||||
_thr_umutex_init(&_keytable_lock); | _thr_umutex_init(&_keytable_lock); | ||||
_thr_urwlock_init(&_thr_atfork_lock); | _thr_urwlock_init(&_thr_atfork_lock); | ||||
_thr_umutex_init(&_thr_event_lock); | _thr_umutex_init(&_thr_event_lock); | ||||
_thr_umutex_init(&_suspend_all_lock); | _thr_umutex_init(&_suspend_all_lock); | ||||
_thr_spinlock_init(); | _thr_spinlock_init(); | ||||
_thr_list_init(); | _thr_list_init(); | ||||
_thr_wake_addr_init(); | _thr_wake_addr_init(); | ||||
_sleepq_init(); | _sleepq_init(); | ||||
_single_thread = NULL; | _single_thread = NULL; | ||||
_suspend_all_waiters = 0; | _suspend_all_waiters = 0; | ||||
/* | /* | ||||
* Avoid reinitializing some things if they don't need to be, | * Avoid reinitializing some things if they don't need to be, | ||||
* e.g. after a fork(). | * e.g. after a fork(). | ||||
*/ | */ | ||||
if (init_once == 0) { | if (init_once == 0) { | ||||
__thr_pshared_init(); | __thr_pshared_init(); | ||||
__thr_malloc_init(); | __thr_malloc_init(); | ||||
/* Find the stack top */ | /* Find the stack top */ | ||||
mib[0] = CTL_KERN; | if (!__thr_get_main_stack_base(&_usrstack)) | ||||
mib[1] = KERN_USRSTACK; | PANIC("Cannot get kern.usrstack"); | ||||
len = sizeof (_usrstack); | |||||
if (sysctl(mib, 2, &_usrstack, &len, NULL, 0) == -1) | |||||
PANIC("Cannot get kern.usrstack from sysctl"); | |||||
env_bigstack = getenv("LIBPTHREAD_BIGSTACK_MAIN"); | env_bigstack = getenv("LIBPTHREAD_BIGSTACK_MAIN"); | ||||
env_splitstack = getenv("LIBPTHREAD_SPLITSTACK_MAIN"); | env_splitstack = getenv("LIBPTHREAD_SPLITSTACK_MAIN"); | ||||
if (env_bigstack != NULL || env_splitstack == NULL) { | if (env_bigstack != NULL || env_splitstack == NULL) { | ||||
if (getrlimit(RLIMIT_STACK, &rlim) == -1) | if (!__thr_get_main_stack_lim(&_thr_stack_initial)) | ||||
PANIC("Cannot get stack rlimit"); | PANIC("Cannot get stack rlimit"); | ||||
_thr_stack_initial = rlim.rlim_cur; | |||||
} | } | ||||
_thr_is_smp = sysconf(_SC_NPROCESSORS_CONF); | _thr_is_smp = sysconf(_SC_NPROCESSORS_CONF); | ||||
if (_thr_is_smp == -1) | if (_thr_is_smp == -1) | ||||
PANIC("Cannot get _SC_NPROCESSORS_CONF"); | PANIC("Cannot get _SC_NPROCESSORS_CONF"); | ||||
_thr_is_smp = (_thr_is_smp > 1); | _thr_is_smp = (_thr_is_smp > 1); | ||||
_thr_page_size = getpagesize(); | _thr_page_size = getpagesize(); | ||||
_thr_guard_default = _thr_page_size; | _thr_guard_default = _thr_page_size; | ||||
_pthread_attr_default.guardsize_attr = _thr_guard_default; | _pthread_attr_default.guardsize_attr = _thr_guard_default; | ||||
Show All 14 Lines |