Move libc_log code into libasync_safe.
This library is used by a number of different libraries in the system.
Make it easy for platform libraries to use this library and create
an actual exported include file.
Change the names of the functions to reflect the new name of the library.
Run clang_format on the async_safe_log.cpp file since the formatting is
all over the place.
Bug: 31919199
Test: Compiled for angler/bullhead, and booted.
Test: Ran bionic unit tests.
Test: Ran the malloc debug tests.
Change-Id: I8071bf690c17b0ea3bc8dc5749cdd5b6ad58478a
diff --git a/linker/linker_allocator.cpp b/linker/linker_allocator.cpp
index 723ea2b..fd6f496 100644
--- a/linker/linker_allocator.cpp
+++ b/linker/linker_allocator.cpp
@@ -37,6 +37,8 @@
#include <sys/mman.h>
#include <unistd.h>
+#include <async_safe/log.h>
+
#include "private/bionic_prctl.h"
//
@@ -149,7 +151,7 @@
ssize_t offset = reinterpret_cast<uintptr_t>(ptr) - sizeof(page_info);
if (offset % block_size_ != 0) {
- __libc_fatal("invalid pointer: %p (block_size=%zd)", ptr, block_size_);
+ async_safe_fatal("invalid pointer: %p (block_size=%zd)", ptr, block_size_);
}
memset(ptr, 0, block_size_);
@@ -180,7 +182,7 @@
if (it == page_records_.end() || it->page_addr != addr) {
// not found...
- __libc_fatal("page record for %p was not found (block_size=%zd)", ptr, block_size_);
+ async_safe_fatal("page record for %p was not found (block_size=%zd)", ptr, block_size_);
}
return it;
@@ -203,7 +205,7 @@
void* map_ptr = mmap(nullptr, PAGE_SIZE,
PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
if (map_ptr == MAP_FAILED) {
- __libc_fatal("mmap failed");
+ async_safe_fatal("mmap failed");
}
prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, map_ptr, PAGE_SIZE, "linker_alloc_small_objects");
@@ -248,7 +250,7 @@
PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
if (map_ptr == MAP_FAILED) {
- __libc_fatal("mmap failed");
+ async_safe_fatal("mmap failed");
}
prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, map_ptr, allocated_size, "linker_alloc_lob");
@@ -283,7 +285,7 @@
page_info* LinkerMemoryAllocator::get_page_info(void* ptr) {
page_info* info = reinterpret_cast<page_info*>(PAGE_START(reinterpret_cast<size_t>(ptr)));
if (memcmp(info->signature, kSignature, sizeof(kSignature)) != 0) {
- __libc_fatal("invalid pointer %p (page signature mismatch)", ptr);
+ async_safe_fatal("invalid pointer %p (page signature mismatch)", ptr);
}
return info;
@@ -308,7 +310,7 @@
} else {
LinkerSmallObjectAllocator* allocator = get_small_object_allocator(info->type);
if (allocator != info->allocator_addr) {
- __libc_fatal("invalid pointer %p (page signature mismatch)", ptr);
+ async_safe_fatal("invalid pointer %p (page signature mismatch)", ptr);
}
old_size = allocator->get_block_size();
@@ -336,7 +338,7 @@
} else {
LinkerSmallObjectAllocator* allocator = get_small_object_allocator(info->type);
if (allocator != info->allocator_addr) {
- __libc_fatal("invalid pointer %p (invalid allocator address for the page)", ptr);
+ async_safe_fatal("invalid pointer %p (invalid allocator address for the page)", ptr);
}
allocator->free(ptr);
@@ -345,7 +347,7 @@
LinkerSmallObjectAllocator* LinkerMemoryAllocator::get_small_object_allocator(uint32_t type) {
if (type < kSmallObjectMinSizeLog2 || type > kSmallObjectMaxSizeLog2) {
- __libc_fatal("invalid type: %u", type);
+ async_safe_fatal("invalid type: %u", type);
}
initialize_allocators();