am c1416647: Merge "Clean up internal libc logging."
* commit 'c14166477e7fd22693eab194d37624c2f7506ce4':
Clean up internal libc logging.
diff --git a/libc/Android.mk b/libc/Android.mk
index 98399d5..b4613ba 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -149,7 +149,6 @@
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_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 @@
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 6e299ac..f35c68d 100644
--- a/libc/arch-arm/bionic/atexit_legacy.c
+++ b/libc/arch-arm/bionic/atexit_legacy.c
@@ -27,7 +27,7 @@
*/
#include <sys/types.h>
-#include <private/logd.h>
+#include <private/libc_logging.h>
#include <stdio.h>
/*
@@ -52,7 +52,7 @@
*/
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 1911687..97e67d4 100644
--- a/libc/arch-mips/bionic/cacheflush.c
+++ b/libc/arch-mips/bionic/cacheflush.c
@@ -29,8 +29,7 @@
#include <sys/cachectl.h>
#ifdef DEBUG
-#include <private/logd.h>
-#include <private/debug_format.h>
+#include <private/libc_logging.h>
#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 6ae97cc..429eda5 100644
--- a/libc/bionic/__fgets_chk.cpp
+++ b/libc/bionic/__fgets_chk.cpp
@@ -28,7 +28,7 @@
#include <stdio.h>
#include <stdlib.h>
-#include <private/logd.h>
+#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 7a98cb7..b36cfdd 100644
--- a/libc/bionic/__memcpy_chk.cpp
+++ b/libc/bionic/__memcpy_chk.cpp
@@ -29,7 +29,7 @@
#undef _FORTIFY_SOURCE
#include <string.h>
#include <stdlib.h>
-#include <private/logd.h>
+#include "libc_logging.h"
/*
* Runtime implementation of __memcpy_chk.
diff --git a/libc/bionic/__memmove_chk.cpp b/libc/bionic/__memmove_chk.cpp
index 51f2e1c..ff770b5 100644
--- a/libc/bionic/__memmove_chk.cpp
+++ b/libc/bionic/__memmove_chk.cpp
@@ -28,7 +28,7 @@
#include <string.h>
#include <stdlib.h>
-#include <private/logd.h>
+#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 99a12ad..b201ed2 100644
--- a/libc/bionic/__memset_chk.cpp
+++ b/libc/bionic/__memset_chk.cpp
@@ -28,7 +28,7 @@
#include <string.h>
#include <stdlib.h>
-#include <private/logd.h>
+#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 cae66b1..d5031ac 100644
--- a/libc/bionic/__stack_chk_fail.cpp
+++ b/libc/bionic/__stack_chk_fail.cpp
@@ -29,8 +29,7 @@
#include <stdlib.h>
#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 2450da6..fb46e0d 100644
--- a/libc/bionic/__strcat_chk.cpp
+++ b/libc/bionic/__strcat_chk.cpp
@@ -28,7 +28,7 @@
#include <string.h>
#include <stdlib.h>
-#include <private/logd.h>
+#include "libc_logging.h"
#include <safe_iop.h>
/*
diff --git a/libc/bionic/__strcpy_chk.cpp b/libc/bionic/__strcpy_chk.cpp
index 74ceda1..bfb6642 100644
--- a/libc/bionic/__strcpy_chk.cpp
+++ b/libc/bionic/__strcpy_chk.cpp
@@ -28,7 +28,7 @@
#include <string.h>
#include <stdlib.h>
-#include <private/logd.h>
+#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 12676f4..96f62f9 100644
--- a/libc/bionic/__strlcat_chk.cpp
+++ b/libc/bionic/__strlcat_chk.cpp
@@ -28,7 +28,7 @@
#include <string.h>
#include <stdlib.h>
-#include <private/logd.h>
+#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 62fa14b..636966b 100644
--- a/libc/bionic/__strlcpy_chk.cpp
+++ b/libc/bionic/__strlcpy_chk.cpp
@@ -28,7 +28,7 @@
#include <string.h>
#include <stdlib.h>
-#include <private/logd.h>
+#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 5cc052e..6ebf09c 100644
--- a/libc/bionic/__strlen_chk.cpp
+++ b/libc/bionic/__strlen_chk.cpp
@@ -28,7 +28,7 @@
#include <string.h>
#include <stdlib.h>
-#include <private/logd.h>
+#include "libc_logging.h"
/*
* Runtime implementation of __strlen_chk.
diff --git a/libc/bionic/__strncat_chk.cpp b/libc/bionic/__strncat_chk.cpp
index 32a3962..ab28541 100644
--- a/libc/bionic/__strncat_chk.cpp
+++ b/libc/bionic/__strncat_chk.cpp
@@ -28,7 +28,7 @@
#include <string.h>
#include <stdlib.h>
-#include <private/logd.h>
+#include "libc_logging.h"
#include <safe_iop.h>
/*
diff --git a/libc/bionic/__strncpy_chk.cpp b/libc/bionic/__strncpy_chk.cpp
index c9676ed..0f1797e 100644
--- a/libc/bionic/__strncpy_chk.cpp
+++ b/libc/bionic/__strncpy_chk.cpp
@@ -28,7 +28,7 @@
#include <string.h>
#include <stdlib.h>
-#include <private/logd.h>
+#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 e1bc96d..ff67ed6 100644
--- a/libc/bionic/__umask_chk.cpp
+++ b/libc/bionic/__umask_chk.cpp
@@ -30,7 +30,7 @@
#include <sys/types.h>
#include <sys/stat.h>
-#include <private/logd.h>
+#include "libc_logging.h"
#include <stdlib.h>
/*
diff --git a/libc/bionic/__vsnprintf_chk.cpp b/libc/bionic/__vsnprintf_chk.cpp
index 95d4915..0fdda3e 100644
--- a/libc/bionic/__vsnprintf_chk.cpp
+++ b/libc/bionic/__vsnprintf_chk.cpp
@@ -29,7 +29,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
-#include <private/logd.h>
+#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 e1d10f5..12b0ca6 100644
--- a/libc/bionic/__vsprintf_chk.cpp
+++ b/libc/bionic/__vsprintf_chk.cpp
@@ -29,7 +29,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
-#include <private/logd.h>
+#include "libc_logging.h"
/*
* Runtime implementation of __builtin____vsprintf_chk.
diff --git a/libc/bionic/assert.cpp b/libc/bionic/assert.cpp
index e38c16d..6f221a5 100644
--- a/libc/bionic/assert.cpp
+++ b/libc/bionic/assert.cpp
@@ -32,8 +32,7 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
-#include <private/debug_format.h>
-#include <private/logd.h>
+#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 9d53ad2..87dbba3 100644
--- a/libc/bionic/debug_stacktrace.cpp
+++ b/libc/bionic/debug_stacktrace.cpp
@@ -33,9 +33,8 @@
#include <unwind.h>
#include <sys/types.h>
-#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 1ed3205..7d4ef0f 100644
--- a/libc/bionic/dlmalloc.c
+++ b/libc/bionic/dlmalloc.c
@@ -24,8 +24,7 @@
#include <linux/ashmem.h>
-#include <private/debug_format.h>
-#include <private/logd.h>
+#include <private/libc_logging.h>
// 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 793f8b1..755dc81 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 <assert.h>
#include <errno.h>
+#include <pthread.h>
#include <stdarg.h>
#include <stddef.h>
-#include <stdint.h>
+#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -218,29 +220,30 @@
#include <fcntl.h>
#include <sys/uio.h>
+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);
+ int buf_strlen = 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;
+ 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<char*>(tag);
vec[1].iov_len = strlen(tag) + 1;
- vec[2].iov_base = (void *) buf;
- vec[2].iov_len = strlen(buf) + 1;
+ vec[2].iov_base = const_cast<char*>(buf);
+ vec[2].iov_len = buf_strlen + 1;
- TEMP_FAILURE_RETRY(writev(log_fd, vec, 3));
-
- 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 @@
}
}
}
+
+// 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<void*>(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 03ac606..0000000
--- 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 <time.h>
-#include <stdio.h>
-#include <pthread.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/uio.h>
-#include <arpa/inet.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <fcntl.h>
-
-#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 <pthread.h>
-
-/* 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 2ae98b6..91cf287 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 a05a5ef..2148d20 100644
--- a/libc/bionic/malloc_debug_common.cpp
+++ b/libc/bionic/malloc_debug_common.cpp
@@ -249,7 +249,7 @@
#include <sys/system_properties.h>
#include <dlfcn.h>
#include <stdio.h>
-#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 e15ccd0..12d0e65 100644
--- a/libc/bionic/malloc_debug_common.h
+++ b/libc/bionic/malloc_debug_common.h
@@ -35,7 +35,7 @@
#include <stdlib.h>
-#include <private/debug_format.h>
+#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 9e63a86..2db8a1f 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 812a451..08225c1 100644
--- a/libc/bionic/malloc_debug_qemu.cpp
+++ b/libc/bionic/malloc_debug_qemu.cpp
@@ -51,7 +51,7 @@
#include <unistd.h>
#include <errno.h>
#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 be4f04b..e3573a3 100644
--- a/libc/bionic/open.c
+++ b/libc/bionic/open.c
@@ -29,7 +29,7 @@
#include <fcntl.h>
#include <stdarg.h>
#include <stdlib.h>
-#include <private/logd.h>
+#include "libc_logging.h"
extern int __open(const char*, int, int);
@@ -60,4 +60,3 @@
return __open(pathname, flags, 0);
}
-
diff --git a/libc/bionic/openat.c b/libc/bionic/openat.c
index c1abbaa..2d09d17 100644
--- a/libc/bionic/openat.c
+++ b/libc/bionic/openat.c
@@ -29,7 +29,7 @@
#include <fcntl.h>
#include <stdarg.h>
#include <stdlib.h>
-#include <private/logd.h>
+#include "libc_logging.h"
extern int __openat(int, const char*, int, int);
@@ -61,4 +61,3 @@
return __openat(fd, pathname, flags, 0);
}
-
diff --git a/libc/bionic/pthread_create.cpp b/libc/bionic/pthread_create.cpp
index 368c46d..15f18aa 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 f8f0c59..94c23de 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 <private/debug_format.h>
+#include "libc_logging.h"
/*
* ===========================================================================
diff --git a/libc/bionic/stubs.cpp b/libc/bionic/stubs.cpp
index 8ddc326..e8411b7 100644
--- a/libc/bionic/stubs.cpp
+++ b/libc/bionic/stubs.cpp
@@ -38,9 +38,8 @@
#include <unistd.h>
#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 838e084..a2bc7ca 100644
--- a/libc/netbsd/resolv/res_cache.c
+++ b/libc/netbsd/resolv/res_cache.c
@@ -170,9 +170,8 @@
#undef XLOG
#if DEBUG
-# include <logd.h>
-# 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 <stdio.h>
#include <stdarg.h>
@@ -708,9 +707,9 @@
_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 @@
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 f3ee539..c6c863b 100644
--- a/libc/netbsd/resolv/res_send.c
+++ b/libc/netbsd/resolv/res_send.c
@@ -119,7 +119,7 @@
# include <resolv_cache.h>
#endif
-#include "logd.h"
+#include "libc_logging.h"
#ifndef DE_CONST
#define DE_CONST(c,v) v = ((c) ? \
@@ -542,7 +542,7 @@
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 @@
} 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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
}
}
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 e05846a..3e1f67b 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 <logd.h>
+# include "libc_logging.h"
# include <unistd.h> /* 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 438dc04..81195b5 100644
--- a/libc/private/arpa_nameser.h
+++ b/libc/private/arpa_nameser.h
@@ -567,9 +567,8 @@
#endif
#if 0
-# include <logd.h>
-# 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 0bc1148..4c9dc21 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 <sys/cdefs.h>
#include <stdarg.h>
#include <stddef.h>
+#include <stdint.h>
__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_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 a2828ec..0000000
--- 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 <stdarg.h>
-#include <stdint.h>
-
-#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 564ea80..93cb250 100644
--- a/libc/string/strchr.c
+++ b/libc/string/strchr.c
@@ -29,7 +29,7 @@
*/
#include <string.h>
-#include <private/logd.h>
+#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 5d0415e..14f29c5 100644
--- a/libc/string/strrchr.c
+++ b/libc/string/strrchr.c
@@ -29,7 +29,7 @@
*/
#include <string.h>
-#include <private/logd.h>
+#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 affb80f..6b5e328 100644
--- a/libstdc++/src/pure_virtual.cpp
+++ b/libstdc++/src/pure_virtual.cpp
@@ -2,7 +2,7 @@
#include <assert.h>
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 586cd2f..6fddb1c 100644
--- a/linker/debugger.cpp
+++ b/linker/debugger.cpp
@@ -37,9 +37,6 @@
#include <sys/socket.h>
#include <sys/un.h>
-#include <private/debug_format.h>
-#include <private/logd.h>
-
extern "C" int tgkill(int tgid, int tid, int sig);
#define DEBUGGER_SOCKET_NAME "android:debuggerd"
@@ -157,15 +154,15 @@
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 2f119e4..3afd314 100755
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -42,7 +42,6 @@
// Private C library headers.
#include <private/bionic_tls.h>
#include <private/KernelArgumentBlock.h>
-#include <private/logd.h>
#include <private/ScopedPthreadMutexLocker.h>
#include "linker.h"
@@ -141,13 +140,13 @@
// 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 d6a4fc5..6196bec 100644
--- a/linker/linker.h
+++ b/linker/linker.h
@@ -36,7 +36,7 @@
#include <link.h>
-#include <private/debug_format.h>
+#include "private/libc_logging.h"
#define DL_ERR(fmt, x...) \
do { \
diff --git a/linker/linker_debug.h b/linker/linker_debug.h
index 8fc235f..7d24853 100644
--- a/linker/linker_debug.h
+++ b/linker/linker_debug.h
@@ -58,7 +58,7 @@
/*********************************************************************/
-#include <private/debug_format.h>
+#include "private/libc_logging.h"
__LIBC_HIDDEN__ extern int gLdDebugVerbosity;
diff --git a/tests/Android.mk b/tests/Android.mk
index 46427ec..491b13c 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -57,11 +57,11 @@
-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 8419e4a..d9c615e 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 @@
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);