1336817Sdim//===-- scudo_errors.cpp ----------------------------------------*- C++ -*-===//
2336817Sdim//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6336817Sdim//
7336817Sdim//===----------------------------------------------------------------------===//
8336817Sdim///
9336817Sdim/// Verbose termination functions.
10336817Sdim///
11336817Sdim//===----------------------------------------------------------------------===//
12336817Sdim
13336817Sdim#include "scudo_utils.h"
14336817Sdim
15336817Sdim#include "sanitizer_common/sanitizer_flags.h"
16336817Sdim
17336817Sdimnamespace __scudo {
18336817Sdim
19336817Sdimvoid NORETURN reportCallocOverflow(uptr Count, uptr Size) {
20336817Sdim  dieWithMessage("calloc parameters overflow: count * size (%zd * %zd) cannot "
21336817Sdim      "be represented with type size_t\n", Count, Size);
22336817Sdim}
23336817Sdim
24336817Sdimvoid NORETURN reportPvallocOverflow(uptr Size) {
25336817Sdim  dieWithMessage("pvalloc parameters overflow: size 0x%zx rounded up to system "
26336817Sdim      "page size 0x%zx cannot be represented in type size_t\n", Size,
27336817Sdim      GetPageSizeCached());
28336817Sdim}
29336817Sdim
30336817Sdimvoid NORETURN reportAllocationAlignmentTooBig(uptr Alignment,
31336817Sdim                                              uptr MaxAlignment) {
32336817Sdim  dieWithMessage("invalid allocation alignment: %zd exceeds maximum supported "
33336817Sdim      "allocation of %zd\n", Alignment, MaxAlignment);
34336817Sdim}
35336817Sdim
36336817Sdimvoid NORETURN reportAllocationAlignmentNotPowerOfTwo(uptr Alignment) {
37336817Sdim  dieWithMessage("invalid allocation alignment: %zd, alignment must be a power "
38336817Sdim      "of two\n", Alignment);
39336817Sdim}
40336817Sdim
41336817Sdimvoid NORETURN reportInvalidPosixMemalignAlignment(uptr Alignment) {
42360784Sdim  dieWithMessage(
43360784Sdim      "invalid alignment requested in posix_memalign: %zd, alignment"
44336817Sdim      " must be a power of two and a multiple of sizeof(void *) == %zd\n",
45360784Sdim      Alignment, sizeof(void *));
46336817Sdim}
47336817Sdim
48336817Sdimvoid NORETURN reportInvalidAlignedAllocAlignment(uptr Size, uptr Alignment) {
49336817Sdim#if SANITIZER_POSIX
50336817Sdim  dieWithMessage("invalid alignment requested in aligned_alloc: %zd, alignment "
51336817Sdim      "must be a power of two and the requested size 0x%zx must be a multiple "
52336817Sdim      "of alignment\n", Alignment, Size);
53336817Sdim#else
54336817Sdim  dieWithMessage("invalid alignment requested in aligned_alloc: %zd, the "
55336817Sdim      "requested size 0x%zx must be a multiple of alignment\n", Alignment,
56336817Sdim      Size);
57336817Sdim#endif
58336817Sdim}
59336817Sdim
60336817Sdimvoid NORETURN reportAllocationSizeTooBig(uptr UserSize, uptr TotalSize,
61336817Sdim                                         uptr MaxSize) {
62336817Sdim  dieWithMessage("requested allocation size 0x%zx (0x%zx after adjustments) "
63336817Sdim      "exceeds maximum supported size of 0x%zx\n", UserSize, TotalSize,
64336817Sdim      MaxSize);
65336817Sdim}
66336817Sdim
67336817Sdimvoid NORETURN reportRssLimitExceeded() {
68336817Sdim  dieWithMessage("specified RSS limit exceeded, currently set to "
69336817Sdim      "soft_rss_limit_mb=%zd\n", common_flags()->soft_rss_limit_mb);
70336817Sdim}
71336817Sdim
72336817Sdimvoid NORETURN reportOutOfMemory(uptr RequestedSize) {
73336817Sdim  dieWithMessage("allocator is out of memory trying to allocate 0x%zx bytes\n",
74336817Sdim                 RequestedSize);
75336817Sdim}
76336817Sdim
77336817Sdim}  // namespace __scudo
78