Module Name: src Committed By: rmind Date: Sun Oct 27 16:39:47 UTC 2013
Modified Files: src/lib/librumpuser: rumpuser.c rumpuser_dl.c rumpuser_port.h rumpuser_pth.c rumpuser_sp.c Log Message: librumpuser: add some #ifdef __APPLE__ and missing bits to build it on OS X. OK pooka@ To generate a diff of this commit: cvs rdiff -u -r1.54 -r1.55 src/lib/librumpuser/rumpuser.c cvs rdiff -u -r1.21 -r1.22 src/lib/librumpuser/rumpuser_dl.c \ src/lib/librumpuser/rumpuser_port.h cvs rdiff -u -r1.33 -r1.34 src/lib/librumpuser/rumpuser_pth.c cvs rdiff -u -r1.59 -r1.60 src/lib/librumpuser/rumpuser_sp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/librumpuser/rumpuser.c diff -u src/lib/librumpuser/rumpuser.c:1.54 src/lib/librumpuser/rumpuser.c:1.55 --- src/lib/librumpuser/rumpuser.c:1.54 Wed Aug 14 08:29:25 2013 +++ src/lib/librumpuser/rumpuser.c Sun Oct 27 16:39:46 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: rumpuser.c,v 1.54 2013/08/14 08:29:25 pooka Exp $ */ +/* $NetBSD: rumpuser.c,v 1.55 2013/10/27 16:39:46 rmind Exp $ */ /* * Copyright (c) 2007-2010 Antti Kantee. All Rights Reserved. @@ -28,7 +28,7 @@ #include "rumpuser_port.h" #if !defined(lint) -__RCSID("$NetBSD: rumpuser.c,v 1.54 2013/08/14 08:29:25 pooka Exp $"); +__RCSID("$NetBSD: rumpuser.c,v 1.55 2013/10/27 16:39:46 rmind Exp $"); #endif /* !lint */ #include <sys/ioctl.h> @@ -43,7 +43,12 @@ __RCSID("$NetBSD: rumpuser.c,v 1.54 2013 #include <sys/dkio.h> #endif -#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) +#if defined(__NetBSD__) || defined(__FreeBSD__) || \ + defined(__DragonFly__) || defined(__APPLE__) +#define __BSD__ +#endif + +#if defined(__BSD__) #include <sys/sysctl.h> #endif @@ -533,7 +538,7 @@ gethostncpu(void) { int ncpu = 1; -#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) +#if defined(__BSD__) size_t sz = sizeof(ncpu); sysctlbyname("hw.ncpu", &ncpu, &sz, NULL, 0); @@ -607,7 +612,7 @@ rumpuser_putchar(int c) putchar(c); } -void +__dead void rumpuser_exit(int rv) { Index: src/lib/librumpuser/rumpuser_dl.c diff -u src/lib/librumpuser/rumpuser_dl.c:1.21 src/lib/librumpuser/rumpuser_dl.c:1.22 --- src/lib/librumpuser/rumpuser_dl.c:1.21 Tue Jul 30 18:56:03 2013 +++ src/lib/librumpuser/rumpuser_dl.c Sun Oct 27 16:39:46 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: rumpuser_dl.c,v 1.21 2013/07/30 18:56:03 pooka Exp $ */ +/* $NetBSD: rumpuser_dl.c,v 1.22 2013/10/27 16:39:46 rmind Exp $ */ /* * Copyright (c) 2009 Antti Kantee. All Rights Reserved. @@ -40,7 +40,7 @@ #include "rumpuser_port.h" #if !defined(lint) -__RCSID("$NetBSD: rumpuser_dl.c,v 1.21 2013/07/30 18:56:03 pooka Exp $"); +__RCSID("$NetBSD: rumpuser_dl.c,v 1.22 2013/10/27 16:39:46 rmind Exp $"); #endif /* !lint */ #include <sys/types.h> @@ -48,7 +48,6 @@ __RCSID("$NetBSD: rumpuser_dl.c,v 1.21 2 #include <assert.h> #include <dlfcn.h> -#include <elf.h> #include <errno.h> #include <fcntl.h> #include <stdio.h> @@ -61,6 +60,7 @@ __RCSID("$NetBSD: rumpuser_dl.c,v 1.21 2 #if defined(__ELF__) && (defined(__NetBSD__) || defined(__FreeBSD__) \ || (defined(__sun__) && defined(__svr4__))) || defined(__linux__) \ || defined(__DragonFly__) +#include <elf.h> #include <link.h> static size_t symtabsize = 0, strtabsize = 0; Index: src/lib/librumpuser/rumpuser_port.h diff -u src/lib/librumpuser/rumpuser_port.h:1.21 src/lib/librumpuser/rumpuser_port.h:1.22 --- src/lib/librumpuser/rumpuser_port.h:1.21 Tue Sep 10 17:58:39 2013 +++ src/lib/librumpuser/rumpuser_port.h Sun Oct 27 16:39:46 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: rumpuser_port.h,v 1.21 2013/09/10 17:58:39 pooka Exp $ */ +/* $NetBSD: rumpuser_port.h,v 1.22 2013/10/27 16:39:46 rmind Exp $ */ /* * Portability header for non-NetBSD platforms. @@ -68,15 +68,43 @@ # endif #endif +#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 + #include <sys/types.h> #include <sys/param.h> /* maybe this should be !__NetBSD__ ? */ #if defined(__linux__) || defined(__sun__) || defined(__FreeBSD__) \ - || defined(__DragonFly__) || defined(__CYGWIN__) + || defined(__DragonFly__) || defined(__APPLE__) || defined(__CYGWIN__) #include <errno.h> #include <stdlib.h> #include <string.h> +#include <inttypes.h> /* this is inline simply to make this header self-contained */ static inline int Index: src/lib/librumpuser/rumpuser_pth.c diff -u src/lib/librumpuser/rumpuser_pth.c:1.33 src/lib/librumpuser/rumpuser_pth.c:1.34 --- src/lib/librumpuser/rumpuser_pth.c:1.33 Thu Sep 26 00:41:51 2013 +++ src/lib/librumpuser/rumpuser_pth.c Sun Oct 27 16:39:46 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: rumpuser_pth.c,v 1.33 2013/09/26 00:41:51 rmind Exp $ */ +/* $NetBSD: rumpuser_pth.c,v 1.34 2013/10/27 16:39:46 rmind Exp $ */ /* * Copyright (c) 2007-2010 Antti Kantee. All Rights Reserved. @@ -28,7 +28,7 @@ #include "rumpuser_port.h" #if !defined(lint) -__RCSID("$NetBSD: rumpuser_pth.c,v 1.33 2013/09/26 00:41:51 rmind Exp $"); +__RCSID("$NetBSD: rumpuser_pth.c,v 1.34 2013/10/27 16:39:46 rmind Exp $"); #endif /* !lint */ #include <sys/queue.h> @@ -258,8 +258,10 @@ rumpuser_mutex_owner(struct rumpuser_mtx struct rumpuser_rw { pthread_rwlock_t pthrw; +#if !defined(__APPLE__) char pad[64 - sizeof(pthread_rwlock_t)]; pthread_spinlock_t spin; +#endif unsigned int readers; struct lwp *writer; int downgrade; /* someone is downgrading (hopefully lock holder ;) */ @@ -319,7 +321,7 @@ static inline void rw_readup(struct rumpuser_rw *rw) { -#if defined(__NetBSD__) +#if defined(__NetBSD__) || defined(__APPLE__) atomic_inc_uint(&rw->readers); #else pthread_spin_lock(&rw->spin); @@ -332,7 +334,7 @@ static inline void rw_readdown(struct rumpuser_rw *rw) { -#if defined(__NetBSD__) +#if defined(__NetBSD__) || defined(__APPLE__) atomic_dec_uint(&rw->readers); #else pthread_spin_lock(&rw->spin); @@ -348,7 +350,9 @@ rumpuser_rw_init(struct rumpuser_rw **rw NOFAIL(*rw = aligned_alloc(sizeof(struct rumpuser_rw))); NOFAIL_ERRNO(pthread_rwlock_init(&((*rw)->pthrw), NULL)); +#if !defined(__APPLE__) NOFAIL_ERRNO(pthread_spin_init(&((*rw)->spin),PTHREAD_PROCESS_PRIVATE)); +#endif (*rw)->readers = 0; (*rw)->writer = NULL; (*rw)->downgrade = 0; @@ -452,7 +456,9 @@ rumpuser_rw_destroy(struct rumpuser_rw * { NOFAIL_ERRNO(pthread_rwlock_destroy(&rw->pthrw)); +#if !defined(__APPLE__) NOFAIL_ERRNO(pthread_spin_destroy(&rw->spin)); +#endif free(rw); } Index: src/lib/librumpuser/rumpuser_sp.c diff -u src/lib/librumpuser/rumpuser_sp.c:1.59 src/lib/librumpuser/rumpuser_sp.c:1.60 --- src/lib/librumpuser/rumpuser_sp.c:1.59 Thu Jul 18 12:28:26 2013 +++ src/lib/librumpuser/rumpuser_sp.c Sun Oct 27 16:39:46 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: rumpuser_sp.c,v 1.59 2013/07/18 12:28:26 pooka Exp $ */ +/* $NetBSD: rumpuser_sp.c,v 1.60 2013/10/27 16:39:46 rmind Exp $ */ /* * Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved. @@ -37,7 +37,7 @@ #include "rumpuser_port.h" #if !defined(lint) -__RCSID("$NetBSD: rumpuser_sp.c,v 1.59 2013/07/18 12:28:26 pooka Exp $"); +__RCSID("$NetBSD: rumpuser_sp.c,v 1.60 2013/10/27 16:39:46 rmind Exp $"); #endif /* !lint */ #include <sys/types.h> @@ -90,7 +90,7 @@ static char banner[MAXBANNER]; /* how to use atomic ops on Linux? */ -#if defined(__linux__) || defined(__CYGWIN__) +#if defined(__linux__) || defined(__APPLE__) || defined(__CYGWIN__) static pthread_mutex_t discomtx = PTHREAD_MUTEX_INITIALIZER; static void