[clang][extract-api] Emit "navigator" property of "name" in SymbolGraph
[llvm-project.git] / compiler-rt / lib / sanitizer_common / sanitizer_allocator_report.cpp
blob1c6520819ef9397b489b030b0a106ef3235d26e6
1 //===-- sanitizer_allocator_report.cpp --------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// Shared allocator error reporting for ThreadSanitizer, MemorySanitizer, etc.
11 ///
12 //===----------------------------------------------------------------------===//
14 #include "sanitizer_allocator.h"
15 #include "sanitizer_allocator_report.h"
16 #include "sanitizer_common.h"
17 #include "sanitizer_report_decorator.h"
19 namespace __sanitizer {
21 class ScopedAllocatorErrorReport {
22 public:
23 ScopedAllocatorErrorReport(const char *error_summary_,
24 const StackTrace *stack_)
25 : error_summary(error_summary_),
26 stack(stack_) {
27 Printf("%s", d.Error());
29 ~ScopedAllocatorErrorReport() {
30 Printf("%s", d.Default());
31 stack->Print();
32 PrintHintAllocatorCannotReturnNull();
33 ReportErrorSummary(error_summary, stack);
36 private:
37 ScopedErrorReportLock lock;
38 const char *error_summary;
39 const StackTrace* const stack;
40 const SanitizerCommonDecorator d;
43 void NORETURN ReportCallocOverflow(uptr count, uptr size,
44 const StackTrace *stack) {
46 ScopedAllocatorErrorReport report("calloc-overflow", stack);
47 Report("ERROR: %s: calloc parameters overflow: count * size (%zd * %zd) "
48 "cannot be represented in type size_t\n", SanitizerToolName, count,
49 size);
51 Die();
54 void NORETURN ReportReallocArrayOverflow(uptr count, uptr size,
55 const StackTrace *stack) {
57 ScopedAllocatorErrorReport report("reallocarray-overflow", stack);
58 Report(
59 "ERROR: %s: reallocarray parameters overflow: count * size (%zd * %zd) "
60 "cannot be represented in type size_t\n",
61 SanitizerToolName, count, size);
63 Die();
66 void NORETURN ReportPvallocOverflow(uptr size, const StackTrace *stack) {
68 ScopedAllocatorErrorReport report("pvalloc-overflow", stack);
69 Report("ERROR: %s: pvalloc parameters overflow: size 0x%zx rounded up to "
70 "system page size 0x%zx cannot be represented in type size_t\n",
71 SanitizerToolName, size, GetPageSizeCached());
73 Die();
76 void NORETURN ReportInvalidAllocationAlignment(uptr alignment,
77 const StackTrace *stack) {
79 ScopedAllocatorErrorReport report("invalid-allocation-alignment", stack);
80 Report("ERROR: %s: invalid allocation alignment: %zd, alignment must be a "
81 "power of two\n", SanitizerToolName, alignment);
83 Die();
86 void NORETURN ReportInvalidAlignedAllocAlignment(uptr size, uptr alignment,
87 const StackTrace *stack) {
89 ScopedAllocatorErrorReport report("invalid-aligned-alloc-alignment", stack);
90 #if SANITIZER_POSIX
91 Report("ERROR: %s: invalid alignment requested in "
92 "aligned_alloc: %zd, alignment must be a power of two and the "
93 "requested size 0x%zx must be a multiple of alignment\n",
94 SanitizerToolName, alignment, size);
95 #else
96 Report("ERROR: %s: invalid alignment requested in aligned_alloc: %zd, "
97 "the requested size 0x%zx must be a multiple of alignment\n",
98 SanitizerToolName, alignment, size);
99 #endif
101 Die();
104 void NORETURN ReportInvalidPosixMemalignAlignment(uptr alignment,
105 const StackTrace *stack) {
107 ScopedAllocatorErrorReport report("invalid-posix-memalign-alignment",
108 stack);
109 Report(
110 "ERROR: %s: invalid alignment requested in "
111 "posix_memalign: %zd, alignment must be a power of two and a "
112 "multiple of sizeof(void*) == %zd\n",
113 SanitizerToolName, alignment, sizeof(void *));
115 Die();
118 void NORETURN ReportAllocationSizeTooBig(uptr user_size, uptr max_size,
119 const StackTrace *stack) {
121 ScopedAllocatorErrorReport report("allocation-size-too-big", stack);
122 Report("ERROR: %s: requested allocation size 0x%zx exceeds maximum "
123 "supported size of 0x%zx\n", SanitizerToolName, user_size, max_size);
125 Die();
128 void NORETURN ReportOutOfMemory(uptr requested_size, const StackTrace *stack) {
130 ScopedAllocatorErrorReport report("out-of-memory", stack);
131 Report("ERROR: %s: allocator is out of memory trying to allocate 0x%zx "
132 "bytes\n", SanitizerToolName, requested_size);
134 Die();
137 void NORETURN ReportRssLimitExceeded(const StackTrace *stack) {
139 ScopedAllocatorErrorReport report("rss-limit-exceeded", stack);
140 Report("ERROR: %s: allocator exceeded the RSS limit\n", SanitizerToolName);
142 Die();
145 } // namespace __sanitizer