Bug 1432473, Update NSPR to build with Android NDK r16. r=kaie
authorJim Chen <nchen@mozilla.com>
Tue, 23 Jan 2018 15:10:22 +0100
changeset 4778 66debb98223766062f811d52366398da8073938c
parent 4777 1b5d811e3b136ec14fe45d5e0914829fba8cac15
child 4779 d750caf6e4c65d80189facb3bcd4864ac2e1dc24
push id288
push userkaie@kuix.de
push dateTue, 23 Jan 2018 14:09:42 +0000
reviewerskaie
bugs1432473
Bug 1432473, Update NSPR to build with Android NDK r16. r=kaie
pr/src/md/unix/unix.c
--- a/pr/src/md/unix/unix.c
+++ b/pr/src/md/unix/unix.c
@@ -2708,18 +2708,23 @@ static void* _MD_Unix_mmap64(
     void *addr, PRSize len, PRIntn prot, PRIntn flags,
     PRIntn fildes, PRInt64 offset)
 {
     PR_SetError(PR_FILE_TOO_BIG_ERROR, 0);
     return NULL;
 }  /* _MD_Unix_mmap64 */
 #endif /* defined(_PR_NO_LARGE_FILES) || defined(SOLARIS2_5) */
 
-/* Android <= 19 doesn't have mmap64. */
-#if defined(ANDROID) && __ANDROID_API__ <= 19
+/* NDK non-unified headers for API < 21 don't have mmap64. However,
+ * NDK unified headers do provide mmap64 for all API versions when building
+ * with clang. Therefore, we should provide mmap64 here for API < 21 if we're
+ * not using clang or if we're using non-unified headers. We check for
+ * non-unified headers by the lack of __ANDROID_API_L__ macro. */
+#if defined(ANDROID) && __ANDROID_API__ < 21 && \
+    (!defined(__clang__) || !defined(__ANDROID_API_L__))
 PR_IMPORT(void) *__mmap2(void *, size_t, int, int, int, size_t);
 
 #define ANDROID_PAGE_SIZE 4096
 
 static void *
 mmap64(void *addr, size_t len, int prot, int flags, int fd, loff_t offset)
 {
     if (offset & (ANDROID_PAGE_SIZE - 1)) {
@@ -2779,28 +2784,34 @@ static void _PR_InitIOV(void)
     }
 #elif defined(_PR_NO_LARGE_FILES)
     _md_iovector._open64 = open;
     _md_iovector._mmap64 = _MD_Unix_mmap64;
     _md_iovector._fstat64 = fstat;
     _md_iovector._stat64 = stat;
     _md_iovector._lseek64 = _MD_Unix_lseek64;
 #elif defined(_PR_HAVE_OFF64_T)
-#if defined(IRIX5_3) || defined(ANDROID)
+#if defined(IRIX5_3) || (defined(ANDROID) && __ANDROID_API__ < 21)
     /*
-     * Android doesn't have open64.  We pass the O_LARGEFILE flag to open
+     * Android < 21 doesn't have open64.  We pass the O_LARGEFILE flag to open
      * in _MD_open.
      */
     _md_iovector._open64 = open;
 #else
     _md_iovector._open64 = open64;
 #endif
     _md_iovector._mmap64 = mmap64;
+#if (defined(ANDROID) && __ANDROID_API__ < 21)
+    /* Same as the open64 case for Android. */
+    _md_iovector._fstat64 = fstat;
+    _md_iovector._stat64 = stat;
+#else
     _md_iovector._fstat64 = fstat64;
     _md_iovector._stat64 = stat64;
+#endif
     _md_iovector._lseek64 = lseek64;
 #elif defined(_PR_HAVE_LARGE_OFF_T)
     _md_iovector._open64 = open;
     _md_iovector._mmap64 = mmap;
 #if defined(OSF1) && defined(__GNUC__)
     _md_iovector._fstat64 = fstat_forwarder;
     _md_iovector._stat64 = stat_forwarder;
 #else