xref: /f-stack/app/redis-5.0.5/src/config.h (revision 572c4311)
1 /*
2  * Copyright (c) 2009-2012, Salvatore Sanfilippo <antirez at gmail dot com>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  *   * Redistributions of source code must retain the above copyright notice,
9  *     this list of conditions and the following disclaimer.
10  *   * Redistributions in binary form must reproduce the above copyright
11  *     notice, this list of conditions and the following disclaimer in the
12  *     documentation and/or other materials provided with the distribution.
13  *   * Neither the name of Redis nor the names of its contributors may be used
14  *     to endorse or promote products derived from this software without
15  *     specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef __CONFIG_H
31 #define __CONFIG_H
32 
33 #ifdef __APPLE__
34 #include <AvailabilityMacros.h>
35 #endif
36 
37 #ifdef __linux__
38 #include <linux/version.h>
39 #include <features.h>
40 #endif
41 
42 /* Define redis_fstat to fstat or fstat64() */
43 #if defined(__APPLE__) && !defined(MAC_OS_X_VERSION_10_6)
44 #define redis_fstat fstat64
45 #define redis_stat stat64
46 #else
47 #define redis_fstat fstat
48 #define redis_stat stat
49 #endif
50 
51 /* Test for proc filesystem */
52 #ifdef __linux__
53 #define HAVE_PROC_STAT 1
54 #define HAVE_PROC_MAPS 1
55 #define HAVE_PROC_SMAPS 1
56 #define HAVE_PROC_SOMAXCONN 1
57 #endif
58 
59 /* Test for task_info() */
60 #if defined(__APPLE__)
61 #define HAVE_TASKINFO 1
62 #endif
63 
64 /* Test for backtrace() */
65 #if defined(__APPLE__) || (defined(__linux__) && defined(__GLIBC__)) || \
66     defined(__FreeBSD__) || (defined(__OpenBSD__) && defined(USE_BACKTRACE))\
67  || defined(__DragonFly__)
68 #define HAVE_BACKTRACE 1
69 #endif
70 
71 /* MSG_NOSIGNAL. */
72 #ifdef __linux__
73 #define HAVE_MSG_NOSIGNAL 1
74 #endif
75 
76 /* Test for polling API */
77 #ifdef __linux__
78 #define HAVE_EPOLL 1
79 #endif
80 
81 #if (defined(__APPLE__) && defined(MAC_OS_X_VERSION_10_6)) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined (__NetBSD__)
82 #define HAVE_KQUEUE 1
83 #endif
84 
85 #ifdef __sun
86 #include <sys/feature_tests.h>
87 #ifdef _DTRACE_VERSION
88 #define HAVE_EVPORT 1
89 #endif
90 #endif
91 
92 /* Define redis_fsync to fdatasync() in Linux and fsync() for all the rest */
93 #ifdef __linux__
94 #define redis_fsync fdatasync
95 #else
96 #define redis_fsync fsync
97 #endif
98 
99 /* Define rdb_fsync_range to sync_file_range() on Linux, otherwise we use
100  * the plain fsync() call. */
101 #ifdef __linux__
102 #if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
103 #if (LINUX_VERSION_CODE >= 0x020611 && __GLIBC_PREREQ(2, 6))
104 #define HAVE_SYNC_FILE_RANGE 1
105 #endif
106 #else
107 #if (LINUX_VERSION_CODE >= 0x020611)
108 #define HAVE_SYNC_FILE_RANGE 1
109 #endif
110 #endif
111 #endif
112 
113 #ifdef HAVE_SYNC_FILE_RANGE
114 #define rdb_fsync_range(fd,off,size) sync_file_range(fd,off,size,SYNC_FILE_RANGE_WAIT_BEFORE|SYNC_FILE_RANGE_WRITE)
115 #else
116 #define rdb_fsync_range(fd,off,size) fsync(fd)
117 #endif
118 
119 /* Check if we can use setproctitle().
120  * BSD systems have support for it, we provide an implementation for
121  * Linux and osx. */
122 #if (defined __NetBSD__ || defined __FreeBSD__ || defined __OpenBSD__)
123 #define USE_SETPROCTITLE
124 #endif
125 
126 #ifndef HAVE_FF_KQUEUE
127 #if ((defined __linux && defined(__GLIBC__)) || defined __APPLE__)
128 #define USE_SETPROCTITLE
129 #define INIT_SETPROCTITLE_REPLACEMENT
130 void spt_init(int argc, char *argv[]);
131 void setproctitle(const char *fmt, ...);
132 #endif
133 #endif
134 
135 /* Byte ordering detection */
136 #include <sys/types.h> /* This will likely define BYTE_ORDER */
137 
138 #ifndef BYTE_ORDER
139 #if (BSD >= 199103)
140 # include <machine/endian.h>
141 #else
142 #if defined(linux) || defined(__linux__)
143 # include <endian.h>
144 #else
145 #define	LITTLE_ENDIAN	1234	/* least-significant byte first (vax, pc) */
146 #define	BIG_ENDIAN	4321	/* most-significant byte first (IBM, net) */
147 #define	PDP_ENDIAN	3412	/* LSB first in word, MSW first in long (pdp)*/
148 
149 #if defined(__i386__) || defined(__x86_64__) || defined(__amd64__) || \
150    defined(vax) || defined(ns32000) || defined(sun386) || \
151    defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \
152    defined(__alpha__) || defined(__alpha)
153 #define BYTE_ORDER    LITTLE_ENDIAN
154 #endif
155 
156 #if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \
157     defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \
158     defined(MIPSEB) || defined(_MIPSEB) || defined(_IBMR2) || defined(DGUX) ||\
159     defined(apollo) || defined(__convex__) || defined(_CRAY) || \
160     defined(__hppa) || defined(__hp9000) || \
161     defined(__hp9000s300) || defined(__hp9000s700) || \
162     defined (BIT_ZERO_ON_LEFT) || defined(m68k) || defined(__sparc)
163 #define BYTE_ORDER	BIG_ENDIAN
164 #endif
165 #endif /* linux */
166 #endif /* BSD */
167 #endif /* BYTE_ORDER */
168 
169 /* Sometimes after including an OS-specific header that defines the
170  * endianess we end with __BYTE_ORDER but not with BYTE_ORDER that is what
171  * the Redis code uses. In this case let's define everything without the
172  * underscores. */
173 #ifndef BYTE_ORDER
174 #ifdef __BYTE_ORDER
175 #if defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN)
176 #ifndef LITTLE_ENDIAN
177 #define LITTLE_ENDIAN __LITTLE_ENDIAN
178 #endif
179 #ifndef BIG_ENDIAN
180 #define BIG_ENDIAN __BIG_ENDIAN
181 #endif
182 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
183 #define BYTE_ORDER LITTLE_ENDIAN
184 #else
185 #define BYTE_ORDER BIG_ENDIAN
186 #endif
187 #endif
188 #endif
189 #endif
190 
191 #if !defined(BYTE_ORDER) || \
192     (BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN)
193 	/* you must determine what the correct bit order is for
194 	 * your compiler - the next line is an intentional error
195 	 * which will force your compiles to bomb until you fix
196 	 * the above macros.
197 	 */
198 #error "Undefined or invalid BYTE_ORDER"
199 #endif
200 
201 #if (__i386 || __amd64 || __powerpc__) && __GNUC__
202 #define GNUC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
203 #if defined(__clang__)
204 #define HAVE_ATOMIC
205 #endif
206 #if (defined(__GLIBC__) && defined(__GLIBC_PREREQ))
207 #if (GNUC_VERSION >= 40100 && __GLIBC_PREREQ(2, 6))
208 #define HAVE_ATOMIC
209 #endif
210 #endif
211 #endif
212 
213 /* Make sure we can test for ARM just checking for __arm__, since sometimes
214  * __arm is defined but __arm__ is not. */
215 #if defined(__arm) && !defined(__arm__)
216 #define __arm__
217 #endif
218 #if defined (__aarch64__) && !defined(__arm64__)
219 #define __arm64__
220 #endif
221 
222 /* Make sure we can test for SPARC just checking for __sparc__. */
223 #if defined(__sparc) && !defined(__sparc__)
224 #define __sparc__
225 #endif
226 
227 #if defined(__sparc__) || defined(__arm__)
228 #define USE_ALIGNED_ACCESS
229 #endif
230 
231 #endif
232