.\" Copyright (c) 2003 by Michael Kerrisk .\" .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" License. .\" .\" Japanese Version Copyright (c) 2005 Yuichi SATO .\" all rights reserved. .\" Translated Thu Jan 27 07:03:56 JST 2005 .\" by Yuichi SATO .\" .TH DL_ITERATE_PHDR 3 2007-05-18 "Linux" "Linux Programmer's Manual" .\"O .SH NAME .SH 名前 .\"O dl_iterate_phdr \- walk through list of shared objects dl_iterate_phdr \- 共有オブジェクトのリストを辿る .\"O .SH SYNOPSIS .SH 書式 .nf .\"O .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */" .BR "#define _GNU_SOURCE" " /* feature_test_macros(7) 参照 */" .B #include \fBint dl_iterate_phdr(\fP \fBint (*\fPcallback\fB) \ (struct dl_phdr_info *\fPinfo\fB,\fP \fBsize_t\fP size\fB, void *\fPdata\fB),\fP \fBvoid *\fPdata\fB);\fP .fi .\"O .SH DESCRIPTION .SH 説明 .\"O The .\"O .BR dl_iterate_phdr () .\"O function allows an application to inquire at run time to find .\"O out which shared objects it has loaded. .BR dl_iterate_phdr () 関数を使うと、アプリケーションは実行時に どの共有オブジェクトをロードしたかを見つけることができる。 .\"O The .\"O .BR dl_iterate_phdr () .\"O function walks through the list of an .\"O application's shared objects and calls the function .\"O .I callback .\"O once for each object, .\"O until either all shared objects have been processed or .\"O .I callback .\"O returns a nonzero value. .BR dl_iterate_phdr () 関数はアプリケーションの共有オブジェクトのリストを辿り、 各オブジェクトに対して関数 .I callback を 1 回ずつ呼び出す。 これは全ての共有オブジェクトが処理されるか、 .I callback が 0 以外の値を返すまで行われる。 .\"O Each call to .\"O .I callback .\"O receives three arguments: 各々の .I callback 呼び出しは 3 つの引き数を受け取る: .\"O .IR info , .\"O which is a pointer to a structure containing information .\"O about the shared object; .I info は共有オブジェクトの情報を保持する構造体へのポインタである。 .\"O .IR size , .\"O which is the size of the structure pointed to by .\"O .IR info ; .I size は .I info で指される構造体のサイズである。 .\"O and .\"O .IR data , .\"O which is a copy of whatever value was passed by the calling .\"O program as the second argument (also named .\"O .IR data ) .\"O in the call to .\"O .BR dl_iterate_phdr (). .I data は呼び出し元プログラムから .BR dl_iterate_phdr () の呼び出しの (同じく .I data という名前の) 第 2 引き数として渡される値のコピーである。 .\"O The .\"O .I info .\"O argument is a structure of the following type: .I info 引き数は、以下のような型の構造体である。 .in +4n .nf struct dl_phdr_info { .\"O ElfW(Addr) dlpi_addr; /* Base address of object */ ElfW(Addr) dlpi_addr; /* オブジェクトのベースアドレス */ .\"O const char *dlpi_name; /* (Null-terminated) name of .\"O object */ const char *dlpi_name; /* (null 文字で終端された) オブジェクト名 */ .\"O const ElfW(Phdr) *dlpi_phdr; /* Pointer to array of .\"O ELF program headers .\"O for this object */ const ElfW(Phdr) *dlpi_phdr; /* このオブジェクトの ELF プログラムヘッダの 配列へのポインタ */ .\"O ElfW(Half) dlpi_phnum; /* # of items in \fIdlpi_phdr\fP */ ElfW(Half) dlpi_phnum; /* \fIdlpi_phdr\fP のアイテム数 */ }; .fi .in .\"O (The .\"O .IR ElfW () .\"O macro definition turns its argument into the name of an ELF data .\"O type suitable for the hardware architecture. .RI ( ElfW () マクロ定義は引き数をハードウェアアーキテクチャに適した ELF データ型の名前に変換する。 .\"O For example, on a 32-bit platform, .\"O ElfW(Addr) yields the data type name Elf32_Addr. たとえば、32 ビットプラットフォームでは ElfW(Addr) はデータ型名 Elf32_Addr を生成する。 .\"O Further information on these types can be found in the .\"O .IR " and " .\"O header files.) これらの型についての更に詳細な情報は、ヘッダファイル .IR " と " にある。 .\"O The .\"O .I dlpi_addr .\"O field indicates the base address of the shared object .\"O (i.e., the difference between the virtual memory address of .\"O the shared object and the offset of that object in the file .\"O from which it was loaded). .I dlpi_addr フィールドは共有オブジェクトのベースアドレス (つまり、共有オブジェクトの仮想メモリアドレスと、 ファイル (このファイルから共有オブジェクトがロードされる) における 共有オブジェクトのオフセットとの差分) を表す。 .\"O The .\"O .I dlpi_name .\"O field is a null-terminated string giving the pathname .\"O from which the shared object was loaded. .I dlpi_name は null 文字で終端された文字列であり、 このパス名のファイルから共有オブジェクトがロードされる。 .\"O To understand the meaning of the .\"O .I dlpi_phdr .\"O and .\"O .I dlpi_phnum .\"O fields, we need to be aware that an ELF shared object consists .\"O of a number of segments, each of which has a corresponding .\"O program header describing the segment. .I dlpi_phdr と .I dlpi_phnum フィールドの意味を理解するには、 ELF 共有オブジェクトが幾つかのセグメントから構成されていることと、 各セグメントがそれに対応するプログラムヘッダ (そのセグメントを説明する) を持っていることを知っている必要がある。 .\"O The .\"O .I dlpi_phdr .\"O field is a pointer to an array of the program headers for this .\"O shared object. .I dlpi_phdr フィールドは、この共有オブジェクトのプログラムヘッダの配列へのポインタである。 .\"O The .\"O .I dlpi_phnum .\"O field indicates the size of this array. .I dlpi_phnum は、この配列のサイズを表す。 .\"O These program headers are structures of the following form: これらのプログラムヘッダは以下のような形式の構造体である: .in +4n .nf typedef struct { .\"O Elf32_Word p_type; /* Segment type */ Elf32_Word p_type; /* セグメントの型 */ .\"O Elf32_Off p_offset; /* Segment file offset */ Elf32_Off p_offset; /* セグメントのファイルオフセット */ .\"O Elf32_Addr p_vaddr; /* Segment virtual address */ Elf32_Addr p_vaddr; /* セグメントの仮想アドレス */ .\"O Elf32_Addr p_paddr; /* Segment physical address */ Elf32_Addr p_paddr; /* セグメントの物理アドレス */ .\"O Elf32_Word p_filesz; /* Segment size in file */ Elf32_Word p_filesz; /* ファイルにおけるセグメントサイズ */ .\"O Elf32_Word p_memsz; /* Segment size in memory */ Elf32_Word p_memsz; /* メモリにおけるセグメントサイズ */ .\"O Elf32_Word p_flags; /* Segment flags */ Elf32_Word p_flags; /* セグメントフラグ */ .\"O Elf32_Word p_align; /* Segment alignment */ Elf32_Word p_align; /* セグメントの配置 (alignment) */ } Elf32_Phdr; .fi .in .\"O Note that we can calculate the location of a particular program header, .\"O .IR x , .\"O in virtual memory using the formula: 特定のプログラムヘッダ .I x の仮想メモリにおける位置は、以下の式で計算できる点に注意すること: .nf addr == info\->dlpi_addr + info\->dlpi_phdr[x].p_vaddr; .fi .\"O .SH RETURN VALUE .SH 返り値 .\"O The .\"O .BR dl_iterate_phdr () .\"O function returns whatever value was returned by the last call to .\"O .IR callback . .BR dl_iterate_phdr () 関数は最後の .I callback の呼び出しで返された値を返す。 .\"O .SH VERSIONS .SH バージョン .\"O .BR dl_iterate_phdr () .\"O has been supported in glibc since version 2.2.4. .BR dl_iterate_phdr () は glibc のバージョン 2.2.4 以降でサポートされている。 .\"O .SH "CONFORMING TO" .SH 準拠 .\"O The .\"O .BR dl_iterate_phdr () .\"O function is Linux-specific and should be avoided in portable applications. .BR dl_iterate_phdr () 関数は Linux 固有であり、移植を考えたアプリケーションでは避けるべきである。 .\"O .SH EXAMPLE .SH 例 .\"O The following program displays a list of pathnames of the .\"O shared objects it has loaded. 以下のプログラムは、共有オブジェクトがロードされた パス名の一覧を表示する。 .\"O For each shared object, the program lists the virtual addresses .\"O at which the object's ELF segments are loaded. 各共有オブジェクトについて、このプログラムは オブジェクトの ELF セグメントがロードされた 仮想アドレスの一覧を表示する。 .nf #define _GNU_SOURCE #include #include #include static int callback(struct dl_phdr_info *info, size_t size, void *data) { int j; printf("name=%s (%d segments)\\n", info\->dlpi_name, info\->dlpi_phnum); for (j = 0; j < info\->dlpi_phnum; j++) printf("\\t\\t header %2d: address=%10p\\n", j, (void *) (info\->dlpi_addr + info\->dlpi_phdr[j].p_vaddr)); return 0; } int main(int argc, char *argv[]) { dl_iterate_phdr(callback, NULL); exit(EXIT_SUCCESS); } .fi .\"O .SH "SEE ALSO" .SH 関連項目 .BR ldd (1), .BR objdump (1), .BR readelf (1), .BR dlopen (3), .BR elf (5), .BR ld.so (8), .\"O and the .\"O .I "Executable and Linking Format Specification" .\"O available at various locations online. オンラインのいろいろな場所で入手できる .I "Executable and Linking Format Specification"