1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20: #include <dlfcn.h>
21: #include <libintl.h>
22: #include <stddef.h>
23: #include <unistd.h>
24: #include <ldsodefs.h>
25:
26: #if !defined SHARED && defined IS_IN_libdl
27:
28: void *
29: dlopen (const char *file, int mode)
30: {
31: return __dlopen (file, mode, RETURN_ADDRESS (0));
32: }
33: static_link_warning (dlopen)
34:
35: #else
36:
37: struct dlopen_args
38: {
39:
40: const char *file;
41: int mode;
42:
43: void *new;
44:
45: const void *caller;
46: };
47:
48:
49:
50: # ifdef SHARED
51: # define NS __LM_ID_CALLER
52: # else
53: # define NS LM_ID_BASE
54: # endif
55:
56:
57: static void
58: dlopen_doit (void *a)
59: {
60: struct dlopen_args *args = (struct dlopen_args *) a;
61:
62: if (args->mode & ~(RTLD_BINDING_MASK | RTLD_NOLOAD | RTLD_DEEPBIND
63: | RTLD_GLOBAL | RTLD_LOCAL | RTLD_NODELETE))
64: GLRO(dl_signal_error) (0, NULL, NULL, _("invalid mode parameter"));
65:
66: args->new = GLRO(dl_open) (args->file ?: "", args->mode | __RTLD_DLOPEN,
67: args->caller,
68: args->file == NULL ? LM_ID_BASE : NS,
69: __dlfcn_argc, __dlfcn_argv, __environ);
70: }
71:
72:
73: void *
74: __dlopen (const char *file, int mode DL_CALLER_DECL)
75: {
76: # ifdef SHARED
77: if (__builtin_expect (_dlfcn_hook != NULL, 0))
78: return _dlfcn_hook->dlopen (file, mode, DL_CALLER);
79: # endif
80:
81: struct dlopen_args args;
82: args.file = file;
83: args.mode = mode;
84: args.caller = DL_CALLER;
85:
86: # ifdef SHARED
87: return _dlerror_run (dlopen_doit, &args) ? NULL : args.new;
88: # else
89: if (_dlerror_run (dlopen_doit, &args))
90: return NULL;
91:
92: __libc_register_dl_open_hook ((struct link_map *) args.new);
93: __libc_register_dlfcn_hook ((struct link_map *) args.new);
94:
95: return args.new;
96: # endif
97: }
98: # ifdef SHARED
99: # include <shlib-compat.h>
100: strong_alias (__dlopen, __dlopen_check)
101: versioned_symbol (libdl, __dlopen_check, dlopen, GLIBC_2_1);
102: # endif
103: #endif