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