1 /*
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation;
5  * version 2.1 of the License.
6  *
7  * This library is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10  * Lesser General Public License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with this library; If not, see <http://www.gnu.org/licenses/>.
14  */
15 #ifndef __LIBELF_PRIVATE_H__
16 #define __LIBELF_PRIVATE_H__
17 
18 #ifdef __XEN__
19 
20 #include <xen/byteorder.h>
21 #include <xen/lib.h>
22 #include <xen/libelf.h>
23 #include <xen/softirq.h>
24 
25 #include <public/elfnote.h>
26 
27 /* we would like to use elf->log_callback but we can't because
28  * there is no vprintk in Xen */
29 #define elf_msg(elf, fmt, args ... ) \
30    if ((elf)->verbose) printk(fmt, ## args )
31 #define elf_err(elf, fmt, args ... ) \
32    printk(fmt, ## args )
33 
34 #define strtoull(str, end, base) simple_strtoull(str, end, base)
35 #define bswap_16(x) bswap16(x)
36 #define bswap_32(x) bswap32(x)
37 #define bswap_64(x) bswap64(x)
38 
39 #else /* !__XEN__ */
40 
41 #include <stdarg.h>
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <string.h>
45 #include <stddef.h>
46 #include <inttypes.h>
47 #include <limits.h>
48 #ifdef __sun__
49 #include <sys/byteorder.h>
50 #define bswap_16(x) BSWAP_16(x)
51 #define bswap_32(x) BSWAP_32(x)
52 #define bswap_64(x) BSWAP_64(x)
53 #elif defined(__NetBSD__)
54 #include <sys/bswap.h>
55 #define bswap_16(x) bswap16(x)
56 #define bswap_32(x) bswap32(x)
57 #define bswap_64(x) bswap64(x)
58 #elif defined(__OpenBSD__)
59 #include <machine/endian.h>
60 #define bswap_16(x) swap16(x)
61 #define bswap_32(x) swap32(x)
62 #define bswap_64(x) swap64(x)
63 #elif defined(__FreeBSD__)
64 #include <sys/endian.h>
65 #define bswap_16(x) bswap16(x)
66 #define bswap_32(x) bswap32(x)
67 #define bswap_64(x) bswap64(x)
68 #elif defined(__linux__) || defined(__Linux__) || defined(__MINIOS__)
69 #include <byteswap.h>
70 #else
71 #error Unsupported OS
72 #endif
73 #include <xen/elfnote.h>
74 #include <xen/libelf/libelf.h>
75 #include <xen-tools/common-macros.h>
76 
77 #ifndef FUZZ_NO_LIBXC
78 #include "xenctrl.h"
79 #include "xc_private.h"
80 #endif
81 
82 #define elf_msg(elf, fmt, args ... )                    \
83     elf_call_log_callback(elf, 0, fmt , ## args );
84 #define elf_err(elf, fmt, args ... )                    \
85     elf_call_log_callback(elf, 1, fmt , ## args );
86 
87 void elf_call_log_callback(struct elf_binary*, bool iserr, const char *fmt,...);
88 
89 #define safe_strcpy(d,s)                        \
90 do { strncpy((d),(s),sizeof((d))-1);            \
91      (d)[sizeof((d))-1] = '\0';                 \
92 } while (0)
93 
94 #endif
95 
96 #undef memcpy
97 #undef memset
98 #undef memmove
99 #undef strcpy
100 
101 #define memcpy  MISTAKE_unspecified_memcpy
102 #define memset  MISTAKE_unspecified_memset
103 #define memmove MISTAKE_unspecified_memmove
104 #define strcpy  MISTAKE_unspecified_strcpy
105   /* This prevents libelf from using these undecorated versions
106    * of memcpy, memset, memmove and strcpy.  Every call site
107    * must either use elf_mem*_unchecked, or elf_mem*_safe. */
108 
109 #endif /* __LIBELF_PRIVATE_H__ */
110 
111 /*
112  * Local variables:
113  * mode: C
114  * c-file-style: "BSD"
115  * c-basic-offset: 4
116  * tab-width: 4
117  * indent-tabs-mode: nil
118  * End:
119  */
120