OSDN Git Service

(split) LDP v3.30, v3.31 の定型的な変更内容を反映。
[linuxjm/LDP_man-pages.git] / release / man3 / dl_iterate_phdr.3
1 .\" Copyright (c) 2003 by Michael Kerrisk <mtk.manpages@gmail.com>
2 .\"
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.
6 .\"
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
11 .\"
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
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\" License.
23 .\"
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>
28 .\"
29 .TH DL_ITERATE_PHDR 3 2007-05-18 "Linux" "Linux Programmer's Manual"
30 .SH Ì¾Á°
31 dl_iterate_phdr \- ¶¦Í­¥ª¥Ö¥¸¥§¥¯¥È¤Î¥ê¥¹¥È¤òé¤ë
32 .SH ½ñ¼°
33 .nf
34 .BR "#define _GNU_SOURCE" "         /* feature_test_macros(7) »²¾È */"
35 .B #include <link.h>
36
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
42 .fi
43 .SH ÀâÌÀ
44 .BR dl_iterate_phdr ()
45 ´Ø¿ô¤ò»È¤¦¤È¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ï¼Â¹Ô»þ¤Ë
46 ¤É¤Î¶¦Í­¥ª¥Ö¥¸¥§¥¯¥È¤ò¥í¡¼¥É¤·¤¿¤«¤ò¸«¤Ä¤±¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
47
48 .BR dl_iterate_phdr ()
49 ´Ø¿ô¤Ï¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Î¶¦Í­¥ª¥Ö¥¸¥§¥¯¥È¤Î¥ê¥¹¥È¤òé¤ê¡¢
50 ³Æ¥ª¥Ö¥¸¥§¥¯¥È¤ËÂФ·¤Æ´Ø¿ô
51 .I callback
52 ¤ò 1 ²ó¤º¤Ä¸Æ¤Ó½Ð¤¹¡£
53 ¤³¤ì¤ÏÁ´¤Æ¤Î¶¦Í­¥ª¥Ö¥¸¥§¥¯¥È¤¬½èÍý¤µ¤ì¤ë¤«¡¢
54 .I callback
55 ¤¬ 0 °Ê³°¤ÎÃͤòÊÖ¤¹¤Þ¤Ç¹Ô¤ï¤ì¤ë¡£
56
57 ³Æ¡¹¤Î
58 .I callback
59 ¸Æ¤Ó½Ð¤·¤Ï 3 ¤Ä¤Î°ú¤­¿ô¤ò¼õ¤±¼è¤ë:
60 .I info
61 ¤Ï¶¦Í­¥ª¥Ö¥¸¥§¥¯¥È¤Î¾ðÊó¤òÊÝ»ý¤¹¤ë¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤Ç¤¢¤ë¡£
62 .I size
63 ¤Ï
64 .I info
65 ¤Ç»Ø¤µ¤ì¤ë¹½Â¤ÂΤΥµ¥¤¥º¤Ç¤¢¤ë¡£
66 .I data
67 ¤Ï¸Æ¤Ó½Ð¤·¸µ¥×¥í¥°¥é¥à¤«¤é
68 .BR dl_iterate_phdr ()
69 ¤Î¸Æ¤Ó½Ð¤·¤Î (Ʊ¤¸¤¯
70 .I data
71 ¤È¤¤¤¦Ì¾Á°¤Î) Âè 2 °ú¤­¿ô¤È¤·¤ÆÅϤµ¤ì¤ëÃͤΥ³¥Ô¡¼¤Ç¤¢¤ë¡£
72
73 .I info
74 °ú¤­¿ô¤Ï¡¢°Ê²¼¤Î¤è¤¦¤Ê·¿¤Î¹½Â¤ÂΤǤ¢¤ë¡£
75
76 .in +4n
77 .nf
78 struct dl_phdr_info {
79     ElfW(Addr)        dlpi_addr;  /* ¥ª¥Ö¥¸¥§¥¯¥È¤Î¥Ù¡¼¥¹¥¢¥É¥ì¥¹ */
80     const char       *dlpi_name;  /* (null Ê¸»ú¤Ç½ªÃ¼¤µ¤ì¤¿)
81                                      ¥ª¥Ö¥¸¥§¥¯¥È̾ */
82     const ElfW(Phdr) *dlpi_phdr;  /* ¤³¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Î
83                                      ELF ¥×¥í¥°¥é¥à¥Ø¥Ã¥À¤Î
84                                      ÇÛÎó¤Ø¤Î¥Ý¥¤¥ó¥¿ */
85     ElfW(Half)        dlpi_phnum; /* \fIdlpi_phdr\fP ¤Î¥¢¥¤¥Æ¥à¿ô */
86 };
87 .fi
88 .in
89
90 .RI ( ElfW ()
91 ¥Þ¥¯¥íÄêµÁ¤Ï°ú¤­¿ô¤ò¥Ï¡¼¥É¥¦¥§¥¢¥¢¡¼¥­¥Æ¥¯¥Á¥ã¤ËŬ¤·¤¿
92 ELF ¥Ç¡¼¥¿·¿¤Î̾Á°¤ËÊÑ´¹¤¹¤ë¡£
93 ¤¿¤È¤¨¤Ð¡¢32 ¥Ó¥Ã¥È¥×¥é¥Ã¥È¥Õ¥©¡¼¥à¤Ç¤Ï
94 ElfW(Addr) ¤Ï¥Ç¡¼¥¿·¿Ì¾ Elf32_Addr ¤òÀ¸À®¤¹¤ë¡£
95 ¤³¤ì¤é¤Î·¿¤Ë¤Ä¤¤¤Æ¤Î¹¹¤Ë¾ÜºÙ¤Ê¾ðÊó¤Ï¡¢¥Ø¥Ã¥À¥Õ¥¡¥¤¥ë
96 .IR <elf.h> " ¤È " <link.h>
97 ¤Ë¤¢¤ë¡£
98
99 .I dlpi_addr
100 ¥Õ¥£¡¼¥ë¥É¤Ï¶¦Í­¥ª¥Ö¥¸¥§¥¯¥È¤Î¥Ù¡¼¥¹¥¢¥É¥ì¥¹
101 (¤Ä¤Þ¤ê¡¢¶¦Í­¥ª¥Ö¥¸¥§¥¯¥È¤Î²¾ÁÛ¥á¥â¥ê¥¢¥É¥ì¥¹¤È¡¢
102 ¥Õ¥¡¥¤¥ë (¤³¤Î¥Õ¥¡¥¤¥ë¤«¤é¶¦Í­¥ª¥Ö¥¸¥§¥¯¥È¤¬¥í¡¼¥É¤µ¤ì¤ë) ¤Ë¤ª¤±¤ë
103 ¶¦Í­¥ª¥Ö¥¸¥§¥¯¥È¤Î¥ª¥Õ¥»¥Ã¥È¤È¤Îº¹Ê¬) ¤òɽ¤¹¡£
104 .I dlpi_name
105 ¤Ï null Ê¸»ú¤Ç½ªÃ¼¤µ¤ì¤¿Ê¸»úÎó¤Ç¤¢¤ê¡¢
106 ¤³¤Î¥Ñ¥¹Ì¾¤Î¥Õ¥¡¥¤¥ë¤«¤é¶¦Í­¥ª¥Ö¥¸¥§¥¯¥È¤¬¥í¡¼¥É¤µ¤ì¤ë¡£
107
108 .I dlpi_phdr
109 ¤È
110 .I dlpi_phnum
111 ¥Õ¥£¡¼¥ë¥É¤Î°ÕÌ£¤òÍý²ò¤¹¤ë¤Ë¤Ï¡¢
112 ELF ¶¦Í­¥ª¥Ö¥¸¥§¥¯¥È¤¬´ö¤Ä¤«¤Î¥»¥°¥á¥ó¥È¤«¤é¹½À®¤µ¤ì¤Æ¤¤¤ë¤³¤È¤È¡¢
113 ³Æ¥»¥°¥á¥ó¥È¤¬¤½¤ì¤ËÂбþ¤¹¤ë¥×¥í¥°¥é¥à¥Ø¥Ã¥À
114 (¤½¤Î¥»¥°¥á¥ó¥È¤òÀâÌÀ¤¹¤ë) ¤ò»ý¤Ã¤Æ¤¤¤ë¤³¤È¤òÃΤäƤ¤¤ëɬÍפ¬¤¢¤ë¡£
115 .I dlpi_phdr
116 ¥Õ¥£¡¼¥ë¥É¤Ï¡¢¤³¤Î¶¦Í­¥ª¥Ö¥¸¥§¥¯¥È¤Î¥×¥í¥°¥é¥à¥Ø¥Ã¥À¤ÎÇÛÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
117 .I dlpi_phnum
118 ¤Ï¡¢¤³¤ÎÇÛÎó¤Î¥µ¥¤¥º¤òɽ¤¹¡£
119
120 ¤³¤ì¤é¤Î¥×¥í¥°¥é¥à¥Ø¥Ã¥À¤Ï°Ê²¼¤Î¤è¤¦¤Ê·Á¼°¤Î¹½Â¤ÂΤǤ¢¤ë:
121 .in +4n
122 .nf
123
124 typedef struct
125 {
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) */
134 } Elf32_Phdr;
135 .fi
136 .in
137
138 ÆÃÄê¤Î¥×¥í¥°¥é¥à¥Ø¥Ã¥À
139 .I x
140 ¤Î²¾ÁÛ¥á¥â¥ê¤Ë¤ª¤±¤ë°ÌÃ֤ϡ¢°Ê²¼¤Î¼°¤Ç·×»»¤Ç¤­¤ëÅÀ¤ËÃí°Õ¤¹¤ë¤³¤È:
141
142 .nf
143   addr == info\->dlpi_addr + info\->dlpi_phdr[x].p_vaddr;
144 .fi
145 .SH ÊÖ¤êÃÍ
146 .BR dl_iterate_phdr ()
147 ´Ø¿ô¤ÏºÇ¸å¤Î
148 .I callback
149 ¤Î¸Æ¤Ó½Ð¤·¤ÇÊÖ¤µ¤ì¤¿ÃͤòÊÖ¤¹¡£
150 .SH ¥Ð¡¼¥¸¥ç¥ó
151 .BR dl_iterate_phdr ()
152 ¤Ï glibc ¤Î¥Ð¡¼¥¸¥ç¥ó 2.2.4 °Ê¹ß¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¡£
153 .SH ½àµò
154 .BR dl_iterate_phdr ()
155 ´Ø¿ô¤Ï Linux ¸ÇÍ­¤Ç¤¢¤ê¡¢°Ü¿¢¤ò¹Í¤¨¤¿¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤ÏÈò¤±¤ë¤Ù¤­¤Ç¤¢¤ë¡£
156 .SH Îã
157 °Ê²¼¤Î¥×¥í¥°¥é¥à¤Ï¡¢¶¦Í­¥ª¥Ö¥¸¥§¥¯¥È¤¬¥í¡¼¥É¤µ¤ì¤¿
158 ¥Ñ¥¹Ì¾¤Î°ìÍ÷¤òɽ¼¨¤¹¤ë¡£
159 ³Æ¶¦Í­¥ª¥Ö¥¸¥§¥¯¥È¤Ë¤Ä¤¤¤Æ¡¢¤³¤Î¥×¥í¥°¥é¥à¤Ï
160 ¥ª¥Ö¥¸¥§¥¯¥È¤Î ELF ¥»¥°¥á¥ó¥È¤¬¥í¡¼¥É¤µ¤ì¤¿
161 ²¾ÁÛ¥¢¥É¥ì¥¹¤Î°ìÍ÷¤òɽ¼¨¤¹¤ë¡£
162
163 .nf
164 #define _GNU_SOURCE
165 #include <link.h>
166 #include <stdlib.h>
167 #include <stdio.h>
168
169 static int
170 callback(struct dl_phdr_info *info, size_t size, void *data)
171 {
172     int j;
173
174     printf("name=%s (%d segments)\\n", info\->dlpi_name,
175         info\->dlpi_phnum);
176
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));
180     return 0;
181 }
182
183 int
184 main(int argc, char *argv[])
185 {
186     dl_iterate_phdr(callback, NULL);
187
188     exit(EXIT_SUCCESS);
189 }
190 .fi
191 .SH ´ØÏ¢¹àÌÜ
192 .BR ldd (1),
193 .BR objdump (1),
194 .BR readelf (1),
195 .BR dlopen (3),
196 .BR elf (5),
197 .BR ld.so (8),
198 ¥ª¥ó¥é¥¤¥ó¤Î¤¤¤í¤¤¤í¤Ê¾ì½ê¤ÇÆþ¼ê¤Ç¤­¤ë
199 .I "Executable and Linking Format Specification"