2014-04-04 17:47:41 +08:00
|
|
|
//===-- msan_thread.h -------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2014-04-04 17:47:41 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of MemorySanitizer.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef MSAN_THREAD_H
|
|
|
|
#define MSAN_THREAD_H
|
|
|
|
|
|
|
|
#include "msan_allocator.h"
|
|
|
|
#include "sanitizer_common/sanitizer_common.h"
|
2021-11-06 10:57:19 +08:00
|
|
|
#include "sanitizer_common/sanitizer_posix.h"
|
2014-04-04 17:47:41 +08:00
|
|
|
namespace __msan {
|
|
|
|
|
|
|
|
class MsanThread {
|
|
|
|
public:
|
|
|
|
static MsanThread *Create(thread_callback_t start_routine, void *arg);
|
|
|
|
static void TSDDtor(void *tsd);
|
|
|
|
void Destroy();
|
|
|
|
|
|
|
|
void Init(); // Should be called from the thread itself.
|
|
|
|
thread_return_t ThreadStart();
|
|
|
|
|
2020-08-28 10:21:59 +08:00
|
|
|
uptr stack_top();
|
|
|
|
uptr stack_bottom();
|
2014-04-04 17:47:41 +08:00
|
|
|
uptr tls_begin() { return tls_begin_; }
|
|
|
|
uptr tls_end() { return tls_end_; }
|
2015-10-01 08:22:21 +08:00
|
|
|
bool IsMainThread() { return start_routine_ == nullptr; }
|
2014-04-04 17:47:41 +08:00
|
|
|
|
2020-08-28 10:21:59 +08:00
|
|
|
bool AddrIsInStack(uptr addr);
|
2014-04-04 17:47:41 +08:00
|
|
|
|
2014-04-23 22:01:57 +08:00
|
|
|
bool InSignalHandler() { return in_signal_handler_; }
|
|
|
|
void EnterSignalHandler() { in_signal_handler_++; }
|
|
|
|
void LeaveSignalHandler() { in_signal_handler_--; }
|
|
|
|
|
2020-08-28 10:21:59 +08:00
|
|
|
void StartSwitchFiber(uptr bottom, uptr size);
|
|
|
|
void FinishSwitchFiber(uptr *bottom_old, uptr *size_old);
|
|
|
|
|
2014-04-04 17:47:41 +08:00
|
|
|
MsanThreadLocalMallocStorage &malloc_storage() { return malloc_storage_; }
|
|
|
|
|
|
|
|
int destructor_iterations_;
|
2021-11-06 10:57:19 +08:00
|
|
|
__sanitizer_sigset_t starting_sigset_;
|
2014-04-04 17:47:41 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
// NOTE: There is no MsanThread constructor. It is allocated
|
|
|
|
// via mmap() and *must* be valid in zero-initialized state.
|
|
|
|
void SetThreadStackAndTls();
|
|
|
|
void ClearShadowForThreadStackAndTLS();
|
2020-08-28 10:21:59 +08:00
|
|
|
struct StackBounds {
|
|
|
|
uptr bottom;
|
|
|
|
uptr top;
|
|
|
|
};
|
|
|
|
StackBounds GetStackBounds() const;
|
2014-04-04 17:47:41 +08:00
|
|
|
thread_callback_t start_routine_;
|
|
|
|
void *arg_;
|
2020-08-28 10:21:59 +08:00
|
|
|
|
|
|
|
bool stack_switching_;
|
|
|
|
|
|
|
|
StackBounds stack_;
|
|
|
|
StackBounds next_stack_;
|
|
|
|
|
2014-04-04 17:47:41 +08:00
|
|
|
uptr tls_begin_;
|
|
|
|
uptr tls_end_;
|
|
|
|
|
2014-04-23 22:01:57 +08:00
|
|
|
unsigned in_signal_handler_;
|
|
|
|
|
2014-04-04 17:47:41 +08:00
|
|
|
MsanThreadLocalMallocStorage malloc_storage_;
|
|
|
|
};
|
|
|
|
|
|
|
|
MsanThread *GetCurrentThread();
|
|
|
|
void SetCurrentThread(MsanThread *t);
|
|
|
|
|
|
|
|
} // namespace __msan
|
|
|
|
|
|
|
|
#endif // MSAN_THREAD_H
|