* map + size ----------------------------------------------------------
*/
+static const size_t __uk_tsd_size = sizeof(void *) * PTHREAD_KEYS_MAX;
void *__uk_copy_tls(unsigned char *mem)
{
{
pthread_t td = p;
+ /*
+ * Clean and initialize pthread structure for init thread.
+ * FIXME: Some fields from pthread are not initialized yet:
+ * - information about stack
+ * - canary
+ */
+ memset(td, 0, sizeof(*td));
+
+ td->tsd = (void *)uk_memalign(uk_alloc_get_default(), __PAGE_SIZE,
+ __uk_tsd_size);
+ if (!td->tsd)
+ UK_CRASH("Failed to initialize init thread tsd\n");
+
+ memset(td->tsd, 0, __uk_tsd_size);
+
+ /*
+ * The initial thread in the new image shall be joinable, as if
+ * created with the detachstate attribute set to
+ * PTHREAD_CREATE_JOINABLE.
+ */
+ td->detach_state = DT_JOINABLE;
+
/* Musl maintains a circular doubly linked list for threads. */
td->self = td->next = td->prev = td;
/*
libc.page_size = __PAGE_SIZE;
}
-static const size_t __uk_tsd_size = sizeof(void *) * PTHREAD_KEYS_MAX;
-
/*
* This callback will only be called for threads that are NOT
* created with the pthread API but we still want them to be