]>
Commit | Line | Data |
---|---|---|
94e365c6 | 1 | /* Look up a symbol in a shared object loaded by `dlopen'. |
688903eb | 2 | Copyright (C) 1995-2018 Free Software Foundation, Inc. |
afd4eb37 | 3 | This file is part of the GNU C Library. |
d66e34cd | 4 | |
afd4eb37 | 5 | The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
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. | |
d66e34cd | 9 | |
afd4eb37 UD |
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 | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
d66e34cd | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
16 | License along with the GNU C Library; if not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
d66e34cd | 18 | |
d66e34cd | 19 | #include <dlfcn.h> |
b2b28911 | 20 | #include <stddef.h> |
94e365c6 | 21 | |
a461b147 UD |
22 | #include <ldsodefs.h> |
23 | ||
9b42a0b3 | 24 | #if !defined SHARED && IS_IN (libdl) |
5f21997b UD |
25 | |
26 | void * | |
27 | dlsym (void *handle, const char *name) | |
28 | { | |
29 | return __dlsym (handle, name, RETURN_ADDRESS (0)); | |
30 | } | |
31 | ||
32 | #else | |
33 | ||
94e365c6 UD |
34 | struct dlsym_args |
35 | { | |
36 | /* The arguments to dlsym_doit. */ | |
37 | void *handle; | |
38 | const char *name; | |
39 | void *who; | |
40 | ||
41 | /* The return value of dlsym_doit. */ | |
42 | void *sym; | |
43 | }; | |
d66e34cd | 44 | |
993b3242 | 45 | static void |
94e365c6 | 46 | dlsym_doit (void *a) |
993b3242 | 47 | { |
94e365c6 UD |
48 | struct dlsym_args *args = (struct dlsym_args *) a; |
49 | ||
50 | args->sym = _dl_sym (args->handle, args->name, args->who); | |
993b3242 UD |
51 | } |
52 | ||
94e365c6 UD |
53 | |
54 | void * | |
5f21997b | 55 | __dlsym (void *handle, const char *name DL_CALLER_DECL) |
d66e34cd | 56 | { |
5f21997b | 57 | # ifdef SHARED |
8e1472d2 | 58 | if (!rtld_active ()) |
5f21997b UD |
59 | return _dlfcn_hook->dlsym (handle, name, DL_CALLER); |
60 | # endif | |
61 | ||
94e365c6 | 62 | struct dlsym_args args; |
5f21997b | 63 | args.who = DL_CALLER; |
94e365c6 UD |
64 | args.handle = handle; |
65 | args.name = name; | |
66 | ||
a461b147 UD |
67 | /* Protect against concurrent loads and unloads. */ |
68 | __rtld_lock_lock_recursive (GL(dl_load_lock)); | |
69 | ||
70 | void *result = (_dlerror_run (dlsym_doit, &args) ? NULL : args.sym); | |
71 | ||
72 | __rtld_lock_unlock_recursive (GL(dl_load_lock)); | |
73 | ||
74 | return result; | |
d66e34cd | 75 | } |
5f21997b UD |
76 | # ifdef SHARED |
77 | strong_alias (__dlsym, dlsym) | |
78 | # endif | |
79 | #endif |