/[gentoo-projects]/pax-utils/porting.h
Gentoo

Contents of /pax-utils/porting.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.45 - (show annotations) (download) (as text)
Sat Jan 11 00:29:11 2014 UTC (8 months, 1 week ago) by vapier
Branch: MAIN
CVS Tags: HEAD
Changes since 1.44: +1 -15 lines
File MIME type: text/x-chdr
update elf.h

1 /*
2 * Copyright 2005-2012 Gentoo Foundation
3 * Distributed under the terms of the GNU General Public License v2
4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/porting.h,v 1.44 2013/04/02 21:13:05 vapier Exp $
5 *
6 * Copyright 2005-2012 Ned Ludd - <solar@gentoo.org>
7 * Copyright 2005-2012 Mike Frysinger - <vapier@gentoo.org>
8 *
9 * Make sure all of the common elf stuff is setup as we expect
10 */
11
12 #ifndef _PORTING_H
13 #define _PORTING_H
14
15 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(*arr))
16 #undef __PAX_UTILS_CLEANUP
17
18 #include <assert.h>
19 #include <ctype.h>
20 #include <dirent.h>
21 #include <errno.h>
22 #include <fcntl.h>
23 #include <fnmatch.h>
24 #include <getopt.h>
25 #include <inttypes.h>
26 #include <libgen.h>
27 #include <limits.h>
28 #include <pwd.h>
29 #include <regex.h>
30 #include <stdbool.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <unistd.h>
35 #include <sys/mman.h>
36 #include <sys/stat.h>
37 #include <sys/types.h>
38 #include "elf.h"
39 #if !defined(__FreeBSD__) && !defined(__OpenBSD__)
40 # include <alloca.h>
41 #endif
42 #if defined(__GLIBC__) || defined(__UCLIBC__)
43 # include <byteswap.h>
44 # include <endian.h>
45 #elif defined(__FreeBSD__)
46 # include <sys/endian.h>
47 #elif defined(__sun__)
48 # include <sys/isa_defs.h>
49 #elif defined(__MACH__)
50 # include <machine/endian.h>
51 #endif
52
53 #if defined(__GLIBC__) || defined(__UCLIBC__)
54 # include <glob.h>
55 #endif
56
57 #if defined(__GLIBC__) || defined(__UCLIBC__) || defined(__NetBSD__)
58 # define __PAX_UTILS_DEFAULT_LD_CACHE_CONFIG "/etc/ld.so.conf"
59 #elif defined(__FreeBSD__) || defined(__DragonFly__)
60 # include <elf-hints.h>
61 # define __PAX_UTILS_DEFAULT_LD_CACHE_CONFIG _PATH_ELF_HINTS
62 #else
63 # define __PAX_UTILS_DEFAULT_LD_CACHE_CONFIG ""
64 #endif
65
66 /* bounds checking code will fart on free(NULL) even though that
67 * is valid usage. So let's wrap it if need be.
68 */
69 #ifdef __BOUNDS_CHECKING_ON
70 # define free(ptr) do { if (ptr) free(ptr); } while (0)
71 # define __PAX_UTILS_CLEANUP
72 #endif
73
74 /* Few arches can safely do unaligned accesses */
75 #if defined(__cris__) || \
76 defined(__i386__) || \
77 defined(__powerpc__) || \
78 defined(__s390__) || \
79 defined(__x86_64__)
80 # define __PAX_UNALIGNED_OK 1
81 #else
82 # define __PAX_UNALIGNED_OK 0
83 #endif
84
85 #if !defined(bswap_16)
86 # if defined(bswap16)
87 # define bswap_16 bswap16
88 # define bswap_32 bswap32
89 # define bswap_64 bswap64
90 # else
91 # define bswap_16(x) \
92 ((((x) & 0xff00) >> 8) | \
93 (((x) & 0x00ff) << 8))
94 # define bswap_32(x) \
95 ((((x) & 0xff000000) >> 24) | \
96 (((x) & 0x00ff0000) >> 8) | \
97 (((x) & 0x0000ff00) << 8) | \
98 (((x) & 0x000000ff) << 24))
99 # if defined(__GNUC__)
100 # define bswap_64(x) \
101 ((((x) & 0xff00000000000000ull) >> 56) | \
102 (((x) & 0x00ff000000000000ull) >> 40) | \
103 (((x) & 0x0000ff0000000000ull) >> 24) | \
104 (((x) & 0x000000ff00000000ull) >> 8) | \
105 (((x) & 0x00000000ff000000ull) << 8) | \
106 (((x) & 0x0000000000ff0000ull) << 24) | \
107 (((x) & 0x000000000000ff00ull) << 40) | \
108 (((x) & 0x00000000000000ffull) << 56))
109 # else
110 # define bswap_64(x) \
111 ((((x) & 0xff00000000000000) >> 56) | \
112 (((x) & 0x00ff000000000000) >> 40) | \
113 (((x) & 0x0000ff0000000000) >> 24) | \
114 (((x) & 0x000000ff00000000) >> 8) | \
115 (((x) & 0x00000000ff000000) << 8) | \
116 (((x) & 0x0000000000ff0000) << 24) | \
117 (((x) & 0x000000000000ff00) << 40) | \
118 (((x) & 0x00000000000000ff) << 56))
119 # endif
120 # endif
121 #endif
122
123 #define _minmax(x, y, op) \
124 ({ typeof(x) __x = (x); typeof(y) __y = (y); (__x op __y ? __x : __y); })
125 #if !defined(min)
126 # define min(x, y) _minmax(x, y, <)
127 #endif
128 #if !defined(max)
129 # define max(x, y) _minmax(x, y, >)
130 #endif
131
132 #if !defined(_POSIX_PATH_MAX) && !defined(PATH_MAX) /* __PAX_UTILS_PATH_MAX */
133 # define __PAX_UTILS_PATH_MAX 8192
134 #elif _POSIX_PATH_MAX > PATH_MAX /* __PAX_UTILS_PATH_MAX */
135 # define __PAX_UTILS_PATH_MAX _POSIX_PATH_MAX
136 #else
137 # define __PAX_UTILS_PATH_MAX PATH_MAX
138 #endif
139
140 /* fall back case for non-Linux hosts ... so lame */
141 #if !defined(ELF_DATA)
142 # if defined(BYTE_ORDER)
143 # if BYTE_ORDER == LITTLE_ENDIAN
144 # define ELF_DATA ELFDATA2LSB
145 # elif BYTE_ORDER == BIG_ENDIAN
146 # define ELF_DATA ELFDATA2MSB
147 # else
148 # error "BYTE_ORDER: you fail"
149 # endif
150 # elif defined(__BYTE_ORDER)
151 # if __BYTE_ORDER == __LITTLE_ENDIAN
152 # define ELF_DATA ELFDATA2LSB
153 # elif __BYTE_ORDER == __BIG_ENDIAN
154 # define ELF_DATA ELFDATA2BSB
155 # else
156 # error "__BYTE_ORDER: you fail"
157 # endif
158 # elif defined(WORDS_LITTLENDIAN)
159 # define ELF_DATA ELFDATA2LSB
160 # elif defined(WORDS_BIGENDIAN)
161 # define ELF_DATA ELFDATA2MSB
162 # elif defined(_LITTLE_ENDIAN)
163 # define ELF_DATA ELFDATA2LSB
164 # elif defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN__)
165 # define ELF_DATA ELFDATA2MSB
166 # else
167 # error "no idea what the native byte order is"
168 # endif
169 #endif
170
171 /*
172 * propably will never be official added to the toolchain.
173 * But none the less we should try to get 0x65041580 reserved
174 */
175 #ifndef PT_PAX_FLAGS
176 # define PT_PAX_FLAGS 0x65041580
177
178 # define PF_PAGEEXEC (1 << 4) /* Enable PAGEEXEC */
179 # define PF_NOPAGEEXEC (1 << 5) /* Disable PAGEEXEC */
180 # define PF_SEGMEXEC (1 << 6) /* Enable SEGMEXEC */
181 # define PF_NOSEGMEXEC (1 << 7) /* Disable SEGMEXEC */
182 # define PF_MPROTECT (1 << 8) /* Enable MPROTECT */
183 # define PF_NOMPROTECT (1 << 9) /* Disable MPROTECT */
184 # define PF_RANDEXEC (1 << 10) /* Enable RANDEXEC */
185 # define PF_NORANDEXEC (1 << 11) /* Disable RANDEXEC */
186 # define PF_EMUTRAMP (1 << 12) /* Enable EMUTRAMP */
187 # define PF_NOEMUTRAMP (1 << 13) /* Disable EMUTRAMP */
188 # define PF_RANDMMAP (1 << 14) /* Enable RANDMMAP */
189 # define PF_NORANDMMAP (1 << 15) /* Disable RANDMMAP */
190 #endif /* PT_PAX_ */
191
192 /* older glibc/uclibc will need this since they typo-ed the define */
193 #ifndef EM_ST19
194 # ifdef EM_AT19
195 # define EM_ST19 EM_AT19
196 # else
197 # define EM_ST19 74
198 # endif
199 #endif
200
201 #ifndef O_CLOEXEC
202 # define O_CLOEXEC 0
203 #endif
204
205 #endif /* _PORTING_H */

  ViewVC Help
Powered by ViewVC 1.1.20