1//===-- asan_test_utils.h ---------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file is a part of AddressSanitizer, an address sanity checker.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef ASAN_TEST_UTILS_H
14#define ASAN_TEST_UTILS_H
15
16#if !defined(SANITIZER_EXTERNAL_TEST_CONFIG)
17# define INCLUDED_FROM_ASAN_TEST_UTILS_H
18# include "asan_test_config.h"
19# undef INCLUDED_FROM_ASAN_TEST_UTILS_H
20#endif
21
22#include "sanitizer_test_utils.h"
23#include "sanitizer_pthread_wrappers.h"
24
25#include <stdio.h>
26#include <signal.h>
27#include <stdlib.h>
28#include <string.h>
29#include <stdint.h>
30#include <assert.h>
31#include <algorithm>
32#include <setjmp.h>
33
34#if !defined(_WIN32)
35# include <strings.h>
36# include <sys/mman.h>
37#endif
38
39#ifdef __linux__
40# include <sys/prctl.h>
41# include <sys/types.h>
42# include <sys/stat.h>
43# include <fcntl.h>
44#include <unistd.h>
45#endif
46
47#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__)
48#include <malloc.h>
49#endif
50
51#if ASAN_HAS_EXCEPTIONS
52# define ASAN_THROW(x) throw (x)
53#else
54# define ASAN_THROW(x)
55#endif
56
57typedef uint8_t U1;
58typedef uint16_t U2;
59typedef uint32_t U4;
60typedef uint64_t U8;
61
62static const int kPageSize = 4096;
63
64// Big enough to be handled by secondary allocator and small enough to fit into
65// quarantine for all configurations.
66const size_t kLargeMalloc = 1 << 22;
67
68extern void free_aaa(void *p);
69extern void *malloc_aaa(size_t size);
70
71template<typename T>
72NOINLINE void asan_write(T *a) {
73 *a = 0;
74}
75
76std::string RightOOBErrorMessage(int oob_distance, bool is_write);
77std::string RightOOBWriteMessage(int oob_distance);
78std::string RightOOBReadMessage(int oob_distance);
79std::string LeftOOBErrorMessage(int oob_distance, bool is_write);
80std::string LeftOOBWriteMessage(int oob_distance);
81std::string LeftOOBReadMessage(int oob_distance);
82std::string LeftOOBAccessMessage(int oob_distance);
83char* MallocAndMemsetString(size_t size, char ch);
84char* MallocAndMemsetString(size_t size);
85
86extern char glob1[1];
87extern char glob2[2];
88extern char glob3[3];
89extern char glob4[4];
90extern char glob5[5];
91extern char glob6[6];
92extern char glob7[7];
93extern char glob8[8];
94extern char glob9[9];
95extern char glob10[10];
96extern char glob11[11];
97extern char glob12[12];
98extern char glob13[13];
99extern char glob14[14];
100extern char glob15[15];
101extern char glob16[16];
102extern char glob17[17];
103extern char glob1000[1000];
104extern char glob10000[10000];
105extern char glob100000[100000];
106extern int GlobalsTest(int x);
107
108#endif // ASAN_TEST_UTILS_H
109

source code of compiler-rt/lib/asan/tests/asan_test_utils.h