forked from OSchip/llvm-project
[sanitizer] add a function MmapNoAccess that mmaps a protected region *somewhere*; use MmapNoAccess in the Allocator when SpaceBeg is not a constant. In this mode the allocator will be a bit more hardened
llvm-svn: 267256
This commit is contained in:
parent
9c1112d09a
commit
3884f1a5bd
|
@ -327,8 +327,8 @@ class SizeClassAllocator64 {
|
|||
CHECK_EQ(kSpaceBeg, reinterpret_cast<uptr>(
|
||||
MmapFixedNoAccess(kSpaceBeg, kSpaceSize)));
|
||||
} else {
|
||||
NonConstSpaceBeg = reinterpret_cast<uptr>(
|
||||
MmapFixedNoAccess(0, kSpaceSize + AdditionalSize()));
|
||||
NonConstSpaceBeg =
|
||||
reinterpret_cast<uptr>(MmapNoAccess(kSpaceSize + AdditionalSize()));
|
||||
CHECK_NE(NonConstSpaceBeg, ~(uptr)0);
|
||||
}
|
||||
MapWithCallback(SpaceEnd(), AdditionalSize());
|
||||
|
|
|
@ -85,6 +85,7 @@ void *MmapFixedNoReserve(uptr fixed_addr, uptr size,
|
|||
void *MmapNoReserveOrDie(uptr size, const char *mem_type);
|
||||
void *MmapFixedOrDie(uptr fixed_addr, uptr size);
|
||||
void *MmapFixedNoAccess(uptr fixed_addr, uptr size, const char *name = nullptr);
|
||||
void *MmapNoAccess(uptr size);
|
||||
// Map aligned chunk of address space; size and alignment are powers of two.
|
||||
void *MmapAlignedOrDie(uptr size, uptr alignment, const char *mem_type);
|
||||
// Disallow access to a memory range. Use MmapFixedNoAccess to allocate an
|
||||
|
|
|
@ -279,6 +279,11 @@ void *MmapFixedNoAccess(uptr fixed_addr, uptr size, const char *name) {
|
|||
0);
|
||||
}
|
||||
|
||||
void *MmapNoAccess(uptr size) {
|
||||
unsigned flags = MAP_PRIVATE | MAP_ANON | MAP_NORESERVE;
|
||||
return (void *)internal_mmap(nullptr, size, PROT_NONE, flags, -1, 0);
|
||||
}
|
||||
|
||||
// This function is defined elsewhere if we intercepted pthread_attr_getstack.
|
||||
extern "C" {
|
||||
SANITIZER_WEAK_ATTRIBUTE int
|
||||
|
|
|
@ -211,6 +211,11 @@ void *MmapFixedNoAccess(uptr fixed_addr, uptr size, const char *name) {
|
|||
return res;
|
||||
}
|
||||
|
||||
void *MmapNoAccess(uptr size) {
|
||||
// FIXME: unsupported.
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool MprotectNoAccess(uptr addr, uptr size) {
|
||||
DWORD old_protection;
|
||||
return VirtualProtect((LPVOID)addr, size, PAGE_NOACCESS, &old_protection);
|
||||
|
|
|
@ -37,7 +37,8 @@ namespace {
|
|||
static const uptr kAllocatorSpace = 0x600000000000ULL;
|
||||
static const uptr kAllocatorSize = 0x10000000000ULL; // 1T.
|
||||
|
||||
typedef SizeClassAllocator64<kAllocatorSpace, kAllocatorSize, 0,
|
||||
// typedef SizeClassAllocator64<kAllocatorSpace, kAllocatorSize, 0,
|
||||
typedef SizeClassAllocator64<~(uptr)0, kAllocatorSize, 0,
|
||||
CompactSizeClassMap> PrimaryAllocator;
|
||||
typedef SizeClassAllocatorLocalCache<PrimaryAllocator> AllocatorCache;
|
||||
typedef LargeMmapAllocator<> SecondaryAllocator;
|
||||
|
|
Loading…
Reference in New Issue