Back to index

glibc  2.9
dlinfo.c
Go to the documentation of this file.
00001 /* dlinfo -- Get information from the dynamic linker.
00002    Copyright (C) 2003, 2004, 2006, 2007, 2008 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 <link.h>
00022 #include <ldsodefs.h>
00023 #include <libintl.h>
00024 
00025 #if !defined SHARED && defined IS_IN_libdl
00026 
00027 int
00028 dlinfo (void *handle, int request, void *arg)
00029 {
00030   return __dlinfo (handle, request, arg, RETURN_ADDRESS (0));
00031 }
00032 
00033 #else
00034 
00035 # include <dl-tls.h>
00036 
00037 struct dlinfo_args
00038 {
00039   ElfW(Addr) caller;
00040   void *handle;
00041   int request;
00042   void *arg;
00043 };
00044 
00045 static void
00046 dlinfo_doit (void *argsblock)
00047 {
00048   struct dlinfo_args *const args = argsblock;
00049   struct link_map *l = args->handle;
00050 
00051 # if 0
00052   if (args->handle == RTLD_SELF)
00053     {
00054       Lmid_t nsid;
00055 
00056       /* Find the highest-addressed object that CALLER is not below.  */
00057       for (nsid = 0; nsid < DL_NNS; ++nsid)
00058        for (l = GL(dl_ns)[nsid]._ns_loaded; l != NULL; l = l->l_next)
00059          if (caller >= l->l_map_start && caller < l->l_map_end
00060              && (l->l_contiguous || _dl_addr_inside_object (l, caller)))
00061            break;
00062 
00063       if (l == NULL)
00064        GLRO(dl_signal_error) (0, NULL, NULL, N_("\
00065 RTLD_SELF used in code not dynamically loaded"));
00066     }
00067 # endif
00068 
00069   switch (args->request)
00070     {
00071     case RTLD_DI_CONFIGADDR:
00072     default:
00073       GLRO(dl_signal_error) (0, NULL, NULL, N_("unsupported dlinfo request"));
00074       break;
00075 
00076     case RTLD_DI_LMID:
00077       *(Lmid_t *) args->arg = l->l_ns;
00078       break;
00079 
00080     case RTLD_DI_LINKMAP:
00081       *(struct link_map **) args->arg = l;
00082       break;
00083 
00084     case RTLD_DI_SERINFO:
00085       _dl_rtld_di_serinfo (l, args->arg, false);
00086       break;
00087     case RTLD_DI_SERINFOSIZE:
00088       _dl_rtld_di_serinfo (l, args->arg, true);
00089       break;
00090 
00091     case RTLD_DI_ORIGIN:
00092       strcpy (args->arg, l->l_origin);
00093       break;
00094 
00095     case RTLD_DI_TLS_MODID:
00096       *(size_t *) args->arg = 0;
00097       *(size_t *) args->arg = l->l_tls_modid;
00098       break;
00099 
00100     case RTLD_DI_TLS_DATA:
00101       {
00102        void *data = NULL;
00103        if (l->l_tls_modid != 0)
00104          data = GLRO(dl_tls_get_addr_soft) (l);
00105        *(void **) args->arg = data;
00106        break;
00107       }
00108     }
00109 }
00110 
00111 int
00112 __dlinfo (void *handle, int request, void *arg DL_CALLER_DECL)
00113 {
00114 # ifdef SHARED
00115   if (__builtin_expect (_dlfcn_hook != NULL, 0))
00116     return _dlfcn_hook->dlinfo (handle, request, arg,
00117                             DL_CALLER);
00118 # endif
00119 
00120   struct dlinfo_args args = { (ElfW(Addr)) DL_CALLER,
00121                            handle, request, arg };
00122   return _dlerror_run (&dlinfo_doit, &args) ? -1 : 0;
00123 }
00124 # ifdef SHARED
00125 strong_alias (__dlinfo, dlinfo)
00126 # endif
00127 #endif