Fix freebsd build

This commit is contained in:
proller 2019-07-15 15:27:12 +03:00
parent 8345509a78
commit 828f4e1d29
2 changed files with 32 additions and 2 deletions

View File

@ -5,7 +5,9 @@
#include <vector> #include <vector>
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <common/likely.h> #include <common/likely.h>
#include <sanitizer/asan_interface.h> #if __has_include(<sanitizer/asan_interface.h>)
# include <sanitizer/asan_interface.h>
#endif
#include <Core/Defines.h> #include <Core/Defines.h>
#include <Common/memcpySmall.h> #include <Common/memcpySmall.h>
#include <Common/ProfileEvents.h> #include <Common/ProfileEvents.h>
@ -55,7 +57,9 @@ private:
end = begin + size_ - pad_right; end = begin + size_ - pad_right;
prev = prev_; prev = prev_;
#if __has_include(<sanitizer/asan_interface.h>)
ASAN_POISON_MEMORY_REGION(begin, size_); ASAN_POISON_MEMORY_REGION(begin, size_);
#endif
} }
~Chunk() ~Chunk()
@ -64,7 +68,9 @@ private:
/// because the allocator might not have asan integration, and the /// because the allocator might not have asan integration, and the
/// memory would stay poisoned forever. If the allocator supports /// memory would stay poisoned forever. If the allocator supports
/// asan, it will correctly poison the memory by itself. /// asan, it will correctly poison the memory by itself.
#if __has_include(<sanitizer/asan_interface.h>)
ASAN_UNPOISON_MEMORY_REGION(begin, size()); ASAN_UNPOISON_MEMORY_REGION(begin, size());
#endif
Allocator<false>::free(begin, size()); Allocator<false>::free(begin, size());
@ -135,7 +141,11 @@ public:
char * res = head->pos; char * res = head->pos;
head->pos += size; head->pos += size;
#if __has_include(<sanitizer/asan_interface.h>)
ASAN_UNPOISON_MEMORY_REGION(res, size + pad_right); ASAN_UNPOISON_MEMORY_REGION(res, size + pad_right);
#endif
return res; return res;
} }
@ -152,7 +162,11 @@ public:
{ {
head->pos = static_cast<char *>(head_pos); head->pos = static_cast<char *>(head_pos);
head->pos += size; head->pos += size;
#if __has_include(<sanitizer/asan_interface.h>)
ASAN_UNPOISON_MEMORY_REGION(res, size + pad_right); ASAN_UNPOISON_MEMORY_REGION(res, size + pad_right);
#endif
return res; return res;
} }
@ -172,7 +186,9 @@ public:
void rollback(size_t size) void rollback(size_t size)
{ {
head->pos -= size; head->pos -= size;
#if __has_include(<sanitizer/asan_interface.h>)
ASAN_POISON_MEMORY_REGION(head->pos, size + pad_right); ASAN_POISON_MEMORY_REGION(head->pos, size + pad_right);
#endif
} }
/** Begin or expand allocation of contiguous piece of memory without alignment. /** Begin or expand allocation of contiguous piece of memory without alignment.
@ -199,7 +215,9 @@ public:
if (!begin) if (!begin)
begin = res; begin = res;
#if __has_include(<sanitizer/asan_interface.h>)
ASAN_UNPOISON_MEMORY_REGION(res, size + pad_right); ASAN_UNPOISON_MEMORY_REGION(res, size + pad_right);
#endif
return res; return res;
} }
@ -232,7 +250,9 @@ public:
if (!begin) if (!begin)
begin = res; begin = res;
#if __has_include(<sanitizer/asan_interface.h>)
ASAN_UNPOISON_MEMORY_REGION(res, size + pad_right); ASAN_UNPOISON_MEMORY_REGION(res, size + pad_right);
#endif
return res; return res;
} }
@ -243,7 +263,9 @@ public:
if (old_data) if (old_data)
{ {
memcpy(res, old_data, old_size); memcpy(res, old_data, old_size);
#if __has_include(<sanitizer/asan_interface.h>)
ASAN_POISON_MEMORY_REGION(old_data, old_size); ASAN_POISON_MEMORY_REGION(old_data, old_size);
#endif
} }
return res; return res;
} }
@ -254,7 +276,9 @@ public:
if (old_data) if (old_data)
{ {
memcpy(res, old_data, old_size); memcpy(res, old_data, old_size);
#if __has_include(<sanitizer/asan_interface.h>)
ASAN_POISON_MEMORY_REGION(old_data, old_size); ASAN_POISON_MEMORY_REGION(old_data, old_size);
#endif
} }
return res; return res;
} }

View File

@ -1,6 +1,8 @@
#pragma once #pragma once
#include <sanitizer/asan_interface.h> #if __has_include(<sanitizer/asan_interface.h>)
# include <sanitizer/asan_interface.h>
#endif
#include <Common/Arena.h> #include <Common/Arena.h>
#include <Common/BitHelpers.h> #include <Common/BitHelpers.h>
@ -68,8 +70,10 @@ public:
/// item in the list. We poisoned the free block before putting /// item in the list. We poisoned the free block before putting
/// it into the free list, so we have to unpoison it before /// it into the free list, so we have to unpoison it before
/// reading anything. /// reading anything.
#if __has_include(<sanitizer/asan_interface.h>)
ASAN_UNPOISON_MEMORY_REGION(free_block_ptr, ASAN_UNPOISON_MEMORY_REGION(free_block_ptr,
std::max(size, sizeof(Block))); std::max(size, sizeof(Block)));
#endif
const auto res = free_block_ptr->data; const auto res = free_block_ptr->data;
free_block_ptr = free_block_ptr->next; free_block_ptr = free_block_ptr->next;
@ -100,7 +104,9 @@ public:
/// destructor, to support an underlying allocator that doesn't /// destructor, to support an underlying allocator that doesn't
/// integrate with asan. We don't do that, and rely on the fact that /// integrate with asan. We don't do that, and rely on the fact that
/// our underlying allocator is Arena, which does have asan integration. /// our underlying allocator is Arena, which does have asan integration.
#if __has_include(<sanitizer/asan_interface.h>)
ASAN_POISON_MEMORY_REGION(ptr, 1ULL << (list_idx + 1)); ASAN_POISON_MEMORY_REGION(ptr, 1ULL << (list_idx + 1));
#endif
} }
/// Size of the allocated pool in bytes /// Size of the allocated pool in bytes