[compiler-rt] [asan] Use InternalMmapVector for error_message_buffer, reallocate wh… (PR #77488)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 9 07:47:55 PST 2024
https://github.com/Enna1 created https://github.com/llvm/llvm-project/pull/77488
…en the size of error_message_buffer is not enough
>From 37e6da69848ec29cf827e8d5ee01234453d6fc6d Mon Sep 17 00:00:00 2001
From: "xumingjie.enna1" <xumingjie.enna1 at bytedance.com>
Date: Tue, 9 Jan 2024 23:27:25 +0800
Subject: [PATCH] [asan] Use InternalMmapVector for error_message_buffer,
reallocate when the size of error_message_buffer is not enough
---
compiler-rt/lib/asan/asan_report.cpp | 29 +++++++++++++---------------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/compiler-rt/lib/asan/asan_report.cpp b/compiler-rt/lib/asan/asan_report.cpp
index 7603e8131154ba..1cd21bfbc0bfeb 100644
--- a/compiler-rt/lib/asan/asan_report.cpp
+++ b/compiler-rt/lib/asan/asan_report.cpp
@@ -32,8 +32,7 @@ namespace __asan {
// -------------------- User-specified callbacks ----------------- {{{1
static void (*error_report_callback)(const char*);
-static char *error_message_buffer = nullptr;
-static uptr error_message_buffer_pos = 0;
+static InternalMmapVector<char> *error_message_buffer = nullptr;
static Mutex error_message_buf_mutex;
static const unsigned kAsanBuggyPcPoolSize = 25;
static __sanitizer::atomic_uintptr_t AsanBuggyPcPool[kAsanBuggyPcPoolSize];
@@ -42,17 +41,15 @@ void AppendToErrorMessageBuffer(const char *buffer) {
Lock l(&error_message_buf_mutex);
if (!error_message_buffer) {
error_message_buffer =
- (char*)MmapOrDieQuietly(kErrorMessageBufferSize, __func__);
- error_message_buffer_pos = 0;
+ new (GetGlobalLowLevelAllocator()) InternalMmapVector<char>();
+ error_message_buffer->reserve(kErrorMessageBufferSize);
+ error_message_buffer->push_back('\0');
}
- uptr length = internal_strlen(buffer);
- RAW_CHECK(kErrorMessageBufferSize >= error_message_buffer_pos);
- uptr remaining = kErrorMessageBufferSize - error_message_buffer_pos;
- internal_strncpy(error_message_buffer + error_message_buffer_pos,
- buffer, remaining);
- error_message_buffer[kErrorMessageBufferSize - 1] = '\0';
- // FIXME: reallocate the buffer instead of truncating the message.
- error_message_buffer_pos += Min(remaining, length);
+ uptr error_message_buffer_len = error_message_buffer->size() - 1;
+ uptr buffer_len = internal_strlen(buffer);
+ error_message_buffer->resize(error_message_buffer_len + buffer_len + 1);
+ internal_memcpy(error_message_buffer->data() + error_message_buffer_len,
+ buffer, buffer_len + 1);
}
// ---------------------- Helper functions ----------------------- {{{1
@@ -158,14 +155,14 @@ class ScopedInErrorReport {
// Copy the message buffer so that we could start logging without holding a
// lock that gets acquired during printing.
- InternalMmapVector<char> buffer_copy(kErrorMessageBufferSize);
+ InternalScopedString buffer_copy;
{
Lock l(&error_message_buf_mutex);
- internal_memcpy(buffer_copy.data(),
- error_message_buffer, kErrorMessageBufferSize);
+ buffer_copy.Append(error_message_buffer->data());
// Clear error_message_buffer so that if we find other errors
// we don't re-log this error.
- error_message_buffer_pos = 0;
+ error_message_buffer->clear();
+ error_message_buffer->push_back('\0');
}
LogFullErrorReport(buffer_copy.data());
More information about the llvm-commits
mailing list