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