Path: blob/main/contrib/llvm-project/compiler-rt/lib/msan/msan_thread.h
35262 views
//===-- msan_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 MemorySanitizer.9//10//===----------------------------------------------------------------------===//1112#ifndef MSAN_THREAD_H13#define MSAN_THREAD_H1415#include "msan_allocator.h"16#include "sanitizer_common/sanitizer_common.h"17#include "sanitizer_common/sanitizer_posix.h"18namespace __msan {1920class MsanThread {21public:22static MsanThread *Create(thread_callback_t start_routine, void *arg);23static void TSDDtor(void *tsd);24void Destroy();2526void Init(); // Should be called from the thread itself.27thread_return_t ThreadStart();2829uptr stack_top();30uptr stack_bottom();31uptr tls_begin() { return tls_begin_; }32uptr tls_end() { return tls_end_; }33bool IsMainThread() { return start_routine_ == nullptr; }3435bool AddrIsInStack(uptr addr);3637bool InSignalHandler() { return in_signal_handler_; }38void EnterSignalHandler() { in_signal_handler_++; }39void LeaveSignalHandler() { in_signal_handler_--; }4041void StartSwitchFiber(uptr bottom, uptr size);42void FinishSwitchFiber(uptr *bottom_old, uptr *size_old);4344MsanThreadLocalMallocStorage &malloc_storage() { return malloc_storage_; }4546int destructor_iterations_;47__sanitizer_sigset_t starting_sigset_;4849private:50// NOTE: There is no MsanThread constructor. It is allocated51// via mmap() and *must* be valid in zero-initialized state.52void SetThreadStackAndTls();53void ClearShadowForThreadStackAndTLS();54struct StackBounds {55uptr bottom;56uptr top;57};58StackBounds GetStackBounds() const;59thread_callback_t start_routine_;60void *arg_;6162bool stack_switching_;6364StackBounds stack_;65StackBounds next_stack_;6667uptr tls_begin_;68uptr tls_end_;6970unsigned in_signal_handler_;7172MsanThreadLocalMallocStorage malloc_storage_;73};7475MsanThread *GetCurrentThread();76void SetCurrentThread(MsanThread *t);7778} // namespace __msan7980#endif // MSAN_THREAD_H818283