Use linker -Wl,--wrap=symbol

Linker --wrap option resolves to __wrap_symbol for undefined symbol.
During the compilation of host libportable.a, __HOST__ is defined
to rename all portable functions to  __wrap_symbol, and the
real function to __real_symbol.  This way libportable.a can be
validated at host w/o changes of user's source code.

See http://sourceware.org/binutils/docs/ld/Options.html

Change-Id: Idcbe53dd642536f3dc2be85a875f95535b9dc0b1
diff --git a/ndk/sources/android/libportable/arch-arm/epoll.c b/ndk/sources/android/libportable/arch-arm/epoll.c
index f703ba1..ef75695 100644
--- a/ndk/sources/android/libportable/arch-arm/epoll.c
+++ b/ndk/sources/android/libportable/arch-arm/epoll.c
@@ -14,15 +14,16 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <sys/epoll.h>
 
-int epoll_ctl_portable(int epfd, int op, int fd, struct epoll_event *event)
+int WRAP(epoll_ctl)(int epfd, int op, int fd, struct epoll_event *event)
 {
-    return epoll_ctl(epfd, op, fd, event);
+    return REAL(epoll_ctl)(epfd, op, fd, event);
 }
 
-int epoll_wait_portable(int epfd, struct epoll_event *events, int max, int timeout)
+int WRAP(epoll_wait)(int epfd, struct epoll_event *events, int max, int timeout)
 {
-    return epoll_wait(epfd, events, max, timeout);
+    return REAL(epoll_wait)(epfd, events, max, timeout);
 }
 
diff --git a/ndk/sources/android/libportable/arch-arm/errno.c b/ndk/sources/android/libportable/arch-arm/errno.c
index ffa5998..776b12e 100644
--- a/ndk/sources/android/libportable/arch-arm/errno.c
+++ b/ndk/sources/android/libportable/arch-arm/errno.c
@@ -14,8 +14,10 @@
  * limitations under the License.
  */
 
-extern volatile int*   __errno(void);
-volatile int* __errno_portable()
+#include <portability.h>
+
+extern volatile int*   REAL(__errno)(void);
+volatile int* WRAP(__errno)()
 {
-  return __errno();
+  return REAL(__errno)();
 }
diff --git a/ndk/sources/android/libportable/arch-arm/socket.c b/ndk/sources/android/libportable/arch-arm/socket.c
index 7e7ca9b..72211c9 100644
--- a/ndk/sources/android/libportable/arch-arm/socket.c
+++ b/ndk/sources/android/libportable/arch-arm/socket.c
@@ -14,10 +14,11 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <unistd.h>
 #include <sys/socket.h>
 #include <sys/linux-syscalls.h>
 
-int socket_portable(int domain, int type, int protocol) {
-    return socket(domain, type, protocol);
+int WRAP(socket)(int domain, int type, int protocol) {
+    return REAL(socket)(domain, type, protocol);
 }
diff --git a/ndk/sources/android/libportable/arch-arm/sockopt.c b/ndk/sources/android/libportable/arch-arm/sockopt.c
index c86ded3..a9d2084 100644
--- a/ndk/sources/android/libportable/arch-arm/sockopt.c
+++ b/ndk/sources/android/libportable/arch-arm/sockopt.c
@@ -14,17 +14,18 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 
 extern int setsockopt(int, int, int, const void *, socklen_t);
-int setsockopt_portable(int s, int level, int optname, const void *optval, socklen_t optlen)
+int WRAP(setsockopt)(int s, int level, int optname, const void *optval, socklen_t optlen)
 {
-    return setsockopt(s, level, optname, optval, optlen);
+    return REAL(setsockopt)(s, level, optname, optval, optlen);
 }
 
 extern int getsockopt (int, int, int, void *, socklen_t *);
-int getsockopt_portable(int s, int level, int optname, void *optval, socklen_t *optlen)
+int WRAP(getsockopt)(int s, int level, int optname, void *optval, socklen_t *optlen)
 {
-    return getsockopt(s, level, optname, optval, optlen);
+    return REAL(getsockopt)(s, level, optname, optval, optlen);
 }
diff --git a/ndk/sources/android/libportable/arch-arm/stat.c b/ndk/sources/android/libportable/arch-arm/stat.c
index 20a34ad..be9ca62 100644
--- a/ndk/sources/android/libportable/arch-arm/stat.c
+++ b/ndk/sources/android/libportable/arch-arm/stat.c
@@ -14,25 +14,26 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <stat_portable.h>
 
 /* Note: The Portable Header will define stat to stat_portable */
-int stat_portable(const char *path, struct stat_portable *s)
+int WRAP(stat)(const char *path, struct stat_portable *s)
 {
-   return stat(path, s);
+   return REAL(stat)(path, s);
 }
 
-int fstat_portable(int fd, struct stat_portable *s)
+int WRAP(fstat)(int fd, struct stat_portable *s)
 {
-    return fstat(fd, s);
-}   
-
-int lstat_portable(const char *path, struct stat_portable *s)
-{
-    return lstat(path, s);
+    return REAL(fstat)(fd, s);
 }
 
-int fstatat_portable(int dirfd, const char *path, struct stat_portable *s, int flags)
+int WRAP(lstat)(const char *path, struct stat_portable *s)
 {
-    return fstatat(dirfd, path, s, flags);
+    return REAL(lstat)(path, s);
+}
+
+int WRAP(fstatat)(int dirfd, const char *path, struct stat_portable *s, int flags)
+{
+    return REAL(fstatat)(dirfd, path, s, flags);
 }
diff --git a/ndk/sources/android/libportable/arch-arm/unwind.c b/ndk/sources/android/libportable/arch-arm/unwind.c
index ddc034b..99f2dac 100644
--- a/ndk/sources/android/libportable/arch-arm/unwind.c
+++ b/ndk/sources/android/libportable/arch-arm/unwind.c
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <stdint.h>
 
 struct _Unwind_Context;
@@ -55,25 +56,25 @@
 #define UNWIND_STACK_REG    13
 #define UNWIND_IP_REG       15
 
-uint64_t _Unwind_GetGR_portable(struct _Unwind_Context* ctx, int index) {
+uint64_t WRAP(_Unwind_GetGR)(struct _Unwind_Context* ctx, int index) {
   uint32_t val;
   _Unwind_VRS_Get(ctx, _UVRSC_CORE, index, _UVRSD_UINT32, &val);
   return (uint64_t)val;
 }
 
-void _Unwind_SetGR_portable(struct _Unwind_Context* ctx, int index, uint64_t new_value) {
+void WRAP(_Unwind_SetGR)(struct _Unwind_Context* ctx, int index, uint64_t new_value) {
   uint32_t val = (uint32_t)new_value;
   _Unwind_VRS_Set(ctx, _UVRSC_CORE, index, _UVRSD_UINT32, &val);
 }
 
-uint64_t _Unwind_GetIP_portable(struct _Unwind_Context* ctx) {
-  return _Unwind_GetGR_portable(ctx, UNWIND_IP_REG) & ~1; // thumb bit
+uint64_t WRAP(_Unwind_GetIP)(struct _Unwind_Context* ctx) {
+  return WRAP(_Unwind_GetGR)(ctx, UNWIND_IP_REG) & ~1; // thumb bit
 }
 
-void _Unwind_SetIP_portable(struct _Unwind_Context* ctx, uintptr_t new_value) {
+void WRAP(_Unwind_SetIP)(struct _Unwind_Context* ctx, uintptr_t new_value) {
   uint32_t val = (uint32_t)new_value;
   // Propagate thumb bit to instruction pointer
-  uint32_t thumbState = _Unwind_GetGR_portable(ctx, UNWIND_IP_REG) & 1;
+  uint32_t thumbState = WRAP(_Unwind_GetGR)(ctx, UNWIND_IP_REG) & 1;
   uint64_t new_val = (uint64_t)(val | thumbState);
-  _Unwind_SetGR_portable(ctx, UNWIND_IP_REG, new_val);
+  WRAP(_Unwind_SetGR)(ctx, UNWIND_IP_REG, new_val);
 }
diff --git a/ndk/sources/android/libportable/arch-mips/clone.c b/ndk/sources/android/libportable/arch-mips/clone.c
index 2fc6421..7498ef6 100644
--- a/ndk/sources/android/libportable/arch-mips/clone.c
+++ b/ndk/sources/android/libportable/arch-mips/clone.c
@@ -15,6 +15,7 @@
  */
 
 #define _GNU_SOURCE
+#include <portability.h>
 #include <sched.h>
 #include <stdarg.h>
 #include <stdlib.h>
@@ -47,7 +48,7 @@
  * If no signal is specified, then the parent process is not
  * signaled when the child terminates.
  */
-int clone_portable(int (*fn)(void *), void *child_stack, int port_flags, void *arg, ...)
+int WRAP(clone)(int (*fn)(void *), void *child_stack, int port_flags, void *arg, ...)
 {
     va_list     args;
     int         ret;
@@ -117,7 +118,7 @@
     ALOGV("%s: clone(%p, %p, 0x%x, %p, %p, %p, %p);", __func__,
            fn, child_stack, mips_flags, arg, parent_tidptr, new_tls, child_tidptr);
 
-    ret = clone(fn, child_stack, mips_flags, arg, parent_tidptr,
+    ret = REAL(clone)(fn, child_stack, mips_flags, arg, parent_tidptr,
                 new_tls, child_tidptr);
 
     if (ret > 0) {
diff --git a/ndk/sources/android/libportable/arch-mips/epoll.c b/ndk/sources/android/libportable/arch-mips/epoll.c
index f703ba1..ef75695 100644
--- a/ndk/sources/android/libportable/arch-mips/epoll.c
+++ b/ndk/sources/android/libportable/arch-mips/epoll.c
@@ -14,15 +14,16 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <sys/epoll.h>
 
-int epoll_ctl_portable(int epfd, int op, int fd, struct epoll_event *event)
+int WRAP(epoll_ctl)(int epfd, int op, int fd, struct epoll_event *event)
 {
-    return epoll_ctl(epfd, op, fd, event);
+    return REAL(epoll_ctl)(epfd, op, fd, event);
 }
 
-int epoll_wait_portable(int epfd, struct epoll_event *events, int max, int timeout)
+int WRAP(epoll_wait)(int epfd, struct epoll_event *events, int max, int timeout)
 {
-    return epoll_wait(epfd, events, max, timeout);
+    return REAL(epoll_wait)(epfd, events, max, timeout);
 }
 
diff --git a/ndk/sources/android/libportable/arch-mips/errno.c b/ndk/sources/android/libportable/arch-mips/errno.c
index 8adf248..6ccd512 100644
--- a/ndk/sources/android/libportable/arch-mips/errno.c
+++ b/ndk/sources/android/libportable/arch-mips/errno.c
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <pthread.h>
 #include <string.h>
 #include <errno.h>
@@ -278,7 +279,7 @@
  * This can be assigned to without affecting the native errno. If the key
  * allocation fails fall back to using the native errno location.
  */
-volatile int* __errno_portable()
+volatile int* WRAP(__errno)()
 {
     struct errno_state *p;
     int save_errno;
@@ -331,7 +332,7 @@
 
 
 /* set portable errno */
-void __set_errno_portable(int portable_errno)
+void WRAP(__set_errno)(int portable_errno)
 {
     struct errno_state *p;
     int save_errno;
@@ -356,13 +357,14 @@
     ALOGV("%s: return; }", __func__);
 }
 
-char *strerror_portable(int errnum)
+extern char* REAL(strerror)(int);
+char *WRAP(strerror)(int errnum)
 {
-    return strerror(errno_pton(errnum));
+    return REAL(strerror)(errno_pton(errnum));
 }
 
 /* BSD style strerror_r */
-int strerror_r_portable(int errnum, char *buf, size_t buflen)
+int WRAP(strerror_r)(int errnum, char *buf, size_t buflen)
 {
-    return strerror_r(errno_pton(errnum), buf, buflen);
+    return REAL(strerror_r)(errno_pton(errnum), buf, buflen);
 }
diff --git a/ndk/sources/android/libportable/arch-mips/eventfd.c b/ndk/sources/android/libportable/arch-mips/eventfd.c
index c16d9bc..35285d9 100644
--- a/ndk/sources/android/libportable/arch-mips/eventfd.c
+++ b/ndk/sources/android/libportable/arch-mips/eventfd.c
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <unistd.h>
 #include <fcntl.h>
 
@@ -71,7 +72,7 @@
  * new eventfd2 system call number, so it likely best to just use
  * the Android eventfd() for both eventfd and eventfd2 system calls.
  */
-int eventfd_portable(unsigned int initval, int portable_flags) {
+int WRAP(eventfd)(unsigned int initval, int portable_flags) {
     int rv;
     int native_flags;
 
@@ -81,7 +82,7 @@
 
     native_flags = efd_flags_pton(portable_flags);
 
-    rv = eventfd(initval, native_flags);
+    rv = REAL(eventfd)(initval, native_flags);
     if (rv >= 0) {
         if (native_flags & EFD_CLOEXEC) {
             filefd_CLOEXEC_enabled(rv);
diff --git a/ndk/sources/android/libportable/arch-mips/fcntl.c b/ndk/sources/android/libportable/arch-mips/fcntl.c
index d714016..2ef83e5 100644
--- a/ndk/sources/android/libportable/arch-mips/fcntl.c
+++ b/ndk/sources/android/libportable/arch-mips/fcntl.c
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <fcntl.h>
 #include <errno.h>
 #include <stdarg.h>
@@ -284,7 +285,7 @@
  *        pid_t l_pid;            pid_t l_pid;
  *      }                       }
  */
-int fcntl_portable(int fd, int portable_cmd, ...)
+int WRAP(fcntl)(int fd, int portable_cmd, ...)
 {
     int flags;
     va_list ap;
diff --git a/ndk/sources/android/libportable/arch-mips/filefd.c b/ndk/sources/android/libportable/arch-mips/filefd.c
index 4911ee1..f6e55fa 100644
--- a/ndk/sources/android/libportable/arch-mips/filefd.c
+++ b/ndk/sources/android/libportable/arch-mips/filefd.c
@@ -14,10 +14,10 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <unistd.h>
 #include <stdarg.h>
 #include <stdlib.h>
-#include <portability.h>
 #include <stdio.h>
 #include <errno.h>
 #include <errno_portable.h>
@@ -415,14 +415,14 @@
 }
 
 
-int close_portable(int fd)
+int WRAP(close)(int fd)
 {
     int rv;
 
     ALOGV(" ");
     ALOGV("%s(fd:%d) {", __func__, fd);
 
-    rv = close(fd);
+    rv = REAL(close)(fd);
     filefd_closed(fd);
 
     ALOGV("%s: return(rv:%d); }", __func__, rv);
@@ -430,7 +430,7 @@
 }
 
 
-int read_portable(int fd, void *buf, size_t count)
+int WRAP(read)(int fd, void *buf, size_t count)
 {
     int rv;
     enum filefd_type fd_type;
@@ -449,7 +449,7 @@
     case EVENT_FD_TYPE:
     case INOTIFY_FD_TYPE:
     case TIMER_FD_TYPE:
-        rv = read(fd, buf, count);
+        rv = REAL(read)(fd, buf, count);
         break;
 
     /* The read() of a signalfd() file descriptor needs to be mapped. */
@@ -457,13 +457,13 @@
         if (filefd_enabled) {
             rv = read_signalfd_mapper(fd, buf, count);
         } else {
-            rv = read(fd, buf, count);
+            rv = REAL(read)(fd, buf, count);
         }
         break;
 
     default:
         ALOGE("Unknown fd_type:%d!", fd_type);
-        rv = read(fd, buf, count);
+        rv = REAL(read)(fd, buf, count);
         break;
     }
 
@@ -477,7 +477,7 @@
  * Tries a second time if it detects an extremely unlikely
  * race condition.
  */
-int execve_portable(const char *filename, char *const argv[],  char *const envp[])
+int WRAP(execve)(const char *filename, char *const argv[],  char *const envp[])
 {
     int rv;
     int mapped_files = filefd_mapped_files;
@@ -494,7 +494,7 @@
     }
     import_fd_env(verify_consistancy);          /* File type table consistancy verified. */
 
-    rv = execve(filename, argv, envp);
+    rv = REAL(execve)(filename, argv, envp);
 
     ALOGV("%s: return(rv:%d); }", __func__, rv);
     return rv;
diff --git a/ndk/sources/android/libportable/arch-mips/flags.c b/ndk/sources/android/libportable/arch-mips/flags.c
index c55fe86..f18b8d9 100644
--- a/ndk/sources/android/libportable/arch-mips/flags.c
+++ b/ndk/sources/android/libportable/arch-mips/flags.c
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <stdio.h>
 #include <fcntl.h>
 #include <fcntl_portable.h>
@@ -26,7 +27,7 @@
 extern int __sflags(const char *, int *);
 
 int
-__sflags_portable(const char *mode, int *optr)
+WRAP(__sflags)(const char *mode, int *optr)
 {
     int rv;
     int nflags, pflags;
diff --git a/ndk/sources/android/libportable/arch-mips/inotify.c b/ndk/sources/android/libportable/arch-mips/inotify.c
index c417aa2..76b1cac 100644
--- a/ndk/sources/android/libportable/arch-mips/inotify.c
+++ b/ndk/sources/android/libportable/arch-mips/inotify.c
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <unistd.h>
 #include <fcntl.h>
 
@@ -60,7 +61,7 @@
 }
 
 
-int inotify_init1_portable(int portable_flags) {
+int WRAP(inotify_init1)(int portable_flags) {
     int rv;
     int native_flags;
 
diff --git a/ndk/sources/android/libportable/arch-mips/ioctl.c b/ndk/sources/android/libportable/arch-mips/ioctl.c
index cbd517f..7e82a6a 100644
--- a/ndk/sources/android/libportable/arch-mips/ioctl.c
+++ b/ndk/sources/android/libportable/arch-mips/ioctl.c
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <stdarg.h>
 #include <sys/ioctl.h>
 #include <ioctls_portable.h>
@@ -213,7 +214,7 @@
 }
 
 extern int __ioctl(int, int, void *);
-int ioctl_portable(int fd, int request, ...)
+int WRAP(ioctl)(int fd, int request, ...)
 {
     va_list ap;
     void * arg;
diff --git a/ndk/sources/android/libportable/arch-mips/mmap.c b/ndk/sources/android/libportable/arch-mips/mmap.c
index ee44513..f2c3a1a 100644
--- a/ndk/sources/android/libportable/arch-mips/mmap.c
+++ b/ndk/sources/android/libportable/arch-mips/mmap.c
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <unistd.h>
 #include <errno.h>
 #include <sys/mman.h>
@@ -87,8 +88,8 @@
     return native_flags;
 }
 
-
-void *mmap_portable(void *addr, size_t size, int prot, int flags, int fd, long byte_offset)
+extern void* REAL(mmap)(void *, size_t, int, int, int, off_t);
+void *WRAP(mmap)(void *addr, size_t size, int prot, int flags, int fd, long byte_offset)
 {
     int native_prot, native_flags;
     int saved_errno;
@@ -101,7 +102,7 @@
     native_prot = mmap_prot_pton(prot);
     native_flags = mmap_flags_pton(flags);
 
-    ret_addr = mmap(addr, size, native_prot, native_flags, fd, byte_offset);
+    ret_addr = REAL(mmap)(addr, size, native_prot, native_flags, fd, byte_offset);
 
     ALOGV("%s: return(ret_addr:%p); }", __func__, ret_addr);
     return ret_addr;
@@ -110,7 +111,7 @@
 
 extern int mprotect(const void *, size_t, int);
 
-int mprotect_portable(const void *addr, size_t size, int portable_prot)
+int WRAP(mprotect)(const void *addr, size_t size, int portable_prot)
 {
     int rv;
     int native_prot;
@@ -121,7 +122,7 @@
 
     native_prot = mmap_prot_pton(portable_prot);
 
-    rv = mprotect(addr, size, native_prot);
+    rv = REAL(mprotect)(addr, size, native_prot);
 
     ALOGV("%s: return(rv:%d); }", __func__, rv);
     return rv;
diff --git a/ndk/sources/android/libportable/arch-mips/open.c b/ndk/sources/android/libportable/arch-mips/open.c
index 4804f88..99ed7f9 100644
--- a/ndk/sources/android/libportable/arch-mips/open.c
+++ b/ndk/sources/android/libportable/arch-mips/open.c
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <stdarg.h>
@@ -72,7 +73,7 @@
 
 extern int  __open(const char*, int, int);
 
-int open_portable(const char *pathname, int flags, ...)
+int WRAP(open)(const char *pathname, int flags, ...)
 {
     mode_t  mode = 0;
     int native_flags;
@@ -113,7 +114,7 @@
 
 extern int  __openat(int, const char*, int, int);
 
-int openat_portable(int dirfd, const char *pathname, int flags, ...)
+int WRAP(openat)(int dirfd, const char *pathname, int flags, ...)
 {
     mode_t  mode = 0;
     int native_flags;
diff --git a/ndk/sources/android/libportable/arch-mips/pipe.c b/ndk/sources/android/libportable/arch-mips/pipe.c
index 07d01a9..fa80266 100644
--- a/ndk/sources/android/libportable/arch-mips/pipe.c
+++ b/ndk/sources/android/libportable/arch-mips/pipe.c
@@ -15,6 +15,7 @@
  */
 
 #define _GNU_SOURCE             /* GLibc compatibility to declare pipe2(2) */
+#include <portability.h>
 #include <unistd.h>
 #include <fcntl.h>
 
@@ -59,7 +60,7 @@
 }
 
 
-int pipe2_portable(int pipefd[2], int portable_flags) {
+int WRAP(pipe2)(int pipefd[2], int portable_flags) {
     int native_flags;
     int rv;
 
@@ -69,7 +70,7 @@
 
     native_flags = tdf_flags_pton(portable_flags);
 
-    rv = pipe2(pipefd, native_flags);
+    rv = REAL(pipe2)(pipefd, native_flags);
     if (rv >= 0) {
         ALOGV("%s: pipe2() returned pipefd[0]:%d, pipefd[1]:%d", __func__,
                                     pipefd[0],    pipefd[1]);
diff --git a/ndk/sources/android/libportable/arch-mips/poll.c b/ndk/sources/android/libportable/arch-mips/poll.c
index 89e06c7..3f97176 100644
--- a/ndk/sources/android/libportable/arch-mips/poll.c
+++ b/ndk/sources/android/libportable/arch-mips/poll.c
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <poll.h>
 #include <poll_portable.h>
 
@@ -105,7 +106,7 @@
 
 extern int poll(struct pollfd *, nfds_t, long);
 
-int poll_portable(struct pollfd *fds, nfds_t nfds, long timeout)
+int WRAP(poll)(struct pollfd *fds, nfds_t nfds, long timeout)
 {
   nfds_t i;
   int ret;
@@ -113,7 +114,7 @@
   for (i = 0; i < nfds; i++)
       fds->events = mips_change_portable_events(fds->events);
 
-  ret = poll(fds, nfds, timeout);
+  ret = REAL(poll)(fds, nfds, timeout);
 
   for (i = 0; i < nfds; i++) {
       fds->events = change_mips_events(fds->events);
diff --git a/ndk/sources/android/libportable/arch-mips/pthread.c b/ndk/sources/android/libportable/arch-mips/pthread.c
index 3c8e0d4..41d9478 100644
--- a/ndk/sources/android/libportable/arch-mips/pthread.c
+++ b/ndk/sources/android/libportable/arch-mips/pthread.c
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <pthread.h>
 #include <time.h>
 #include <signal.h>
@@ -54,13 +55,13 @@
  * Call pthread function and convert return value (a native errno) to portable error number.
  */
 #define PTHREAD_WRAPPER(fn, DECLARGS, CALLARGS, fmt)            \
-    int fn##_portable DECLARGS                                  \
+    int WRAP(fn) DECLARGS                                       \
     {                                                           \
         int rv, portable_rv;                                    \
                                                                 \
         ALOGV(" ");                                             \
         ALOGV("%s" fmt, __func__, STRIP_PARENS(CALLARGS));      \
-        rv = fn CALLARGS;                                       \
+        rv = REAL(fn) CALLARGS;                                 \
         portable_rv = errno_ntop(rv);                           \
         ALOGV("%s: return(portable_rv:%d); rv:%d;", __func__,   \
                           portable_rv,     rv);                 \
@@ -258,7 +259,7 @@
 
 // void *pthread_getspecific(pthread_key_t key);
 
-int pthread_kill_portable(pthread_t thread, int portable_signum)
+int WRAP(pthread_kill)(pthread_t thread, int portable_signum)
 {
     char *portable_signame = map_portable_signum_to_name(portable_signum);
     int mips_signum;
@@ -274,7 +275,7 @@
     } else {
         ALOGV("%s: calling pthread_kill(thread:%lx, mips_signum:%d);", __func__,
                                         thread,     mips_signum);
-        ret = pthread_kill(thread, mips_signum);
+        ret = REAL(pthread_kill)(thread, mips_signum);
     }
     portable_ret = errno_ntop(ret);
 
@@ -284,7 +285,7 @@
     return portable_ret;
 }
 
-int pthread_sigmask_portable(int portable_how, const sigset_portable_t *portable_sigset,
+int WRAP(pthread_sigmask)(int portable_how, const sigset_portable_t *portable_sigset,
                              sigset_portable_t *portable_oldset)
 {
     int portable_ret, ret;
diff --git a/ndk/sources/android/libportable/arch-mips/resource.c b/ndk/sources/android/libportable/arch-mips/resource.c
index 4119e79..38ee79d 100644
--- a/ndk/sources/android/libportable/arch-mips/resource.c
+++ b/ndk/sources/android/libportable/arch-mips/resource.c
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <sys/resource.h>
 #include <resource_portable.h>
 
@@ -39,13 +40,13 @@
 }
 
 extern int getrlimit(int resource, struct rlimit *rlp);
-int getrlimit_portable(int resource, struct rlimit *rlp)
+int WRAP(getrlimit)(int resource, struct rlimit *rlp)
 {
-    return getrlimit(mips_change_resource(resource), rlp);
+    return REAL(getrlimit)(mips_change_resource(resource), rlp);
 }
 
 extern int setrlimit(int resource, const struct rlimit *rlp);
-int setrlimit_portable(int resource, const struct rlimit *rlp)
+int WRAP(setrlimit)(int resource, const struct rlimit *rlp)
 {
-    return setrlimit(mips_change_resource(resource), rlp);
+    return REAL(setrlimit)(mips_change_resource(resource), rlp);
 }
diff --git a/ndk/sources/android/libportable/arch-mips/setjmp.S b/ndk/sources/android/libportable/arch-mips/setjmp.S
index bf6c6b7..1532972 100644
--- a/ndk/sources/android/libportable/arch-mips/setjmp.S
+++ b/ndk/sources/android/libportable/arch-mips/setjmp.S
@@ -29,6 +29,7 @@
  *
  */
 
+#include <asm-generic/portability.h>
 #include <machine/asm.h>
 #include <machine/regnum.h>
 
@@ -57,10 +58,10 @@
 
 
 
-NON_LEAF(setjmp_portable, FRAMESZ, ra)
+NON_LEAF(WRAP(setjmp), FRAMESZ, ra)
         .mask   0x80000000, RAOFF
         PTR_SUBU sp, FRAMESZ                    # allocate stack frame
-        SETUP_GP64(GPOFF, setjmp_portable)
+        SETUP_GP64(GPOFF, WRAP(setjmp))
         SAVE_GP(GPOFF)
         .set    reorder
         REG_S   ra, RAOFF(sp)                   # save state
@@ -143,12 +144,12 @@
         jal     abort
         RESTORE_GP64
         PTR_ADDU sp, FRAMESZ
-END(setjmp_portable)
+END(WRAP(setjmp))
 
 
-LEAF(longjmp_portable, FRAMESZ)
+LEAF(WRAP(longjmp), FRAMESZ)
         PTR_SUBU sp, FRAMESZ
-        SETUP_GP64(GPOFF, longjmp_portable)
+        SETUP_GP64(GPOFF, WRAP(longjmp))
         SAVE_GP(GPOFF)
         .set    reorder
         sw      a1, A1OFF(sp)
@@ -214,4 +215,4 @@
         j       ra
          move   v0, a1
 
-END(longjmp_portable)
+END(WRAP(longjmp))
diff --git a/ndk/sources/android/libportable/arch-mips/signal.c b/ndk/sources/android/libportable/arch-mips/signal.c
index 95ee8bc..c96e898 100644
--- a/ndk/sources/android/libportable/arch-mips/signal.c
+++ b/ndk/sources/android/libportable/arch-mips/signal.c
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <unistd.h>
 #include <stdarg.h>
 #include <stdlib.h>
@@ -732,7 +733,7 @@
  * redirects the call to bsd_signal(). _signal() is a static function; not to be called
  * directly. This function isn't actually needed.
  */
-sighandler_portable_t signal_portable(int portable_signum, sighandler_portable_t handler)
+sighandler_portable_t WRAP(signal)(int portable_signum, sighandler_portable_t handler)
 {
     sighandler_portable_t rv;
 
@@ -748,7 +749,7 @@
 }
 
 
-sighandler_portable_t sysv_signal_portable(int portable_signum, sighandler_portable_t handler)
+sighandler_portable_t WRAP(sysv_signal)(int portable_signum, sighandler_portable_t handler)
 {
     sighandler_portable_t rv;
 
@@ -771,7 +772,8 @@
  * or
  *      the sysv_signal() signal handler.
  */
-sighandler_portable_t bsd_signal_portable(int portable_signum, sighandler_portable_t handler)
+
+sighandler_portable_t WRAP(bsd_signal)(int portable_signum, sighandler_portable_t handler)
 {
     sighandler_portable_t rv;
 
@@ -812,46 +814,48 @@
 }
 
 
-int killpg_portable(int pgrp, int portable_signum)
+int WRAP(killpg)(int pgrp, int portable_signum)
 {
+    extern int REAL(killpg)(int pgrp, int sig);
     int rv;
 
     ALOGV(" ");
     ALOGV("%s(pgrp:%d, portable_signum:%d) {", __func__,
               pgrp,    portable_signum);
 
-    rv = do_kill(pgrp, portable_signum, killpg);
+    rv = do_kill(pgrp, portable_signum, REAL(killpg));
 
     ALOGV("%s: return(rv:%d); }", __func__, rv);
     return rv;
 }
 
 
-int kill_portable(pid_t pid, int portable_signum)
+int WRAP(kill)(pid_t pid, int portable_signum)
 {
+    extern int REAL(kill)(pid_t, int);
     int rv;
 
     ALOGV(" ");
     ALOGV("%s(pid:%d, portable_signum:%d) {", __func__,
               pid,    portable_signum);
 
-    rv = do_kill(pid, portable_signum, kill);
+    rv = do_kill(pid, portable_signum, REAL(kill));
 
     ALOGV("%s: return(rv:%d); }", __func__, rv);
     return rv;
 }
 
 
-int tkill_portable(int tid, int portable_signum)
+int WRAP(tkill)(int tid, int portable_signum)
 {
-    extern int tkill(int, int);
+    extern int REAL(tkill)(int, int);
     int rv;
 
     ALOGV(" ");
     ALOGV("%s(tid:%d, portable_signum:%d) {", __func__,
               tid,    portable_signum);
 
-    rv = do_kill(tid, portable_signum, tkill);
+    rv = do_kill(tid, portable_signum, REAL(tkill));
 
     ALOGV("%s: return(rv:%d); }", __func__, rv);
     return rv;
@@ -860,7 +864,7 @@
 
 /* tgkill is not exported from android-14 libc.so */
 #if 0
-int tgkill_portable(int tgid, int tid, int portable_signum)
+int WRAP(tgkill)(int tgid, int tid, int portable_signum)
 {
     extern int tgkill(int, int, int);
     char *portable_signame = map_portable_signum_to_name(portable_signum);
@@ -875,7 +879,7 @@
     if ((portable_signum != 0) && (mips_signum == 0))
         rv = 0;
     else
-        rv = tgkill(tgid, tid, mips_signum);
+        rv = REAL(tgkill)(tgid, tid, mips_signum);
 
     ALOGV("%s: return rv:%d; }", __func__, rv);
     return rv;
@@ -883,7 +887,7 @@
 #endif
 
 
-int raise_portable(int portable_signum)
+int WRAP(raise)(int portable_signum)
 {
     char *portable_signame = map_portable_signum_to_name(portable_signum);
     int mips_signum = signum_pton(portable_signum);
@@ -894,7 +898,7 @@
     if ((portable_signum != 0) && (mips_signum == 0))
         rv = 0;
     else
-        rv = raise(mips_signum);
+        rv = REAL(raise)(mips_signum);
 
     ALOGV("%s: return(rv:%d); }", __func__, rv);
     return rv;
@@ -919,7 +923,7 @@
 
     for(portable_signum = 1; portable_signum <= NSIG_PORTABLE; portable_signum++) {
 
-        if (sigismember_portable(portable_sigset, portable_signum)) {
+        if (WRAP(sigismember)(portable_sigset, portable_signum)) {
             char *portable_signame = map_portable_signum_to_name(portable_signum);
             int mips_signum = signum_pton(portable_signum);
             char *mips_signame;
@@ -962,14 +966,14 @@
                    portable_sigset);
         goto done;
     }
-    sigemptyset_portable(portable_sigset);
+    WRAP(sigemptyset)(portable_sigset);
 
     for(mips_signum = 1; mips_signum <= NSIG; mips_signum++) {
         if (sigismember(mips_sigset, mips_signum)) {
             int portable_signum = signum_ntop(mips_signum);
 
             if (portable_signum != 0)
-                sigaddset_portable(portable_sigset, portable_signum);
+                WRAP(sigaddset)(portable_sigset, portable_signum);
         }
     }
 
@@ -1172,7 +1176,7 @@
             mips_oldact.sa_sigaction == (__sigaction_handler_portable_t) mips_sighandler) {
 
             oldact->sa_sigaction_portable =
-                                           (__sigaction_handler_portable_t) prev_portable_handler;
+                                        (__sigaction_handler_portable_t) prev_portable_handler;
         } else {
             oldact->sa_sigaction_portable =
                                         (__sigaction_handler_portable_t) mips_oldact.sa_sigaction;
@@ -1190,16 +1194,17 @@
 }
 
 
-int sigaction_portable(int portable_signum, const struct sigaction_portable *act,
+int WRAP(sigaction)(int portable_signum, const struct sigaction_portable *act,
                        struct sigaction_portable *oldact)
 {
+    extern int REAL(sigaction)(int, const struct sigaction *, struct sigaction *);
     int rv;
 
     ALOGV(" ");
     ALOGV("%s(portable_signum:%d, act:%p, oldact:%p) {", __func__,
               portable_signum,    act,    oldact);
 
-    rv = do_sigaction_portable(portable_signum, act, oldact, sigaction, NULL);
+    rv = do_sigaction_portable(portable_signum, act, oldact, REAL(sigaction), NULL);
 
     ALOGV("%s: return(rv:%d); }", __func__, rv);
     return rv;
@@ -1261,7 +1266,7 @@
  * This function can't be called from bionic, so there isn't an entry in the experimental
  * linker.cpp table for testing and this function.
  */
-int signalfd_portable(int fd, const sigset_portable_t *portable_sigmask, int portable_flags)
+int WRAP(signalfd)(int fd, const sigset_portable_t *portable_sigmask, int portable_flags)
 {
     int portable_sigsetsize = sizeof(sigset_portable_t);
     int rv;
@@ -1325,7 +1330,7 @@
 }
 
 
-int sigsuspend_portable(const sigset_portable_t *portable_sigmask)
+int WRAP(sigsuspend)(const sigset_portable_t *portable_sigmask)
 {
     int rv;
     sigset_t mips_sigmask;
@@ -1337,7 +1342,7 @@
         rv = -1;
     } else {
         sigset_pton((sigset_portable_t *)portable_sigmask, &mips_sigmask);
-        rv = sigsuspend(&mips_sigmask);
+        rv = REAL(sigsuspend)(&mips_sigmask);
     }
 
     ALOGV("%s: return(rv:%d); }", __func__, rv);
@@ -1345,7 +1350,7 @@
 }
 
 
-int sigpending_portable(sigset_portable_t *portable_sigset)
+int WRAP(sigpending)(sigset_portable_t *portable_sigset)
 {
     int rv;
     sigset_t mips_sigset;
@@ -1357,7 +1362,7 @@
         errno = EFAULT;
         rv = -1;
     } else {
-        rv = sigpending(&mips_sigset);
+        rv = REAL(sigpending)(&mips_sigset);
         sigset_ntop(&mips_sigset, portable_sigset);
     }
 
@@ -1366,7 +1371,7 @@
 }
 
 
-int sigwait_portable(const sigset_portable_t *portable_sigset, int *ptr_to_portable_sig)
+int WRAP(sigwait)(const sigset_portable_t *portable_sigset, int *ptr_to_portable_sig)
 {
     int rv;
     sigset_t mips_sigset;
@@ -1382,7 +1387,7 @@
     } else {
         sigset_pton((sigset_portable_t *)portable_sigset, &mips_sigset);
 
-        rv = sigwait(&mips_sigset, &mips_sig);
+        rv = REAL(sigwait)(&mips_sigset, &mips_sig);
 
         portable_sig = signum_ntop(mips_sig);
         *ptr_to_portable_sig = portable_sig;
@@ -1392,7 +1397,7 @@
 }
 
 
-int siginterrupt_portable(int portable_signum, int flag)
+int WRAP(siginterrupt)(int portable_signum, int flag)
 
 {
     int rv;
@@ -1408,7 +1413,7 @@
                                portable_signum);
         rv = 0;
     } else {
-        rv = siginterrupt(mips_signum, flag);
+        rv = REAL(siginterrupt)(mips_signum, flag);
     }
     ALOGV("%s: return(rv:%d); }", __func__, rv);
     return rv;
@@ -1474,26 +1479,27 @@
 }
 
 
-int sigprocmask_portable(int portable_how, const sigset_portable_t *portable_sigset,
+int WRAP(sigprocmask)(int portable_how, const sigset_portable_t *portable_sigset,
                          sigset_portable_t *portable_oldset)
 {
+    extern int REAL(sigprocmask)(int, const sigset_t *, sigset_t *);
     int rv;
 
     ALOGV(" ");
     ALOGV("%s(portable_how:%d, portable_sigset:%p, portable_oldset:%p) {", __func__,
               portable_how,    portable_sigset,    portable_oldset);
 
-    rv = do_sigmask(portable_how, portable_sigset, portable_oldset, sigprocmask, NULL);
+    rv = do_sigmask(portable_how, portable_sigset, portable_oldset, REAL(sigprocmask), NULL);
 
     ALOGV("%s: return(rv:%d); }", __func__, rv);
     return rv;
 }
 
 
-int __rt_sigaction_portable(int portable_signum, const struct sigaction_portable *act,
+int WRAP(__rt_sigaction)(int portable_signum, const struct sigaction_portable *act,
                             struct sigaction_portable *oldact, size_t sigsetsize)
 {
-    extern int __rt_sigaction(int , const struct sigaction *, struct sigaction *, size_t);
+    extern int REAL(__rt_sigaction)(int , const struct sigaction *, struct sigaction *, size_t);
     int rv;
 
     ALOGV(" ");
@@ -1506,19 +1512,19 @@
         rv = -1;
         goto done;
     }
-    rv = do_sigaction_portable(portable_signum, act, oldact, NULL, __rt_sigaction);
+    rv = do_sigaction_portable(portable_signum, act, oldact, NULL, REAL(__rt_sigaction));
 
 done:
     ALOGV("%s: return(rv:%d); }", __func__, rv);
     return rv;
 }
 
-int __rt_sigprocmask_portable(int portable_how,
+int WRAP(__rt_sigprocmask)(int portable_how,
                               const sigset_portable_t *portable_sigset,
                               sigset_portable_t *portable_oldset,
                               size_t sigsetsize)
 {
-    extern int __rt_sigprocmask(int, const sigset_t *, sigset_t *, size_t);
+    extern int REAL(__rt_sigprocmask)(int, const sigset_t *, sigset_t *, size_t);
     int rv;
 
     ALOGV(" ");
@@ -1531,7 +1537,7 @@
         rv = -1;
         goto done;
     }
-    rv = do_sigmask(portable_how, portable_sigset, portable_oldset, NULL, __rt_sigprocmask);
+    rv = do_sigmask(portable_how, portable_sigset, portable_oldset, NULL, REAL(__rt_sigprocmask));
 
  done:
     ALOGV("%s: return(rv:%d); }", __func__, rv);
@@ -1540,12 +1546,12 @@
 }
 
 
-int __rt_sigtimedwait_portable(const sigset_portable_t *portable_sigset,
+int WRAP(__rt_sigtimedwait)(const sigset_portable_t *portable_sigset,
                                siginfo_portable_t *portable_siginfo,
                                const struct timespec *timeout,
                                size_t portable_sigsetsize)
 {
-    extern int __rt_sigtimedwait(const sigset_t *, siginfo_t *, const struct timespec *, size_t);
+    extern int REAL(__rt_sigtimedwait)(const sigset_t *, siginfo_t *, const struct timespec *, size_t);
 
     sigset_t native_sigset_struct;
     sigset_t *native_sigset = &native_sigset_struct;
@@ -1573,7 +1579,7 @@
     } else {
         native_siginfo = &native_siginfo_struct;
     }
-    rv = __rt_sigtimedwait(native_sigset, native_siginfo, timeout, sizeof(sigset_t));
+    rv = REAL(__rt_sigtimedwait)(native_sigset, native_siginfo, timeout, sizeof(sigset_t));
     if (rv == 0 && native_siginfo != NULL) {
         /* Map siginfo struct from native to portable format. */
         siginfo_ntop(native_siginfo, portable_siginfo);
@@ -1604,7 +1610,7 @@
  *
  *    sigqueue() must return EAGAIN if exceeded and we don't on Android.
  */
-int sigqueue_portable(pid_t pid, int portable_sig, const union sigval value)
+int WRAP(sigqueue)(pid_t pid, int portable_sig, const union sigval value)
 {
     siginfo_t native_siginfo;
     siginfo_t *native_sip;
@@ -1646,7 +1652,7 @@
 /*
  * Real Time version of sigqueueinfo().
  */
-int rt_sigqueueinfo_portable(pid_t pid, int portable_sig, siginfo_portable_t *portable_sip)
+int WRAP(rt_sigqueueinfo)(pid_t pid, int portable_sig, siginfo_portable_t *portable_sip)
 {
     int native_sig;
     siginfo_t native_siginfo, *native_sip;
@@ -1676,7 +1682,7 @@
 /*
  * Thread Group flavor of the real time version of sigqueueinfo().
  */
-int rt_tgsigqueueinfo_portable(pid_t tgid, pid_t pid, int portable_sig,
+int WRAP(rt_tgsigqueueinfo)(pid_t tgid, pid_t pid, int portable_sig,
                                siginfo_portable_t *portable_sip)
 {
     siginfo_t native_siginfo, *native_sip;
@@ -1715,7 +1721,7 @@
  *    } stack_t;
  *
  */
-int sigaltstack_portable(const portable_stack_t *ss, portable_stack_t *oss)
+int WRAP(sigaltstack)(const portable_stack_t *ss, portable_stack_t *oss)
 {
     int rv;
     stack_t new_stack, *mips_ss;
@@ -1754,7 +1760,7 @@
         }
     }
 
-    rv = sigaltstack(mips_ss, mips_oss);
+    rv = REAL(sigaltstack)(mips_ss, mips_oss);
 
     if (!invalid_pointer(oss)) {
         oss->ss_sp = old_stack.ss_sp;
diff --git a/ndk/sources/android/libportable/arch-mips/sigsetjmp.S b/ndk/sources/android/libportable/arch-mips/sigsetjmp.S
index fa6aba9..237d46b 100644
--- a/ndk/sources/android/libportable/arch-mips/sigsetjmp.S
+++ b/ndk/sources/android/libportable/arch-mips/sigsetjmp.S
@@ -31,6 +31,7 @@
  * SUCH DAMAGE.
  */
 
+#include <asm-generic/portability.h>
 #include <machine/asm.h>
 #include <machine/regnum.h>
 
@@ -42,7 +43,7 @@
 FRAMESZ= MKFSIZ(1,1)
 GPOFF= FRAMESZ-2*REGSZ
 
-LEAF(sigsetjmp_portable, FRAMESZ)
+LEAF(WRAP(sigsetjmp), FRAMESZ)
         PTR_SUBU sp, FRAMESZ
         SETUP_GP64(GPOFF, sigsetjmp)
         .set    reorder
@@ -53,15 +54,15 @@
         PTR_ADDU sp, FRAMESZ
         jr t9
 
-1:      LA      t9, setjmp_portable
+1:      LA      t9, WRAP(setjmp)
         RESTORE_GP64
         PTR_ADDU sp, FRAMESZ
         jr t9
-END(sigsetjmp_portable)
+END(WRAP(sigsetjmp))
 
-LEAF(siglongjmp_portable, FRAMESZ)
+LEAF(WRAP(siglongjmp), FRAMESZ)
         PTR_SUBU sp, FRAMESZ
-        SETUP_GP64(GPOFF, siglongjmp_portable)
+        SETUP_GP64(GPOFF, WRAP(siglongjmp))
         .set    reorder
         REG_L   t0, JB_SAVEMASK(a0)             # get "savemask"
         bne     t0, 0x0, 1f                     # restore signal mask?
@@ -70,8 +71,8 @@
         PTR_ADDU sp, FRAMESZ
         jr      t9
 1:
-        LA      t9, longjmp_portable
+        LA      t9, WRAP(longjmp)
         RESTORE_GP64
         PTR_ADDU sp, FRAMESZ
         jr      t9
-END(siglongjmp_portable)
+END(WRAP(siglongjmp))
diff --git a/ndk/sources/android/libportable/arch-mips/socket.c b/ndk/sources/android/libportable/arch-mips/socket.c
index 32a3157..be2c7e6 100644
--- a/ndk/sources/android/libportable/arch-mips/socket.c
+++ b/ndk/sources/android/libportable/arch-mips/socket.c
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <unistd.h>
 #include <sys/socket.h>
 #include <fcntl.h>
@@ -127,30 +128,30 @@
 }
 
 
-extern int socket(int, int, int);
+extern int REAL(socket)(int, int, int);
 
-int socket_portable(int domain, int type, int protocol) {
+int WRAP(socket)(int domain, int type, int protocol) {
     int rv;
 
     ALOGV(" ");
     ALOGV("%s(domain:%d, type:%d, protocol:%d) {", __func__,
               domain,    type,    protocol);
 
-    rv = socket(domain, socktype_pton(type), protocol);
+    rv = REAL(socket)(domain, socktype_pton(type), protocol);
 
     ALOGV("%s: return(rv:%d); }", __func__, rv);
     return rv;
 }
 
 
-int socketpair_portable(int domain, int type, int protocol, int sv[2]) {
+int WRAP(socketpair)(int domain, int type, int protocol, int sv[2]) {
     int rv;
 
     ALOGV(" ");
     ALOGV("%s(domain:%d, type:%d, protocol:%d, sv[2]:%p) {", __func__,
               domain,    type,    protocol,    sv);
 
-    rv = socketpair(domain, socktype_pton(type), protocol, sv);
+    rv = REAL(socketpair)(domain, socktype_pton(type), protocol, sv);
 
     if ((rv != 0) || invalid_pointer(sv)) {
         ALOGV("%s: return(rv:%d); }", __func__,
@@ -175,7 +176,7 @@
  * later made free with a call to the portable version of
  * freeaddrinfo(); which is written below this function.
  */
-int getaddrinfo_portable(const char *node, const char *service,
+int WRAP(getaddrinfo)(const char *node, const char *service,
                  struct addrinfo_portable *portable_hints,
                  struct addrinfo_portable **portable_results)
 {
@@ -203,7 +204,7 @@
     ASSERT(portable_results != NULL);
     native_results = (struct addrinfo **) portable_results;
 
-    rv = getaddrinfo(node, service, native_hints, native_results);
+    rv = REAL(getaddrinfo)(node, service, native_hints, native_results);
 
     if (native_hints != NULL) {
         portable_hints->ai_socktype = saved_portable_socktype;
@@ -230,7 +231,7 @@
  * Free the results list returned from a previous call
  * to the portable version of getaddrinfo().
  */
-void freeaddrinfo_portable(struct addrinfo_portable *portable_results)
+void WRAP(freeaddrinfo)(struct addrinfo_portable *portable_results)
 {
     struct addrinfo *native_results, *rp;
 
@@ -253,7 +254,7 @@
         PRINT_ADDRINFO(rp);
         rp->ai_socktype = socktype_pton(rp->ai_socktype);       /* Likely not really necessary */
     }
-    freeaddrinfo(native_results);
+    REAL(freeaddrinfo)(native_results);
 
     ALOGV("%s: return; }", __func__);
     return;
diff --git a/ndk/sources/android/libportable/arch-mips/sockopt.c b/ndk/sources/android/libportable/arch-mips/sockopt.c
index 6435cdc..6c7ec51 100644
--- a/ndk/sources/android/libportable/arch-mips/sockopt.c
+++ b/ndk/sources/android/libportable/arch-mips/sockopt.c
@@ -14,11 +14,11 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <socket_portable.h>
 
-
 #if SOL_SOCKET_PORTABLE==SOL_SOCKET
 #error Build environment
 #endif
@@ -108,13 +108,13 @@
 }
 
 extern int setsockopt(int, int, int, const void *, socklen_t);
-int setsockopt_portable(int s, int level, int optname, const void *optval, socklen_t optlen)
+int WRAP(setsockopt)(int s, int level, int optname, const void *optval, socklen_t optlen)
 {
-    return setsockopt(s, mips_change_level(level), mips_change_optname(optname), optval, optlen);
+    return REAL(setsockopt)(s, mips_change_level(level), mips_change_optname(optname), optval, optlen);
 }
 
 extern int getsockopt (int, int, int, void *, socklen_t *);
-int getsockopt_portable(int s, int level, int optname, void *optval, socklen_t *optlen)
+int WRAP(getsockopt)(int s, int level, int optname, void *optval, socklen_t *optlen)
 {
-    return getsockopt(s, mips_change_level(level), mips_change_optname(optname), optval, optlen);
+    return REAL(getsockopt)(s, mips_change_level(level), mips_change_optname(optname), optval, optlen);
 }
diff --git a/ndk/sources/android/libportable/arch-mips/stat.c b/ndk/sources/android/libportable/arch-mips/stat.c
index f8322c1..06fb42d 100644
--- a/ndk/sources/android/libportable/arch-mips/stat.c
+++ b/ndk/sources/android/libportable/arch-mips/stat.c
@@ -14,13 +14,12 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <errno.h>
 #include <stat_portable.h>
 
-#include <portability.h>
-
 /* Note: The Portable Header will define stat to stat_portable */
-int stat_portable(const char *path, struct stat_portable *s)
+int WRAP(stat)(const char *path, struct stat_portable *s)
 {
     struct stat mips_stat;
     int ret;
@@ -29,12 +28,12 @@
         errno = EFAULT;
         return -1;
     }
-    ret = stat(path, &mips_stat);
+    ret = REAL(stat)(path, &mips_stat);
     stat_ntop(&mips_stat, s);
     return ret;
 }
 
-int fstat_portable(int fd, struct stat_portable *s)
+int WRAP(fstat)(int fd, struct stat_portable *s)
 {
     struct stat mips_stat;
     int ret;
@@ -43,12 +42,12 @@
         errno = EFAULT;
         return -1;
     }
-    ret = fstat(fd, &mips_stat);
+    ret = REAL(fstat)(fd, &mips_stat);
     stat_ntop(&mips_stat, s);
     return ret;
 }   
 
-int lstat_portable(const char *path, struct stat_portable *s)
+int WRAP(lstat)(const char *path, struct stat_portable *s)
 {
     struct stat mips_stat;
     int ret;
@@ -57,12 +56,12 @@
         errno = EFAULT;
         return -1;
     }
-    ret = lstat(path, &mips_stat);
+    ret = REAL(lstat)(path, &mips_stat);
     stat_ntop(&mips_stat, s);
     return ret;
 }
 
-int fstatat_portable(int dirfd, const char *path, struct stat_portable *s, int flags)
+int WRAP(fstatat)(int dirfd, const char *path, struct stat_portable *s, int flags)
 {
     struct stat mips_stat;
     int ret;
@@ -71,7 +70,7 @@
         errno = EFAULT;
         return -1;
     }
-    ret = fstatat(dirfd, path, &mips_stat, flags);
+    ret = REAL(fstatat)(dirfd, path, &mips_stat, flags);
     stat_ntop(&mips_stat, s);
     return ret;
 }
diff --git a/ndk/sources/android/libportable/arch-mips/statfs.c b/ndk/sources/android/libportable/arch-mips/statfs.c
index 33ed1c6..6c0e079 100644
--- a/ndk/sources/android/libportable/arch-mips/statfs.c
+++ b/ndk/sources/android/libportable/arch-mips/statfs.c
@@ -14,12 +14,11 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <string.h>
 #include <errno.h>
 #include <statfs_portable.h>
 
-#include <portability.h>
-
 static inline void statfs_ntop(struct statfs *n_statfs, struct statfs_portable *p_statfs)
 {
     memset(p_statfs, '\0', sizeof(struct statfs_portable));
@@ -35,7 +34,7 @@
     p_statfs->f_frsize = n_statfs->f_frsize;
 }
 
-int statfs_portable(const char*  path, struct statfs_portable*  stat)
+int WRAP(statfs)(const char*  path, struct statfs_portable*  stat)
 {
     struct statfs mips_stat;
     int ret;
@@ -44,12 +43,12 @@
         errno = EFAULT;
         return -1;
     }
-    ret = statfs(path, &mips_stat);
+    ret = REAL(statfs)(path, &mips_stat);
     statfs_ntop(&mips_stat, stat);
     return ret;
 }
 
-int fstatfs_portable(int fd, struct statfs_portable*  stat)
+int WRAP(fstatfs)(int fd, struct statfs_portable*  stat)
 {
     struct statfs mips_stat;
     int ret;
@@ -58,7 +57,7 @@
         errno = EFAULT;
         return -1;
     }
-    ret = fstatfs(fd, &mips_stat);
+    ret = REAL(fstatfs)(fd, &mips_stat);
     statfs_ntop(&mips_stat, stat);
     return ret;
 }
diff --git a/ndk/sources/android/libportable/arch-mips/syscall.c b/ndk/sources/android/libportable/arch-mips/syscall.c
index aa145b9..39d15d9 100644
--- a/ndk/sources/android/libportable/arch-mips/syscall.c
+++ b/ndk/sources/android/libportable/arch-mips/syscall.c
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <unistd.h>
 #include <stdarg.h>
 #include <signal.h>
@@ -48,11 +49,11 @@
  */
 
 
-extern int syscall(int, ...);
+extern int REAL(syscall)(int, ...);
 
 #define MAXARGS 8
 
-int syscall_portable(int portable_number, ...)
+int WRAP(syscall)(int portable_number, ...)
 {
     va_list ap;
     int native_number, ret;
@@ -126,7 +127,7 @@
 
         va_end(ap);
 
-        ret = eventfd_portable(initval, flags);      /* Android uses __NR_eventfd2 in eventfd() */
+        ret = WRAP(eventfd)(initval, flags);      /* Android uses __NR_eventfd2 in eventfd() */
         goto done;
     }
 #endif
@@ -148,7 +149,7 @@
 
         va_end(ap);
 
-        ret = eventfd_portable(initval, flags);      /* Android uses __NR_eventfd2 in eventfd() */
+        ret = WRAP(eventfd)(initval, flags);      /* Android uses __NR_eventfd2 in eventfd() */
         goto done;
     }
 #endif
@@ -229,7 +230,7 @@
         portable_flags = va_arg(ap, int);
         va_end(ap);
 
-        ret = inotify_init1_portable(portable_flags);
+        ret = WRAP(inotify_init1)(portable_flags);
         goto done;
     }
 #endif
@@ -268,7 +269,7 @@
         portable_flags = va_arg(ap, int);
         va_end(ap);
 
-        ret = pipe2_portable(pipefd_ptr, portable_flags);
+        ret = WRAP(pipe2)(pipefd_ptr, portable_flags);
         goto done;
     }
 #endif
@@ -298,7 +299,7 @@
         oact = va_arg(ap, struct sigaction_portable *);
         sigsetsize = va_arg(ap, size_t);
         va_end(ap);
-        return __rt_sigaction_portable(sig, act, oact, sigsetsize);
+        return WRAP(__rt_sigaction)(sig, act, oact, sigsetsize);
     }
 #endif
 
@@ -316,7 +317,7 @@
         sigsetsize = va_arg(ap, size_t);
         va_end(ap);
 
-        ret = __rt_sigprocmask_portable(how, set, oset, sigsetsize);
+        ret = WRAP(__rt_sigprocmask)(how, set, oset, sigsetsize);
         goto done;
     }
 #endif
@@ -335,7 +336,7 @@
         sigsetsize = va_arg(ap, size_t);
         va_end(ap);
 
-        ret = __rt_sigtimedwait_portable(set, info, timeout, sigsetsize);
+        ret = WRAP(__rt_sigtimedwait)(set, info, timeout, sigsetsize);
         goto done;
     }
 #endif
@@ -352,7 +353,7 @@
         uinfo = va_arg(ap, siginfo_portable_t *);
         va_end(ap);
 
-        ret = rt_sigqueueinfo_portable(pid, sig, uinfo);
+        ret = WRAP(rt_sigqueueinfo)(pid, sig, uinfo);
         goto done;
     }
 #endif
@@ -465,7 +466,7 @@
               native_number, fd, align_fill, offset_low, offset_high,
               nbytes_low, nbytes_high, flags);
 
-        ret = syscall(native_number, fd, align_fill, offset_low, offset_high,
+        ret = REAL(syscall)(native_number, fd, align_fill, offset_low, offset_high,
                       nbytes_low, nbytes_high, flags);
 
         goto done;
@@ -501,7 +502,7 @@
         timerid = va_arg(ap, timer_t *);
         va_end(ap);
 
-        ret = timer_create_portable(clockid, evp, timerid);
+        ret = WRAP(timer_create)(clockid, evp, timerid);
         goto done;
     }
 #endif
@@ -516,7 +517,7 @@
         flags = va_arg(ap, int);                /* flags need to be mapped */
         va_end(ap);
 
-        ret = timerfd_create_portable(clockid, flags);
+        ret = WRAP(timerfd_create)(clockid, flags);
         goto done;
     }
 #endif
@@ -555,7 +556,7 @@
         uinfo = va_arg(ap, siginfo_portable_t *);
         va_end(ap);
 
-        ret = rt_tgsigqueueinfo_portable(tgid, pid, sig, uinfo);
+        ret = WRAP(rt_tgsigqueueinfo)(tgid, pid, sig, uinfo);
         goto done;
     }
 #endif
@@ -569,7 +570,7 @@
         sig = va_arg(ap, int);
         va_end(ap);
 
-        ret = tkill_portable(tid, sig);
+        ret = WRAP(tkill)(tid, sig);
         goto done;
     }
 #endif
@@ -627,7 +628,7 @@
           native_number, args[0], args[1], args[2], args[3], args[4],
           args[5], args[6], args[7]);
 
-    ret = syscall(native_number, args[0], args[1], args[2], args[3],
+    ret = REAL(syscall)(native_number, args[0], args[1], args[2], args[3],
                   args[4], args[5], args[6], args[7]);
 
 done:
diff --git a/ndk/sources/android/libportable/arch-mips/timer.c b/ndk/sources/android/libportable/arch-mips/timer.c
index 037a524..c2844e1 100644
--- a/ndk/sources/android/libportable/arch-mips/timer.c
+++ b/ndk/sources/android/libportable/arch-mips/timer.c
@@ -14,13 +14,12 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <signal.h>
 #include <signal_portable.h>
 #include <time.h>
 
-#include <portability.h>
-
-int timer_create_portable(clockid_t clockid, struct sigevent *portable_evp,
+int WRAP(timer_create)(clockid_t clockid, struct sigevent *portable_evp,
                           timer_t *timerid)
 {
     struct sigevent native_sigevent, *evp = portable_evp;
@@ -33,5 +32,5 @@
         evp = &native_sigevent;
         evp->sigev_signo = signum_pton(evp->sigev_signo);
     }
-    return timer_create(clockid, evp, timerid);
+    return REAL(timer_create)(clockid, evp, timerid);
 }
diff --git a/ndk/sources/android/libportable/arch-mips/timerfd.c b/ndk/sources/android/libportable/arch-mips/timerfd.c
index 3196d18..b57c3f2 100644
--- a/ndk/sources/android/libportable/arch-mips/timerfd.c
+++ b/ndk/sources/android/libportable/arch-mips/timerfd.c
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <unistd.h>
 #include <fcntl.h>
 
@@ -57,7 +58,7 @@
 }
 
 
-int timerfd_create_portable(int clockid, int portable_flags) {
+int WRAP(timerfd_create)(int clockid, int portable_flags) {
     int rv;
     int native_flags;
 
@@ -67,7 +68,7 @@
 
     native_flags = tdf_flags_pton(portable_flags);
 
-    rv = syscall(__NR_timerfd_create, clockid, native_flags);
+    rv = REAL(syscall)(__NR_timerfd_create, clockid, native_flags);
     if (rv >= 0) {
         if (native_flags & TFD_CLOEXEC) {
             filefd_CLOEXEC_enabled(rv);
diff --git a/ndk/sources/android/libportable/arch-mips/waitpid.c b/ndk/sources/android/libportable/arch-mips/waitpid.c
index ae7a9b9..77e6283 100644
--- a/ndk/sources/android/libportable/arch-mips/waitpid.c
+++ b/ndk/sources/android/libportable/arch-mips/waitpid.c
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <stdarg.h>
 #include <stdlib.h>
 #include <signal.h>
@@ -24,11 +25,11 @@
 #define PORTABLE_TAG            "waitpid_portable"
 #include <log_portable.h>
 
-pid_t waitpid_portable(pid_t pid, int *status, int options)
+pid_t WRAP(waitpid)(pid_t pid, int *status, int options)
 {
     pid_t ret;
 
-    ret = waitpid(pid, status, options);
+    ret = REAL(waitpid)(pid, status, options);
     if (status && ret > 0) {
         /*
          * Status layout is identical, so just the signal
diff --git a/ndk/sources/android/libportable/arch-x86/epoll.c b/ndk/sources/android/libportable/arch-x86/epoll.c
index e2f91f2..c683441 100644
--- a/ndk/sources/android/libportable/arch-x86/epoll.c
+++ b/ndk/sources/android/libportable/arch-x86/epoll.c
@@ -14,23 +14,24 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <sys/epoll.h>
 #include <epoll_portable.h>
 
-int epoll_ctl_portable(int epfd, int op, int fd, struct epoll_event_portable *event)
+int WRAP(epoll_ctl)(int epfd, int op, int fd, struct epoll_event_portable *event)
 {
     struct epoll_event x86_epoll_event;
 
     x86_epoll_event.events = event->events;
     x86_epoll_event.data = event->data;
 
-    return epoll_ctl(epfd, op, fd, &x86_epoll_event);
+    return REAL(epoll_ctl)(epfd, op, fd, &x86_epoll_event);
 }
 
-int epoll_wait_portable(int epfd, struct epoll_event_portable *events, int max, int timeout)
+int WRAP(epoll_wait)(int epfd, struct epoll_event_portable *events, int max, int timeout)
 {
     struct epoll_event x86_epoll_event;
-    int ret = epoll_wait(epfd, &x86_epoll_event, max, timeout);
+    int ret = REAL(epoll_wait)(epfd, &x86_epoll_event, max, timeout);
 
     events->events = x86_epoll_event.events;
     events->data = x86_epoll_event.data;
diff --git a/ndk/sources/android/libportable/arch-x86/errno.c b/ndk/sources/android/libportable/arch-x86/errno.c
index ffa5998..776b12e 100644
--- a/ndk/sources/android/libportable/arch-x86/errno.c
+++ b/ndk/sources/android/libportable/arch-x86/errno.c
@@ -14,8 +14,10 @@
  * limitations under the License.
  */
 
-extern volatile int*   __errno(void);
-volatile int* __errno_portable()
+#include <portability.h>
+
+extern volatile int*   REAL(__errno)(void);
+volatile int* WRAP(__errno)()
 {
-  return __errno();
+  return REAL(__errno)();
 }
diff --git a/ndk/sources/android/libportable/arch-x86/fcntl.c b/ndk/sources/android/libportable/arch-x86/fcntl.c
index 7561f85..74b14c1 100644
--- a/ndk/sources/android/libportable/arch-x86/fcntl.c
+++ b/ndk/sources/android/libportable/arch-x86/fcntl.c
@@ -14,13 +14,14 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <fcntl.h>
 #include <stdarg.h>
 #include <fcntl_portable.h>
 
 extern int __fcntl64(int, int, void *);
 
-int fcntl_portable(int fd, int cmd, ...)
+int WRAP(fcntl)(int fd, int cmd, ...)
 {
     va_list ap;
     void * arg;
diff --git a/ndk/sources/android/libportable/arch-x86/ioctl.c b/ndk/sources/android/libportable/arch-x86/ioctl.c
index ea88c30..01ddbcd 100644
--- a/ndk/sources/android/libportable/arch-x86/ioctl.c
+++ b/ndk/sources/android/libportable/arch-x86/ioctl.c
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <stdarg.h>
 #include <sys/ioctl.h>
 #include <ioctls_portable.h>
@@ -31,7 +32,7 @@
 }
 
 extern int __ioctl(int, int, void *);
-int ioctl_portable(int fd, int request, ...)
+int WRAP(ioctl)(int fd, int request, ...)
 {
     va_list ap;
     void * arg;
diff --git a/ndk/sources/android/libportable/arch-x86/open.c b/ndk/sources/android/libportable/arch-x86/open.c
index a38f38c..dae578b 100644
--- a/ndk/sources/android/libportable/arch-x86/open.c
+++ b/ndk/sources/android/libportable/arch-x86/open.c
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <stdarg.h>
@@ -56,7 +57,7 @@
 }
 
 extern int  __open(const char*, int, int);
-int open_portable(const char *pathname, int flags, ...)
+int WRAP(open)(const char *pathname, int flags, ...)
 {
     mode_t  mode = 0;
     flags |= O_LARGEFILE;
diff --git a/ndk/sources/android/libportable/arch-x86/socket.c b/ndk/sources/android/libportable/arch-x86/socket.c
index 7e7ca9b..72211c9 100644
--- a/ndk/sources/android/libportable/arch-x86/socket.c
+++ b/ndk/sources/android/libportable/arch-x86/socket.c
@@ -14,10 +14,11 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <unistd.h>
 #include <sys/socket.h>
 #include <sys/linux-syscalls.h>
 
-int socket_portable(int domain, int type, int protocol) {
-    return socket(domain, type, protocol);
+int WRAP(socket)(int domain, int type, int protocol) {
+    return REAL(socket)(domain, type, protocol);
 }
diff --git a/ndk/sources/android/libportable/arch-x86/sockopt.c b/ndk/sources/android/libportable/arch-x86/sockopt.c
index c86ded3..87d8b2f 100644
--- a/ndk/sources/android/libportable/arch-x86/sockopt.c
+++ b/ndk/sources/android/libportable/arch-x86/sockopt.c
@@ -14,17 +14,18 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 
-extern int setsockopt(int, int, int, const void *, socklen_t);
-int setsockopt_portable(int s, int level, int optname, const void *optval, socklen_t optlen)
+extern int REAL(setsockopt)(int, int, int, const void *, socklen_t);
+int WRAP(setsockopt)(int s, int level, int optname, const void *optval, socklen_t optlen)
 {
-    return setsockopt(s, level, optname, optval, optlen);
+   return REAL(setsockopt)(s, level, optname, optval, optlen);
 }
 
-extern int getsockopt (int, int, int, void *, socklen_t *);
-int getsockopt_portable(int s, int level, int optname, void *optval, socklen_t *optlen)
+extern int REAL(getsockopt)(int, int, int, void *, socklen_t *);
+int WRAP(getsockopt)(int s, int level, int optname, void *optval, socklen_t *optlen)
 {
-    return getsockopt(s, level, optname, optval, optlen);
+    return REAL(getsockopt)(s, level, optname, optval, optlen);
 }
diff --git a/ndk/sources/android/libportable/arch-x86/stat.c b/ndk/sources/android/libportable/arch-x86/stat.c
index 6b368c8..1d17378 100644
--- a/ndk/sources/android/libportable/arch-x86/stat.c
+++ b/ndk/sources/android/libportable/arch-x86/stat.c
@@ -14,37 +14,38 @@
  * limitations under the License.
  */
 
+#include <portability.h>
 #include <stat_portable.h>
 
 /* Note: The Portable Header will define stat to stat_portable */
-int stat_portable(const char *path, struct stat_portable *s)
+int WRAP(stat)(const char *path, struct stat_portable *s)
 {
     struct stat x86_stat;
-    int ret = stat(path, &x86_stat);
+    int ret = REAL(stat)(path, &x86_stat);
     stat_ntop(&x86_stat, s);
     return ret;
 }
 
-int fstat_portable(int fd, struct stat_portable *s)
+int WRAP(fstat)(int fd, struct stat_portable *s)
 {
     struct stat x86_stat;
-    int ret = fstat(fd, &x86_stat);
+    int ret = REAL(fstat)(fd, &x86_stat);
     stat_ntop(&x86_stat, s);
     return ret;
 }   
 
-int lstat_portable(const char *path, struct stat_portable *s)
+int WRAP(lstat)(const char *path, struct stat_portable *s)
 {
     struct stat x86_stat;
-    int ret = lstat(path, &x86_stat);
+    int ret = REAL(lstat)(path, &x86_stat);
     stat_ntop(&x86_stat, s);
     return ret;
 }
 
-int fstatat_portable(int dirfd, const char *path, struct stat_portable *s, int flags)
+int WRAP(fstatat)(int dirfd, const char *path, struct stat_portable *s, int flags)
 {
     struct stat x86_stat;
-    int ret = fstatat(dirfd, path, &x86_stat, flags);
+    int ret = REAL(fstatat)(dirfd, path, &x86_stat, flags);
     stat_ntop(&x86_stat, s);
     return ret;
 }
diff --git a/ndk/sources/android/libportable/common/include/asm-generic/portability.h b/ndk/sources/android/libportable/common/include/asm-generic/portability.h
new file mode 100644
index 0000000..8d91854
--- /dev/null
+++ b/ndk/sources/android/libportable/common/include/asm-generic/portability.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _ASM_PORTABILITY_H_
+#define _ASM_PORTABILITY_H_
+
+#if !defined(__HOST__)
+#define WRAP(f)     f ## _portable
+#define REAL(f)     f
+#else
+/* On host app link with libpportable.a with -Wl,--wrap=symbol, which resolve symbol symbol to __wrap_symbol,
+ * and __real_symbol refer to the original symbol
+ */
+#define WRAP(f)     __wrap_ ## f
+#define REAL(f)     __real_ ## f
+#endif
+
+#endif /* _ASM_PORTABILITY_H_ */
diff --git a/ndk/sources/android/libportable/common/include/eventfd_portable.h b/ndk/sources/android/libportable/common/include/eventfd_portable.h
index 7572fc5..d72ca8d 100644
--- a/ndk/sources/android/libportable/common/include/eventfd_portable.h
+++ b/ndk/sources/android/libportable/common/include/eventfd_portable.h
@@ -30,8 +30,8 @@
 #ifndef _SYS_EVENTFD_PORTABLE_H
 #define _SYS_EVENTFD_PORTABLE_H
 
-#include <sys/cdefs.h>
 #include <portability.h>
+#include <sys/cdefs.h>
 #include <fcntl_portable.h>
 
 __BEGIN_DECLS
@@ -50,7 +50,7 @@
 /* type of event counter */
 typedef uint64_t  eventfd_portable_t;
 
-extern int eventfd_portable(unsigned int initval, int flags);
+extern int WRAP(eventfd)(unsigned int initval, int flags);
 
 #if 0
 /* Compatibility with GLibc; libportable versions don't appear to be necessary */
diff --git a/ndk/sources/android/libportable/common/include/filefd_portable.h b/ndk/sources/android/libportable/common/include/filefd_portable.h
index 10c7b56..76cd4b8 100644
--- a/ndk/sources/android/libportable/common/include/filefd_portable.h
+++ b/ndk/sources/android/libportable/common/include/filefd_portable.h
@@ -37,8 +37,8 @@
 extern __hidden void filefd_CLOEXEC_disabled(int fd);
 extern __hidden void filefd_disable_mapping(void);
 
-extern int close_portable(int fd);
-extern int read_portable(int fd, void *buf, size_t count);
-extern int pipe2_portable(int pipefd[2], int portable_flags);
+extern int WRAP(close)(int fd);
+extern int WRAP(read)(int fd, void *buf, size_t count);
+extern int WRAP(pipe2)(int pipefd[2], int portable_flags);
 
 #endif /* _FILEFD_PORTABLE_H_ */
diff --git a/ndk/sources/android/libportable/common/include/inotify_portable.h b/ndk/sources/android/libportable/common/include/inotify_portable.h
index 2f08047..09d4d64 100644
--- a/ndk/sources/android/libportable/common/include/inotify_portable.h
+++ b/ndk/sources/android/libportable/common/include/inotify_portable.h
@@ -31,8 +31,8 @@
 #ifndef _SYS_INOTIFY_PORTABLE_H
 #define _SYS_INOTIFY_PORTABLE_H
 
-#include <sys/cdefs.h>
 #include <portability.h>
+#include <sys/cdefs.h>
 #include <fcntl.h>
 #include <fcntl_portable.h>
 
@@ -44,7 +44,7 @@
 #define  IN_CLOEXEC_PORTABLE   O_CLOEXEC_PORTABLE
 #define  IN_NONBLOCK_PORTABLE  O_NONBLOCK_PORTABLE
 
-extern int inotify_init1_portable(int flags);
+extern int WRAP(inotify_init1)(int flags);
 
 __END_DECLS
 
diff --git a/ndk/sources/android/libportable/common/include/log_portable.h b/ndk/sources/android/libportable/common/include/log_portable.h
index 27f521e..79baa62 100644
--- a/ndk/sources/android/libportable/common/include/log_portable.h
+++ b/ndk/sources/android/libportable/common/include/log_portable.h
@@ -81,7 +81,7 @@
     _rv;                   /* Returned to caller */         \
 })
 
-#if !defined(HAS_NO_LOG_H)
+#if !defined(__HOST__)
 #include <cutils/log.h>
 
 # define PERROR(str)  {                                                                  \
@@ -91,8 +91,11 @@
 # define ASSERT(cond) ALOG_ASSERT(cond, "assertion failed:(%s), file: %s, line: %d:%s",  \
                                  #cond, __FILE__, __LINE__, __func__);
 #else
-
+#include <assert.h>
 # define PERROR(str) fprintf(stderr, "%s: PERROR('%s'): errno:%d:'%s'", __func__, str, errno, strerror(errno))
 # define ASSERT(cond) assert(cond)
+# define ALOGV(a,...)
+# define ALOGW(a,...)
+# define ALOGE(a,...)
 
 #endif
\ No newline at end of file
diff --git a/ndk/sources/android/libportable/common/include/netdb_portable.h b/ndk/sources/android/libportable/common/include/netdb_portable.h
index 53db942..b3e6528 100644
--- a/ndk/sources/android/libportable/common/include/netdb_portable.h
+++ b/ndk/sources/android/libportable/common/include/netdb_portable.h
@@ -232,10 +232,10 @@
 const char      *hstrerror(int);
 #endif
 
-int getaddrinfo_portable(const char *, const char *, struct addrinfo_portable *,
+int WRAP(getaddrinfo)(const char *, const char *, struct addrinfo_portable *,
                          struct addrinfo_portable **);
 
-void freeaddrinfo_portable(struct addrinfo_portable *);
+void WRAP(freeaddrinfo)(struct addrinfo_portable *);
 
 #if 0 /* Not needed for addrinfo mapping */
 int getnameinfo(const struct sockaddr *, socklen_t, char *, size_t, char *, size_t, int);
diff --git a/ndk/sources/android/libportable/common/include/portability.h b/ndk/sources/android/libportable/common/include/portability.h
index 4293d9d..54f1406 100644
--- a/ndk/sources/android/libportable/common/include/portability.h
+++ b/ndk/sources/android/libportable/common/include/portability.h
@@ -17,6 +17,7 @@
 #ifndef _PORTABILITY_H_
 #define _PORTABILITY_H_
 
+#include "asm-generic/portability.h"
 /*
  * Common portability helper routines
  */
@@ -31,7 +32,7 @@
  */
 inline static int invalid_pointer(void *p)
 {
-    return p == NULL
+    return p == 0
         || p == (void *)-1
 #ifdef __mips__
         || (int)p < 0
diff --git a/ndk/sources/android/libportable/common/include/signal_portable.h b/ndk/sources/android/libportable/common/include/signal_portable.h
index abb9987..3ea8de1 100644
--- a/ndk/sources/android/libportable/common/include/signal_portable.h
+++ b/ndk/sources/android/libportable/common/include/signal_portable.h
@@ -64,7 +64,7 @@
 extern const char * const sys_siglist[];
 extern const char * const sys_signame[];
 
-static __inline__ int sigismember_portable(sigset_portable_t *set, int signum)
+static __inline__ int WRAP(sigismember)(sigset_portable_t *set, int signum)
 {
     unsigned long *local_set = (unsigned long *)set;
     signum--;
@@ -72,7 +72,7 @@
 }
 
 
-static __inline__ int sigaddset_portable(sigset_portable_t *set, int signum)
+static __inline__ int WRAP(sigaddset)(sigset_portable_t *set, int signum)
 {
     unsigned long *local_set = (unsigned long *)set;
     signum--;
@@ -81,7 +81,7 @@
 }
 
 
-static __inline__ int sigdelset_portable(sigset_portable_t *set, int signum)
+static __inline__ int WRAP(sigdelset)(sigset_portable_t *set, int signum)
 {
     unsigned long *local_set = (unsigned long *)set;
     signum--;
@@ -90,13 +90,13 @@
 }
 
 
-static __inline__ int sigemptyset_portable(sigset_portable_t *set)
+static __inline__ int WRAP(sigemptyset)(sigset_portable_t *set)
 {
     memset(set, 0, sizeof *set);
     return 0;
 }
 
-static __inline__ int sigfillset_portable(sigset_portable_t *set)
+static __inline__ int WRAP(sigfillset)(sigset_portable_t *set)
 {
     memset(set, ~0, sizeof *set);
     return 0;
@@ -116,34 +116,34 @@
 
 #if 0
 /* the default is bsd */
-static __inline__ __sighandler_portable_t signal_portable(int s, sighandler_portable_t f)
+static __inline__ __sighandler_portable_t WRAP(signal)(int s, sighandler_portable_t f)
 {
     return bsd_signal(s,f);
 }
 #endif
 
 /* the portable mapped syscall itself */
-extern __sighandler_portable_t __signal_portable(int, __sighandler_portable_t);
+extern __sighandler_portable_t WRAP(__signal)(int, __sighandler_portable_t);
 
-extern int sigprocmask_portable(int, const sigset_portable_t *, sigset_portable_t *);
+extern int WRAP(sigprocmask)(int, const sigset_portable_t *, sigset_portable_t *);
 
-extern int sigaction_portable(int, const struct sigaction_portable *,
+extern int WRAP(sigaction)(int, const struct sigaction_portable *,
                               struct sigaction_portable *);
 
-extern int sigpending_portable(sigset_portable_t *);
-extern int sigsuspend_portable(const sigset_portable_t *);
-extern int sigwait_portable(const sigset_portable_t *set, int *sig);
-extern int siginterrupt_portable(int  sig, int  flag);
+extern int WRAP(sigpending)(sigset_portable_t *);
+extern int WRAP(sigsuspend)(const sigset_portable_t *);
+extern int WRAP(sigwait)(const sigset_portable_t *set, int *sig);
+extern int WRAP(siginterrupt)(int  sig, int  flag);
 
-extern int raise_portable(int);
-extern int kill_portable(pid_t, int);
-extern int killpg_portable(int pgrp, int sig);
-extern int tkill_portable(int tid, int portable_signum);
-extern int sigaltstack_portable(const portable_stack_t *ss, portable_stack_t *oss);
-extern int timer_create_portable(clockid_t, struct sigevent *, timer_t *);
+extern int WRAP(raise)(int);
+extern int WRAP(kill)(pid_t, int);
+extern int WRAP(killpg)(int pgrp, int sig);
+extern int WRAP(tkill)(int tid, int portable_signum);
+extern int WRAP(sigaltstack)(const portable_stack_t *ss, portable_stack_t *oss);
+extern int WRAP(timer_create)(clockid_t, struct sigevent *, timer_t *);
 
 #if 0
-extern int signalfd_portable(int fd, const sigset_portable_t *portable_sigmask, int flags);
+extern int WRAP(signalfd)(int fd, const sigset_portable_t *portable_sigmask, int flags);
 #endif
 
 extern __hidden int do_signalfd4_portable(int fd, const sigset_portable_t *portable_sigmask,
@@ -167,26 +167,26 @@
 
 
 /* These functions are called from syscall.c and experimental Bionic linker. */
-extern int __rt_sigaction_portable(int portable_signum,
-                                   const struct sigaction_portable *act,
-                                   struct sigaction_portable *oldact,
-                                   size_t sigsetsize);
+extern int WRAP(__rt_sigaction)(int portable_signum,
+                                const struct sigaction_portable *act,
+                                struct sigaction_portable *oldact,
+                                size_t sigsetsize);
 
-extern int __rt_sigprocmask_portable(int portable_how,
-                                     const sigset_portable_t *portable_sigset,
-                                     sigset_portable_t *portable_oldset,
-                                     size_t sigsetsize);
+extern int WRAP(__rt_sigprocmask)(int portable_how,
+                                  const sigset_portable_t *portable_sigset,
+                                  sigset_portable_t *portable_oldset,
+                                  size_t sigsetsize);
 
-extern int __rt_sigtimedwait_portable(const sigset_portable_t *portable_sigset,
-                                      siginfo_portable_t *portable_siginfo,
-                                      const struct timespec *timeout,
-                                      size_t portable_sigsetsize);
+extern int WRAP(__rt_sigtimedwait)(const sigset_portable_t *portable_sigset,
+                                   siginfo_portable_t *portable_siginfo,
+                                   const struct timespec *timeout,
+                                   size_t portable_sigsetsize);
 
 
 /* These functions are only called from syscall.c; not experimental Bionic linker. */
-extern __hidden int rt_sigqueueinfo_portable(pid_t pid, int sig, siginfo_portable_t *uinfo);
+extern __hidden int WRAP(rt_sigqueueinfo)(pid_t pid, int sig, siginfo_portable_t *uinfo);
 
-extern __hidden int rt_tgsigqueueinfo_portable(pid_t tgid, pid_t pid, int sig,
+extern __hidden int WRAP(rt_tgsigqueueinfo)(pid_t tgid, pid_t pid, int sig,
                                                siginfo_portable_t *uinfo);
 
 
diff --git a/ndk/sources/android/libportable/common/include/timerfd_portable.h b/ndk/sources/android/libportable/common/include/timerfd_portable.h
index f83c0ed..d6c294c 100644
--- a/ndk/sources/android/libportable/common/include/timerfd_portable.h
+++ b/ndk/sources/android/libportable/common/include/timerfd_portable.h
@@ -31,8 +31,8 @@
 #ifndef _SYS_TIMERFD_PORTABLE_H
 #define _SYS_TIMERFD_PORTABLE_H
 
-#include <sys/cdefs.h>
 #include <portability.h>
+#include <sys/cdefs.h>
 #include <fcntl.h>
 #include <fcntl_portable.h>
 
@@ -44,7 +44,7 @@
 #define  TFD_CLOEXEC_PORTABLE   O_CLOEXEC_PORTABLE
 #define  TFD_NONBLOCK_PORTABLE  O_NONBLOCK_PORTABLE
 
-extern int timerfd_create_portable(int clockid, int flags);
+extern int WRAP(timerfd_create)(int clockid, int flags);
 
 __END_DECLS