diff options
author | Kostya Serebryany <kcc@google.com> | 2012-11-23 15:38:49 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2012-11-23 15:38:49 +0000 |
commit | f67ec2b6e8d2ae328c27de0b026eea2d6667836e (patch) | |
tree | 0620adeec02b25bba4f0d4ebb8b63912640b528e /lib/asan | |
parent | 11e985f7e13fb41f55be82496dbfbf22e769ac4d (diff) |
[asan] get rid of some of the uses of kPageSize. The intent is to get rid of it completely to support platforms with multiple possible page sizes.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@168517 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/asan')
-rw-r--r-- | lib/asan/asan_allocator.cc | 18 | ||||
-rw-r--r-- | lib/asan/asan_linux.cc | 5 | ||||
-rw-r--r-- | lib/asan/asan_malloc_mac.cc | 2 | ||||
-rw-r--r-- | lib/asan/asan_rtl.cc | 7 | ||||
-rw-r--r-- | lib/asan/asan_stats.cc | 2 | ||||
-rw-r--r-- | lib/asan/asan_thread.cc | 9 |
6 files changed, 24 insertions, 19 deletions
diff --git a/lib/asan/asan_allocator.cc b/lib/asan/asan_allocator.cc index b570f0d98..9719aac32 100644 --- a/lib/asan/asan_allocator.cc +++ b/lib/asan/asan_allocator.cc @@ -132,7 +132,7 @@ static void PoisonHeapPartialRightRedzone(uptr mem, uptr size) { } static u8 *MmapNewPagesAndPoisonShadow(uptr size) { - CHECK(IsAligned(size, kPageSize)); + CHECK(IsAligned(size, GetPageSizeCached())); u8 *res = (u8*)MmapOrDie(size, __FUNCTION__); PoisonShadow((uptr)res, size, kAsanHeapLeftRedzoneMagic); if (flags()->debug) { @@ -534,12 +534,13 @@ class MallocInfo { uptr mmap_size = Max(size, kMinMmapSize); uptr n_chunks = mmap_size / size; CHECK(n_chunks * size == mmap_size); - if (size < kPageSize) { + uptr PageSize = GetPageSizeCached(); + if (size < PageSize) { // Size is small, just poison the last chunk. n_chunks--; } else { // Size is large, allocate an extra page at right and poison it. - mmap_size += kPageSize; + mmap_size += PageSize; } CHECK(n_chunks > 0); u8 *mem = MmapNewPagesAndPoisonShadow(mmap_size); @@ -813,18 +814,19 @@ void *asan_realloc(void *p, uptr size, StackTrace *stack) { } void *asan_valloc(uptr size, StackTrace *stack) { - void *ptr = (void*)Allocate(kPageSize, size, stack); + void *ptr = (void*)Allocate(GetPageSizeCached(), size, stack); __asan_malloc_hook(ptr, size); return ptr; } void *asan_pvalloc(uptr size, StackTrace *stack) { - size = RoundUpTo(size, kPageSize); + uptr PageSize = GetPageSizeCached(); + size = RoundUpTo(size, PageSize); if (size == 0) { // pvalloc(0) should allocate one page. - size = kPageSize; + size = PageSize; } - void *ptr = (void*)Allocate(kPageSize, size, stack); + void *ptr = (void*)Allocate(PageSize, size, stack); __asan_malloc_hook(ptr, size); return ptr; } @@ -943,7 +945,7 @@ uptr FakeStack::ClassMmapSize(uptr size_class) { } void FakeStack::AllocateOneSizeClass(uptr size_class) { - CHECK(ClassMmapSize(size_class) >= kPageSize); + CHECK(ClassMmapSize(size_class) >= GetPageSizeCached()); uptr new_mem = (uptr)MmapOrDie( ClassMmapSize(size_class), __FUNCTION__); // Printf("T%d new_mem[%zu]: %p-%p mmap %zu\n", diff --git a/lib/asan/asan_linux.cc b/lib/asan/asan_linux.cc index a70adeeea..2f89a1ef5 100644 --- a/lib/asan/asan_linux.cc +++ b/lib/asan/asan_linux.cc @@ -176,9 +176,10 @@ void ClearShadowMemoryForContext(void *context) { uptr sp = (uptr)ucp->uc_stack.ss_sp; uptr size = ucp->uc_stack.ss_size; // Align to page size. - uptr bottom = sp & ~(kPageSize - 1); + uptr PageSize = GetPageSizeCached(); + uptr bottom = sp & ~(PageSize - 1); size += sp - bottom; - size = RoundUpTo(size, kPageSize); + size = RoundUpTo(size, PageSize); PoisonShadow(bottom, size, 0); } #else diff --git a/lib/asan/asan_malloc_mac.cc b/lib/asan/asan_malloc_mac.cc index 5b47e120f..b32c18ef2 100644 --- a/lib/asan/asan_malloc_mac.cc +++ b/lib/asan/asan_malloc_mac.cc @@ -165,7 +165,7 @@ void *mz_valloc(malloc_zone_t *zone, size_t size) { return malloc_zone_valloc(system_malloc_zone, size); } GET_STACK_TRACE_HERE_FOR_MALLOC; - return asan_memalign(kPageSize, size, &stack); + return asan_memalign(GetPageSizeCached(), size, &stack); } #define GET_ZONE_FOR_PTR(ptr) \ diff --git a/lib/asan/asan_rtl.cc b/lib/asan/asan_rtl.cc index 5d0c966fb..28a8c03f6 100644 --- a/lib/asan/asan_rtl.cc +++ b/lib/asan/asan_rtl.cc @@ -165,8 +165,8 @@ void ShowStatsAndAbort() { // ---------------------- mmap -------------------- {{{1 // Reserve memory range [beg, end]. static void ReserveShadowMemoryRange(uptr beg, uptr end) { - CHECK((beg % kPageSize) == 0); - CHECK(((end + 1) % kPageSize) == 0); + CHECK((beg % GetPageSizeCached()) == 0); + CHECK(((end + 1) % GetPageSizeCached()) == 0); uptr size = end - beg + 1; void *res = MmapFixedNoReserve(beg, size); if (res != (void*)beg) { @@ -271,8 +271,9 @@ void NOINLINE __asan_handle_no_return() { int local_stack; AsanThread *curr_thread = asanThreadRegistry().GetCurrent(); CHECK(curr_thread); + uptr PageSize = GetPageSizeCached(); uptr top = curr_thread->stack_top(); - uptr bottom = ((uptr)&local_stack - kPageSize) & ~(kPageSize-1); + uptr bottom = ((uptr)&local_stack - PageSize) & ~(PageSize-1); PoisonShadow(bottom, top - bottom, 0); } diff --git a/lib/asan/asan_stats.cc b/lib/asan/asan_stats.cc index 4f39ba61b..cf8cadf39 100644 --- a/lib/asan/asan_stats.cc +++ b/lib/asan/asan_stats.cc @@ -43,7 +43,7 @@ void AsanStats::Print() { Printf("Stats: %zuM really freed by %zu calls\n", really_freed>>20, real_frees); Printf("Stats: %zuM (%zu full pages) mmaped in %zu calls\n", - mmaped>>20, mmaped / kPageSize, mmaps); + mmaped>>20, mmaped / GetPageSizeCached(), mmaps); PrintMallocStatsArray(" mmaps by size class: ", mmaped_by_size); PrintMallocStatsArray(" mallocs by size class: ", malloced_by_size); diff --git a/lib/asan/asan_thread.cc b/lib/asan/asan_thread.cc index 7f60ca913..a77e43579 100644 --- a/lib/asan/asan_thread.cc +++ b/lib/asan/asan_thread.cc @@ -28,15 +28,16 @@ AsanThread::AsanThread(LinkerInitialized x) AsanThread *AsanThread::Create(u32 parent_tid, thread_callback_t start_routine, void *arg, StackTrace *stack) { - uptr size = RoundUpTo(sizeof(AsanThread), kPageSize); + uptr PageSize = GetPageSizeCached(); + uptr size = RoundUpTo(sizeof(AsanThread), PageSize); AsanThread *thread = (AsanThread*)MmapOrDie(size, __FUNCTION__); thread->start_routine_ = start_routine; thread->arg_ = arg; - const uptr kSummaryAllocSize = kPageSize; + const uptr kSummaryAllocSize = PageSize; CHECK_LE(sizeof(AsanThreadSummary), kSummaryAllocSize); AsanThreadSummary *summary = - (AsanThreadSummary*)MmapOrDie(kPageSize, "AsanThreadSummary"); + (AsanThreadSummary*)MmapOrDie(PageSize, "AsanThreadSummary"); summary->Init(parent_tid, stack); summary->set_thread(thread); thread->set_summary(summary); @@ -66,7 +67,7 @@ void AsanThread::Destroy() { // and we don't want it to have any poisoned stack. ClearShadowForThreadStack(); fake_stack().Cleanup(); - uptr size = RoundUpTo(sizeof(AsanThread), kPageSize); + uptr size = RoundUpTo(sizeof(AsanThread), GetPageSizeCached()); UnmapOrDie(this, size); } |