Loading include/android/log.h +5 −2 Original line number Diff line number Diff line Loading @@ -803,10 +803,12 @@ int android_log_destroy(android_log_context *ctx); */ #if LOG_NDEBUG /* Production */ #define android_testLog(prio, tag) \ (__android_log_is_loggable(prio, tag, ANDROID_LOG_DEBUG) != 0) (__android_log_is_loggable_len(prio, tag, (tag && *tag) ? strlen(tag) : 0, \ ANDROID_LOG_DEBUG) != 0) #else #define android_testLog(prio, tag) \ (__android_log_is_loggable(prio, tag, ANDROID_LOG_VERBOSE) != 0) (__android_log_is_loggable_len(prio, tag, (tag && *tag) ? strlen(tag) : 0, \ ANDROID_LOG_VERBOSE) != 0) #endif /* Loading @@ -816,6 +818,7 @@ int android_log_destroy(android_log_context *ctx); * any other value. */ int __android_log_is_loggable(int prio, const char *tag, int default_prio); int __android_log_is_loggable_len(int prio, const char *tag, size_t len, int default_prio); int __android_log_security(); /* Device Owner is present */ Loading include/log/event_tag_map.h +8 −1 Original line number Diff line number Diff line Loading @@ -41,7 +41,14 @@ void android_closeEventTagMap(EventTagMap* map); /* * Look up a tag by index. Returns the tag string, or NULL if not found. */ const char* android_lookupEventTag(const EventTagMap* map, unsigned int tag); const char* android_lookupEventTag(const EventTagMap* map, unsigned int tag) __attribute__((deprecated("use android_lookupEventTag_len() instead to minimize MAP_PRIVATE copy-on-write memory impact"))); /* * Look up a tag by index. Returns the tag string & string length, or NULL if * not found. Returned string is not guaranteed to be nul terminated. */ const char* android_lookupEventTag_len(const EventTagMap* map, size_t* len, unsigned int tag); #ifdef __cplusplus } Loading include/log/logprint.h +1 −0 Original line number Diff line number Diff line Loading @@ -59,6 +59,7 @@ typedef struct AndroidLogEntry_t { int32_t pid; int32_t tid; const char * tag; size_t tagLen; size_t messageLen; const char * message; } AndroidLogEntry; Loading liblog/event_tag_map.c +36 −16 Original line number Diff line number Diff line Loading @@ -35,7 +35,8 @@ */ typedef struct EventTag { uint32_t tagIndex; const char* tagStr; char* tagStr; size_t tagLen; } EventTag; /* Loading Loading @@ -139,7 +140,8 @@ LIBLOG_ABI_PUBLIC void android_closeEventTagMap(EventTagMap* map) * * The entries are sorted by tag number, so we can do a binary search. */ LIBLOG_ABI_PUBLIC const char* android_lookupEventTag(const EventTagMap* map, LIBLOG_ABI_PUBLIC const char* android_lookupEventTag_len(const EventTagMap* map, size_t *len, unsigned int tag) { int lo = 0; Loading @@ -157,14 +159,36 @@ LIBLOG_ABI_PUBLIC const char* android_lookupEventTag(const EventTagMap* map, hi = mid - 1; } else { /* found */ if (len) *len = map->tagArray[mid].tagLen; /* * b/31456426 to check if gTest can detect copy-on-write issue * add the following line to break us: * map->tagArray[mid].tagStr[map->tagArray[mid].tagLen] = '\0'; * or explicitly use deprecated android_lookupEventTag(). */ return map->tagArray[mid].tagStr; } } errno = ENOENT; if (len) *len = 0; return NULL; } LIBLOG_ABI_PUBLIC const char* android_lookupEventTag(const EventTagMap* map, unsigned int tag) { size_t len; const char* tagStr = android_lookupEventTag_len(map, &len, tag); char* cp; if (!tagStr) return tagStr; cp = (char*)tagStr; cp += len; if (*cp) *cp = '\0'; /* Trigger copy on write :-( */ return tagStr; } /* * Crunch through the file, parsing the contents and creating a tag index. */ Loading Loading @@ -337,19 +361,13 @@ static int scanTagLine(char** pData, EventTag* tag, int lineNum) /* Determine whether "c" is a valid tag char. */ while (isalnum(*++cp) || (*cp == '_')) { } tag->tagLen = cp - tag->tagStr; if (*cp == '\n') { /* null terminate and return */ *cp = '\0'; } else if (isspace(*cp)) { /* CRLF or trailin spaces; zap this char, then scan for the '\n' */ *cp = '\0'; if (isspace(*cp)) { /* just ignore the rest of the line till \n TODO: read the tag description that follows the tag name */ while (*++cp != '\n') { } while (*cp != '\n') ++cp; } else { fprintf(stderr, "%s: invalid tag chars on line %d\n", OUT_TAG, lineNum); errno = EINVAL; Loading Loading @@ -387,10 +405,12 @@ static int sortTags(EventTagMap* map) for (i = 1; i < map->numTags; i++) { if (map->tagArray[i].tagIndex == map->tagArray[i - 1].tagIndex) { fprintf(stderr, "%s: duplicate tag entries (%" PRIu32 ":%s and %" PRIu32 ":%s)\n", "%s: duplicate tag entries (%" PRIu32 ":%.*s and %" PRIu32 ":%.*s)\n", OUT_TAG, map->tagArray[i].tagIndex, map->tagArray[i].tagStr, map->tagArray[i - 1].tagIndex, map->tagArray[i - 1].tagStr); map->tagArray[i].tagIndex, (int)map->tagArray[i].tagLen, map->tagArray[i].tagStr, map->tagArray[i - 1].tagIndex, (int)map->tagArray[i - 1].tagLen, map->tagArray[i - 1].tagStr); errno = EMLINK; return -1; } Loading liblog/fake_log_device.c +9 −0 Original line number Diff line number Diff line Loading @@ -718,3 +718,12 @@ LIBLOG_ABI_PUBLIC int __android_log_is_loggable(int prio, int logLevel = def; return logLevel >= 0 && prio >= logLevel; } LIBLOG_ABI_PUBLIC int __android_log_is_loggable_len(int prio, const char *tag __unused, size_t len __unused, int def) { int logLevel = def; return logLevel >= 0 && prio >= logLevel; } Loading
include/android/log.h +5 −2 Original line number Diff line number Diff line Loading @@ -803,10 +803,12 @@ int android_log_destroy(android_log_context *ctx); */ #if LOG_NDEBUG /* Production */ #define android_testLog(prio, tag) \ (__android_log_is_loggable(prio, tag, ANDROID_LOG_DEBUG) != 0) (__android_log_is_loggable_len(prio, tag, (tag && *tag) ? strlen(tag) : 0, \ ANDROID_LOG_DEBUG) != 0) #else #define android_testLog(prio, tag) \ (__android_log_is_loggable(prio, tag, ANDROID_LOG_VERBOSE) != 0) (__android_log_is_loggable_len(prio, tag, (tag && *tag) ? strlen(tag) : 0, \ ANDROID_LOG_VERBOSE) != 0) #endif /* Loading @@ -816,6 +818,7 @@ int android_log_destroy(android_log_context *ctx); * any other value. */ int __android_log_is_loggable(int prio, const char *tag, int default_prio); int __android_log_is_loggable_len(int prio, const char *tag, size_t len, int default_prio); int __android_log_security(); /* Device Owner is present */ Loading
include/log/event_tag_map.h +8 −1 Original line number Diff line number Diff line Loading @@ -41,7 +41,14 @@ void android_closeEventTagMap(EventTagMap* map); /* * Look up a tag by index. Returns the tag string, or NULL if not found. */ const char* android_lookupEventTag(const EventTagMap* map, unsigned int tag); const char* android_lookupEventTag(const EventTagMap* map, unsigned int tag) __attribute__((deprecated("use android_lookupEventTag_len() instead to minimize MAP_PRIVATE copy-on-write memory impact"))); /* * Look up a tag by index. Returns the tag string & string length, or NULL if * not found. Returned string is not guaranteed to be nul terminated. */ const char* android_lookupEventTag_len(const EventTagMap* map, size_t* len, unsigned int tag); #ifdef __cplusplus } Loading
include/log/logprint.h +1 −0 Original line number Diff line number Diff line Loading @@ -59,6 +59,7 @@ typedef struct AndroidLogEntry_t { int32_t pid; int32_t tid; const char * tag; size_t tagLen; size_t messageLen; const char * message; } AndroidLogEntry; Loading
liblog/event_tag_map.c +36 −16 Original line number Diff line number Diff line Loading @@ -35,7 +35,8 @@ */ typedef struct EventTag { uint32_t tagIndex; const char* tagStr; char* tagStr; size_t tagLen; } EventTag; /* Loading Loading @@ -139,7 +140,8 @@ LIBLOG_ABI_PUBLIC void android_closeEventTagMap(EventTagMap* map) * * The entries are sorted by tag number, so we can do a binary search. */ LIBLOG_ABI_PUBLIC const char* android_lookupEventTag(const EventTagMap* map, LIBLOG_ABI_PUBLIC const char* android_lookupEventTag_len(const EventTagMap* map, size_t *len, unsigned int tag) { int lo = 0; Loading @@ -157,14 +159,36 @@ LIBLOG_ABI_PUBLIC const char* android_lookupEventTag(const EventTagMap* map, hi = mid - 1; } else { /* found */ if (len) *len = map->tagArray[mid].tagLen; /* * b/31456426 to check if gTest can detect copy-on-write issue * add the following line to break us: * map->tagArray[mid].tagStr[map->tagArray[mid].tagLen] = '\0'; * or explicitly use deprecated android_lookupEventTag(). */ return map->tagArray[mid].tagStr; } } errno = ENOENT; if (len) *len = 0; return NULL; } LIBLOG_ABI_PUBLIC const char* android_lookupEventTag(const EventTagMap* map, unsigned int tag) { size_t len; const char* tagStr = android_lookupEventTag_len(map, &len, tag); char* cp; if (!tagStr) return tagStr; cp = (char*)tagStr; cp += len; if (*cp) *cp = '\0'; /* Trigger copy on write :-( */ return tagStr; } /* * Crunch through the file, parsing the contents and creating a tag index. */ Loading Loading @@ -337,19 +361,13 @@ static int scanTagLine(char** pData, EventTag* tag, int lineNum) /* Determine whether "c" is a valid tag char. */ while (isalnum(*++cp) || (*cp == '_')) { } tag->tagLen = cp - tag->tagStr; if (*cp == '\n') { /* null terminate and return */ *cp = '\0'; } else if (isspace(*cp)) { /* CRLF or trailin spaces; zap this char, then scan for the '\n' */ *cp = '\0'; if (isspace(*cp)) { /* just ignore the rest of the line till \n TODO: read the tag description that follows the tag name */ while (*++cp != '\n') { } while (*cp != '\n') ++cp; } else { fprintf(stderr, "%s: invalid tag chars on line %d\n", OUT_TAG, lineNum); errno = EINVAL; Loading Loading @@ -387,10 +405,12 @@ static int sortTags(EventTagMap* map) for (i = 1; i < map->numTags; i++) { if (map->tagArray[i].tagIndex == map->tagArray[i - 1].tagIndex) { fprintf(stderr, "%s: duplicate tag entries (%" PRIu32 ":%s and %" PRIu32 ":%s)\n", "%s: duplicate tag entries (%" PRIu32 ":%.*s and %" PRIu32 ":%.*s)\n", OUT_TAG, map->tagArray[i].tagIndex, map->tagArray[i].tagStr, map->tagArray[i - 1].tagIndex, map->tagArray[i - 1].tagStr); map->tagArray[i].tagIndex, (int)map->tagArray[i].tagLen, map->tagArray[i].tagStr, map->tagArray[i - 1].tagIndex, (int)map->tagArray[i - 1].tagLen, map->tagArray[i - 1].tagStr); errno = EMLINK; return -1; } Loading
liblog/fake_log_device.c +9 −0 Original line number Diff line number Diff line Loading @@ -718,3 +718,12 @@ LIBLOG_ABI_PUBLIC int __android_log_is_loggable(int prio, int logLevel = def; return logLevel >= 0 && prio >= logLevel; } LIBLOG_ABI_PUBLIC int __android_log_is_loggable_len(int prio, const char *tag __unused, size_t len __unused, int def) { int logLevel = def; return logLevel >= 0 && prio >= logLevel; }