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