Kostya Serebryany | 4ad375f | 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 | 954fc8c | 2012-08-15 15:35:15 +0000 | [diff] [blame] | 20 | const uptr kDefaultAlignment = 16; |
| 21 | |
| 22 | void InitializeAllocator(); |
Dmitry Vyukov | 6e406cd | 2013-01-24 09:08:03 +0000 | [diff] [blame^] | 23 | void AllocatorThreadStart(ThreadState *thr); |
| 24 | void AllocatorThreadFinish(ThreadState *thr); |
| 25 | void AllocatorPrintStats(); |
Kostya Serebryany | 4ad375f | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 26 | |
| 27 | // For user allocations. |
Dmitry Vyukov | 954fc8c | 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 | 4ad375f | 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); |
| 34 | // Given the pointer p into a valid allocated block, |
| 35 | // returns the descriptor of the block. |
| 36 | MBlock *user_mblock(ThreadState *thr, void *p); |
| 37 | |
Alexey Samsonov | 3130146 | 2012-09-24 13:19:47 +0000 | [diff] [blame] | 38 | // Invoking malloc/free hooks that may be installed by the user. |
| 39 | void invoke_malloc_hook(void *ptr, uptr size); |
| 40 | void invoke_free_hook(void *ptr); |
| 41 | |
Kostya Serebryany | 4ad375f | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 42 | enum MBlockType { |
| 43 | MBlockScopedBuf, |
| 44 | MBlockString, |
| 45 | MBlockStackTrace, |
Dmitry Vyukov | 5bfac97 | 2012-07-16 16:44:47 +0000 | [diff] [blame] | 46 | MBlockShadowStack, |
Kostya Serebryany | 4ad375f | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 47 | MBlockSync, |
| 48 | MBlockClock, |
| 49 | MBlockThreadContex, |
Dmitry Vyukov | f6985e3 | 2012-05-22 14:34:43 +0000 | [diff] [blame] | 50 | MBlockDeadInfo, |
Kostya Serebryany | 4ad375f | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 51 | MBlockRacyStacks, |
| 52 | MBlockRacyAddresses, |
| 53 | MBlockAtExit, |
| 54 | MBlockFlag, |
| 55 | MBlockReport, |
| 56 | MBlockReportMop, |
| 57 | MBlockReportThread, |
| 58 | MBlockReportMutex, |
| 59 | MBlockReportLoc, |
| 60 | MBlockReportStack, |
| 61 | MBlockSuppression, |
| 62 | MBlockExpectRace, |
Dmitry Vyukov | 97c26bd | 2012-06-27 16:05:06 +0000 | [diff] [blame] | 63 | MBlockSignal, |
Dmitry Vyukov | 60c14ce | 2012-12-12 11:59:30 +0000 | [diff] [blame] | 64 | MBlockFD, |
Kostya Serebryany | 4ad375f | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 65 | |
| 66 | // This must be the last. |
Alexey Samsonov | 046248c | 2012-09-13 11:54:41 +0000 | [diff] [blame] | 67 | MBlockTypeCount |
Kostya Serebryany | 4ad375f | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | // For internal data structures. |
| 71 | void *internal_alloc(MBlockType typ, uptr sz); |
| 72 | void internal_free(void *p); |
| 73 | |
| 74 | template<typename T> |
| 75 | void DestroyAndFree(T *&p) { |
| 76 | p->~T(); |
| 77 | internal_free(p); |
| 78 | p = 0; |
| 79 | } |
| 80 | |
Kostya Serebryany | 4ad375f | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 81 | } // namespace __tsan |
| 82 | #endif // TSAN_MMAN_H |