Path: blob/main/contrib/llvm-project/compiler-rt/lib/tsan/rtl/tsan_mman.h
35269 views
//===-- tsan_mman.h ---------------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file is a part of ThreadSanitizer (TSan), a race detector.9//10//===----------------------------------------------------------------------===//11#ifndef TSAN_MMAN_H12#define TSAN_MMAN_H1314#include "tsan_defs.h"1516namespace __tsan {1718const uptr kDefaultAlignment = 16;1920void InitializeAllocator();21void InitializeAllocatorLate();22void ReplaceSystemMalloc();23void AllocatorProcStart(Processor *proc);24void AllocatorProcFinish(Processor *proc);25void AllocatorPrintStats();26void AllocatorLockBeforeFork();27void AllocatorUnlockAfterFork(bool child);28void GlobalProcessorLock();29void GlobalProcessorUnlock();3031// For user allocations.32void *user_alloc_internal(ThreadState *thr, uptr pc, uptr sz,33uptr align = kDefaultAlignment, bool signal = true);34// Does not accept NULL.35void user_free(ThreadState *thr, uptr pc, void *p, bool signal = true);36// Interceptor implementations.37void *user_alloc(ThreadState *thr, uptr pc, uptr sz);38void *user_calloc(ThreadState *thr, uptr pc, uptr sz, uptr n);39void *user_realloc(ThreadState *thr, uptr pc, void *p, uptr sz);40void *user_reallocarray(ThreadState *thr, uptr pc, void *p, uptr sz, uptr n);41void *user_memalign(ThreadState *thr, uptr pc, uptr align, uptr sz);42int user_posix_memalign(ThreadState *thr, uptr pc, void **memptr, uptr align,43uptr sz);44void *user_aligned_alloc(ThreadState *thr, uptr pc, uptr align, uptr sz);45void *user_valloc(ThreadState *thr, uptr pc, uptr sz);46void *user_pvalloc(ThreadState *thr, uptr pc, uptr sz);47uptr user_alloc_usable_size(const void *p);4849// Invoking malloc/free hooks that may be installed by the user.50void invoke_malloc_hook(void *ptr, uptr size);51void invoke_free_hook(void *ptr);5253// For internal data structures.54void *Alloc(uptr sz);55void FreeImpl(void *p);5657template <typename T, typename... Args>58T *New(Args &&...args) {59return new (Alloc(sizeof(T))) T(static_cast<Args &&>(args)...);60}6162template <typename T>63void Free(T *&p) {64if (p == nullptr)65return;66FreeImpl(p);67p = nullptr;68}6970template <typename T>71void DestroyAndFree(T *&p) {72if (p == nullptr)73return;74p->~T();75Free(p);76}7778} // namespace __tsan79#endif // TSAN_MMAN_H808182