2014-07-23 02:41:58 +04:00
|
|
|
/* $NetBSD: rumpuser_port.h,v 1.34 2014/07/22 22:41:58 justin Exp $ */
|
2012-07-27 13:09:05 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Portability header for non-NetBSD platforms.
|
|
|
|
* Quick & dirty.
|
|
|
|
* Maybe should try to use the infrastructure in tools/compat instead?
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LIB_LIBRUMPUSER_RUMPUSER_PORT_H_
|
|
|
|
#define _LIB_LIBRUMPUSER_RUMPUSER_PORT_H_
|
|
|
|
|
|
|
|
#ifdef __NetBSD__
|
|
|
|
#include <sys/cdefs.h>
|
2012-08-25 22:00:06 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
|
|
|
|
#define PLATFORM_HAS_KQUEUE
|
|
|
|
#define PLATFORM_HAS_CHFLAGS
|
|
|
|
#define PLATFORM_HAS_NBMOUNT
|
|
|
|
#define PLATFORM_HAS_NFSSVC
|
|
|
|
#define PLATFORM_HAS_FSYNC_RANGE
|
|
|
|
#define PLATFORM_HAS_NBSYSCTL
|
2012-09-03 15:33:35 +04:00
|
|
|
#define PLATFORM_HAS_NBFILEHANDLE
|
2014-03-21 20:03:35 +04:00
|
|
|
#ifndef HAVE_PTHREAD_SETNAME_3
|
|
|
|
#define HAVE_PTHREAD_SETNAME_3
|
2014-03-21 16:28:54 +04:00
|
|
|
#endif
|
2012-08-25 22:00:06 +04:00
|
|
|
|
2013-09-10 21:58:39 +04:00
|
|
|
#define PLATFORM_HAS_STRSUFTOLL
|
|
|
|
#define PLATFORM_HAS_SETGETPROGNAME
|
|
|
|
|
2012-08-25 22:00:06 +04:00
|
|
|
#if __NetBSD_Prereq__(5,99,48)
|
|
|
|
#define PLATFORM_HAS_NBQUOTA
|
|
|
|
#endif
|
|
|
|
|
2013-04-28 17:17:24 +04:00
|
|
|
#if __NetBSD_Prereq__(6,99,16)
|
|
|
|
#define HAVE_CLOCK_NANOSLEEP
|
|
|
|
#endif
|
|
|
|
|
2012-08-25 22:00:06 +04:00
|
|
|
/*
|
|
|
|
* This includes also statvfs1() and fstatvfs1(). They could be
|
|
|
|
* reasonably easily emulated on other platforms.
|
|
|
|
*/
|
|
|
|
#define PLATFORM_HAS_NBVFSSTAT
|
2013-04-28 17:17:24 +04:00
|
|
|
#endif /* __NetBSD__ */
|
|
|
|
|
2014-04-02 21:09:23 +04:00
|
|
|
#ifndef MIN
|
|
|
|
#define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
|
|
|
|
#endif
|
|
|
|
#ifndef MAX
|
|
|
|
#define MAX(a,b) ((/*CONSTCOND*/(a)>(b))?(a):(b))
|
|
|
|
#endif
|
|
|
|
|
2013-04-28 17:17:24 +04:00
|
|
|
/* might not be 100% accurate, maybe need to revisit later */
|
2014-04-02 21:09:23 +04:00
|
|
|
#if (defined(__linux__) && !defined(__ANDROID__)) || defined(__sun__)
|
2013-04-28 17:17:24 +04:00
|
|
|
#define HAVE_CLOCK_NANOSLEEP
|
2012-07-27 13:09:05 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
#define _XOPEN_SOURCE 600
|
|
|
|
#define _BSD_SOURCE
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#endif
|
|
|
|
|
2014-04-02 21:09:23 +04:00
|
|
|
#ifdef __ANDROID__
|
|
|
|
#include <stdint.h>
|
|
|
|
typedef uint16_t in_port_t;
|
|
|
|
#include <sys/select.h>
|
|
|
|
#define atomic_inc_uint(x) __sync_fetch_and_add(x, 1)
|
|
|
|
#define atomic_dec_uint(x) __sync_fetch_and_sub(x, 1)
|
|
|
|
static inline int getsubopt(char **optionp, char * const *tokens, char **valuep);
|
|
|
|
static inline int
|
|
|
|
getsubopt(char **optionp, char * const *tokens, char **valuep)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* TODO make a definition */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-03-20 16:59:10 +04:00
|
|
|
#if defined(__sun__)
|
|
|
|
# if defined(RUMPUSER_NO_FILE_OFFSET_BITS)
|
|
|
|
# undef _FILE_OFFSET_BITS
|
|
|
|
# endif
|
2013-03-20 16:30:13 +04:00
|
|
|
#endif
|
|
|
|
|
2013-10-27 20:39:46 +04:00
|
|
|
#if defined(__APPLE__)
|
|
|
|
#define __dead __attribute__((noreturn))
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
|
|
|
#include <libkern/OSAtomic.h>
|
|
|
|
#define atomic_inc_uint(x) OSAtomicIncrement32((volatile int32_t *)(x))
|
|
|
|
#define atomic_dec_uint(x) OSAtomicDecrement32((volatile int32_t *)(x))
|
|
|
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
#define CLOCK_REALTIME 0
|
|
|
|
typedef int clockid_t;
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
clock_gettime(clockid_t clk, struct timespec *ts)
|
|
|
|
{
|
|
|
|
struct timeval tv;
|
|
|
|
|
|
|
|
if (gettimeofday(&tv, 0) == 0) {
|
|
|
|
ts->tv_sec = tv.tv_sec;
|
|
|
|
ts->tv_nsec = tv.tv_usec * 1000;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2012-07-27 13:09:05 +04:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
|
2014-01-08 05:47:31 +04:00
|
|
|
/* NetBSD is the only(?) platform with getenv_r() */
|
|
|
|
#if !defined(__NetBSD__)
|
2012-08-25 22:00:06 +04:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2013-10-27 20:39:46 +04:00
|
|
|
#include <inttypes.h>
|
2012-08-25 22:00:06 +04:00
|
|
|
|
|
|
|
/* this is inline simply to make this header self-contained */
|
|
|
|
static inline int
|
|
|
|
getenv_r(const char *name, char *buf, size_t buflen)
|
|
|
|
{
|
|
|
|
char *tmp;
|
|
|
|
|
|
|
|
if ((tmp = getenv(name)) != NULL) {
|
|
|
|
if (strlen(tmp) >= buflen) {
|
|
|
|
errno = ERANGE;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
strcpy(buf, tmp);
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
errno = ENOENT;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-03-15 01:31:35 +04:00
|
|
|
#if defined(__sun__)
|
2013-01-18 01:42:22 +04:00
|
|
|
#include <sys/sysmacros.h>
|
|
|
|
|
2013-03-15 01:31:35 +04:00
|
|
|
#if !defined(HAVE_POSIX_MEMALIGN)
|
2013-01-18 01:42:22 +04:00
|
|
|
/* Solarisa 10 has memalign() but no posix_memalign() */
|
2012-11-18 23:29:40 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
posix_memalign(void **ptr, size_t align, size_t size)
|
|
|
|
{
|
|
|
|
|
|
|
|
*ptr = memalign(align, size);
|
|
|
|
if (*ptr == NULL)
|
|
|
|
return ENOMEM;
|
|
|
|
return 0;
|
|
|
|
}
|
2013-03-15 01:31:35 +04:00
|
|
|
#endif /* !HAVE_POSIX_MEMALIGN */
|
2012-11-18 23:29:40 +04:00
|
|
|
#endif /* __sun__ */
|
|
|
|
|
2012-07-27 13:09:05 +04:00
|
|
|
#ifndef __RCSID
|
|
|
|
#define __RCSID(a)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef INFTIM
|
|
|
|
#define INFTIM (-1)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _DIAGASSERT
|
|
|
|
#define _DIAGASSERT(_p_)
|
|
|
|
#endif
|
|
|
|
|
2013-01-15 01:00:16 +04:00
|
|
|
#if defined(__linux__) || defined(__sun__) || defined(__CYGWIN__)
|
2012-11-26 20:30:14 +04:00
|
|
|
#define SIN_SETLEN(a,b)
|
2012-07-27 13:09:05 +04:00
|
|
|
#else /* BSD */
|
2012-11-26 20:30:14 +04:00
|
|
|
#define SIN_SETLEN(_sin_, _len_) _sin_.sin_len = _len_
|
2012-07-27 13:09:05 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __predict_true
|
|
|
|
#define __predict_true(a) a
|
|
|
|
#define __predict_false(a) a
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __dead
|
2012-11-23 01:23:08 +04:00
|
|
|
#define __dead __attribute__((__noreturn__))
|
2012-07-27 13:09:05 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __printflike
|
2014-02-26 00:58:18 +04:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#define __printflike(a,b) __attribute__((__format__ (__printf__,a,b)))
|
|
|
|
#else
|
2012-07-27 13:09:05 +04:00
|
|
|
#define __printflike(a,b)
|
|
|
|
#endif
|
2014-02-26 00:58:18 +04:00
|
|
|
#endif
|
2012-07-27 13:09:05 +04:00
|
|
|
|
2012-08-25 22:00:06 +04:00
|
|
|
#ifndef __noinline
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#define __noinline __attribute__((__noinline__))
|
|
|
|
#else
|
|
|
|
#define __noinline
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2012-07-27 13:09:05 +04:00
|
|
|
#ifndef __arraycount
|
|
|
|
#define __arraycount(_ar_) (sizeof(_ar_)/sizeof(_ar_[0]))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __UNCONST
|
|
|
|
#define __UNCONST(_a_) ((void *)(unsigned long)(const void *)(_a_))
|
|
|
|
#endif
|
|
|
|
|
2013-07-20 22:46:15 +04:00
|
|
|
#ifndef __CONCAT
|
|
|
|
#define __CONCAT(x,y) x ## y
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __STRING
|
|
|
|
#define __STRING(x) #x
|
|
|
|
#endif
|
|
|
|
|
2014-07-23 02:41:58 +04:00
|
|
|
#if (defined(__NetBSD__) && __NetBSD_Version__ > 600000000) || \
|
|
|
|
defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
|
|
|
|
#define PLATFORM_HAS_ARC4RANDOM_BUF
|
2012-07-27 13:09:05 +04:00
|
|
|
#endif
|
|
|
|
|
2012-08-25 22:00:06 +04:00
|
|
|
#ifndef __NetBSD_Prereq__
|
|
|
|
#define __NetBSD_Prereq__(a,b,c) 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/socket.h>
|
2012-11-18 23:29:40 +04:00
|
|
|
|
|
|
|
#if !defined(__CMSG_ALIGN)
|
2012-08-25 22:00:06 +04:00
|
|
|
#ifdef CMSG_ALIGN
|
|
|
|
#define __CMSG_ALIGN(a) CMSG_ALIGN(a)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2012-11-18 23:29:40 +04:00
|
|
|
#ifndef PF_LOCAL
|
|
|
|
#define PF_LOCAL PF_UNIX
|
|
|
|
#endif
|
|
|
|
#ifndef AF_LOCAL
|
|
|
|
#define AF_LOCAL AF_UNIX
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* pfft, but what are you going to do? */
|
|
|
|
#ifndef MSG_NOSIGNAL
|
|
|
|
#define MSG_NOSIGNAL 0
|
|
|
|
#endif
|
|
|
|
|
2014-04-02 21:09:23 +04:00
|
|
|
#if (defined(__sun__) || defined(__ANDROID__)) && !defined(RUMP_REGISTER_T)
|
2012-11-21 21:41:27 +04:00
|
|
|
#define RUMP_REGISTER_T long
|
|
|
|
typedef RUMP_REGISTER_T register_t;
|
|
|
|
#endif
|
|
|
|
|
2013-07-22 12:58:31 +04:00
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
#ifndef TIMEVAL_TO_TIMESPEC
|
|
|
|
#define TIMEVAL_TO_TIMESPEC(tv, ts) \
|
|
|
|
do { \
|
|
|
|
(ts)->tv_sec = (tv)->tv_sec; \
|
|
|
|
(ts)->tv_nsec = (tv)->tv_usec * 1000; \
|
|
|
|
} while (/*CONSTCOND*/0)
|
|
|
|
#endif
|
|
|
|
|
2014-01-15 20:53:15 +04:00
|
|
|
#ifndef PLATFORM_HAS_SETGETPROGNAME
|
|
|
|
#define setprogname(a)
|
|
|
|
#endif
|
|
|
|
|
2012-07-27 13:09:05 +04:00
|
|
|
#endif /* _LIB_LIBRUMPUSER_RUMPUSER_PORT_H_ */
|