allocator_shim_override_libc_symbols.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. // Its purpose is to preempt the Libc symbols for malloc/new so they call the
  5. // shim layer entry points.
  6. #ifdef BASE_ALLOCATOR_ALLOCATOR_SHIM_OVERRIDE_LIBC_SYMBOLS_H_
  7. #error This header is meant to be included only once by allocator_shim.cc
  8. #endif
  9. #define BASE_ALLOCATOR_ALLOCATOR_SHIM_OVERRIDE_LIBC_SYMBOLS_H_
  10. #include "build/build_config.h"
  11. #if BUILDFLAG(IS_APPLE)
  12. #include <malloc/malloc.h>
  13. #else
  14. #include <malloc.h>
  15. #endif
  16. #include "base/allocator/allocator_shim_internals.h"
  17. extern "C" {
  18. // WARNING: Whenever a new function is added there (which, surprisingly enough,
  19. // happens. For instance glibc 2.33 introduced mallinfo2(), which we don't
  20. // support... yet?), it MUST be added to build/linux/chrome.map.
  21. //
  22. // Otherwise the new symbol is not exported from Chromium's main binary, which
  23. // is necessary to override libc's weak symbol, which in turn is necessary to
  24. // intercept calls made by dynamic libraries. See crbug.com/1292206 for such
  25. // an example.
  26. SHIM_ALWAYS_EXPORT void* malloc(size_t size) __THROW {
  27. return ShimMalloc(size, nullptr);
  28. }
  29. SHIM_ALWAYS_EXPORT void free(void* ptr) __THROW {
  30. ShimFree(ptr, nullptr);
  31. }
  32. SHIM_ALWAYS_EXPORT void* realloc(void* ptr, size_t size) __THROW {
  33. return ShimRealloc(ptr, size, nullptr);
  34. }
  35. SHIM_ALWAYS_EXPORT void* calloc(size_t n, size_t size) __THROW {
  36. return ShimCalloc(n, size, nullptr);
  37. }
  38. SHIM_ALWAYS_EXPORT void cfree(void* ptr) __THROW {
  39. ShimFree(ptr, nullptr);
  40. }
  41. SHIM_ALWAYS_EXPORT void* memalign(size_t align, size_t s) __THROW {
  42. return ShimMemalign(align, s, nullptr);
  43. }
  44. SHIM_ALWAYS_EXPORT void* aligned_alloc(size_t align, size_t s) __THROW {
  45. return ShimMemalign(align, s, nullptr);
  46. }
  47. SHIM_ALWAYS_EXPORT void* valloc(size_t size) __THROW {
  48. return ShimValloc(size, nullptr);
  49. }
  50. SHIM_ALWAYS_EXPORT void* pvalloc(size_t size) __THROW {
  51. return ShimPvalloc(size);
  52. }
  53. SHIM_ALWAYS_EXPORT int posix_memalign(void** r, size_t a, size_t s) __THROW {
  54. return ShimPosixMemalign(r, a, s);
  55. }
  56. SHIM_ALWAYS_EXPORT size_t malloc_size(const void* address) __THROW {
  57. return ShimGetSizeEstimate(address, nullptr);
  58. }
  59. SHIM_ALWAYS_EXPORT size_t malloc_usable_size(void* address) __THROW {
  60. return ShimGetSizeEstimate(address, nullptr);
  61. }
  62. // The default dispatch translation unit has to define also the following
  63. // symbols (unless they are ultimately routed to the system symbols):
  64. // void malloc_stats(void);
  65. // int mallopt(int, int);
  66. // struct mallinfo mallinfo(void);
  67. } // extern "C"