Path: blob/main/contrib/llvm-project/compiler-rt/lib/dfsan/dfsan_thread.h
35233 views
//===-- dfsan_thread.h ------------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file is a part of DataFlowSanitizer.9//10//===----------------------------------------------------------------------===//1112#ifndef DFSAN_THREAD_H13#define DFSAN_THREAD_H1415#include "dfsan_allocator.h"16#include "sanitizer_common/sanitizer_common.h"17#include "sanitizer_common/sanitizer_posix.h"1819namespace __dfsan {2021class DFsanThread {22public:23// NOTE: There is no DFsanThread constructor. It is allocated24// via mmap() and *must* be valid in zero-initialized state.2526static DFsanThread *Create(thread_callback_t start_routine, void *arg,27bool track_origins = false);28static void TSDDtor(void *tsd);29void Destroy();3031void Init(); // Should be called from the thread itself.32thread_return_t ThreadStart();3334uptr stack_top();35uptr stack_bottom();36uptr tls_begin() { return tls_begin_; }37uptr tls_end() { return tls_end_; }38bool IsMainThread() { return start_routine_ == nullptr; }3940bool InSignalHandler() { return in_signal_handler_; }41void EnterSignalHandler() { in_signal_handler_++; }42void LeaveSignalHandler() { in_signal_handler_--; }4344DFsanThreadLocalMallocStorage &malloc_storage() { return malloc_storage_; }4546int destructor_iterations_;47__sanitizer_sigset_t starting_sigset_;4849private:50void SetThreadStackAndTls();51void ClearShadowForThreadStackAndTLS();52struct StackBounds {53uptr bottom;54uptr top;55};56StackBounds GetStackBounds() const;5758bool AddrIsInStack(uptr addr);5960thread_callback_t start_routine_;61void *arg_;62bool track_origins_;6364StackBounds stack_;6566uptr tls_begin_;67uptr tls_end_;6869unsigned in_signal_handler_;7071DFsanThreadLocalMallocStorage malloc_storage_;72};7374DFsanThread *GetCurrentThread();75void SetCurrentThread(DFsanThread *t);76void DFsanTSDInit(void (*destructor)(void *tsd));77void DFsanTSDDtor(void *tsd);7879} // namespace __dfsan8081#endif // DFSAN_THREAD_H828384