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

Commit c8ef0134 authored by Tom Cherry's avatar Tom Cherry Committed by Gerrit Code Review
Browse files

Merge changes from topic "remove-legacy-logger_entry-structs"

* changes:
  liblog: document the liblog<->logd protocol format
  liblog: remove unused parts of android_log_transport_context
  Remove old logger_entry_v* formats
  liblog: disable header_abi_checker
parents 59cb3c62 a379b1ce
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -595,7 +595,7 @@ static void dump_log_file(log_t* log, pid_t pid, const char* filename, unsigned
      }
      AndroidLogEntry e;
      char buf[512];
      if (android_log_processBinaryLogBuffer(&log_entry.entry_v1, &e, g_eventTagMap, buf,
      if (android_log_processBinaryLogBuffer(&log_entry.entry, &e, g_eventTagMap, buf,
                                             sizeof(buf)) == 0) {
        _LOG(log, logtype::LOGS, "%s.%03d %5d %5d %c %-8.*s: %s\n", timeBuf,
             log_entry.entry.nsec / 1000000, log_entry.entry.pid, log_entry.entry.tid, 'I',
+5 −0
Original line number Diff line number Diff line
@@ -105,6 +105,11 @@ cc_library {
        versions: ["10000"],
    },

    // TODO(tomcherry): Renable this before release branch is cut
    header_abi_checker: {
        enabled: false,
    },

    cflags: [
        "-Wall",
        "-Werror",
+49 −0
Original line number Diff line number Diff line
# liblog -> logd

The data that liblog sends to logd is represented below.

    struct {
        android_log_header_t header;
        union {
           struct {
                char     prio;
                char     tag[...];
                char     message[...];
            } string;
            struct {
                android_event_header_t event_header;
                android_event_*_t      payload[...];
            } binary;
        };
    };

The payload, excluding the header, has a max size of LOGGER_ENTRY_MAX_PAYLOAD.

## header

The header is added immediately before sending the log message to logd.

## `string` payload

The `string` part of the union is for normal buffers (main, system, radio, etc) and consists of a
single character priority, followed by a variable length null terminated string for the tag, and
finally a variable length null terminated string for the message.

This payload is used for the `__android_log_buf_write()` family of functions.

## `binary` payload

The `binary` part of the union is for binary buffers (events, security, etc) and consists of an
android_event_header_t struct followed by a variable number of android_event_*_t
(android_event_list_t, android_event_int_t, etc) structs.

If multiple android_event_*_t elements are present, then they must be in a list and the first
element in payload must be an android_event_list_t.

This payload is used for the `__android_log_bwrite()` family of functions. It is additionally used
for `android_log_write_list()` and the related functions that manipulate event lists.

# logd -> liblog

logd sends a `logger_entry` struct to liblog followed by the payload. The payload is identical to
the payloads defined above. The max size of the entire message from logd is LOGGER_ENTRY_MAX_LEN.
+4 −59
Original line number Diff line number Diff line
@@ -50,53 +50,9 @@ extern "C" {

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wzero-length-array"
/*
 * The userspace structure for version 1 of the logger_entry ABI.
 */
struct logger_entry {
  uint16_t len;      /* length of the payload */
  uint16_t __pad; /* no matter what, we get 2 bytes of padding */
  int32_t pid;    /* generating process's pid */
  int32_t tid;    /* generating process's tid */
  int32_t sec;    /* seconds since Epoch */
  int32_t nsec;   /* nanoseconds */
  char msg[0]; /* the entry's payload */
};

/*
 * The userspace structure for version 2 of the logger_entry ABI.
 */
struct logger_entry_v2 {
  uint16_t len;      /* length of the payload */
  uint16_t hdr_size; /* sizeof(struct logger_entry_v2) */
  int32_t pid;       /* generating process's pid */
  int32_t tid;       /* generating process's tid */
  int32_t sec;       /* seconds since Epoch */
  int32_t nsec;      /* nanoseconds */
  uint32_t euid;     /* effective UID of logger */
  char msg[0]; /* the entry's payload */
} __attribute__((__packed__));

/*
 * The userspace structure for version 3 of the logger_entry ABI.
 */
struct logger_entry_v3 {
  uint16_t len;      /* length of the payload */
  uint16_t hdr_size; /* sizeof(struct logger_entry_v3) */
  int32_t pid;       /* generating process's pid */
  int32_t tid;       /* generating process's tid */
  int32_t sec;       /* seconds since Epoch */
  int32_t nsec;      /* nanoseconds */
  uint32_t lid;      /* log id of the payload */
  char msg[0]; /* the entry's payload */
} __attribute__((__packed__));

/*
 * The userspace structure for version 4 of the logger_entry ABI.
 */
struct logger_entry_v4 {
  uint16_t len;      /* length of the payload */
  uint16_t hdr_size; /* sizeof(struct logger_entry_v4) */
  uint16_t hdr_size; /* sizeof(struct logger_entry) */
  int32_t pid;       /* generating process's pid */
  uint32_t tid;      /* generating process's tid */
  uint32_t sec;      /* seconds since Epoch */
@@ -124,11 +80,7 @@ struct logger_entry_v4 {
struct log_msg {
  union {
    unsigned char buf[LOGGER_ENTRY_MAX_LEN + 1];
    struct logger_entry_v4 entry;
    struct logger_entry_v4 entry_v4;
    struct logger_entry_v3 entry_v3;
    struct logger_entry_v2 entry_v2;
    struct logger_entry entry_v1;
    struct logger_entry entry;
  } __attribute__((aligned(4)));
#ifdef __cplusplus
  /* Matching log_time operators */
@@ -162,19 +114,12 @@ struct log_msg {
  }
  char* msg() {
    unsigned short hdr_size = entry.hdr_size;
    if (!hdr_size) {
      hdr_size = sizeof(entry_v1);
    }
    if ((hdr_size < sizeof(entry_v1)) || (hdr_size > sizeof(entry))) {
    if (hdr_size != sizeof(entry)) {
      return nullptr;
    }
    return reinterpret_cast<char*>(buf) + hdr_size;
  }
  unsigned int len() {
    return (entry.hdr_size ? entry.hdr_size
                           : static_cast<uint16_t>(sizeof(entry_v1))) +
           entry.len;
  }
  unsigned int len() { return entry.hdr_size + entry.len; }
#endif
};

+0 −18
Original line number Diff line number Diff line
@@ -148,24 +148,6 @@ static int logdWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, siz
    return 0;
  }

  /*
   *  struct {
   *      // what we provide to socket
   *      android_log_header_t header;
   *      // caller provides
   *      union {
   *          struct {
   *              char     prio;
   *              char     payload[];
   *          } string;
   *          struct {
   *              uint32_t tag
   *              char     payload[];
   *          } binary;
   *      };
   *  };
   */

  header.tid = gettid();
  header.realtime.tv_sec = ts->tv_sec;
  header.realtime.tv_nsec = ts->tv_nsec;
Loading