]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/xray/xray_log_interface.cc
Upgrade our copies of clang, llvm, lld and lldb to r309439 from the
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / xray / xray_log_interface.cc
1 //===-- xray_log_interface.cc ---------------------------------------------===//
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 XRay, a function call tracing system.
11 //
12 //===----------------------------------------------------------------------===//
13 #include "xray/xray_log_interface.h"
14
15 #include "sanitizer_common/sanitizer_atomic.h"
16 #include "sanitizer_common/sanitizer_mutex.h"
17 #include "xray/xray_interface.h"
18 #include "xray_defs.h"
19
20 #include <memory>
21
22 __sanitizer::SpinMutex XRayImplMutex;
23 std::unique_ptr<XRayLogImpl> GlobalXRayImpl;
24
25 void __xray_set_log_impl(XRayLogImpl Impl) XRAY_NEVER_INSTRUMENT {
26   if (Impl.log_init == nullptr || Impl.log_finalize == nullptr ||
27       Impl.handle_arg0 == nullptr || Impl.flush_log == nullptr) {
28     __sanitizer::SpinMutexLock Guard(&XRayImplMutex);
29     GlobalXRayImpl.reset();
30     __xray_remove_handler();
31     __xray_remove_handler_arg1();
32     return;
33   }
34
35   __sanitizer::SpinMutexLock Guard(&XRayImplMutex);
36   GlobalXRayImpl.reset(new XRayLogImpl);
37   *GlobalXRayImpl = Impl;
38   __xray_set_handler(Impl.handle_arg0);
39 }
40
41 void __xray_remove_log_impl() XRAY_NEVER_INSTRUMENT {
42   __sanitizer::SpinMutexLock Guard(&XRayImplMutex);
43   GlobalXRayImpl.reset();
44   __xray_remove_handler();
45   __xray_remove_handler_arg1();
46 }
47
48 XRayLogInitStatus __xray_log_init(size_t BufferSize, size_t MaxBuffers,
49                                   void *Args,
50                                   size_t ArgsSize) XRAY_NEVER_INSTRUMENT {
51   __sanitizer::SpinMutexLock Guard(&XRayImplMutex);
52   if (!GlobalXRayImpl)
53     return XRayLogInitStatus::XRAY_LOG_UNINITIALIZED;
54   return GlobalXRayImpl->log_init(BufferSize, MaxBuffers, Args, ArgsSize);
55 }
56
57 XRayLogInitStatus __xray_log_finalize() XRAY_NEVER_INSTRUMENT {
58   __sanitizer::SpinMutexLock Guard(&XRayImplMutex);
59   if (!GlobalXRayImpl)
60     return XRayLogInitStatus::XRAY_LOG_UNINITIALIZED;
61   return GlobalXRayImpl->log_finalize();
62 }
63
64 XRayLogFlushStatus __xray_log_flushLog() XRAY_NEVER_INSTRUMENT {
65   __sanitizer::SpinMutexLock Guard(&XRayImplMutex);
66   if (!GlobalXRayImpl)
67     return XRayLogFlushStatus::XRAY_LOG_NOT_FLUSHING;
68   return GlobalXRayImpl->flush_log();
69 }