Home | History | Annotate | Line # | Download | only in librumpuser
rumpuser_port.h revision 1.48
      1 /*	$NetBSD: rumpuser_port.h,v 1.48 2017/01/12 18:23:04 christos 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 #include <poll.h>
    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 /* at least GNU Hurd does not specify various common hardcoded constants */
    321 #include <limits.h>
    322 #ifndef MAXPATHLEN
    323 #define MAXPATHLEN	4096
    324 #endif
    325 #ifndef PATH_MAX
    326 #define PATH_MAX	MAXPATHLEN
    327 #endif
    328 #ifndef MAXHOSTNAMELEN
    329 #define MAXHOSTNAMELEN	256
    330 #endif
    331 
    332 #endif /* _LIB_LIBRUMPUSER_RUMPUSER_PORT_H_ */
    333