blob: 4f87ad6e4e1aec598bd325a4f24118aa1c3a0f15 [file] [log] [blame]
Kostya Serebryany4ad375f2012-05-10 13:48:04 +00001//===-- 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
18namespace __tsan {
19
Dmitry Vyukov954fc8c2012-08-15 15:35:15 +000020const uptr kDefaultAlignment = 16;
21
22void InitializeAllocator();
Dmitry Vyukov6e406cd2013-01-24 09:08:03 +000023void AllocatorThreadStart(ThreadState *thr);
24void AllocatorThreadFinish(ThreadState *thr);
25void AllocatorPrintStats();
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000026
27// For user allocations.
Dmitry Vyukov954fc8c2012-08-15 15:35:15 +000028void *user_alloc(ThreadState *thr, uptr pc, uptr sz,
29 uptr align = kDefaultAlignment);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000030// Does not accept NULL.
31void user_free(ThreadState *thr, uptr pc, void *p);
32void *user_realloc(ThreadState *thr, uptr pc, void *p, uptr sz);
33void *user_alloc_aligned(ThreadState *thr, uptr pc, uptr sz, uptr align);
Alexey Samsonov91bb8e02014-07-07 17:39:31 +000034uptr user_alloc_usable_size(const void *p);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000035
Alexey Samsonov31301462012-09-24 13:19:47 +000036// Invoking malloc/free hooks that may be installed by the user.
37void invoke_malloc_hook(void *ptr, uptr size);
38void invoke_free_hook(void *ptr);
39
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000040enum MBlockType {
41 MBlockScopedBuf,
42 MBlockString,
43 MBlockStackTrace,
Dmitry Vyukov5bfac972012-07-16 16:44:47 +000044 MBlockShadowStack,
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000045 MBlockSync,
46 MBlockClock,
47 MBlockThreadContex,
Dmitry Vyukovf6985e32012-05-22 14:34:43 +000048 MBlockDeadInfo,
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000049 MBlockRacyStacks,
50 MBlockRacyAddresses,
51 MBlockAtExit,
52 MBlockFlag,
53 MBlockReport,
54 MBlockReportMop,
55 MBlockReportThread,
56 MBlockReportMutex,
57 MBlockReportLoc,
58 MBlockReportStack,
59 MBlockSuppression,
60 MBlockExpectRace,
Dmitry Vyukov97c26bd2012-06-27 16:05:06 +000061 MBlockSignal,
Dmitry Vyukov4adf49d2013-03-25 10:10:44 +000062 MBlockJmpBuf,
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000063
64 // This must be the last.
Alexey Samsonov046248c2012-09-13 11:54:41 +000065 MBlockTypeCount
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000066};
67
68// For internal data structures.
69void *internal_alloc(MBlockType typ, uptr sz);
70void internal_free(void *p);
71
72template<typename T>
73void DestroyAndFree(T *&p) {
74 p->~T();
75 internal_free(p);
76 p = 0;
77}
78
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000079} // namespace __tsan
80#endif // TSAN_MMAN_H