forked from OSchip/llvm-project
[XRay][compiler-rt] Remove __sanitizer:: from namespace __xray (NFC)
This is a non-functional change that removes the full qualification of functions in __sanitizer:: being used in __xray. llvm-svn: 333983
This commit is contained in:
parent
8ba925d2c3
commit
5eaaff6095
|
@ -160,7 +160,7 @@ TEST(FDRLoggingTest, MultiThreadedCycling) {
|
|||
std::thread t{[I, &Threads] {
|
||||
fdrLoggingHandleArg0(I + 1, XRayEntryType::ENTRY);
|
||||
fdrLoggingHandleArg0(I + 1, XRayEntryType::EXIT);
|
||||
Threads[I] = __sanitizer::GetTid();
|
||||
Threads[I] = GetTid();
|
||||
}};
|
||||
t.join();
|
||||
}
|
||||
|
|
|
@ -153,7 +153,7 @@ void threadProcessing() {
|
|||
T.exitFunction(2, 3);
|
||||
T.exitFunction(1, 4);
|
||||
|
||||
profileCollectorService::post(T, __sanitizer::GetTid());
|
||||
profileCollectorService::post(T, GetTid());
|
||||
}
|
||||
|
||||
TEST(profileCollectorServiceTest, PostSerializeCollectMultipleThread) {
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
|
||||
namespace __xray {
|
||||
|
||||
__sanitizer::SpinMutex LogMutex;
|
||||
SpinMutex LogMutex;
|
||||
|
||||
// We use elements of this type to record the entry TSC of every function ID we
|
||||
// see as we're tracing a particular thread's execution.
|
||||
|
@ -66,7 +66,7 @@ struct alignas(64) ThreadLocalData {
|
|||
|
||||
static pthread_key_t PThreadKey;
|
||||
|
||||
static __sanitizer::atomic_uint8_t BasicInitialized{0};
|
||||
static atomic_uint8_t BasicInitialized{0};
|
||||
|
||||
BasicLoggingOptions GlobalOptions;
|
||||
|
||||
|
@ -117,11 +117,11 @@ ThreadLocalData &getThreadLocalData() XRAY_NEVER_INSTRUMENT {
|
|||
thread_local ThreadLocalData TLD;
|
||||
thread_local bool UNUSED TOnce = [] {
|
||||
if (GlobalOptions.ThreadBufferSize == 0) {
|
||||
if (__sanitizer::Verbosity())
|
||||
if (Verbosity())
|
||||
Report("Not initializing TLD since ThreadBufferSize == 0.\n");
|
||||
return false;
|
||||
}
|
||||
TLD.TID = __sanitizer::GetTid();
|
||||
TLD.TID = GetTid();
|
||||
pthread_setspecific(PThreadKey, &TLD);
|
||||
TLD.Fd = getGlobalFd();
|
||||
TLD.InMemoryBuffer = reinterpret_cast<XRayRecord *>(
|
||||
|
@ -130,7 +130,7 @@ ThreadLocalData &getThreadLocalData() XRAY_NEVER_INSTRUMENT {
|
|||
TLD.BufferSize = GlobalOptions.ThreadBufferSize;
|
||||
TLD.BufferOffset = 0;
|
||||
if (GlobalOptions.MaxStackDepth == 0) {
|
||||
if (__sanitizer::Verbosity())
|
||||
if (Verbosity())
|
||||
Report("Not initializing the ShadowStack since MaxStackDepth == 0.\n");
|
||||
TLD.StackSize = 0;
|
||||
TLD.StackEntries = 0;
|
||||
|
@ -142,7 +142,7 @@ ThreadLocalData &getThreadLocalData() XRAY_NEVER_INSTRUMENT {
|
|||
alignof(StackEntry)));
|
||||
TLD.StackSize = GlobalOptions.MaxStackDepth;
|
||||
TLD.StackEntries = 0;
|
||||
if (__sanitizer::Verbosity() >= 2) {
|
||||
if (Verbosity() >= 2) {
|
||||
static auto UNUSED Once = [] {
|
||||
auto ticks = thresholdTicks();
|
||||
Report("Ticks threshold: %d\n", ticks);
|
||||
|
@ -168,7 +168,7 @@ void InMemoryRawLog(int32_t FuncId, XRayEntryType Type,
|
|||
if (RecursionGuard)
|
||||
return;
|
||||
RecursionGuard = true;
|
||||
auto ExitGuard = __sanitizer::at_scope_exit([] { RecursionGuard = false; });
|
||||
auto ExitGuard = at_scope_exit([] { RecursionGuard = false; });
|
||||
|
||||
uint8_t CPU = 0;
|
||||
uint64_t TSC = ReadTSC(CPU);
|
||||
|
@ -189,7 +189,7 @@ void InMemoryRawLog(int32_t FuncId, XRayEntryType Type,
|
|||
E.TSC = TSC;
|
||||
auto StackEntryPtr = static_cast<char *>(TLD.ShadowStack) +
|
||||
(sizeof(StackEntry) * (TLD.StackEntries - 1));
|
||||
__sanitizer::internal_memcpy(StackEntryPtr, &E, sizeof(StackEntry));
|
||||
internal_memcpy(StackEntryPtr, &E, sizeof(StackEntry));
|
||||
break;
|
||||
}
|
||||
case XRayEntryType::EXIT:
|
||||
|
@ -213,7 +213,7 @@ void InMemoryRawLog(int32_t FuncId, XRayEntryType Type,
|
|||
StackEntry StackTop;
|
||||
auto StackEntryPtr = static_cast<char *>(TLD.ShadowStack) +
|
||||
(sizeof(StackEntry) * TLD.StackEntries);
|
||||
__sanitizer::internal_memcpy(&StackTop, StackEntryPtr, sizeof(StackEntry));
|
||||
internal_memcpy(&StackTop, StackEntryPtr, sizeof(StackEntry));
|
||||
if (StackTop.FuncId == FuncId && StackTop.CPU == CPU &&
|
||||
StackTop.TSC < TSC) {
|
||||
auto Delta = TSC - StackTop.TSC;
|
||||
|
@ -241,9 +241,9 @@ void InMemoryRawLog(int32_t FuncId, XRayEntryType Type,
|
|||
R.Type = Type;
|
||||
R.FuncId = FuncId;
|
||||
auto FirstEntry = reinterpret_cast<__xray::XRayRecord *>(TLD.InMemoryBuffer);
|
||||
__sanitizer::internal_memcpy(FirstEntry + TLD.BufferOffset, &R, sizeof(R));
|
||||
internal_memcpy(FirstEntry + TLD.BufferOffset, &R, sizeof(R));
|
||||
if (++TLD.BufferOffset == TLD.BufferSize) {
|
||||
__sanitizer::SpinMutexLock L(&LogMutex);
|
||||
SpinMutexLock L(&LogMutex);
|
||||
retryingWriteAll(Fd, reinterpret_cast<char *>(FirstEntry),
|
||||
reinterpret_cast<char *>(FirstEntry + TLD.BufferOffset));
|
||||
TLD.BufferOffset = 0;
|
||||
|
@ -266,7 +266,7 @@ void InMemoryRawLogWithArg(int32_t FuncId, XRayEntryType Type, uint64_t Arg1,
|
|||
// in the thread-local buffer. If not, we first flush the buffer before
|
||||
// attempting to write the two records that must be consecutive.
|
||||
if (TLD.BufferOffset + 2 > BuffLen) {
|
||||
__sanitizer::SpinMutexLock L(&LogMutex);
|
||||
SpinMutexLock L(&LogMutex);
|
||||
retryingWriteAll(Fd, reinterpret_cast<char *>(FirstEntry),
|
||||
reinterpret_cast<char *>(FirstEntry + TLD.BufferOffset));
|
||||
TLD.BufferOffset = 0;
|
||||
|
@ -279,7 +279,7 @@ void InMemoryRawLogWithArg(int32_t FuncId, XRayEntryType Type, uint64_t Arg1,
|
|||
if (RecursionGuard)
|
||||
return;
|
||||
RecursionGuard = true;
|
||||
auto ExitGuard = __sanitizer::at_scope_exit([] { RecursionGuard = false; });
|
||||
auto ExitGuard = at_scope_exit([] { RecursionGuard = false; });
|
||||
|
||||
// And from here on write the arg payload.
|
||||
__xray::XRayArgPayload R;
|
||||
|
@ -287,9 +287,9 @@ void InMemoryRawLogWithArg(int32_t FuncId, XRayEntryType Type, uint64_t Arg1,
|
|||
R.FuncId = FuncId;
|
||||
R.TId = TLD.TID;
|
||||
R.Arg = Arg1;
|
||||
__sanitizer::internal_memcpy(FirstEntry + TLD.BufferOffset, &R, sizeof(R));
|
||||
internal_memcpy(FirstEntry + TLD.BufferOffset, &R, sizeof(R));
|
||||
if (++TLD.BufferOffset == BuffLen) {
|
||||
__sanitizer::SpinMutexLock L(&LogMutex);
|
||||
SpinMutexLock L(&LogMutex);
|
||||
retryingWriteAll(Fd, reinterpret_cast<char *>(FirstEntry),
|
||||
reinterpret_cast<char *>(FirstEntry + TLD.BufferOffset));
|
||||
TLD.BufferOffset = 0;
|
||||
|
@ -338,25 +338,25 @@ void basicLoggingHandleArg1EmulateTSC(int32_t FuncId, XRayEntryType Type,
|
|||
|
||||
static void TLDDestructor(void *P) XRAY_NEVER_INSTRUMENT {
|
||||
ThreadLocalData &TLD = *reinterpret_cast<ThreadLocalData *>(P);
|
||||
auto ExitGuard = __sanitizer::at_scope_exit([&TLD] {
|
||||
auto ExitGuard = at_scope_exit([&TLD] {
|
||||
// Clean up dynamic resources.
|
||||
if (TLD.InMemoryBuffer)
|
||||
InternalFree(TLD.InMemoryBuffer);
|
||||
if (TLD.ShadowStack)
|
||||
InternalFree(TLD.ShadowStack);
|
||||
if (__sanitizer::Verbosity())
|
||||
if (Verbosity())
|
||||
Report("Cleaned up log for TID: %d\n", TLD.TID);
|
||||
});
|
||||
|
||||
if (TLD.Fd == -1 || TLD.BufferOffset == 0) {
|
||||
if (__sanitizer::Verbosity())
|
||||
if (Verbosity())
|
||||
Report("Skipping buffer for TID: %d; Fd = %d; Offset = %llu\n", TLD.TID,
|
||||
TLD.Fd, TLD.BufferOffset);
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
__sanitizer::SpinMutexLock L(&LogMutex);
|
||||
SpinMutexLock L(&LogMutex);
|
||||
retryingWriteAll(TLD.Fd, reinterpret_cast<char *>(TLD.InMemoryBuffer),
|
||||
reinterpret_cast<char *>(TLD.InMemoryBuffer) +
|
||||
(sizeof(__xray::XRayRecord) * TLD.BufferOffset));
|
||||
|
@ -373,9 +373,9 @@ XRayLogInitStatus basicLoggingInit(size_t BufferSize, size_t BufferMax,
|
|||
void *Options,
|
||||
size_t OptionsSize) XRAY_NEVER_INSTRUMENT {
|
||||
uint8_t Expected = 0;
|
||||
if (!__sanitizer::atomic_compare_exchange_strong(
|
||||
&BasicInitialized, &Expected, 1, __sanitizer::memory_order_acq_rel)) {
|
||||
if (__sanitizer::Verbosity())
|
||||
if (!atomic_compare_exchange_strong(
|
||||
&BasicInitialized, &Expected, 1, memory_order_acq_rel)) {
|
||||
if (Verbosity())
|
||||
Report("Basic logging already initialized.\n");
|
||||
return XRayLogInitStatus::XRAY_LOG_INITIALIZED;
|
||||
}
|
||||
|
@ -422,7 +422,7 @@ XRayLogInitStatus basicLoggingInit(size_t BufferSize, size_t BufferMax,
|
|||
}
|
||||
|
||||
static auto UseRealTSC = probeRequiredCPUFeatures();
|
||||
if (!UseRealTSC && __sanitizer::Verbosity())
|
||||
if (!UseRealTSC && Verbosity())
|
||||
Report("WARNING: Required CPU features missing for XRay instrumentation, "
|
||||
"using emulation instead.\n");
|
||||
|
||||
|
@ -438,9 +438,9 @@ XRayLogInitStatus basicLoggingInit(size_t BufferSize, size_t BufferMax,
|
|||
|
||||
XRayLogInitStatus basicLoggingFinalize() XRAY_NEVER_INSTRUMENT {
|
||||
uint8_t Expected = 0;
|
||||
if (!__sanitizer::atomic_compare_exchange_strong(
|
||||
&BasicInitialized, &Expected, 0, __sanitizer::memory_order_acq_rel) &&
|
||||
__sanitizer::Verbosity())
|
||||
if (!atomic_compare_exchange_strong(
|
||||
&BasicInitialized, &Expected, 0, memory_order_acq_rel) &&
|
||||
Verbosity())
|
||||
Report("Basic logging already finalized.\n");
|
||||
|
||||
// Nothing really to do aside from marking state of the global to be
|
||||
|
@ -493,7 +493,7 @@ bool basicLogDynamicInitializer() XRAY_NEVER_INSTRUMENT {
|
|||
}
|
||||
static auto UNUSED Once = [] {
|
||||
static auto UNUSED &TLD = getThreadLocalData();
|
||||
__sanitizer::Atexit(+[] { TLDDestructor(&TLD); });
|
||||
Atexit(+[] { TLDDestructor(&TLD); });
|
||||
return false;
|
||||
}();
|
||||
}
|
||||
|
|
|
@ -69,9 +69,9 @@ BufferQueue::BufferQueue(size_t B, size_t N, bool &Success)
|
|||
}
|
||||
|
||||
BufferQueue::ErrorCode BufferQueue::getBuffer(Buffer &Buf) {
|
||||
if (__sanitizer::atomic_load(&Finalizing, __sanitizer::memory_order_acquire))
|
||||
if (atomic_load(&Finalizing, memory_order_acquire))
|
||||
return ErrorCode::QueueFinalizing;
|
||||
__sanitizer::SpinMutexLock Guard(&Mutex);
|
||||
SpinMutexLock Guard(&Mutex);
|
||||
if (LiveBuffers == BufferCount)
|
||||
return ErrorCode::NotEnoughMemory;
|
||||
|
||||
|
@ -99,7 +99,7 @@ BufferQueue::ErrorCode BufferQueue::releaseBuffer(Buffer &Buf) {
|
|||
if (!Found)
|
||||
return ErrorCode::UnrecognizedBuffer;
|
||||
|
||||
__sanitizer::SpinMutexLock Guard(&Mutex);
|
||||
SpinMutexLock Guard(&Mutex);
|
||||
|
||||
// This points to a semantic bug, we really ought to not be releasing more
|
||||
// buffers than we actually get.
|
||||
|
@ -119,8 +119,7 @@ BufferQueue::ErrorCode BufferQueue::releaseBuffer(Buffer &Buf) {
|
|||
}
|
||||
|
||||
BufferQueue::ErrorCode BufferQueue::finalize() {
|
||||
if (__sanitizer::atomic_exchange(&Finalizing, 1,
|
||||
__sanitizer::memory_order_acq_rel))
|
||||
if (atomic_exchange(&Finalizing, 1, memory_order_acq_rel))
|
||||
return ErrorCode::QueueFinalizing;
|
||||
return ErrorCode::Ok;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace __xray {
|
|||
class BufferQueue {
|
||||
public:
|
||||
struct alignas(64) BufferExtents {
|
||||
__sanitizer::atomic_uint64_t Size;
|
||||
atomic_uint64_t Size;
|
||||
};
|
||||
|
||||
struct Buffer {
|
||||
|
@ -112,8 +112,8 @@ private:
|
|||
// Amount of pre-allocated buffers.
|
||||
size_t BufferCount;
|
||||
|
||||
__sanitizer::SpinMutex Mutex;
|
||||
__sanitizer::atomic_uint8_t Finalizing;
|
||||
SpinMutex Mutex;
|
||||
atomic_uint8_t Finalizing;
|
||||
|
||||
// Pointers to buffers managed/owned by the BufferQueue.
|
||||
void **OwnedBuffers;
|
||||
|
@ -180,8 +180,7 @@ public:
|
|||
ErrorCode releaseBuffer(Buffer &Buf);
|
||||
|
||||
bool finalizing() const {
|
||||
return __sanitizer::atomic_load(&Finalizing,
|
||||
__sanitizer::memory_order_acquire);
|
||||
return atomic_load(&Finalizing, memory_order_acquire);
|
||||
}
|
||||
|
||||
/// Returns the configured size of the buffers in the buffer queue.
|
||||
|
@ -200,7 +199,7 @@ public:
|
|||
/// Buffer is marked 'used' (i.e. has been the result of getBuffer(...) and a
|
||||
/// releaseBuffer(...) operation).
|
||||
template <class F> void apply(F Fn) {
|
||||
__sanitizer::SpinMutexLock G(&Mutex);
|
||||
SpinMutexLock G(&Mutex);
|
||||
for (auto I = begin(), E = end(); I != E; ++I)
|
||||
Fn(*I);
|
||||
}
|
||||
|
|
|
@ -38,12 +38,11 @@ namespace __xray {
|
|||
// Global BufferQueue.
|
||||
BufferQueue *BQ = nullptr;
|
||||
|
||||
__sanitizer::atomic_sint32_t LogFlushStatus = {
|
||||
XRayLogFlushStatus::XRAY_LOG_NOT_FLUSHING};
|
||||
atomic_sint32_t LogFlushStatus = {XRayLogFlushStatus::XRAY_LOG_NOT_FLUSHING};
|
||||
|
||||
FDRLoggingOptions FDROptions;
|
||||
|
||||
__sanitizer::SpinMutex FDROptionsMutex;
|
||||
SpinMutex FDROptionsMutex;
|
||||
|
||||
namespace {
|
||||
XRayFileHeader &fdrCommonHeaderInfo() {
|
||||
|
@ -125,40 +124,38 @@ XRayBuffer fdrIterator(const XRayBuffer B) {
|
|||
|
||||
XRayBuffer Result;
|
||||
Result.Data = It->Data;
|
||||
Result.Size = __sanitizer::atomic_load(&It->Extents->Size,
|
||||
__sanitizer::memory_order_acquire);
|
||||
Result.Size = atomic_load(&It->Extents->Size, memory_order_acquire);
|
||||
++It;
|
||||
return Result;
|
||||
}
|
||||
|
||||
// Must finalize before flushing.
|
||||
XRayLogFlushStatus fdrLoggingFlush() XRAY_NEVER_INSTRUMENT {
|
||||
if (__sanitizer::atomic_load(&LoggingStatus,
|
||||
__sanitizer::memory_order_acquire) !=
|
||||
if (atomic_load(&LoggingStatus, memory_order_acquire) !=
|
||||
XRayLogInitStatus::XRAY_LOG_FINALIZED) {
|
||||
if (__sanitizer::Verbosity())
|
||||
if (Verbosity())
|
||||
Report("Not flushing log, implementation is not finalized.\n");
|
||||
return XRayLogFlushStatus::XRAY_LOG_NOT_FLUSHING;
|
||||
}
|
||||
|
||||
s32 Result = XRayLogFlushStatus::XRAY_LOG_NOT_FLUSHING;
|
||||
if (!__sanitizer::atomic_compare_exchange_strong(
|
||||
&LogFlushStatus, &Result, XRayLogFlushStatus::XRAY_LOG_FLUSHING,
|
||||
__sanitizer::memory_order_release)) {
|
||||
if (__sanitizer::Verbosity())
|
||||
if (!atomic_compare_exchange_strong(&LogFlushStatus, &Result,
|
||||
XRayLogFlushStatus::XRAY_LOG_FLUSHING,
|
||||
memory_order_release)) {
|
||||
if (Verbosity())
|
||||
Report("Not flushing log, implementation is still finalizing.\n");
|
||||
return static_cast<XRayLogFlushStatus>(Result);
|
||||
}
|
||||
|
||||
if (BQ == nullptr) {
|
||||
if (__sanitizer::Verbosity())
|
||||
if (Verbosity())
|
||||
Report("Cannot flush when global buffer queue is null.\n");
|
||||
return XRayLogFlushStatus::XRAY_LOG_NOT_FLUSHING;
|
||||
}
|
||||
|
||||
// We wait a number of milliseconds to allow threads to see that we've
|
||||
// finalised before attempting to flush the log.
|
||||
__sanitizer::SleepForMillis(fdrFlags()->grace_period_ms);
|
||||
SleepForMillis(fdrFlags()->grace_period_ms);
|
||||
|
||||
// At this point, we're going to uninstall the iterator implementation, before
|
||||
// we decide to do anything further with the global buffer queue.
|
||||
|
@ -171,9 +168,8 @@ XRayLogFlushStatus fdrLoggingFlush() XRAY_NEVER_INSTRUMENT {
|
|||
// Clean up the buffer queue, and do not bother writing out the files!
|
||||
delete BQ;
|
||||
BQ = nullptr;
|
||||
__sanitizer::atomic_store(&LogFlushStatus,
|
||||
XRayLogFlushStatus::XRAY_LOG_FLUSHED,
|
||||
__sanitizer::memory_order_release);
|
||||
atomic_store(&LogFlushStatus, XRayLogFlushStatus::XRAY_LOG_FLUSHED,
|
||||
memory_order_release);
|
||||
return XRayLogFlushStatus::XRAY_LOG_FLUSHED;
|
||||
}
|
||||
|
||||
|
@ -190,15 +186,14 @@ XRayLogFlushStatus fdrLoggingFlush() XRAY_NEVER_INSTRUMENT {
|
|||
{
|
||||
// FIXME: Remove this section of the code, when we remove the struct-based
|
||||
// configuration API.
|
||||
__sanitizer::SpinMutexLock Guard(&FDROptionsMutex);
|
||||
SpinMutexLock Guard(&FDROptionsMutex);
|
||||
Fd = FDROptions.Fd;
|
||||
}
|
||||
if (Fd == -1)
|
||||
Fd = getLogFD();
|
||||
if (Fd == -1) {
|
||||
auto Result = XRayLogFlushStatus::XRAY_LOG_NOT_FLUSHING;
|
||||
__sanitizer::atomic_store(&LogFlushStatus, Result,
|
||||
__sanitizer::memory_order_release);
|
||||
atomic_store(&LogFlushStatus, Result, memory_order_release);
|
||||
return Result;
|
||||
}
|
||||
|
||||
|
@ -214,8 +209,7 @@ XRayLogFlushStatus fdrLoggingFlush() XRAY_NEVER_INSTRUMENT {
|
|||
// still use a Metadata record, but fill in the extents instead for the
|
||||
// data.
|
||||
MetadataRecord ExtentsRecord;
|
||||
auto BufferExtents = __sanitizer::atomic_load(
|
||||
&B.Extents->Size, __sanitizer::memory_order_acquire);
|
||||
auto BufferExtents = atomic_load(&B.Extents->Size, memory_order_acquire);
|
||||
assert(BufferExtents <= B.Size);
|
||||
ExtentsRecord.Type = uint8_t(RecordType::Metadata);
|
||||
ExtentsRecord.RecordKind =
|
||||
|
@ -230,19 +224,17 @@ XRayLogFlushStatus fdrLoggingFlush() XRAY_NEVER_INSTRUMENT {
|
|||
}
|
||||
});
|
||||
|
||||
__sanitizer::atomic_store(&LogFlushStatus,
|
||||
XRayLogFlushStatus::XRAY_LOG_FLUSHED,
|
||||
__sanitizer::memory_order_release);
|
||||
atomic_store(&LogFlushStatus, XRayLogFlushStatus::XRAY_LOG_FLUSHED,
|
||||
memory_order_release);
|
||||
return XRayLogFlushStatus::XRAY_LOG_FLUSHED;
|
||||
}
|
||||
|
||||
XRayLogInitStatus fdrLoggingFinalize() XRAY_NEVER_INSTRUMENT {
|
||||
s32 CurrentStatus = XRayLogInitStatus::XRAY_LOG_INITIALIZED;
|
||||
if (!__sanitizer::atomic_compare_exchange_strong(
|
||||
&LoggingStatus, &CurrentStatus,
|
||||
XRayLogInitStatus::XRAY_LOG_FINALIZING,
|
||||
__sanitizer::memory_order_release)) {
|
||||
if (__sanitizer::Verbosity())
|
||||
if (!atomic_compare_exchange_strong(&LoggingStatus, &CurrentStatus,
|
||||
XRayLogInitStatus::XRAY_LOG_FINALIZING,
|
||||
memory_order_release)) {
|
||||
if (Verbosity())
|
||||
Report("Cannot finalize log, implementation not initialized.\n");
|
||||
return static_cast<XRayLogInitStatus>(CurrentStatus);
|
||||
}
|
||||
|
@ -251,9 +243,8 @@ XRayLogInitStatus fdrLoggingFinalize() XRAY_NEVER_INSTRUMENT {
|
|||
// operations to be performed until re-initialized.
|
||||
BQ->finalize();
|
||||
|
||||
__sanitizer::atomic_store(&LoggingStatus,
|
||||
XRayLogInitStatus::XRAY_LOG_FINALIZED,
|
||||
__sanitizer::memory_order_release);
|
||||
atomic_store(&LoggingStatus, XRayLogInitStatus::XRAY_LOG_FINALIZED,
|
||||
memory_order_release);
|
||||
return XRayLogInitStatus::XRAY_LOG_FINALIZED;
|
||||
}
|
||||
|
||||
|
@ -415,11 +406,10 @@ XRayLogInitStatus fdrLoggingInit(size_t BufferSize, size_t BufferMax,
|
|||
return XRayLogInitStatus::XRAY_LOG_UNINITIALIZED;
|
||||
|
||||
s32 CurrentStatus = XRayLogInitStatus::XRAY_LOG_UNINITIALIZED;
|
||||
if (!__sanitizer::atomic_compare_exchange_strong(
|
||||
&LoggingStatus, &CurrentStatus,
|
||||
XRayLogInitStatus::XRAY_LOG_INITIALIZING,
|
||||
__sanitizer::memory_order_release)) {
|
||||
if (__sanitizer::Verbosity())
|
||||
if (!atomic_compare_exchange_strong(&LoggingStatus, &CurrentStatus,
|
||||
XRayLogInitStatus::XRAY_LOG_INITIALIZING,
|
||||
memory_order_release)) {
|
||||
if (Verbosity())
|
||||
Report("Cannot initialize already initialized implementation.\n");
|
||||
return static_cast<XRayLogInitStatus>(CurrentStatus);
|
||||
}
|
||||
|
@ -428,7 +418,7 @@ XRayLogInitStatus fdrLoggingInit(size_t BufferSize, size_t BufferMax,
|
|||
// called with BufferSize == 0 and BufferMax == 0 we parse the configuration
|
||||
// provided in the Options pointer as a string instead.
|
||||
if (BufferSize == 0 && BufferMax == 0) {
|
||||
if (__sanitizer::Verbosity())
|
||||
if (Verbosity())
|
||||
Report("Initializing FDR mode with options: %s\n",
|
||||
static_cast<const char *>(Options));
|
||||
|
||||
|
@ -463,23 +453,23 @@ XRayLogInitStatus fdrLoggingInit(size_t BufferSize, size_t BufferMax,
|
|||
*fdrFlags() = FDRFlags;
|
||||
BufferSize = FDRFlags.buffer_size;
|
||||
BufferMax = FDRFlags.buffer_max;
|
||||
__sanitizer::SpinMutexLock Guard(&FDROptionsMutex);
|
||||
SpinMutexLock Guard(&FDROptionsMutex);
|
||||
FDROptions.Fd = -1;
|
||||
FDROptions.ReportErrors = true;
|
||||
} else if (OptionsSize != sizeof(FDRLoggingOptions)) {
|
||||
// FIXME: This is deprecated, and should really be removed.
|
||||
// At this point we use the flag parser specific to the FDR mode
|
||||
// implementation.
|
||||
if (__sanitizer::Verbosity())
|
||||
if (Verbosity())
|
||||
Report("Cannot initialize FDR logging; wrong size for options: %d\n",
|
||||
OptionsSize);
|
||||
return static_cast<XRayLogInitStatus>(__sanitizer::atomic_load(
|
||||
&LoggingStatus, __sanitizer::memory_order_acquire));
|
||||
return static_cast<XRayLogInitStatus>(
|
||||
atomic_load(&LoggingStatus, memory_order_acquire));
|
||||
} else {
|
||||
if (__sanitizer::Verbosity())
|
||||
if (Verbosity())
|
||||
Report("XRay FDR: struct-based init is deprecated, please use "
|
||||
"string-based configuration instead.\n");
|
||||
__sanitizer::SpinMutexLock Guard(&FDROptionsMutex);
|
||||
SpinMutexLock Guard(&FDROptionsMutex);
|
||||
memcpy(&FDROptions, Options, OptionsSize);
|
||||
}
|
||||
|
||||
|
@ -526,11 +516,10 @@ XRayLogInitStatus fdrLoggingInit(size_t BufferSize, size_t BufferMax,
|
|||
// Install the buffer iterator implementation.
|
||||
__xray_log_set_buffer_iterator(fdrIterator);
|
||||
|
||||
__sanitizer::atomic_store(&LoggingStatus,
|
||||
XRayLogInitStatus::XRAY_LOG_INITIALIZED,
|
||||
__sanitizer::memory_order_release);
|
||||
atomic_store(&LoggingStatus, XRayLogInitStatus::XRAY_LOG_INITIALIZED,
|
||||
memory_order_release);
|
||||
|
||||
if (__sanitizer::Verbosity())
|
||||
if (Verbosity())
|
||||
Report("XRay FDR init successful.\n");
|
||||
return XRayLogInitStatus::XRAY_LOG_INITIALIZED;
|
||||
}
|
||||
|
@ -545,11 +534,10 @@ bool fdrLogDynamicInitializer() XRAY_NEVER_INSTRUMENT {
|
|||
};
|
||||
auto RegistrationResult = __xray_log_register_mode("xray-fdr", Impl);
|
||||
if (RegistrationResult != XRayLogRegisterStatus::XRAY_REGISTRATION_OK &&
|
||||
__sanitizer::Verbosity())
|
||||
Verbosity())
|
||||
Report("Cannot register XRay FDR mode to 'xray-fdr'; error = %d\n",
|
||||
RegistrationResult);
|
||||
if (flags()->xray_fdr_log ||
|
||||
!__sanitizer::internal_strcmp(flags()->xray_mode, "xray-fdr"))
|
||||
if (flags()->xray_fdr_log || !internal_strcmp(flags()->xray_mode, "xray-fdr"))
|
||||
__xray_set_log_impl(Impl);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -37,8 +37,7 @@
|
|||
|
||||
namespace __xray {
|
||||
|
||||
__sanitizer::atomic_sint32_t LoggingStatus = {
|
||||
XRayLogInitStatus::XRAY_LOG_UNINITIALIZED};
|
||||
atomic_sint32_t LoggingStatus = {XRayLogInitStatus::XRAY_LOG_UNINITIALIZED};
|
||||
|
||||
/// We expose some of the state transitions when FDR logging mode is operating
|
||||
/// such that we can simulate a series of log events that may occur without
|
||||
|
@ -228,8 +227,8 @@ static void writeNewBufferPreamble(tid_t Tid,
|
|||
TLD.RecordPtr += sizeof(Metadata);
|
||||
// Since we write out the extents as the first metadata record of the
|
||||
// buffer, we need to write out the extents including the extents record.
|
||||
__sanitizer::atomic_store(&TLD.Buffer.Extents->Size, sizeof(Metadata),
|
||||
__sanitizer::memory_order_release);
|
||||
atomic_store(&TLD.Buffer.Extents->Size, sizeof(Metadata),
|
||||
memory_order_release);
|
||||
}
|
||||
|
||||
inline void setupNewBuffer(int (*wall_clock_reader)(
|
||||
|
@ -237,7 +236,7 @@ inline void setupNewBuffer(int (*wall_clock_reader)(
|
|||
auto &TLD = getThreadLocalData();
|
||||
auto &B = TLD.Buffer;
|
||||
TLD.RecordPtr = static_cast<char *>(B.Data);
|
||||
tid_t Tid = __sanitizer::GetTid();
|
||||
tid_t Tid = GetTid();
|
||||
timespec TS{0, 0};
|
||||
// This is typically clock_gettime, but callers have injection ability.
|
||||
wall_clock_reader(CLOCK_MONOTONIC, &TS);
|
||||
|
@ -248,14 +247,12 @@ inline void setupNewBuffer(int (*wall_clock_reader)(
|
|||
|
||||
static void incrementExtents(size_t Add) {
|
||||
auto &TLD = getThreadLocalData();
|
||||
__sanitizer::atomic_fetch_add(&TLD.Buffer.Extents->Size, Add,
|
||||
__sanitizer::memory_order_acq_rel);
|
||||
atomic_fetch_add(&TLD.Buffer.Extents->Size, Add, memory_order_acq_rel);
|
||||
}
|
||||
|
||||
static void decrementExtents(size_t Subtract) {
|
||||
auto &TLD = getThreadLocalData();
|
||||
__sanitizer::atomic_fetch_sub(&TLD.Buffer.Extents->Size, Subtract,
|
||||
__sanitizer::memory_order_acq_rel);
|
||||
atomic_fetch_sub(&TLD.Buffer.Extents->Size, Subtract, memory_order_acq_rel);
|
||||
}
|
||||
|
||||
inline void writeNewCPUIdMetadata(uint16_t CPU,
|
||||
|
@ -494,8 +491,7 @@ isLogInitializedAndReady(BufferQueue *LBQ, uint64_t TSC, unsigned char CPU,
|
|||
XRAY_NEVER_INSTRUMENT {
|
||||
// Bail out right away if logging is not initialized yet.
|
||||
// We should take the opportunity to release the buffer though.
|
||||
auto Status = __sanitizer::atomic_load(&LoggingStatus,
|
||||
__sanitizer::memory_order_acquire);
|
||||
auto Status = atomic_load(&LoggingStatus, memory_order_acquire);
|
||||
auto &TLD = getThreadLocalData();
|
||||
if (Status != XRayLogInitStatus::XRAY_LOG_INITIALIZED) {
|
||||
if (TLD.RecordPtr != nullptr &&
|
||||
|
@ -509,8 +505,7 @@ isLogInitializedAndReady(BufferQueue *LBQ, uint64_t TSC, unsigned char CPU,
|
|||
return false;
|
||||
}
|
||||
|
||||
if (__sanitizer::atomic_load(&LoggingStatus,
|
||||
__sanitizer::memory_order_acquire) !=
|
||||
if (atomic_load(&LoggingStatus, memory_order_acquire) !=
|
||||
XRayLogInitStatus::XRAY_LOG_INITIALIZED ||
|
||||
LBQ->finalizing()) {
|
||||
if (!releaseThreadLocalBuffer(*LBQ))
|
||||
|
@ -521,8 +516,7 @@ isLogInitializedAndReady(BufferQueue *LBQ, uint64_t TSC, unsigned char CPU,
|
|||
if (TLD.Buffer.Data == nullptr) {
|
||||
auto EC = LBQ->getBuffer(TLD.Buffer);
|
||||
if (EC != BufferQueue::ErrorCode::Ok) {
|
||||
auto LS = __sanitizer::atomic_load(&LoggingStatus,
|
||||
__sanitizer::memory_order_acquire);
|
||||
auto LS = atomic_load(&LoggingStatus, memory_order_acquire);
|
||||
if (LS != XRayLogInitStatus::XRAY_LOG_FINALIZING &&
|
||||
LS != XRayLogInitStatus::XRAY_LOG_FINALIZED)
|
||||
Report("Failed to acquire a buffer; error=%s\n",
|
||||
|
|
|
@ -38,32 +38,29 @@ using namespace __xray;
|
|||
//
|
||||
// FIXME: Support DSO instrumentation maps too. The current solution only works
|
||||
// for statically linked executables.
|
||||
__sanitizer::atomic_uint8_t XRayInitialized{0};
|
||||
atomic_uint8_t XRayInitialized{0};
|
||||
|
||||
// This should always be updated before XRayInitialized is updated.
|
||||
__sanitizer::SpinMutex XRayInstrMapMutex;
|
||||
SpinMutex XRayInstrMapMutex;
|
||||
XRaySledMap XRayInstrMap;
|
||||
|
||||
// Global flag to determine whether the flags have been initialized.
|
||||
__sanitizer::atomic_uint8_t XRayFlagsInitialized{0};
|
||||
atomic_uint8_t XRayFlagsInitialized{0};
|
||||
|
||||
// A mutex to allow only one thread to initialize the XRay data structures.
|
||||
__sanitizer::SpinMutex XRayInitMutex;
|
||||
SpinMutex XRayInitMutex;
|
||||
|
||||
// __xray_init() will do the actual loading of the current process' memory map
|
||||
// and then proceed to look for the .xray_instr_map section/segment.
|
||||
void __xray_init() XRAY_NEVER_INSTRUMENT {
|
||||
__sanitizer::SpinMutexLock Guard(&XRayInitMutex);
|
||||
SpinMutexLock Guard(&XRayInitMutex);
|
||||
// Short-circuit if we've already initialized XRay before.
|
||||
if (__sanitizer::atomic_load(&XRayInitialized,
|
||||
__sanitizer::memory_order_acquire))
|
||||
if (atomic_load(&XRayInitialized, memory_order_acquire))
|
||||
return;
|
||||
|
||||
if (!__sanitizer::atomic_load(&XRayFlagsInitialized,
|
||||
__sanitizer::memory_order_acquire)) {
|
||||
if (!atomic_load(&XRayFlagsInitialized, memory_order_acquire)) {
|
||||
initializeFlags();
|
||||
__sanitizer::atomic_store(&XRayFlagsInitialized, true,
|
||||
__sanitizer::memory_order_release);
|
||||
atomic_store(&XRayFlagsInitialized, true, memory_order_release);
|
||||
}
|
||||
|
||||
if (__start_xray_instr_map == nullptr) {
|
||||
|
@ -73,14 +70,13 @@ void __xray_init() XRAY_NEVER_INSTRUMENT {
|
|||
}
|
||||
|
||||
{
|
||||
__sanitizer::SpinMutexLock Guard(&XRayInstrMapMutex);
|
||||
SpinMutexLock Guard(&XRayInstrMapMutex);
|
||||
XRayInstrMap.Sleds = __start_xray_instr_map;
|
||||
XRayInstrMap.Entries = __stop_xray_instr_map - __start_xray_instr_map;
|
||||
XRayInstrMap.SledsIndex = __start_xray_fn_idx;
|
||||
XRayInstrMap.Functions = __stop_xray_fn_idx - __start_xray_fn_idx;
|
||||
}
|
||||
__sanitizer::atomic_store(&XRayInitialized, true,
|
||||
__sanitizer::memory_order_release);
|
||||
atomic_store(&XRayInitialized, true, memory_order_release);
|
||||
|
||||
#ifndef XRAY_NO_PREINIT
|
||||
if (flags()->patch_premain)
|
||||
|
|
|
@ -51,31 +51,31 @@ static const int16_t cSledLength = 8;
|
|||
#endif /* CPU architecture */
|
||||
|
||||
// This is the function to call when we encounter the entry or exit sleds.
|
||||
__sanitizer::atomic_uintptr_t XRayPatchedFunction{0};
|
||||
atomic_uintptr_t XRayPatchedFunction{0};
|
||||
|
||||
// This is the function to call from the arg1-enabled sleds/trampolines.
|
||||
__sanitizer::atomic_uintptr_t XRayArgLogger{0};
|
||||
atomic_uintptr_t XRayArgLogger{0};
|
||||
|
||||
// This is the function to call when we encounter a custom event log call.
|
||||
__sanitizer::atomic_uintptr_t XRayPatchedCustomEvent{0};
|
||||
atomic_uintptr_t XRayPatchedCustomEvent{0};
|
||||
|
||||
// This is the function to call when we encounter a typed event log call.
|
||||
__sanitizer::atomic_uintptr_t XRayPatchedTypedEvent{0};
|
||||
atomic_uintptr_t XRayPatchedTypedEvent{0};
|
||||
|
||||
// This is the global status to determine whether we are currently
|
||||
// patching/unpatching.
|
||||
__sanitizer::atomic_uint8_t XRayPatching{0};
|
||||
atomic_uint8_t XRayPatching{0};
|
||||
|
||||
struct TypeDescription {
|
||||
uint32_t type_id;
|
||||
std::size_t description_string_length;
|
||||
};
|
||||
|
||||
using TypeDescriptorMapType = __sanitizer::AddrHashMap<TypeDescription, 11>;
|
||||
using TypeDescriptorMapType = AddrHashMap<TypeDescription, 11>;
|
||||
// An address map from immutable descriptors to type ids.
|
||||
TypeDescriptorMapType TypeDescriptorAddressMap{};
|
||||
|
||||
__sanitizer::atomic_uint32_t TypeEventDescriptorCounter{0};
|
||||
atomic_uint32_t TypeEventDescriptorCounter{0};
|
||||
|
||||
// MProtectHelper is an RAII wrapper for calls to mprotect(...) that will
|
||||
// undo any successful mprotect(...) changes. This is used to make a page
|
||||
|
@ -145,19 +145,19 @@ bool patchSled(const XRaySledEntry &Sled, bool Enable,
|
|||
|
||||
XRayPatchingStatus patchFunction(int32_t FuncId,
|
||||
bool Enable) XRAY_NEVER_INSTRUMENT {
|
||||
if (!__sanitizer::atomic_load(&XRayInitialized,
|
||||
__sanitizer::memory_order_acquire))
|
||||
if (!atomic_load(&XRayInitialized,
|
||||
memory_order_acquire))
|
||||
return XRayPatchingStatus::NOT_INITIALIZED; // Not initialized.
|
||||
|
||||
uint8_t NotPatching = false;
|
||||
if (!__sanitizer::atomic_compare_exchange_strong(
|
||||
&XRayPatching, &NotPatching, true, __sanitizer::memory_order_acq_rel))
|
||||
if (!atomic_compare_exchange_strong(
|
||||
&XRayPatching, &NotPatching, true, memory_order_acq_rel))
|
||||
return XRayPatchingStatus::ONGOING; // Already patching.
|
||||
|
||||
// Next, we look for the function index.
|
||||
XRaySledMap InstrMap;
|
||||
{
|
||||
__sanitizer::SpinMutexLock Guard(&XRayInstrMapMutex);
|
||||
SpinMutexLock Guard(&XRayInstrMapMutex);
|
||||
InstrMap = XRayInstrMap;
|
||||
}
|
||||
|
||||
|
@ -181,8 +181,8 @@ XRayPatchingStatus patchFunction(int32_t FuncId,
|
|||
while (f != e)
|
||||
SucceedOnce |= patchSled(*f++, Enable, FuncId);
|
||||
|
||||
__sanitizer::atomic_store(&XRayPatching, false,
|
||||
__sanitizer::memory_order_release);
|
||||
atomic_store(&XRayPatching, false,
|
||||
memory_order_release);
|
||||
|
||||
if (!SucceedOnce) {
|
||||
Report("Failed patching any sled for function '%d'.", FuncId);
|
||||
|
@ -196,26 +196,26 @@ XRayPatchingStatus patchFunction(int32_t FuncId,
|
|||
// implementation. |Enable| defines whether we're enabling or disabling the
|
||||
// runtime XRay instrumentation.
|
||||
XRayPatchingStatus controlPatching(bool Enable) XRAY_NEVER_INSTRUMENT {
|
||||
if (!__sanitizer::atomic_load(&XRayInitialized,
|
||||
__sanitizer::memory_order_acquire))
|
||||
if (!atomic_load(&XRayInitialized,
|
||||
memory_order_acquire))
|
||||
return XRayPatchingStatus::NOT_INITIALIZED; // Not initialized.
|
||||
|
||||
uint8_t NotPatching = false;
|
||||
if (!__sanitizer::atomic_compare_exchange_strong(
|
||||
&XRayPatching, &NotPatching, true, __sanitizer::memory_order_acq_rel))
|
||||
if (!atomic_compare_exchange_strong(
|
||||
&XRayPatching, &NotPatching, true, memory_order_acq_rel))
|
||||
return XRayPatchingStatus::ONGOING; // Already patching.
|
||||
|
||||
uint8_t PatchingSuccess = false;
|
||||
auto XRayPatchingStatusResetter =
|
||||
__sanitizer::at_scope_exit([&PatchingSuccess] {
|
||||
at_scope_exit([&PatchingSuccess] {
|
||||
if (!PatchingSuccess)
|
||||
__sanitizer::atomic_store(&XRayPatching, false,
|
||||
__sanitizer::memory_order_release);
|
||||
atomic_store(&XRayPatching, false,
|
||||
memory_order_release);
|
||||
});
|
||||
|
||||
XRaySledMap InstrMap;
|
||||
{
|
||||
__sanitizer::SpinMutexLock Guard(&XRayInstrMapMutex);
|
||||
SpinMutexLock Guard(&XRayInstrMapMutex);
|
||||
InstrMap = XRayInstrMap;
|
||||
}
|
||||
if (InstrMap.Entries == 0)
|
||||
|
@ -271,8 +271,8 @@ XRayPatchingStatus controlPatching(bool Enable) XRAY_NEVER_INSTRUMENT {
|
|||
}
|
||||
patchSled(Sled, Enable, FuncId);
|
||||
}
|
||||
__sanitizer::atomic_store(&XRayPatching, false,
|
||||
__sanitizer::memory_order_release);
|
||||
atomic_store(&XRayPatching, false,
|
||||
memory_order_release);
|
||||
PatchingSuccess = true;
|
||||
return XRayPatchingStatus::SUCCESS;
|
||||
}
|
||||
|
@ -281,7 +281,7 @@ XRayPatchingStatus mprotectAndPatchFunction(int32_t FuncId,
|
|||
bool Enable) XRAY_NEVER_INSTRUMENT {
|
||||
XRaySledMap InstrMap;
|
||||
{
|
||||
__sanitizer::SpinMutexLock Guard(&XRayInstrMapMutex);
|
||||
SpinMutexLock Guard(&XRayInstrMapMutex);
|
||||
InstrMap = XRayInstrMap;
|
||||
}
|
||||
|
||||
|
@ -338,12 +338,12 @@ using namespace __xray;
|
|||
|
||||
int __xray_set_handler(void (*entry)(int32_t,
|
||||
XRayEntryType)) XRAY_NEVER_INSTRUMENT {
|
||||
if (__sanitizer::atomic_load(&XRayInitialized,
|
||||
__sanitizer::memory_order_acquire)) {
|
||||
if (atomic_load(&XRayInitialized,
|
||||
memory_order_acquire)) {
|
||||
|
||||
__sanitizer::atomic_store(&__xray::XRayPatchedFunction,
|
||||
atomic_store(&__xray::XRayPatchedFunction,
|
||||
reinterpret_cast<uintptr_t>(entry),
|
||||
__sanitizer::memory_order_release);
|
||||
memory_order_release);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -351,11 +351,11 @@ int __xray_set_handler(void (*entry)(int32_t,
|
|||
|
||||
int __xray_set_customevent_handler(void (*entry)(void *, size_t))
|
||||
XRAY_NEVER_INSTRUMENT {
|
||||
if (__sanitizer::atomic_load(&XRayInitialized,
|
||||
__sanitizer::memory_order_acquire)) {
|
||||
__sanitizer::atomic_store(&__xray::XRayPatchedCustomEvent,
|
||||
if (atomic_load(&XRayInitialized,
|
||||
memory_order_acquire)) {
|
||||
atomic_store(&__xray::XRayPatchedCustomEvent,
|
||||
reinterpret_cast<uintptr_t>(entry),
|
||||
__sanitizer::memory_order_release);
|
||||
memory_order_release);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -363,11 +363,11 @@ int __xray_set_customevent_handler(void (*entry)(void *, size_t))
|
|||
|
||||
int __xray_set_typedevent_handler(void (*entry)(
|
||||
uint16_t, const void *, size_t)) XRAY_NEVER_INSTRUMENT {
|
||||
if (__sanitizer::atomic_load(&XRayInitialized,
|
||||
__sanitizer::memory_order_acquire)) {
|
||||
__sanitizer::atomic_store(&__xray::XRayPatchedTypedEvent,
|
||||
if (atomic_load(&XRayInitialized,
|
||||
memory_order_acquire)) {
|
||||
atomic_store(&__xray::XRayPatchedTypedEvent,
|
||||
reinterpret_cast<uintptr_t>(entry),
|
||||
__sanitizer::memory_order_release);
|
||||
memory_order_release);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -389,8 +389,8 @@ uint16_t __xray_register_event_type(
|
|||
const char *const event_type) XRAY_NEVER_INSTRUMENT {
|
||||
TypeDescriptorMapType::Handle h(&TypeDescriptorAddressMap, (uptr)event_type);
|
||||
if (h.created()) {
|
||||
h->type_id = __sanitizer::atomic_fetch_add(
|
||||
&TypeEventDescriptorCounter, 1, __sanitizer::memory_order_acq_rel);
|
||||
h->type_id = atomic_fetch_add(
|
||||
&TypeEventDescriptorCounter, 1, memory_order_acq_rel);
|
||||
h->description_string_length = strnlen(event_type, 1024);
|
||||
}
|
||||
return h->type_id;
|
||||
|
@ -414,22 +414,22 @@ __xray_unpatch_function(int32_t FuncId) XRAY_NEVER_INSTRUMENT {
|
|||
}
|
||||
|
||||
int __xray_set_handler_arg1(void (*entry)(int32_t, XRayEntryType, uint64_t)) {
|
||||
if (!__sanitizer::atomic_load(&XRayInitialized,
|
||||
__sanitizer::memory_order_acquire))
|
||||
if (!atomic_load(&XRayInitialized,
|
||||
memory_order_acquire))
|
||||
return 0;
|
||||
|
||||
// A relaxed write might not be visible even if the current thread gets
|
||||
// scheduled on a different CPU/NUMA node. We need to wait for everyone to
|
||||
// have this handler installed for consistency of collected data across CPUs.
|
||||
__sanitizer::atomic_store(&XRayArgLogger, reinterpret_cast<uint64_t>(entry),
|
||||
__sanitizer::memory_order_release);
|
||||
atomic_store(&XRayArgLogger, reinterpret_cast<uint64_t>(entry),
|
||||
memory_order_release);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int __xray_remove_handler_arg1() { return __xray_set_handler_arg1(nullptr); }
|
||||
|
||||
uintptr_t __xray_function_address(int32_t FuncId) XRAY_NEVER_INSTRUMENT {
|
||||
__sanitizer::SpinMutexLock Guard(&XRayInstrMapMutex);
|
||||
SpinMutexLock Guard(&XRayInstrMapMutex);
|
||||
if (FuncId <= 0 || static_cast<size_t>(FuncId) > XRayInstrMap.Functions)
|
||||
return 0;
|
||||
return XRayInstrMap.SledsIndex[FuncId - 1].Begin->Function
|
||||
|
@ -443,6 +443,6 @@ uintptr_t __xray_function_address(int32_t FuncId) XRAY_NEVER_INSTRUMENT {
|
|||
}
|
||||
|
||||
size_t __xray_max_function_id() XRAY_NEVER_INSTRUMENT {
|
||||
__sanitizer::SpinMutexLock Guard(&XRayInstrMapMutex);
|
||||
SpinMutexLock Guard(&XRayInstrMapMutex);
|
||||
return XRayInstrMap.Functions;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "xray_defs.h"
|
||||
|
||||
namespace __xray {
|
||||
static __sanitizer::SpinMutex XRayImplMutex;
|
||||
static SpinMutex XRayImplMutex;
|
||||
static XRayLogImpl CurrentXRayImpl{nullptr, nullptr, nullptr, nullptr};
|
||||
static XRayLogImpl *GlobalXRayImpl = nullptr;
|
||||
|
||||
|
@ -30,7 +30,7 @@ XRayBuffer NullBufferIterator(XRayBuffer) XRAY_NEVER_INSTRUMENT {
|
|||
}
|
||||
|
||||
// This is the global function responsible for iterating through given buffers.
|
||||
__sanitizer::atomic_uintptr_t XRayBufferIterator{
|
||||
atomic_uintptr_t XRayBufferIterator{
|
||||
reinterpret_cast<uintptr_t>(&NullBufferIterator)};
|
||||
|
||||
// We use a linked list of Mode to XRayLogImpl mappings. This is a linked list
|
||||
|
@ -53,9 +53,8 @@ using namespace __xray;
|
|||
|
||||
void __xray_log_set_buffer_iterator(XRayBuffer (*Iterator)(XRayBuffer))
|
||||
XRAY_NEVER_INSTRUMENT {
|
||||
__sanitizer::atomic_store(&__xray::XRayBufferIterator,
|
||||
reinterpret_cast<uintptr_t>(Iterator),
|
||||
__sanitizer::memory_order_release);
|
||||
atomic_store(&__xray::XRayBufferIterator,
|
||||
reinterpret_cast<uintptr_t>(Iterator), memory_order_release);
|
||||
}
|
||||
|
||||
void __xray_log_remove_buffer_iterator() XRAY_NEVER_INSTRUMENT {
|
||||
|
@ -69,16 +68,15 @@ __xray_log_register_mode(const char *Mode,
|
|||
Impl.log_finalize == nullptr || Impl.log_init == nullptr)
|
||||
return XRayLogRegisterStatus::XRAY_INCOMPLETE_IMPL;
|
||||
|
||||
__sanitizer::SpinMutexLock Guard(&XRayImplMutex);
|
||||
SpinMutexLock Guard(&XRayImplMutex);
|
||||
// First, look for whether the mode already has a registered implementation.
|
||||
for (ModeImpl *it = ModeImpls; it != &SentinelModeImpl; it = it->Next) {
|
||||
if (!__sanitizer::internal_strcmp(Mode, it->Mode))
|
||||
if (!internal_strcmp(Mode, it->Mode))
|
||||
return XRayLogRegisterStatus::XRAY_DUPLICATE_MODE;
|
||||
}
|
||||
auto *NewModeImpl =
|
||||
static_cast<ModeImpl *>(__sanitizer::InternalAlloc(sizeof(ModeImpl)));
|
||||
auto *NewModeImpl = static_cast<ModeImpl *>(InternalAlloc(sizeof(ModeImpl)));
|
||||
NewModeImpl->Next = ModeImpls;
|
||||
NewModeImpl->Mode = __sanitizer::internal_strdup(Mode);
|
||||
NewModeImpl->Mode = internal_strdup(Mode);
|
||||
NewModeImpl->Impl = Impl;
|
||||
ModeImpls = NewModeImpl;
|
||||
return XRayLogRegisterStatus::XRAY_REGISTRATION_OK;
|
||||
|
@ -86,9 +84,9 @@ __xray_log_register_mode(const char *Mode,
|
|||
|
||||
XRayLogRegisterStatus
|
||||
__xray_log_select_mode(const char *Mode) XRAY_NEVER_INSTRUMENT {
|
||||
__sanitizer::SpinMutexLock Guard(&XRayImplMutex);
|
||||
SpinMutexLock Guard(&XRayImplMutex);
|
||||
for (ModeImpl *it = ModeImpls; it != &SentinelModeImpl; it = it->Next) {
|
||||
if (!__sanitizer::internal_strcmp(Mode, it->Mode)) {
|
||||
if (!internal_strcmp(Mode, it->Mode)) {
|
||||
CurrentMode = it;
|
||||
CurrentXRayImpl = it->Impl;
|
||||
GlobalXRayImpl = &CurrentXRayImpl;
|
||||
|
@ -100,7 +98,7 @@ __xray_log_select_mode(const char *Mode) XRAY_NEVER_INSTRUMENT {
|
|||
}
|
||||
|
||||
const char *__xray_log_get_current_mode() XRAY_NEVER_INSTRUMENT {
|
||||
__sanitizer::SpinMutexLock Guard(&XRayImplMutex);
|
||||
SpinMutexLock Guard(&XRayImplMutex);
|
||||
if (CurrentMode != nullptr)
|
||||
return CurrentMode->Mode;
|
||||
return nullptr;
|
||||
|
@ -109,7 +107,7 @@ const char *__xray_log_get_current_mode() XRAY_NEVER_INSTRUMENT {
|
|||
void __xray_set_log_impl(XRayLogImpl Impl) XRAY_NEVER_INSTRUMENT {
|
||||
if (Impl.log_init == nullptr || Impl.log_finalize == nullptr ||
|
||||
Impl.handle_arg0 == nullptr || Impl.flush_log == nullptr) {
|
||||
__sanitizer::SpinMutexLock Guard(&XRayImplMutex);
|
||||
SpinMutexLock Guard(&XRayImplMutex);
|
||||
GlobalXRayImpl = nullptr;
|
||||
CurrentMode = nullptr;
|
||||
__xray_remove_handler();
|
||||
|
@ -117,14 +115,14 @@ void __xray_set_log_impl(XRayLogImpl Impl) XRAY_NEVER_INSTRUMENT {
|
|||
return;
|
||||
}
|
||||
|
||||
__sanitizer::SpinMutexLock Guard(&XRayImplMutex);
|
||||
SpinMutexLock Guard(&XRayImplMutex);
|
||||
CurrentXRayImpl = Impl;
|
||||
GlobalXRayImpl = &CurrentXRayImpl;
|
||||
__xray_set_handler(Impl.handle_arg0);
|
||||
}
|
||||
|
||||
void __xray_remove_log_impl() XRAY_NEVER_INSTRUMENT {
|
||||
__sanitizer::SpinMutexLock Guard(&XRayImplMutex);
|
||||
SpinMutexLock Guard(&XRayImplMutex);
|
||||
GlobalXRayImpl = nullptr;
|
||||
__xray_remove_handler();
|
||||
__xray_remove_handler_arg1();
|
||||
|
@ -133,7 +131,7 @@ void __xray_remove_log_impl() XRAY_NEVER_INSTRUMENT {
|
|||
XRayLogInitStatus __xray_log_init(size_t BufferSize, size_t MaxBuffers,
|
||||
void *Args,
|
||||
size_t ArgsSize) XRAY_NEVER_INSTRUMENT {
|
||||
__sanitizer::SpinMutexLock Guard(&XRayImplMutex);
|
||||
SpinMutexLock Guard(&XRayImplMutex);
|
||||
if (!GlobalXRayImpl)
|
||||
return XRayLogInitStatus::XRAY_LOG_UNINITIALIZED;
|
||||
return GlobalXRayImpl->log_init(BufferSize, MaxBuffers, Args, ArgsSize);
|
||||
|
@ -141,7 +139,7 @@ XRayLogInitStatus __xray_log_init(size_t BufferSize, size_t MaxBuffers,
|
|||
|
||||
XRayLogInitStatus __xray_log_init_mode(const char *Mode, const char *Config)
|
||||
XRAY_NEVER_INSTRUMENT {
|
||||
__sanitizer::SpinMutexLock Guard(&XRayImplMutex);
|
||||
SpinMutexLock Guard(&XRayImplMutex);
|
||||
if (!GlobalXRayImpl)
|
||||
return XRayLogInitStatus::XRAY_LOG_UNINITIALIZED;
|
||||
|
||||
|
@ -162,7 +160,7 @@ XRayLogInitStatus __xray_log_init_mode(const char *Mode, const char *Config)
|
|||
XRayLogInitStatus
|
||||
__xray_log_init_mode_bin(const char *Mode, const char *Config,
|
||||
size_t ConfigSize) XRAY_NEVER_INSTRUMENT {
|
||||
__sanitizer::SpinMutexLock Guard(&XRayImplMutex);
|
||||
SpinMutexLock Guard(&XRayImplMutex);
|
||||
if (!GlobalXRayImpl)
|
||||
return XRayLogInitStatus::XRAY_LOG_UNINITIALIZED;
|
||||
|
||||
|
@ -181,14 +179,14 @@ __xray_log_init_mode_bin(const char *Mode, const char *Config,
|
|||
}
|
||||
|
||||
XRayLogInitStatus __xray_log_finalize() XRAY_NEVER_INSTRUMENT {
|
||||
__sanitizer::SpinMutexLock Guard(&XRayImplMutex);
|
||||
SpinMutexLock Guard(&XRayImplMutex);
|
||||
if (!GlobalXRayImpl)
|
||||
return XRayLogInitStatus::XRAY_LOG_UNINITIALIZED;
|
||||
return GlobalXRayImpl->log_finalize();
|
||||
}
|
||||
|
||||
XRayLogFlushStatus __xray_log_flushLog() XRAY_NEVER_INSTRUMENT {
|
||||
__sanitizer::SpinMutexLock Guard(&XRayImplMutex);
|
||||
SpinMutexLock Guard(&XRayImplMutex);
|
||||
if (!GlobalXRayImpl)
|
||||
return XRayLogFlushStatus::XRAY_LOG_NOT_FLUSHING;
|
||||
return GlobalXRayImpl->flush_log();
|
||||
|
@ -201,7 +199,7 @@ XRayLogFlushStatus __xray_log_process_buffers(
|
|||
if (!GlobalXRayImpl)
|
||||
return XRayLogFlushStatus::XRAY_LOG_NOT_FLUSHING;
|
||||
auto Iterator = reinterpret_cast<XRayBuffer (*)(XRayBuffer)>(
|
||||
atomic_load(&XRayBufferIterator, __sanitizer::memory_order_acquire));
|
||||
atomic_load(&XRayBufferIterator, memory_order_acquire));
|
||||
auto Buffer = (*Iterator)(XRayBuffer{nullptr, 0});
|
||||
auto Mode = CurrentMode ? CurrentMode->Mode : nullptr;
|
||||
while (Buffer.Data != nullptr) {
|
||||
|
|
|
@ -117,7 +117,7 @@ int getLogFD() XRAY_NEVER_INSTRUMENT {
|
|||
TmpFilename);
|
||||
return -1;
|
||||
}
|
||||
if (__sanitizer::Verbosity())
|
||||
if (Verbosity())
|
||||
Report("XRay: Log file in '%s'\n", TmpFilename);
|
||||
|
||||
return Fd;
|
||||
|
|
Loading…
Reference in New Issue