asan_test_utils.h revision 38db30686c5962f8b5c877e29c6669d72198d42b
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
79#endif  // ASAN_TEST_UTILS_H
80