1 .\" Copyright (c) 2003 by Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" Japanese Version Copyright (c) 2005 Yuichi SATO
25 .\" all rights reserved.
26 .\" Translated Thu Jan 27 07:03:56 JST 2005
27 .\" by Yuichi SATO <ysato444@yahoo.co.jp>
29 .TH DL_ITERATE_PHDR 3 2007-05-18 "Linux" "Linux Programmer's Manual"
32 .\"O dl_iterate_phdr \- walk through list of shared objects
33 dl_iterate_phdr \- ¶¦Í¥ª¥Ö¥¸¥§¥¯¥È¤Î¥ê¥¹¥È¤òé¤ë
37 .\"O .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
38 .BR "#define _GNU_SOURCE" " /* feature_test_macros(7) »²¾È */"
41 \fBint dl_iterate_phdr(\fP
42 \fBint (*\fPcallback\fB) \
43 (struct dl_phdr_info *\fPinfo\fB,\fP
44 \fBsize_t\fP size\fB, void *\fPdata\fB),\fP
45 \fBvoid *\fPdata\fB);\fP
50 .\"O .BR dl_iterate_phdr ()
51 .\"O function allows an application to inquire at run time to find
52 .\"O out which shared objects it has loaded.
53 .BR dl_iterate_phdr ()
54 ´Ø¿ô¤ò»È¤¦¤È¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ï¼Â¹Ô»þ¤Ë
55 ¤É¤Î¶¦Í¥ª¥Ö¥¸¥§¥¯¥È¤ò¥í¡¼¥É¤·¤¿¤«¤ò¸«¤Ä¤±¤ë¤³¤È¤¬¤Ç¤¤ë¡£
58 .\"O .BR dl_iterate_phdr ()
59 .\"O function walks through the list of an
60 .\"O application's shared objects and calls the function
62 .\"O once for each object,
63 .\"O until either all shared objects have been processed or
65 .\"O returns a nonzero value.
66 .BR dl_iterate_phdr ()
67 ´Ø¿ô¤Ï¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Î¶¦Í¥ª¥Ö¥¸¥§¥¯¥È¤Î¥ê¥¹¥È¤òé¤ê¡¢
68 ³Æ¥ª¥Ö¥¸¥§¥¯¥È¤ËÂФ·¤Æ´Ø¿ô
71 ¤³¤ì¤ÏÁ´¤Æ¤Î¶¦Í¥ª¥Ö¥¸¥§¥¯¥È¤¬½èÍý¤µ¤ì¤ë¤«¡¢
73 ¤¬ 0 °Ê³°¤ÎÃͤòÊÖ¤¹¤Þ¤Ç¹Ô¤ï¤ì¤ë¡£
77 .\"O receives three arguments:
80 ¸Æ¤Ó½Ð¤·¤Ï 3 ¤Ä¤Î°ú¤¿ô¤ò¼õ¤±¼è¤ë:
82 .\"O which is a pointer to a structure containing information
83 .\"O about the shared object;
85 ¤Ï¶¦Í¥ª¥Ö¥¸¥§¥¯¥È¤Î¾ðÊó¤òÊÝ»ý¤¹¤ë¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤Ç¤¢¤ë¡£
87 .\"O which is the size of the structure pointed to by
92 ¤Ç»Ø¤µ¤ì¤ë¹½Â¤ÂΤΥµ¥¤¥º¤Ç¤¢¤ë¡£
95 .\"O which is a copy of whatever value was passed by the calling
96 .\"O program as the second argument (also named
99 .\"O .BR dl_iterate_phdr ().
101 ¤Ï¸Æ¤Ó½Ð¤·¸µ¥×¥í¥°¥é¥à¤«¤é
102 .BR dl_iterate_phdr ()
105 ¤È¤¤¤¦Ì¾Á°¤Î) Âè 2 °ú¤¿ô¤È¤·¤ÆÅϤµ¤ì¤ëÃͤΥ³¥Ô¡¼¤Ç¤¢¤ë¡£
109 .\"O argument is a structure of the following type:
111 °ú¤¿ô¤Ï¡¢°Ê²¼¤Î¤è¤¦¤Ê·¿¤Î¹½Â¤ÂΤǤ¢¤ë¡£
115 struct dl_phdr_info {
116 .\"O ElfW(Addr) dlpi_addr; /* Base address of object */
117 ElfW(Addr) dlpi_addr; /* ¥ª¥Ö¥¸¥§¥¯¥È¤Î¥Ù¡¼¥¹¥¢¥É¥ì¥¹ */
118 .\"O const char *dlpi_name; /* (Null-terminated) name of
120 const char *dlpi_name; /* (null ʸ»ú¤Ç½ªÃ¼¤µ¤ì¤¿)
122 .\"O const ElfW(Phdr) *dlpi_phdr; /* Pointer to array of
123 .\"O ELF program headers
124 .\"O for this object */
125 const ElfW(Phdr) *dlpi_phdr; /* ¤³¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Î
126 ELF ¥×¥í¥°¥é¥à¥Ø¥Ã¥À¤Î
128 .\"O ElfW(Half) dlpi_phnum; /* # of items in \fIdlpi_phdr\fP */
129 ElfW(Half) dlpi_phnum; /* \fIdlpi_phdr\fP ¤Î¥¢¥¤¥Æ¥à¿ô */
136 .\"O macro definition turns its argument into the name of an ELF data
137 .\"O type suitable for the hardware architecture.
139 ¥Þ¥¯¥íÄêµÁ¤Ï°ú¤¿ô¤ò¥Ï¡¼¥É¥¦¥§¥¢¥¢¡¼¥¥Æ¥¯¥Á¥ã¤ËŬ¤·¤¿
140 ELF ¥Ç¡¼¥¿·¿¤Î̾Á°¤ËÊÑ´¹¤¹¤ë¡£
141 .\"O For example, on a 32-bit platform,
142 .\"O ElfW(Addr) yields the data type name Elf32_Addr.
143 ¤¿¤È¤¨¤Ð¡¢32 ¥Ó¥Ã¥È¥×¥é¥Ã¥È¥Õ¥©¡¼¥à¤Ç¤Ï
144 ElfW(Addr) ¤Ï¥Ç¡¼¥¿·¿Ì¾ Elf32_Addr ¤òÀ¸À®¤¹¤ë¡£
145 .\"O Further information on these types can be found in the
146 .\"O .IR <elf.h> " and " <link.h>
148 ¤³¤ì¤é¤Î·¿¤Ë¤Ä¤¤¤Æ¤Î¹¹¤Ë¾ÜºÙ¤Ê¾ðÊó¤Ï¡¢¥Ø¥Ã¥À¥Õ¥¡¥¤¥ë
149 .IR <elf.h> " ¤È " <link.h>
154 .\"O field indicates the base address of the shared object
155 .\"O (i.e., the difference between the virtual memory address of
156 .\"O the shared object and the offset of that object in the file
157 .\"O from which it was loaded).
159 ¥Õ¥£¡¼¥ë¥É¤Ï¶¦Í¥ª¥Ö¥¸¥§¥¯¥È¤Î¥Ù¡¼¥¹¥¢¥É¥ì¥¹
160 (¤Ä¤Þ¤ê¡¢¶¦Í¥ª¥Ö¥¸¥§¥¯¥È¤Î²¾ÁÛ¥á¥â¥ê¥¢¥É¥ì¥¹¤È¡¢
161 ¥Õ¥¡¥¤¥ë (¤³¤Î¥Õ¥¡¥¤¥ë¤«¤é¶¦Í¥ª¥Ö¥¸¥§¥¯¥È¤¬¥í¡¼¥É¤µ¤ì¤ë) ¤Ë¤ª¤±¤ë
162 ¶¦Í¥ª¥Ö¥¸¥§¥¯¥È¤Î¥ª¥Õ¥»¥Ã¥È¤È¤Îº¹Ê¬) ¤òɽ¤¹¡£
165 .\"O field is a null-terminated string giving the pathname
166 .\"O from which the shared object was loaded.
168 ¤Ï null ʸ»ú¤Ç½ªÃ¼¤µ¤ì¤¿Ê¸»úÎó¤Ç¤¢¤ê¡¢
169 ¤³¤Î¥Ñ¥¹Ì¾¤Î¥Õ¥¡¥¤¥ë¤«¤é¶¦Í¥ª¥Ö¥¸¥§¥¯¥È¤¬¥í¡¼¥É¤µ¤ì¤ë¡£
171 .\"O To understand the meaning of the
175 .\"O fields, we need to be aware that an ELF shared object consists
176 .\"O of a number of segments, each of which has a corresponding
177 .\"O program header describing the segment.
181 ¥Õ¥£¡¼¥ë¥É¤Î°ÕÌ£¤òÍý²ò¤¹¤ë¤Ë¤Ï¡¢
182 ELF ¶¦Í¥ª¥Ö¥¸¥§¥¯¥È¤¬´ö¤Ä¤«¤Î¥»¥°¥á¥ó¥È¤«¤é¹½À®¤µ¤ì¤Æ¤¤¤ë¤³¤È¤È¡¢
183 ³Æ¥»¥°¥á¥ó¥È¤¬¤½¤ì¤ËÂбþ¤¹¤ë¥×¥í¥°¥é¥à¥Ø¥Ã¥À
184 (¤½¤Î¥»¥°¥á¥ó¥È¤òÀâÌÀ¤¹¤ë) ¤ò»ý¤Ã¤Æ¤¤¤ë¤³¤È¤òÃΤäƤ¤¤ëɬÍפ¬¤¢¤ë¡£
187 .\"O field is a pointer to an array of the program headers for this
190 ¥Õ¥£¡¼¥ë¥É¤Ï¡¢¤³¤Î¶¦Í¥ª¥Ö¥¸¥§¥¯¥È¤Î¥×¥í¥°¥é¥à¥Ø¥Ã¥À¤ÎÇÛÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
193 .\"O field indicates the size of this array.
195 ¤Ï¡¢¤³¤ÎÇÛÎó¤Î¥µ¥¤¥º¤òɽ¤¹¡£
197 .\"O These program headers are structures of the following form:
198 ¤³¤ì¤é¤Î¥×¥í¥°¥é¥à¥Ø¥Ã¥À¤Ï°Ê²¼¤Î¤è¤¦¤Ê·Á¼°¤Î¹½Â¤ÂΤǤ¢¤ë:
204 .\"O Elf32_Word p_type; /* Segment type */
205 Elf32_Word p_type; /* ¥»¥°¥á¥ó¥È¤Î·¿ */
206 .\"O Elf32_Off p_offset; /* Segment file offset */
207 Elf32_Off p_offset; /* ¥»¥°¥á¥ó¥È¤Î¥Õ¥¡¥¤¥ë¥ª¥Õ¥»¥Ã¥È */
208 .\"O Elf32_Addr p_vaddr; /* Segment virtual address */
209 Elf32_Addr p_vaddr; /* ¥»¥°¥á¥ó¥È¤Î²¾ÁÛ¥¢¥É¥ì¥¹ */
210 .\"O Elf32_Addr p_paddr; /* Segment physical address */
211 Elf32_Addr p_paddr; /* ¥»¥°¥á¥ó¥È¤ÎʪÍý¥¢¥É¥ì¥¹ */
212 .\"O Elf32_Word p_filesz; /* Segment size in file */
213 Elf32_Word p_filesz; /* ¥Õ¥¡¥¤¥ë¤Ë¤ª¤±¤ë¥»¥°¥á¥ó¥È¥µ¥¤¥º */
214 .\"O Elf32_Word p_memsz; /* Segment size in memory */
215 Elf32_Word p_memsz; /* ¥á¥â¥ê¤Ë¤ª¤±¤ë¥»¥°¥á¥ó¥È¥µ¥¤¥º */
216 .\"O Elf32_Word p_flags; /* Segment flags */
217 Elf32_Word p_flags; /* ¥»¥°¥á¥ó¥È¥Õ¥é¥° */
218 .\"O Elf32_Word p_align; /* Segment alignment */
219 Elf32_Word p_align; /* ¥»¥°¥á¥ó¥È¤ÎÇÛÃÖ (alignment) */
224 .\"O Note that we can calculate the location of a particular program header,
226 .\"O in virtual memory using the formula:
227 ÆÃÄê¤Î¥×¥í¥°¥é¥à¥Ø¥Ã¥À
229 ¤Î²¾ÁÛ¥á¥â¥ê¤Ë¤ª¤±¤ë°ÌÃ֤ϡ¢°Ê²¼¤Î¼°¤Ç·×»»¤Ç¤¤ëÅÀ¤ËÃí°Õ¤¹¤ë¤³¤È:
232 addr == info\->dlpi_addr + info\->dlpi_phdr[x].p_vaddr;
234 .\"O .SH RETURN VALUE
237 .\"O .BR dl_iterate_phdr ()
238 .\"O function returns whatever value was returned by the last call to
240 .BR dl_iterate_phdr ()
243 ¤Î¸Æ¤Ó½Ð¤·¤ÇÊÖ¤µ¤ì¤¿ÃͤòÊÖ¤¹¡£
246 .\"O .BR dl_iterate_phdr ()
247 .\"O has been supported in glibc since version 2.2.4.
248 .BR dl_iterate_phdr ()
249 ¤Ï glibc ¤Î¥Ð¡¼¥¸¥ç¥ó 2.2.4 °Ê¹ß¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¡£
250 .\"O .SH "CONFORMING TO"
253 .\"O .BR dl_iterate_phdr ()
254 .\"O function is Linux-specific and should be avoided in portable applications.
255 .BR dl_iterate_phdr ()
256 ´Ø¿ô¤Ï Linux ¸ÇͤǤ¢¤ê¡¢°Ü¿¢¤ò¹Í¤¨¤¿¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤ÏÈò¤±¤ë¤Ù¤¤Ç¤¢¤ë¡£
259 .\"O The following program displays a list of pathnames of the
260 .\"O shared objects it has loaded.
261 °Ê²¼¤Î¥×¥í¥°¥é¥à¤Ï¡¢¶¦Í¥ª¥Ö¥¸¥§¥¯¥È¤¬¥í¡¼¥É¤µ¤ì¤¿
262 ¥Ñ¥¹Ì¾¤Î°ìÍ÷¤òɽ¼¨¤¹¤ë¡£
263 .\"O For each shared object, the program lists the virtual addresses
264 .\"O at which the object's ELF segments are loaded.
265 ³Æ¶¦Í¥ª¥Ö¥¸¥§¥¯¥È¤Ë¤Ä¤¤¤Æ¡¢¤³¤Î¥×¥í¥°¥é¥à¤Ï
266 ¥ª¥Ö¥¸¥§¥¯¥È¤Î ELF ¥»¥°¥á¥ó¥È¤¬¥í¡¼¥É¤µ¤ì¤¿
267 ²¾ÁÛ¥¢¥É¥ì¥¹¤Î°ìÍ÷¤òɽ¼¨¤¹¤ë¡£
276 callback(struct dl_phdr_info *info, size_t size, void *data)
280 printf("name=%s (%d segments)\\n", info\->dlpi_name,
283 for (j = 0; j < info\->dlpi_phnum; j++)
284 printf("\\t\\t header %2d: address=%10p\\n", j,
285 (void *) (info\->dlpi_addr + info\->dlpi_phdr[j].p_vaddr));
290 main(int argc, char *argv[])
292 dl_iterate_phdr(callback, NULL);
306 .\"O .I "Executable and Linking Format Specification"
307 .\"O available at various locations online.
308 ¥ª¥ó¥é¥¤¥ó¤Î¤¤¤í¤¤¤í¤Ê¾ì½ê¤ÇÆþ¼ê¤Ç¤¤ë
309 .I "Executable and Linking Format Specification"