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