Index: lib/sanitizer_common/sanitizer_allocator_primary64.h =================================================================== --- lib/sanitizer_common/sanitizer_allocator_primary64.h +++ lib/sanitizer_common/sanitizer_allocator_primary64.h @@ -72,11 +72,10 @@ void Init(s32 release_to_os_interval_ms) { uptr TotalSpaceSize = kSpaceSize + AdditionalSize(); if (kUsingConstantSpaceBeg) { - CHECK_EQ(kSpaceBeg, reinterpret_cast( - MmapFixedNoAccess(kSpaceBeg, TotalSpaceSize))); + CHECK_EQ(kSpaceBeg, address_range.Init(TotalSpaceSize, AllocatorName(), + kSpaceBeg)); } else { - NonConstSpaceBeg = - reinterpret_cast(MmapNoAccess(TotalSpaceSize)); + NonConstSpaceBeg = address_range.Init(TotalSpaceSize, AllocatorName()); CHECK_NE(NonConstSpaceBeg, ~(uptr)0); } SetReleaseToOSIntervalMs(release_to_os_interval_ms); @@ -531,6 +530,9 @@ 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 @@ -624,7 +626,7 @@ } bool MapWithCallback(uptr beg, uptr size) { - uptr mapped = reinterpret_cast(MmapFixedOrDieOnFatalError(beg, size)); + uptr mapped = address_range.Map(beg, size); if (UNLIKELY(!mapped)) return false; CHECK_EQ(beg, mapped); @@ -633,13 +635,13 @@ } void MapWithCallbackOrDie(uptr beg, uptr size) { - CHECK_EQ(beg, reinterpret_cast(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(beg), size); + address_range.Unmap(beg, size); } bool EnsureFreeArraySpace(RegionInfo *region, uptr region_beg, Index: lib/sanitizer_common/sanitizer_common.h =================================================================== --- lib/sanitizer_common/sanitizer_common.h +++ lib/sanitizer_common/sanitizer_common.h @@ -131,7 +131,8 @@ 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_; } Index: lib/sanitizer_common/sanitizer_fuchsia.cc =================================================================== --- lib/sanitizer_common/sanitizer_fuchsia.cc +++ lib/sanitizer_common/sanitizer_fuchsia.cc @@ -246,7 +246,7 @@ // 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, +uptr MapImpl(uptr fixed_addr, uptr map_size, bool tolerate_enomem) { return reinterpret_cast(MmapFixedOrDie(fixed_addr, map_size)); } @@ -262,6 +262,14 @@ UnmapOrDie(reinterpret_cast(addr), size); } +uptr ReservedAddressRange::MapOrDie(uptr fixed_addr, uptr map_size) { + return MapImpl(fixed_addr, map_size, true); +} + +uptr ReservedAddressRange::Map(uptr fixed_addr, uptr map_size) { + return MapImpl(fixed_addr, map_size, false); +} + // MmapNoAccess and MmapFixedOrDie are used only by sanitizer_allocator. // Instead of doing exactly what they say, we make MmapNoAccess actually // just allocate a VMAR to reserve the address space. Then MmapFixedOrDie Index: lib/sanitizer_common/sanitizer_posix_libcdep.cc =================================================================== --- lib/sanitizer_common/sanitizer_posix_libcdep.cc +++ lib/sanitizer_common/sanitizer_posix_libcdep.cc @@ -350,7 +350,7 @@ // 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, +uptr MapImpl(uptr fixed_addr, uptr size, bool tolerate_enomem) { if (tolerate_enomem) { return reinterpret_cast(MmapFixedOrDieOnFatalError(fixed_addr, size)); @@ -358,6 +358,14 @@ return reinterpret_cast(MmapFixedOrDie(fixed_addr, size)); } +uptr ReservedAddressRange::Map(uptr fixed_addr, uptr size) { + return MapImpl(fixed_addr, size, true); +} + +uptr ReservedAddressRange::MapOrDie(uptr fixed_addr, uptr size) { + return MapImpl(fixed_addr, size, false); +} + void ReservedAddressRange::Unmap(uptr addr, uptr size) { void* addr_as_void = reinterpret_cast(addr); uptr base_as_uptr = reinterpret_cast(base_); Index: lib/sanitizer_common/sanitizer_win.cc =================================================================== --- lib/sanitizer_common/sanitizer_win.cc +++ lib/sanitizer_common/sanitizer_win.cc @@ -237,7 +237,7 @@ // 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, +uptr MapImpl(uptr fixed_addr, uptr size, bool tolerate_enomem) { if (tolerate_enomem) { return reinterpret_cast(MmapFixedOrDieOnFatalError(fixed_addr, size)); @@ -245,6 +245,14 @@ return reinterpret_cast(MmapFixedOrDie(uptr fixed_addr, uptr size)); } +uptr ReservedAddressRange::Map(uptr fixed_addr, uptr size) { + return MapImpl(fixed_addr, size, true); +} + +uptr ReservedAddressRange::MapOrDie(uptr fixed_addr, uptr size) { + return MapImpl(fixed_addr, size, false); +} + void ReservedAddressRange::Unmap(uptr addr, uptr size) { void* addr_as_void = reinterpret_cast(addr); uptr base_as_uptr = reinterpret_cast(base_);