|
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 <libintl.h>
|
|
Packit |
6c4009 |
#include <stddef.h>
|
|
Packit |
6c4009 |
#include <unistd.h>
|
|
Packit |
6c4009 |
#include <ldsodefs.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#if !defined SHARED && IS_IN (libdl)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
void *
|
|
Packit |
6c4009 |
dlopen (const char *file, int mode)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
return __dlopen (file, mode, RETURN_ADDRESS (0));
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
static_link_warning (dlopen)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#else
|
|
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 |
if (args->mode & ~(RTLD_BINDING_MASK | RTLD_NOLOAD | RTLD_DEEPBIND
|
|
Packit |
6c4009 |
| RTLD_GLOBAL | RTLD_LOCAL | RTLD_NODELETE
|
|
Packit |
6c4009 |
| __RTLD_SPROF))
|
|
Packit |
6c4009 |
_dl_signal_error (0, NULL, NULL, _("invalid mode parameter"));
|
|
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 |
|
|
Packit |
6c4009 |
void *
|
|
Packit |
6c4009 |
__dlopen (const char *file, int mode DL_CALLER_DECL)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
# ifdef SHARED
|
|
Packit |
6c4009 |
if (!rtld_active ())
|
|
Packit |
6c4009 |
return _dlfcn_hook->dlopen (file, mode, DL_CALLER);
|
|
Packit |
6c4009 |
# endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
struct dlopen_args args;
|
|
Packit |
6c4009 |
args.file = file;
|
|
Packit |
6c4009 |
args.mode = mode;
|
|
Packit |
6c4009 |
args.caller = DL_CALLER;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# ifdef SHARED
|
|
Packit |
6c4009 |
return _dlerror_run (dlopen_doit, &args) ? NULL : args.new;
|
|
Packit |
6c4009 |
# else
|
|
Packit |
6c4009 |
if (_dlerror_run (dlopen_doit, &args))
|
|
Packit |
6c4009 |
return NULL;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
__libc_register_dl_open_hook ((struct link_map *) args.new);
|
|
Packit |
6c4009 |
__libc_register_dlfcn_hook ((struct link_map *) args.new);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return args.new;
|
|
Packit |
6c4009 |
# endif
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
# ifdef SHARED
|
|
Packit |
6c4009 |
# include <shlib-compat.h>
|
|
Packit |
6c4009 |
strong_alias (__dlopen, __dlopen_check)
|
|
Packit |
6c4009 |
versioned_symbol (libdl, __dlopen_check, dlopen, GLIBC_2_1);
|
|
Packit |
6c4009 |
# endif
|
|
Packit |
6c4009 |
#endif
|