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$");
29164190Sjkoshy
30164190Sjkoshy#include <gelf.h>
31164190Sjkoshy#include <libelf.h>
32164190Sjkoshy#include <string.h>
33164190Sjkoshy
34164190Sjkoshy#include "_libelf.h"
35164190Sjkoshy
36164190Sjkoshy
37164190SjkoshyElf_Data *
38164190Sjkoshyelf32_xlatetof(Elf_Data *dst, const Elf_Data *src, unsigned int encoding)
39164190Sjkoshy{
40164190Sjkoshy	return _libelf_xlate(dst, src, encoding, ELFCLASS32, ELF_TOFILE);
41164190Sjkoshy}
42164190Sjkoshy
43164190SjkoshyElf_Data *
44164190Sjkoshyelf64_xlatetof(Elf_Data *dst, const Elf_Data *src, unsigned int encoding)
45164190Sjkoshy{
46164190Sjkoshy	return _libelf_xlate(dst, src, encoding, ELFCLASS64, ELF_TOFILE);
47164190Sjkoshy}
48164190Sjkoshy
49164190SjkoshyElf_Data *
50164190Sjkoshyelf32_xlatetom(Elf_Data *dst, const Elf_Data *src, unsigned int encoding)
51164190Sjkoshy{
52164190Sjkoshy	return _libelf_xlate(dst, src, encoding, ELFCLASS32, ELF_TOMEMORY);
53164190Sjkoshy}
54164190Sjkoshy
55164190SjkoshyElf_Data *
56164190Sjkoshyelf64_xlatetom(Elf_Data *dst, const Elf_Data *src, unsigned int encoding)
57164190Sjkoshy{
58164190Sjkoshy	return _libelf_xlate(dst, src, encoding, ELFCLASS64, ELF_TOMEMORY);
59164190Sjkoshy}
60164190Sjkoshy
61164190SjkoshyElf_Data *
62164190Sjkoshygelf_xlatetom(Elf *e, Elf_Data *dst, const Elf_Data *src, unsigned int encoding)
63164190Sjkoshy{
64164190Sjkoshy	if (e != NULL)
65164190Sjkoshy		return (_libelf_xlate(dst, src, encoding, e->e_class,
66164190Sjkoshy		    ELF_TOMEMORY));
67164190Sjkoshy	LIBELF_SET_ERROR(ARGUMENT, 0);
68164190Sjkoshy	return (NULL);
69164190Sjkoshy}
70164190Sjkoshy
71164190SjkoshyElf_Data *
72164190Sjkoshygelf_xlatetof(Elf *e, Elf_Data *dst, const Elf_Data *src, unsigned int encoding)
73164190Sjkoshy{
74164190Sjkoshy	if (e != NULL)
75164190Sjkoshy		return (_libelf_xlate(dst, src, encoding, e->e_class,
76164190Sjkoshy		    ELF_TOFILE));
77164190Sjkoshy	LIBELF_SET_ERROR(ARGUMENT, 0);
78164190Sjkoshy	return (NULL);
79164190Sjkoshy}
80