Consistently use %m rather than strerror() in logging.
When I added %m to async_safe_* too, we never followed up and cleaned up
callers.
Test: treehugger
Change-Id: If81943c4c45de49f0fb4bc29cfbd3fc53d4a47fe
diff --git a/libc/bionic/pthread_create.cpp b/libc/bionic/pthread_create.cpp
index 75226d3..194db18 100644
--- a/libc/bionic/pthread_create.cpp
+++ b/libc/bionic/pthread_create.cpp
@@ -78,8 +78,7 @@
MAP_PRIVATE | MAP_ANONYMOUS,
-1, 0);
if (allocation == MAP_FAILED) {
- // Avoid strerror because it might need bionic_tls.
- async_safe_fatal("failed to allocate bionic_tls: error %d", errno);
+ async_safe_fatal("failed to allocate bionic_tls: %m");
}
return static_cast<bionic_tls*>(allocation);
}
@@ -138,8 +137,7 @@
// stack pointer. This is deliberately the only place where the address is stored.
char* scs = scs_aligned_guard_region + scs_offset;
if (mprotect(scs, SCS_SIZE, PROT_READ | PROT_WRITE) == -1) {
- async_safe_fatal("failed to mprotect() on shadow stack %p %d error %s", scs, SCS_SIZE,
- strerror(errno));
+ async_safe_fatal("shadow stack read-write mprotect(%p, %d) failed: %m", scs, SCS_SIZE);
}
#if defined(__aarch64__)
__asm__ __volatile__("mov x18, %0" ::"r"(scs));
@@ -174,12 +172,11 @@
if (need_set) {
if (policy == -1) {
async_safe_format_log(ANDROID_LOG_WARN, "libc",
- "pthread_create sched_getscheduler failed: %s", strerror(errno));
+ "pthread_create sched_getscheduler failed: %m");
return errno;
}
if (sched_getparam(0, ¶m) == -1) {
- async_safe_format_log(ANDROID_LOG_WARN, "libc",
- "pthread_create sched_getparam failed: %s", strerror(errno));
+ async_safe_format_log(ANDROID_LOG_WARN, "libc", "pthread_create sched_getparam failed: %m");
return errno;
}
}
@@ -195,8 +192,8 @@
if (need_set) {
if (sched_setscheduler(thread->tid, policy, ¶m) == -1) {
async_safe_format_log(ANDROID_LOG_WARN, "libc",
- "pthread_create sched_setscheduler(%d, {%d}) call failed: %s", policy,
- param.sched_priority, strerror(errno));
+ "pthread_create sched_setscheduler(%d, {%d}) call failed: %m", policy,
+ param.sched_priority);
#if defined(__LP64__)
// For backwards compatibility reasons, we only report failures on 64-bit devices.
return errno;
@@ -231,10 +228,9 @@
const int flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE;
char* const space = static_cast<char*>(mmap(nullptr, mmap_size, PROT_NONE, flags, -1, 0));
if (space == MAP_FAILED) {
- async_safe_format_log(ANDROID_LOG_WARN,
- "libc",
- "pthread_create failed: couldn't allocate %zu-bytes mapped space: %s",
- mmap_size, strerror(errno));
+ async_safe_format_log(ANDROID_LOG_WARN, "libc",
+ "pthread_create failed: couldn't allocate %zu-bytes mapped space: %m",
+ mmap_size);
return {};
}
const size_t writable_size = mmap_size - stack_guard_size - PTHREAD_GUARD_SIZE;
@@ -249,8 +245,8 @@
if (mprotect(space + stack_guard_size, writable_size, prot) != 0) {
async_safe_format_log(
ANDROID_LOG_WARN, "libc",
- "pthread_create failed: couldn't mprotect %s %zu-byte thread mapping region: %s", prot_str,
- writable_size, strerror(errno));
+ "pthread_create failed: couldn't mprotect %s %zu-byte thread mapping region: %m", prot_str,
+ writable_size);
munmap(space, mmap_size);
return {};
}
@@ -461,8 +457,7 @@
if (thread->mmap_size != 0) {
munmap(thread->mmap_base, thread->mmap_size);
}
- async_safe_format_log(ANDROID_LOG_WARN, "libc", "pthread_create failed: clone failed: %s",
- strerror(clone_errno));
+ async_safe_format_log(ANDROID_LOG_WARN, "libc", "pthread_create failed: clone failed: %m");
return clone_errno;
}