1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
.\" Copyright (c) 2003 by Michael Kerrisk <mtk-manpages@gmx.net>
.\"
.\" 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.
.\"
.\" 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 <ysato444@yahoo.co.jp>
.\"
.TH DL_ITERATE_PHDR 3 "Linux 2.4.21" "Linux Programmer's Manual"
.SH ̾
dl_iterate_phdr \- ֥ͭȤΥꥹȤé
.SH
.nf
#define _GNU_SOURCE
.B #include <link.h>
\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
.SH
.B dl_iterate_phdr
ؿȤȡץꥱϼ¹Ի
ɤζ֥ͭȤɤĤ뤳ȤǤ롣
.B dl_iterate_phdr
ؿϥץꥱζ֥ͭȤΥꥹȤéꡢ
ƥ֥ȤФƴؿ
.I callback
1 ĸƤӽФ
Ƥζ֥ͭȤ뤫
.I callback
0 ʳ֤ͤޤǹԤ롣
ơ
.I callback
ƤӽФ 3 Ĥΰ:
.I info
϶֥ͭȤξݻ빽¤ΤؤΥݥǤ롣
.I size
.I info
ǻؤ빽¤ΤΥǤ롣
.I data
ϸƤӽФץफ
.B dl_iterate_phdr
θƤӽФ (Ʊ
.I data
Ȥ̾) 2 ȤϤͤΥԡǤ롣
.I info
ϡʲΤ褦ʷι¤ΤǤ롣
.nf
struct dl_phdr_info {
ElfW(Addr) dlpi_addr; /* ֥ȤΥ١ɥ쥹 */
const char *dlpi_name; /* (null ʸǽü줿)
֥̾
const ElfW(Phdr) *dlpi_phdr; /* Υ֥Ȥ
ELF ץإå
ؤΥݥ */
ElfW(Half) dlpi_phnum; /* 'dlpi_phdr' Υƥ */
};
.fi
.RI ( ElfW()
ޥϰϡɥƥŬ
ELF ǡ̾Ѵ롣
ȤС32 ӥåȥץåȥեǤ
ElfW(Addr) ϥǡ̾ Elf32_Addr 롣
ηˤĤƤι˾ܺ٤ʾϡإåե
.IR <elf.h> " " <link.h>
ˤ롣
.I dlpi_addr
եɤ϶֥ͭȤΥ١ɥ쥹
(Ĥޤꡢ֥ͭȤβۥꥢɥ쥹ȡ
ե (Υե뤫鶦֥ͭȤɤ) ˤ
֥ͭȤΥեåȤȤκʬ) ɽ
.I dlpi_name
null ʸǽü줿ʸǤꡢ
Υѥ̾Υե뤫鶦֥ͭȤɤ롣
.I dlpi_phdr
.I dlpi_phnum
եɤΰ̣ˤϡ
ELF ֥ͭȤĤΥȤ鹽Ƥ뤳Ȥȡ
ƥȤбץإå
(ΥȤ) äƤ뤳ȤΤäƤɬפ롣
.I dlpi_phdr
եɤϡζ֥ͭȤΥץإåؤΥݥǤ롣
.I dlpi_phnum
ϡΥɽ
ΥץإåϰʲΤ褦ʷι¤ΤǤ:
.nf
typedef struct
{
Elf32_Word p_type; /* Ȥη */
Elf32_Off p_offset; /* ȤΥե륪եå */
Elf32_Addr p_vaddr; /* Ȥβۥɥ쥹 */
Elf32_Addr p_paddr; /* Ȥʪɥ쥹 */
Elf32_Word p_filesz; /* եˤ륻ȥ */
Elf32_Word p_memsz; /* ˤ륻ȥ */
Elf32_Word p_flags; /* ȥե饰 */
Elf32_Word p_align; /* Ȥ (alignment) */
} Elf32_Phdr;
.fi
Υץإå
.I x
βۥˤ֤ϡʲμǷǤդ뤳:
.nf
addr == info->dlpi_addr + info->dlpi_phdr[x].p_vaddr;
.fi
.SH ץ
ʲΥץϡ֥ͭȤɤ줿
ѥ̾ΰɽ롣
ƶ֥ͭȤˤĤơΥץ
֥Ȥ ELF Ȥɤ줿
ۥɥ쥹ΰɽ롣
.nf
#define _GNU_SOURCE
#include <link.h>
#include <stdlib.h>
#include <stdio.h>
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
.SH ֤
.B dl_iterate_phdr
ؿϺǸ
.I callback
θƤӽФ֤줿֤ͤ
.SH
.B dl_iterate_phdr
ؿ Linux ͭǤꡢܿͤץꥱǤ٤Ǥ롣
.SH Ϣ
.BR ldd (1),
.BR objdump (1),
.BR readelf (1),
.BR dlopen (3),
.BR ld.so (8),
饤ΤʾǤ
.I "Executable and Linking Format Specification"
|