### 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
<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.
"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",
// dynamic linker.
cc_library_static {
+ name: "libc_nomalloc",
+
defaults: ["libc_defaults"],
- srcs: [
- "bionic/dl_iterate_phdr_static.cpp",
- ],
arch: {
arm: {
cflags: ["-DLIBC_STATIC"],
- name: "libc_nomalloc",
-
whole_static_libs: [
"libc_common",
"libc_init_static",
// }
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",
}
}
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",
-------------------------------------------------------------------
-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.
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
+++ /dev/null
-/*
- * 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)
#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;
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.
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);
}
#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);
#include <unistd.h>
#include <errno.h>
-#include <sys/limits.h>
+#include <limits.h>
#include <sys/vfs.h>
static long __filesizebits(const struct statfs& s) {
#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");
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;
#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);
}
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);
}
}
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);
}
#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;
#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>
#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 */
/****************************************************************************/
/****************************************************************************/
}
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
pthread_mutex_unlock(&_res_cache_list_lock);
}
-
#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 */
#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
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;
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;
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,
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 */
*/
#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_ */
-/* $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>
__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)
* 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
#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
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,
},
#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); }
native_coverage: bionic_coverage,
sanitize: {
- never: true,
+ address: false,
+ coverage: false,
},
stl: "none",
}
cc_library_static {
name: "liblinker_malloc",
- clang: true,
defaults: ["linux_bionic_supported"],
srcs: [
}
cc_binary {
- clang: true,
defaults: ["linux_bionic_supported"],
-
srcs: [
"dlfcn.cpp",
"linker.cpp",
"-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,
"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.
static_executable: true,
name: "linker",
+ symlinks: ["linker_asan"],
multilib: {
- lib32: {
- symlinks: ["linker_asan"],
- },
lib64: {
suffix: "64",
- symlinks: ["linker_asan64"],
- },
+ },
},
target: {
android: {
__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);
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;
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) {
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);
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,
}
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
;
// 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
};
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;
__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__)
// 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) {
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);
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);
+ }
}
}
}
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");
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);
* 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
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
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));
// 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.
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
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.
}
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) {
* 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) {
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)));
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)));
*/
#include <inttypes.h>
+#include <limits.h>
#include <stdio.h>
+#include <sys/capability.h>
#include <sys/mman.h>
#include <sys/prctl.h>
#include <unistd.h>
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
+}
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) {
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;
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)));
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)));