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