asan_test_utils.h revision b37127085cbcc79f5f859bfab8e7204201c18287
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_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#ifndef __APPLE__ 45#include <malloc.h> 46#endif 47 48// Check that pthread_create/pthread_join return success. 49#define PTHREAD_CREATE(a, b, c, d) ASSERT_EQ(0, pthread_create(a, b, c, d)) 50#define PTHREAD_JOIN(a, b) ASSERT_EQ(0, pthread_join(a, b)) 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 65const size_t kLargeMalloc = 1 << 24; 66 67extern void free_aaa(void *p); 68extern void *malloc_aaa(size_t size); 69 70template<typename T> 71NOINLINE void asan_write(T *a) { 72 *a = 0; 73} 74 75string RightOOBErrorMessage(int oob_distance, bool is_write); 76string RightOOBWriteMessage(int oob_distance); 77string RightOOBReadMessage(int oob_distance); 78string LeftOOBErrorMessage(int oob_distance, bool is_write); 79string LeftOOBWriteMessage(int oob_distance); 80string LeftOOBReadMessage(int oob_distance); 81string LeftOOBAccessMessage(int oob_distance); 82char* MallocAndMemsetString(size_t size, char ch); 83char* MallocAndMemsetString(size_t size); 84 85extern char glob1[1]; 86extern char glob2[2]; 87extern char glob3[3]; 88extern char glob4[4]; 89extern char glob5[5]; 90extern char glob6[6]; 91extern char glob7[7]; 92extern char glob8[8]; 93extern char glob9[9]; 94extern char glob10[10]; 95extern char glob11[11]; 96extern char glob12[12]; 97extern char glob13[13]; 98extern char glob14[14]; 99extern char glob15[15]; 100extern char glob16[16]; 101extern char glob17[17]; 102extern char glob1000[1000]; 103extern char glob10000[10000]; 104extern char glob100000[100000]; 105extern int GlobalsTest(int x); 106 107#endif // ASAN_TEST_UTILS_H 108