xref: /netbsd-src/sys/external/bsd/compiler_rt/dist/lib/asan/tests/asan_test_utils.h (revision a7c257b03e4462df2b1020128fb82716512d7856)
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 #include <setjmp.h>
34 
35 #if !defined(_WIN32)
36 # include <strings.h>
37 # include <sys/mman.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__) && !defined(__NetBSD__)
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 // Big enough to be handled by secondary allocator and small enough to fit into
66 // quarantine for all configurations.
67 const size_t kLargeMalloc = 1 << 22;
68 
69 extern void free_aaa(void *p);
70 extern void *malloc_aaa(size_t size);
71 
72 template<typename T>
asan_write(T * a)73 NOINLINE void asan_write(T *a) {
74   *a = 0;
75 }
76 
77 string RightOOBErrorMessage(int oob_distance, bool is_write);
78 string RightOOBWriteMessage(int oob_distance);
79 string RightOOBReadMessage(int oob_distance);
80 string LeftOOBErrorMessage(int oob_distance, bool is_write);
81 string LeftOOBWriteMessage(int oob_distance);
82 string LeftOOBReadMessage(int oob_distance);
83 string LeftOOBAccessMessage(int oob_distance);
84 char* MallocAndMemsetString(size_t size, char ch);
85 char* MallocAndMemsetString(size_t size);
86 
87 extern char glob1[1];
88 extern char glob2[2];
89 extern char glob3[3];
90 extern char glob4[4];
91 extern char glob5[5];
92 extern char glob6[6];
93 extern char glob7[7];
94 extern char glob8[8];
95 extern char glob9[9];
96 extern char glob10[10];
97 extern char glob11[11];
98 extern char glob12[12];
99 extern char glob13[13];
100 extern char glob14[14];
101 extern char glob15[15];
102 extern char glob16[16];
103 extern char glob17[17];
104 extern char glob1000[1000];
105 extern char glob10000[10000];
106 extern char glob100000[100000];
107 extern int GlobalsTest(int x);
108 
109 #endif  // ASAN_TEST_UTILS_H
110