1 .\" Copyright (c) 2003 by Michael Kerrisk <mtk.manpages@gmail.com>
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.
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
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
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .\"*******************************************************************
27 .\" This file was generated with po4a. Translate the source file.
29 .\"*******************************************************************
30 .TH DL_ITERATE_PHDR 3 2007\-05\-18 GNU "Linux Programmer's Manual"
32 dl_iterate_phdr \- 共有オブジェクトのリストを辿る
35 \fB#define _GNU_SOURCE\fP /* feature_test_macros(7) 参照 */
36 \fB#include <link.h>\fP
38 \fBint dl_iterate_phdr(\fP
39 \fB int (*\fP\fIcallback\fP\fB) (struct dl_phdr_info *\fP\fIinfo\fP\fB,\fP
40 \fB size_t \fP\fIsize\fP\fB, void *\fP\fIdata\fP\fB,\fP
41 \fB void *\fP\fIdata\fP\fB;\fP
44 \fBdl_iterate_phdr\fP() 関数を使うと、アプリケーションは実行時に どの共有オブジェクトをロードしたかを見つけることができる。
46 \fBdl_iterate_phdr\fP() 関数はアプリケーションの共有オブジェクトのリストを辿り、 各オブジェクトに対して関数 \fIcallback\fP
47 を 1 回ずつ呼び出す。 これは全ての共有オブジェクトが処理されるか、 \fIcallback\fP が 0 以外の値を返すまで行われる。
49 各々の \fIcallback\fP 呼び出しは 3 つの引き数を受け取る: \fIinfo\fP は共有オブジェクトの情報を保持する構造体へのポインタである。
50 \fIsize\fP は \fIinfo\fP で指される構造体のサイズである。 \fIdata\fP は呼び出し元プログラムから
51 \fBdl_iterate_phdr\fP() の呼び出しの (同じく \fIdata\fP という名前の) 第 2 引き数として渡される値のコピーである。
53 \fIinfo\fP 引き数は、以下のような型の構造体である。
58 ElfW(Addr) dlpi_addr; /* オブジェクトのベースアドレス */
59 const char *dlpi_name; /* (null 文字で終端された)
61 const ElfW(Phdr) *dlpi_phdr; /* このオブジェクトの
64 ElfW(Half) dlpi_phnum; /* \fIdlpi_phdr\fP のアイテム数 */
69 (\fIElfW\fP() マクロ定義は引き数をハードウェアアーキテクチャに適した ELF データ型の名前に変換する。 たとえば、32
70 ビットプラットフォームでは ElfW(Addr) はデータ型名 Elf32_Addr を生成する。 これらの型についての更に詳細な情報は、ヘッダファイル
71 \fI<elf.h>\fP と \fI<link.h>\fP にある。
73 \fIdlpi_addr\fP フィールドは共有オブジェクトのベースアドレス (つまり、共有オブジェクトの仮想メモリアドレスと、 ファイル
74 (このファイルから共有オブジェクトがロードされる) における 共有オブジェクトのオフセットとの差分) を表す。 \fIdlpi_name\fP は null
75 文字で終端された文字列であり、 このパス名のファイルから共有オブジェクトがロードされる。
77 \fIdlpi_phdr\fP と \fIdlpi_phnum\fP フィールドの意味を理解するには、 ELF
78 共有オブジェクトが幾つかのセグメントから構成されていることと、 各セグメントがそれに対応するプログラムヘッダ (そのセグメントを説明する)
79 を持っていることを知っている必要がある。 \fIdlpi_phdr\fP フィールドは、この共有オブジェクトのプログラムヘッダの配列へのポインタである。
80 \fIdlpi_phnum\fP は、この配列のサイズを表す。
82 これらのプログラムヘッダは以下のような形式の構造体である:
88 Elf32_Word p_type; /* セグメントの型 */
89 Elf32_Off p_offset; /* セグメントのファイルオフセット */
90 Elf32_Addr p_vaddr; /* セグメントの仮想アドレス */
91 Elf32_Addr p_paddr; /* セグメントの物理アドレス */
92 Elf32_Word p_filesz; /* ファイルにおけるセグメントサイズ */
93 Elf32_Word p_memsz; /* メモリにおけるセグメントサイズ */
94 Elf32_Word p_flags; /* セグメントフラグ */
95 Elf32_Word p_align; /* セグメントの配置 (alignment) */
100 特定のプログラムヘッダ \fIx\fP の仮想メモリにおける位置は、以下の式で計算できる点に注意すること:
103 addr == info\->dlpi_addr + info\->dlpi_phdr[x].p_vaddr;
106 \fBdl_iterate_phdr\fP() 関数は最後の \fIcallback\fP の呼び出しで返された値を返す。
108 \fBdl_iterate_phdr\fP() は glibc のバージョン 2.2.4 以降でサポートされている。
110 \fBdl_iterate_phdr\fP() 関数は Linux 固有であり、移植を考えたアプリケーションでは避けるべきである。
112 以下のプログラムは、共有オブジェクトがロードされた パス名の一覧を表示する。 各共有オブジェクトについて、このプログラムは オブジェクトの ELF
113 セグメントがロードされた 仮想アドレスの一覧を表示する。
122 callback(struct dl_phdr_info *info, size_t size, void *data)
126 printf("name=%s (%d segments)\en", info\->dlpi_name,
129 for (j = 0; j < info\->dlpi_phnum; j++)
130 printf("\et\et header %2d: address=%10p\en", j,
131 (void *) (info\->dlpi_addr + info\->dlpi_phdr[j].p_vaddr));
136 main(int argc, char *argv[])
138 dl_iterate_phdr(callback, NULL);
144 \fBldd\fP(1), \fBobjdump\fP(1), \fBreadelf\fP(1), \fBdlopen\fP(3), \fBelf\fP(5),
147 オンラインのいろいろな場所で入手できる \fIExecutable and Linking Format Specification\fP
149 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.52 の一部
150 である。プロジェクトの説明とバグ報告に関する情報は
151 http://www.kernel.org/doc/man\-pages/ に書かれている。