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
12421242 }
12431243
12441244 #if HAVE_PTHREAD_CREATE
1245−#if HAVE_TLS_FUNC
12461245 typedef struct {
12471246 void *(*start_routine) (void *);
12481247 void *arg;
1248+ sigset_t old_mask;
12491249 } bound_thread_create_type;
12501250
12511251 static void *bound_thread_create(void *bdata)
12521252 {
12531253 bound_thread_create_type *data = (bound_thread_create_type *) bdata;
12541254 void *retval;
1255+#if HAVE_TLS_FUNC
12551256 int *p = (int *) BOUND_MALLOC(sizeof(int));
12561257
12571258 if (!p) bound_alloc_error("bound_thread_create malloc");
12581259 *p = 0;
12591260 pthread_setspecific(no_checking_key, p);
1261+#endif
1262+ pthread_sigmask(SIG_SETMASK, &data->old_mask, NULL);
12601263 retval = data->start_routine(data->arg);
1264+#if HAVE_TLS_FUNC
12611265 pthread_setspecific(no_checking_key, NULL);
12621266 BOUND_FREE (p);
1267+#endif
12631268 BOUND_FREE (data);
12641269 return retval;
12651270 }
1266−#endif
12671271
12681272 int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
12691273 void *(*start_routine) (void *), void *arg)
12701274 {
1275+ int retval;
1276+ bound_thread_create_type *data;
1277+ sigset_t mask;
1278+ sigset_t old_mask;
1279+
12711280 use_sem = 1;
12721281 dprintf (stderr, "%s, %s()\n", __FILE__, __FUNCTION__);
1273−#if HAVE_TLS_FUNC
1274− {
1275− bound_thread_create_type *data;
1276−
1277− data = (bound_thread_create_type *) BOUND_MALLOC(sizeof(bound_thread_create_type));
1278− data->start_routine = start_routine;
1279− data->arg = arg;
1280− return pthread_create_redir(thread, attr, bound_thread_create, data);
1281− }
1282−#else
1283− return pthread_create_redir(thread, attr, start_routine, arg);
1284−#endif
1282+ sigfillset(&mask);
1283+ pthread_sigmask(SIG_SETMASK, &mask, &old_mask);
1284+ data = (bound_thread_create_type *) BOUND_MALLOC(sizeof(bound_thread_create_type));
1285+ if (!data) bound_alloc_error("bound_thread_create malloc");
1286+ data->start_routine = start_routine;
1287+ data->arg = arg;
1288+ data->old_mask = old_mask;
1289+ retval = pthread_create_redir(thread, attr, bound_thread_create, data);
1290+ pthread_sigmask(SIG_SETMASK, &old_mask, NULL);
1291+ return retval;
12851292 }
12861293 #endif
12871294
tests/tests2/114_bound_signal.c+2−2
@@ -107,7 +107,7 @@ main (void) · 106 unmodified lines
107107 sem_init (&sem_child, 0, 0);
108108 pthread_create(&id1, NULL, high_load, NULL);
109109 pthread_create(&id2, NULL, do_signal, NULL);
110−#if !defined(__arm__) && !defined(__APPLE__)
110+#if !defined(__APPLE__)
111111 pthread_create(&id3, NULL, do_fork, NULL);
112112 #endif
113113
@@ -120,7 +120,7 @@ main (void) · 6 unmodified lines
120120
121121 pthread_join(id1, NULL);
122122 pthread_join(id2, NULL);
123−#if !defined(__arm__) && !defined(__APPLE__)
123+#if !defined(__APPLE__)
124124 pthread_join(id3, NULL);
125125 #endif
126126 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