1353944Sdim//===-- tsan_rtl_proc.cpp -----------------------------------------------===// 2353944Sdim// 3353944Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4353944Sdim// See https://llvm.org/LICENSE.txt for license information. 5353944Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6353944Sdim// 7353944Sdim//===----------------------------------------------------------------------===// 8353944Sdim// 9353944Sdim// This file is a part of ThreadSanitizer (TSan), a race detector. 10353944Sdim// 11353944Sdim//===----------------------------------------------------------------------===// 12353944Sdim 13353944Sdim#include "sanitizer_common/sanitizer_placement_new.h" 14353944Sdim#include "tsan_rtl.h" 15353944Sdim#include "tsan_mman.h" 16353944Sdim#include "tsan_flags.h" 17353944Sdim 18353944Sdimnamespace __tsan { 19353944Sdim 20353944SdimProcessor *ProcCreate() { 21353944Sdim void *mem = InternalAlloc(sizeof(Processor)); 22353944Sdim internal_memset(mem, 0, sizeof(Processor)); 23353944Sdim Processor *proc = new(mem) Processor; 24353944Sdim proc->thr = nullptr; 25353944Sdim#if !SANITIZER_GO 26353944Sdim AllocatorProcStart(proc); 27353944Sdim#endif 28353944Sdim if (common_flags()->detect_deadlocks) 29353944Sdim proc->dd_pt = ctx->dd->CreatePhysicalThread(); 30353944Sdim return proc; 31353944Sdim} 32353944Sdim 33353944Sdimvoid ProcDestroy(Processor *proc) { 34353944Sdim CHECK_EQ(proc->thr, nullptr); 35353944Sdim#if !SANITIZER_GO 36353944Sdim AllocatorProcFinish(proc); 37353944Sdim#endif 38353944Sdim ctx->clock_alloc.FlushCache(&proc->clock_cache); 39353944Sdim ctx->metamap.OnProcIdle(proc); 40353944Sdim if (common_flags()->detect_deadlocks) 41353944Sdim ctx->dd->DestroyPhysicalThread(proc->dd_pt); 42353944Sdim proc->~Processor(); 43353944Sdim InternalFree(proc); 44353944Sdim} 45353944Sdim 46353944Sdimvoid ProcWire(Processor *proc, ThreadState *thr) { 47353944Sdim CHECK_EQ(thr->proc1, nullptr); 48353944Sdim CHECK_EQ(proc->thr, nullptr); 49353944Sdim thr->proc1 = proc; 50353944Sdim proc->thr = thr; 51353944Sdim} 52353944Sdim 53353944Sdimvoid ProcUnwire(Processor *proc, ThreadState *thr) { 54353944Sdim CHECK_EQ(thr->proc1, proc); 55353944Sdim CHECK_EQ(proc->thr, thr); 56353944Sdim thr->proc1 = nullptr; 57353944Sdim proc->thr = nullptr; 58353944Sdim} 59353944Sdim 60353944Sdim} // namespace __tsan 61