Skip to content

Instantly share code, notes, and snippets.

@justincormack
Last active August 29, 2015 13:58
Show Gist options
  • Save justincormack/9931322 to your computer and use it in GitHub Desktop.
Save justincormack/9931322 to your computer and use it in GitHub Desktop.
rump android patches
diff --git a/lib/librumpclient/rumpclient.c b/lib/librumpclient/rumpclient.c
index a92dbdd..5a2ad58 100644
--- a/lib/librumpclient/rumpclient.c
+++ b/lib/librumpclient/rumpclient.c
@@ -84,9 +84,17 @@ int (*host_socket)(int, int, int);
int (*host_close)(int);
int (*host_connect)(int, const struct sockaddr *, socklen_t);
int (*host_fcntl)(int, int, ...);
+#ifdef __ANDROID__
+int (*host_poll)(struct pollfd *, nfds_t, long);
+#else
int (*host_poll)(struct pollfd *, nfds_t, int);
+#endif
ssize_t (*host_read)(int, void *, size_t);
+#ifdef __ANDROID__
+int (*host_sendmsg)(int, const struct msghdr *, unsigned int);
+#else
ssize_t (*host_sendmsg)(int, const struct msghdr *, int);
+#endif
int (*host_setsockopt)(int, int, int, const void *, socklen_t);
int (*host_dup)(int);
diff --git a/lib/librumphijack/hijack.c b/lib/librumphijack/hijack.c
index bea984b..9794ea5 100644
--- a/lib/librumphijack/hijack.c
+++ b/lib/librumphijack/hijack.c
@@ -38,10 +38,13 @@ __RCSID("$NetBSD: hijack.c,v 1.106 2013/09/10 16:53:06 pooka Exp $");
#include <sys/mount.h>
#include <sys/socket.h>
#include <sys/stat.h>
-#include <sys/statvfs.h>
#include <sys/time.h>
#include <sys/uio.h>
+#ifdef PLATFORM_HAS_NBVFSSTAT
+#include <sys/statvfs.h>
+#endif
+
#ifdef PLATFORM_HAS_KQUEUE
#include <sys/event.h>
#endif
diff --git a/lib/librumpuser/rumpuser_dl.c b/lib/librumpuser/rumpuser_dl.c
index 2ee5c37..0aa1d0b 100644
--- a/lib/librumpuser/rumpuser_dl.c
+++ b/lib/librumpuser/rumpuser_dl.c
@@ -59,8 +59,8 @@ __RCSID("$NetBSD: rumpuser_dl.c,v 1.27 2014/03/14 01:18:39 justin Exp $");
#include <rump/rumpuser.h>
#if defined(__ELF__) && (defined(__NetBSD__) || defined(__FreeBSD__) \
- || (defined(__sun__) && defined(__svr4__))) || defined(__linux__) \
- || defined(__DragonFly__)
+ || (defined(__sun__) && defined(__svr4__))) || defined(__DragonFly__) \
+ || (defined(__linux__) && !defined(__ANDROID__))
#include <elf.h>
#include <link.h>
diff --git a/lib/librumpuser/rumpuser_port.h b/lib/librumpuser/rumpuser_port.h
index 0b4bb19..65e5489 100644
--- a/lib/librumpuser/rumpuser_port.h
+++ b/lib/librumpuser/rumpuser_port.h
@@ -39,8 +39,15 @@
#define PLATFORM_HAS_NBVFSSTAT
#endif /* __NetBSD__ */
+#ifndef MIN
+#define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
+#endif
+#ifndef MAX
+#define MAX(a,b) ((/*CONSTCOND*/(a)>(b))?(a):(b))
+#endif
+
/* might not be 100% accurate, maybe need to revisit later */
-#if defined(__linux__) || defined(__sun__)
+#if (defined(__linux__) && !defined(__ANDROID__)) || defined(__sun__)
#define HAVE_CLOCK_NANOSLEEP
#endif
@@ -51,6 +58,22 @@
#include <features.h>
#endif
+#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
+
#if defined(__sun__)
# if defined(RUMPUSER_NO_FILE_OFFSET_BITS)
# undef _FILE_OFFSET_BITS
@@ -223,7 +246,7 @@ posix_memalign(void **ptr, size_t align, size_t size)
#define MSG_NOSIGNAL 0
#endif
-#if defined(__sun__) && !defined(RUMP_REGISTER_T)
+#if (defined(__sun__) || defined(__ANDROID__)) && !defined(RUMP_REGISTER_T)
#define RUMP_REGISTER_T long
typedef RUMP_REGISTER_T register_t;
#endif
diff --git a/lib/librumpuser/rumpuser_pth.c b/lib/librumpuser/rumpuser_pth.c
index 70f4a88..9189935 100644
--- a/lib/librumpuser/rumpuser_pth.c
+++ b/lib/librumpuser/rumpuser_pth.c
@@ -258,7 +258,7 @@ rumpuser_mutex_owner(struct rumpuser_mtx *mtx, struct lwp **lp)
struct rumpuser_rw {
pthread_rwlock_t pthrw;
-#if !defined(__APPLE__)
+#if !defined(__APPLE__) && !defined(__ANDROID__)
char pad[64 - sizeof(pthread_rwlock_t)];
pthread_spinlock_t spin;
#endif
@@ -321,7 +321,7 @@ static inline void
rw_readup(struct rumpuser_rw *rw)
{
-#if defined(__NetBSD__) || defined(__APPLE__)
+#if defined(__NetBSD__) || defined(__APPLE__) || defined(__ANDROID__)
atomic_inc_uint(&rw->readers);
#else
pthread_spin_lock(&rw->spin);
@@ -334,7 +334,7 @@ static inline void
rw_readdown(struct rumpuser_rw *rw)
{
-#if defined(__NetBSD__) || defined(__APPLE__)
+#if defined(__NetBSD__) || defined(__APPLE__) || defined(__ANDROID__)
atomic_dec_uint(&rw->readers);
#else
pthread_spin_lock(&rw->spin);
@@ -350,7 +350,7 @@ 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__)
+#if !defined(__APPLE__) && !defined(__ANDROID__)
NOFAIL_ERRNO(pthread_spin_init(&((*rw)->spin),PTHREAD_PROCESS_PRIVATE));
#endif
(*rw)->readers = 0;
@@ -456,7 +456,7 @@ rumpuser_rw_destroy(struct rumpuser_rw *rw)
{
NOFAIL_ERRNO(pthread_rwlock_destroy(&rw->pthrw));
-#if !defined(__APPLE__)
+#if !defined(__APPLE__) && ! defined(__ANDROID__)
NOFAIL_ERRNO(pthread_spin_destroy(&rw->spin));
#endif
free(rw);
diff --git a/sys/rump/include/rump/rump.h b/sys/rump/include/rump/rump.h
index 2380f7f..df37afb 100644
--- a/sys/rump/include/rump/rump.h
+++ b/sys/rump/include/rump/rump.h
@@ -57,7 +57,7 @@ typedef struct prop_dictionary *prop_dictionary_t;
#endif
#endif /* __NetBSD__ */
-#if defined(__sun__) && !defined(RUMP_REGISTER_T)
+#if (!defined(_KERNEL)) && (defined(__sun__) || defined(__ANDROID__)) && !defined(RUMP_REGISTER_T)
#define RUMP_REGISTER_T long
typedef RUMP_REGISTER_T register_t;
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment