Home | History | Annotate | Line # | Download | only in librumpuser
rumpuser_port.h revision 1.14
      1 /*	$NetBSD: rumpuser_port.h,v 1.14 2013/03/14 21:31:35 pooka Exp $	*/
      2 
      3 /*
      4  * Portability header for non-NetBSD platforms.
      5  * Quick & dirty.
      6  * Maybe should try to use the infrastructure in tools/compat instead?
      7  */
      8 
      9 /*
     10  * XXX:
     11  * There is currently no errno translation for the error values reported
     12  * by the hypercall layer.
     13  */
     14 
     15 #ifndef _LIB_LIBRUMPUSER_RUMPUSER_PORT_H_
     16 #define _LIB_LIBRUMPUSER_RUMPUSER_PORT_H_
     17 
     18 #ifdef __NetBSD__
     19 #include <sys/cdefs.h>
     20 #include <sys/param.h>
     21 
     22 #define PLATFORM_HAS_KQUEUE
     23 #define PLATFORM_HAS_CHFLAGS
     24 #define PLATFORM_HAS_NBMOUNT
     25 #define PLATFORM_HAS_NFSSVC
     26 #define PLATFORM_HAS_FSYNC_RANGE
     27 #define PLATFORM_HAS_NBSYSCTL
     28 #define PLATFORM_HAS_NBFILEHANDLE
     29 
     30 #if __NetBSD_Prereq__(5,99,48)
     31 #define PLATFORM_HAS_NBQUOTA
     32 #endif
     33 
     34 /*
     35  * This includes also statvfs1() and fstatvfs1().  They could be
     36  * reasonably easily emulated on other platforms.
     37  */
     38 #define PLATFORM_HAS_NBVFSSTAT
     39 #endif
     40 
     41 #ifdef __linux__
     42 #define _XOPEN_SOURCE 600
     43 #define _BSD_SOURCE
     44 #define _FILE_OFFSET_BITS 64
     45 #define _GNU_SOURCE
     46 #include <features.h>
     47 #endif
     48 
     49 #include <sys/types.h>
     50 #include <sys/param.h>
     51 
     52 /* maybe this should be !__NetBSD__ ? */
     53 #if defined(__linux__) || defined(__sun__) || defined(__FreeBSD__)	\
     54     || defined(__DragonFly__) || defined(__CYGWIN__)
     55 #include <errno.h>
     56 #include <stdlib.h>
     57 #include <string.h>
     58 
     59 /* this is inline simply to make this header self-contained */
     60 static inline int
     61 getenv_r(const char *name, char *buf, size_t buflen)
     62 {
     63 	char *tmp;
     64 
     65 	if ((tmp = getenv(name)) != NULL) {
     66 		if (strlen(tmp) >= buflen) {
     67 			errno = ERANGE;
     68 			return -1;
     69 		}
     70 		strcpy(buf, tmp);
     71 		return 0;
     72 	} else {
     73 		errno = ENOENT;
     74 		return -1;
     75 	}
     76 }
     77 #endif
     78 
     79 #if defined(__sun__)
     80 #include <sys/sysmacros.h>
     81 
     82 #if !defined(HAVE_POSIX_MEMALIGN)
     83 /* Solarisa 10 has memalign() but no posix_memalign() */
     84 #include <stdlib.h>
     85 
     86 static inline int
     87 posix_memalign(void **ptr, size_t align, size_t size)
     88 {
     89 
     90 	*ptr = memalign(align, size);
     91 	if (*ptr == NULL)
     92 		return ENOMEM;
     93 	return 0;
     94 }
     95 #endif /* !HAVE_POSIX_MEMALIGN */
     96 #endif /* __sun__ */
     97 
     98 #ifndef __RCSID
     99 #define __RCSID(a)
    100 #endif
    101 
    102 #ifndef INFTIM
    103 #define INFTIM (-1)
    104 #endif
    105 
    106 #ifndef _DIAGASSERT
    107 #define _DIAGASSERT(_p_)
    108 #endif
    109 
    110 #if defined(__linux__) || defined(__sun__) || defined(__CYGWIN__)
    111 #define SIN_SETLEN(a,b)
    112 #else /* BSD */
    113 #define SIN_SETLEN(_sin_, _len_) _sin_.sin_len = _len_
    114 #endif
    115 
    116 #ifndef __predict_true
    117 #define __predict_true(a) a
    118 #define __predict_false(a) a
    119 #endif
    120 
    121 #ifndef __dead
    122 #define __dead __attribute__((__noreturn__))
    123 #endif
    124 
    125 #ifndef __printflike
    126 #define __printflike(a,b)
    127 #endif
    128 
    129 #ifndef __noinline
    130 #ifdef __GNUC__
    131 #define __noinline __attribute__((__noinline__))
    132 #else
    133 #define __noinline
    134 #endif
    135 #endif
    136 
    137 #ifndef __arraycount
    138 #define __arraycount(_ar_) (sizeof(_ar_)/sizeof(_ar_[0]))
    139 #endif
    140 
    141 #ifndef __UNCONST
    142 #define __UNCONST(_a_) ((void *)(unsigned long)(const void *)(_a_))
    143 #endif
    144 
    145 #if defined(__linux__) || defined(__sun__) || defined (__CYGWIN__)
    146 #define arc4random() random()
    147 #define RUMPUSER_USE_RANDOM
    148 #endif
    149 
    150 #ifndef __NetBSD_Prereq__
    151 #define __NetBSD_Prereq__(a,b,c) 0
    152 #endif
    153 
    154 #include <sys/socket.h>
    155 
    156 #if !defined(__CMSG_ALIGN)
    157 #ifdef CMSG_ALIGN
    158 #define __CMSG_ALIGN(a) CMSG_ALIGN(a)
    159 #endif
    160 #endif
    161 
    162 #ifndef PF_LOCAL
    163 #define PF_LOCAL PF_UNIX
    164 #endif
    165 #ifndef AF_LOCAL
    166 #define AF_LOCAL AF_UNIX
    167 #endif
    168 
    169 /* pfft, but what are you going to do? */
    170 #ifndef MSG_NOSIGNAL
    171 #define MSG_NOSIGNAL 0
    172 #endif
    173 
    174 #if defined(__sun__) && !defined(RUMP_REGISTER_T)
    175 #define RUMP_REGISTER_T long
    176 typedef RUMP_REGISTER_T register_t;
    177 #endif
    178 
    179 #endif /* _LIB_LIBRUMPUSER_RUMPUSER_PORT_H_ */
    180