#include "sanitizer_common/sanitizer_platform.h"
#if SANITIZER_APPLE
#include "asan_interceptors.h"
#include "asan_report.h"
#include "asan_stack.h"
#include "asan_stats.h"
#include "lsan/lsan_common.h"
using namespace __asan;
#define COMMON_MALLOC_ZONE_NAME …
#define COMMON_MALLOC_ENTER …
#define COMMON_MALLOC_SANITIZER_INITIALIZED …
#define COMMON_MALLOC_FORCE_LOCK …
#define COMMON_MALLOC_FORCE_UNLOCK …
#define COMMON_MALLOC_MEMALIGN …
#define COMMON_MALLOC_MALLOC …
#define COMMON_MALLOC_REALLOC …
#define COMMON_MALLOC_CALLOC …
#define COMMON_MALLOC_POSIX_MEMALIGN …
#define COMMON_MALLOC_VALLOC …
#define COMMON_MALLOC_FREE …
#define COMMON_MALLOC_SIZE …
#define COMMON_MALLOC_FILL_STATS …
#define COMMON_MALLOC_REPORT_UNKNOWN_REALLOC …
#define COMMON_MALLOC_NAMESPACE …
#define COMMON_MALLOC_HAS_ZONE_ENUMERATOR …
#define COMMON_MALLOC_HAS_EXTRA_INTROSPECTION_INIT …
# include "sanitizer_common/sanitizer_malloc_mac.inc"
namespace COMMON_MALLOC_NAMESPACE {
bool HandleDlopenInit() {
static_assert(SANITIZER_SUPPORTS_INIT_FOR_DLOPEN,
"Expected SANITIZER_SUPPORTS_INIT_FOR_DLOPEN to be true");
auto init_str = GetEnv("APPLE_ASAN_INIT_FOR_DLOPEN");
if (!init_str)
return false;
if (internal_strncmp(init_str, "1", 1) != 0)
return false;
InitMallocZoneFields();
return true;
}
}
namespace {
void mi_extra_init(sanitizer_malloc_introspection_t *mi) {
uptr last_byte_plus_one = 0;
mi->allocator_ptr = 0;
__lsan::GetAllocatorGlobalRange(&(mi->allocator_ptr), &last_byte_plus_one);
CHECK_NE(mi->allocator_ptr, 0);
CHECK_GT(last_byte_plus_one, mi->allocator_ptr);
mi->allocator_size = last_byte_plus_one - (mi->allocator_ptr);
CHECK_GT(mi->allocator_size, 0);
}
}
#endif