Update kernel version to 5.8 in tst-mman-consts.py.
[glibc.git] / dlfcn / dlvsym.c
blob021697fb75f6422dbfb1b381555a03c4cdc0c17d
1 /* Look up a versioned symbol in a shared object loaded by `dlopen'.
2 Copyright (C) 1995-2020 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, see
17 <https://www.gnu.org/licenses/>. */
19 #include <dlfcn.h>
20 #include <stddef.h>
22 #include <ldsodefs.h>
24 #if !defined SHARED && IS_IN (libdl)
26 void *
27 weak_function
28 dlvsym (void *handle, const char *name, const char *version_str)
30 return __dlvsym (handle, name, version_str, RETURN_ADDRESS (0));
33 #else
35 struct dlvsym_args
37 /* The arguments to dlvsym_doit. */
38 void *handle;
39 const char *name;
40 const char *version;
41 void *who;
43 /* The return values of dlvsym_doit. */
44 void *sym;
48 static void
49 dlvsym_doit (void *a)
51 struct dlvsym_args *args = (struct dlvsym_args *)a;
53 args->sym = _dl_vsym (args->handle, args->name, args->version, args->who);
56 void *
57 __dlvsym (void *handle, const char *name, const char *version_str
58 DL_CALLER_DECL)
60 # ifdef SHARED
61 if (!rtld_active ())
62 return _dlfcn_hook->dlvsym (handle, name, version_str, DL_CALLER);
63 # endif
65 struct dlvsym_args args;
66 args.handle = handle;
67 args.name = name;
68 args.who = DL_CALLER;
69 args.version = version_str;
71 /* Protect against concurrent loads and unloads. */
72 __rtld_lock_lock_recursive (GL(dl_load_lock));
74 void *result = (_dlerror_run (dlvsym_doit, &args) ? NULL : args.sym);
76 __rtld_lock_unlock_recursive (GL(dl_load_lock));
78 return result;
80 # ifdef SHARED
81 weak_alias (__dlvsym, dlvsym)
82 # endif
83 #endif