lsan_malloc_mac.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //===-- lsan_malloc_mac.cpp -----------------------------------------------===//
  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. // This file is a part of LeakSanitizer (LSan), a memory leak detector.
  10. //
  11. // Mac-specific malloc interception.
  12. //===----------------------------------------------------------------------===//
  13. #include "sanitizer_common/sanitizer_platform.h"
  14. #if SANITIZER_MAC
  15. #include "lsan.h"
  16. #include "lsan_allocator.h"
  17. #include "lsan_thread.h"
  18. using namespace __lsan;
  19. #define COMMON_MALLOC_ZONE_NAME "lsan"
  20. #define COMMON_MALLOC_ENTER() ENSURE_LSAN_INITED
  21. #define COMMON_MALLOC_SANITIZER_INITIALIZED lsan_inited
  22. #define COMMON_MALLOC_FORCE_LOCK()
  23. #define COMMON_MALLOC_FORCE_UNLOCK()
  24. #define COMMON_MALLOC_MEMALIGN(alignment, size) \
  25. GET_STACK_TRACE_MALLOC; \
  26. void *p = lsan_memalign(alignment, size, stack)
  27. #define COMMON_MALLOC_MALLOC(size) \
  28. GET_STACK_TRACE_MALLOC; \
  29. void *p = lsan_malloc(size, stack)
  30. #define COMMON_MALLOC_REALLOC(ptr, size) \
  31. GET_STACK_TRACE_MALLOC; \
  32. void *p = lsan_realloc(ptr, size, stack)
  33. #define COMMON_MALLOC_CALLOC(count, size) \
  34. GET_STACK_TRACE_MALLOC; \
  35. void *p = lsan_calloc(count, size, stack)
  36. #define COMMON_MALLOC_POSIX_MEMALIGN(memptr, alignment, size) \
  37. GET_STACK_TRACE_MALLOC; \
  38. int res = lsan_posix_memalign(memptr, alignment, size, stack)
  39. #define COMMON_MALLOC_VALLOC(size) \
  40. GET_STACK_TRACE_MALLOC; \
  41. void *p = lsan_valloc(size, stack)
  42. #define COMMON_MALLOC_FREE(ptr) \
  43. lsan_free(ptr)
  44. #define COMMON_MALLOC_SIZE(ptr) \
  45. uptr size = lsan_mz_size(ptr)
  46. #define COMMON_MALLOC_FILL_STATS(zone, stats)
  47. #define COMMON_MALLOC_REPORT_UNKNOWN_REALLOC(ptr, zone_ptr, zone_name) \
  48. (void)zone_name; \
  49. Report("mz_realloc(%p) -- attempting to realloc unallocated memory.\n", ptr);
  50. #define COMMON_MALLOC_NAMESPACE __lsan
  51. #define COMMON_MALLOC_HAS_ZONE_ENUMERATOR 0
  52. #define COMMON_MALLOC_HAS_EXTRA_INTROSPECTION_INIT 0
  53. #include "sanitizer_common/sanitizer_malloc_mac.inc"
  54. #endif // SANITIZER_MAC