blob: 19d555437f3ec1f9ae7d04b7ac3df2cf834b5ea8 [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,
29 uptr align = kDefaultAlignment);
Kostya Serebryany7ac41482012-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 Samsonov8a6b5e52013-02-25 08:43:10 +000034uptr user_alloc_usable_size(ThreadState *thr, uptr pc, void *p);
Kostya Serebryany7ac41482012-05-10 13:48:04 +000035// Given the pointer p into a valid allocated block,
36// returns the descriptor of the block.
37MBlock *user_mblock(ThreadState *thr, void *p);
38
Alexey Samsonov4f0ea392012-09-24 13:19:47 +000039// Invoking malloc/free hooks that may be installed by the user.
40void invoke_malloc_hook(void *ptr, uptr size);
41void invoke_free_hook(void *ptr);
42
Kostya Serebryany7ac41482012-05-10 13:48:04 +000043enum MBlockType {
44 MBlockScopedBuf,
45 MBlockString,
46 MBlockStackTrace,
Dmitry Vyukov25d1c792012-07-16 16:44:47 +000047 MBlockShadowStack,
Kostya Serebryany7ac41482012-05-10 13:48:04 +000048 MBlockSync,
49 MBlockClock,
50 MBlockThreadContex,
Dmitry Vyukov9d2ffc22012-05-22 14:34:43 +000051 MBlockDeadInfo,
Kostya Serebryany7ac41482012-05-10 13:48:04 +000052 MBlockRacyStacks,
53 MBlockRacyAddresses,
54 MBlockAtExit,
55 MBlockFlag,
56 MBlockReport,
57 MBlockReportMop,
58 MBlockReportThread,
59 MBlockReportMutex,
60 MBlockReportLoc,
61 MBlockReportStack,
62 MBlockSuppression,
63 MBlockExpectRace,
Dmitry Vyukove9636662012-06-27 16:05:06 +000064 MBlockSignal,
Dmitry Vyukovc78839f2012-12-12 11:59:30 +000065 MBlockFD,
Dmitry Vyukov8b30c252013-03-25 10:10:44 +000066 MBlockJmpBuf,
Kostya Serebryany7ac41482012-05-10 13:48:04 +000067
68 // This must be the last.
Alexey Samsonov2135d8a2012-09-13 11:54:41 +000069 MBlockTypeCount
Kostya Serebryany7ac41482012-05-10 13:48:04 +000070};
71
72// For internal data structures.
73void *internal_alloc(MBlockType typ, uptr sz);
74void internal_free(void *p);
75
76template<typename T>
77void DestroyAndFree(T *&p) {
78 p->~T();
79 internal_free(p);
80 p = 0;
81}
82
Kostya Serebryany7ac41482012-05-10 13:48:04 +000083} // namespace __tsan
84#endif // TSAN_MMAN_H