forked from OSchip/llvm-project
Update sanitizer_allocator to use new API.
Summary: Update sanitizer_allocator to use new API. Second patch in a series. First patch https://reviews.llvm.org/D39072 Updates MmapNoAccess / MmapFixed call sites in the saniziter_allocator to use the new Init/Map APIs instead. Reviewers: alekseyshl, cryptoad, phosek, mcgrathr, dvyukov Reviewed By: alekseyshl, cryptoad Subscribers: dvyukov, mcgrathr, kubamracek Differential Revision: https://reviews.llvm.org/D38592 llvm-svn: 317586
This commit is contained in:
parent
ba070108a6
commit
c6f0ade6c3
|
@ -72,11 +72,10 @@ class SizeClassAllocator64 {
|
|||
void Init(s32 release_to_os_interval_ms) {
|
||||
uptr TotalSpaceSize = kSpaceSize + AdditionalSize();
|
||||
if (kUsingConstantSpaceBeg) {
|
||||
CHECK_EQ(kSpaceBeg, reinterpret_cast<uptr>(
|
||||
MmapFixedNoAccess(kSpaceBeg, TotalSpaceSize)));
|
||||
CHECK_EQ(kSpaceBeg, address_range.Init(TotalSpaceSize, AllocatorName(),
|
||||
kSpaceBeg));
|
||||
} else {
|
||||
NonConstSpaceBeg =
|
||||
reinterpret_cast<uptr>(MmapNoAccess(TotalSpaceSize));
|
||||
NonConstSpaceBeg = address_range.Init(TotalSpaceSize, AllocatorName());
|
||||
CHECK_NE(NonConstSpaceBeg, ~(uptr)0);
|
||||
}
|
||||
SetReleaseToOSIntervalMs(release_to_os_interval_ms);
|
||||
|
@ -544,6 +543,9 @@ class SizeClassAllocator64 {
|
|||
private:
|
||||
friend class MemoryMapper;
|
||||
|
||||
ReservedAddressRange address_range;
|
||||
static const char *AllocatorName() { return "sanitizer_allocator"; }
|
||||
|
||||
static const uptr kRegionSize = kSpaceSize / kNumClassesRounded;
|
||||
// FreeArray is the array of free-d chunks (stored as 4-byte offsets).
|
||||
// In the worst case it may reguire kRegionSize/SizeClassMap::kMinSize
|
||||
|
@ -625,7 +627,7 @@ class SizeClassAllocator64 {
|
|||
}
|
||||
|
||||
bool MapWithCallback(uptr beg, uptr size) {
|
||||
uptr mapped = reinterpret_cast<uptr>(MmapFixedOrDieOnFatalError(beg, size));
|
||||
uptr mapped = address_range.Map(beg, size);
|
||||
if (UNLIKELY(!mapped))
|
||||
return false;
|
||||
CHECK_EQ(beg, mapped);
|
||||
|
@ -634,13 +636,13 @@ class SizeClassAllocator64 {
|
|||
}
|
||||
|
||||
void MapWithCallbackOrDie(uptr beg, uptr size) {
|
||||
CHECK_EQ(beg, reinterpret_cast<uptr>(MmapFixedOrDie(beg, size)));
|
||||
CHECK_EQ(beg, address_range.MapOrDie(beg, size));
|
||||
MapUnmapCallback().OnMap(beg, size);
|
||||
}
|
||||
|
||||
void UnmapWithCallbackOrDie(uptr beg, uptr size) {
|
||||
MapUnmapCallback().OnUnmap(beg, size);
|
||||
UnmapOrDie(reinterpret_cast<void *>(beg), size);
|
||||
address_range.Unmap(beg, size);
|
||||
}
|
||||
|
||||
bool EnsureFreeArraySpace(RegionInfo *region, uptr region_beg,
|
||||
|
|
|
@ -131,7 +131,8 @@ void RunFreeHooks(const void *ptr);
|
|||
class ReservedAddressRange {
|
||||
public:
|
||||
uptr Init(uptr size, const char *name = nullptr, uptr fixed_addr = 0);
|
||||
uptr Map(uptr fixed_addr, uptr size, bool tolerate_enomem = false);
|
||||
uptr Map(uptr fixed_addr, uptr size);
|
||||
uptr MapOrDie(uptr fixed_addr, uptr size);
|
||||
void Unmap(uptr addr, uptr size);
|
||||
void *base() const { return base_; }
|
||||
uptr size() const { return size_; }
|
||||
|
|
|
@ -246,8 +246,12 @@ uptr ReservedAddressRange::Init(uptr init_size, const char* name,
|
|||
|
||||
// Uses fixed_addr for now.
|
||||
// Will use offset instead once we've implemented this function for real.
|
||||
uptr ReservedAddressRange::Map(uptr fixed_addr, uptr map_size,
|
||||
bool tolerate_enomem) {
|
||||
uptr ReservedAddressRange::Map(uptr fixed_addr, uptr map_size) {
|
||||
return reinterpret_cast<uptr>(MmapFixedOrDieOnFatalError(fixed_addr,
|
||||
map_size));
|
||||
}
|
||||
|
||||
uptr ReservedAddressRange::MapOrDie(uptr fixed_addr, uptr map_size) {
|
||||
return reinterpret_cast<uptr>(MmapFixedOrDie(fixed_addr, map_size));
|
||||
}
|
||||
|
||||
|
|
|
@ -338,8 +338,13 @@ void *MmapFixedNoReserve(uptr fixed_addr, uptr size, const char *name) {
|
|||
}
|
||||
|
||||
uptr ReservedAddressRange::Init(uptr size, const char *name, uptr fixed_addr) {
|
||||
// We don't pass `name` along because, when you enable `decorate_proc_maps`
|
||||
// AND actually use a named mapping AND are using a sanitizer intercepting
|
||||
// `open` (e.g. TSAN, ESAN), then you'll get a failure during initialization.
|
||||
// TODO(flowerhack): Fix the implementation of GetNamedMappingFd to solve
|
||||
// this problem.
|
||||
if (fixed_addr) {
|
||||
base_ = MmapFixedNoAccess(fixed_addr, size, name);
|
||||
base_ = MmapFixedNoAccess(fixed_addr, size);
|
||||
} else {
|
||||
base_ = MmapNoAccess(size);
|
||||
}
|
||||
|
@ -350,11 +355,11 @@ uptr ReservedAddressRange::Init(uptr size, const char *name, uptr fixed_addr) {
|
|||
|
||||
// Uses fixed_addr for now.
|
||||
// Will use offset instead once we've implemented this function for real.
|
||||
uptr ReservedAddressRange::Map(uptr fixed_addr, uptr size,
|
||||
bool tolerate_enomem) {
|
||||
if (tolerate_enomem) {
|
||||
return reinterpret_cast<uptr>(MmapFixedOrDieOnFatalError(fixed_addr, size));
|
||||
}
|
||||
uptr ReservedAddressRange::Map(uptr fixed_addr, uptr size) {
|
||||
return reinterpret_cast<uptr>(MmapFixedOrDieOnFatalError(fixed_addr, size));
|
||||
}
|
||||
|
||||
uptr ReservedAddressRange::MapOrDie(uptr fixed_addr, uptr size) {
|
||||
return reinterpret_cast<uptr>(MmapFixedOrDie(fixed_addr, size));
|
||||
}
|
||||
|
||||
|
|
|
@ -237,11 +237,11 @@ void *MmapFixedOrDie(uptr fixed_addr, uptr size) {
|
|||
|
||||
// Uses fixed_addr for now.
|
||||
// Will use offset instead once we've implemented this function for real.
|
||||
uptr ReservedAddressRange::Map(uptr fixed_addr, uptr size,
|
||||
bool tolerate_enomem) {
|
||||
if (tolerate_enomem) {
|
||||
return reinterpret_cast<uptr>(MmapFixedOrDieOnFatalError(fixed_addr, size));
|
||||
}
|
||||
uptr ReservedAddressRange::Map(uptr fixed_addr, uptr size) {
|
||||
return reinterpret_cast<uptr>(MmapFixedOrDieOnFatalError(fixed_addr, size));
|
||||
}
|
||||
|
||||
uptr ReservedAddressRange::MapOrDie(uptr fixed_addr, uptr size) {
|
||||
return reinterpret_cast<uptr>(MmapFixedOrDie(fixed_addr, size));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue