diff options
Diffstat (limited to 'compiler-rt')
11 files changed, 39 insertions, 41 deletions
diff --git a/compiler-rt/lib/asan/asan_mac.cc b/compiler-rt/lib/asan/asan_mac.cc index e4e897e23c5..fe8784326c1 100644 --- a/compiler-rt/lib/asan/asan_mac.cc +++ b/compiler-rt/lib/asan/asan_mac.cc @@ -184,11 +184,11 @@ void ClearShadowMemoryForContext(void *context) { static void *island_allocator_pos = 0; #if SANITIZER_WORDSIZE == 32 -# define kIslandEnd (0xffdf0000 - kPageSize) -# define kIslandBeg (kIslandEnd - 256 * kPageSize) +# define kIslandEnd (0xffdf0000 - GetPageSizeCached()) +# define kIslandBeg (kIslandEnd - 256 * GetPageSizeCached()) #else -# define kIslandEnd (0x7fffffdf0000 - kPageSize) -# define kIslandBeg (kIslandEnd - 256 * kPageSize) +# define kIslandEnd (0x7fffffdf0000 - GetPageSizeCached()) +# define kIslandBeg (kIslandEnd - 256 * GetPageSizeCached()) #endif extern "C" @@ -212,7 +212,7 @@ mach_error_t __interception_allocate_island(void **ptr, internal_memset(island_allocator_pos, 0xCC, kIslandEnd - kIslandBeg); }; *ptr = island_allocator_pos; - island_allocator_pos = (char*)island_allocator_pos + kPageSize; + island_allocator_pos = (char*)island_allocator_pos + GetPageSizeCached(); if (flags()->verbosity) { Report("Branch island allocated at %p\n", *ptr); } diff --git a/compiler-rt/lib/asan/asan_mapping.h b/compiler-rt/lib/asan/asan_mapping.h index 803fcd8ed29..3a5f88bb9b5 100644 --- a/compiler-rt/lib/asan/asan_mapping.h +++ b/compiler-rt/lib/asan/asan_mapping.h @@ -68,7 +68,12 @@ extern __attribute__((visibility("default"))) uptr __asan_mapping_offset; #define kHighShadowBeg MEM_TO_SHADOW(kHighMemBeg) #define kHighShadowEnd MEM_TO_SHADOW(kHighMemEnd) -#define kShadowGapBeg (kLowShadowEnd ? kLowShadowEnd + 1 : 16 * kPageSize) +// With the zero shadow base we can not actually map pages starting from 0. +// This constant is somewhat arbitrary. +#define kZeroBaseShadowStart (1 << 18) + +#define kShadowGapBeg (kLowShadowEnd ? kLowShadowEnd + 1 \ + : kZeroBaseShadowStart) #define kShadowGapEnd (kHighShadowBeg - 1) #define kGlobalAndStackRedzone \ diff --git a/compiler-rt/lib/asan/asan_rtl.cc b/compiler-rt/lib/asan/asan_rtl.cc index 28a8c03f635..bd5c0fe8d90 100644 --- a/compiler-rt/lib/asan/asan_rtl.cc +++ b/compiler-rt/lib/asan/asan_rtl.cc @@ -350,12 +350,13 @@ void __asan_init() { } uptr shadow_start = kLowShadowBeg; - if (kLowShadowBeg > 0) shadow_start -= kMmapGranularity; + if (kLowShadowBeg > 0) shadow_start -= GetMmapGranularity(); uptr shadow_end = kHighShadowEnd; if (MemoryRangeIsAvailable(shadow_start, shadow_end)) { if (kLowShadowBeg != kLowShadowEnd) { // mmap the low shadow plus at least one page. - ReserveShadowMemoryRange(kLowShadowBeg - kMmapGranularity, kLowShadowEnd); + ReserveShadowMemoryRange(kLowShadowBeg - GetMmapGranularity(), + kLowShadowEnd); } // mmap the high shadow. ReserveShadowMemoryRange(kHighShadowBeg, kHighShadowEnd); diff --git a/compiler-rt/lib/asan/tests/asan_noinst_test.cc b/compiler-rt/lib/asan/tests/asan_noinst_test.cc index a75f1544063..fdb78202954 100644 --- a/compiler-rt/lib/asan/tests/asan_noinst_test.cc +++ b/compiler-rt/lib/asan/tests/asan_noinst_test.cc @@ -336,11 +336,12 @@ TEST(AddressSanitizer, MemsetWildAddressTest) { typedef void*(*memset_p)(void*, int, size_t); // Prevent inlining of memset(). volatile memset_p libc_memset = (memset_p)memset; - EXPECT_DEATH(libc_memset((void*)(kLowShadowBeg + kPageSize), 0, 100), + uptr PageSize = GetPageSizeCached(); + EXPECT_DEATH(libc_memset((void*)(kLowShadowBeg + PageSize), 0, 100), "unknown-crash.*low shadow"); - EXPECT_DEATH(libc_memset((void*)(kShadowGapBeg + kPageSize), 0, 100), + EXPECT_DEATH(libc_memset((void*)(kShadowGapBeg + PageSize), 0, 100), "unknown-crash.*shadow gap"); - EXPECT_DEATH(libc_memset((void*)(kHighShadowBeg + kPageSize), 0, 100), + EXPECT_DEATH(libc_memset((void*)(kHighShadowBeg + PageSize), 0, 100), "unknown-crash.*high shadow"); } diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc index 985f91a103e..c43933061f1 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc @@ -63,7 +63,7 @@ void *LowLevelAllocator::Allocate(uptr size) { // Align allocation size. size = RoundUpTo(size, 8); if (allocated_end_ - allocated_current_ < (sptr)size) { - uptr size_to_allocate = Max(size, kPageSize); + uptr size_to_allocate = Max(size, GetPageSizeCached()); allocated_current_ = (char*)MmapOrDie(size_to_allocate, __FUNCTION__); allocated_end_ = allocated_current_ + size_to_allocate; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator64.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator64.h index a537ff0c46a..2f4e697415d 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator64.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator64.h @@ -217,7 +217,6 @@ class SizeClassAllocator64 { } static uptr AllocBeg() { return kSpaceBeg; } - static uptr AllocEnd() { return kSpaceBeg + kSpaceSize + AdditionalSize(); } static uptr AllocSize() { return kSpaceSize + AdditionalSize(); } static const uptr kNumClasses = 256; // Power of two <= 256 @@ -243,7 +242,7 @@ class SizeClassAllocator64 { static uptr AdditionalSize() { uptr res = sizeof(RegionInfo) * kNumClasses; - CHECK_EQ(res % kPageSize, 0); + CHECK_EQ(res % GetPageSizeCached(), 0); return res; } @@ -366,17 +365,18 @@ class LargeMmapAllocator { public: void Init() { internal_memset(this, 0, sizeof(*this)); + page_size_ = GetPageSizeCached(); } void *Allocate(uptr size, uptr alignment) { CHECK(IsPowerOfTwo(alignment)); uptr map_size = RoundUpMapSize(size); - if (alignment > kPageSize) + if (alignment > page_size_) map_size += alignment; if (map_size < size) return 0; // Overflow. uptr map_beg = reinterpret_cast<uptr>( MmapOrDie(map_size, "LargeMmapAllocator")); uptr map_end = map_beg + map_size; - uptr res = map_beg + kPageSize; + uptr res = map_beg + page_size_; if (res & (alignment - 1)) // Align. res += alignment - (res & (alignment - 1)); CHECK_EQ(0, res & (alignment - 1)); @@ -423,7 +423,7 @@ class LargeMmapAllocator { bool PointerIsMine(void *p) { // Fast check. - if ((reinterpret_cast<uptr>(p) % kPageSize) != 0) return false; + if ((reinterpret_cast<uptr>(p) & (page_size_ - 1))) return false; SpinMutexLock l(&mutex_); for (Header *l = list_; l; l = l->next) { if (GetUser(l) == p) return true; @@ -432,10 +432,10 @@ class LargeMmapAllocator { } uptr GetActuallyAllocatedSize(void *p) { - return RoundUpMapSize(GetHeader(p)->size) - kPageSize; + return RoundUpMapSize(GetHeader(p)->size) - page_size_; } - // At least kPageSize/2 metadata bytes is available. + // At least page_size_/2 metadata bytes is available. void *GetMetaData(void *p) { return GetHeader(p) + 1; } @@ -459,17 +459,20 @@ class LargeMmapAllocator { Header *prev; }; - Header *GetHeader(uptr p) { return reinterpret_cast<Header*>(p - kPageSize); } + Header *GetHeader(uptr p) { + return reinterpret_cast<Header*>(p - page_size_); + } Header *GetHeader(void *p) { return GetHeader(reinterpret_cast<uptr>(p)); } void *GetUser(Header *h) { - return reinterpret_cast<void*>(reinterpret_cast<uptr>(h) + kPageSize); + return reinterpret_cast<void*>(reinterpret_cast<uptr>(h) + page_size_); } uptr RoundUpMapSize(uptr size) { - return RoundUpTo(size, kPageSize) + kPageSize; + return RoundUpTo(size, page_size_) + page_size_; } + uptr page_size_; Header *list_; SpinMutex mutex_; }; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h index 1842446f63f..dc53d885795 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h @@ -23,23 +23,11 @@ namespace __sanitizer { // Constants. const uptr kWordSize = SANITIZER_WORDSIZE / 8; const uptr kWordSizeInBits = 8 * kWordSize; + #if defined(__powerpc__) || defined(__powerpc64__) -// Current PPC64 kernels use 64K pages sizes, but they can be -// configured with 4K or even other sizes. -// We may want to use getpagesize() or sysconf(_SC_PAGESIZE) here rather than -// hardcoding the values, but today these values need to be compile-time -// constants. -const uptr kPageSize = 1UL << 16; const uptr kCacheLineSize = 128; -const uptr kMmapGranularity = kPageSize; -#elif !defined(_WIN32) -const uptr kPageSize = 1UL << 12; -const uptr kCacheLineSize = 64; -const uptr kMmapGranularity = kPageSize; #else -const uptr kPageSize = 1UL << 12; const uptr kCacheLineSize = 64; -const uptr kMmapGranularity = 1UL << 16; #endif uptr GetPageSize(); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc index 4da41ee5f71..aeb291474d2 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc @@ -65,7 +65,7 @@ void StackTrace::PrintStack(const uptr *addr, uptr size, bool symbolize, const char *strip_file_prefix, SymbolizeCallback symbolize_callback ) { MemoryMappingLayout proc_maps; - InternalScopedBuffer<char> buff(kPageSize * 2); + InternalScopedBuffer<char> buff(GetPageSizeCached() * 2); InternalScopedBuffer<AddressInfo> addr_frames(64); uptr frame_num = 0; for (uptr i = 0; i < size && addr[i]; i++) { diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc index 2d97d3ab2ad..e915399bcf8 100644 --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc @@ -182,7 +182,7 @@ TEST(SanitizerCommon, LargeMmapAllocator) { for (uptr alignment = 8; alignment <= (1<<28); alignment *= 2) { for (int i = 0; i < kNumAllocs; i++) { - uptr size = ((i % 10) + 1) * kPageSize; + uptr size = ((i % 10) + 1) * 4096; allocated[i] = a.Allocate(size, alignment); CHECK_EQ(0, (uptr)allocated[i] % alignment); char *p = (char*)allocated[i]; diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator64_testlib.cc b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator64_testlib.cc index 3552f0dfbae..d95c217b677 100644 --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator64_testlib.cc +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator64_testlib.cc @@ -75,13 +75,13 @@ int posix_memalign(void **memptr, size_t alignment, size_t size) { void *valloc(size_t size) { assert(inited); - return allocator.Allocate(&cache, size, kPageSize); + return allocator.Allocate(&cache, size, GetPageSizeCached()); } void *pvalloc(size_t size) { assert(inited); - if (size == 0) size = kPageSize; - return allocator.Allocate(&cache, size, kPageSize); + if (size == 0) size = GetPageSizeCached(); + return allocator.Allocate(&cache, size, GetPageSizeCached()); } } #endif diff --git a/compiler-rt/lib/tsan/rtl/tsan_platform.h b/compiler-rt/lib/tsan/rtl/tsan_platform.h index 26e171271b5..a3c962dccfd 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_platform.h +++ b/compiler-rt/lib/tsan/rtl/tsan_platform.h @@ -52,7 +52,7 @@ static const uptr kLinuxAppMemMsk = 0x7c0000000000ULL; static const uptr kLinuxShadowBeg = MemToShadow(kLinuxAppMemBeg); static const uptr kLinuxShadowEnd = - MemToShadow(kLinuxAppMemEnd) | (kPageSize - 1); + MemToShadow(kLinuxAppMemEnd) | 0xff; static inline bool IsAppMem(uptr mem) { return mem >= kLinuxAppMemBeg && mem <= kLinuxAppMemEnd; |