blob: d381f010f56623241ce3588a01d6de0cd9132a10 [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
David Sehr67bf42e2018-02-26 16:43:04 -080017#ifndef ART_LIBARTBASE_BASE_MEMORY_TOOL_H_
18#define ART_LIBARTBASE_BASE_MEMORY_TOOL_H_
Evgenii Stepanov1e133742015-05-20 12:30:59 -070019
20#include <stddef.h>
21
Roland Levillain05e34f42018-05-24 13:19:05 +000022namespace art {
23
Evgenii Stepanov1e133742015-05-20 12:30:59 -070024#if !defined(__has_feature)
Roland Levillain05e34f42018-05-24 13:19:05 +000025# define __has_feature(x) 0
Evgenii Stepanov1e133742015-05-20 12:30:59 -070026#endif
27
28#if __has_feature(address_sanitizer)
29
Roland Levillain05e34f42018-05-24 13:19:05 +000030# include <sanitizer/asan_interface.h>
31# define ADDRESS_SANITIZER
Evgenii Stepanov0f2fd322015-07-15 17:40:14 -070032
Roland Levillain05e34f42018-05-24 13:19:05 +000033# ifdef ART_ENABLE_ADDRESS_SANITIZER
34# define MEMORY_TOOL_MAKE_NOACCESS(p, s) __asan_poison_memory_region(p, s)
35# define MEMORY_TOOL_MAKE_UNDEFINED(p, s) __asan_unpoison_memory_region(p, s)
36# define MEMORY_TOOL_MAKE_DEFINED(p, s) __asan_unpoison_memory_region(p, s)
Vladimir Marko2a408a32015-09-18 14:11:00 +010037constexpr bool kMemoryToolIsAvailable = true;
Roland Levillain05e34f42018-05-24 13:19:05 +000038# else
39# define MEMORY_TOOL_MAKE_NOACCESS(p, s) do { (void)(p); (void)(s); } while (0)
40# define MEMORY_TOOL_MAKE_UNDEFINED(p, s) do { (void)(p); (void)(s); } while (0)
41# define MEMORY_TOOL_MAKE_DEFINED(p, s) do { (void)(p); (void)(s); } while (0)
Vladimir Marko2a408a32015-09-18 14:11:00 +010042constexpr bool kMemoryToolIsAvailable = false;
Roland Levillain05e34f42018-05-24 13:19:05 +000043# endif
Evgenii Stepanov0f2fd322015-07-15 17:40:14 -070044
Evgenii Stepanov1ffcf7b2016-11-17 17:57:25 -080045extern "C" void __asan_handle_no_return();
46
Roland Levillain05e34f42018-05-24 13:19:05 +000047# define ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
48# define MEMORY_TOOL_HANDLE_NO_RETURN __asan_handle_no_return()
49constexpr bool kRunningOnMemoryTool = true;
Evgenii Stepanov1e133742015-05-20 12:30:59 -070050constexpr bool kMemoryToolDetectsLeaks = true;
51constexpr bool kMemoryToolAddsRedzones = true;
52constexpr size_t kMemoryToolStackGuardSizeScale = 2;
53
54#else
55
Roland Levillain05e34f42018-05-24 13:19:05 +000056# define MEMORY_TOOL_MAKE_NOACCESS(p, s) do { (void)(p); (void)(s); } while (0)
57# define MEMORY_TOOL_MAKE_UNDEFINED(p, s) do { (void)(p); (void)(s); } while (0)
58# define MEMORY_TOOL_MAKE_DEFINED(p, s) do { (void)(p); (void)(s); } while (0)
59# define ATTRIBUTE_NO_SANITIZE_ADDRESS
60# define MEMORY_TOOL_HANDLE_NO_RETURN do { } while (0)
61constexpr bool kRunningOnMemoryTool = false;
62constexpr bool kMemoryToolIsAvailable = false;
63constexpr bool kMemoryToolDetectsLeaks = false;
64constexpr bool kMemoryToolAddsRedzones = false;
Evgenii Stepanov1e133742015-05-20 12:30:59 -070065constexpr size_t kMemoryToolStackGuardSizeScale = 1;
66
67#endif
68
Roland Levillain05e34f42018-05-24 13:19:05 +000069} // namespace art
70
David Sehr67bf42e2018-02-26 16:43:04 -080071#endif // ART_LIBARTBASE_BASE_MEMORY_TOOL_H_