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 #ifndef ASAN_POISON_MEMORY_REGION 37 #define ASAN_POISON_MEMORY_REGION(addr, size) __asan_poison_memory_region((addr), (size)) 38 #endif 39 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 40 #ifndef ASAN_UNPOISON_MEMORY_REGION 41 #define ASAN_UNPOISON_MEMORY_REGION(addr, size) __asan_unpoison_memory_region((addr), (size)) 42 #endif 43 #else 44 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 45 #ifdef ASAN_POISON_MEMORY_REGION 46 #undef ASAN_POISON_MEMORY_REGION 47 #endif 48 #define ASAN_POISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size)) 49 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 50 #ifdef ASAN_UNPOISON_MEMORY_REGION 51 #undef ASAN_UNPOISON_MEMORY_REGION 52 #endif 53 #define ASAN_UNPOISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size)) 54 #endif 55 56 #endif // ECMASCRIPT_BASE_ASAN_INTERFACE_H 57