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 "wrappers_c.h"
  13. #include <stdint.h>
  14. namespace std {
  15. struct nothrow_t {};
  16. enum class align_val_t : size_t {};
  17. } // namespace std
  18. INTERFACE WEAK void *operator new(size_t size) {
  19. return Allocator.allocate(size, scudo::Chunk::Origin::New);
  20. }
  21. INTERFACE WEAK void *operator new[](size_t size) {
  22. return Allocator.allocate(size, scudo::Chunk::Origin::NewArray);
  23. }
  24. INTERFACE WEAK void *operator new(size_t size,
  25. std::nothrow_t const &) NOEXCEPT {
  26. return Allocator.allocate(size, scudo::Chunk::Origin::New);
  27. }
  28. INTERFACE WEAK void *operator new[](size_t size,
  29. std::nothrow_t const &) NOEXCEPT {
  30. return Allocator.allocate(size, scudo::Chunk::Origin::NewArray);
  31. }
  32. INTERFACE WEAK void *operator new(size_t size, std::align_val_t align) {
  33. return Allocator.allocate(size, scudo::Chunk::Origin::New,
  34. static_cast<scudo::uptr>(align));
  35. }
  36. INTERFACE WEAK void *operator new[](size_t size, std::align_val_t align) {
  37. return Allocator.allocate(size, scudo::Chunk::Origin::NewArray,
  38. static_cast<scudo::uptr>(align));
  39. }
  40. INTERFACE WEAK void *operator new(size_t size, std::align_val_t align,
  41. std::nothrow_t const &) NOEXCEPT {
  42. return Allocator.allocate(size, scudo::Chunk::Origin::New,
  43. static_cast<scudo::uptr>(align));
  44. }
  45. INTERFACE WEAK void *operator new[](size_t size, std::align_val_t align,
  46. std::nothrow_t const &) NOEXCEPT {
  47. return Allocator.allocate(size, scudo::Chunk::Origin::NewArray,
  48. static_cast<scudo::uptr>(align));
  49. }
  50. INTERFACE WEAK void operator delete(void *ptr) NOEXCEPT {
  51. Allocator.deallocate(ptr, scudo::Chunk::Origin::New);
  52. }
  53. INTERFACE WEAK void operator delete[](void *ptr) NOEXCEPT {
  54. Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray);
  55. }
  56. INTERFACE WEAK void operator delete(void *ptr,
  57. 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,
  71. std::align_val_t align) NOEXCEPT {
  72. Allocator.deallocate(ptr, scudo::Chunk::Origin::New, 0,
  73. static_cast<scudo::uptr>(align));
  74. }
  75. INTERFACE WEAK void operator delete[](void *ptr,
  76. std::align_val_t align) NOEXCEPT {
  77. Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, 0,
  78. static_cast<scudo::uptr>(align));
  79. }
  80. INTERFACE WEAK void operator delete(void *ptr, std::align_val_t align,
  81. std::nothrow_t const &) NOEXCEPT {
  82. Allocator.deallocate(ptr, scudo::Chunk::Origin::New, 0,
  83. static_cast<scudo::uptr>(align));
  84. }
  85. INTERFACE WEAK void operator delete[](void *ptr, std::align_val_t align,
  86. std::nothrow_t const &) NOEXCEPT {
  87. Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, 0,
  88. static_cast<scudo::uptr>(align));
  89. }
  90. INTERFACE WEAK void operator delete(void *ptr, size_t size,
  91. std::align_val_t align) NOEXCEPT {
  92. Allocator.deallocate(ptr, scudo::Chunk::Origin::New, size,
  93. static_cast<scudo::uptr>(align));
  94. }
  95. INTERFACE WEAK void operator delete[](void *ptr, size_t size,
  96. std::align_val_t align) NOEXCEPT {
  97. Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, size,
  98. static_cast<scudo::uptr>(align));
  99. }
  100. #endif // !SCUDO_ANDROID || !_BIONIC