1 //===-- scudo_errors.cpp ----------------------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// Verbose termination functions.
11 ///
12 //===----------------------------------------------------------------------===//
13
14 #include "scudo_utils.h"
15
16 #include "sanitizer_common/sanitizer_flags.h"
17
18 namespace __scudo {
19
reportCallocOverflow(uptr Count,uptr Size)20 void NORETURN reportCallocOverflow(uptr Count, uptr Size) {
21 dieWithMessage("calloc parameters overflow: count * size (%zd * %zd) cannot "
22 "be represented with type size_t\n", Count, Size);
23 }
24
reportPvallocOverflow(uptr Size)25 void NORETURN reportPvallocOverflow(uptr Size) {
26 dieWithMessage("pvalloc parameters overflow: size 0x%zx rounded up to system "
27 "page size 0x%zx cannot be represented in type size_t\n", Size,
28 GetPageSizeCached());
29 }
30
reportAllocationAlignmentTooBig(uptr Alignment,uptr MaxAlignment)31 void NORETURN reportAllocationAlignmentTooBig(uptr Alignment,
32 uptr MaxAlignment) {
33 dieWithMessage("invalid allocation alignment: %zd exceeds maximum supported "
34 "allocation of %zd\n", Alignment, MaxAlignment);
35 }
36
reportAllocationAlignmentNotPowerOfTwo(uptr Alignment)37 void NORETURN reportAllocationAlignmentNotPowerOfTwo(uptr Alignment) {
38 dieWithMessage("invalid allocation alignment: %zd, alignment must be a power "
39 "of two\n", Alignment);
40 }
41
reportInvalidPosixMemalignAlignment(uptr Alignment)42 void NORETURN reportInvalidPosixMemalignAlignment(uptr Alignment) {
43 dieWithMessage("invalid alignment requested in posix_memalign: %zd, alignment"
44 " must be a power of two and a multiple of sizeof(void *) == %zd\n",
45 Alignment, sizeof(void *)); // NOLINT
46 }
47
reportInvalidAlignedAllocAlignment(uptr Size,uptr Alignment)48 void NORETURN reportInvalidAlignedAllocAlignment(uptr Size, uptr Alignment) {
49 #if SANITIZER_POSIX
50 dieWithMessage("invalid alignment requested in aligned_alloc: %zd, alignment "
51 "must be a power of two and the requested size 0x%zx must be a multiple "
52 "of alignment\n", Alignment, Size);
53 #else
54 dieWithMessage("invalid alignment requested in aligned_alloc: %zd, the "
55 "requested size 0x%zx must be a multiple of alignment\n", Alignment,
56 Size);
57 #endif
58 }
59
reportAllocationSizeTooBig(uptr UserSize,uptr TotalSize,uptr MaxSize)60 void NORETURN reportAllocationSizeTooBig(uptr UserSize, uptr TotalSize,
61 uptr MaxSize) {
62 dieWithMessage("requested allocation size 0x%zx (0x%zx after adjustments) "
63 "exceeds maximum supported size of 0x%zx\n", UserSize, TotalSize,
64 MaxSize);
65 }
66
reportRssLimitExceeded()67 void NORETURN reportRssLimitExceeded() {
68 dieWithMessage("specified RSS limit exceeded, currently set to "
69 "soft_rss_limit_mb=%zd\n", common_flags()->soft_rss_limit_mb);
70 }
71
reportOutOfMemory(uptr RequestedSize)72 void NORETURN reportOutOfMemory(uptr RequestedSize) {
73 dieWithMessage("allocator is out of memory trying to allocate 0x%zx bytes\n",
74 RequestedSize);
75 }
76
77 } // namespace __scudo
78