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"
31 dl_iterate_phdr \- ¶¦Í¥ª¥Ö¥¸¥§¥¯¥È¤Î¥ê¥¹¥È¤òé¤ë
34 .BR "#define _GNU_SOURCE" " /* feature_test_macros(7) »²¾È */"
37 \fBint dl_iterate_phdr(\fP
38 \fBint (*\fPcallback\fB) \
39 (struct dl_phdr_info *\fPinfo\fB,\fP
40 \fBsize_t\fP size\fB, void *\fPdata\fB),\fP
41 \fBvoid *\fPdata\fB);\fP
44 .BR dl_iterate_phdr ()
45 ´Ø¿ô¤ò»È¤¦¤È¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ï¼Â¹Ô»þ¤Ë
46 ¤É¤Î¶¦Í¥ª¥Ö¥¸¥§¥¯¥È¤ò¥í¡¼¥É¤·¤¿¤«¤ò¸«¤Ä¤±¤ë¤³¤È¤¬¤Ç¤¤ë¡£
48 .BR dl_iterate_phdr ()
49 ´Ø¿ô¤Ï¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Î¶¦Í¥ª¥Ö¥¸¥§¥¯¥È¤Î¥ê¥¹¥È¤òé¤ê¡¢
50 ³Æ¥ª¥Ö¥¸¥§¥¯¥È¤ËÂФ·¤Æ´Ø¿ô
53 ¤³¤ì¤ÏÁ´¤Æ¤Î¶¦Í¥ª¥Ö¥¸¥§¥¯¥È¤¬½èÍý¤µ¤ì¤ë¤«¡¢
55 ¤¬ 0 °Ê³°¤ÎÃͤòÊÖ¤¹¤Þ¤Ç¹Ô¤ï¤ì¤ë¡£
59 ¸Æ¤Ó½Ð¤·¤Ï 3 ¤Ä¤Î°ú¤¿ô¤ò¼õ¤±¼è¤ë:
61 ¤Ï¶¦Í¥ª¥Ö¥¸¥§¥¯¥È¤Î¾ðÊó¤òÊÝ»ý¤¹¤ë¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤Ç¤¢¤ë¡£
65 ¤Ç»Ø¤µ¤ì¤ë¹½Â¤ÂΤΥµ¥¤¥º¤Ç¤¢¤ë¡£
67 ¤Ï¸Æ¤Ó½Ð¤·¸µ¥×¥í¥°¥é¥à¤«¤é
68 .BR dl_iterate_phdr ()
71 ¤È¤¤¤¦Ì¾Á°¤Î) Âè 2 °ú¤¿ô¤È¤·¤ÆÅϤµ¤ì¤ëÃͤΥ³¥Ô¡¼¤Ç¤¢¤ë¡£
74 °ú¤¿ô¤Ï¡¢°Ê²¼¤Î¤è¤¦¤Ê·¿¤Î¹½Â¤ÂΤǤ¢¤ë¡£
79 ElfW(Addr) dlpi_addr; /* ¥ª¥Ö¥¸¥§¥¯¥È¤Î¥Ù¡¼¥¹¥¢¥É¥ì¥¹ */
80 const char *dlpi_name; /* (null ʸ»ú¤Ç½ªÃ¼¤µ¤ì¤¿)
82 const ElfW(Phdr) *dlpi_phdr; /* ¤³¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Î
83 ELF ¥×¥í¥°¥é¥à¥Ø¥Ã¥À¤Î
85 ElfW(Half) dlpi_phnum; /* \fIdlpi_phdr\fP ¤Î¥¢¥¤¥Æ¥à¿ô */
91 ¥Þ¥¯¥íÄêµÁ¤Ï°ú¤¿ô¤ò¥Ï¡¼¥É¥¦¥§¥¢¥¢¡¼¥¥Æ¥¯¥Á¥ã¤ËŬ¤·¤¿
92 ELF ¥Ç¡¼¥¿·¿¤Î̾Á°¤ËÊÑ´¹¤¹¤ë¡£
93 ¤¿¤È¤¨¤Ð¡¢32 ¥Ó¥Ã¥È¥×¥é¥Ã¥È¥Õ¥©¡¼¥à¤Ç¤Ï
94 ElfW(Addr) ¤Ï¥Ç¡¼¥¿·¿Ì¾ Elf32_Addr ¤òÀ¸À®¤¹¤ë¡£
95 ¤³¤ì¤é¤Î·¿¤Ë¤Ä¤¤¤Æ¤Î¹¹¤Ë¾ÜºÙ¤Ê¾ðÊó¤Ï¡¢¥Ø¥Ã¥À¥Õ¥¡¥¤¥ë
96 .IR <elf.h> " ¤È " <link.h>
100 ¥Õ¥£¡¼¥ë¥É¤Ï¶¦Í¥ª¥Ö¥¸¥§¥¯¥È¤Î¥Ù¡¼¥¹¥¢¥É¥ì¥¹
101 (¤Ä¤Þ¤ê¡¢¶¦Í¥ª¥Ö¥¸¥§¥¯¥È¤Î²¾ÁÛ¥á¥â¥ê¥¢¥É¥ì¥¹¤È¡¢
102 ¥Õ¥¡¥¤¥ë (¤³¤Î¥Õ¥¡¥¤¥ë¤«¤é¶¦Í¥ª¥Ö¥¸¥§¥¯¥È¤¬¥í¡¼¥É¤µ¤ì¤ë) ¤Ë¤ª¤±¤ë
103 ¶¦Í¥ª¥Ö¥¸¥§¥¯¥È¤Î¥ª¥Õ¥»¥Ã¥È¤È¤Îº¹Ê¬) ¤òɽ¤¹¡£
105 ¤Ï null ʸ»ú¤Ç½ªÃ¼¤µ¤ì¤¿Ê¸»úÎó¤Ç¤¢¤ê¡¢
106 ¤³¤Î¥Ñ¥¹Ì¾¤Î¥Õ¥¡¥¤¥ë¤«¤é¶¦Í¥ª¥Ö¥¸¥§¥¯¥È¤¬¥í¡¼¥É¤µ¤ì¤ë¡£
111 ¥Õ¥£¡¼¥ë¥É¤Î°ÕÌ£¤òÍý²ò¤¹¤ë¤Ë¤Ï¡¢
112 ELF ¶¦Í¥ª¥Ö¥¸¥§¥¯¥È¤¬´ö¤Ä¤«¤Î¥»¥°¥á¥ó¥È¤«¤é¹½À®¤µ¤ì¤Æ¤¤¤ë¤³¤È¤È¡¢
113 ³Æ¥»¥°¥á¥ó¥È¤¬¤½¤ì¤ËÂбþ¤¹¤ë¥×¥í¥°¥é¥à¥Ø¥Ã¥À
114 (¤½¤Î¥»¥°¥á¥ó¥È¤òÀâÌÀ¤¹¤ë) ¤ò»ý¤Ã¤Æ¤¤¤ë¤³¤È¤òÃΤäƤ¤¤ëɬÍפ¬¤¢¤ë¡£
116 ¥Õ¥£¡¼¥ë¥É¤Ï¡¢¤³¤Î¶¦Í¥ª¥Ö¥¸¥§¥¯¥È¤Î¥×¥í¥°¥é¥à¥Ø¥Ã¥À¤ÎÇÛÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
118 ¤Ï¡¢¤³¤ÎÇÛÎó¤Î¥µ¥¤¥º¤òɽ¤¹¡£
120 ¤³¤ì¤é¤Î¥×¥í¥°¥é¥à¥Ø¥Ã¥À¤Ï°Ê²¼¤Î¤è¤¦¤Ê·Á¼°¤Î¹½Â¤ÂΤǤ¢¤ë:
126 Elf32_Word p_type; /* ¥»¥°¥á¥ó¥È¤Î·¿ */
127 Elf32_Off p_offset; /* ¥»¥°¥á¥ó¥È¤Î¥Õ¥¡¥¤¥ë¥ª¥Õ¥»¥Ã¥È */
128 Elf32_Addr p_vaddr; /* ¥»¥°¥á¥ó¥È¤Î²¾ÁÛ¥¢¥É¥ì¥¹ */
129 Elf32_Addr p_paddr; /* ¥»¥°¥á¥ó¥È¤ÎʪÍý¥¢¥É¥ì¥¹ */
130 Elf32_Word p_filesz; /* ¥Õ¥¡¥¤¥ë¤Ë¤ª¤±¤ë¥»¥°¥á¥ó¥È¥µ¥¤¥º */
131 Elf32_Word p_memsz; /* ¥á¥â¥ê¤Ë¤ª¤±¤ë¥»¥°¥á¥ó¥È¥µ¥¤¥º */
132 Elf32_Word p_flags; /* ¥»¥°¥á¥ó¥È¥Õ¥é¥° */
133 Elf32_Word p_align; /* ¥»¥°¥á¥ó¥È¤ÎÇÛÃÖ (alignment) */
138 ÆÃÄê¤Î¥×¥í¥°¥é¥à¥Ø¥Ã¥À
140 ¤Î²¾ÁÛ¥á¥â¥ê¤Ë¤ª¤±¤ë°ÌÃ֤ϡ¢°Ê²¼¤Î¼°¤Ç·×»»¤Ç¤¤ëÅÀ¤ËÃí°Õ¤¹¤ë¤³¤È:
143 addr == info\->dlpi_addr + info\->dlpi_phdr[x].p_vaddr;
146 .BR dl_iterate_phdr ()
149 ¤Î¸Æ¤Ó½Ð¤·¤ÇÊÖ¤µ¤ì¤¿ÃͤòÊÖ¤¹¡£
151 .BR dl_iterate_phdr ()
152 ¤Ï glibc ¤Î¥Ð¡¼¥¸¥ç¥ó 2.2.4 °Ê¹ß¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¡£
154 .BR dl_iterate_phdr ()
155 ´Ø¿ô¤Ï Linux ¸ÇͤǤ¢¤ê¡¢°Ü¿¢¤ò¹Í¤¨¤¿¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤ÏÈò¤±¤ë¤Ù¤¤Ç¤¢¤ë¡£
157 °Ê²¼¤Î¥×¥í¥°¥é¥à¤Ï¡¢¶¦Í¥ª¥Ö¥¸¥§¥¯¥È¤¬¥í¡¼¥É¤µ¤ì¤¿
158 ¥Ñ¥¹Ì¾¤Î°ìÍ÷¤òɽ¼¨¤¹¤ë¡£
159 ³Æ¶¦Í¥ª¥Ö¥¸¥§¥¯¥È¤Ë¤Ä¤¤¤Æ¡¢¤³¤Î¥×¥í¥°¥é¥à¤Ï
160 ¥ª¥Ö¥¸¥§¥¯¥È¤Î ELF ¥»¥°¥á¥ó¥È¤¬¥í¡¼¥É¤µ¤ì¤¿
161 ²¾ÁÛ¥¢¥É¥ì¥¹¤Î°ìÍ÷¤òɽ¼¨¤¹¤ë¡£
170 callback(struct dl_phdr_info *info, size_t size, void *data)
174 printf("name=%s (%d segments)\\n", info\->dlpi_name,
177 for (j = 0; j < info\->dlpi_phnum; j++)
178 printf("\\t\\t header %2d: address=%10p\\n", j,
179 (void *) (info\->dlpi_addr + info\->dlpi_phdr[j].p_vaddr));
184 main(int argc, char *argv[])
186 dl_iterate_phdr(callback, NULL);
198 ¥ª¥ó¥é¥¤¥ó¤Î¤¤¤í¤¤¤í¤Ê¾ì½ê¤ÇÆþ¼ê¤Ç¤¤ë
199 .I "Executable and Linking Format Specification"