libelf_msize.m4 revision 210332
138494Sobrien/*- 2310490Scy * Copyright (c) 2006 Joseph Koshy 338494Sobrien * All rights reserved. 438494Sobrien * 538494Sobrien * Redistribution and use in source and binary forms, with or without 638494Sobrien * modification, are permitted provided that the following conditions 738494Sobrien * are met: 838494Sobrien * 1. Redistributions of source code must retain the above copyright 938494Sobrien * notice, this list of conditions and the following disclaimer. 1038494Sobrien * 2. Redistributions in binary form must reproduce the above copyright 1138494Sobrien * notice, this list of conditions and the following disclaimer in the 1238494Sobrien * documentation and/or other materials provided with the distribution. 1338494Sobrien * 1438494Sobrien * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1538494Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1638494Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1738494Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1838494Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19310490Scy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2038494Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2138494Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2238494Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2338494Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2438494Sobrien * SUCH DAMAGE. 2538494Sobrien */ 2638494Sobrien 2738494Sobrien#include <sys/cdefs.h> 2838494Sobrien__FBSDID("$FreeBSD: head/lib/libelf/libelf_msize.m4 210332 2010-07-21 09:56:42Z kaiw $"); 2938494Sobrien 3038494Sobrien#include <sys/types.h> 3138494Sobrien#include <sys/elf32.h> 3238494Sobrien#include <sys/elf64.h> 3338494Sobrien 3438494Sobrien#include <assert.h> 3538494Sobrien#include <libelf.h> 36174313Sobrien#include <osreldate.h> 3738494Sobrien#include <string.h> 3838494Sobrien 3938494Sobrien#include "_libelf.h" 4038494Sobrien 4138494Sobrien/* WARNING: GENERATED FROM __file__. */ 4238494Sobrien 4338494Sobrienstruct msize { 4438494Sobrien size_t msz32; 4538494Sobrien size_t msz64; 4638494Sobrien}; 4742633Sobrien 4842633Sobriendivert(-1) 4942633Sobrieninclude(SRCDIR`/elf_types.m4') 5038494Sobrien 5138494Sobriendefine(BYTE_SIZE, 1) 5238494Sobriendefine(GNUHASH_SIZE, 1) 5338494Sobriendefine(NOTE_SIZE, 1) 5438494Sobrien 5538494Sobrien/* 5638494Sobrien * Unimplemented types. 5738494Sobrien */ 58310490Scydefine(MOVEP_SIZE, 0) 5938494Sobriendefine(SXWORD_SIZE32, 0) 6042633Sobriendefine(XWORD_SIZE32, 0) 6138494Sobrien 6241145Sobriendefine(`DEFINE_ELF_MSIZE', 6338494Sobrien `ifdef($1`_SIZE', 6438494Sobrien `define($1_SIZE32,$1_SIZE) 6538494Sobrien define($1_SIZE64,$1_SIZE)', 6638500Sobrien `ifdef($1`_SIZE32',`', 6738494Sobrien `define($1_SIZE32,sizeof(Elf32_$2))') 6838494Sobrien ifdef($1`_SIZE64',`', 6938494Sobrien `define($1_SIZE64,sizeof(Elf64_$2))')')') 7038494Sobriendefine(`DEFINE_ELF_MSIZES', 7138494Sobrien `ifelse($#,1,`', 7238494Sobrien `DEFINE_ELF_MSIZE($1) 7338494Sobrien DEFINE_ELF_MSIZES(shift($@))')') 7438494Sobrien 7538494SobrienDEFINE_ELF_MSIZES(ELF_TYPE_LIST) 7638494Sobrien 77174313Sobriendefine(`MSIZE', 7838494Sobrien `#if __FreeBSD_version >= $3 7938494Sobrien [ELF_T_$1] = { .msz32 = $1_SIZE32, .msz64 = $1_SIZE64 }, 8038494Sobrien#endif') 8138494Sobriendefine(`MSIZES', 8238494Sobrien `ifelse($#,1,`', 8338494Sobrien `MSIZE($1) 8438494SobrienMSIZES(shift($@))')') 8538494Sobrien 8638494Sobriendivert(0) 8738494Sobrien 8838494Sobrienstatic struct msize msize[ELF_T_NUM] = { 8938494SobrienMSIZES(ELF_TYPE_LIST) 9038494Sobrien}; 9138494Sobrien 9238494Sobriensize_t 9338494Sobrien_libelf_msize(Elf_Type t, int elfclass, unsigned int version) 9438494Sobrien{ 9538494Sobrien size_t sz; 96174313Sobrien 9738494Sobrien assert(elfclass == ELFCLASS32 || elfclass == ELFCLASS64); 9838494Sobrien assert((signed) t >= ELF_T_FIRST && t <= ELF_T_LAST); 9938494Sobrien 10038494Sobrien if (version != EV_CURRENT) { 10138494Sobrien LIBELF_SET_ERROR(VERSION, 0); 10238494Sobrien return (0); 10338494Sobrien } 10438494Sobrien 105310490Scy sz = (elfclass == ELFCLASS32) ? msize[t].msz32 : msize[t].msz64; 10638494Sobrien 10738494Sobrien return (sz); 10838494Sobrien} 10938494Sobrien