@@ -71,6 +71,10 @@ static int dummy_getpid(void) {
71
71
}
72
72
weak_alias (dummy_getpid , __syscall_getpid );
73
73
74
+ /* pthread_key_create.c overrides this */
75
+ static volatile size_t dummy = 0 ;
76
+ weak_alias (dummy , __pthread_tsd_size );
77
+
74
78
int __pthread_create (pthread_t * restrict res ,
75
79
const pthread_attr_t * restrict attrp ,
76
80
void * (* entry )(void * ),
@@ -116,8 +120,10 @@ int __pthread_create(pthread_t* restrict res,
116
120
new -> locale = & libc .global_locale ;
117
121
118
122
// Allocate memory for thread-local storage and initialize it to zero.
119
- new -> tsd = malloc (PTHREAD_KEYS_MAX * sizeof (void * ));
120
- memset (new -> tsd , 0 , PTHREAD_KEYS_MAX * sizeof (void * ));
123
+ if (__pthread_tsd_size ) {
124
+ new -> tsd = malloc (__pthread_tsd_size );
125
+ memset (new -> tsd , 0 , __pthread_tsd_size );
126
+ }
121
127
122
128
new -> detach_state = DT_JOINABLE ;
123
129
@@ -237,8 +243,10 @@ void _emscripten_thread_exit(void* result) {
237
243
238
244
// We have the call the buildin free here since lsan handling for this thread
239
245
// gets shut down during __pthread_tsd_run_dtors.
240
- emscripten_builtin_free (self -> tsd );
241
- self -> tsd = NULL ;
246
+ if (self -> tsd ) {
247
+ emscripten_builtin_free (self -> tsd );
248
+ self -> tsd = NULL ;
249
+ }
242
250
243
251
// Not hosting a pthread anymore in this worker set __pthread_self to NULL
244
252
__set_thread_state (NULL , 0 , 0 , 1 );
0 commit comments