]> git.proxmox.com Git - rustc.git/blob - src/libcompiler_builtins/compiler-rt/lib/esan/esan_sideline.h
New upstream version 1.25.0+dfsg1
[rustc.git] / src / libcompiler_builtins / compiler-rt / lib / esan / esan_sideline.h
1 //===-- esan_sideline.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 EfficiencySanitizer, a family of performance tuners.
11 //
12 // Esan sideline thread support.
13 //===----------------------------------------------------------------------===//
14
15 #ifndef ESAN_SIDELINE_H
16 #define ESAN_SIDELINE_H
17
18 #include "sanitizer_common/sanitizer_atomic.h"
19 #include "sanitizer_common/sanitizer_internal_defs.h"
20 #include "sanitizer_common/sanitizer_platform_limits_posix.h"
21
22 namespace __esan {
23
24 typedef void (*SidelineFunc)(void *Arg);
25
26 // Currently only one sideline thread is supported.
27 // It calls the SidelineFunc passed to launchThread once on each sample at the
28 // given frequency in real time (i.e., wall clock time).
29 class SidelineThread {
30 public:
31 // We cannot initialize any fields in the constructor as it will be called
32 // *after* launchThread for a static instance, as esan.module_ctor is called
33 // before static initializers.
34 SidelineThread() {}
35 ~SidelineThread() {}
36
37 // To simplify declaration in sanitizer code where we want to avoid
38 // heap allocations, the constructor and destructor do nothing and
39 // launchThread and joinThread do the real work.
40 // They should each be called just once.
41 bool launchThread(SidelineFunc takeSample, void *Arg, u32 FreqMilliSec);
42 bool joinThread();
43
44 // Must be called from the sideline thread itself.
45 bool adjustTimer(u32 FreqMilliSec);
46
47 private:
48 static int runSideline(void *Arg);
49 static void registerSignal(int SigNum);
50 static void handleSidelineSignal(int SigNum, __sanitizer_siginfo *SigInfo,
51 void *Ctx);
52
53 char *Stack;
54 SidelineFunc sampleFunc;
55 void *FuncArg;
56 u32 Freq;
57 uptr SidelineId;
58 atomic_uintptr_t SidelineExit;
59 };
60
61 } // namespace __esan
62
63 #endif // ESAN_SIDELINE_H