OSDN Git Service

(split) LDP: Release pages for LDP v3.39.
[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 .\"*******************************************************************
25 .\"
26 .\" This file was generated with po4a. Translate the source file.
27 .\"
28 .\"*******************************************************************
29 .TH DL_ITERATE_PHDR 3 2007\-05\-18 GNU "Linux Programmer's Manual"
30 .SH 名前
31 dl_iterate_phdr \- 共有オブジェクトのリストを辿る
32 .SH 書式
33 .nf
34 \fB#define _GNU_SOURCE\fP         /* feature_test_macros(7) 参照 */
35 \fB#include <link.h>\fP
36
37 \fBint dl_iterate_phdr(\fP
38           \fBint (*\fPcallback\fB) (struct dl_phdr_info *\fPinfo\fB,\fP
39                            \fBsize_t\fP size\fB, void *\fPdata\fB),\fP
40           \fBvoid *\fPdata\fB);\fP
41 .fi
42 .SH 説明
43 \fBdl_iterate_phdr\fP()  関数を使うと、アプリケーションは実行時に どの共有オブジェクトをロードしたかを見つけることができる。
44
45 \fBdl_iterate_phdr\fP()  関数はアプリケーションの共有オブジェクトのリストを辿り、 各オブジェクトに対して関数 \fIcallback\fP
46 を 1 回ずつ呼び出す。 これは全ての共有オブジェクトが処理されるか、 \fIcallback\fP が 0 以外の値を返すまで行われる。
47
48 各々の \fIcallback\fP 呼び出しは 3 つの引き数を受け取る: \fIinfo\fP は共有オブジェクトの情報を保持する構造体へのポインタである。
49 \fIsize\fP は \fIinfo\fP で指される構造体のサイズである。 \fIdata\fP は呼び出し元プログラムから
50 \fBdl_iterate_phdr\fP()  の呼び出しの (同じく \fIdata\fP という名前の) 第 2 引き数として渡される値のコピーである。
51
52 \fIinfo\fP 引き数は、以下のような型の構造体である。
53
54 .in +4n
55 .nf
56 struct dl_phdr_info {
57     ElfW(Addr)        dlpi_addr;  /* オブジェクトのベースアドレス */
58     const char       *dlpi_name;  /* (null 文字で終端された)
59                                      オブジェクト名 */
60     const ElfW(Phdr) *dlpi_phdr;  /* このオブジェクトの
61                                      ELF プログラムヘッダの
62                                      配列へのポインタ */
63     ElfW(Half)        dlpi_phnum; /* \fIdlpi_phdr\fP のアイテム数 */
64 };
65 .fi
66 .in
67
68 (\fIElfW\fP()  マクロ定義は引き数をハードウェアアーキテクチャに適した ELF データ型の名前に変換する。 たとえば、32
69 ビットプラットフォームでは ElfW(Addr) はデータ型名 Elf32_Addr を生成する。 これらの型についての更に詳細な情報は、ヘッダファイル
70 \fI<elf.h>\fP と \fI<link.h>\fP にある。
71
72 \fIdlpi_addr\fP フィールドは共有オブジェクトのベースアドレス (つまり、共有オブジェクトの仮想メモリアドレスと、 ファイル
73 (このファイルから共有オブジェクトがロードされる) における 共有オブジェクトのオフセットとの差分) を表す。 \fIdlpi_name\fP は null
74 文字で終端された文字列であり、 このパス名のファイルから共有オブジェクトがロードされる。
75
76 \fIdlpi_phdr\fP と \fIdlpi_phnum\fP フィールドの意味を理解するには、 ELF
77 共有オブジェクトが幾つかのセグメントから構成されていることと、 各セグメントがそれに対応するプログラムヘッダ (そのセグメントを説明する)
78 を持っていることを知っている必要がある。 \fIdlpi_phdr\fP フィールドは、この共有オブジェクトのプログラムヘッダの配列へのポインタである。
79 \fIdlpi_phnum\fP は、この配列のサイズを表す。
80
81 これらのプログラムヘッダは以下のような形式の構造体である:
82 .in +4n
83 .nf
84
85 typedef struct
86 {
87     Elf32_Word  p_type;    /* セグメントの型 */
88     Elf32_Off   p_offset;  /* セグメントのファイルオフセット */
89     Elf32_Addr  p_vaddr;   /* セグメントの仮想アドレス */
90     Elf32_Addr  p_paddr;   /* セグメントの物理アドレス */
91     Elf32_Word  p_filesz;  /* ファイルにおけるセグメントサイズ */
92     Elf32_Word  p_memsz;   /* メモリにおけるセグメントサイズ */
93     Elf32_Word  p_flags;   /* セグメントフラグ */
94     Elf32_Word  p_align;   /* セグメントの配置 (alignment) */
95 } Elf32_Phdr;
96 .fi
97 .in
98
99 特定のプログラムヘッダ \fIx\fP の仮想メモリにおける位置は、以下の式で計算できる点に注意すること:
100
101 .nf
102   addr == info\->dlpi_addr + info\->dlpi_phdr[x].p_vaddr;
103 .fi
104 .SH 返り値
105 \fBdl_iterate_phdr\fP()  関数は最後の \fIcallback\fP の呼び出しで返された値を返す。
106 .SH バージョン
107 \fBdl_iterate_phdr\fP()  は glibc のバージョン 2.2.4 以降でサポートされている。
108 .SH 準拠
109 \fBdl_iterate_phdr\fP()  関数は Linux 固有であり、移植を考えたアプリケーションでは避けるべきである。
110 .SH 例
111 以下のプログラムは、共有オブジェクトがロードされた パス名の一覧を表示する。 各共有オブジェクトについて、このプログラムは オブジェクトの ELF
112 セグメントがロードされた 仮想アドレスの一覧を表示する。
113
114 .nf
115 #define _GNU_SOURCE
116 #include <link.h>
117 #include <stdlib.h>
118 #include <stdio.h>
119
120 static int
121 callback(struct dl_phdr_info *info, size_t size, void *data)
122 {
123     int j;
124
125     printf("name=%s (%d segments)\en", info\->dlpi_name,
126         info\->dlpi_phnum);
127
128     for (j = 0; j < info\->dlpi_phnum; j++)
129          printf("\et\et header %2d: address=%10p\en", j,
130              (void *) (info\->dlpi_addr + info\->dlpi_phdr[j].p_vaddr));
131     return 0;
132 }
133
134 int
135 main(int argc, char *argv[])
136 {
137     dl_iterate_phdr(callback, NULL);
138
139     exit(EXIT_SUCCESS);
140 }
141 .fi
142 .SH 関連項目
143 \fBldd\fP(1), \fBobjdump\fP(1), \fBreadelf\fP(1), \fBdlopen\fP(3), \fBelf\fP(5),
144 \fBld.so\fP(8), オンラインのいろいろな場所で入手できる \fIExecutable and Linking Format
145 Specification\fP