329e925
commit e4a2fb76efb45210c541ee3f8ef32f317783c3a8
329e925
Author: Florian Weimer <fweimer@redhat.com>
329e925
Date:   Wed May 11 20:30:49 2022 +0200
329e925
329e925
    manual: Document the dlinfo function
329e925
    
329e925
    Reviewed-by: Carlos O'Donell <carlos@redhat.com>
329e925
    Tested-by: Carlos O'Donell <carlos@rehdat.com>
329e925
    (cherry picked from commit 93804a1ee084d4bdc620b2b9f91615c7da0fabe1)
329e925
    
329e925
    Also includes partial backport of commit 5d28a8962dcb6ec056b81d730e
329e925
    (the addition of manual/dynlink.texi).
329e925
329e925
diff --git a/manual/Makefile b/manual/Makefile
329e925
index e83444341e282916..31678681ef059e0f 100644
329e925
--- a/manual/Makefile
329e925
+++ b/manual/Makefile
329e925
@@ -39,7 +39,7 @@ chapters = $(addsuffix .texi, \
329e925
 		       pipe socket terminal syslog math arith time	\
329e925
 		       resource setjmp signal startup process ipc job	\
329e925
 		       nss users sysinfo conf crypt debug threads	\
329e925
-		       probes tunables)
329e925
+		       dynlink probes tunables)
329e925
 appendices = lang.texi header.texi install.texi maint.texi platform.texi \
329e925
 	     contrib.texi
329e925
 licenses = freemanuals.texi lgpl-2.1.texi fdl-1.3.texi
329e925
diff --git a/manual/dynlink.texi b/manual/dynlink.texi
329e925
new file mode 100644
329e925
index 0000000000000000..dbf3de11769d8e57
329e925
--- /dev/null
329e925
+++ b/manual/dynlink.texi
329e925
@@ -0,0 +1,100 @@
329e925
+@node Dynamic Linker
329e925
+@c @node Dynamic Linker, Internal Probes, Threads, Top
329e925
+@c %MENU% Loading programs and shared objects.
329e925
+@chapter Dynamic Linker
329e925
+@cindex dynamic linker
329e925
+@cindex dynamic loader
329e925
+
329e925
+The @dfn{dynamic linker} is responsible for loading dynamically linked
329e925
+programs and their dependencies (in the form of shared objects).  The
329e925
+dynamic linker in @theglibc{} also supports loading shared objects (such
329e925
+as plugins) later at run time.
329e925
+
329e925
+Dynamic linkers are sometimes called @dfn{dynamic loaders}.
329e925
+
329e925
+@menu
329e925
+* Dynamic Linker Introspection::    Interfaces for querying mapping information.
329e925
+@end menu
329e925
+
329e925
+@node Dynamic Linker Introspection
329e925
+@section Dynamic Linker Introspection
329e925
+
329e925
+@Theglibc{} provides various functions for querying information from the
329e925
+dynamic linker.
329e925
+
329e925
+@deftypefun {int} dlinfo (void *@var{handle}, int @var{request}, void *@var{arg})
329e925
+@safety{@mtsafe{}@asunsafe{@asucorrupt{}}@acunsafe{@acucorrupt{}}}
329e925
+@standards{GNU, dlfcn.h}
329e925
+This function returns information about @var{handle} in the memory
329e925
+location @var{arg}, based on @var{request}.  The @var{handle} argument
329e925
+must be a pointer returned by @code{dlopen} or @code{dlmopen}; it must
329e925
+not have been closed by @code{dlclose}.
329e925
+
329e925
+On success, @code{dlinfo} returns 0.  If there is an error, the function
329e925
+returns @math{-1}, and @code{dlerror} can be used to obtain a
329e925
+corresponding error message.
329e925
+
329e925
+The following operations are defined for use with @var{request}:
329e925
+
329e925
+@vtable @code
329e925
+@item RTLD_DI_LINKMAP
329e925
+The corresponding @code{struct link_map} pointer for @var{handle} is
329e925
+written to @code{*@var{arg}}.  The @var{arg} argument must be the
329e925
+address of an object of type @code{struct link_map *}.
329e925
+
329e925
+@item RTLD_DI_LMID
329e925
+The namespace identifier of @var{handle} is written to
329e925
+@code{*@var{arg}}.  The @var{arg} argument must be the address of an
329e925
+object of type @code{Lmid_t}.
329e925
+
329e925
+@item RTLD_DI_ORIGIN
329e925
+The value of the @code{$ORIGIN} dynamic string token for @var{handle} is
329e925
+written to the character array starting at @var{arg} as a
329e925
+null-terminated string.
329e925
+
329e925
+This request type should not be used because it is prone to buffer
329e925
+overflows.
329e925
+
329e925
+@item RTLD_DI_SERINFO
329e925
+@itemx RTLD_DI_SERINFOSIZE
329e925
+These requests can be used to obtain search path information for
329e925
+@var{handle}.  For both requests, @var{arg} must point to a
329e925
+@code{Dl_serinfo} object.  The @code{RTLD_DI_SERINFOSIZE} request must
329e925
+be made first; it updates the @code{dls_size} and @code{dls_cnt} members
329e925
+of the @code{Dl_serinfo} object.  The caller should then allocate memory
329e925
+to store at least @code{dls_size} bytes and pass that buffer to a
329e925
+@code{RTLD_DI_SERINFO} request.  This second request fills the
329e925
+@code{dls_serpath} array.  The number of array elements was returned in
329e925
+the @code{dls_cnt} member in the initial @code{RTLD_DI_SERINFOSIZE}
329e925
+request.  The caller is responsible for freeing the allocated buffer.
329e925
+
329e925
+This interface is prone to buffer overflows in multi-threaded processes
329e925
+because the required size can change between the
329e925
+@code{RTLD_DI_SERINFOSIZE} and @code{RTLD_DI_SERINFO} requests.
329e925
+
329e925
+@item RTLD_DI_TLS_DATA
329e925
+This request writes the address of the TLS block (in the current thread)
329e925
+for the shared object identified by @var{handle} to @code{*@var{arg}}.
329e925
+The argument @var{arg} must be the address of an object of type
329e925
+@code{void *}.  A null pointer is written if the object does not have
329e925
+any associated TLS block.
329e925
+
329e925
+@item RTLD_DI_TLS_MODID
329e925
+This request writes the TLS module ID for the shared object @var{handle}
329e925
+to @code{*@var{arg}}.  The argument @var{arg} must be the address of an
329e925
+object of type @code{size_t}.  The module ID is zero if the object
329e925
+does not have an associated TLS block.
329e925
+@end vtable
329e925
+
329e925
+The @code{dlinfo} function is a GNU extension.
329e925
+@end deftypefun
329e925
+
329e925
+@c FIXME these are undocumented:
329e925
+@c dladdr
329e925
+@c dladdr1
329e925
+@c dlclose
329e925
+@c dlerror
329e925
+@c dlmopen
329e925
+@c dlopen
329e925
+@c dlsym
329e925
+@c dlvsym
329e925
diff --git a/manual/libdl.texi b/manual/libdl.texi
329e925
deleted file mode 100644
329e925
index e3fe0452d9f41d47..0000000000000000
329e925
--- a/manual/libdl.texi
329e925
+++ /dev/null
329e925
@@ -1,10 +0,0 @@
329e925
-@c FIXME these are undocumented:
329e925
-@c dladdr
329e925
-@c dladdr1
329e925
-@c dlclose
329e925
-@c dlerror
329e925
-@c dlinfo
329e925
-@c dlmopen
329e925
-@c dlopen
329e925
-@c dlsym
329e925
-@c dlvsym
329e925
diff --git a/manual/probes.texi b/manual/probes.texi
329e925
index 4aae76b81921f347..ee019e651706f492 100644
329e925
--- a/manual/probes.texi
329e925
+++ b/manual/probes.texi
329e925
@@ -1,5 +1,5 @@
329e925
 @node Internal Probes
329e925
-@c @node Internal Probes, Tunables, Threads, Top
329e925
+@c @node Internal Probes, Tunables, Dynamic Linker, Top
329e925
 @c %MENU% Probes to monitor libc internal behavior
329e925
 @chapter Internal probes
329e925
 
329e925
diff --git a/manual/threads.texi b/manual/threads.texi
329e925
index 06b6b277a1228af1..7f166bfa87e88c36 100644
329e925
--- a/manual/threads.texi
329e925
+++ b/manual/threads.texi
329e925
@@ -1,5 +1,5 @@
329e925
 @node Threads
329e925
-@c @node Threads, Internal Probes, Debugging Support, Top
329e925
+@c @node Threads, Dynamic Linker, Debugging Support, Top
329e925
 @c %MENU% Functions, constants, and data types for working with threads
329e925
 @chapter Threads
329e925
 @cindex threads