[llvm-commits] [ASan] Add a few more malloc-related interceptors for Windows (issue 5882055)

timurrrr at google.com timurrrr at google.com
Fri Mar 23 03:08:55 PDT 2012


Reviewers: glider,

Message:
Hi Alexander,

Can you please review this small patch?

Thanks!
Timur

Description:
[ASan] Add a few more malloc-related interceptors for Windows

Please review this at http://codereview.appspot.com/5882055/

Affected files:
   M lib/asan/asan_malloc_win.cc


Index: lib/asan/asan_malloc_win.cc
diff --git a/lib/asan/asan_malloc_win.cc b/lib/asan/asan_malloc_win.cc
index  
2235616106fa023d96df1371b167f999df5a997f..42ba8fe08e418e1f70632fd3fcdff3f2b8070839  
100644
--- a/lib/asan/asan_malloc_win.cc
+++ b/lib/asan/asan_malloc_win.cc
@@ -34,19 +34,34 @@ void free(void *ptr) {
    return asan_free(ptr, &stack);
  }

+void _free_dbg(void* ptr, int) {
+  free(ptr);
+}
+
+void cfree(void *ptr) {
+  CHECK(!"cfree() should not be used on Windows?");
+}
+
  void *malloc(size_t size) {
    GET_STACK_TRACE_HERE_FOR_MALLOC;
    return asan_malloc(size, &stack);
  }

+void* _malloc_dbg(size_t size, int , const char*, int) {
+  return malloc(size);
+}
+
  void *calloc(size_t nmemb, size_t size) {
    GET_STACK_TRACE_HERE_FOR_MALLOC;
    return asan_calloc(nmemb, size, &stack);
  }

+void* _calloc_dbg(size_t n, size_t size, int, const char*, int) {
+  return calloc(n, size);
+}
+
  void *_calloc_impl(size_t nmemb, size_t size, int *errno_tmp) {
-  GET_STACK_TRACE_HERE_FOR_MALLOC;
-  return asan_calloc(nmemb, size, &stack);
+  return calloc(nmemb, size);
  }

  void *realloc(void *ptr, size_t size) {
@@ -54,10 +69,38 @@ void *realloc(void *ptr, size_t size) {
    return asan_realloc(ptr, size, &stack);
  }

+void *_realloc_dbg(void *ptr, size_t size, int) {
+  CHECK(!"_realloc_dbg should not exist!");
+  return NULL;
+}
+
+void* _recalloc(void* p, size_t n, size_t elem_size) {
+  if (!p)
+    return calloc(n, elem_size);
+  const size_t size = n * elem_size;
+  if (elem_size != 0 && size / elem_size != n)
+    return NULL;
+  return realloc(p, size);
+}
+
  size_t _msize(void *ptr) {
    GET_STACK_TRACE_HERE_FOR_MALLOC;
    return asan_malloc_usable_size(ptr, &stack);
  }
+
+int _CrtDbgReport(int, const char*, int,
+                  const char*, const char*, ...) {
+  ShowStatsAndAbort();
+}
+
+int _CrtDbgReportW(int reportType, const wchar_t*, int,
+                   const wchar_t*, const wchar_t*, ...) {
+  ShowStatsAndAbort();
+}
+
+int _CrtSetReportMode(int, int) {
+  return 0;
+}
  }  // extern "C"

  using __interception::GetRealFunctionAddress;





More information about the llvm-commits mailing list