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