1 | /* Look up a versioned symbol in a shared object loaded by `dlopen'. |
2 | Copyright (C) 1995-2018 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. |
4 | |
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. |
9 | |
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. |
14 | |
15 | You should have received a copy of the GNU Lesser General Public |
16 | License along with the GNU C Library; if not, see |
17 | <http://www.gnu.org/licenses/>. */ |
18 | |
19 | #include <dlfcn.h> |
20 | #include <stddef.h> |
21 | |
22 | #include <ldsodefs.h> |
23 | |
24 | #if !defined SHARED && 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 | |
35 | struct dlvsym_args |
36 | { |
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; |
45 | }; |
46 | |
47 | |
48 | static void |
49 | dlvsym_doit (void *a) |
50 | { |
51 | struct dlvsym_args *args = (struct dlvsym_args *)a; |
52 | |
53 | args->sym = _dl_vsym (args->handle, args->name, args->version, args->who); |
54 | } |
55 | |
56 | void * |
57 | __dlvsym (void *handle, const char *name, const char *version_str |
58 | DL_CALLER_DECL) |
59 | { |
60 | # ifdef SHARED |
61 | if (!rtld_active ()) |
62 | return _dlfcn_hook->dlvsym (handle, name, version_str, DL_CALLER); |
63 | # endif |
64 | |
65 | struct dlvsym_args args; |
66 | args.handle = handle; |
67 | args.name = name; |
68 | args.who = DL_CALLER; |
69 | args.version = version_str; |
70 | |
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; |
79 | } |
80 | # ifdef SHARED |
81 | weak_alias (__dlvsym, dlvsym) |
82 | # endif |
83 | #endif |
84 | |