OSDN Git Service

Revert "move android_ids into bionic"
authorElliott Hughes <enh@google.com>
Tue, 13 Dec 2016 00:42:35 +0000 (00:42 +0000)
committerandroid-build-merger <android-build-merger@google.com>
Tue, 13 Dec 2016 00:42:35 +0000 (00:42 +0000)
am: 77cb68d9f2

Change-Id: I45d8098e38dd35fdf9b3d270ac4f26c3a7284971

37 files changed:
README.md
libc/Android.bp
libc/NOTICE
libc/SYSCALLS.TXT
libc/arch-arm/bionic/abort_arm.S [deleted file]
libc/bionic/abort.cpp
libc/bionic/bionic_arc4random.cpp
libc/bionic/pathconf.cpp
libc/bionic/wcstod.cpp
libc/bionic/wctype.cpp
libc/dns/net/getaddrinfo.c
libc/dns/net/getnameinfo.c
libc/dns/resolv/res_cache.c
libc/dns/resolv/res_init.c
libc/dns/resolv/res_state.c
libc/include/limits.h
libc/include/sys/limits.h
libc/include/sys/uio.h
libc/private/bionic_arc4random.h
libc/private/icu.h
libdl/Android.bp
libdl/ld_android.c [new file with mode: 0644]
libdl/libdl.c
libm/Android.bp
linker/Android.bp
linker/dlfcn.cpp
linker/linker.cpp
linker/linker.h
linker/linker_main.cpp
linker/linker_soinfo.h
tests/gtest_main.cpp
tests/inttypes_test.cpp
tests/pty_test.cpp
tests/stdlib_test.cpp
tests/sys_prctl_test.cpp
tests/unistd_test.cpp
tests/wchar_test.cpp

index 0dd7490..61314b6 100644 (file)
--- a/README.md
+++ b/README.md
@@ -200,9 +200,8 @@ The tests are all built from the tests/ directory.
 
 ### Device tests
 
-    $ mma
-    $ adb remount
-    $ adb sync
+    $ mma # In $ANDROID_ROOT/bionic.
+    $ adb root && adb remount && adb sync
     $ adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests32
     $ adb shell \
         /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static32
@@ -216,6 +215,30 @@ options documented at
 <https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md#running-test-programs-advanced-options>,
 in particular for test isolation and parallelism (both on by default).
 
+### Device tests via CTS
+
+Most of the unit tests are executed by CTS. By default, CTS runs as
+a non-root user, so the unit tests must also pass when not run as root.
+Some tests cannot do any useful work unless run as root. In this case,
+the test should check `getuid() == 0` and do nothing otherwise (typically
+we log in this case to prevent accidents!). Obviously, if the test can be
+rewritten to not require root, that's an even better solution.
+
+Currently, the list of bionic CTS tests is generated at build time by
+running a host version of the test executable and dumping the list of
+all tests. In order for this to continue to work, all architectures must
+have the same number of tests, and the host version of the executable
+must also have the same number of tests.
+
+Running the gtests directly is orders of magnitude faster than using CTS,
+but in cases where you really have to run CTS:
+
+    $ make cts # In $ANDROID_ROOT.
+    $ adb unroot # Because real CTS doesn't run as root.
+    # This will sync any *test* changes, but not *code* changes:
+    $ cts-tradefed \
+        run singleCommand cts --skip-preconditions -m CtsBionicTestCases
+
 ### Host tests
 
 The host tests require that you have `lunch`ed either an x86 or x86_64 target.
index 094ad5c..b1d077d 100644 (file)
@@ -779,7 +779,6 @@ cc_library_static {
                 "arch-arm/generic/bionic/strcpy.S",
                 "arch-arm/generic/bionic/strlen.c",
 
-                "arch-arm/bionic/abort_arm.S",
                 "arch-arm/bionic/atomics_arm.c",
                 "arch-arm/bionic/__bionic_clone.S",
                 "arch-arm/bionic/_exit_with_stack_teardown.S",
@@ -1579,10 +1578,9 @@ cc_library_static {
 // dynamic linker.
 
 cc_library_static {
+    name: "libc_nomalloc",
+
     defaults: ["libc_defaults"],
-    srcs: [
-        "bionic/dl_iterate_phdr_static.cpp",
-    ],
 
     arch: {
         arm: {
@@ -1592,8 +1590,6 @@ cc_library_static {
 
     cflags: ["-DLIBC_STATIC"],
 
-    name: "libc_nomalloc",
-
     whole_static_libs: [
         "libc_common",
         "libc_init_static",
@@ -2009,10 +2005,21 @@ cc_object {
 // }
 
 ndk_headers {
-    name: "libc_linux",
-    from: "kernel/uapi/linux",
-    to: "linux",
-    srcs: ["kernel/uapi/linux/**/*.h"],
+    name: "libc_uapi",
+    from: "kernel/uapi",
+    to: "",
+    srcs: [
+        "kernel/uapi/asm-generic/**/*.h",
+        "kernel/uapi/drm/**/*.h",
+        "kernel/uapi/linux/**/*.h",
+        "kernel/uapi/misc/**/*.h",
+        "kernel/uapi/mtd/**/*.h",
+        "kernel/uapi/rdma/**/*.h",
+        "kernel/uapi/scsi/**/*.h",
+        "kernel/uapi/sound/**/*.h",
+        "kernel/uapi/video/**/*.h",
+        "kernel/uapi/xen/**/*.h",
+    ],
     license: "NOTICE",
 }
 
@@ -2025,14 +2032,6 @@ ndk_headers {
 }
 
 ndk_headers {
-    name: "libc_asm_generic",
-    from: "kernel/uapi/asm-generic",
-    to: "asm-generic",
-    srcs: ["kernel/uapi/asm-generic/**/*.h"],
-    license: "NOTICE",
-}
-
-ndk_headers {
     name: "libc_asm_arm",
     from: "kernel/uapi/asm-arm",
     to: "arm-linux-androideabi",
index cdf29e3..f3ed69c 100644 (file)
@@ -3415,31 +3415,6 @@ POSSIBILITY OF SUCH DAMAGE.
 
 -------------------------------------------------------------------
 
-Copyright (c) 2002 Marc Espie.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
-   notice, this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
-``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OPENBSD
-PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
--------------------------------------------------------------------
-
 Copyright (c) 2002 The NetBSD Foundation, Inc.
 All rights reserved.
 
index 781d404..f98cc61 100644 (file)
@@ -117,8 +117,8 @@ int         mlockall(int flags)   all
 int         munlockall()   all
 int         mincore(void*  start, size_t  length, unsigned char*  vec)   all
 int         __ioctl:ioctl(int, int, void*)  all
-int         readv(int, const struct iovec*, int)   all
-int         writev(int, const struct iovec*, int)  all
+ssize_t     readv(int, const struct iovec*, int)   all
+ssize_t     writev(int, const struct iovec*, int)  all
 int         __fcntl64:fcntl64(int, int, void*)  arm,mips,x86
 int         fcntl(int, int, void*)  arm64,mips64,x86_64
 int         flock(int, int)   all
diff --git a/libc/arch-arm/bionic/abort_arm.S b/libc/arch-arm/bionic/abort_arm.S
deleted file mode 100644 (file)
index 1039502..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <private/bionic_asm.h>
-
-/*
- * Coding the abort function in assembly so that registers are guaranteed to
- * be preserved properly regardless of GCC's assumption on the "noreturn"
- * attribute. When the registers are not properly preserved we won't be able
- * to unwind the stack all the way to the bottom to fully reveal the call
- * sequence when the crash happens.
- */
-ENTRY(abort)
-    stmfd   sp!, {r3, r14}
-    .cfi_def_cfa_offset 8
-    .cfi_rel_offset r3, 0
-    .cfi_rel_offset r14, 4
-    bl      __libc_android_abort
-END(abort)
index 75413c6..9aefd44 100644 (file)
 #include <stdlib.h>
 #include <unistd.h>
 
-#ifdef __arm__
-extern "C" __LIBC_HIDDEN__ void __libc_android_abort()
-#else
-void abort()
-#endif
-{
+extern "C" int tgkill(int tgid, int tid, int sig);
+
+void abort() {
   // Don't block SIGABRT to give any signal handler a chance; we ignore
   // any errors -- X311J doesn't allow abort to return anyway.
   sigset_t mask;
@@ -44,7 +41,7 @@ void abort()
   sigdelset(&mask, SIGABRT);
   sigprocmask(SIG_SETMASK, &mask, NULL);
 
-  raise(SIGABRT);
+  tgkill(getpid(), gettid(), SIGABRT);
 
   // If SIGABRT ignored, or caught and the handler returns,
   // remove the SIGABRT signal handler and raise SIGABRT again.
@@ -54,6 +51,9 @@ void abort()
   sigemptyset(&sa.sa_mask);
   sigaction(SIGABRT, &sa, &sa);
   sigprocmask(SIG_SETMASK, &mask, NULL);
-  raise(SIGABRT);
-  _exit(1);
+
+  tgkill(getpid(), gettid(), SIGABRT);
+
+  // If we get this far, just exit.
+  _exit(127);
 }
index 4ff18ab..ba3b4e1 100644 (file)
@@ -29,6 +29,7 @@
 #include "private/bionic_arc4random.h"
 
 #include <errno.h>
+#include <stdatomic.h>
 #include <stdlib.h>
 #include <sys/auxv.h>
 #include <syscall.h>
 #include "private/KernelArgumentBlock.h"
 #include "private/libc_logging.h"
 
-void __libc_safe_arc4random_buf(void* buf, size_t n, KernelArgumentBlock& args) {
+bool __libc_arc4random_has_unlimited_entropy() {
   static bool have_urandom = access("/dev/urandom", R_OK) == 0;
-  static size_t at_random_bytes_consumed = 0;
+  return have_urandom;
+}
 
+void __libc_safe_arc4random_buf(void* buf, size_t n, KernelArgumentBlock& args) {
   // Only call arc4random_buf once we `have_urandom', since in getentropy_getrandom we may fallback
   // to use /dev/urandom, if the kernel entropy pool hasn't been initialized or not enough bytes
-  if (have_urandom) {
+  if (__libc_arc4random_has_unlimited_entropy()) {
     arc4random_buf(buf, n);
     return;
   }
 
+  static size_t at_random_bytes_consumed = 0;
   if (at_random_bytes_consumed + n > 16) {
     __libc_fatal("ran out of AT_RANDOM bytes, have %zu, requested %zu",
                  16 - at_random_bytes_consumed, n);
index e6f5742..9724f44 100644 (file)
@@ -29,7 +29,7 @@
 #include <unistd.h>
 
 #include <errno.h>
-#include <sys/limits.h>
+#include <limits.h>
 #include <sys/vfs.h>
 
 static long __filesizebits(const struct statfs& s) {
index eb66ba0..f7bd433 100644 (file)
 
 #include "local.h"
 
-template <typename float_type> float_type wcstod(const wchar_t* str, wchar_t** end,
-                                                 float_type strtod_fn(const char*, char**)) {
+/// Performs wide-character string to floating point conversion.
+template <typename float_type>
+float_type wcstod(const wchar_t* str, wchar_t** end, float_type strtod_fn(const char*, char**)) {
+  const wchar_t* original_str = str;
+  while (iswspace(*str)) {
+    str++;
+  }
+
   // What's the longest span of the input that might be part of the float?
   size_t max_len = wcsspn(str, L"-+0123456789.xXeEpP()nNaAiIfFtTyY");
 
@@ -70,7 +76,15 @@ template <typename float_type> float_type wcstod(const wchar_t* str, wchar_t** e
   float_type result = strtod_fn(ascii_str, &ascii_end);
   if (ascii_end != ascii_str + actual_len) abort();
 
-  if (end) *end = const_cast<wchar_t*>(str) + actual_len;
+  if (end) {
+    if (actual_len == 0) {
+      // There was an error. We need to set the end pointer back to the original string, not the
+      // one we advanced past the leading whitespace.
+      *end = const_cast<wchar_t*>(original_str);
+    } else {
+      *end = const_cast<wchar_t*>(str) + actual_len;
+    }
+  }
 
   delete[] ascii_str;
   return result;
index 64c3467..77f8dde 100644 (file)
 
 #include "private/icu.h"
 
-static constexpr int UCHAR_ALPHABETIC = 0;
-static constexpr int UCHAR_LOWERCASE = 22;
-static constexpr int UCHAR_POSIX_ALNUM = 44;
-static constexpr int UCHAR_POSIX_BLANK = 45;
-static constexpr int UCHAR_POSIX_GRAPH = 46;
-static constexpr int UCHAR_POSIX_PRINT = 47;
-static constexpr int UCHAR_POSIX_XDIGIT = 48;
-static constexpr int UCHAR_UPPERCASE = 30;
-static constexpr int UCHAR_WHITE_SPACE = 31;
-
-static constexpr int U_CONTROL_CHAR = 15;
-
-static bool __icu_hasBinaryProperty(wint_t wc, int property, int (*fallback)(int)) {
-  typedef int (*FnT)(wint_t, int);
+static bool __icu_hasBinaryProperty(wint_t wc, UProperty property, int (*fallback)(int)) {
+  typedef UBool (*FnT)(UChar32, UProperty);
   static auto u_hasBinaryProperty = reinterpret_cast<FnT>(__find_icu_symbol("u_hasBinaryProperty"));
   return u_hasBinaryProperty ? u_hasBinaryProperty(wc, property) : fallback(wc);
 }
@@ -65,19 +53,19 @@ int iswupper(wint_t wc) { return __icu_hasBinaryProperty(wc, UCHAR_UPPERCASE, is
 int iswxdigit(wint_t wc) { return __icu_hasBinaryProperty(wc, UCHAR_POSIX_XDIGIT, isxdigit); }
 
 int iswcntrl(wint_t wc) {
-  typedef int (*FnT)(wint_t);
+  typedef int8_t (*FnT)(UChar32);
   static auto u_charType = reinterpret_cast<FnT>(__find_icu_symbol("u_charType"));
   return u_charType ? (u_charType(wc) == U_CONTROL_CHAR) : iscntrl(wc);
 }
 
 int iswdigit(wint_t wc) {
-  typedef int (*FnT)(wint_t);
+  typedef UBool (*FnT)(UChar32);
   static auto u_isdigit = reinterpret_cast<FnT>(__find_icu_symbol("u_isdigit"));
   return u_isdigit ? u_isdigit(wc) : isdigit(wc);
 }
 
 int iswpunct(wint_t wc) {
-  typedef int (*FnT)(wint_t);
+  typedef UBool (*FnT)(UChar32);
   static auto u_ispunct = reinterpret_cast<FnT>(__find_icu_symbol("u_ispunct"));
   return u_ispunct ? u_ispunct(wc) : ispunct(wc);
 }
@@ -118,13 +106,13 @@ int iswctype_l(wint_t wc, wctype_t char_class, locale_t) {
 }
 
 wint_t towlower(wint_t wc) {
-  typedef wchar_t (*FnT)(wchar_t);
+  typedef UChar32 (*FnT)(UChar32);
   static auto u_tolower = reinterpret_cast<FnT>(__find_icu_symbol("u_tolower"));
   return u_tolower ? u_tolower(wc) : tolower(wc);
 }
 
 wint_t towupper(wint_t wc) {
-  typedef wchar_t (*FnT)(wchar_t);
+  typedef UChar32 (*FnT)(UChar32);
   static auto u_toupper = reinterpret_cast<FnT>(__find_icu_symbol("u_toupper"));
   return u_toupper ? u_toupper(wc) : toupper(wc);
 }
index c6f0d24..6c26cd3 100644 (file)
 #include <stdarg.h>
 #include "nsswitch.h"
 
-#if defined(__BIONIC__)
-#include <sys/system_properties.h>
-#endif
-
 typedef union sockaddr_union {
     struct sockaddr     generic;
     struct sockaddr_in  in;
index 63a347e..236e7f2 100644 (file)
@@ -62,7 +62,6 @@ __RCSID("$NetBSD: getnameinfo.c,v 1.53 2012/09/26 23:13:00 christos Exp $");
 #include <arpa/nameser.h>
 #include "resolv_netid.h"
 #include "resolv_private.h"
-#include <sys/system_properties.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <errno.h>
index ad2c5c0..8b3c76b 100644 (file)
@@ -38,7 +38,6 @@
 
 #include <errno.h>
 #include <arpa/nameser.h>
-#include <sys/system_properties.h>
 #include <net/if.h>
 #include <netdb.h>
 #include <linux/if.h>
  * *****************************************
  */
 #define  CONFIG_MAX_ENTRIES    64 * 2 * 5
-/* name of the system property that can be used to set the cache size */
 
 /****************************************************************************/
 /****************************************************************************/
@@ -2010,8 +2008,8 @@ _resolv_set_nameservers_for_net(unsigned netid, const char** servers, unsigned n
             }
             cache_info->nscount = numservers;
 
-            // Flush the cache and reset the stats.
-            _flush_cache_for_net_locked(netid);
+            // Clear the NS statistics because the mapping to nameservers might have changed.
+            _res_cache_clear_stats_locked(cache_info);
 
             // increment the revision id to ensure that sample state is not written back if the
             // servers change; in theory it would suffice to do so only if the servers or
@@ -2286,4 +2284,3 @@ _resolv_cache_add_resolver_stats_sample( unsigned netid, int revision_id, int ns
 
     pthread_mutex_unlock(&_res_cache_list_lock);
 }
-
index a5413dd..b9fc131 100644 (file)
@@ -101,7 +101,6 @@ __RCSID("$NetBSD: res_init.c,v 1.8 2006/03/19 03:10:08 christos Exp $");
 #ifdef ANDROID_CHANGES
 #include <errno.h>
 #include <fcntl.h>
-#include <sys/system_properties.h>
 #endif /* ANDROID_CHANGES */
 
 /* ensure that sockaddr_in6 and IN6ADDR_ANY_INIT are declared / defined */
index 0e02a8f..4ed168c 100644 (file)
@@ -36,8 +36,6 @@
 #include <stdlib.h>
 #include <string.h>
 
-#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
-#include <sys/_system_properties.h>
 
 /* Set to 1 to enable debug traces */
 #define DEBUG 0
@@ -54,8 +52,6 @@ typedef struct {
     int                  _h_errno;
     // TODO: Have one __res_state per network so we don't have to repopulate frequently.
     struct __res_state  _nres[1];
-    unsigned             _serial;
-    struct prop_info*   _pi;
     struct res_static   _rstatic[1];
 } _res_thread;
 
@@ -66,12 +62,6 @@ _res_thread_alloc(void)
 
     if (rt) {
         rt->_h_errno = 0;
-        /* Special system property which tracks any changes to 'net.*'. */
-        rt->_serial = 0;
-        rt->_pi = (struct prop_info*) __system_property_find("net.change");
-        if (rt->_pi) {
-            rt->_serial = __system_property_serial(rt->_pi);
-        }
         memset(rt->_rstatic, 0, sizeof rt->_rstatic);
     }
     return rt;
@@ -116,32 +106,7 @@ _res_thread_get(void)
     rt = pthread_getspecific( _res_key );
 
     if (rt != NULL) {
-        /* We already have one thread-specific DNS state object.
-         * Check the serial value for any changes to net.* properties */
-        D("%s: Called for tid=%d rt=%p rt->pi=%p rt->serial=%d",
-           __FUNCTION__, gettid(), rt, rt->_pi, rt->_serial);
-        if (rt->_pi == NULL) {
-            /* The property wasn't created when _res_thread_get() was
-             * called the last time. This should only happen very
-             * early during the boot sequence. First, let's try to see if it
-             * is here now. */
-            rt->_pi = (struct prop_info*) __system_property_find("net.change");
-            if (rt->_pi == NULL) {
-                /* Still nothing, return current state */
-                D("%s: exiting for tid=%d rt=%p since system property not found",
-                  __FUNCTION__, gettid(), rt);
-                return rt;
-            }
-        }
-        if (rt->_serial == __system_property_serial(rt->_pi)) {
-            /* Nothing changed, so return the current state */
-            D("%s: tid=%d rt=%p nothing changed, returning",
-              __FUNCTION__, gettid(), rt);
-            return rt;
-        }
-        /* Update the recorded serial number, and go reset the state */
-        rt->_serial = __system_property_serial(rt->_pi);
-        goto RESET_STATE;
+        return rt;
     }
 
     /* It is the first time this function is called in this thread,
@@ -154,11 +119,10 @@ _res_thread_get(void)
     D("%s: tid=%d Created new DNS state rt=%p",
       __FUNCTION__, gettid(), rt);
 
-RESET_STATE:
     /* Reset the state, note that res_ninit() can now properly reset
      * an existing state without leaking memory.
      */
-    D("%s: tid=%d, rt=%p, resetting DNS state (options RES_INIT=%d)",
+    D("%s: tid=%d, rt=%p, setting DNS state (options RES_INIT=%d)",
       __FUNCTION__, gettid(), rt, (rt->_nres->options & RES_INIT) != 0);
     if ( res_ninit( rt->_nres ) < 0 ) {
         /* This should not happen */
index a1124b3..a25eb65 100644 (file)
  */
 
 #ifndef _LIMITS_H_
-#define        _LIMITS_H_
+#define _LIMITS_H_
 
 #include <sys/cdefs.h>
 
+/* Historically bionic exposed the content of <float.h> from <limits.h> and <sys/limits.h> too. */
+#include <float.h>
+
+#include <linux/limits.h>
+
 #define PASS_MAX               128     /* _PASSWORD_LEN from <pwd.h> */
 
 #define NL_ARGMAX              9
 
 #define TMP_MAX                 308915776
 
-#include <sys/limits.h>
+/* TODO: get all these from the compiler's <limits.h>? */
+
+#define CHAR_BIT 8
+#ifdef __LP64__
+# define LONG_BIT 64
+#else
+# define LONG_BIT 32
+#endif
+
+#define        SCHAR_MAX       0x7f            /* max value for a signed char */
+#define SCHAR_MIN      (-0x7f-1)       /* min value for a signed char */
+
+#define        UCHAR_MAX       0xffU           /* max value for an unsigned char */
+#ifdef __CHAR_UNSIGNED__
+# define CHAR_MIN      0               /* min value for a char */
+# define CHAR_MAX      0xff            /* max value for a char */
+#else
+# define CHAR_MAX      0x7f
+# define CHAR_MIN      (-0x7f-1)
+#endif
+
+#define        USHRT_MAX       0xffffU         /* max value for an unsigned short */
+#define        SHRT_MAX        0x7fff          /* max value for a short */
+#define SHRT_MIN        (-0x7fff-1)     /* min value for a short */
+
+#define        UINT_MAX        0xffffffffU     /* max value for an unsigned int */
+#define        INT_MAX         0x7fffffff      /* max value for an int */
+#define        INT_MIN         (-0x7fffffff-1) /* min value for an int */
+
+#ifdef __LP64__
+# define ULONG_MAX     0xffffffffffffffffUL     /* max value for unsigned long */
+# define LONG_MAX      0x7fffffffffffffffL      /* max value for a signed long */
+# define LONG_MIN      (-0x7fffffffffffffffL-1) /* min value for a signed long */
+#else
+# define ULONG_MAX     0xffffffffUL    /* max value for an unsigned long */
+# define LONG_MAX      0x7fffffffL     /* max value for a long */
+# define LONG_MIN      (-0x7fffffffL-1)/* min value for a long */
+#endif
+
+# define ULLONG_MAX    0xffffffffffffffffULL     /* max value for unsigned long long */
+# define LLONG_MAX     0x7fffffffffffffffLL      /* max value for a signed long long */
+# define LLONG_MIN     (-0x7fffffffffffffffLL-1) /* min value for a signed long long */
 
 /* GLibc compatibility definitions.
    Note that these are defined by GCC's <limits.h>
 #endif
 
 #if defined(__USE_BSD) || defined(__BIONIC__) /* Historically bionic exposed these. */
+# define UID_MAX       UINT_MAX        /* max value for a uid_t */
+# define GID_MAX       UINT_MAX        /* max value for a gid_t */
 #if defined(__LP64__)
 #define SIZE_T_MAX ULONG_MAX
 #else
 #include <bits/posix_limits.h>
 
 #define HOST_NAME_MAX _POSIX_HOST_NAME_MAX
+
+#define  _POSIX_VERSION             200809L   /* Posix C language bindings version */
+#define  _POSIX2_VERSION            -1        /* we don't support Posix command-line tools */
+#define  _XOPEN_VERSION             700       /* by Posix definition */
+
+/* >= _POSIX_THREAD_DESTRUCTOR_ITERATIONS */
+#define PTHREAD_DESTRUCTOR_ITERATIONS 4
+/* >= _POSIX_THREAD_KEYS_MAX */
+#define PTHREAD_KEYS_MAX 128
+/* bionic has no specific limit */
+#undef PTHREAD_THREADS_MAX
+
 #endif /* !_LIMITS_H_ */
index 60cc7f7..1e189a1 100644 (file)
@@ -1,122 +1 @@
-/* $OpenBSD: limits.h,v 1.6 2005/12/13 00:35:23 millert Exp $ */
-/*
- * Copyright (c) 2002 Marc Espie.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OPENBSD
- * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#ifndef _SYS_LIMITS_H_
-#define _SYS_LIMITS_H_
-
-#include <sys/cdefs.h>
-#include <linux/limits.h>
-
-/* Common definitions for limits.h. */
-
-#define        CHAR_BIT        8               /* number of bits in a char */
-
-#define        SCHAR_MAX       0x7f            /* max value for a signed char */
-#define SCHAR_MIN      (-0x7f-1)       /* min value for a signed char */
-
-#define        UCHAR_MAX       0xffU           /* max value for an unsigned char */
-#ifdef __CHAR_UNSIGNED__
-# define CHAR_MIN      0               /* min value for a char */
-# define CHAR_MAX      0xff            /* max value for a char */
-#else
-# define CHAR_MAX      0x7f
-# define CHAR_MIN      (-0x7f-1)
-#endif
-
-#define        USHRT_MAX       0xffffU         /* max value for an unsigned short */
-#define        SHRT_MAX        0x7fff          /* max value for a short */
-#define SHRT_MIN        (-0x7fff-1)     /* min value for a short */
-
-#define        UINT_MAX        0xffffffffU     /* max value for an unsigned int */
-#define        INT_MAX         0x7fffffff      /* max value for an int */
-#define        INT_MIN         (-0x7fffffff-1) /* min value for an int */
-
-#ifdef __LP64__
-# define ULONG_MAX     0xffffffffffffffffUL
-                                       /* max value for unsigned long */
-# define LONG_MAX      0x7fffffffffffffffL
-                                       /* max value for a signed long */
-# define LONG_MIN      (-0x7fffffffffffffffL-1)
-                                       /* min value for a signed long */
-#else
-# define ULONG_MAX     0xffffffffUL    /* max value for an unsigned long */
-# define LONG_MAX      0x7fffffffL     /* max value for a long */
-# define LONG_MIN      (-0x7fffffffL-1)/* min value for a long */
-#endif
-
-# define ULLONG_MAX    0xffffffffffffffffULL
-                                       /* max value for unsigned long long */
-# define LLONG_MAX     0x7fffffffffffffffLL
-                                       /* max value for a signed long long */
-# define LLONG_MIN     (-0x7fffffffffffffffLL-1)
-                                       /* min value for a signed long long */
-
-#if defined(__USE_BSD) || defined(__BIONIC__) /* Historically bionic exposed these. */
-# define UID_MAX       UINT_MAX        /* max value for a uid_t */
-# define GID_MAX       UINT_MAX        /* max value for a gid_t */
-#endif
-
-
-#ifdef __LP64__
-# define LONG_BIT      64
-#else
-# define LONG_BIT      32
-#endif
-
-/* float.h defines these as well */
-# if !defined(DBL_DIG)
-#  if defined(__DBL_DIG)
-#   define DBL_DIG     __DBL_DIG
-#   define DBL_MAX     __DBL_MAX
-#   define DBL_MIN     __DBL_MIN
-
-#   define FLT_DIG     __FLT_DIG
-#   define FLT_MAX     __FLT_MAX
-#   define FLT_MIN     __FLT_MIN
-#  else
-#   define DBL_DIG     15
-#   define DBL_MAX     1.7976931348623157E+308
-#   define DBL_MIN     2.2250738585072014E-308
-
-#   define FLT_DIG     6
-#   define FLT_MAX     3.40282347E+38F
-#   define FLT_MIN     1.17549435E-38F
-#  endif
-# endif
-
-/* Bionic-specific definitions */
-
-#define  _POSIX_VERSION             200809L   /* Posix C language bindings version */
-#define  _POSIX2_VERSION            -1        /* we don't support Posix command-line tools */
-#define  _XOPEN_VERSION             700       /* by Posix definition */
-
-/* >= _POSIX_THREAD_DESTRUCTOR_ITERATIONS */
-#define PTHREAD_DESTRUCTOR_ITERATIONS 4
-/* >= _POSIX_THREAD_KEYS_MAX */
-#define PTHREAD_KEYS_MAX 128
-/* bionic has no specific limit */
-#undef PTHREAD_THREADS_MAX
-
-#endif
+#include <limits.h>
index 7a009b4..0e56d7d 100644 (file)
@@ -34,8 +34,8 @@
 
 __BEGIN_DECLS
 
-int readv(int, const struct iovec*, int);
-int writev(int, const struct iovec*, int);
+ssize_t readv(int, const struct iovec*, int);
+ssize_t writev(int, const struct iovec*, int);
 
 #if defined(__USE_GNU)
 #if defined(__USE_FILE_OFFSET64)
index d26a4e7..b51f818 100644 (file)
  * created yet. Provide a wrapper function that falls back to AT_RANDOM if
  * we don't have getrandom and /dev/urandom is missing.
  */
-
 void __libc_safe_arc4random_buf(void* buf, size_t n, KernelArgumentBlock& args);
 
+/*
+ * Return true if libc has an unlimited entropy source (something other than
+ * AT_RANDOM), and arc4random* calls will always succeed.
+ */
+bool __libc_arc4random_has_unlimited_entropy();
+
 #endif
index c5d89b8..03fdf66 100644 (file)
 #ifndef _PRIVATE_ICU_H
 #define _PRIVATE_ICU_H
 
+#include <stdint.h>
+
+typedef int8_t UBool;
+typedef int32_t UChar32;
+
+enum UProperty {
+  UCHAR_ALPHABETIC = 0,
+  UCHAR_LOWERCASE = 22,
+  UCHAR_POSIX_ALNUM = 44,
+  UCHAR_POSIX_BLANK = 45,
+  UCHAR_POSIX_GRAPH = 46,
+  UCHAR_POSIX_PRINT = 47,
+  UCHAR_POSIX_XDIGIT = 48,
+  UCHAR_UPPERCASE = 30,
+  UCHAR_WHITE_SPACE = 31,
+};
+
+enum UCharCategory {
+  U_CONTROL_CHAR = 15,
+};
+
 void* __find_icu_symbol(const char* symbol_name);
 
 #endif  // _PRIVATE_ICU_H
index 9db3a94..e9b79d7 100644 (file)
@@ -57,6 +57,55 @@ cc_library {
     allow_undefined_symbols: true,
     system_shared_libs: [],
 
+    // This is placeholder library the actual implementation is (currently)
+    // provided by the linker.
+    shared_libs: [ "ld-android" ],
+
+    sanitize: {
+        never: true,
+    },
+}
+
+cc_library {
+    // NOTE: --exclude-libs=libgcc.a makes sure that any symbols libdl.so pulls from
+    // libgcc.a are made static to ld-android.so.  This in turn ensures that libraries that
+    // a) pull symbols from libgcc.a and b) depend on ld-android.so will not rely on ld-android.so
+    // to provide those symbols, but will instead pull them from libgcc.a.  Specifically,
+    // we use this property to make sure libc.so has its own copy of the code from
+    // libgcc.a it uses.
+    //
+    // DO NOT REMOVE --exclude-libs!
+
+    ldflags: ["-Wl,--exclude-libs=libgcc.a"],
+
+    // for x86, exclude libgcc_eh.a for the same reasons as above
+    arch: {
+        x86: {
+            ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
+        },
+        x86_64: {
+            ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
+        },
+    },
+    srcs: ["ld_android.c"],
+    cflags: [
+        "-Wall",
+        "-Wextra",
+        "-Wunused",
+        "-Werror",
+    ],
+    stl: "none",
+
+    name: "ld-android",
+
+    // NOTE: libdl needs __aeabi_unwind_cpp_pr0 from libgcc.a but libgcc.a needs a
+    // few symbols from libc. Using --no-undefined here results in having to link
+    // against libc creating a circular dependency which is removed and we end up
+    // with missing symbols. Since this library is just a bunch of stubs, we set
+    // LOCAL_ALLOW_UNDEFINED_SYMBOLS to remove --no-undefined from the linker flags.
+    allow_undefined_symbols: true,
+    system_shared_libs: [],
+
     sanitize: {
         never: true,
     },
diff --git a/libdl/ld_android.c b/libdl/ld_android.c
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+
index 4cc4dea..8329468 100644 (file)
 #include <stdbool.h>
 #include <android/dlext.h>
 
-// These are stubs for functions that are actually defined
-// in the dynamic linker and hijacked at runtime.
+// These functions are exported by the loader
+// TODO(dimitry): replace these with reference to libc.so
 
-void* dlopen(const char* filename __unused, int flag __unused) { return 0; }
+__attribute__((__weak__, visibility("default")))
+void* __loader_dlopen(const char* filename, int flags, const void* caller_addr);
 
-char* dlerror(void) { return 0; }
+__attribute__((__weak__, visibility("default")))
+void* __loader_dlerror();
 
-void* dlsym(void* handle __unused, const char* symbol __unused) { return 0; }
+__attribute__((__weak__, visibility("default")))
+void* __loader_dlsym(void* handle, const char* symbol, const void* caller_addr);
 
-void* dlvsym(void* handle __unused, const char* symbol __unused, const char* version __unused) {
-  return 0;
+__attribute__((__weak__, visibility("default")))
+void* __loader_dlvsym(void* handle,
+                      const char* symbol,
+                      const char* version,
+                      const void* caller_addr);
+
+__attribute__((__weak__, visibility("default")))
+int __loader_dladdr(const void* addr, Dl_info* info);
+
+__attribute__((__weak__, visibility("default")))
+int __loader_dlclose(void* handle);
+
+#if defined(__arm__)
+__attribute__((__weak__, visibility("default")))
+_Unwind_Ptr __loader_dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount);
+#endif
+
+__attribute__((__weak__, visibility("default")))
+int __loader_dl_iterate_phdr(int (*cb)(struct dl_phdr_info* info, size_t size, void* data),
+                             void* data);
+
+__attribute__((__weak__, visibility("default")))
+void __loader_android_get_LD_LIBRARY_PATH(char* buffer, size_t buffer_size);
+
+__attribute__((__weak__, visibility("default")))
+void __loader_android_update_LD_LIBRARY_PATH(const char* ld_library_path);
+
+__attribute__((__weak__, visibility("default")))
+void* __loader_android_dlopen_ext(const char* filename,
+                                  int flag,
+                                  const android_dlextinfo* extinfo,
+                                  const void* caller_addr);
+
+__attribute__((__weak__, visibility("default")))
+void __loader_android_set_application_target_sdk_version(uint32_t target);
+
+__attribute__((__weak__, visibility("default")))
+uint32_t __loader_android_get_application_target_sdk_version();
+
+__attribute__((__weak__, visibility("default")))
+bool __loader_android_init_namespaces(const char* public_ns_sonames,
+                                      const char* anon_ns_library_path);
+
+__attribute__((__weak__, visibility("default")))
+struct android_namespace_t* __loader_android_create_namespace(
+                                const char* name,
+                                const char* ld_library_path,
+                                const char* default_library_path,
+                                uint64_t type,
+                                const char* permitted_when_isolated_path,
+                                struct android_namespace_t* parent,
+                                const void* caller_addr);
+
+// Proxy calls to bionic loader
+void* dlopen(const char* filename, int flag) {
+  const void* caller_addr = __builtin_return_address(0);
+  return __loader_dlopen(filename, flag, caller_addr);
+}
+
+char* dlerror() {
+  return __loader_dlerror();
+}
+
+void* dlsym(void* handle, const char* symbol) {
+  const void* caller_addr = __builtin_return_address(0);
+  return __loader_dlsym(handle, symbol, caller_addr);
 }
 
-int dladdr(const void* addr __unused, Dl_info* info __unused) { return 0; }
+void* dlvsym(void* handle, const char* symbol, const char* version) {
+  const void* caller_addr = __builtin_return_address(0);
+  return __loader_dlvsym(handle, symbol, version, caller_addr);
+}
 
-int dlclose(void* handle __unused) { return 0; }
+int dladdr(const void* addr, Dl_info* info) {
+  return __loader_dladdr(addr, info);
+}
+
+int dlclose(void* handle) {
+  return __loader_dlclose(handle);
+}
 
 #if defined(__arm__)
-_Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr pc __unused, int* pcount __unused) { return 0; }
+_Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount) {
+  return __loader_dl_unwind_find_exidx(pc, pcount);
+}
 #endif
 
-int dl_iterate_phdr(int (*cb)(struct dl_phdr_info* info, size_t size, void* data) __unused,
-                    void* data __unused) {
-  return 0;
+int dl_iterate_phdr(int (*cb)(struct dl_phdr_info* info, size_t size, void* data), void* data) {
+  return __loader_dl_iterate_phdr(cb, data);
 }
 
-void android_get_LD_LIBRARY_PATH(char* buffer __unused, size_t buffer_size __unused) { }
-void android_update_LD_LIBRARY_PATH(const char* ld_library_path __unused) { }
+void android_get_LD_LIBRARY_PATH(char* buffer, size_t buffer_size) {
+  __loader_android_get_LD_LIBRARY_PATH(buffer, buffer_size);
+}
+
+void android_update_LD_LIBRARY_PATH(const char* ld_library_path) {
+  __loader_android_update_LD_LIBRARY_PATH(ld_library_path);
+}
 
-void* android_dlopen_ext(const char* filename __unused, int flag __unused,
-                         const android_dlextinfo* extinfo __unused) {
-  return 0;
+void* android_dlopen_ext(const char* filename, int flag, const android_dlextinfo* extinfo) {
+  const void* caller_addr = __builtin_return_address(0);
+  return __loader_android_dlopen_ext(filename, flag, extinfo, caller_addr);
 }
 
-void android_set_application_target_sdk_version(uint32_t target __unused) { }
-uint32_t android_get_application_target_sdk_version() { return 0; }
+void android_set_application_target_sdk_version(uint32_t target) {
+  __loader_android_set_application_target_sdk_version(target);
+}
+uint32_t android_get_application_target_sdk_version() {
+  return __loader_android_get_application_target_sdk_version();
+}
 
-bool android_init_namespaces(const char* public_ns_sonames __unused,
-                             const char* anon_ns_library_path __unused) {
-  return false;
+bool android_init_namespaces(const char* public_ns_sonames,
+                             const char* anon_ns_library_path) {
+  return __loader_android_init_namespaces(public_ns_sonames, anon_ns_library_path);
 }
 
-struct android_namespace_t* android_create_namespace(const char* name __unused,
-                                                     const char* ld_library_path __unused,
-                                                     const char* default_library_path __unused,
-                                                     uint64_t type __unused,
-                                                     const char* permitted_when_isolated_path __unused) {
-  return 0;
+struct android_namespace_t* android_create_namespace(const char* name,
+                                                     const char* ld_library_path,
+                                                     const char* default_library_path,
+                                                     uint64_t type,
+                                                     const char* permitted_when_isolated_path,
+                                                     struct android_namespace_t* parent) {
+  const void* caller_addr = __builtin_return_address(0);
+  return __loader_android_create_namespace(name,
+                                           ld_library_path,
+                                           default_library_path,
+                                           type,
+                                           permitted_when_isolated_path,
+                                           parent,
+                                           caller_addr);
 }
 
 void android_dlwarning(void* obj, void (*f)(void*, const char*)) { f(obj, 0); }
index 35f5fe4..7489bfe 100644 (file)
@@ -527,7 +527,8 @@ cc_library {
 
     native_coverage: bionic_coverage,
     sanitize: {
-        never: true,
+        address: false,
+        coverage: false,
     },
     stl: "none",
 }
index 5745d73..a3b9cb2 100644 (file)
@@ -1,6 +1,5 @@
 cc_library_static {
     name: "liblinker_malloc",
-    clang: true,
     defaults: ["linux_bionic_supported"],
 
     srcs: [
@@ -13,9 +12,7 @@ cc_library_static {
 }
 
 cc_binary {
-    clang: true,
     defaults: ["linux_bionic_supported"],
-
     srcs: [
         "dlfcn.cpp",
         "linker.cpp",
@@ -99,10 +96,14 @@ cc_binary {
         "-Werror",
     ],
 
-    conlyflags: ["-std=gnu99"],
-
     cppflags: ["-Wold-style-cast"],
 
+    // we are going to link libc++_static manually because
+    // when stl is not set to "none" build system adds libdl
+    // to the list of static libraries which needs to be
+    // avoided in the case of building loader.
+    stl: "none",
+
     // we don't want crtbegin.o (because we have begin.o), so unset it
     // just for this module
     nocrt: true,
@@ -114,6 +115,7 @@ cc_binary {
         "libbase",
         "libz",
         "liblog",
+        "libc++_static",
 
         // Important: The liblinker_malloc should be the last library in the list
         // to overwrite any other malloc implementations by other static libraries.
@@ -122,14 +124,11 @@ cc_binary {
     static_executable: true,
 
     name: "linker",
+    symlinks: ["linker_asan"],
     multilib: {
-        lib32: {
-            symlinks: ["linker_asan"],
-        },
         lib64: {
             suffix: "64",
-            symlinks: ["linker_asan64"],
-       },
+        },
     },
     target: {
         android: {
index 3ac61d7..bb7b1ca 100644 (file)
@@ -52,23 +52,25 @@ static void __bionic_format_dlerror(const char* msg, const char* detail) {
   __bionic_set_dlerror(buffer);
 }
 
-char* dlerror() {
+char* __dlerror() {
   char* old_value = __bionic_set_dlerror(nullptr);
   return old_value;
 }
 
-void android_get_LD_LIBRARY_PATH(char* buffer, size_t buffer_size) {
+void __android_get_LD_LIBRARY_PATH(char* buffer, size_t buffer_size) {
   ScopedPthreadMutexLocker locker(&g_dl_mutex);
   do_android_get_LD_LIBRARY_PATH(buffer, buffer_size);
 }
 
-void android_update_LD_LIBRARY_PATH(const char* ld_library_path) {
+void __android_update_LD_LIBRARY_PATH(const char* ld_library_path) {
   ScopedPthreadMutexLocker locker(&g_dl_mutex);
   do_android_update_LD_LIBRARY_PATH(ld_library_path);
 }
 
-static void* dlopen_ext(const char* filename, int flags,
-                        const android_dlextinfo* extinfo, void* caller_addr) {
+static void* dlopen_ext(const char* filename,
+                        int flags,
+                        const android_dlextinfo* extinfo,
+                        const void* caller_addr) {
   ScopedPthreadMutexLocker locker(&g_dl_mutex);
   g_linker_logger.ResetState();
   void* result = do_dlopen(filename, flags, extinfo, caller_addr);
@@ -79,17 +81,18 @@ static void* dlopen_ext(const char* filename, int flags,
   return result;
 }
 
-void* android_dlopen_ext(const char* filename, int flags, const android_dlextinfo* extinfo) {
-  void* caller_addr = __builtin_return_address(0);
+void* __android_dlopen_ext(const char* filename,
+                           int flags,
+                           const android_dlextinfo* extinfo,
+                           const void* caller_addr) {
   return dlopen_ext(filename, flags, extinfo, caller_addr);
 }
 
-void* dlopen(const char* filename, int flags) {
-  void* caller_addr = __builtin_return_address(0);
+void* __dlopen(const char* filename, int flags, const void* caller_addr) {
   return dlopen_ext(filename, flags, nullptr, caller_addr);
 }
 
-void* dlsym_impl(void* handle, const char* symbol, const char* version, void* caller_addr) {
+void* dlsym_impl(void* handle, const char* symbol, const char* version, const void* caller_addr) {
   ScopedPthreadMutexLocker locker(&g_dl_mutex);
   g_linker_logger.ResetState();
   void* result;
@@ -101,22 +104,20 @@ void* dlsym_impl(void* handle, const char* symbol, const char* version, void* ca
   return result;
 }
 
-void* dlsym(void* handle, const char* symbol) {
-  void* caller_addr = __builtin_return_address(0);
+void* __dlsym(void* handle, const char* symbol, const void* caller_addr) {
   return dlsym_impl(handle, symbol, nullptr, caller_addr);
 }
 
-void* dlvsym(void* handle, const char* symbol, const char* version) {
-  void* caller_addr = __builtin_return_address(0);
+void* __dlvsym(void* handle, const char* symbol, const char* version, const void* caller_addr) {
   return dlsym_impl(handle, symbol, version, caller_addr);
 }
 
-int dladdr(const void* addr, Dl_info* info) {
+int __dladdr(const void* addr, Dl_info* info) {
   ScopedPthreadMutexLocker locker(&g_dl_mutex);
   return do_dladdr(addr, info);
 }
 
-int dlclose(void* handle) {
+int __dlclose(void* handle) {
   ScopedPthreadMutexLocker locker(&g_dl_mutex);
   int result = do_dlclose(handle);
   if (result != 0) {
@@ -125,27 +126,35 @@ int dlclose(void* handle) {
   return result;
 }
 
+// This function is needed by libgcc.a (this is why there is no prefix for this one)
 int dl_iterate_phdr(int (*cb)(dl_phdr_info* info, size_t size, void* data), void* data) {
   ScopedPthreadMutexLocker locker(&g_dl_mutex);
   return do_dl_iterate_phdr(cb, data);
 }
 
-void android_set_application_target_sdk_version(uint32_t target) {
+#if defined(__arm__)
+_Unwind_Ptr __dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount) {
+  ScopedPthreadMutexLocker locker(&g_dl_mutex);
+  return do_dl_unwind_find_exidx(pc, pcount);
+}
+#endif
+
+void __android_set_application_target_sdk_version(uint32_t target) {
   // lock to avoid modification in the middle of dlopen.
   ScopedPthreadMutexLocker locker(&g_dl_mutex);
   set_application_target_sdk_version(target);
 }
 
-uint32_t android_get_application_target_sdk_version() {
+uint32_t __android_get_application_target_sdk_version() {
   return get_application_target_sdk_version();
 }
 
-void android_dlwarning(void* obj, void (*f)(void*, const char*)) {
+void __android_dlwarning(void* obj, void (*f)(void*, const char*)) {
   ScopedPthreadMutexLocker locker(&g_dl_mutex);
   get_dlwarning(obj, f);
 }
 
-bool android_init_namespaces(const char* public_ns_sonames,
+bool __android_init_namespaces(const char* public_ns_sonames,
                              const char* anon_ns_library_path) {
   ScopedPthreadMutexLocker locker(&g_dl_mutex);
   bool success = init_namespaces(public_ns_sonames, anon_ns_library_path);
@@ -156,13 +165,13 @@ bool android_init_namespaces(const char* public_ns_sonames,
   return success;
 }
 
-android_namespace_t* android_create_namespace(const char* name,
-                                              const char* ld_library_path,
-                                              const char* default_library_path,
-                                              uint64_t type,
-                                              const char* permitted_when_isolated_path,
-                                              android_namespace_t* parent_namespace) {
-  void* caller_addr = __builtin_return_address(0);
+android_namespace_t* __android_create_namespace(const char* name,
+                                                const char* ld_library_path,
+                                                const char* default_library_path,
+                                                uint64_t type,
+                                                const char* permitted_when_isolated_path,
+                                                android_namespace_t* parent_namespace,
+                                                const void* caller_addr) {
   ScopedPthreadMutexLocker locker(&g_dl_mutex);
 
   android_namespace_t* result = create_namespace(caller_addr,
@@ -200,18 +209,28 @@ android_namespace_t* android_create_namespace(const char* name,
     }
 
 static const char ANDROID_LIBDL_STRTAB[] =
-  // 0000000 00011111 111112 22222222 2333333 3333444444444455555555556666666 6667777777777888888888899999 99999
-  // 0123456 78901234 567890 12345678 9012345 6789012345678901234567890123456 7890123456789012345678901234 56789
-    "dlopen\0dlclose\0dlsym\0dlerror\0dladdr\0android_update_LD_LIBRARY_PATH\0android_get_LD_LIBRARY_PATH\0dl_it"
-  // 00000000001 1111111112222222222 3333333333444444444455555555556666666666777 777777788888888889999999999
-  // 01234567890 1234567890123456789 0123456789012345678901234567890123456789012 345678901234567890123456789
-    "erate_phdr\0android_dlopen_ext\0android_set_application_target_sdk_version\0android_get_application_tar"
-  // 0000000000111111 111122222222223333333333 4444444444555555555566666 6666677 777777778888888888
-  // 0123456789012345 678901234567890123456789 0123456789012345678901234 5678901 234567890123456789
-    "get_sdk_version\0android_init_namespaces\0android_create_namespace\0dlvsym\0android_dlwarning\0"
+  // 0000000000111111 11112222222222333 333333344444444 44555555555566666 6666677777777778 8888888889999999999
+  // 0123456789012345 67890123456789012 345678901234567 89012345678901234 5678901234567890 1234567890123456789
+    "__loader_dlopen\0__loader_dlclose\0__loader_dlsym\0__loader_dlerror\0__loader_dladdr\0__loader_android_up"
+  // 1*
+  // 000000000011111111112 2222222223333333333444444444455555555 5566666666667777777777888 88888889999999999
+  // 012345678901234567890 1234567890123456789012345678901234567 8901234567890123456789012 34567890123456789
+    "date_LD_LIBRARY_PATH\0__loader_android_get_LD_LIBRARY_PATH\0__loader_dl_iterate_phdr\0__loader_android_"
+  // 2*
+  // 00000000001 1111111112222222222333333333344444444445555555555666 6666666777777777788888888889999999999
+  // 01234567890 1234567890123456789012345678901234567890123456789012 3456789012345678901234567890123456789
+    "dlopen_ext\0__loader_android_set_application_target_sdk_version\0__loader_android_get_application_targ"
+  // 3*
+  // 000000000011111 111112222222222333333333344444444 4455555555556666666666777777777788 8888888899999999 99
+  // 012345678901234 567890123456789012345678901234567 8901234567890123456789012345678901 2345678901234567 89
+    "et_sdk_version\0__loader_android_init_namespaces\0__loader_android_create_namespace\0__loader_dlvsym\0__"
+  // 4*
+  // 0000000000111111111122222 2222233333333334444444 4445555555555666666666677777777778 8888888889999999 999
+  // 0123456789012345678901234 5678901234567890123456 7890123456789012345678901234567890 1234567890123456 789
+    "loader_android_dlwarning\0"
 #if defined(__arm__)
-  // 290
-    "dl_unwind_find_exidx\0"
+  // 425
+    "__loader_dl_unwind_find_exidx\0"
 #endif
     ;
 
@@ -221,23 +240,23 @@ static ElfW(Sym) g_libdl_symtab[] = {
   // supposed to have st_name == 0, but instead, it points to an index
   // in the strtab with a \0 to make iterating through the symtab easier.
   ELFW(SYM_INITIALIZER)(sizeof(ANDROID_LIBDL_STRTAB) - 1, nullptr, 0),
-  ELFW(SYM_INITIALIZER)(  0, &dlopen, 1),
-  ELFW(SYM_INITIALIZER)(  7, &dlclose, 1),
-  ELFW(SYM_INITIALIZER)( 15, &dlsym, 1),
-  ELFW(SYM_INITIALIZER)( 21, &dlerror, 1),
-  ELFW(SYM_INITIALIZER)( 29, &dladdr, 1),
-  ELFW(SYM_INITIALIZER)( 36, &android_update_LD_LIBRARY_PATH, 1),
-  ELFW(SYM_INITIALIZER)( 67, &android_get_LD_LIBRARY_PATH, 1),
-  ELFW(SYM_INITIALIZER)( 95, &dl_iterate_phdr, 1),
-  ELFW(SYM_INITIALIZER)(111, &android_dlopen_ext, 1),
-  ELFW(SYM_INITIALIZER)(130, &android_set_application_target_sdk_version, 1),
-  ELFW(SYM_INITIALIZER)(173, &android_get_application_target_sdk_version, 1),
-  ELFW(SYM_INITIALIZER)(216, &android_init_namespaces, 1),
-  ELFW(SYM_INITIALIZER)(240, &android_create_namespace, 1),
-  ELFW(SYM_INITIALIZER)(265, &dlvsym, 1),
-  ELFW(SYM_INITIALIZER)(272, &android_dlwarning, 1),
+  ELFW(SYM_INITIALIZER)(  0, &__dlopen, 1),
+  ELFW(SYM_INITIALIZER)( 16, &__dlclose, 1),
+  ELFW(SYM_INITIALIZER)( 33, &__dlsym, 1),
+  ELFW(SYM_INITIALIZER)( 48, &__dlerror, 1),
+  ELFW(SYM_INITIALIZER)( 65, &__dladdr, 1),
+  ELFW(SYM_INITIALIZER)( 81, &__android_update_LD_LIBRARY_PATH, 1),
+  ELFW(SYM_INITIALIZER)(121, &__android_get_LD_LIBRARY_PATH, 1),
+  ELFW(SYM_INITIALIZER)(158, &dl_iterate_phdr, 1),
+  ELFW(SYM_INITIALIZER)(183, &__android_dlopen_ext, 1),
+  ELFW(SYM_INITIALIZER)(211, &__android_set_application_target_sdk_version, 1),
+  ELFW(SYM_INITIALIZER)(263, &__android_get_application_target_sdk_version, 1),
+  ELFW(SYM_INITIALIZER)(315, &__android_init_namespaces, 1),
+  ELFW(SYM_INITIALIZER)(348, &__android_create_namespace, 1),
+  ELFW(SYM_INITIALIZER)(382, &__dlvsym, 1),
+  ELFW(SYM_INITIALIZER)(398, &__android_dlwarning, 1),
 #if defined(__arm__)
-  ELFW(SYM_INITIALIZER)(290, &dl_unwind_find_exidx, 1),
+  ELFW(SYM_INITIALIZER)(425, &__dl_unwind_find_exidx, 1),
 #endif
 };
 
@@ -263,9 +282,9 @@ static uint8_t __libdl_info_buf[sizeof(soinfo)] __attribute__((aligned(8)));
 static soinfo* __libdl_info = nullptr;
 
 // This is used by the dynamic linker. Every process gets these symbols for free.
-soinfo* get_libdl_info() {
+soinfo* get_libdl_info(const char* linker_path) {
   if (__libdl_info == nullptr) {
-    __libdl_info = new (__libdl_info_buf) soinfo(&g_default_namespace, "libdl.so", nullptr, 0, RTLD_GLOBAL);
+    __libdl_info = new (__libdl_info_buf) soinfo(&g_default_namespace, linker_path, nullptr, 0, 0);
     __libdl_info->flags_ |= FLAG_LINKED;
     __libdl_info->strtab_ = ANDROID_LIBDL_STRTAB;
     __libdl_info->symtab_ = g_libdl_symtab;
@@ -276,7 +295,7 @@ soinfo* get_libdl_info() {
     __libdl_info->ref_count_ = 1;
     __libdl_info->strtab_size_ = sizeof(ANDROID_LIBDL_STRTAB);
     __libdl_info->local_group_root_ = __libdl_info;
-    __libdl_info->soname_ = "libdl.so";
+    __libdl_info->soname_ = "ld-android.so";
     __libdl_info->target_sdk_version_ = __ANDROID_API__;
     __libdl_info->generate_handle();
 #if defined(__work_around_b_24465209__)
index 62e6bb6..d3ab8d8 100644 (file)
@@ -324,9 +324,7 @@ static bool realpath_fd(int fd, std::string* realpath) {
 // in that section (via *pcount).
 //
 // Intended to be called by libc's __gnu_Unwind_Find_exidx().
-//
-// This function is exposed via dlfcn.cpp and libdl.so.
-_Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount) {
+_Unwind_Ptr do_dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount) {
   uintptr_t addr = reinterpret_cast<uintptr_t>(pc);
 
   for (soinfo* si = solist_get_head(); si != 0; si = si->next) {
@@ -1730,8 +1728,9 @@ static std::string android_dlextinfo_to_string(const android_dlextinfo* info) {
                                         info->library_namespace : nullptr);
 }
 
-void* do_dlopen(const char* name, int flags, const android_dlextinfo* extinfo,
-                  void* caller_addr) {
+void* do_dlopen(const char* name, int flags,
+                const android_dlextinfo* extinfo,
+                const void* caller_addr) {
   soinfo* const caller = find_containing_library(caller_addr);
   android_namespace_t* ns = get_caller_namespace(caller);
 
@@ -1785,18 +1784,21 @@ void* do_dlopen(const char* name, int flags, const android_dlextinfo* extinfo,
   std::string asan_name_holder;
 
   const char* translated_name = name;
-  if (g_is_asan) {
-    if (file_is_in_dir(name, kSystemLibDir)) {
-      asan_name_holder = std::string(kAsanSystemLibDir) + "/" + basename(name);
-      if (file_exists(asan_name_holder.c_str())) {
-        translated_name = asan_name_holder.c_str();
-        PRINT("linker_asan dlopen translating \"%s\" -> \"%s\"", name, translated_name);
-      }
-    } else if (file_is_in_dir(name, kVendorLibDir)) {
-      asan_name_holder = std::string(kAsanVendorLibDir) + "/" + basename(name);
-      if (file_exists(asan_name_holder.c_str())) {
-        translated_name = asan_name_holder.c_str();
-        PRINT("linker_asan dlopen translating \"%s\" -> \"%s\"", name, translated_name);
+  if (g_is_asan && translated_name != nullptr && translated_name[0] == '/') {
+    char translated_path[PATH_MAX];
+    if (realpath(translated_name, translated_path) != nullptr) {
+      if (file_is_in_dir(translated_path, kSystemLibDir)) {
+        asan_name_holder = std::string(kAsanSystemLibDir) + "/" + basename(translated_path);
+        if (file_exists(asan_name_holder.c_str())) {
+          translated_name = asan_name_holder.c_str();
+          PRINT("linker_asan dlopen translating \"%s\" -> \"%s\"", name, translated_name);
+        }
+      } else if (file_is_in_dir(translated_path, kVendorLibDir)) {
+        asan_name_holder = std::string(kAsanVendorLibDir) + "/" + basename(translated_path);
+        if (file_exists(asan_name_holder.c_str())) {
+          translated_name = asan_name_holder.c_str();
+          PRINT("linker_asan dlopen translating \"%s\" -> \"%s\"", name, translated_name);
+        }
       }
     }
   }
@@ -1855,8 +1857,11 @@ static soinfo* soinfo_from_handle(void* handle) {
   return static_cast<soinfo*>(handle);
 }
 
-bool do_dlsym(void* handle, const char* sym_name, const char* sym_ver,
-              void* caller_addr, void** symbol) {
+bool do_dlsym(void* handle,
+              const char* sym_name,
+              const char* sym_ver,
+              const void* caller_addr,
+              void** symbol) {
 #if !defined(__LP64__)
   if (handle == nullptr) {
     DL_ERR("dlsym failed: library handle is null");
index 4787471..c65d503 100644 (file)
@@ -101,17 +101,27 @@ enum RelocationKind {
 
 void count_relocation(RelocationKind kind);
 
-soinfo* get_libdl_info();
+soinfo* get_libdl_info(const char* linker_path);
 
 void do_android_get_LD_LIBRARY_PATH(char*, size_t);
 void do_android_update_LD_LIBRARY_PATH(const char* ld_library_path);
-void* do_dlopen(const char* name, int flags, const android_dlextinfo* extinfo, void* caller_addr);
+void* do_dlopen(const char* name,
+                int flags,
+                const android_dlextinfo* extinfo,
+                const void* caller_addr);
+
 int do_dlclose(void* handle);
 
 int do_dl_iterate_phdr(int (*cb)(dl_phdr_info* info, size_t size, void* data), void* data);
 
-bool do_dlsym(void* handle, const char* sym_name, const char* sym_ver,
-              void* caller_addr, void** symbol);
+#if defined(__arm__)
+_Unwind_Ptr do_dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount);
+#endif
+
+bool do_dlsym(void* handle, const char* sym_name,
+              const char* sym_ver,
+              const void* caller_addr,
+              void** symbol);
 
 int do_dladdr(const void* addr, Dl_info* info);
 
index a8cc814..13edfe1 100644 (file)
@@ -160,16 +160,11 @@ static void add_vdso(KernelArgumentBlock& args __unused) {
  * relocate the offset of our exported 'rtld_db_dlactivity' symbol.
  * Note that the linker shouldn't be on the soinfo list.
  */
-static void init_linker_info_for_gdb(ElfW(Addr) linker_base) {
+static void init_linker_info_for_gdb(ElfW(Addr) linker_base, char* linker_path) {
   static link_map linker_link_map_for_gdb;
-#if defined(__LP64__)
-  static char kLinkerPath[] = "/system/bin/linker64";
-#else
-  static char kLinkerPath[] = "/system/bin/linker";
-#endif
 
   linker_link_map_for_gdb.l_addr = linker_base;
-  linker_link_map_for_gdb.l_name = kLinkerPath;
+  linker_link_map_for_gdb.l_name = linker_path;
 
   /*
    * Set the dynamic field in the link map otherwise gdb will complain with
@@ -201,6 +196,12 @@ static const char* get_executable_path() {
   return executable_path.c_str();
 }
 
+#if defined(__LP64__)
+static char kLinkerPath[] = "/system/bin/linker64";
+#else
+static char kLinkerPath[] = "/system/bin/linker";
+#endif
+
 /*
  * This code is called after the linker has linked itself and
  * fixed it's own GOT. It is safe to make references to externs
@@ -282,7 +283,7 @@ static ElfW(Addr) __linker_init_post_relocation(KernelArgumentBlock& args, ElfW(
   map->l_addr = 0;
   map->l_name = const_cast<char*>(executable_path);
   insert_link_map_into_debug_map(map);
-  init_linker_info_for_gdb(linker_base);
+  init_linker_info_for_gdb(linker_base, kLinkerPath);
 
   // Extract information passed from the kernel.
   si->phdr = reinterpret_cast<ElfW(Phdr)*>(args.getauxval(AT_PHDR));
@@ -524,9 +525,8 @@ extern "C" ElfW(Addr) __linker_init(void* raw_args) {
   // Initialize static variables. Note that in order to
   // get correct libdl_info we need to call constructors
   // before get_libdl_info().
-  solist = get_libdl_info();
-  sonext = get_libdl_info();
-  g_default_namespace.add_soinfo(get_libdl_info());
+  sonext = solist = get_libdl_info(kLinkerPath);
+  g_default_namespace.add_soinfo(solist);
 
   // We have successfully fixed our own relocations. It's safe to run
   // the main part of the linker now.
index a0fe9e2..7ef5da2 100644 (file)
@@ -336,7 +336,7 @@ struct soinfo {
   android_namespace_list_t secondary_namespaces_;
   uintptr_t handle_;
 
-  friend soinfo* get_libdl_info();
+  friend soinfo* get_libdl_info(const char* linker_path);
 };
 
 // This function is used by dlvsym() to calculate hash of sym_ver
index b12c28f..f0dac7c 100644 (file)
@@ -1020,26 +1020,27 @@ static bool PickOptions(std::vector<char*>& args, IsolationTestOptions& options)
   std::string gtest_filter_str;
   for (size_t i = args.size() - 1; i >= 1; --i) {
     if (strncmp(args[i], "--gtest_filter=", strlen("--gtest_filter=")) == 0) {
-      gtest_filter_str = std::string(args[i]);
+      gtest_filter_str = args[i] + strlen("--gtest_filter=");
       args.erase(args.begin() + i);
       break;
     }
   }
   if (enable_selftest == true) {
-    args.push_back(strdup("--gtest_filter=bionic_selftest*"));
+    gtest_filter_str = "bionic_selftest*";
   } else {
-    if (gtest_filter_str == "") {
-      gtest_filter_str = "--gtest_filter=-bionic_selftest*";
+    if (gtest_filter_str.empty()) {
+      gtest_filter_str = "-bionic_selftest*";
     } else {
       // Find if '-' for NEGATIVE_PATTERNS exists.
-      if (gtest_filter_str.find(":-") != std::string::npos) {
+      if (gtest_filter_str.find("-") != std::string::npos) {
         gtest_filter_str += ":bionic_selftest*";
       } else {
         gtest_filter_str += ":-bionic_selftest*";
       }
     }
-    args.push_back(strdup(gtest_filter_str.c_str()));
   }
+  gtest_filter_str = "--gtest_filter=" + gtest_filter_str;
+  args.push_back(strdup(gtest_filter_str.c_str()));
 
   options.isolate = true;
   // Parse arguments that make us can't run in isolation mode.
index 80580a4..01d6b82 100644 (file)
@@ -98,11 +98,15 @@ TEST(inttypes, scanf_macros) {
 }
 
 TEST(inttypes, wcstoimax) {
-  ASSERT_EQ(123, wcstoimax(L"123", NULL, 10));
+  wchar_t* end = nullptr;
+  EXPECT_EQ(123, wcstoimax(L"  +123x", &end, 10));
+  EXPECT_EQ(L'x', *end);
 }
 
 TEST(inttypes, wcstoumax) {
-  ASSERT_EQ(123U, wcstoumax(L"123", NULL, 10));
+  wchar_t* end = nullptr;
+  EXPECT_EQ(123U, wcstoumax(L"  +123x", &end, 10));
+  EXPECT_EQ(L'x', *end);
 }
 
 TEST(inttypes, strtoimax_EINVAL) {
index 9b5785a..74415d5 100644 (file)
  * limitations under the License.
  */
 
+#include <pty.h>
+
 #include <gtest/gtest.h>
 
-#include <pty.h>
+#include <pthread.h>
 #include <sys/ioctl.h>
 
+#include <atomic>
+
+#include <android-base/file.h>
+
 #include "utils.h"
 
 TEST(pty, openpty) {
index 5b9442f..fc17cde 100644 (file)
@@ -298,6 +298,11 @@ static void CheckStrToFloat(T fn(const char* s, char** end)) {
   EXPECT_PRED_FORMAT2(pred, 9.0, fn("0.9e1", nullptr));
   EXPECT_PRED_FORMAT2(pred, 9.0, fn("0x1.2p3", nullptr));
 
+  const char* s = " \t\v\f\r\n9.0";
+  char* p;
+  EXPECT_PRED_FORMAT2(pred, 9.0, fn(s, &p));
+  EXPECT_EQ(s + strlen(s), p);
+
   EXPECT_TRUE(isnan(fn("+nan", nullptr)));
   EXPECT_TRUE(isnan(fn("nan", nullptr)));
   EXPECT_TRUE(isnan(fn("-nan", nullptr)));
@@ -306,7 +311,6 @@ static void CheckStrToFloat(T fn(const char* s, char** end)) {
   EXPECT_TRUE(isnan(fn("nan(0xff)", nullptr)));
   EXPECT_TRUE(isnan(fn("-nan(0xff)", nullptr)));
 
-  char* p;
   EXPECT_TRUE(isnan(fn("+nanny", &p)));
   EXPECT_STREQ("ny", p);
   EXPECT_TRUE(isnan(fn("nanny", &p)));
index 205db86..1d80dbc 100644 (file)
@@ -15,7 +15,9 @@
  */
 
 #include <inttypes.h>
+#include <limits.h>
 #include <stdio.h>
+#include <sys/capability.h>
 #include <sys/mman.h>
 #include <sys/prctl.h>
 #include <unistd.h>
@@ -64,3 +66,51 @@ TEST(sys_prctl, bug_20017123) {
   GTEST_LOG_(INFO) << "This test does nothing as it tests an Android specific kernel feature.";
 #endif
 }
+
+TEST(sys_prctl, pr_cap_ambient) {
+// PR_CAP_AMBIENT was introduced in v4.3.  Android devices should always
+// have a backport, but we can't guarantee it's available on the host.
+#if defined(__ANDROID__) || defined(PR_CAP_AMBIENT)
+  const std::string caps_sha =
+      "https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/"
+      "?id=58319057b7847667f0c9585b9de0e8932b0fdb08";
+  const std::string caps_typo_sha =
+      "https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/"
+      "?id=b7f76ea2ef6739ee484a165ffbac98deb855d3d3";
+
+  auto err = prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_CLEAR_ALL, 0, 0, 0);
+  EXPECT_EQ(0, err);
+  // EINVAL -> unrecognized prctl option
+  ASSERT_NE(EINVAL, errno) << "kernel missing required commits:\n"
+                           << caps_sha << "\n"
+                           << caps_typo_sha << "\n";
+
+  // Unprivileged processes shouldn't be able to raise CAP_SYS_ADMIN,
+  // but they can check or lower it
+  err = prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, CAP_SYS_ADMIN, 0, 0);
+  EXPECT_EQ(-1, err);
+  EXPECT_EQ(EPERM, errno);
+
+  err = prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, CAP_SYS_ADMIN, 0, 0);
+  EXPECT_EQ(0, err);
+
+  err = prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_LOWER, CAP_SYS_ADMIN, 0, 0);
+  EXPECT_EQ(0, err);
+
+  // ULONG_MAX isn't a legal cap
+  err = prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, ULONG_MAX, 0, 0);
+  EXPECT_EQ(-1, err);
+  EXPECT_EQ(EINVAL, errno);
+
+  err = prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, ULONG_MAX, 0, 0);
+  EXPECT_EQ(-1, err);
+  EXPECT_EQ(EINVAL, errno);
+
+  err = prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_LOWER, ULONG_MAX, 0, 0);
+  EXPECT_EQ(-1, err);
+  EXPECT_EQ(EINVAL, errno);
+#else
+  GTEST_LOG_(INFO)
+      << "Skipping test that requires host support for PR_CAP_AMBIENT.";
+#endif
+}
index f8b35cc..9d809f0 100644 (file)
@@ -1347,7 +1347,8 @@ TEST(UNISTD_TEST, execvpe_failure) {
   ExecTestHelper eth;
   errno = 0;
   ASSERT_EQ(-1, execvpe("this-does-not-exist", eth.GetArgs(), eth.GetEnv()));
-  ASSERT_EQ(ENOENT, errno);
+  // Running in CTS we might not even be able to search all directories in $PATH.
+  ASSERT_TRUE(errno == ENOENT || errno == EACCES);
 }
 
 TEST(UNISTD_TEST, execvpe) {
@@ -1380,8 +1381,8 @@ TEST(UNISTD_TEST, execvpe_ENOEXEC) {
   ASSERT_EQ(-1, execvpe(basename(tf.filename), eth.GetArgs(), eth.GetEnv()));
   ASSERT_EQ(EACCES, errno);
 
-  // Make it executable.
-  ASSERT_EQ(0, chmod(tf.filename, 0555));
+  // Make it executable (and keep it writable because we're going to rewrite it below).
+  ASSERT_EQ(0, chmod(tf.filename, 0777));
 
   // TemporaryFile will have a writable fd, so we can test ETXTBSY while we're here...
   errno = 0;
index 34ed5a7..830eb70 100644 (file)
@@ -686,6 +686,11 @@ static void CheckWcsToFloat(T fn(const wchar_t* s, wchar_t** end)) {
   EXPECT_PRED_FORMAT2(pred, 9.0, fn(L"0.9e1", nullptr));
   EXPECT_PRED_FORMAT2(pred, 9.0, fn(L"0x1.2p3", nullptr));
 
+  const wchar_t* s = L" \t\v\f\r\n9.0";
+  wchar_t* p;
+  EXPECT_PRED_FORMAT2(pred, 9.0, fn(s, &p));
+  EXPECT_EQ(s + wcslen(s), p);
+
   EXPECT_TRUE(isnan(fn(L"+nan", nullptr)));
   EXPECT_TRUE(isnan(fn(L"nan", nullptr)));
   EXPECT_TRUE(isnan(fn(L"-nan", nullptr)));
@@ -694,7 +699,6 @@ static void CheckWcsToFloat(T fn(const wchar_t* s, wchar_t** end)) {
   EXPECT_TRUE(isnan(fn(L"nan(0xff)", nullptr)));
   EXPECT_TRUE(isnan(fn(L"-nan(0xff)", nullptr)));
 
-  wchar_t* p;
   EXPECT_TRUE(isnan(fn(L"+nanny", &p)));
   EXPECT_STREQ(L"ny", p);
   EXPECT_TRUE(isnan(fn(L"nanny", &p)));