OSDN Git Service

151f50fc89eae6c7482e3c85bc74fb2d324daaeb
[linuxjm/LDP_man-pages.git] / release / man3 / dl_iterate_phdr.3
1 .\" Copyright (c) 2003 by Michael Kerrisk <mtk.manpages@gmail.com>
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\"*******************************************************************
26 .\"
27 .\" This file was generated with po4a. Translate the source file.
28 .\"
29 .\"*******************************************************************
30 .\"
31 .\" Japanese Version Copyright (c) 2005 Yuichi SATO
32 .\"         all rights reserved.
33 .\" Translated Thu Jan 27 07:03:56 JST 2005
34 .\"         by Yuichi SATO <ysato444@yahoo.co.jp>
35 .\"
36 .TH DL_ITERATE_PHDR 3 2007\-05\-18 GNU "Linux Programmer's Manual"
37 .SH 名前
38 dl_iterate_phdr \- 共有オブジェクトのリストを辿る
39 .SH 書式
40 .nf
41 \fB#define _GNU_SOURCE\fP         /* feature_test_macros(7) 参照 */
42 \fB#include <link.h>\fP
43
44 \fBint dl_iterate_phdr(\fP
45 \fB          int (*\fP\fIcallback\fP\fB) (struct dl_phdr_info *\fP\fIinfo\fP\fB,\fP
46 \fB                           size_t \fP\fIsize\fP\fB, void *\fP\fIdata\fP\fB,\fP
47 \fB          void *\fP\fIdata\fP\fB;\fP
48 .fi
49 .SH 説明
50 \fBdl_iterate_phdr\fP()  関数を使うと、アプリケーションは実行時に どの共有オブジェクトをロードしたかを見つけることができる。
51
52 \fBdl_iterate_phdr\fP()  関数はアプリケーションの共有オブジェクトのリストを辿り、 各オブジェクトに対して関数 \fIcallback\fP
53 を 1 回ずつ呼び出す。 これは全ての共有オブジェクトが処理されるか、 \fIcallback\fP が 0 以外の値を返すまで行われる。
54
55 各々の \fIcallback\fP 呼び出しは 3 つの引き数を受け取る: \fIinfo\fP は共有オブジェクトの情報を保持する構造体へのポインタである。
56 \fIsize\fP は \fIinfo\fP で指される構造体のサイズである。 \fIdata\fP は呼び出し元プログラムから
57 \fBdl_iterate_phdr\fP()  の呼び出しの (同じく \fIdata\fP という名前の) 第 2 引き数として渡される値のコピーである。
58
59 \fIinfo\fP 引き数は、以下のような型の構造体である。
60
61 .in +4n
62 .nf
63 struct dl_phdr_info {
64     ElfW(Addr)        dlpi_addr;  /* オブジェクトのベースアドレス */
65     const char       *dlpi_name;  /* (ヌル文字で終端された)
66                                      オブジェクト名 */
67     const ElfW(Phdr) *dlpi_phdr;  /* このオブジェクトの
68                                      ELF プログラムヘッダの
69                                      配列へのポインタ */
70     ElfW(Half)        dlpi_phnum; /* \fIdlpi_phdr\fP のアイテム数 */
71 };
72 .fi
73 .in
74
75 (\fIElfW\fP()  マクロ定義は引き数をハードウェアアーキテクチャに適した ELF データ型の名前に変換する。 たとえば、32
76 ビットプラットフォームでは ElfW(Addr) はデータ型名 Elf32_Addr を生成する。 これらの型についての更に詳細な情報は、ヘッダファイル
77 \fI<elf.h>\fP と \fI<link.h>\fP にある。
78
79 \fIdlpi_addr\fP フィールドは共有オブジェクトのベースアドレス (つまり、共有オブジェクトの仮想メモリアドレスと、 ファイル
80 (このファイルから共有オブジェクトがロードされる) における 共有オブジェクトのオフセットとの差分) を表す。 \fIdlpi_name\fP
81 はヌル文字で終端された文字列であり、 このパス名のファイルから共有オブジェクトがロードされる。
82
83 \fIdlpi_phdr\fP と \fIdlpi_phnum\fP フィールドの意味を理解するには、 ELF
84 共有オブジェクトが幾つかのセグメントから構成されていることと、 各セグメントがそれに対応するプログラムヘッダ (そのセグメントを説明する)
85 を持っていることを知っている必要がある。 \fIdlpi_phdr\fP フィールドは、この共有オブジェクトのプログラムヘッダの配列へのポインタである。
86 \fIdlpi_phnum\fP は、この配列のサイズを表す。
87
88 これらのプログラムヘッダは以下のような形式の構造体である:
89 .in +4n
90 .nf
91
92 typedef struct
93 {
94     Elf32_Word  p_type;    /* セグメントの型 */
95     Elf32_Off   p_offset;  /* セグメントのファイルオフセット */
96     Elf32_Addr  p_vaddr;   /* セグメントの仮想アドレス */
97     Elf32_Addr  p_paddr;   /* セグメントの物理アドレス */
98     Elf32_Word  p_filesz;  /* ファイルにおけるセグメントサイズ */
99     Elf32_Word  p_memsz;   /* メモリにおけるセグメントサイズ */
100     Elf32_Word  p_flags;   /* セグメントフラグ */
101     Elf32_Word  p_align;   /* セグメントの配置 (alignment) */
102 } Elf32_Phdr;
103 .fi
104 .in
105
106 特定のプログラムヘッダ \fIx\fP の仮想メモリにおける位置は、以下の式で計算できる点に注意すること:
107
108 .nf
109   addr == info\->dlpi_addr + info\->dlpi_phdr[x].p_vaddr;
110 .fi
111 .SH 返り値
112 \fBdl_iterate_phdr\fP()  関数は最後の \fIcallback\fP の呼び出しで返された値を返す。
113 .SH バージョン
114 \fBdl_iterate_phdr\fP()  は glibc のバージョン 2.2.4 以降でサポートされている。
115 .SH 準拠
116 \fBdl_iterate_phdr\fP()  関数は Linux 固有であり、移植を考えたアプリケーションでは避けるべきである。
117 .SH 例
118 以下のプログラムは、共有オブジェクトがロードされた パス名の一覧を表示する。 各共有オブジェクトについて、このプログラムは オブジェクトの ELF
119 セグメントがロードされた 仮想アドレスの一覧を表示する。
120
121 .nf
122 #define _GNU_SOURCE
123 #include <link.h>
124 #include <stdlib.h>
125 #include <stdio.h>
126
127 static int
128 callback(struct dl_phdr_info *info, size_t size, void *data)
129 {
130     int j;
131
132     printf("name=%s (%d segments)\en", info\->dlpi_name,
133         info\->dlpi_phnum);
134
135     for (j = 0; j < info\->dlpi_phnum; j++)
136          printf("\et\et header %2d: address=%10p\en", j,
137              (void *) (info\->dlpi_addr + info\->dlpi_phdr[j].p_vaddr));
138     return 0;
139 }
140
141 int
142 main(int argc, char *argv[])
143 {
144     dl_iterate_phdr(callback, NULL);
145
146     exit(EXIT_SUCCESS);
147 }
148 .fi
149 .SH 関連項目
150 \fBldd\fP(1), \fBobjdump\fP(1), \fBreadelf\fP(1), \fBdlopen\fP(3), \fBelf\fP(5),
151 \fBld.so\fP(8)
152
153 オンラインのいろいろな場所で入手できる \fIExecutable and Linking Format Specification\fP
154 .SH この文書について
155 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.65 の一部
156 である。プロジェクトの説明とバグ報告に関する情報は
157 http://www.kernel.org/doc/man\-pages/ に書かれている。