[PATCH] D78018: [scudo][standalone] Split logs on Android

Kostya Kortchinsky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 13 07:29:51 PDT 2020


cryptoad created this revision.
cryptoad added reviewers: pcc, cferris, hctim, eugenis.
Herald added a project: Sanitizers.
Herald added a subscriber: Sanitizers.

The function used to log on Android will cut the message past
a certain amount of characters, which mostly materializes when
dumping the size class map on OOM.

This change splits the log message at newline boundaries.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78018

Files:
  compiler-rt/lib/scudo/standalone/linux.cpp


Index: compiler-rt/lib/scudo/standalone/linux.cpp
===================================================================
--- compiler-rt/lib/scudo/standalone/linux.cpp
+++ compiler-rt/lib/scudo/standalone/linux.cpp
@@ -171,6 +171,23 @@
 void outputRaw(const char *Buffer) {
   if (&async_safe_write_log) {
     constexpr s32 AndroidLogInfo = 4;
+    constexpr uptr MaxLength = 1024U;
+    char LocalBuffer[MaxLength];
+    while (strlen(Buffer) > MaxLength) {
+      uptr P;
+      for (P = MaxLength - 1; P > 0; P--) {
+        if (Buffer[P] == '\n') {
+          memcpy(LocalBuffer, Buffer, P);
+          LocalBuffer[P] = '\0';
+          async_safe_write_log(AndroidLogInfo, "scudo", LocalBuffer);
+          Buffer = &Buffer[P + 1];
+          break;
+        }
+      }
+      // If no newline was found, something is likely wrong.
+      if (P == 0)
+        return;
+    }
     async_safe_write_log(AndroidLogInfo, "scudo", Buffer);
   } else {
     write(2, Buffer, strlen(Buffer));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78018.256968.patch
Type: text/x-patch
Size: 989 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200413/7f885d6e/attachment.bin>


More information about the llvm-commits mailing list