Changeset 40abf56 in mainline for uspace/lib/c/generic/thread.c


Ignore:
Timestamp:
2018-07-18T19:42:28Z (7 years ago)
Author:
Jiří Zárevúcky <jiri.zarevucky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9bde0d5
Parents:
0b05082
git-author:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-07-18 19:05:08)
git-committer:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-07-18 19:42:28)
Message:

Make sure that a thread with uninitialized TLS does not need to call malloc()
to initialize it.

For threads and tasks created by loader, we create TLS beforehand and pass
it to the child. For tasks spawned directly by the kernel, we require it is
a static executable and allocate the initial TLS using as_area_create() instead
of the libc allocator.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/thread.c

    r0b05082 r40abf56  
    5858void __thread_main(uspace_arg_t *uarg)
    5959{
    60         fibril_t *fibril = fibril_setup();
    61         if (fibril == NULL)
    62                 thread_exit(0);
     60        assert(!__tcb_is_set());
     61
     62        fibril_t *fibril = uarg->uspace_thread_arg;
     63        assert(fibril);
    6364
    6465        __tcb_set(fibril->tcb);
    6566
    66         uarg->uspace_thread_function(uarg->uspace_thread_arg);
     67        uarg->uspace_thread_function(fibril->arg);
    6768        /*
    6869         * XXX: we cannot free the userspace stack while running on it
     
    9596    thread_id_t *tid)
    9697{
    97         uspace_arg_t *uarg =
    98             (uspace_arg_t *) malloc(sizeof(uspace_arg_t));
     98        uspace_arg_t *uarg = calloc(1, sizeof(uspace_arg_t));
    9999        if (!uarg)
    100100                return ENOMEM;
     101
     102        fibril_t *fibril = fibril_alloc();
     103        if (!fibril) {
     104                free(uarg);
     105                return ENOMEM;
     106        }
    101107
    102108        size_t stack_size = stack_size_get();
     
    105111            AS_AREA_LATE_RESERVE, AS_AREA_UNPAGED);
    106112        if (stack == AS_MAP_FAILED) {
     113                fibril_teardown(fibril, false);
    107114                free(uarg);
    108115                return ENOMEM;
     
    112119        malloc_enable_multithreaded();
    113120
     121        fibril->arg = arg;
    114122        uarg->uspace_entry = (void *) FADDR(__thread_entry);
    115123        uarg->uspace_stack = stack;
    116124        uarg->uspace_stack_size = stack_size;
    117125        uarg->uspace_thread_function = function;
    118         uarg->uspace_thread_arg = arg;
     126        uarg->uspace_thread_arg = fibril;
    119127        uarg->uspace_uarg = uarg;
    120128
Note: See TracChangeset for help on using the changeset viewer.