Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:46

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___LIBCXX_DEBUG_UTILS_SANITIZERS_H
0010 #define _LIBCPP___LIBCXX_DEBUG_UTILS_SANITIZERS_H
0011 
0012 #include <__config>
0013 #include <__type_traits/integral_constant.h>
0014 #include <__type_traits/is_constant_evaluated.h>
0015 
0016 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0017 #  pragma GCC system_header
0018 #endif
0019 
0020 #if _LIBCPP_HAS_ASAN
0021 
0022 extern "C" {
0023 _LIBCPP_EXPORTED_FROM_ABI void
0024 __sanitizer_annotate_contiguous_container(const void*, const void*, const void*, const void*);
0025 _LIBCPP_EXPORTED_FROM_ABI void __sanitizer_annotate_double_ended_contiguous_container(
0026     const void*, const void*, const void*, const void*, const void*, const void*);
0027 _LIBCPP_EXPORTED_FROM_ABI int
0028 __sanitizer_verify_double_ended_contiguous_container(const void*, const void*, const void*, const void*);
0029 }
0030 
0031 #endif // _LIBCPP_HAS_ASAN
0032 
0033 _LIBCPP_BEGIN_NAMESPACE_STD
0034 
0035 // ASan choices
0036 #if _LIBCPP_HAS_ASAN
0037 #  define _LIBCPP_HAS_ASAN_CONTAINER_ANNOTATIONS_FOR_ALL_ALLOCATORS 1
0038 #endif
0039 
0040 #ifdef _LIBCPP_HAS_ASAN_CONTAINER_ANNOTATIONS_FOR_ALL_ALLOCATORS
0041 // __asan_annotate_container_with_allocator determines whether containers with custom allocators are annotated. This is
0042 // a public customization point to disable annotations if the custom allocator assumes that the memory isn't poisoned.
0043 // See the https://libcxx.llvm.org/UsingLibcxx.html#turning-off-asan-annotation-in-containers for more information.
0044 template <class _Alloc>
0045 struct __asan_annotate_container_with_allocator : true_type {};
0046 #endif
0047 
0048 // Annotate a double-ended contiguous range.
0049 // - [__first_storage, __last_storage) is the allocated memory region,
0050 // - [__first_old_contained, __last_old_contained) is the previously allowed (unpoisoned) range, and
0051 // - [__first_new_contained, __last_new_contained) is the new allowed (unpoisoned) range.
0052 template <class _Allocator>
0053 _LIBCPP_HIDE_FROM_ABI void __annotate_double_ended_contiguous_container(
0054     const void* __first_storage,
0055     const void* __last_storage,
0056     const void* __first_old_contained,
0057     const void* __last_old_contained,
0058     const void* __first_new_contained,
0059     const void* __last_new_contained) {
0060 #if !_LIBCPP_HAS_ASAN
0061   (void)__first_storage;
0062   (void)__last_storage;
0063   (void)__first_old_contained;
0064   (void)__last_old_contained;
0065   (void)__first_new_contained;
0066   (void)__last_new_contained;
0067 #else
0068   if (__asan_annotate_container_with_allocator<_Allocator>::value && __first_storage != nullptr)
0069     __sanitizer_annotate_double_ended_contiguous_container(
0070         __first_storage,
0071         __last_storage,
0072         __first_old_contained,
0073         __last_old_contained,
0074         __first_new_contained,
0075         __last_new_contained);
0076 #endif
0077 }
0078 
0079 // Annotate a contiguous range.
0080 // [__first_storage, __last_storage) is the allocated memory region,
0081 // __old_last_contained is the previously last allowed (unpoisoned) element, and
0082 // __new_last_contained is the new last allowed (unpoisoned) element.
0083 template <class _Allocator>
0084 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __annotate_contiguous_container(
0085     const void* __first_storage,
0086     const void* __last_storage,
0087     const void* __old_last_contained,
0088     const void* __new_last_contained) {
0089 #if !_LIBCPP_HAS_ASAN
0090   (void)__first_storage;
0091   (void)__last_storage;
0092   (void)__old_last_contained;
0093   (void)__new_last_contained;
0094 #else
0095   if (!__libcpp_is_constant_evaluated() && __asan_annotate_container_with_allocator<_Allocator>::value &&
0096       __first_storage != nullptr)
0097     __sanitizer_annotate_contiguous_container(
0098         __first_storage, __last_storage, __old_last_contained, __new_last_contained);
0099 #endif
0100 }
0101 
0102 _LIBCPP_END_NAMESPACE_STD
0103 
0104 #endif // _LIBCPP___LIBCXX_DEBUG_UTILS_SANITIZERS_H