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(const void *p);
35
36 // Invoking malloc/free hooks that may be installed by the user.
37 void invoke_malloc_hook(void *ptr, uptr size);
38 void invoke_free_hook(void *ptr);
39
40 enum MBlockType {
41 MBlockScopedBuf,
42 MBlockString,
43 MBlockStackTrace,
44 MBlockShadowStack,
45 MBlockSync,
46 MBlockClock,
47 MBlockThreadContex,
48 MBlockDeadInfo,
49 MBlockRacyStacks,
50 MBlockRacyAddresses,
51 MBlockAtExit,
52 MBlockFlag,
53 MBlockReport,
54 MBlockReportMop,
55 MBlockReportThread,
56 MBlockReportMutex,
57 MBlockReportLoc,
58 MBlockReportStack,
59 MBlockSuppression,
60 MBlockExpectRace,
61 MBlockSignal,
62 MBlockJmpBuf,
63
64 // This must be the last.
65 MBlockTypeCount
66 };
67
68 // For internal data structures.
69 void *internal_alloc(MBlockType typ, uptr sz);
70 void internal_free(void *p);
71
72 template<typename T>
DestroyAndFree(T * & p)73 void DestroyAndFree(T *&p) {
74 p->~T();
75 internal_free(p);
76 p = 0;
77 }
78
79 } // namespace __tsan
80 #endif // TSAN_MMAN_H
81