DL_ITERATE_PHDR(3) | Linux Programmer's Manual | DL_ITERATE_PHDR(3) |
NAME
dl_iterate_phdr - walk through list of shared objectsSYNOPSIS
#define _GNU_SOURCE /* See feature_test_macros(7) */ #include
<link.h>
int dl_iterate_phdr(
int (*callback) (struct dl_phdr_info *info,
size_t size, void *data,
void *data;
DESCRIPTION
The dl_iterate_phdr() function allows an application to inquire at run time to find out which shared objects it has loaded.struct dl_phdr_info {
ElfW(Addr) dlpi_addr; /* Base address of object */
const char *dlpi_name; /* (Null-terminated) name of
object */
const ElfW(Phdr) *dlpi_phdr; /* Pointer to array of
ELF program headers
for this object */
ElfW(Half) dlpi_phnum; /* # of items in dlpi_phdr */
};
typedef struct {
Elf32_Word p_type; /* Segment type */
Elf32_Off p_offset; /* Segment file offset */
Elf32_Addr p_vaddr; /* Segment virtual address */
Elf32_Addr p_paddr; /* Segment physical address */
Elf32_Word p_filesz; /* Segment size in file */
Elf32_Word p_memsz; /* Segment size in memory */
Elf32_Word p_flags; /* Segment flags */
Elf32_Word p_align; /* Segment alignment */
} Elf32_Phdr;
Note that we can calculate the location of a particular program header, x, in virtual memory using the formula:
addr == info->dlpi_addr + info->dlpi_phdr[x].p_vaddr;
RETURN VALUE
The dl_iterate_phdr() function returns whatever value was returned by the last call to callback.VERSIONS
dl_iterate_phdr() has been supported in glibc since version 2.2.4.CONFORMING TO
The dl_iterate_phdr() function is Linux-specific and should be avoided in portable applications.EXAMPLE
The following program displays a list of pathnames of the shared objects it has loaded. For each shared object, the program lists the virtual addresses at which the object's ELF segments are loaded.#define _GNU_SOURCE
#include <link.h>
#include <stdlib.h>
#include <stdio.h>
static int
callback(struct dl_phdr_info *info, size_t size, void *data)
{
int j;
printf("name=%s (%d segments)\n", info->dlpi_name,
info->dlpi_phnum);
for (j = 0; j < info->dlpi_phnum; j++)
printf("\t\t header %2d: address=%10p\n", j,
(void *) (info->dlpi_addr + info->dlpi_phdr[j].p_vaddr));
return 0;
}
int
main(int argc, char *argv[])
{
dl_iterate_phdr(callback, NULL);
exit(EXIT_SUCCESS);
}
SEE ALSO
ldd(1), objdump(1), readelf(1), dlopen(3), elf(5), ld.so(8)COLOPHON
This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/.2007-05-18 | GNU |