From 42f318af0b5730ea7835ad4ea124311747c9c3c5 Mon Sep 17 00:00:00 2001 From: Pirama Arumuga Nainar Date: Wed, 29 May 2019 14:18:18 -0700 Subject: Do not create property_watch_loop thread for zygote Bug: http://b/116873221 Bug: http://b/133872559 Do not create thread running property_watch_loop for zygote (which is essentially /system/bin/app_process invoked with a specific argument to start the zygote). The reason this is needed is because when the zygote forks system_server or an app, it waits for all threads to stop. But the thread created here doesn't know that it has to stop. So zygote gets stuck waiting and the device doesn't boot. This check is only needed for the platform, but can be done on any version after Android L, when getprogname() was added. Test: cuttlefish with coverage enabled can boot. Change-Id: I65aa603a88bf8da1f14b5c4ada3adf3776f33275 (cherry picked from commit 4cedcc68d4dfedf96474973de1e7e22d0ce0a523) --- toolchain-extras/profile-extras.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/toolchain-extras/profile-extras.cpp b/toolchain-extras/profile-extras.cpp index 3af46a10..21bbfedd 100644 --- a/toolchain-extras/profile-extras.cpp +++ b/toolchain-extras/profile-extras.cpp @@ -17,7 +17,9 @@ #include #include #include +#include #include +#include // For POSIX basename(). // Use _system_properties.h to use __system_property_wait_any() #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ @@ -84,6 +86,20 @@ __attribute__((constructor)) int init_profile_extras(void) { return -1; } + // Do not create thread running property_watch_loop for zygote (it can get + // invoked as zygote or app_process). This check is only needed for the + // platform, but can be done on any version after Android L, when + // getprogname() was added. +#if defined(__ANDROID_API__) && __ANDROID_API__ >= __ANDROID_API_L__ + const char *prog_basename = basename(getprogname()); + if (strncmp(prog_basename, "zygote", strlen("zygote")) == 0) { + return 0; + } + if (strncmp(prog_basename, "app_process", strlen("app_process")) == 0) { + return 0; + } +#endif + pthread_t thread; int error = pthread_create(&thread, nullptr, property_watch_loop, nullptr); if (error != 0) { -- cgit v1.2.3 From baedc8e8815de4e5ec0060ce7a9292560422b268 Mon Sep 17 00:00:00 2001 From: Pirama Arumuga Nainar Date: Wed, 22 May 2019 10:04:50 -0700 Subject: Prefix sysprop for flushing coverage with 'debug.' Bug: http://b/133322197 Fix selinux denials when reading the coverage.flush sysprop by prefixing it with 'debug.'. Sysprops starting with 'debug.' are readable by all processes when ro.debuggable is set. Test: Build cuttlefish with coverage and verify that selinux denials for sysprop reads no longer happen. Change-Id: I76bef0a658ce881cc81e2d2d4947bef966060376 (cherry picked from commit 9d31ce99069b28d302c5487c2154fc0fd5c2f9fd) --- toolchain-extras/profile-extras-test.cpp | 2 +- toolchain-extras/profile-extras.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/toolchain-extras/profile-extras-test.cpp b/toolchain-extras/profile-extras-test.cpp index 0cc4cef8..5e48a646 100644 --- a/toolchain-extras/profile-extras-test.cpp +++ b/toolchain-extras/profile-extras-test.cpp @@ -28,7 +28,7 @@ void __gcov_flush() { } } -static const char kCoveragePropName[] = "coverage.flush"; +static const char kCoveragePropName[] = "debug.coverage.flush"; TEST(profile_extras, smoke) { flush_count = 0; diff --git a/toolchain-extras/profile-extras.cpp b/toolchain-extras/profile-extras.cpp index 3af46a10..1b1393b7 100644 --- a/toolchain-extras/profile-extras.cpp +++ b/toolchain-extras/profile-extras.cpp @@ -33,7 +33,7 @@ static void gcov_signal_handler(__unused int signum) { __gcov_flush(); } -static const char kCoveragePropName[] = "coverage.flush"; +static const char kCoveragePropName[] = "debug.coverage.flush"; // In a loop, wait for any change to sysprops and trigger a __gcov_flush when // sysprop transistions to "1" after a transistion to "0". -- cgit v1.2.3