1 .\" $NetBSD: dl_iterate_phdr.3,v 1.2 2010/10/16 12:05:48 wiz Exp $
2 .\" $OpenBSD: dl_iterate_phdr.3,v 1.3 2007/05/31 19:19:48 jmc Exp $
4 .\" Copyright (c) 2005 Mark Kettenis
6 .\" Permission to use, copy, modify, and distribute this software for any
7 .\" purpose with or without fee is hereby granted, provided that the above
8 .\" copyright notice and this permission notice appear in all copies.
10 .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 .Nd iterate over program headers
25 This function is not in a library.
26 It is included in every dynamically linked program automatically.
30 .Fn dl_iterate_phdr "int (*callback)(struct dl_phdr_info *, size_t, void*)" "void *data"
34 function iterates over all shared objects loaded into a process's
35 address space, calling
37 for each shared object, passing it information about the object's
38 program headers and the
41 The information about the program headers is passed in a structure
46 const char *dlpi_name;
47 const Elf_Phdr *dlpi_phdr;
49 unsigned long long int dlpi_adds;
50 unsigned long long int dlpi_subs;
51 size_t dlpi_tls_modid;
57 .Li struct dl_phdr_info
58 have the following meaning:
59 .Bl -tag -width XXXdlpi_phdr
61 The base address at which the shared object is mapped into the address
62 space of the calling process.
64 The name of the shared object.
66 A pointer to the shared object's program headers.
68 The number of program headers in the shared object.
70 The number of objects added into the main program.
72 The number of objects removed from the main program.
75 To make it possible for programs to check whether any new members have
76 been added, the size of the structure is passed as an argument to
81 function returns whatever value was returned by the last call to callback.
83 The following program displays a list of pathnames of the shared objects it has
85 For each shared object, the program lists the virtual addresses at
86 which the object's ELF segments are loaded.
93 callback(struct dl_phdr_info *info, size_t size, void *data)
96 printf("name=%s (%d segments)\en", info->dlpi_name,
98 for (j = 0; j < info->dlpi_phnum; j++)
99 printf("\t\t header %2d: address=%10p\en", j,
100 (void *) (info->dlpi_addr + info->dlpi_phdr[j].p_vaddr));
105 main(int argc, char *argv[])
107 dl_iterate_phdr(callback, NULL);
119 function first appeared in