1/*- 2 * Copyright (c) 2006 Joseph Koshy 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> 28__FBSDID("$FreeBSD: releng/10.2/lib/libelf/libelf_msize.m4 210332 2010-07-21 09:56:42Z kaiw $"); 29 30#include <sys/types.h> 31#include <sys/elf32.h> 32#include <sys/elf64.h> 33 34#include <assert.h> 35#include <libelf.h> 36#include <osreldate.h> 37#include <string.h> 38 39#include "_libelf.h" 40 41/* WARNING: GENERATED FROM __file__. */ 42 43struct msize { 44 size_t msz32; 45 size_t msz64; 46}; 47 48divert(-1) 49include(SRCDIR`/elf_types.m4') 50 51define(BYTE_SIZE, 1) 52define(GNUHASH_SIZE, 1) 53define(NOTE_SIZE, 1) 54 55/* 56 * Unimplemented types. 57 */ 58define(MOVEP_SIZE, 0) 59define(SXWORD_SIZE32, 0) 60define(XWORD_SIZE32, 0) 61 62define(`DEFINE_ELF_MSIZE', 63 `ifdef($1`_SIZE', 64 `define($1_SIZE32,$1_SIZE) 65 define($1_SIZE64,$1_SIZE)', 66 `ifdef($1`_SIZE32',`', 67 `define($1_SIZE32,sizeof(Elf32_$2))') 68 ifdef($1`_SIZE64',`', 69 `define($1_SIZE64,sizeof(Elf64_$2))')')') 70define(`DEFINE_ELF_MSIZES', 71 `ifelse($#,1,`', 72 `DEFINE_ELF_MSIZE($1) 73 DEFINE_ELF_MSIZES(shift($@))')') 74 75DEFINE_ELF_MSIZES(ELF_TYPE_LIST) 76 77define(`MSIZE', 78 `#if __FreeBSD_version >= $3 79 [ELF_T_$1] = { .msz32 = $1_SIZE32, .msz64 = $1_SIZE64 }, 80#endif') 81define(`MSIZES', 82 `ifelse($#,1,`', 83 `MSIZE($1) 84MSIZES(shift($@))')') 85 86divert(0) 87 88static struct msize msize[ELF_T_NUM] = { 89MSIZES(ELF_TYPE_LIST) 90}; 91 92size_t 93_libelf_msize(Elf_Type t, int elfclass, unsigned int version) 94{ 95 size_t sz; 96 97 assert(elfclass == ELFCLASS32 || elfclass == ELFCLASS64); 98 assert((signed) t >= ELF_T_FIRST && t <= ELF_T_LAST); 99 100 if (version != EV_CURRENT) { 101 LIBELF_SET_ERROR(VERSION, 0); 102 return (0); 103 } 104 105 sz = (elfclass == ELFCLASS32) ? msize[t].msz32 : msize[t].msz64; 106 107 return (sz); 108} 109