00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <private.h>
00025 #include <ext_types.h>
00026
00027 #ifndef lint
00028 static const char rcsid[] = "@(#) $Id: 32.fsize.c,v 1.1.1.1 2005/10/21 19:00:00 marcel Exp $";
00029 #endif
00030
00031 const size_t
00032 _elf_fmsize[2][EV_CURRENT - EV_NONE][ELF_T_NUM][2] = {
00033
00034 {
00035
00036 {
00037 { sizeof(unsigned char), sizeof(unsigned char) },
00038 { sizeof(Elf32_Addr), sizeof(__ext_Elf32_Addr) },
00039 { sizeof(Elf32_Dyn), sizeof(__ext_Elf32_Dyn) },
00040 { sizeof(Elf32_Ehdr), sizeof(__ext_Elf32_Ehdr) },
00041 { sizeof(Elf32_Half), sizeof(__ext_Elf32_Half) },
00042 { sizeof(Elf32_Off), sizeof(__ext_Elf32_Off) },
00043 { sizeof(Elf32_Phdr), sizeof(__ext_Elf32_Phdr) },
00044 { sizeof(Elf32_Rela), sizeof(__ext_Elf32_Rela) },
00045 { sizeof(Elf32_Rel), sizeof(__ext_Elf32_Rel) },
00046 { sizeof(Elf32_Shdr), sizeof(__ext_Elf32_Shdr) },
00047 { sizeof(Elf32_Sword), sizeof(__ext_Elf32_Sword) },
00048 { sizeof(Elf32_Sym), sizeof(__ext_Elf32_Sym) },
00049 { sizeof(Elf32_Word), sizeof(__ext_Elf32_Word) },
00050 { 0, 0 },
00051 { 0, 0 },
00052
00053 { 0, 0 },
00054 { 0, 0 },
00055 },
00056 },
00057 #if __LIBELF64
00058
00059 {
00060
00061 {
00062 { sizeof(unsigned char), sizeof(unsigned char) },
00063 { sizeof(Elf64_Addr), sizeof(__ext_Elf64_Addr) },
00064 { sizeof(Elf64_Dyn), sizeof(__ext_Elf64_Dyn) },
00065 { sizeof(Elf64_Ehdr), sizeof(__ext_Elf64_Ehdr) },
00066 { sizeof(Elf64_Half), sizeof(__ext_Elf64_Half) },
00067 { sizeof(Elf64_Off), sizeof(__ext_Elf64_Off) },
00068 { sizeof(Elf64_Phdr), sizeof(__ext_Elf64_Phdr) },
00069 { sizeof(Elf64_Rela), sizeof(__ext_Elf64_Rela) },
00070 { sizeof(Elf64_Rel), sizeof(__ext_Elf64_Rel) },
00071 { sizeof(Elf64_Shdr), sizeof(__ext_Elf64_Shdr) },
00072 { sizeof(Elf64_Sword), sizeof(__ext_Elf64_Sword) },
00073 { sizeof(Elf64_Sym), sizeof(__ext_Elf64_Sym) },
00074 { sizeof(Elf64_Word), sizeof(__ext_Elf64_Word) },
00075 { sizeof(Elf64_Sxword), sizeof(__ext_Elf64_Sxword) },
00076 { sizeof(Elf64_Xword), sizeof(__ext_Elf64_Xword) },
00077
00078 { 0, 0 },
00079 { 0, 0 },
00080 },
00081 },
00082 #endif
00083 };
00084
00085 static size_t
00086 _elf_fsize(unsigned cls, Elf_Type type, unsigned ver) {
00087 size_t n = 0;
00088
00089 if (!valid_version(ver)) {
00090 seterr(ERROR_UNKNOWN_VERSION);
00091 }
00092 else if (!valid_type(type)) {
00093 seterr(ERROR_UNKNOWN_TYPE);
00094 }
00095 else if (!(n = _fsize(cls, ver, type))) {
00096 seterr(ERROR_UNKNOWN_TYPE);
00097 }
00098 return n;
00099 }
00100
00101 size_t
00102 elf32_fsize(Elf_Type type, size_t count, unsigned ver) {
00103 return count * _elf_fsize(ELFCLASS32, type, ver);
00104 }
00105
00106 #if __LIBELF64
00107
00108 size_t
00109 elf64_fsize(Elf_Type type, size_t count, unsigned ver) {
00110 return count * _elf_fsize(ELFCLASS64, type, ver);
00111 }
00112
00113 size_t
00114 gelf_fsize(Elf *elf, Elf_Type type, size_t count, unsigned ver) {
00115 if (elf) {
00116 if (elf->e_kind != ELF_K_ELF) {
00117 seterr(ERROR_NOTELF);
00118 }
00119 else if (valid_class(elf->e_class)) {
00120 return count * _elf_fsize(elf->e_class, type, ver);
00121 }
00122 else {
00123 seterr(ERROR_UNKNOWN_CLASS);
00124 }
00125 }
00126 return 0;
00127 }
00128
00129
00130
00131
00132 size_t
00133 gelf_msize(Elf *elf, Elf_Type type, size_t count, unsigned ver) {
00134 size_t n;
00135
00136 if (elf) {
00137 if (elf->e_kind != ELF_K_ELF) {
00138 seterr(ERROR_NOTELF);
00139 }
00140 else if (!valid_class(elf->e_class)) {
00141 seterr(ERROR_UNKNOWN_CLASS);
00142 }
00143 else if (!valid_version(ver)) {
00144 seterr(ERROR_UNKNOWN_VERSION);
00145 }
00146 else if (!valid_type(type)) {
00147 seterr(ERROR_UNKNOWN_TYPE);
00148 }
00149 else if (!(n = _msize(elf->e_class, ver, type))) {
00150 seterr(ERROR_UNKNOWN_TYPE);
00151 }
00152 else {
00153 return count * n;
00154 }
00155 }
00156 return 0;
00157 }
00158
00159 #endif