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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 //===- subzero/runtime/szrt_asan.c - AddressSanitizer Runtime -----*- C -*-===// 1 //===- subzero/runtime/szrt_asan.c - AddressSanitizer Runtime -----*- C -*-===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 /// 9 ///
10 /// \file 10 /// \file
11 /// \brief Provides the AddressSanitizer runtime. 11 /// \brief Provides the AddressSanitizer runtime.
12 /// 12 ///
13 /// Exposes functions for initializing the shadow memory region and managing it 13 /// Exposes functions for initializing the shadow memory region and managing it
14 /// on loads, stores, and allocations. 14 /// on loads, stores, and allocations.
15 /// 15 ///
16 //===----------------------------------------------------------------------===// 16 //===----------------------------------------------------------------------===//
17 17
18 #include <stdbool.h>
18 #include <stddef.h> 19 #include <stddef.h>
19 #include <stdlib.h> 20 #include <stdlib.h>
20 21
22 static unsigned behind_malloc = 0;
23
21 // TODO(tlively): Define and implement this library 24 // TODO(tlively): Define and implement this library
22 void __asan_init(void) { 25 void __asan_init(void) {
23 printf("Set up shadow memory here\n"); 26 if (behind_malloc)
24 return; 27 return;
28 printf("set up shadow memory here\n");
25 } 29 }
26 30
27 void __asan_check(void *addr, int size) { 31 void __asan_check(void *addr, int size) {
28 printf("Check %d bytes at %p\n", size, addr); 32 if (behind_malloc)
29 return; 33 return;
34 printf("check %d bytes at %p\n", size, addr);
30 } 35 }
31 36
32 void *__asan_malloc(size_t size) { 37 void *__asan_malloc(size_t size) {
33 printf("malloc() called with size %d\n", size); 38 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.
34 return malloc(size); 39 printf("malloc() called with size %d\n", size);
40 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.
41 void *ret = malloc(size);
42 behind_malloc--;
43 return ret;
35 } 44 }
36 45
37 void __asan_free(void *ptr) { 46 void __asan_free(void *ptr) {
38 printf("free() called on %p\n", ptr); 47 if (!behind_malloc)
48 printf("free() called on %p\n", ptr);
49 behind_malloc++;
39 free(ptr); 50 free(ptr);
51 behind_malloc--;
40 } 52 }
53
54 void __asan_alloca(void *ptr, int size) {
55 if (!behind_malloc)
56 printf("alloca of %d bytes at %p\n", size, ptr);
57 }
58
59 void __asan_unalloca(void *ptr, int size) {
60 if (!behind_malloc)
61 printf("unalloca of %d bytes as %p\n", size, ptr);
62 }
OLDNEW
« 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