2 32.fsize.c - implementation of the elf{32,64}_fsize(3) functions.
3 Copyright (C) 1995 - 2001 Michael Riepe
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <ext_types.h>
24 static const char rcsid[] = "@(#) $Id: 32.fsize.c,v 1.13 2008/05/23 08:15:33 michael Exp $";
28 _elf_fmsize[2][EV_CURRENT - EV_NONE][ELF_T_NUM][2] = {
33 { sizeof(unsigned char), sizeof(unsigned char) },
34 { sizeof(Elf32_Addr), sizeof(__ext_Elf32_Addr) },
35 { sizeof(Elf32_Dyn), sizeof(__ext_Elf32_Dyn) },
36 { sizeof(Elf32_Ehdr), sizeof(__ext_Elf32_Ehdr) },
37 { sizeof(Elf32_Half), sizeof(__ext_Elf32_Half) },
38 { sizeof(Elf32_Off), sizeof(__ext_Elf32_Off) },
39 { sizeof(Elf32_Phdr), sizeof(__ext_Elf32_Phdr) },
40 { sizeof(Elf32_Rela), sizeof(__ext_Elf32_Rela) },
41 { sizeof(Elf32_Rel), sizeof(__ext_Elf32_Rel) },
42 { sizeof(Elf32_Shdr), sizeof(__ext_Elf32_Shdr) },
43 { sizeof(Elf32_Sword), sizeof(__ext_Elf32_Sword) },
44 { sizeof(Elf32_Sym), sizeof(__ext_Elf32_Sym) },
45 { sizeof(Elf32_Word), sizeof(__ext_Elf32_Word) },
46 { 0, 0 }, /* there is no Elf32_Sxword */
47 { 0, 0 }, /* there is no Elf32_Xword */
48 /* XXX: check Solaris values */
49 { 0, 0 }, /* Elf32_Verdef/Verdaux size varies */
50 { 0, 0 }, /* Elf32_Verneed/Vernaux size varies */
58 { sizeof(unsigned char), sizeof(unsigned char) },
59 { sizeof(Elf64_Addr), sizeof(__ext_Elf64_Addr) },
60 { sizeof(Elf64_Dyn), sizeof(__ext_Elf64_Dyn) },
61 { sizeof(Elf64_Ehdr), sizeof(__ext_Elf64_Ehdr) },
62 { sizeof(Elf64_Half), sizeof(__ext_Elf64_Half) },
63 { sizeof(Elf64_Off), sizeof(__ext_Elf64_Off) },
64 { sizeof(Elf64_Phdr), sizeof(__ext_Elf64_Phdr) },
65 { sizeof(Elf64_Rela), sizeof(__ext_Elf64_Rela) },
66 { sizeof(Elf64_Rel), sizeof(__ext_Elf64_Rel) },
67 { sizeof(Elf64_Shdr), sizeof(__ext_Elf64_Shdr) },
68 { sizeof(Elf64_Sword), sizeof(__ext_Elf64_Sword) },
69 { sizeof(Elf64_Sym), sizeof(__ext_Elf64_Sym) },
70 { sizeof(Elf64_Word), sizeof(__ext_Elf64_Word) },
71 { sizeof(Elf64_Sxword), sizeof(__ext_Elf64_Sxword) },
72 { sizeof(Elf64_Xword), sizeof(__ext_Elf64_Xword) },
73 /* XXX: check Solaris values */
74 { 0, 0 }, /* Elf64_Verdef/Verdaux size varies */
75 { 0, 0 }, /* Elf64_Verneed/Vernaux size varies */
78 #endif /* __LIBELF64 */
82 _elf_fsize(unsigned cls, Elf_Type type, unsigned ver) {
85 if (!valid_version(ver)) {
86 seterr(ERROR_UNKNOWN_VERSION);
88 else if (!valid_type(type)) {
89 seterr(ERROR_UNKNOWN_TYPE);
91 else if (!(n = _fsize(cls, ver, type))) {
92 seterr(ERROR_UNKNOWN_TYPE);
98 elf32_fsize(Elf_Type type, size_t count, unsigned ver) {
99 return count * _elf_fsize(ELFCLASS32, type, ver);
105 elf64_fsize(Elf_Type type, size_t count, unsigned ver) {
106 return count * _elf_fsize(ELFCLASS64, type, ver);
110 gelf_fsize(Elf *elf, Elf_Type type, size_t count, unsigned ver) {
112 if (elf->e_kind != ELF_K_ELF) {
113 seterr(ERROR_NOTELF);
115 else if (valid_class(elf->e_class)) {
116 return count * _elf_fsize(elf->e_class, type, ver);
119 seterr(ERROR_UNKNOWN_CLASS);
126 * Extension: report memory size
129 gelf_msize(Elf *elf, Elf_Type type, size_t count, unsigned ver) {
133 if (elf->e_kind != ELF_K_ELF) {
134 seterr(ERROR_NOTELF);
136 else if (!valid_class(elf->e_class)) {
137 seterr(ERROR_UNKNOWN_CLASS);
139 else if (!valid_version(ver)) {
140 seterr(ERROR_UNKNOWN_VERSION);
142 else if (!valid_type(type)) {
143 seterr(ERROR_UNKNOWN_TYPE);
145 else if (!(n = _msize(elf->e_class, ver, type))) {
146 seterr(ERROR_UNKNOWN_TYPE);
155 #endif /* __LIBELF64 */