1ab8f652cSKonstantin Belousov.\" Copyright (c) 2005 Mark Kettenis 2ab8f652cSKonstantin Belousov.\" Copyright (c) 2012 Konstantin Belousov <kib@FreeBSD.org> 3ab8f652cSKonstantin Belousov.\" 4ab8f652cSKonstantin Belousov.\" Permission to use, copy, modify, and distribute this software for any 5ab8f652cSKonstantin Belousov.\" purpose with or without fee is hereby granted, provided that the above 6ab8f652cSKonstantin Belousov.\" copyright notice and this permission notice appear in all copies. 7ab8f652cSKonstantin Belousov.\" 8ab8f652cSKonstantin Belousov.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9ab8f652cSKonstantin Belousov.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10ab8f652cSKonstantin Belousov.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11ab8f652cSKonstantin Belousov.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12ab8f652cSKonstantin Belousov.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13ab8f652cSKonstantin Belousov.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14ab8f652cSKonstantin Belousov.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15ab8f652cSKonstantin Belousov.\" 16ab8f652cSKonstantin Belousov.\" $OpenBSD: dl_iterate_phdr.3,v 1.3 2007/05/31 19:19:48 jmc Exp $ 17*d36d6816SKonstantin Belousov.Dd April 5, 2021 18ab8f652cSKonstantin Belousov.Dt DL_ITERATE_PHDR 3 19ab8f652cSKonstantin Belousov.Os 20ab8f652cSKonstantin Belousov.Sh NAME 21ab8f652cSKonstantin Belousov.Nm dl_iterate_phdr 22ab8f652cSKonstantin Belousov.Nd iterate over program headers 23ab8f652cSKonstantin Belousov.Sh LIBRARY 24ab8f652cSKonstantin BelousovFor the dynamically linked binaries, the service is provided by 251c90f07cSKonstantin Belousov.Xr ld-elf.so.1 1 26ab8f652cSKonstantin Belousovdynamic linker. 27ab8f652cSKonstantin BelousovStatically linked programs use an implementation of 28ab8f652cSKonstantin Belousov.Fn dl_iterate_phdr 29ab8f652cSKonstantin Belousovfrom libc. 30ab8f652cSKonstantin Belousov.Sh SYNOPSIS 31580dbd65SJoel Dahl.In link.h 32ab8f652cSKonstantin Belousov.Ft int 33ab8f652cSKonstantin Belousov.Fn dl_iterate_phdr "int (*callback)(struct dl_phdr_info *, size_t, void *)" "void *data" 34ab8f652cSKonstantin Belousov.Sh DESCRIPTION 35ab8f652cSKonstantin BelousovThe 36ab8f652cSKonstantin Belousov.Fn dl_iterate_phdr 37ab8f652cSKonstantin Belousovfunction iterates over all ELF objects loaded into a process's 38ab8f652cSKonstantin Belousovaddress space, calling 39ab8f652cSKonstantin Belousov.Fa callback 40ab8f652cSKonstantin Belousovfor each object, passing it information about the object's 41ab8f652cSKonstantin Belousovprogram headers and the 42ab8f652cSKonstantin Belousov.Fa data 43ab8f652cSKonstantin Belousovargument. 44ab8f652cSKonstantin BelousovThe iteration is aborted when all objects are passed, or when the next 45ab8f652cSKonstantin Belousov.Fa callback 46ab8f652cSKonstantin Belousovcall returns non-zero value. 47ab8f652cSKonstantin BelousovThe information about the program headers is passed in a structure 48ab8f652cSKonstantin Belousovthat is defined as: 49ab8f652cSKonstantin Belousov.Bd -literal 50ab8f652cSKonstantin Belousovstruct dl_phdr_info { 51ab8f652cSKonstantin Belousov Elf_Addr dlpi_addr; 52ab8f652cSKonstantin Belousov const char *dlpi_name; 53ab8f652cSKonstantin Belousov const Elf_Phdr *dlpi_phdr; 54ab8f652cSKonstantin Belousov Elf_Half dlpi_phnum; 55ab8f652cSKonstantin Belousov unsigned long long int dlpi_adds; 56ab8f652cSKonstantin Belousov unsigned long long int dlpi_subs; 57ab8f652cSKonstantin Belousov size_t dlpi_tls_modid; 58ab8f652cSKonstantin Belousov void *dlpi_tls_data; 59ab8f652cSKonstantin Belousov}; 60ab8f652cSKonstantin Belousov.Ed 61ab8f652cSKonstantin Belousov.Pp 62ab8f652cSKonstantin BelousovThe members of 63ab8f652cSKonstantin Belousov.Li struct dl_phdr_info 64ab8f652cSKonstantin Belousovhave the following meaning: 65ab8f652cSKonstantin Belousov.Bl -tag -width dlpi_tls_modid 66ab8f652cSKonstantin Belousov.It Fa dlpi_addr 67ab8f652cSKonstantin BelousovThe base address at which the object is mapped into the address 68ab8f652cSKonstantin Belousovspace of the calling process. 69ab8f652cSKonstantin Belousov.It Fa dlpi_name 70a6897b93SEd MasteThe pathname of the ELF object. 71ab8f652cSKonstantin Belousov.It Fa dlpi_phdr 72ab8f652cSKonstantin BelousovA pointer to the object's program headers. 73ab8f652cSKonstantin Belousov.It Fa dlpi_phnum 74ab8f652cSKonstantin BelousovThe number of program headers in the object. 75ab8f652cSKonstantin Belousov.It Fa dlpi_adds 76ab8f652cSKonstantin BelousovThe counter of the object loads performed by the dynamic linker. 77ab8f652cSKonstantin Belousov.It Fa dlpi_subs 78ab8f652cSKonstantin BelousovThe counter of the object unloads performed by the dynamic linker. 79ab8f652cSKonstantin Belousov.It Fa dlpi_tls_modid 80ab8f652cSKonstantin BelousovThe TLS index of the object. 81ab8f652cSKonstantin Belousov.It Fa dlpi_tls_data 82*d36d6816SKonstantin BelousovA pointer to the calling thread' TLS data segment for this module, 83*d36d6816SKonstantin Belousovif it was allocated, 84*d36d6816SKonstantin Belousov.Dv NULL 85*d36d6816SKonstantin Belousovotherwise. 86ab8f652cSKonstantin Belousov.El 87ab8f652cSKonstantin Belousov.Pp 88ab8f652cSKonstantin BelousovFuture versions of 89ab8f652cSKonstantin Belousov.Fx 90ab8f652cSKonstantin Belousovmight add more members to this structure. 91ab8f652cSKonstantin BelousovTo make it possible for programs to check whether any new members have 92ab8f652cSKonstantin Belousovbeen added, the size of the structure is passed as an second argument to 93ab8f652cSKonstantin Belousov.Fa callback . 94ab8f652cSKonstantin Belousov.Pp 95ab8f652cSKonstantin BelousovThe third argument to callback is the 96ab8f652cSKonstantin Belousov.Fa data 97ab8f652cSKonstantin Belousovvalue passed to the call to 98ab8f652cSKonstantin Belousov.Fn dl_iterate_phdr , 99ab8f652cSKonstantin Belousovallowing the 100ab8f652cSKonstantin Belousov.Fa callback 101ab8f652cSKonstantin Belousovto have a context. 102ab8f652cSKonstantin Belousov.Sh RETURN VALUES 103ab8f652cSKonstantin BelousovThe 104ab8f652cSKonstantin Belousov.Fn dl_iterate_phdr 105ab8f652cSKonstantin Belousovreturns the value returned by the last 106ab8f652cSKonstantin Belousov.Fa callback 107ab8f652cSKonstantin Belousovcall executed. 108ab8f652cSKonstantin Belousov.Sh SEE ALSO 109ab8f652cSKonstantin Belousov.Xr ld 1 , 1101c90f07cSKonstantin Belousov.Xr ld-elf.so.1 1 , 111ab8f652cSKonstantin Belousov.Xr dlopen 3 , 112ab8f652cSKonstantin Belousov.Xr elf 5 113ab8f652cSKonstantin Belousov.Sh HISTORY 114ab8f652cSKonstantin BelousovThe 115ab8f652cSKonstantin Belousov.Nm 116ab8f652cSKonstantin Belousovfunction first appeared in 117ab8f652cSKonstantin Belousov.Fx 7.0 . 118