From 45ad00158cee28182b7338b963e38b97747d7924 Mon Sep 17 00:00:00 2001 From: Ryan Prichard Date: Mon, 7 Jun 2021 15:51:38 -0700 Subject: cxa_guard: avoid sys/syscall.h and SYS_gettid Avoid including sys/syscall.h on Android Trusty, because sys/syscall.h tries to include bits/syscall.h, which doesn't exist. Detect this situation using _LIBCXXABI_HAS_NO_THREADS, which Trust seems to define, and if there are no threads, then SYS_gettid isn't needed. Disable the SYS_gettid call for Bionic, because some Android processes have a seccomp filter blocking gettid. Bug: http://b/189279320 Test: treehugger Change-Id: I542d649d11f10f07ce702521f9d18736e67602c1 --- src/cxa_guard_impl.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cxa_guard_impl.h b/src/cxa_guard_impl.h index 58c5dc5..552c454 100644 --- a/src/cxa_guard_impl.h +++ b/src/cxa_guard_impl.h @@ -41,7 +41,10 @@ #include "include/atomic_support.h" #include #include -#if defined(__has_include) +// Android Trusty: sys/syscall.h tries to include bits/syscall.h, which is +// missing. Trusty seems to define _LIBCXXABI_HAS_NO_THREADS, and gettid isn't +// needed in that case, so skip sys/syscall.h. +#if defined(__has_include) && !defined(_LIBCXXABI_HAS_NO_THREADS) # if __has_include() # include # endif @@ -113,7 +116,10 @@ uint32_t PlatformThreadID() { return static_cast( pthread_mach_thread_np(std::__libcpp_thread_get_current_id())); } -#elif defined(SYS_gettid) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD) +#elif defined(SYS_gettid) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \ + !defined(__BIONIC__) +// Bionic: Disable the SYS_gettid feature for now. Some processes on Android +// block SYS_gettid using seccomp. uint32_t PlatformThreadID() { static_assert(sizeof(pid_t) == sizeof(uint32_t), ""); return static_cast(syscall(SYS_gettid)); -- cgit v1.2.3