• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2022-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ECMASCRIPT_BASE_ASAN_INTERFACE_H
17 #define ECMASCRIPT_BASE_ASAN_INTERFACE_H
18 
19 #if (defined(__has_feature) && __has_feature(address_sanitizer)) || defined(__SANITIZE_ADDRESS__)
20 #define HAS_SANITIZER
21 #endif
22 
23 #if defined(HAS_SANITIZER) && defined(RUN_WITH_ASAN)
24 #define ARK_ASAN_ON
25 #endif
26 
27 #ifdef ARK_ASAN_ON
28 extern "C" {
29 // NOLINTNEXTLINE(readability-identifier-naming)
30 void __asan_poison_memory_region(void const volatile *addr, size_t size) __attribute__((visibility("default")));
31 // NOLINTNEXTLINE(readability-identifier-naming)
32 void __asan_unpoison_memory_region(void const volatile *addr, size_t size) __attribute__((visibility("default")));
33 }
34 
35 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
36 #define ASAN_POISON_MEMORY_REGION(addr, size) __asan_poison_memory_region((addr), (size))
37 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
38 #define ASAN_UNPOISON_MEMORY_REGION(addr, size) __asan_unpoison_memory_region((addr), (size))
39 #else
40 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
41 #define ASAN_POISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
42 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
43 #define ASAN_UNPOISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
44 #endif
45 
46 #endif  // ECMASCRIPT_BASE_ASAN_INTERFACE_H
47