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