blob: 5ff956d827f664b580286847e077e93ad4ad185c [file] [log] [blame]
Kostya Serebryany7ac41482012-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 Vyukov2e870512012-08-15 15:35:15 +000020const uptr kDefaultAlignment = 16;
21
22void InitializeAllocator();
Dmitry Vyukovbdd844c2013-01-24 09:08:03 +000023void AllocatorThreadStart(ThreadState *thr);
24void AllocatorThreadFinish(ThreadState *thr);
25void AllocatorPrintStats();
Kostya Serebryany7ac41482012-05-10 13:48:04 +000026
27// For user allocations.
Dmitry Vyukov2e870512012-08-15 15:35:15 +000028void *user_alloc(ThreadState *thr, uptr pc, uptr sz,
Stephen Hines6d186232014-11-26 17:56:19 -080029 uptr align = kDefaultAlignment, bool signal = true);
Stephen Hines86277eb2015-03-23 12:06:32 -070030void *user_calloc(ThreadState *thr, uptr pc, uptr sz, uptr n);
Kostya Serebryany7ac41482012-05-10 13:48:04 +000031// Does not accept NULL.
Stephen Hines6d186232014-11-26 17:56:19 -080032void user_free(ThreadState *thr, uptr pc, void *p, bool signal = true);
Kostya Serebryany7ac41482012-05-10 13:48:04 +000033void *user_realloc(ThreadState *thr, uptr pc, void *p, uptr sz);
34void *user_alloc_aligned(ThreadState *thr, uptr pc, uptr sz, uptr align);
Stephen Hines6a211c52014-07-21 00:49:56 -070035uptr user_alloc_usable_size(const void *p);
Kostya Serebryany7ac41482012-05-10 13:48:04 +000036
Alexey Samsonov4f0ea392012-09-24 13:19:47 +000037// Invoking malloc/free hooks that may be installed by the user.
38void invoke_malloc_hook(void *ptr, uptr size);
39void invoke_free_hook(void *ptr);
40
Kostya Serebryany7ac41482012-05-10 13:48:04 +000041enum MBlockType {
42 MBlockScopedBuf,
43 MBlockString,
44 MBlockStackTrace,
Dmitry Vyukov25d1c792012-07-16 16:44:47 +000045 MBlockShadowStack,
Kostya Serebryany7ac41482012-05-10 13:48:04 +000046 MBlockSync,
47 MBlockClock,
48 MBlockThreadContex,
Dmitry Vyukov9d2ffc22012-05-22 14:34:43 +000049 MBlockDeadInfo,
Kostya Serebryany7ac41482012-05-10 13:48:04 +000050 MBlockRacyStacks,
51 MBlockRacyAddresses,
52 MBlockAtExit,
53 MBlockFlag,
54 MBlockReport,
55 MBlockReportMop,
56 MBlockReportThread,
57 MBlockReportMutex,
58 MBlockReportLoc,
59 MBlockReportStack,
60 MBlockSuppression,
61 MBlockExpectRace,
Dmitry Vyukove9636662012-06-27 16:05:06 +000062 MBlockSignal,
Dmitry Vyukov8b30c252013-03-25 10:10:44 +000063 MBlockJmpBuf,
Kostya Serebryany7ac41482012-05-10 13:48:04 +000064
65 // This must be the last.
Alexey Samsonov2135d8a2012-09-13 11:54:41 +000066 MBlockTypeCount
Kostya Serebryany7ac41482012-05-10 13:48:04 +000067};
68
69// For internal data structures.
70void *internal_alloc(MBlockType typ, uptr sz);
71void internal_free(void *p);
72
73template<typename T>
74void DestroyAndFree(T *&p) {
75 p->~T();
76 internal_free(p);
77 p = 0;
78}
79
Kostya Serebryany7ac41482012-05-10 13:48:04 +000080} // namespace __tsan
81#endif // TSAN_MMAN_H