[llvm-commits] PATCH: AddressSanitizer: replace all "real_X" calls with "REAL(X)". (issue 5645054)
samsonov at google.com
samsonov at google.com
Wed Feb 8 02:39:50 PST 2012
Reviewers: ramosian.glider, kcc,
Description:
AddressSanitizer: replace all "real_X" calls with "REAL(X)".
Please review this at http://codereview.appspot.com/5645054/
Affected files:
M asan_allocator.cc
M asan_allocator.h
M asan_interceptors.cc
M asan_linux.cc
M asan_mac.cc
M asan_malloc_linux.cc
M asan_malloc_mac.cc
M asan_poisoning.cc
M asan_posix.cc
M asan_rtl.cc
M asan_stack.cc
M asan_stats.cc
-------------- next part --------------
Index: asan_stats.cc
===================================================================
--- asan_stats.cc (revision 150068)
+++ asan_stats.cc (working copy)
@@ -21,8 +21,8 @@
namespace __asan {
AsanStats::AsanStats() {
- CHECK(real_memset != NULL);
- real_memset(this, 0, sizeof(AsanStats));
+ CHECK(REAL(memset) != NULL);
+ REAL(memset)(this, 0, sizeof(AsanStats));
}
static void PrintMallocStatsArray(const char *prefix,
Index: asan_rtl.cc
===================================================================
--- asan_rtl.cc (revision 150068)
+++ asan_rtl.cc (working copy)
@@ -148,7 +148,7 @@
// where alloc_i looks like "offset size len ObjectName ".
CHECK(frame_descr);
// Report the function name and the offset.
- const char *name_end = real_strchr(frame_descr, ' ');
+ const char *name_end = REAL(strchr)(frame_descr, ' ');
CHECK(name_end);
buf[0] = 0;
internal_strncat(buf, frame_descr,
Index: asan_posix.cc
===================================================================
--- asan_posix.cc (revision 150068)
+++ asan_posix.cc (working copy)
@@ -35,10 +35,10 @@
if (!AsanInterceptsSignal(signum))
return;
struct sigaction sigact;
- real_memset(&sigact, 0, sizeof(sigact));
+ REAL(memset)(&sigact, 0, sizeof(sigact));
sigact.sa_sigaction = handler;
sigact.sa_flags = SA_SIGINFO;
- CHECK(0 == real_sigaction(signum, &sigact, 0));
+ CHECK(0 == REAL(sigaction)(signum, &sigact, 0));
}
static void ASAN_OnSIGSEGV(int, siginfo_t *siginfo, void *context) {
Index: asan_poisoning.cc
===================================================================
--- asan_poisoning.cc (revision 150068)
+++ asan_poisoning.cc (working copy)
@@ -24,8 +24,8 @@
CHECK(AddrIsAlignedByGranularity(addr + size));
uintptr_t shadow_beg = MemToShadow(addr);
uintptr_t shadow_end = MemToShadow(addr + size);
- CHECK(real_memset != NULL);
- real_memset((void*)shadow_beg, value, shadow_end - shadow_beg);
+ CHECK(REAL(memset) != NULL);
+ REAL(memset)((void*)shadow_beg, value, shadow_end - shadow_beg);
}
void PoisonShadowPartialRightRedzone(uintptr_t addr,
@@ -108,7 +108,7 @@
}
beg.chunk++;
}
- real_memset(beg.chunk, kAsanUserPoisonedMemoryMagic, end.chunk - beg.chunk);
+ REAL(memset)(beg.chunk, kAsanUserPoisonedMemoryMagic, end.chunk - beg.chunk);
// Poison if byte in end.offset is unaddressable.
if (end.value > 0 && end.value <= end.offset) {
*end.chunk = kAsanUserPoisonedMemoryMagic;
@@ -140,7 +140,7 @@
*beg.chunk = 0;
beg.chunk++;
}
- real_memset(beg.chunk, 0, end.chunk - beg.chunk);
+ REAL(memset)(beg.chunk, 0, end.chunk - beg.chunk);
if (end.offset > 0 && end.value != 0) {
*end.chunk = Max(end.value, end.offset);
}
Index: asan_interceptors.cc
===================================================================
--- asan_interceptors.cc (revision 150068)
+++ asan_interceptors.cc (working copy)
@@ -159,8 +159,8 @@
size_t internal_strnlen(const char *s, size_t maxlen) {
#ifndef __APPLE__
- if (real_strnlen != NULL) {
- return real_strnlen(s, maxlen);
+ if (REAL(strnlen) != NULL) {
+ return REAL(strnlen)(s, maxlen);
}
#endif
size_t i = 0;
@@ -264,12 +264,12 @@
int current_tid = asanThreadRegistry().GetCurrentTidOrMinusOne();
AsanThread *t = AsanThread::Create(current_tid, start_routine, arg, &stack);
asanThreadRegistry().RegisterThread(t);
- return real_pthread_create(thread, attr, asan_thread_start, t);
+ return REAL(pthread_create)(thread, attr, asan_thread_start, t);
}
INTERCEPTOR(void*, signal, int signum, void *handler) {
if (!AsanInterceptsSignal(signum)) {
- return real_signal(signum, handler);
+ return REAL(signal)(signum, handler);
}
return NULL;
}
@@ -277,7 +277,7 @@
INTERCEPTOR(int, sigaction, int signum, const struct sigaction *act,
struct sigaction *oldact) {
if (!AsanInterceptsSignal(signum)) {
- return real_sigaction(signum, act, oldact);
+ return REAL(sigaction)(signum, act, oldact);
}
return 0;
}
@@ -295,17 +295,17 @@
INTERCEPTOR(void, longjmp, void *env, int val) {
UnpoisonStackFromHereToTop();
- real_longjmp(env, val);
+ REAL(longjmp)(env, val);
}
INTERCEPTOR(void, _longjmp, void *env, int val) {
UnpoisonStackFromHereToTop();
- real__longjmp(env, val);
+ REAL(_longjmp)(env, val);
}
INTERCEPTOR(void, siglongjmp, void *env, int val) {
UnpoisonStackFromHereToTop();
- real_siglongjmp(env, val);
+ REAL(siglongjmp)(env, val);
}
#if ASAN_HAS_EXCEPTIONS == 1
@@ -314,9 +314,9 @@
#endif // __APPLE__
INTERCEPTOR(void, __cxa_throw, void *a, void *b, void *c) {
- CHECK(&real___cxa_throw);
+ CHECK(REAL(__cxa_throw));
UnpoisonStackFromHereToTop();
- real___cxa_throw(a, b, c);
+ REAL(__cxa_throw)(a, b, c);
}
#endif
@@ -386,7 +386,7 @@
// memcpy is called during __asan_init() from the internals
// of printf(...).
if (asan_init_is_running) {
- return real_memcpy(to, from, size);
+ return REAL(memcpy)(to, from, size);
}
ENSURE_ASAN_INITED();
if (FLAG_replace_intrin) {
@@ -398,7 +398,7 @@
ASAN_WRITE_RANGE(from, size);
ASAN_READ_RANGE(to, size);
}
- return real_memcpy(to, from, size);
+ return REAL(memcpy)(to, from, size);
}
INTERCEPTOR(void*, memmove, void *to, const void *from, size_t size) {
@@ -407,26 +407,26 @@
ASAN_WRITE_RANGE(from, size);
ASAN_READ_RANGE(to, size);
}
- return real_memmove(to, from, size);
+ return REAL(memmove)(to, from, size);
}
INTERCEPTOR(void*, memset, void *block, int c, size_t size) {
// memset is called inside INTERCEPT_FUNCTION on Mac.
if (asan_init_is_running) {
- return real_memset(block, c, size);
+ return REAL(memset)(block, c, size);
}
ENSURE_ASAN_INITED();
if (FLAG_replace_intrin) {
ASAN_WRITE_RANGE(block, size);
}
- return real_memset(block, c, size);
+ return REAL(memset)(block, c, size);
}
INTERCEPTOR(char*, strchr, const char *str, int c) {
ENSURE_ASAN_INITED();
- char *result = real_strchr(str, c);
+ char *result = REAL(strchr)(str, c);
if (FLAG_replace_str) {
- size_t bytes_read = (result ? result - str : real_strlen(str)) + 1;
+ size_t bytes_read = (result ? result - str : REAL(strlen)(str)) + 1;
ASAN_READ_RANGE(str, bytes_read);
}
return result;
@@ -456,16 +456,16 @@
INTERCEPTOR(char*, strcat, char *to, const char *from) { // NOLINT
ENSURE_ASAN_INITED();
if (FLAG_replace_str) {
- size_t from_length = real_strlen(from);
+ size_t from_length = REAL(strlen)(from);
ASAN_READ_RANGE(from, from_length + 1);
if (from_length > 0) {
- size_t to_length = real_strlen(to);
+ size_t 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);
}
}
- return real_strcat(to, from);
+ return REAL(strcat)(to, from); // NOLINT
}
INTERCEPTOR(int, strcmp, const char *s1, const char *s2) {
@@ -488,35 +488,35 @@
// strcpy is called from malloc_default_purgeable_zone()
// in __asan::ReplaceSystemAlloc() on Mac.
if (asan_init_is_running) {
- return real_strcpy(to, from);
+ return REAL(strcpy)(to, from); // NOLINT
}
ENSURE_ASAN_INITED();
if (FLAG_replace_str) {
- size_t from_size = real_strlen(from) + 1;
+ size_t 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);
}
- return real_strcpy(to, from);
+ return REAL(strcpy)(to, from); // NOLINT
}
INTERCEPTOR(char*, strdup, const char *s) {
ENSURE_ASAN_INITED();
if (FLAG_replace_str) {
- size_t length = real_strlen(s);
+ size_t length = REAL(strlen)(s);
ASAN_READ_RANGE(s, length + 1);
}
- return real_strdup(s);
+ return REAL(strdup)(s);
}
INTERCEPTOR(size_t, 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);
+ return REAL(strlen)(s);
}
ENSURE_ASAN_INITED();
- size_t length = real_strlen(s);
+ size_t length = REAL(strlen)(s);
if (FLAG_replace_str) {
ASAN_READ_RANGE(s, length + 1);
}
@@ -541,7 +541,7 @@
// strncmp is called from malloc_default_purgeable_zone()
// in __asan::ReplaceSystemAlloc() on Mac.
if (asan_init_is_running) {
- return real_strncmp(s1, s2, size);
+ return REAL(strncmp)(s1, s2, size);
}
unsigned char c1 = 0, c2 = 0;
size_t i;
@@ -563,13 +563,13 @@
ASAN_READ_RANGE(from, from_size);
ASAN_WRITE_RANGE(to, size);
}
- return real_strncpy(to, from, size);
+ return REAL(strncpy)(to, from, size);
}
#ifndef __APPLE__
INTERCEPTOR(size_t, strnlen, const char *s, size_t maxlen) {
ENSURE_ASAN_INITED();
- size_t length = real_strnlen(s, maxlen);
+ size_t length = REAL(strnlen)(s, maxlen);
if (FLAG_replace_str) {
ASAN_READ_RANGE(s, Min(length + 1, maxlen));
}
@@ -596,7 +596,7 @@
if (GetMacosVersion() == MACOS_VERSION_SNOW_LEOPARD) {
INTERCEPT_FUNCTION(memcpy);
} else {
- real_memcpy = real_memmove;
+ REAL(memcpy) = REAL(memmove);
}
#else
// Always wrap memcpy() on non-Darwin platforms.
Index: asan_allocator.h
===================================================================
--- asan_allocator.h (revision 150068)
+++ asan_allocator.h (working copy)
@@ -45,8 +45,8 @@
explicit AsanThreadLocalMallocStorage(LinkerInitialized x)
: quarantine_(x) { }
AsanThreadLocalMallocStorage() {
- CHECK(real_memset);
- real_memset(this, 0, sizeof(AsanThreadLocalMallocStorage));
+ CHECK(REAL(memset));
+ REAL(memset)(this, 0, sizeof(AsanThreadLocalMallocStorage));
}
AsanChunkFifoList quarantine_;
Index: asan_linux.cc
===================================================================
--- asan_linux.cc (revision 150068)
+++ asan_linux.cc (working copy)
@@ -241,7 +241,7 @@
data->filename[path_len] = 0;
} else {
CHECK(info->dlpi_name);
- real_strncpy(data->filename, info->dlpi_name, data->filename_size);
+ REAL(strncpy)(data->filename, info->dlpi_name, data->filename_size);
}
data->offset = data->addr - info->dlpi_addr;
return 1;
Index: asan_mac.cc
===================================================================
--- asan_mac.cc (revision 150068)
+++ asan_mac.cc (working copy)
@@ -209,8 +209,8 @@
if (end) *end = sc->vmaddr + sc->vmsize + dlloff;
if (offset) *offset = sc->fileoff;
if (filename) {
- real_strncpy(filename, _dyld_get_image_name(current_image_),
- filename_size);
+ REAL(strncpy)(filename, _dyld_get_image_name(current_image_),
+ filename_size);
}
if (FLAG_v >= 4)
Report("LC_SEGMENT: %p--%p %s+%p\n", *start, *end, filename, *offset);
@@ -432,8 +432,8 @@
asan_ctxt, pthread_self());
PRINT_CURRENT_STACK();
}
- return real_dispatch_async_f(dq, (void*)asan_ctxt,
- asan_dispatch_call_block_and_release);
+ return REAL(dispatch_async_f)(dq, (void*)asan_ctxt,
+ asan_dispatch_call_block_and_release);
}
INTERCEPTOR(void, dispatch_sync_f, dispatch_queue_t dq, void *ctxt,
@@ -445,8 +445,8 @@
asan_ctxt, pthread_self());
PRINT_CURRENT_STACK();
}
- return real_dispatch_sync_f(dq, (void*)asan_ctxt,
- asan_dispatch_call_block_and_release);
+ return REAL(dispatch_sync_f)(dq, (void*)asan_ctxt,
+ asan_dispatch_call_block_and_release);
}
INTERCEPTOR(void, dispatch_after_f, dispatch_time_t when,
@@ -458,8 +458,8 @@
Report("dispatch_after_f: %p\n", asan_ctxt);
PRINT_CURRENT_STACK();
}
- return real_dispatch_after_f(when, dq, (void*)asan_ctxt,
- asan_dispatch_call_block_and_release);
+ return REAL(dispatch_after_f)(when, dq, (void*)asan_ctxt,
+ asan_dispatch_call_block_and_release);
}
INTERCEPTOR(void, dispatch_barrier_async_f, dispatch_queue_t dq, void *ctxt,
@@ -471,8 +471,8 @@
asan_ctxt, pthread_self());
PRINT_CURRENT_STACK();
}
- real_dispatch_barrier_async_f(dq, (void*)asan_ctxt,
- asan_dispatch_call_block_and_release);
+ REAL(dispatch_barrier_async_f)(dq, (void*)asan_ctxt,
+ asan_dispatch_call_block_and_release);
}
INTERCEPTOR(void, dispatch_group_async_f, dispatch_group_t group,
@@ -485,8 +485,8 @@
asan_ctxt, pthread_self());
PRINT_CURRENT_STACK();
}
- real_dispatch_group_async_f(group, dq, (void*)asan_ctxt,
- asan_dispatch_call_block_and_release);
+ REAL(dispatch_group_async_f)(group, dq, (void*)asan_ctxt,
+ asan_dispatch_call_block_and_release);
}
// The following stuff has been extremely helpful while looking for the
@@ -521,8 +521,9 @@
Report("pthread_workqueue_additem_np: %p\n", asan_ctxt);
PRINT_CURRENT_STACK();
}
- return real_pthread_workqueue_additem_np(workq, wrap_workitem_func, asan_ctxt,
- itemhandlep, gencountp);
+ return REAL(pthread_workqueue_additem_np)(workq, wrap_workitem_func,
+ asan_ctxt, itemhandlep,
+ gencountp);
}
// CF_RC_BITS, the layout of CFRuntimeBase and __CFStrIsConstant are internal
@@ -562,7 +563,7 @@
if (__CFStrIsConstant(str)) {
return str;
} else {
- return real_CFStringCreateCopy(alloc, str);
+ return REAL(CFStringCreateCopy)(alloc, str);
}
}
Index: asan_stack.cc
===================================================================
--- asan_stack.cc (revision 150068)
+++ asan_stack.cc (working copy)
@@ -140,8 +140,8 @@
// |res| may be greater than check_stack.size, because
// 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(0 == REAL(memcmp)(check_stack.trace, stack->trace,
+ check_stack.size * sizeof(uintptr_t)));
#endif
return res;
Index: asan_allocator.cc
===================================================================
--- asan_allocator.cc (revision 150068)
+++ asan_allocator.cc (working copy)
@@ -668,7 +668,7 @@
size & (REDZONE - 1));
}
if (size <= FLAG_max_malloc_fill_size) {
- real_memset((void*)addr, 0, rounded_size);
+ REAL(memset)((void*)addr, 0, rounded_size);
}
return (uint8_t*)addr;
}
@@ -740,8 +740,8 @@
size_t memcpy_size = Min(new_size, old_size);
uint8_t *new_ptr = Allocate(0, new_size, stack);
if (new_ptr) {
- CHECK(real_memcpy != NULL);
- real_memcpy(new_ptr, old_ptr, memcpy_size);
+ CHECK(REAL(memcpy) != NULL);
+ REAL(memcpy)(new_ptr, old_ptr, memcpy_size);
Deallocate(old_ptr, stack);
}
return new_ptr;
@@ -791,7 +791,7 @@
void *asan_calloc(size_t nmemb, size_t size, AsanStackTrace *stack) {
void *ptr = (void*)Allocate(0, nmemb * size, stack);
if (ptr)
- real_memset(ptr, 0, nmemb * size);
+ REAL(memset)(ptr, 0, nmemb * size);
ASAN_NEW_HOOK(ptr, nmemb * size);
return ptr;
}
@@ -867,8 +867,8 @@
// ---------------------- Fake stack-------------------- {{{1
FakeStack::FakeStack() {
- CHECK(real_memset != NULL);
- real_memset(this, 0, sizeof(*this));
+ CHECK(REAL(memset) != NULL);
+ REAL(memset)(this, 0, sizeof(*this));
}
bool FakeStack::AddrIsInSizeClass(uintptr_t addr, size_t size_class) {
Index: asan_malloc_linux.cc
===================================================================
--- asan_malloc_linux.cc (revision 150068)
+++ asan_malloc_linux.cc (working copy)
@@ -71,7 +71,7 @@
INTERCEPTOR(void*, calloc, size_t nmemb, size_t size) {
if (!asan_inited) {
- // Hack: dlsym calls calloc before real_calloc is retrieved from dlsym.
+ // 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 size_t allocated;
@@ -105,7 +105,7 @@
INTERCEPTOR(struct mallinfo, mallinfo) {
struct mallinfo res;
- real_memset(&res, 0, sizeof(res));
+ REAL(memset)(&res, 0, sizeof(res));
return res;
}
Index: asan_malloc_mac.cc
===================================================================
--- asan_malloc_mac.cc (revision 150068)
+++ asan_malloc_mac.cc (working copy)
@@ -92,7 +92,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.
+ // 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 size_t allocated;
@@ -310,7 +310,7 @@
namespace __asan {
void ReplaceSystemMalloc() {
static malloc_introspection_t asan_introspection;
- __asan::real_memset(&asan_introspection, 0, sizeof(asan_introspection));
+ __asan::REAL(memset)(&asan_introspection, 0, sizeof(asan_introspection));
asan_introspection.enumerator = &mi_enumerator;
asan_introspection.good_size = &mi_good_size;
@@ -321,7 +321,7 @@
asan_introspection.force_unlock = &mi_force_unlock;
static malloc_zone_t asan_zone;
- __asan::real_memset(&asan_zone, 0, sizeof(malloc_zone_t));
+ __asan::REAL(memset)(&asan_zone, 0, sizeof(malloc_zone_t));
// Start with a version 4 zone which is used for OS X 10.4 and 10.5.
asan_zone.version = 4;
More information about the llvm-commits
mailing list