]> git.ipfire.org Git - thirdparty/glibc.git/blame - dlfcn/dlinfo.c
INSTALL, install.texi: minor updates, regenerate
[thirdparty/glibc.git] / dlfcn / dlinfo.c
CommitLineData
45e4762c 1/* dlinfo -- Get information from the dynamic linker.
dff8da6b 2 Copyright (C) 2003-2024 Free Software Foundation, Inc.
45e4762c
RM
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
59ba27a6 16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
45e4762c
RM
18
19#include <dlfcn.h>
20#include <link.h>
21#include <ldsodefs.h>
22#include <libintl.h>
6dfc0207
FW
23#include <dl-tls.h>
24#include <shlib-compat.h>
d78efd9f 25
45e4762c
RM
26struct dlinfo_args
27{
45e4762c
RM
28 void *handle;
29 int request;
30 void *arg;
d056c212
FW
31
32 /* This is the value that is returned from dlinfo if no error is
33 signaled. */
34 int result;
45e4762c
RM
35};
36
37static void
38dlinfo_doit (void *argsblock)
39{
40 struct dlinfo_args *const args = argsblock;
41 struct link_map *l = args->handle;
42
45e4762c
RM
43 switch (args->request)
44 {
45e4762c
RM
45 case RTLD_DI_CONFIGADDR:
46 default:
d056c212 47 args->result = -1;
9e78f6f6 48 _dl_signal_error (0, NULL, NULL, N_("unsupported dlinfo request"));
45e4762c
RM
49 break;
50
c0f62c56
UD
51 case RTLD_DI_LMID:
52 *(Lmid_t *) args->arg = l->l_ns;
53 break;
54
45e4762c
RM
55 case RTLD_DI_LINKMAP:
56 *(struct link_map **) args->arg = l;
57 break;
58
59 case RTLD_DI_SERINFO:
60 _dl_rtld_di_serinfo (l, args->arg, false);
61 break;
62 case RTLD_DI_SERINFOSIZE:
63 _dl_rtld_di_serinfo (l, args->arg, true);
64 break;
65
66 case RTLD_DI_ORIGIN:
67 strcpy (args->arg, l->l_origin);
68 break;
d78efd9f
RM
69
70 case RTLD_DI_TLS_MODID:
71 *(size_t *) args->arg = 0;
d78efd9f 72 *(size_t *) args->arg = l->l_tls_modid;
d78efd9f
RM
73 break;
74
75 case RTLD_DI_TLS_DATA:
76 {
77 void *data = NULL;
d78efd9f 78 if (l->l_tls_modid != 0)
93025f93 79 data = GLRO(dl_tls_get_addr_soft) (l);
d78efd9f
RM
80 *(void **) args->arg = data;
81 break;
82 }
d056c212
FW
83
84 case RTLD_DI_PHDR:
85 *(const ElfW(Phdr) **) args->arg = l->l_phdr;
86 args->result = l->l_phnum;
87 break;
45e4762c
RM
88 }
89}
90
6dfc0207
FW
91static int
92dlinfo_implementation (void *handle, int request, void *arg)
93{
94 struct dlinfo_args args = { handle, request, arg };
d056c212
FW
95 _dlerror_run (&dlinfo_doit, &args);
96 return args.result;
6dfc0207
FW
97}
98
99#ifdef SHARED
45e4762c 100int
6dfc0207 101___dlinfo (void *handle, int request, void *arg)
45e4762c 102{
8dcb6d0a 103 if (GLRO (dl_dlfcn_hook) != NULL)
466c1ea1 104 return GLRO (dl_dlfcn_hook)->dlinfo (handle, request, arg);
6dfc0207
FW
105 else
106 return dlinfo_implementation (handle, request, arg);
45e4762c 107}
6dfc0207
FW
108versioned_symbol (libc, ___dlinfo, dlinfo, GLIBC_2_34);
109
110# if OTHER_SHLIB_COMPAT (libdl, GLIBC_2_3_3, GLIBC_2_34)
111compat_symbol (libc, ___dlinfo, dlinfo, GLIBC_2_3_3);
5f21997b 112# endif
6dfc0207
FW
113#else /* !SHARED */
114/* Also used with _dlfcn_hook. */
115int
116__dlinfo (void *handle, int request, void *arg)
117{
118 return dlinfo_implementation (handle, request, arg);
119}
120weak_alias (__dlinfo, dlinfo)
5f21997b 121#endif