Commits

Mark Salyzyn  committed bb0fbdb Merge

Merge "logd: liblog: 64-bit issues"

  • Participants
  • Parent commits 0a8a563, 7e2f83c

Comments (0)

Files changed (9)

File include/log/log_read.h

 
 #include <time.h>
 
+/* struct log_time is a wire-format variant of struct timespec */
 #define NS_PER_SEC 1000000000ULL
 #ifdef __cplusplus
-struct log_time : public timespec {
+struct log_time {
 public:
+    uint32_t tv_sec; // good to Feb 5 2106
+    uint32_t tv_nsec;
+
     log_time(const timespec &T)
     {
         tv_sec = T.tv_sec;
         tv_nsec = T.tv_nsec;
     }
+    log_time(const log_time &T)
+    {
+        tv_sec = T.tv_sec;
+        tv_nsec = T.tv_nsec;
+    }
+    log_time(uint32_t sec, uint32_t nsec)
+    {
+        tv_sec = sec;
+        tv_nsec = nsec;
+    }
     log_time()
     {
     }
     log_time(clockid_t id)
     {
-        clock_gettime(id, (timespec *) this);
+        timespec T;
+        clock_gettime(id, &T);
+        tv_sec = T.tv_sec;
+        tv_nsec = T.tv_nsec;
     }
     log_time(const char *T)
     {
         tv_sec = c[0] | (c[1] << 8) | (c[2] << 16) | (c[3] << 24);
         tv_nsec = c[4] | (c[5] << 8) | (c[6] << 16) | (c[7] << 24);
     }
+
+    // timespec
     bool operator== (const timespec &T) const
     {
         return (tv_sec == T.tv_sec) && (tv_nsec == T.tv_nsec);
     {
         return !(*this > T);
     }
+
+    // log_time
+    bool operator== (const log_time &T) const
+    {
+        return (tv_sec == T.tv_sec) && (tv_nsec == T.tv_nsec);
+    }
+    bool operator!= (const log_time &T) const
+    {
+        return !(*this == T);
+    }
+    bool operator< (const log_time &T) const
+    {
+        return (tv_sec < T.tv_sec)
+            || ((tv_sec == T.tv_sec) && (tv_nsec < T.tv_nsec));
+    }
+    bool operator>= (const log_time &T) const
+    {
+        return !(*this < T);
+    }
+    bool operator> (const log_time &T) const
+    {
+        return (tv_sec > T.tv_sec)
+            || ((tv_sec == T.tv_sec) && (tv_nsec > T.tv_nsec));
+    }
+    bool operator<= (const log_time &T) const
+    {
+        return !(*this > T);
+    }
+
     uint64_t nsec() const
     {
         return static_cast<uint64_t>(tv_sec) * NS_PER_SEC + tv_nsec;
     }
-};
+} __attribute__((__packed__));
 #else
-typedef struct timespec log_time;
+typedef struct log_time {
+    uint32_t tv_sec;
+    uint32_t tv_nsec;
+} __attribute__((__packed__)) log_time;
 #endif
 
 #endif /* define _LIBS_LOG_LOG_READ_H */

File include/log/logger.h

     int32_t     sec;    /* seconds since Epoch */
     int32_t     nsec;   /* nanoseconds */
     char        msg[0]; /* the entry's payload */
-};
+} __attribute__((__packed__));
 
 /*
  * The userspace structure for version 2 of the logger_entry ABI.
     int32_t     nsec;      /* nanoseconds */
     uint32_t    euid;      /* effective UID of logger */
     char        msg[0];    /* the entry's payload */
-};
+} __attribute__((__packed__));
 
 struct logger_entry_v3 {
     uint16_t    len;       /* length of the payload */
-    uint16_t    hdr_size;  /* sizeof(struct logger_entry_v2) */
+    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 maximum size of the log entry payload that can be

File liblog/logd_write.c

     newVec[0].iov_base   = (unsigned char *) &log_id_buf;
     newVec[0].iov_len    = sizeof_log_id_t;
 
+    struct timespec ts;
+    clock_gettime(CLOCK_REALTIME, &ts);
     log_time realtime_ts;
-    clock_gettime(CLOCK_REALTIME, &realtime_ts);
+    realtime_ts.tv_sec = ts.tv_sec;
+    realtime_ts.tv_nsec = ts.tv_nsec;
 
     newVec[1].iov_base   = (unsigned char *) &realtime_ts;
     newVec[1].iov_len    = sizeof(log_time);

File liblog/tests/liblog_benchmark.cpp

     for (int j = 0, i = 0; i < iters && j < 10*iters; ++i, ++j) {
         log_time ts;
         LOG_FAILURE_RETRY((
-            clock_gettime(CLOCK_REALTIME, &ts),
+            ts = log_time(CLOCK_REALTIME),
             android_btWriteLog(0, EVENT_TYPE_LONG, &ts, sizeof(ts))));
 
         for (;;) {

File liblog/tests/liblog_test.cpp

 
     ++signaled;
     if ((signal_time.tv_sec == 0) && (signal_time.tv_nsec == 0)) {
-        clock_gettime(CLOCK_MONOTONIC, &signal_time);
+        signal_time = log_time(CLOCK_MONOTONIC);
         signal_time.tv_sec += 2;
     }
 

File logd/LogBuffer.cpp

     pthread_mutex_init(&mLogElementsLock, NULL);
 }
 
-void LogBuffer::log(log_id_t log_id, struct timespec realtime,
+void LogBuffer::log(log_id_t log_id, log_time realtime,
                     uid_t uid, pid_t pid, const char *msg,
                     unsigned short len) {
     if ((log_id >= LOG_ID_MAX) || (log_id < 0)) {
     return LOG_BUFFER_SIZE;
 }
 
-struct timespec LogBuffer::flushTo(
-        SocketClient *reader, const struct timespec start, bool privileged,
+log_time LogBuffer::flushTo(
+        SocketClient *reader, const log_time start, bool privileged,
         bool (*filter)(const LogBufferElement *element, void *arg), void *arg) {
     LogBufferElementCollection::iterator it;
     log_time max = start;

File logd/LogBuffer.h

 
     LogBuffer(LastLogTimes *times);
 
-    void log(log_id_t log_id, struct timespec realtime,
+    void log(log_id_t log_id, log_time realtime,
              uid_t uid, pid_t pid, const char *msg, unsigned short len);
-    struct timespec flushTo(SocketClient *writer, const struct timespec start,
-                            bool privileged,
-                            bool (*filter)(const LogBufferElement *element, void *arg) = NULL,
-                            void *arg = NULL);
+    log_time flushTo(SocketClient *writer, const log_time start,
+                     bool privileged,
+                     bool (*filter)(const LogBufferElement *element, void *arg) = NULL,
+                     void *arg = NULL);
 
     void clear(log_id_t id);
     unsigned long getSize(log_id_t id);

File logd/LogBufferElement.cpp

 #include "LogBufferElement.h"
 #include "LogReader.h"
 
-const struct timespec LogBufferElement::FLUSH_ERROR = { 0, 0 };
+const log_time LogBufferElement::FLUSH_ERROR(0, 0);
 
-LogBufferElement::LogBufferElement(log_id_t log_id, struct timespec realtime, uid_t uid, pid_t pid, const char *msg, unsigned short len)
+LogBufferElement::LogBufferElement(log_id_t log_id, log_time realtime,
+                                   uid_t uid, pid_t pid, const char *msg,
+                                   unsigned short len)
         : mLogId(log_id)
         , mUid(uid)
         , mPid(pid)
     delete [] mMsg;
 }
 
-struct timespec LogBufferElement::flushTo(SocketClient *reader) {
+log_time LogBufferElement::flushTo(SocketClient *reader) {
     struct logger_entry_v3 entry;
     memset(&entry, 0, sizeof(struct logger_entry_v3));
     entry.hdr_size = sizeof(struct logger_entry_v3);

File logd/LogBufferElement.h

     const log_time mRealTime;
 
 public:
-    LogBufferElement(log_id_t log_id, struct timespec realtime,
+    LogBufferElement(log_id_t log_id, log_time realtime,
                      uid_t uid, pid_t pid, const char *msg, unsigned short len);
     virtual ~LogBufferElement();
 
     log_time getMonotonicTime(void) const { return mMonotonicTime; }
     log_time getRealTime(void) const { return mRealTime; }
 
-    static const struct timespec FLUSH_ERROR;
-    struct timespec flushTo(SocketClient *writer);
+    static const log_time FLUSH_ERROR;
+    log_time flushTo(SocketClient *writer);
 };
 
 #endif