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 | |
David Sehr | 67bf42e | 2018-02-26 16:43:04 -0800 | [diff] [blame] | 17 | #ifndef ART_LIBARTBASE_BASE_MEMORY_TOOL_H_ |
| 18 | #define ART_LIBARTBASE_BASE_MEMORY_TOOL_H_ |
Evgenii Stepanov | 1e13374 | 2015-05-20 12:30:59 -0700 | [diff] [blame] | 19 | |
| 20 | #include <stddef.h> |
| 21 | |
| 22 | #if !defined(__has_feature) |
Andreas Gampe | 8b362a8 | 2018-05-22 20:54:14 +0000 | [diff] [blame] | 23 | #define __has_feature(x) 0 |
Evgenii Stepanov | 1e13374 | 2015-05-20 12:30:59 -0700 | [diff] [blame] | 24 | #endif |
| 25 | |
| 26 | #if __has_feature(address_sanitizer) |
| 27 | |
Andreas Gampe | 8b362a8 | 2018-05-22 20:54:14 +0000 | [diff] [blame] | 28 | #include <sanitizer/asan_interface.h> |
| 29 | #define ADDRESS_SANITIZER |
Evgenii Stepanov | 0f2fd32 | 2015-07-15 17:40:14 -0700 | [diff] [blame] | 30 | |
Andreas Gampe | 8b362a8 | 2018-05-22 20:54:14 +0000 | [diff] [blame] | 31 | #ifdef ART_ENABLE_ADDRESS_SANITIZER |
| 32 | #define MEMORY_TOOL_MAKE_NOACCESS(p, s) __asan_poison_memory_region(p, s) |
| 33 | #define MEMORY_TOOL_MAKE_UNDEFINED(p, s) __asan_unpoison_memory_region(p, s) |
| 34 | #define MEMORY_TOOL_MAKE_DEFINED(p, s) __asan_unpoison_memory_region(p, s) |
Vladimir Marko | 2a408a3 | 2015-09-18 14:11:00 +0100 | [diff] [blame] | 35 | constexpr bool kMemoryToolIsAvailable = true; |
Andreas Gampe | 8b362a8 | 2018-05-22 20:54:14 +0000 | [diff] [blame] | 36 | #else |
| 37 | #define MEMORY_TOOL_MAKE_NOACCESS(p, s) do { (void)(p); (void)(s); } while (0) |
| 38 | #define MEMORY_TOOL_MAKE_UNDEFINED(p, s) do { (void)(p); (void)(s); } while (0) |
| 39 | #define MEMORY_TOOL_MAKE_DEFINED(p, s) do { (void)(p); (void)(s); } while (0) |
Vladimir Marko | 2a408a3 | 2015-09-18 14:11:00 +0100 | [diff] [blame] | 40 | constexpr bool kMemoryToolIsAvailable = false; |
Andreas Gampe | 8b362a8 | 2018-05-22 20:54:14 +0000 | [diff] [blame] | 41 | #endif |
Evgenii Stepanov | 0f2fd32 | 2015-07-15 17:40:14 -0700 | [diff] [blame] | 42 | |
Evgenii Stepanov | 1ffcf7b | 2016-11-17 17:57:25 -0800 | [diff] [blame] | 43 | extern "C" void __asan_handle_no_return(); |
| 44 | |
Andreas Gampe | 8b362a8 | 2018-05-22 20:54:14 +0000 | [diff] [blame] | 45 | #define ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address)) |
| 46 | #define MEMORY_TOOL_HANDLE_NO_RETURN __asan_handle_no_return() |
| 47 | #define RUNNING_ON_MEMORY_TOOL 1U |
| 48 | constexpr bool kMemoryToolIsValgrind = false; |
Evgenii Stepanov | 1e13374 | 2015-05-20 12:30:59 -0700 | [diff] [blame] | 49 | constexpr bool kMemoryToolDetectsLeaks = true; |
| 50 | constexpr bool kMemoryToolAddsRedzones = true; |
| 51 | constexpr size_t kMemoryToolStackGuardSizeScale = 2; |
| 52 | |
| 53 | #else |
| 54 | |
Andreas Gampe | 8b362a8 | 2018-05-22 20:54:14 +0000 | [diff] [blame] | 55 | #include <memcheck/memcheck.h> |
| 56 | #include <valgrind.h> |
| 57 | #define MEMORY_TOOL_MAKE_NOACCESS(p, s) VALGRIND_MAKE_MEM_NOACCESS(p, s) |
| 58 | #define MEMORY_TOOL_MAKE_UNDEFINED(p, s) VALGRIND_MAKE_MEM_UNDEFINED(p, s) |
| 59 | #define MEMORY_TOOL_MAKE_DEFINED(p, s) VALGRIND_MAKE_MEM_DEFINED(p, s) |
| 60 | #define ATTRIBUTE_NO_SANITIZE_ADDRESS |
| 61 | #define MEMORY_TOOL_HANDLE_NO_RETURN do { } while (0) |
| 62 | #define RUNNING_ON_MEMORY_TOOL RUNNING_ON_VALGRIND |
| 63 | constexpr bool kMemoryToolIsAvailable = true; |
| 64 | constexpr bool kMemoryToolIsValgrind = true; |
| 65 | constexpr bool kMemoryToolDetectsLeaks = true; |
| 66 | constexpr bool kMemoryToolAddsRedzones = true; |
Evgenii Stepanov | 1e13374 | 2015-05-20 12:30:59 -0700 | [diff] [blame] | 67 | constexpr size_t kMemoryToolStackGuardSizeScale = 1; |
| 68 | |
| 69 | #endif |
| 70 | |
David Sehr | 67bf42e | 2018-02-26 16:43:04 -0800 | [diff] [blame] | 71 | #endif // ART_LIBARTBASE_BASE_MEMORY_TOOL_H_ |