Ignore:
File:
1 edited

Legend:

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

    r6adb775f r31399f3  
    3434 * Support for thread-local storage, as described in:
    3535 *      Drepper U.: ELF Handling For Thread-Local Storage, 2005
    36  */
     36 *
     37 * Only static model is supported.
     38 */
    3739
    3840#include <tls.h>
    3941#include <malloc.h>
    4042#include <str.h>
     43#include <align.h>
    4144#include <unistd.h>
    4245
    43 #ifdef CONFIG_RTLD
    44 #include <rtld/rtld.h>
    45 #endif
    46 
    47 size_t tls_get_size(void)
    48 {
    49         return &_tbss_end - &_tdata_start;
    50 }
    51 
    5246/** 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.
    5350 *
    5451 * @return Pointer to TCB.
     
    5956        tcb_t *tcb;
    6057        size_t tls_size = &_tbss_end - &_tdata_start;
    61 
    62 #ifdef CONFIG_RTLD
    63         if (runtime_env != NULL)
    64                 return rtld_tls_make(runtime_env);
    65 #endif
     58       
    6659        tcb = tls_alloc_arch(&data, tls_size);
    6760        if (!tcb)
    6861                return NULL;
    69 
     62       
    7063        /*
    7164         * Copy thread local data from the initialization image.
     
    8477{
    8578        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
    9179        tls_free_arch(tcb, tls_size);
    9280}
     
    133121{
    134122        tcb_t *tcb;
    135 
    136         *data = malloc(sizeof(tcb_t) + size);
    137         if (*data == NULL)
     123       
     124        size = ALIGN_UP(size, &_tls_alignment);
     125        *data = memalign((uintptr_t) &_tls_alignment, sizeof(tcb_t) + size);
     126        if (!*data)
    138127                return NULL;
    139128        tcb = (tcb_t *) (*data + size);
     
    150139void tls_free_variant_2(tcb_t *tcb, size_t size)
    151140{
     141        size = ALIGN_UP(size, &_tls_alignment);
    152142        void *start = ((void *) tcb) - size;
    153143        free(start);
Note: See TracChangeset for help on using the changeset viewer.