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