#include "sanitizer_common/sanitizer_platform.h"
#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
# include <elf.h>
# include <link.h>
# include <pthread.h>
# include <signal.h>
# include <stdio.h>
# include <stdlib.h>
# if SANITIZER_LINUX
# include <sys/personality.h>
# endif
# include <sys/resource.h>
# include <sys/time.h>
# include <unistd.h>
# include <unwind.h>
# include "msan.h"
# include "msan_allocator.h"
# include "msan_chained_origin_depot.h"
# include "msan_report.h"
# include "msan_thread.h"
# include "sanitizer_common/sanitizer_common.h"
# include "sanitizer_common/sanitizer_procmaps.h"
# include "sanitizer_common/sanitizer_stackdepot.h"
namespace __msan {
void ReportMapRange(const char *descr, uptr beg, uptr size) { … }
static bool CheckMemoryRangeAvailability(uptr beg, uptr size, bool verbose) { … }
static bool ProtectMemoryRange(uptr beg, uptr size, const char *name) { … }
static void CheckMemoryLayoutSanity() { … }
static bool InitShadow(bool init_origins, bool dry_run) { … }
bool InitShadowWithReExec(bool init_origins) { … }
static void MsanAtExit(void) { … }
void InstallAtExitHandler() { … }
#if SANITIZER_NETBSD
static void (*tsd_destructor)(void *tsd) = nullptr;
struct tsd_key {
tsd_key() : key(nullptr) {}
~tsd_key() {
CHECK(tsd_destructor);
if (key)
(*tsd_destructor)(key);
}
MsanThread *key;
};
static thread_local struct tsd_key key;
void MsanTSDInit(void (*destructor)(void *tsd)) {
CHECK(!tsd_destructor);
tsd_destructor = destructor;
}
MsanThread *GetCurrentThread() {
CHECK(tsd_destructor);
return key.key;
}
void SetCurrentThread(MsanThread *tsd) {
CHECK(tsd_destructor);
CHECK(tsd);
CHECK(!key.key);
key.key = tsd;
}
void MsanTSDDtor(void *tsd) {
CHECK(tsd_destructor);
CHECK_EQ(key.key, tsd);
key.key = nullptr;
atomic_signal_fence(memory_order_seq_cst);
MsanThread::TSDDtor(tsd);
}
#else
static pthread_key_t tsd_key;
static bool tsd_key_inited = …;
void MsanTSDInit(void (*destructor)(void *tsd)) { … }
static THREADLOCAL MsanThread* msan_current_thread;
MsanThread *GetCurrentThread() { … }
void SetCurrentThread(MsanThread *t) { … }
void MsanTSDDtor(void *tsd) { … }
# endif
static void BeforeFork() { … }
static void AfterFork(bool fork_child) { … }
void InstallAtForkHandler() { … }
}
#endif