Changes in uspace/lib/c/generic/tls.c [58563585:31399f3] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/tls.c
r58563585 r31399f3 34 34 * Support for thread-local storage, as described in: 35 35 * Drepper U.: ELF Handling For Thread-Local Storage, 2005 36 */ 36 * 37 * Only static model is supported. 38 */ 37 39 38 #include <align.h>39 40 #include <tls.h> 40 41 #include <malloc.h> 41 42 #include <str.h> 43 #include <align.h> 42 44 #include <unistd.h> 43 45 44 #ifdef CONFIG_RTLD45 #include <rtld/rtld.h>46 #endif47 48 size_t tls_get_size(void)49 {50 #ifdef CONFIG_RTLD51 if (runtime_env != NULL)52 return runtime_env->tls_size;53 #endif54 return &_tbss_end - &_tdata_start;55 }56 57 /** Get address of static TLS block */58 void *tls_get(void)59 {60 #ifdef CONFIG_TLS_VARIANT_161 return (uint8_t *)__tcb_get() + sizeof(tcb_t);62 #else /* CONFIG_TLS_VARIANT_2 */63 return (uint8_t *)__tcb_get() - tls_get_size();64 #endif65 }66 67 46 /** 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. 68 50 * 69 51 * @return Pointer to TCB. … … 74 56 tcb_t *tcb; 75 57 size_t tls_size = &_tbss_end - &_tdata_start; 76 77 #ifdef CONFIG_RTLD78 if (runtime_env != NULL)79 return rtld_tls_make(runtime_env);80 #endif81 58 82 59 tcb = tls_alloc_arch(&data, tls_size); … … 99 76 void tls_free(tcb_t *tcb) 100 77 { 101 #ifdef CONFIG_RTLD 102 free(tcb->dtv); 103 #endif 104 tls_free_arch(tcb, tls_get_size()); 78 size_t tls_size = &_tbss_end - &_tdata_start; 79 tls_free_arch(tcb, tls_size); 105 80 } 106 81 … … 114 89 tcb_t *tls_alloc_variant_1(void **data, size_t size) 115 90 { 116 tcb_t * tcb;91 tcb_t *result; 117 92 118 tcb= malloc(sizeof(tcb_t) + size);119 if (! tcb)93 result = malloc(sizeof(tcb_t) + size); 94 if (!result) 120 95 return NULL; 121 122 *data = ((void *) tcb) + sizeof(tcb_t); 123 #ifdef CONFIG_RTLD 124 tcb->dtv = NULL; 125 #endif 96 *data = ((void *)result) + sizeof(tcb_t); 126 97 127 return tcb;98 return result; 128 99 } 129 100 … … 153 124 size = ALIGN_UP(size, &_tls_alignment); 154 125 *data = memalign((uintptr_t) &_tls_alignment, sizeof(tcb_t) + size); 155 if ( *data == NULL)126 if (!*data) 156 127 return NULL; 157 128 tcb = (tcb_t *) (*data + size); 158 129 tcb->self = tcb; 159 #ifdef CONFIG_RTLD160 tcb->dtv = NULL;161 #endif162 130 163 131 return tcb;
Note:
See TracChangeset
for help on using the changeset viewer.