rumpuser_port.h revision 1.45 1 /* $NetBSD: rumpuser_port.h,v 1.45 2015/08/16 11:37:39 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 HAVE_UTIMENSAT 1
51 #define PACKAGE_BUGREPORT "http://rumpkernel.org/"
52 #define PACKAGE_NAME "rumpuser-posix"
53 #define PACKAGE_STRING "rumpuser-posix 999"
54 #define PACKAGE_TARNAME "rumpuser-posix"
55 #define PACKAGE_URL ""
56 #define PACKAGE_VERSION "999"
57 #define STDC_HEADERS 1
58 #ifndef _DARWIN_USE_64_BIT_INODE
59 # define _DARWIN_USE_64_BIT_INODE 1
60 #endif
61
62 #else /* RUMPUSER_CONFIG */
63 #include "rumpuser_config.h"
64 #endif
65
66 #if defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)
67 #define _GNU_SOURCE
68 #endif
69
70 #if defined(HAVE_SYS_CDEFS_H)
71 #include <sys/cdefs.h>
72 #endif
73
74 /*
75 * Some versions of FreeBSD (e.g. 9.2) contain C11 stuff without
76 * any obvious way to expose the protos. Kludge around it.
77 */
78 #ifdef __FreeBSD__
79 #if __ISO_C_VISIBLE < 2011
80 #undef __ISO_C_VISIBLE
81 #define __ISO_C_VISIBLE 2011
82 #endif
83 #endif
84
85 #if defined(HAVE_SYS_PARAM_H)
86 #include <sys/param.h>
87 #endif
88
89 #ifndef MIN
90 #define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
91 #endif
92 #ifndef MAX
93 #define MAX(a,b) ((/*CONSTCOND*/(a)>(b))?(a):(b))
94 #endif
95
96 #if !defined(HAVE_GETSUBOPT)
97 static inline int
98 getsubopt(char **optionp, char * const *tokens, char **valuep)
99 {
100
101 /* TODO make a definition */
102 return -1;
103 }
104 #endif
105
106 #if !defined(HAVE_CLOCKID_T)
107 typedef int clockid_t;
108 #endif
109
110 #ifdef __ANDROID__
111 #include <stdint.h>
112 typedef uint16_t in_port_t;
113 #include <sys/select.h>
114 #define atomic_inc_uint(x) __sync_fetch_and_add(x, 1)
115 #define atomic_dec_uint(x) __sync_fetch_and_sub(x, 1)
116 #endif
117
118 /* sunny magic */
119 #if defined(__sun__)
120 # if defined(RUMPUSER_NO_FILE_OFFSET_BITS)
121 # undef _FILE_OFFSET_BITS
122 # define _FILE_OFFSET_BITS 32
123 # endif
124 #endif
125
126 #if !defined(HAVE_CLOCK_GETTIME)
127 #include <sys/time.h>
128 #define CLOCK_REALTIME 0
129 static inline int
130 clock_gettime(clockid_t clk, struct timespec *ts)
131 {
132 struct timeval tv;
133
134 if (gettimeofday(&tv, 0) == 0) {
135 ts->tv_sec = tv.tv_sec;
136 ts->tv_nsec = tv.tv_usec * 1000;
137 return 0;
138 }
139 return -1;
140 }
141 #endif
142
143 #if defined(__APPLE__)
144 #include <libkern/OSAtomic.h>
145 #define atomic_inc_uint(x) OSAtomicIncrement32((volatile int32_t *)(x))
146 #define atomic_dec_uint(x) OSAtomicDecrement32((volatile int32_t *)(x))
147 #endif
148
149 #include <sys/types.h>
150
151 #if !defined(HAVE_GETENV_R)
152 #include <errno.h>
153 #include <stdlib.h>
154 #include <string.h>
155 #include <inttypes.h>
156 static inline int
157 getenv_r(const char *name, char *buf, size_t buflen)
158 {
159 char *tmp;
160
161 if ((tmp = getenv(name)) != NULL) {
162 if (strlen(tmp) >= buflen) {
163 errno = ERANGE;
164 return -1;
165 }
166 strcpy(buf, tmp);
167 return 0;
168 } else {
169 errno = ENOENT;
170 return -1;
171 }
172 }
173 #endif
174
175 #if !defined(HAVE_POSIX_MEMALIGN)
176 #if !defined(HAVE_MEMALIGN)
177 #error method for aligned memory allocation required
178 #endif
179 #include <sys/sysmacros.h>
180 #include <stdlib.h>
181 static inline int
182 posix_memalign(void **ptr, size_t align, size_t size)
183 {
184
185 *ptr = memalign(align, size);
186 if (*ptr == NULL)
187 return ENOMEM;
188 return 0;
189 }
190 #endif
191
192 /*
193 * For NetBSD, use COHERENCY_UNIT as the lock alignment size.
194 * On other platforms, just guess it to be 64.
195 */
196 #ifdef __NetBSD__
197 #define RUMPUSER_LOCKALIGN COHERENCY_UNIT
198 #else
199 #define RUMPUSER_LOCKALIGN 64
200 #endif
201
202 #if !defined(HAVE_ALIGNED_ALLOC)
203 #include <stdlib.h>
204 static inline void *
205 aligned_alloc(size_t alignment, size_t size)
206 {
207 void *ptr;
208 int rv;
209
210 rv = posix_memalign(&ptr, alignment, size);
211 return rv ? NULL : ptr;
212 }
213 #endif
214
215 #ifndef __RCSID
216 #define __RCSID(a)
217 #endif
218
219 #ifndef INFTIM
220 #define INFTIM (-1)
221 #endif
222
223 #ifndef _DIAGASSERT
224 #define _DIAGASSERT(_p_)
225 #endif
226
227 #if !defined(HAVE_STRUCT_SOCKADDR_IN_SIN_LEN)
228 #define SIN_SETLEN(a,b)
229 #else
230 #define SIN_SETLEN(_sin_, _len_) _sin_.sin_len = _len_
231 #endif
232
233 #ifndef __predict_true
234 #define __predict_true(a) a
235 #define __predict_false(a) a
236 #endif
237
238 #ifndef __dead
239 #define __dead __attribute__((__noreturn__))
240 #endif
241
242 #ifndef __printflike
243 #ifdef __GNUC__
244 #define __printflike(a,b) __attribute__((__format__ (__printf__,a,b)))
245 #else
246 #define __printflike(a,b)
247 #endif
248 #endif
249
250 #ifndef __noinline
251 #ifdef __GNUC__
252 #define __noinline __attribute__((__noinline__))
253 #else
254 #define __noinline
255 #endif
256 #endif
257
258 #ifndef __arraycount
259 #define __arraycount(_ar_) (sizeof(_ar_)/sizeof(_ar_[0]))
260 #endif
261
262 #ifndef __UNCONST
263 #define __UNCONST(_a_) ((void *)(unsigned long)(const void *)(_a_))
264 #endif
265
266 #ifndef __CONCAT
267 #define __CONCAT(x,y) x ## y
268 #endif
269
270 #ifndef __STRING
271 #define __STRING(x) #x
272 #endif
273
274 #ifndef __NetBSD_Prereq__
275 #define __NetBSD_Prereq__(a,b,c) 0
276 #endif
277
278 #include <sys/socket.h>
279
280 #if !defined(__CMSG_ALIGN)
281 #ifdef CMSG_ALIGN
282 #define __CMSG_ALIGN(a) CMSG_ALIGN(a)
283 #endif
284 #endif
285
286 #ifndef PF_LOCAL
287 #define PF_LOCAL PF_UNIX
288 #endif
289 #ifndef AF_LOCAL
290 #define AF_LOCAL AF_UNIX
291 #endif
292
293 /* pfft, but what are you going to do? */
294 #ifndef MSG_NOSIGNAL
295 #define MSG_NOSIGNAL 0
296 #endif
297
298 #if !defined(HAVE_REGISTER_T) && !defined(RUMP_REGISTER_T)
299 #define RUMP_REGISTER_T long
300 typedef RUMP_REGISTER_T register_t;
301 #endif
302
303 #include <sys/time.h>
304
305 #ifndef TIMEVAL_TO_TIMESPEC
306 #define TIMEVAL_TO_TIMESPEC(tv, ts) \
307 do { \
308 (ts)->tv_sec = (tv)->tv_sec; \
309 (ts)->tv_nsec = (tv)->tv_usec * 1000; \
310 } while (/*CONSTCOND*/0)
311 #endif
312
313 #if !defined(HAVE_SETPROGNAME)
314 #define setprogname(a)
315 #endif
316
317 #endif /* _LIB_LIBRUMPUSER_RUMPUSER_PORT_H_ */
318