From fa1c063febb8726f7b629ba04c083edf33b87789 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Tue, 3 Mar 2015 15:44:52 -0800 Subject: [PATCH 1/2] private: Add event payload structures to android_logger.h - common android_event_header_t - android_event_int_t ANDROID_TYPE_INT payload - android_log_event_int_t single ANDROID_TYPE_INT event - android_event_long_t ANDROID_TYPE_LONG payload - android_log_event_long_t single ANDROID_TYPE_LONG event - android_event_string_t ANDROID_TYPE_STRING payload - android_log_event_string_t single ANDROID_TYPE_STRING event Change-Id: I9e5fccba38e3f230c2c4ec7dec51ed110c460f95 --- include/private/android_logger.h | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/include/private/android_logger.h b/include/private/android_logger.h index cc7ba3042..724ca5173 100644 --- a/include/private/android_logger.h +++ b/include/private/android_logger.h @@ -41,4 +41,46 @@ typedef struct __attribute__((__packed__)) { log_time realtime; } android_log_header_t; +/* Event Header Structure to logd */ +typedef struct __attribute__((__packed__)) { + int32_t tag; // Little Endian Order +} android_event_header_t; + +/* Event payload EVENT_TYPE_INT */ +typedef struct __attribute__((__packed__)) { + int8_t type; // EVENT_TYPE_INT + int32_t data; // Little Endian Order +} android_event_int_t; + +/* Event with single EVENT_TYPE_INT */ +typedef struct __attribute__((__packed__)) { + android_event_header_t header; + android_event_int_t payload; +} android_log_event_int_t; + +/* Event payload EVENT_TYPE_LONG */ +typedef struct __attribute__((__packed__)) { + int8_t type; // EVENT_TYPE_LONG + int64_t data; // Little Endian Order +} android_event_long_t; + +/* Event with single EVENT_TYPE_LONG */ +typedef struct __attribute__((__packed__)) { + android_event_header_t header; + android_event_long_t payload; +} android_log_event_long_t; + +/* Event payload EVENT_TYPE_STRING */ +typedef struct __attribute__((__packed__)) { + int8_t type; // EVENT_TYPE_STRING; + int32_t length; // Little Endian Order + char data[]; +} android_event_string_t; + +/* Event with single EVENT_TYPE_STRING */ +typedef struct __attribute__((__packed__)) { + android_event_header_t header; + android_event_string_t payload; +} android_log_event_string_t; + #endif From 66bfc5ccbda1c36923230b8dea36e86e8ac62d67 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Tue, 3 Mar 2015 15:23:24 -0800 Subject: [PATCH 2/2] liblog: logprint use Change-Id: I0ec0fe3e954f6f04964d58e57c817d28057b630b --- liblog/logprint.c | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/liblog/logprint.c b/liblog/logprint.c index 7ba4c8e78..8093a4c26 100644 --- a/liblog/logprint.c +++ b/liblog/logprint.c @@ -415,27 +415,6 @@ int android_log_processLogBuffer(struct logger_entry *buf, return 0; } -/* - * Extract a 4-byte value from a byte stream. - */ -static inline uint32_t get4LE(const uint8_t* src) -{ - return src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24); -} - -/* - * Extract an 8-byte value from a byte stream. - */ -static inline uint64_t get8LE(const uint8_t* src) -{ - uint32_t low, high; - - low = src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24); - high = src[4] | (src[5] << 8) | (src[6] << 16) | (src[7] << 24); - return ((long long) high << 32) | (long long) low; -} - - /* * Recursively convert binary log data to printable form. * @@ -473,7 +452,7 @@ static int android_log_printBinaryEvent(const unsigned char** pEventData, if (eventDataLen < 4) return -1; - ival = get4LE(eventData); + ival = le32toh(*((int32_t *)eventData)); eventData += 4; eventDataLen -= 4; @@ -494,7 +473,7 @@ static int android_log_printBinaryEvent(const unsigned char** pEventData, if (eventDataLen < 8) return -1; - lval = get8LE(eventData); + lval = le64toh(*((int64_t *)eventData)); eventData += 8; eventDataLen -= 8; @@ -515,7 +494,7 @@ static int android_log_printBinaryEvent(const unsigned char** pEventData, if (eventDataLen < 4) return -1; - strLen = get4LE(eventData); + strLen = le32toh(*((int32_t *)eventData)); eventData += 4; eventDataLen -= 4; @@ -630,7 +609,7 @@ int android_log_processBinaryLogBuffer(struct logger_entry *buf, inCount = buf->len; if (inCount < 4) return -1; - tagIndex = get4LE(eventData); + tagIndex = le32toh(*((int32_t *)eventData)); eventData += 4; inCount -= 4;