History

Disable signals in bcheck.c pthread_create

glibc-2.32 contains new code to prevent a race conditions with signals in pthread_create.

herman ten brugge committed 6 years ago

Commit 54b4aa31 parent 8b690592 files · +23 −16Browse files

Unified · Split

2 files
  1. lib/bcheck.c +21 −14
  2. tests/tests2/114_bound_signal.c +2 −2
lib/bcheck.c+21−14
@@ -1242,46 +1242,53 @@ void __attribute__((destructor)) __bound_exit(void) · 1241 unmodified lines
1242}1242}
1243 1243
1244#if HAVE_PTHREAD_CREATE1244#if HAVE_PTHREAD_CREATE
1245#if HAVE_TLS_FUNC
1246typedef struct {1245typedef struct {
1247 void *(*start_routine) (void *);1246 void *(*start_routine) (void *);
1248 void *arg;1247 void *arg;
1248 sigset_t old_mask;
1249} bound_thread_create_type;1249} bound_thread_create_type;
1250 1250
1251static void *bound_thread_create(void *bdata)1251static void *bound_thread_create(void *bdata)
1252{1252{
1253 bound_thread_create_type *data = (bound_thread_create_type *) bdata;1253 bound_thread_create_type *data = (bound_thread_create_type *) bdata;
1254 void *retval;1254 void *retval;
1255#if HAVE_TLS_FUNC
1255 int *p = (int *) BOUND_MALLOC(sizeof(int));1256 int *p = (int *) BOUND_MALLOC(sizeof(int));
1256 1257
1257 if (!p) bound_alloc_error("bound_thread_create malloc");1258 if (!p) bound_alloc_error("bound_thread_create malloc");
1258 *p = 0;1259 *p = 0;
1259 pthread_setspecific(no_checking_key, p);1260 pthread_setspecific(no_checking_key, p);
1261#endif
1262 pthread_sigmask(SIG_SETMASK, &data->old_mask, NULL);
1260 retval = data->start_routine(data->arg);1263 retval = data->start_routine(data->arg);
1264#if HAVE_TLS_FUNC
1261 pthread_setspecific(no_checking_key, NULL);1265 pthread_setspecific(no_checking_key, NULL);
1262 BOUND_FREE (p);1266 BOUND_FREE (p);
1267#endif
1263 BOUND_FREE (data);1268 BOUND_FREE (data);
1264 return retval;1269 return retval;
1265}1270}
1266#endif
1267 1271
1268int pthread_create(pthread_t *thread, const pthread_attr_t *attr,1272int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
1269 void *(*start_routine) (void *), void *arg)1273 void *(*start_routine) (void *), void *arg)
1270{1274{
1275 int retval;
1276 bound_thread_create_type *data;
1277 sigset_t mask;
1278 sigset_t old_mask;
1279
1271 use_sem = 1;1280 use_sem = 1;
1272 dprintf (stderr, "%s, %s()\n", __FILE__, __FUNCTION__);1281 dprintf (stderr, "%s, %s()\n", __FILE__, __FUNCTION__);
1273#if HAVE_TLS_FUNC1282 sigfillset(&mask);
1274 {1283 pthread_sigmask(SIG_SETMASK, &mask, &old_mask);
1275 bound_thread_create_type *data;1284 data = (bound_thread_create_type *) BOUND_MALLOC(sizeof(bound_thread_create_type));
1276 1285 if (!data) bound_alloc_error("bound_thread_create malloc");
1277 data = (bound_thread_create_type *) BOUND_MALLOC(sizeof(bound_thread_create_type));1286 data->start_routine = start_routine;
1278 data->start_routine = start_routine;1287 data->arg = arg;
1279 data->arg = arg;1288 data->old_mask = old_mask;
1280 return pthread_create_redir(thread, attr, bound_thread_create, data);1289 retval = pthread_create_redir(thread, attr, bound_thread_create, data);
1281 }1290 pthread_sigmask(SIG_SETMASK, &old_mask, NULL);
1282#else1291 return retval;
1283 return pthread_create_redir(thread, attr, start_routine, arg);
1284#endif
1285}1292}
1286#endif1293#endif
1287 1294
tests/tests2/114_bound_signal.c+2−2
@@ -107,7 +107,7 @@ main (void) · 106 unmodified lines
107 sem_init (&sem_child, 0, 0);107 sem_init (&sem_child, 0, 0);
108 pthread_create(&id1, NULL, high_load, NULL);108 pthread_create(&id1, NULL, high_load, NULL);
109 pthread_create(&id2, NULL, do_signal, NULL);109 pthread_create(&id2, NULL, do_signal, NULL);
110#if !defined(__arm__) && !defined(__APPLE__)110#if !defined(__APPLE__)
111 pthread_create(&id3, NULL, do_fork, NULL);111 pthread_create(&id3, NULL, do_fork, NULL);
112#endif112#endif
113 113
@@ -120,7 +120,7 @@ main (void) · 6 unmodified lines
120 120
121 pthread_join(id1, NULL);121 pthread_join(id1, NULL);
122 pthread_join(id2, NULL);122 pthread_join(id2, NULL);
123#if !defined(__arm__) && !defined(__APPLE__)123#if !defined(__APPLE__)
124 pthread_join(id3, NULL);124 pthread_join(id3, NULL);
125#endif125#endif
126 sem_destroy (&sem);126 sem_destroy (&sem);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t