Changeset 6adb775f in mainline for uspace/lib/c/generic/rtld/module.c


Ignore:
Timestamp:
2016-04-25T16:46:31Z (8 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
32573ff
Parents:
dc0d8b52
Message:

TLS for dynamically linked executables and initially loaded DSOs (but must not call dlopen or there will be trouble).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/rtld/module.c

    rdc0d8b52 r6adb775f  
    3737#include <adt/list.h>
    3838#include <elf/elf_load.h>
     39#include <errno.h>
    3940#include <fcntl.h>
    4041#include <loader/pcb.h>
     
    129130        int rc;
    130131       
    131         m = malloc(sizeof(module_t));
    132         if (!m) {
     132        m = calloc(1, sizeof(module_t));
     133        if (m == NULL) {
    133134                printf("malloc failed\n");
    134135                exit(1);
     
    136137
    137138        m->rtld = rtld;
     139        m->id = rtld_get_next_id(rtld);
    138140
    139141        if (str_size(name) > NAME_BUF_SIZE - 2) {
     
    174176        /* Insert into the list of loaded modules */
    175177        list_append(&m->modules_link, &rtld->modules);
     178
     179        /* Copy TLS info */
     180        m->tdata = info.tls.tdata;
     181        m->tdata_size = info.tls.tdata_size;
     182        m->tbss_size = info.tls.tbss_size;
     183
     184        printf("tdata at %p size %zu, tbss size %zu\n",
     185            m->tdata, m->tdata_size, m->tbss_size);
    176186
    177187        return m;
     
    236246}
    237247
     248/** Find module structure by ID. */
     249module_t *module_by_id(rtld_t *rtld, unsigned long id)
     250{
     251        list_foreach(rtld->modules, modules_link, module_t, m) {
     252                if (m->id == id)
     253                        return m;
     254        }
     255
     256        return NULL;
     257}
     258
    238259/** Process relocations in modules.
    239260 *
     
    253274}
    254275
     276void modules_process_tls(rtld_t *rtld)
     277{
     278        list_foreach(rtld->modules, modules_link, module_t, m) {
     279                m->ioffs = rtld->tls_size;
     280                rtld->tls_size += m->tdata_size + m->tbss_size;
     281        }
     282}
     283
    255284/** Clear BFS tags of all modules.
    256285 */
Note: See TracChangeset for help on using the changeset viewer.