1*68d75effSDimitry Andric //===-- tsan_rtl_proc.cpp -----------------------------------------------===//
2*68d75effSDimitry Andric //
3*68d75effSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*68d75effSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*68d75effSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*68d75effSDimitry Andric //
7*68d75effSDimitry Andric //===----------------------------------------------------------------------===//
8*68d75effSDimitry Andric //
9*68d75effSDimitry Andric // This file is a part of ThreadSanitizer (TSan), a race detector.
10*68d75effSDimitry Andric //
11*68d75effSDimitry Andric //===----------------------------------------------------------------------===//
12*68d75effSDimitry Andric
13*68d75effSDimitry Andric #include "sanitizer_common/sanitizer_placement_new.h"
14*68d75effSDimitry Andric #include "tsan_rtl.h"
15*68d75effSDimitry Andric #include "tsan_mman.h"
16*68d75effSDimitry Andric #include "tsan_flags.h"
17*68d75effSDimitry Andric
18*68d75effSDimitry Andric namespace __tsan {
19*68d75effSDimitry Andric
ProcCreate()20*68d75effSDimitry Andric Processor *ProcCreate() {
21*68d75effSDimitry Andric void *mem = InternalAlloc(sizeof(Processor));
22*68d75effSDimitry Andric internal_memset(mem, 0, sizeof(Processor));
23*68d75effSDimitry Andric Processor *proc = new(mem) Processor;
24*68d75effSDimitry Andric proc->thr = nullptr;
25*68d75effSDimitry Andric #if !SANITIZER_GO
26*68d75effSDimitry Andric AllocatorProcStart(proc);
27*68d75effSDimitry Andric #endif
28*68d75effSDimitry Andric if (common_flags()->detect_deadlocks)
29*68d75effSDimitry Andric proc->dd_pt = ctx->dd->CreatePhysicalThread();
30*68d75effSDimitry Andric return proc;
31*68d75effSDimitry Andric }
32*68d75effSDimitry Andric
ProcDestroy(Processor * proc)33*68d75effSDimitry Andric void ProcDestroy(Processor *proc) {
34*68d75effSDimitry Andric CHECK_EQ(proc->thr, nullptr);
35*68d75effSDimitry Andric #if !SANITIZER_GO
36*68d75effSDimitry Andric AllocatorProcFinish(proc);
37*68d75effSDimitry Andric #endif
38*68d75effSDimitry Andric ctx->metamap.OnProcIdle(proc);
39*68d75effSDimitry Andric if (common_flags()->detect_deadlocks)
40*68d75effSDimitry Andric ctx->dd->DestroyPhysicalThread(proc->dd_pt);
41*68d75effSDimitry Andric proc->~Processor();
42*68d75effSDimitry Andric InternalFree(proc);
43*68d75effSDimitry Andric }
44*68d75effSDimitry Andric
ProcWire(Processor * proc,ThreadState * thr)45*68d75effSDimitry Andric void ProcWire(Processor *proc, ThreadState *thr) {
46*68d75effSDimitry Andric CHECK_EQ(thr->proc1, nullptr);
47*68d75effSDimitry Andric CHECK_EQ(proc->thr, nullptr);
48*68d75effSDimitry Andric thr->proc1 = proc;
49*68d75effSDimitry Andric proc->thr = thr;
50*68d75effSDimitry Andric }
51*68d75effSDimitry Andric
ProcUnwire(Processor * proc,ThreadState * thr)52*68d75effSDimitry Andric void ProcUnwire(Processor *proc, ThreadState *thr) {
53*68d75effSDimitry Andric CHECK_EQ(thr->proc1, proc);
54*68d75effSDimitry Andric CHECK_EQ(proc->thr, thr);
55*68d75effSDimitry Andric thr->proc1 = nullptr;
56*68d75effSDimitry Andric proc->thr = nullptr;
57*68d75effSDimitry Andric }
58*68d75effSDimitry Andric
59*68d75effSDimitry Andric } // namespace __tsan
60