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(SANITIZER_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 "sanitizer_pthread_wrappers.h"
25 
26 #include <stdio.h>
27 #include <signal.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <stdint.h>
31 #include <assert.h>
32 #include <algorithm>
33 
34 #if !defined(_WIN32)
35 # include <strings.h>
36 # include <sys/mman.h>
37 # include <setjmp.h>
38 #endif
39 
40 #ifdef __linux__
41 # include <sys/prctl.h>
42 # include <sys/types.h>
43 # include <sys/stat.h>
44 # include <fcntl.h>
45 #include <unistd.h>
46 #endif
47 
48 #if !defined(__APPLE__) && !defined(__FreeBSD__)
49 #include <malloc.h>
50 #endif
51 
52 #if ASAN_HAS_EXCEPTIONS
53 # define ASAN_THROW(x) throw (x)
54 #else
55 # define ASAN_THROW(x)
56 #endif
57 
58 typedef uint8_t   U1;
59 typedef uint16_t  U2;
60 typedef uint32_t  U4;
61 typedef uint64_t  U8;
62 
63 static const int kPageSize = 4096;
64 
65 const size_t kLargeMalloc = 1 << 24;
66 
67 extern void free_aaa(void *p);
68 extern void *malloc_aaa(size_t size);
69 
70 template<typename T>
asan_write(T * a)71 NOINLINE void asan_write(T *a) {
72   *a = 0;
73 }
74 
75 string RightOOBErrorMessage(int oob_distance, bool is_write);
76 string RightOOBWriteMessage(int oob_distance);
77 string RightOOBReadMessage(int oob_distance);
78 string LeftOOBErrorMessage(int oob_distance, bool is_write);
79 string LeftOOBWriteMessage(int oob_distance);
80 string LeftOOBReadMessage(int oob_distance);
81 string LeftOOBAccessMessage(int oob_distance);
82 char* MallocAndMemsetString(size_t size, char ch);
83 char* MallocAndMemsetString(size_t size);
84 
85 extern char glob1[1];
86 extern char glob2[2];
87 extern char glob3[3];
88 extern char glob4[4];
89 extern char glob5[5];
90 extern char glob6[6];
91 extern char glob7[7];
92 extern char glob8[8];
93 extern char glob9[9];
94 extern char glob10[10];
95 extern char glob11[11];
96 extern char glob12[12];
97 extern char glob13[13];
98 extern char glob14[14];
99 extern char glob15[15];
100 extern char glob16[16];
101 extern char glob17[17];
102 extern char glob1000[1000];
103 extern char glob10000[10000];
104 extern char glob100000[100000];
105 extern int GlobalsTest(int x);
106 
107 #endif  // ASAN_TEST_UTILS_H
108