Ignore:
File:
1 edited

Legend:

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

    r09ab0a9a ra0e2f9c  
    5050#include <rtld/rtld_arch.h>
    5151#include <rtld/module.h>
     52#include <libarch/rtld/module.h>
    5253
    5354#include "../private/libc.h"
     
    6465
    6566        module = calloc(1, sizeof(module_t));
    66         if (module == NULL)
     67        if (module == NULL) {
     68                DPRINTF("malloc failed\n");
    6769                return ENOMEM;
     70        }
    6871
    6972        module->id = rtld_get_next_id(rtld);
     
    181184        char name_buf[NAME_BUF_SIZE];
    182185        module_t *m;
    183         int rc;
     186        errno_t rc;
    184187
    185188        m = calloc(1, sizeof(module_t));
    186189        if (m == NULL) {
    187                 printf("malloc failed\n");
    188                 exit(1);
     190                DPRINTF("malloc failed\n");
     191                goto error;
    189192        }
    190193
     
    196199
    197200        if (str_size(name) > NAME_BUF_SIZE - 2) {
    198                 printf("soname too long. increase NAME_BUF_SIZE\n");
    199                 exit(1);
     201                DPRINTF("soname too long. increase NAME_BUF_SIZE\n");
     202                goto error;
    200203        }
    201204
     
    206209        DPRINTF("filename:'%s'\n", name_buf);
    207210
    208         rc = elf_load_file_name(name_buf, ELDF_RW, &info);
    209         if (rc != EE_OK) {
    210                 printf("Failed to load '%s'\n", name_buf);
    211                 exit(1);
     211        rc = elf_load_file_name(name_buf, RTLD_MODULE_LDF, &info);
     212        if (rc != EOK) {
     213                DPRINTF("Failed to load '%s'\n", name_buf);
     214                goto error;
    212215        }
    213216
     
    217220
    218221        if (info.dynamic == NULL) {
    219                 printf("Error: '%s' is not a dynamically-linked object.\n",
     222                DPRINTF("Error: '%s' is not a dynamically-linked object.\n",
    220223                    name_buf);
    221                 exit(1);
     224                goto error;
    222225        }
    223226
     
    242245
    243246        return m;
     247
     248error:
     249        if (m)
     250                free(m);
     251
     252        return NULL;
    244253}
    245254
    246255/** Load all modules on which m (transitively) depends.
    247256 */
    248 void module_load_deps(module_t *m, mlflags_t flags)
     257errno_t module_load_deps(module_t *m, mlflags_t flags)
    249258{
    250259        elf_dyn_t *dp;
     
    273282                /* There are no dependencies, so we are done. */
    274283                m->deps = NULL;
    275                 return;
     284                return EOK;
    276285        }
    277286
    278287        m->deps = malloc(n * sizeof(module_t *));
    279288        if (!m->deps) {
    280                 printf("malloc failed\n");
    281                 exit(1);
     289                DPRINTF("malloc failed\n");
     290                return ENOMEM;
    282291        }
    283292
     
    293302                        if (!dm) {
    294303                                dm = module_load(m->rtld, dep_name, flags);
    295                                 module_load_deps(dm, flags);
     304                                if (!dm) {
     305                                        return EINVAL;
     306                                }
     307
     308                                errno_t rc = module_load_deps(dm, flags);
     309                                if (rc != EOK) {
     310                                        return rc;
     311                                }
    296312                        }
    297313
     
    301317                ++dp;
    302318        }
     319
     320        return EOK;
    303321}
    304322
Note: See TracChangeset for help on using the changeset viewer.