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

Contents of /pax-utils/porting.h

Parent Directory Parent Directory | Revision Log Revision Log


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

1 vapier 1.1 /*
2 vapier 1.43 * Copyright 2005-2012 Gentoo Foundation
3 vapier 1.4 * Distributed under the terms of the GNU General Public License v2
4 vapier 1.43 * $Header: /var/cvsroot/gentoo-projects/pax-utils/porting.h,v 1.42 2012/02/04 18:15:37 vapier Exp $
5 vapier 1.4 *
6 vapier 1.43 * Copyright 2005-2012 Ned Ludd - <solar@gentoo.org>
7     * Copyright 2005-2012 Mike Frysinger - <vapier@gentoo.org>
8 vapier 1.4 *
9 vapier 1.1 * 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 vapier 1.20 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(*arr))
16 vapier 1.21 #undef __PAX_UTILS_CLEANUP
17 vapier 1.20
18 vapier 1.34 #include <assert.h>
19     #include <ctype.h>
20     #include <dirent.h>
21 vapier 1.9 #include <errno.h>
22     #include <fcntl.h>
23 vapier 1.34 #include <fnmatch.h>
24 vapier 1.9 #include <getopt.h>
25 vapier 1.34 #include <inttypes.h>
26 vapier 1.9 #include <libgen.h>
27 vapier 1.34 #include <limits.h>
28 vapier 1.9 #include <pwd.h>
29 solar 1.24 #include <regex.h>
30 vapier 1.38 #include <stdbool.h>
31 vapier 1.34 #include <stdio.h>
32     #include <stdlib.h>
33     #include <string.h>
34     #include <unistd.h>
35 vapier 1.1 #include <sys/mman.h>
36 vapier 1.34 #include <sys/stat.h>
37     #include <sys/types.h>
38 vapier 1.1 #include "elf.h"
39 vapier 1.40 #if !defined(__FreeBSD__) && !defined(__OpenBSD__)
40 vapier 1.35 # include <alloca.h>
41     #endif
42 vapier 1.41 #if defined(__GLIBC__) || defined(__UCLIBC__)
43 vapier 1.33 # include <byteswap.h>
44 vapier 1.7 # include <endian.h>
45 vapier 1.1 #elif defined(__FreeBSD__)
46     # include <sys/endian.h>
47 vapier 1.27 #elif defined(__sun__)
48     # include <sys/isa_defs.h>
49 solar 1.25 #elif defined(__MACH__)
50     # include <machine/endian.h>
51 vapier 1.1 #endif
52    
53 vapier 1.18 #if defined(__GLIBC__) || defined(__UCLIBC__)
54     # include <glob.h>
55     #endif
56    
57 solar 1.22 #if defined(__GLIBC__) || defined(__UCLIBC__) || defined(__NetBSD__)
58 vapier 1.19 # define __PAX_UTILS_DEFAULT_LD_CACHE_CONFIG "/etc/ld.so.conf"
59     #elif defined(__FreeBSD__) || defined(__DragonFly__)
60 vapier 1.18 # include <elf-hints.h>
61 vapier 1.19 # define __PAX_UTILS_DEFAULT_LD_CACHE_CONFIG _PATH_ELF_HINTS
62     #else
63 solar 1.25 # define __PAX_UTILS_DEFAULT_LD_CACHE_CONFIG ""
64 vapier 1.18 #endif
65    
66 vapier 1.21 /* bounds checking code will fart on free(NULL) even though that
67 vapier 1.23 * is valid usage. So let's wrap it if need be.
68     */
69 vapier 1.21 #ifdef __BOUNDS_CHECKING_ON
70     # define free(ptr) do { if (ptr) free(ptr); } while (0)
71     # define __PAX_UTILS_CLEANUP
72     #endif
73    
74 vapier 1.39 /* 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 vapier 1.3 #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 vapier 1.1 #endif
122    
123 vapier 1.36 #if !defined(_POSIX_PATH_MAX) && !defined(PATH_MAX) /* __PAX_UTILS_PATH_MAX */
124 vapier 1.11 # define __PAX_UTILS_PATH_MAX 8192
125 vapier 1.36 #elif _POSIX_PATH_MAX > PATH_MAX /* __PAX_UTILS_PATH_MAX */
126 vapier 1.11 # define __PAX_UTILS_PATH_MAX _POSIX_PATH_MAX
127     #else
128     # define __PAX_UTILS_PATH_MAX PATH_MAX
129     #endif
130    
131 vapier 1.27 /* fall back case for non-Linux hosts ... so lame */
132 vapier 1.2 #if !defined(ELF_DATA)
133 vapier 1.7 # if defined(BYTE_ORDER)
134 vapier 1.30 # 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 vapier 1.7 # elif defined(__BYTE_ORDER)
142 vapier 1.30 # 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 vapier 1.7 # elif defined(WORDS_LITTLENDIAN)
150 vapier 1.30 # define ELF_DATA ELFDATA2LSB
151 vapier 1.7 # elif defined(WORDS_BIGENDIAN)
152 vapier 1.30 # define ELF_DATA ELFDATA2MSB
153 vapier 1.27 # elif defined(_LITTLE_ENDIAN)
154 vapier 1.30 # define ELF_DATA ELFDATA2LSB
155 grobian 1.37 # elif defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN__)
156 vapier 1.30 # define ELF_DATA ELFDATA2MSB
157 vapier 1.7 # else
158     # error "no idea what the native byte order is"
159 vapier 1.6 # endif
160 vapier 1.2 #endif
161    
162 vapier 1.1 /*
163 vapier 1.23 * in case we are not defined by proper/up-to-date system headers,
164 vapier 1.1 * 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 vapier 1.23 /*
177 vapier 1.1 * propably will never be official added to the toolchain.
178 vapier 1.23 * But none the less we should try to get 0x65041580 reserved
179 vapier 1.1 */
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 vapier 1.42 #ifndef O_CLOEXEC
207     # define O_CLOEXEC 0
208     #endif
209    
210 vapier 1.1 #endif /* _PORTING_H */

  ViewVC Help
Powered by ViewVC 1.1.20