From 8f2a5a0b40fc82126c691d5c30131d908772aab7 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 15 Mar 2013 15:30:25 -0700 Subject: [PATCH] Clean up internal libc logging. We only need one logging API, and I prefer the one that does no allocation and is thus safe to use in any context. Also use O_CLOEXEC when opening the /dev/log files. Move everything logging-related into one header file. Change-Id: Ic1e3ea8e9b910dc29df351bff6c0aa4db26fbb58 --- libc/Android.mk | 3 +- libc/arch-arm/bionic/atexit_legacy.c | 4 +- libc/arch-mips/bionic/cacheflush.c | 3 +- libc/bionic/__fgets_chk.cpp | 2 +- libc/bionic/__memcpy_chk.cpp | 2 +- libc/bionic/__memmove_chk.cpp | 2 +- libc/bionic/__memset_chk.cpp | 2 +- libc/bionic/__stack_chk_fail.cpp | 3 +- libc/bionic/__strcat_chk.cpp | 2 +- libc/bionic/__strcpy_chk.cpp | 2 +- libc/bionic/__strlcat_chk.cpp | 2 +- libc/bionic/__strlcpy_chk.cpp | 2 +- libc/bionic/__strlen_chk.cpp | 2 +- libc/bionic/__strncat_chk.cpp | 2 +- libc/bionic/__strncpy_chk.cpp | 2 +- libc/bionic/__umask_chk.cpp | 2 +- libc/bionic/__vsnprintf_chk.cpp | 2 +- libc/bionic/__vsprintf_chk.cpp | 2 +- libc/bionic/assert.cpp | 3 +- libc/bionic/debug_stacktrace.cpp | 3 +- libc/bionic/dlmalloc.c | 3 +- libc/bionic/{debug_format.cpp => libc_logging.cpp} | 76 ++++-- libc/bionic/logd_write.c | 255 --------------------- libc/bionic/malloc_debug_check.cpp | 2 +- libc/bionic/malloc_debug_common.cpp | 2 +- libc/bionic/malloc_debug_common.h | 2 +- libc/bionic/malloc_debug_leak.cpp | 2 +- libc/bionic/malloc_debug_qemu.cpp | 2 +- libc/bionic/open.c | 3 +- libc/bionic/openat.c | 3 +- libc/bionic/pthread_create.cpp | 3 +- libc/bionic/pthread_debug.cpp | 4 +- libc/bionic/stubs.cpp | 3 +- libc/netbsd/resolv/res_cache.c | 11 +- libc/netbsd/resolv/res_send.c | 32 ++- libc/netbsd/resolv/res_state.c | 4 +- libc/private/arpa_nameser.h | 5 +- libc/private/{debug_format.h => libc_logging.h} | 49 +++- libc/private/logd.h | 80 ------- libc/string/strchr.c | 2 +- libc/string/strrchr.c | 2 +- libstdc++/src/pure_virtual.cpp | 2 +- linker/debugger.cpp | 15 +- linker/linker.cpp | 13 +- linker/linker.h | 2 +- linker/linker_debug.h | 2 +- tests/Android.mk | 2 +- ...debug_format_test.cpp => libc_logging_test.cpp} | 16 +- 48 files changed, 187 insertions(+), 457 deletions(-) rename libc/bionic/{debug_format.cpp => libc_logging.cpp} (85%) delete mode 100644 libc/bionic/logd_write.c rename libc/private/{debug_format.h => libc_logging.h} (64%) delete mode 100644 libc/private/logd.h rename tests/{debug_format_test.cpp => libc_logging_test.cpp} (93%) diff --git a/libc/Android.mk b/libc/Android.mk index 98399d59b..b4613bae3 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -149,7 +149,6 @@ libc_common_src_files := \ bionic/isatty.c \ bionic/issetugid.c \ bionic/ldexp.c \ - bionic/logd_write.c \ bionic/lseek64.c \ bionic/md5.c \ bionic/memchr.c \ @@ -238,7 +237,6 @@ libc_common_src_files := \ libc_bionic_src_files := \ bionic/assert.cpp \ bionic/brk.cpp \ - bionic/debug_format.cpp \ bionic/dirent.cpp \ bionic/__errno.c \ bionic/eventfd.cpp \ @@ -246,6 +244,7 @@ libc_bionic_src_files := \ bionic/getauxval.cpp \ bionic/getcwd.cpp \ bionic/libc_init_common.cpp \ + bionic/libc_logging.cpp \ bionic/libgen.cpp \ bionic/__memcpy_chk.cpp \ bionic/__memmove_chk.cpp \ diff --git a/libc/arch-arm/bionic/atexit_legacy.c b/libc/arch-arm/bionic/atexit_legacy.c index 6e299ac08..f35c68d11 100644 --- a/libc/arch-arm/bionic/atexit_legacy.c +++ b/libc/arch-arm/bionic/atexit_legacy.c @@ -27,7 +27,7 @@ */ #include -#include +#include #include /* @@ -52,7 +52,7 @@ atexit(void (*func)(void)) */ static char const warning[] = "WARNING: generic atexit() called from legacy shared library\n"; - __libc_android_log_write(ANDROID_LOG_WARN, "libc", warning); + __libc_format_log(ANDROID_LOG_WARN, "libc", warning); fprintf(stderr, warning); return (__cxa_atexit((void (*)(void *))func, NULL, NULL)); diff --git a/libc/arch-mips/bionic/cacheflush.c b/libc/arch-mips/bionic/cacheflush.c index 19116877e..97e67d4d2 100644 --- a/libc/arch-mips/bionic/cacheflush.c +++ b/libc/arch-mips/bionic/cacheflush.c @@ -29,8 +29,7 @@ #include #ifdef DEBUG -#include -#include +#include #define XLOG(...) __libc_format_log(ANDROID_LOG_DEBUG,"libc-cacheflush",__VA_ARGS__) #endif diff --git a/libc/bionic/__fgets_chk.cpp b/libc/bionic/__fgets_chk.cpp index 6ae97ccc0..429eda515 100644 --- a/libc/bionic/__fgets_chk.cpp +++ b/libc/bionic/__fgets_chk.cpp @@ -28,7 +28,7 @@ #include #include -#include +#include "libc_logging.h" /* * __fgets_chk. Called in place of fgets() when we know the diff --git a/libc/bionic/__memcpy_chk.cpp b/libc/bionic/__memcpy_chk.cpp index 7a98cb716..b36cfdda5 100644 --- a/libc/bionic/__memcpy_chk.cpp +++ b/libc/bionic/__memcpy_chk.cpp @@ -29,7 +29,7 @@ #undef _FORTIFY_SOURCE #include #include -#include +#include "libc_logging.h" /* * Runtime implementation of __memcpy_chk. diff --git a/libc/bionic/__memmove_chk.cpp b/libc/bionic/__memmove_chk.cpp index 51f2e1cca..ff770b5aa 100644 --- a/libc/bionic/__memmove_chk.cpp +++ b/libc/bionic/__memmove_chk.cpp @@ -28,7 +28,7 @@ #include #include -#include +#include "libc_logging.h" /* * Runtime implementation of __builtin____memmove_chk. diff --git a/libc/bionic/__memset_chk.cpp b/libc/bionic/__memset_chk.cpp index 99a12ad09..b201ed2ea 100644 --- a/libc/bionic/__memset_chk.cpp +++ b/libc/bionic/__memset_chk.cpp @@ -28,7 +28,7 @@ #include #include -#include +#include "libc_logging.h" /* * Runtime implementation of __builtin____memset_chk. diff --git a/libc/bionic/__stack_chk_fail.cpp b/libc/bionic/__stack_chk_fail.cpp index cae66b10a..d5031ac7b 100644 --- a/libc/bionic/__stack_chk_fail.cpp +++ b/libc/bionic/__stack_chk_fail.cpp @@ -29,8 +29,7 @@ #include #include "bionic_ssp.h" -#include "debug_format.h" -#include "logd.h" +#include "libc_logging.h" void __stack_chk_fail() { __libc_format_log(ANDROID_LOG_FATAL, "libc", "stack corruption detected"); diff --git a/libc/bionic/__strcat_chk.cpp b/libc/bionic/__strcat_chk.cpp index 2450da6cc..fb46e0d7d 100644 --- a/libc/bionic/__strcat_chk.cpp +++ b/libc/bionic/__strcat_chk.cpp @@ -28,7 +28,7 @@ #include #include -#include +#include "libc_logging.h" #include /* diff --git a/libc/bionic/__strcpy_chk.cpp b/libc/bionic/__strcpy_chk.cpp index 74ceda1bc..bfb664235 100644 --- a/libc/bionic/__strcpy_chk.cpp +++ b/libc/bionic/__strcpy_chk.cpp @@ -28,7 +28,7 @@ #include #include -#include +#include "libc_logging.h" /* * Runtime implementation of __builtin____strcpy_chk. diff --git a/libc/bionic/__strlcat_chk.cpp b/libc/bionic/__strlcat_chk.cpp index 12676f4f0..96f62f9aa 100644 --- a/libc/bionic/__strlcat_chk.cpp +++ b/libc/bionic/__strlcat_chk.cpp @@ -28,7 +28,7 @@ #include #include -#include +#include "libc_logging.h" /* * __strlcat_chk. Called in place of strlcat() when we know the diff --git a/libc/bionic/__strlcpy_chk.cpp b/libc/bionic/__strlcpy_chk.cpp index 62fa14bc5..636966b5f 100644 --- a/libc/bionic/__strlcpy_chk.cpp +++ b/libc/bionic/__strlcpy_chk.cpp @@ -28,7 +28,7 @@ #include #include -#include +#include "libc_logging.h" /* * __strlcpy_chk. Called in place of strlcpy() when we know the diff --git a/libc/bionic/__strlen_chk.cpp b/libc/bionic/__strlen_chk.cpp index 5cc052e56..6ebf09c6f 100644 --- a/libc/bionic/__strlen_chk.cpp +++ b/libc/bionic/__strlen_chk.cpp @@ -28,7 +28,7 @@ #include #include -#include +#include "libc_logging.h" /* * Runtime implementation of __strlen_chk. diff --git a/libc/bionic/__strncat_chk.cpp b/libc/bionic/__strncat_chk.cpp index 32a3962ff..ab2854175 100644 --- a/libc/bionic/__strncat_chk.cpp +++ b/libc/bionic/__strncat_chk.cpp @@ -28,7 +28,7 @@ #include #include -#include +#include "libc_logging.h" #include /* diff --git a/libc/bionic/__strncpy_chk.cpp b/libc/bionic/__strncpy_chk.cpp index c9676ed85..0f1797e2a 100644 --- a/libc/bionic/__strncpy_chk.cpp +++ b/libc/bionic/__strncpy_chk.cpp @@ -28,7 +28,7 @@ #include #include -#include +#include "libc_logging.h" /* * Runtime implementation of __builtin____strncpy_chk. diff --git a/libc/bionic/__umask_chk.cpp b/libc/bionic/__umask_chk.cpp index e1bc96d28..ff67ed69d 100644 --- a/libc/bionic/__umask_chk.cpp +++ b/libc/bionic/__umask_chk.cpp @@ -30,7 +30,7 @@ #include #include -#include +#include "libc_logging.h" #include /* diff --git a/libc/bionic/__vsnprintf_chk.cpp b/libc/bionic/__vsnprintf_chk.cpp index 95d491569..0fdda3ece 100644 --- a/libc/bionic/__vsnprintf_chk.cpp +++ b/libc/bionic/__vsnprintf_chk.cpp @@ -29,7 +29,7 @@ #include #include #include -#include +#include "libc_logging.h" /* * Runtime implementation of __builtin____vsnprintf_chk. diff --git a/libc/bionic/__vsprintf_chk.cpp b/libc/bionic/__vsprintf_chk.cpp index e1d10f55a..12b0ca6ab 100644 --- a/libc/bionic/__vsprintf_chk.cpp +++ b/libc/bionic/__vsprintf_chk.cpp @@ -29,7 +29,7 @@ #include #include #include -#include +#include "libc_logging.h" /* * Runtime implementation of __builtin____vsprintf_chk. diff --git a/libc/bionic/assert.cpp b/libc/bionic/assert.cpp index e38c16dbc..6f221a56a 100644 --- a/libc/bionic/assert.cpp +++ b/libc/bionic/assert.cpp @@ -32,8 +32,7 @@ #include #include #include -#include -#include +#include "libc_logging.h" // We log to stderr for the benefit of "adb shell" users, and the log for the benefit // of regular app developers who want to see their asserts. diff --git a/libc/bionic/debug_stacktrace.cpp b/libc/bionic/debug_stacktrace.cpp index 9d53ad2b3..87dbba3d9 100644 --- a/libc/bionic/debug_stacktrace.cpp +++ b/libc/bionic/debug_stacktrace.cpp @@ -33,9 +33,8 @@ #include #include -#include "debug_format.h" #include "debug_mapinfo.h" -#include "logd.h" +#include "libc_logging.h" /* depends how the system includes define this */ #ifdef HAVE_UNWIND_CONTEXT_STRUCT diff --git a/libc/bionic/dlmalloc.c b/libc/bionic/dlmalloc.c index 1ed3205a0..7d4ef0f71 100644 --- a/libc/bionic/dlmalloc.c +++ b/libc/bionic/dlmalloc.c @@ -24,8 +24,7 @@ #include -#include -#include +#include // Send dlmalloc errors to the log. static void __bionic_heap_corruption_error(const char* function); diff --git a/libc/bionic/debug_format.cpp b/libc/bionic/libc_logging.cpp similarity index 85% rename from libc/bionic/debug_format.cpp rename to libc/bionic/libc_logging.cpp index 793f8b19f..755dc8111 100644 --- a/libc/bionic/debug_format.cpp +++ b/libc/bionic/libc_logging.cpp @@ -26,13 +26,15 @@ * SUCH DAMAGE. */ -#include <../private/debug_format.h> // Relative path so we can #include this for testing. +#include <../private/libc_logging.h> // Relative path so we can #include this .cpp file for testing. +#include <../private/ScopedPthreadMutexLocker.h> #include #include +#include #include #include -#include +#include #include #include @@ -218,29 +220,30 @@ int __libc_format_fd(int fd, const char* format, ...) { #include #include +static pthread_mutex_t gLogInitializationLock = PTHREAD_MUTEX_INITIALIZER; + int __libc_format_log_va_list(int priority, const char* tag, const char* fmt, va_list args) { char buf[1024]; - int result = vformat_buffer(buf, sizeof buf, fmt, args); - - static int log_fd = -1; - if (log_fd == -1) { - log_fd = open("/dev/log/main", O_WRONLY); - if (log_fd == -1) { - return result; + int buf_strlen = vformat_buffer(buf, sizeof(buf), fmt, args); + + static int main_log_fd = -1; + if (main_log_fd == -1) { + ScopedPthreadMutexLocker locker(&gLogInitializationLock); + main_log_fd = TEMP_FAILURE_RETRY(open("/dev/log/main", O_CLOEXEC | O_WRONLY)); + if (main_log_fd == -1) { + return -1; } } struct iovec vec[3]; - vec[0].iov_base = (unsigned char *) &priority; + vec[0].iov_base = &priority; vec[0].iov_len = 1; - vec[1].iov_base = (void *) tag; + vec[1].iov_base = const_cast(tag); vec[1].iov_len = strlen(tag) + 1; - vec[2].iov_base = (void *) buf; - vec[2].iov_len = strlen(buf) + 1; - - TEMP_FAILURE_RETRY(writev(log_fd, vec, 3)); + vec[2].iov_base = const_cast(buf); + vec[2].iov_len = buf_strlen + 1; - return result; + return TEMP_FAILURE_RETRY(writev(main_log_fd, vec, 3)); } int __libc_format_log(int priority, const char* tag, const char* format, ...) { @@ -516,3 +519,44 @@ out_vformat(Out *o, const char *format, va_list args) } } } + +// must be kept in sync with frameworks/base/core/java/android/util/EventLog.java +enum AndroidEventLogType { + EVENT_TYPE_INT = 0, + EVENT_TYPE_LONG = 1, + EVENT_TYPE_STRING = 2, + EVENT_TYPE_LIST = 3, +}; + +static int __libc_android_log_event(int32_t tag, char type, const void* payload, size_t len) { + struct iovec vec[3]; + vec[0].iov_base = &tag; + vec[0].iov_len = sizeof(tag); + vec[1].iov_base = &type; + vec[1].iov_len = sizeof(type); + vec[2].iov_base = const_cast(payload); + vec[2].iov_len = len; + + static int event_log_fd = -1; + if (event_log_fd == -1) { + ScopedPthreadMutexLocker locker(&gLogInitializationLock); + event_log_fd = TEMP_FAILURE_RETRY(open("/dev/log/events", O_CLOEXEC | O_WRONLY)); + } + return TEMP_FAILURE_RETRY(writev(event_log_fd, vec, 3)); +} + +void __libc_android_log_event_int(int32_t tag, int value) { + __libc_android_log_event(tag, EVENT_TYPE_INT, &value, sizeof(value)); +} + +void __libc_android_log_event_uid(int32_t tag) { + __libc_android_log_event_int(tag, getuid()); +} + +void __fortify_chk_fail(const char *msg, uint32_t tag) { + __libc_format_log(ANDROID_LOG_FATAL, "libc", "FORTIFY_SOURCE: %s. Calling abort().\n", msg); + if (tag != 0) { + __libc_android_log_event_uid(tag); + } + abort(); +} diff --git a/libc/bionic/logd_write.c b/libc/bionic/logd_write.c deleted file mode 100644 index 03ac6063d..000000000 --- a/libc/bionic/logd_write.c +++ /dev/null @@ -1,255 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "logd.h" - -/* should match system/core/include/cutils/logger.h */ -#define LOGGER_LOG_MAIN "log/main" -#define LOGGER_LOG_RADIO "log/radio" -#define LOGGER_LOG_EVENTS "log/events" -#define LOGGER_LOG_SYSTEM "log/system" - -#include - -/* IMPORTANT IMPORTANT IMPORTANT: TECHNICAL NOTE - * - * Some of the functions below can be called when our malloc() implementation - * has detected that the heap is corrupted, or even from a signal handler. - * - * These functions should *not* use a function that allocates heap memory - * or is not signal-safe. Using direct system calls is acceptable, and we - * also assume that pthread_mutex_lock/unlock can be used too. - */ - -#define LOG_BUF_SIZE 1024 - -typedef enum { - LOG_ID_NONE = 0, - LOG_ID_MAIN, - LOG_ID_RADIO, - LOG_ID_EVENTS, - LOG_ID_MAX -} log_id_t; - -/* logger handles writing to object, pointed by log channel id */ -typedef int (*logger_function_t)(log_id_t log_id, struct iovec *vec); - -typedef struct { - logger_function_t logger; - int fd; - const char *path; -} log_channel_t; - -static int __write_to_log_init(log_id_t log_id, struct iovec *vec); -static int __write_to_log_null(log_id_t log_id, struct iovec *vec); - -static pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER; - -static log_channel_t log_channels[LOG_ID_MAX] = { - { __write_to_log_null, -1, NULL }, - { __write_to_log_init, -1, "/dev/"LOGGER_LOG_MAIN }, - { __write_to_log_init, -1, "/dev/"LOGGER_LOG_RADIO }, - { __write_to_log_init, -1, "/dev/"LOGGER_LOG_EVENTS } -}; - -/* Important: see technical note at start of source file */ -static int __write_to_log_null(log_id_t log_id, struct iovec *vec) -{ - /* - * ALTERED behaviour from previous version - * always returns successful result - */ - int i = 0; - size_t res = 0; - - for ( ; i < 3; ++i) { - res += vec[i].iov_len; - } - - return (int)res; -} - -/* - * it's supposed, that log_id contains valid id always. - * this check must be performed in higher level functions - */ -/* Important: see technical note at start of source file */ -static int __write_to_log_kernel(log_id_t log_id, struct iovec *vec) -{ - return TEMP_FAILURE_RETRY( writev(log_channels[log_id].fd, vec, 3) ); -} - -/* Important: see technical note at start of source file */ -static int __write_to_log_init(log_id_t log_id, struct iovec *vec) -{ - if ((LOG_ID_NONE < log_id) && (log_id < LOG_ID_MAX)) { - int fd; - - pthread_mutex_lock(&log_init_lock); - - fd = TEMP_FAILURE_RETRY(open(log_channels[log_id].path, O_WRONLY)); - - log_channels[log_id].logger = - (fd < 0) ? __write_to_log_null : __write_to_log_kernel; - log_channels[log_id].fd = fd; - - log_channels[log_id].fd = fd; - - pthread_mutex_unlock(&log_init_lock); - - return log_channels[log_id].logger(log_id, vec); - } - - /* log_id is invalid */ - return -1; -} - -/* Important: see technical note at start of source file */ -__LIBC_HIDDEN__ -int __libc_android_log_write(int prio, const char *tag, const char *msg) -{ - struct iovec vec[3]; - log_id_t log_id = LOG_ID_MAIN; - - if (tag == NULL) - tag = ""; - - vec[0].iov_base = (unsigned char *) &prio; - vec[0].iov_len = 1; - vec[1].iov_base = (void *) tag; - vec[1].iov_len = strlen(tag) + 1; - vec[2].iov_base = (void *) msg; - vec[2].iov_len = strlen(msg) + 1; - - return log_channels[log_id].logger(log_id, vec); -} - -/* The functions below are not designed to be called from a heap panic - * function or from a signal handler. As such, they are free to use complex - * C library functions like vsnprintf() - */ -__LIBC_HIDDEN__ -int __libc_android_log_vprint(int prio, const char *tag, const char *fmt, - va_list ap) -{ - char buf[LOG_BUF_SIZE]; - - vsnprintf(buf, LOG_BUF_SIZE, fmt, ap); - - return __libc_android_log_write(prio, tag, buf); -} - -__LIBC_HIDDEN__ -int __libc_android_log_print(int prio, const char *tag, const char *fmt, ...) -{ - va_list ap; - char buf[LOG_BUF_SIZE]; - - va_start(ap, fmt); - vsnprintf(buf, LOG_BUF_SIZE, fmt, ap); - va_end(ap); - - return __libc_android_log_write(prio, tag, buf); -} - -__LIBC_HIDDEN__ -int __libc_android_log_assert(const char *cond, const char *tag, - const char *fmt, ...) -{ - va_list ap; - char buf[LOG_BUF_SIZE]; - - va_start(ap, fmt); - vsnprintf(buf, LOG_BUF_SIZE, fmt, ap); - va_end(ap); - - __libc_android_log_write(ANDROID_LOG_FATAL, tag, buf); - - exit(1); - - return -1; -} - -/* - * Event logging. - */ - -// must be kept in sync with frameworks/base/core/java/android/util/EventLog.java -typedef enum { - EVENT_TYPE_INT = 0, - EVENT_TYPE_LONG = 1, - EVENT_TYPE_STRING = 2, - EVENT_TYPE_LIST = 3, -} AndroidEventLogType; - -static int __libc_android_log_btwrite(int32_t tag, char type, const void *payload, size_t len) -{ - struct iovec vec[3]; - - vec[0].iov_base = &tag; - vec[0].iov_len = sizeof(tag); - vec[1].iov_base = &type; - vec[1].iov_len = sizeof(type); - vec[2].iov_base = (void*)payload; - vec[2].iov_len = len; - - return log_channels[LOG_ID_EVENTS].logger(LOG_ID_EVENTS, vec); -} - -__LIBC_HIDDEN__ -void __libc_android_log_event_int(int32_t tag, int value) -{ - __libc_android_log_btwrite(tag, EVENT_TYPE_INT, &value, sizeof(value)); -} - -__LIBC_HIDDEN__ -void __libc_android_log_event_uid(int32_t tag) -{ - __libc_android_log_event_int(tag, getuid()); -} - -__LIBC_HIDDEN__ -void __fortify_chk_fail(const char *msg, uint32_t tag) { - __libc_format_log(ANDROID_LOG_FATAL, "libc", "FORTIFY_SOURCE: %s. Calling abort().\n", msg); - if (tag != 0) { - __libc_android_log_event_uid(tag); - } - abort(); -} diff --git a/libc/bionic/malloc_debug_check.cpp b/libc/bionic/malloc_debug_check.cpp index 2ae98b6c0..91cf28799 100644 --- a/libc/bionic/malloc_debug_check.cpp +++ b/libc/bionic/malloc_debug_check.cpp @@ -48,7 +48,7 @@ #include "debug_mapinfo.h" #include "debug_stacktrace.h" #include "dlmalloc.h" -#include "logd.h" +#include "libc_logging.h" #include "malloc_debug_common.h" #include "ScopedPthreadMutexLocker.h" diff --git a/libc/bionic/malloc_debug_common.cpp b/libc/bionic/malloc_debug_common.cpp index a05a5ef40..2148d202f 100644 --- a/libc/bionic/malloc_debug_common.cpp +++ b/libc/bionic/malloc_debug_common.cpp @@ -249,7 +249,7 @@ extern "C" void* memalign(size_t alignment, size_t bytes) { #include #include #include -#include "logd.h" +#include "libc_logging.h" /* Table for dispatching malloc calls, depending on environment. */ static MallocDebug gMallocUse __attribute__((aligned(32))) = { diff --git a/libc/bionic/malloc_debug_common.h b/libc/bionic/malloc_debug_common.h index e15ccd038..12d0e65e2 100644 --- a/libc/bionic/malloc_debug_common.h +++ b/libc/bionic/malloc_debug_common.h @@ -35,7 +35,7 @@ #include -#include +#include "libc_logging.h" #define HASHTABLE_SIZE 1543 #define BACKTRACE_SIZE 32 diff --git a/libc/bionic/malloc_debug_leak.cpp b/libc/bionic/malloc_debug_leak.cpp index 9e63a863f..2db8a1f62 100644 --- a/libc/bionic/malloc_debug_leak.cpp +++ b/libc/bionic/malloc_debug_leak.cpp @@ -47,7 +47,7 @@ #include "debug_stacktrace.h" #include "dlmalloc.h" -#include "logd.h" +#include "libc_logging.h" #include "malloc_debug_common.h" #include "ScopedPthreadMutexLocker.h" diff --git a/libc/bionic/malloc_debug_qemu.cpp b/libc/bionic/malloc_debug_qemu.cpp index 812a45120..08225c1e1 100644 --- a/libc/bionic/malloc_debug_qemu.cpp +++ b/libc/bionic/malloc_debug_qemu.cpp @@ -51,7 +51,7 @@ #include #include #include "dlmalloc.h" -#include "logd.h" +#include "libc_logging.h" #include "malloc_debug_common.h" /* This file should be included into the build only when diff --git a/libc/bionic/open.c b/libc/bionic/open.c index be4f04b58..e3573a3ca 100644 --- a/libc/bionic/open.c +++ b/libc/bionic/open.c @@ -29,7 +29,7 @@ #include #include #include -#include +#include "libc_logging.h" extern int __open(const char*, int, int); @@ -60,4 +60,3 @@ int __open_2(const char *pathname, int flags) { return __open(pathname, flags, 0); } - diff --git a/libc/bionic/openat.c b/libc/bionic/openat.c index c1abbaa1b..2d09d17fc 100644 --- a/libc/bionic/openat.c +++ b/libc/bionic/openat.c @@ -29,7 +29,7 @@ #include #include #include -#include +#include "libc_logging.h" extern int __openat(int, const char*, int, int); @@ -61,4 +61,3 @@ int __openat_2(int fd, const char *pathname, int flags) return __openat(fd, pathname, flags, 0); } - diff --git a/libc/bionic/pthread_create.cpp b/libc/bionic/pthread_create.cpp index 368c46de2..15f18aa2f 100644 --- a/libc/bionic/pthread_create.cpp +++ b/libc/bionic/pthread_create.cpp @@ -35,8 +35,7 @@ #include "private/bionic_ssp.h" #include "private/bionic_tls.h" -#include "private/debug_format.h" -#include "private/logd.h" +#include "private/libc_logging.h" #include "private/thread_private.h" #include "private/ErrnoRestorer.h" #include "private/ScopedPthreadMutexLocker.h" diff --git a/libc/bionic/pthread_debug.cpp b/libc/bionic/pthread_debug.cpp index f8f0c5953..94c23de35 100644 --- a/libc/bionic/pthread_debug.cpp +++ b/libc/bionic/pthread_debug.cpp @@ -43,9 +43,7 @@ #include "bionic_tls.h" #include "debug_mapinfo.h" #include "debug_stacktrace.h" -#include "logd.h" - -#include +#include "libc_logging.h" /* * =========================================================================== diff --git a/libc/bionic/stubs.cpp b/libc/bionic/stubs.cpp index 8ddc326e0..e8411b774 100644 --- a/libc/bionic/stubs.cpp +++ b/libc/bionic/stubs.cpp @@ -38,9 +38,8 @@ #include #include "private/android_filesystem_config.h" -#include "private/debug_format.h" #include "private/ErrnoRestorer.h" -#include "private/logd.h" +#include "private/libc_logging.h" // Thread-specific state for the non-reentrant functions. static pthread_once_t stubs_once = PTHREAD_ONCE_INIT; diff --git a/libc/netbsd/resolv/res_cache.c b/libc/netbsd/resolv/res_cache.c index 838e084e2..a2bc7ca44 100644 --- a/libc/netbsd/resolv/res_cache.c +++ b/libc/netbsd/resolv/res_cache.c @@ -170,9 +170,8 @@ #undef XLOG #if DEBUG -# include -# define XLOG(...) \ - __libc_android_log_print(ANDROID_LOG_DEBUG,"libc",__VA_ARGS__) +# include "libc_logging.h" +# define XLOG(...) __libc_format_log(ANDROID_LOG_DEBUG,"libc",__VA_ARGS__) #include #include @@ -708,9 +707,9 @@ static char* _dnsPacket_bprintQR(DnsPacket* packet, char* p, char* end) { #define QQ(x) { DNS_TYPE_##x, #x } - static const struct { + static const struct { const char* typeBytes; - const char* typeString; + const char* typeString; } qTypes[] = { QQ(A), QQ(PTR), QQ(MX), QQ(AAAA), QQ(ALL), @@ -1487,7 +1486,7 @@ _cache_lookup_p( Cache* cache, pnode = &node->hlink; } - return pnode; + return pnode; } /* Add a new entry to the hash table. 'lookup' must be the diff --git a/libc/netbsd/resolv/res_send.c b/libc/netbsd/resolv/res_send.c index f3ee53979..c6c863bfa 100644 --- a/libc/netbsd/resolv/res_send.c +++ b/libc/netbsd/resolv/res_send.c @@ -119,7 +119,7 @@ __RCSID("$NetBSD: res_send.c,v 1.9 2006/01/24 17:41:25 christos Exp $"); # include #endif -#include "logd.h" +#include "libc_logging.h" #ifndef DE_CONST #define DE_CONST(c,v) v = ((c) ? \ @@ -542,7 +542,7 @@ res_nsend(res_state statp, ns); if (DBG) { - __libc_android_log_print(ANDROID_LOG_DEBUG, "libc", + __libc_format_log(ANDROID_LOG_DEBUG, "libc", "used send_vc %d\n", n); } @@ -554,15 +554,13 @@ res_nsend(res_state statp, } else { /* Use datagrams. */ if (DBG) { - __libc_android_log_print(ANDROID_LOG_DEBUG, "libc", - "using send_dg\n"); + __libc_format_log(ANDROID_LOG_DEBUG, "libc", "using send_dg\n"); } n = send_dg(statp, buf, buflen, ans, anssiz, &terrno, ns, &v_circuit, &gotsomewhere); if (DBG) { - __libc_android_log_print(ANDROID_LOG_DEBUG, "libc", - "used send_dg %d\n",n); + __libc_format_log(ANDROID_LOG_DEBUG, "libc", "used send_dg %d\n",n); } if (n < 0) @@ -570,7 +568,7 @@ res_nsend(res_state statp, if (n == 0) goto next_ns; if (DBG) { - __libc_android_log_print(ANDROID_LOG_DEBUG, "libc", + __libc_format_log(ANDROID_LOG_DEBUG, "libc", "time=%d, %d\n",time(NULL), time(NULL)%2); } if (v_circuit) @@ -715,8 +713,7 @@ static int get_timeout(const res_state statp, const int ns) timeout = 1; } if (DBG) { - __libc_android_log_print(ANDROID_LOG_DEBUG, "libc", - "using timeout of %d sec\n", timeout); + __libc_format_log(ANDROID_LOG_DEBUG, "libc", "using timeout of %d sec\n", timeout); } return timeout; @@ -738,7 +735,7 @@ send_vc(res_state statp, void *tmp; if (DBG) { - __libc_android_log_print(ANDROID_LOG_DEBUG, "libc", "using send_vc\n"); + __libc_format_log(ANDROID_LOG_DEBUG, "libc", "using send_vc\n"); } nsap = get_nsaddr(statp, (size_t)ns); @@ -939,8 +936,7 @@ connect_with_timeout(int sock, const struct sockaddr *nsap, socklen_t salen, int timeout = evConsTime((long)sec, 0L); finish = evAddTime(now, timeout); if (DBG) { - __libc_android_log_print(ANDROID_LOG_DEBUG, "libc", - " %d send_vc\n", sock); + __libc_format_log(ANDROID_LOG_DEBUG, "libc", " %d send_vc\n", sock); } res = retrying_select(sock, &rset, &wset, &finish); @@ -951,7 +947,7 @@ connect_with_timeout(int sock, const struct sockaddr *nsap, socklen_t salen, int done: fcntl(sock, F_SETFL, origflags); if (DBG) { - __libc_android_log_print(ANDROID_LOG_DEBUG, "libc", + __libc_format_log(ANDROID_LOG_DEBUG, "libc", " %d connect_with_timeout returning %s\n", sock, res); } return res; @@ -967,7 +963,7 @@ retrying_select(const int sock, fd_set *readset, fd_set *writeset, const struct retry: if (DBG) { - __libc_android_log_print(ANDROID_LOG_DEBUG, "libc", " %d retying_select\n", sock); + __libc_format_log(ANDROID_LOG_DEBUG, "libc", " %d retying_select\n", sock); } now = evNowTime(); @@ -987,7 +983,7 @@ retry: n = pselect(sock + 1, readset, writeset, NULL, &timeout, NULL); if (n == 0) { if (DBG) { - __libc_android_log_print(ANDROID_LOG_DEBUG, " libc", + __libc_format_log(ANDROID_LOG_DEBUG, " libc", " %d retrying_select timeout\n", sock); } errno = ETIMEDOUT; @@ -997,7 +993,7 @@ retry: if (errno == EINTR) goto retry; if (DBG) { - __libc_android_log_print(ANDROID_LOG_DEBUG, "libc", + __libc_format_log(ANDROID_LOG_DEBUG, "libc", " %d retrying_select got error %d\n",sock, n); } return n; @@ -1007,7 +1003,7 @@ retry: if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &error, &len) < 0 || error) { errno = error; if (DBG) { - __libc_android_log_print(ANDROID_LOG_DEBUG, "libc", + __libc_format_log(ANDROID_LOG_DEBUG, "libc", " %d retrying_select dot error2 %d\n", sock, errno); } @@ -1015,7 +1011,7 @@ retry: } } if (DBG) { - __libc_android_log_print(ANDROID_LOG_DEBUG, "libc", + __libc_format_log(ANDROID_LOG_DEBUG, "libc", " %d retrying_select returning %d for %d\n",sock, n); } diff --git a/libc/netbsd/resolv/res_state.c b/libc/netbsd/resolv/res_state.c index e05846a93..3e1f67b82 100644 --- a/libc/netbsd/resolv/res_state.c +++ b/libc/netbsd/resolv/res_state.c @@ -42,9 +42,9 @@ #define DEBUG 0 #if DEBUG -# include +# include "libc_logging.h" # include /* for gettid() */ -# define D(...) __libc_android_log_print(ANDROID_LOG_DEBUG,"libc", __VA_ARGS__) +# define D(...) __libc_format_log(ANDROID_LOG_DEBUG,"libc", __VA_ARGS__) #else # define D(...) do{}while(0) #endif diff --git a/libc/private/arpa_nameser.h b/libc/private/arpa_nameser.h index 438dc0496..81195b526 100644 --- a/libc/private/arpa_nameser.h +++ b/libc/private/arpa_nameser.h @@ -567,9 +567,8 @@ __END_DECLS #endif #if 0 -# include -# define XLOG(...) \ - __libc_android_log_print(ANDROID_LOG_DEBUG,"libc",__VA_ARGS__) +# include "libc_logging.h" +# define XLOG(...) __libc_format_log(ANDROID_LOG_DEBUG,"libc",__VA_ARGS__) #else #define XLOG(...) do {} while (0) #endif diff --git a/libc/private/debug_format.h b/libc/private/libc_logging.h similarity index 64% rename from libc/private/debug_format.h rename to libc/private/libc_logging.h index 0bc114834..4c9dc2190 100644 --- a/libc/private/debug_format.h +++ b/libc/private/libc_logging.h @@ -26,17 +26,51 @@ * SUCH DAMAGE. */ -#ifndef _DEBUG_FORMAT_H -#define _DEBUG_FORMAT_H +#ifndef _LIBC_LOGGING_H +#define _LIBC_LOGGING_H #include #include #include +#include __BEGIN_DECLS +enum { + BIONIC_EVENT_MEMCPY_BUFFER_OVERFLOW = 80100, + BIONIC_EVENT_STRCAT_BUFFER_OVERFLOW = 80105, + BIONIC_EVENT_MEMMOVE_BUFFER_OVERFLOW = 80110, + BIONIC_EVENT_STRNCAT_BUFFER_OVERFLOW = 80115, + BIONIC_EVENT_STRNCPY_BUFFER_OVERFLOW = 80120, + BIONIC_EVENT_MEMSET_BUFFER_OVERFLOW = 80125, + BIONIC_EVENT_STRCPY_BUFFER_OVERFLOW = 80130, + + BIONIC_EVENT_STRCAT_INTEGER_OVERFLOW = 80200, + BIONIC_EVENT_STRNCAT_INTEGER_OVERFLOW = 80205, + + BIONIC_EVENT_RESOLVER_OLD_RESPONSE = 80300, + BIONIC_EVENT_RESOLVER_WRONG_SERVER = 80305, + BIONIC_EVENT_RESOLVER_WRONG_QUERY = 80310, +}; + +enum { + ANDROID_LOG_UNKNOWN = 0, + ANDROID_LOG_DEFAULT, /* only for SetMinPriority() */ + + ANDROID_LOG_VERBOSE, + ANDROID_LOG_DEBUG, + ANDROID_LOG_INFO, + ANDROID_LOG_WARN, + ANDROID_LOG_ERROR, + ANDROID_LOG_FATAL, + + ANDROID_LOG_SILENT, /* only for SetMinPriority(); must be last */ +}; + +// // Formatting routines for the C library's internal debugging. // Unlike the usual alternatives, these don't allocate. +// __LIBC_HIDDEN__ int __libc_format_buffer(char* buffer, size_t buffer_size, const char* format, ...) __attribute__((__format__(printf, 3, 4))); @@ -50,6 +84,15 @@ __LIBC_HIDDEN__ int __libc_format_log(int priority, const char* tag, const char* __LIBC_HIDDEN__ int __libc_format_log_va_list(int priority, const char* tag, const char* format, va_list ap); +// +// Event logging. +// + +__LIBC_HIDDEN__ void __libc_android_log_event_int(int32_t tag, int value); +__LIBC_HIDDEN__ void __libc_android_log_event_uid(int32_t tag); + +__LIBC_HIDDEN__ __noreturn void __fortify_chk_fail(const char* msg, uint32_t event_tag); + __END_DECLS -#endif /* _DEBUG_FORMAT_H */ +#endif diff --git a/libc/private/logd.h b/libc/private/logd.h deleted file mode 100644 index a2828ec09..000000000 --- a/libc/private/logd.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -#ifndef _ANDROID_BIONIC_LOGD_H -#define _ANDROID_BIONIC_LOGD_H - -#include -#include - -#define BIONIC_EVENT_MEMCPY_BUFFER_OVERFLOW 80100 -#define BIONIC_EVENT_STRCAT_BUFFER_OVERFLOW 80105 -#define BIONIC_EVENT_MEMMOVE_BUFFER_OVERFLOW 80110 -#define BIONIC_EVENT_STRNCAT_BUFFER_OVERFLOW 80115 -#define BIONIC_EVENT_STRNCPY_BUFFER_OVERFLOW 80120 -#define BIONIC_EVENT_MEMSET_BUFFER_OVERFLOW 80125 -#define BIONIC_EVENT_STRCPY_BUFFER_OVERFLOW 80130 - -#define BIONIC_EVENT_STRCAT_INTEGER_OVERFLOW 80200 -#define BIONIC_EVENT_STRNCAT_INTEGER_OVERFLOW 80205 - -#define BIONIC_EVENT_RESOLVER_OLD_RESPONSE 80300 -#define BIONIC_EVENT_RESOLVER_WRONG_SERVER 80305 -#define BIONIC_EVENT_RESOLVER_WRONG_QUERY 80310 - -enum { - ANDROID_LOG_UNKNOWN = 0, - ANDROID_LOG_DEFAULT, /* only for SetMinPriority() */ - - ANDROID_LOG_VERBOSE, - ANDROID_LOG_DEBUG, - ANDROID_LOG_INFO, - ANDROID_LOG_WARN, - ANDROID_LOG_ERROR, - ANDROID_LOG_FATAL, - - ANDROID_LOG_SILENT, /* only for SetMinPriority(); must be last */ -}; - -#ifdef __cplusplus -extern "C" { -#endif - -int __libc_android_log_write(int prio, const char* tag, const char* buffer); -int __libc_android_log_print(int prio, const char *tag, const char *fmt, ...); -int __libc_android_log_vprint(int prio, const char *tag, const char *fmt, va_list ap); - -void __libc_android_log_event_int(int32_t tag, int value); -void __libc_android_log_event_uid(int32_t tag); - -__noreturn extern void __fortify_chk_fail(const char *, uint32_t); - -#ifdef __cplusplus -}; -#endif - -#endif /* _ANDROID_BIONIC_LOGD_H */ diff --git a/libc/string/strchr.c b/libc/string/strchr.c index 564ea8051..93cb250b0 100644 --- a/libc/string/strchr.c +++ b/libc/string/strchr.c @@ -29,7 +29,7 @@ */ #include -#include +#include "libc_logging.h" char * __strchr_chk(const char *p, int ch, size_t s_len) diff --git a/libc/string/strrchr.c b/libc/string/strrchr.c index 5d0415e13..14f29c551 100644 --- a/libc/string/strrchr.c +++ b/libc/string/strrchr.c @@ -29,7 +29,7 @@ */ #include -#include +#include "libc_logging.h" char * __strrchr_chk(const char *p, int ch, size_t s_len) diff --git a/libstdc++/src/pure_virtual.cpp b/libstdc++/src/pure_virtual.cpp index affb80fcc..6b5e3287b 100644 --- a/libstdc++/src/pure_virtual.cpp +++ b/libstdc++/src/pure_virtual.cpp @@ -2,7 +2,7 @@ #include extern "C" void __cxa_pure_virtual() { - // We can't call __libc_android_log_write from libstdc++ because it's private, so cheat. + // We can't call __libc_format_log from libstdc++ because it's hidden and in libc, so cheat. assert(!"Pure virtual function called. Are you calling virtual methods from a destructor?"); /* NOTREACHED */ } diff --git a/linker/debugger.cpp b/linker/debugger.cpp index 586cd2f8f..6fddb1c75 100644 --- a/linker/debugger.cpp +++ b/linker/debugger.cpp @@ -37,9 +37,6 @@ #include #include -#include -#include - extern "C" int tgkill(int tgid, int tid, int sig); #define DEBUGGER_SOCKET_NAME "android:debuggerd" @@ -157,15 +154,15 @@ static bool haveSiginfo(int signum) { sigemptyset(&newact.sa_mask); if (sigaction(signum, &newact, &oldact) < 0) { - __libc_android_log_write(ANDROID_LOG_FATAL, "libc", - "Failed testing for SA_SIGINFO"); - return 0; + __libc_format_log(ANDROID_LOG_FATAL, "libc", "Failed testing for SA_SIGINFO: %s", + strerror(errno)); + return 0; } bool ret = (oldact.sa_flags & SA_SIGINFO) != 0; - if (sigaction(signum, &oldact, NULL) < 0) { - __libc_android_log_write(ANDROID_LOG_FATAL, "libc", - "Restore failed in test for SA_SIGINFO"); + if (sigaction(signum, &oldact, NULL) == -1) { + __libc_format_log(ANDROID_LOG_FATAL, "libc", "Restore failed in test for SA_SIGINFO: %s", + strerror(errno)); } return ret; } diff --git a/linker/linker.cpp b/linker/linker.cpp index 2f119e44a..3afd31405 100755 --- a/linker/linker.cpp +++ b/linker/linker.cpp @@ -42,7 +42,6 @@ // Private C library headers. #include #include -#include #include #include "linker.h" @@ -141,13 +140,13 @@ static unsigned bitmask[4096]; // You shouldn't try to call memory-allocating functions in the dynamic linker. // Guard against the most obvious ones. -#define DISALLOW_ALLOCATION(return_type, name, ...) \ - return_type name __VA_ARGS__ \ - { \ +#define DISALLOW_ALLOCATION(return_type, name, ...) \ + return_type name __VA_ARGS__ \ + { \ const char* msg = "ERROR: " #name " called from the dynamic linker!\n"; \ - __libc_android_log_write(ANDROID_LOG_FATAL, "linker", msg); \ - write(2, msg, strlen(msg)); \ - abort(); \ + __libc_format_log(ANDROID_LOG_FATAL, "linker", "%s", msg); \ + write(2, msg, strlen(msg)); \ + abort(); \ } #define UNUSED __attribute__((unused)) DISALLOW_ALLOCATION(void*, malloc, (size_t u UNUSED)); diff --git a/linker/linker.h b/linker/linker.h index d6a4fc502..6196bec02 100644 --- a/linker/linker.h +++ b/linker/linker.h @@ -36,7 +36,7 @@ #include -#include +#include "private/libc_logging.h" #define DL_ERR(fmt, x...) \ do { \ diff --git a/linker/linker_debug.h b/linker/linker_debug.h index 8fc235fbb..7d2485342 100644 --- a/linker/linker_debug.h +++ b/linker/linker_debug.h @@ -58,7 +58,7 @@ /*********************************************************************/ -#include +#include "private/libc_logging.h" __LIBC_HIDDEN__ extern int gLdDebugVerbosity; diff --git a/tests/Android.mk b/tests/Android.mk index 46427ecea..491b13c15 100644 --- a/tests/Android.mk +++ b/tests/Android.mk @@ -57,11 +57,11 @@ test_c_flags = \ -fno-builtin \ test_src_files = \ - debug_format_test.cpp \ dirent_test.cpp \ fenv_test.cpp \ getauxval_test.cpp \ getcwd_test.cpp \ + libc_logging_test.cpp \ libgen_test.cpp \ math_test.cpp \ netdb_test.cpp \ diff --git a/tests/debug_format_test.cpp b/tests/libc_logging_test.cpp similarity index 93% rename from tests/debug_format_test.cpp rename to tests/libc_logging_test.cpp index 8419e4afc..d9c615ef4 100644 --- a/tests/debug_format_test.cpp +++ b/tests/libc_logging_test.cpp @@ -18,11 +18,11 @@ #if defined(__BIONIC__) -#include "../libc/bionic/debug_format.cpp" +#include "../libc/bionic/libc_logging.cpp" extern int __libc_format_buffer(char* buffer, size_t buffer_size, const char* format, ...); -TEST(debug_format, smoke) { +TEST(libc_logging, smoke) { char buf[BUFSIZ]; __libc_format_buffer(buf, sizeof(buf), "a"); @@ -106,37 +106,37 @@ TEST(debug_format, smoke) { EXPECT_STREQ("a68719476736,6,7,8z", buf); } -TEST(debug_format, d_INT_MAX) { +TEST(libc_logging, d_INT_MAX) { char buf[BUFSIZ]; __libc_format_buffer(buf, sizeof(buf), "%d", INT_MAX); EXPECT_STREQ("2147483647", buf); } -TEST(debug_format, d_INT_MIN) { +TEST(libc_logging, d_INT_MIN) { char buf[BUFSIZ]; __libc_format_buffer(buf, sizeof(buf), "%d", INT_MIN); EXPECT_STREQ("-2147483648", buf); } -TEST(debug_format, ld_LONG_MAX) { +TEST(libc_logging, ld_LONG_MAX) { char buf[BUFSIZ]; __libc_format_buffer(buf, sizeof(buf), "%ld", LONG_MAX); EXPECT_STREQ("2147483647", buf); } -TEST(debug_format, ld_LONG_MIN) { +TEST(libc_logging, ld_LONG_MIN) { char buf[BUFSIZ]; __libc_format_buffer(buf, sizeof(buf), "%ld", LONG_MIN); EXPECT_STREQ("-2147483648", buf); } -TEST(debug_format, lld_LLONG_MAX) { +TEST(libc_logging, lld_LLONG_MAX) { char buf[BUFSIZ]; __libc_format_buffer(buf, sizeof(buf), "%lld", LLONG_MAX); EXPECT_STREQ("9223372036854775807", buf); } -TEST(debug_format, lld_LLONG_MIN) { +TEST(libc_logging, lld_LLONG_MIN) { char buf[BUFSIZ]; __libc_format_buffer(buf, sizeof(buf), "%lld", LLONG_MIN); EXPECT_STREQ("-9223372036854775808", buf); -- 2.11.0