summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2020-02-04 02:04:48 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2020-02-04 02:04:48 +0000
commita328d2156f8b8fdb7ddfac66162ad098e9c8d455 (patch)
treef287d43acdeba2afc7167ab13c26a3e4aed8bb57
parentef17b323e8be065ed9fbcd1ea863d72e63488fc0 (diff)
parentb47555debc7373287ee2ae960df2a3e55579c52b (diff)
downloadextras-a328d2156f8b8fdb7ddfac66162ad098e9c8d455.tar.gz
Snap for 6179254 from b47555debc7373287ee2ae960df2a3e55579c52b to qt-qpr3-release
Change-Id: I9ca65cd159fcccb784ed18b26f524e582c923d38
-rw-r--r--toolchain-extras/Android.bp5
-rw-r--r--toolchain-extras/profile-extras.cpp29
-rw-r--r--toolchain-extras/profile-globals.c44
3 files changed, 73 insertions, 5 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..b7a9318a 100644
--- a/toolchain-extras/profile-extras.cpp
+++ b/toolchain-extras/profile-extras.cpp
@@ -67,6 +67,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,6 +97,10 @@ 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;
+
sighandler_t ret1 = signal(GCOV_FLUSH_SIGNAL, gcov_signal_handler);
if (ret1 == SIG_ERR) {
return -1;
@@ -92,11 +112,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;
+}