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