xref: /netbsd-src/external/gpl3/gcc/dist/libsanitizer/tsan/tsan_mman.h (revision b1bb3099bf4d47bbe8c7be5b78240a535263771f)
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 AllocatorThreadStart(ThreadState *thr);
22 void AllocatorThreadFinish(ThreadState *thr);
23 void AllocatorPrintStats();
24 
25 // For user allocations.
26 void *user_alloc(ThreadState *thr, uptr pc, uptr sz,
27                  uptr align = kDefaultAlignment);
28 // Does not accept NULL.
29 void user_free(ThreadState *thr, uptr pc, void *p);
30 void *user_realloc(ThreadState *thr, uptr pc, void *p, uptr sz);
31 void *user_alloc_aligned(ThreadState *thr, uptr pc, uptr sz, uptr align);
32 // Given the pointer p into a valid allocated block,
33 // returns the descriptor of the block.
34 MBlock *user_mblock(ThreadState *thr, 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   MBlockFD,
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>
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