Blame dlfcn/dlopenold.c

Packit 6c4009
/* Load a shared object at run time.
Packit 6c4009
   Copyright (C) 1995-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <dlfcn.h>
Packit 6c4009
#include <stddef.h>
Packit 6c4009
#include <unistd.h>
Packit 6c4009
#include <ldsodefs.h>
Packit 6c4009
Packit 6c4009
/* This file is for compatibility with glibc 2.0.  Compile it only if
Packit 6c4009
   versioning is used.  */
Packit 6c4009
#include <shlib-compat.h>
Packit 6c4009
#if SHLIB_COMPAT (libdl, GLIBC_2_0, GLIBC_2_1)
Packit 6c4009
Packit 6c4009
struct dlopen_args
Packit 6c4009
{
Packit 6c4009
  /* The arguments for dlopen_doit.  */
Packit 6c4009
  const char *file;
Packit 6c4009
  int mode;
Packit 6c4009
  /* The return value of dlopen_doit.  */
Packit 6c4009
  void *new;
Packit 6c4009
  /* Address of the caller.  */
Packit 6c4009
  const void *caller;
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Non-shared code has no support for multiple namespaces.  */
Packit 6c4009
#ifdef SHARED
Packit 6c4009
# define NS __LM_ID_CALLER
Packit 6c4009
#else
Packit 6c4009
# define NS LM_ID_BASE
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
Packit 6c4009
static void
Packit 6c4009
dlopen_doit (void *a)
Packit 6c4009
{
Packit 6c4009
  struct dlopen_args *args = (struct dlopen_args *) a;
Packit 6c4009
Packit 6c4009
  args->new = GLRO(dl_open) (args->file ?: "", args->mode | __RTLD_DLOPEN,
Packit 6c4009
			     args->caller,
Packit 6c4009
			     args->file == NULL ? LM_ID_BASE : NS,
Packit 6c4009
			     __dlfcn_argc, __dlfcn_argv, __environ);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
extern void *__dlopen_nocheck (const char *file, int mode);
Packit 6c4009
void *
Packit 6c4009
__dlopen_nocheck (const char *file, int mode)
Packit 6c4009
{
Packit 6c4009
  struct dlopen_args args;
Packit 6c4009
  args.file = file;
Packit 6c4009
  args.caller = RETURN_ADDRESS (0);
Packit 6c4009
Packit 6c4009
  if ((mode & RTLD_BINDING_MASK) == 0)
Packit 6c4009
    /* By default assume RTLD_LAZY.  */
Packit 6c4009
    mode |= RTLD_LAZY;
Packit 6c4009
  args.mode = mode;
Packit 6c4009
Packit 6c4009
  if (!rtld_active ())
Packit 6c4009
    return _dlfcn_hook->dlopen (file, mode, RETURN_ADDRESS (0));
Packit 6c4009
Packit 6c4009
  return _dlerror_run (dlopen_doit, &args) ? NULL : args.new;
Packit 6c4009
}
Packit 6c4009
compat_symbol (libdl, __dlopen_nocheck, dlopen, GLIBC_2_0);
Packit 6c4009
#endif