|
| 1 | +#ifndef __qd_asan_interface_h__ |
| 2 | +#define __qd_asan_interface_h__ 1 |
| 3 | +/* |
| 4 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 5 | + * or more contributor license agreements. See the NOTICE file |
| 6 | + * distributed with this work for additional information |
| 7 | + * regarding copyright ownership. The ASF licenses this file |
| 8 | + * to you under the Apache License, Version 2.0 (the |
| 9 | + * "License"); you may not use this file except in compliance |
| 10 | + * with the License. You may obtain a copy of the License at |
| 11 | + * |
| 12 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | + * |
| 14 | + * Unless required by applicable law or agreed to in writing, |
| 15 | + * software distributed under the License is distributed on an |
| 16 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 17 | + * KIND, either express or implied. See the License for the |
| 18 | + * specific language governing permissions and limitations |
| 19 | + * under the License. |
| 20 | + */ |
| 21 | + |
| 22 | +/** |
| 23 | + * Defines the ASAN interface file if available. If not, defines stub macros. |
| 24 | + * |
| 25 | + * See #include <sanitizer/asan_interface.h> in Clang for the source. |
| 26 | + */ |
| 27 | + |
| 28 | +#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) |
| 29 | + |
| 30 | +void __asan_poison_memory_region(void const volatile *addr, size_t size); |
| 31 | +void __asan_unpoison_memory_region(void const volatile *addr, size_t size); |
| 32 | + |
| 33 | +/// Marks a memory region as unaddressable. |
| 34 | +/// |
| 35 | +/// \note Macro provided for convenience; defined as a no-op if ASan is not |
| 36 | +/// enabled. |
| 37 | +/// |
| 38 | +/// \param addr Start of memory region. |
| 39 | +/// \param size Size of memory region. |
| 40 | +#define ASAN_POISON_MEMORY_REGION(addr, size) \ |
| 41 | + __asan_poison_memory_region((addr), (size)) |
| 42 | + |
| 43 | +/// Marks a memory region as addressable. |
| 44 | +/// |
| 45 | +/// \note Macro provided for convenience; defined as a no-op if ASan is not |
| 46 | +/// enabled. |
| 47 | +/// |
| 48 | +/// \param addr Start of memory region. |
| 49 | +/// \param size Size of memory region. |
| 50 | +#define ASAN_UNPOISON_MEMORY_REGION(addr, size) \ |
| 51 | + __asan_unpoison_memory_region((addr), (size)) |
| 52 | + |
| 53 | +#else // __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) |
| 54 | + |
| 55 | +#define ASAN_POISON_MEMORY_REGION(addr, size) \ |
| 56 | + ((void)(addr), (void)(size)) |
| 57 | +#define ASAN_UNPOISON_MEMORY_REGION(addr, size) \ |
| 58 | + ((void)(addr), (void)(size)) |
| 59 | + |
| 60 | +#endif // __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) |
| 61 | + |
| 62 | +// https://github.com/google/sanitizers/wiki/AddressSanitizer#turning-off-instrumentation |
| 63 | + |
| 64 | +#if defined(__clang__) || defined (__GNUC__) |
| 65 | +# define ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address)) |
| 66 | +#else |
| 67 | +# define ATTRIBUTE_NO_SANITIZE_ADDRESS |
| 68 | +#endif |
| 69 | + |
| 70 | +#endif // __qd_asan_interface_h__ |
0 commit comments