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, |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 29 | uptr align = kDefaultAlignment, bool signal = true); |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 30 | void *user_calloc(ThreadState *thr, uptr pc, uptr sz, uptr n); |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 31 | // Does not accept NULL. |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 32 | void user_free(ThreadState *thr, uptr pc, void *p, bool signal = true); |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 33 | void *user_realloc(ThreadState *thr, uptr pc, void *p, uptr sz); |
| 34 | void *user_alloc_aligned(ThreadState *thr, uptr pc, uptr sz, uptr align); |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 35 | uptr user_alloc_usable_size(const void *p); |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 36 | |
Alexey Samsonov | 4f0ea39 | 2012-09-24 13:19:47 +0000 | [diff] [blame] | 37 | // Invoking malloc/free hooks that may be installed by the user. |
| 38 | void invoke_malloc_hook(void *ptr, uptr size); |
| 39 | void invoke_free_hook(void *ptr); |
| 40 | |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 41 | enum MBlockType { |
| 42 | MBlockScopedBuf, |
| 43 | MBlockString, |
| 44 | MBlockStackTrace, |
Dmitry Vyukov | 25d1c79 | 2012-07-16 16:44:47 +0000 | [diff] [blame] | 45 | MBlockShadowStack, |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 46 | MBlockSync, |
| 47 | MBlockClock, |
| 48 | MBlockThreadContex, |
Dmitry Vyukov | 9d2ffc2 | 2012-05-22 14:34:43 +0000 | [diff] [blame] | 49 | MBlockDeadInfo, |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 50 | MBlockRacyStacks, |
| 51 | MBlockRacyAddresses, |
| 52 | MBlockAtExit, |
| 53 | MBlockFlag, |
| 54 | MBlockReport, |
| 55 | MBlockReportMop, |
| 56 | MBlockReportThread, |
| 57 | MBlockReportMutex, |
| 58 | MBlockReportLoc, |
| 59 | MBlockReportStack, |
| 60 | MBlockSuppression, |
| 61 | MBlockExpectRace, |
Dmitry Vyukov | e963666 | 2012-06-27 16:05:06 +0000 | [diff] [blame] | 62 | MBlockSignal, |
Dmitry Vyukov | 8b30c25 | 2013-03-25 10:10:44 +0000 | [diff] [blame] | 63 | MBlockJmpBuf, |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 64 | |
| 65 | // This must be the last. |
Alexey Samsonov | 2135d8a | 2012-09-13 11:54:41 +0000 | [diff] [blame] | 66 | MBlockTypeCount |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | // For internal data structures. |
| 70 | void *internal_alloc(MBlockType typ, uptr sz); |
| 71 | void internal_free(void *p); |
| 72 | |
| 73 | template<typename T> |
| 74 | void DestroyAndFree(T *&p) { |
| 75 | p->~T(); |
| 76 | internal_free(p); |
| 77 | p = 0; |
| 78 | } |
| 79 | |
Kostya Serebryany | 7ac4148 | 2012-05-10 13:48:04 +0000 | [diff] [blame] | 80 | } // namespace __tsan |
| 81 | #endif // TSAN_MMAN_H |