1 //===-- tsan_mman.h ---------------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file is a part of ThreadSanitizer (TSan), a race detector.
11 //===----------------------------------------------------------------------===//
15 #include "tsan_defs.h"
19 const uptr kDefaultAlignment
= 16;
21 void InitializeAllocator();
22 void InitializeAllocatorLate();
23 void ReplaceSystemMalloc();
24 void AllocatorProcStart(Processor
*proc
);
25 void AllocatorProcFinish(Processor
*proc
);
26 void AllocatorPrintStats();
28 void AllocatorUnlock();
29 void GlobalProcessorLock();
30 void GlobalProcessorUnlock();
32 // For user allocations.
33 void *user_alloc_internal(ThreadState
*thr
, uptr pc
, uptr sz
,
34 uptr align
= kDefaultAlignment
, bool signal
= true);
35 // Does not accept NULL.
36 void user_free(ThreadState
*thr
, uptr pc
, void *p
, bool signal
= true);
37 // Interceptor implementations.
38 void *user_alloc(ThreadState
*thr
, uptr pc
, uptr sz
);
39 void *user_calloc(ThreadState
*thr
, uptr pc
, uptr sz
, uptr n
);
40 void *user_realloc(ThreadState
*thr
, uptr pc
, void *p
, uptr sz
);
41 void *user_reallocarray(ThreadState
*thr
, uptr pc
, void *p
, uptr sz
, uptr n
);
42 void *user_memalign(ThreadState
*thr
, uptr pc
, uptr align
, uptr sz
);
43 int user_posix_memalign(ThreadState
*thr
, uptr pc
, void **memptr
, uptr align
,
45 void *user_aligned_alloc(ThreadState
*thr
, uptr pc
, uptr align
, uptr sz
);
46 void *user_valloc(ThreadState
*thr
, uptr pc
, uptr sz
);
47 void *user_pvalloc(ThreadState
*thr
, uptr pc
, uptr sz
);
48 uptr
user_alloc_usable_size(const void *p
);
50 // Invoking malloc/free hooks that may be installed by the user.
51 void invoke_malloc_hook(void *ptr
, uptr size
);
52 void invoke_free_hook(void *ptr
);
54 // For internal data structures.
56 void FreeImpl(void *p
);
58 template <typename T
, typename
... Args
>
59 T
*New(Args
&&...args
) {
60 return new (Alloc(sizeof(T
))) T(static_cast<Args
&&>(args
)...);
72 void DestroyAndFree(T
*&p
) {