* init.c (__pthread_initialize_minimal_internal): Cheat a bit by
[glibc.git] / dlfcn / dlopen.c
blobe93a584e815b2423d6a97d164fbe7d53b3be9fae
1 /* Load a shared object at run time.
2 Copyright (C) 1995-2000,2003,2004,2005 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <dlfcn.h>
21 #include <libintl.h>
22 #include <stddef.h>
23 #include <unistd.h>
24 #include <ldsodefs.h>
26 #if !defined SHARED && defined IS_IN_libdl
28 void *
29 dlopen (const char *file, int mode)
31 return __dlopen (file, mode, RETURN_ADDRESS (0));
33 static_link_warning (dlopen)
35 #else
37 struct dlopen_args
39 /* The arguments for dlopen_doit. */
40 const char *file;
41 int mode;
42 /* The return value of dlopen_doit. */
43 void *new;
44 /* Address of the caller. */
45 const void *caller;
49 /* Non-shared code has no support for multiple namespaces. */
50 # ifdef SHARED
51 # define NS __LM_ID_CALLER
52 # else
53 # define NS LM_ID_BASE
54 # endif
57 static void
58 dlopen_doit (void *a)
60 struct dlopen_args *args = (struct dlopen_args *) a;
62 if (args->mode & ~(RTLD_BINDING_MASK | RTLD_NOLOAD | RTLD_DEEPBIND
63 | RTLD_GLOBAL | RTLD_LOCAL | RTLD_NODELETE
64 | __RTLD_SPROF))
65 GLRO(dl_signal_error) (0, NULL, NULL, _("invalid mode parameter"));
67 args->new = GLRO(dl_open) (args->file ?: "", args->mode | __RTLD_DLOPEN,
68 args->caller,
69 args->file == NULL ? LM_ID_BASE : NS,
70 __dlfcn_argc, __dlfcn_argv, __environ);
74 void *
75 __dlopen (const char *file, int mode DL_CALLER_DECL)
77 # ifdef SHARED
78 if (__builtin_expect (_dlfcn_hook != NULL, 0))
79 return _dlfcn_hook->dlopen (file, mode, DL_CALLER);
80 # endif
82 struct dlopen_args args;
83 args.file = file;
84 args.mode = mode;
85 args.caller = DL_CALLER;
87 # ifdef SHARED
88 return _dlerror_run (dlopen_doit, &args) ? NULL : args.new;
89 # else
90 if (_dlerror_run (dlopen_doit, &args))
91 return NULL;
93 __libc_register_dl_open_hook ((struct link_map *) args.new);
94 __libc_register_dlfcn_hook ((struct link_map *) args.new);
96 return args.new;
97 # endif
99 # ifdef SHARED
100 # include <shlib-compat.h>
101 strong_alias (__dlopen, __dlopen_check)
102 versioned_symbol (libdl, __dlopen_check, dlopen, GLIBC_2_1);
103 # endif
104 #endif