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