Update LOCAL_PATCHES after libsanitizer merge.
[official-gcc.git] / libsanitizer / sanitizer_common / sanitizer_allocator_report.cc
bloba09fb91e6b1b7cf00e181cb6cfc04933c39c39c0
1 //===-- sanitizer_allocator_report.cc ---------------------------*- C++ -*-===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 ///
8 /// \file
9 /// Shared allocator error reporting for ThreadSanitizer, MemorySanitizer, etc.
10 ///
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 {
21 public:
22 ScopedAllocatorErrorReport(const char *error_summary_,
23 const StackTrace *stack_)
24 : error_summary(error_summary_),
25 stack(stack_) {
26 Printf("%s", d.Error());
28 ~ScopedAllocatorErrorReport() {
29 Printf("%s", d.Default());
30 stack->Print();
31 PrintHintAllocatorCannotReturnNull();
32 ReportErrorSummary(error_summary, stack);
35 private:
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,
48 size);
50 Die();
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());
60 Die();
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);
70 Die();
73 void NORETURN ReportInvalidAlignedAllocAlignment(uptr size, uptr alignment,
74 const StackTrace *stack) {
76 ScopedAllocatorErrorReport report("invalid-aligned-alloc-alignment", stack);
77 #if SANITIZER_POSIX
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);
82 #else
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);
86 #endif
88 Die();
91 void NORETURN ReportInvalidPosixMemalignAlignment(uptr alignment,
92 const StackTrace *stack) {
94 ScopedAllocatorErrorReport report("invalid-posix-memalign-alignment",
95 stack);
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
101 Die();
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);
111 Die();
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);
120 Die();
123 } // namespace __sanitizer