blob: 31162a3baaaffeca3f8e786ca2800afca05b84c5 [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
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 Stepanov4abf4512015-07-13 10:41:57 -070033#define ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
Evgenii Stepanov1e133742015-05-20 12:30:59 -070034#define RUNNING_ON_MEMORY_TOOL 1U
35constexpr bool kMemoryToolIsValgrind = false;
36constexpr bool kMemoryToolDetectsLeaks = true;
37constexpr bool kMemoryToolAddsRedzones = true;
38constexpr 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 Stepanov4abf4512015-07-13 10:41:57 -070047#define ATTRIBUTE_NO_SANITIZE_ADDRESS
Evgenii Stepanov1e133742015-05-20 12:30:59 -070048#define RUNNING_ON_MEMORY_TOOL RUNNING_ON_VALGRIND
49constexpr bool kMemoryToolIsValgrind = true;
50constexpr bool kMemoryToolDetectsLeaks = true;
51constexpr bool kMemoryToolAddsRedzones = true;
52constexpr size_t kMemoryToolStackGuardSizeScale = 1;
53
54#endif
55
56#endif // ART_RUNTIME_BASE_MEMORY_TOOL_H_