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