mirror of
https://github.com/mirror/tinycc.git
synced 2025-03-30 12:20:06 +08:00
Disable signals in bcheck.c pthread_create
glibc-2.32 contains new code to prevent a race conditions with signals in pthread_create.
This commit is contained in:
parent
8b69059f66
commit
54b4aa3cd6
29
lib/bcheck.c
29
lib/bcheck.c
@ -1242,46 +1242,53 @@ void __attribute__((destructor)) __bound_exit(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if HAVE_PTHREAD_CREATE
|
#if HAVE_PTHREAD_CREATE
|
||||||
#if HAVE_TLS_FUNC
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void *(*start_routine) (void *);
|
void *(*start_routine) (void *);
|
||||||
void *arg;
|
void *arg;
|
||||||
|
sigset_t old_mask;
|
||||||
} bound_thread_create_type;
|
} bound_thread_create_type;
|
||||||
|
|
||||||
static void *bound_thread_create(void *bdata)
|
static void *bound_thread_create(void *bdata)
|
||||||
{
|
{
|
||||||
bound_thread_create_type *data = (bound_thread_create_type *) bdata;
|
bound_thread_create_type *data = (bound_thread_create_type *) bdata;
|
||||||
void *retval;
|
void *retval;
|
||||||
|
#if HAVE_TLS_FUNC
|
||||||
int *p = (int *) BOUND_MALLOC(sizeof(int));
|
int *p = (int *) BOUND_MALLOC(sizeof(int));
|
||||||
|
|
||||||
if (!p) bound_alloc_error("bound_thread_create malloc");
|
if (!p) bound_alloc_error("bound_thread_create malloc");
|
||||||
*p = 0;
|
*p = 0;
|
||||||
pthread_setspecific(no_checking_key, p);
|
pthread_setspecific(no_checking_key, p);
|
||||||
|
#endif
|
||||||
|
pthread_sigmask(SIG_SETMASK, &data->old_mask, NULL);
|
||||||
retval = data->start_routine(data->arg);
|
retval = data->start_routine(data->arg);
|
||||||
|
#if HAVE_TLS_FUNC
|
||||||
pthread_setspecific(no_checking_key, NULL);
|
pthread_setspecific(no_checking_key, NULL);
|
||||||
BOUND_FREE (p);
|
BOUND_FREE (p);
|
||||||
|
#endif
|
||||||
BOUND_FREE (data);
|
BOUND_FREE (data);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
|
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
|
||||||
void *(*start_routine) (void *), void *arg)
|
void *(*start_routine) (void *), void *arg)
|
||||||
{
|
{
|
||||||
|
int retval;
|
||||||
|
bound_thread_create_type *data;
|
||||||
|
sigset_t mask;
|
||||||
|
sigset_t old_mask;
|
||||||
|
|
||||||
use_sem = 1;
|
use_sem = 1;
|
||||||
dprintf (stderr, "%s, %s()\n", __FILE__, __FUNCTION__);
|
dprintf (stderr, "%s, %s()\n", __FILE__, __FUNCTION__);
|
||||||
#if HAVE_TLS_FUNC
|
sigfillset(&mask);
|
||||||
{
|
pthread_sigmask(SIG_SETMASK, &mask, &old_mask);
|
||||||
bound_thread_create_type *data;
|
|
||||||
|
|
||||||
data = (bound_thread_create_type *) BOUND_MALLOC(sizeof(bound_thread_create_type));
|
data = (bound_thread_create_type *) BOUND_MALLOC(sizeof(bound_thread_create_type));
|
||||||
|
if (!data) bound_alloc_error("bound_thread_create malloc");
|
||||||
data->start_routine = start_routine;
|
data->start_routine = start_routine;
|
||||||
data->arg = arg;
|
data->arg = arg;
|
||||||
return pthread_create_redir(thread, attr, bound_thread_create, data);
|
data->old_mask = old_mask;
|
||||||
}
|
retval = pthread_create_redir(thread, attr, bound_thread_create, data);
|
||||||
#else
|
pthread_sigmask(SIG_SETMASK, &old_mask, NULL);
|
||||||
return pthread_create_redir(thread, attr, start_routine, arg);
|
return retval;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ main (void)
|
|||||||
sem_init (&sem_child, 0, 0);
|
sem_init (&sem_child, 0, 0);
|
||||||
pthread_create(&id1, NULL, high_load, NULL);
|
pthread_create(&id1, NULL, high_load, NULL);
|
||||||
pthread_create(&id2, NULL, do_signal, NULL);
|
pthread_create(&id2, NULL, do_signal, NULL);
|
||||||
#if !defined(__arm__) && !defined(__APPLE__)
|
#if !defined(__APPLE__)
|
||||||
pthread_create(&id3, NULL, do_fork, NULL);
|
pthread_create(&id3, NULL, do_fork, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ main (void)
|
|||||||
|
|
||||||
pthread_join(id1, NULL);
|
pthread_join(id1, NULL);
|
||||||
pthread_join(id2, NULL);
|
pthread_join(id2, NULL);
|
||||||
#if !defined(__arm__) && !defined(__APPLE__)
|
#if !defined(__APPLE__)
|
||||||
pthread_join(id3, NULL);
|
pthread_join(id3, NULL);
|
||||||
#endif
|
#endif
|
||||||
sem_destroy (&sem);
|
sem_destroy (&sem);
|
||||||
|
Loading…
Reference in New Issue
Block a user