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