1 //===-- tsan_mman.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 ThreadSanitizer (TSan), a race detector.
9 //
10 //===----------------------------------------------------------------------===//
11 #ifndef TSAN_MMAN_H
12 #define TSAN_MMAN_H
13
14 #include "tsan_defs.h"
15
16 namespace __tsan {
17
18 const uptr kDefaultAlignment = 16;
19
20 void InitializeAllocator();
21 void InitializeAllocatorLate();
22 void ReplaceSystemMalloc();
23 void AllocatorProcStart(Processor *proc);
24 void AllocatorProcFinish(Processor *proc);
25 void AllocatorPrintStats();
26
27 // For user allocations.
28 void *user_alloc_internal(ThreadState *thr, uptr pc, uptr sz,
29 uptr align = kDefaultAlignment, bool signal = true);
30 // Does not accept NULL.
31 void user_free(ThreadState *thr, uptr pc, void *p, bool signal = true);
32 // Interceptor implementations.
33 void *user_alloc(ThreadState *thr, uptr pc, uptr sz);
34 void *user_calloc(ThreadState *thr, uptr pc, uptr sz, uptr n);
35 void *user_realloc(ThreadState *thr, uptr pc, void *p, uptr sz);
36 void *user_memalign(ThreadState *thr, uptr pc, uptr align, uptr sz);
37 int user_posix_memalign(ThreadState *thr, uptr pc, void **memptr, uptr align,
38 uptr sz);
39 void *user_aligned_alloc(ThreadState *thr, uptr pc, uptr align, uptr sz);
40 void *user_valloc(ThreadState *thr, uptr pc, uptr sz);
41 void *user_pvalloc(ThreadState *thr, uptr pc, uptr sz);
42 uptr user_alloc_usable_size(const void *p);
43
44 // Invoking malloc/free hooks that may be installed by the user.
45 void invoke_malloc_hook(void *ptr, uptr size);
46 void invoke_free_hook(void *ptr);
47
48 enum MBlockType {
49 MBlockScopedBuf,
50 MBlockString,
51 MBlockStackTrace,
52 MBlockShadowStack,
53 MBlockSync,
54 MBlockClock,
55 MBlockThreadContex,
56 MBlockDeadInfo,
57 MBlockRacyStacks,
58 MBlockRacyAddresses,
59 MBlockAtExit,
60 MBlockFlag,
61 MBlockReport,
62 MBlockReportMop,
63 MBlockReportThread,
64 MBlockReportMutex,
65 MBlockReportLoc,
66 MBlockReportStack,
67 MBlockSuppression,
68 MBlockExpectRace,
69 MBlockSignal,
70 MBlockJmpBuf,
71
72 // This must be the last.
73 MBlockTypeCount
74 };
75
76 // For internal data structures.
77 void *internal_alloc(MBlockType typ, uptr sz);
78 void internal_free(void *p);
79
80 template<typename T>
DestroyAndFree(T * & p)81 void DestroyAndFree(T *&p) {
82 p->~T();
83 internal_free(p);
84 p = 0;
85 }
86
87 } // namespace __tsan
88 #endif // TSAN_MMAN_H
89