xref: /freebsd/contrib/elftoolchain/libelftc/_libelftc.h (revision 6829dae12bb055451fa467da4589c43bd03b1e64)
1 /*-
2  * Copyright (c) 2009 Kai Wang
3  * Copyright (c) 2007,2008 Hyogeol Lee <hyogeollee@gmail.com>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer
11  *    in this position and unchanged.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * $Id: _libelftc.h 3531 2017-06-05 05:08:43Z kaiwang27 $
28  */
29 
30 #ifndef	__LIBELFTC_H_
31 #define	__LIBELFTC_H_
32 
33 #include <stdbool.h>
34 
35 #include "_elftc.h"
36 
37 struct _Elftc_Bfd_Target {
38 	const char	*bt_name;	/* target name. */
39 	unsigned int	 bt_type;	/* target type. */
40 	unsigned int	 bt_byteorder;	/* elf target byteorder. */
41 	unsigned int	 bt_elfclass;	/* elf target class (32/64bit). */
42 	unsigned int	 bt_machine;	/* elf target arch. */
43 	unsigned int	 bt_osabi;	/* elf target abi. */
44 };
45 
46 extern struct _Elftc_Bfd_Target _libelftc_targets[];
47 
48 /** @brief Dynamic vector data for string. */
49 struct vector_str {
50 	/** Current size */
51 	size_t		size;
52 	/** Total capacity */
53 	size_t		capacity;
54 	/** String array */
55 	char		**container;
56 };
57 
58 #define BUFFER_GROWFACTOR	1.618
59 
60 #define	ELFTC_FAILURE		0
61 #define	ELFTC_ISDIGIT(C) 	(isdigit((C) & 0xFF))
62 #define	ELFTC_SUCCESS		1
63 
64 #define VECTOR_DEF_CAPACITY	8
65 
66 
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70 char	*cpp_demangle_ARM(const char *_org);
71 char	*cpp_demangle_gnu2(const char *_org);
72 char	*cpp_demangle_gnu3(const char *_org);
73 bool	is_cpp_mangled_ARM(const char *_org);
74 bool	is_cpp_mangled_gnu2(const char *_org);
75 bool	is_cpp_mangled_gnu3(const char *_org);
76 unsigned int	libelftc_hash_string(const char *);
77 void	vector_str_dest(struct vector_str *_vec);
78 int	vector_str_find(const struct vector_str *_vs, const char *_str,
79     size_t _len);
80 char	*vector_str_get_flat(const struct vector_str *_vs, size_t *_len);
81 bool	vector_str_init(struct vector_str *_vs);
82 bool	vector_str_pop(struct vector_str *_vs);
83 bool	vector_str_push(struct vector_str *_vs, const char *_str,
84     size_t _len);
85 bool	vector_str_push_vector(struct vector_str *_dst,
86     struct vector_str *_org);
87 bool	vector_str_push_vector_head(struct vector_str *_dst,
88     struct vector_str *_org);
89 char	*vector_str_substr(const struct vector_str *_vs, size_t _begin,
90     size_t _end, size_t *_rlen);
91 #ifdef __cplusplus
92 }
93 #endif
94 
95 #endif	/* __LIBELFTC_H */
96