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