rumpuser_port.h revision 1.38 1 /* $NetBSD: rumpuser_port.h,v 1.38 2014/11/05 01:15:58 pooka Exp $ */
2
3 #ifndef _LIB_LIBRUMPUSER_RUMPUSER_PORT_H_
4 #define _LIB_LIBRUMPUSER_RUMPUSER_PORT_H_
5
6 /*
7 * Define things found by autoconf. buildrump.sh defines RUMPUSER_CONFIG,
8 * the NetBSD build does not run autoconf during build and supplies the
9 * necessary values here. To update the NetBSD values, run ./configure
10 * for an up-to-date NetBSD installation and insert rumpuser_config.h
11 * in the space below, e.g. with ":r !sed -ne '/^\#/p' rumpuser_config.h"
12 */
13 #if !defined(RUMPUSER_CONFIG)
14
15 #define HAVE_ARC4RANDOM_BUF 1
16 #define HAVE_CHFLAGS 1
17 #define HAVE_CLOCKID_T 1
18 #define HAVE_CLOCK_GETTIME 1
19 #define HAVE_CLOCK_NANOSLEEP 1
20 #define HAVE_DLINFO 1
21 #define HAVE_FSYNC_RANGE 1
22 #define HAVE_GETENV_R 1
23 #define HAVE_GETPROGNAME 1
24 #define HAVE_GETSUBOPT 1
25 #define HAVE_INTTYPES_H 1
26 #define HAVE_KQUEUE 1
27 #define HAVE_MEMORY_H 1
28 #define HAVE_PATHS_H 1
29 #define HAVE_POSIX_MEMALIGN 1
30 #define HAVE_PTHREAD_SETNAME3 1
31 #define HAVE_REGISTER_T 1
32 #define HAVE_SETPROGNAME 1
33 #define HAVE_STDINT_H 1
34 #define HAVE_STDLIB_H 1
35 #define HAVE_STRINGS_H 1
36 #define HAVE_STRING_H 1
37 #define HAVE_STRSUFTOLL 1
38 #define HAVE_STRUCT_SOCKADDR_IN_SIN_LEN 1
39 #define HAVE_SYS_ATOMIC_H 1
40 #define HAVE_SYS_CDEFS_H 1
41 #define HAVE_SYS_DISKLABEL_H 1
42 #define HAVE_SYS_DISK_H 1
43 #define HAVE_SYS_DKIO_H 1
44 #define HAVE_SYS_PARAM_H 1
45 #define HAVE_SYS_STAT_H 1
46 #define HAVE_SYS_SYSCTL_H 1
47 #define HAVE_SYS_TYPES_H 1
48 #define HAVE_UNISTD_H 1
49 #define HAVE___QUOTACTL 1
50 #define PACKAGE_BUGREPORT "http://rumpkernel.org/"
51 #define PACKAGE_NAME "rumpuser-posix"
52 #define PACKAGE_STRING "rumpuser-posix 999"
53 #define PACKAGE_TARNAME "rumpuser-posix"
54 #define PACKAGE_URL ""
55 #define PACKAGE_VERSION "999"
56 #define STDC_HEADERS 1
57 #ifndef _DARWIN_USE_64_BIT_INODE
58 # define _DARWIN_USE_64_BIT_INODE 1
59 #endif
60
61 #else /* RUMPUSER_CONFIG */
62 #include "rumpuser_config.h"
63 #endif
64
65 #ifdef __linux__
66 #define _XOPEN_SOURCE 600
67 #define _BSD_SOURCE
68 #define _GNU_SOURCE
69 #endif
70
71 #if defined(HAVE_SYS_CDEFS_H)
72 #include <sys/cdefs.h>
73 #endif
74 #if defined(HAVE_SYS_PARAM_H)
75 #include <sys/param.h>
76 #endif
77
78 #ifndef MIN
79 #define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
80 #endif
81 #ifndef MAX
82 #define MAX(a,b) ((/*CONSTCOND*/(a)>(b))?(a):(b))
83 #endif
84
85 #if !defined(HAVE_GETSUBOPT)
86 static inline int
87 getsubopt(char **optionp, char * const *tokens, char **valuep)
88 {
89
90 /* TODO make a definition */
91 return -1;
92 }
93 #endif
94
95 #ifdef __ANDROID__
96 #include <stdint.h>
97 typedef uint16_t in_port_t;
98 #include <sys/select.h>
99 #define atomic_inc_uint(x) __sync_fetch_and_add(x, 1)
100 #define atomic_dec_uint(x) __sync_fetch_and_sub(x, 1)
101 #endif
102
103 /* sunny magic */
104 #if defined(__sun__)
105 # if defined(RUMPUSER_NO_FILE_OFFSET_BITS)
106 # undef _FILE_OFFSET_BITS
107 # define _FILE_OFFSET_BITS 32
108 # endif
109 #endif
110
111 #if !defined(HAVE_CLOCKID_T)
112 typedef int clockid_t;
113 #endif
114
115 #if !defined(HAVE_CLOCK_GETTIME)
116 #include <sys/time.h>
117 #define CLOCK_REALTIME 0
118 static inline int
119 clock_gettime(clockid_t clk, struct timespec *ts)
120 {
121 struct timeval tv;
122
123 if (gettimeofday(&tv, 0) == 0) {
124 ts->tv_sec = tv.tv_sec;
125 ts->tv_nsec = tv.tv_usec * 1000;
126 }
127 return -1;
128 }
129 #endif
130
131 #if defined(__APPLE__)
132 #include <libkern/OSAtomic.h>
133 #define atomic_inc_uint(x) OSAtomicIncrement32((volatile int32_t *)(x))
134 #define atomic_dec_uint(x) OSAtomicDecrement32((volatile int32_t *)(x))
135 #endif
136
137 #include <sys/types.h>
138
139 #if !defined(HAVE_GETENV_R)
140 #include <errno.h>
141 #include <stdlib.h>
142 #include <string.h>
143 #include <inttypes.h>
144 static inline int
145 getenv_r(const char *name, char *buf, size_t buflen)
146 {
147 char *tmp;
148
149 if ((tmp = getenv(name)) != NULL) {
150 if (strlen(tmp) >= buflen) {
151 errno = ERANGE;
152 return -1;
153 }
154 strcpy(buf, tmp);
155 return 0;
156 } else {
157 errno = ENOENT;
158 return -1;
159 }
160 }
161 #endif
162
163 #if !defined(HAVE_POSIX_MEMALIGN)
164 #if !defined(HAVE_MEMALIGN)
165 #error method for aligned memory allocation required
166 #endif
167 #include <sys/sysmacros.h>
168 #include <stdlib.h>
169 static inline int
170 posix_memalign(void **ptr, size_t align, size_t size)
171 {
172
173 *ptr = memalign(align, size);
174 if (*ptr == NULL)
175 return ENOMEM;
176 return 0;
177 }
178 #endif
179
180 /*
181 * For NetBSD, use COHERENCY_UNIT as the lock alignment size.
182 * On other platforms, just guess it to be 64.
183 */
184 #ifdef __NetBSD__
185 #define RUMPUSER_LOCKALIGN COHERENCY_UNIT
186 #else
187 #define RUMPUSER_LOCKALIGN 64
188 #endif
189
190 #if !defined(HAVE_ALIGNED_ALLOC)
191 #include <stdlib.h>
192 static inline void *
193 aligned_alloc(size_t alignment, size_t size)
194 {
195 void *ptr;
196 int rv;
197
198 rv = posix_memalign(&ptr, alignment, size);
199 return rv ? NULL : ptr;
200 }
201 #endif
202
203 #ifndef __RCSID
204 #define __RCSID(a)
205 #endif
206
207 #ifndef INFTIM
208 #define INFTIM (-1)
209 #endif
210
211 #ifndef _DIAGASSERT
212 #define _DIAGASSERT(_p_)
213 #endif
214
215 #if !defined(HAVE_STRUCT_SOCKADDR_IN_SIN_LEN)
216 #define SIN_SETLEN(a,b)
217 #else
218 #define SIN_SETLEN(_sin_, _len_) _sin_.sin_len = _len_
219 #endif
220
221 #ifndef __predict_true
222 #define __predict_true(a) a
223 #define __predict_false(a) a
224 #endif
225
226 #ifndef __dead
227 #define __dead __attribute__((__noreturn__))
228 #endif
229
230 #ifndef __printflike
231 #ifdef __GNUC__
232 #define __printflike(a,b) __attribute__((__format__ (__printf__,a,b)))
233 #else
234 #define __printflike(a,b)
235 #endif
236 #endif
237
238 #ifndef __noinline
239 #ifdef __GNUC__
240 #define __noinline __attribute__((__noinline__))
241 #else
242 #define __noinline
243 #endif
244 #endif
245
246 #ifndef __arraycount
247 #define __arraycount(_ar_) (sizeof(_ar_)/sizeof(_ar_[0]))
248 #endif
249
250 #ifndef __UNCONST
251 #define __UNCONST(_a_) ((void *)(unsigned long)(const void *)(_a_))
252 #endif
253
254 #ifndef __CONCAT
255 #define __CONCAT(x,y) x ## y
256 #endif
257
258 #ifndef __STRING
259 #define __STRING(x) #x
260 #endif
261
262 #ifndef __NetBSD_Prereq__
263 #define __NetBSD_Prereq__(a,b,c) 0
264 #endif
265
266 #include <sys/socket.h>
267
268 #if !defined(__CMSG_ALIGN)
269 #ifdef CMSG_ALIGN
270 #define __CMSG_ALIGN(a) CMSG_ALIGN(a)
271 #endif
272 #endif
273
274 #ifndef PF_LOCAL
275 #define PF_LOCAL PF_UNIX
276 #endif
277 #ifndef AF_LOCAL
278 #define AF_LOCAL AF_UNIX
279 #endif
280
281 /* pfft, but what are you going to do? */
282 #ifndef MSG_NOSIGNAL
283 #define MSG_NOSIGNAL 0
284 #endif
285
286 #if !defined(HAVE_REGISTER_T) && !defined(RUMP_REGISTER_T)
287 #define RUMP_REGISTER_T long
288 typedef RUMP_REGISTER_T register_t;
289 #endif
290
291 #include <sys/time.h>
292
293 #ifndef TIMEVAL_TO_TIMESPEC
294 #define TIMEVAL_TO_TIMESPEC(tv, ts) \
295 do { \
296 (ts)->tv_sec = (tv)->tv_sec; \
297 (ts)->tv_nsec = (tv)->tv_usec * 1000; \
298 } while (/*CONSTCOND*/0)
299 #endif
300
301 #if !defined(HAVE_SETPROGNAME)
302 #define setprogname(a)
303 #endif
304
305 #endif /* _LIB_LIBRUMPUSER_RUMPUSER_PORT_H_ */
306