summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/asan/asan_allocator.cc278
-rw-r--r--lib/asan/asan_allocator.h62
-rw-r--r--lib/asan/asan_globals.cc12
-rw-r--r--lib/asan/asan_interceptors.cc132
-rw-r--r--lib/asan/asan_interceptors.h26
-rw-r--r--lib/asan/asan_interface.h4
-rw-r--r--lib/asan/asan_internal.h81
-rw-r--r--lib/asan/asan_linux.cc94
-rw-r--r--lib/asan/asan_lock.h4
-rw-r--r--lib/asan/asan_mac.cc44
-rw-r--r--lib/asan/asan_malloc_linux.cc2
-rw-r--r--lib/asan/asan_malloc_mac.cc24
-rw-r--r--lib/asan/asan_malloc_win.cc4
-rw-r--r--lib/asan/asan_mapping.h28
-rw-r--r--lib/asan/asan_poisoning.cc28
-rw-r--r--lib/asan/asan_posix.cc34
-rw-r--r--lib/asan/asan_printf.cc22
-rw-r--r--lib/asan/asan_procmaps.h22
-rw-r--r--lib/asan/asan_rtl.cc112
-rw-r--r--lib/asan/asan_stack.cc72
-rw-r--r--lib/asan/asan_stack.h48
-rw-r--r--lib/asan/asan_stats.cc6
-rw-r--r--lib/asan/asan_stats.h42
-rw-r--r--lib/asan/asan_thread.cc18
-rw-r--r--lib/asan/asan_thread.h14
-rw-r--r--lib/asan/asan_thread_registry.cc26
-rw-r--r--lib/asan/asan_thread_registry.h12
-rw-r--r--lib/asan/asan_win.cc36
-rw-r--r--lib/asan/tests/asan_noinst_test.cc14
29 files changed, 650 insertions, 651 deletions
diff --git a/lib/asan/asan_allocator.cc b/lib/asan/asan_allocator.cc
index 64288120d..900384feb 100644
--- a/lib/asan/asan_allocator.cc
+++ b/lib/asan/asan_allocator.cc
@@ -42,27 +42,27 @@
namespace __asan {
#define REDZONE FLAG_redzone
-static const size_t kMinAllocSize = REDZONE * 2;
+static const uptr kMinAllocSize = REDZONE * 2;
static const uint64_t kMaxAvailableRam = 128ULL << 30; // 128G
-static const size_t kMaxThreadLocalQuarantine = 1 << 20; // 1M
+static const uptr kMaxThreadLocalQuarantine = 1 << 20; // 1M
-static const size_t kMinMmapSize = (ASAN_LOW_MEMORY) ? 4UL << 17 : 4UL << 20;
-static const size_t kMaxSizeForThreadLocalFreeList =
+static const uptr kMinMmapSize = (ASAN_LOW_MEMORY) ? 4UL << 17 : 4UL << 20;
+static const uptr kMaxSizeForThreadLocalFreeList =
(ASAN_LOW_MEMORY) ? 1 << 15 : 1 << 17;
// Size classes less than kMallocSizeClassStep are powers of two.
// All other size classes are multiples of kMallocSizeClassStep.
-static const size_t kMallocSizeClassStepLog = 26;
-static const size_t kMallocSizeClassStep = 1UL << kMallocSizeClassStepLog;
+static const uptr kMallocSizeClassStepLog = 26;
+static const uptr kMallocSizeClassStep = 1UL << kMallocSizeClassStepLog;
static const uptr kMaxAllowedMallocSize =
(__WORDSIZE == 32) ? 3UL << 30 : 8UL << 30;
-static inline bool IsAligned(uintptr_t a, uintptr_t alignment) {
+static inline bool IsAligned(uptr a, uptr alignment) {
return (a & (alignment - 1)) == 0;
}
-static inline size_t Log2(size_t x) {
+static inline uptr Log2(uptr x) {
CHECK(IsPowerOfTwo(x));
#if !defined(_WIN32) || defined(__clang__)
return __builtin_ctzl(x);
@@ -77,7 +77,7 @@ static inline size_t Log2(size_t x) {
#endif
}
-static inline size_t RoundUpToPowerOfTwo(size_t size) {
+static inline uptr RoundUpToPowerOfTwo(uptr size) {
CHECK(size);
if (IsPowerOfTwo(size)) return size;
@@ -94,7 +94,7 @@ static inline size_t RoundUpToPowerOfTwo(size_t size) {
return 1UL << (up + 1);
}
-static inline size_t SizeClassToSize(uint8_t size_class) {
+static inline uptr SizeClassToSize(uint8_t size_class) {
CHECK(size_class < kNumberOfSizeClasses);
if (size_class <= kMallocSizeClassStepLog) {
return 1UL << size_class;
@@ -103,10 +103,10 @@ static inline size_t SizeClassToSize(uint8_t size_class) {
}
}
-static inline uint8_t SizeToSizeClass(size_t size) {
+static inline uint8_t SizeToSizeClass(uptr size) {
uint8_t res = 0;
if (size <= kMallocSizeClassStep) {
- size_t rounded = RoundUpToPowerOfTwo(size);
+ uptr rounded = RoundUpToPowerOfTwo(size);
res = Log2(rounded);
} else {
res = ((size + kMallocSizeClassStep - 1) / kMallocSizeClassStep)
@@ -119,7 +119,7 @@ static inline uint8_t SizeToSizeClass(size_t size) {
// Given REDZONE bytes, we need to mark first size bytes
// as addressable and the rest REDZONE-size bytes as unaddressable.
-static void PoisonHeapPartialRightRedzone(uintptr_t mem, size_t size) {
+static void PoisonHeapPartialRightRedzone(uptr mem, uptr size) {
CHECK(size <= REDZONE);
CHECK(IsAligned(mem, REDZONE));
CHECK(IsPowerOfTwo(SHADOW_GRANULARITY));
@@ -129,10 +129,10 @@ static void PoisonHeapPartialRightRedzone(uintptr_t mem, size_t size) {
kAsanHeapRightRedzoneMagic);
}
-static uint8_t *MmapNewPagesAndPoisonShadow(size_t size) {
+static uint8_t *MmapNewPagesAndPoisonShadow(uptr size) {
CHECK(IsAligned(size, kPageSize));
uint8_t *res = (uint8_t*)AsanMmapSomewhereOrDie(size, __FUNCTION__);
- PoisonShadow((uintptr_t)res, size, kAsanHeapLeftRedzoneMagic);
+ PoisonShadow((uptr)res, size, kAsanHeapLeftRedzoneMagic);
if (FLAG_debug) {
Printf("ASAN_MMAP: [%p, %p)\n", res, res + size);
}
@@ -162,33 +162,33 @@ struct ChunkBase {
uint32_t offset; // User-visible memory starts at this+offset (beg()).
int32_t alloc_tid;
int32_t free_tid;
- size_t used_size; // Size requested by the user.
+ uptr used_size; // Size requested by the user.
AsanChunk *next;
- uintptr_t beg() { return (uintptr_t)this + offset; }
- size_t Size() { return SizeClassToSize(size_class); }
+ uptr beg() { return (uptr)this + offset; }
+ uptr Size() { return SizeClassToSize(size_class); }
uint8_t SizeClass() { return size_class; }
};
struct AsanChunk: public ChunkBase {
uint32_t *compressed_alloc_stack() {
CHECK(REDZONE >= sizeof(ChunkBase));
- return (uint32_t*)((uintptr_t)this + sizeof(ChunkBase));
+ return (uint32_t*)((uptr)this + sizeof(ChunkBase));
}
uint32_t *compressed_free_stack() {
CHECK(REDZONE >= sizeof(ChunkBase));
- return (uint32_t*)((uintptr_t)this + REDZONE);
+ return (uint32_t*)((uptr)this + REDZONE);
}
// The left redzone after the ChunkBase is given to the alloc stack trace.
- size_t compressed_alloc_stack_size() {
+ uptr compressed_alloc_stack_size() {
return (REDZONE - sizeof(ChunkBase)) / sizeof(uint32_t);
}
- size_t compressed_free_stack_size() {
+ uptr compressed_free_stack_size() {
return (REDZONE) / sizeof(uint32_t);
}
- bool AddrIsInside(uintptr_t addr, size_t access_size, size_t *offset) {
+ bool AddrIsInside(uptr addr, uptr access_size, uptr *offset) {
if (addr >= beg() && (addr + access_size) <= (beg() + used_size)) {
*offset = addr - beg();
return true;
@@ -196,7 +196,7 @@ struct AsanChunk: public ChunkBase {
return false;
}
- bool AddrIsAtLeft(uintptr_t addr, size_t access_size, size_t *offset) {
+ bool AddrIsAtLeft(uptr addr, uptr access_size, uptr *offset) {
if (addr < beg()) {
*offset = beg() - addr;
return true;
@@ -204,7 +204,7 @@ struct AsanChunk: public ChunkBase {
return false;
}
- bool AddrIsAtRight(uintptr_t addr, size_t access_size, size_t *offset) {
+ bool AddrIsAtRight(uptr addr, uptr access_size, uptr *offset) {
if (addr + access_size >= beg() + used_size) {
if (addr <= beg() + used_size)
*offset = 0;
@@ -215,8 +215,8 @@ struct AsanChunk: public ChunkBase {
return false;
}
- void DescribeAddress(uintptr_t addr, size_t access_size) {
- size_t offset;
+ void DescribeAddress(uptr addr, uptr access_size) {
+ uptr offset;
Printf("%p is located ", addr);
if (AddrIsInside(addr, access_size, &offset)) {
Printf("%zu bytes inside of", offset);
@@ -232,7 +232,7 @@ struct AsanChunk: public ChunkBase {
}
};
-static AsanChunk *PtrToChunk(uintptr_t ptr) {
+static AsanChunk *PtrToChunk(uptr ptr) {
AsanChunk *m = (AsanChunk*)(ptr - REDZONE);
if (m->chunk_state == CHUNK_MEMALIGN) {
m = m->next;
@@ -261,7 +261,7 @@ void AsanChunkFifoList::PushList(AsanChunkFifoList *q) {
}
void AsanChunkFifoList::Push(AsanChunk *n) {
- CHECK(n->next == NULL);
+ CHECK(n->next == 0);
if (last_) {
CHECK(first_);
CHECK(!last_->next);
@@ -281,8 +281,8 @@ AsanChunk *AsanChunkFifoList::Pop() {
CHECK(first_);
AsanChunk *res = first_;
first_ = first_->next;
- if (first_ == NULL)
- last_ = NULL;
+ if (first_ == 0)
+ last_ = 0;
CHECK(size_ >= res->Size());
size_ -= res->Size();
if (last_) {
@@ -293,11 +293,11 @@ AsanChunk *AsanChunkFifoList::Pop() {
// All pages we ever allocated.
struct PageGroup {
- uintptr_t beg;
- uintptr_t end;
- size_t size_of_chunk;
- uintptr_t last_chunk;
- bool InRange(uintptr_t addr) {
+ uptr beg;
+ uptr end;
+ uptr size_of_chunk;
+ uptr last_chunk;
+ bool InRange(uptr addr) {
return addr >= beg && addr < end;
}
};
@@ -307,12 +307,12 @@ class MallocInfo {
explicit MallocInfo(LinkerInitialized x) : mu_(x) { }
- AsanChunk *AllocateChunks(uint8_t size_class, size_t n_chunks) {
- AsanChunk *m = NULL;
+ AsanChunk *AllocateChunks(uint8_t size_class, uptr n_chunks) {
+ AsanChunk *m = 0;
AsanChunk **fl = &free_lists_[size_class];
{
ScopedLock lock(&mu_);
- for (size_t i = 0; i < n_chunks; i++) {
+ for (uptr i = 0; i < n_chunks; i++) {
if (!(*fl)) {
*fl = GetNewChunks(size_class);
}
@@ -338,7 +338,7 @@ class MallocInfo {
}
}
if (eat_free_lists) {
- for (size_t size_class = 0; size_class < kNumberOfSizeClasses;
+ for (uptr size_class = 0; size_class < kNumberOfSizeClasses;
size_class++) {
AsanChunk *m = x->free_lists_[size_class];
while (m) {
@@ -357,12 +357,12 @@ class MallocInfo {
quarantine_.Push(chunk);
}
- AsanChunk *FindMallocedOrFreed(uintptr_t addr, size_t access_size) {
+ AsanChunk *FindMallocedOrFreed(uptr addr, uptr access_size) {
ScopedLock lock(&mu_);
return FindChunkByAddr(addr);
}
- size_t AllocationSize(uintptr_t ptr) {
+ uptr AllocationSize(uptr ptr) {
if (!ptr) return 0;
ScopedLock lock(&mu_);
@@ -387,14 +387,14 @@ class MallocInfo {
void PrintStatus() {
ScopedLock lock(&mu_);
- size_t malloced = 0;
+ uptr malloced = 0;
Printf(" MallocInfo: in quarantine: %zu malloced: %zu; ",
quarantine_.size() >> 20, malloced >> 20);
- for (size_t j = 1; j < kNumberOfSizeClasses; j++) {
+ for (uptr j = 1; j < kNumberOfSizeClasses; j++) {
AsanChunk *i = free_lists_[j];
if (!i) continue;
- size_t t = 0;
+ uptr t = 0;
for (; i; i = i->next) {
t += i->Size();
}
@@ -403,24 +403,24 @@ class MallocInfo {
Printf("\n");
}
- PageGroup *FindPageGroup(uintptr_t addr) {
+ PageGroup *FindPageGroup(uptr addr) {
ScopedLock lock(&mu_);
return FindPageGroupUnlocked(addr);
}
private:
- PageGroup *FindPageGroupUnlocked(uintptr_t addr) {
+ PageGroup *FindPageGroupUnlocked(uptr addr) {
int n = n_page_groups_;
// If the page groups are not sorted yet, sort them.
if (n_sorted_page_groups_ < n) {
- SortArray((uintptr_t*)page_groups_, n);
+ SortArray((uptr*)page_groups_, n);
n_sorted_page_groups_ = n;
}
// Binary search over the page groups.
int beg = 0, end = n;
while (beg < end) {
int med = (beg + end) / 2;
- uintptr_t g = (uintptr_t)page_groups_[med];
+ uptr g = (uptr)page_groups_[med];
if (addr > g) {
// 'g' points to the end of the group, so 'addr'
// may not belong to page_groups_[med] or any previous group.
@@ -431,16 +431,16 @@ class MallocInfo {
}
}
if (beg >= n)
- return NULL;
+ return 0;
PageGroup *g = page_groups_[beg];
CHECK(g);
if (g->InRange(addr))
return g;
- return NULL;
+ return 0;
}
// We have an address between two chunks, and we want to report just one.
- AsanChunk *ChooseChunk(uintptr_t addr,
+ AsanChunk *ChooseChunk(uptr addr,
AsanChunk *left_chunk, AsanChunk *right_chunk) {
// Prefer an allocated chunk or a chunk from quarantine.
if (left_chunk->chunk_state == CHUNK_AVAILABLE &&
@@ -450,7 +450,7 @@ class MallocInfo {
left_chunk->chunk_state != CHUNK_AVAILABLE)
return left_chunk;
// Choose based on offset.
- size_t l_offset = 0, r_offset = 0;
+ uptr l_offset = 0, r_offset = 0;
CHECK(left_chunk->AddrIsAtRight(addr, 1, &l_offset));
CHECK(right_chunk->AddrIsAtLeft(addr, 1, &r_offset));
if (l_offset < r_offset)
@@ -458,33 +458,33 @@ class MallocInfo {
return right_chunk;
}
- AsanChunk *FindChunkByAddr(uintptr_t addr) {
+ AsanChunk *FindChunkByAddr(uptr addr) {
PageGroup *g = FindPageGroupUnlocked(addr);
if (!g) return 0;
CHECK(g->size_of_chunk);
- uintptr_t offset_from_beg = addr - g->beg;
- uintptr_t this_chunk_addr = g->beg +
+ uptr offset_from_beg = addr - g->beg;
+ uptr this_chunk_addr = g->beg +
(offset_from_beg / g->size_of_chunk) * g->size_of_chunk;
CHECK(g->InRange(this_chunk_addr));
AsanChunk *m = (AsanChunk*)this_chunk_addr;
CHECK(m->chunk_state == CHUNK_ALLOCATED ||
m->chunk_state == CHUNK_AVAILABLE ||
m->chunk_state == CHUNK_QUARANTINE);
- size_t offset = 0;
+ uptr offset = 0;
if (m->AddrIsInside(addr, 1, &offset))
return m;
if (m->AddrIsAtRight(addr, 1, &offset)) {
if (this_chunk_addr == g->last_chunk) // rightmost chunk
return m;
- uintptr_t right_chunk_addr = this_chunk_addr + g->size_of_chunk;
+ uptr right_chunk_addr = this_chunk_addr + g->size_of_chunk;
CHECK(g->InRange(right_chunk_addr));
return ChooseChunk(addr, m, (AsanChunk*)right_chunk_addr);
} else {
CHECK(m->AddrIsAtLeft(addr, 1, &offset));
if (this_chunk_addr == g->beg) // leftmost chunk
return m;
- uintptr_t left_chunk_addr = this_chunk_addr - g->size_of_chunk;
+ uptr left_chunk_addr = this_chunk_addr - g->size_of_chunk;
CHECK(g->InRange(left_chunk_addr));
return ChooseChunk(addr, (AsanChunk*)left_chunk_addr, m);
}
@@ -498,11 +498,11 @@ class MallocInfo {
CHECK(m->chunk_state == CHUNK_QUARANTINE);
m->chunk_state = CHUNK_AVAILABLE;
- PoisonShadow((uintptr_t)m, m->Size(), kAsanHeapLeftRedzoneMagic);
+ PoisonShadow((uptr)m, m->Size(), kAsanHeapLeftRedzoneMagic);
CHECK(m->alloc_tid >= 0);
CHECK(m->free_tid >= 0);
- size_t size_class = m->SizeClass();
+ uptr size_class = m->SizeClass();
m->next = free_lists_[size_class];
free_lists_[size_class] = m;
@@ -516,11 +516,11 @@ class MallocInfo {
// Get a list of newly allocated chunks.
AsanChunk *GetNewChunks(uint8_t size_class) {
- size_t size = SizeClassToSize(size_class);
+ uptr size = SizeClassToSize(size_class);
CHECK(IsPowerOfTwo(kMinMmapSize));
CHECK(size < kMinMmapSize || (size % kMinMmapSize) == 0);
- size_t mmap_size = Max(size, kMinMmapSize);
- size_t n_chunks = mmap_size / size;
+ uptr mmap_size = Max(size, kMinMmapSize);
+ uptr n_chunks = mmap_size / size;
CHECK(n_chunks * size == mmap_size);
if (size < kPageSize) {
// Size is small, just poison the last chunk.
@@ -538,8 +538,8 @@ class MallocInfo {
thread_stats.mmaped += mmap_size;
thread_stats.mmaped_by_size[size_class] += n_chunks;
- AsanChunk *res = NULL;
- for (size_t i = 0; i < n_chunks; i++) {
+ AsanChunk *res = 0;
+ for (uptr i = 0; i < n_chunks; i++) {
AsanChunk *m = (AsanChunk*)(mem + i * size);
m->chunk_state = CHUNK_AVAILABLE;
m->size_class = size_class;
@@ -548,10 +548,10 @@ class MallocInfo {
}
PageGroup *pg = (PageGroup*)(mem + n_chunks * size);
// This memory is already poisoned, no need to poison it again.
- pg->beg = (uintptr_t)mem;
+ pg->beg = (uptr)mem;
pg->end = pg->beg + mmap_size;
pg->size_of_chunk = size;
- pg->last_chunk = (uintptr_t)(mem + size * (n_chunks - 1));
+ pg->last_chunk = (uptr)(mem + size * (n_chunks - 1));
int page_group_idx = AtomicInc(&n_page_groups_) - 1;
CHECK(page_group_idx < (int)ASAN_ARRAY_SIZE(page_groups_));
page_groups_[page_group_idx] = pg;
@@ -573,7 +573,7 @@ void AsanThreadLocalMallocStorage::CommitBack() {
malloc_info.SwallowThreadLocalMallocStorage(this, true);
}
-static void Describe(uintptr_t addr, size_t access_size) {
+static void Describe(uptr addr, uptr access_size) {
AsanChunk *m = malloc_info.FindMallocedOrFreed(addr, access_size);
if (!m) return;
m->DescribeAddress(addr, access_size);
@@ -608,15 +608,15 @@ static void Describe(uintptr_t addr, size_t access_size) {
}
}
-static uint8_t *Allocate(size_t alignment, size_t size, AsanStackTrace *stack) {
+static uint8_t *Allocate(uptr alignment, uptr size, AsanStackTrace *stack) {
__asan_init();
CHECK(stack);
if (size == 0) {
size = 1; // TODO(kcc): do something smarter
}
CHECK(IsPowerOfTwo(alignment));
- size_t rounded_size = RoundUpTo(size, REDZONE);
- size_t needed_size = rounded_size + REDZONE;
+ uptr rounded_size = RoundUpTo(size, REDZONE);
+ uptr needed_size = rounded_size + REDZONE;
if (alignment > REDZONE) {
needed_size += alignment;
}
@@ -627,7 +627,7 @@ static uint8_t *Allocate(size_t alignment, size_t size, AsanStackTrace *stack) {
}
uint8_t size_class = SizeToSizeClass(needed_size);
- size_t size_to_allocate = SizeClassToSize(size_class);
+ uptr size_to_allocate = SizeClassToSize(size_class);
CHECK(size_to_allocate >= kMinAllocSize);
CHECK(size_to_allocate >= needed_size);
CHECK(IsAligned(size_to_allocate, REDZONE));
@@ -645,7 +645,7 @@ static uint8_t *Allocate(size_t alignment, size_t size, AsanStackTrace *stack) {
thread_stats.malloced_redzones += size_to_allocate - size;
thread_stats.malloced_by_size[size_class]++;
- AsanChunk *m = NULL;
+ AsanChunk *m = 0;
if (!t || size_to_allocate >= kMaxSizeForThreadLocalFreeList) {
// get directly from global storage.
m = malloc_info.AllocateChunks(size_class, 1);
@@ -654,7 +654,7 @@ static uint8_t *Allocate(size_t alignment, size_t size, AsanStackTrace *stack) {
// get from the thread-local storage.
AsanChunk **fl = &t->malloc_storage().free_lists_[size_class];
if (!*fl) {
- size_t n_new_chunks = kMaxSizeForThreadLocalFreeList / size_to_allocate;
+ uptr n_new_chunks = kMaxSizeForThreadLocalFreeList / size_to_allocate;
*fl = malloc_info.AllocateChunks(size_class, n_new_chunks);
thread_stats.malloc_small_slow++;
}
@@ -664,10 +664,10 @@ static uint8_t *Allocate(size_t alignment, size_t size, AsanStackTrace *stack) {
CHECK(m);
CHECK(m->chunk_state == CHUNK_AVAILABLE);
m->chunk_state = CHUNK_ALLOCATED;
- m->next = NULL;
+ m->next = 0;
CHECK(m->Size() == size_to_allocate);
- uintptr_t addr = (uintptr_t)m + REDZONE;
- CHECK(addr == (uintptr_t)m->compressed_free_stack());
+ uptr addr = (uptr)m + REDZONE;
+ CHECK(addr == (uptr)m->compressed_free_stack());
if (alignment > REDZONE && (addr & (alignment - 1))) {
addr = RoundUpTo(addr, alignment);
@@ -678,7 +678,7 @@ static uint8_t *Allocate(size_t alignment, size_t size, AsanStackTrace *stack) {
}
CHECK(m == PtrToChunk(addr));
m->used_size = size;
- m->offset = addr - (uintptr_t)m;
+ m->offset = addr - (uptr)m;
CHECK(m->beg() == addr);
m->alloc_tid = t ? t->tid() : 0;
m->free_tid = AsanThread::kInvalidTid;
@@ -700,11 +700,11 @@ static void Deallocate(uint8_t *ptr, AsanStackTrace *stack) {
CHECK(stack);
if (FLAG_debug) {
- CHECK(malloc_info.FindPageGroup((uintptr_t)ptr));
+ CHECK(malloc_info.FindPageGroup((uptr)ptr));
}
// Printf("Deallocate %p\n", ptr);
- AsanChunk *m = PtrToChunk((uintptr_t)ptr);
+ AsanChunk *m = PtrToChunk((uptr)ptr);
// Flip the state atomically to avoid race on double-free.
uint16_t old_chunk_state = AtomicExchange(&m->chunk_state, CHUNK_QUARANTINE);
@@ -712,7 +712,7 @@ static void Deallocate(uint8_t *ptr, AsanStackTrace *stack) {
if (old_chunk_state == CHUNK_QUARANTINE) {
Report("ERROR: AddressSanitizer attempting double-free on %p:\n", ptr);
stack->PrintStack();
- Describe((uintptr_t)ptr, 1);
+ Describe((uptr)ptr, 1);
ShowStatsAndAbort();
} else if (old_chunk_state != CHUNK_ALLOCATED) {
Report("ERROR: AddressSanitizer attempting free on address which was not"
@@ -727,8 +727,8 @@ static void Deallocate(uint8_t *ptr, AsanStackTrace *stack) {
m->free_tid = t ? t->tid() : 0;
AsanStackTrace::CompressStack(stack, m->compressed_free_stack(),
m->compressed_free_stack_size());
- size_t rounded_size = RoundUpTo(m->used_size, REDZONE);
- PoisonShadow((uintptr_t)ptr, rounded_size, kAsanHeapFreeMagic);
+ uptr rounded_size = RoundUpTo(m->used_size, REDZONE);
+ PoisonShadow((uptr)ptr, rounded_size, kAsanHeapFreeMagic);
// Statistics.
AsanStats &thread_stats = asanThreadRegistry().GetCurrentThreadStats();
@@ -751,7 +751,7 @@ static void Deallocate(uint8_t *ptr, AsanStackTrace *stack) {
}
}
-static uint8_t *Reallocate(uint8_t *old_ptr, size_t new_size,
+static uint8_t *Reallocate(uint8_t *old_ptr, uptr new_size,
AsanStackTrace *stack) {
CHECK(old_ptr && new_size);
@@ -760,13 +760,13 @@ static uint8_t *Reallocate(uint8_t *old_ptr, size_t new_size,
thread_stats.reallocs++;
thread_stats.realloced += new_size;
- AsanChunk *m = PtrToChunk((uintptr_t)old_ptr);
+ AsanChunk *m = PtrToChunk((uptr)old_ptr);
CHECK(m->chunk_state == CHUNK_ALLOCATED);
- size_t old_size = m->used_size;
- size_t memcpy_size = Min(new_size, old_size);
+ uptr old_size = m->used_size;
+ uptr memcpy_size = Min(new_size, old_size);
uint8_t *new_ptr = Allocate(0, new_size, stack);
if (new_ptr) {
- CHECK(REAL(memcpy) != NULL);
+ CHECK(REAL(memcpy) != 0);
REAL(memcpy)(new_ptr, old_ptr, memcpy_size);
Deallocate(old_ptr, stack);
}
@@ -784,9 +784,9 @@ static uint8_t *Reallocate(uint8_t *old_ptr, size_t new_size,
// program must provide implementation of this hook.
// If macro is undefined, the hook is no-op.
#ifdef ASAN_NEW_HOOK
-extern "C" void ASAN_NEW_HOOK(void *ptr, size_t size);
+extern "C" void ASAN_NEW_HOOK(void *ptr, uptr size);
#else
-static inline void ASAN_NEW_HOOK(void *ptr, size_t size) { }
+static inline void ASAN_NEW_HOOK(void *ptr, uptr size) { }
#endif
#ifdef ASAN_DELETE_HOOK
@@ -797,7 +797,7 @@ static inline void ASAN_DELETE_HOOK(void *ptr) { }
namespace __asan {
-void *asan_memalign(size_t alignment, size_t size, AsanStackTrace *stack) {
+void *asan_memalign(uptr alignment, uptr size, AsanStackTrace *stack) {
void *ptr = (void*)Allocate(alignment, size, stack);
ASAN_NEW_HOOK(ptr, size);
return ptr;
@@ -808,13 +808,13 @@ void asan_free(void *ptr, AsanStackTrace *stack) {
Deallocate((uint8_t*)ptr, stack);
}
-void *asan_malloc(size_t size, AsanStackTrace *stack) {
+void *asan_malloc(uptr size, AsanStackTrace *stack) {
void *ptr = (void*)Allocate(0, size, stack);
ASAN_NEW_HOOK(ptr, size);
return ptr;
}
-void *asan_calloc(size_t nmemb, size_t size, AsanStackTrace *stack) {
+void *asan_calloc(uptr nmemb, uptr size, AsanStackTrace *stack) {
void *ptr = (void*)Allocate(0, nmemb * size, stack);
if (ptr)
REAL(memset)(ptr, 0, nmemb * size);
@@ -822,26 +822,26 @@ void *asan_calloc(size_t nmemb, size_t size, AsanStackTrace *stack) {
return ptr;
}
-void *asan_realloc(void *p, size_t size, AsanStackTrace *stack) {
- if (p == NULL) {
+void *asan_realloc(void *p, uptr size, AsanStackTrace *stack) {
+ if (p == 0) {
void *ptr = (void*)Allocate(0, size, stack);
ASAN_NEW_HOOK(ptr, size);
return ptr;
} else if (size == 0) {
ASAN_DELETE_HOOK(p);
Deallocate((uint8_t*)p, stack);
- return NULL;
+ return 0;
}
return Reallocate((uint8_t*)p, size, stack);
}
-void *asan_valloc(size_t size, AsanStackTrace *stack) {
+void *asan_valloc(uptr size, AsanStackTrace *stack) {
void *ptr = (void*)Allocate(kPageSize, size, stack);
ASAN_NEW_HOOK(ptr, size);
return ptr;
}
-void *asan_pvalloc(size_t size, AsanStackTrace *stack) {
+void *asan_pvalloc(uptr size, AsanStackTrace *stack) {
size = RoundUpTo(size, kPageSize);
if (size == 0) {
// pvalloc(0) should allocate one page.
@@ -852,34 +852,34 @@ void *asan_pvalloc(size_t size, AsanStackTrace *stack) {
return ptr;
}
-int asan_posix_memalign(void **memptr, size_t alignment, size_t size,
+int asan_posix_memalign(void **memptr, uptr alignment, uptr size,
AsanStackTrace *stack) {
void *ptr = Allocate(alignment, size, stack);
- CHECK(IsAligned((uintptr_t)ptr, alignment));
+ CHECK(IsAligned((uptr)ptr, alignment));
ASAN_NEW_HOOK(ptr, size);
*memptr = ptr;
return 0;
}
-size_t asan_malloc_usable_size(void *ptr, AsanStackTrace *stack) {
+uptr asan_malloc_usable_size(void *ptr, AsanStackTrace *stack) {
CHECK(stack);
- if (ptr == NULL) return 0;
- size_t usable_size = malloc_info.AllocationSize((uintptr_t)ptr);
+ if (ptr == 0) return 0;
+ uptr usable_size = malloc_info.AllocationSize((uptr)ptr);
if (FLAG_check_malloc_usable_size && (usable_size == 0)) {
Report("ERROR: AddressSanitizer attempting to call malloc_usable_size() "
"for pointer which is not owned: %p\n", ptr);
stack->PrintStack();
- Describe((uintptr_t)ptr, 1);
+ Describe((uptr)ptr, 1);
ShowStatsAndAbort();
}
return usable_size;
}
-size_t asan_mz_size(const void *ptr) {
- return malloc_info.AllocationSize((uintptr_t)ptr);
+uptr asan_mz_size(const void *ptr) {
+ return malloc_info.AllocationSize((uptr)ptr);
}
-void DescribeHeapAddress(uintptr_t addr, uintptr_t access_size) {
+void DescribeHeapAddress(uptr addr, uptr access_size) {
Describe(addr, access_size);
}
@@ -893,34 +893,34 @@ void asan_mz_force_unlock() {
// ---------------------- Fake stack-------------------- {{{1
FakeStack::FakeStack() {
- CHECK(REAL(memset) != NULL);
+ CHECK(REAL(memset) != 0);
REAL(memset)(this, 0, sizeof(*this));
}
-bool FakeStack::AddrIsInSizeClass(uintptr_t addr, size_t size_class) {
- uintptr_t mem = allocated_size_classes_[size_class];
- uintptr_t size = ClassMmapSize(size_class);
+bool FakeStack::AddrIsInSizeClass(uptr addr, uptr size_class) {
+ uptr mem = allocated_size_classes_[size_class];
+ uptr size = ClassMmapSize(size_class);
bool res = mem && addr >= mem && addr < mem + size;
return res;
}
-uintptr_t FakeStack::AddrIsInFakeStack(uintptr_t addr) {
- for (size_t i = 0; i < kNumberOfSizeClasses; i++) {
+uptr FakeStack::AddrIsInFakeStack(uptr addr) {
+ for (uptr i = 0; i < kNumberOfSizeClasses; i++) {
if (AddrIsInSizeClass(addr, i)) return allocated_size_classes_[i];
}
return 0;
}
// We may want to compute this during compilation.
-inline size_t FakeStack::ComputeSizeClass(size_t alloc_size) {
- size_t rounded_size = RoundUpToPowerOfTwo(alloc_size);
- size_t log = Log2(rounded_size);
+inline uptr FakeStack::ComputeSizeClass(uptr alloc_size) {
+ uptr rounded_size = RoundUpToPowerOfTwo(alloc_size);
+ uptr log = Log2(rounded_size);
CHECK(alloc_size <= (1UL << log));
if (!(alloc_size > (1UL << (log-1)))) {
Printf("alloc_size %zu log %zu\n", alloc_size, log);
}
CHECK(alloc_size > (1UL << (log-1)));
- size_t res = log < kMinStackFrameSizeLog ? 0 : log - kMinStackFrameSizeLog;
+ uptr res = log < kMinStackFrameSizeLog ? 0 : log - kMinStackFrameSizeLog;
CHECK(res < kNumberOfSizeClasses);
CHECK(ClassSize(res) >= rounded_size);
return res;
@@ -952,15 +952,15 @@ FakeFrame *FakeFrameFifo::FifoPop() {
return res;
}
-void FakeStack::Init(size_t stack_size) {
+void FakeStack::Init(uptr stack_size) {
stack_size_ = stack_size;
alive_ = true;
}
void FakeStack::Cleanup() {
alive_ = false;
- for (size_t i = 0; i < kNumberOfSizeClasses; i++) {
- uintptr_t mem = allocated_size_classes_[i];
+ for (uptr i = 0; i < kNumberOfSizeClasses; i++) {
+ uptr mem = allocated_size_classes_[i];
if (mem) {
PoisonShadow(mem, ClassMmapSize(i), 0);
allocated_size_classes_[i] = 0;
@@ -969,19 +969,19 @@ void FakeStack::Cleanup() {
}
}
-size_t FakeStack::ClassMmapSize(size_t size_class) {
+uptr FakeStack::ClassMmapSize(uptr size_class) {
return RoundUpToPowerOfTwo(stack_size_);
}
-void FakeStack::AllocateOneSizeClass(size_t size_class) {
+void FakeStack::AllocateOneSizeClass(uptr size_class) {
CHECK(ClassMmapSize(size_class) >= kPageSize);
- uintptr_t new_mem = (uintptr_t)AsanMmapSomewhereOrDie(
+ uptr new_mem = (uptr)AsanMmapSomewhereOrDie(
ClassMmapSize(size_class), __FUNCTION__);
// Printf("T%d new_mem[%zu]: %p-%p mmap %zu\n",
// asanThreadRegistry().GetCurrent()->tid(),
// size_class, new_mem, new_mem + ClassMmapSize(size_class),
// ClassMmapSize(size_class));
- size_t i;
+ uptr i;
for (i = 0; i < ClassMmapSize(size_class);
i += ClassSize(size_class)) {
size_classes_[size_class].FifoPush((FakeFrame*)(new_mem + i));
@@ -990,10 +990,10 @@ void FakeStack::AllocateOneSizeClass(size_t size_class) {
allocated_size_classes_[size_class] = new_mem;
}
-uintptr_t FakeStack::AllocateStack(size_t size, size_t real_stack) {
+uptr FakeStack::AllocateStack(uptr size, uptr real_stack) {
if (!alive_) return real_stack;
CHECK(size <= kMaxStackMallocSize && size > 1);
- size_t size_class = ComputeSizeClass(size);
+ uptr size_class = ComputeSizeClass(size);
if (!allocated_size_classes_[size_class]) {
AllocateOneSizeClass(size_class);
}
@@ -1007,23 +1007,23 @@ uintptr_t FakeStack::AllocateStack(size_t size, size_t real_stack) {
DeallocateFrame(top);
}
call_stack_.LifoPush(fake_frame);
- uintptr_t ptr = (uintptr_t)fake_frame;
+ uptr ptr = (uptr)fake_frame;
PoisonShadow(ptr, size, 0);
return ptr;
}
void FakeStack::DeallocateFrame(FakeFrame *fake_frame) {
CHECK(alive_);
- size_t size = fake_frame->size_minus_one + 1;
- size_t size_class = ComputeSizeClass(size);
+ uptr size = fake_frame->size_minus_one + 1;
+ uptr size_class = ComputeSizeClass(size);
CHECK(allocated_size_classes_[size_class]);
- uintptr_t ptr = (uintptr_t)fake_frame;
+ uptr ptr = (uptr)fake_frame;
CHECK(AddrIsInSizeClass(ptr, size_class));
CHECK(AddrIsInSizeClass(ptr + size - 1, size_class));
size_classes_[size_class].FifoPush(fake_frame);
}
-void FakeStack::OnFree(size_t ptr, size_t size, size_t real_stack) {
+void FakeStack::OnFree(uptr ptr, uptr size, uptr real_stack) {
FakeFrame *fake_frame = (FakeFrame*)ptr;
CHECK(fake_frame->magic = kRetiredStackFrameMagic);
CHECK(fake_frame->descr != 0);
@@ -1036,19 +1036,19 @@ void FakeStack::OnFree(size_t ptr, size_t size, size_t real_stack) {
// ---------------------- Interface ---------------- {{{1
using namespace __asan; // NOLINT
-uptr __asan_stack_malloc(size_t size, size_t real_stack) {
+uptr __asan_stack_malloc(uptr size, uptr real_stack) {
if (!FLAG_use_fake_stack) return real_stack;
AsanThread *t = asanThreadRegistry().GetCurrent();
if (!t) {
// TSD is gone, use the real stack.
return real_stack;
}
- size_t ptr = t->fake_stack().AllocateStack(size, real_stack);
+ uptr ptr = t->fake_stack().AllocateStack(size, real_stack);
// Printf("__asan_stack_malloc %p %zu %p\n", ptr, size, real_stack);
return ptr;
}
-void __asan_stack_free(size_t ptr, size_t size, size_t real_stack) {
+void __asan_stack_free(uptr ptr, uptr size, uptr real_stack) {
if (!FLAG_use_fake_stack) return;
if (ptr != real_stack) {
FakeStack::OnFree(ptr, size, real_stack);
@@ -1063,19 +1063,19 @@ uptr __asan_get_estimated_allocated_size(uptr size) {
}
bool __asan_get_ownership(const void *p) {
- return malloc_info.AllocationSize((uintptr_t)p) > 0;
+ return malloc_info.AllocationSize((uptr)p) > 0;
}
uptr __asan_get_allocated_size(const void *p) {
- if (p == NULL) return 0;
- size_t allocated_size = malloc_info.AllocationSize((uintptr_t)p);
+ if (p == 0) return 0;
+ uptr allocated_size = malloc_info.AllocationSize((uptr)p);
// Die if p is not malloced or if it is already freed.
if (allocated_size == 0) {
Report("ERROR: AddressSanitizer attempting to call "
"__asan_get_allocated_size() for pointer which is "
"not owned: %p\n", p);
PRINT_CURRENT_STACK();
- Describe((uintptr_t)p, 1);
+ Describe((uptr)p, 1);
ShowStatsAndAbort();
}
return allocated_size;
diff --git a/lib/asan/asan_allocator.h b/lib/asan/asan_allocator.h
index cc6ac8487..eee590122 100644
--- a/lib/asan/asan_allocator.h
+++ b/lib/asan/asan_allocator.h
@@ -20,7 +20,7 @@
namespace __asan {
-static const size_t kNumberOfSizeClasses = 255;
+static const uptr kNumberOfSizeClasses = 255;
struct AsanChunk;
class AsanChunkFifoList {
@@ -30,15 +30,15 @@ class AsanChunkFifoList {
void Push(AsanChunk *n);
void PushList(AsanChunkFifoList *q);
AsanChunk *Pop();
- size_t size() { return size_; }
+ uptr size() { return size_; }
void clear() {
- first_ = last_ = NULL;
+ first_ = last_ = 0;
size_ = 0;
}
private:
AsanChunk *first_;
AsanChunk *last_;
- size_t size_;
+ uptr size_;
};
struct AsanThreadLocalMallocStorage {
@@ -57,8 +57,8 @@ struct AsanThreadLocalMallocStorage {
// Fake stack frame contains local variables of one function.
// This struct should fit into a stack redzone (32 bytes).
struct FakeFrame {
- uintptr_t magic; // Modified by the instrumented code.
- uintptr_t descr; // Modified by the instrumented code.
+ uptr magic; // Modified by the instrumented code.
+ uptr descr; // Modified by the instrumented code.
FakeFrame *next;
uint64_t real_stack : 48;
uint64_t size_minus_one : 16;
@@ -100,60 +100,60 @@ class FakeStack {
public:
FakeStack();
explicit FakeStack(LinkerInitialized) {}
- void Init(size_t stack_size);
+ void Init(uptr stack_size);
void StopUsingFakeStack() { alive_ = false; }
void Cleanup();
- uintptr_t AllocateStack(size_t size, size_t real_stack);
- static void OnFree(size_t ptr, size_t size, size_t real_stack);
+ uptr AllocateStack(uptr size, uptr real_stack);
+ static void OnFree(uptr ptr, uptr size, uptr real_stack);
// Return the bottom of the maped region.
- uintptr_t AddrIsInFakeStack(uintptr_t addr);
+ uptr AddrIsInFakeStack(uptr addr);
bool StackSize() { return stack_size_; }
private:
- static const size_t kMinStackFrameSizeLog = 9; // Min frame is 512B.
- static const size_t kMaxStackFrameSizeLog = 16; // Max stack frame is 64K.
- static const size_t kMaxStackMallocSize = 1 << kMaxStackFrameSizeLog;
- static const size_t kNumberOfSizeClasses =
+ static const uptr kMinStackFrameSizeLog = 9; // Min frame is 512B.
+ static const uptr kMaxStackFrameSizeLog = 16; // Max stack frame is 64K.
+ static const uptr kMaxStackMallocSize = 1 << kMaxStackFrameSizeLog;
+ static const uptr kNumberOfSizeClasses =
kMaxStackFrameSizeLog - kMinStackFrameSizeLog + 1;
- bool AddrIsInSizeClass(uintptr_t addr, size_t size_class);
+ bool AddrIsInSizeClass(uptr addr, uptr size_class);
// Each size class should be large enough to hold all frames.
- size_t ClassMmapSize(size_t size_class);
+ uptr ClassMmapSize(uptr size_class);
- size_t ClassSize(size_t size_class) {
+ uptr ClassSize(uptr size_class) {
return 1UL << (size_class + kMinStackFrameSizeLog);
}
void DeallocateFrame(FakeFrame *fake_frame);
- size_t ComputeSizeClass(size_t alloc_size);
- void AllocateOneSizeClass(size_t size_class);
+ uptr ComputeSizeClass(uptr alloc_size);
+ void AllocateOneSizeClass(uptr size_class);
- size_t stack_size_;
+ uptr stack_size_;
bool alive_;
- uintptr_t allocated_size_classes_[kNumberOfSizeClasses];
+ uptr allocated_size_classes_[kNumberOfSizeClasses];
FakeFrameFifo size_classes_[kNumberOfSizeClasses];
FakeFrameLifo call_stack_;
};
-void *asan_memalign(size_t alignment, size_t size, AsanStackTrace *stack);
+void *asan_memalign(uptr alignment, uptr size, AsanStackTrace *stack);
void asan_free(void *ptr, AsanStackTrace *stack);
-void *asan_malloc(size_t size, AsanStackTrace *stack);
-void *asan_calloc(size_t nmemb, size_t size, AsanStackTrace *stack);
-void *asan_realloc(void *p, size_t size, AsanStackTrace *stack);
-void *asan_valloc(size_t size, AsanStackTrace *stack);
-void *asan_pvalloc(size_t size, AsanStackTrace *stack);
+void *asan_malloc(uptr size, AsanStackTrace *stack);
+void *asan_calloc(uptr nmemb, uptr size, AsanStackTrace *stack);
+void *asan_realloc(void *p, uptr size, AsanStackTrace *stack);
+void *asan_valloc(uptr size, AsanStackTrace *stack);
+void *asan_pvalloc(uptr size, AsanStackTrace *stack);
-int asan_posix_memalign(void **memptr, size_t alignment, size_t size,
+int asan_posix_memalign(void **memptr, uptr alignment, uptr size,
AsanStackTrace *stack);
-size_t asan_malloc_usable_size(void *ptr, AsanStackTrace *stack);
+uptr asan_malloc_usable_size(void *ptr, AsanStackTrace *stack);
-size_t asan_mz_size(const void *ptr);
+uptr asan_mz_size(const void *ptr);
void asan_mz_force_lock();
void asan_mz_force_unlock();
-void DescribeHeapAddress(uintptr_t addr, size_t access_size);
+void DescribeHeapAddress(uptr addr, uptr access_size);
} // namespace __asan
#endif // ASAN_ALLOCATOR_H
diff --git a/lib/asan/asan_globals.cc b/lib/asan/asan_globals.cc
index 96972c19c..713f6003e 100644
--- a/lib/asan/asan_globals.cc
+++ b/lib/asan/asan_globals.cc
@@ -36,10 +36,10 @@ static ListOfGlobals *list_of_globals;
static LowLevelAllocator allocator_for_globals(LINKER_INITIALIZED);
void PoisonRedZones(const Global &g) {
- size_t shadow_rz_size = kGlobalAndStackRedzone >> SHADOW_SCALE;
+ uptr shadow_rz_size = kGlobalAndStackRedzone >> SHADOW_SCALE;
CHECK(shadow_rz_size == 1 || shadow_rz_size == 2 || shadow_rz_size == 4);
// full right redzone
- size_t g_aligned_size = kGlobalAndStackRedzone *
+ uptr g_aligned_size = kGlobalAndStackRedzone *
((g.size + kGlobalAndStackRedzone - 1) / kGlobalAndStackRedzone);
PoisonShadow(g.beg + g_aligned_size,
kGlobalAndStackRedzone, kAsanGlobalRedzoneMagic);
@@ -55,21 +55,21 @@ void PoisonRedZones(const Global &g) {
}
}
-static size_t GetAlignedSize(size_t size) {
+static uptr GetAlignedSize(uptr size) {
return ((size + kGlobalAndStackRedzone - 1) / kGlobalAndStackRedzone)
* kGlobalAndStackRedzone;
}
// Check if the global is a zero-terminated ASCII string. If so, print it.
void PrintIfASCII(const Global &g) {
- for (size_t p = g.beg; p < g.beg + g.size - 1; p++) {
+ for (uptr p = g.beg; p < g.beg + g.size - 1; p++) {
if (!isascii(*(char*)p)) return;
}
if (*(char*)(g.beg + g.size - 1) != 0) return;
Printf(" '%s' is ascii string '%s'\n", g.name, g.beg);
}
-bool DescribeAddrIfMyRedZone(const Global &g, uintptr_t addr) {
+bool DescribeAddrIfMyRedZone(const Global &g, uptr addr) {
if (addr < g.beg - kGlobalAndStackRedzone) return false;
if (addr >= g.beg + g.size_with_redzone) return false;
Printf("%p is located ", addr);
@@ -87,7 +87,7 @@ bool DescribeAddrIfMyRedZone(const Global &g, uintptr_t addr) {
}
-bool DescribeAddrIfGlobal(uintptr_t addr) {
+bool DescribeAddrIfGlobal(uptr addr) {
if (!FLAG_report_globals) return false;
ScopedLock lock(&mu_for_globals);
bool res = false;
diff --git a/lib/asan/asan_interceptors.cc b/lib/asan/asan_interceptors.cc
index c68fb78a2..4ecba152b 100644
--- a/lib/asan/asan_interceptors.cc
+++ b/lib/asan/asan_interceptors.cc
@@ -61,27 +61,27 @@ void _longjmp(void *env, int value);
# endif
// string.h / strings.h
-int memcmp(const void *a1, const void *a2, size_t size);
-void* memmove(void *to, const void *from, size_t size);
-void* memcpy(void *to, const void *from, size_t size);
-void* memset(void *block, int c, size_t size);
+int memcmp(const void *a1, const void *a2, uptr size);
+void* memmove(void *to, const void *from, uptr size);
+void* memcpy(void *to, const void *from, uptr size);
+void* memset(void *block, int c, uptr size);
char* strchr(const char *str, int c);
# if defined(__APPLE__)
char* index(const char *string, int c);
# endif
char* strcat(char *to, const char* from); // NOLINT
char* strcpy(char *to, const char* from); // NOLINT
-char* strncpy(char *to, const char* from, size_t size);
+char* strncpy(char *to, const char* from, uptr size);
int strcmp(const char *s1, const char* s2);
-int strncmp(const char *s1, const char* s2, size_t size);
+int strncmp(const char *s1, const char* s2, uptr size);
# if !defined(_WIN32)
int strcasecmp(const char *s1, const char *s2);
-int strncasecmp(const char *s1, const char *s2, size_t n);
+int strncasecmp(const char *s1, const char *s2, uptr n);
char* strdup(const char *s);
# endif
-size_t strlen(const char *s);
+uptr strlen(const char *s);
# if ASAN_INTERCEPT_STRNLEN
-size_t strnlen(const char *s, size_t maxlen);
+uptr strnlen(const char *s, uptr maxlen);
# endif
// stdlib.h
@@ -96,7 +96,7 @@ long long strtoll(const char *nptr, char **endptr, int base); // NOLINT
// Windows threads.
# if defined(_WIN32)
__declspec(dllimport)
-void* __stdcall CreateThread(void *sec, size_t st, void* start,
+void* __stdcall CreateThread(void *sec, uptr st, void* start,
void *arg, DWORD fl, DWORD *id);
# endif
@@ -129,7 +129,7 @@ namespace __asan {
// checking the first and the last byte of a range.
#define ACCESS_MEMORY_RANGE(offset, size, isWrite) do { \
if (size > 0) { \
- uintptr_t ptr = (uintptr_t)(offset); \
+ uptr ptr = (uptr)(offset); \
ACCESS_ADDRESS(ptr, isWrite); \
ACCESS_ADDRESS(ptr + (size) - 1, isWrite); \
} \
@@ -146,8 +146,8 @@ namespace __asan {
// Behavior of functions like "memcpy" or "strcpy" is undefined
// if memory intervals overlap. We report error in this case.
// Macro is used to avoid creation of new frames.
-static inline bool RangesOverlap(const char *offset1, size_t length1,
- const char *offset2, size_t length2) {
+static inline bool RangesOverlap(const char *offset1, uptr length1,
+ const char *offset2, uptr length2) {
return !((offset1 + length1 <= offset2) || (offset2 + length2 <= offset1));
}
#define CHECK_RANGES_OVERLAP(name, _offset1, length1, _offset2, length2) do { \
@@ -205,7 +205,7 @@ int64_t internal_simple_strtoll(const char *nptr, char **endptr, int base) {
have_digits = true;
nptr++;
}
- if (endptr != NULL) {
+ if (endptr != 0) {
*endptr = (have_digits) ? (char*)nptr : old_nptr;
}
if (sgn > 0) {
@@ -216,22 +216,22 @@ int64_t internal_simple_strtoll(const char *nptr, char **endptr, int base) {
}
int64_t internal_atoll(const char *nptr) {
- return internal_simple_strtoll(nptr, (char**)NULL, 10);
+ return internal_simple_strtoll(nptr, (char**)0, 10);
}
-size_t internal_strlen(const char *s) {
- size_t i = 0;
+uptr internal_strlen(const char *s) {
+ uptr i = 0;
while (s[i]) i++;
return i;
}
-size_t internal_strnlen(const char *s, size_t maxlen) {
+uptr internal_strnlen(const char *s, uptr maxlen) {
#if ASAN_INTERCEPT_STRNLEN
- if (REAL(strnlen) != NULL) {
+ if (REAL(strnlen) != 0) {
return REAL(strnlen)(s, maxlen);
}
#endif
- size_t i = 0;
+ uptr i = 0;
while (i < maxlen && s[i]) i++;
return i;
}
@@ -241,36 +241,36 @@ char* internal_strchr(const char *s, int c) {
if (*s == (char)c)
return (char*)s;
if (*s == 0)
- return NULL;
+ return 0;
s++;
}
}
-void* internal_memchr(const void* s, int c, size_t n) {
+void* internal_memchr(const void* s, int c, uptr n) {
const char* t = (char*)s;
- for (size_t i = 0; i < n; ++i, ++t)
+ for (uptr i = 0; i < n; ++i, ++t)
if (*t == c)
return (void*)t;
- return NULL;
+ return 0;
}
-int internal_memcmp(const void* s1, const void* s2, size_t n) {
+int internal_memcmp(const void* s1, const void* s2, uptr n) {
const char* t1 = (char*)s1;
const char* t2 = (char*)s2;
- for (size_t i = 0; i < n; ++i, ++t1, ++t2)
+ for (uptr i = 0; i < n; ++i, ++t1, ++t2)
if (*t1 != *t2)
return *t1 < *t2 ? -1 : 1;
return 0;
}
// Should not be used in performance-critical places.
-void* internal_memset(void* s, int c, size_t n) {
+void* internal_memset(void* s, int c, uptr n) {
// The next line prevents Clang from making a call to memset() instead of the
// loop below.
// FIXME: building the runtime with -ffreestanding is a better idea. However
// there currently are linktime problems due to PR12396.
char volatile *t = (char*)s;
- for (size_t i = 0; i < n; ++i, ++t) {
+ for (uptr i = 0; i < n; ++i, ++t) {
*t = c;
}
return s;
@@ -278,19 +278,19 @@ void* internal_memset(void* s, int c, size_t n) {
char *internal_strstr(const char *haystack, const char *needle) {
// This is O(N^2), but we are not using it in hot places.
- size_t len1 = internal_strlen(haystack);
- size_t len2 = internal_strlen(needle);
+ uptr len1 = internal_strlen(haystack);
+ uptr len2 = internal_strlen(needle);
if (len1 < len2) return 0;
- for (size_t pos = 0; pos <= len1 - len2; pos++) {
+ for (uptr pos = 0; pos <= len1 - len2; pos++) {
if (internal_memcmp(haystack + pos, needle, len2) == 0)
return (char*)haystack + pos;
}
return 0;
}
-char *internal_strncat(char *dst, const char *src, size_t n) {
- size_t len = internal_strlen(dst);
- size_t i;
+char *internal_strncat(char *dst, const char *src, uptr n) {
+ uptr len = internal_strlen(dst);
+ uptr i;
for (i = 0; i < n && src[i]; i++)
dst[len + i] = src[i];
dst[len + i] = 0;
@@ -309,8 +309,8 @@ int internal_strcmp(const char *s1, const char *s2) {
return 0;
}
-char *internal_strncpy(char *dst, const char *src, size_t n) {
- size_t i;
+char *internal_strncpy(char *dst, const char *src, uptr n) {
+ uptr i;
for (i = 0; i < n && src[i]; i++)
dst[i] = src[i];
return dst;
@@ -343,7 +343,7 @@ INTERCEPTOR(void*, signal, int signum, void *handler) {
if (!AsanInterceptsSignal(signum)) {
return REAL(signal)(signum, handler);
}
- return NULL;
+ return 0;
}
INTERCEPTOR(int, sigaction, int signum, const struct sigaction *act,
@@ -400,13 +400,13 @@ static void MlockIsUnsupported() {
extern "C" {
INTERCEPTOR_ATTRIBUTE
-int mlock(const void *addr, size_t len) {
+int mlock(const void *addr, uptr len) {
MlockIsUnsupported();
return 0;
}
INTERCEPTOR_ATTRIBUTE
-int munlock(const void *addr, size_t len) {
+int munlock(const void *addr, uptr len) {
MlockIsUnsupported();
return 0;
}
@@ -434,12 +434,12 @@ static inline int CharCaseCmp(unsigned char c1, unsigned char c2) {
return c1_low - c2_low;
}
-INTERCEPTOR(int, memcmp, const void *a1, const void *a2, size_t size) {
+INTERCEPTOR(int, memcmp, const void *a1, const void *a2, uptr size) {
ENSURE_ASAN_INITED();
unsigned char c1 = 0, c2 = 0;
const unsigned char *s1 = (const unsigned char*)a1;
const unsigned char *s2 = (const unsigned char*)a2;
- size_t i;
+ uptr i;
for (i = 0; i < size; i++) {
c1 = s1[i];
c2 = s2[i];
@@ -450,7 +450,7 @@ INTERCEPTOR(int, memcmp, const void *a1, const void *a2, size_t size) {
return CharCmp(c1, c2);
}
-INTERCEPTOR(void*, memcpy, void *to, const void *from, size_t size) {
+INTERCEPTOR(void*, memcpy, void *to, const void *from, uptr size) {
// memcpy is called during __asan_init() from the internals
// of printf(...).
if (asan_init_is_running) {
@@ -469,7 +469,7 @@ INTERCEPTOR(void*, memcpy, void *to, const void *from, size_t size) {
return REAL(memcpy)(to, from, size);
}
-INTERCEPTOR(void*, memmove, void *to, const void *from, size_t size) {
+INTERCEPTOR(void*, memmove, void *to, const void *from, uptr size) {
ENSURE_ASAN_INITED();
if (FLAG_replace_intrin) {
ASAN_WRITE_RANGE(from, size);
@@ -478,7 +478,7 @@ INTERCEPTOR(void*, memmove, void *to, const void *from, size_t size) {
return REAL(memmove)(to, from, size);
}
-INTERCEPTOR(void*, memset, void *block, int c, size_t size) {
+INTERCEPTOR(void*, memset, void *block, int c, uptr size) {
// memset is called inside Printf.
if (asan_init_is_running) {
return REAL(memset)(block, c, size);
@@ -494,7 +494,7 @@ INTERCEPTOR(char*, strchr, const char *str, int c) {
ENSURE_ASAN_INITED();
char *result = REAL(strchr)(str, c);
if (FLAG_replace_str) {
- size_t bytes_read = (result ? result - str : REAL(strlen)(str)) + 1;
+ uptr bytes_read = (result ? result - str : REAL(strlen)(str)) + 1;
ASAN_READ_RANGE(str, bytes_read);
}
return result;
@@ -510,7 +510,7 @@ DEFINE_REAL(char*, index, const char *string, int c);
INTERCEPTOR(int, strcasecmp, const char *s1, const char *s2) {
ENSURE_ASAN_INITED();
unsigned char c1, c2;
- size_t i;
+ uptr i;
for (i = 0; ; i++) {
c1 = (unsigned char)s1[i];
c2 = (unsigned char)s2[i];
@@ -524,10 +524,10 @@ INTERCEPTOR(int, strcasecmp, const char *s1, const char *s2) {
INTERCEPTOR(char*, strcat, char *to, const char *from) { // NOLINT
ENSURE_ASAN_INITED();
if (FLAG_replace_str) {
- size_t from_length = REAL(strlen)(from);
+ uptr from_length = REAL(strlen)(from);
ASAN_READ_RANGE(from, from_length + 1);
if (from_length > 0) {
- size_t to_length = REAL(strlen)(to);
+ uptr to_length = REAL(strlen)(to);
ASAN_READ_RANGE(to, to_length);
ASAN_WRITE_RANGE(to + to_length, from_length + 1);
CHECK_RANGES_OVERLAP("strcat", to, to_length + 1, from, from_length + 1);
@@ -541,7 +541,7 @@ INTERCEPTOR(int, strcmp, const char *s1, const char *s2) {
return internal_strcmp(s1, s2);
}
unsigned char c1, c2;
- size_t i;
+ uptr i;
for (i = 0; ; i++) {
c1 = (unsigned char)s1[i];
c2 = (unsigned char)s2[i];
@@ -560,7 +560,7 @@ INTERCEPTOR(char*, strcpy, char *to, const char *from) { // NOLINT
}
ENSURE_ASAN_INITED();
if (FLAG_replace_str) {
- size_t from_size = REAL(strlen)(from) + 1;
+ uptr from_size = REAL(strlen)(from) + 1;
CHECK_RANGES_OVERLAP("strcpy", to, from_size, from, from_size);
ASAN_READ_RANGE(from, from_size);
ASAN_WRITE_RANGE(to, from_size);
@@ -571,30 +571,30 @@ INTERCEPTOR(char*, strcpy, char *to, const char *from) { // NOLINT
INTERCEPTOR(char*, strdup, const char *s) {
ENSURE_ASAN_INITED();
if (FLAG_replace_str) {
- size_t length = REAL(strlen)(s);
+ uptr length = REAL(strlen)(s);
ASAN_READ_RANGE(s, length + 1);
}
return REAL(strdup)(s);
}
-INTERCEPTOR(size_t, strlen, const char *s) {
+INTERCEPTOR(uptr, strlen, const char *s) {
// strlen is called from malloc_default_purgeable_zone()
// in __asan::ReplaceSystemAlloc() on Mac.
if (asan_init_is_running) {
return REAL(strlen)(s);
}
ENSURE_ASAN_INITED();
- size_t length = REAL(strlen)(s);
+ uptr length = REAL(strlen)(s);
if (FLAG_replace_str) {
ASAN_READ_RANGE(s, length + 1);
}
return length;
}
-INTERCEPTOR(int, strncasecmp, const char *s1, const char *s2, size_t n) {
+INTERCEPTOR(int, strncasecmp, const char *s1, const char *s2, uptr n) {
ENSURE_ASAN_INITED();
unsigned char c1 = 0, c2 = 0;
- size_t i;
+ uptr i;
for (i = 0; i < n; i++) {
c1 = (unsigned char)s1[i];
c2 = (unsigned char)s2[i];
@@ -605,14 +605,14 @@ INTERCEPTOR(int, strncasecmp, const char *s1, const char *s2, size_t n) {
return CharCaseCmp(c1, c2);
}
-INTERCEPTOR(int, strncmp, const char *s1, const char *s2, size_t size) {
+INTERCEPTOR(int, strncmp, const char *s1, const char *s2, uptr size) {
// strncmp is called from malloc_default_purgeable_zone()
// in __asan::ReplaceSystemAlloc() on Mac.
if (asan_init_is_running) {
return REAL(strncmp)(s1, s2, size);
}
unsigned char c1 = 0, c2 = 0;
- size_t i;
+ uptr i;
for (i = 0; i < size; i++) {
c1 = (unsigned char)s1[i];
c2 = (unsigned char)s2[i];
@@ -623,10 +623,10 @@ INTERCEPTOR(int, strncmp, const char *s1, const char *s2, size_t size) {
return CharCmp(c1, c2);
}
-INTERCEPTOR(char*, strncpy, char *to, const char *from, size_t size) {
+INTERCEPTOR(char*, strncpy, char *to, const char *from, uptr size) {
ENSURE_ASAN_INITED();
if (FLAG_replace_str) {
- size_t from_size = Min(size, internal_strnlen(from, size) + 1);
+ uptr from_size = Min(size, internal_strnlen(from, size) + 1);
CHECK_RANGES_OVERLAP("strncpy", to, from_size, from, from_size);
ASAN_READ_RANGE(from, from_size);
ASAN_WRITE_RANGE(to, size);
@@ -635,9 +635,9 @@ INTERCEPTOR(char*, strncpy, char *to, const char *from, size_t size) {
}
#if ASAN_INTERCEPT_STRNLEN
-INTERCEPTOR(size_t, strnlen, const char *s, size_t maxlen) {
+INTERCEPTOR(uptr, strnlen, const char *s, uptr maxlen) {
ENSURE_ASAN_INITED();
- size_t length = REAL(strnlen)(s, maxlen);
+ uptr length = REAL(strnlen)(s, maxlen);
if (FLAG_replace_str) {
ASAN_READ_RANGE(s, Min(length + 1, maxlen));
}
@@ -650,7 +650,7 @@ static inline bool IsValidStrtolBase(int base) {
}
static inline void FixRealStrtolEndptr(const char *nptr, char **endptr) {
- CHECK(endptr != NULL);
+ CHECK(endptr != 0);
if (nptr == *endptr) {
// No digits were found at strtol call, we need to find out the last
// symbol accessed by strtoll on our own.
@@ -670,7 +670,7 @@ INTERCEPTOR(long, strtol, const char *nptr, // NOLINT
}
char *real_endptr;
long result = REAL(strtol)(nptr, &real_endptr, base); // NOLINT
- if (endptr != NULL) {
+ if (endptr != 0) {
*endptr = real_endptr;
}
if (IsValidStrtolBase(base)) {
@@ -687,7 +687,7 @@ INTERCEPTOR(int, atoi, const char *nptr) {
}
char *real_endptr;
// "man atoi" tells that behavior of atoi(nptr) is the same as
- // strtol(nptr, NULL, 10), i.e. it sets errno to ERANGE if the
+ // strtol(nptr, 0, 10), i.e. it sets errno to ERANGE if the
// parsed integer can't be stored in *long* type (even if it's
// different from int). So, we just imitate this behavior.
int result = REAL(strtol)(nptr, &real_endptr, 10);
@@ -717,7 +717,7 @@ INTERCEPTOR(long long, strtoll, const char *nptr, // NOLINT
}
char *real_endptr;
long long result = REAL(strtoll)(nptr, &real_endptr, base); // NOLINT
- if (endptr != NULL) {
+ if (endptr != 0) {
*endptr = real_endptr;
}
// If base has unsupported value, strtoll can exit with EINVAL
@@ -750,7 +750,7 @@ INTERCEPTOR(long long, atoll, const char *nptr) { // NOLINT
#if defined(_WIN32)
INTERCEPTOR_WINAPI(DWORD, CreateThread,
- void* security, size_t stack_size,
+ void* security, uptr stack_size,
DWORD (__stdcall *start_routine)(void*), void* arg,
DWORD flags, void* tid) {
GET_STACK_TRACE_HERE(kStackTraceMax);
diff --git a/lib/asan/asan_interceptors.h b/lib/asan/asan_interceptors.h
index e98514ec4..005e7e4db 100644
--- a/lib/asan/asan_interceptors.h
+++ b/lib/asan/asan_interceptors.h
@@ -17,13 +17,13 @@
#include "asan_internal.h"
#include "interception/interception.h"
-DECLARE_REAL(int, memcmp, const void *a1, const void *a2, size_t size);
-DECLARE_REAL(void*, memcpy, void *to, const void *from, size_t size);
-DECLARE_REAL(void*, memset, void *block, int c, size_t size);
+DECLARE_REAL(int, memcmp, const void *a1, const void *a2, uptr size);
+DECLARE_REAL(void*, memcpy, void *to, const void *from, uptr size);
+DECLARE_REAL(void*, memset, void *block, int c, uptr size);
DECLARE_REAL(char*, strchr, const char *str, int c);
-DECLARE_REAL(size_t, strlen, const char *s);
-DECLARE_REAL(char*, strncpy, char *to, const char *from, size_t size);
-DECLARE_REAL(size_t, strnlen, const char *s, size_t maxlen);
+DECLARE_REAL(uptr, strlen, const char *s);
+DECLARE_REAL(char*, strncpy, char *to, const char *from, uptr size);
+DECLARE_REAL(uptr, strnlen, const char *s, uptr maxlen);
struct sigaction;
DECLARE_REAL(int, sigaction, int signum, const struct sigaction *act,
struct sigaction *oldact);
@@ -32,16 +32,16 @@ namespace __asan {
// __asan::internal_X() is the implementation of X() for use in RTL.
int64_t internal_atoll(const char *nptr);
-size_t internal_strlen(const char *s);
-size_t internal_strnlen(const char *s, size_t maxlen);
+uptr internal_strlen(const char *s);
+uptr internal_strnlen(const char *s, uptr maxlen);
char* internal_strchr(const char *s, int c);
-void* internal_memchr(const void* s, int c, size_t n);
-void* internal_memset(void *s, int c, size_t n);
-int internal_memcmp(const void* s1, const void* s2, size_t n);
+void* internal_memchr(const void* s, int c, uptr n);
+void* internal_memset(void *s, int c, uptr n);
+int internal_memcmp(const void* s1, const void* s2, uptr n);
char *internal_strstr(const char *haystack, const char *needle);
-char *internal_strncat(char *dst, const char *src, size_t n);
+char *internal_strncat(char *dst, const char *src, uptr n);
int internal_strcmp(const char *s1, const char *s2);
-char *internal_strncpy(char *dst, const char *src, size_t n);
+char *internal_strncpy(char *dst, const char *src, uptr n);
// Works only for base=10 and doesn't set errno.
int64_t internal_simple_strtoll(const char *nptr, char **endptr, int base);
diff --git a/lib/asan/asan_interface.h b/lib/asan/asan_interface.h
index 794bcfeb2..9dc507c50 100644
--- a/lib/asan/asan_interface.h
+++ b/lib/asan/asan_interface.h
@@ -112,7 +112,7 @@ extern "C" {
SANITIZER_INTERFACE_FUNCTION_ATTRIBUTE;
// Sets the callback to be called right before death on error.
- // Passing NULL will unset the callback.
+ // Passing 0 will unset the callback.
void __asan_set_death_callback(void (*callback)(void))
SANITIZER_INTERFACE_FUNCTION_ATTRIBUTE;
@@ -130,7 +130,7 @@ extern "C" {
bool __asan_get_ownership(const void *p)
SANITIZER_INTERFACE_FUNCTION_ATTRIBUTE;
// Returns the number of bytes reserved for the pointer p.
- // Requires (get_ownership(p) == true) or (p == NULL).
+ // Requires (get_ownership(p) == true) or (p == 0).
uptr __asan_get_allocated_size(const void *p)
SANITIZER_INTERFACE_FUNCTION_ATTRIBUTE;
// Number of bytes, allocated and not yet freed by the application.
diff --git a/lib/asan/asan_internal.h b/lib/asan/asan_internal.h
index 68a539424..53d6eb280 100644
--- a/lib/asan/asan_internal.h
+++ b/lib/asan/asan_internal.h
@@ -14,18 +14,17 @@
#ifndef ASAN_INTERNAL_H
#define ASAN_INTERNAL_H
+#include "sanitizer_common/sanitizer_defs.h"
#include "sanitizer_common/sanitizer_libc.h"
#if !defined(__linux__) && !defined(__APPLE__) && !defined(_WIN32)
# error "This operating system is not supported by AddressSanitizer"
#endif
-#include <stddef.h> // for size_t, uintptr_t, etc.
-
#if defined(_WIN32)
# if defined(__clang__)
typedef int intptr_t;
-typedef unsigned int uintptr_t;
+typedef unsigned int uptr;
# endif
// There's no <stdint.h> in Visual Studio 9, so we have to define [u]int*_t.
@@ -160,13 +159,13 @@ void NORETURN CheckFailed(const char *cond, const char *file, int line);
void NORETURN ShowStatsAndAbort();
// asan_globals.cc
-bool DescribeAddrIfGlobal(uintptr_t addr);
+bool DescribeAddrIfGlobal(uptr addr);
void ReplaceOperatorsNewAndDelete();
// asan_malloc_linux.cc / asan_malloc_mac.cc
void ReplaceSystemMalloc();
-void OutOfMemoryMessageAndDie(const char *mem_type, size_t size);
+void OutOfMemoryMessageAndDie(const char *mem_type, uptr size);
// asan_linux.cc / asan_mac.cc / asan_win.cc
void *AsanDoesNotSupportStaticLinkage();
@@ -175,17 +174,17 @@ int AsanOpenReadonly(const char* filename);
const char *AsanGetEnv(const char *name);
void AsanDumpProcessMap();
-void *AsanMmapFixedNoReserve(uintptr_t fixed_addr, size_t size);
-void *AsanMmapFixedReserve(uintptr_t fixed_addr, size_t size);
-void *AsanMprotect(uintptr_t fixed_addr, size_t size);
-void *AsanMmapSomewhereOrDie(size_t size, const char *where);
-void AsanUnmapOrDie(void *ptr, size_t size);
+void *AsanMmapFixedNoReserve(uptr fixed_addr, uptr size);
+void *AsanMmapFixedReserve(uptr fixed_addr, uptr size);
+void *AsanMprotect(uptr fixed_addr, uptr size);
+void *AsanMmapSomewhereOrDie(uptr size, const char *where);
+void AsanUnmapOrDie(void *ptr, uptr size);
void AsanDisableCoreDumper();
-void GetPcSpBp(void *context, uintptr_t *pc, uintptr_t *sp, uintptr_t *bp);
+void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp);
-size_t AsanRead(int fd, void *buf, size_t count);
-size_t AsanWrite(int fd, const void *buf, size_t count);
+uptr AsanRead(int fd, void *buf, uptr count);
+uptr AsanWrite(int fd, const void *buf, uptr count);
int AsanClose(int fd);
bool AsanInterceptsSignal(int signum);
@@ -193,7 +192,7 @@ void SetAlternateSignalStack();
void UnsetAlternateSignalStack();
void InstallSignalHandlers();
int GetPid();
-uintptr_t GetThreadSelf();
+uptr GetThreadSelf();
int AtomicInc(int *a);
uint16_t AtomicExchange(uint16_t *a, uint16_t new_val);
@@ -206,12 +205,12 @@ void AsanTSDSet(void *tsd);
// The resulting buffer is mmaped and stored in '*buff'.
// The size of the mmaped region is stored in '*buff_size',
// Returns the number of read bytes or 0 if file can not be opened.
-size_t ReadFileToBuffer(const char *file_name, char **buff,
- size_t *buff_size, size_t max_len);
+uptr ReadFileToBuffer(const char *file_name, char **buff,
+ uptr *buff_size, uptr max_len);
// asan_printf.cc
void RawWrite(const char *buffer);
-int SNPrintf(char *buffer, size_t length, const char *format, ...);
+int SNPrintf(char *buffer, uptr length, const char *format, ...);
void Printf(const char *format, ...);
int SScanf(const char *str, const char *format, ...);
void Report(const char *format, ...);
@@ -220,16 +219,16 @@ void Report(const char *format, ...);
template<class T> T Min(T a, T b) { return a < b ? a : b; }
template<class T> T Max(T a, T b) { return a > b ? a : b; }
-void SortArray(uintptr_t *array, size_t size);
+void SortArray(uptr *array, uptr size);
// asan_poisoning.cc
// Poisons the shadow memory for "size" bytes starting from "addr".
-void PoisonShadow(uintptr_t addr, size_t size, uint8_t value);
+void PoisonShadow(uptr addr, uptr size, uint8_t value);
// Poisons the shadow memory for "redzone_size" bytes starting from
// "addr + size".
-void PoisonShadowPartialRightRedzone(uintptr_t addr,
- uintptr_t size,
- uintptr_t redzone_size,
+void PoisonShadowPartialRightRedzone(uptr addr,
+ uptr size,
+ uptr redzone_size,
uint8_t value);
// Platfrom-specific options.
@@ -241,21 +240,21 @@ bool PlatformHasDifferentMemcpyAndMemmove();
# define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE true
#endif // __APPLE__
-extern size_t FLAG_quarantine_size;
+extern uptr FLAG_quarantine_size;
extern int64_t FLAG_demangle;
extern bool FLAG_symbolize;
extern int64_t FLAG_v;
-extern size_t FLAG_redzone;
+extern uptr FLAG_redzone;
extern int64_t FLAG_debug;
extern bool FLAG_poison_shadow;
extern int64_t FLAG_report_globals;
-extern size_t FLAG_malloc_context_size;
+extern uptr FLAG_malloc_context_size;
extern bool FLAG_replace_str;
extern bool FLAG_replace_intrin;
extern bool FLAG_replace_cfallocator;
extern bool FLAG_fast_unwind;
extern bool FLAG_use_fake_stack;
-extern size_t FLAG_max_malloc_fill_size;
+extern uptr FLAG_max_malloc_fill_size;
extern int64_t FLAG_exitcode;
extern bool FLAG_allow_user_poisoning;
extern int64_t FLAG_sleep_before_dying;
@@ -292,28 +291,28 @@ int Atexit(void (*function)(void));
#define ASAN_ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
-const size_t kWordSize = __WORDSIZE / 8;
-const size_t kWordSizeInBits = 8 * kWordSize;
-const size_t kPageSizeBits = 12;
-const size_t kPageSize = 1UL << kPageSizeBits;
+const uptr kWordSize = __WORDSIZE / 8;
+const uptr kWordSizeInBits = 8 * kWordSize;
+const uptr kPageSizeBits = 12;
+const uptr kPageSize = 1UL << kPageSizeBits;
#if !defined(_WIN32) || defined(__clang__)
-# define GET_CALLER_PC() (uintptr_t)__builtin_return_address(0)
-# define GET_CURRENT_FRAME() (uintptr_t)__builtin_frame_address(0)
+# define GET_CALLER_PC() (uptr)__builtin_return_address(0)
+# define GET_CURRENT_FRAME() (uptr)__builtin_frame_address(0)
#else
-# define GET_CALLER_PC() (uintptr_t)_ReturnAddress()
+# define GET_CALLER_PC() (uptr)_ReturnAddress()
// CaptureStackBackTrace doesn't need to know BP on Windows.
// FIXME: This macro is still used when printing error reports though it's not
// clear if the BP value is needed in the ASan reports on Windows.
-# define GET_CURRENT_FRAME() (uintptr_t)0xDEADBEEF
+# define GET_CURRENT_FRAME() (uptr)0xDEADBEEF
#endif
#ifndef _WIN32
-const size_t kMmapGranularity = kPageSize;
+const uptr kMmapGranularity = kPageSize;
# define THREAD_CALLING_CONV
typedef void* thread_return_t;
#else
-const size_t kMmapGranularity = 1UL << 16;
+const uptr kMmapGranularity = 1UL << 16;
# define THREAD_CALLING_CONV __stdcall
typedef DWORD thread_return_t;
@@ -338,15 +337,15 @@ const int kAsanUserPoisonedMemoryMagic = 0xf7;
const int kAsanGlobalRedzoneMagic = 0xf9;
const int kAsanInternalHeapMagic = 0xfe;
-static const uintptr_t kCurrentStackFrameMagic = 0x41B58AB3;
-static const uintptr_t kRetiredStackFrameMagic = 0x45E0360E;
+static const uptr kCurrentStackFrameMagic = 0x41B58AB3;
+static const uptr kRetiredStackFrameMagic = 0x45E0360E;
// --------------------------- Bit twiddling ------- {{{1
-inline bool IsPowerOfTwo(size_t x) {
+inline bool IsPowerOfTwo(uptr x) {
return (x & (x - 1)) == 0;
}
-inline size_t RoundUpTo(size_t size, size_t boundary) {
+inline uptr RoundUpTo(uptr size, uptr boundary) {
CHECK(IsPowerOfTwo(boundary));
return (size + boundary - 1) & ~(boundary - 1);
}
@@ -358,7 +357,7 @@ class LowLevelAllocator {
explicit LowLevelAllocator(LinkerInitialized) {}
// 'size' must be a power of two.
// Requires an external lock.
- void *Allocate(size_t size);
+ void *Allocate(uptr size);
private:
char *allocated_end_;
char *allocated_current_;
diff --git a/lib/asan/asan_linux.cc b/lib/asan/asan_linux.cc
index 26c67e917..5ff4dea64 100644
--- a/lib/asan/asan_linux.cc
+++ b/lib/asan/asan_linux.cc
@@ -39,14 +39,14 @@ extern "C" void* _DYNAMIC;
namespace __asan {
-const size_t kMaxThreadStackSize = 256 * (1 << 20); // 256M
+const uptr kMaxThreadStackSize = 256 * (1 << 20); // 256M
void *AsanDoesNotSupportStaticLinkage() {
// This will fail to link with -static.
return &_DYNAMIC; // defined in link.h
}
-void GetPcSpBp(void *context, uintptr_t *pc, uintptr_t *sp, uintptr_t *bp) {
+void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) {
#ifdef ANDROID
*pc = *sp = *bp = 0;
#elif defined(__arm__)
@@ -73,7 +73,7 @@ bool AsanInterceptsSignal(int signum) {
return signum == SIGSEGV && FLAG_handle_segv;
}
-static void *asan_mmap(void *addr, size_t length, int prot, int flags,
+static void *asan_mmap(void *addr, uptr length, int prot, int flags,
int fd, uint64_t offset) {
# if __WORDSIZE == 64
return (void *)syscall(__NR_mmap, addr, length, prot, flags, fd, offset);
@@ -82,7 +82,7 @@ static void *asan_mmap(void *addr, size_t length, int prot, int flags,
# endif
}
-void *AsanMmapSomewhereOrDie(size_t size, const char *mem_type) {
+void *AsanMmapSomewhereOrDie(uptr size, const char *mem_type) {
size = RoundUpTo(size, kPageSize);
void *res = asan_mmap(0, size,
PROT_READ | PROT_WRITE,
@@ -93,21 +93,21 @@ void *AsanMmapSomewhereOrDie(size_t size, const char *mem_type) {
return res;
}
-void *AsanMmapFixedNoReserve(uintptr_t fixed_addr, size_t size) {
+void *AsanMmapFixedNoReserve(uptr fixed_addr, uptr size) {
return asan_mmap((void*)fixed_addr, size,
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON | MAP_FIXED | MAP_NORESERVE,
0, 0);
}
-void *AsanMprotect(uintptr_t fixed_addr, size_t size) {
+void *AsanMprotect(uptr fixed_addr, uptr size) {
return asan_mmap((void*)fixed_addr, size,
PROT_NONE,
MAP_PRIVATE | MAP_ANON | MAP_FIXED | MAP_NORESERVE,
0, 0);
}
-void AsanUnmapOrDie(void *addr, size_t size) {
+void AsanUnmapOrDie(void *addr, uptr size) {
if (!addr || !size) return;
int res = syscall(__NR_munmap, addr, size);
if (res != 0) {
@@ -116,8 +116,8 @@ void AsanUnmapOrDie(void *addr, size_t size) {
}
}
-size_t AsanWrite(int fd, const void *buf, size_t count) {
- return (size_t)syscall(__NR_write, fd, buf, count);
+uptr AsanWrite(int fd, const void *buf, uptr count) {
+ return (uptr)syscall(__NR_write, fd, buf, count);
}
int AsanOpenReadonly(const char* filename) {
@@ -128,32 +128,32 @@ int AsanOpenReadonly(const char* filename) {
// This function should be called first inside __asan_init.
const char* AsanGetEnv(const char* name) {
static char *environ;
- static size_t len;
+ static uptr len;
static bool inited;
if (!inited) {
inited = true;
- size_t environ_size;
+ uptr environ_size;
len = ReadFileToBuffer("/proc/self/environ",
&environ, &environ_size, 1 << 26);
}
- if (!environ || len == 0) return NULL;
- size_t namelen = internal_strlen(name);
+ if (!environ || len == 0) return 0;
+ uptr namelen = internal_strlen(name);
const char *p = environ;
while (*p != '\0') { // will happen at the \0\0 that terminates the buffer
// proc file has the format NAME=value\0NAME=value\0NAME=value\0...
const char* endp =
(char*)internal_memchr(p, '\0', len - (p - environ));
- if (endp == NULL) // this entry isn't NUL terminated
- return NULL;
+ if (endp == 0) // this entry isn't NUL terminated
+ return 0;
else if (!internal_memcmp(p, name, namelen) && p[namelen] == '=') // Match.
return p + namelen + 1; // point after =
p = endp + 1;
}
- return NULL; // Not found.
+ return 0; // Not found.
}
-size_t AsanRead(int fd, void *buf, size_t count) {
- return (size_t)syscall(__NR_read, fd, buf, count);
+uptr AsanRead(int fd, void *buf, uptr count) {
+ return (uptr)syscall(__NR_read, fd, buf, count);
}
int AsanClose(int fd) {
@@ -177,21 +177,21 @@ void AsanProcMaps::Reset() {
current_ = proc_self_maps_buff_;
}
-bool AsanProcMaps::Next(uintptr_t *start, uintptr_t *end,
- uintptr_t *offset, char filename[],
- size_t filename_size) {
+bool AsanProcMaps::Next(uptr *start, uptr *end,
+ uptr *offset, char filename[],
+ uptr filename_size) {
char *last = proc_self_maps_buff_ + proc_self_maps_buff_len_;
if (current_ >= last) return false;
int consumed = 0;
char flags[10];
int major, minor;
- uintptr_t inode;
- uintptr_t dummy;
+ uptr inode;
+ uptr dummy;
if (!start) start = &dummy;
if (!end) end = &dummy;
if (!offset) offset = &dummy;
char *next_line = (char*)internal_memchr(current_, '\n', last - current_);
- if (next_line == NULL)
+ if (next_line == 0)
next_line = last;
if (SScanf(current_,
"%lx-%lx %4s %lx %x:%x %ld %n",
@@ -203,7 +203,7 @@ bool AsanProcMaps::Next(uintptr_t *start, uintptr_t *end,
while (current_ < next_line && *current_ == ' ')
current_++;
// Fill in the filename.
- size_t i = 0;
+ uptr i = 0;
while (current_ < next_line) {
if (filename && i < filename_size - 1)
filename[i++] = *current_;
@@ -216,9 +216,9 @@ bool AsanProcMaps::Next(uintptr_t *start, uintptr_t *end,
}
// Gets the object name and the offset by walking AsanProcMaps.
-bool AsanProcMaps::GetObjectNameAndOffset(uintptr_t addr, uintptr_t *offset,
+bool AsanProcMaps::GetObjectNameAndOffset(uptr addr, uptr *offset,
char filename[],
- size_t filename_size) {
+ uptr filename_size) {
return IterateForObjectNameAndOffset(addr, offset, filename, filename_size);
}
@@ -230,18 +230,18 @@ void AsanThread::SetThreadStackTopAndBottom() {
// Find the mapping that contains a stack variable.
AsanProcMaps proc_maps;
- uintptr_t start, end, offset;
- uintptr_t prev_end = 0;
- while (proc_maps.Next(&start, &end, &offset, NULL, 0)) {
- if ((uintptr_t)&rl < end)
+ uptr start, end, offset;
+ uptr prev_end = 0;
+ while (proc_maps.Next(&start, &end, &offset, 0, 0)) {
+ if ((uptr)&rl < end)
break;
prev_end = end;
}
- CHECK((uintptr_t)&rl >= start && (uintptr_t)&rl < end);
+ CHECK((uptr)&rl >= start && (uptr)&rl < end);
// Get stacksize from rlimit, but clip it so that it does not overlap
// with other mappings.
- size_t stacksize = rl.rlim_cur;
+ uptr stacksize = rl.rlim_cur;
if (stacksize > end - prev_end)
stacksize = end - prev_end;
// When running with unlimited stack size, we still want to set some limit.
@@ -251,20 +251,20 @@ void AsanThread::SetThreadStackTopAndBottom() {
stacksize = kMaxThreadStackSize;
stack_top_ = end;
stack_bottom_ = end - stacksize;
- CHECK(AddrIsInStack((uintptr_t)&rl));
+ CHECK(AddrIsInStack((uptr)&rl));
return;
}
pthread_attr_t attr;
CHECK(pthread_getattr_np(pthread_self(), &attr) == 0);
- size_t stacksize = 0;
- void *stackaddr = NULL;
- pthread_attr_getstack(&attr, &stackaddr, &stacksize);
+ uptr stacksize = 0;
+ void *stackaddr = 0;
+ pthread_attr_getstack(&attr, &stackaddr, (size_t*)&stacksize);
pthread_attr_destroy(&attr);
- stack_top_ = (uintptr_t)stackaddr + stacksize;
- stack_bottom_ = (uintptr_t)stackaddr;
+ stack_top_ = (uptr)stackaddr + stacksize;
+ stack_bottom_ = (uptr)stackaddr;
CHECK(stacksize < kMaxThreadStackSize); // Sanity check.
- CHECK(AddrIsInStack((uintptr_t)&attr));
+ CHECK(AddrIsInStack((uptr)&attr));
}
AsanLock::AsanLock(LinkerInitialized) {
@@ -278,11 +278,11 @@ void AsanLock::Lock() {
CHECK(sizeof(pthread_mutex_t) <= sizeof(opaque_storage_));
pthread_mutex_lock((pthread_mutex_t*)&opaque_storage_);
CHECK(!owner_);
- owner_ = (uintptr_t)pthread_self();
+ owner_ = (uptr)pthread_self();
}
void AsanLock::Unlock() {
- CHECK(owner_ == (uintptr_t)pthread_self());
+ CHECK(owner_ == (uptr)pthread_self());
owner_ = 0;
pthread_mutex_unlock((pthread_mutex_t*)&opaque_storage_);
}
@@ -295,14 +295,14 @@ void AsanLock::Unlock() {
#define UNWIND_CONTINUE _URC_NO_REASON
#endif
-uintptr_t Unwind_GetIP(struct _Unwind_Context *ctx) {
+uptr Unwind_GetIP(struct _Unwind_Context *ctx) {
#ifdef __arm__
- uintptr_t val;
+ uptr val;
_Unwind_VRS_Result res = _Unwind_VRS_Get(ctx, _UVRSC_CORE,
15 /* r15 = PC */, _UVRSD_UINT32, &val);
CHECK(res == _UVRSR_OK && "_Unwind_VRS_Get failed");
// Clear the Thumb bit.
- return val & ~(uintptr_t)1;
+ return val & ~(uptr)1;
#else
return _Unwind_GetIP(ctx);
#endif
@@ -312,13 +312,13 @@ _Unwind_Reason_Code Unwind_Trace(struct _Unwind_Context *ctx,
void *param) {
AsanStackTrace *b = (AsanStackTrace*)param;
CHECK(b->size < b->max_size);
- uintptr_t pc = Unwind_GetIP(ctx);
+ uptr pc = Unwind_GetIP(ctx);
b->trace[b->size++] = pc;
if (b->size == b->max_size) return UNWIND_STOP;
return UNWIND_CONTINUE;
}
-void AsanStackTrace::GetStackTrace(size_t max_s, uintptr_t pc, uintptr_t bp) {
+void AsanStackTrace::GetStackTrace(uptr max_s, uptr pc, uptr bp) {
size = 0;
trace[0] = pc;
if ((max_s) > 1) {
diff --git a/lib/asan/asan_lock.h b/lib/asan/asan_lock.h
index 75da8ae68..15b2180ce 100644
--- a/lib/asan/asan_lock.h
+++ b/lib/asan/asan_lock.h
@@ -30,8 +30,8 @@ class AsanLock {
void Unlock();
bool IsLocked() { return owner_ != 0; }
private:
- uintptr_t opaque_storage_[10];
- uintptr_t owner_; // for debugging and for malloc_introspection_t interface
+ uptr opaque_storage_[10];
+ uptr owner_; // for debugging and for malloc_introspection_t interface
};
class ScopedLock {
diff --git a/lib/asan/asan_mac.cc b/lib/asan/asan_mac.cc
index df039c55c..e3c1e722a 100644
--- a/lib/asan/asan_mac.cc
+++ b/lib/asan/asan_mac.cc
@@ -37,7 +37,7 @@
namespace __asan {
-void GetPcSpBp(void *context, uintptr_t *pc, uintptr_t *sp, uintptr_t *bp) {
+void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) {
ucontext_t *ucontext = (ucontext_t*)context;
# if __WORDSIZE == 64
*pc = ucontext->uc_mcontext->__ss.__rip;
@@ -63,9 +63,9 @@ static int GetMacosVersion() {
size_t len = 0, maxlen = sizeof(version) / sizeof(version[0]);
for (int i = 0; i < maxlen; i++) version[i] = '\0';
// Get the version length.
- CHECK(sysctl(mib, 2, NULL, &len, NULL, 0) != -1);
+ CHECK(sysctl(mib, 2, 0, &len, 0, 0) != -1);
CHECK(len < maxlen);
- CHECK(sysctl(mib, 2, version, &len, NULL, 0) != -1);
+ CHECK(sysctl(mib, 2, version, &len, 0, 0) != -1);
switch (version[0]) {
case '9': return MACOS_VERSION_LEOPARD;
case '1': {
@@ -90,7 +90,7 @@ bool PlatformHasDifferentMemcpyAndMemmove() {
// No-op. Mac does not support static linkage anyway.
void *AsanDoesNotSupportStaticLinkage() {
- return NULL;
+ return 0;
}
bool AsanInterceptsSignal(int signum) {
@@ -117,14 +117,14 @@ void *AsanMmapSomewhereOrDie(size_t size, const char *mem_type) {
return res;
}
-void *AsanMmapFixedNoReserve(uintptr_t fixed_addr, size_t size) {
+void *AsanMmapFixedNoReserve(uptr fixed_addr, size_t size) {
return asan_mmap((void*)fixed_addr, size,
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON | MAP_FIXED | MAP_NORESERVE,
0, 0);
}
-void *AsanMprotect(uintptr_t fixed_addr, size_t size) {
+void *AsanMprotect(uptr fixed_addr, size_t size) {
return asan_mmap((void*)fixed_addr, size,
PROT_NONE,
MAP_PRIVATE | MAP_ANON | MAP_FIXED | MAP_NORESERVE,
@@ -150,7 +150,7 @@ const char *AsanGetEnv(const char *name) {
char **environ = *env_ptr;
CHECK(environ);
size_t name_len = internal_strlen(name);
- while (*environ != NULL) {
+ while (*environ != 0) {
size_t len = internal_strlen(*environ);
if (len > name_len) {
const char *p = *environ;
@@ -161,7 +161,7 @@ const char *AsanGetEnv(const char *name) {
}
environ++;
}
- return NULL;
+ return 0;
}
size_t AsanRead(int fd, void *buf, size_t count) {
@@ -200,7 +200,7 @@ void AsanProcMaps::Reset() {
// adding and removing images which will invalidate the AsanProcMaps state.
current_image_ = _dyld_image_count();
current_load_cmd_count_ = -1;
- current_load_cmd_addr_ = NULL;
+ current_load_cmd_addr_ = 0;
current_magic_ = 0;
}
@@ -213,7 +213,7 @@ void AsanProcMaps::Reset() {
// Note that the segment addresses are not necessarily sorted.
template<uint32_t kLCSegment, typename SegmentCommand>
bool AsanProcMaps::NextSegmentLoad(
- uintptr_t *start, uintptr_t *end, uintptr_t *offset,
+ uptr *start, uptr *end, uptr *offset,
char filename[], size_t filename_size) {
const char* lc = current_load_cmd_addr_;
current_load_cmd_addr_ += ((const load_command *)lc)->cmdsize;
@@ -234,8 +234,8 @@ bool AsanProcMaps::NextSegmentLoad(
return false;
}
-bool AsanProcMaps::Next(uintptr_t *start, uintptr_t *end,
- uintptr_t *offset, char filename[],
+bool AsanProcMaps::Next(uptr *start, uptr *end,
+ uptr *offset, char filename[],
size_t filename_size) {
for (; current_image_ >= 0; current_image_--) {
const mach_header* hdr = _dyld_get_image_header(current_image_);
@@ -286,7 +286,7 @@ bool AsanProcMaps::Next(uintptr_t *start, uintptr_t *end,
return false;
}
-bool AsanProcMaps::GetObjectNameAndOffset(uintptr_t addr, uintptr_t *offset,
+bool AsanProcMaps::GetObjectNameAndOffset(uptr addr, uptr *offset,
char filename[],
size_t filename_size) {
return IterateForObjectNameAndOffset(addr, offset, filename, filename_size);
@@ -295,10 +295,10 @@ bool AsanProcMaps::GetObjectNameAndOffset(uintptr_t addr, uintptr_t *offset,
void AsanThread::SetThreadStackTopAndBottom() {
size_t stacksize = pthread_get_stacksize_np(pthread_self());
void *stackaddr = pthread_get_stackaddr_np(pthread_self());
- stack_top_ = (uintptr_t)stackaddr;
+ stack_top_ = (uptr)stackaddr;
stack_bottom_ = stack_top_ - stacksize;
int local;
- CHECK(AddrIsInStack((uintptr_t)&local));
+ CHECK(AddrIsInStack((uptr)&local));
}
AsanLock::AsanLock(LinkerInitialized) {
@@ -308,19 +308,19 @@ AsanLock::AsanLock(LinkerInitialized) {
void AsanLock::Lock() {
CHECK(sizeof(OSSpinLock) <= sizeof(opaque_storage_));
CHECK(OS_SPINLOCK_INIT == 0);
- CHECK(owner_ != (uintptr_t)pthread_self());
+ CHECK(owner_ != (uptr)pthread_self());
OSSpinLockLock((OSSpinLock*)&opaque_storage_);
CHECK(!owner_);
- owner_ = (uintptr_t)pthread_self();
+ owner_ = (uptr)pthread_self();
}
void AsanLock::Unlock() {
- CHECK(owner_ == (uintptr_t)pthread_self());
+ CHECK(owner_ == (uptr)pthread_self());
owner_ = 0;
OSSpinLockUnlock((OSSpinLock*)&opaque_storage_);
}
-void AsanStackTrace::GetStackTrace(size_t max_s, uintptr_t pc, uintptr_t bp) {
+void AsanStackTrace::GetStackTrace(size_t max_s, uptr pc, uptr bp) {
size = 0;
trace[0] = pc;
if ((max_s) > 1) {
@@ -335,7 +335,7 @@ void AsanStackTrace::GetStackTrace(size_t max_s, uintptr_t pc, uintptr_t bp) {
// These constants were chosen empirically and may not work if the shadow
// memory layout changes. Unfortunately they do necessarily depend on
// kHighMemBeg or kHighMemEnd.
-static void *island_allocator_pos = NULL;
+static void *island_allocator_pos = 0;
#if __WORDSIZE == 32
# define kIslandEnd (0xffdf0000 - kPageSize)
@@ -457,7 +457,7 @@ void asan_dispatch_call_block_and_release(void *block) {
}
AsanThread *t = asanThreadRegistry().GetCurrent();
if (!t) {
- t = AsanThread::Create(context->parent_tid, NULL, NULL, &stack);
+ t = AsanThread::Create(context->parent_tid, 0, 0, &stack);
asanThreadRegistry().RegisterThread(t);
t->Init();
asanThreadRegistry().SetCurrent(t);
@@ -603,7 +603,7 @@ INTERCEPTOR(int, pthread_workqueue_additem_np, pthread_workqueue_t workq,
// See http://opensource.apple.com/source/CF/CF-635.15/CFRuntime.h
typedef struct __CFRuntimeBase {
- uintptr_t _cfisa;
+ uptr _cfisa;
uint8_t _cfinfo[4];
#if __LP64__
uint32_t _rc;
diff --git a/lib/asan/asan_malloc_linux.cc b/lib/asan/asan_malloc_linux.cc
index 84ef929cd..c676d9b12 100644
--- a/lib/asan/asan_malloc_linux.cc
+++ b/lib/asan/asan_malloc_linux.cc
@@ -73,7 +73,7 @@ INTERCEPTOR(void*, calloc, size_t nmemb, size_t size) {
if (!asan_inited) {
// Hack: dlsym calls calloc before REAL(calloc) is retrieved from dlsym.
const size_t kCallocPoolSize = 1024;
- static uintptr_t calloc_memory_for_dlsym[kCallocPoolSize];
+ static uptr calloc_memory_for_dlsym[kCallocPoolSize];
static size_t allocated;
size_t size_in_words = ((nmemb * size) + kWordSize - 1) / kWordSize;
void *mem = (void*)&calloc_memory_for_dlsym[allocated];
diff --git a/lib/asan/asan_malloc_mac.cc b/lib/asan/asan_malloc_mac.cc
index 14d63858a..7dcc41c44 100644
--- a/lib/asan/asan_malloc_mac.cc
+++ b/lib/asan/asan_malloc_mac.cc
@@ -31,7 +31,7 @@
using namespace __asan; // NOLINT
// The free() implementation provided by OS X calls malloc_zone_from_ptr()
-// to find the owner of |ptr|. If the result is NULL, an invalid free() is
+// to find the owner of |ptr|. If the result is 0, an invalid free() is
// reported. Our implementation falls back to asan_free() in this case
// in order to print an ASan-style report.
extern "C"
@@ -55,8 +55,8 @@ void free(void *ptr) {
}
// TODO(glider): do we need both zones?
-static malloc_zone_t *system_malloc_zone = NULL;
-static malloc_zone_t *system_purgeable_zone = NULL;
+static malloc_zone_t *system_malloc_zone = 0;
+static malloc_zone_t *system_purgeable_zone = 0;
// We need to provide wrappers around all the libc functions.
namespace {
@@ -94,7 +94,7 @@ void *mz_calloc(malloc_zone_t *zone, size_t nmemb, size_t size) {
if (!asan_inited) {
// Hack: dlsym calls calloc before REAL(calloc) is retrieved from dlsym.
const size_t kCallocPoolSize = 1024;
- static uintptr_t calloc_memory_for_dlsym[kCallocPoolSize];
+ static uptr calloc_memory_for_dlsym[kCallocPoolSize];
static size_t allocated;
size_t size_in_words = ((nmemb * size) + kWordSize - 1) / kWordSize;
void *mem = (void*)&calloc_memory_for_dlsym[allocated];
@@ -126,7 +126,7 @@ void print_zone_for_ptr(void *ptr) {
ptr, orig_zone);
}
} else {
- Printf("malloc_zone_from_ptr(%p) = NULL\n", ptr);
+ Printf("malloc_zone_from_ptr(%p) = 0\n", ptr);
}
}
@@ -197,7 +197,7 @@ void *mz_realloc(malloc_zone_t *zone, void *ptr, size_t size) {
GET_STACK_TRACE_HERE_FOR_FREE(ptr);
stack.PrintStack();
ShowStatsAndAbort();
- return NULL; // unreachable
+ return 0; // unreachable
}
}
}
@@ -220,7 +220,7 @@ void *cf_realloc(void *ptr, CFIndex size, CFOptionFlags hint, void *info) {
GET_STACK_TRACE_HERE_FOR_FREE(ptr);
stack.PrintStack();
ShowStatsAndAbort();
- return NULL; // unreachable
+ return 0; // unreachable
}
}
}
@@ -337,8 +337,8 @@ void ReplaceSystemMalloc() {
asan_zone.free = &mz_free;
asan_zone.realloc = &mz_realloc;
asan_zone.destroy = &mz_destroy;
- asan_zone.batch_malloc = NULL;
- asan_zone.batch_free = NULL;
+ asan_zone.batch_malloc = 0;
+ asan_zone.batch_free = 0;
asan_zone.introspect = &asan_introspection;
// from AvailabilityMacros.h
@@ -378,12 +378,12 @@ void ReplaceSystemMalloc() {
if (FLAG_replace_cfallocator) {
static CFAllocatorContext asan_context =
{ /*version*/ 0, /*info*/ &asan_zone,
- /*retain*/ NULL, /*release*/ NULL,
- /*copyDescription*/NULL,
+ /*retain*/ 0, /*release*/ 0,
+ /*copyDescription*/0,
/*allocate*/ &cf_malloc,
/*reallocate*/ &cf_realloc,
/*deallocate*/ &cf_free,
- /*preferredSize*/ NULL };
+ /*preferredSize*/ 0 };
CFAllocatorRef cf_asan =
CFAllocatorCreate(kCFAllocatorUseContext, &asan_context);
CFAllocatorSetDefault(cf_asan);
diff --git a/lib/asan/asan_malloc_win.cc b/lib/asan/asan_malloc_win.cc
index 42ba8fe08..ae0bfabeb 100644
--- a/lib/asan/asan_malloc_win.cc
+++ b/lib/asan/asan_malloc_win.cc
@@ -71,7 +71,7 @@ void *realloc(void *ptr, size_t size) {
void *_realloc_dbg(void *ptr, size_t size, int) {
CHECK(!"_realloc_dbg should not exist!");
- return NULL;
+ return 0;
}
void* _recalloc(void* p, size_t n, size_t elem_size) {
@@ -79,7 +79,7 @@ void* _recalloc(void* p, size_t n, size_t elem_size) {
return calloc(n, elem_size);
const size_t size = n * elem_size;
if (elem_size != 0 && size / elem_size != n)
- return NULL;
+ return 0;
return realloc(p, size);
}
diff --git a/lib/asan/asan_mapping.h b/lib/asan/asan_mapping.h
index 22ee81fb5..31564f71b 100644
--- a/lib/asan/asan_mapping.h
+++ b/lib/asan/asan_mapping.h
@@ -20,8 +20,8 @@
// http://code.google.com/p/address-sanitizer/wiki/AddressSanitizerAlgorithm
#if ASAN_FLEXIBLE_MAPPING_AND_OFFSET == 1
-extern __attribute__((visibility("default"))) uintptr_t __asan_mapping_scale;
-extern __attribute__((visibility("default"))) uintptr_t __asan_mapping_offset;
+extern __attribute__((visibility("default"))) uptr __asan_mapping_scale;
+extern __attribute__((visibility("default"))) uptr __asan_mapping_offset;
# define SHADOW_SCALE (__asan_mapping_scale)
# define SHADOW_OFFSET (__asan_mapping_offset)
#else
@@ -43,9 +43,9 @@ extern __attribute__((visibility("default"))) uintptr_t __asan_mapping_offset;
#define SHADOW_TO_MEM(shadow) (((shadow) - SHADOW_OFFSET) << SHADOW_SCALE)
#if __WORDSIZE == 64
- static const size_t kHighMemEnd = 0x00007fffffffffffUL;
+ static const uptr kHighMemEnd = 0x00007fffffffffffUL;
#else // __WORDSIZE == 32
- static const size_t kHighMemEnd = 0xffffffff;
+ static const uptr kHighMemEnd = 0xffffffff;
#endif // __WORDSIZE
@@ -68,41 +68,41 @@ extern __attribute__((visibility("default"))) uintptr_t __asan_mapping_offset;
namespace __asan {
-static inline bool AddrIsInLowMem(uintptr_t a) {
+static inline bool AddrIsInLowMem(uptr a) {
return a < kLowMemEnd;
}
-static inline bool AddrIsInLowShadow(uintptr_t a) {
+static inline bool AddrIsInLowShadow(uptr a) {
return a >= kLowShadowBeg && a <= kLowShadowEnd;
}
-static inline bool AddrIsInHighMem(uintptr_t a) {
+static inline bool AddrIsInHighMem(uptr a) {
return a >= kHighMemBeg && a <= kHighMemEnd;
}
-static inline bool AddrIsInMem(uintptr_t a) {
+static inline bool AddrIsInMem(uptr a) {
return AddrIsInLowMem(a) || AddrIsInHighMem(a);
}
-static inline uintptr_t MemToShadow(uintptr_t p) {
+static inline uptr MemToShadow(uptr p) {
CHECK(AddrIsInMem(p));
return MEM_TO_SHADOW(p);
}
-static inline bool AddrIsInHighShadow(uintptr_t a) {
+static inline bool AddrIsInHighShadow(uptr a) {
return a >= kHighShadowBeg && a <= kHighMemEnd;
}
-static inline bool AddrIsInShadow(uintptr_t a) {
+static inline bool AddrIsInShadow(uptr a) {
return AddrIsInLowShadow(a) || AddrIsInHighShadow(a);
}
-static inline bool AddrIsAlignedByGranularity(uintptr_t a) {
+static inline bool AddrIsAlignedByGranularity(uptr a) {
return (a & (SHADOW_GRANULARITY - 1)) == 0;
}
-static inline bool AddressIsPoisoned(uintptr_t a) {
- const size_t kAccessSize = 1;
+static inline bool AddressIsPoisoned(uptr a) {
+ const uptr kAccessSize = 1;
uint8_t *shadow_address = (uint8_t*)MemToShadow(a);
int8_t shadow_value = *shadow_address;
if (shadow_value) {
diff --git a/lib/asan/asan_poisoning.cc b/lib/asan/asan_poisoning.cc
index 82d4a5cac..36b14e8f8 100644
--- a/lib/asan/asan_poisoning.cc
+++ b/lib/asan/asan_poisoning.cc
@@ -19,22 +19,22 @@
namespace __asan {
-void PoisonShadow(uintptr_t addr, size_t size, uint8_t value) {
+void PoisonShadow(uptr addr, uptr size, uint8_t value) {
CHECK(AddrIsAlignedByGranularity(addr));
CHECK(AddrIsAlignedByGranularity(addr + size));
- uintptr_t shadow_beg = MemToShadow(addr);
- uintptr_t shadow_end = MemToShadow(addr + size);
- CHECK(REAL(memset) != NULL);
+ uptr shadow_beg = MemToShadow(addr);
+ uptr shadow_end = MemToShadow(addr + size);
+ CHECK(REAL(memset) != 0);
REAL(memset)((void*)shadow_beg, value, shadow_end - shadow_beg);
}
-void PoisonShadowPartialRightRedzone(uintptr_t addr,
- uintptr_t size,
- uintptr_t redzone_size,
+void PoisonShadowPartialRightRedzone(uptr addr,
+ uptr size,
+ uptr redzone_size,
uint8_t value) {
CHECK(AddrIsAlignedByGranularity(addr));
uint8_t *shadow = (uint8_t*)MemToShadow(addr);
- for (uintptr_t i = 0; i < redzone_size;
+ for (uptr i = 0; i < redzone_size;
i += SHADOW_GRANULARITY, shadow++) {
if (i + SHADOW_GRANULARITY <= size) {
*shadow = 0; // fully addressable
@@ -52,7 +52,7 @@ struct ShadowSegmentEndpoint {
int8_t offset; // in [0, SHADOW_GRANULARITY)
int8_t value; // = *chunk;
- explicit ShadowSegmentEndpoint(uintptr_t address) {
+ explicit ShadowSegmentEndpoint(uptr address) {
chunk = (uint8_t*)MemToShadow(address);
offset = address & (SHADOW_GRANULARITY - 1);
value = *chunk;
@@ -76,8 +76,8 @@ using namespace __asan; // NOLINT
// at most [AlignDown(left), right).
void __asan_poison_memory_region(void const volatile *addr, uptr size) {
if (!FLAG_allow_user_poisoning || size == 0) return;
- uintptr_t beg_addr = (uintptr_t)addr;
- uintptr_t end_addr = beg_addr + size;
+ uptr beg_addr = (uptr)addr;
+ uptr end_addr = beg_addr + size;
if (FLAG_v >= 1) {
Printf("Trying to poison memory region [%p, %p)\n", beg_addr, end_addr);
}
@@ -117,8 +117,8 @@ void __asan_poison_memory_region(void const volatile *addr, uptr size) {
void __asan_unpoison_memory_region(void const volatile *addr, uptr size) {
if (!FLAG_allow_user_poisoning || size == 0) return;
- uintptr_t beg_addr = (uintptr_t)addr;
- uintptr_t end_addr = beg_addr + size;
+ uptr beg_addr = (uptr)addr;
+ uptr end_addr = beg_addr + size;
if (FLAG_v >= 1) {
Printf("Trying to unpoison memory region [%p, %p)\n", beg_addr, end_addr);
}
@@ -147,5 +147,5 @@ void __asan_unpoison_memory_region(void const volatile *addr, uptr size) {
}
bool __asan_address_is_poisoned(void const volatile *addr) {
- return __asan::AddressIsPoisoned((uintptr_t)addr);
+ return __asan::AddressIsPoisoned((uptr)addr);
}
diff --git a/lib/asan/asan_posix.cc b/lib/asan/asan_posix.cc
index 7ce296e80..9fde9df4c 100644
--- a/lib/asan/asan_posix.cc
+++ b/lib/asan/asan_posix.cc
@@ -35,12 +35,12 @@
// since most of the stuff here is inlinable.
#include <algorithm>
-static const size_t kAltStackSize = SIGSTKSZ * 4; // SIGSTKSZ is not enough.
+static const uptr kAltStackSize = SIGSTKSZ * 4; // SIGSTKSZ is not enough.
namespace __asan {
-static inline bool IntervalsAreSeparate(uintptr_t start1, uintptr_t end1,
- uintptr_t start2, uintptr_t end2) {
+static inline bool IntervalsAreSeparate(uptr start1, uptr end1,
+ uptr start2, uptr end2) {
CHECK(start1 <= end1);
CHECK(start2 <= end2);
return (end1 < start2) || (end2 < start1);
@@ -52,12 +52,12 @@ static inline bool IntervalsAreSeparate(uintptr_t start1, uintptr_t end1,
// memory).
bool AsanShadowRangeIsAvailable() {
AsanProcMaps procmaps;
- uintptr_t start, end;
- uintptr_t shadow_start = kLowShadowBeg;
+ uptr start, end;
+ uptr shadow_start = kLowShadowBeg;
if (kLowShadowBeg > 0) shadow_start -= kMmapGranularity;
- uintptr_t shadow_end = kHighShadowEnd;
+ uptr shadow_end = kHighShadowEnd;
while (procmaps.Next(&start, &end,
- /*offset*/NULL, /*filename*/NULL, /*filename_size*/0)) {
+ /*offset*/0, /*filename*/0, /*filename_size*/0)) {
if (!IntervalsAreSeparate(start, end, shadow_start, shadow_end))
return false;
}
@@ -80,10 +80,10 @@ static void MaybeInstallSigaction(int signum,
}
static void ASAN_OnSIGSEGV(int, siginfo_t *siginfo, void *context) {
- uintptr_t addr = (uintptr_t)siginfo->si_addr;
+ uptr addr = (uptr)siginfo->si_addr;
// Write the first message using the bullet-proof write.
if (13 != AsanWrite(2, "ASAN:SIGSEGV\n", 13)) AsanDie();
- uintptr_t pc, sp, bp;
+ uptr pc, sp, bp;
GetPcSpBp(context, &pc, &sp, &bp);
Report("ERROR: AddressSanitizer crashed on unknown address %p"
" (pc %p sp %p bp %p T%d)\n",
@@ -97,7 +97,7 @@ static void ASAN_OnSIGSEGV(int, siginfo_t *siginfo, void *context) {
void SetAlternateSignalStack() {
stack_t altstack, oldstack;
- CHECK(0 == sigaltstack(NULL, &oldstack));
+ CHECK(0 == sigaltstack(0, &oldstack));
// If the alternate stack is already in place, do nothing.
if ((oldstack.ss_flags & SS_DISABLE) == 0) return;
// TODO(glider): the mapped stack should have the MAP_STACK flag in the
@@ -107,7 +107,7 @@ void SetAlternateSignalStack() {
altstack.ss_sp = base;
altstack.ss_flags = 0;
altstack.ss_size = kAltStackSize;
- CHECK(0 == sigaltstack(&altstack, NULL));
+ CHECK(0 == sigaltstack(&altstack, 0));
if (FLAG_v > 0) {
Report("Alternative stack for T%d set: [%p,%p)\n",
asanThreadRegistry().GetCurrentTidOrMinusOne(),
@@ -117,7 +117,7 @@ void SetAlternateSignalStack() {
void UnsetAlternateSignalStack() {
stack_t altstack, oldstack;
- altstack.ss_sp = NULL;
+ altstack.ss_sp = 0;
altstack.ss_flags = SS_DISABLE;
altstack.ss_size = 0;
CHECK(0 == sigaltstack(&altstack, &oldstack));
@@ -142,11 +142,11 @@ void AsanDisableCoreDumper() {
void AsanDumpProcessMap() {
AsanProcMaps proc_maps;
- uintptr_t start, end;
+ uptr start, end;
const intptr_t kBufSize = 4095;
char filename[kBufSize];
Report("Process memory map follows:\n");
- while (proc_maps.Next(&start, &end, /* file_offset */NULL,
+ while (proc_maps.Next(&start, &end, /* file_offset */0,
filename, kBufSize)) {
Printf("\t%p-%p\t%s\n", (void*)start, (void*)end, filename);
}
@@ -157,8 +157,8 @@ int GetPid() {
return getpid();
}
-uintptr_t GetThreadSelf() {
- return (uintptr_t)pthread_self();
+uptr GetThreadSelf() {
+ return (uptr)pthread_self();
}
void SleepForSeconds(int seconds) {
@@ -189,7 +189,7 @@ uint16_t AtomicExchange(uint16_t *a, uint16_t new_val) {
return __sync_lock_test_and_set(a, new_val);
}
-void SortArray(uintptr_t *array, size_t size) {
+void SortArray(uptr *array, uptr size) {
std::sort(array, array + size);
}
diff --git a/lib/asan/asan_printf.cc b/lib/asan/asan_printf.cc
index 69c34fa4f..a9f501ce2 100644
--- a/lib/asan/asan_printf.cc
+++ b/lib/asan/asan_printf.cc
@@ -23,11 +23,11 @@
namespace __asan {
extern char *error_message_buffer;
-extern size_t error_message_buffer_pos, error_message_buffer_size;
+extern uptr error_message_buffer_pos, error_message_buffer_size;
void RawWrite(const char *buffer) {
static const char *kRawWriteError = "RawWrite can't output requested buffer!";
- size_t length = (size_t)internal_strlen(buffer);
+ uptr length = (uptr)internal_strlen(buffer);
if (length != AsanWrite(2, buffer, length)) {
AsanWrite(2, kRawWriteError, internal_strlen(kRawWriteError));
AsanDie();
@@ -54,11 +54,11 @@ static inline int AppendChar(char **buff, const char *buff_end, char c) {
// "minimal_num_length", it is padded with leading zeroes.
static int AppendUnsigned(char **buff, const char *buff_end, uint64_t num,
uint8_t base, uint8_t minimal_num_length) {
- size_t const kMaxLen = 30;
+ uptr const kMaxLen = 30;
RAW_CHECK(base == 10 || base == 16);
RAW_CHECK(minimal_num_length < kMaxLen);
- size_t num_buffer[kMaxLen];
- size_t pos = 0;
+ uptr num_buffer[kMaxLen];
+ uptr pos = 0;
do {
RAW_CHECK_MSG(pos < kMaxLen, "appendNumber buffer overflow");
num_buffer[pos++] = num % base;
@@ -67,7 +67,7 @@ static int AppendUnsigned(char **buff, const char *buff_end, uint64_t num,
while (pos < minimal_num_length) num_buffer[pos++] = 0;
int result = 0;
while (pos-- > 0) {
- size_t digit = num_buffer[pos];
+ uptr digit = num_buffer[pos];
result += AppendChar(buff, buff_end, (digit < 10) ? '0' + digit
: 'a' + digit - 10);
}
@@ -88,7 +88,7 @@ static inline int AppendSignedDecimal(char **buff, const char *buff_end,
static inline int AppendString(char **buff, const char *buff_end,
const char *s) {
// Avoid library functions like stpcpy here.
- RAW_CHECK_MSG(s, "Error: passing a NULL pointer to AppendString\n");
+ RAW_CHECK_MSG(s, "Error: passing a 0 pointer to AppendString\n");
int result = 0;
for (; *s; s++) {
result += AppendChar(buff, buff_end, *s);
@@ -126,17 +126,17 @@ static int VSNPrintf(char *buff, int buff_length,
: va_arg(args, int);
result += AppendSignedDecimal(&buff, buff_end, dval);
break;
- case 'u': uval = have_z ? va_arg(args, size_t)
+ case 'u': uval = have_z ? va_arg(args, uptr)
: va_arg(args, unsigned);
result += AppendUnsigned(&buff, buff_end, uval, 10, 0);
break;
- case 'x': uval = have_z ? va_arg(args, size_t)
+ case 'x': uval = have_z ? va_arg(args, uptr)
: va_arg(args, unsigned);
result += AppendUnsigned(&buff, buff_end, uval, 16, 0);
break;
case 'p': RAW_CHECK_MSG(!have_z, kPrintfFormatsHelp);
result += AppendPointer(&buff, buff_end,
- va_arg(args, uintptr_t));
+ va_arg(args, uptr));
break;
case 's': RAW_CHECK_MSG(!have_z, kPrintfFormatsHelp);
result += AppendString(&buff, buff_end, va_arg(args, char*));
@@ -167,7 +167,7 @@ void Printf(const char *format, ...) {
// Returns the number of symbols that should have been written to buffer
// (not including trailing '\0'). Thus, the string is truncated
// iff return value is not less than "length".
-int SNPrintf(char *buffer, size_t length, const char *format, ...) {
+int SNPrintf(char *buffer, uptr length, const char *format, ...) {
va_list args;
va_start(args, format);
int needed_length = VSNPrintf(buffer, length, format, args);
diff --git a/lib/asan/asan_procmaps.h b/lib/asan/asan_procmaps.h
index 5ae5fb238..f660e312b 100644
--- a/lib/asan/asan_procmaps.h
+++ b/lib/asan/asan_procmaps.h
@@ -21,22 +21,22 @@ namespace __asan {
class AsanProcMaps {
public:
AsanProcMaps();
- bool Next(uintptr_t *start, uintptr_t *end, uintptr_t *offset,
- char filename[], size_t filename_size);
+ bool Next(uptr *start, uptr *end, uptr *offset,
+ char filename[], uptr filename_size);
void Reset();
// Gets the object file name and the offset in that object for a given
// address 'addr'. Returns true on success.
- bool GetObjectNameAndOffset(uintptr_t addr, uintptr_t *offset,
- char filename[], size_t filename_size);
+ bool GetObjectNameAndOffset(uptr addr, uptr *offset,
+ char filename[], uptr filename_size);
~AsanProcMaps();
private:
// Default implementation of GetObjectNameAndOffset.
// Quite slow, because it iterates through the whole process map for each
// lookup.
- bool IterateForObjectNameAndOffset(uintptr_t addr, uintptr_t *offset,
- char filename[], size_t filename_size) {
+ bool IterateForObjectNameAndOffset(uptr addr, uptr *offset,
+ char filename[], uptr filename_size) {
Reset();
- uintptr_t start, end, file_offset;
+ uptr start, end, file_offset;
for (int i = 0; Next(&start, &end, &file_offset, filename, filename_size);
i++) {
if (addr >= start && addr < end) {
@@ -52,13 +52,13 @@ class AsanProcMaps {
#if defined __linux__
char *proc_self_maps_buff_;
- size_t proc_self_maps_buff_mmaped_size_;
- size_t proc_self_maps_buff_len_;
+ uptr proc_self_maps_buff_mmaped_size_;
+ uptr proc_self_maps_buff_len_;
char *current_;
#elif defined __APPLE__
template<uint32_t kLCSegment, typename SegmentCommand>
- bool NextSegmentLoad(uintptr_t *start, uintptr_t *end, uintptr_t *offset,
- char filename[], size_t filename_size);
+ bool NextSegmentLoad(uptr *start, uptr *end, uptr *offset,
+ char filename[], uptr filename_size);
int current_image_;
uint32_t current_magic_;
int current_load_cmd_count_;
diff --git a/lib/asan/asan_rtl.cc b/lib/asan/asan_rtl.cc
index 224caf438..e13768ab4 100644
--- a/lib/asan/asan_rtl.cc
+++ b/lib/asan/asan_rtl.cc
@@ -26,13 +26,13 @@ namespace __asan {
using namespace __sanitizer;
// -------------------------- Flags ------------------------- {{{1
-static const size_t kMallocContextSize = 30;
+static const uptr kMallocContextSize = 30;
-size_t FLAG_malloc_context_size = kMallocContextSize;
-size_t FLAG_max_malloc_fill_size = 0;
+uptr FLAG_malloc_context_size = kMallocContextSize;
+uptr FLAG_max_malloc_fill_size = 0;
int64_t FLAG_v = 0;
-size_t FLAG_redzone = (ASAN_LOW_MEMORY) ? 64 : 128; // power of two, >= 32
-size_t FLAG_quarantine_size = (ASAN_LOW_MEMORY) ? 1UL << 24 : 1UL << 28;
+uptr FLAG_redzone = (ASAN_LOW_MEMORY) ? 64 : 128; // power of two, >= 32
+uptr FLAG_quarantine_size = (ASAN_LOW_MEMORY) ? 1UL << 24 : 1UL << 28;
static int64_t FLAG_atexit = 0;
bool FLAG_poison_shadow = 1;
int64_t FLAG_report_globals = 1;
@@ -58,9 +58,9 @@ int asan_inited;
bool asan_init_is_running;
static void (*death_callback)(void);
static void (*error_report_callback)(const char*);
-char *error_message_buffer = NULL;
-size_t error_message_buffer_pos = 0;
-size_t error_message_buffer_size = 0;
+char *error_message_buffer = 0;
+uptr error_message_buffer_pos = 0;
+uptr error_message_buffer_size = 0;
// -------------------------- Misc ---------------- {{{1
void ShowStatsAndAbort() {
@@ -68,24 +68,24 @@ void ShowStatsAndAbort() {
AsanDie();
}
-static void PrintBytes(const char *before, uintptr_t *a) {
+static void PrintBytes(const char *before, uptr *a) {
uint8_t *bytes = (uint8_t*)a;
- size_t byte_num = (__WORDSIZE) / 8;
+ uptr byte_num = (__WORDSIZE) / 8;
Printf("%s%p:", before, (void*)a);
- for (size_t i = 0; i < byte_num; i++) {
+ for (uptr i = 0; i < byte_num; i++) {
Printf(" %x%x", bytes[i] >> 4, bytes[i] & 15);
}
Printf("\n");
}
-size_t ReadFileToBuffer(const char *file_name, char **buff,
- size_t *buff_size, size_t max_len) {
- const size_t kMinFileLen = kPageSize;
- size_t read_len = 0;
+uptr ReadFileToBuffer(const char *file_name, char **buff,
+ uptr *buff_size, uptr max_len) {
+ const uptr kMinFileLen = kPageSize;
+ uptr read_len = 0;
*buff = 0;
*buff_size = 0;
// The files we usually open are not seekable, so try different buffer sizes.
- for (size_t size = kMinFileLen; size <= max_len; size *= 2) {
+ for (uptr size = kMinFileLen; size <= max_len; size *= 2) {
int fd = AsanOpenReadonly(file_name);
if (fd < 0) return 0;
AsanUnmapOrDie(*buff, *buff_size);
@@ -95,7 +95,7 @@ size_t ReadFileToBuffer(const char *file_name, char **buff,
read_len = 0;
bool reached_eof = false;
while (read_len + kPageSize <= size) {
- size_t just_read = AsanRead(fd, *buff + read_len, kPageSize);
+ uptr just_read = AsanRead(fd, *buff + read_len, kPageSize);
if (just_read == 0) {
reached_eof = true;
break;
@@ -129,7 +129,7 @@ void AsanDie() {
}
// ---------------------- mmap -------------------- {{{1
-void OutOfMemoryMessageAndDie(const char *mem_type, size_t size) {
+void OutOfMemoryMessageAndDie(const char *mem_type, uptr size) {
Report("ERROR: AddressSanitizer failed to allocate "
"0x%zx (%zd) bytes of %s\n",
size, size, mem_type);
@@ -138,23 +138,23 @@ void OutOfMemoryMessageAndDie(const char *mem_type, size_t size) {
}
// Reserve memory range [beg, end].
-static void ReserveShadowMemoryRange(uintptr_t beg, uintptr_t end) {
+static void ReserveShadowMemoryRange(uptr beg, uptr end) {
CHECK((beg % kPageSize) == 0);
CHECK(((end + 1) % kPageSize) == 0);
- size_t size = end - beg + 1;
+ uptr size = end - beg + 1;
void *res = AsanMmapFixedNoReserve(beg, size);
CHECK(res == (void*)beg && "ReserveShadowMemoryRange failed");
}
// ---------------------- LowLevelAllocator ------------- {{{1
-void *LowLevelAllocator::Allocate(size_t size) {
+void *LowLevelAllocator::Allocate(uptr size) {
CHECK((size & (size - 1)) == 0 && "size must be a power of two");
if (allocated_end_ - allocated_current_ < size) {
- size_t size_to_allocate = Max(size, kPageSize);
+ uptr size_to_allocate = Max(size, kPageSize);
allocated_current_ =
(char*)AsanMmapSomewhereOrDie(size_to_allocate, __FUNCTION__);
allocated_end_ = allocated_current_ + size_to_allocate;
- PoisonShadow((uintptr_t)allocated_current_, size_to_allocate,
+ PoisonShadow((uptr)allocated_current_, size_to_allocate,
kAsanInternalHeapMagic);
}
CHECK(allocated_end_ - allocated_current_ >= size);
@@ -164,12 +164,12 @@ void *LowLevelAllocator::Allocate(size_t size) {
}
// ---------------------- DescribeAddress -------------------- {{{1
-static bool DescribeStackAddress(uintptr_t addr, uintptr_t access_size) {
+static bool DescribeStackAddress(uptr addr, uptr access_size) {
AsanThread *t = asanThreadRegistry().FindThreadByStackAddress(addr);
if (!t) return false;
const intptr_t kBufSize = 4095;
char buf[kBufSize];
- uintptr_t offset = 0;
+ uptr offset = 0;
const char *frame_descr = t->GetFrameNameByAddr(addr, &offset);
// This string is created by the compiler and has the following form:
// "FunctioName n alloc_1 alloc_2 ... alloc_n"
@@ -187,12 +187,12 @@ static bool DescribeStackAddress(uintptr_t addr, uintptr_t access_size) {
addr, offset, buf, t->tid());
// Report the number of stack objects.
char *p;
- size_t n_objects = internal_simple_strtoll(name_end, &p, 10);
+ uptr n_objects = internal_simple_strtoll(name_end, &p, 10);
CHECK(n_objects > 0);
Printf(" This frame has %zu object(s):\n", n_objects);
// Report all objects in this frame.
- for (size_t i = 0; i < n_objects; i++) {
- size_t beg, size;
+ for (uptr i = 0; i < n_objects; i++) {
+ uptr beg, size;
intptr_t len;
beg = internal_simple_strtoll(p, &p, 10);
size = internal_simple_strtoll(p, &p, 10);
@@ -215,7 +215,7 @@ static bool DescribeStackAddress(uintptr_t addr, uintptr_t access_size) {
return true;
}
-static NOINLINE void DescribeAddress(uintptr_t addr, uintptr_t access_size) {
+static NOINLINE void DescribeAddress(uptr addr, uptr access_size) {
// Check if this is a global.
if (DescribeAddrIfGlobal(addr))
return;
@@ -231,8 +231,8 @@ static NOINLINE void DescribeAddress(uintptr_t addr, uintptr_t access_size) {
// exported functions
#define ASAN_REPORT_ERROR(type, is_write, size) \
extern "C" NOINLINE ASAN_INTERFACE_ATTRIBUTE \
-void __asan_report_ ## type ## size(uintptr_t addr); \
-void __asan_report_ ## type ## size(uintptr_t addr) { \
+void __asan_report_ ## type ## size(uptr addr); \
+void __asan_report_ ## type ## size(uptr addr) { \
GET_CALLER_PC_BP_SP; \
__asan_report_error(pc, bp, sp, addr, is_write, size); \
}
@@ -266,11 +266,11 @@ static NOINLINE void force_interface_symbols() {
__asan_report_store4(0);
__asan_report_store8(0);
__asan_report_store16(0);
- __asan_register_global(0, 0, NULL);
- __asan_register_globals(NULL, 0);
- __asan_unregister_globals(NULL, 0);
- __asan_set_death_callback(NULL);
- __asan_set_error_report_callback(NULL);
+ __asan_register_global(0, 0, 0);
+ __asan_register_globals(0, 0);
+ __asan_unregister_globals(0, 0);
+ __asan_set_death_callback(0);
+ __asan_set_error_report_callback(0);
__asan_handle_no_return();
}
}
@@ -340,8 +340,8 @@ void NOINLINE __asan_handle_no_return() {
int local_stack;
AsanThread *curr_thread = asanThreadRegistry().GetCurrent();
CHECK(curr_thread);
- uintptr_t top = curr_thread->stack_top();
- uintptr_t bottom = ((uintptr_t)&local_stack - kPageSize) & ~(kPageSize-1);
+ uptr top = curr_thread->stack_top();
+ uptr bottom = ((uptr)&local_stack - kPageSize) & ~(kPageSize-1);
PoisonShadow(bottom, top - bottom, 0);
}
@@ -421,7 +421,7 @@ void __asan_report_error(uptr pc, uptr bp, uptr sp,
access_size, addr, curr_tid);
if (FLAG_debug) {
- PrintBytes("PC: ", (uintptr_t*)pc);
+ PrintBytes("PC: ", (uptr*)pc);
}
GET_STACK_TRACE_WITH_PC_AND_BP(kStackTraceMax, pc, bp);
@@ -431,23 +431,23 @@ void __asan_report_error(uptr pc, uptr bp, uptr sp,
DescribeAddress(addr, access_size);
- uintptr_t shadow_addr = MemToShadow(addr);
+ uptr shadow_addr = MemToShadow(addr);
Report("ABORTING\n");
__asan_print_accumulated_stats();
Printf("Shadow byte and word:\n");
Printf(" %p: %x\n", shadow_addr, *(unsigned char*)shadow_addr);
- uintptr_t aligned_shadow = shadow_addr & ~(kWordSize - 1);
- PrintBytes(" ", (uintptr_t*)(aligned_shadow));
+ uptr aligned_shadow = shadow_addr & ~(kWordSize - 1);
+ PrintBytes(" ", (uptr*)(aligned_shadow));
Printf("More shadow bytes:\n");
- PrintBytes(" ", (uintptr_t*)(aligned_shadow-4*kWordSize));
- PrintBytes(" ", (uintptr_t*)(aligned_shadow-3*kWordSize));
- PrintBytes(" ", (uintptr_t*)(aligned_shadow-2*kWordSize));
- PrintBytes(" ", (uintptr_t*)(aligned_shadow-1*kWordSize));
- PrintBytes("=>", (uintptr_t*)(aligned_shadow+0*kWordSize));
- PrintBytes(" ", (uintptr_t*)(aligned_shadow+1*kWordSize));
- PrintBytes(" ", (uintptr_t*)(aligned_shadow+2*kWordSize));
- PrintBytes(" ", (uintptr_t*)(aligned_shadow+3*kWordSize));
- PrintBytes(" ", (uintptr_t*)(aligned_shadow+4*kWordSize));
+ PrintBytes(" ", (uptr*)(aligned_shadow-4*kWordSize));
+ PrintBytes(" ", (uptr*)(aligned_shadow-3*kWordSize));
+ PrintBytes(" ", (uptr*)(aligned_shadow-2*kWordSize));
+ PrintBytes(" ", (uptr*)(aligned_shadow-1*kWordSize));
+ PrintBytes("=>", (uptr*)(aligned_shadow+0*kWordSize));
+ PrintBytes(" ", (uptr*)(aligned_shadow+1*kWordSize));
+ PrintBytes(" ", (uptr*)(aligned_shadow+2*kWordSize));
+ PrintBytes(" ", (uptr*)(aligned_shadow+3*kWordSize));
+ PrintBytes(" ", (uptr*)(aligned_shadow+4*kWordSize));
if (error_report_callback) {
error_report_callback(error_message_buffer);
}
@@ -544,12 +544,12 @@ void __asan_init() {
MEM_TO_SHADOW(kLowShadowEnd),
MEM_TO_SHADOW(kHighShadowBeg),
MEM_TO_SHADOW(kHighShadowEnd));
- Printf("red_zone=%zu\n", (size_t)FLAG_redzone);
- Printf("malloc_context_size=%zu\n", (size_t)FLAG_malloc_context_size);
+ Printf("red_zone=%zu\n", (uptr)FLAG_redzone);
+ Printf("malloc_context_size=%zu\n", (uptr)FLAG_malloc_context_size);
- Printf("SHADOW_SCALE: %zx\n", (size_t)SHADOW_SCALE);
- Printf("SHADOW_GRANULARITY: %zx\n", (size_t)SHADOW_GRANULARITY);
- Printf("SHADOW_OFFSET: %zx\n", (size_t)SHADOW_OFFSET);
+ Printf("SHADOW_SCALE: %zx\n", (uptr)SHADOW_SCALE);
+ Printf("SHADOW_GRANULARITY: %zx\n", (uptr)SHADOW_GRANULARITY);
+ Printf("SHADOW_OFFSET: %zx\n", (uptr)SHADOW_OFFSET);
CHECK(SHADOW_SCALE >= 3 && SHADOW_SCALE <= 7);
}
diff --git a/lib/asan/asan_stack.cc b/lib/asan/asan_stack.cc
index a8766bbbb..571a2ffb0 100644
--- a/lib/asan/asan_stack.cc
+++ b/lib/asan/asan_stack.cc
@@ -27,9 +27,9 @@ namespace __asan {
// ----------------------- AsanStackTrace ----------------------------- {{{1
#if defined(ASAN_USE_EXTERNAL_SYMBOLIZER)
-void AsanStackTrace::PrintStack(uintptr_t *addr, size_t size) {
- for (size_t i = 0; i < size && addr[i]; i++) {
- uintptr_t pc = addr[i];
+void AsanStackTrace::PrintStack(uptr *addr, uptr size) {
+ for (uptr i = 0; i < size && addr[i]; i++) {
+ uptr pc = addr[i];
char buff[4096];
ASAN_USE_EXTERNAL_SYMBOLIZER((void*)pc, buff, sizeof(buff));
Printf(" #%zu 0x%zx %s\n", i, pc, buff);
@@ -37,12 +37,12 @@ void AsanStackTrace::PrintStack(uintptr_t *addr, size_t size) {
}
#else // ASAN_USE_EXTERNAL_SYMBOLIZER
-void AsanStackTrace::PrintStack(uintptr_t *addr, size_t size) {
+void AsanStackTrace::PrintStack(uptr *addr, uptr size) {
AsanProcMaps proc_maps;
- for (size_t i = 0; i < size && addr[i]; i++) {
+ for (uptr i = 0; i < size && addr[i]; i++) {
proc_maps.Reset();
- uintptr_t pc = addr[i];
- uintptr_t offset;
+ uptr pc = addr[i];
+ uptr offset;
char filename[4096];
if (proc_maps.GetObjectNameAndOffset(pc, &offset,
filename, sizeof(filename))) {
@@ -54,66 +54,66 @@ void AsanStackTrace::PrintStack(uintptr_t *addr, size_t size) {
}
#endif // ASAN_USE_EXTERNAL_SYMBOLIZER
-uintptr_t AsanStackTrace::GetCurrentPc() {
+uptr AsanStackTrace::GetCurrentPc() {
return GET_CALLER_PC();
}
-void AsanStackTrace::FastUnwindStack(uintptr_t pc, uintptr_t bp) {
+void AsanStackTrace::FastUnwindStack(uptr pc, uptr bp) {
CHECK(size == 0 && trace[0] == pc);
size = 1;
if (!asan_inited) return;
AsanThread *t = asanThreadRegistry().GetCurrent();
if (!t) return;
- uintptr_t *frame = (uintptr_t*)bp;
- uintptr_t *prev_frame = frame;
- uintptr_t *top = (uintptr_t*)t->stack_top();
- uintptr_t *bottom = (uintptr_t*)t->stack_bottom();
+ uptr *frame = (uptr*)bp;
+ uptr *prev_frame = frame;
+ uptr *top = (uptr*)t->stack_top();
+ uptr *bottom = (uptr*)t->stack_bottom();
while (frame >= prev_frame &&
frame < top - 2 &&
frame > bottom &&
size < max_size) {
- uintptr_t pc1 = frame[1];
+ uptr pc1 = frame[1];
if (pc1 != pc) {
trace[size++] = pc1;
}
prev_frame = frame;
- frame = (uintptr_t*)frame[0];
+ frame = (uptr*)frame[0];
}
}
// On 32-bits we don't compress stack traces.
// On 64-bits we compress stack traces: if a given pc differes slightly from
// the previous one, we record a 31-bit offset instead of the full pc.
-size_t AsanStackTrace::CompressStack(AsanStackTrace *stack,
- uint32_t *compressed, size_t size) {
+uptr AsanStackTrace::CompressStack(AsanStackTrace *stack,
+ uint32_t *compressed, uptr size) {
#if __WORDSIZE == 32
// Don't compress, just copy.
- size_t res = 0;
- for (size_t i = 0; i < stack->size && i < size; i++) {
+ uptr res = 0;
+ for (uptr i = 0; i < stack->size && i < size; i++) {
compressed[i] = stack->trace[i];
res++;
}
if (stack->size < size)
compressed[stack->size] = 0;
#else // 64 bits, compress.
- uintptr_t prev_pc = 0;
- const uintptr_t kMaxOffset = (1ULL << 30) - 1;
- uintptr_t c_index = 0;
- size_t res = 0;
- for (size_t i = 0, n = stack->size; i < n; i++) {
- uintptr_t pc = stack->trace[i];
+ uptr prev_pc = 0;
+ const uptr kMaxOffset = (1ULL << 30) - 1;
+ uptr c_index = 0;
+ uptr res = 0;
+ for (uptr i = 0, n = stack->size; i < n; i++) {
+ uptr pc = stack->trace[i];
if (!pc) break;
if ((int64_t)pc < 0) break;
// Printf("C pc[%zu] %zx\n", i, pc);
if (prev_pc - pc < kMaxOffset || pc - prev_pc < kMaxOffset) {
- uintptr_t offset = (int64_t)(pc - prev_pc);
+ uptr offset = (int64_t)(pc - prev_pc);
offset |= (1U << 31);
if (c_index >= size) break;
// Printf("C co[%zu] offset %zx\n", i, offset);
compressed[c_index++] = offset;
} else {
- uintptr_t hi = pc >> 32;
- uintptr_t lo = (pc << 32) >> 32;
+ uptr hi = pc >> 32;
+ uptr lo = (pc << 32) >> 32;
CHECK((hi & (1 << 31)) == 0);
if (c_index + 1 >= size) break;
// Printf("C co[%zu] hi/lo: %zx %zx\n", c_index, hi, lo);
@@ -141,28 +141,28 @@ size_t AsanStackTrace::CompressStack(AsanStackTrace *stack,
// UncompressStack(CompressStack(stack)) eliminates the 0x0 frames.
CHECK(res >= check_stack.size);
CHECK(0 == REAL(memcmp)(check_stack.trace, stack->trace,
- check_stack.size * sizeof(uintptr_t)));
+ check_stack.size * sizeof(uptr)));
#endif
return res;
}
void AsanStackTrace::UncompressStack(AsanStackTrace *stack,
- uint32_t *compressed, size_t size) {
+ uint32_t *compressed, uptr size) {
#if __WORDSIZE == 32
// Don't uncompress, just copy.
stack->size = 0;
- for (size_t i = 0; i < size && i < kStackTraceMax; i++) {
+ for (uptr i = 0; i < size && i < kStackTraceMax; i++) {
if (!compressed[i]) break;
stack->size++;
stack->trace[i] = compressed[i];
}
#else // 64 bits, uncompress
- uintptr_t prev_pc = 0;
+ uptr prev_pc = 0;
stack->size = 0;
- for (size_t i = 0; i < size && stack->size < kStackTraceMax; i++) {
+ for (uptr i = 0; i < size && stack->size < kStackTraceMax; i++) {
uint32_t x = compressed[i];
- uintptr_t pc = 0;
+ uptr pc = 0;
if (x & (1U << 31)) {
// Printf("U co[%zu] offset: %x\n", i, x);
// this is an offset
@@ -173,8 +173,8 @@ void AsanStackTrace::UncompressStack(AsanStackTrace *stack,
} else {
// CHECK(i + 1 < size);
if (i + 1 >= size) break;
- uintptr_t hi = x;
- uintptr_t lo = compressed[i+1];
+ uptr hi = x;
+ uptr lo = compressed[i+1];
// Printf("U co[%zu] hi/lo: %zx %zx\n", i, hi, lo);
i++;
pc = (hi << 32) | lo;
diff --git a/lib/asan/asan_stack.h b/lib/asan/asan_stack.h
index 252df93c8..a754515c1 100644
--- a/lib/asan/asan_stack.h
+++ b/lib/asan/asan_stack.h
@@ -18,41 +18,41 @@
namespace __asan {
-static const size_t kStackTraceMax = 64;
+static const uptr kStackTraceMax = 64;
struct AsanStackTrace {
- size_t size;
- size_t max_size;
- uintptr_t trace[kStackTraceMax];
- static void PrintStack(uintptr_t *addr, size_t size);
+ uptr size;
+ uptr max_size;
+ uptr trace[kStackTraceMax];
+ static void PrintStack(uptr *addr, uptr size);
void PrintStack() {
PrintStack(this->trace, this->size);
}
- void CopyTo(uintptr_t *dst, size_t dst_size) {
- for (size_t i = 0; i < size && i < dst_size; i++)
+ void CopyTo(uptr *dst, uptr dst_size) {
+ for (uptr i = 0; i < size && i < dst_size; i++)
dst[i] = trace[i];
- for (size_t i = size; i < dst_size; i++)
+ for (uptr i = size; i < dst_size; i++)
dst[i] = 0;
}
- void CopyFrom(uintptr_t *src, size_t src_size) {
+ void CopyFrom(uptr *src, uptr src_size) {
size = src_size;
if (size > kStackTraceMax) size = kStackTraceMax;
- for (size_t i = 0; i < size; i++) {
+ for (uptr i = 0; i < size; i++) {
trace[i] = src[i];
}
}
- void GetStackTrace(size_t max_s, uintptr_t pc, uintptr_t bp);
+ void GetStackTrace(uptr max_s, uptr pc, uptr bp);
- void FastUnwindStack(uintptr_t pc, uintptr_t bp);
+ void FastUnwindStack(uptr pc, uptr bp);
- static uintptr_t GetCurrentPc();
+ static uptr GetCurrentPc();
- static size_t CompressStack(AsanStackTrace *stack,
- uint32_t *compressed, size_t size);
+ static uptr CompressStack(AsanStackTrace *stack,
+ uint32_t *compressed, uptr size);
static void UncompressStack(AsanStackTrace *stack,
- uint32_t *compressed, size_t size);
+ uint32_t *compressed, uptr size);
};
} // namespace __asan
@@ -60,18 +60,18 @@ struct AsanStackTrace {
// Use this macro if you want to print stack trace with the caller
// of the current function in the top frame.
#define GET_CALLER_PC_BP_SP \
- uintptr_t bp = GET_CURRENT_FRAME(); \
- uintptr_t pc = GET_CALLER_PC(); \
- uintptr_t local_stack; \
- uintptr_t sp = (uintptr_t)&local_stack;
+ uptr bp = GET_CURRENT_FRAME(); \
+ uptr pc = GET_CALLER_PC(); \
+ uptr local_stack; \
+ uptr sp = (uptr)&local_stack;
// Use this macro if you want to print stack trace with the current
// function in the top frame.
#define GET_CURRENT_PC_BP_SP \
- uintptr_t bp = GET_CURRENT_FRAME(); \
- uintptr_t pc = AsanStackTrace::GetCurrentPc(); \
- uintptr_t local_stack; \
- uintptr_t sp = (uintptr_t)&local_stack;
+ uptr bp = GET_CURRENT_FRAME(); \
+ uptr pc = AsanStackTrace::GetCurrentPc(); \
+ uptr local_stack; \
+ uptr sp = (uptr)&local_stack;
// Get the stack trace with the given pc and bp.
// The pc will be in the position 0 of the resulting stack trace.
diff --git a/lib/asan/asan_stats.cc b/lib/asan/asan_stats.cc
index ea01a22df..b697c5dfb 100644
--- a/lib/asan/asan_stats.cc
+++ b/lib/asan/asan_stats.cc
@@ -21,14 +21,14 @@
namespace __asan {
AsanStats::AsanStats() {
- CHECK(REAL(memset) != NULL);
+ CHECK(REAL(memset) != 0);
REAL(memset)(this, 0, sizeof(AsanStats));
}
static void PrintMallocStatsArray(const char *prefix,
- size_t (&array)[kNumberOfSizeClasses]) {
+ uptr (&array)[kNumberOfSizeClasses]) {
Printf("%s", prefix);
- for (size_t i = 0; i < kNumberOfSizeClasses; i++) {
+ for (uptr i = 0; i < kNumberOfSizeClasses; i++) {
if (!array[i]) continue;
Printf("%zu:%zu; ", i, array[i]);
}
diff --git a/lib/asan/asan_stats.h b/lib/asan/asan_stats.h
index d6dd084c0..b4c63f44f 100644
--- a/lib/asan/asan_stats.h
+++ b/lib/asan/asan_stats.h
@@ -23,27 +23,27 @@ namespace __asan {
// Each AsanThread has its own AsanStats, which are sometimes flushed
// to the accumulated AsanStats.
struct AsanStats {
- // AsanStats must be a struct consisting of size_t fields only.
- // When merging two AsanStats structs, we treat them as arrays of size_t.
- size_t mallocs;
- size_t malloced;
- size_t malloced_redzones;
- size_t frees;
- size_t freed;
- size_t real_frees;
- size_t really_freed;
- size_t really_freed_redzones;
- size_t reallocs;
- size_t realloced;
- size_t mmaps;
- size_t mmaped;
- size_t mmaped_by_size[kNumberOfSizeClasses];
- size_t malloced_by_size[kNumberOfSizeClasses];
- size_t freed_by_size[kNumberOfSizeClasses];
- size_t really_freed_by_size[kNumberOfSizeClasses];
-
- size_t malloc_large;
- size_t malloc_small_slow;
+ // AsanStats must be a struct consisting of uptr fields only.
+ // When merging two AsanStats structs, we treat them as arrays of uptr.
+ uptr mallocs;
+ uptr malloced;
+ uptr malloced_redzones;
+ uptr frees;
+ uptr freed;
+ uptr real_frees;
+ uptr really_freed;
+ uptr really_freed_redzones;
+ uptr reallocs;
+ uptr realloced;
+ uptr mmaps;
+ uptr mmaped;
+ uptr mmaped_by_size[kNumberOfSizeClasses];
+ uptr malloced_by_size[kNumberOfSizeClasses];
+ uptr freed_by_size[kNumberOfSizeClasses];
+ uptr really_freed_by_size[kNumberOfSizeClasses];
+
+ uptr malloc_large;
+ uptr malloc_small_slow;
// Ctor for global AsanStats (accumulated stats and main thread stats).
explicit AsanStats(LinkerInitialized) { }
diff --git a/lib/asan/asan_thread.cc b/lib/asan/asan_thread.cc
index 0ebbe585d..da5ab3d47 100644
--- a/lib/asan/asan_thread.cc
+++ b/lib/asan/asan_thread.cc
@@ -28,7 +28,7 @@ AsanThread::AsanThread(LinkerInitialized x)
AsanThread *AsanThread::Create(int parent_tid, thread_callback_t start_routine,
void *arg, AsanStackTrace *stack) {
- size_t size = RoundUpTo(sizeof(AsanThread), kPageSize);
+ uptr size = RoundUpTo(sizeof(AsanThread), kPageSize);
AsanThread *thread = (AsanThread*)AsanMmapSomewhereOrDie(size, __FUNCTION__);
thread->start_routine_ = start_routine;
thread->arg_ = arg;
@@ -56,13 +56,13 @@ void AsanThread::Destroy() {
}
asanThreadRegistry().UnregisterThread(this);
- CHECK(summary()->thread() == NULL);
+ CHECK(summary()->thread() == 0);
// We also clear the shadow on thread destruction because
// some code may still be executing in later TSD destructors
// and we don't want it to have any poisoned stack.
ClearShadowForThreadStack();
fake_stack().Cleanup();
- size_t size = RoundUpTo(sizeof(AsanThread), kPageSize);
+ uptr size = RoundUpTo(sizeof(AsanThread), kPageSize);
AsanUnmapOrDie(this, size);
}
@@ -85,7 +85,7 @@ thread_return_t AsanThread::ThreadStart() {
if (FLAG_use_sigaltstack) SetAlternateSignalStack();
if (!start_routine_) {
- // start_routine_ == NULL if we're on the main thread or on one of the
+ // start_routine_ == 0 if we're on the main thread or on one of the
// OS X libdispatch worker threads. But nobody is supposed to call
// ThreadStart() for the worker threads.
CHECK(tid() == 0);
@@ -105,8 +105,8 @@ void AsanThread::ClearShadowForThreadStack() {
PoisonShadow(stack_bottom_, stack_top_ - stack_bottom_, 0);
}
-const char *AsanThread::GetFrameNameByAddr(uintptr_t addr, uintptr_t *offset) {
- uintptr_t bottom = 0;
+const char *AsanThread::GetFrameNameByAddr(uptr addr, uptr *offset) {
+ uptr bottom = 0;
bool is_fake_stack = false;
if (AddrIsInStack(addr)) {
bottom = stack_bottom();
@@ -115,7 +115,7 @@ const char *AsanThread::GetFrameNameByAddr(uintptr_t addr, uintptr_t *offset) {
CHECK(bottom);
is_fake_stack = true;
}
- uintptr_t aligned_addr = addr & ~(__WORDSIZE/8 - 1); // align addr.
+ uptr aligned_addr = addr & ~(__WORDSIZE/8 - 1); // align addr.
uint8_t *shadow_ptr = (uint8_t*)MemToShadow(aligned_addr);
uint8_t *shadow_bottom = (uint8_t*)MemToShadow(bottom);
@@ -134,10 +134,10 @@ const char *AsanThread::GetFrameNameByAddr(uintptr_t addr, uintptr_t *offset) {
return "UNKNOWN";
}
- uintptr_t* ptr = (uintptr_t*)SHADOW_TO_MEM((uintptr_t)(shadow_ptr + 1));
+ uptr* ptr = (uptr*)SHADOW_TO_MEM((uptr)(shadow_ptr + 1));
CHECK((ptr[0] == kCurrentStackFrameMagic) ||
(is_fake_stack && ptr[0] == kRetiredStackFrameMagic));
- *offset = addr - (uintptr_t)ptr;
+ *offset = addr - (uptr)ptr;
return (const char*)ptr[1];
}
diff --git a/lib/asan/asan_thread.h b/lib/asan/asan_thread.h
index 200d306d8..e76c99b7a 100644
--- a/lib/asan/asan_thread.h
+++ b/lib/asan/asan_thread.h
@@ -70,16 +70,16 @@ class AsanThread {
void Init(); // Should be called from the thread itself.
thread_return_t ThreadStart();
- uintptr_t stack_top() { return stack_top_; }
- uintptr_t stack_bottom() { return stack_bottom_; }
- size_t stack_size() { return stack_top_ - stack_bottom_; }
+ uptr stack_top() { return stack_top_; }
+ uptr stack_bottom() { return stack_bottom_; }
+ uptr stack_size() { return stack_top_ - stack_bottom_; }
int tid() { return summary_->tid(); }
AsanThreadSummary *summary() { return summary_; }
void set_summary(AsanThreadSummary *summary) { summary_ = summary; }
- const char *GetFrameNameByAddr(uintptr_t addr, uintptr_t *offset);
+ const char *GetFrameNameByAddr(uptr addr, uptr *offset);
- bool AddrIsInStack(uintptr_t addr) {
+ bool AddrIsInStack(uptr addr) {
return addr >= stack_bottom_ && addr < stack_top_;
}
@@ -96,8 +96,8 @@ class AsanThread {
AsanThreadSummary *summary_;
thread_callback_t start_routine_;
void *arg_;
- uintptr_t stack_top_;
- uintptr_t stack_bottom_;
+ uptr stack_top_;
+ uptr stack_bottom_;
FakeStack fake_stack_;
AsanThreadLocalMallocStorage malloc_storage_;
diff --git a/lib/asan/asan_thread_registry.cc b/lib/asan/asan_thread_registry.cc
index 09f90fa24..1aae49801 100644
--- a/lib/asan/asan_thread_registry.cc
+++ b/lib/asan/asan_thread_registry.cc
@@ -48,7 +48,7 @@ void AsanThreadRegistry::RegisterThread(AsanThread *thread) {
CHECK(n_threads_ < kMaxNumberOfThreads);
AsanThreadSummary *summary = thread->summary();
- CHECK(summary != NULL);
+ CHECK(summary != 0);
summary->set_tid(tid);
thread_summaries_[tid] = summary;
}
@@ -58,7 +58,7 @@ void AsanThreadRegistry::UnregisterThread(AsanThread *thread) {
FlushToAccumulatedStatsUnlocked(&thread->stats());
AsanThreadSummary *summary = thread->summary();
CHECK(summary);
- summary->set_thread(NULL);
+ summary->set_thread(0);
}
AsanThread *AsanThreadRegistry::GetMain() {
@@ -74,7 +74,7 @@ AsanThread *AsanThreadRegistry::GetCurrent() {
// address. We are not entirely sure that we have correct main thread
// limits, so only do this magic on Android, and only if the found thread is
// the main thread.
- AsanThread* thread = FindThreadByStackAddress((uintptr_t)&summary);
+ AsanThread* thread = FindThreadByStackAddress((uptr)&summary);
if (thread && thread->tid() == 0) {
SetCurrent(thread);
return thread;
@@ -107,19 +107,19 @@ AsanStats AsanThreadRegistry::GetAccumulatedStats() {
return accumulated_stats_;
}
-size_t AsanThreadRegistry::GetCurrentAllocatedBytes() {
+uptr AsanThreadRegistry::GetCurrentAllocatedBytes() {
ScopedLock lock(&mu_);
UpdateAccumulatedStatsUnlocked();
return accumulated_stats_.malloced - accumulated_stats_.freed;
}
-size_t AsanThreadRegistry::GetHeapSize() {
+uptr AsanThreadRegistry::GetHeapSize() {
ScopedLock lock(&mu_);
UpdateAccumulatedStatsUnlocked();
return accumulated_stats_.mmaped;
}
-size_t AsanThreadRegistry::GetFreeBytes() {
+uptr AsanThreadRegistry::GetFreeBytes() {
ScopedLock lock(&mu_);
UpdateAccumulatedStatsUnlocked();
return accumulated_stats_.mmaped
@@ -136,7 +136,7 @@ AsanThreadSummary *AsanThreadRegistry::FindByTid(int tid) {
return thread_summaries_[tid];
}
-AsanThread *AsanThreadRegistry::FindThreadByStackAddress(uintptr_t addr) {
+AsanThread *AsanThreadRegistry::FindThreadByStackAddress(uptr addr) {
ScopedLock lock(&mu_);
// Main thread (tid = 0) stack limits are pretty much guessed; for the other
// threads we ask libpthread, so their limits must be correct.
@@ -154,18 +154,18 @@ AsanThread *AsanThreadRegistry::FindThreadByStackAddress(uintptr_t addr) {
void AsanThreadRegistry::UpdateAccumulatedStatsUnlocked() {
for (int tid = 0; tid < n_threads_; tid++) {
AsanThread *t = thread_summaries_[tid]->thread();
- if (t != NULL) {
+ if (t != 0) {
FlushToAccumulatedStatsUnlocked(&t->stats());
}
}
}
void AsanThreadRegistry::FlushToAccumulatedStatsUnlocked(AsanStats *stats) {
- // AsanStats consists of variables of type size_t only.
- size_t *dst = (size_t*)&accumulated_stats_;
- size_t *src = (size_t*)stats;
- size_t num_fields = sizeof(AsanStats) / sizeof(size_t);
- for (size_t i = 0; i < num_fields; i++) {
+ // AsanStats consists of variables of type uptr only.
+ uptr *dst = (uptr*)&accumulated_stats_;
+ uptr *src = (uptr*)stats;
+ uptr num_fields = sizeof(AsanStats) / sizeof(uptr);
+ for (uptr i = 0; i < num_fields; i++) {
dst[i] += src[i];
src[i] = 0;
}
diff --git a/lib/asan/asan_thread_registry.h b/lib/asan/asan_thread_registry.h
index 491101e74..7a3ad6aba 100644
--- a/lib/asan/asan_thread_registry.h
+++ b/lib/asan/asan_thread_registry.h
@@ -34,7 +34,7 @@ class AsanThreadRegistry {
void UnregisterThread(AsanThread *thread);
AsanThread *GetMain();
- // Get the current thread. May return NULL.
+ // Get the current thread. May return 0.
AsanThread *GetCurrent();
void SetCurrent(AsanThread *t);
@@ -45,17 +45,17 @@ class AsanThreadRegistry {
}
// Returns stats for GetCurrent(), or stats for
- // T0 if GetCurrent() returns NULL.
+ // T0 if GetCurrent() returns 0.
AsanStats &GetCurrentThreadStats();
// Flushes all thread-local stats to accumulated stats, and returns
// a copy of accumulated stats.
AsanStats GetAccumulatedStats();
- size_t GetCurrentAllocatedBytes();
- size_t GetHeapSize();
- size_t GetFreeBytes();
+ uptr GetCurrentAllocatedBytes();
+ uptr GetHeapSize();
+ uptr GetFreeBytes();
AsanThreadSummary *FindByTid(int tid);
- AsanThread *FindThreadByStackAddress(uintptr_t addr);
+ AsanThread *FindThreadByStackAddress(uptr addr);
private:
void UpdateAccumulatedStatsUnlocked();
diff --git a/lib/asan/asan_win.cc b/lib/asan/asan_win.cc
index 801fee5ad..b5f1b3049 100644
--- a/lib/asan/asan_win.cc
+++ b/lib/asan/asan_win.cc
@@ -32,19 +32,19 @@
namespace __asan {
// ---------------------- Memory management ---------------- {{{1
-void *AsanMmapFixedNoReserve(uintptr_t fixed_addr, size_t size) {
+void *AsanMmapFixedNoReserve(uptr fixed_addr, size_t size) {
return VirtualAlloc((LPVOID)fixed_addr, size,
MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
}
void *AsanMmapSomewhereOrDie(size_t size, const char *mem_type) {
- void *rv = VirtualAlloc(NULL, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
- if (rv == NULL)
+ void *rv = VirtualAlloc(0, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
+ if (rv == 0)
OutOfMemoryMessageAndDie(mem_type, size);
return rv;
}
-void *AsanMprotect(uintptr_t fixed_addr, size_t size) {
+void *AsanMprotect(uptr fixed_addr, size_t size) {
return VirtualAlloc((LPVOID)fixed_addr, size,
MEM_RESERVE | MEM_COMMIT, PAGE_NOACCESS);
}
@@ -59,10 +59,10 @@ size_t AsanWrite(int fd, const void *buf, size_t count) {
UNIMPLEMENTED();
HANDLE err = GetStdHandle(STD_ERROR_HANDLE);
- if (err == NULL)
+ if (err == 0)
return 0; // FIXME: this might not work on some apps.
DWORD ret;
- if (!WriteFile(err, buf, count, &ret, NULL))
+ if (!WriteFile(err, buf, count, &ret, 0))
return 0;
return ret;
}
@@ -93,23 +93,23 @@ void AsanThread::SetThreadStackTopAndBottom() {
// FIXME: is it possible for the stack to not be a single allocation?
// Are these values what ASan expects to get (reserved, not committed;
// including stack guard page) ?
- stack_top_ = (uintptr_t)mbi.BaseAddress + mbi.RegionSize;
- stack_bottom_ = (uintptr_t)mbi.AllocationBase;
+ stack_top_ = (uptr)mbi.BaseAddress + mbi.RegionSize;
+ stack_bottom_ = (uptr)mbi.AllocationBase;
}
-void AsanStackTrace::GetStackTrace(size_t max_s, uintptr_t pc, uintptr_t bp) {
+void AsanStackTrace::GetStackTrace(size_t max_s, uptr pc, uptr bp) {
max_size = max_s;
void *tmp[kStackTraceMax];
// FIXME: CaptureStackBackTrace might be too slow for us.
// FIXME: Compare with StackWalk64.
// FIXME: Look at LLVMUnhandledExceptionFilter in Signals.inc
- size_t cs_ret = CaptureStackBackTrace(1, max_size, tmp, NULL),
+ size_t cs_ret = CaptureStackBackTrace(1, max_size, tmp, 0),
offset = 0;
// Skip the RTL frames by searching for the PC in the stacktrace.
// FIXME: this doesn't work well for the malloc/free stacks yet.
for (size_t i = 0; i < cs_ret; i++) {
- if (pc != (uintptr_t)tmp[i])
+ if (pc != (uptr)tmp[i])
continue;
offset = i;
break;
@@ -117,7 +117,7 @@ void AsanStackTrace::GetStackTrace(size_t max_s, uintptr_t pc, uintptr_t bp) {
size = cs_ret - offset;
for (size_t i = 0; i < size; i++)
- trace[i] = (uintptr_t)tmp[i + offset];
+ trace[i] = (uptr)tmp[i + offset];
}
bool __asan_WinSymbolize(const void *addr, char *out_buffer, int buffer_size) {
@@ -126,7 +126,7 @@ bool __asan_WinSymbolize(const void *addr, char *out_buffer, int buffer_size) {
SymSetOptions(SYMOPT_DEFERRED_LOADS |
SYMOPT_UNDNAME |
SYMOPT_LOAD_LINES);
- CHECK(SymInitialize(GetCurrentProcess(), NULL, TRUE));
+ CHECK(SymInitialize(GetCurrentProcess(), 0, TRUE));
// FIXME: We don't call SymCleanup() on exit yet - should we?
dbghelp_initialized = true;
}
@@ -200,7 +200,7 @@ void AsanLock::Unlock() {
// ---------------------- TSD ---------------- {{{1
static bool tsd_key_inited = false;
-static __declspec(thread) void *fake_tsd = NULL;
+static __declspec(thread) void *fake_tsd = 0;
void AsanTSDInit(void (*destructor)(void *tsd)) {
// FIXME: we're ignoring the destructor for now.
@@ -222,7 +222,7 @@ void *AsanDoesNotSupportStaticLinkage() {
#if defined(_DEBUG)
#error Please build the runtime with a non-debug CRT: /MD or /MT
#endif
- return NULL;
+ return 0;
}
bool AsanShadowRangeIsAvailable() {
@@ -260,7 +260,7 @@ const char* AsanGetEnv(const char* name) {
DWORD rv = GetEnvironmentVariableA(name, env_buffer, sizeof(env_buffer));
if (rv > 0 && rv < sizeof(env_buffer))
return env_buffer;
- return NULL;
+ return 0;
}
void AsanDumpProcessMap() {
@@ -271,7 +271,7 @@ int GetPid() {
return GetProcessId(GetCurrentProcess());
}
-uintptr_t GetThreadSelf() {
+uptr GetThreadSelf() {
return GetCurrentThreadId();
}
@@ -308,7 +308,7 @@ int Atexit(void (*function)(void)) {
return atexit(function);
}
-void SortArray(uintptr_t *array, size_t size) {
+void SortArray(uptr *array, size_t size) {
std::sort(array, array + size);
}
diff --git a/lib/asan/tests/asan_noinst_test.cc b/lib/asan/tests/asan_noinst_test.cc
index 204c0dacc..da5b678bf 100644
--- a/lib/asan/tests/asan_noinst_test.cc
+++ b/lib/asan/tests/asan_noinst_test.cc
@@ -92,11 +92,11 @@ TEST(AddressSanitizer, NoInstMallocTest) {
#endif
}
-static void PrintShadow(const char *tag, uintptr_t ptr, size_t size) {
+static void PrintShadow(const char *tag, uptr ptr, size_t size) {
fprintf(stderr, "%s shadow: %lx size % 3ld: ", tag, (long)ptr, (long)size);
- uintptr_t prev_shadow = 0;
+ uptr prev_shadow = 0;
for (intptr_t i = -32; i < (intptr_t)size + 32; i++) {
- uintptr_t shadow = __asan::MemToShadow(ptr + i);
+ uptr shadow = __asan::MemToShadow(ptr + i);
if (i == 0 || i == (intptr_t)size)
fprintf(stderr, ".");
if (shadow != prev_shadow) {
@@ -110,13 +110,13 @@ static void PrintShadow(const char *tag, uintptr_t ptr, size_t size) {
TEST(AddressSanitizer, DISABLED_InternalPrintShadow) {
for (size_t size = 1; size <= 513; size++) {
char *ptr = new char[size];
- PrintShadow("m", (uintptr_t)ptr, size);
+ PrintShadow("m", (uptr)ptr, size);
delete [] ptr;
- PrintShadow("f", (uintptr_t)ptr, size);
+ PrintShadow("f", (uptr)ptr, size);
}
}
-static uintptr_t pc_array[] = {
+static uptr pc_array[] = {
#if __WORDSIZE == 64
0x7effbf756068ULL,
0x7effbf75e5abULL,
@@ -215,7 +215,7 @@ void CompressStackTraceTest(size_t n_iter) {
std::random_shuffle(pc_array, pc_array + kNumPcs);
__asan::AsanStackTrace stack0, stack1;
stack0.CopyFrom(pc_array, kNumPcs);
- stack0.size = std::max((size_t)1, (size_t)my_rand(&seed) % stack0.size);
+ stack0.size = std::max((size_t)1, (size_t)(my_rand(&seed) % stack0.size));
size_t compress_size =
std::max((size_t)2, (size_t)my_rand(&seed) % (2 * kNumPcs));
size_t n_frames =