| Evgenii Stepanov | 1e13374 | 2015-05-20 12:30:59 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2015 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
|  | 17 | #ifndef ART_RUNTIME_BASE_MEMORY_TOOL_H_ | 
|  | 18 | #define ART_RUNTIME_BASE_MEMORY_TOOL_H_ | 
|  | 19 |  | 
|  | 20 | #include <stddef.h> | 
|  | 21 |  | 
|  | 22 | #if !defined(__has_feature) | 
|  | 23 | #define __has_feature(x) 0 | 
|  | 24 | #endif | 
|  | 25 |  | 
|  | 26 | #if __has_feature(address_sanitizer) | 
|  | 27 |  | 
|  | 28 | #include <sanitizer/asan_interface.h> | 
|  | 29 | #define ADDRESS_SANITIZER | 
|  | 30 | #define MEMORY_TOOL_MAKE_NOACCESS(p, s) __asan_poison_memory_region(p, s) | 
|  | 31 | #define MEMORY_TOOL_MAKE_UNDEFINED(p, s) __asan_unpoison_memory_region(p, s) | 
|  | 32 | #define MEMORY_TOOL_MAKE_DEFINED(p, s) __asan_unpoison_memory_region(p, s) | 
| Evgenii Stepanov | 4abf451 | 2015-07-13 10:41:57 -0700 | [diff] [blame^] | 33 | #define ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address)) | 
| Evgenii Stepanov | 1e13374 | 2015-05-20 12:30:59 -0700 | [diff] [blame] | 34 | #define RUNNING_ON_MEMORY_TOOL 1U | 
|  | 35 | constexpr bool kMemoryToolIsValgrind = false; | 
|  | 36 | constexpr bool kMemoryToolDetectsLeaks = true; | 
|  | 37 | constexpr bool kMemoryToolAddsRedzones = true; | 
|  | 38 | constexpr size_t kMemoryToolStackGuardSizeScale = 2; | 
|  | 39 |  | 
|  | 40 | #else | 
|  | 41 |  | 
|  | 42 | #include <valgrind.h> | 
|  | 43 | #include <memcheck/memcheck.h> | 
|  | 44 | #define MEMORY_TOOL_MAKE_NOACCESS(p, s) VALGRIND_MAKE_MEM_NOACCESS(p, s) | 
|  | 45 | #define MEMORY_TOOL_MAKE_UNDEFINED(p, s) VALGRIND_MAKE_MEM_UNDEFINED(p, s) | 
|  | 46 | #define MEMORY_TOOL_MAKE_DEFINED(p, s) VALGRIND_MAKE_MEM_DEFINED(p, s) | 
| Evgenii Stepanov | 4abf451 | 2015-07-13 10:41:57 -0700 | [diff] [blame^] | 47 | #define ATTRIBUTE_NO_SANITIZE_ADDRESS | 
| Evgenii Stepanov | 1e13374 | 2015-05-20 12:30:59 -0700 | [diff] [blame] | 48 | #define RUNNING_ON_MEMORY_TOOL RUNNING_ON_VALGRIND | 
|  | 49 | constexpr bool kMemoryToolIsValgrind = true; | 
|  | 50 | constexpr bool kMemoryToolDetectsLeaks = true; | 
|  | 51 | constexpr bool kMemoryToolAddsRedzones = true; | 
|  | 52 | constexpr size_t kMemoryToolStackGuardSizeScale = 1; | 
|  | 53 |  | 
|  | 54 | #endif | 
|  | 55 |  | 
|  | 56 | #endif  // ART_RUNTIME_BASE_MEMORY_TOOL_H_ |