Decrease logspam of stack MTE remapping.
Currently the log is called for each library that's loaded with MTE
stack. For apps that are a launched with stack MTE (e.g. the CTS test
apps), this causes ~40 or so loglines telling us that the stack is being
remapped.
Instead, make it log only once, the first time it's remapped.
Bug: N/A
Test: blatant visual code inspection
Change-Id: If2883bc2355318b1db83f0c5ccb67050a457b52e
diff --git a/libc/bionic/pthread_internal.cpp b/libc/bionic/pthread_internal.cpp
index 3c8f9d5..e8a8ba2 100644
--- a/libc/bionic/pthread_internal.cpp
+++ b/libc/bionic/pthread_internal.cpp
@@ -240,12 +240,12 @@
return reinterpret_cast<void*>(aligned_allocation | ((1ULL << n) << 56ULL));
}
-void __pthread_internal_remap_stack_with_mte() {
+bool __pthread_internal_remap_stack_with_mte() {
#if defined(__aarch64__)
ScopedWriteLock creation_locker(&g_thread_creation_lock);
ScopedReadLock list_locker(&g_thread_list_lock);
// If process already uses memtag-stack ABI, we don't need to do anything.
- if (__libc_memtag_stack_abi) return;
+ if (__libc_memtag_stack_abi) return false;
__libc_memtag_stack_abi = true;
for (pthread_internal_t* t = g_thread_list; t != nullptr; t = t->next) {
@@ -253,8 +253,8 @@
t->bionic_tcb->tls_slot(TLS_SLOT_STACK_MTE) =
__allocate_stack_mte_ringbuffer(0, t->is_main() ? nullptr : t);
}
- if (!atomic_load(&__libc_globals->memtag)) return;
- if (atomic_exchange(&__libc_memtag_stack, true)) return;
+ if (!atomic_load(&__libc_globals->memtag)) return false;
+ if (atomic_exchange(&__libc_memtag_stack, true)) return false;
uintptr_t lo, hi;
__find_main_stack_limits(&lo, &hi);
@@ -269,7 +269,10 @@
async_safe_fatal("error: failed to set PROT_MTE on thread: %d", t->tid);
}
}
-#endif
+ return true;
+#else
+ return false;
+#endif // defined(__aarch64__)
}
bool android_run_on_all_threads(bool (*func)(void*), void* arg) {