forked from OSchip/llvm-project
[ASan] Added __cplusplus guard around the C++ code so it is safe to include asan_mapping.h in assembly files.
This will avoid addind asan_shadow_defines.h in D114558. Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D115348
This commit is contained in:
parent
287fa2e164
commit
00616123f8
|
@ -13,8 +13,6 @@
|
|||
#ifndef ASAN_MAPPING_H
|
||||
#define ASAN_MAPPING_H
|
||||
|
||||
#include "asan_internal.h"
|
||||
|
||||
// The full explanation of the memory mapping could be found here:
|
||||
// https://github.com/google/sanitizers/wiki/AddressSanitizerAlgorithm
|
||||
//
|
||||
|
@ -153,8 +151,6 @@
|
|||
|
||||
#define ASAN_SHADOW_SCALE 3
|
||||
|
||||
static const u64 kDefaultShadowSentinel = ~(uptr)0;
|
||||
|
||||
#if SANITIZER_FUCHSIA
|
||||
# define ASAN_SHADOW_OFFSET_CONST (0)
|
||||
#elif SANITIZER_WORDSIZE == 32
|
||||
|
@ -199,91 +195,99 @@ static const u64 kDefaultShadowSentinel = ~(uptr)0;
|
|||
# elif SANITIZER_WINDOWS64
|
||||
# define ASAN_SHADOW_OFFSET_DYNAMIC
|
||||
# else
|
||||
# define ASAN_SHADOW_OFFSET_CONST \
|
||||
0x000000007FFFFFFF & (~0xFFFULL << ASAN_SHADOW_SCALE)
|
||||
# if ASAN_SHADOW_SCALE != 3
|
||||
# error "Value below is based on shadow scale = 3."
|
||||
# error "Original formula was: 0x7FFFFFFF & (~0xFFFULL << SHADOW_SCALE)."
|
||||
# endif
|
||||
# define ASAN_SHADOW_OFFSET_CONST 0x000000007fff8000
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(ASAN_SHADOW_OFFSET_CONST)
|
||||
#if defined(__cplusplus)
|
||||
# include "asan_internal.h"
|
||||
|
||||
static const u64 kDefaultShadowSentinel = ~(uptr)0;
|
||||
|
||||
# if defined(ASAN_SHADOW_OFFSET_CONST)
|
||||
static const u64 kConstShadowOffset = ASAN_SHADOW_OFFSET_CONST;
|
||||
# define ASAN_SHADOW_OFFSET kConstShadowOffset
|
||||
#elif defined(ASAN_SHADOW_OFFSET_DYNAMIC)
|
||||
# define ASAN_SHADOW_OFFSET __asan_shadow_memory_dynamic_address
|
||||
#else
|
||||
# error "ASAN_SHADOW_OFFSET can't be determined."
|
||||
#endif
|
||||
# define ASAN_SHADOW_OFFSET kConstShadowOffset
|
||||
# elif defined(ASAN_SHADOW_OFFSET_DYNAMIC)
|
||||
# define ASAN_SHADOW_OFFSET __asan_shadow_memory_dynamic_address
|
||||
# else
|
||||
# error "ASAN_SHADOW_OFFSET can't be determined."
|
||||
# endif
|
||||
|
||||
#if SANITIZER_ANDROID && defined(__arm__)
|
||||
# define ASAN_PREMAP_SHADOW 1
|
||||
#else
|
||||
# define ASAN_PREMAP_SHADOW 0
|
||||
#endif
|
||||
# if SANITIZER_ANDROID && defined(__arm__)
|
||||
# define ASAN_PREMAP_SHADOW 1
|
||||
# else
|
||||
# define ASAN_PREMAP_SHADOW 0
|
||||
# endif
|
||||
|
||||
#define ASAN_SHADOW_GRANULARITY (1ULL << ASAN_SHADOW_SCALE)
|
||||
# define ASAN_SHADOW_GRANULARITY (1ULL << ASAN_SHADOW_SCALE)
|
||||
|
||||
#define DO_ASAN_MAPPING_PROFILE 0 // Set to 1 to profile the functions below.
|
||||
# define DO_ASAN_MAPPING_PROFILE 0 // Set to 1 to profile the functions below.
|
||||
|
||||
#if DO_ASAN_MAPPING_PROFILE
|
||||
# define PROFILE_ASAN_MAPPING() AsanMappingProfile[__LINE__]++;
|
||||
#else
|
||||
# define PROFILE_ASAN_MAPPING()
|
||||
#endif
|
||||
# if DO_ASAN_MAPPING_PROFILE
|
||||
# define PROFILE_ASAN_MAPPING() AsanMappingProfile[__LINE__]++;
|
||||
# else
|
||||
# define PROFILE_ASAN_MAPPING()
|
||||
# endif
|
||||
|
||||
// If 1, all shadow boundaries are constants.
|
||||
// Don't set to 1 other than for testing.
|
||||
#define ASAN_FIXED_MAPPING 0
|
||||
# define ASAN_FIXED_MAPPING 0
|
||||
|
||||
namespace __asan {
|
||||
|
||||
extern uptr AsanMappingProfile[];
|
||||
|
||||
#if ASAN_FIXED_MAPPING
|
||||
# if ASAN_FIXED_MAPPING
|
||||
// Fixed mapping for 64-bit Linux. Mostly used for performance comparison
|
||||
// with non-fixed mapping. As of r175253 (Feb 2013) the performance
|
||||
// difference between fixed and non-fixed mapping is below the noise level.
|
||||
static uptr kHighMemEnd = 0x7fffffffffffULL;
|
||||
static uptr kMidMemBeg = 0x3000000000ULL;
|
||||
static uptr kMidMemEnd = 0x4fffffffffULL;
|
||||
#else
|
||||
# else
|
||||
extern uptr kHighMemEnd, kMidMemBeg, kMidMemEnd; // Initialized in __asan_init.
|
||||
#endif
|
||||
# endif
|
||||
|
||||
} // namespace __asan
|
||||
|
||||
#if defined(__sparc__) && SANITIZER_WORDSIZE == 64
|
||||
# include "asan_mapping_sparc64.h"
|
||||
#else
|
||||
# define MEM_TO_SHADOW(mem) \
|
||||
(((mem) >> ASAN_SHADOW_SCALE) + (ASAN_SHADOW_OFFSET))
|
||||
# if defined(__sparc__) && SANITIZER_WORDSIZE == 64
|
||||
# include "asan_mapping_sparc64.h"
|
||||
# else
|
||||
# define MEM_TO_SHADOW(mem) \
|
||||
(((mem) >> ASAN_SHADOW_SCALE) + (ASAN_SHADOW_OFFSET))
|
||||
|
||||
# define kLowMemBeg 0
|
||||
# define kLowMemEnd (ASAN_SHADOW_OFFSET ? ASAN_SHADOW_OFFSET - 1 : 0)
|
||||
# define kLowMemBeg 0
|
||||
# define kLowMemEnd (ASAN_SHADOW_OFFSET ? ASAN_SHADOW_OFFSET - 1 : 0)
|
||||
|
||||
# define kLowShadowBeg ASAN_SHADOW_OFFSET
|
||||
# define kLowShadowEnd MEM_TO_SHADOW(kLowMemEnd)
|
||||
# define kLowShadowBeg ASAN_SHADOW_OFFSET
|
||||
# define kLowShadowEnd MEM_TO_SHADOW(kLowMemEnd)
|
||||
|
||||
# define kHighMemBeg (MEM_TO_SHADOW(kHighMemEnd) + 1)
|
||||
# define kHighMemBeg (MEM_TO_SHADOW(kHighMemEnd) + 1)
|
||||
|
||||
# define kHighShadowBeg MEM_TO_SHADOW(kHighMemBeg)
|
||||
# define kHighShadowEnd MEM_TO_SHADOW(kHighMemEnd)
|
||||
# define kHighShadowBeg MEM_TO_SHADOW(kHighMemBeg)
|
||||
# define kHighShadowEnd MEM_TO_SHADOW(kHighMemEnd)
|
||||
|
||||
# define kMidShadowBeg MEM_TO_SHADOW(kMidMemBeg)
|
||||
# define kMidShadowEnd MEM_TO_SHADOW(kMidMemEnd)
|
||||
# define kMidShadowBeg MEM_TO_SHADOW(kMidMemBeg)
|
||||
# define kMidShadowEnd MEM_TO_SHADOW(kMidMemEnd)
|
||||
|
||||
// With the zero shadow base we can not actually map pages starting from 0.
|
||||
// This constant is somewhat arbitrary.
|
||||
# define kZeroBaseShadowStart 0
|
||||
# define kZeroBaseMaxShadowStart (1 << 18)
|
||||
# define kZeroBaseShadowStart 0
|
||||
# define kZeroBaseMaxShadowStart (1 << 18)
|
||||
|
||||
# define kShadowGapBeg \
|
||||
(kLowShadowEnd ? kLowShadowEnd + 1 : kZeroBaseShadowStart)
|
||||
# define kShadowGapEnd ((kMidMemBeg ? kMidShadowBeg : kHighShadowBeg) - 1)
|
||||
# define kShadowGapBeg \
|
||||
(kLowShadowEnd ? kLowShadowEnd + 1 : kZeroBaseShadowStart)
|
||||
# define kShadowGapEnd ((kMidMemBeg ? kMidShadowBeg : kHighShadowBeg) - 1)
|
||||
|
||||
# define kShadowGap2Beg (kMidMemBeg ? kMidShadowEnd + 1 : 0)
|
||||
# define kShadowGap2End (kMidMemBeg ? kMidMemBeg - 1 : 0)
|
||||
# define kShadowGap2Beg (kMidMemBeg ? kMidShadowEnd + 1 : 0)
|
||||
# define kShadowGap2End (kMidMemBeg ? kMidMemBeg - 1 : 0)
|
||||
|
||||
# define kShadowGap3Beg (kMidMemBeg ? kMidMemEnd + 1 : 0)
|
||||
# define kShadowGap3End (kMidMemBeg ? kHighShadowBeg - 1 : 0)
|
||||
# define kShadowGap3Beg (kMidMemBeg ? kMidMemEnd + 1 : 0)
|
||||
# define kShadowGap3End (kMidMemBeg ? kHighShadowBeg - 1 : 0)
|
||||
|
||||
namespace __asan {
|
||||
|
||||
|
@ -334,7 +338,7 @@ static inline bool AddrIsInShadowGap(uptr a) {
|
|||
|
||||
} // namespace __asan
|
||||
|
||||
#endif
|
||||
# endif
|
||||
|
||||
namespace __asan {
|
||||
|
||||
|
@ -382,4 +386,6 @@ static const uptr kAsanMappingProfileSize = __LINE__;
|
|||
|
||||
} // namespace __asan
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // ASAN_MAPPING_H
|
||||
|
|
Loading…
Reference in New Issue