support asan in 3.1_opensource_release

This commit is contained in:
xy0
2022-04-08 14:00:52 +08:00
committed by LINxiansheng
parent 021cb19e6c
commit e43242fe44
4 changed files with 70 additions and 60 deletions

View File

@ -71,25 +71,25 @@ static uint64_t up2align(uint64_t x, uint64_t align)
#define __DIRECT_MALLOC__ __DM_MMAP_ALIGNED
#if __DIRECT_MALLOC__ == __DM_MALLOC
void* direct_malloc(int64_t size)
void *direct_malloc(int64_t size)
{
return ::malloc(size);
}
void direct_free(void* p, int64_t size)
void direct_free(void *p, int64_t size)
{
UNUSED(size);
::free(p);
}
#elif __DIRECT_MALLOC__ == __DM_MMAP
void* direct_malloc(int64_t size)
void *direct_malloc(int64_t size)
{
void* p = NULL;
void *p = NULL;
if (MAP_FAILED == (p = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0))) {
p = NULL;
}
return p;
}
void direct_free(void* p, int64_t size)
void direct_free(void *p, int64_t size)
{
if (NULL != p) {
munmap(p, size);
@ -98,9 +98,9 @@ void direct_free(void* p, int64_t size)
#elif __DIRECT_MALLOC__ == __DM_MMAP_ALIGNED
const static uint64_t MMAP_BLOCK_ALIGN = 1ULL << 21;
inline void* mmap_aligned(uint64_t size, uint64_t align)
inline void *mmap_aligned(uint64_t size, uint64_t align)
{
void* ret = NULL;
void *ret = NULL;
if (MAP_FAILED == (ret = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0))) {
ret = NULL;
} else if (is_aligned((uint64_t)ret, align)) {
@ -115,19 +115,19 @@ inline void* mmap_aligned(uint64_t size, uint64_t align)
uint64_t trailer_size = (uint64_t)ret + align - aligned_addr;
munmap(ret, header_size);
munmap((void*)(aligned_addr + size), trailer_size);
ret = (void*)aligned_addr;
munmap((void *)(aligned_addr + size), trailer_size);
ret = (void *)aligned_addr;
}
}
return ret;
}
void* direct_malloc(int64_t size)
void *direct_malloc(int64_t size)
{
return mmap_aligned(size, MMAP_BLOCK_ALIGN);
}
void direct_free(void* p, int64_t size)
void direct_free(void *p, int64_t size)
{
if (NULL != p) {
munmap(p, size);
@ -138,25 +138,25 @@ void direct_free(void* p, int64_t size)
namespace oceanbase {
namespace common {
ObIAllocator* global_default_allocator = NULL;
ObIAllocator *global_default_allocator = NULL;
int ob_init_memory_pool(int64_t block_size)
{
UNUSED(block_size);
return OB_SUCCESS;
}
ObMemLeakChecker& get_mem_leak_checker()
ObMemLeakChecker &get_mem_leak_checker()
{
return ObMemLeakChecker::get_instance();
}
void reset_mem_leak_checker_label(const char* str)
void reset_mem_leak_checker_label(const char *str)
{
get_mem_leak_checker().set_str(str);
get_mem_leak_checker().reset();
}
const ObCtxInfo& get_global_ctx_info()
const ObCtxInfo &get_global_ctx_info()
{
static ObCtxInfo info;
return info;
@ -166,15 +166,17 @@ void __attribute__((constructor(MALLOC_INIT_PRIORITY))) init_global_memory_pool(
{
int ret = OB_SUCCESS;
// coro local storage construct function
CoRoutine::co_cb_ = [](CoRoutine& coro) {
CoRoutine::co_cb_ = [](CoRoutine &coro) {
new (coro.get_context().get_local_store()) ObLocalStore();
new (coro.get_rtctx()) ObRuntimeContext();
auto cls = reinterpret_cast<common::ObLocalStore*>(coro.get_context().get_local_store());
auto cls = reinterpret_cast<common::ObLocalStore *>(coro.get_context().get_local_store());
coro.get_context().get_stack(cls->stack_addr_, cls->stack_size_);
return OB_SUCCESS;
};
global_default_allocator = ObMallocAllocator::get_instance();
#ifndef OB_USE_ASAN
abort_unless(OB_SUCCESS == install_ob_signal_handler());
#endif
}
void __attribute__((destructor(MALLOC_INIT_PRIORITY))) deinit_global_memory_pool()