Changes in uspace/lib/c/generic/tls.c [118a872:31399f3] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/tls.c
r118a872 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_RTLD 78 if (runtime_env != NULL) 79 return rtld_tls_make(runtime_env); 80 #endif 58 81 59 tcb = tls_alloc_arch(&data, tls_size); 82 60 if (!tcb) 83 61 return NULL; 84 62 85 63 /* 86 64 * Copy thread local data from the initialization image. … … 98 76 void tls_free(tcb_t *tcb) 99 77 { 100 #ifdef CONFIG_RTLD 101 free(tcb->dtv); 102 #endif 103 tls_free_arch(tcb, tls_get_size()); 78 size_t tls_size = &_tbss_end - &_tdata_start; 79 tls_free_arch(tcb, tls_size); 104 80 } 105 81 … … 113 89 tcb_t *tls_alloc_variant_1(void **data, size_t size) 114 90 { 115 tcb_t * tcb;91 tcb_t *result; 116 92 117 tcb= malloc(sizeof(tcb_t) + size);118 if (! tcb)93 result = malloc(sizeof(tcb_t) + size); 94 if (!result) 119 95 return NULL; 120 *data = ((void *)tcb) + sizeof(tcb_t); 121 #ifdef CONFIG_RTLD 122 tcb->dtv = NULL; 123 #endif 96 *data = ((void *)result) + sizeof(tcb_t); 124 97 125 return tcb;98 return result; 126 99 } 127 100 … … 148 121 { 149 122 tcb_t *tcb; 150 123 151 124 size = ALIGN_UP(size, &_tls_alignment); 152 125 *data = memalign((uintptr_t) &_tls_alignment, sizeof(tcb_t) + size); 153 if ( *data == NULL)126 if (!*data) 154 127 return NULL; 155 128 tcb = (tcb_t *) (*data + size); 156 129 tcb->self = tcb; 157 #ifdef CONFIG_RTLD158 tcb->dtv = NULL;159 #endif160 130 161 131 return tcb;
Note:
See TracChangeset
for help on using the changeset viewer.