]>
Commit | Line | Data |
---|---|---|
94e365c6 | 1 | /* Look up a versioned symbol in a shared object loaded by `dlopen'. |
d4697bc9 | 2 | Copyright (C) 1995-2014 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> |
d66e34cd | 21 | |
a461b147 UD |
22 | #include <ldsodefs.h> |
23 | ||
5f21997b UD |
24 | #if !defined SHARED && defined IS_IN_libdl |
25 | ||
26 | void * | |
27 | weak_function | |
28 | dlvsym (void *handle, const char *name, const char *version_str) | |
29 | { | |
30 | return __dlvsym (handle, name, version_str, RETURN_ADDRESS (0)); | |
31 | } | |
32 | ||
33 | #else | |
34 | ||
94e365c6 | 35 | struct dlvsym_args |
d66e34cd | 36 | { |
94e365c6 UD |
37 | /* The arguments to dlvsym_doit. */ |
38 | void *handle; | |
39 | const char *name; | |
40 | const char *version; | |
41 | void *who; | |
42 | ||
43 | /* The return values of dlvsym_doit. */ | |
44 | void *sym; | |
993b3242 UD |
45 | }; |
46 | ||
d66e34cd | 47 | |
993b3242 | 48 | static void |
94e365c6 | 49 | dlvsym_doit (void *a) |
993b3242 | 50 | { |
94e365c6 | 51 | struct dlvsym_args *args = (struct dlvsym_args *)a; |
993b3242 | 52 | |
94e365c6 | 53 | args->sym = _dl_vsym (args->handle, args->name, args->version, args->who); |
993b3242 UD |
54 | } |
55 | ||
993b3242 | 56 | void * |
5f21997b UD |
57 | __dlvsym (void *handle, const char *name, const char *version_str |
58 | DL_CALLER_DECL) | |
993b3242 | 59 | { |
5f21997b UD |
60 | # ifdef SHARED |
61 | if (__builtin_expect (_dlfcn_hook != NULL, 0)) | |
62 | return _dlfcn_hook->dlvsym (handle, name, version_str, DL_CALLER); | |
63 | # endif | |
94e365c6 | 64 | |
5f21997b | 65 | struct dlvsym_args args; |
94e365c6 UD |
66 | args.handle = handle; |
67 | args.name = name; | |
5f21997b | 68 | args.who = DL_CALLER; |
94e365c6 | 69 | args.version = version_str; |
d66e34cd | 70 | |
a461b147 UD |
71 | /* Protect against concurrent loads and unloads. */ |
72 | __rtld_lock_lock_recursive (GL(dl_load_lock)); | |
73 | ||
74 | void *result = (_dlerror_run (dlvsym_doit, &args) ? NULL : args.sym); | |
75 | ||
76 | __rtld_lock_unlock_recursive (GL(dl_load_lock)); | |
77 | ||
78 | return result; | |
d66e34cd | 79 | } |
5f21997b | 80 | # ifdef SHARED |
94e365c6 | 81 | weak_alias (__dlvsym, dlvsym) |
5f21997b UD |
82 | # endif |
83 | #endif |