asan_test_utils.h revision 2d1fdb26e458c4ddc04155c1d421bced3ba90cd0
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
58typedef uint8_t   U1;
59typedef uint16_t  U2;
60typedef uint32_t  U4;
61typedef uint64_t  U8;
62
63static const int kPageSize = 4096;
64
65const size_t kLargeMalloc = 1 << 24;
66
67extern void free_aaa(void *p);
68extern void *malloc_aaa(size_t size);
69
70template<typename T>
71NOINLINE void asan_write(T *a) {
72  *a = 0;
73}
74
75string RightOOBErrorMessage(int oob_distance, bool is_write);
76string RightOOBWriteMessage(int oob_distance);
77string RightOOBReadMessage(int oob_distance);
78string LeftOOBErrorMessage(int oob_distance, bool is_write);
79string LeftOOBWriteMessage(int oob_distance);
80string LeftOOBReadMessage(int oob_distance);
81string LeftOOBAccessMessage(int oob_distance);
82char* MallocAndMemsetString(size_t size, char ch);
83char* MallocAndMemsetString(size_t size);
84
85extern char glob1[1];
86extern char glob2[2];
87extern char glob3[3];
88extern char glob4[4];
89extern char glob5[5];
90extern char glob6[6];
91extern char glob7[7];
92extern char glob8[8];
93extern char glob9[9];
94extern char glob10[10];
95extern char glob11[11];
96extern char glob12[12];
97extern char glob13[13];
98extern char glob14[14];
99extern char glob15[15];
100extern char glob16[16];
101extern char glob17[17];
102extern char glob1000[1000];
103extern char glob10000[10000];
104extern char glob100000[100000];
105extern int GlobalsTest(int x);
106
107#endif  // ASAN_TEST_UTILS_H
108