Changeset f356618 in mainline for uspace/lib/c/generic/tls.c


Ignore:
Timestamp:
2016-05-22T21:05:55Z (9 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b3364b7c
Parents:
af2254ec (diff), 3a9414e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge dynamic linking support for thread local storage.

File:
1 edited

Legend:

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

    raf2254ec rf356618  
    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#ifdef CONFIG_RTLD
     50        if (runtime_env != NULL)
     51                return runtime_env->tls_size;
     52#endif
     53        return &_tbss_end - &_tdata_start;
     54}
     55
     56/** Get address of static TLS block */
     57void *tls_get(void)
     58{
     59#ifdef CONFIG_TLS_VARIANT_1
     60        return (uint8_t *)__tcb_get() + sizeof(tcb_t);
     61#else /* CONFIG_TLS_VARIANT_2 */
     62        return (uint8_t *)__tcb_get() - tls_get_size();
     63#endif
     64}
     65
    4666/** 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.
    5067 *
    5168 * @return Pointer to TCB.
     
    5673        tcb_t *tcb;
    5774        size_t tls_size = &_tbss_end - &_tdata_start;
    58        
     75
     76#ifdef CONFIG_RTLD
     77        if (runtime_env != NULL)
     78                return rtld_tls_make(runtime_env);
     79#endif
    5980        tcb = tls_alloc_arch(&data, tls_size);
    6081        if (!tcb)
    6182                return NULL;
    62        
     83
    6384        /*
    6485         * Copy thread local data from the initialization image.
     
    7697void tls_free(tcb_t *tcb)
    7798{
    78         size_t tls_size = &_tbss_end - &_tdata_start;
    79         tls_free_arch(tcb, tls_size);
     99#ifdef CONFIG_RTLD
     100        free(tcb->dtv);
     101#endif
     102        tls_free_arch(tcb, tls_get_size());
    80103}
    81104
     
    89112tcb_t *tls_alloc_variant_1(void **data, size_t size)
    90113{
    91         tcb_t *result;
     114        tcb_t *tcb;
    92115
    93         result = malloc(sizeof(tcb_t) + size);
    94         if (!result)
     116        tcb = malloc(sizeof(tcb_t) + size);
     117        if (!tcb)
    95118                return NULL;
    96         *data = ((void *)result) + sizeof(tcb_t);
     119        *data = ((void *)tcb) + sizeof(tcb_t);
     120#ifdef CONFIG_RTLD
     121        tcb->dtv = NULL;
     122#endif
    97123
    98         return result;
     124        return tcb;
    99125}
    100126
     
    121147{
    122148        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)
     149
     150        *data = malloc(sizeof(tcb_t) + size);
     151        if (*data == NULL)
    127152                return NULL;
    128153        tcb = (tcb_t *) (*data + size);
    129154        tcb->self = tcb;
     155#ifdef CONFIG_RTLD
     156        tcb->dtv = NULL;
     157#endif
    130158
    131159        return tcb;
     
    139167void tls_free_variant_2(tcb_t *tcb, size_t size)
    140168{
    141         size = ALIGN_UP(size, &_tls_alignment);
    142169        void *start = ((void *) tcb) - size;
    143170        free(start);
Note: See TracChangeset for help on using the changeset viewer.