14adf2450SKostya Kortchinsky //===-- scudo_errors.cpp ----------------------------------------*- C++ -*-===//
24adf2450SKostya Kortchinsky //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
64adf2450SKostya Kortchinsky //
74adf2450SKostya Kortchinsky //===----------------------------------------------------------------------===//
84adf2450SKostya Kortchinsky ///
94adf2450SKostya Kortchinsky /// Verbose termination functions.
104adf2450SKostya Kortchinsky ///
114adf2450SKostya Kortchinsky //===----------------------------------------------------------------------===//
124adf2450SKostya Kortchinsky 
134adf2450SKostya Kortchinsky #include "scudo_utils.h"
144adf2450SKostya Kortchinsky 
154adf2450SKostya Kortchinsky #include "sanitizer_common/sanitizer_flags.h"
164adf2450SKostya Kortchinsky 
174adf2450SKostya Kortchinsky namespace __scudo {
184adf2450SKostya Kortchinsky 
reportCallocOverflow(uptr Count,uptr Size)194adf2450SKostya Kortchinsky void NORETURN reportCallocOverflow(uptr Count, uptr Size) {
204adf2450SKostya Kortchinsky   dieWithMessage("calloc parameters overflow: count * size (%zd * %zd) cannot "
214adf2450SKostya Kortchinsky       "be represented with type size_t\n", Count, Size);
224adf2450SKostya Kortchinsky }
234adf2450SKostya Kortchinsky 
reportPvallocOverflow(uptr Size)244adf2450SKostya Kortchinsky void NORETURN reportPvallocOverflow(uptr Size) {
254adf2450SKostya Kortchinsky   dieWithMessage("pvalloc parameters overflow: size 0x%zx rounded up to system "
264adf2450SKostya Kortchinsky       "page size 0x%zx cannot be represented in type size_t\n", Size,
274adf2450SKostya Kortchinsky       GetPageSizeCached());
284adf2450SKostya Kortchinsky }
294adf2450SKostya Kortchinsky 
reportAllocationAlignmentTooBig(uptr Alignment,uptr MaxAlignment)304adf2450SKostya Kortchinsky void NORETURN reportAllocationAlignmentTooBig(uptr Alignment,
314adf2450SKostya Kortchinsky                                               uptr MaxAlignment) {
324adf2450SKostya Kortchinsky   dieWithMessage("invalid allocation alignment: %zd exceeds maximum supported "
334adf2450SKostya Kortchinsky       "allocation of %zd\n", Alignment, MaxAlignment);
344adf2450SKostya Kortchinsky }
354adf2450SKostya Kortchinsky 
reportAllocationAlignmentNotPowerOfTwo(uptr Alignment)364adf2450SKostya Kortchinsky void NORETURN reportAllocationAlignmentNotPowerOfTwo(uptr Alignment) {
374adf2450SKostya Kortchinsky   dieWithMessage("invalid allocation alignment: %zd, alignment must be a power "
384adf2450SKostya Kortchinsky       "of two\n", Alignment);
394adf2450SKostya Kortchinsky }
404adf2450SKostya Kortchinsky 
reportInvalidPosixMemalignAlignment(uptr Alignment)414adf2450SKostya Kortchinsky void NORETURN reportInvalidPosixMemalignAlignment(uptr Alignment) {
42*c0fa6322SVitaly Buka   dieWithMessage(
43*c0fa6322SVitaly Buka       "invalid alignment requested in posix_memalign: %zd, alignment"
444adf2450SKostya Kortchinsky       " must be a power of two and a multiple of sizeof(void *) == %zd\n",
45*c0fa6322SVitaly Buka       Alignment, sizeof(void *));
464adf2450SKostya Kortchinsky }
474adf2450SKostya Kortchinsky 
reportInvalidAlignedAllocAlignment(uptr Size,uptr Alignment)484adf2450SKostya Kortchinsky void NORETURN reportInvalidAlignedAllocAlignment(uptr Size, uptr Alignment) {
494adf2450SKostya Kortchinsky #if SANITIZER_POSIX
504adf2450SKostya Kortchinsky   dieWithMessage("invalid alignment requested in aligned_alloc: %zd, alignment "
514adf2450SKostya Kortchinsky       "must be a power of two and the requested size 0x%zx must be a multiple "
524adf2450SKostya Kortchinsky       "of alignment\n", Alignment, Size);
534adf2450SKostya Kortchinsky #else
544adf2450SKostya Kortchinsky   dieWithMessage("invalid alignment requested in aligned_alloc: %zd, the "
554adf2450SKostya Kortchinsky       "requested size 0x%zx must be a multiple of alignment\n", Alignment,
564adf2450SKostya Kortchinsky       Size);
574adf2450SKostya Kortchinsky #endif
584adf2450SKostya Kortchinsky }
594adf2450SKostya Kortchinsky 
reportAllocationSizeTooBig(uptr UserSize,uptr TotalSize,uptr MaxSize)604adf2450SKostya Kortchinsky void NORETURN reportAllocationSizeTooBig(uptr UserSize, uptr TotalSize,
614adf2450SKostya Kortchinsky                                          uptr MaxSize) {
624adf2450SKostya Kortchinsky   dieWithMessage("requested allocation size 0x%zx (0x%zx after adjustments) "
634adf2450SKostya Kortchinsky       "exceeds maximum supported size of 0x%zx\n", UserSize, TotalSize,
644adf2450SKostya Kortchinsky       MaxSize);
654adf2450SKostya Kortchinsky }
664adf2450SKostya Kortchinsky 
reportRssLimitExceeded()674adf2450SKostya Kortchinsky void NORETURN reportRssLimitExceeded() {
684adf2450SKostya Kortchinsky   dieWithMessage("specified RSS limit exceeded, currently set to "
694adf2450SKostya Kortchinsky       "soft_rss_limit_mb=%zd\n", common_flags()->soft_rss_limit_mb);
704adf2450SKostya Kortchinsky }
714adf2450SKostya Kortchinsky 
reportOutOfMemory(uptr RequestedSize)724adf2450SKostya Kortchinsky void NORETURN reportOutOfMemory(uptr RequestedSize) {
734adf2450SKostya Kortchinsky   dieWithMessage("allocator is out of memory trying to allocate 0x%zx bytes\n",
744adf2450SKostya Kortchinsky                  RequestedSize);
754adf2450SKostya Kortchinsky }
764adf2450SKostya Kortchinsky 
774adf2450SKostya Kortchinsky }  // namespace __scudo
78