[llvm-commits] [compiler-rt] r149875 - /compiler-rt/trunk/lib/asan/asan_malloc_win.cc
Kostya Serebryany
kcc at google.com
Mon Feb 6 09:56:38 PST 2012
Author: kcc
Date: Mon Feb 6 11:56:38 2012
New Revision: 149875
URL: http://llvm.org/viewvc/llvm-project?rev=149875&view=rev
Log:
[asan] The first version of Windows malloc interceptors, patch by timurrrr at google.com
Added:
compiler-rt/trunk/lib/asan/asan_malloc_win.cc
Added: compiler-rt/trunk/lib/asan/asan_malloc_win.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_malloc_win.cc?rev=149875&view=auto
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_malloc_win.cc (added)
+++ compiler-rt/trunk/lib/asan/asan_malloc_win.cc Mon Feb 6 11:56:38 2012
@@ -0,0 +1,57 @@
+//===-- asan_malloc_win.cc --------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is a part of AddressSanitizer, an address sanity checker.
+//
+// Windows-specific malloc interception.
+//===----------------------------------------------------------------------===//
+#ifdef _WIN32
+
+#include "asan_allocator.h"
+#include "asan_interceptors.h"
+#include "asan_internal.h"
+#include "asan_stack.h"
+
+namespace __asan {
+void ReplaceSystemMalloc() {
+ // FIXME: investigate whether any action is needed.
+}
+} // namespace __asan
+
+// ---------------------- Replacement functions ---------------- {{{1
+using namespace __asan; // NOLINT
+
+// FIXME: Simply defining functions with the same signature in *.obj
+// files overrides the standard functions in *.lib
+// This works well for simple helloworld-like tests but might need to be
+// revisited in the future.
+
+extern "C" {
+void free(void *ptr) {
+ GET_STACK_TRACE_HERE_FOR_FREE(ptr);
+ return asan_free(ptr, &stack);
+}
+
+void *malloc(size_t size) {
+ GET_STACK_TRACE_HERE_FOR_MALLOC;
+ return asan_malloc(size, &stack);
+}
+
+void *calloc(size_t nmemb, size_t size) {
+ GET_STACK_TRACE_HERE_FOR_MALLOC;
+ return asan_calloc(nmemb, size, &stack);
+}
+
+void *realloc(void *ptr, size_t size) {
+ GET_STACK_TRACE_HERE_FOR_MALLOC;
+ return asan_realloc(ptr, size, &stack);
+}
+} // extern "C"
+
+#endif // _WIN32
More information about the llvm-commits
mailing list