Index: runtime/szrt_asan.c |
diff --git a/runtime/szrt_asan.c b/runtime/szrt_asan.c |
index 47b6abc8c3a054e623cfbecb065c0cf5c08740a8..038ad089afdc192233a1c89315e5c0a143b4718b 100644 |
--- a/runtime/szrt_asan.c |
+++ b/runtime/szrt_asan.c |
@@ -15,26 +15,48 @@ |
/// |
//===----------------------------------------------------------------------===// |
+#include <stdbool.h> |
#include <stddef.h> |
#include <stdlib.h> |
+static unsigned behind_malloc = 0; |
+ |
// TODO(tlively): Define and implement this library |
void __asan_init(void) { |
- printf("Set up shadow memory here\n"); |
- return; |
+ if (behind_malloc) |
+ return; |
+ printf("set up shadow memory here\n"); |
} |
void __asan_check(void *addr, int size) { |
- printf("Check %d bytes at %p\n", size, addr); |
- return; |
+ if (behind_malloc) |
+ return; |
+ printf("check %d bytes at %p\n", size, addr); |
} |
void *__asan_malloc(size_t size) { |
- printf("malloc() called with size %d\n", size); |
- return malloc(size); |
+ if (!behind_malloc) |
Jim Stichnoth
2016/06/20 19:44:41
if (behind_malloc == 0)
It's clearer when implici
tlively
2016/06/20 22:19:33
Done.
|
+ printf("malloc() called with size %d\n", size); |
+ behind_malloc++; |
Jim Stichnoth
2016/06/20 19:44:40
Generally prefer pre-increment and pre-decrement o
tlively
2016/06/20 22:19:33
Done.
|
+ void *ret = malloc(size); |
+ behind_malloc--; |
+ return ret; |
} |
void __asan_free(void *ptr) { |
- printf("free() called on %p\n", ptr); |
+ if (!behind_malloc) |
+ printf("free() called on %p\n", ptr); |
+ behind_malloc++; |
free(ptr); |
+ behind_malloc--; |
+} |
+ |
+void __asan_alloca(void *ptr, int size) { |
+ if (!behind_malloc) |
+ printf("alloca of %d bytes at %p\n", size, ptr); |
+} |
+ |
+void __asan_unalloca(void *ptr, int size) { |
+ if (!behind_malloc) |
+ printf("unalloca of %d bytes as %p\n", size, ptr); |
} |