Back to index

glibc  2.9
Classes | Functions | Variables
dl-libc.c File Reference
#include <dlfcn.h>
#include <stdlib.h>
#include <ldsodefs.h>

Go to the source code of this file.

Classes

struct  do_dlopen_args
struct  do_dlsym_args
struct  dl_open_hook

Functions

static int internal_function dlerror_run (void(*operate)(void *), void *args)
static void do_dlopen (void *ptr)
static void do_dlsym (void *ptr)
static void do_dlclose (void *ptr)
static void do_dlsym_private (void *ptr)
void * __libc_dlopen_mode (const char *name, int mode)
 libc_hidden_def (__libc_dlopen_mode)
void __libc_register_dl_open_hook (struct link_map *map)
void * __libc_dlsym (void *map, const char *name)
 libc_hidden_def (__libc_dlsym)
 libc_hidden_def (__libc_dlclose)

Variables

int __libc_argc attribute_hidden
char ** __environ
static struct dl_open_hook

Class Documentation

struct do_dlopen_args

Definition at line 59 of file dl-libc.c.

Collaboration diagram for do_dlopen_args:
Class Members
struct link_map * map
int mode
const char * name
struct do_dlsym_args

Definition at line 70 of file dl-libc.c.

Collaboration diagram for do_dlsym_args:
Class Members
lookup_t loadbase
struct link_map * map
const char * name

Function Documentation

void* __libc_dlopen_mode ( const char *  name,
int  mode 
)

Definition at line 151 of file dl-libc.c.

{
  struct do_dlopen_args args;
  args.name = name;
  args.mode = mode;

#ifdef SHARED
  if (__builtin_expect (_dl_open_hook != NULL, 0))
    return _dl_open_hook->dlopen_mode (name, mode);
  return (dlerror_run (do_dlopen, &args) ? NULL : (void *) args.map);
#else
  if (dlerror_run (do_dlopen, &args))
    return NULL;

  __libc_register_dl_open_hook (args.map);
  __libc_register_dlfcn_hook (args.map);
  return (void *) args.map;
#endif
}

Here is the call graph for this function:

void* __libc_dlsym ( void *  map,
const char *  name 
)

Definition at line 197 of file dl-libc.c.

{
  struct do_dlsym_args args;
  args.map = map;
  args.name = name;

#ifdef SHARED
  if (__builtin_expect (_dl_open_hook != NULL, 0))
    return _dl_open_hook->dlsym (map, name);
#endif
  return (dlerror_run (do_dlsym, &args) ? NULL
         : (void *) (DL_SYMBOL_ADDRESS (args.loadbase, args.ref)));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void __libc_register_dl_open_hook ( struct link_map map)

Definition at line 186 of file dl-libc.c.

{
  struct dl_open_hook **hook;

  hook = (struct dl_open_hook **) __libc_dlsym_private (map, "_dl_open_hook");
  if (hook != NULL)
    *hook = &_dl_open_hook;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int internal_function dlerror_run ( void(*)(void *)  operate,
void *  args 
) [static]

Definition at line 41 of file dl-libc.c.

{
  const char *objname;
  const char *last_errstring = NULL;
  bool malloced;

  (void) GLRO(dl_catch_error) (&objname, &last_errstring, &malloced,
                            operate, args);

  int result = last_errstring != NULL;
  if (result && malloced)
    free ((char *) last_errstring);

  return result;
}

Here is the caller graph for this function:

static void do_dlclose ( void *  ptr) [static]

Definition at line 101 of file dl-libc.c.

{
  GLRO(dl_close) ((struct link_map *) ptr);
}

Here is the caller graph for this function:

static void do_dlopen ( void *  ptr) [static]

Definition at line 82 of file dl-libc.c.

{
  struct do_dlopen_args *args = (struct do_dlopen_args *) ptr;
  /* Open and relocate the shared object.  */
  args->map = GLRO(dl_open) (args->name, args->mode, NULL, __LM_ID_CALLER,
                          __libc_argc, __libc_argv, __environ);
}

Here is the caller graph for this function:

static void do_dlsym ( void *  ptr) [static]

Definition at line 91 of file dl-libc.c.

{
  struct do_dlsym_args *args = (struct do_dlsym_args *) ptr;
  args->ref = NULL;
  args->loadbase = GLRO(dl_lookup_symbol_x) (args->name, args->map, &args->ref,
                                        args->map->l_local_scope, NULL, 0,
                                        DL_LOOKUP_RETURN_NEWEST, NULL);
}

Here is the caller graph for this function:

static void do_dlsym_private ( void *  ptr) [static]

Definition at line 123 of file dl-libc.c.

{
  lookup_t l;
  struct r_found_version vers;
  vers.name = "GLIBC_PRIVATE";
  vers.hidden = 1;
  /* vers.hash = _dl_elf_hash (vers.name);  */
  vers.hash = 0x0963cf85;
  vers.filename = NULL;

  struct do_dlsym_args *args = (struct do_dlsym_args *) ptr;
  args->ref = NULL;
  l = GLRO(dl_lookup_symbol_x) (args->name, args->map, &args->ref,
                            args->map->l_scope, &vers, 0, 0, NULL);
  args->loadbase = l;
}

Here is the caller graph for this function:

Definition at line 170 of file dl-libc.c.

{
  struct do_dlsym_args sargs;
  sargs.map = map;
  sargs.name = name;

  if (! dlerror_run (do_dlsym_private, &sargs))
    return DL_SYMBOL_ADDRESS (sargs.loadbase, sargs.ref);
  return NULL;
}

Here is the call graph for this function:

Definition at line 210 of file dl-libc.c.

{
#ifdef SHARED
  if (__builtin_expect (_dl_open_hook != NULL, 0))
    return _dl_open_hook->dlclose (map);
#endif
  return dlerror_run (do_dlclose, map);
}

Here is the call graph for this function:

Definition at line 221 of file dl-libc.c.

{
  struct link_map *l;
  struct r_search_path_elem *d;

  /* Remove all search directories.  */
  d = GL(dl_all_dirs);
  while (d != GLRO(dl_init_all_dirs))
    {
      struct r_search_path_elem *old = d;
      d = d->next;
      free (old);
    }

  /* Remove all additional names added to the objects.  */
  for (Lmid_t ns = 0; ns < DL_NNS; ++ns)
    for (l = GL(dl_ns)[ns]._ns_loaded; l != NULL; l = l->l_next)
      {
       struct libname_list *lnp = l->l_libname->next;

       l->l_libname->next = NULL;

       while (lnp != NULL)
         {
           struct libname_list *old = lnp;
           lnp = lnp->next;
           if (! old->dont_free)
           free (old);
         }
      }
}

Variable Documentation

char** __environ

Definition at line 72 of file libc-start.c.

Definition at line 26 of file dl-libc.c.

struct dl_open_hook [static]
Initial value:
  {
    .dlopen_mode = __libc_dlopen_mode,
    .dlsym = __libc_dlsym,
    .dlclose = __libc_dlclose
  }

Definition at line 140 of file dl-libc.c.