summaryrefslogtreecommitdiff
path: root/lib/lsan
diff options
context:
space:
mode:
authorAlex Shlyapnikov <alekseys@google.com>2018-06-11 17:33:53 +0000
committerAlex Shlyapnikov <alekseys@google.com>2018-06-11 17:33:53 +0000
commitf2f5d0836a38981d7ca46ac145467880aae82e2d (patch)
treedc7cc2e66f04fa2926a7e69b1f5fd67a91292867 /lib/lsan
parent14601e5de1d9b20da589f2d9047745dad52d56b8 (diff)
[Sanitizers] Move pvalloc overflow tests to common.
Summary: Now all sanitizers with improved allocator error reporting are covered by these common tests. Also, add pvalloc-specific checks to LSan. HWASan is not covered by sanitizer_common, hence its own pvalloc and other allocator tests. Reviewers: vitalybuka Subscribers: srhines, kubamracek, delcypher, #sanitizers, llvm-commits Differential Revision: https://reviews.llvm.org/D47970 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@334424 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/lsan')
-rw-r--r--lib/lsan/lsan_allocator.cc13
-rw-r--r--lib/lsan/lsan_allocator.h1
-rw-r--r--lib/lsan/lsan_interceptors.cc8
3 files changed, 15 insertions, 7 deletions
diff --git a/lib/lsan/lsan_allocator.cc b/lib/lsan/lsan_allocator.cc
index f959a3de0..c58c35480 100644
--- a/lib/lsan/lsan_allocator.cc
+++ b/lib/lsan/lsan_allocator.cc
@@ -198,6 +198,19 @@ void *lsan_valloc(uptr size, const StackTrace &stack) {
Allocate(stack, size, GetPageSizeCached(), kAlwaysClearMemory));
}
+void *lsan_pvalloc(uptr size, const StackTrace &stack) {
+ uptr PageSize = GetPageSizeCached();
+ if (UNLIKELY(CheckForPvallocOverflow(size, PageSize))) {
+ errno = errno_ENOMEM;
+ if (AllocatorMayReturnNull())
+ return nullptr;
+ ReportPvallocOverflow(size, &stack);
+ }
+ // pvalloc(0) should allocate one page.
+ size = size ? RoundUpTo(size, PageSize) : PageSize;
+ return SetErrnoOnNull(Allocate(stack, size, PageSize, kAlwaysClearMemory));
+}
+
uptr lsan_mz_size(const void *p) {
return GetMallocUsableSize(p);
}
diff --git a/lib/lsan/lsan_allocator.h b/lib/lsan/lsan_allocator.h
index 169fcc442..7c70bb6d9 100644
--- a/lib/lsan/lsan_allocator.h
+++ b/lib/lsan/lsan_allocator.h
@@ -99,6 +99,7 @@ void lsan_free(void *p);
void *lsan_realloc(void *p, uptr size, const StackTrace &stack);
void *lsan_calloc(uptr nmemb, uptr size, const StackTrace &stack);
void *lsan_valloc(uptr size, const StackTrace &stack);
+void *lsan_pvalloc(uptr size, const StackTrace &stack);
uptr lsan_mz_size(const void *p);
} // namespace __lsan
diff --git a/lib/lsan/lsan_interceptors.cc b/lib/lsan/lsan_interceptors.cc
index e60b1ab7c..aee726f83 100644
--- a/lib/lsan/lsan_interceptors.cc
+++ b/lib/lsan/lsan_interceptors.cc
@@ -165,13 +165,7 @@ INTERCEPTOR(int, mallopt, int cmd, int value) {
INTERCEPTOR(void*, pvalloc, uptr size) {
ENSURE_LSAN_INITED;
GET_STACK_TRACE_MALLOC;
- uptr PageSize = GetPageSizeCached();
- size = RoundUpTo(size, PageSize);
- if (size == 0) {
- // pvalloc(0) should allocate one page.
- size = PageSize;
- }
- return Allocate(stack, size, GetPageSizeCached(), kAlwaysClearMemory);
+ return lsan_pvalloc(size, stack);
}
#define LSAN_MAYBE_INTERCEPT_PVALLOC INTERCEPT_FUNCTION(pvalloc)
#else