[compiler-rt] [asan] Use InternalMmapVector for error_message_buffer, reallocate wh… (PR #77488)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 10 22:13:49 PST 2024
https://github.com/Enna1 updated https://github.com/llvm/llvm-project/pull/77488
>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 1/5] [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());
>From 487b92f71493278f792d9204c40e0c5f920e9843 Mon Sep 17 00:00:00 2001
From: "xumingjie.enna1" <xumingjie.enna1 at bytedance.com>
Date: Wed, 10 Jan 2024 09:45:34 +0800
Subject: [PATCH 2/5] Revert "[asan] Use InternalMmapVector for
error_message_buffer, reallocate when the size of error_message_buffer is not
enough"
This reverts commit 37e6da69848ec29cf827e8d5ee01234453d6fc6d.
---
compiler-rt/lib/asan/asan_report.cpp | 29 +++++++++++++++-------------
1 file changed, 16 insertions(+), 13 deletions(-)
diff --git a/compiler-rt/lib/asan/asan_report.cpp b/compiler-rt/lib/asan/asan_report.cpp
index 1cd21bfbc0bfeb..7603e8131154ba 100644
--- a/compiler-rt/lib/asan/asan_report.cpp
+++ b/compiler-rt/lib/asan/asan_report.cpp
@@ -32,7 +32,8 @@ namespace __asan {
// -------------------- User-specified callbacks ----------------- {{{1
static void (*error_report_callback)(const char*);
-static InternalMmapVector<char> *error_message_buffer = nullptr;
+static char *error_message_buffer = nullptr;
+static uptr error_message_buffer_pos = 0;
static Mutex error_message_buf_mutex;
static const unsigned kAsanBuggyPcPoolSize = 25;
static __sanitizer::atomic_uintptr_t AsanBuggyPcPool[kAsanBuggyPcPoolSize];
@@ -41,15 +42,17 @@ void AppendToErrorMessageBuffer(const char *buffer) {
Lock l(&error_message_buf_mutex);
if (!error_message_buffer) {
error_message_buffer =
- new (GetGlobalLowLevelAllocator()) InternalMmapVector<char>();
- error_message_buffer->reserve(kErrorMessageBufferSize);
- error_message_buffer->push_back('\0');
+ (char*)MmapOrDieQuietly(kErrorMessageBufferSize, __func__);
+ error_message_buffer_pos = 0;
}
- 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);
+ 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);
}
// ---------------------- Helper functions ----------------------- {{{1
@@ -155,14 +158,14 @@ class ScopedInErrorReport {
// Copy the message buffer so that we could start logging without holding a
// lock that gets acquired during printing.
- InternalScopedString buffer_copy;
+ InternalMmapVector<char> buffer_copy(kErrorMessageBufferSize);
{
Lock l(&error_message_buf_mutex);
- buffer_copy.Append(error_message_buffer->data());
+ internal_memcpy(buffer_copy.data(),
+ error_message_buffer, kErrorMessageBufferSize);
// Clear error_message_buffer so that if we find other errors
// we don't re-log this error.
- error_message_buffer->clear();
- error_message_buffer->push_back('\0');
+ error_message_buffer_pos = 0;
}
LogFullErrorReport(buffer_copy.data());
>From 3cf10f33f5630c701578316279cc0f23def7e700 Mon Sep 17 00:00:00 2001
From: "xumingjie.enna1" <xumingjie.enna1 at bytedance.com>
Date: Wed, 10 Jan 2024 15:59:23 +0800
Subject: [PATCH 3/5] [asan] reallocate error_message_buffer when size is not
enough
---
compiler-rt/lib/asan/asan_report.cpp | 23 ++++++++++++-------
.../lib/sanitizer_common/sanitizer_common.h | 5 +++-
.../lib/sanitizer_common/sanitizer_posix.cpp | 8 +++----
3 files changed, 23 insertions(+), 13 deletions(-)
diff --git a/compiler-rt/lib/asan/asan_report.cpp b/compiler-rt/lib/asan/asan_report.cpp
index 7603e8131154ba..d37b4be9d9a34b 100644
--- a/compiler-rt/lib/asan/asan_report.cpp
+++ b/compiler-rt/lib/asan/asan_report.cpp
@@ -34,6 +34,7 @@ namespace __asan {
static void (*error_report_callback)(const char*);
static char *error_message_buffer = nullptr;
static uptr error_message_buffer_pos = 0;
+static uptr error_message_buffer_size = kErrorMessageBufferSize;
static Mutex error_message_buf_mutex;
static const unsigned kAsanBuggyPcPoolSize = 25;
static __sanitizer::atomic_uintptr_t AsanBuggyPcPool[kAsanBuggyPcPoolSize];
@@ -42,17 +43,23 @@ void AppendToErrorMessageBuffer(const char *buffer) {
Lock l(&error_message_buf_mutex);
if (!error_message_buffer) {
error_message_buffer =
- (char*)MmapOrDieQuietly(kErrorMessageBufferSize, __func__);
+ (char *)MmapOrDieQuietly(error_message_buffer_size, __func__);
error_message_buffer_pos = 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);
+ if (error_message_buffer_pos + length + 1 > error_message_buffer_size) {
+ uptr new_size = RoundUpToPowerOfTwo(error_message_buffer_size + length + 1);
+ RAW_CHECK(new_size > error_message_buffer_size);
+ char *new_buffer = (char *)MmapOrDieQuietly(new_size, __func__);
+ internal_memcpy(new_buffer, error_message_buffer,
+ error_message_buffer_size);
+ UnmapOrDieQuietly(error_message_buffer, error_message_buffer_size);
+ error_message_buffer = new_buffer;
+ error_message_buffer_size = new_size;
+ }
+ internal_strncpy(error_message_buffer + error_message_buffer_pos, buffer,
+ length + 1);
+ error_message_buffer_pos += length;
}
// ---------------------- Helper functions ----------------------- {{{1
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
index b99c0cffcbb116..96dfabfc09a795 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
@@ -94,7 +94,10 @@ void *MmapOrDie(uptr size, const char *mem_type, bool raw_report = false);
inline void *MmapOrDieQuietly(uptr size, const char *mem_type) {
return MmapOrDie(size, mem_type, /*raw_report*/ true);
}
-void UnmapOrDie(void *addr, uptr size);
+void UnmapOrDie(void *addr, uptr size, bool raw_report = false);
+inline void UnmapOrDieQuietly(void *addr, uptr size) {
+ UnmapOrDie(addr, size, /*raw_report*/ true);
+}
// Behaves just like MmapOrDie, but tolerates out of memory condition, in that
// case returns nullptr.
void *MmapOrDieOnFatalError(uptr size, const char *mem_type);
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp
index 8d2c5b2cefbea2..969327a7a0fbe0 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp
@@ -54,12 +54,12 @@ void *MmapOrDie(uptr size, const char *mem_type, bool raw_report) {
return (void *)res;
}
-void UnmapOrDie(void *addr, uptr size) {
+void UnmapOrDie(void *addr, uptr size, bool raw_report) {
if (!addr || !size) return;
uptr res = internal_munmap(addr, size);
int reserrno;
if (UNLIKELY(internal_iserror(res, &reserrno)))
- ReportMunmapFailureAndDie(addr, size, reserrno);
+ ReportMunmapFailureAndDie(addr, size, reserrno, raw_report);
DecreaseTotalMmap(size);
}
@@ -85,8 +85,8 @@ void *MmapAlignedOrDieOnFatalError(uptr size, uptr alignment,
CHECK(IsPowerOfTwo(size));
CHECK(IsPowerOfTwo(alignment));
uptr map_size = size + alignment;
- // mmap maps entire pages and rounds up map_size needs to be a an integral
- // number of pages.
+ // mmap maps entire pages and rounds up map_size needs to be a an integral
+ // number of pages.
// We need to be aware of this size for calculating end and for unmapping
// fragments before and after the alignment region.
map_size = RoundUpTo(map_size, GetPageSizeCached());
>From a22c438f0619f991c0a5828ff1ef0ca41c7971d7 Mon Sep 17 00:00:00 2001
From: "xumingjie.enna1" <xumingjie.enna1 at bytedance.com>
Date: Wed, 10 Jan 2024 17:28:49 +0800
Subject: [PATCH 4/5] Revert "[asan] reallocate error_message_buffer when size
is not enough"
This reverts commit 3cf10f33f5630c701578316279cc0f23def7e700.
---
compiler-rt/lib/asan/asan_report.cpp | 23 +++++++------------
.../lib/sanitizer_common/sanitizer_common.h | 5 +---
.../lib/sanitizer_common/sanitizer_posix.cpp | 8 +++----
3 files changed, 13 insertions(+), 23 deletions(-)
diff --git a/compiler-rt/lib/asan/asan_report.cpp b/compiler-rt/lib/asan/asan_report.cpp
index d37b4be9d9a34b..7603e8131154ba 100644
--- a/compiler-rt/lib/asan/asan_report.cpp
+++ b/compiler-rt/lib/asan/asan_report.cpp
@@ -34,7 +34,6 @@ namespace __asan {
static void (*error_report_callback)(const char*);
static char *error_message_buffer = nullptr;
static uptr error_message_buffer_pos = 0;
-static uptr error_message_buffer_size = kErrorMessageBufferSize;
static Mutex error_message_buf_mutex;
static const unsigned kAsanBuggyPcPoolSize = 25;
static __sanitizer::atomic_uintptr_t AsanBuggyPcPool[kAsanBuggyPcPoolSize];
@@ -43,23 +42,17 @@ void AppendToErrorMessageBuffer(const char *buffer) {
Lock l(&error_message_buf_mutex);
if (!error_message_buffer) {
error_message_buffer =
- (char *)MmapOrDieQuietly(error_message_buffer_size, __func__);
+ (char*)MmapOrDieQuietly(kErrorMessageBufferSize, __func__);
error_message_buffer_pos = 0;
}
uptr length = internal_strlen(buffer);
- if (error_message_buffer_pos + length + 1 > error_message_buffer_size) {
- uptr new_size = RoundUpToPowerOfTwo(error_message_buffer_size + length + 1);
- RAW_CHECK(new_size > error_message_buffer_size);
- char *new_buffer = (char *)MmapOrDieQuietly(new_size, __func__);
- internal_memcpy(new_buffer, error_message_buffer,
- error_message_buffer_size);
- UnmapOrDieQuietly(error_message_buffer, error_message_buffer_size);
- error_message_buffer = new_buffer;
- error_message_buffer_size = new_size;
- }
- internal_strncpy(error_message_buffer + error_message_buffer_pos, buffer,
- length + 1);
- error_message_buffer_pos += length;
+ 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);
}
// ---------------------- Helper functions ----------------------- {{{1
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
index 96dfabfc09a795..b99c0cffcbb116 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
@@ -94,10 +94,7 @@ void *MmapOrDie(uptr size, const char *mem_type, bool raw_report = false);
inline void *MmapOrDieQuietly(uptr size, const char *mem_type) {
return MmapOrDie(size, mem_type, /*raw_report*/ true);
}
-void UnmapOrDie(void *addr, uptr size, bool raw_report = false);
-inline void UnmapOrDieQuietly(void *addr, uptr size) {
- UnmapOrDie(addr, size, /*raw_report*/ true);
-}
+void UnmapOrDie(void *addr, uptr size);
// Behaves just like MmapOrDie, but tolerates out of memory condition, in that
// case returns nullptr.
void *MmapOrDieOnFatalError(uptr size, const char *mem_type);
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp
index 969327a7a0fbe0..8d2c5b2cefbea2 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp
@@ -54,12 +54,12 @@ void *MmapOrDie(uptr size, const char *mem_type, bool raw_report) {
return (void *)res;
}
-void UnmapOrDie(void *addr, uptr size, bool raw_report) {
+void UnmapOrDie(void *addr, uptr size) {
if (!addr || !size) return;
uptr res = internal_munmap(addr, size);
int reserrno;
if (UNLIKELY(internal_iserror(res, &reserrno)))
- ReportMunmapFailureAndDie(addr, size, reserrno, raw_report);
+ ReportMunmapFailureAndDie(addr, size, reserrno);
DecreaseTotalMmap(size);
}
@@ -85,8 +85,8 @@ void *MmapAlignedOrDieOnFatalError(uptr size, uptr alignment,
CHECK(IsPowerOfTwo(size));
CHECK(IsPowerOfTwo(alignment));
uptr map_size = size + alignment;
- // mmap maps entire pages and rounds up map_size needs to be a an integral
- // number of pages.
+ // mmap maps entire pages and rounds up map_size needs to be a an integral
+ // number of pages.
// We need to be aware of this size for calculating end and for unmapping
// fragments before and after the alignment region.
map_size = RoundUpTo(map_size, GetPageSizeCached());
>From 170270bdb604657c9a6903fefb7a72188a0033c1 Mon Sep 17 00:00:00 2001
From: "xumingjie.enna1" <xumingjie.enna1 at bytedance.com>
Date: Wed, 10 Jan 2024 17:29:05 +0800
Subject: [PATCH 5/5] Reland "[asan] Use InternalMmapVector for
error_message_buffer, reallocate when the size of error_message_buffer is not
enough"
Fix deadlock
Address review comments
---
compiler-rt/lib/asan/asan_report.cpp | 33 ++++++++++---------
.../lib/sanitizer_common/sanitizer_common.h | 9 ++---
.../lib/sanitizer_common/sanitizer_posix.cpp | 8 ++---
3 files changed, 26 insertions(+), 24 deletions(-)
diff --git a/compiler-rt/lib/asan/asan_report.cpp b/compiler-rt/lib/asan/asan_report.cpp
index 7603e8131154ba..d30908d6cc9943 100644
--- a/compiler-rt/lib/asan/asan_report.cpp
+++ b/compiler-rt/lib/asan/asan_report.cpp
@@ -24,6 +24,7 @@
#include "sanitizer_common/sanitizer_common.h"
#include "sanitizer_common/sanitizer_flags.h"
#include "sanitizer_common/sanitizer_interface_internal.h"
+#include "sanitizer_common/sanitizer_placement_new.h"
#include "sanitizer_common/sanitizer_report_decorator.h"
#include "sanitizer_common/sanitizer_stackdepot.h"
#include "sanitizer_common/sanitizer_symbolizer.h"
@@ -32,8 +33,11 @@ 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;
+typedef InternalMmapVectorNoCtor<char, true> ErrorMessageBuffer;
+static ALIGNED(
+ alignof(ErrorMessageBuffer)) char error_message_buffer_placeholder
+ [sizeof(ErrorMessageBuffer)];
+static ErrorMessageBuffer *error_message_buffer = nullptr;
static Mutex error_message_buf_mutex;
static const unsigned kAsanBuggyPcPoolSize = 25;
static __sanitizer::atomic_uintptr_t AsanBuggyPcPool[kAsanBuggyPcPoolSize];
@@ -42,17 +46,14 @@ 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 (error_message_buffer_placeholder) ErrorMessageBuffer();
+ error_message_buffer->Initialize(kErrorMessageBufferSize);
}
- 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();
+ uptr buffer_len = internal_strlen(buffer);
+ error_message_buffer->resize(error_message_buffer_len + buffer_len);
+ internal_memcpy(error_message_buffer->data() + error_message_buffer_len,
+ buffer, buffer_len);
}
// ---------------------- Helper functions ----------------------- {{{1
@@ -158,14 +159,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);
+ error_message_buffer->push_back('\0');
+ 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();
}
LogFullErrorReport(buffer_copy.data());
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
index b99c0cffcbb116..dd4c71640b4492 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
@@ -94,7 +94,7 @@ void *MmapOrDie(uptr size, const char *mem_type, bool raw_report = false);
inline void *MmapOrDieQuietly(uptr size, const char *mem_type) {
return MmapOrDie(size, mem_type, /*raw_report*/ true);
}
-void UnmapOrDie(void *addr, uptr size);
+void UnmapOrDie(void *addr, uptr size, bool raw_report = false);
// Behaves just like MmapOrDie, but tolerates out of memory condition, in that
// case returns nullptr.
void *MmapOrDieOnFatalError(uptr size, const char *mem_type);
@@ -510,7 +510,7 @@ inline int ToLower(int c) {
// A low-level vector based on mmap. May incur a significant memory overhead for
// small vectors.
// WARNING: The current implementation supports only POD types.
-template<typename T>
+template <typename T, bool raw_report = false>
class InternalMmapVectorNoCtor {
public:
using value_type = T;
@@ -520,7 +520,7 @@ class InternalMmapVectorNoCtor {
data_ = 0;
reserve(initial_capacity);
}
- void Destroy() { UnmapOrDie(data_, capacity_bytes_); }
+ void Destroy() { UnmapOrDie(data_, capacity_bytes_, raw_report); }
T &operator[](uptr i) {
CHECK_LT(i, size_);
return data_[i];
@@ -596,7 +596,8 @@ class InternalMmapVectorNoCtor {
CHECK_LE(size_, new_capacity);
uptr new_capacity_bytes =
RoundUpTo(new_capacity * sizeof(T), GetPageSizeCached());
- T *new_data = (T *)MmapOrDie(new_capacity_bytes, "InternalMmapVector");
+ T *new_data =
+ (T *)MmapOrDie(new_capacity_bytes, "InternalMmapVector", raw_report);
internal_memcpy(new_data, data_, size_ * sizeof(T));
UnmapOrDie(data_, capacity_bytes_);
data_ = new_data;
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp
index 8d2c5b2cefbea2..969327a7a0fbe0 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp
@@ -54,12 +54,12 @@ void *MmapOrDie(uptr size, const char *mem_type, bool raw_report) {
return (void *)res;
}
-void UnmapOrDie(void *addr, uptr size) {
+void UnmapOrDie(void *addr, uptr size, bool raw_report) {
if (!addr || !size) return;
uptr res = internal_munmap(addr, size);
int reserrno;
if (UNLIKELY(internal_iserror(res, &reserrno)))
- ReportMunmapFailureAndDie(addr, size, reserrno);
+ ReportMunmapFailureAndDie(addr, size, reserrno, raw_report);
DecreaseTotalMmap(size);
}
@@ -85,8 +85,8 @@ void *MmapAlignedOrDieOnFatalError(uptr size, uptr alignment,
CHECK(IsPowerOfTwo(size));
CHECK(IsPowerOfTwo(alignment));
uptr map_size = size + alignment;
- // mmap maps entire pages and rounds up map_size needs to be a an integral
- // number of pages.
+ // mmap maps entire pages and rounds up map_size needs to be a an integral
+ // number of pages.
// We need to be aware of this size for calculating end and for unmapping
// fragments before and after the alignment region.
map_size = RoundUpTo(map_size, GetPageSizeCached());
More information about the llvm-commits
mailing list