| Skip Navigation Links | |
| Exit Print View | |
![]() | man pages section 3: Basic Library Functions Oracle Solaris 11 Information Library |
enable_extended_FILE_stdio(3C)
posix_spawnattr_getschedparam(3C)
posix_spawnattr_getschedpolicy(3C)
posix_spawnattr_getsigdefault(3C)
posix_spawnattr_getsigignore_np(3C)
posix_spawnattr_getsigmask(3C)
posix_spawnattr_setschedparam(3C)
posix_spawnattr_setschedpolicy(3C)
posix_spawnattr_setsigdefault(3C)
posix_spawnattr_setsigignore_np(3C)
posix_spawnattr_setsigmask(3C)
posix_spawn_file_actions_addclose(3C)
posix_spawn_file_actions_addclosefrom_np(3C)
posix_spawn_file_actions_adddup2(3C)
posix_spawn_file_actions_addopen(3C)
posix_spawn_file_actions_destroy(3C)
posix_spawn_file_actions_init(3C)
pthread_attr_getdetachstate(3C)
pthread_attr_getinheritsched(3C)
pthread_attr_getschedparam(3C)
pthread_attr_getschedpolicy(3C)
pthread_attr_setdetachstate(3C)
pthread_attr_setinheritsched(3C)
pthread_attr_setschedparam(3C)
pthread_attr_setschedpolicy(3C)
pthread_barrierattr_destroy(3C)
pthread_barrierattr_getpshared(3C)
pthread_barrierattr_setpshared(3C)
pthread_condattr_getpshared(3C)
pthread_condattr_setpshared(3C)
pthread_cond_reltimedwait_np(3C)
pthread_key_create_once_np(3C)
pthread_mutexattr_getprioceiling(3C)
pthread_mutexattr_getprotocol(3C)
pthread_mutexattr_getpshared(3C)
pthread_mutexattr_getrobust(3C)
pthread_mutexattr_setprioceiling(3C)
pthread_mutexattr_setprotocol(3C)
pthread_mutexattr_setpshared(3C)
pthread_mutexattr_setrobust(3C)
pthread_mutex_getprioceiling(3C)
pthread_mutex_reltimedlock_np(3C)
pthread_mutex_setprioceiling(3C)
pthread_rwlockattr_destroy(3C)
pthread_rwlockattr_getpshared(3C)
pthread_rwlockattr_setpshared(3C)
pthread_rwlock_reltimedrdlock_np(3C)
pthread_rwlock_reltimedwrlock_np(3C)
pthread_rwlock_timedrdlock(3C)
pthread_rwlock_timedwrlock(3C)
rctlblk_get_enforced_value(3C)
- walk through a list of objects
#include <link.h>intdl_iterate_phdr(int (*callback)(struct dl_phdr_info *info,size_tsize,void *data),void *data);
Thedl_iterate_phdr() function returns information regarding each ELF object currently resident in theprocess address space.
Thedl_iterate_phdr() function calls the functioncallback once for each object, untileither all objects have been processed orcallback returns a non-zero value.
Each call tocallback receives three arguments:info, which is a pointerto a structure containing information about the object;size, which is the sizeof the structure pointed to byinfo; and thedata argument passed todl_iterate_phdr()by the caller.
Theinfo argument is a pointer to a structure of the following type:
struct dl_phdr_info { /* Fields present in all implementations */ ElfW(Addr) dlpi_addr; const char *dlpi_name; const ElfW(Phdr) *dlpi_phdr; ElfW(Half) dlpi_phnum; /* Additional fields present in this implementation */ u_longlong_t dlpi_adds; u_longlong_t dlpi_subs; };TheElfW() macro definition turns its argument into the name of an ELFdata type suitable for the hardware architecture, by adding theElf32_ prefix for32-bit code, orElf64_ for 64-bit code.
The first four fields (dlpi_addr,dlpi_name,dlpi_phdr,dlpi_phnum) are present in allimplementations ofdl_iterate_phdr(), and can be accessed on any system that provides this function.The callback function must use thesize argument to determine if the remainingfields (dlpi_adds,dlpi_subs) are present. See EXAMPLES.
Thedlpi_addr field is 0 for executable objects (ET_EXEC), and is thebase address at which the object is mapped otherwise. Therefore, the address ofany loadable segment in the program header array can be calculated as:
addr == info->dlpi_addr + info->dlpi_phdr[x].p_vaddr
dlpi_name gives the pathname of the object.
dlpi_phdr provides a pointer to the program header array for the object, anddlpi_phnum specifies the number of program headers found in the array.
dlpi_adds provides the number of objects that have been mapped into the currentprocess since it started, anddlpi_subs provides the number of objects that havebeen unmapped. See NOTES.
See theLinker and Libraries Guide for more information about ELF objects, andthe information contained in program headers.
Example 1 Display all currently mapped object
The following program displays the pathnames of currently mapped objects. For each object,the virtual address of each loadable segment is shown.
#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 program headers)\n", info->dlpi_name, info->dlpi_phnum); for (j = 0; j < info->dlpi_phnum; j++) { if (info->dlpi_phdr[j].p_type == PT_LOAD) printf("\t[%d] 0x%p\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); return(0); }Example 2 Testing for optionaldl_phdr_info fields
Every implementation of dl_iterate_phdr is required to supply the first four fields instruct dl_phdr_info described above. The callback is allowed to assume that they arepresent and to access them without first testing for their presence. Additional fieldsmay be present. The callback must use the size argument to test fortheir presence before accessing them. This example demonstrates how a callback function candetect the presence of the dlpi_adds and dlpi_subs fields described above:
static int callback(struct dl_phdr_info *info, size_t size, void *data) { /* * This must match the definition of dl_phdr_info, as * defined in <link.h>. It is used to determine whether * the info structure contains optional fields. */ struct dl_phdr_info_test { ElfW(Addr) dlpi_addr; const char *dlpi_name; const ElfW(Phdr) *dlpi_phdr; ElfW(Half) dlpi_phnum; u_longlong_t dlpi_adds; u_longlong_t dlpi_subs; }; printf("object: %s\n", info->dlpi_name); printf(" addr: 0x%p\n", (u_longlong_t) info->dlpi_addr); printf(" phdr: 0x%p\n", (u_longlong_t) info->dlpi_phdr); printf(" phnum: %d\n", (int) info->dlpi_phnum); if (size >= sizeof (struct dl_phdr_info_test)) { printf(" adds: %llu\n", info->dlpi_adds); printf(" subs: %llu\n", info->dlpi_subs); } return (0); }Thedl_iterate_phdr() function returns whatever value was returned by the last call tocallback.
Thedl_iterate_phdr() function is a member of a family of functions that givethe user direct access to the dynamic linking facilities. This family of functionsis available only to dynamically-linked processes. See theLinker and Libraries Guide.
Seeattributes(5) for descriptions of the following attributes:
|
ld(1),ld.so.1(1),dladdr(3C),dlclose(3C),dldump(3C),dlerror(3C),dlinfo(3C),dlopen(3C),dlsym(3C),attributes(5),standards(5)
dl_iterate_phdr() was originally defined by the Linux operating system, and is contained inthe Linux Standard Base (LSB).
The behavior ofdl_iterate_phdr()when a callback function causes a new object to beloaded, either via lazy loading or a call todlopen(), is undefined. Thecall todl_iterate_phdr() that triggers the load may or may not issuea callback for the new object. This depends on the current position ofdl_iterate_phdr() in the list of known objects when the new object is added.The caller must make no assumptions about this case.
dl_iterate_phdr() callbacks must not unload objects. If a call todlclose()is detected fromwithin the callback function,dl_iterate_phdr() immediately terminates the iteration operation and returns a valueof -1.
If two separate calls todl_iterate_phdr() provide the same two values fordlpi_addsanddlpi_subs, the caller may safely assume that the process object state hasnot changed between the two calls. An application can use this information tocache object data, and avoid unnecessary iteration. In such a scenario, the firstcall to the callback function would check to see if a cache exists,and thatdlpi_adds anddlpi_subs have not changed since the last call todl_iterate_phdr(), and if so, return a non-zero value to terminate the iteration operationimmediately.
Copyright © 2011, Oracle and/or its affiliates. All rights reserved.Legal Notices | ![]() ![]() |