llvm-project/compiler-rt/lib/lsan/lsan_common_mac.cc

85 lines
2.3 KiB
C++

//=-- lsan_common_mac.cc --------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file is a part of LeakSanitizer.
// Implementation of common leak checking functionality. Darwin-specific code.
//
//===----------------------------------------------------------------------===//
#include "sanitizer_common/sanitizer_allocator_internal.h"
#include "sanitizer_common/sanitizer_platform.h"
#include "lsan_common.h"
#if CAN_SANITIZE_LEAKS && SANITIZER_MAC
#include <pthread.h>
namespace __lsan {
typedef struct {
int disable_counter;
u32 current_thread_id;
} thread_local_data_t;
static pthread_key_t key;
static pthread_once_t key_once = PTHREAD_ONCE_INIT;
static void make_tls_key() { CHECK_EQ(pthread_key_create(&key, NULL), 0); }
static thread_local_data_t *get_tls_val() {
pthread_once(&key_once, make_tls_key);
thread_local_data_t *ptr = (thread_local_data_t *)pthread_getspecific(key);
if (ptr == NULL) {
ptr = (thread_local_data_t *)InternalAlloc(sizeof(*ptr));
ptr->disable_counter = 0;
ptr->current_thread_id = kInvalidTid;
pthread_setspecific(key, ptr);
}
return ptr;
}
bool DisabledInThisThread() { return get_tls_val()->disable_counter > 0; }
void DisableInThisThread() { ++get_tls_val()->disable_counter; }
void EnableInThisThread() {
int *disable_counter = &get_tls_val()->disable_counter;
if (*disable_counter == 0) {
DisableCounterUnderflow();
}
--*disable_counter;
}
u32 GetCurrentThread() { return get_tls_val()->current_thread_id; }
void SetCurrentThread(u32 tid) { get_tls_val()->current_thread_id = tid; }
void InitializePlatformSpecificModules() {
CHECK(0 && "unimplemented");
}
// Scans global variables for heap pointers.
void ProcessGlobalRegions(Frontier *frontier) {
CHECK(0 && "unimplemented");
}
void ProcessPlatformSpecificAllocations(Frontier *frontier) {
CHECK(0 && "unimplemented");
}
void DoStopTheWorld(StopTheWorldCallback callback, void *argument) {
CHECK(0 && "unimplemented");
}
} // namespace __lsan
#endif // CAN_SANITIZE_LEAKS && SANITIZER_MAC