Changeset f570cdf in mainline for uspace/lib/c
- Timestamp:
- 2016-05-24T15:32:57Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c170438
- Parents:
- dcc150cb (diff), 0a981e3 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace/lib/c
- Files:
-
- 20 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/Makefile
rdcc150cb rf570cdf 46 46 SLIBRARY = libc.so.0.0 47 47 LSONAME = libc.so.0 48 49 EXTRA_CFLAGS += -I$(LIBURCU_PREFIX)50 48 51 49 -include $(CONFIG_MAKEFILE) … … 149 147 generic/vfs/vfs.c \ 150 148 generic/vfs/canonify.c \ 149 generic/rcu.c \ 151 150 generic/setjmp.c \ 152 151 generic/stack.c \ -
uspace/lib/c/arch/ia32/_link.ld.in
rdcc150cb rf570cdf 12 12 #endif 13 13 data PT_LOAD FLAGS(6); 14 tls PT_TLS; 14 15 #if defined(SHLIB) || defined(DLEXE) 15 16 dynamic PT_DYNAMIC; … … 95 96 #endif 96 97 98 .tdata : { 97 99 #ifndef DLEXE 98 .tdata : {99 100 _tdata_start = .; 101 #endif 100 102 *(.tdata); 101 103 *(.gnu.linkonce.tb.*); 104 #ifndef DLEXE 102 105 _tdata_end = .; 106 #endif 107 } :data :tls 108 .tbss : { 109 #ifndef DLEXE 103 110 _tbss_start = .; 111 #endif 104 112 *(.tbss); 113 #ifndef DLEXE 105 114 _tbss_end = .; 106 } :data 115 #endif 116 } :data :tls 107 117 108 _tls_alignment = ALIGNOF(.tdata); 118 #ifndef DLEXE 119 _tls_alignment = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)); 109 120 #endif 110 121 -
uspace/lib/c/arch/ia32/include/libarch/rtld/elf_dyn.h
rdcc150cb rf570cdf 36 36 #define LIBC_ia32_RTLD_ELF_DYN_H_ 37 37 38 /* 38 /* 39 39 * ia32 dynamic relocation types 40 40 */ … … 47 47 #define R_386_RELATIVE 8 48 48 49 #define R_386_TLS_TPOFF 14 49 50 #define R_386_TLS_DTPMOD32 35 51 #define R_386_TLS_DTPOFF32 36 50 52 51 53 #endif -
uspace/lib/c/arch/ia32/include/libarch/tls.h
rdcc150cb rf570cdf 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
rdcc150cb rf570cdf 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 { … … 115 115 sym_addr = 0; 116 116 sym_def = NULL; 117 118 /* 119 * DTPMOD with null st_name should return the index 120 * of the current module. 121 */ 122 dest = m; 117 123 } 118 124 … … 148 154 if (sym_def) { 149 155 sym_addr = (uint32_t) 150 symbol_get_addr(sym_def, dest );156 symbol_get_addr(sym_def, dest, NULL); 151 157 } else { 152 158 printf("Source definition of '%s' not found.\n", … … 171 177 break; 172 178 179 case R_386_TLS_TPOFF: 180 DPRINTF("fixup R_386_TLS_TPOFF\n"); 181 *r_ptr = (dest->ioffs + sym_def->st_value) - dest->rtld->tls_size; 182 break; 183 184 case R_386_TLS_DTPOFF32: 185 DPRINTF("fixup R_386_TLS_DTPOFF32\n"); 186 *r_ptr = sym_def->st_value; 187 break; 188 173 189 case R_386_TLS_DTPMOD32: 174 /* 175 * We can ignore this as long as the only module 176 * with TLS variables is libc.so. 177 */ 178 DPRINTF("Ignoring R_386_TLS_DTPMOD32\n"); 190 DPRINTF("fixup R_386_TLS_DTPMOD32\n"); 191 *r_ptr = dest->id; 179 192 break; 180 193 -
uspace/lib/c/arch/ia32/src/tls.c
rdcc150cb rf570cdf 1 1 /* 2 2 * Copyright (c) 2006 Ondrej Palkovsky 3 * Copyright (c) 2016 Jiri Svoboda 3 4 * All rights reserved. 4 5 * … … 39 40 #include <align.h> 40 41 42 #ifdef CONFIG_RTLD 43 #include <rtld/rtld.h> 44 #endif 45 41 46 tcb_t *tls_alloc_arch(void **data, size_t size) 42 47 { … … 64 69 *___tls_get_addr(tls_index *ti) 65 70 { 66 size_t tls_size;67 71 uint8_t *tls; 68 72 69 /* Calculate size of TLS block */ 70 tls_size = ALIGN_UP(&_tbss_end - &_tdata_start, &_tls_alignment); 71 72 /* The TLS block is just before TCB */ 73 tls = (uint8_t *)__tcb_get() - tls_size; 74 73 #ifdef CONFIG_RTLD 74 if (runtime_env != NULL) { 75 return rtld_tls_get_addr(runtime_env, __tcb_get(), 76 ti->ti_module, ti->ti_offset); 77 } 78 #endif 79 /* Get address of static TLS block */ 80 tls = tls_get(); 75 81 return tls + ti->ti_offset; 76 82 } -
uspace/lib/c/generic/dlfcn.c
rdcc150cb rf570cdf 49 49 module_t *m; 50 50 51 if (runtime_env == NULL) {52 printf("Dynamic linker not set up -- initializing.\n");53 rtld_init_static();54 }55 56 printf("dlopen(\"%s\", %d)\n", path, flag);57 58 printf("module_find('%s')\n", path);59 51 m = module_find(runtime_env, path); 60 52 if (m == NULL) { 61 printf("NULL. module_load('%s')\n", path);62 53 m = module_load(runtime_env, path, mlf_local); 63 printf("module_load_deps(m)\n");64 54 module_load_deps(m, mlf_local); 65 55 /* Now relocate. */ 66 printf("module_process_relocs(m)\n");67 56 module_process_relocs(m); 68 } else {69 printf("not NULL\n");70 57 } 71 58 … … 81 68 module_t *sm; 82 69 83 printf("dlsym(0x%lx, \"%s\")\n", (long)mod, sym_name);84 70 sd = symbol_bfs_find(sym_name, (module_t *) mod, &sm); 85 71 if (sd != NULL) { 86 return symbol_get_addr(sd, sm );72 return symbol_get_addr(sd, sm, __tcb_get()); 87 73 } 88 74 -
uspace/lib/c/generic/elf/elf_mod.c
rdcc150cb rf570cdf 248 248 } 249 249 250 /** Process TLS program header. 251 * 252 * @param elf Pointer to loader state buffer. 253 * @param hdr TLS program header 254 * @param info Place to store TLS info 255 */ 256 static void tls_program_header(elf_ld_t *elf, elf_segment_header_t *hdr, 257 elf_tls_info_t *info) 258 { 259 info->tdata = (void *)((uint8_t *)hdr->p_vaddr + elf->bias); 260 info->tdata_size = hdr->p_filesz; 261 info->tbss_size = hdr->p_memsz - hdr->p_filesz; 262 info->tls_align = hdr->p_align; 263 } 264 250 265 /** Process segment header. 251 266 * 267 * @param elf Pointer to loader state buffer. 252 268 * @param entry Segment header. 253 269 * … … 277 293 case 0x70000000: 278 294 /* FIXME: MIPS reginfo */ 295 break; 296 case PT_TLS: 297 /* Parse TLS program header */ 298 tls_program_header(elf, entry, &elf->info->tls); 299 DPRINTF("TLS header found at %p\n", 300 (void *)((uint8_t *)entry->p_vaddr + elf->bias)); 279 301 break; 280 302 case PT_SHLIB: -
uspace/lib/c/generic/libc.c
rdcc150cb rf570cdf 41 41 */ 42 42 43 #include <errno.h> 43 44 #include <libc.h> 44 45 #include <stdlib.h> … … 68 69 __malloc_init(); 69 70 71 /* Save the PCB pointer */ 72 __pcb = (pcb_t *) pcb_ptr; 73 74 #ifdef CONFIG_RTLD 75 if (__pcb != NULL && __pcb->rtld_runtime != NULL) { 76 runtime_env = (rtld_t *) __pcb->rtld_runtime; 77 } else { 78 if (rtld_init_static() != EOK) 79 abort(); 80 } 81 #endif 82 70 83 fibril_t *fibril = fibril_setup(); 71 84 if (fibril == NULL) … … 74 87 __tcb_set(fibril->tcb); 75 88 76 /* Save the PCB pointer */77 __pcb = (pcb_t *) pcb_ptr;78 89 79 90 #ifdef FUTEX_UPGRADABLE … … 89 100 char **argv; 90 101 91 #ifdef CONFIG_RTLD92 if (__pcb != NULL && __pcb->rtld_runtime != NULL) {93 runtime_env = (rtld_t *) __pcb->rtld_runtime;94 }95 #endif96 102 /* 97 103 * Get command line arguments and initialize -
uspace/lib/c/generic/rtld/module.c
rdcc150cb rf570cdf 37 37 #include <adt/list.h> 38 38 #include <elf/elf_load.h> 39 #include <errno.h> 39 40 #include <fcntl.h> 40 41 #include <loader/pcb.h> … … 48 49 #include <rtld/rtld_arch.h> 49 50 #include <rtld/module.h> 51 52 /** Create module for static executable. 53 * 54 * @param rtld Run-time dynamic linker 55 * @param rmodule Place to store pointer to new module or @c NULL 56 * @return EOK on success, ENOMEM if out of memory 57 */ 58 int module_create_static_exec(rtld_t *rtld, module_t **rmodule) 59 { 60 module_t *module; 61 62 module = calloc(1, sizeof(module_t)); 63 if (module == NULL) 64 return ENOMEM; 65 66 module->id = rtld_get_next_id(rtld); 67 module->dyn.soname = "[program]"; 68 69 module->rtld = rtld; 70 module->exec = true; 71 module->local = true; 72 73 module->tdata = &_tdata_start; 74 module->tdata_size = &_tdata_end - &_tdata_start; 75 module->tbss_size = &_tbss_end - &_tbss_start; 76 module->tls_align = (uintptr_t)&_tls_alignment; 77 78 list_append(&module->modules_link, &rtld->modules); 79 80 if (rmodule != NULL) 81 *rmodule = module; 82 return EOK; 83 } 50 84 51 85 /** (Eagerly) process all relocation tables in a module. … … 135 169 136 170 m = calloc(1, sizeof(module_t)); 137 if ( !m) {171 if (m == NULL) { 138 172 printf("malloc failed\n"); 139 173 exit(1); … … 141 175 142 176 m->rtld = rtld; 177 m->id = rtld_get_next_id(rtld); 178 143 179 if ((flags & mlf_local) != 0) 144 180 m->local = true; … … 181 217 /* Insert into the list of loaded modules */ 182 218 list_append(&m->modules_link, &rtld->modules); 219 220 /* Copy TLS info */ 221 m->tdata = info.tls.tdata; 222 m->tdata_size = info.tls.tdata_size; 223 m->tbss_size = info.tls.tbss_size; 224 m->tls_align = info.tls.tls_align; 225 226 DPRINTF("tdata at %p size %zu, tbss size %zu\n", 227 m->tdata, m->tdata_size, m->tbss_size); 183 228 184 229 return m; … … 243 288 } 244 289 290 /** Find module structure by ID. */ 291 module_t *module_by_id(rtld_t *rtld, unsigned long id) 292 { 293 list_foreach(rtld->modules, modules_link, module_t, m) { 294 if (m->id == id) 295 return m; 296 } 297 298 return NULL; 299 } 300 245 301 /** Process relocations in modules. 246 302 * … … 260 316 } 261 317 318 void modules_process_tls(rtld_t *rtld) 319 { 320 #ifdef CONFIG_TLS_VARIANT_1 321 list_foreach(rtld->modules, modules_link, module_t, m) { 322 m->ioffs = rtld->tls_size; 323 list_append(&m->imodules_link, &rtmd->imodules); 324 rtld->tls_size += m->tdata_size + m->tbss_size; 325 } 326 #else /* CONFIG_TLS_VARIANT_2 */ 327 size_t offs; 328 329 list_foreach(rtld->modules, modules_link, module_t, m) { 330 rtld->tls_size += m->tdata_size + m->tbss_size; 331 } 332 333 offs = 0; 334 list_foreach(rtld->modules, modules_link, module_t, m) { 335 offs += m->tdata_size + m->tbss_size; 336 m->ioffs = rtld->tls_size - offs; 337 list_append(&m->imodules_link, &rtld->imodules); 338 } 339 #endif 340 } 341 262 342 /** Clear BFS tags of all modules. 263 343 */ -
uspace/lib/c/generic/rtld/rtld.c
rdcc150cb rf570cdf 43 43 rtld_t *runtime_env; 44 44 static rtld_t rt_env_static; 45 static module_t prog_mod;46 45 47 46 /** Initialize the runtime linker for use in a statically-linked executable. */ 48 void rtld_init_static(void) 49 { 47 int rtld_init_static(void) 48 { 49 int rc; 50 50 51 runtime_env = &rt_env_static; 51 52 list_initialize(&runtime_env->modules); 53 list_initialize(&runtime_env->imodules); 52 54 runtime_env->next_bias = 0x2000000; 53 55 runtime_env->program = NULL; 56 runtime_env->next_id = 1; 57 58 rc = module_create_static_exec(runtime_env, NULL); 59 if (rc != EOK) 60 return rc; 61 62 modules_process_tls(runtime_env); 63 64 return EOK; 54 65 } 55 66 … … 62 73 { 63 74 rtld_t *env; 75 module_t *prog; 64 76 65 77 DPRINTF("Load dynamically linked program.\n"); … … 70 82 return ENOMEM; 71 83 84 env->next_id = 1; 85 86 prog = calloc(1, sizeof(module_t)); 87 if (prog == NULL) { 88 free(env); 89 return ENOMEM; 90 } 91 72 92 /* 73 93 * First we need to process dynamic sections of the executable … … 76 96 77 97 DPRINTF("Parse program .dynamic section at %p\n", p_info->dynamic); 78 dynamic_parse(p_info->dynamic, 0, &prog_mod.dyn); 79 prog_mod.bias = 0; 80 prog_mod.dyn.soname = "[program]"; 81 prog_mod.rtld = env; 82 prog_mod.exec = true; 83 prog_mod.local = false; 98 dynamic_parse(p_info->dynamic, 0, &prog->dyn); 99 prog->bias = 0; 100 prog->dyn.soname = "[program]"; 101 prog->rtld = env; 102 prog->id = rtld_get_next_id(env); 103 prog->exec = true; 104 prog->local = false; 105 106 prog->tdata = p_info->tls.tdata; 107 prog->tdata_size = p_info->tls.tdata_size; 108 prog->tbss_size = p_info->tls.tbss_size; 109 prog->tls_align = p_info->tls.tls_align; 110 111 DPRINTF("prog tdata at %p size %zu, tbss size %zu\n", 112 prog->tdata, prog->tdata_size, prog->tbss_size); 84 113 85 114 /* Initialize list of loaded modules */ 86 115 list_initialize(&env->modules); 87 list_append(&prog_mod.modules_link, &env->modules); 116 list_initialize(&env->imodules); 117 list_append(&prog->modules_link, &env->modules); 88 118 89 119 /* Pointer to program module. Used as root of the module graph. */ 90 env->program = &prog_mod;120 env->program = prog; 91 121 92 122 /* Work around non-existent memory space allocation. */ … … 98 128 99 129 DPRINTF("Load all program dependencies\n"); 100 module_load_deps(&prog_mod, 0); 130 module_load_deps(prog, 0); 131 132 /* Compute static TLS size */ 133 modules_process_tls(env); 101 134 102 135 /* … … 106 139 /* Process relocations in all modules */ 107 140 DPRINTF("Relocate all modules\n"); 108 modules_process_relocs(env, &prog_mod);141 modules_process_relocs(env, prog); 109 142 110 143 *rre = env; … … 112 145 } 113 146 147 /** Create TLS (Thread Local Storage) data structures. 148 * 149 * @return Pointer to TCB. 150 */ 151 tcb_t *rtld_tls_make(rtld_t *rtld) 152 { 153 void *data; 154 tcb_t *tcb; 155 size_t offset; 156 void **dtv; 157 size_t nmods; 158 size_t i; 159 160 tcb = tls_alloc_arch(&data, rtld->tls_size); 161 if (tcb == NULL) 162 return NULL; 163 164 /** Allocate dynamic thread vector */ 165 nmods = list_count(&rtld->imodules); 166 dtv = malloc((nmods + 1) * sizeof(void *)); 167 if (dtv == NULL) { 168 tls_free(tcb); 169 return NULL; 170 } 171 172 /* 173 * We define generation number to be equal to vector length. 174 * We start with a vector covering the initially loaded modules. 175 */ 176 DTV_GN(dtv) = nmods; 177 178 /* 179 * Copy thread local data from the initialization images of initial 180 * modules. Zero out thread-local uninitialized data. 181 */ 182 183 #ifdef CONFIG_TLS_VARIANT_1 184 /* 185 * Ascending addresses 186 */ 187 offset = 0; i = 1; 188 list_foreach(rtld->imodules, imodules_link, module_t, m) { 189 assert(i == m->id); 190 assert(offset + m->tdata_size + m->tbss_size <= rtld->tls_size); 191 dtv[i++] = data + offset; 192 memcpy(data + offset, m->tdata, m->tdata_size); 193 offset += m->tdata_size; 194 memset(data + offset, 0, m->tbss_size); 195 offset += m->tbss_size; 196 } 197 #else /* CONFIG_TLS_VARIANT_2 */ 198 /* 199 * Descending addresses 200 */ 201 offset = 0; i = 1; 202 list_foreach(rtld->imodules, imodules_link, module_t, m) { 203 assert(i == m->id); 204 assert(offset + m->tdata_size + m->tbss_size <= rtld->tls_size); 205 offset += m->tbss_size; 206 memset(data + rtld->tls_size - offset, 0, m->tbss_size); 207 offset += m->tdata_size; 208 memcpy(data + rtld->tls_size - offset, m->tdata, m->tdata_size); 209 dtv[i++] = data + rtld->tls_size - offset; 210 } 211 #endif 212 213 tcb->dtv = dtv; 214 return tcb; 215 } 216 217 unsigned long rtld_get_next_id(rtld_t *rtld) 218 { 219 return rtld->next_id++; 220 } 221 222 /** Get address of thread-local variable. 223 * 224 * @param rtld RTLD instance 225 * @param tcb TCB of the thread whose instance to return 226 * @param mod_id Module ID 227 * @param offset Offset within TLS block of the module 228 * 229 * @return Address of thread-local variable 230 */ 231 void *rtld_tls_get_addr(rtld_t *rtld, tcb_t *tcb, unsigned long mod_id, 232 unsigned long offset) 233 { 234 module_t *m; 235 size_t dtv_len; 236 void *tls_block; 237 238 dtv_len = DTV_GN(tcb->dtv); 239 if (dtv_len < mod_id) { 240 /* Vector is short */ 241 242 tcb->dtv = realloc(tcb->dtv, (1 + mod_id) * sizeof(void *)); 243 /* XXX This can fail if OOM */ 244 assert(tcb->dtv != NULL); 245 /* Zero out new part of vector */ 246 memset(tcb->dtv + (1 + dtv_len), 0, (mod_id - dtv_len) * 247 sizeof(void *)); 248 } 249 250 if (tcb->dtv[mod_id] == NULL) { 251 /* TLS block is not allocated */ 252 253 m = module_by_id(rtld, mod_id); 254 assert(m != NULL); 255 /* Should not be initial module, those have TLS pre-allocated */ 256 assert(!link_used(&m->imodules_link)); 257 258 tls_block = malloc(m->tdata_size + m->tbss_size); 259 /* XXX This can fail if OOM */ 260 assert(tls_block != NULL); 261 262 /* Copy tdata */ 263 memcpy(tls_block, m->tdata, m->tdata_size); 264 /* Zero out tbss */ 265 memset(tls_block + m->tdata_size, 0, m->tbss_size); 266 267 tcb->dtv[mod_id] = tls_block; 268 } 269 270 return (uint8_t *)(tcb->dtv[mod_id]) + offset; 271 } 272 114 273 /** @} 115 274 */ -
uspace/lib/c/generic/rtld/symbol.c
rdcc150cb rf570cdf 249 249 } 250 250 251 void *symbol_get_addr(elf_symbol_t *sym, module_t *m) 252 { 253 if (sym->st_shndx == SHN_ABS) { 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) 262 { 263 if (ELF_ST_TYPE(sym->st_info) == STT_TLS) { 264 if (tcb == NULL) 265 return NULL; 266 return rtld_tls_get_addr(m->rtld, tcb, m->id, sym->st_value); 267 } else if (sym->st_shndx == SHN_ABS) { 254 268 /* Do not add bias to absolute symbols */ 255 269 return (void *) sym->st_value; -
uspace/lib/c/generic/tls.c
rdcc150cb rf570cdf 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 38 #include <align.h> 40 39 #include <tls.h> 41 40 #include <malloc.h> 42 41 #include <str.h> 43 #include <align.h>44 42 #include <unistd.h> 45 43 44 #ifdef CONFIG_RTLD 45 #include <rtld/rtld.h> 46 #endif 47 48 size_t tls_get_size(void) 49 { 50 #ifdef CONFIG_RTLD 51 if (runtime_env != NULL) 52 return runtime_env->tls_size; 53 #endif 54 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_1 61 return (uint8_t *)__tcb_get() + sizeof(tcb_t); 62 #else /* CONFIG_TLS_VARIANT_2 */ 63 return (uint8_t *)__tcb_get() - tls_get_size(); 64 #endif 65 } 66 46 67 /** 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 68 * 51 69 * @return Pointer to TCB. … … 56 74 tcb_t *tcb; 57 75 size_t tls_size = &_tbss_end - &_tdata_start; 58 76 77 #ifdef CONFIG_RTLD 78 if (runtime_env != NULL) 79 return rtld_tls_make(runtime_env); 80 #endif 59 81 tcb = tls_alloc_arch(&data, tls_size); 60 82 if (!tcb) 61 83 return NULL; 62 84 63 85 /* 64 86 * Copy thread local data from the initialization image. … … 76 98 void tls_free(tcb_t *tcb) 77 99 { 78 size_t tls_size = &_tbss_end - &_tdata_start; 79 tls_free_arch(tcb, tls_size); 100 #ifdef CONFIG_RTLD 101 free(tcb->dtv); 102 #endif 103 tls_free_arch(tcb, tls_get_size()); 80 104 } 81 105 … … 89 113 tcb_t *tls_alloc_variant_1(void **data, size_t size) 90 114 { 91 tcb_t * result;115 tcb_t *tcb; 92 116 93 result= malloc(sizeof(tcb_t) + size);94 if (! result)117 tcb = malloc(sizeof(tcb_t) + size); 118 if (!tcb) 95 119 return NULL; 96 *data = ((void *)result) + sizeof(tcb_t); 120 *data = ((void *)tcb) + sizeof(tcb_t); 121 #ifdef CONFIG_RTLD 122 tcb->dtv = NULL; 123 #endif 97 124 98 return result;125 return tcb; 99 126 } 100 127 … … 121 148 { 122 149 tcb_t *tcb; 123 150 124 151 size = ALIGN_UP(size, &_tls_alignment); 125 152 *data = memalign((uintptr_t) &_tls_alignment, sizeof(tcb_t) + size); 126 if ( !*data)153 if (*data == NULL) 127 154 return NULL; 128 155 tcb = (tcb_t *) (*data + size); 129 156 tcb->self = tcb; 157 #ifdef CONFIG_RTLD 158 tcb->dtv = NULL; 159 #endif 130 160 131 161 return tcb; -
uspace/lib/c/include/elf/elf_mod.h
rdcc150cb rf570cdf 58 58 } eld_flags_t; 59 59 60 /** TLS info for a module */ 61 typedef struct { 62 /** tdata section image */ 63 void *tdata; 64 /** Size of tdata section image in bytes */ 65 size_t tdata_size; 66 /** Size of tbss section */ 67 size_t tbss_size; 68 /** Alignment of TLS initialization image */ 69 size_t tls_align; 70 } elf_tls_info_t; 71 60 72 /** 61 73 * Some data extracted from the headers are stored here … … 70 82 /** Pointer to the dynamic section */ 71 83 void *dynamic; 84 85 /** TLS info */ 86 elf_tls_info_t tls; 72 87 } elf_finfo_t; 73 88 -
uspace/lib/c/include/rtld/module.h
rdcc150cb rf570cdf 42 42 #include <types/rtld/rtld.h> 43 43 44 extern int module_create_static_exec(rtld_t *, module_t **); 44 45 extern void module_process_relocs(module_t *); 45 46 extern module_t *module_find(rtld_t *, const char *); 46 47 extern module_t *module_load(rtld_t *, const char *, mlflags_t); 47 48 extern void module_load_deps(module_t *, mlflags_t); 49 extern module_t *module_by_id(rtld_t *, unsigned long); 48 50 49 51 extern void modules_process_relocs(rtld_t *, module_t *); 52 extern void modules_process_tls(rtld_t *); 50 53 extern void modules_untag(rtld_t *); 51 54 -
uspace/lib/c/include/rtld/rtld.h
rdcc150cb rf570cdf 41 41 42 42 #include <rtld/dynamic.h> 43 #include <tls.h> 43 44 #include <types/rtld/rtld.h> 44 45 45 46 extern rtld_t *runtime_env; 46 47 47 extern voidrtld_init_static(void);48 extern int rtld_init_static(void); 48 49 extern int rtld_prog_process(elf_finfo_t *, rtld_t **); 50 extern tcb_t *rtld_tls_make(rtld_t *); 51 extern unsigned long rtld_get_next_id(rtld_t *); 52 extern void *rtld_tls_get_addr(rtld_t *, tcb_t *, unsigned long, unsigned long); 49 53 50 54 #endif -
uspace/lib/c/include/rtld/symbol.h
rdcc150cb rf570cdf 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
rdcc150cb rf570cdf 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. … … 52 55 extern void tls_free(tcb_t *); 53 56 extern void tls_free_arch(tcb_t *, size_t); 57 extern size_t tls_get_size(void); 58 extern void *tls_get(void); 54 59 55 60 #ifdef CONFIG_TLS_VARIANT_1 -
uspace/lib/c/include/types/rtld/module.h
rdcc150cb rf570cdf 46 46 /** Dynamically linked module */ 47 47 typedef struct module { 48 /** Module ID */ 49 unsigned long id; 50 /** Dynamic info for this module */ 48 51 dyn_info_t dyn; 52 /** Load bias */ 49 53 size_t bias; 54 55 /** tdata image start */ 56 void *tdata; 57 /** tdata image size */ 58 size_t tdata_size; 59 /** tbss size */ 60 size_t tbss_size; 61 /** TLS alignment */ 62 size_t tls_align; 63 64 size_t ioffs; 50 65 51 66 /** Containing rtld */ … … 61 76 /** Link to list of all modules in runtime environment */ 62 77 link_t modules_link; 78 /** Link to list of initial modules */ 79 link_t imodules_link; 63 80 64 81 /** Link to BFS queue. Only used when doing a BFS of the module graph */ -
uspace/lib/c/include/types/rtld/rtld.h
rdcc150cb rf570cdf 48 48 module_t *program; 49 49 50 /** Next module ID */ 51 unsigned long next_id; 52 53 /** Size of initial TLS tdata + tbss */ 54 size_t tls_size; 55 50 56 /** List of all loaded modules including rtld and the program */ 51 57 list_t modules; 58 59 /** List of initial modules */ 60 list_t imodules; 52 61 53 62 /** Temporary hack to place each module at different address. */
Note:
See TracChangeset
for help on using the changeset viewer.