libelf_msize.m4 revision 165317
1164190Sjkoshy/*-
2164190Sjkoshy * Copyright (c) 2006 Joseph Koshy
3164190Sjkoshy * All rights reserved.
4164190Sjkoshy *
5164190Sjkoshy * Redistribution and use in source and binary forms, with or without
6164190Sjkoshy * modification, are permitted provided that the following conditions
7164190Sjkoshy * are met:
8164190Sjkoshy * 1. Redistributions of source code must retain the above copyright
9164190Sjkoshy *    notice, this list of conditions and the following disclaimer.
10164190Sjkoshy * 2. Redistributions in binary form must reproduce the above copyright
11164190Sjkoshy *    notice, this list of conditions and the following disclaimer in the
12164190Sjkoshy *    documentation and/or other materials provided with the distribution.
13164190Sjkoshy *
14164190Sjkoshy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15164190Sjkoshy * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16164190Sjkoshy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17164190Sjkoshy * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18164190Sjkoshy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19164190Sjkoshy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20164190Sjkoshy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21164190Sjkoshy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22164190Sjkoshy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23164190Sjkoshy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24164190Sjkoshy * SUCH DAMAGE.
25164190Sjkoshy */
26164190Sjkoshy
27164190Sjkoshy#include <sys/cdefs.h>
28164190Sjkoshy__FBSDID("$FreeBSD: head/lib/libelf/libelf_msize.m4 165317 2006-12-18 05:40:01Z jkoshy $");
29164190Sjkoshy
30164190Sjkoshy#include <sys/types.h>
31164190Sjkoshy#include <sys/elf32.h>
32164190Sjkoshy#include <sys/elf64.h>
33164190Sjkoshy
34164190Sjkoshy#include <assert.h>
35164190Sjkoshy#include <libelf.h>
36165317Sjkoshy#include <osreldate.h>
37164190Sjkoshy#include <string.h>
38164190Sjkoshy
39164190Sjkoshy#include "_libelf.h"
40164190Sjkoshy
41164190Sjkoshy/* WARNING: GENERATED FROM __file__. */
42164190Sjkoshy
43164190Sjkoshystruct msize {
44164190Sjkoshy	size_t	msz32;
45164190Sjkoshy	size_t	msz64;
46164190Sjkoshy};
47164190Sjkoshy
48164190Sjkoshydivert(-1)
49164190Sjkoshyinclude(SRCDIR`/elf_types.m4')
50164190Sjkoshy
51164190Sjkoshydefine(BYTE_SIZE,	1)
52164190Sjkoshydefine(NOTE_SIZE,	1)
53164190Sjkoshy
54164190Sjkoshy/*
55164190Sjkoshy * Unimplemented types.
56164190Sjkoshy */
57164190Sjkoshydefine(MOVEP_SIZE,	0)
58164190Sjkoshydefine(SXWORD_SIZE32,	0)
59164190Sjkoshydefine(XWORD_SIZE32,	0)
60164190Sjkoshy
61164190Sjkoshydefine(`DEFINE_ELF_MSIZE',
62164190Sjkoshy  `ifdef($1`_SIZE',
63164190Sjkoshy    `define($1_SIZE32,$1_SIZE)
64164190Sjkoshy     define($1_SIZE64,$1_SIZE)',
65164190Sjkoshy    `ifdef($1`_SIZE32',`',
66164190Sjkoshy      `define($1_SIZE32,sizeof(Elf32_$2))')
67164190Sjkoshy     ifdef($1`_SIZE64',`',
68164190Sjkoshy      `define($1_SIZE64,sizeof(Elf64_$2))')')')
69164190Sjkoshydefine(`DEFINE_ELF_MSIZES',
70164190Sjkoshy  `ifelse($#,1,`',
71164190Sjkoshy    `DEFINE_ELF_MSIZE($1)
72164190Sjkoshy     DEFINE_ELF_MSIZES(shift($@))')')
73164190Sjkoshy
74164190SjkoshyDEFINE_ELF_MSIZES(ELF_TYPE_LIST)
75164190Sjkoshy
76164190Sjkoshydefine(`MSIZE',
77165317Sjkoshy  `#if	__FreeBSD_version >= $3
78165317Sjkoshy    [ELF_T_$1] = { .msz32 = $1_SIZE32, .msz64 = $1_SIZE64 },
79165317Sjkoshy#endif')
80164190Sjkoshydefine(`MSIZES',
81164190Sjkoshy  `ifelse($#,1,`',
82164190Sjkoshy    `MSIZE($1)
83164190SjkoshyMSIZES(shift($@))')')
84164190Sjkoshy
85164190Sjkoshydivert(0)
86164190Sjkoshy
87164190Sjkoshystatic struct msize msize[ELF_T_NUM] = {
88164190SjkoshyMSIZES(ELF_TYPE_LIST)
89164190Sjkoshy};
90164190Sjkoshy
91164190Sjkoshysize_t
92164190Sjkoshy_libelf_msize(Elf_Type t, int elfclass, unsigned int version)
93164190Sjkoshy{
94164190Sjkoshy	size_t sz;
95164190Sjkoshy
96164190Sjkoshy	assert(elfclass == ELFCLASS32 || elfclass == ELFCLASS64);
97164190Sjkoshy	assert((signed) t >= ELF_T_FIRST && t <= ELF_T_LAST);
98164190Sjkoshy
99164190Sjkoshy	if (version != EV_CURRENT) {
100164190Sjkoshy		LIBELF_SET_ERROR(VERSION, 0);
101164190Sjkoshy		return (0);
102164190Sjkoshy	}
103164190Sjkoshy
104164190Sjkoshy	sz = (elfclass == ELFCLASS32) ? msize[t].msz32 : msize[t].msz64;
105164190Sjkoshy
106164190Sjkoshy	return (sz);
107164190Sjkoshy}
108