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