xref: /netbsd-src/external/bsd/elftoolchain/dist/libelf/gelf_xlate.c (revision 5ac3bc719ce6e70593039505b491894133237d12)
1*5ac3bc71Schristos /*	$NetBSD: gelf_xlate.c,v 1.5 2024/03/03 17:37:34 christos Exp $	*/
2e81373b4Schristos 
39dd9d0cfSchristos /*-
4*5ac3bc71Schristos  * Copyright (c) 2006,2008,2018 Joseph Koshy
59dd9d0cfSchristos  * All rights reserved.
69dd9d0cfSchristos  *
79dd9d0cfSchristos  * Redistribution and use in source and binary forms, with or without
89dd9d0cfSchristos  * modification, are permitted provided that the following conditions
99dd9d0cfSchristos  * are met:
109dd9d0cfSchristos  * 1. Redistributions of source code must retain the above copyright
119dd9d0cfSchristos  *    notice, this list of conditions and the following disclaimer.
129dd9d0cfSchristos  * 2. Redistributions in binary form must reproduce the above copyright
139dd9d0cfSchristos  *    notice, this list of conditions and the following disclaimer in the
149dd9d0cfSchristos  *    documentation and/or other materials provided with the distribution.
159dd9d0cfSchristos  *
169dd9d0cfSchristos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
179dd9d0cfSchristos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
189dd9d0cfSchristos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199dd9d0cfSchristos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
209dd9d0cfSchristos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
219dd9d0cfSchristos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
229dd9d0cfSchristos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
239dd9d0cfSchristos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
249dd9d0cfSchristos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
259dd9d0cfSchristos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
269dd9d0cfSchristos  * SUCH DAMAGE.
279dd9d0cfSchristos  */
289dd9d0cfSchristos 
29*5ac3bc71Schristos #include <sys/cdefs.h>
30*5ac3bc71Schristos 
319dd9d0cfSchristos #include <gelf.h>
329dd9d0cfSchristos #include <libelf.h>
339dd9d0cfSchristos #include <string.h>
349dd9d0cfSchristos 
359dd9d0cfSchristos #include "_libelf.h"
369dd9d0cfSchristos 
37*5ac3bc71Schristos __RCSID("$NetBSD: gelf_xlate.c,v 1.5 2024/03/03 17:37:34 christos Exp $");
38*5ac3bc71Schristos ELFTC_VCSID("Id: gelf_xlate.c 3977 2022-05-01 06:45:34Z jkoshy");
399dd9d0cfSchristos 
409dd9d0cfSchristos Elf_Data *
elf32_xlatetof(Elf_Data * dst,const Elf_Data * src,unsigned int encoding)419dd9d0cfSchristos elf32_xlatetof(Elf_Data *dst, const Elf_Data *src, unsigned int encoding)
429dd9d0cfSchristos {
43*5ac3bc71Schristos 	return _libelf_xlate(dst, src, encoding, ELFCLASS32, EM_NONE,
44*5ac3bc71Schristos 	    ELF_TOFILE);
459dd9d0cfSchristos }
469dd9d0cfSchristos 
479dd9d0cfSchristos Elf_Data *
elf64_xlatetof(Elf_Data * dst,const Elf_Data * src,unsigned int encoding)489dd9d0cfSchristos elf64_xlatetof(Elf_Data *dst, const Elf_Data *src, unsigned int encoding)
499dd9d0cfSchristos {
50*5ac3bc71Schristos 	return _libelf_xlate(dst, src, encoding, ELFCLASS64, EM_NONE,
51*5ac3bc71Schristos 	    ELF_TOFILE);
529dd9d0cfSchristos }
539dd9d0cfSchristos 
549dd9d0cfSchristos Elf_Data *
elf32_xlatetom(Elf_Data * dst,const Elf_Data * src,unsigned int encoding)559dd9d0cfSchristos elf32_xlatetom(Elf_Data *dst, const Elf_Data *src, unsigned int encoding)
569dd9d0cfSchristos {
57*5ac3bc71Schristos 	return _libelf_xlate(dst, src, encoding, ELFCLASS32, EM_NONE,
58*5ac3bc71Schristos 	    ELF_TOMEMORY);
599dd9d0cfSchristos }
609dd9d0cfSchristos 
619dd9d0cfSchristos Elf_Data *
elf64_xlatetom(Elf_Data * dst,const Elf_Data * src,unsigned int encoding)629dd9d0cfSchristos elf64_xlatetom(Elf_Data *dst, const Elf_Data *src, unsigned int encoding)
639dd9d0cfSchristos {
64*5ac3bc71Schristos 	return _libelf_xlate(dst, src, encoding, ELFCLASS64, EM_NONE,
65*5ac3bc71Schristos 	    ELF_TOMEMORY);
669dd9d0cfSchristos }
679dd9d0cfSchristos 
689dd9d0cfSchristos Elf_Data *
gelf_xlatetom(Elf * e,Elf_Data * dst,const Elf_Data * src,unsigned int encoding)699dd9d0cfSchristos gelf_xlatetom(Elf *e, Elf_Data *dst, const Elf_Data *src,
709dd9d0cfSchristos     unsigned int encoding)
719dd9d0cfSchristos {
729dd9d0cfSchristos 	if (e != NULL)
739dd9d0cfSchristos 		return (_libelf_xlate(dst, src, encoding, e->e_class,
74*5ac3bc71Schristos 		    _libelf_elfmachine(e), ELF_TOMEMORY));
759dd9d0cfSchristos 	LIBELF_SET_ERROR(ARGUMENT, 0);
769dd9d0cfSchristos 	return (NULL);
779dd9d0cfSchristos }
789dd9d0cfSchristos 
799dd9d0cfSchristos Elf_Data *
gelf_xlatetof(Elf * e,Elf_Data * dst,const Elf_Data * src,unsigned int encoding)809dd9d0cfSchristos gelf_xlatetof(Elf *e, Elf_Data *dst, const Elf_Data *src,
819dd9d0cfSchristos     unsigned int encoding)
829dd9d0cfSchristos {
839dd9d0cfSchristos 	if (e != NULL)
849dd9d0cfSchristos 		return (_libelf_xlate(dst, src, encoding, e->e_class,
85*5ac3bc71Schristos 		    _libelf_elfmachine(e), ELF_TOFILE));
869dd9d0cfSchristos 	LIBELF_SET_ERROR(ARGUMENT, 0);
879dd9d0cfSchristos 	return (NULL);
889dd9d0cfSchristos }
89