scudo_errors.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //===-- scudo_errors.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. /// Verbose termination functions.
  10. ///
  11. //===----------------------------------------------------------------------===//
  12. #include "scudo_utils.h"
  13. #include "sanitizer_common/sanitizer_flags.h"
  14. namespace __scudo {
  15. void NORETURN reportCallocOverflow(uptr Count, uptr Size) {
  16. dieWithMessage("calloc parameters overflow: count * size (%zd * %zd) cannot "
  17. "be represented with type size_t\n", Count, Size);
  18. }
  19. void NORETURN reportPvallocOverflow(uptr Size) {
  20. dieWithMessage("pvalloc parameters overflow: size 0x%zx rounded up to system "
  21. "page size 0x%zx cannot be represented in type size_t\n", Size,
  22. GetPageSizeCached());
  23. }
  24. void NORETURN reportAllocationAlignmentTooBig(uptr Alignment,
  25. uptr MaxAlignment) {
  26. dieWithMessage("invalid allocation alignment: %zd exceeds maximum supported "
  27. "allocation of %zd\n", Alignment, MaxAlignment);
  28. }
  29. void NORETURN reportAllocationAlignmentNotPowerOfTwo(uptr Alignment) {
  30. dieWithMessage("invalid allocation alignment: %zd, alignment must be a power "
  31. "of two\n", Alignment);
  32. }
  33. void NORETURN reportInvalidPosixMemalignAlignment(uptr Alignment) {
  34. dieWithMessage(
  35. "invalid alignment requested in posix_memalign: %zd, alignment"
  36. " must be a power of two and a multiple of sizeof(void *) == %zd\n",
  37. Alignment, sizeof(void *));
  38. }
  39. void NORETURN reportInvalidAlignedAllocAlignment(uptr Size, uptr Alignment) {
  40. #if SANITIZER_POSIX
  41. dieWithMessage("invalid alignment requested in aligned_alloc: %zd, alignment "
  42. "must be a power of two and the requested size 0x%zx must be a multiple "
  43. "of alignment\n", Alignment, Size);
  44. #else
  45. dieWithMessage("invalid alignment requested in aligned_alloc: %zd, the "
  46. "requested size 0x%zx must be a multiple of alignment\n", Alignment,
  47. Size);
  48. #endif
  49. }
  50. void NORETURN reportAllocationSizeTooBig(uptr UserSize, uptr TotalSize,
  51. uptr MaxSize) {
  52. dieWithMessage("requested allocation size 0x%zx (0x%zx after adjustments) "
  53. "exceeds maximum supported size of 0x%zx\n", UserSize, TotalSize,
  54. MaxSize);
  55. }
  56. void NORETURN reportRssLimitExceeded() {
  57. dieWithMessage("specified RSS limit exceeded, currently set to "
  58. "soft_rss_limit_mb=%zd\n", common_flags()->soft_rss_limit_mb);
  59. }
  60. void NORETURN reportOutOfMemory(uptr RequestedSize) {
  61. dieWithMessage("allocator is out of memory trying to allocate 0x%zx bytes\n",
  62. RequestedSize);
  63. }
  64. } // namespace __scudo