Changeset 40abf56 in mainline for uspace/lib/c/generic/libc.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/libc.c

    r0b05082 r40abf56  
    6363progsymbols_t __progsymbols;
    6464
    65 static bool env_setup = false;
     65static bool env_setup;
     66static fibril_t main_fibril;
    6667
    6768void __libc_main(void *pcb_ptr)
    6869{
     70        assert(!__tcb_is_set());
     71
     72        __pcb = (pcb_t *) pcb_ptr;
     73
     74        if (__pcb) {
     75                main_fibril.tcb = __pcb->tcb;
     76        } else {
     77                /*
     78                 * Loaded by kernel, not the loader.
     79                 * Kernel only supports loading fully static binaries,
     80                 * so we can do basic initialization without worrying about
     81                 * dynamic libraries.
     82                 */
     83
     84                main_fibril.tcb = tls_make_initial(__progsymbols.elfstart);
     85        }
     86
     87        assert(main_fibril.tcb);
     88
     89        /* Initialize the fibril. */
     90        main_fibril.tcb->fibril_data = &main_fibril;
     91        __tcb_set(main_fibril.tcb);
     92        fibril_setup(&main_fibril);
     93
    6994        /* Initialize user task run-time environment */
    7095        __malloc_init();
    71 
    72         /* Save the PCB pointer */
    73         __pcb = (pcb_t *) pcb_ptr;
    7496
    7597#ifdef CONFIG_RTLD
     
    81103        }
    82104#endif
    83 
    84         fibril_t *fibril = fibril_setup();
    85         if (fibril == NULL)
    86                 abort();
    87 
    88         __tcb_set(fibril->tcb);
    89105
    90106        __async_server_init();
     
    151167                __stdio_done();
    152168                task_retval(status);
    153                 fibril_teardown(__tcb_get()->fibril_data, false);
    154169        }
    155170
Note: See TracChangeset for help on using the changeset viewer.