Imported Upstream version 4.8.1
[platform/upstream/gcc48.git] / gcc / testsuite / g++.dg / asan / asan_test_utils.h
1 //===-- asan_test_utils.h ---------------------------------------*- C++ -*-===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // This file is a part of AddressSanitizer, an address sanity checker.
9 //
10 //===----------------------------------------------------------------------===//
11
12 #ifndef ASAN_TEST_UTILS_H
13 #define ASAN_TEST_UTILS_H
14
15 #if !defined(ASAN_EXTERNAL_TEST_CONFIG)
16 # define INCLUDED_FROM_ASAN_TEST_UTILS_H
17 # include "asan_test_config.h"
18 # undef INCLUDED_FROM_ASAN_TEST_UTILS_H
19 #endif
20
21 #include "sanitizer_test_utils.h"
22 #include <stdio.h>
23 #include <signal.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <strings.h>
27 #include <pthread.h>
28 #include <stdint.h>
29 #include <setjmp.h>
30 #include <assert.h>
31 #include <algorithm>
32 #include <sys/mman.h>
33
34 #ifdef __linux__
35 # include <sys/prctl.h>
36 # include <sys/types.h>
37 # include <sys/stat.h>
38 # include <fcntl.h>
39 #include <unistd.h>
40 #endif
41
42 #if defined(__i386__) || defined(__x86_64__)
43 #include <emmintrin.h>
44 #endif
45
46 #ifndef __APPLE__
47 #include <malloc.h>
48 #endif
49
50 // Check that pthread_create/pthread_join return success.
51 #define PTHREAD_CREATE(a, b, c, d) ASSERT_EQ(0, pthread_create(a, b, c, d))
52 #define PTHREAD_JOIN(a, b) ASSERT_EQ(0, pthread_join(a, b))
53
54 #if ASAN_HAS_EXCEPTIONS
55 # define ASAN_THROW(x) throw (x)
56 #else
57 # define ASAN_THROW(x)
58 #endif
59
60 typedef uint8_t   U1;
61 typedef uint16_t  U2;
62 typedef uint32_t  U4;
63 typedef uint64_t  U8;
64
65 static const int kPageSize = 4096;
66
67 const size_t kLargeMalloc = 1 << 24;
68
69 extern void free_aaa(void *p);
70 extern void *malloc_aaa(size_t size);
71
72 template<typename T>
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