1 //===-- asan_test_utils.h ---------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file is a part of AddressSanitizer, an address sanity checker. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef ASAN_TEST_UTILS_H 15 #define ASAN_TEST_UTILS_H 16 17 #if !defined(ASAN_EXTERNAL_TEST_CONFIG) 18 # define INCLUDED_FROM_ASAN_TEST_UTILS_H 19 # include "asan_test_config.h" 20 # undef INCLUDED_FROM_ASAN_TEST_UTILS_H 21 #endif 22 23 #include "sanitizer_test_utils.h" 24 #include <stdio.h> 25 #include <signal.h> 26 #include <stdlib.h> 27 #include <string.h> 28 #include <strings.h> 29 #include <pthread.h> 30 #include <stdint.h> 31 #include <setjmp.h> 32 #include <assert.h> 33 #include <algorithm> 34 #include <sys/mman.h> 35 36 #ifdef __linux__ 37 # include <sys/prctl.h> 38 # include <sys/types.h> 39 # include <sys/stat.h> 40 # include <fcntl.h> 41 #include <unistd.h> 42 #endif 43 44 #if defined(__i386__) || defined(__x86_64__) 45 #include <emmintrin.h> 46 #endif 47 48 #ifndef __APPLE__ 49 #include <malloc.h> 50 #endif 51 52 // Check that pthread_create/pthread_join return success. 53 #define PTHREAD_CREATE(a, b, c, d) ASSERT_EQ(0, pthread_create(a, b, c, d)) 54 #define PTHREAD_JOIN(a, b) ASSERT_EQ(0, pthread_join(a, b)) 55 56 #if ASAN_HAS_EXCEPTIONS 57 # define ASAN_THROW(x) throw (x) 58 #else 59 # define ASAN_THROW(x) 60 #endif 61 62 typedef uint8_t U1; 63 typedef uint16_t U2; 64 typedef uint32_t U4; 65 typedef uint64_t U8; 66 67 static const int kPageSize = 4096; 68 69 const size_t kLargeMalloc = 1 << 24; 70 71 extern void free_aaa(void *p); 72 extern void *malloc_aaa(size_t size); 73 74 template<typename T> 75 NOINLINE void asan_write(T *a) { 76 *a = 0; 77 } 78 79 string RightOOBErrorMessage(int oob_distance, bool is_write); 80 string RightOOBWriteMessage(int oob_distance); 81 string RightOOBReadMessage(int oob_distance); 82 string LeftOOBErrorMessage(int oob_distance, bool is_write); 83 string LeftOOBWriteMessage(int oob_distance); 84 string LeftOOBReadMessage(int oob_distance); 85 string LeftOOBAccessMessage(int oob_distance); 86 char* MallocAndMemsetString(size_t size, char ch); 87 char* MallocAndMemsetString(size_t size); 88 89 extern char glob1[1]; 90 extern char glob2[2]; 91 extern char glob3[3]; 92 extern char glob4[4]; 93 extern char glob5[5]; 94 extern char glob6[6]; 95 extern char glob7[7]; 96 extern char glob8[8]; 97 extern char glob9[9]; 98 extern char glob10[10]; 99 extern char glob11[11]; 100 extern char glob12[12]; 101 extern char glob13[13]; 102 extern char glob14[14]; 103 extern char glob15[15]; 104 extern char glob16[16]; 105 extern char glob17[17]; 106 extern char glob1000[1000]; 107 extern char glob10000[10000]; 108 extern char glob100000[100000]; 109 extern int GlobalsTest(int x); 110 111 #endif // ASAN_TEST_UTILS_H 112