1 //===-- xray_log_interface.cc ---------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file is a part of XRay, a function call tracing system.
12 //===----------------------------------------------------------------------===//
13 #include "xray/xray_log_interface.h"
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"
22 __sanitizer::SpinMutex XRayImplMutex;
23 std::unique_ptr<XRayLogImpl> GlobalXRayImpl;
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();
35 __sanitizer::SpinMutexLock Guard(&XRayImplMutex);
36 GlobalXRayImpl.reset(new XRayLogImpl);
37 *GlobalXRayImpl = Impl;
38 __xray_set_handler(Impl.handle_arg0);
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();
48 XRayLogInitStatus __xray_log_init(size_t BufferSize, size_t MaxBuffers,
50 size_t ArgsSize) XRAY_NEVER_INSTRUMENT {
51 __sanitizer::SpinMutexLock Guard(&XRayImplMutex);
53 return XRayLogInitStatus::XRAY_LOG_UNINITIALIZED;
54 return GlobalXRayImpl->log_init(BufferSize, MaxBuffers, Args, ArgsSize);
57 XRayLogInitStatus __xray_log_finalize() XRAY_NEVER_INSTRUMENT {
58 __sanitizer::SpinMutexLock Guard(&XRayImplMutex);
60 return XRayLogInitStatus::XRAY_LOG_UNINITIALIZED;
61 return GlobalXRayImpl->log_finalize();
64 XRayLogFlushStatus __xray_log_flushLog() XRAY_NEVER_INSTRUMENT {
65 __sanitizer::SpinMutexLock Guard(&XRayImplMutex);
67 return XRayLogFlushStatus::XRAY_LOG_NOT_FLUSHING;
68 return GlobalXRayImpl->flush_log();