wrappers_cpp.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //===-- wrappers_cpp.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. #include "platform.h"
  9. // Skip this compilation unit if compiled as part of Bionic.
  10. #if !SCUDO_ANDROID || !_BIONIC
  11. #include "allocator_config.h"
  12. #include <stdint.h>
  13. extern "C" void malloc_postinit();
  14. extern HIDDEN scudo::Allocator<scudo::Config, malloc_postinit> Allocator;
  15. namespace std {
  16. struct nothrow_t {};
  17. enum class align_val_t : size_t {};
  18. } // namespace std
  19. INTERFACE WEAK void *operator new(size_t size) {
  20. return Allocator.allocate(size, scudo::Chunk::Origin::New);
  21. }
  22. INTERFACE WEAK void *operator new[](size_t size) {
  23. return Allocator.allocate(size, scudo::Chunk::Origin::NewArray);
  24. }
  25. INTERFACE WEAK void *operator new(size_t size,
  26. std::nothrow_t const &) NOEXCEPT {
  27. return Allocator.allocate(size, scudo::Chunk::Origin::New);
  28. }
  29. INTERFACE WEAK void *operator new[](size_t size,
  30. std::nothrow_t const &) NOEXCEPT {
  31. return Allocator.allocate(size, scudo::Chunk::Origin::NewArray);
  32. }
  33. INTERFACE WEAK void *operator new(size_t size, std::align_val_t align) {
  34. return Allocator.allocate(size, scudo::Chunk::Origin::New,
  35. static_cast<scudo::uptr>(align));
  36. }
  37. INTERFACE WEAK void *operator new[](size_t size, std::align_val_t align) {
  38. return Allocator.allocate(size, scudo::Chunk::Origin::NewArray,
  39. static_cast<scudo::uptr>(align));
  40. }
  41. INTERFACE WEAK void *operator new(size_t size, std::align_val_t align,
  42. std::nothrow_t const &) NOEXCEPT {
  43. return Allocator.allocate(size, scudo::Chunk::Origin::New,
  44. static_cast<scudo::uptr>(align));
  45. }
  46. INTERFACE WEAK void *operator new[](size_t size, std::align_val_t align,
  47. std::nothrow_t const &) NOEXCEPT {
  48. return Allocator.allocate(size, scudo::Chunk::Origin::NewArray,
  49. static_cast<scudo::uptr>(align));
  50. }
  51. INTERFACE WEAK void operator delete(void *ptr)NOEXCEPT {
  52. Allocator.deallocate(ptr, scudo::Chunk::Origin::New);
  53. }
  54. INTERFACE WEAK void operator delete[](void *ptr) NOEXCEPT {
  55. Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray);
  56. }
  57. INTERFACE WEAK void operator delete(void *ptr, std::nothrow_t const &)NOEXCEPT {
  58. Allocator.deallocate(ptr, scudo::Chunk::Origin::New);
  59. }
  60. INTERFACE WEAK void operator delete[](void *ptr,
  61. std::nothrow_t const &) NOEXCEPT {
  62. Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray);
  63. }
  64. INTERFACE WEAK void operator delete(void *ptr, size_t size)NOEXCEPT {
  65. Allocator.deallocate(ptr, scudo::Chunk::Origin::New, size);
  66. }
  67. INTERFACE WEAK void operator delete[](void *ptr, size_t size) NOEXCEPT {
  68. Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, size);
  69. }
  70. INTERFACE WEAK void operator delete(void *ptr, std::align_val_t align)NOEXCEPT {
  71. Allocator.deallocate(ptr, scudo::Chunk::Origin::New, 0,
  72. static_cast<scudo::uptr>(align));
  73. }
  74. INTERFACE WEAK void operator delete[](void *ptr,
  75. std::align_val_t align) NOEXCEPT {
  76. Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, 0,
  77. static_cast<scudo::uptr>(align));
  78. }
  79. INTERFACE WEAK void operator delete(void *ptr, std::align_val_t align,
  80. std::nothrow_t const &)NOEXCEPT {
  81. Allocator.deallocate(ptr, scudo::Chunk::Origin::New, 0,
  82. static_cast<scudo::uptr>(align));
  83. }
  84. INTERFACE WEAK void operator delete[](void *ptr, std::align_val_t align,
  85. std::nothrow_t const &) NOEXCEPT {
  86. Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, 0,
  87. static_cast<scudo::uptr>(align));
  88. }
  89. INTERFACE WEAK void operator delete(void *ptr, size_t size,
  90. std::align_val_t align)NOEXCEPT {
  91. Allocator.deallocate(ptr, scudo::Chunk::Origin::New, size,
  92. static_cast<scudo::uptr>(align));
  93. }
  94. INTERFACE WEAK void operator delete[](void *ptr, size_t size,
  95. std::align_val_t align) NOEXCEPT {
  96. Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, size,
  97. static_cast<scudo::uptr>(align));
  98. }
  99. #endif // !SCUDO_ANDROID || !_BIONIC