Back to index

glibc  2.9
dlvsym.c
Go to the documentation of this file.
00001 /* Look up a versioned symbol in a shared object loaded by `dlopen'.
00002    Copyright (C) 1995-2000, 2004 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <dlfcn.h>
00021 #include <stddef.h>
00022 
00023 #include <ldsodefs.h>
00024 
00025 #if !defined SHARED && defined IS_IN_libdl
00026 
00027 void *
00028 weak_function
00029 dlvsym (void *handle, const char *name, const char *version_str)
00030 {
00031   return __dlvsym (handle, name, version_str, RETURN_ADDRESS (0));
00032 }
00033 
00034 #else
00035 
00036 struct dlvsym_args
00037 {
00038   /* The arguments to dlvsym_doit.  */
00039   void *handle;
00040   const char *name;
00041   const char *version;
00042   void *who;
00043 
00044   /* The return values of dlvsym_doit.  */
00045   void *sym;
00046 };
00047 
00048 
00049 static void
00050 dlvsym_doit (void *a)
00051 {
00052   struct dlvsym_args *args = (struct dlvsym_args *)a;
00053 
00054   args->sym = _dl_vsym (args->handle, args->name, args->version, args->who);
00055 }
00056 
00057 void *
00058 __dlvsym (void *handle, const char *name, const char *version_str
00059          DL_CALLER_DECL)
00060 {
00061 # ifdef SHARED
00062   if (__builtin_expect (_dlfcn_hook != NULL, 0))
00063     return _dlfcn_hook->dlvsym (handle, name, version_str, DL_CALLER);
00064 # endif
00065 
00066   struct dlvsym_args args;
00067   args.handle = handle;
00068   args.name = name;
00069   args.who = DL_CALLER;
00070   args.version = version_str;
00071 
00072   /* Protect against concurrent loads and unloads.  */
00073   __rtld_lock_lock_recursive (GL(dl_load_lock));
00074 
00075   void *result = (_dlerror_run (dlvsym_doit, &args) ? NULL : args.sym);
00076 
00077   __rtld_lock_unlock_recursive (GL(dl_load_lock));
00078 
00079   return result;
00080 }
00081 # ifdef SHARED
00082 weak_alias (__dlvsym, dlvsym)
00083 # endif
00084 #endif