Merge "Nullability check for system_properties module."
diff --git a/libc/bionic/gwp_asan_wrappers.cpp b/libc/bionic/gwp_asan_wrappers.cpp
index fab29ef..251633d 100644
--- a/libc/bionic/gwp_asan_wrappers.cpp
+++ b/libc/bionic/gwp_asan_wrappers.cpp
@@ -307,10 +307,8 @@
sysprop_names[3] = persist_default_sysprop;
}
- // TODO(mitchp): Log overrides using this.
- const char* source;
return get_config_from_env_or_sysprops(env_var, sysprop_names, arraysize(sysprop_names),
- value_out, PROP_VALUE_MAX, &source);
+ value_out, PROP_VALUE_MAX);
}
bool GetGwpAsanIntegerOption(unsigned long long* result,
diff --git a/libc/bionic/libc_init_static.cpp b/libc/bionic/libc_init_static.cpp
index 0935cd6..d64d402 100644
--- a/libc/bionic/libc_init_static.cpp
+++ b/libc/bionic/libc_init_static.cpp
@@ -217,13 +217,16 @@
// Returns true if there's an environment setting (either sysprop or env var)
// that should overwrite the ELF note, and places the equivalent heap tagging
// level into *level.
-static bool get_environment_memtag_setting(const char* basename, HeapTaggingLevel* level) {
+static bool get_environment_memtag_setting(HeapTaggingLevel* level) {
static const char kMemtagPrognameSyspropPrefix[] = "arm64.memtag.process.";
static const char kMemtagGlobalSysprop[] = "persist.arm64.memtag.default";
static const char kMemtagOverrideSyspropPrefix[] =
"persist.device_config.memory_safety_native.mode_override.process.";
- if (basename == nullptr) return false;
+ const char* progname = __libc_shared_globals()->init_progname;
+ if (progname == nullptr) return false;
+
+ const char* basename = __gnu_basename(progname);
char options_str[PROP_VALUE_MAX];
char sysprop_name[512];
@@ -234,9 +237,8 @@
kMemtagOverrideSyspropPrefix, basename);
const char* sys_prop_names[] = {sysprop_name, remote_sysprop_name, kMemtagGlobalSysprop};
- const char* source = nullptr;
if (!get_config_from_env_or_sysprops("MEMTAG_OPTIONS", sys_prop_names, arraysize(sys_prop_names),
- options_str, sizeof(options_str), &source)) {
+ options_str, sizeof(options_str))) {
return false;
}
@@ -247,20 +249,14 @@
} else if (strcmp("off", options_str) == 0) {
*level = M_HEAP_TAGGING_LEVEL_TBI;
} else {
- async_safe_format_log(ANDROID_LOG_ERROR, "libc",
- "%s: unrecognized memtag level in %s: \"%s\" (options are \"sync\", "
- "\"async\", or \"off\").",
- basename, source, options_str);
+ async_safe_format_log(
+ ANDROID_LOG_ERROR, "libc",
+ "unrecognized memtag level: \"%s\" (options are \"sync\", \"async\", or \"off\").",
+ options_str);
return false;
}
- async_safe_format_log(ANDROID_LOG_DEBUG, "libc", "%s: chose memtag level \"%s\" from %s.",
- basename, options_str, source);
- return true;
-}
-static void log_elf_memtag_level(const char* basename, const char* level) {
- async_safe_format_log(ANDROID_LOG_DEBUG, "libc", "%s: chose memtag level \"%s\" from ELF note",
- basename ?: "<unknown>", level);
+ return true;
}
// Returns the initial heap tagging level. Note: This function will never return
@@ -268,14 +264,12 @@
// M_HEAP_TAGGING_LEVEL_TBI.
static HeapTaggingLevel __get_heap_tagging_level(const void* phdr_start, size_t phdr_ct,
uintptr_t load_bias, bool* stack) {
- const char* progname = __libc_shared_globals()->init_progname;
- const char* basename = progname ? __gnu_basename(progname) : nullptr;
unsigned note_val =
__get_memtag_note(reinterpret_cast<const ElfW(Phdr)*>(phdr_start), phdr_ct, load_bias);
*stack = note_val & NT_MEMTAG_STACK;
HeapTaggingLevel level;
- if (get_environment_memtag_setting(basename, &level)) return level;
+ if (get_environment_memtag_setting(&level)) return level;
// Note, previously (in Android 12), any value outside of bits [0..3] resulted
// in a check-fail. In order to be permissive of further extensions, we
@@ -290,17 +284,14 @@
// by anyone, but we note it (heh) here for posterity, in case the zero
// level becomes meaningful, and binaries with this note can be executed
// on Android 12 devices.
- log_elf_memtag_level(basename, "off");
return M_HEAP_TAGGING_LEVEL_TBI;
case NT_MEMTAG_LEVEL_ASYNC:
- log_elf_memtag_level(basename, "async");
return M_HEAP_TAGGING_LEVEL_ASYNC;
case NT_MEMTAG_LEVEL_SYNC:
default:
// We allow future extensions to specify mode 3 (currently unused), with
// the idea that it might be used for ASYMM mode or something else. On
// this version of Android, it falls back to SYNC mode.
- log_elf_memtag_level(basename, "sync");
return M_HEAP_TAGGING_LEVEL_SYNC;
}
}
diff --git a/libc/bionic/sysprop_helpers.cpp b/libc/bionic/sysprop_helpers.cpp
index 2051330..5627034 100644
--- a/libc/bionic/sysprop_helpers.cpp
+++ b/libc/bionic/sysprop_helpers.cpp
@@ -57,22 +57,18 @@
}
bool get_config_from_env_or_sysprops(const char* env_var_name, const char* const* sys_prop_names,
- size_t sys_prop_names_size, char* options, size_t options_size,
- const char** chosen_source) {
+ size_t sys_prop_names_size, char* options,
+ size_t options_size) {
const char* env = getenv(env_var_name);
if (env && *env != '\0') {
strncpy(options, env, options_size);
options[options_size - 1] = '\0'; // Ensure null-termination.
- *chosen_source = env_var_name;
return true;
}
for (size_t i = 0; i < sys_prop_names_size; ++i) {
if (sys_prop_names[i] == nullptr) continue;
- if (get_property_value(sys_prop_names[i], options, options_size)) {
- *chosen_source = sys_prop_names[i];
- return true;
- }
+ if (get_property_value(sys_prop_names[i], options, options_size)) return true;
}
return false;
}
diff --git a/libc/bionic/sysprop_helpers.h b/libc/bionic/sysprop_helpers.h
index 84e7af1..a02c2dc 100644
--- a/libc/bionic/sysprop_helpers.h
+++ b/libc/bionic/sysprop_helpers.h
@@ -36,13 +36,10 @@
// 2. System properties, in the order they're specified in sys_prop_names.
// If neither of these options are specified (or they're both an empty string),
// this function returns false. Otherwise, it returns true, and the presiding
-// options string is written to the `options` buffer of size `size`. It will
-// store a pointer to either env_var_name, or into the relevant entry of
-// sys_prop_names into choicen_source, indiciating which value was used. If
-// this function returns true, `options` is guaranteed to be null-terminated.
+// options string is written to the `options` buffer of size `size`. If this
+// function returns true, `options` is guaranteed to be null-terminated.
// `options_size` should be at least PROP_VALUE_MAX.
__LIBC_HIDDEN__ bool get_config_from_env_or_sysprops(const char* env_var_name,
const char* const* sys_prop_names,
size_t sys_prop_names_size, char* options,
- size_t options_size,
- const char** chosen_source);
+ size_t options_size);
diff --git a/libfdtrack/Android.bp b/libfdtrack/Android.bp
index 83ea7cb..7539052 100644
--- a/libfdtrack/Android.bp
+++ b/libfdtrack/Android.bp
@@ -22,10 +22,16 @@
static_libs: [
"libasync_safe",
"libbase",
+ "libdexfile_support",
"libunwindstack",
"liblzma",
"liblog",
],
+ target: {
+ recovery: {
+ exclude_static_libs: ["libdexfile_support"],
+ },
+ },
version_script: "libfdtrack.map.txt",
allow_undefined_symbols: true,
diff --git a/libfdtrack/fdtrack.cpp b/libfdtrack/fdtrack.cpp
index b064401..57b9d37 100644
--- a/libfdtrack/fdtrack.cpp
+++ b/libfdtrack/fdtrack.cpp
@@ -45,10 +45,8 @@
#include <android-base/thread_annotations.h>
#include <async_safe/log.h>
#include <bionic/reserved_signals.h>
-#include <unwindstack/Maps.h>
-#include <unwindstack/Regs.h>
-#include <unwindstack/RegsGetLocal.h>
-#include <unwindstack/Unwinder.h>
+
+#include <unwindstack/AndroidUnwinder.h>
struct FdEntry {
std::mutex mutex;
@@ -70,22 +68,16 @@
// Only unwind up to 32 frames outside of libfdtrack.so.
static constexpr size_t kStackDepth = 32;
-// Skip any initial frames from libfdtrack.so.
-// Also ignore frames from ART (http://b/236197847) because we'd rather spend
-// our precious few frames on the actual Java calling code rather than the
-// implementation of JNI!
-static std::vector<std::string> kSkipFdtrackLib
- [[clang::no_destroy]] = {"libfdtrack.so", "libart.so"};
-
static bool installed = false;
static std::array<FdEntry, kFdTableSize> stack_traces [[clang::no_destroy]];
-static unwindstack::LocalUpdatableMaps& Maps() {
- static android::base::NoDestructor<unwindstack::LocalUpdatableMaps> maps;
- return *maps.get();
-}
-static std::shared_ptr<unwindstack::Memory>& ProcessMemory() {
- static android::base::NoDestructor<std::shared_ptr<unwindstack::Memory>> process_memory;
- return *process_memory.get();
+static unwindstack::AndroidLocalUnwinder& Unwinder() {
+ // Skip any initial frames from libfdtrack.so.
+ // Also ignore frames from ART (http://b/236197847) because we'd rather spend
+ // our precious few frames on the actual Java calling code rather than the
+ // implementation of JNI!
+ static android::base::NoDestructor<unwindstack::AndroidLocalUnwinder> unwinder(
+ std::vector<std::string>{"libfdtrack.so", "libart.so"});
+ return *unwinder.get();
}
__attribute__((constructor)) static void ctor() {
@@ -104,8 +96,8 @@
sa.sa_flags = SA_SIGINFO | SA_ONSTACK;
sigaction(BIONIC_SIGNAL_FDTRACK, &sa, nullptr);
- if (Maps().Parse()) {
- ProcessMemory() = unwindstack::Memory::CreateProcessMemoryThreadCached(getpid());
+ unwindstack::ErrorData error;
+ if (Unwinder().Initialize(error)) {
android_fdtrack_hook_t expected = nullptr;
installed = android_fdtrack_compare_exchange_hook(&expected, &fd_hook);
}
@@ -133,11 +125,10 @@
std::lock_guard<std::mutex> lock(entry->mutex);
entry->backtrace.clear();
- std::unique_ptr<unwindstack::Regs> regs(unwindstack::Regs::CreateFromLocal());
- unwindstack::RegsGetLocal(regs.get());
- unwindstack::Unwinder unwinder(kStackDepth, &Maps(), regs.get(), ProcessMemory());
- unwinder.Unwind(&kSkipFdtrackLib);
- entry->backtrace = unwinder.ConsumeFrames();
+ unwindstack::AndroidUnwinderData data(kStackDepth);
+ if (Unwinder().Unwind(data)) {
+ entry->backtrace = std::move(data.frames);
+ }
}
} else if (event->type == ANDROID_FDTRACK_EVENT_TYPE_CLOSE) {
if (FdEntry* entry = GetFdEntry(event->fd); entry) {