Merge "liblog: audit declare LIBLOG_ABI_PUBLIC"

This commit is contained in:
Mark Salyzyn 2016-03-10 22:28:23 +00:00 committed by Gerrit Code Review
commit 8c8acccd88
13 changed files with 257 additions and 151 deletions

View File

@ -39,7 +39,7 @@ LOCAL_SRC_FILES := $(liblog_host_sources)
LOCAL_SRC_FILES_darwin := event_tag_map.c
LOCAL_SRC_FILES_linux := event_tag_map.c
LOCAL_SRC_FILES_windows := uio.c
LOCAL_CFLAGS := -DFAKE_LOG_DEVICE=1 -Werror $(liblog_cflags)
LOCAL_CFLAGS := -DFAKE_LOG_DEVICE=1 -Werror -fvisibility=hidden $(liblog_cflags)
LOCAL_MULTILIB := both
LOCAL_MODULE_HOST_OS := darwin linux windows
include $(BUILD_HOST_STATIC_LIBRARY)
@ -59,7 +59,7 @@ include $(BUILD_HOST_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := liblog
LOCAL_SRC_FILES := $(liblog_target_sources)
LOCAL_CFLAGS := -Werror $(liblog_cflags)
LOCAL_CFLAGS := -Werror -fvisibility=hidden $(liblog_cflags)
# AddressSanitizer runtime library depends on liblog.
LOCAL_SANITIZE := never
include $(BUILD_STATIC_LIBRARY)
@ -67,7 +67,7 @@ include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := liblog
LOCAL_WHOLE_STATIC_LIBRARIES := liblog
LOCAL_CFLAGS := -Werror $(liblog_cflags)
LOCAL_CFLAGS := -Werror -fvisibility=hidden $(liblog_cflags)
# TODO: This is to work around b/24465209. Remove after root cause is fixed
LOCAL_LDFLAGS_arm := -Wl,--hash-style=both

View File

@ -24,6 +24,8 @@
#include <log/event_tag_map.h>
#include <log/log.h>
#include "log_cdefs.h"
#define OUT_TAG "EventTagMap"
/*
@ -61,7 +63,7 @@ static int sortTags(EventTagMap* map);
* We create a private mapping because we want to terminate the log tag
* strings with '\0'.
*/
EventTagMap* android_openEventTagMap(const char* fileName)
LIBLOG_ABI_PUBLIC EventTagMap* android_openEventTagMap(const char* fileName)
{
EventTagMap* newTagMap;
off_t end;
@ -109,7 +111,7 @@ fail:
/*
* Close the map.
*/
void android_closeEventTagMap(EventTagMap* map)
LIBLOG_ABI_PUBLIC void android_closeEventTagMap(EventTagMap* map)
{
if (map == NULL)
return;
@ -123,7 +125,8 @@ void android_closeEventTagMap(EventTagMap* map)
*
* The entries are sorted by tag number, so we can do a binary search.
*/
const char* android_lookupEventTag(const EventTagMap* map, int tag)
LIBLOG_ABI_PUBLIC const char* android_lookupEventTag(const EventTagMap* map,
int tag)
{
int hi, lo, mid;

View File

@ -19,23 +19,19 @@
* passed on to the underlying (fake) log device. When not in the
* simulator, messages are printed to stderr.
*/
#include "fake_log_device.h"
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#if !defined(_WIN32)
#include <pthread.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <log/logd.h>
#if !defined(_WIN32)
#include <pthread.h>
#endif
#ifndef __unused
#define __unused __attribute__((__unused__))
#endif
#include "fake_log_device.h"
#include "log_cdefs.h"
#define kMaxTagLen 16 /* from the long-dead utils/Log.cpp */
@ -512,7 +508,7 @@ static void showLog(LogState *state,
}
numLines -= 1;
}
/*
* Write the entire message to the log file with a single writev() call.
* We need to use this rather than a collection of printf()s on a FILE*
@ -531,10 +527,10 @@ static void showLog(LogState *state,
int cc = writev(fileno(stderr), vec, v-vec);
if (cc == totalLen) break;
if (cc < 0) {
if(errno == EINTR) continue;
/* can't really log the failure; for now, throw out a stderr */
fprintf(stderr, "+++ LOG: write failed (errno=%d)\n", errno);
break;
@ -683,7 +679,7 @@ static void setRedirects()
}
}
int fakeLogOpen(const char *pathName, int flags)
LIBLOG_HIDDEN int fakeLogOpen(const char *pathName, int flags)
{
if (redirectOpen == NULL) {
setRedirects();
@ -702,19 +698,22 @@ int fakeLogOpen(const char *pathName, int flags)
* call is in the exit handler. Logging can continue in the exit handler to
* help debug HOST tools ...
*/
int fakeLogClose(int fd)
LIBLOG_HIDDEN int fakeLogClose(int fd)
{
/* Assume that open() was called first. */
return redirectClose(fd);
}
ssize_t fakeLogWritev(int fd, const struct iovec* vector, int count)
LIBLOG_HIDDEN ssize_t fakeLogWritev(int fd,
const struct iovec* vector, int count)
{
/* Assume that open() was called first. */
return redirectWritev(fd, vector, count);
}
int __android_log_is_loggable(int prio, const char *tag __unused, int def)
LIBLOG_ABI_PUBLIC int __android_log_is_loggable(int prio,
const char *tag __unused,
int def)
{
int logLevel = def;
return logLevel >= 0 && prio >= logLevel;

View File

@ -19,10 +19,13 @@
#include <sys/types.h>
#include "log_cdefs.h"
struct iovec;
int fakeLogOpen(const char *pathName, int flags);
int fakeLogClose(int fd);
ssize_t fakeLogWritev(int fd, const struct iovec* vector, int count);
LIBLOG_HIDDEN int fakeLogOpen(const char *pathName, int flags);
LIBLOG_HIDDEN int fakeLogClose(int fd);
LIBLOG_HIDDEN ssize_t fakeLogWritev(int fd,
const struct iovec* vector, int count);
#endif // _LIBLOG_FAKE_LOG_DEVICE_H

54
liblog/log_cdefs.h Normal file
View File

@ -0,0 +1,54 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LIBLOG_CDEFS_H__
#define _LIBLOG_CDEFS_H__
#include <sys/cdefs.h>
/* Declare this library function hidden and internal */
#if defined(_WIN32)
#define LIBLOG_HIDDEN
#else
#define LIBLOG_HIDDEN __attribute__((visibility("hidden")))
#endif
/* Declare this library function visible and external */
#if defined(_WIN32)
#define LIBLOG_ABI_PUBLIC
#else
#define LIBLOG_ABI_PUBLIC __attribute__((visibility("default")))
#endif
/* Declare this library function visible but private */
#define LIBLOG_ABI_PRIVATE LIBLOG_ABI_PUBLIC
/*
* Declare this library function as reimplementation.
* Prevent circular dependencies, but allow _real_ library to hijack
*/
#if defined(_WIN32)
#define LIBLOG_WEAK static /* Accept that it is totally private */
#else
#define LIBLOG_WEAK __attribute__((weak,visibility("default")))
#endif
/* Unused argument. For C code only, remove symbol name for C++ */
#ifndef __unused
#define __unused __attribute__((__unused__))
#endif
#endif /* _LIBLOG_CDEFS_H__ */

View File

@ -25,6 +25,8 @@
#include <log/log.h>
#include <log/logger.h>
#include "log_cdefs.h"
#define MAX_EVENT_PAYLOAD (LOGGER_ENTRY_MAX_PAYLOAD - sizeof(int32_t))
typedef struct {
@ -43,7 +45,7 @@ typedef struct {
uint8_t storage[LOGGER_ENTRY_MAX_PAYLOAD];
} android_log_context_internal;
android_log_context create_android_logger(uint32_t tag) {
LIBLOG_ABI_PUBLIC android_log_context create_android_logger(uint32_t tag) {
size_t needed, i;
android_log_context_internal *context;
@ -65,7 +67,9 @@ android_log_context create_android_logger(uint32_t tag) {
return (android_log_context)context;
}
android_log_context create_android_log_parser(const char *msg, size_t len) {
LIBLOG_ABI_PUBLIC android_log_context create_android_log_parser(
const char *msg,
size_t len) {
android_log_context_internal *context;
size_t i;
@ -81,7 +85,7 @@ android_log_context create_android_log_parser(const char *msg, size_t len) {
return (android_log_context)context;
}
int android_log_destroy(android_log_context *ctx) {
LIBLOG_ABI_PUBLIC int android_log_destroy(android_log_context *ctx) {
android_log_context_internal *context;
context = (android_log_context_internal *)*ctx;
@ -94,7 +98,7 @@ int android_log_destroy(android_log_context *ctx) {
return 0;
}
int android_log_write_list_begin(android_log_context ctx) {
LIBLOG_ABI_PUBLIC int android_log_write_list_begin(android_log_context ctx) {
size_t needed;
android_log_context_internal *context;
@ -137,7 +141,8 @@ static inline void copy4LE(uint8_t *buf, uint32_t val)
buf[3] = (val >> 24) & 0xFF;
}
int android_log_write_int32(android_log_context ctx, int32_t value) {
LIBLOG_ABI_PUBLIC int android_log_write_int32(android_log_context ctx,
int32_t value) {
size_t needed;
android_log_context_internal *context;
@ -172,7 +177,8 @@ static inline void copy8LE(uint8_t *buf, uint64_t val)
buf[7] = (val >> 56) & 0xFF;
}
int android_log_write_int64(android_log_context ctx, int64_t value) {
LIBLOG_ABI_PUBLIC int android_log_write_int64(android_log_context ctx,
int64_t value) {
size_t needed;
android_log_context_internal *context;
@ -195,8 +201,9 @@ int android_log_write_int64(android_log_context ctx, int64_t value) {
return 0;
}
int android_log_write_string8_len(android_log_context ctx,
const char *value, size_t maxlen) {
LIBLOG_ABI_PUBLIC int android_log_write_string8_len(android_log_context ctx,
const char *value,
size_t maxlen) {
size_t needed;
ssize_t len;
android_log_context_internal *context;
@ -231,11 +238,13 @@ int android_log_write_string8_len(android_log_context ctx,
return len;
}
int android_log_write_string8(android_log_context ctx, const char *value) {
LIBLOG_ABI_PUBLIC int android_log_write_string8(android_log_context ctx,
const char *value) {
return android_log_write_string8_len(ctx, value, MAX_EVENT_PAYLOAD);
}
int android_log_write_float32(android_log_context ctx, float value) {
LIBLOG_ABI_PUBLIC int android_log_write_float32(android_log_context ctx,
float value) {
size_t needed;
uint32_t ivalue;
android_log_context_internal *context;
@ -260,7 +269,7 @@ int android_log_write_float32(android_log_context ctx, float value) {
return 0;
}
int android_log_write_list_end(android_log_context ctx) {
LIBLOG_ABI_PUBLIC int android_log_write_list_end(android_log_context ctx) {
android_log_context_internal *context;
context = (android_log_context_internal *)ctx;
@ -290,7 +299,8 @@ int android_log_write_list_end(android_log_context ctx) {
/*
* Logs the list of elements to the event log.
*/
int android_log_write_list(android_log_context ctx, log_id_t id) {
LIBLOG_ABI_PUBLIC int android_log_write_list(android_log_context ctx,
log_id_t id) {
android_log_context_internal *context;
const char *msg;
ssize_t len;
@ -518,10 +528,12 @@ static android_log_list_element android_log_read_next_internal(
}
}
android_log_list_element android_log_read_next(android_log_context ctx) {
LIBLOG_ABI_PUBLIC android_log_list_element android_log_read_next(
android_log_context ctx) {
return android_log_read_next_internal(ctx, 0);
}
android_log_list_element android_log_peek_next(android_log_context ctx) {
LIBLOG_ABI_PUBLIC android_log_list_element android_log_peek_next(
android_log_context ctx) {
return android_log_read_next_internal(ctx, 1);
}

View File

@ -18,10 +18,15 @@
#include <log/log.h>
#include "log_cdefs.h"
#define MAX_SUBTAG_LEN 32
int __android_log_error_write(int tag, const char *subTag, int32_t uid,
const char *data, uint32_t dataLen)
LIBLOG_ABI_PUBLIC int __android_log_error_write(
int tag,
const char *subTag,
int32_t uid,
const char *data, uint32_t dataLen)
{
int ret = -EINVAL;

View File

@ -23,6 +23,8 @@
#include <android/log.h>
#include "log_cdefs.h"
static pthread_mutex_t lock_loggable = PTHREAD_MUTEX_INITIALIZER;
static int lock()
@ -250,7 +252,8 @@ static int __android_log_level(const char *tag, int default_prio)
return default_prio;
}
int __android_log_is_loggable(int prio, const char *tag, int default_prio)
LIBLOG_ABI_PUBLIC int __android_log_is_loggable(int prio, const char *tag,
int default_prio)
{
int logLevel = __android_log_level(tag, default_prio);
return logLevel >= 0 && prio >= logLevel;
@ -315,7 +318,7 @@ static unsigned char evaluate_persist_ro(const struct cache2 *self)
* Timestamp state generally remains constant, but can change at any time
* to handle developer requirements.
*/
clockid_t android_log_clockid()
LIBLOG_ABI_PUBLIC clockid_t android_log_clockid()
{
static struct cache2 clockid = {
PTHREAD_MUTEX_INITIALIZER,
@ -343,7 +346,7 @@ static unsigned char evaluate_security(const struct cache2 *self)
return (c != BOOLEAN_FALSE) && c && (self->cache_persist.c == BOOLEAN_TRUE);
}
int __android_log_security()
LIBLOG_ABI_PUBLIC int __android_log_security()
{
static struct cache2 security = {
PTHREAD_MUTEX_INITIALIZER,

View File

@ -24,7 +24,6 @@
#define NOMINMAX /* for windows to suppress definition of min in stdlib.h */
#include <stdlib.h>
#include <string.h>
#include <sys/cdefs.h>
#include <unistd.h>
#include <cutils/list.h>
@ -34,23 +33,16 @@
#include <private/android_filesystem_config.h>
#include <private/android_logger.h>
#include "log_cdefs.h"
/* branchless on many architectures. */
#define min(x,y) ((y) ^ (((x) ^ (y)) & -((x) < (y))))
#if defined(_WIN32)
#define WEAK static
#else
#define WEAK __attribute__((weak))
#endif
#ifndef __unused
#define __unused __attribute__((unused))
#endif
/* Private copy of ../libcutils/socket_local_client.c prevent library loops */
#if defined(_WIN32)
int WEAK socket_local_client(const char *name, int namespaceId, int type)
LIBLOG_WEAK int socket_local_client(const char *name, int namespaceId, int type)
{
errno = ENOSYS;
return -ENOSYS;
@ -71,8 +63,9 @@ int WEAK socket_local_client(const char *name, int namespaceId, int type)
#define LISTEN_BACKLOG 4
/* Documented in header file. */
int WEAK socket_make_sockaddr_un(const char *name, int namespaceId,
struct sockaddr_un *p_addr, socklen_t *alen)
LIBLOG_WEAK int socket_make_sockaddr_un(const char *name, int namespaceId,
struct sockaddr_un *p_addr,
socklen_t *alen)
{
memset (p_addr, 0, sizeof (*p_addr));
size_t namelen;
@ -151,8 +144,8 @@ error:
*
* Used by AndroidSocketImpl
*/
int WEAK socket_local_client_connect(int fd, const char *name, int namespaceId,
int type __unused)
LIBLOG_WEAK int socket_local_client_connect(int fd, const char *name,
int namespaceId, int type __unused)
{
struct sockaddr_un addr;
socklen_t alen;
@ -178,7 +171,7 @@ error:
* connect to peer named "name"
* returns fd or -1 on error
*/
int WEAK socket_local_client(const char *name, int namespaceId, int type)
LIBLOG_WEAK int socket_local_client(const char *name, int namespaceId, int type)
{
int s;
@ -212,7 +205,7 @@ static const char *LOG_NAME[LOG_ID_MAX] = {
[LOG_ID_KERNEL] = "kernel",
};
const char *android_log_id_to_name(log_id_t log_id)
LIBLOG_ABI_PUBLIC const char *android_log_id_to_name(log_id_t log_id)
{
if (log_id >= LOG_ID_MAX) {
log_id = LOG_ID_MAIN;
@ -220,7 +213,7 @@ const char *android_log_id_to_name(log_id_t log_id)
return LOG_NAME[log_id];
}
log_id_t android_name_to_log_id(const char *logName)
LIBLOG_ABI_PUBLIC log_id_t android_name_to_log_id(const char *logName)
{
const char *b;
int ret;
@ -275,7 +268,7 @@ static void android_logger_free(struct logger *logger)
/* android_logger_alloc unimplemented, no use case */
/* method for getting the associated sublog id */
log_id_t android_logger_get_id(struct logger *logger)
LIBLOG_ABI_PUBLIC log_id_t android_logger_get_id(struct logger *logger)
{
return logger->id;
}
@ -409,7 +402,7 @@ static uid_t get_best_effective_uid()
return last_uid = uid;
}
int android_logger_clear(struct logger *logger)
LIBLOG_ABI_PUBLIC int android_logger_clear(struct logger *logger)
{
char buf[512];
@ -425,7 +418,7 @@ int android_logger_clear(struct logger *logger)
}
/* returns the total size of the log's ring buffer */
long android_logger_get_log_size(struct logger *logger)
LIBLOG_ABI_PUBLIC long android_logger_get_log_size(struct logger *logger)
{
char buf[512];
@ -441,7 +434,8 @@ long android_logger_get_log_size(struct logger *logger)
return atol(buf);
}
int android_logger_set_log_size(struct logger *logger, unsigned long size)
LIBLOG_ABI_PUBLIC int android_logger_set_log_size(struct logger *logger,
unsigned long size)
{
char buf[512];
@ -455,7 +449,8 @@ int android_logger_set_log_size(struct logger *logger, unsigned long size)
* returns the readable size of the log's ring buffer (that is, amount of the
* log consumed)
*/
long android_logger_get_log_readable_size(struct logger *logger)
LIBLOG_ABI_PUBLIC long android_logger_get_log_readable_size(
struct logger *logger)
{
char buf[512];
@ -474,16 +469,18 @@ long android_logger_get_log_readable_size(struct logger *logger)
/*
* returns the logger version
*/
int android_logger_get_log_version(struct logger *logger __unused)
LIBLOG_ABI_PUBLIC int android_logger_get_log_version(
struct logger *logger __unused)
{
return 3;
return 4;
}
/*
* returns statistics
*/
ssize_t android_logger_get_statistics(struct logger_list *logger_list,
char *buf, size_t len)
LIBLOG_ABI_PUBLIC ssize_t android_logger_get_statistics(
struct logger_list *logger_list,
char *buf, size_t len)
{
struct logger *logger;
char *cp = buf;
@ -509,14 +506,16 @@ ssize_t android_logger_get_statistics(struct logger_list *logger_list,
return send_log_msg(NULL, NULL, buf, len);
}
ssize_t android_logger_get_prune_list(struct logger_list *logger_list __unused,
char *buf, size_t len)
LIBLOG_ABI_PUBLIC ssize_t android_logger_get_prune_list(
struct logger_list *logger_list __unused,
char *buf, size_t len)
{
return send_log_msg(NULL, "getPruneList", buf, len);
}
int android_logger_set_prune_list(struct logger_list *logger_list __unused,
char *buf, size_t len)
LIBLOG_ABI_PUBLIC int android_logger_set_prune_list(
struct logger_list *logger_list __unused,
char *buf, size_t len)
{
const char cmd[] = "setPruneList ";
const size_t cmdlen = sizeof(cmd) - 1;
@ -531,9 +530,10 @@ int android_logger_set_prune_list(struct logger_list *logger_list __unused,
return check_log_success(buf, send_log_msg(NULL, NULL, buf, len));
}
struct logger_list *android_logger_list_alloc(int mode,
unsigned int tail,
pid_t pid)
LIBLOG_ABI_PUBLIC struct logger_list *android_logger_list_alloc(
int mode,
unsigned int tail,
pid_t pid)
{
struct logger_list *logger_list;
@ -553,9 +553,10 @@ struct logger_list *android_logger_list_alloc(int mode,
return logger_list;
}
struct logger_list *android_logger_list_alloc_time(int mode,
log_time start,
pid_t pid)
LIBLOG_ABI_PUBLIC struct logger_list *android_logger_list_alloc_time(
int mode,
log_time start,
pid_t pid)
{
struct logger_list *logger_list;
@ -578,8 +579,9 @@ struct logger_list *android_logger_list_alloc_time(int mode,
/* android_logger_list_unregister unimplemented, no use case */
/* Open the named log and add it to the logger list */
struct logger *android_logger_open(struct logger_list *logger_list,
log_id_t id)
LIBLOG_ABI_PUBLIC struct logger *android_logger_open(
struct logger_list *logger_list,
log_id_t id)
{
struct logger *logger;
@ -610,10 +612,11 @@ ok:
}
/* Open the single named log and make it part of a new logger list */
struct logger_list *android_logger_list_open(log_id_t id,
int mode,
unsigned int tail,
pid_t pid)
LIBLOG_ABI_PUBLIC struct logger_list *android_logger_list_open(
log_id_t id,
int mode,
unsigned int tail,
pid_t pid)
{
struct logger_list *logger_list = android_logger_list_alloc(mode, tail, pid);
if (!logger_list) {
@ -751,8 +754,9 @@ static void caught_signal(int signum __unused)
}
/* Read from the selected logs */
int android_logger_list_read(struct logger_list *logger_list,
struct log_msg *log_msg)
LIBLOG_ABI_PUBLIC int android_logger_list_read(
struct logger_list *logger_list,
struct log_msg *log_msg)
{
int ret, e;
struct logger *logger;
@ -892,7 +896,8 @@ int android_logger_list_read(struct logger_list *logger_list,
}
/* Close all the logs */
void android_logger_list_free(struct logger_list *logger_list)
LIBLOG_ABI_PUBLIC void android_logger_list_free(
struct logger_list *logger_list)
{
if (logger_list == NULL) {
return;

View File

@ -18,16 +18,17 @@
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <sys/cdefs.h>
#include <log/log_read.h>
const char log_time::default_format[] = "%m-%d %H:%M:%S.%q";
const timespec log_time::EPOCH = { 0, 0 };
#include "log_cdefs.h"
LIBLOG_ABI_PRIVATE const char log_time::default_format[] = "%m-%d %H:%M:%S.%q";
LIBLOG_ABI_PRIVATE const timespec log_time::EPOCH = { 0, 0 };
// Add %#q for fractional seconds to standard strptime function
char *log_time::strptime(const char *s, const char *format) {
LIBLOG_ABI_PRIVATE char *log_time::strptime(const char *s, const char *format) {
time_t now;
#ifdef __linux__
*this = log_time(CLOCK_REALTIME);
@ -133,7 +134,7 @@ char *log_time::strptime(const char *s, const char *format) {
return ret;
}
log_time log_time::operator-= (const timespec &T) {
LIBLOG_ABI_PRIVATE log_time log_time::operator-= (const timespec &T) {
// No concept of negative time, clamp to EPOCH
if (*this <= T) {
return *this = EPOCH;
@ -150,7 +151,7 @@ log_time log_time::operator-= (const timespec &T) {
return *this;
}
log_time log_time::operator+= (const timespec &T) {
LIBLOG_ABI_PRIVATE log_time log_time::operator+= (const timespec &T) {
this->tv_nsec += (unsigned long int)T.tv_nsec;
if (this->tv_nsec >= NS_PER_SEC) {
this->tv_nsec -= NS_PER_SEC;
@ -161,7 +162,7 @@ log_time log_time::operator+= (const timespec &T) {
return *this;
}
log_time log_time::operator-= (const log_time &T) {
LIBLOG_ABI_PRIVATE log_time log_time::operator-= (const log_time &T) {
// No concept of negative time, clamp to EPOCH
if (*this <= T) {
return *this = EPOCH;
@ -178,7 +179,7 @@ log_time log_time::operator-= (const log_time &T) {
return *this;
}
log_time log_time::operator+= (const log_time &T) {
LIBLOG_ABI_PRIVATE log_time log_time::operator+= (const log_time &T) {
this->tv_nsec += T.tv_nsec;
if (this->tv_nsec >= NS_PER_SEC) {
this->tv_nsec -= NS_PER_SEC;

View File

@ -46,6 +46,8 @@
#include <private/android_filesystem_config.h>
#include <private/android_logger.h>
#include "log_cdefs.h"
#define LOG_BUF_SIZE 1024
#if FAKE_LOG_DEVICE
@ -56,10 +58,6 @@
static int __write_to_log_init(log_id_t, struct iovec *vec, size_t nr);
static int (*write_to_log)(log_id_t, struct iovec *vec, size_t nr) = __write_to_log_init;
#ifndef __unused
#define __unused __attribute__((__unused__))
#endif
#if !defined(_WIN32)
static pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER;
@ -106,7 +104,7 @@ static enum {
kLogUninitialized, kLogNotAvailable, kLogAvailable
} g_log_status = kLogUninitialized;
int __android_log_dev_available(void)
LIBLOG_ABI_PUBLIC int __android_log_dev_available()
{
if (g_log_status == kLogUninitialized) {
if (access("/dev/socket/logdw", W_OK) == 0)
@ -485,7 +483,7 @@ static const char *LOG_NAME[LOG_ID_MAX] = {
[LOG_ID_KERNEL] = "kernel",
};
const char *android_log_id_to_name(log_id_t log_id)
LIBLOG_ABI_PUBLIC const char *android_log_id_to_name(log_id_t log_id)
{
if (log_id >= LOG_ID_MAX) {
log_id = LOG_ID_MAIN;
@ -520,12 +518,14 @@ static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr)
return write_to_log(log_id, vec, nr);
}
int __android_log_write(int prio, const char *tag, const char *msg)
LIBLOG_ABI_PUBLIC int __android_log_write(int prio, const char *tag,
const char *msg)
{
return __android_log_buf_write(LOG_ID_MAIN, prio, tag, msg);
}
int __android_log_buf_write(int bufID, int prio, const char *tag, const char *msg)
LIBLOG_ABI_PUBLIC int __android_log_buf_write(int bufID, int prio,
const char *tag, const char *msg)
{
struct iovec vec[3];
char tmp_tag[32];
@ -566,7 +566,8 @@ int __android_log_buf_write(int bufID, int prio, const char *tag, const char *ms
return write_to_log(bufID, vec, 3);
}
int __android_log_vprint(int prio, const char *tag, const char *fmt, va_list ap)
LIBLOG_ABI_PUBLIC int __android_log_vprint(int prio, const char *tag,
const char *fmt, va_list ap)
{
char buf[LOG_BUF_SIZE];
@ -575,7 +576,8 @@ int __android_log_vprint(int prio, const char *tag, const char *fmt, va_list ap)
return __android_log_write(prio, tag, buf);
}
int __android_log_print(int prio, const char *tag, const char *fmt, ...)
LIBLOG_ABI_PUBLIC int __android_log_print(int prio, const char *tag,
const char *fmt, ...)
{
va_list ap;
char buf[LOG_BUF_SIZE];
@ -587,7 +589,9 @@ int __android_log_print(int prio, const char *tag, const char *fmt, ...)
return __android_log_write(prio, tag, buf);
}
int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...)
LIBLOG_ABI_PUBLIC int __android_log_buf_print(int bufID, int prio,
const char *tag,
const char *fmt, ...)
{
va_list ap;
char buf[LOG_BUF_SIZE];
@ -599,8 +603,10 @@ int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fm
return __android_log_buf_write(bufID, prio, tag, buf);
}
void __android_log_assert(const char *cond, const char *tag,
const char *fmt, ...)
LIBLOG_ABI_PUBLIC void __android_log_assert(
const char *cond,
const char *tag,
const char *fmt, ...)
{
char buf[LOG_BUF_SIZE];
@ -625,7 +631,8 @@ void __android_log_assert(const char *cond, const char *tag,
/* NOTREACHED */
}
int __android_log_bwrite(int32_t tag, const void *payload, size_t len)
LIBLOG_ABI_PUBLIC int __android_log_bwrite(int32_t tag,
const void *payload, size_t len)
{
struct iovec vec[2];
@ -637,7 +644,9 @@ int __android_log_bwrite(int32_t tag, const void *payload, size_t len)
return write_to_log(LOG_ID_EVENTS, vec, 2);
}
int __android_log_security_bwrite(int32_t tag, const void *payload, size_t len)
LIBLOG_ABI_PUBLIC int __android_log_security_bwrite(int32_t tag,
const void *payload,
size_t len)
{
struct iovec vec[2];
@ -654,8 +663,8 @@ int __android_log_security_bwrite(int32_t tag, const void *payload, size_t len)
* for the general case where we're generating lists of stuff, but very
* handy if we just want to dump an integer into the log.
*/
int __android_log_btwrite(int32_t tag, char type, const void *payload,
size_t len)
LIBLOG_ABI_PUBLIC int __android_log_btwrite(int32_t tag, char type,
const void *payload, size_t len)
{
struct iovec vec[3];
@ -673,7 +682,7 @@ int __android_log_btwrite(int32_t tag, char type, const void *payload,
* Like __android_log_bwrite, but used for writing strings to the
* event log.
*/
int __android_log_bswrite(int32_t tag, const char *payload)
LIBLOG_ABI_PUBLIC int __android_log_bswrite(int32_t tag, const char *payload)
{
struct iovec vec[4];
char type = EVENT_TYPE_STRING;
@ -695,7 +704,8 @@ int __android_log_bswrite(int32_t tag, const char *payload)
* Like __android_log_security_bwrite, but used for writing strings to the
* security log.
*/
int __android_log_security_bswrite(int32_t tag, const char *payload)
LIBLOG_ABI_PUBLIC int __android_log_security_bswrite(int32_t tag,
const char *payload)
{
struct iovec vec[4];
char type = EVENT_TYPE_STRING;

View File

@ -34,12 +34,11 @@
#include <log/logprint.h>
#include <private/android_filesystem_config.h>
#include "log_cdefs.h"
#define MS_PER_NSEC 1000000
#define US_PER_NSEC 1000
/* open coded fragment, prevent circular dependencies */
#define WEAK static
typedef struct FilterInfo_t {
char *mTag;
android_LogPriority mPri;
@ -185,13 +184,15 @@ static android_LogPriority filterPriForTag(
* returns 1 if this log line should be printed based on its priority
* and tag, and 0 if it should not
*/
int android_log_shouldPrintLine (
AndroidLogFormat *p_format, const char *tag, android_LogPriority pri)
LIBLOG_ABI_PUBLIC int android_log_shouldPrintLine (
AndroidLogFormat *p_format,
const char *tag,
android_LogPriority pri)
{
return pri >= filterPriForTag(p_format, tag);
}
AndroidLogFormat *android_log_format_new()
LIBLOG_ABI_PUBLIC AndroidLogFormat *android_log_format_new()
{
AndroidLogFormat *p_ret;
@ -213,7 +214,7 @@ AndroidLogFormat *android_log_format_new()
static list_declare(convertHead);
void android_log_format_free(AndroidLogFormat *p_format)
LIBLOG_ABI_PUBLIC void android_log_format_free(AndroidLogFormat *p_format)
{
FilterInfo *p_info, *p_info_old;
@ -236,7 +237,8 @@ void android_log_format_free(AndroidLogFormat *p_format)
}
}
int android_log_setPrintFormat(AndroidLogFormat *p_format,
LIBLOG_ABI_PUBLIC int android_log_setPrintFormat(
AndroidLogFormat *p_format,
AndroidLogPrintFormat format)
{
switch (format) {
@ -277,7 +279,8 @@ static const char utc[] = "UTC";
/**
* Returns FORMAT_OFF on invalid string
*/
AndroidLogPrintFormat android_log_formatFromString(const char * formatString)
LIBLOG_ABI_PUBLIC AndroidLogPrintFormat android_log_formatFromString(
const char * formatString)
{
static AndroidLogPrintFormat format;
@ -341,7 +344,8 @@ AndroidLogPrintFormat android_log_formatFromString(const char * formatString)
* Assumes single threaded execution
*/
int android_log_addFilterRule(AndroidLogFormat *p_format,
LIBLOG_ABI_PUBLIC int android_log_addFilterRule(
AndroidLogFormat *p_format,
const char *filterExpression)
{
size_t tagNameLength;
@ -419,7 +423,8 @@ error:
*
*/
int android_log_addFilterString(AndroidLogFormat *p_format,
LIBLOG_ABI_PUBLIC int android_log_addFilterString(
AndroidLogFormat *p_format,
const char *filterString)
{
char *filterStringCopy = strdup (filterString);
@ -453,8 +458,9 @@ error:
* Returns 0 on success and -1 on invalid wire format (entry will be
* in unspecified state)
*/
int android_log_processLogBuffer(struct logger_entry *buf,
AndroidLogEntry *entry)
LIBLOG_ABI_PUBLIC int android_log_processLogBuffer(
struct logger_entry *buf,
AndroidLogEntry *entry)
{
entry->tv_sec = buf->sec;
entry->tv_nsec = buf->nsec;
@ -734,9 +740,11 @@ no_room:
* it however we choose, which means we can't really use a fixed-size buffer
* here.
*/
int android_log_processBinaryLogBuffer(struct logger_entry *buf,
AndroidLogEntry *entry, const EventTagMap* map, char* messageBuf,
int messageBufLen)
LIBLOG_ABI_PUBLIC int android_log_processBinaryLogBuffer(
struct logger_entry *buf,
AndroidLogEntry *entry,
const EventTagMap *map,
char *messageBuf, int messageBufLen)
{
size_t inCount;
unsigned int tagIndex;
@ -852,7 +860,7 @@ int android_log_processBinaryLogBuffer(struct logger_entry *buf,
* _also_ be part of libutils/Unicode.cpp if its usefullness needs to
* propagate globally.
*/
WEAK ssize_t utf8_character_length(const char *src, size_t len)
LIBLOG_WEAK ssize_t utf8_character_length(const char *src, size_t len)
{
const char *cur = src;
const char first_char = *cur++;
@ -956,7 +964,7 @@ static size_t convertPrintable(char *p, const char *message, size_t messageLen)
return p - begin;
}
char *readSeconds(char *e, struct timespec *t)
static char *readSeconds(char *e, struct timespec *t)
{
unsigned long multiplier;
char *p;
@ -1243,12 +1251,12 @@ static void convertMonotonic(struct timespec *result,
* Returns NULL on malloc error
*/
char *android_log_formatLogLine (
AndroidLogFormat *p_format,
char *defaultBuffer,
size_t defaultBufferSize,
const AndroidLogEntry *entry,
size_t *p_outLength)
LIBLOG_ABI_PUBLIC char *android_log_formatLogLine (
AndroidLogFormat *p_format,
char *defaultBuffer,
size_t defaultBufferSize,
const AndroidLogEntry *entry,
size_t *p_outLength)
{
#if !defined(_WIN32)
struct tm tmBuf;
@ -1526,10 +1534,10 @@ char *android_log_formatLogLine (
* Returns count bytes written
*/
int android_log_printLogLine(
AndroidLogFormat *p_format,
int fd,
const AndroidLogEntry *entry)
LIBLOG_ABI_PUBLIC int android_log_printLogLine(
AndroidLogFormat *p_format,
int fd,
const AndroidLogEntry *entry)
{
int ret;
char defaultBuffer[512];

View File

@ -16,17 +16,20 @@
#if defined(_WIN32)
#include <log/uio.h>
#include <unistd.h>
int readv( int fd, struct iovec* vecs, int count )
#include <log/uio.h>
#include "log_cdefs.h"
LIBLOG_ABI_PUBLIC int readv(int fd, struct iovec *vecs, int count)
{
int total = 0;
for ( ; count > 0; count--, vecs++ ) {
char* buf = vecs->iov_base;
int len = vecs->iov_len;
while (len > 0) {
int ret = read( fd, buf, len );
if (ret < 0) {
@ -46,14 +49,14 @@ Exit:
return total;
}
int writev( int fd, const struct iovec* vecs, int count )
LIBLOG_ABI_PUBLIC int writev(int fd, const struct iovec *vecs, int count)
{
int total = 0;
for ( ; count > 0; count--, vecs++ ) {
const char* buf = vecs->iov_base;
int len = vecs->iov_len;
while (len > 0) {
int ret = write( fd, buf, len );
if (ret < 0) {
@ -69,7 +72,7 @@ int writev( int fd, const struct iovec* vecs, int count )
len -= ret;
}
}
Exit:
Exit:
return total;
}