Home | History | Annotate | Line # | Download | only in librumpuser
rumpuser_port.h revision 1.39
      1 /*	$NetBSD: rumpuser_port.h,v 1.39 2014/11/05 01:37:27 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 _XOPEN_SOURCE 600
     67 #define _BSD_SOURCE
     68 #define _GNU_SOURCE
     69 #endif
     70 
     71 #if defined(HAVE_SYS_CDEFS_H)
     72 #include <sys/cdefs.h>
     73 #endif
     74 #if defined(HAVE_SYS_PARAM_H)
     75 #include <sys/param.h>
     76 #endif
     77 
     78 #ifndef MIN
     79 #define MIN(a,b)        ((/*CONSTCOND*/(a)<(b))?(a):(b))
     80 #endif
     81 #ifndef MAX
     82 #define MAX(a,b)        ((/*CONSTCOND*/(a)>(b))?(a):(b))
     83 #endif
     84 
     85 #if !defined(HAVE_GETSUBOPT)
     86 static inline int
     87 getsubopt(char **optionp, char * const *tokens, char **valuep)
     88 {
     89 
     90 	/* TODO make a definition */
     91 	return -1;
     92 }
     93 #endif
     94 
     95 #ifdef __ANDROID__
     96 #include <stdint.h>
     97 typedef uint16_t in_port_t;
     98 #include <sys/select.h>
     99 #define atomic_inc_uint(x)  __sync_fetch_and_add(x, 1)
    100 #define atomic_dec_uint(x)  __sync_fetch_and_sub(x, 1)
    101 #endif
    102 
    103 /* sunny magic */
    104 #if defined(__sun__)
    105 #  if defined(RUMPUSER_NO_FILE_OFFSET_BITS)
    106 #    undef _FILE_OFFSET_BITS
    107 #    define _FILE_OFFSET_BITS 32
    108 #  endif
    109 #endif
    110 
    111 #if !defined(HAVE_CLOCKID_T)
    112 typedef int clockid_t;
    113 #endif
    114 
    115 #if !defined(HAVE_CLOCK_GETTIME)
    116 #include <sys/time.h>
    117 #define	CLOCK_REALTIME	0
    118 static inline int
    119 clock_gettime(clockid_t clk, struct timespec *ts)
    120 {
    121 	struct timeval tv;
    122 
    123 	if (gettimeofday(&tv, 0) == 0) {
    124 		ts->tv_sec = tv.tv_sec;
    125 		ts->tv_nsec = tv.tv_usec * 1000;
    126 		return 0;
    127 	}
    128 	return -1;
    129 }
    130 #endif
    131 
    132 #if defined(__APPLE__)
    133 #include <libkern/OSAtomic.h>
    134 #define	atomic_inc_uint(x)	OSAtomicIncrement32((volatile int32_t *)(x))
    135 #define	atomic_dec_uint(x)	OSAtomicDecrement32((volatile int32_t *)(x))
    136 #endif
    137 
    138 #include <sys/types.h>
    139 
    140 #if !defined(HAVE_GETENV_R)
    141 #include <errno.h>
    142 #include <stdlib.h>
    143 #include <string.h>
    144 #include <inttypes.h>
    145 static inline int
    146 getenv_r(const char *name, char *buf, size_t buflen)
    147 {
    148 	char *tmp;
    149 
    150 	if ((tmp = getenv(name)) != NULL) {
    151 		if (strlen(tmp) >= buflen) {
    152 			errno = ERANGE;
    153 			return -1;
    154 		}
    155 		strcpy(buf, tmp);
    156 		return 0;
    157 	} else {
    158 		errno = ENOENT;
    159 		return -1;
    160 	}
    161 }
    162 #endif
    163 
    164 #if !defined(HAVE_POSIX_MEMALIGN)
    165 #if !defined(HAVE_MEMALIGN)
    166 #error method for aligned memory allocation required
    167 #endif
    168 #include <sys/sysmacros.h>
    169 #include <stdlib.h>
    170 static inline int
    171 posix_memalign(void **ptr, size_t align, size_t size)
    172 {
    173 
    174 	*ptr = memalign(align, size);
    175 	if (*ptr == NULL)
    176 		return ENOMEM;
    177 	return 0;
    178 }
    179 #endif
    180 
    181 /*
    182  * For NetBSD, use COHERENCY_UNIT as the lock alignment size.
    183  * On other platforms, just guess it to be 64.
    184  */
    185 #ifdef __NetBSD__
    186 #define RUMPUSER_LOCKALIGN COHERENCY_UNIT
    187 #else
    188 #define RUMPUSER_LOCKALIGN 64
    189 #endif
    190 
    191 #if !defined(HAVE_ALIGNED_ALLOC)
    192 #include <stdlib.h>
    193 static inline void *
    194 aligned_alloc(size_t alignment, size_t size)
    195 {
    196 	void *ptr;
    197 	int rv;
    198 
    199 	rv = posix_memalign(&ptr, alignment, size);
    200 	return rv ? NULL : ptr;
    201 }
    202 #endif
    203 
    204 #ifndef __RCSID
    205 #define __RCSID(a)
    206 #endif
    207 
    208 #ifndef INFTIM
    209 #define INFTIM (-1)
    210 #endif
    211 
    212 #ifndef _DIAGASSERT
    213 #define _DIAGASSERT(_p_)
    214 #endif
    215 
    216 #if !defined(HAVE_STRUCT_SOCKADDR_IN_SIN_LEN)
    217 #define SIN_SETLEN(a,b)
    218 #else
    219 #define SIN_SETLEN(_sin_, _len_) _sin_.sin_len = _len_
    220 #endif
    221 
    222 #ifndef __predict_true
    223 #define __predict_true(a) a
    224 #define __predict_false(a) a
    225 #endif
    226 
    227 #ifndef __dead
    228 #define __dead __attribute__((__noreturn__))
    229 #endif
    230 
    231 #ifndef __printflike
    232 #ifdef __GNUC__
    233 #define __printflike(a,b) __attribute__((__format__ (__printf__,a,b)))
    234 #else
    235 #define __printflike(a,b)
    236 #endif
    237 #endif
    238 
    239 #ifndef __noinline
    240 #ifdef __GNUC__
    241 #define __noinline __attribute__((__noinline__))
    242 #else
    243 #define __noinline
    244 #endif
    245 #endif
    246 
    247 #ifndef __arraycount
    248 #define __arraycount(_ar_) (sizeof(_ar_)/sizeof(_ar_[0]))
    249 #endif
    250 
    251 #ifndef __UNCONST
    252 #define __UNCONST(_a_) ((void *)(unsigned long)(const void *)(_a_))
    253 #endif
    254 
    255 #ifndef __CONCAT
    256 #define __CONCAT(x,y)	x ## y
    257 #endif
    258 
    259 #ifndef __STRING
    260 #define __STRING(x)	#x
    261 #endif
    262 
    263 #ifndef __NetBSD_Prereq__
    264 #define __NetBSD_Prereq__(a,b,c) 0
    265 #endif
    266 
    267 #include <sys/socket.h>
    268 
    269 #if !defined(__CMSG_ALIGN)
    270 #ifdef CMSG_ALIGN
    271 #define __CMSG_ALIGN(a) CMSG_ALIGN(a)
    272 #endif
    273 #endif
    274 
    275 #ifndef PF_LOCAL
    276 #define PF_LOCAL PF_UNIX
    277 #endif
    278 #ifndef AF_LOCAL
    279 #define AF_LOCAL AF_UNIX
    280 #endif
    281 
    282 /* pfft, but what are you going to do? */
    283 #ifndef MSG_NOSIGNAL
    284 #define MSG_NOSIGNAL 0
    285 #endif
    286 
    287 #if !defined(HAVE_REGISTER_T) && !defined(RUMP_REGISTER_T)
    288 #define RUMP_REGISTER_T long
    289 typedef RUMP_REGISTER_T register_t;
    290 #endif
    291 
    292 #include <sys/time.h>
    293 
    294 #ifndef TIMEVAL_TO_TIMESPEC
    295 #define TIMEVAL_TO_TIMESPEC(tv, ts)		\
    296 do {						\
    297 	(ts)->tv_sec  = (tv)->tv_sec;		\
    298 	(ts)->tv_nsec = (tv)->tv_usec * 1000;	\
    299 } while (/*CONSTCOND*/0)
    300 #endif
    301 
    302 #if !defined(HAVE_SETPROGNAME)
    303 #define setprogname(a)
    304 #endif
    305 
    306 #endif /* _LIB_LIBRUMPUSER_RUMPUSER_PORT_H_ */
    307