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

Contents of /pax-utils/porting.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.43 - (show annotations) (download) (as text)
Sun Nov 4 07:26:24 2012 UTC (22 months, 1 week ago) by vapier
Branch: MAIN
Changes since 1.42: +4 -4 lines
File MIME type: text/x-chdr
update copyright years

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.42 2012/02/04 18:15:37 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 #if !defined(_POSIX_PATH_MAX) && !defined(PATH_MAX) /* __PAX_UTILS_PATH_MAX */
124 # define __PAX_UTILS_PATH_MAX 8192
125 #elif _POSIX_PATH_MAX > PATH_MAX /* __PAX_UTILS_PATH_MAX */
126 # define __PAX_UTILS_PATH_MAX _POSIX_PATH_MAX
127 #else
128 # define __PAX_UTILS_PATH_MAX PATH_MAX
129 #endif
130
131 /* fall back case for non-Linux hosts ... so lame */
132 #if !defined(ELF_DATA)
133 # if defined(BYTE_ORDER)
134 # if BYTE_ORDER == LITTLE_ENDIAN
135 # define ELF_DATA ELFDATA2LSB
136 # elif BYTE_ORDER == BIG_ENDIAN
137 # define ELF_DATA ELFDATA2MSB
138 # else
139 # error "BYTE_ORDER: you fail"
140 # endif
141 # elif defined(__BYTE_ORDER)
142 # if __BYTE_ORDER == __LITTLE_ENDIAN
143 # define ELF_DATA ELFDATA2LSB
144 # elif __BYTE_ORDER == __BIG_ENDIAN
145 # define ELF_DATA ELFDATA2BSB
146 # else
147 # error "__BYTE_ORDER: you fail"
148 # endif
149 # elif defined(WORDS_LITTLENDIAN)
150 # define ELF_DATA ELFDATA2LSB
151 # elif defined(WORDS_BIGENDIAN)
152 # define ELF_DATA ELFDATA2MSB
153 # elif defined(_LITTLE_ENDIAN)
154 # define ELF_DATA ELFDATA2LSB
155 # elif defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN__)
156 # define ELF_DATA ELFDATA2MSB
157 # else
158 # error "no idea what the native byte order is"
159 # endif
160 #endif
161
162 /*
163 * in case we are not defined by proper/up-to-date system headers,
164 * we check for a whole lot of things and copy them from elf.h.
165 */
166
167 #ifndef PT_GNU_STACK
168 # define PT_GNU_STACK 0x6474e551
169 #endif
170
171 /* not in <=binutils-2.14.90.0.8 (should come in by way of .9) */
172 #ifndef PT_GNU_RELRO
173 # define PT_GNU_RELRO 0x6474e552
174 #endif
175
176 /*
177 * propably will never be official added to the toolchain.
178 * But none the less we should try to get 0x65041580 reserved
179 */
180 #ifndef PT_PAX_FLAGS
181 # define PT_PAX_FLAGS 0x65041580
182
183 # define PF_PAGEEXEC (1 << 4) /* Enable PAGEEXEC */
184 # define PF_NOPAGEEXEC (1 << 5) /* Disable PAGEEXEC */
185 # define PF_SEGMEXEC (1 << 6) /* Enable SEGMEXEC */
186 # define PF_NOSEGMEXEC (1 << 7) /* Disable SEGMEXEC */
187 # define PF_MPROTECT (1 << 8) /* Enable MPROTECT */
188 # define PF_NOMPROTECT (1 << 9) /* Disable MPROTECT */
189 # define PF_RANDEXEC (1 << 10) /* Enable RANDEXEC */
190 # define PF_NORANDEXEC (1 << 11) /* Disable RANDEXEC */
191 # define PF_EMUTRAMP (1 << 12) /* Enable EMUTRAMP */
192 # define PF_NOEMUTRAMP (1 << 13) /* Disable EMUTRAMP */
193 # define PF_RANDMMAP (1 << 14) /* Enable RANDMMAP */
194 # define PF_NORANDMMAP (1 << 15) /* Disable RANDMMAP */
195 #endif /* PT_PAX_ */
196
197 /* older glibc/uclibc will need this since they typo-ed the define */
198 #ifndef EM_ST19
199 # ifdef EM_AT19
200 # define EM_ST19 EM_AT19
201 # else
202 # define EM_ST19 74
203 # endif
204 #endif
205
206 #ifndef O_CLOEXEC
207 # define O_CLOEXEC 0
208 #endif
209
210 #endif /* _PORTING_H */

  ViewVC Help
Powered by ViewVC 1.1.20