Changeset 985e0f15 in mainline


Ignore:
Timestamp:
2019-05-18T21:42:02Z (5 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
87bc11f
Parents:
1e8b633
git-author:
Matthieu Riolo <matthieu.riolo@…> (2019-05-17 13:04:30)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2019-05-18 21:42:02)
Message:

Removing exit() from lib rtld

Several functions in the library rtld called
exit() from stdlib when an error occured. This
commit removes those calls and replace it with a
proper failure response

Location:
uspace/lib/c
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/dlfcn.c

    r1e8b633 r985e0f15  
    3535 */
    3636
     37#include <errno.h>
    3738#include <stdio.h>
    3839#include <stdlib.h>
     
    5354        if (m == NULL) {
    5455                m = module_load(runtime_env, path, mlf_local);
    55                 module_load_deps(m, mlf_local);
     56                if (module_load_deps(m, mlf_local) != EOK) {
     57                        return NULL;
     58                }
     59
    5660                /* Now relocate. */
    5761                module_process_relocs(m);
  • uspace/lib/c/generic/rtld/module.c

    r1e8b633 r985e0f15  
    187187        if (m == NULL) {
    188188                printf("malloc failed\n");
    189                 exit(1);
     189                goto error;
    190190        }
    191191
     
    198198        if (str_size(name) > NAME_BUF_SIZE - 2) {
    199199                printf("soname too long. increase NAME_BUF_SIZE\n");
    200                 exit(1);
     200                goto error;
    201201        }
    202202
     
    210210        if (rc != EE_OK) {
    211211                printf("Failed to load '%s'\n", name_buf);
    212                 exit(1);
     212                goto error;
    213213        }
    214214
     
    220220                printf("Error: '%s' is not a dynamically-linked object.\n",
    221221                    name_buf);
    222                 exit(1);
     222                goto error;
    223223        }
    224224
     
    243243
    244244        return m;
     245
     246error:
     247        if (m)
     248                free(m);
     249
     250        return NULL;
    245251}
    246252
    247253/** Load all modules on which m (transitively) depends.
    248254 */
    249 void module_load_deps(module_t *m, mlflags_t flags)
     255errno_t module_load_deps(module_t *m, mlflags_t flags)
    250256{
    251257        elf_dyn_t *dp;
     
    274280                /* There are no dependencies, so we are done. */
    275281                m->deps = NULL;
    276                 return;
     282                return EOK;
    277283        }
    278284
     
    280286        if (!m->deps) {
    281287                printf("malloc failed\n");
    282                 exit(1);
     288                return ENOMEM;
    283289        }
    284290
     
    294300                        if (!dm) {
    295301                                dm = module_load(m->rtld, dep_name, flags);
    296                                 module_load_deps(dm, flags);
     302                                errno_t rc = module_load_deps(dm, flags);
     303                                if (rc != EOK) {
     304                                        return rc;
     305                                }
    297306                        }
    298307
     
    302311                ++dp;
    303312        }
     313
     314        return EOK;
    304315}
    305316
  • uspace/lib/c/generic/rtld/rtld.c

    r1e8b633 r985e0f15  
    125125
    126126        DPRINTF("Load all program dependencies\n");
    127         module_load_deps(prog, 0);
     127        errno_t rc = module_load_deps(prog, 0);
     128        if (rc != EOK) {
     129                return rc;
     130        }
    128131
    129132        /* Compute static TLS size */
  • uspace/lib/c/include/rtld/module.h

    r1e8b633 r985e0f15  
    4545extern module_t *module_find(rtld_t *, const char *);
    4646extern module_t *module_load(rtld_t *, const char *, mlflags_t);
    47 extern void module_load_deps(module_t *, mlflags_t);
     47extern errno_t module_load_deps(module_t *, mlflags_t);
    4848extern module_t *module_by_id(rtld_t *, unsigned long);
    4949
Note: See TracChangeset for help on using the changeset viewer.