diff options
author | Kostya Serebryany <kcc@google.com> | 2012-05-31 15:02:07 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2012-05-31 15:02:07 +0000 |
commit | ee3925515e4c7966f3ef489f687aa7e5692806a9 (patch) | |
tree | c4b568e66a63c903be88a1fb312bfb5ef9690199 | |
parent | 3f4c3875c42078e22c7e5356c5746fd18756d958 (diff) |
[asan] more renaming
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@157747 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/asan/asan_allocator.cc | 62 | ||||
-rw-r--r-- | lib/asan/asan_allocator.h | 4 | ||||
-rw-r--r-- | lib/asan/asan_globals.cc | 2 | ||||
-rw-r--r-- | lib/asan/asan_interceptors.cc | 10 | ||||
-rw-r--r-- | lib/asan/asan_interceptors.h | 4 | ||||
-rw-r--r-- | lib/asan/asan_internal.h | 36 | ||||
-rw-r--r-- | lib/asan/asan_linux.cc | 2 | ||||
-rw-r--r-- | lib/asan/asan_mac.cc | 12 | ||||
-rw-r--r-- | lib/asan/asan_mapping.h | 6 | ||||
-rw-r--r-- | lib/asan/asan_poisoning.cc | 18 | ||||
-rw-r--r-- | lib/asan/asan_posix.cc | 4 | ||||
-rw-r--r-- | lib/asan/asan_printf.cc | 16 | ||||
-rw-r--r-- | lib/asan/asan_procmaps.h | 4 | ||||
-rw-r--r-- | lib/asan/asan_rtl.cc | 34 | ||||
-rw-r--r-- | lib/asan/asan_stack.cc | 12 | ||||
-rw-r--r-- | lib/asan/asan_stack.h | 4 | ||||
-rw-r--r-- | lib/asan/asan_thread.cc | 4 | ||||
-rw-r--r-- | lib/asan/asan_win.cc | 2 | ||||
-rw-r--r-- | lib/asan/tests/asan_noinst_test.cc | 20 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_defs.h | 12 |
20 files changed, 138 insertions, 130 deletions
diff --git a/lib/asan/asan_allocator.cc b/lib/asan/asan_allocator.cc index 900384feb..2557d9689 100644 --- a/lib/asan/asan_allocator.cc +++ b/lib/asan/asan_allocator.cc @@ -43,7 +43,7 @@ namespace __asan { #define REDZONE FLAG_redzone static const uptr kMinAllocSize = REDZONE * 2; -static const uint64_t kMaxAvailableRam = 128ULL << 30; // 128G +static const u64 kMaxAvailableRam = 128ULL << 30; // 128G static const uptr kMaxThreadLocalQuarantine = 1 << 20; // 1M static const uptr kMinMmapSize = (ASAN_LOW_MEMORY) ? 4UL << 17 : 4UL << 20; @@ -94,7 +94,7 @@ static inline uptr RoundUpToPowerOfTwo(uptr size) { return 1UL << (up + 1); } -static inline uptr SizeClassToSize(uint8_t size_class) { +static inline uptr SizeClassToSize(u8 size_class) { CHECK(size_class < kNumberOfSizeClasses); if (size_class <= kMallocSizeClassStepLog) { return 1UL << size_class; @@ -103,8 +103,8 @@ static inline uptr SizeClassToSize(uint8_t size_class) { } } -static inline uint8_t SizeToSizeClass(uptr size) { - uint8_t res = 0; +static inline u8 SizeToSizeClass(uptr size) { + u8 res = 0; if (size <= kMallocSizeClassStep) { uptr rounded = RoundUpToPowerOfTwo(size); res = Log2(rounded); @@ -129,9 +129,9 @@ static void PoisonHeapPartialRightRedzone(uptr mem, uptr size) { kAsanHeapRightRedzoneMagic); } -static uint8_t *MmapNewPagesAndPoisonShadow(uptr size) { +static u8 *MmapNewPagesAndPoisonShadow(uptr size) { CHECK(IsAligned(size, kPageSize)); - uint8_t *res = (uint8_t*)AsanMmapSomewhereOrDie(size, __FUNCTION__); + u8 *res = (u8*)AsanMmapSomewhereOrDie(size, __FUNCTION__); PoisonShadow((uptr)res, size, kAsanHeapLeftRedzoneMagic); if (FLAG_debug) { Printf("ASAN_MMAP: [%p, %p)\n", res, res + size); @@ -157,35 +157,35 @@ enum { }; struct ChunkBase { - uint16_t chunk_state; - uint8_t size_class; - uint32_t offset; // User-visible memory starts at this+offset (beg()). - int32_t alloc_tid; - int32_t free_tid; + u16 chunk_state; + u8 size_class; + u32 offset; // User-visible memory starts at this+offset (beg()). + s32 alloc_tid; + s32 free_tid; uptr used_size; // Size requested by the user. AsanChunk *next; uptr beg() { return (uptr)this + offset; } uptr Size() { return SizeClassToSize(size_class); } - uint8_t SizeClass() { return size_class; } + u8 SizeClass() { return size_class; } }; struct AsanChunk: public ChunkBase { - uint32_t *compressed_alloc_stack() { + u32 *compressed_alloc_stack() { CHECK(REDZONE >= sizeof(ChunkBase)); - return (uint32_t*)((uptr)this + sizeof(ChunkBase)); + return (u32*)((uptr)this + sizeof(ChunkBase)); } - uint32_t *compressed_free_stack() { + u32 *compressed_free_stack() { CHECK(REDZONE >= sizeof(ChunkBase)); - return (uint32_t*)((uptr)this + REDZONE); + return (u32*)((uptr)this + REDZONE); } // The left redzone after the ChunkBase is given to the alloc stack trace. uptr compressed_alloc_stack_size() { - return (REDZONE - sizeof(ChunkBase)) / sizeof(uint32_t); + return (REDZONE - sizeof(ChunkBase)) / sizeof(u32); } uptr compressed_free_stack_size() { - return (REDZONE) / sizeof(uint32_t); + return (REDZONE) / sizeof(u32); } bool AddrIsInside(uptr addr, uptr access_size, uptr *offset) { @@ -307,7 +307,7 @@ class MallocInfo { explicit MallocInfo(LinkerInitialized x) : mu_(x) { } - AsanChunk *AllocateChunks(uint8_t size_class, uptr n_chunks) { + AsanChunk *AllocateChunks(u8 size_class, uptr n_chunks) { AsanChunk *m = 0; AsanChunk **fl = &free_lists_[size_class]; { @@ -515,7 +515,7 @@ class MallocInfo { } // Get a list of newly allocated chunks. - AsanChunk *GetNewChunks(uint8_t size_class) { + AsanChunk *GetNewChunks(u8 size_class) { uptr size = SizeClassToSize(size_class); CHECK(IsPowerOfTwo(kMinMmapSize)); CHECK(size < kMinMmapSize || (size % kMinMmapSize) == 0); @@ -530,7 +530,7 @@ class MallocInfo { mmap_size += kPageSize; } CHECK(n_chunks > 0); - uint8_t *mem = MmapNewPagesAndPoisonShadow(mmap_size); + u8 *mem = MmapNewPagesAndPoisonShadow(mmap_size); // Statistics. AsanStats &thread_stats = asanThreadRegistry().GetCurrentThreadStats(); @@ -608,7 +608,7 @@ static void Describe(uptr addr, uptr access_size) { } } -static uint8_t *Allocate(uptr alignment, uptr size, AsanStackTrace *stack) { +static u8 *Allocate(uptr alignment, uptr size, AsanStackTrace *stack) { __asan_init(); CHECK(stack); if (size == 0) { @@ -626,7 +626,7 @@ static uint8_t *Allocate(uptr alignment, uptr size, AsanStackTrace *stack) { return 0; } - uint8_t size_class = SizeToSizeClass(needed_size); + u8 size_class = SizeToSizeClass(needed_size); uptr size_to_allocate = SizeClassToSize(size_class); CHECK(size_to_allocate >= kMinAllocSize); CHECK(size_to_allocate >= needed_size); @@ -692,10 +692,10 @@ static uint8_t *Allocate(uptr alignment, uptr size, AsanStackTrace *stack) { if (size <= FLAG_max_malloc_fill_size) { REAL(memset)((void*)addr, 0, rounded_size); } - return (uint8_t*)addr; + return (u8*)addr; } -static void Deallocate(uint8_t *ptr, AsanStackTrace *stack) { +static void Deallocate(u8 *ptr, AsanStackTrace *stack) { if (!ptr) return; CHECK(stack); @@ -707,7 +707,7 @@ static void Deallocate(uint8_t *ptr, AsanStackTrace *stack) { 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); + u16 old_chunk_state = AtomicExchange(&m->chunk_state, CHUNK_QUARANTINE); if (old_chunk_state == CHUNK_QUARANTINE) { Report("ERROR: AddressSanitizer attempting double-free on %p:\n", ptr); @@ -751,7 +751,7 @@ static void Deallocate(uint8_t *ptr, AsanStackTrace *stack) { } } -static uint8_t *Reallocate(uint8_t *old_ptr, uptr new_size, +static u8 *Reallocate(u8 *old_ptr, uptr new_size, AsanStackTrace *stack) { CHECK(old_ptr && new_size); @@ -764,7 +764,7 @@ static uint8_t *Reallocate(uint8_t *old_ptr, uptr new_size, CHECK(m->chunk_state == CHUNK_ALLOCATED); uptr old_size = m->used_size; uptr memcpy_size = Min(new_size, old_size); - uint8_t *new_ptr = Allocate(0, new_size, stack); + u8 *new_ptr = Allocate(0, new_size, stack); if (new_ptr) { CHECK(REAL(memcpy) != 0); REAL(memcpy)(new_ptr, old_ptr, memcpy_size); @@ -805,7 +805,7 @@ void *asan_memalign(uptr alignment, uptr size, AsanStackTrace *stack) { void asan_free(void *ptr, AsanStackTrace *stack) { ASAN_DELETE_HOOK(ptr); - Deallocate((uint8_t*)ptr, stack); + Deallocate((u8*)ptr, stack); } void *asan_malloc(uptr size, AsanStackTrace *stack) { @@ -829,10 +829,10 @@ void *asan_realloc(void *p, uptr size, AsanStackTrace *stack) { return ptr; } else if (size == 0) { ASAN_DELETE_HOOK(p); - Deallocate((uint8_t*)p, stack); + Deallocate((u8*)p, stack); return 0; } - return Reallocate((uint8_t*)p, size, stack); + return Reallocate((u8*)p, size, stack); } void *asan_valloc(uptr size, AsanStackTrace *stack) { diff --git a/lib/asan/asan_allocator.h b/lib/asan/asan_allocator.h index eee590122..2aed59853 100644 --- a/lib/asan/asan_allocator.h +++ b/lib/asan/asan_allocator.h @@ -60,8 +60,8 @@ struct FakeFrame { 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; + u64 real_stack : 48; + u64 size_minus_one : 16; }; struct FakeFrameFifo { diff --git a/lib/asan/asan_globals.cc b/lib/asan/asan_globals.cc index 713f6003e..111d336ec 100644 --- a/lib/asan/asan_globals.cc +++ b/lib/asan/asan_globals.cc @@ -45,7 +45,7 @@ void PoisonRedZones(const Global &g) { kGlobalAndStackRedzone, kAsanGlobalRedzoneMagic); if ((g.size % kGlobalAndStackRedzone) != 0) { // partial right redzone - uint64_t g_aligned_down_size = kGlobalAndStackRedzone * + u64 g_aligned_down_size = kGlobalAndStackRedzone * (g.size / kGlobalAndStackRedzone); CHECK(g_aligned_down_size == g_aligned_size - kGlobalAndStackRedzone); PoisonShadowPartialRightRedzone(g.beg + g_aligned_down_size, diff --git a/lib/asan/asan_interceptors.cc b/lib/asan/asan_interceptors.cc index 4ecba152b..75e184d87 100644 --- a/lib/asan/asan_interceptors.cc +++ b/lib/asan/asan_interceptors.cc @@ -184,11 +184,11 @@ static inline int ToLower(int c) { // ---------------------- Internal string functions ---------------- {{{1 -int64_t internal_simple_strtoll(const char *nptr, char **endptr, int base) { +s64 internal_simple_strtoll(const char *nptr, char **endptr, int base) { CHECK(base == 10); while (IsSpace(*nptr)) nptr++; int sgn = 1; - uint64_t res = 0; + u64 res = 0; bool have_digits = false; char *old_nptr = (char*)nptr; if (*nptr == '+') { @@ -209,13 +209,13 @@ int64_t internal_simple_strtoll(const char *nptr, char **endptr, int base) { *endptr = (have_digits) ? (char*)nptr : old_nptr; } if (sgn > 0) { - return (int64_t)(Min((uint64_t)INT64_MAX, res)); + return (s64)(Min((u64)INT64_MAX, res)); } else { - return (res > INT64_MAX) ? INT64_MIN : ((int64_t)res * -1); + return (res > INT64_MAX) ? INT64_MIN : ((s64)res * -1); } } -int64_t internal_atoll(const char *nptr) { +s64 internal_atoll(const char *nptr) { return internal_simple_strtoll(nptr, (char**)0, 10); } diff --git a/lib/asan/asan_interceptors.h b/lib/asan/asan_interceptors.h index 005e7e4db..3a52bea91 100644 --- a/lib/asan/asan_interceptors.h +++ b/lib/asan/asan_interceptors.h @@ -31,7 +31,7 @@ DECLARE_REAL(int, sigaction, int signum, const struct sigaction *act, namespace __asan { // __asan::internal_X() is the implementation of X() for use in RTL. -int64_t internal_atoll(const char *nptr); +s64 internal_atoll(const char *nptr); uptr internal_strlen(const char *s); uptr internal_strnlen(const char *s, uptr maxlen); char* internal_strchr(const char *s, int c); @@ -43,7 +43,7 @@ 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, uptr n); // Works only for base=10 and doesn't set errno. -int64_t internal_simple_strtoll(const char *nptr, char **endptr, int base); +s64 internal_simple_strtoll(const char *nptr, char **endptr, int base); void InitializeAsanInterceptors(); diff --git a/lib/asan/asan_internal.h b/lib/asan/asan_internal.h index 53d6eb280..597621e61 100644 --- a/lib/asan/asan_internal.h +++ b/lib/asan/asan_internal.h @@ -23,19 +23,19 @@ #if defined(_WIN32) # if defined(__clang__) -typedef int intptr_t; +typedef int sptr; typedef unsigned int uptr; # endif // There's no <stdint.h> in Visual Studio 9, so we have to define [u]int*_t. -typedef unsigned __int8 uint8_t; -typedef unsigned __int16 uint16_t; -typedef unsigned __int32 uint32_t; -typedef unsigned __int64 uint64_t; -typedef __int8 int8_t; +typedef unsigned __int8 u8; +typedef unsigned __int16 u16; +typedef unsigned __int32 u32; +typedef unsigned __int64 u64; +typedef __int8 s8; typedef __int16 int16_t; -typedef __int32 int32_t; -typedef __int64 int64_t; +typedef __int32 s32; +typedef __int64 s64; typedef unsigned long DWORD; // NOLINT extern "C" void* _ReturnAddress(void); @@ -48,7 +48,7 @@ extern "C" void* _ReturnAddress(void); # define ASAN_INTERFACE_ATTRIBUTE // TODO(timurrrr): do we need this on Win? #else // defined(_WIN32) -# include <stdint.h> // for __WORDSIZE +// #include <stdint.h> # define ALIAS(x) __attribute__((alias(x))) # define ALIGNED(x) __attribute__((aligned(x))) @@ -194,7 +194,7 @@ void InstallSignalHandlers(); int GetPid(); uptr GetThreadSelf(); int AtomicInc(int *a); -uint16_t AtomicExchange(uint16_t *a, uint16_t new_val); +u16 AtomicExchange(u16 *a, u16 new_val); // Wrapper for TLS/TSD. void AsanTSDInit(void (*destructor)(void *tsd)); @@ -223,13 +223,13 @@ void SortArray(uptr *array, uptr size); // asan_poisoning.cc // Poisons the shadow memory for "size" bytes starting from "addr". -void PoisonShadow(uptr addr, uptr size, uint8_t value); +void PoisonShadow(uptr addr, uptr size, u8 value); // Poisons the shadow memory for "redzone_size" bytes starting from // "addr + size". void PoisonShadowPartialRightRedzone(uptr addr, uptr size, uptr redzone_size, - uint8_t value); + u8 value); // Platfrom-specific options. #ifdef __APPLE__ @@ -241,13 +241,13 @@ bool PlatformHasDifferentMemcpyAndMemmove(); #endif // __APPLE__ extern uptr FLAG_quarantine_size; -extern int64_t FLAG_demangle; +extern s64 FLAG_demangle; extern bool FLAG_symbolize; -extern int64_t FLAG_v; +extern s64 FLAG_v; extern uptr FLAG_redzone; -extern int64_t FLAG_debug; +extern s64 FLAG_debug; extern bool FLAG_poison_shadow; -extern int64_t FLAG_report_globals; +extern s64 FLAG_report_globals; extern uptr FLAG_malloc_context_size; extern bool FLAG_replace_str; extern bool FLAG_replace_intrin; @@ -255,9 +255,9 @@ extern bool FLAG_replace_cfallocator; extern bool FLAG_fast_unwind; extern bool FLAG_use_fake_stack; extern uptr FLAG_max_malloc_fill_size; -extern int64_t FLAG_exitcode; +extern s64 FLAG_exitcode; extern bool FLAG_allow_user_poisoning; -extern int64_t FLAG_sleep_before_dying; +extern s64 FLAG_sleep_before_dying; extern bool FLAG_handle_segv; extern bool FLAG_use_sigaltstack; extern bool FLAG_check_malloc_usable_size; diff --git a/lib/asan/asan_linux.cc b/lib/asan/asan_linux.cc index 5ff4dea64..040b8b711 100644 --- a/lib/asan/asan_linux.cc +++ b/lib/asan/asan_linux.cc @@ -74,7 +74,7 @@ bool AsanInterceptsSignal(int signum) { } static void *asan_mmap(void *addr, uptr length, int prot, int flags, - int fd, uint64_t offset) { + int fd, u64 offset) { # if __WORDSIZE == 64 return (void *)syscall(__NR_mmap, addr, length, prot, flags, fd, offset); # else diff --git a/lib/asan/asan_mac.cc b/lib/asan/asan_mac.cc index e3c1e722a..21e97954d 100644 --- a/lib/asan/asan_mac.cc +++ b/lib/asan/asan_mac.cc @@ -98,7 +98,7 @@ bool AsanInterceptsSignal(int signum) { } static void *asan_mmap(void *addr, size_t length, int prot, int flags, - int fd, uint64_t offset) { + int fd, u64 offset) { return mmap(addr, length, prot, flags, fd, offset); } @@ -211,14 +211,14 @@ void AsanProcMaps::Reset() { // and returns the start and end addresses and file offset of the corresponding // segment. // Note that the segment addresses are not necessarily sorted. -template<uint32_t kLCSegment, typename SegmentCommand> +template<u32 kLCSegment, typename SegmentCommand> bool AsanProcMaps::NextSegmentLoad( 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; if (((const load_command *)lc)->cmd == kLCSegment) { - const intptr_t dlloff = _dyld_get_image_vmaddr_slide(current_image_); + const sptr dlloff = _dyld_get_image_vmaddr_slide(current_image_); const SegmentCommand* sc = (const SegmentCommand *)lc; if (start) *start = sc->vmaddr + dlloff; if (end) *end = sc->vmaddr + sc->vmsize + dlloff; @@ -414,7 +414,7 @@ typedef void* pthread_workitem_handle_t; typedef void* dispatch_group_t; typedef void* dispatch_queue_t; -typedef uint64_t dispatch_time_t; +typedef u64 dispatch_time_t; typedef void (*dispatch_function_t)(void *block); typedef void* (*worker_t)(void *block); @@ -604,9 +604,9 @@ 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 { uptr _cfisa; - uint8_t _cfinfo[4]; + u8 _cfinfo[4]; #if __LP64__ - uint32_t _rc; + u32 _rc; #endif } CFRuntimeBase; diff --git a/lib/asan/asan_mapping.h b/lib/asan/asan_mapping.h index 31564f71b..6bf79a39c 100644 --- a/lib/asan/asan_mapping.h +++ b/lib/asan/asan_mapping.h @@ -103,10 +103,10 @@ static inline bool AddrIsAlignedByGranularity(uptr a) { static inline bool AddressIsPoisoned(uptr a) { const uptr kAccessSize = 1; - uint8_t *shadow_address = (uint8_t*)MemToShadow(a); - int8_t shadow_value = *shadow_address; + u8 *shadow_address = (u8*)MemToShadow(a); + s8 shadow_value = *shadow_address; if (shadow_value) { - uint8_t last_accessed_byte = (a & (SHADOW_GRANULARITY - 1)) + u8 last_accessed_byte = (a & (SHADOW_GRANULARITY - 1)) + kAccessSize - 1; return (last_accessed_byte >= shadow_value); } diff --git a/lib/asan/asan_poisoning.cc b/lib/asan/asan_poisoning.cc index 36b14e8f8..7a9d16e7b 100644 --- a/lib/asan/asan_poisoning.cc +++ b/lib/asan/asan_poisoning.cc @@ -19,7 +19,7 @@ namespace __asan { -void PoisonShadow(uptr addr, uptr size, uint8_t value) { +void PoisonShadow(uptr addr, uptr size, u8 value) { CHECK(AddrIsAlignedByGranularity(addr)); CHECK(AddrIsAlignedByGranularity(addr + size)); uptr shadow_beg = MemToShadow(addr); @@ -31,9 +31,9 @@ void PoisonShadow(uptr addr, uptr size, uint8_t value) { void PoisonShadowPartialRightRedzone(uptr addr, uptr size, uptr redzone_size, - uint8_t value) { + u8 value) { CHECK(AddrIsAlignedByGranularity(addr)); - uint8_t *shadow = (uint8_t*)MemToShadow(addr); + u8 *shadow = (u8*)MemToShadow(addr); for (uptr i = 0; i < redzone_size; i += SHADOW_GRANULARITY, shadow++) { if (i + SHADOW_GRANULARITY <= size) { @@ -48,12 +48,12 @@ void PoisonShadowPartialRightRedzone(uptr addr, struct ShadowSegmentEndpoint { - uint8_t *chunk; - int8_t offset; // in [0, SHADOW_GRANULARITY) - int8_t value; // = *chunk; + u8 *chunk; + s8 offset; // in [0, SHADOW_GRANULARITY) + s8 value; // = *chunk; explicit ShadowSegmentEndpoint(uptr address) { - chunk = (uint8_t*)MemToShadow(address); + chunk = (u8*)MemToShadow(address); offset = address & (SHADOW_GRANULARITY - 1); value = *chunk; } @@ -85,7 +85,7 @@ void __asan_poison_memory_region(void const volatile *addr, uptr size) { ShadowSegmentEndpoint end(end_addr); if (beg.chunk == end.chunk) { CHECK(beg.offset < end.offset); - int8_t value = beg.value; + s8 value = beg.value; CHECK(value == end.value); // We can only poison memory if the byte in end.offset is unaddressable. // No need to re-poison memory if it is poisoned already. @@ -126,7 +126,7 @@ void __asan_unpoison_memory_region(void const volatile *addr, uptr size) { ShadowSegmentEndpoint end(end_addr); if (beg.chunk == end.chunk) { CHECK(beg.offset < end.offset); - int8_t value = beg.value; + s8 value = beg.value; CHECK(value == end.value); // We unpoison memory bytes up to enbytes up to end.offset if it is not // unpoisoned already. diff --git a/lib/asan/asan_posix.cc b/lib/asan/asan_posix.cc index 9fde9df4c..b5e810722 100644 --- a/lib/asan/asan_posix.cc +++ b/lib/asan/asan_posix.cc @@ -143,7 +143,7 @@ void AsanDisableCoreDumper() { void AsanDumpProcessMap() { AsanProcMaps proc_maps; uptr start, end; - const intptr_t kBufSize = 4095; + const sptr kBufSize = 4095; char filename[kBufSize]; Report("Process memory map follows:\n"); while (proc_maps.Next(&start, &end, /* file_offset */0, @@ -185,7 +185,7 @@ int AtomicInc(int *a) { #endif } -uint16_t AtomicExchange(uint16_t *a, uint16_t new_val) { +u16 AtomicExchange(u16 *a, u16 new_val) { return __sync_lock_test_and_set(a, new_val); } diff --git a/lib/asan/asan_printf.cc b/lib/asan/asan_printf.cc index a9f501ce2..fad3c01f4 100644 --- a/lib/asan/asan_printf.cc +++ b/lib/asan/asan_printf.cc @@ -52,8 +52,8 @@ static inline int AppendChar(char **buff, const char *buff_end, char c) { // Appends number in a given base to buffer. If its length is less than // "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) { +static int AppendUnsigned(char **buff, const char *buff_end, u64 num, + u8 base, u8 minimal_num_length) { uptr const kMaxLen = 30; RAW_CHECK(base == 10 || base == 16); RAW_CHECK(minimal_num_length < kMaxLen); @@ -75,13 +75,13 @@ static int AppendUnsigned(char **buff, const char *buff_end, uint64_t num, } static inline int AppendSignedDecimal(char **buff, const char *buff_end, - int64_t num) { + s64 num) { int result = 0; if (num < 0) { result += AppendChar(buff, buff_end, '-'); num = -num; } - result += AppendUnsigned(buff, buff_end, (uint64_t)num, 10, 0); + result += AppendUnsigned(buff, buff_end, (u64)num, 10, 0); return result; } @@ -97,7 +97,7 @@ static inline int AppendString(char **buff, const char *buff_end, } static inline int AppendPointer(char **buff, const char *buff_end, - uint64_t ptr_value) { + u64 ptr_value) { int result = 0; result += AppendString(buff, buff_end, "0x"); result += AppendUnsigned(buff, buff_end, ptr_value, 16, @@ -119,10 +119,10 @@ static int VSNPrintf(char *buff, int buff_length, cur++; bool have_z = (*cur == 'z'); cur += have_z; - int64_t dval; - uint64_t uval; + s64 dval; + u64 uval; switch (*cur) { - case 'd': dval = have_z ? va_arg(args, intptr_t) + case 'd': dval = have_z ? va_arg(args, sptr) : va_arg(args, int); result += AppendSignedDecimal(&buff, buff_end, dval); break; diff --git a/lib/asan/asan_procmaps.h b/lib/asan/asan_procmaps.h index f660e312b..cfb055002 100644 --- a/lib/asan/asan_procmaps.h +++ b/lib/asan/asan_procmaps.h @@ -56,11 +56,11 @@ class AsanProcMaps { uptr proc_self_maps_buff_len_; char *current_; #elif defined __APPLE__ - template<uint32_t kLCSegment, typename SegmentCommand> + template<u32 kLCSegment, typename SegmentCommand> bool NextSegmentLoad(uptr *start, uptr *end, uptr *offset, char filename[], uptr filename_size); int current_image_; - uint32_t current_magic_; + u32 current_magic_; int current_load_cmd_count_; char *current_load_cmd_addr_; #endif diff --git a/lib/asan/asan_rtl.cc b/lib/asan/asan_rtl.cc index e13768ab4..cc713d585 100644 --- a/lib/asan/asan_rtl.cc +++ b/lib/asan/asan_rtl.cc @@ -30,24 +30,24 @@ static const uptr kMallocContextSize = 30; uptr FLAG_malloc_context_size = kMallocContextSize; uptr FLAG_max_malloc_fill_size = 0; -int64_t FLAG_v = 0; +s64 FLAG_v = 0; 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; +static s64 FLAG_atexit = 0; bool FLAG_poison_shadow = 1; -int64_t FLAG_report_globals = 1; +s64 FLAG_report_globals = 1; bool FLAG_handle_segv = ASAN_NEEDS_SEGV; bool FLAG_use_sigaltstack = 0; bool FLAG_symbolize = 1; -int64_t FLAG_demangle = 1; -int64_t FLAG_debug = 0; +s64 FLAG_demangle = 1; +s64 FLAG_debug = 0; bool FLAG_replace_cfallocator = 1; // Used on Mac only. bool FLAG_replace_str = 1; bool FLAG_replace_intrin = 1; bool FLAG_use_fake_stack = 1; -int64_t FLAG_exitcode = ASAN_DEFAULT_FAILURE_EXITCODE; +s64 FLAG_exitcode = ASAN_DEFAULT_FAILURE_EXITCODE; bool FLAG_allow_user_poisoning = 1; -int64_t FLAG_sleep_before_dying = 0; +s64 FLAG_sleep_before_dying = 0; bool FLAG_abort_on_error = 0; bool FLAG_unmap_shadow_on_exit = 0; bool FLAG_disable_core = __WORDSIZE == 64; @@ -69,7 +69,7 @@ void ShowStatsAndAbort() { } static void PrintBytes(const char *before, uptr *a) { - uint8_t *bytes = (uint8_t*)a; + u8 *bytes = (u8*)a; uptr byte_num = (__WORDSIZE) / 8; Printf("%s%p:", before, (void*)a); for (uptr i = 0; i < byte_num; i++) { @@ -167,7 +167,7 @@ void *LowLevelAllocator::Allocate(uptr size) { static bool DescribeStackAddress(uptr addr, uptr access_size) { AsanThread *t = asanThreadRegistry().FindThreadByStackAddress(addr); if (!t) return false; - const intptr_t kBufSize = 4095; + const sptr kBufSize = 4095; char buf[kBufSize]; uptr offset = 0; const char *frame_descr = t->GetFrameNameByAddr(addr, &offset); @@ -181,7 +181,7 @@ static bool DescribeStackAddress(uptr addr, uptr access_size) { buf[0] = 0; internal_strncat(buf, frame_descr, Min(kBufSize, - static_cast<intptr_t>(name_end - frame_descr))); + static_cast<sptr>(name_end - frame_descr))); Printf("Address %p is located at offset %zu " "in frame <%s> of T%d's stack:\n", addr, offset, buf, t->tid()); @@ -193,7 +193,7 @@ static bool DescribeStackAddress(uptr addr, uptr access_size) { // Report all objects in this frame. for (uptr i = 0; i < n_objects; i++) { uptr beg, size; - intptr_t len; + sptr len; beg = internal_simple_strtoll(p, &p, 10); size = internal_simple_strtoll(p, &p, 10); len = internal_simple_strtoll(p, &p, 10); @@ -277,7 +277,7 @@ static NOINLINE void force_interface_symbols() { // -------------------------- Init ------------------- {{{1 static void IntFlagValue(const char *flags, const char *flag, - int64_t *out_val) { + s64 *out_val) { if (!flags) return; const char *str = internal_strstr(flags, flag); if (!str) return; @@ -368,7 +368,7 @@ void __asan_report_error(uptr pc, uptr bp, uptr sp, Printf("=================================================================\n"); const char *bug_descr = "unknown-crash"; if (AddrIsInMem(addr)) { - uint8_t *shadow_addr = (uint8_t*)MemToShadow(addr); + u8 *shadow_addr = (u8*)MemToShadow(addr); // If we are accessing 16 bytes, look at the second shadow byte. if (*shadow_addr == 0 && access_size > SHADOW_GRANULARITY) shadow_addr++; @@ -456,18 +456,18 @@ void __asan_report_error(uptr pc, uptr bp, uptr sp, static void ParseAsanOptions(const char *options) { IntFlagValue(options, "malloc_context_size=", - (int64_t*)&FLAG_malloc_context_size); + (s64*)&FLAG_malloc_context_size); CHECK(FLAG_malloc_context_size <= kMallocContextSize); IntFlagValue(options, "max_malloc_fill_size=", - (int64_t*)&FLAG_max_malloc_fill_size); + (s64*)&FLAG_max_malloc_fill_size); IntFlagValue(options, "verbosity=", &FLAG_v); - IntFlagValue(options, "redzone=", (int64_t*)&FLAG_redzone); + IntFlagValue(options, "redzone=", (s64*)&FLAG_redzone); CHECK(FLAG_redzone >= 32); CHECK((FLAG_redzone & (FLAG_redzone - 1)) == 0); - IntFlagValue(options, "quarantine_size=", (int64_t*)&FLAG_quarantine_size); + IntFlagValue(options, "quarantine_size=", (s64*)&FLAG_quarantine_size); IntFlagValue(options, "atexit=", &FLAG_atexit); BoolFlagValue(options, "poison_shadow=", &FLAG_poison_shadow); diff --git a/lib/asan/asan_stack.cc b/lib/asan/asan_stack.cc index 571a2ffb0..e00688ac0 100644 --- a/lib/asan/asan_stack.cc +++ b/lib/asan/asan_stack.cc @@ -85,7 +85,7 @@ void AsanStackTrace::FastUnwindStack(uptr pc, uptr bp) { // 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. uptr AsanStackTrace::CompressStack(AsanStackTrace *stack, - uint32_t *compressed, uptr size) { + u32 *compressed, uptr size) { #if __WORDSIZE == 32 // Don't compress, just copy. uptr res = 0; @@ -103,10 +103,10 @@ uptr AsanStackTrace::CompressStack(AsanStackTrace *stack, for (uptr i = 0, n = stack->size; i < n; i++) { uptr pc = stack->trace[i]; if (!pc) break; - if ((int64_t)pc < 0) break; + if ((s64)pc < 0) break; // Printf("C pc[%zu] %zx\n", i, pc); if (prev_pc - pc < kMaxOffset || pc - prev_pc < kMaxOffset) { - uptr offset = (int64_t)(pc - prev_pc); + uptr offset = (s64)(pc - prev_pc); offset |= (1U << 31); if (c_index >= size) break; // Printf("C co[%zu] offset %zx\n", i, offset); @@ -148,7 +148,7 @@ uptr AsanStackTrace::CompressStack(AsanStackTrace *stack, } void AsanStackTrace::UncompressStack(AsanStackTrace *stack, - uint32_t *compressed, uptr size) { + u32 *compressed, uptr size) { #if __WORDSIZE == 32 // Don't uncompress, just copy. stack->size = 0; @@ -161,12 +161,12 @@ void AsanStackTrace::UncompressStack(AsanStackTrace *stack, uptr prev_pc = 0; stack->size = 0; for (uptr i = 0; i < size && stack->size < kStackTraceMax; i++) { - uint32_t x = compressed[i]; + u32 x = compressed[i]; uptr pc = 0; if (x & (1U << 31)) { // Printf("U co[%zu] offset: %x\n", i, x); // this is an offset - int32_t offset = x; + s32 offset = x; offset = (offset << 1) >> 1; // remove the 31-byte and sign-extend. pc = prev_pc + offset; CHECK(pc); diff --git a/lib/asan/asan_stack.h b/lib/asan/asan_stack.h index a754515c1..101408a81 100644 --- a/lib/asan/asan_stack.h +++ b/lib/asan/asan_stack.h @@ -50,9 +50,9 @@ struct AsanStackTrace { static uptr GetCurrentPc(); static uptr CompressStack(AsanStackTrace *stack, - uint32_t *compressed, uptr size); + u32 *compressed, uptr size); static void UncompressStack(AsanStackTrace *stack, - uint32_t *compressed, uptr size); + u32 *compressed, uptr size); }; } // namespace __asan diff --git a/lib/asan/asan_thread.cc b/lib/asan/asan_thread.cc index da5ab3d47..a9102535a 100644 --- a/lib/asan/asan_thread.cc +++ b/lib/asan/asan_thread.cc @@ -116,8 +116,8 @@ const char *AsanThread::GetFrameNameByAddr(uptr addr, uptr *offset) { is_fake_stack = true; } 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); + u8 *shadow_ptr = (u8*)MemToShadow(aligned_addr); + u8 *shadow_bottom = (u8*)MemToShadow(bottom); while (shadow_ptr >= shadow_bottom && *shadow_ptr != kAsanStackLeftRedzoneMagic) { diff --git a/lib/asan/asan_win.cc b/lib/asan/asan_win.cc index b5f1b3049..679147eca 100644 --- a/lib/asan/asan_win.cc +++ b/lib/asan/asan_win.cc @@ -234,7 +234,7 @@ int AtomicInc(int *a) { return InterlockedExchangeAdd((LONG*)a, 1) + 1; } -uint16_t AtomicExchange(uint16_t *a, uint16_t new_val) { +u16 AtomicExchange(u16 *a, u16 new_val) { // InterlockedExchange16 seems unavailable on some MSVS installations. // Everybody stand back, I pretend to know inline assembly! // FIXME: I assume VC is smart enough to save/restore eax/ecx? diff --git a/lib/asan/tests/asan_noinst_test.cc b/lib/asan/tests/asan_noinst_test.cc index da5b678bf..a6982e90c 100644 --- a/lib/asan/tests/asan_noinst_test.cc +++ b/lib/asan/tests/asan_noinst_test.cc @@ -27,11 +27,11 @@ // Simple stand-alone pseudorandom number generator. // Current algorithm is ANSI C linear congruential PRNG. -static inline uint32_t my_rand(uint32_t* state) { +static inline u32 my_rand(u32* state) { return (*state = *state * 1103515245 + 12345) >> 16; } -static uint32_t global_seed = 0; +static u32 global_seed = 0; TEST(AddressSanitizer, InternalSimpleDeathTest) { @@ -39,7 +39,7 @@ TEST(AddressSanitizer, InternalSimpleDeathTest) { } static void MallocStress(size_t n) { - uint32_t seed = my_rand(&global_seed); + u32 seed = my_rand(&global_seed); __asan::AsanStackTrace stack1; stack1.trace[0] = 0xa123; stack1.trace[1] = 0xa456; @@ -95,13 +95,13 @@ TEST(AddressSanitizer, NoInstMallocTest) { static void PrintShadow(const char *tag, uptr ptr, size_t size) { fprintf(stderr, "%s shadow: %lx size % 3ld: ", tag, (long)ptr, (long)size); uptr prev_shadow = 0; - for (intptr_t i = -32; i < (intptr_t)size + 32; i++) { + for (sptr i = -32; i < (sptr)size + 32; i++) { uptr shadow = __asan::MemToShadow(ptr + i); - if (i == 0 || i == (intptr_t)size) + if (i == 0 || i == (sptr)size) fprintf(stderr, "."); if (shadow != prev_shadow) { prev_shadow = shadow; - fprintf(stderr, "%02x", (int)*(uint8_t*)shadow); + fprintf(stderr, "%02x", (int)*(u8*)shadow); } } fprintf(stderr, "\n"); @@ -207,9 +207,9 @@ static uptr pc_array[] = { }; void CompressStackTraceTest(size_t n_iter) { - uint32_t seed = my_rand(&global_seed); + u32 seed = my_rand(&global_seed); const size_t kNumPcs = ASAN_ARRAY_SIZE(pc_array); - uint32_t compressed[2 * kNumPcs]; + u32 compressed[2 * kNumPcs]; for (size_t iter = 0; iter < n_iter; iter++) { std::random_shuffle(pc_array, pc_array + kNumPcs); @@ -235,7 +235,7 @@ TEST(AddressSanitizer, CompressStackTraceTest) { void CompressStackTraceBenchmark(size_t n_iter) { const size_t kNumPcs = ASAN_ARRAY_SIZE(pc_array); - uint32_t compressed[2 * kNumPcs]; + u32 compressed[2 * kNumPcs]; std::random_shuffle(pc_array, pc_array + kNumPcs); __asan::AsanStackTrace stack0; @@ -274,7 +274,7 @@ TEST(AddressSanitizer, QuarantineTest) { } void *ThreadedQuarantineTestWorker(void *unused) { - uint32_t seed = my_rand(&global_seed); + u32 seed = my_rand(&global_seed); __asan::AsanStackTrace stack; stack.trace[0] = 0x890; stack.size = 1; diff --git a/lib/sanitizer_common/sanitizer_defs.h b/lib/sanitizer_common/sanitizer_defs.h index 5e08ef3c6..4296c2633 100644 --- a/lib/sanitizer_common/sanitizer_defs.h +++ b/lib/sanitizer_common/sanitizer_defs.h @@ -28,7 +28,15 @@ // For portability reasons we do not include stddef.h, stdint.h or any other // system header, but we do need some basic types that are not defined // in a portable way by the language itself. -typedef unsigned long uptr; // Unsigned integer of the same size as a pointer. -// FIXME: add u64, u32, etc. +typedef unsigned long uptr; +typedef signed long sptr; +typedef unsigned char u8; +typedef unsigned short u16; +typedef unsigned int u32; +typedef unsigned long long u64; +typedef signed char s8; +typedef signed short s16; +typedef signed int s32; +typedef signed long long s64; #endif // SANITIZER_DEFS_H |