rumpuser_port.h revision 1.9 1 /* $NetBSD: rumpuser_port.h,v 1.9 2012/11/26 19:57:24 pooka Exp $ */
2
3 /*
4 * Portability header for non-NetBSD platforms.
5 * Quick & dirty.
6 * Maybe should try to use the infrastructure in tools/compat instead?
7 */
8
9 /*
10 * XXX:
11 * There is currently no errno translation for the error values reported
12 * by the hypercall layer.
13 */
14
15 #ifndef _LIB_LIBRUMPUSER_RUMPUSER_PORT_H_
16 #define _LIB_LIBRUMPUSER_RUMPUSER_PORT_H_
17
18 #ifdef __NetBSD__
19 #include <sys/cdefs.h>
20 #include <sys/param.h>
21
22 #define PLATFORM_HAS_KQUEUE
23 #define PLATFORM_HAS_CHFLAGS
24 #define PLATFORM_HAS_NBMOUNT
25 #define PLATFORM_HAS_NFSSVC
26 #define PLATFORM_HAS_FSYNC_RANGE
27 #define PLATFORM_HAS_NBSYSCTL
28 #define PLATFORM_HAS_NBFILEHANDLE
29
30 #if __NetBSD_Prereq__(5,99,48)
31 #define PLATFORM_HAS_NBQUOTA
32 #endif
33
34 /*
35 * This includes also statvfs1() and fstatvfs1(). They could be
36 * reasonably easily emulated on other platforms.
37 */
38 #define PLATFORM_HAS_NBVFSSTAT
39 #endif
40
41 #ifdef __linux__
42 #define _XOPEN_SOURCE 600
43 #define _BSD_SOURCE
44 #define _FILE_OFFSET_BITS 64
45 #define _GNU_SOURCE
46 #include <features.h>
47 #endif
48
49 #include <sys/types.h>
50 #include <sys/param.h>
51
52 /* maybe this should be !__NetBSD__ ? */
53 #if defined(__linux__) || defined(__sun__) || defined(__FreeBSD__) \
54 defined(__DragonFly__)
55 #include <errno.h>
56 #include <stdlib.h>
57 #include <string.h>
58
59 /* this is inline simply to make this header self-contained */
60 static inline int
61 getenv_r(const char *name, char *buf, size_t buflen)
62 {
63 char *tmp;
64
65 if ((tmp = getenv(name)) != NULL) {
66 if (strlen(tmp) >= buflen) {
67 errno = ERANGE;
68 return -1;
69 }
70 strcpy(buf, tmp);
71 return 0;
72 } else {
73 errno = ENOENT;
74 return -1;
75 }
76 }
77 #endif
78
79 /* Solarisa 10 has memalign() but no posix_memalign() */
80 #if defined(__sun__)
81 #include <stdlib.h>
82
83 static inline int
84 posix_memalign(void **ptr, size_t align, size_t size)
85 {
86
87 *ptr = memalign(align, size);
88 if (*ptr == NULL)
89 return ENOMEM;
90 return 0;
91 }
92 #endif /* __sun__ */
93
94 #ifndef __RCSID
95 #define __RCSID(a)
96 #endif
97
98 #ifndef INFTIM
99 #define INFTIM (-1)
100 #endif
101
102 #ifndef _DIAGASSERT
103 #define _DIAGASSERT(_p_)
104 #endif
105
106 #if defined(__linux__) || defined(__sun__)
107 #define SIN_SETLEN(a,b)
108 #else /* BSD */
109 #define SIN_SETLEN(_sin_, _len_) _sin_.sin_len = _len_
110 #endif
111
112 #ifndef __predict_true
113 #define __predict_true(a) a
114 #define __predict_false(a) a
115 #endif
116
117 #ifndef __dead
118 #define __dead __attribute__((__noreturn__))
119 #endif
120
121 #ifndef __printflike
122 #define __printflike(a,b)
123 #endif
124
125 #ifndef __noinline
126 #ifdef __GNUC__
127 #define __noinline __attribute__((__noinline__))
128 #else
129 #define __noinline
130 #endif
131 #endif
132
133 #ifndef __arraycount
134 #define __arraycount(_ar_) (sizeof(_ar_)/sizeof(_ar_[0]))
135 #endif
136
137 #ifndef __UNCONST
138 #define __UNCONST(_a_) ((void *)(unsigned long)(const void *)(_a_))
139 #endif
140
141 #if defined(__linux__) || defined(__sun__)
142 #define arc4random() random()
143 #endif
144
145 #ifndef __NetBSD_Prereq__
146 #define __NetBSD_Prereq__(a,b,c) 0
147 #endif
148
149 #include <sys/socket.h>
150
151 #if !defined(__CMSG_ALIGN)
152 #ifdef CMSG_ALIGN
153 #define __CMSG_ALIGN(a) CMSG_ALIGN(a)
154 #endif
155 #endif
156
157 #ifndef PF_LOCAL
158 #define PF_LOCAL PF_UNIX
159 #endif
160 #ifndef AF_LOCAL
161 #define AF_LOCAL AF_UNIX
162 #endif
163
164 /* pfft, but what are you going to do? */
165 #ifndef MSG_NOSIGNAL
166 #define MSG_NOSIGNAL 0
167 #endif
168
169 #if defined(__sun__) && !defined(RUMP_REGISTER_T)
170 #define RUMP_REGISTER_T long
171 typedef RUMP_REGISTER_T register_t;
172 #endif
173
174 #endif /* _LIB_LIBRUMPUSER_RUMPUSER_PORT_H_ */
175