Changes in uspace/lib/c/generic/rtld/rtld.c [5035ba05:6adb775f] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/rtld/rtld.c
r5035ba05 r6adb775f 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. */ … … 62 61 { 63 62 rtld_t *env; 63 module_t *prog; 64 64 65 65 DPRINTF("Load dynamically linked program.\n"); … … 70 70 return ENOMEM; 71 71 72 env->next_id = 1; 73 74 prog = calloc(1, sizeof(module_t)); 75 if (prog == NULL) { 76 free(env); 77 return ENOMEM; 78 } 79 72 80 /* 73 81 * First we need to process dynamic sections of the executable … … 76 84 77 85 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; 86 dynamic_parse(p_info->dynamic, 0, &prog->dyn); 87 prog->bias = 0; 88 prog->dyn.soname = "[program]"; 89 prog->rtld = env; 90 prog->id = rtld_get_next_id(env); 91 92 prog->tdata = p_info->tls.tdata; 93 prog->tdata_size = p_info->tls.tdata_size; 94 prog->tbss_size = p_info->tls.tbss_size; 95 96 printf("prog tdata at %p size %zu, tbss size %zu\n", 97 prog->tdata, prog->tdata_size, prog->tbss_size); 84 98 85 99 /* Initialize list of loaded modules */ 86 100 list_initialize(&env->modules); 87 list_append(&prog _mod.modules_link, &env->modules);101 list_append(&prog->modules_link, &env->modules); 88 102 89 103 /* Pointer to program module. Used as root of the module graph. */ 90 env->program = &prog_mod;104 env->program = prog; 91 105 92 106 /* Work around non-existent memory space allocation. */ … … 98 112 99 113 DPRINTF("Load all program dependencies\n"); 100 module_load_deps( &prog_mod, 0);114 module_load_deps(prog); 101 115 102 116 /* … … 106 120 /* Process relocations in all modules */ 107 121 DPRINTF("Relocate all modules\n"); 108 modules_process_relocs(env, &prog_mod); 122 modules_process_relocs(env, prog); 123 124 modules_process_tls(env); 109 125 110 126 *rre = env; … … 112 128 } 113 129 130 /** Create TLS (Thread Local Storage) data structures. 131 * 132 * @return Pointer to TCB. 133 */ 134 tcb_t *rtld_tls_make(rtld_t *rtld) 135 { 136 void *data; 137 tcb_t *tcb; 138 size_t offset; 139 140 tcb = tls_alloc_arch(&data, rtld->tls_size); 141 if (tcb == NULL) 142 return NULL; 143 144 /* 145 * Copy thread local data from the modules' initialization images. 146 * Zero out thread-local uninitialized data. 147 */ 148 149 offset = 0; 150 list_foreach(rtld->modules, modules_link, module_t, m) { 151 memcpy(data + offset, m->tdata, m->tdata_size); 152 offset += m->tdata_size; 153 memset(data + offset, 0, m->tbss_size); 154 offset += m->tbss_size; 155 } 156 157 return tcb; 158 } 159 160 unsigned long rtld_get_next_id(rtld_t *rtld) 161 { 162 return rtld->next_id++; 163 } 164 165 void *rtld_tls_get_addr(rtld_t *rtld, void *tls, unsigned long mod_id, 166 unsigned long offset) 167 { 168 module_t *m; 169 170 m = module_by_id(rtld, mod_id); 171 assert(m != NULL); 172 173 return tls + m->ioffs + offset; 174 } 175 176 114 177 /** @} 115 178 */
Note:
See TracChangeset
for help on using the changeset viewer.