* config/sh/sh.c (barrier_align): Return 0 when barrier_or_label
[official-gcc.git] / libsanitizer / asan / asan_allocator.h
blob1f83dcd6780005ad2a727c7415f3dd512d07777b
1 //===-- asan_allocator.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 // ASan-private header for asan_allocator2.cc.
11 //===----------------------------------------------------------------------===//
13 #ifndef ASAN_ALLOCATOR_H
14 #define ASAN_ALLOCATOR_H
16 #include "asan_internal.h"
17 #include "asan_interceptors.h"
18 #include "sanitizer_common/sanitizer_list.h"
20 namespace __asan {
22 enum AllocType {
23 FROM_MALLOC = 1, // Memory block came from malloc, calloc, realloc, etc.
24 FROM_NEW = 2, // Memory block came from operator new.
25 FROM_NEW_BR = 3 // Memory block came from operator new [ ]
28 static const uptr kNumberOfSizeClasses = 255;
29 struct AsanChunk;
31 void InitializeAllocator();
33 class AsanChunkView {
34 public:
35 explicit AsanChunkView(AsanChunk *chunk) : chunk_(chunk) {}
36 bool IsValid() { return chunk_ != 0; }
37 uptr Beg(); // first byte of user memory.
38 uptr End(); // last byte of user memory.
39 uptr UsedSize(); // size requested by the user.
40 uptr AllocTid();
41 uptr FreeTid();
42 void GetAllocStack(StackTrace *stack);
43 void GetFreeStack(StackTrace *stack);
44 bool AddrIsInside(uptr addr, uptr access_size, sptr *offset) {
45 if (addr >= Beg() && (addr + access_size) <= End()) {
46 *offset = addr - Beg();
47 return true;
49 return false;
51 bool AddrIsAtLeft(uptr addr, uptr access_size, sptr *offset) {
52 (void)access_size;
53 if (addr < Beg()) {
54 *offset = Beg() - addr;
55 return true;
57 return false;
59 bool AddrIsAtRight(uptr addr, uptr access_size, sptr *offset) {
60 if (addr + access_size > End()) {
61 *offset = addr - End();
62 return true;
64 return false;
67 private:
68 AsanChunk *const chunk_;
71 AsanChunkView FindHeapChunkByAddress(uptr address);
73 // List of AsanChunks with total size.
74 class AsanChunkFifoList: public IntrusiveList<AsanChunk> {
75 public:
76 explicit AsanChunkFifoList(LinkerInitialized) { }
77 AsanChunkFifoList() { clear(); }
78 void Push(AsanChunk *n);
79 void PushList(AsanChunkFifoList *q);
80 AsanChunk *Pop();
81 uptr size() { return size_; }
82 void clear() {
83 IntrusiveList<AsanChunk>::clear();
84 size_ = 0;
86 private:
87 uptr size_;
90 struct AsanThreadLocalMallocStorage {
91 explicit AsanThreadLocalMallocStorage(LinkerInitialized x)
92 { }
93 AsanThreadLocalMallocStorage() {
94 CHECK(REAL(memset));
95 REAL(memset)(this, 0, sizeof(AsanThreadLocalMallocStorage));
98 uptr quarantine_cache[16];
99 uptr allocator2_cache[96 * (512 * 8 + 16)]; // Opaque.
100 void CommitBack();
103 void *asan_memalign(uptr alignment, uptr size, StackTrace *stack,
104 AllocType alloc_type);
105 void asan_free(void *ptr, StackTrace *stack, AllocType alloc_type);
107 void *asan_malloc(uptr size, StackTrace *stack);
108 void *asan_calloc(uptr nmemb, uptr size, StackTrace *stack);
109 void *asan_realloc(void *p, uptr size, StackTrace *stack);
110 void *asan_valloc(uptr size, StackTrace *stack);
111 void *asan_pvalloc(uptr size, StackTrace *stack);
113 int asan_posix_memalign(void **memptr, uptr alignment, uptr size,
114 StackTrace *stack);
115 uptr asan_malloc_usable_size(void *ptr, StackTrace *stack);
117 uptr asan_mz_size(const void *ptr);
118 void asan_mz_force_lock();
119 void asan_mz_force_unlock();
121 void PrintInternalAllocatorStats();
123 } // namespace __asan
124 #endif // ASAN_ALLOCATOR_H