2003-02-14 10:07:43 +00:00
|
|
|
.\"
|
|
|
|
.\" Copyright (c) 2003 Alexey Zelkin <phantom@FreeBSD.org>
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
|
|
|
.\" $FreeBSD$
|
|
|
|
.\"
|
|
|
|
.Dd February 14, 2003
|
|
|
|
.Os
|
|
|
|
.Dt DLINFO 3
|
|
|
|
.Sh NAME
|
|
|
|
.Nm dlinfo
|
|
|
|
.Nd information about dynamically loaded object
|
|
|
|
.Sh LIBRARY
|
|
|
|
.Lb libc
|
|
|
|
.Sh SYNOPSIS
|
|
|
|
.In link.h
|
|
|
|
.In dlfcn.h
|
|
|
|
.Ft int
|
2003-06-01 19:19:59 +00:00
|
|
|
.Fn dlinfo "void * restrict handle" "int request" "void * restrict p"
|
2003-02-14 10:07:43 +00:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
|
|
|
.Fn dlinfo
|
|
|
|
function provides information about dynamically loaded object.
|
|
|
|
The action taken by
|
|
|
|
.Fn dlinfo
|
|
|
|
and exact meaning and type of
|
|
|
|
.Fa p
|
|
|
|
argument depend on value of the
|
|
|
|
.Fa request
|
|
|
|
argument provided by caller.
|
|
|
|
.Pp
|
2003-06-01 19:19:59 +00:00
|
|
|
The
|
2003-02-14 10:07:43 +00:00
|
|
|
.Fa handle
|
2003-06-01 19:19:59 +00:00
|
|
|
argument is either the value returned from the
|
|
|
|
.Xr dlopen 3
|
2003-02-14 10:07:43 +00:00
|
|
|
function call or special handle
|
|
|
|
.Dv RTLD_SELF .
|
2003-06-01 19:19:59 +00:00
|
|
|
If
|
|
|
|
.Fa handle
|
|
|
|
is the value returned from
|
|
|
|
.Xr dlopen 3 ,
|
|
|
|
the information returned by the
|
2003-02-14 10:07:43 +00:00
|
|
|
.Fn dlinfo
|
2003-06-01 19:19:59 +00:00
|
|
|
function pertains to the specified object.
|
2003-02-14 10:07:43 +00:00
|
|
|
If handle is the special handle
|
|
|
|
.Dv RTLD_SELF ,
|
|
|
|
the information returned pertains to the caller itself.
|
|
|
|
.Pp
|
2003-06-01 19:19:59 +00:00
|
|
|
Possible values for the
|
2003-02-14 10:07:43 +00:00
|
|
|
.Fa request
|
2003-06-01 19:19:59 +00:00
|
|
|
argument are:
|
|
|
|
.Bl -tag -width indent
|
|
|
|
.It Dv RTLD_DI_LINKMAP
|
|
|
|
Retrieve the
|
|
|
|
.Vt Link_map
|
|
|
|
.Pq Vt "struct link_map"
|
|
|
|
structure pointer for the specified
|
|
|
|
.Fa handle .
|
|
|
|
On successful return, the
|
2003-02-14 10:07:43 +00:00
|
|
|
.Fa p
|
2003-06-01 19:19:59 +00:00
|
|
|
argument is filled with the pointer to the
|
|
|
|
.Vt Link_map
|
|
|
|
structure
|
|
|
|
.Pq Fa "Link_map **p"
|
|
|
|
describing a shared object specified by the
|
2003-02-14 10:07:43 +00:00
|
|
|
.Fa handle
|
|
|
|
argument.
|
2003-06-01 19:19:59 +00:00
|
|
|
The
|
|
|
|
.Vt Link_map
|
2004-06-21 19:30:45 +00:00
|
|
|
structures are maintained as a doubly linked list by
|
2003-06-01 19:19:59 +00:00
|
|
|
.Xr ld.so 1 ,
|
|
|
|
in the same order as
|
|
|
|
.Xr dlopen 3
|
2003-02-14 10:07:43 +00:00
|
|
|
and
|
2003-06-01 19:19:59 +00:00
|
|
|
.Xr dlclose 3
|
2003-02-14 10:07:43 +00:00
|
|
|
are called.
|
|
|
|
See
|
2003-06-01 19:19:59 +00:00
|
|
|
.Sx EXAMPLES ,
|
|
|
|
example 1.
|
2003-02-14 10:54:37 +00:00
|
|
|
.Pp
|
|
|
|
The
|
2003-06-01 19:19:59 +00:00
|
|
|
.Vt Link_map
|
|
|
|
structure is defined in
|
2003-09-08 19:57:22 +00:00
|
|
|
.In link.h
|
2003-06-01 19:19:59 +00:00
|
|
|
and has the following members:
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
caddr_t l_addr; /* Base Address of library */
|
|
|
|
const char *l_name; /* Absolute Path to Library */
|
|
|
|
const void *l_ld; /* Pointer to .dynamic in memory */
|
|
|
|
struct link_map *l_next, /* linked list of mapped libs */
|
|
|
|
*l_prev;
|
2003-02-14 10:54:37 +00:00
|
|
|
.Ed
|
2003-06-01 19:19:59 +00:00
|
|
|
.Bl -tag -width ".Va l_addr"
|
|
|
|
.It Va l_addr
|
2003-02-14 10:54:37 +00:00
|
|
|
The base address of the object loaded into memory.
|
2003-06-01 19:19:59 +00:00
|
|
|
.It Va l_name
|
|
|
|
The full name of the loaded shared object.
|
|
|
|
.It Va l_ld
|
|
|
|
The address of the dynamic linking information segment
|
|
|
|
.Pq Dv PT_DYNAMIC
|
2003-02-14 10:54:37 +00:00
|
|
|
loaded into memory.
|
2003-06-01 19:19:59 +00:00
|
|
|
.It Va l_next
|
|
|
|
The next
|
|
|
|
.Vt Link_map
|
|
|
|
structure on the link-map list.
|
|
|
|
.It Va l_prev
|
|
|
|
The previous
|
|
|
|
.Vt Link_map
|
|
|
|
structure on the link-map list.
|
2003-02-14 10:54:37 +00:00
|
|
|
.El
|
2003-06-01 19:19:59 +00:00
|
|
|
.It Dv RTLD_DI_SERINFO
|
|
|
|
Retrieve the library search paths associated with the given
|
2003-02-14 10:07:43 +00:00
|
|
|
.Fa handle
|
|
|
|
argument.
|
|
|
|
The
|
|
|
|
.Fa p
|
|
|
|
argument should point to
|
2003-06-01 19:19:59 +00:00
|
|
|
.Vt Dl_serinfo
|
2003-02-14 10:07:43 +00:00
|
|
|
structure buffer
|
2003-06-01 19:19:59 +00:00
|
|
|
.Pq Fa "Dl_serinfo *p" .
|
|
|
|
The
|
|
|
|
.Vt Dl_serinfo
|
|
|
|
structure must be initialized first with the
|
2003-02-14 10:07:43 +00:00
|
|
|
.Dv RTLD_DI_SERINFOSIZE
|
|
|
|
request.
|
|
|
|
.Pp
|
|
|
|
The returned
|
2003-06-01 19:19:59 +00:00
|
|
|
.Vt Dl_serinfo
|
2003-02-14 10:07:43 +00:00
|
|
|
structure contains
|
2003-06-01 19:19:59 +00:00
|
|
|
.Va dls_cnt
|
|
|
|
.Vt Dl_serpath
|
2003-02-14 10:07:43 +00:00
|
|
|
entries.
|
|
|
|
Each entry's
|
2003-06-01 19:19:59 +00:00
|
|
|
.Va dlp_name
|
2003-02-14 10:07:43 +00:00
|
|
|
field points to the search path.
|
|
|
|
The corresponding
|
2003-06-01 19:19:59 +00:00
|
|
|
.Va dlp_info
|
2003-02-14 10:07:43 +00:00
|
|
|
field contains one of more flags indicating the origin of the path (see the
|
|
|
|
.Dv LA_SER_*
|
2003-06-01 19:19:59 +00:00
|
|
|
flags defined in the
|
2003-09-08 19:57:22 +00:00
|
|
|
.In link.h
|
2003-06-01 19:19:59 +00:00
|
|
|
header file).
|
2003-02-14 10:07:43 +00:00
|
|
|
See
|
2003-06-01 19:19:59 +00:00
|
|
|
.Sx EXAMPLES ,
|
|
|
|
example 2, for a usage example.
|
|
|
|
.It Dv RTLD_DI_SERINFOSIZE
|
2003-02-14 10:07:43 +00:00
|
|
|
Initialize a
|
2003-06-01 19:19:59 +00:00
|
|
|
.Vt Dl_serinfo
|
2003-02-14 10:07:43 +00:00
|
|
|
structure for use in a
|
|
|
|
.Dv RTLD_DI_SERINFO
|
|
|
|
request.
|
|
|
|
Both the
|
2003-06-01 19:19:59 +00:00
|
|
|
.Va dls_cnt
|
2003-02-14 10:07:43 +00:00
|
|
|
and
|
2003-06-01 19:19:59 +00:00
|
|
|
.Va dls_size
|
2003-02-14 10:07:43 +00:00
|
|
|
fields are returned to indicate the number of search paths applicable
|
|
|
|
to the handle, and the total size of a
|
2003-06-01 19:19:59 +00:00
|
|
|
.Vt Dl_serinfo
|
2003-02-14 10:07:43 +00:00
|
|
|
buffer required to hold
|
2003-06-01 19:19:59 +00:00
|
|
|
.Va dls_cnt
|
|
|
|
.Vt Dl_serpath
|
2003-02-14 10:07:43 +00:00
|
|
|
entries and the associated search path strings.
|
|
|
|
See
|
2003-06-01 19:19:59 +00:00
|
|
|
.Sx EXAMPLES ,
|
|
|
|
example 2, for a usage example.
|
|
|
|
.It Va RTLD_DI_ORIGIN
|
2003-02-14 10:07:43 +00:00
|
|
|
Retrieve the origin of the dynamic object associated with the handle.
|
2003-06-01 19:19:59 +00:00
|
|
|
On successful return,
|
2003-02-14 10:07:43 +00:00
|
|
|
.Fa p
|
2003-06-01 19:19:59 +00:00
|
|
|
argument is filled with the
|
|
|
|
.Vt char
|
2003-02-14 10:07:43 +00:00
|
|
|
pointer
|
2003-06-01 19:19:59 +00:00
|
|
|
.Pq Fa "char *p" .
|
2003-02-14 10:07:43 +00:00
|
|
|
.El
|
2005-01-20 09:17:07 +00:00
|
|
|
.Sh RETURN VALUES
|
|
|
|
The
|
|
|
|
.Fn dlinfo
|
|
|
|
function returns 0 on success, or \-1 if an error occurred.
|
|
|
|
Whenever an error has been detected, a message detailing it can
|
|
|
|
be retrieved via a call to
|
|
|
|
.Xr dlerror 3 .
|
2003-02-14 10:07:43 +00:00
|
|
|
.Sh EXAMPLES
|
2003-02-15 10:51:05 +00:00
|
|
|
Example 1: Using
|
|
|
|
.Fn dlinfo
|
2003-06-01 19:19:59 +00:00
|
|
|
to retrieve
|
|
|
|
.Vt Link_map
|
|
|
|
structure.
|
2003-02-15 10:51:05 +00:00
|
|
|
.Pp
|
|
|
|
The following example shows how dynamic library can detect the list
|
|
|
|
of shared libraries loaded after caller's one.
|
|
|
|
For simplicity, error checking has been omitted.
|
2003-06-01 19:19:59 +00:00
|
|
|
.Bd -literal -offset indent
|
|
|
|
Link_map *map;
|
2003-02-15 10:51:05 +00:00
|
|
|
|
2003-06-01 19:19:59 +00:00
|
|
|
dlinfo(RTLD_SELF, RTLD_DI_LINKMAP, &map);
|
2003-02-15 10:51:05 +00:00
|
|
|
|
2003-06-01 19:19:59 +00:00
|
|
|
while (map != NULL) {
|
|
|
|
printf("%p: %s\\n", map->l_addr, map->l_name);
|
|
|
|
map = map->l_next;
|
|
|
|
}
|
2003-02-15 10:51:05 +00:00
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
Example 2: Using
|
|
|
|
.Fn dlinfo
|
|
|
|
to retrieve the library search paths.
|
|
|
|
.Pp
|
|
|
|
The following example shows how a dynamic object can inspect the library
|
|
|
|
search paths that would be used to locate a simple filename with
|
2003-06-01 19:19:59 +00:00
|
|
|
.Xr dlopen 3 .
|
2003-02-15 10:51:05 +00:00
|
|
|
For simplicity, error checking has been omitted.
|
2003-06-01 19:19:59 +00:00
|
|
|
.Bd -literal -offset indent
|
|
|
|
Dl_serinfo _info, *info = &_info;
|
|
|
|
Dl_serpath *path;
|
|
|
|
unsigned int cnt;
|
2003-02-15 10:51:05 +00:00
|
|
|
|
2003-06-01 19:19:59 +00:00
|
|
|
/* determine search path count and required buffer size */
|
|
|
|
dlinfo(RTLD_SELF, RTLD_DI_SERINFOSIZE, (void *)info);
|
2003-02-15 10:51:05 +00:00
|
|
|
|
2003-06-01 19:19:59 +00:00
|
|
|
/* allocate new buffer and initialize */
|
|
|
|
info = malloc(_info.dls_size);
|
|
|
|
info->dls_size = _info.dls_size;
|
|
|
|
info->dls_cnt = _info.dls_cnt;
|
2003-02-15 10:51:05 +00:00
|
|
|
|
2003-06-01 19:19:59 +00:00
|
|
|
/* obtain sarch path information */
|
|
|
|
dlinfo(RTLD_SELF, RTLD_DI_SERINFO, (void *)info);
|
2003-02-15 10:51:05 +00:00
|
|
|
|
2003-06-01 19:19:59 +00:00
|
|
|
path = &info->dls_serpath[0];
|
2003-02-15 10:51:05 +00:00
|
|
|
|
2003-06-01 19:19:59 +00:00
|
|
|
for (cnt = 1; cnt <= info->dls_cnt; cnt++, path++) {
|
|
|
|
(void) printf("%2d: %s\\n", cnt, path->dls_name);
|
|
|
|
}
|
2003-02-15 10:51:05 +00:00
|
|
|
.Ed
|
2003-02-14 10:07:43 +00:00
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr rtld 1 ,
|
|
|
|
.Xr dladdr 3 ,
|
|
|
|
.Xr dlopen 3 ,
|
|
|
|
.Xr dlsym 3
|
|
|
|
.Sh HISTORY
|
|
|
|
The
|
|
|
|
.Fn dlinfo
|
|
|
|
function first appeared in the Solaris operating system.
|
|
|
|
In
|
2003-06-01 19:19:59 +00:00
|
|
|
.Fx ,
|
2003-02-14 10:07:43 +00:00
|
|
|
it first appeared in
|
|
|
|
.Fx 4.8 .
|
|
|
|
.Sh AUTHORS
|
2003-06-01 19:19:59 +00:00
|
|
|
.An -nosplit
|
2003-02-14 10:07:43 +00:00
|
|
|
The
|
2003-02-14 10:54:37 +00:00
|
|
|
.Fx
|
2003-06-01 19:19:59 +00:00
|
|
|
implementation of the
|
2003-02-14 10:07:43 +00:00
|
|
|
.Fn dlinfo
|
|
|
|
function was originally written by
|
|
|
|
.An Alexey Zelkin
|
|
|
|
.Aq phantom@FreeBSD.org
|
|
|
|
and later extended and improved by
|
|
|
|
.An Alexander Kabaev
|
|
|
|
.Aq kan@FreeBSD.org .
|
|
|
|
.Pp
|
|
|
|
The manual page for this function was written by
|
|
|
|
.An Alexey Zelkin
|
|
|
|
.Aq phantom@FreeBSD.org .
|