Changes in uspace/lib/c/generic/tls.c [31399f3:d2bb25e7] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/tls.c
r31399f3 rd2bb25e7 34 34 * Support for thread-local storage, as described in: 35 35 * Drepper U.: ELF Handling For Thread-Local Storage, 2005 36 * 37 * Only static model is supported. 38 */ 36 */ 39 37 40 38 #include <tls.h> 41 39 #include <malloc.h> 42 40 #include <str.h> 43 #include <align.h>44 41 #include <unistd.h> 45 42 43 #ifdef CONFIG_RTLD 44 #include <rtld/rtld.h> 45 #endif 46 47 size_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 */ 57 void *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 46 66 /** Create TLS (Thread Local Storage) data structures. 47 *48 * The code requires, that sections .tdata and .tbss are adjacent. It may be49 * changed in the future.50 67 * 51 68 * @return Pointer to TCB. … … 56 73 tcb_t *tcb; 57 74 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 59 80 tcb = tls_alloc_arch(&data, tls_size); 60 81 if (!tcb) 61 82 return NULL; 62 83 63 84 /* 64 85 * Copy thread local data from the initialization image. … … 76 97 void tls_free(tcb_t *tcb) 77 98 { 78 size_t tls_size = &_tbss_end - &_tdata_start;79 tls_free_arch(tcb, tls_ size);99 free(tcb->dtv); 100 tls_free_arch(tcb, tls_get_size()); 80 101 } 81 102 … … 89 110 tcb_t *tls_alloc_variant_1(void **data, size_t size) 90 111 { 91 tcb_t * result;112 tcb_t *tcb; 92 113 93 result= malloc(sizeof(tcb_t) + size);94 if (! result)114 tcb = malloc(sizeof(tcb_t) + size); 115 if (!tcb) 95 116 return NULL; 96 *data = ((void *)result) + sizeof(tcb_t); 117 *data = ((void *)tcb) + sizeof(tcb_t); 118 tcb->dtv = NULL; 97 119 98 return result;120 return tcb; 99 121 } 100 122 … … 121 143 { 122 144 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) 145 146 *data = malloc(sizeof(tcb_t) + size); 147 if (*data == NULL) 127 148 return NULL; 128 149 tcb = (tcb_t *) (*data + size); 129 150 tcb->self = tcb; 151 tcb->dtv = NULL; 130 152 131 153 return tcb; … … 139 161 void tls_free_variant_2(tcb_t *tcb, size_t size) 140 162 { 141 size = ALIGN_UP(size, &_tls_alignment);142 163 void *start = ((void *) tcb) - size; 143 164 free(start);
Note:
See TracChangeset
for help on using the changeset viewer.