Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(436)

Unified Diff: runtime/szrt_asan.c

Issue 2086593002: Inserted local redzones. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Fixes Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/szrt_asan.c
diff --git a/runtime/szrt_asan.c b/runtime/szrt_asan.c
index 47b6abc8c3a054e623cfbecb065c0cf5c08740a8..9f62e28ef474015e8843a38cea631e0f364396ac 100644
--- a/runtime/szrt_asan.c
+++ b/runtime/szrt_asan.c
@@ -15,26 +15,49 @@
///
//===----------------------------------------------------------------------===//
+#include <assert.h>
#include <stddef.h>
+#include <stdio.h>
#include <stdlib.h>
+static __thread int 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 == 0)
+ 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 == 0)
+ 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 == 0)
+ printf("malloc() called with size %d\n", size);
+ ++behind_malloc;
+ void *ret = malloc(size);
+ --behind_malloc;
+ assert(behind_malloc >= 0);
+ return ret;
}
void __asan_free(void *ptr) {
- printf("free() called on %p\n", ptr);
+ if (behind_malloc == 0)
+ printf("free() called on %p\n", ptr);
+ ++behind_malloc;
free(ptr);
+ --behind_malloc;
+ assert(behind_malloc >= 0);
+}
+
+void __asan_alloca(void *ptr, int size) {
+ if (behind_malloc == 0)
+ printf("alloca of %d bytes at %p\n", size, ptr);
+}
+
+void __asan_unalloca(void *ptr, int size) {
+ if (behind_malloc == 0)
+ printf("unalloca of %d bytes as %p\n", size, ptr);
}
« no previous file with comments | « docs/ASAN.rst ('k') | src/IceASanInstrumentation.h » ('j') | src/IceASanInstrumentation.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698