1 //===-- sanitizer_allocator_report.cc ---------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// Shared allocator error reporting for ThreadSanitizer, MemorySanitizer, etc.
13 //===----------------------------------------------------------------------===//
15 #include "sanitizer_allocator.h"
16 #include "sanitizer_allocator_report.h"
17 #include "sanitizer_common.h"
18 #include "sanitizer_report_decorator.h"
20 namespace __sanitizer {
22 class ScopedAllocatorErrorReport {
24 ScopedAllocatorErrorReport(const char *error_summary_,
25 const StackTrace *stack_)
26 : error_summary(error_summary_),
28 Printf("%s", d.Error());
30 ~ScopedAllocatorErrorReport() {
31 Printf("%s", d.Default());
33 PrintHintAllocatorCannotReturnNull();
34 ReportErrorSummary(error_summary, stack);
38 ScopedErrorReportLock lock;
39 const char *error_summary;
40 const StackTrace* const stack;
41 const SanitizerCommonDecorator d;
44 void NORETURN ReportCallocOverflow(uptr count, uptr size,
45 const StackTrace *stack) {
47 ScopedAllocatorErrorReport report("calloc-overflow", stack);
48 Report("ERROR: %s: calloc parameters overflow: count * size (%zd * %zd) "
49 "cannot be represented in type size_t\n", SanitizerToolName, count,
55 void NORETURN ReportPvallocOverflow(uptr size, const StackTrace *stack) {
57 ScopedAllocatorErrorReport report("pvalloc-overflow", stack);
58 Report("ERROR: %s: pvalloc parameters overflow: size 0x%zx rounded up to "
59 "system page size 0x%zx cannot be represented in type size_t\n",
60 SanitizerToolName, size, GetPageSizeCached());
65 void NORETURN ReportInvalidAllocationAlignment(uptr alignment,
66 const StackTrace *stack) {
68 ScopedAllocatorErrorReport report("invalid-allocation-alignment", stack);
69 Report("ERROR: %s: invalid allocation alignment: %zd, alignment must be a "
70 "power of two\n", SanitizerToolName, alignment);
75 void NORETURN ReportInvalidAlignedAllocAlignment(uptr size, uptr alignment,
76 const StackTrace *stack) {
78 ScopedAllocatorErrorReport report("invalid-aligned-alloc-alignment", stack);
80 Report("ERROR: %s: invalid alignment requested in "
81 "aligned_alloc: %zd, alignment must be a power of two and the "
82 "requested size 0x%zx must be a multiple of alignment\n",
83 SanitizerToolName, alignment, size);
85 Report("ERROR: %s: invalid alignment requested in aligned_alloc: %zd, "
86 "the requested size 0x%zx must be a multiple of alignment\n",
87 SanitizerToolName, alignment, size);
93 void NORETURN ReportInvalidPosixMemalignAlignment(uptr alignment,
94 const StackTrace *stack) {
96 ScopedAllocatorErrorReport report("invalid-posix-memalign-alignment",
98 Report("ERROR: %s: invalid alignment requested in "
99 "posix_memalign: %zd, alignment must be a power of two and a "
100 "multiple of sizeof(void*) == %zd\n", SanitizerToolName, alignment,
101 sizeof(void*)); // NOLINT
106 void NORETURN ReportAllocationSizeTooBig(uptr user_size, uptr max_size,
107 const StackTrace *stack) {
109 ScopedAllocatorErrorReport report("allocation-size-too-big", stack);
110 Report("ERROR: %s: requested allocation size 0x%zx exceeds maximum "
111 "supported size of 0x%zx\n", SanitizerToolName, user_size, max_size);
116 void NORETURN ReportOutOfMemory(uptr requested_size, const StackTrace *stack) {
118 ScopedAllocatorErrorReport report("out-of-memory", stack);
119 Report("ERROR: %s: allocator is out of memory trying to allocate 0x%zx "
120 "bytes\n", SanitizerToolName, requested_size);
125 } // namespace __sanitizer