If these fields are not initialized as expected by musl, then calls
to pthread functions such `pthread_getspecific` can return unexpected
values or even crash.
Signed-off-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Eduard Vintilă <eduard.vintila47@gmail.com>
Reviewed-by: Sergiu Moga <sergiu.moga@protonmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #41
*/
int uk_thread_uktcb_init(struct uk_thread *thread, void *tcb)
{
+ struct pthread *self = pthread_self();
struct pthread *td = (struct pthread *) tcb;
uk_pr_debug("%s uk_thread %p, tcb %p\n", __func__, thread, tcb);
uk_alloc_get_default(),
__PAGE_SIZE,
__uk_tsd_size);
+ /* musl expects that the tsd area is zero-initialized and will not
+ * zero the pointers on pthread_key_create.
+ */
+ memset(td->tsd, 0, __uk_tsd_size);
td->locale = &libc.global_locale;
+ td->next = self->next;
+ td->prev = self;
+ td->next->prev = td;
+ td->prev->next = td;
return 0;
}