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);
30 // Does not accept NULL.
31 void user_free(ThreadState *thr, uptr pc, void *p);
32 void *user_realloc(ThreadState *thr, uptr pc, void *p, uptr sz);
33 void *user_alloc_aligned(ThreadState *thr, uptr pc, uptr sz, uptr align);
34 uptr user_alloc_usable_size(ThreadState *thr, uptr pc, void *p);
35 // Given the pointer p into a valid allocated block,
36 // returns the descriptor of the block.
37 MBlock *user_mblock(ThreadState *thr, void *p);
38
39 // Invoking malloc/free hooks that may be installed by the user.
40 void invoke_malloc_hook(void *ptr, uptr size);
41 void invoke_free_hook(void *ptr);
42
43 enum MBlockType {
44 MBlockScopedBuf,
45 MBlockString,
46 MBlockStackTrace,
47 MBlockShadowStack,
48 MBlockSync,
49 MBlockClock,
50 MBlockThreadContex,
51 MBlockDeadInfo,
52 MBlockRacyStacks,
53 MBlockRacyAddresses,
54 MBlockAtExit,
55 MBlockFlag,
56 MBlockReport,
57 MBlockReportMop,
58 MBlockReportThread,
59 MBlockReportMutex,
60 MBlockReportLoc,
61 MBlockReportStack,
62 MBlockSuppression,
63 MBlockExpectRace,
64 MBlockSignal,
65 MBlockFD,
66
67 // This must be the last.
68 MBlockTypeCount
69 };
70
71 // For internal data structures.
72 void *internal_alloc(MBlockType typ, uptr sz);
73 void internal_free(void *p);
74
75 template<typename T>
DestroyAndFree(T * & p)76 void DestroyAndFree(T *&p) {
77 p->~T();
78 internal_free(p);
79 p = 0;
80 }
81
82 } // namespace __tsan
83 #endif // TSAN_MMAN_H
84