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