Home | History | Annotate | Line # | Download | only in librumpuser
rumpuser_port.h revision 1.19
      1 /*	$NetBSD: rumpuser_port.h,v 1.19 2013/07/20 18:46:15 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 #if __NetBSD_Prereq__(6,99,16)
     35 #define HAVE_CLOCK_NANOSLEEP
     36 #endif
     37 
     38 /*
     39  * This includes also statvfs1() and fstatvfs1().  They could be
     40  * reasonably easily emulated on other platforms.
     41  */
     42 #define PLATFORM_HAS_NBVFSSTAT
     43 #endif /* __NetBSD__ */
     44 
     45 /* might not be 100% accurate, maybe need to revisit later */
     46 #if defined(__linux__) || defined(__sun__)
     47 #define HAVE_CLOCK_NANOSLEEP
     48 #endif
     49 
     50 #ifdef __linux__
     51 #define _XOPEN_SOURCE 600
     52 #define _BSD_SOURCE
     53 #define _FILE_OFFSET_BITS 64
     54 #define _GNU_SOURCE
     55 #include <features.h>
     56 #endif
     57 
     58 #if defined(__sun__)
     59 #  if defined(RUMPUSER_NO_FILE_OFFSET_BITS)
     60 #    undef _FILE_OFFSET_BITS
     61 #  else
     62 #    define _FILE_OFFSET_BITS 64
     63 #  endif
     64 #endif
     65 
     66 #include <sys/types.h>
     67 #include <sys/param.h>
     68 
     69 /* maybe this should be !__NetBSD__ ? */
     70 #if defined(__linux__) || defined(__sun__) || defined(__FreeBSD__)	\
     71     || defined(__DragonFly__) || defined(__CYGWIN__)
     72 #include <errno.h>
     73 #include <stdlib.h>
     74 #include <string.h>
     75 
     76 /* this is inline simply to make this header self-contained */
     77 static inline int
     78 getenv_r(const char *name, char *buf, size_t buflen)
     79 {
     80 	char *tmp;
     81 
     82 	if ((tmp = getenv(name)) != NULL) {
     83 		if (strlen(tmp) >= buflen) {
     84 			errno = ERANGE;
     85 			return -1;
     86 		}
     87 		strcpy(buf, tmp);
     88 		return 0;
     89 	} else {
     90 		errno = ENOENT;
     91 		return -1;
     92 	}
     93 }
     94 #endif
     95 
     96 #if defined(__sun__)
     97 #include <sys/sysmacros.h>
     98 
     99 #if !defined(HAVE_POSIX_MEMALIGN)
    100 /* Solarisa 10 has memalign() but no posix_memalign() */
    101 #include <stdlib.h>
    102 
    103 static inline int
    104 posix_memalign(void **ptr, size_t align, size_t size)
    105 {
    106 
    107 	*ptr = memalign(align, size);
    108 	if (*ptr == NULL)
    109 		return ENOMEM;
    110 	return 0;
    111 }
    112 #endif /* !HAVE_POSIX_MEMALIGN */
    113 #endif /* __sun__ */
    114 
    115 #ifndef __RCSID
    116 #define __RCSID(a)
    117 #endif
    118 
    119 #ifndef INFTIM
    120 #define INFTIM (-1)
    121 #endif
    122 
    123 #ifndef _DIAGASSERT
    124 #define _DIAGASSERT(_p_)
    125 #endif
    126 
    127 #if defined(__linux__) || defined(__sun__) || defined(__CYGWIN__)
    128 #define SIN_SETLEN(a,b)
    129 #else /* BSD */
    130 #define SIN_SETLEN(_sin_, _len_) _sin_.sin_len = _len_
    131 #endif
    132 
    133 #ifndef __predict_true
    134 #define __predict_true(a) a
    135 #define __predict_false(a) a
    136 #endif
    137 
    138 #ifndef __dead
    139 #define __dead __attribute__((__noreturn__))
    140 #endif
    141 
    142 #ifndef __printflike
    143 #define __printflike(a,b)
    144 #endif
    145 
    146 #ifndef __noinline
    147 #ifdef __GNUC__
    148 #define __noinline __attribute__((__noinline__))
    149 #else
    150 #define __noinline
    151 #endif
    152 #endif
    153 
    154 #ifndef __arraycount
    155 #define __arraycount(_ar_) (sizeof(_ar_)/sizeof(_ar_[0]))
    156 #endif
    157 
    158 #ifndef __UNCONST
    159 #define __UNCONST(_a_) ((void *)(unsigned long)(const void *)(_a_))
    160 #endif
    161 
    162 #ifndef __CONCAT
    163 #define __CONCAT(x,y)	x ## y
    164 #endif
    165 
    166 #ifndef __STRING
    167 #define __STRING(x)	#x
    168 #endif
    169 
    170 #if defined(__linux__) || defined(__sun__) || defined (__CYGWIN__)
    171 #define RUMPUSER_RANDOM() random()
    172 #define RUMPUSER_USE_DEVRANDOM
    173 #else
    174 #define RUMPUSER_RANDOM() arc4random()
    175 #endif
    176 
    177 #ifndef __NetBSD_Prereq__
    178 #define __NetBSD_Prereq__(a,b,c) 0
    179 #endif
    180 
    181 #include <sys/socket.h>
    182 
    183 #if !defined(__CMSG_ALIGN)
    184 #ifdef CMSG_ALIGN
    185 #define __CMSG_ALIGN(a) CMSG_ALIGN(a)
    186 #endif
    187 #endif
    188 
    189 #ifndef PF_LOCAL
    190 #define PF_LOCAL PF_UNIX
    191 #endif
    192 #ifndef AF_LOCAL
    193 #define AF_LOCAL AF_UNIX
    194 #endif
    195 
    196 /* pfft, but what are you going to do? */
    197 #ifndef MSG_NOSIGNAL
    198 #define MSG_NOSIGNAL 0
    199 #endif
    200 
    201 #if defined(__sun__) && !defined(RUMP_REGISTER_T)
    202 #define RUMP_REGISTER_T long
    203 typedef RUMP_REGISTER_T register_t;
    204 #endif
    205 
    206 #endif /* _LIB_LIBRUMPUSER_RUMPUSER_PORT_H_ */
    207