Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4c63e04f authored by Tom Cherry's avatar Tom Cherry
Browse files

liblog: remove endianness functions

Android is little endian.

Test: liblog unit tests
Change-Id: Ieea7af39013a97f9f0d138a6d1ada3524d94e710
parent ebb7cdd0
Loading
Loading
Loading
Loading
+3 −19
Original line number Diff line number Diff line
@@ -399,22 +399,6 @@ int android_log_write_list_buffer(android_log_context ctx, const char** buffer)
  return len;
}

/*
 * 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 = src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24);
  uint32_t high = src[4] | (src[5] << 8) | (src[6] << 16) | (src[7] << 24);
  return ((uint64_t)high << 32) | (uint64_t)low;
}

/*
 * Gets the next element. Parsing errors result in an EVENT_TYPE_UNKNOWN type.
 * If there is nothing to process, the complete field is set to non-zero. If
@@ -488,7 +472,7 @@ static android_log_list_element android_log_read_next_internal(android_log_conte
        elem.type = EVENT_TYPE_UNKNOWN;
        return elem;
      }
      elem.data.int32 = get4LE(&context->storage[pos]);
      elem.data.int32 = *reinterpret_cast<int32_t*>(&context->storage[pos]);
      /* common tangeable object suffix */
      pos += elem.len;
      elem.complete = !context->list_nest_depth && !context->count[0];
@@ -507,7 +491,7 @@ static android_log_list_element android_log_read_next_internal(android_log_conte
        elem.type = EVENT_TYPE_UNKNOWN;
        return elem;
      }
      elem.data.int64 = get8LE(&context->storage[pos]);
      elem.data.int64 = *reinterpret_cast<int64_t*>(&context->storage[pos]);
      /* common tangeable object suffix */
      pos += elem.len;
      elem.complete = !context->list_nest_depth && !context->count[0];
@@ -526,7 +510,7 @@ static android_log_list_element android_log_read_next_internal(android_log_conte
        elem.complete = true;
        return elem;
      }
      elem.len = get4LE(&context->storage[pos]);
      elem.len = *reinterpret_cast<int32_t*>(&context->storage[pos]);
      pos += sizeof(int32_t);
      if ((pos + elem.len) > context->len) {
        elem.len = context->len - pos; /* truncate string */
+0 −1
Original line number Diff line number Diff line
@@ -14,7 +14,6 @@
 * limitations under the License.
 */

#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
+4 −5
Original line number Diff line number Diff line
@@ -14,7 +14,6 @@
 * limitations under the License.
 */

#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
@@ -184,9 +183,9 @@ static int logdWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, siz
      android_log_event_int_t buffer;

      header.id = LOG_ID_SECURITY;
      buffer.header.tag = htole32(LIBLOG_LOG_TAG);
      buffer.header.tag = LIBLOG_LOG_TAG;
      buffer.payload.type = EVENT_TYPE_INT;
      buffer.payload.data = htole32(snapshot);
      buffer.payload.data = snapshot;

      newVec[headerLength].iov_base = &buffer;
      newVec[headerLength].iov_len = sizeof(buffer);
@@ -202,9 +201,9 @@ static int logdWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, siz
      android_log_event_int_t buffer;

      header.id = LOG_ID_EVENTS;
      buffer.header.tag = htole32(LIBLOG_LOG_TAG);
      buffer.header.tag = LIBLOG_LOG_TAG;
      buffer.payload.type = EVENT_TYPE_INT;
      buffer.payload.data = htole32(snapshot);
      buffer.payload.data = snapshot;

      newVec[headerLength].iov_base = &buffer;
      newVec[headerLength].iov_len = sizeof(buffer);
+5 −23
Original line number Diff line number Diff line
@@ -582,24 +582,6 @@ int android_log_processLogBuffer(struct logger_entry* buf, AndroidLogEntry* entr
  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 ((uint64_t)high << 32) | (uint64_t)low;
}

static bool findChar(const char** cp, size_t* len, int c) {
  while ((*len) && isspace(*(*cp))) {
    ++(*cp);
@@ -746,7 +728,7 @@ static int android_log_printBinaryEvent(const unsigned char** pEventData, size_t
        int32_t ival;

        if (eventDataLen < 4) return -1;
        ival = get4LE(eventData);
        ival = *reinterpret_cast<const int32_t*>(eventData);
        eventData += 4;
        eventDataLen -= 4;

@@ -756,7 +738,7 @@ static int android_log_printBinaryEvent(const unsigned char** pEventData, size_t
    case EVENT_TYPE_LONG:
      /* 64-bit signed long */
      if (eventDataLen < 8) return -1;
      lval = get8LE(eventData);
      lval = *reinterpret_cast<const int64_t*>(eventData);
      eventData += 8;
      eventDataLen -= 8;
    pr_lval:
@@ -776,7 +758,7 @@ static int android_log_printBinaryEvent(const unsigned char** pEventData, size_t
        float fval;

        if (eventDataLen < 4) return -1;
        ival = get4LE(eventData);
        ival = *reinterpret_cast<const uint32_t*>(eventData);
        fval = *(float*)&ival;
        eventData += 4;
        eventDataLen -= 4;
@@ -797,7 +779,7 @@ static int android_log_printBinaryEvent(const unsigned char** pEventData, size_t
        unsigned int strLen;

        if (eventDataLen < 4) return -1;
        strLen = get4LE(eventData);
        strLen = *reinterpret_cast<const uint32_t*>(eventData);
        eventData += 4;
        eventDataLen -= 4;

@@ -1036,7 +1018,7 @@ int android_log_processBinaryLogBuffer(
  }
  inCount = buf->len;
  if (inCount < 4) return -1;
  tagIndex = get4LE(eventData);
  tagIndex = *reinterpret_cast<const uint32_t*>(eventData);
  eventData += 4;
  inCount -= 4;

+1 −8
Original line number Diff line number Diff line
@@ -87,13 +87,6 @@ static int pmsgAvailable(log_id_t logId) {
  return 1;
}

/*
 * 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);
}

static int pmsgWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, size_t nr) {
  static const unsigned headerLength = 2;
  struct iovec newVec[nr + headerLength];
@@ -107,7 +100,7 @@ static int pmsgWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, siz
      return -EINVAL;
    }

    if (SNET_EVENT_LOG_TAG != get4LE(static_cast<uint8_t*>(vec[0].iov_base))) {
    if (SNET_EVENT_LOG_TAG != *static_cast<uint8_t*>(vec[0].iov_base)) {
      return -EPERM;
    }
  }
Loading