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 ()
46 どの共有オブジェクトをロードしたかを見つけることができる。
48 .BR dl_iterate_phdr ()
49 関数はアプリケーションの共有オブジェクトのリストを辿り、
53 これは全ての共有オブジェクトが処理されるか、
61 は共有オブジェクトの情報を保持する構造体へのポインタである。
68 .BR dl_iterate_phdr ()
71 という名前の) 第 2 引き数として渡される値のコピーである。
79 ElfW(Addr) dlpi_addr; /* オブジェクトのベースアドレス */
80 const char *dlpi_name; /* (null 文字で終端された)
82 const ElfW(Phdr) *dlpi_phdr; /* このオブジェクトの
85 ElfW(Half) dlpi_phnum; /* \fIdlpi_phdr\fP のアイテム数 */
91 マクロ定義は引き数をハードウェアアーキテクチャに適した
94 ElfW(Addr) はデータ型名 Elf32_Addr を生成する。
95 これらの型についての更に詳細な情報は、ヘッダファイル
96 .IR <elf.h> " と " <link.h>
100 フィールドは共有オブジェクトのベースアドレス
101 (つまり、共有オブジェクトの仮想メモリアドレスと、
102 ファイル (このファイルから共有オブジェクトがロードされる) における
103 共有オブジェクトのオフセットとの差分) を表す。
105 は null 文字で終端された文字列であり、
106 このパス名のファイルから共有オブジェクトがロードされる。
112 ELF 共有オブジェクトが幾つかのセグメントから構成されていることと、
113 各セグメントがそれに対応するプログラムヘッダ
114 (そのセグメントを説明する) を持っていることを知っている必要がある。
116 フィールドは、この共有オブジェクトのプログラムヘッダの配列へのポインタである。
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) */
140 の仮想メモリにおける位置は、以下の式で計算できる点に注意すること:
143 addr == info\->dlpi_addr + info\->dlpi_phdr[x].p_vaddr;
146 .BR dl_iterate_phdr ()
151 .BR dl_iterate_phdr ()
152 は glibc のバージョン 2.2.4 以降でサポートされている。
154 .BR dl_iterate_phdr ()
155 関数は Linux 固有であり、移植を考えたアプリケーションでは避けるべきである。
157 以下のプログラムは、共有オブジェクトがロードされた
159 各共有オブジェクトについて、このプログラムは
160 オブジェクトの ELF セグメントがロードされた
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);
199 .I "Executable and Linking Format Specification"