Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(120)

Side by Side Diff: lib/asan/asan_internal.h

Issue 5630065: Implement the GET_CALLER_PC macro, stub the GET_CURRENT_FRAME macro (Closed)
Patch Set: Created 2 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===-- asan_internal.h -----------------------------------------*- C++ -*-===// 1 //===-- asan_internal.h -----------------------------------------*- C++ -*-===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // The LLVM Compiler Infrastructure
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 // This file is a part of AddressSanitizer, an address sanity checker. 10 // This file is a part of AddressSanitizer, an address sanity checker.
11 // 11 //
12 // ASan-private header which defines various general utilities. 12 // ASan-private header which defines various general utilities.
13 //===----------------------------------------------------------------------===// 13 //===----------------------------------------------------------------------===//
14 #ifndef ASAN_INTERNAL_H 14 #ifndef ASAN_INTERNAL_H
15 #define ASAN_INTERNAL_H 15 #define ASAN_INTERNAL_H
16 16
17 #if !defined(__linux__) && !defined(__APPLE__) && !defined(_WIN32) 17 #if !defined(__linux__) && !defined(__APPLE__) && !defined(_WIN32)
18 # error "This operating system is not supported by AddressSanitizer" 18 # error "This operating system is not supported by AddressSanitizer"
19 #endif 19 #endif
20 20
21 #include <stdlib.h> // for size_t, uintptr_t, etc. 21 #include <stdlib.h> // for size_t, uintptr_t, etc.
22 22
23 #if defined(_WIN32) 23 #if defined(_WIN32)
24 # include <intrin.h>
kcc 2012/02/06 19:18:31 Can we avoid this include in the header? ( I am n
timurrrr_at_google_com 2012/02/07 12:51:08 I doubt so. Or we'll need to #include it in every
25
24 // There's no <stdint.h> in Visual Studio 9, so we have to define [u]int*_t. 26 // There's no <stdint.h> in Visual Studio 9, so we have to define [u]int*_t.
25 typedef unsigned __int8 uint8_t; 27 typedef unsigned __int8 uint8_t;
26 typedef unsigned __int16 uint16_t; 28 typedef unsigned __int16 uint16_t;
27 typedef unsigned __int32 uint32_t; 29 typedef unsigned __int32 uint32_t;
28 typedef unsigned __int64 uint64_t; 30 typedef unsigned __int64 uint64_t;
29 typedef __int8 int8_t; 31 typedef __int8 int8_t;
30 typedef __int16 int16_t; 32 typedef __int16 int16_t;
31 typedef __int32 int32_t; 33 typedef __int32 int32_t;
32 typedef __int64 int64_t; 34 typedef __int64 int64_t;
33 35
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 #define UNIMPLEMENTED() CHECK("unimplemented" && 0) 207 #define UNIMPLEMENTED() CHECK("unimplemented" && 0)
206 208
207 #define ASAN_ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0])) 209 #define ASAN_ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
208 210
209 const size_t kWordSize = __WORDSIZE / 8; 211 const size_t kWordSize = __WORDSIZE / 8;
210 const size_t kWordSizeInBits = 8 * kWordSize; 212 const size_t kWordSizeInBits = 8 * kWordSize;
211 const size_t kPageSizeBits = 12; 213 const size_t kPageSizeBits = 12;
212 const size_t kPageSize = 1UL << kPageSizeBits; 214 const size_t kPageSize = 1UL << kPageSizeBits;
213 215
214 #ifndef _WIN32 216 #ifndef _WIN32
215 #define GET_CALLER_PC() (uintptr_t)__builtin_return_address(0) 217 # define GET_CALLER_PC() \
216 #define GET_CURRENT_FRAME() (uintptr_t)__builtin_frame_address(0) 218 (uintptr_t)__builtin_extract_return_address(__builtin_return_address(0))
timurrrr_at_google_com 2012/02/06 13:49:02 Looks like the __builtin_return_address macro was
glider 2012/02/06 14:16:45 This seems to be ok on x86 and ARM.
kcc 2012/02/06 19:18:31 I'd keep this as as, it works.
timurrrr_at_google_com 2012/02/07 12:51:08 The other one works too, but up to you (reverted)
219 # define GET_CURRENT_FRAME() (uintptr_t)__builtin_frame_address(0)
217 #else 220 #else
218 // TODO(timurrrr): implement. 221 # define GET_CALLER_PC() (uintptr_t)_ReturnAddress()
219 #define GET_CALLER_PC() (uintptr_t)0 222 // TODO(timurrrr): We don't unwind on Windows - do we need this?
kcc 2012/02/06 19:18:31 What do you mean "we don't unwind"? Also, better u
timurrrr_at_google_com 2012/02/07 12:51:08 Done.
220 #define GET_CURRENT_FRAME() (uintptr_t)0 223 # define GET_CURRENT_FRAME() (uintptr_t)0xDEADBEEF
221 #endif 224 #endif
222 225
223 #define GET_BP_PC_SP \ 226 #define GET_BP_PC_SP \
224 uintptr_t bp = GET_CURRENT_FRAME(); \ 227 uintptr_t bp = GET_CURRENT_FRAME(); \
225 uintptr_t pc = GET_CALLER_PC(); \ 228 uintptr_t pc = GET_CALLER_PC(); \
226 uintptr_t local_stack; \ 229 uintptr_t local_stack; \
227 uintptr_t sp = (uintptr_t)&local_stack; 230 uintptr_t sp = (uintptr_t)&local_stack;
228 231
229 // These magic values are written to shadow for better error reporting. 232 // These magic values are written to shadow for better error reporting.
230 const int kAsanHeapLeftRedzoneMagic = 0xfa; 233 const int kAsanHeapLeftRedzoneMagic = 0xfa;
(...skipping 30 matching lines...) Expand all
261 // Requires an external lock. 264 // Requires an external lock.
262 void *Allocate(size_t size); 265 void *Allocate(size_t size);
263 private: 266 private:
264 char *allocated_end_; 267 char *allocated_end_;
265 char *allocated_current_; 268 char *allocated_current_;
266 }; 269 };
267 270
268 } // namespace __asan 271 } // namespace __asan
269 272
270 #endif // ASAN_INTERNAL_H 273 #endif // ASAN_INTERNAL_H
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld 1278:e6ce13d99bf5