mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-11 09:50:12 +00:00
Initialize rtld lock just before turning on thread mode and
uninitialize rtld lock after thread mode shutdown.
This commit is contained in:
parent
7292e8d174
commit
b2674f96cc
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=118747
@ -309,8 +309,6 @@ _libpthread_init(struct pthread *curthread)
|
||||
_kcb_set(_thr_initial->kse->k_kcb);
|
||||
_tcb_set(_thr_initial->kse->k_kcb, _thr_initial->tcb);
|
||||
_thr_initial->kse->k_flags |= KF_INITIALIZED;
|
||||
|
||||
_thr_rtld_init();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -213,16 +213,17 @@ _kse_single_thread(struct pthread *curthread)
|
||||
kse_critical_t crit;
|
||||
int i;
|
||||
|
||||
|
||||
/*
|
||||
* Disable upcalls and clear the threaded flag.
|
||||
* XXX - I don't think we need to disable upcalls after a fork().
|
||||
* but it doesn't hurt.
|
||||
*/
|
||||
crit = _kse_critical_enter();
|
||||
if (__isthreaded) {
|
||||
_thr_rtld_fini();
|
||||
_thr_signal_deinit();
|
||||
}
|
||||
__isthreaded = 0;
|
||||
/*
|
||||
* Restore signal mask early, so any memory problems could
|
||||
* dump core.
|
||||
*/
|
||||
sigprocmask(SIG_SETMASK, &curthread->sigmask, NULL);
|
||||
active_threads = 1;
|
||||
_thr_signal_deinit();
|
||||
|
||||
/*
|
||||
* Enter a loop to remove and free all threads other than
|
||||
@ -359,11 +360,18 @@ _kse_single_thread(struct pthread *curthread)
|
||||
_kse_initial = NULL;
|
||||
_libpthread_init(curthread);
|
||||
#else
|
||||
if (__isthreaded)
|
||||
if (__isthreaded) {
|
||||
_thr_rtld_fini();
|
||||
_thr_signal_deinit();
|
||||
}
|
||||
__isthreaded = 0;
|
||||
/*
|
||||
* Restore signal mask early, so any memory problems could
|
||||
* dump core.
|
||||
*/
|
||||
sigprocmask(SIG_SETMASK, &curthread->sigmask, NULL);
|
||||
curthread->kse->k_kcb->kcb_kmbx.km_curthread = NULL;
|
||||
__isthreaded = 0;
|
||||
active_threads = 0;
|
||||
active_threads = 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -410,18 +418,13 @@ _kse_isthreaded(void)
|
||||
int
|
||||
_kse_setthreaded(int threaded)
|
||||
{
|
||||
if ((threaded != 0) && (__isthreaded == 0)) {
|
||||
/*
|
||||
* Locking functions in libc are required when there are
|
||||
* threads other than the initial thread.
|
||||
*/
|
||||
__isthreaded = 1;
|
||||
sigset_t sigset;
|
||||
|
||||
if ((threaded != 0) && (__isthreaded == 0)) {
|
||||
/*
|
||||
* Tell the kernel to create a KSE for the initial thread
|
||||
* and enable upcalls in it.
|
||||
*/
|
||||
_thr_signal_init();
|
||||
_kse_initial->k_flags |= KF_STARTED;
|
||||
|
||||
#ifdef SYSTEM_SCOPE_ONLY
|
||||
@ -433,7 +436,17 @@ _kse_setthreaded(int threaded)
|
||||
KSE_SET_MBOX(_kse_initial, _thr_initial);
|
||||
_kse_initial->k_kcb->kcb_kmbx.km_flags |= KMF_BOUND;
|
||||
#endif
|
||||
SIGFILLSET(sigset);
|
||||
__sys_sigprocmask(SIG_SETMASK, &sigset, &_thr_initial->sigmask);
|
||||
_thr_signal_init();
|
||||
|
||||
/*
|
||||
* Locking functions in libc are required when there are
|
||||
* threads other than the initial thread.
|
||||
*/
|
||||
_thr_rtld_init();
|
||||
|
||||
__isthreaded = 1;
|
||||
if (kse_create(&_kse_initial->k_kcb->kcb_kmbx, 0) != 0) {
|
||||
_kse_initial->k_flags &= ~KF_STARTED;
|
||||
__isthreaded = 0;
|
||||
@ -447,8 +460,9 @@ _kse_setthreaded(int threaded)
|
||||
KSE_SET_MBOX(_kse_initial, _thr_initial);
|
||||
_thr_start_sig_daemon();
|
||||
_thr_setmaxconcurrency();
|
||||
#else
|
||||
__sys_sigprocmask(SIG_SETMASK, &_thr_initial->sigmask, NULL);
|
||||
#endif
|
||||
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
@ -1050,13 +1050,10 @@ thr_sigframe_save(struct pthread *thread, struct pthread_sigframe *psf)
|
||||
void
|
||||
_thr_signal_init(void)
|
||||
{
|
||||
sigset_t sigset;
|
||||
struct sigaction act;
|
||||
__siginfohandler_t *sigfunc;
|
||||
int i;
|
||||
|
||||
SIGFILLSET(sigset);
|
||||
__sys_sigprocmask(SIG_SETMASK, &sigset, &_thr_initial->sigmask);
|
||||
/* Enter a loop to get the existing signal status: */
|
||||
for (i = 1; i <= _SIG_MAXSIG; i++) {
|
||||
/* Check for signals which cannot be trapped: */
|
||||
@ -1078,7 +1075,8 @@ _thr_signal_init(void)
|
||||
((__sighandler_t *)sigfunc) != SIG_IGN) {
|
||||
act = _thread_sigact[i - 1];
|
||||
act.sa_flags |= SA_SIGINFO;
|
||||
act.sa_sigaction = (__siginfohandler_t *)_thr_sig_handler;
|
||||
act.sa_sigaction =
|
||||
(__siginfohandler_t *)_thr_sig_handler;
|
||||
__sys_sigaction(i, &act, NULL);
|
||||
}
|
||||
}
|
||||
@ -1097,21 +1095,13 @@ _thr_signal_init(void)
|
||||
*/
|
||||
PANIC("Cannot initialize signal handler");
|
||||
}
|
||||
#ifdef SYSTEM_SCOPE_ONLY
|
||||
__sys_sigprocmask(SIG_SETMASK, &_thr_initial->sigmask, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
_thr_signal_deinit(void)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
sigset_t tmpmask;
|
||||
int i;
|
||||
|
||||
SIGFILLSET(tmpmask);
|
||||
SIG_CANTMASK(tmpmask);
|
||||
__sys_sigprocmask(SIG_SETMASK, &tmpmask, NULL);
|
||||
/* Enter a loop to get the existing signal status: */
|
||||
for (i = 1; i <= _SIG_MAXSIG; i++) {
|
||||
/* Check for signals which cannot be trapped: */
|
||||
@ -1119,7 +1109,8 @@ _thr_signal_deinit(void)
|
||||
}
|
||||
|
||||
/* Set the signal handler details: */
|
||||
else if (__sys_sigaction(i, &_thread_sigact[i - 1], NULL) != 0) {
|
||||
else if (__sys_sigaction(i, &_thread_sigact[i - 1],
|
||||
NULL) != 0) {
|
||||
/*
|
||||
* Abort this process if signal
|
||||
* initialisation fails:
|
||||
@ -1127,6 +1118,5 @@ _thr_signal_deinit(void)
|
||||
PANIC("Cannot set signal handler info");
|
||||
}
|
||||
}
|
||||
__sys_sigprocmask(SIG_SETMASK, &curthread->sigmask, NULL);
|
||||
}
|
||||
|
||||
|
@ -309,8 +309,6 @@ _libpthread_init(struct pthread *curthread)
|
||||
_kcb_set(_thr_initial->kse->k_kcb);
|
||||
_tcb_set(_thr_initial->kse->k_kcb, _thr_initial->tcb);
|
||||
_thr_initial->kse->k_flags |= KF_INITIALIZED;
|
||||
|
||||
_thr_rtld_init();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -213,16 +213,17 @@ _kse_single_thread(struct pthread *curthread)
|
||||
kse_critical_t crit;
|
||||
int i;
|
||||
|
||||
|
||||
/*
|
||||
* Disable upcalls and clear the threaded flag.
|
||||
* XXX - I don't think we need to disable upcalls after a fork().
|
||||
* but it doesn't hurt.
|
||||
*/
|
||||
crit = _kse_critical_enter();
|
||||
if (__isthreaded) {
|
||||
_thr_rtld_fini();
|
||||
_thr_signal_deinit();
|
||||
}
|
||||
__isthreaded = 0;
|
||||
/*
|
||||
* Restore signal mask early, so any memory problems could
|
||||
* dump core.
|
||||
*/
|
||||
sigprocmask(SIG_SETMASK, &curthread->sigmask, NULL);
|
||||
active_threads = 1;
|
||||
_thr_signal_deinit();
|
||||
|
||||
/*
|
||||
* Enter a loop to remove and free all threads other than
|
||||
@ -359,11 +360,18 @@ _kse_single_thread(struct pthread *curthread)
|
||||
_kse_initial = NULL;
|
||||
_libpthread_init(curthread);
|
||||
#else
|
||||
if (__isthreaded)
|
||||
if (__isthreaded) {
|
||||
_thr_rtld_fini();
|
||||
_thr_signal_deinit();
|
||||
}
|
||||
__isthreaded = 0;
|
||||
/*
|
||||
* Restore signal mask early, so any memory problems could
|
||||
* dump core.
|
||||
*/
|
||||
sigprocmask(SIG_SETMASK, &curthread->sigmask, NULL);
|
||||
curthread->kse->k_kcb->kcb_kmbx.km_curthread = NULL;
|
||||
__isthreaded = 0;
|
||||
active_threads = 0;
|
||||
active_threads = 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -410,18 +418,13 @@ _kse_isthreaded(void)
|
||||
int
|
||||
_kse_setthreaded(int threaded)
|
||||
{
|
||||
if ((threaded != 0) && (__isthreaded == 0)) {
|
||||
/*
|
||||
* Locking functions in libc are required when there are
|
||||
* threads other than the initial thread.
|
||||
*/
|
||||
__isthreaded = 1;
|
||||
sigset_t sigset;
|
||||
|
||||
if ((threaded != 0) && (__isthreaded == 0)) {
|
||||
/*
|
||||
* Tell the kernel to create a KSE for the initial thread
|
||||
* and enable upcalls in it.
|
||||
*/
|
||||
_thr_signal_init();
|
||||
_kse_initial->k_flags |= KF_STARTED;
|
||||
|
||||
#ifdef SYSTEM_SCOPE_ONLY
|
||||
@ -433,7 +436,17 @@ _kse_setthreaded(int threaded)
|
||||
KSE_SET_MBOX(_kse_initial, _thr_initial);
|
||||
_kse_initial->k_kcb->kcb_kmbx.km_flags |= KMF_BOUND;
|
||||
#endif
|
||||
SIGFILLSET(sigset);
|
||||
__sys_sigprocmask(SIG_SETMASK, &sigset, &_thr_initial->sigmask);
|
||||
_thr_signal_init();
|
||||
|
||||
/*
|
||||
* Locking functions in libc are required when there are
|
||||
* threads other than the initial thread.
|
||||
*/
|
||||
_thr_rtld_init();
|
||||
|
||||
__isthreaded = 1;
|
||||
if (kse_create(&_kse_initial->k_kcb->kcb_kmbx, 0) != 0) {
|
||||
_kse_initial->k_flags &= ~KF_STARTED;
|
||||
__isthreaded = 0;
|
||||
@ -447,8 +460,9 @@ _kse_setthreaded(int threaded)
|
||||
KSE_SET_MBOX(_kse_initial, _thr_initial);
|
||||
_thr_start_sig_daemon();
|
||||
_thr_setmaxconcurrency();
|
||||
#else
|
||||
__sys_sigprocmask(SIG_SETMASK, &_thr_initial->sigmask, NULL);
|
||||
#endif
|
||||
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
@ -1050,13 +1050,10 @@ thr_sigframe_save(struct pthread *thread, struct pthread_sigframe *psf)
|
||||
void
|
||||
_thr_signal_init(void)
|
||||
{
|
||||
sigset_t sigset;
|
||||
struct sigaction act;
|
||||
__siginfohandler_t *sigfunc;
|
||||
int i;
|
||||
|
||||
SIGFILLSET(sigset);
|
||||
__sys_sigprocmask(SIG_SETMASK, &sigset, &_thr_initial->sigmask);
|
||||
/* Enter a loop to get the existing signal status: */
|
||||
for (i = 1; i <= _SIG_MAXSIG; i++) {
|
||||
/* Check for signals which cannot be trapped: */
|
||||
@ -1078,7 +1075,8 @@ _thr_signal_init(void)
|
||||
((__sighandler_t *)sigfunc) != SIG_IGN) {
|
||||
act = _thread_sigact[i - 1];
|
||||
act.sa_flags |= SA_SIGINFO;
|
||||
act.sa_sigaction = (__siginfohandler_t *)_thr_sig_handler;
|
||||
act.sa_sigaction =
|
||||
(__siginfohandler_t *)_thr_sig_handler;
|
||||
__sys_sigaction(i, &act, NULL);
|
||||
}
|
||||
}
|
||||
@ -1097,21 +1095,13 @@ _thr_signal_init(void)
|
||||
*/
|
||||
PANIC("Cannot initialize signal handler");
|
||||
}
|
||||
#ifdef SYSTEM_SCOPE_ONLY
|
||||
__sys_sigprocmask(SIG_SETMASK, &_thr_initial->sigmask, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
_thr_signal_deinit(void)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
sigset_t tmpmask;
|
||||
int i;
|
||||
|
||||
SIGFILLSET(tmpmask);
|
||||
SIG_CANTMASK(tmpmask);
|
||||
__sys_sigprocmask(SIG_SETMASK, &tmpmask, NULL);
|
||||
/* Enter a loop to get the existing signal status: */
|
||||
for (i = 1; i <= _SIG_MAXSIG; i++) {
|
||||
/* Check for signals which cannot be trapped: */
|
||||
@ -1119,7 +1109,8 @@ _thr_signal_deinit(void)
|
||||
}
|
||||
|
||||
/* Set the signal handler details: */
|
||||
else if (__sys_sigaction(i, &_thread_sigact[i - 1], NULL) != 0) {
|
||||
else if (__sys_sigaction(i, &_thread_sigact[i - 1],
|
||||
NULL) != 0) {
|
||||
/*
|
||||
* Abort this process if signal
|
||||
* initialisation fails:
|
||||
@ -1127,6 +1118,5 @@ _thr_signal_deinit(void)
|
||||
PANIC("Cannot set signal handler info");
|
||||
}
|
||||
}
|
||||
__sys_sigprocmask(SIG_SETMASK, &curthread->sigmask, NULL);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user