summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2020-02-04 02:11:18 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2020-02-04 02:11:18 +0000
commit992fcd8f95133af1a6f9cebffb2c13e75115506a (patch)
tree8c64e6ae9306cdbdbda36580bc247a36a051e1fa
parent73e67e44e0a972b3e1a0a48986905e974b9a092e (diff)
parent29e06f5526a2dd48c9f19ef7f238804f84c03c30 (diff)
downloadextras-android10-d4-s1-release.tar.gz
Snap for 6179678 from 29e06f5526a2dd48c9f19ef7f238804f84c03c30 to qt-d4-releaseandroid-10.0.0_r45android-10.0.0_r44android-10.0.0_r43android-10.0.0_r42android10-d4-s1-releaseandroid10-d4-release
Change-Id: Ief5e239a67ac08ccb615513f80cb33506f459511
-rw-r--r--toolchain-extras/Android.bp5
-rw-r--r--toolchain-extras/profile-extras.cpp44
-rw-r--r--toolchain-extras/profile-globals.c44
3 files changed, 87 insertions, 6 deletions
diff --git a/toolchain-extras/Android.bp b/toolchain-extras/Android.bp
index 727f9795..5c839a1e 100644
--- a/toolchain-extras/Android.bp
+++ b/toolchain-extras/Android.bp
@@ -2,6 +2,7 @@ cc_defaults {
name: "libprofile-defaults",
srcs: [
"profile-extras.cpp",
+ "profile-globals.c",
],
native_coverage: false,
}
@@ -24,6 +25,10 @@ cc_library_static {
cc_library_static {
name: "libprofile-extras_ndk",
defaults: ["libprofile-defaults",],
+ vendor_available: true,
+ vndk: {
+ enabled: true,
+ },
sdk_version: "minimum",
}
diff --git a/toolchain-extras/profile-extras.cpp b/toolchain-extras/profile-extras.cpp
index 2d685084..7d78a0a5 100644
--- a/toolchain-extras/profile-extras.cpp
+++ b/toolchain-extras/profile-extras.cpp
@@ -31,8 +31,16 @@ extern "C" {
void __gcov_flush(void);
-static void gcov_signal_handler(__unused int signum) {
+// storing SIG_ERR helps us detect (unlikely) looping.
+static sighandler_t chained_gcov_signal_handler = SIG_ERR;
+
+static void gcov_signal_handler(int signum) {
__gcov_flush();
+ if (chained_gcov_signal_handler != SIG_ERR &&
+ chained_gcov_signal_handler != SIG_IGN &&
+ chained_gcov_signal_handler != SIG_DFL) {
+ (chained_gcov_signal_handler)(signum);
+ }
}
static const char kCoveragePropName[] = "debug.coverage.flush";
@@ -67,6 +75,22 @@ void *property_watch_loop(__unused void *arg) {
}
}
+#if defined(__ANDROID_API__) && __ANDROID_API__ >= __ANDROID_API_L__
+static char prop_watch_disabled_procs[][128] = {
+ "zygote",
+ "zygote32",
+ "app_process",
+ "app_process32",
+ "adbd",
+ "init",
+};
+
+static size_t prop_watch_num_disabled_procs = \
+ sizeof(prop_watch_disabled_procs) / sizeof(prop_watch_disabled_procs[0]);
+#endif
+
+__attribute__((weak)) int init_profile_extras_once = 0;
+
// Initialize libprofile-extras:
// - Install a signal handler that triggers __gcov_flush on <GCOV_FLUSH_SIGNAL>.
// - Create a thread that calls __gcov_flush when <kCoveragePropName> sysprop
@@ -81,10 +105,19 @@ void *property_watch_loop(__unused void *arg) {
// We force the linker to include init_profile_extras() by passing
// '-uinit_profile_extras' to the linker (in build/soong).
__attribute__((constructor)) int init_profile_extras(void) {
+ if (init_profile_extras_once)
+ return 0;
+ init_profile_extras_once = 1;
+
+ // is this instance already registered?
+ if (chained_gcov_signal_handler != SIG_ERR) {
+ return -1;
+ }
sighandler_t ret1 = signal(GCOV_FLUSH_SIGNAL, gcov_signal_handler);
if (ret1 == SIG_ERR) {
return -1;
}
+ chained_gcov_signal_handler = ret1;
// 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
@@ -92,11 +125,10 @@ __attribute__((constructor)) int init_profile_extras(void) {
// 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;
+ for (size_t i = 0; i < prop_watch_num_disabled_procs; i ++) {
+ if (strcmp(prog_basename, prop_watch_disabled_procs[i]) == 0) {
+ return 0;
+ }
}
#endif
diff --git a/toolchain-extras/profile-globals.c b/toolchain-extras/profile-globals.c
new file mode 100644
index 00000000..309f0606
--- /dev/null
+++ b/toolchain-extras/profile-globals.c
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+// This file provides a wrapper for getenv that appends the userid (geteuid())
+// of the current process to GCOV_PREFIX. This avoids conflicts and permissions
+// issues when different processes try to create/access the same directories and
+// files under $GCOV_PREFIX.
+//
+// When this file is linked to a binary, the -Wl,--wrap,getenv flag must be
+// used. The linker redirects calls to getenv to __wrap_getenv and sets
+// __real_getenv to point to libc's getenv.
+
+char *__real_getenv(const char *name);
+
+static char modified_gcov_prefix[128];
+
+__attribute__((weak)) char *__wrap_getenv(const char *name) {
+ if (strcmp(name, "GCOV_PREFIX") != 0) {
+ return __real_getenv(name);
+ }
+
+ sprintf(modified_gcov_prefix, "%s/%u", __real_getenv(name), geteuid());
+ mkdir(modified_gcov_prefix, 0777);
+ return modified_gcov_prefix;
+}