• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 InitializeAllocatorLate();
24 void ReplaceSystemMalloc();
25 void AllocatorProcStart(Processor *proc);
26 void AllocatorProcFinish(Processor *proc);
27 void AllocatorPrintStats();
28 
29 // For user allocations.
30 void *user_alloc(ThreadState *thr, uptr pc, uptr sz,
31                  uptr align = kDefaultAlignment, bool signal = true);
32 void *user_calloc(ThreadState *thr, uptr pc, uptr sz, uptr n);
33 // Does not accept NULL.
34 void user_free(ThreadState *thr, uptr pc, void *p, bool signal = true);
35 void *user_realloc(ThreadState *thr, uptr pc, void *p, uptr sz);
36 void *user_alloc_aligned(ThreadState *thr, uptr pc, uptr sz, uptr align);
37 uptr user_alloc_usable_size(const 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   MBlockJmpBuf,
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