1 //===-- asan_test_utils.h ---------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file is a part of AddressSanitizer, an address sanity checker. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef ASAN_TEST_UTILS_H 14 #define ASAN_TEST_UTILS_H 15 16 #if !defined(SANITIZER_EXTERNAL_TEST_CONFIG) 17 # define INCLUDED_FROM_ASAN_TEST_UTILS_H 18 # include "asan_test_config.h" 19 # undef INCLUDED_FROM_ASAN_TEST_UTILS_H 20 #endif 21 22 #include "sanitizer_test_utils.h" 23 #include "sanitizer_pthread_wrappers.h" 24 25 #include <stdio.h> 26 #include <signal.h> 27 #include <stdlib.h> 28 #include <string.h> 29 #include <stdint.h> 30 #include <assert.h> 31 #include <algorithm> 32 #include <setjmp.h> 33 34 #if !defined(_WIN32) 35 # include <strings.h> 36 # include <sys/mman.h> 37 #endif 38 39 #ifdef __linux__ 40 # include <sys/prctl.h> 41 # include <sys/types.h> 42 # include <sys/stat.h> 43 # include <fcntl.h> 44 #include <unistd.h> 45 #endif 46 47 #if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__) 48 #include <malloc.h> 49 #endif 50 51 #if ASAN_HAS_EXCEPTIONS 52 # define ASAN_THROW(x) throw (x) 53 #else 54 # define ASAN_THROW(x) 55 #endif 56 57 typedef uint8_t U1; 58 typedef uint16_t U2; 59 typedef uint32_t U4; 60 typedef uint64_t U8; 61 62 static const int kPageSize = 4096; 63 64 // Big enough to be handled by secondary allocator and small enough to fit into 65 // quarantine for all configurations. 66 const size_t kLargeMalloc = 1 << 22; 67 68 extern void free_aaa(void *p); 69 extern void *malloc_aaa(size_t size); 70 71 template<typename T> asan_write(T * a)72NOINLINE void asan_write(T *a) { 73 *a = 0; 74 } 75 76 std::string RightOOBErrorMessage(int oob_distance, bool is_write); 77 std::string RightOOBWriteMessage(int oob_distance); 78 std::string RightOOBReadMessage(int oob_distance); 79 std::string LeftOOBErrorMessage(int oob_distance, bool is_write); 80 std::string LeftOOBWriteMessage(int oob_distance); 81 std::string LeftOOBReadMessage(int oob_distance); 82 std::string LeftOOBAccessMessage(int oob_distance); 83 char* MallocAndMemsetString(size_t size, char ch); 84 char* MallocAndMemsetString(size_t size); 85 86 extern char glob1[1]; 87 extern char glob2[2]; 88 extern char glob3[3]; 89 extern char glob4[4]; 90 extern char glob5[5]; 91 extern char glob6[6]; 92 extern char glob7[7]; 93 extern char glob8[8]; 94 extern char glob9[9]; 95 extern char glob10[10]; 96 extern char glob11[11]; 97 extern char glob12[12]; 98 extern char glob13[13]; 99 extern char glob14[14]; 100 extern char glob15[15]; 101 extern char glob16[16]; 102 extern char glob17[17]; 103 extern char glob1000[1000]; 104 extern char glob10000[10000]; 105 extern char glob100000[100000]; 106 extern int GlobalsTest(int x); 107 108 #endif // ASAN_TEST_UTILS_H 109