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


Ignore:
Timestamp:
2016-05-24T15:32:57Z (9 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c170438
Parents:
dcc150cb (diff), 0a981e3 (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 with mainline

File:
1 edited

Legend:

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

    rdcc150cb rf570cdf  
    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
     38#include <align.h>
    4039#include <tls.h>
    4140#include <malloc.h>
    4241#include <str.h>
    43 #include <align.h>
    4442#include <unistd.h>
    4543
     44#ifdef CONFIG_RTLD
     45#include <rtld/rtld.h>
     46#endif
     47
     48size_t tls_get_size(void)
     49{
     50#ifdef CONFIG_RTLD
     51        if (runtime_env != NULL)
     52                return runtime_env->tls_size;
     53#endif
     54        return &_tbss_end - &_tdata_start;
     55}
     56
     57/** Get address of static TLS block */
     58void *tls_get(void)
     59{
     60#ifdef CONFIG_TLS_VARIANT_1
     61        return (uint8_t *)__tcb_get() + sizeof(tcb_t);
     62#else /* CONFIG_TLS_VARIANT_2 */
     63        return (uint8_t *)__tcb_get() - tls_get_size();
     64#endif
     65}
     66
    4667/** 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.
    5068 *
    5169 * @return Pointer to TCB.
     
    5674        tcb_t *tcb;
    5775        size_t tls_size = &_tbss_end - &_tdata_start;
    58        
     76
     77#ifdef CONFIG_RTLD
     78        if (runtime_env != NULL)
     79                return rtld_tls_make(runtime_env);
     80#endif
    5981        tcb = tls_alloc_arch(&data, tls_size);
    6082        if (!tcb)
    6183                return NULL;
    62        
     84
    6385        /*
    6486         * Copy thread local data from the initialization image.
     
    7698void tls_free(tcb_t *tcb)
    7799{
    78         size_t tls_size = &_tbss_end - &_tdata_start;
    79         tls_free_arch(tcb, tls_size);
     100#ifdef CONFIG_RTLD
     101        free(tcb->dtv);
     102#endif
     103        tls_free_arch(tcb, tls_get_size());
    80104}
    81105
     
    89113tcb_t *tls_alloc_variant_1(void **data, size_t size)
    90114{
    91         tcb_t *result;
     115        tcb_t *tcb;
    92116
    93         result = malloc(sizeof(tcb_t) + size);
    94         if (!result)
     117        tcb = malloc(sizeof(tcb_t) + size);
     118        if (!tcb)
    95119                return NULL;
    96         *data = ((void *)result) + sizeof(tcb_t);
     120        *data = ((void *)tcb) + sizeof(tcb_t);
     121#ifdef CONFIG_RTLD
     122        tcb->dtv = NULL;
     123#endif
    97124
    98         return result;
     125        return tcb;
    99126}
    100127
     
    121148{
    122149        tcb_t *tcb;
    123        
     150
    124151        size = ALIGN_UP(size, &_tls_alignment);
    125152        *data = memalign((uintptr_t) &_tls_alignment, sizeof(tcb_t) + size);
    126         if (!*data)
     153        if (*data == NULL)
    127154                return NULL;
    128155        tcb = (tcb_t *) (*data + size);
    129156        tcb->self = tcb;
     157#ifdef CONFIG_RTLD
     158        tcb->dtv = NULL;
     159#endif
    130160
    131161        return tcb;
Note: See TracChangeset for help on using the changeset viewer.