2 .\" Copyright (c) 2003 Alexey Zelkin <phantom@FreeBSD.org>
3 .\" All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .Nd information about dynamically loaded object
38 .Fn dlinfo "void * restrict handle" "int request" "void * restrict p"
42 function provides information about dynamically loaded object.
45 and exact meaning and type of
47 argument depend on value of the
49 argument provided by caller.
53 argument is either the value returned from the
55 function call or special handle
59 is the value returned from
61 the information returned by the
63 function pertains to the specified object.
64 If handle is the special handle
66 the information returned pertains to the caller itself.
68 Possible values for the
71 .Bl -tag -width indent
72 .It Dv RTLD_DI_LINKMAP
75 .Pq Vt "struct link_map"
76 structure pointer for the specified
78 On successful return, the
80 argument is filled with the pointer to the
84 describing a shared object specified by the
89 structures are maintained as a doubly linked list by
102 structure is defined in
104 and has the following members:
105 .Bd -literal -offset indent
106 caddr_t l_base; /* Base Address of library */
107 const char *l_name; /* Absolute Path to Library */
108 const void *l_ld; /* Pointer to .dynamic in memory */
109 struct link_map *l_next, /* linked list of mapped libs */
111 caddr_t l_addr; /* Load Offset of library */
112 const char *l_refname; /* Object this one filters for */
114 .Bl -tag -width ".Va l_addr"
116 The base address of the object loaded into memory.
118 The full name of the loaded shared object.
120 The address of the dynamic linking information segment
126 structure on the link-map list.
130 structure on the link-map list.
132 The load offset of the object, that is, the difference between
133 the actual load address and the base virtual address the object
136 A name of the object this object filters for, if any.
137 If there are more then one filtee, a name from the first
139 dynamic entry is supplied.
141 .It Dv RTLD_DI_SERINFO
142 Retrieve the library search paths associated with the given
147 argument should point to
150 .Pq Fa "Dl_serinfo *p" .
153 structure must be initialized first with the
154 .Dv RTLD_DI_SERINFOSIZE
165 field points to the search path.
168 field contains one of more flags indicating the origin of the path (see the
175 example 2, for a usage example.
176 .It Dv RTLD_DI_SERINFOSIZE
179 structure for use in a
186 fields are returned to indicate the number of search paths applicable
187 to the handle, and the total size of a
189 buffer required to hold
192 entries and the associated search path strings.
195 example 2, for a usage example.
196 .It Va RTLD_DI_ORIGIN
197 Retrieve the origin of the dynamic object associated with the handle.
198 On successful return,
200 argument is filled with the
208 function returns 0 on success, or \-1 if an error occurred.
209 Whenever an error has been detected, a message detailing it can
210 be retrieved via a call to
219 The following example shows how dynamic library can detect the list
220 of shared libraries loaded after caller's one.
221 For simplicity, error checking has been omitted.
222 .Bd -literal -offset indent
225 dlinfo(RTLD_SELF, RTLD_DI_LINKMAP, &map);
227 while (map != NULL) {
228 printf("%p: %s\\n", map->l_addr, map->l_name);
235 to retrieve the library search paths.
237 The following example shows how a dynamic object can inspect the library
238 search paths that would be used to locate a simple filename with
240 For simplicity, error checking has been omitted.
241 .Bd -literal -offset indent
242 Dl_serinfo _info, *info = &_info;
246 /* determine search path count and required buffer size */
247 dlinfo(RTLD_SELF, RTLD_DI_SERINFOSIZE, (void *)info);
249 /* allocate new buffer and initialize */
250 info = malloc(_info.dls_size);
251 info->dls_size = _info.dls_size;
252 info->dls_cnt = _info.dls_cnt;
254 /* obtain sarch path information */
255 dlinfo(RTLD_SELF, RTLD_DI_SERINFO, (void *)info);
257 path = &info->dls_serpath[0];
259 for (cnt = 1; cnt <= info->dls_cnt; cnt++, path++) {
260 (void) printf("%2d: %s\\n", cnt, path->dls_name);
271 function first appeared in the Solaris operating system.
280 implementation of the
282 function was originally written by
283 .An Alexey Zelkin Aq Mt phantom@FreeBSD.org
284 and later extended and improved by
285 .An Alexander Kabaev Aq Mt kan@FreeBSD.org .
287 The manual page for this function was written by
288 .An Alexey Zelkin Aq Mt phantom@FreeBSD.org .