Changeset 6adb775f in mainline for uspace/lib/c/generic/tls.c


Ignore:
Timestamp:
2016-04-25T16:46:31Z (8 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
32573ff
Parents:
dc0d8b52
Message:

TLS for dynamically linked executables and initially loaded DSOs (but must not call dlopen or there will be trouble).

File:
1 edited

Legend:

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

    rdc0d8b52 r6adb775f  
    3434 * Support for thread-local storage, as described in:
    3535 *      Drepper U.: ELF Handling For Thread-Local Storage, 2005
    36  *
    37  * Only static model is supported.
    38  */
     36 */
    3937
    4038#include <tls.h>
    4139#include <malloc.h>
    4240#include <str.h>
    43 #include <align.h>
    4441#include <unistd.h>
    4542
     43#ifdef CONFIG_RTLD
     44#include <rtld/rtld.h>
     45#endif
     46
     47size_t tls_get_size(void)
     48{
     49        return &_tbss_end - &_tdata_start;
     50}
     51
    4652/** Create TLS (Thread Local Storage) data structures.
    47  *
    48  * The code requires, that sections .tdata and .tbss are adjacent. It may be
    49  * changed in the future.
    5053 *
    5154 * @return Pointer to TCB.
     
    5659        tcb_t *tcb;
    5760        size_t tls_size = &_tbss_end - &_tdata_start;
    58        
     61
     62#ifdef CONFIG_RTLD
     63        if (runtime_env != NULL)
     64                return rtld_tls_make(runtime_env);
     65#endif
    5966        tcb = tls_alloc_arch(&data, tls_size);
    6067        if (!tcb)
    6168                return NULL;
    62        
     69
    6370        /*
    6471         * Copy thread local data from the initialization image.
     
    7784{
    7885        size_t tls_size = &_tbss_end - &_tdata_start;
     86
     87#ifdef CONFIG_RTLD
     88        if (runtime_env != NULL)
     89                tls_size = runtime_env->tls_size;
     90#endif
    7991        tls_free_arch(tcb, tls_size);
    8092}
     
    121133{
    122134        tcb_t *tcb;
    123        
    124         size = ALIGN_UP(size, &_tls_alignment);
    125         *data = memalign((uintptr_t) &_tls_alignment, sizeof(tcb_t) + size);
    126         if (!*data)
     135
     136        *data = malloc(sizeof(tcb_t) + size);
     137        if (*data == NULL)
    127138                return NULL;
    128139        tcb = (tcb_t *) (*data + size);
     
    139150void tls_free_variant_2(tcb_t *tcb, size_t size)
    140151{
    141         size = ALIGN_UP(size, &_tls_alignment);
    142152        void *start = ((void *) tcb) - size;
    143153        free(start);
Note: See TracChangeset for help on using the changeset viewer.