1 // Copyright 2014 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 // 5 // Defines some functions that intentionally do an invalid memory access in 6 // order to trigger an AddressSanitizer (ASan) error report. 7 8 #ifndef BASE_DEBUG_ASAN_INVALID_ACCESS_H_ 9 #define BASE_DEBUG_ASAN_INVALID_ACCESS_H_ 10 11 #include "base/base_export.h" 12 #include "base/compiler_specific.h" 13 #include "base/sanitizer_buildflags.h" 14 #include "build/build_config.h" 15 16 namespace base { 17 namespace debug { 18 19 #if defined(ADDRESS_SANITIZER) || BUILDFLAG(IS_HWASAN) 20 21 // Generates an heap buffer overflow. 22 NOINLINE BASE_EXPORT void AsanHeapOverflow(); 23 24 // Generates an heap buffer underflow. 25 NOINLINE BASE_EXPORT void AsanHeapUnderflow(); 26 27 // Generates an use after free. 28 NOINLINE BASE_EXPORT void AsanHeapUseAfterFree(); 29 30 // The "corrupt-block" and "corrupt-heap" classes of bugs is specific to 31 // Windows. 32 #if BUILDFLAG(IS_WIN) 33 // Corrupts a memory block and makes sure that the corruption gets detected when 34 // we try to free this block. 35 NOINLINE BASE_EXPORT void AsanCorruptHeapBlock(); 36 37 // Corrupts the heap and makes sure that the corruption gets detected when a 38 // crash occur. 39 NOINLINE BASE_EXPORT void AsanCorruptHeap(); 40 41 #endif // BUILDFLAG(IS_WIN) 42 #endif // ADDRESS_SANITIZER 43 44 } // namespace debug 45 } // namespace base 46 47 #endif // BASE_DEBUG_ASAN_INVALID_ACCESS_H_ 48