1 //===-- sanitizer_allocator_report.cc ---------------------------*- C++ -*-===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
9 /// Shared allocator error reporting for ThreadSanitizer, MemorySanitizer, etc.
11 //===----------------------------------------------------------------------===//
13 #include "sanitizer_allocator.h"
14 #include "sanitizer_allocator_report.h"
15 #include "sanitizer_common.h"
16 #include "sanitizer_report_decorator.h"
18 namespace __sanitizer
{
20 class ScopedAllocatorErrorReport
{
22 ScopedAllocatorErrorReport(const char *error_summary_
,
23 const StackTrace
*stack_
)
24 : error_summary(error_summary_
),
26 Printf("%s", d
.Error());
28 ~ScopedAllocatorErrorReport() {
29 Printf("%s", d
.Default());
31 PrintHintAllocatorCannotReturnNull();
32 ReportErrorSummary(error_summary
, stack
);
36 ScopedErrorReportLock lock
;
37 const char *error_summary
;
38 const StackTrace
* const stack
;
39 const SanitizerCommonDecorator d
;
42 void NORETURN
ReportCallocOverflow(uptr count
, uptr size
,
43 const StackTrace
*stack
) {
45 ScopedAllocatorErrorReport
report("calloc-overflow", stack
);
46 Report("ERROR: %s: calloc parameters overflow: count * size (%zd * %zd) "
47 "cannot be represented in type size_t\n", SanitizerToolName
, count
,
53 void NORETURN
ReportPvallocOverflow(uptr size
, const StackTrace
*stack
) {
55 ScopedAllocatorErrorReport
report("pvalloc-overflow", stack
);
56 Report("ERROR: %s: pvalloc parameters overflow: size 0x%zx rounded up to "
57 "system page size 0x%zx cannot be represented in type size_t\n",
58 SanitizerToolName
, size
, GetPageSizeCached());
63 void NORETURN
ReportInvalidAllocationAlignment(uptr alignment
,
64 const StackTrace
*stack
) {
66 ScopedAllocatorErrorReport
report("invalid-allocation-alignment", stack
);
67 Report("ERROR: %s: invalid allocation alignment: %zd, alignment must be a "
68 "power of two\n", SanitizerToolName
, alignment
);
73 void NORETURN
ReportInvalidAlignedAllocAlignment(uptr size
, uptr alignment
,
74 const StackTrace
*stack
) {
76 ScopedAllocatorErrorReport
report("invalid-aligned-alloc-alignment", stack
);
78 Report("ERROR: %s: invalid alignment requested in "
79 "aligned_alloc: %zd, alignment must be a power of two and the "
80 "requested size 0x%zx must be a multiple of alignment\n",
81 SanitizerToolName
, alignment
, size
);
83 Report("ERROR: %s: invalid alignment requested in aligned_alloc: %zd, "
84 "the requested size 0x%zx must be a multiple of alignment\n",
85 SanitizerToolName
, alignment
, size
);
91 void NORETURN
ReportInvalidPosixMemalignAlignment(uptr alignment
,
92 const StackTrace
*stack
) {
94 ScopedAllocatorErrorReport
report("invalid-posix-memalign-alignment",
96 Report("ERROR: %s: invalid alignment requested in "
97 "posix_memalign: %zd, alignment must be a power of two and a "
98 "multiple of sizeof(void*) == %zd\n", SanitizerToolName
, alignment
,
99 sizeof(void*)); // NOLINT
104 void NORETURN
ReportAllocationSizeTooBig(uptr user_size
, uptr max_size
,
105 const StackTrace
*stack
) {
107 ScopedAllocatorErrorReport
report("allocation-size-too-big", stack
);
108 Report("ERROR: %s: requested allocation size 0x%zx exceeds maximum "
109 "supported size of 0x%zx\n", SanitizerToolName
, user_size
, max_size
);
114 void NORETURN
ReportOutOfMemory(uptr requested_size
, const StackTrace
*stack
) {
116 ScopedAllocatorErrorReport
report("out-of-memory", stack
);
117 Report("ERROR: %s: allocator is out of memory trying to allocate 0x%zx "
118 "bytes\n", SanitizerToolName
, requested_size
);
123 } // namespace __sanitizer