blob: e0bdcfeced15ef35a9ca00df3b9131887cc9993c [file] [log] [blame]
Evgenii Stepanov1e133742015-05-20 12:30:59 -07001/*
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
Evgenii Stepanov0f2fd322015-07-15 17:40:14 -070030
31#ifdef ART_ENABLE_ADDRESS_SANITIZER
Evgenii Stepanov1e133742015-05-20 12:30:59 -070032#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)
Evgenii Stepanov0f2fd322015-07-15 17:40:14 -070035#else
36#define MEMORY_TOOL_MAKE_NOACCESS(p, s) do { (void)(p); (void)(s); } while (0)
37#define MEMORY_TOOL_MAKE_UNDEFINED(p, s) do { (void)(p); (void)(s); } while (0)
38#define MEMORY_TOOL_MAKE_DEFINED(p, s) do { (void)(p); (void)(s); } while (0)
39#endif
40
Evgenii Stepanov4abf4512015-07-13 10:41:57 -070041#define ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
Evgenii Stepanov1e133742015-05-20 12:30:59 -070042#define RUNNING_ON_MEMORY_TOOL 1U
43constexpr bool kMemoryToolIsValgrind = false;
44constexpr bool kMemoryToolDetectsLeaks = true;
45constexpr bool kMemoryToolAddsRedzones = true;
46constexpr size_t kMemoryToolStackGuardSizeScale = 2;
47
48#else
49
50#include <valgrind.h>
51#include <memcheck/memcheck.h>
52#define MEMORY_TOOL_MAKE_NOACCESS(p, s) VALGRIND_MAKE_MEM_NOACCESS(p, s)
53#define MEMORY_TOOL_MAKE_UNDEFINED(p, s) VALGRIND_MAKE_MEM_UNDEFINED(p, s)
54#define MEMORY_TOOL_MAKE_DEFINED(p, s) VALGRIND_MAKE_MEM_DEFINED(p, s)
Evgenii Stepanov4abf4512015-07-13 10:41:57 -070055#define ATTRIBUTE_NO_SANITIZE_ADDRESS
Evgenii Stepanov1e133742015-05-20 12:30:59 -070056#define RUNNING_ON_MEMORY_TOOL RUNNING_ON_VALGRIND
57constexpr bool kMemoryToolIsValgrind = true;
58constexpr bool kMemoryToolDetectsLeaks = true;
59constexpr bool kMemoryToolAddsRedzones = true;
60constexpr size_t kMemoryToolStackGuardSizeScale = 1;
61
62#endif
63
64#endif // ART_RUNTIME_BASE_MEMORY_TOOL_H_