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