Merge "Fix clang-tidy performance warnings in system/core."
diff --git a/base/include/android-base/macros.h b/base/include/android-base/macros.h
index 49cc0c9..1748665 100644
--- a/base/include/android-base/macros.h
+++ b/base/include/android-base/macros.h
@@ -170,7 +170,9 @@
//
// In either case this macro has no effect on runtime behavior and performance
// of code.
+#ifndef FALLTHROUGH_INTENDED
#define FALLTHROUGH_INTENDED [[clang::fallthrough]] // NOLINT
+#endif
// Current ABI string
#if defined(__arm__)
diff --git a/debuggerd/debuggerd_test.cpp b/debuggerd/debuggerd_test.cpp
index 388facb..bea8b43 100644
--- a/debuggerd/debuggerd_test.cpp
+++ b/debuggerd/debuggerd_test.cpp
@@ -37,6 +37,7 @@
#include <android-base/macros.h>
#include <android-base/parseint.h>
#include <android-base/properties.h>
+#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <android-base/test_utils.h>
#include <android-base/unique_fd.h>
@@ -1053,3 +1054,42 @@
ASSERT_TRUE(android::base::ReadFully(output_fd.get(), outbuf, sizeof(outbuf)));
ASSERT_STREQ("any", outbuf);
}
+
+TEST(tombstoned, interceptless_backtrace) {
+ // Generate 50 backtraces, and then check to see that we haven't created 50 new tombstones.
+ auto get_tombstone_timestamps = []() -> std::map<int, time_t> {
+ std::map<int, time_t> result;
+ for (int i = 0; i < 99; ++i) {
+ std::string path = android::base::StringPrintf("/data/tombstones/tombstone_%02d", i);
+ struct stat st;
+ if (stat(path.c_str(), &st) == 0) {
+ result[i] = st.st_mtim.tv_sec;
+ }
+ }
+ return result;
+ };
+
+ auto before = get_tombstone_timestamps();
+ for (int i = 0; i < 50; ++i) {
+ raise_debugger_signal(kDebuggerdNativeBacktrace);
+ }
+ auto after = get_tombstone_timestamps();
+
+ int diff = 0;
+ for (int i = 0; i < 99; ++i) {
+ if (after.count(i) == 0) {
+ continue;
+ }
+ if (before.count(i) == 0) {
+ ++diff;
+ continue;
+ }
+ if (before[i] != after[i]) {
+ ++diff;
+ }
+ }
+
+ // We can't be sure that nothing's crash looping in the background.
+ // This should be good enough, though...
+ ASSERT_LT(diff, 10) << "too many new tombstones; is something crashing in the background?";
+}
diff --git a/debuggerd/tombstoned/tombstoned.cpp b/debuggerd/tombstoned/tombstoned.cpp
index 15ae406..ad92067 100644
--- a/debuggerd/tombstoned/tombstoned.cpp
+++ b/debuggerd/tombstoned/tombstoned.cpp
@@ -212,8 +212,13 @@
bool intercepted =
intercept_manager->GetIntercept(crash->crash_pid, crash->crash_type, &output_fd);
if (!intercepted) {
- std::tie(crash->crash_tombstone_path, output_fd) = CrashQueue::for_crash(crash)->get_output();
- crash->crash_tombstone_fd.reset(dup(output_fd.get()));
+ if (crash->crash_type == kDebuggerdNativeBacktrace) {
+ // Don't generate tombstones for native backtrace requests.
+ output_fd.reset(open("/dev/null", O_WRONLY | O_CLOEXEC));
+ } else {
+ std::tie(crash->crash_tombstone_path, output_fd) = CrashQueue::for_crash(crash)->get_output();
+ crash->crash_tombstone_fd.reset(dup(output_fd.get()));
+ }
}
TombstonedCrashPacket response = {
diff --git a/init/Android.mk b/init/Android.mk
index dc400ad..5554995 100644
--- a/init/Android.mk
+++ b/init/Android.mk
@@ -61,9 +61,9 @@
# Set up the same mount points on the ramdisk that system-as-root contains.
LOCAL_POST_INSTALL_CMD := \
mkdir -p $(TARGET_RAMDISK_OUT)/dev \
- mkdir -p $(TARGET_RAMDISK_OUT)/mnt \
- mkdir -p $(TARGET_RAMDISK_OUT)/proc \
- mkdir -p $(TARGET_RAMDISK_OUT)/sys \
+ $(TARGET_RAMDISK_OUT)/mnt \
+ $(TARGET_RAMDISK_OUT)/proc \
+ $(TARGET_RAMDISK_OUT)/sys \
LOCAL_STATIC_LIBRARIES := \
libfs_mgr \
diff --git a/liblog/tests/liblog_test.cpp b/liblog/tests/liblog_test.cpp
index a8a9a12..d1f20f4 100644
--- a/liblog/tests/liblog_test.cpp
+++ b/liblog/tests/liblog_test.cpp
@@ -30,6 +30,7 @@
#include <string>
#include <android-base/file.h>
+#include <android-base/macros.h>
#include <android-base/stringprintf.h>
#ifdef __ANDROID__ // includes sys/properties.h which does not exist outside
#include <cutils/properties.h>
@@ -2516,7 +2517,7 @@
#endif
elem.data.string = const_cast<char*>("<unknown>");
elem.len = strlen(elem.data.string);
- /* FALLTHRU */
+ FALLTHROUGH_INTENDED;
case EVENT_TYPE_STRING:
if (elem.len <= strOutLen) {
memcpy(strOut, elem.data.string, elem.len);
diff --git a/libpixelflinger/Android.mk b/libpixelflinger/Android.mk
index 14883f4..8c80f6a 100644
--- a/libpixelflinger/Android.mk
+++ b/libpixelflinger/Android.mk
@@ -73,6 +73,7 @@
LOCAL_CFLAGS := $(PIXELFLINGER_CFLAGS)
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
LOCAL_C_INCLUDES += $(LOCAL_EXPORT_C_INCLUDE_DIRS)
+LOCAL_HEADER_LIBRARIES := libbase_headers
LOCAL_SHARED_LIBRARIES := libcutils liblog libutils
include $(BUILD_SHARED_LIBRARY)
diff --git a/libpixelflinger/buffer.cpp b/libpixelflinger/buffer.cpp
index dcb95c5..ea9514c 100644
--- a/libpixelflinger/buffer.cpp
+++ b/libpixelflinger/buffer.cpp
@@ -18,6 +18,8 @@
#include <assert.h>
+#include <android-base/macros.h>
+
#include "buffer.h"
namespace android {
@@ -266,8 +268,11 @@
p = downshift_component(p, b, hbits, lbits, f->bh, f->bl, 0, 1, -1);
p = downshift_component(p, a, hbits, lbits, f->ah, f->al, 0, 1, -1);
switch (f->size) {
- case 1: p |= p << 8; // fallthrough
- case 2: p |= p << 16;
+ case 1:
+ p |= p << 8;
+ FALLTHROUGH_INTENDED;
+ case 2:
+ p |= p << 16;
}
return p;
}
diff --git a/libpixelflinger/codeflinger/blending.cpp b/libpixelflinger/codeflinger/blending.cpp
index a55dfe3..2cbb00f 100644
--- a/libpixelflinger/codeflinger/blending.cpp
+++ b/libpixelflinger/codeflinger/blending.cpp
@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <sys/types.h>
+#include <android-base/macros.h>
#include <log/log.h>
#include "GGLAssembler.h"
@@ -301,7 +302,7 @@
return;
}
}
- // fall-through...
+ FALLTHROUGH_INTENDED;
case GGL_ONE_MINUS_DST_COLOR:
case GGL_DST_COLOR:
case GGL_ONE_MINUS_SRC_COLOR:
diff --git a/libsysutils/src/SocketClient.cpp b/libsysutils/src/SocketClient.cpp
index 0625db7..fe2f3d6 100644
--- a/libsysutils/src/SocketClient.cpp
+++ b/libsysutils/src/SocketClient.cpp
@@ -27,6 +27,8 @@
#include <sys/types.h>
#include <unistd.h>
+#include <android-base/file.h>
+#include <android-base/macros.h>
#include <log/log.h>
#include <sysutils/SocketClient.h>
@@ -145,7 +147,8 @@
switch (*arg) {
case '\\':
case '"':
- *(current++) = '\\'; // fallthrough
+ *(current++) = '\\';
+ FALLTHROUGH_INTENDED;
default:
*(current++) = *(arg++);
}
diff --git a/libunwindstack/DwarfCfa.cpp b/libunwindstack/DwarfCfa.cpp
index cd9ef61..0fa1638 100644
--- a/libunwindstack/DwarfCfa.cpp
+++ b/libunwindstack/DwarfCfa.cpp
@@ -21,6 +21,7 @@
#include <type_traits>
#include <vector>
+#include <android-base/macros.h>
#include <android-base/stringprintf.h>
#include <unwindstack/DwarfError.h>
@@ -154,13 +155,15 @@
break;
case DwarfCfaInfo::DWARF_DISPLAY_ADVANCE_LOC:
*cur_pc += value;
- // Fall through to log the value.
+ FALLTHROUGH_INTENDED;
+ // Fall through to log the value.
case DwarfCfaInfo::DWARF_DISPLAY_NUMBER:
string += " " + std::to_string(value);
break;
case DwarfCfaInfo::DWARF_DISPLAY_SET_LOC:
*cur_pc = value;
- // Fall through to log the value.
+ FALLTHROUGH_INTENDED;
+ // Fall through to log the value.
case DwarfCfaInfo::DWARF_DISPLAY_ADDRESS:
if (std::is_same<AddressType, uint32_t>::value) {
string += android::base::StringPrintf(" 0x%" PRIx32, static_cast<uint32_t>(value));
diff --git a/libutils/Android.bp b/libutils/Android.bp
index 1c1bdf7..600c91c 100644
--- a/libutils/Android.bp
+++ b/libutils/Android.bp
@@ -59,6 +59,7 @@
"-Werror",
],
header_libs: [
+ "libbase_headers",
"libutils_headers",
],
export_header_lib_headers: [
diff --git a/libutils/RefBase.cpp b/libutils/RefBase.cpp
index 3f1e79a..ae10789 100644
--- a/libutils/RefBase.cpp
+++ b/libutils/RefBase.cpp
@@ -19,6 +19,8 @@
#include <memory>
+#include <android-base/macros.h>
+
#include <utils/RefBase.h>
#include <utils/CallStack.h>
@@ -479,7 +481,7 @@
case INITIAL_STRONG_VALUE:
refs->mStrong.fetch_sub(INITIAL_STRONG_VALUE,
std::memory_order_relaxed);
- // fall through...
+ FALLTHROUGH_INTENDED;
case 0:
refs->mBase->onFirstRef();
}
diff --git a/libutils/Unicode.cpp b/libutils/Unicode.cpp
index 82f650d..5f0a51f 100644
--- a/libutils/Unicode.cpp
+++ b/libutils/Unicode.cpp
@@ -16,8 +16,9 @@
#define LOG_TAG "unicode"
-#include <utils/Unicode.h>
+#include <android-base/macros.h>
#include <limits.h>
+#include <utils/Unicode.h>
#include <log/log.h>
@@ -105,8 +106,11 @@
switch (bytes)
{ /* note: everything falls through. */
case 4: *--dstP = (uint8_t)((srcChar | kByteMark) & kByteMask); srcChar >>= 6;
+ FALLTHROUGH_INTENDED;
case 3: *--dstP = (uint8_t)((srcChar | kByteMark) & kByteMask); srcChar >>= 6;
+ FALLTHROUGH_INTENDED;
case 2: *--dstP = (uint8_t)((srcChar | kByteMark) & kByteMask); srcChar >>= 6;
+ FALLTHROUGH_INTENDED;
case 1: *--dstP = (uint8_t)(srcChar | kFirstByteMark[bytes]);
}
}
diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp
index 0f1badb..115b1a3 100644
--- a/logcat/logcat.cpp
+++ b/logcat/logcat.cpp
@@ -16,6 +16,7 @@
#include "logcat.h"
+#include <android-base/macros.h>
#include <arpa/inet.h>
#include <assert.h>
#include <ctype.h>
@@ -959,7 +960,7 @@
case 't':
got_t = true;
mode |= ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK;
- // FALLTHRU
+ FALLTHROUGH_INTENDED;
case 'T':
if (strspn(optarg, "0123456789") != strlen(optarg)) {
char* cp = parseTime(tail_time, optarg);
@@ -1009,7 +1010,7 @@
getLogSize = true;
break;
}
- // FALLTHRU
+ FALLTHROUGH_INTENDED;
case 'G': {
char* cp;
@@ -1023,15 +1024,15 @@
case 'g':
case 'G':
setLogSize *= 1024;
- // FALLTHRU
+ FALLTHROUGH_INTENDED;
case 'm':
case 'M':
setLogSize *= 1024;
- // FALLTHRU
+ FALLTHROUGH_INTENDED;
case 'k':
case 'K':
setLogSize *= 1024;
- // FALLTHRU
+ FALLTHROUGH_INTENDED;
case '\0':
break;
@@ -1051,7 +1052,7 @@
getPruneList = true;
break;
}
- // FALLTHRU
+ FALLTHROUGH_INTENDED;
case 'P':
setPruneList = optarg;
diff --git a/logcat/tests/logcat_test.cpp b/logcat/tests/logcat_test.cpp
index bebcc71..9483bb2 100644
--- a/logcat/tests/logcat_test.cpp
+++ b/logcat/tests/logcat_test.cpp
@@ -31,6 +31,7 @@
#include <string>
#include <android-base/file.h>
+#include <android-base/macros.h>
#include <android-base/stringprintf.h>
#include <gtest/gtest.h>
#include <log/event_tag_map.h>
@@ -572,13 +573,13 @@
switch (size_mult[0]) {
case 'G':
full_size *= 1024;
- /* FALLTHRU */
+ FALLTHROUGH_INTENDED;
case 'M':
full_size *= 1024;
- /* FALLTHRU */
+ FALLTHROUGH_INTENDED;
case 'K':
full_size *= 1024;
- /* FALLTHRU */
+ FALLTHROUGH_INTENDED;
case 'B':
break;
default:
@@ -588,13 +589,13 @@
switch (consumed_mult[0]) {
case 'G':
full_consumed *= 1024;
- /* FALLTHRU */
+ FALLTHROUGH_INTENDED;
case 'M':
full_consumed *= 1024;
- /* FALLTHRU */
+ FALLTHROUGH_INTENDED;
case 'K':
full_consumed *= 1024;
- /* FALLTHRU */
+ FALLTHROUGH_INTENDED;
case 'B':
break;
default:
@@ -1241,26 +1242,26 @@
switch (size_mult[0]) {
case 'G':
full_size *= 1024;
- /* FALLTHRU */
+ FALLTHROUGH_INTENDED;
case 'M':
full_size *= 1024;
- /* FALLTHRU */
+ FALLTHROUGH_INTENDED;
case 'K':
full_size *= 1024;
- /* FALLTHRU */
+ FALLTHROUGH_INTENDED;
case 'B':
break;
}
switch (consumed_mult[0]) {
case 'G':
full_consumed *= 1024;
- /* FALLTHRU */
+ FALLTHROUGH_INTENDED;
case 'M':
full_consumed *= 1024;
- /* FALLTHRU */
+ FALLTHROUGH_INTENDED;
case 'K':
full_consumed *= 1024;
- /* FALLTHRU */
+ FALLTHROUGH_INTENDED;
case 'B':
break;
}
diff --git a/logd/LogKlog.cpp b/logd/LogKlog.cpp
index e4393a3..513c0c3 100644
--- a/logd/LogKlog.cpp
+++ b/logd/LogKlog.cpp
@@ -475,9 +475,7 @@
static int convertKernelPrioToAndroidPrio(int pri) {
switch (pri & LOG_PRIMASK) {
case LOG_EMERG:
- // FALLTHRU
case LOG_ALERT:
- // FALLTHRU
case LOG_CRIT:
return ANDROID_LOG_FATAL;
@@ -488,9 +486,7 @@
return ANDROID_LOG_WARN;
default:
- // FALLTHRU
case LOG_NOTICE:
- // FALLTHRU
case LOG_INFO:
break;
diff --git a/rootdir/etc/public.libraries.android.txt b/rootdir/etc/public.libraries.android.txt
index e20b95d..d8f6095 100644
--- a/rootdir/etc/public.libraries.android.txt
+++ b/rootdir/etc/public.libraries.android.txt
@@ -1,6 +1,7 @@
# See https://android.googlesource.com/platform/ndk/+/master/docs/PlatformApis.md
libandroid.so
libaaudio.so
+libbinder_ndk.so
libc.so
libcamera2ndk.so
libdl.so
diff --git a/rootdir/etc/public.libraries.iot.txt b/rootdir/etc/public.libraries.iot.txt
index ff0813d..20905bf 100644
--- a/rootdir/etc/public.libraries.iot.txt
+++ b/rootdir/etc/public.libraries.iot.txt
@@ -2,6 +2,7 @@
libandroid.so
libandroidthings.so
libaaudio.so
+libbinder_ndk.so
libc.so
libcamera2ndk.so
libdl.so
diff --git a/rootdir/etc/public.libraries.wear.txt b/rootdir/etc/public.libraries.wear.txt
index 3c46094..4ece5b5 100644
--- a/rootdir/etc/public.libraries.wear.txt
+++ b/rootdir/etc/public.libraries.wear.txt
@@ -1,6 +1,7 @@
# See https://android.googlesource.com/platform/ndk/+/master/docs/PlatformApis.md
libandroid.so
libaaudio.so
+libbinder_ndk.so
libc.so
libcamera2ndk.so
libdl.so