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

Side by Side Diff: runtime/szrt_asan.c

Issue 2145063003: Updates in preparation of wrapper script (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: minor fix to test Created 4 years, 5 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
« no previous file with comments | « pydir/utils.py ('k') | src/IceASanInstrumentation.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <assert.h> 18 #include <assert.h>
19 #include <errno.h> 19 #include <errno.h>
20 #include <limits.h> 20 #include <limits.h>
21 #include <stdbool.h> 21 #include <stdbool.h>
22 #include <stddef.h> 22 #include <stddef.h>
23 #include <stdint.h> 23 #include <stdint.h>
24 #include <stdio.h> 24 #include <stdio.h>
25 #include <stdlib.h> 25 #include <stdlib.h>
26 #include <string.h>
26 #include <sys/mman.h> 27 #include <sys/mman.h>
27 28
28 #define RZ_SIZE (32) 29 #define RZ_SIZE (32)
29 #define SHADOW_SCALE_LOG2 (3) 30 #define SHADOW_SCALE_LOG2 (3)
30 #define SHADOW_SCALE ((size_t)1 << SHADOW_SCALE_LOG2) 31 #define SHADOW_SCALE ((size_t)1 << SHADOW_SCALE_LOG2)
31 #define DEBUG (0) 32 #define DEBUG (0)
32 33
33 // Assuming 48 bit address space on 64 bit systems 34 // Assuming 48 bit address space on 64 bit systems
34 #define SHADOW_LENGTH_64 (1u << (48 - SHADOW_SCALE_LOG2)) 35 #define SHADOW_LENGTH_64 (1u << (48 - SHADOW_SCALE_LOG2))
35 #define SHADOW_LENGTH_32 (1u << (32 - SHADOW_SCALE_LOG2)) 36 #define SHADOW_LENGTH_32 (1u << (32 - SHADOW_SCALE_LOG2))
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 void *rz_right = ret + size; 147 void *rz_right = ret + size;
147 __asan_poison(rz_left, rz_left_size); 148 __asan_poison(rz_left, rz_left_size);
148 __asan_poison(rz_right, rz_right_size); 149 __asan_poison(rz_right, rz_right_size);
149 // record size and location data so we can find it again 150 // record size and location data so we can find it again
150 *(void **)rz_left = rz_right; 151 *(void **)rz_left = rz_right;
151 *(size_t *)rz_right = rz_right_size; 152 *(size_t *)rz_right = rz_right_size;
152 assert((uintptr_t)ret % 8 == 0); 153 assert((uintptr_t)ret % 8 == 0);
153 return ret; 154 return ret;
154 } 155 }
155 156
157 void *__asan_calloc(size_t nmemb, size_t size) {
158 size_t alloc_size = nmemb * size;
159 void *ret = __asan_malloc(alloc_size);
160 memset(ret, 0, alloc_size);
161 return ret;
162 }
163
156 void __asan_free(char *ptr) { 164 void __asan_free(char *ptr) {
157 DUMP("free() called on %p\n", ptr); 165 DUMP("free() called on %p\n", ptr);
158 void *rz_left = ptr - RZ_SIZE; 166 void *rz_left = ptr - RZ_SIZE;
159 void *rz_right = *(void **)rz_left; 167 void *rz_right = *(void **)rz_left;
160 size_t rz_right_size = *(size_t *)rz_right; 168 size_t rz_right_size = *(size_t *)rz_right;
161 __asan_unpoison(rz_left, RZ_SIZE); 169 __asan_unpoison(rz_left, RZ_SIZE);
162 __asan_unpoison(rz_right, rz_right_size); 170 __asan_unpoison(rz_right, rz_right_size);
163 free(rz_left); 171 free(rz_left);
164 } 172 }
165 173
(...skipping 19 matching lines...) Expand all
185 assert(size < 2 * RZ_SIZE); 193 assert(size < 2 * RZ_SIZE);
186 DUMP("unpoison %d bytes at %p: %p - %p\n", size, ptr, MEM2SHADOW(ptr), 194 DUMP("unpoison %d bytes at %p: %p - %p\n", size, ptr, MEM2SHADOW(ptr),
187 MEM2SHADOW(end)); 195 MEM2SHADOW(end));
188 *(char *)MEM2SHADOW(ptr) = 0; 196 *(char *)MEM2SHADOW(ptr) = 0;
189 ptr += SHADOW_OFFSET(size); 197 ptr += SHADOW_OFFSET(size);
190 assert(IS_SHADOW_ALIGNED(ptr)); 198 assert(IS_SHADOW_ALIGNED(ptr));
191 for (; ptr != end; ptr += SHADOW_SCALE) { 199 for (; ptr != end; ptr += SHADOW_SCALE) {
192 *(char *)MEM2SHADOW(ptr) = 0; 200 *(char *)MEM2SHADOW(ptr) = 0;
193 } 201 }
194 } 202 }
OLDNEW
« no previous file with comments | « pydir/utils.py ('k') | src/IceASanInstrumentation.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698