From 5046dbb4a7eba5eccfd258f92f4735c9ffc8d069 Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Thu, 8 Jun 2017 15:39:03 -0400 Subject: Prepare for radical source tree reorganization. All top-level files and directories are moved into a temporary storage directory, REORG.TODO, except for files that will certainly still exist in their current form at top level when we're done (COPYING, COPYING.LIB, LICENSES, NEWS, README), all old ChangeLog files (which are moved to the new directory OldChangeLogs, instead), and the generated file INSTALL (which is just deleted; in the new order, there will be no generated files checked into version control). --- REORG.TODO/dlfcn/dlinfo.c | 126 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 REORG.TODO/dlfcn/dlinfo.c (limited to 'REORG.TODO/dlfcn/dlinfo.c') diff --git a/REORG.TODO/dlfcn/dlinfo.c b/REORG.TODO/dlfcn/dlinfo.c new file mode 100644 index 0000000000..a34e947ed3 --- /dev/null +++ b/REORG.TODO/dlfcn/dlinfo.c @@ -0,0 +1,126 @@ +/* dlinfo -- Get information from the dynamic linker. + Copyright (C) 2003-2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include + +#if !defined SHARED && IS_IN (libdl) + +int +dlinfo (void *handle, int request, void *arg) +{ + return __dlinfo (handle, request, arg, RETURN_ADDRESS (0)); +} + +#else + +# include + +struct dlinfo_args +{ + ElfW(Addr) caller; + void *handle; + int request; + void *arg; +}; + +static void +dlinfo_doit (void *argsblock) +{ + struct dlinfo_args *const args = argsblock; + struct link_map *l = args->handle; + +# if 0 + if (args->handle == RTLD_SELF) + { + Lmid_t nsid; + + /* Find the highest-addressed object that CALLER is not below. */ + for (nsid = 0; nsid < DL_NNS; ++nsid) + for (l = GL(dl_ns)[nsid]._ns_loaded; l != NULL; l = l->l_next) + if (caller >= l->l_map_start && caller < l->l_map_end + && (l->l_contiguous || _dl_addr_inside_object (l, caller))) + break; + + if (l == NULL) + _dl_signal_error (0, NULL, NULL, N_("\ +RTLD_SELF used in code not dynamically loaded")); + } +# endif + + switch (args->request) + { + case RTLD_DI_CONFIGADDR: + default: + _dl_signal_error (0, NULL, NULL, N_("unsupported dlinfo request")); + break; + + case RTLD_DI_LMID: + *(Lmid_t *) args->arg = l->l_ns; + break; + + case RTLD_DI_LINKMAP: + *(struct link_map **) args->arg = l; + break; + + case RTLD_DI_SERINFO: + _dl_rtld_di_serinfo (l, args->arg, false); + break; + case RTLD_DI_SERINFOSIZE: + _dl_rtld_di_serinfo (l, args->arg, true); + break; + + case RTLD_DI_ORIGIN: + strcpy (args->arg, l->l_origin); + break; + + case RTLD_DI_TLS_MODID: + *(size_t *) args->arg = 0; + *(size_t *) args->arg = l->l_tls_modid; + break; + + case RTLD_DI_TLS_DATA: + { + void *data = NULL; + if (l->l_tls_modid != 0) + data = GLRO(dl_tls_get_addr_soft) (l); + *(void **) args->arg = data; + break; + } + } +} + +int +__dlinfo (void *handle, int request, void *arg DL_CALLER_DECL) +{ +# ifdef SHARED + if (__glibc_unlikely (_dlfcn_hook != NULL)) + return _dlfcn_hook->dlinfo (handle, request, arg, + DL_CALLER); +# endif + + struct dlinfo_args args = { (ElfW(Addr)) DL_CALLER, + handle, request, arg }; + return _dlerror_run (&dlinfo_doit, &args) ? -1 : 0; +} +# ifdef SHARED +strong_alias (__dlinfo, dlinfo) +# endif +#endif -- cgit v1.2.3