Changeset d2bb25e7 in mainline
- Timestamp:
- 2016-05-17T22:51:37Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 9c07c3d
- Parents:
- e2f26002
- Location:
- uspace/lib/c
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/arch/ia32/include/libarch/tls.h
re2f26002 rd2bb25e7 43 43 void *self; 44 44 void *fibril_data; 45 void **dtv; 45 46 } tcb_t; 46 47 -
uspace/lib/c/arch/ia32/src/rtld/reloc.c
re2f26002 rd2bb25e7 101 101 sym_def = symbol_def_find(str_tab + sym->st_name, 102 102 m, ssf_none, &dest); 103 //DPRINTF("dest name: '%s'\n", dest->dyn.soname);103 DPRINTF("dest name: '%s'\n", dest->dyn.soname); 104 104 // DPRINTF("dest bias: 0x%x\n", dest->bias); 105 105 if (sym_def) { 106 106 sym_addr = (uint32_t) 107 symbol_get_addr(sym_def, dest );107 symbol_get_addr(sym_def, dest, NULL); 108 108 // DPRINTF("symbol definition found, addr=0x%x\n", sym_addr); 109 109 } else { … … 154 154 if (sym_def) { 155 155 sym_addr = (uint32_t) 156 symbol_get_addr(sym_def, dest );156 symbol_get_addr(sym_def, dest, NULL); 157 157 } else { 158 158 printf("Source definition of '%s' not found.\n", -
uspace/lib/c/arch/ia32/src/tls.c
re2f26002 rd2bb25e7 73 73 #ifdef CONFIG_RTLD 74 74 if (runtime_env != NULL) { 75 return rtld_tls_get_addr(runtime_env, ti->ti_module,76 ti->ti_ offset);75 return rtld_tls_get_addr(runtime_env, __tcb_get(), 76 ti->ti_module, ti->ti_offset); 77 77 } 78 78 #endif -
uspace/lib/c/generic/dlfcn.c
re2f26002 rd2bb25e7 84 84 sd = symbol_bfs_find(sym_name, (module_t *) mod, &sm); 85 85 if (sd != NULL) { 86 return symbol_get_addr(sd, sm );86 return symbol_get_addr(sd, sm, __tcb_get()); 87 87 } 88 88 -
uspace/lib/c/generic/rtld/rtld.c
re2f26002 rd2bb25e7 143 143 tcb_t *tcb; 144 144 size_t offset; 145 void **dtv; 146 size_t nmods; 147 size_t i; 145 148 146 149 tcb = tls_alloc_arch(&data, rtld->tls_size); … … 148 151 return NULL; 149 152 150 /* 151 * Copy thread local data from the modules' initialization images. 152 * Zero out thread-local uninitialized data. 153 /** Allocate dynamic thread vector */ 154 nmods = list_count(&rtld->imodules); 155 dtv = malloc((nmods + 1) * sizeof(void *)); 156 if (dtv == NULL) { 157 tls_free(tcb); 158 return NULL; 159 } 160 161 /* 162 * We define generation number to be equal to vector length. 163 * We start with a vector covering the initially loaded modules. 164 */ 165 DTV_GN(dtv) = nmods; 166 167 /* 168 * Copy thread local data from the initialization images of initial 169 * modules. Zero out thread-local uninitialized data. 153 170 */ 154 171 … … 157 174 * Ascending addresses 158 175 */ 159 offset = 0; 176 offset = 0; i = 1; 160 177 list_foreach(rtld->imodules, imodules_link, module_t, m) { 178 assert(i == m->id); 161 179 assert(offset + m->tdata_size + m->tbss_size <= rtld->tls_size); 180 dtv[i++] = data + offset; 162 181 memcpy(data + offset, m->tdata, m->tdata_size); 163 182 offset += m->tdata_size; … … 169 188 * Descending addresses 170 189 */ 171 offset = 0; 190 offset = 0; i = 1; 172 191 list_foreach(rtld->imodules, imodules_link, module_t, m) { 192 assert(i == m->id); 173 193 assert(offset + m->tdata_size + m->tbss_size <= rtld->tls_size); 174 194 offset += m->tbss_size; … … 176 196 offset += m->tdata_size; 177 197 memcpy(data + rtld->tls_size - offset, m->tdata, m->tdata_size); 198 dtv[i++] = data + rtld->tls_size - offset; 178 199 } 179 200 #endif 180 201 202 tcb->dtv = dtv; 181 203 return tcb; 182 204 } … … 187 209 } 188 210 189 void *rtld_tls_get_addr(rtld_t *rtld, unsigned long mod_id, 211 /** Get address of thread-local variable. 212 * 213 * @param rtld RTLD instance 214 * @param tcb TCB of the thread whose instance to return 215 * @param mod_id Module ID 216 * @param offset Offset within TLS block of the module 217 * 218 * @return Address of thread-local variable 219 */ 220 void *rtld_tls_get_addr(rtld_t *rtld, tcb_t *tcb, unsigned long mod_id, 190 221 unsigned long offset) 191 222 { 192 module_t *m; 193 uint8_t *tls; 194 195 m = module_by_id(rtld, mod_id); 196 assert(m != NULL); 197 198 if (!link_used(&m->imodules_link)) { 199 printf("module '%s' is not initial. aborting.\n", 200 m->dyn.soname); 223 if (DTV_GN(tcb->dtv) < mod_id || tcb->dtv[mod_id] == NULL) { 224 printf("Module is not initial. aborting.\n"); 201 225 abort(); 202 226 } 203 227 204 tls = tls_get(); 205 return tls + m->ioffs + offset; 206 } 207 228 return (uint8_t *)(tcb->dtv[mod_id]) + offset; 229 } 208 230 209 231 /** @} -
uspace/lib/c/generic/rtld/symbol.c
re2f26002 rd2bb25e7 249 249 } 250 250 251 void *symbol_get_addr(elf_symbol_t *sym, module_t *m) 251 /** Get symbol address. 252 * 253 * @param sym Symbol 254 * @param m Module contaning the symbol 255 * @param tcb TCB of the thread whose thread-local variable instance should 256 * be returned. If @a tcb is @c NULL then @c NULL is returned for 257 * thread-local variables. 258 * 259 * @return Symbol address 260 */ 261 void *symbol_get_addr(elf_symbol_t *sym, module_t *m, tcb_t *tcb) 252 262 { 253 263 if (ELF_ST_TYPE(sym->st_info) == STT_TLS) { 254 return rtld_tls_get_addr(m->rtld, m->id, sym->st_value); 264 if (tcb == NULL) 265 return NULL; 266 return rtld_tls_get_addr(m->rtld, tcb, m->id, sym->st_value); 255 267 } else if (sym->st_shndx == SHN_ABS) { 256 268 /* Do not add bias to absolute symbols */ -
uspace/lib/c/generic/tls.c
re2f26002 rd2bb25e7 97 97 void tls_free(tcb_t *tcb) 98 98 { 99 free(tcb->dtv); 99 100 tls_free_arch(tcb, tls_get_size()); 100 101 } … … 109 110 tcb_t *tls_alloc_variant_1(void **data, size_t size) 110 111 { 111 tcb_t * result;112 tcb_t *tcb; 112 113 113 result= malloc(sizeof(tcb_t) + size);114 if (! result)114 tcb = malloc(sizeof(tcb_t) + size); 115 if (!tcb) 115 116 return NULL; 116 *data = ((void *)result) + sizeof(tcb_t); 117 *data = ((void *)tcb) + sizeof(tcb_t); 118 tcb->dtv = NULL; 117 119 118 return result;120 return tcb; 119 121 } 120 122 … … 147 149 tcb = (tcb_t *) (*data + size); 148 150 tcb->self = tcb; 151 tcb->dtv = NULL; 149 152 150 153 return tcb; -
uspace/lib/c/include/rtld/rtld.h
re2f26002 rd2bb25e7 50 50 extern tcb_t *rtld_tls_make(rtld_t *); 51 51 extern unsigned long rtld_get_next_id(rtld_t *); 52 extern void *rtld_tls_get_addr(rtld_t *, unsigned long, unsigned long);52 extern void *rtld_tls_get_addr(rtld_t *, tcb_t *, unsigned long, unsigned long); 53 53 54 54 #endif -
uspace/lib/c/include/rtld/symbol.h
re2f26002 rd2bb25e7 38 38 #include <elf/elf.h> 39 39 #include <rtld/rtld.h> 40 #include <tls.h> 40 41 41 42 /** Symbol search flags */ … … 50 51 extern elf_symbol_t *symbol_def_find(const char *, module_t *, 51 52 symbol_search_flags_t, module_t **); 52 extern void *symbol_get_addr(elf_symbol_t *, module_t * );53 extern void *symbol_get_addr(elf_symbol_t *, module_t *, tcb_t *); 53 54 54 55 #endif -
uspace/lib/c/include/tls.h
re2f26002 rd2bb25e7 39 39 #include <sys/types.h> 40 40 41 /** DTV Generation number - equals vector length */ 42 #define DTV_GN(dtv) (((uintptr_t *)(dtv))[0]) 43 41 44 /* 42 45 * Symbols defined in the respective linker script.
Note:
See TracChangeset
for help on using the changeset viewer.