xref: /freebsd/contrib/elftoolchain/libelftc/libelftc.h (revision 2e3507c25e42292b45a5482e116d278f5515d04d)
1 /*-
2  * Copyright (c) 2009 Kai Wang
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  *    in this position and unchanged.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * $FreeBSD: users/kaiwang27/elftc/libelftc.h 392 2009-05-31 19:17:46Z kaiwang27 $
27  * $Id: libelftc.h 3744 2019-06-28 00:41:47Z emaste $
28  */
29 
30 #ifndef	_LIBELFTC_H_
31 #define	_LIBELFTC_H_
32 
33 #include <sys/stat.h>
34 
35 #include <libelf.h>
36 
37 /*
38  * Types meant to be opaque to the consumers of these APIs.
39  */
40 typedef struct _Elftc_Bfd_Target Elftc_Bfd_Target;
41 typedef struct _Elftc_String_Table Elftc_String_Table;
42 
43 /* Target types. */
44 typedef enum {
45 	ETF_NONE,
46 	ETF_ELF,
47 	ETF_BINARY,
48 	ETF_SREC,
49 	ETF_IHEX,
50 	ETF_PE,
51 	ETF_EFI,
52 } Elftc_Bfd_Target_Flavor;
53 
54 /*
55  * Demangler flags.
56  */
57 
58 /* Name mangling style. */
59 #define	ELFTC_DEM_UNKNOWN	0x00000000U /* Not specified. */
60 #define	ELFTC_DEM_ARM		0x00000001U /* C++ Ann. Ref. Manual. */
61 #define	ELFTC_DEM_GNU2		0x00000002U /* GNU version 2. */
62 #define	ELFTC_DEM_GNU3		0x00000004U /* GNU version 3. */
63 
64 /* Demangling behaviour control. */
65 #define ELFTC_DEM_NOPARAM	0x00010000U
66 
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70 Elftc_Bfd_Target	*elftc_bfd_find_target(const char *_tgt_name);
71 Elftc_Bfd_Target_Flavor	 elftc_bfd_target_flavor(Elftc_Bfd_Target *_tgt);
72 unsigned int	elftc_bfd_target_byteorder(Elftc_Bfd_Target *_tgt);
73 unsigned int	elftc_bfd_target_class(Elftc_Bfd_Target *_tgt);
74 unsigned int	elftc_bfd_target_machine(Elftc_Bfd_Target *_tgt);
75 unsigned int	elftc_bfd_target_osabi(Elftc_Bfd_Target *_tgt);
76 int		elftc_copyfile(int _srcfd,  int _dstfd);
77 int		elftc_demangle(const char *_mangledname, char *_buffer,
78     size_t _bufsize, unsigned int _flags);
79 const char	*elftc_reloc_type_str(unsigned int mach, unsigned int type);
80 int		elftc_set_timestamps(const char *_filename, struct stat *_sb);
81 Elftc_String_Table	*elftc_string_table_create(size_t _sizehint);
82 void		elftc_string_table_destroy(Elftc_String_Table *_table);
83 Elftc_String_Table	*elftc_string_table_from_section(Elf_Scn *_scn,
84     size_t _sizehint);
85 const char	*elftc_string_table_image(Elftc_String_Table *_table,
86     size_t *_sz);
87 size_t		elftc_string_table_insert(Elftc_String_Table *_table,
88     const char *_string);
89 size_t		elftc_string_table_lookup(Elftc_String_Table *_table,
90     const char *_string);
91 int		elftc_string_table_remove(Elftc_String_Table *_table,
92     const char *_string);
93 const char	*elftc_string_table_to_string(Elftc_String_Table *_table,
94     size_t offset);
95 int		elftc_timestamp(time_t *_timestamp);
96 const char	*elftc_version(void);
97 #ifdef __cplusplus
98 }
99 #endif
100 
101 #endif	/* _LIBELFTC_H_ */
102