Path: blob/main/contrib/llvm-project/compiler-rt/lib/lsan/lsan_thread.h
35233 views
//=-- lsan_thread.h -------------------------------------------------------===//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 LeakSanitizer.9// Thread registry for standalone LSan.10//11//===----------------------------------------------------------------------===//1213#ifndef LSAN_THREAD_H14#define LSAN_THREAD_H1516#include "sanitizer_common/sanitizer_thread_arg_retval.h"17#include "sanitizer_common/sanitizer_thread_registry.h"1819namespace __lsan {2021class ThreadContextLsanBase : public ThreadContextBase {22public:23explicit ThreadContextLsanBase(int tid);24void OnStarted(void *arg) override;25void OnFinished() override;26uptr stack_begin() { return stack_begin_; }27uptr stack_end() { return stack_end_; }28uptr cache_begin() { return cache_begin_; }29uptr cache_end() { return cache_end_; }3031// The argument is passed on to the subclass's OnStarted member function.32static void ThreadStart(u32 tid, tid_t os_id, ThreadType thread_type,33void *onstarted_arg);3435protected:36~ThreadContextLsanBase() {}37uptr stack_begin_ = 0;38uptr stack_end_ = 0;39uptr cache_begin_ = 0;40uptr cache_end_ = 0;41};4243// This subclass of ThreadContextLsanBase is declared in an OS-specific header.44class ThreadContext;4546void InitializeThreads();47void InitializeMainThread();4849ThreadRegistry *GetLsanThreadRegistryLocked();50ThreadArgRetval &GetThreadArgRetval();5152u32 ThreadCreate(u32 tid, bool detached, void *arg = nullptr);53void ThreadFinish();5455ThreadContextLsanBase *GetCurrentThread();56inline u32 GetCurrentThreadId() {57ThreadContextLsanBase *ctx = GetCurrentThread();58return ctx ? ctx->tid : kInvalidTid;59}60void SetCurrentThread(ThreadContextLsanBase *tctx);61void EnsureMainThreadIDIsCorrect();6263} // namespace __lsan6465#endif // LSAN_THREAD_H666768