Introduce the check_malloc_usable_size flag (on by default).
authorAlexander Potapenko <glider@google.com>
Fri, 25 May 2012 15:20:13 +0000 (15:20 +0000)
committerAlexander Potapenko <glider@google.com>
Fri, 25 May 2012 15:20:13 +0000 (15:20 +0000)
When the flag is set to zero, we do not check for errors in malloc_usable_size.
This may be useful to work around a bug in Nvidia drivers prior to 295.*

llvm-svn: 157472

compiler-rt/lib/asan/asan_allocator.cc
compiler-rt/lib/asan/asan_internal.h
compiler-rt/lib/asan/asan_rtl.cc

index 2c31c85..05e2119 100644 (file)
@@ -865,7 +865,7 @@ size_t 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 (usable_size == 0) {
+  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();
index 4478cdf..1d32da7 100644 (file)
@@ -259,6 +259,7 @@ extern bool   FLAG_allow_user_poisoning;
 extern int    FLAG_sleep_before_dying;
 extern bool   FLAG_handle_segv;
 extern bool   FLAG_use_sigaltstack;
+extern bool   FLAG_check_malloc_usable_size;
 
 extern int asan_inited;
 // Used to avoid infinite recursion in __asan_init().
index c02556b..f883d31 100644 (file)
@@ -51,6 +51,7 @@ bool   FLAG_allow_user_poisoning;
 int    FLAG_sleep_before_dying;
 bool   FLAG_unmap_shadow_on_exit;
 bool   FLAG_disable_core;
+bool   FLAG_check_malloc_usable_size;
 
 // -------------------------- Globals --------------------- {{{1
 int asan_inited;
@@ -469,6 +470,10 @@ void __asan_init() {
   // it makes little sense to dump 16T+ core.
   FLAG_disable_core = IntFlagValue(options, "disable_core=", __WORDSIZE == 64);
 
+  // Allow the users to work around the bug in Nvidia drivers prior to 295.*.
+  FLAG_check_malloc_usable_size =
+      IntFlagValue(options, "check_malloc_usable_size=", 1);
+
   FLAG_quarantine_size = IntFlagValue(options, "quarantine_size=",
       (ASAN_LOW_MEMORY) ? 1UL << 24 : 1UL << 28);