1//=-- lsan_thread.h -------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file is a part of LeakSanitizer.
10// Thread registry for standalone LSan.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LSAN_THREAD_H
15#define LSAN_THREAD_H
16
17#include "sanitizer_common/sanitizer_thread_registry.h"
18
19namespace __sanitizer {
20struct DTLS;
21}
22
23namespace __lsan {
24
25class ThreadContext : public ThreadContextBase {
26 public:
27  explicit ThreadContext(int tid);
28  void OnStarted(void *arg) override;
29  void OnFinished() override;
30  uptr stack_begin() { return stack_begin_; }
31  uptr stack_end() { return stack_end_; }
32  uptr tls_begin() { return tls_begin_; }
33  uptr tls_end() { return tls_end_; }
34  uptr cache_begin() { return cache_begin_; }
35  uptr cache_end() { return cache_end_; }
36  DTLS *dtls() { return dtls_; }
37
38 private:
39  uptr stack_begin_, stack_end_,
40       cache_begin_, cache_end_,
41       tls_begin_, tls_end_;
42  DTLS *dtls_;
43};
44
45void InitializeThreadRegistry();
46
47void ThreadStart(u32 tid, tid_t os_id,
48                 ThreadType thread_type = ThreadType::Regular);
49void ThreadFinish();
50u32 ThreadCreate(u32 tid, uptr uid, bool detached);
51void ThreadJoin(u32 tid);
52u32 ThreadTid(uptr uid);
53
54u32 GetCurrentThread();
55void SetCurrentThread(u32 tid);
56ThreadContext *CurrentThreadContext();
57void EnsureMainThreadIDIsCorrect();
58}  // namespace __lsan
59
60#endif  // LSAN_THREAD_H
61