Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 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 | |
Dmitry Vyukov | 2e87051 | 2012-08-15 15:35:15 +0000 | [diff] [blame] | 20 | const uptr kDefaultAlignment = 16; |
| 21 | |
| 22 | void InitializeAllocator(); |
Dmitry Vyukov | bdd844c | 2013-01-24 09:08:03 +0000 | [diff] [blame] | 23 | void AllocatorThreadStart(ThreadState *thr); |
| 24 | void AllocatorThreadFinish(ThreadState *thr); |
| 25 | void AllocatorPrintStats(); |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 26 | |
| 27 | // For user allocations. |
Dmitry Vyukov | 2e87051 | 2012-08-15 15:35:15 +0000 | [diff] [blame] | 28 | void *user_alloc(ThreadState *thr, uptr pc, uptr sz, |
| 29 | uptr align = kDefaultAlignment); |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 30 | // Does not accept NULL. |
| 31 | void user_free(ThreadState *thr, uptr pc, void *p); |
| 32 | void *user_realloc(ThreadState *thr, uptr pc, void *p, uptr sz); |
| 33 | void *user_alloc_aligned(ThreadState *thr, uptr pc, uptr sz, uptr align); |
Alexey Samsonov | 8a6b5e5 | 2013-02-25 08:43:10 +0000 | [diff] [blame] | 34 | uptr user_alloc_usable_size(ThreadState *thr, uptr pc, void *p); |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 35 | // Given the pointer p into a valid allocated block, |
| 36 | // returns the descriptor of the block. |
| 37 | MBlock *user_mblock(ThreadState *thr, void *p); |
| 38 | |
Alexey Samsonov | 4f0ea39 | 2012-09-24 13:19:47 +0000 | [diff] [blame] | 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 | |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 43 | enum MBlockType { |
| 44 | MBlockScopedBuf, |
| 45 | MBlockString, |
| 46 | MBlockStackTrace, |
Dmitry Vyukov | 25d1c79 | 2012-07-16 16:44:47 +0000 | [diff] [blame] | 47 | MBlockShadowStack, |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 48 | MBlockSync, |
| 49 | MBlockClock, |
| 50 | MBlockThreadContex, |
Dmitry Vyukov | 9d2ffc2 | 2012-05-22 14:34:43 +0000 | [diff] [blame] | 51 | MBlockDeadInfo, |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 52 | MBlockRacyStacks, |
| 53 | MBlockRacyAddresses, |
| 54 | MBlockAtExit, |
| 55 | MBlockFlag, |
| 56 | MBlockReport, |
| 57 | MBlockReportMop, |
| 58 | MBlockReportThread, |
| 59 | MBlockReportMutex, |
| 60 | MBlockReportLoc, |
| 61 | MBlockReportStack, |
| 62 | MBlockSuppression, |
| 63 | MBlockExpectRace, |
Dmitry Vyukov | e963666 | 2012-06-27 16:05:06 +0000 | [diff] [blame] | 64 | MBlockSignal, |
Dmitry Vyukov | c78839f | 2012-12-12 11:59:30 +0000 | [diff] [blame] | 65 | MBlockFD, |
Dmitry Vyukov | 8b30c25 | 2013-03-25 10:10:44 +0000 | [diff] [blame] | 66 | MBlockJmpBuf, |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 67 | |
| 68 | // This must be the last. |
Alexey Samsonov | 2135d8a | 2012-09-13 11:54:41 +0000 | [diff] [blame] | 69 | MBlockTypeCount |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | // For internal data structures. |
| 73 | void *internal_alloc(MBlockType typ, uptr sz); |
| 74 | void internal_free(void *p); |
| 75 | |
| 76 | template<typename T> |
| 77 | void DestroyAndFree(T *&p) { |
| 78 | p->~T(); |
| 79 | internal_free(p); |
| 80 | p = 0; |
| 81 | } |
| 82 | |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 83 | } // namespace __tsan |
| 84 | #endif // TSAN_MMAN_H |