[sanitizer_common][nfc] Rename tid_t to avoid conflicting declarations (#149011)

`tid_t` is also defined in the AIX header `/usr/include/sys/types.h`
which is included by system `pthread.h`. The use of `tid_t` by AIX is
conforming according to
[POSIX](https://pubs.opengroup.org/onlinepubs/9799919799/functions/V2_chap02.html):
> Implementations may add symbols to the headers shown in the following
table [ ... ]
This commit is contained in:
Jake Egan 2025-07-23 09:39:19 -04:00 committed by GitHub
parent 43db6c5cc1
commit 8e072b9d49
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
39 changed files with 127 additions and 127 deletions

View File

@ -282,7 +282,7 @@ void AsanThread::Init(const InitOptions *options) {
// asan_fuchsia.c definies CreateMainThread and SetThreadStackAndTls.
#if !SANITIZER_FUCHSIA
void AsanThread::ThreadStart(tid_t os_id) {
void AsanThread::ThreadStart(ThreadID os_id) {
Init();
asanThreadRegistry().StartThread(tid(), os_id, ThreadType::Regular, nullptr);
@ -469,7 +469,7 @@ void EnsureMainThreadIDIsCorrect() {
context->os_id = GetTid();
}
__asan::AsanThread *GetAsanThreadByOsIDLocked(tid_t os_id) {
__asan::AsanThread *GetAsanThreadByOsIDLocked(ThreadID os_id) {
__asan::AsanThreadContext *context = static_cast<__asan::AsanThreadContext *>(
__asan::asanThreadRegistry().FindThreadContextByOsIDLocked(os_id));
if (!context)
@ -497,7 +497,7 @@ static ThreadRegistry *GetAsanThreadRegistryLocked() {
void EnsureMainThreadIDIsCorrect() { __asan::EnsureMainThreadIDIsCorrect(); }
bool GetThreadRangesLocked(tid_t os_id, uptr *stack_begin, uptr *stack_end,
bool GetThreadRangesLocked(ThreadID os_id, uptr *stack_begin, uptr *stack_end,
uptr *tls_begin, uptr *tls_end, uptr *cache_begin,
uptr *cache_end, DTLS **dtls) {
__asan::AsanThread *t = __asan::GetAsanThreadByOsIDLocked(os_id);
@ -516,7 +516,7 @@ bool GetThreadRangesLocked(tid_t os_id, uptr *stack_begin, uptr *stack_end,
void GetAllThreadAllocatorCachesLocked(InternalMmapVector<uptr> *caches) {}
void GetThreadExtraStackRangesLocked(tid_t os_id,
void GetThreadExtraStackRangesLocked(ThreadID os_id,
InternalMmapVector<Range> *ranges) {
__asan::AsanThread *t = __asan::GetAsanThreadByOsIDLocked(os_id);
if (!t)
@ -546,11 +546,11 @@ void GetAdditionalThreadContextPtrsLocked(InternalMmapVector<uptr> *ptrs) {
__asan::asanThreadArgRetval().GetAllPtrsLocked(ptrs);
}
void GetRunningThreadsLocked(InternalMmapVector<tid_t> *threads) {
void GetRunningThreadsLocked(InternalMmapVector<ThreadID> *threads) {
GetAsanThreadRegistryLocked()->RunCallbackForEachThreadLocked(
[](ThreadContextBase *tctx, void *threads) {
if (tctx->status == ThreadStatusRunning)
reinterpret_cast<InternalMmapVector<tid_t> *>(threads)->push_back(
reinterpret_cast<InternalMmapVector<ThreadID> *>(threads)->push_back(
tctx->os_id);
},
threads);

View File

@ -75,7 +75,7 @@ class AsanThread {
struct InitOptions;
void Init(const InitOptions *options = nullptr);
void ThreadStart(tid_t os_id);
void ThreadStart(ThreadID os_id);
thread_return_t RunThread();
uptr stack_top();

View File

@ -174,7 +174,7 @@ static __hwasan::HwasanThreadList *GetHwasanThreadListLocked() {
return &tl;
}
static __hwasan::Thread *GetThreadByOsIDLocked(tid_t os_id) {
static __hwasan::Thread *GetThreadByOsIDLocked(ThreadID os_id) {
return GetHwasanThreadListLocked()->FindThreadLocked(
[os_id](__hwasan::Thread *t) { return t->os_id() == os_id; });
}
@ -191,7 +191,7 @@ void UnlockThreads() {
void EnsureMainThreadIDIsCorrect() { __hwasan::EnsureMainThreadIDIsCorrect(); }
bool GetThreadRangesLocked(tid_t os_id, uptr *stack_begin, uptr *stack_end,
bool GetThreadRangesLocked(ThreadID os_id, uptr *stack_begin, uptr *stack_end,
uptr *tls_begin, uptr *tls_end, uptr *cache_begin,
uptr *cache_end, DTLS **dtls) {
auto *t = GetThreadByOsIDLocked(os_id);
@ -210,7 +210,7 @@ bool GetThreadRangesLocked(tid_t os_id, uptr *stack_begin, uptr *stack_end,
void GetAllThreadAllocatorCachesLocked(InternalMmapVector<uptr> *caches) {}
void GetThreadExtraStackRangesLocked(tid_t os_id,
void GetThreadExtraStackRangesLocked(ThreadID os_id,
InternalMmapVector<Range> *ranges) {}
void GetThreadExtraStackRangesLocked(InternalMmapVector<Range> *ranges) {}
@ -218,7 +218,7 @@ void GetAdditionalThreadContextPtrsLocked(InternalMmapVector<uptr> *ptrs) {
__hwasan::hwasanThreadArgRetval().GetAllPtrsLocked(ptrs);
}
void GetRunningThreadsLocked(InternalMmapVector<tid_t> *threads) {
void GetRunningThreadsLocked(InternalMmapVector<ThreadID> *threads) {
// TODO: implement.
}
void PrintThreads() {

View File

@ -69,8 +69,8 @@ class Thread {
Print("Thread: ");
}
tid_t os_id() const { return os_id_; }
void set_os_id(tid_t os_id) { os_id_ = os_id; }
ThreadID os_id() const { return os_id_; }
void set_os_id(ThreadID os_id) { os_id_ = os_id; }
uptr &vfork_spill() { return vfork_spill_; }
@ -96,7 +96,7 @@ class Thread {
u32 unique_id_; // counting from zero.
tid_t os_id_;
ThreadID os_id_;
u32 tagging_disabled_; // if non-zero, malloc uses zero tag in this thread.

View File

@ -412,7 +412,7 @@ void ScanExtraStackRanges(const InternalMmapVector<Range> &ranges,
# if SANITIZER_FUCHSIA
// Fuchsia handles all threads together with its own callback.
static void ProcessThreads(SuspendedThreadsList const &, Frontier *, tid_t,
static void ProcessThreads(SuspendedThreadsList const &, Frontier *, ThreadID,
uptr) {}
# else
@ -445,7 +445,7 @@ static void ProcessThreadRegistry(Frontier *frontier) {
// Scans thread data (stacks and TLS) for heap pointers.
template <class Accessor>
static void ProcessThread(tid_t os_id, uptr sp,
static void ProcessThread(ThreadID os_id, uptr sp,
const InternalMmapVector<uptr> &registers,
InternalMmapVector<Range> &extra_ranges,
Frontier *frontier, Accessor &accessor) {
@ -556,16 +556,16 @@ static void ProcessThread(tid_t os_id, uptr sp,
}
static void ProcessThreads(SuspendedThreadsList const &suspended_threads,
Frontier *frontier, tid_t caller_tid,
Frontier *frontier, ThreadID caller_tid,
uptr caller_sp) {
InternalMmapVector<tid_t> done_threads;
InternalMmapVector<ThreadID> done_threads;
InternalMmapVector<uptr> registers;
InternalMmapVector<Range> extra_ranges;
for (uptr i = 0; i < suspended_threads.ThreadCount(); i++) {
registers.clear();
extra_ranges.clear();
const tid_t os_id = suspended_threads.GetThreadID(i);
const ThreadID os_id = suspended_threads.GetThreadID(i);
uptr sp = 0;
PtraceRegistersStatus have_registers =
suspended_threads.GetRegistersAndSP(i, &registers, &sp);
@ -589,10 +589,10 @@ static void ProcessThreads(SuspendedThreadsList const &suspended_threads,
if (flags()->use_detached) {
CopyMemoryAccessor accessor;
InternalMmapVector<tid_t> known_threads;
InternalMmapVector<ThreadID> known_threads;
GetRunningThreadsLocked(&known_threads);
Sort(done_threads.data(), done_threads.size());
for (tid_t os_id : known_threads) {
for (ThreadID os_id : known_threads) {
registers.clear();
extra_ranges.clear();
@ -712,7 +712,7 @@ static void CollectIgnoredCb(uptr chunk, void *arg) {
// Sets the appropriate tag on each chunk.
static void ClassifyAllChunks(SuspendedThreadsList const &suspended_threads,
Frontier *frontier, tid_t caller_tid,
Frontier *frontier, ThreadID caller_tid,
uptr caller_sp) {
const InternalMmapVector<u32> &suppressed_stacks =
GetSuppressionContext()->GetSortedSuppressedStacks();
@ -790,13 +790,13 @@ static bool ReportUnsuspendedThreads(const SuspendedThreadsList &) {
static bool ReportUnsuspendedThreads(
const SuspendedThreadsList &suspended_threads) {
InternalMmapVector<tid_t> threads(suspended_threads.ThreadCount());
InternalMmapVector<ThreadID> threads(suspended_threads.ThreadCount());
for (uptr i = 0; i < suspended_threads.ThreadCount(); ++i)
threads[i] = suspended_threads.GetThreadID(i);
Sort(threads.data(), threads.size());
InternalMmapVector<tid_t> known_threads;
InternalMmapVector<ThreadID> known_threads;
GetRunningThreadsLocked(&known_threads);
bool succeded = true;

View File

@ -102,15 +102,15 @@ void UnlockThreads() SANITIZER_NO_THREAD_SAFETY_ANALYSIS;
// where leak checking is initiated from a non-main thread).
void EnsureMainThreadIDIsCorrect();
bool GetThreadRangesLocked(tid_t os_id, uptr *stack_begin, uptr *stack_end,
bool GetThreadRangesLocked(ThreadID os_id, uptr *stack_begin, uptr *stack_end,
uptr *tls_begin, uptr *tls_end, uptr *cache_begin,
uptr *cache_end, DTLS **dtls);
void GetAllThreadAllocatorCachesLocked(InternalMmapVector<uptr> *caches);
void GetThreadExtraStackRangesLocked(InternalMmapVector<Range> *ranges);
void GetThreadExtraStackRangesLocked(tid_t os_id,
void GetThreadExtraStackRangesLocked(ThreadID os_id,
InternalMmapVector<Range> *ranges);
void GetAdditionalThreadContextPtrsLocked(InternalMmapVector<uptr> *ptrs);
void GetRunningThreadsLocked(InternalMmapVector<tid_t> *threads);
void GetRunningThreadsLocked(InternalMmapVector<ThreadID> *threads);
void PrintThreads();
//// --------------------------------------------------------------------------
@ -247,7 +247,7 @@ void ProcessPlatformSpecificAllocations(Frontier *frontier);
struct CheckForLeaksParam {
Frontier frontier;
LeakedChunks leaks;
tid_t caller_tid;
ThreadID caller_tid;
uptr caller_sp;
bool success = false;
};

View File

@ -385,12 +385,12 @@ INTERCEPTOR(void, _lwp_exit) {
#endif
#if SANITIZER_INTERCEPT_THR_EXIT
INTERCEPTOR(void, thr_exit, tid_t *state) {
INTERCEPTOR(void, thr_exit, ThreadID *state) {
ENSURE_LSAN_INITED;
ThreadFinish();
REAL(thr_exit)(state);
}
#define LSAN_MAYBE_INTERCEPT_THR_EXIT INTERCEPT_FUNCTION(thr_exit)
# define LSAN_MAYBE_INTERCEPT_THR_EXIT INTERCEPT_FUNCTION(thr_exit)
#else
#define LSAN_MAYBE_INTERCEPT_THR_EXIT
#endif

View File

@ -48,7 +48,7 @@ void ThreadContext::OnStarted(void *arg) {
dtls_ = args->dtls;
}
void ThreadStart(u32 tid, tid_t os_id, ThreadType thread_type) {
void ThreadStart(u32 tid, ThreadID os_id, ThreadType thread_type) {
OnStartedArgs args;
GetThreadStackAndTls(tid == kMainTid, &args.stack_begin, &args.stack_end,
&args.tls_begin, &args.tls_end);
@ -57,7 +57,7 @@ void ThreadStart(u32 tid, tid_t os_id, ThreadType thread_type) {
ThreadContextLsanBase::ThreadStart(tid, os_id, thread_type, &args);
}
bool GetThreadRangesLocked(tid_t os_id, uptr *stack_begin, uptr *stack_end,
bool GetThreadRangesLocked(ThreadID os_id, uptr *stack_begin, uptr *stack_end,
uptr *tls_begin, uptr *tls_end, uptr *cache_begin,
uptr *cache_end, DTLS **dtls) {
ThreadContext *context = static_cast<ThreadContext *>(

View File

@ -41,7 +41,7 @@ class ThreadContext final : public ThreadContextLsanBase {
DTLS *dtls_ = nullptr;
};
void ThreadStart(u32 tid, tid_t os_id,
void ThreadStart(u32 tid, ThreadID os_id,
ThreadType thread_type = ThreadType::Regular);
} // namespace __lsan

View File

@ -66,7 +66,7 @@ u32 ThreadCreate(u32 parent_tid, bool detached, void *arg) {
return thread_registry->CreateThread(0, detached, parent_tid, arg);
}
void ThreadContextLsanBase::ThreadStart(u32 tid, tid_t os_id,
void ThreadContextLsanBase::ThreadStart(u32 tid, ThreadID os_id,
ThreadType thread_type, void *arg) {
thread_registry->StartThread(tid, os_id, thread_type, arg);
}
@ -80,7 +80,7 @@ void EnsureMainThreadIDIsCorrect() {
///// Interface to the common LSan module. /////
void GetThreadExtraStackRangesLocked(tid_t os_id,
void GetThreadExtraStackRangesLocked(ThreadID os_id,
InternalMmapVector<Range> *ranges) {}
void GetThreadExtraStackRangesLocked(InternalMmapVector<Range> *ranges) {}
@ -99,11 +99,11 @@ ThreadRegistry *GetLsanThreadRegistryLocked() {
return thread_registry;
}
void GetRunningThreadsLocked(InternalMmapVector<tid_t> *threads) {
void GetRunningThreadsLocked(InternalMmapVector<ThreadID> *threads) {
GetLsanThreadRegistryLocked()->RunCallbackForEachThreadLocked(
[](ThreadContextBase *tctx, void *threads) {
if (tctx->status == ThreadStatusRunning) {
reinterpret_cast<InternalMmapVector<tid_t> *>(threads)->push_back(
reinterpret_cast<InternalMmapVector<ThreadID> *>(threads)->push_back(
tctx->os_id);
}
},

View File

@ -30,7 +30,7 @@ class ThreadContextLsanBase : public ThreadContextBase {
uptr cache_end() { return cache_end_; }
// The argument is passed on to the subclass's OnStarted member function.
static void ThreadStart(u32 tid, tid_t os_id, ThreadType thread_type,
static void ThreadStart(u32 tid, ThreadID os_id, ThreadType thread_type,
void *onstarted_arg);
protected:

View File

@ -131,7 +131,7 @@ void MemprofThread::Init(const InitOptions *options) {
}
thread_return_t
MemprofThread::ThreadStart(tid_t os_id,
MemprofThread::ThreadStart(ThreadID os_id,
atomic_uintptr_t *signal_thread_is_registered) {
Init();
memprofThreadRegistry().StartThread(tid(), os_id, ThreadType::Regular,

View File

@ -59,7 +59,7 @@ public:
struct InitOptions;
void Init(const InitOptions *options = nullptr);
thread_return_t ThreadStart(tid_t os_id,
thread_return_t ThreadStart(ThreadID os_id,
atomic_uintptr_t *signal_thread_is_registered);
uptr stack_top();

View File

@ -78,8 +78,8 @@ uptr GetMmapGranularity();
uptr GetMaxVirtualAddress();
uptr GetMaxUserVirtualAddress();
// Threads
tid_t GetTid();
int TgKill(pid_t pid, tid_t tid, int sig);
ThreadID GetTid();
int TgKill(pid_t pid, ThreadID tid, int sig);
uptr GetThreadSelf();
void GetThreadStackTopAndBottom(bool at_initialization, uptr *stack_top,
uptr *stack_bottom);

View File

@ -68,7 +68,7 @@ int internal_dlinfo(void *handle, int request, void *p) { UNIMPLEMENTED(); }
uptr GetThreadSelf() { return reinterpret_cast<uptr>(thrd_current()); }
tid_t GetTid() { return GetThreadSelf(); }
ThreadID GetTid() { return GetThreadSelf(); }
void Abort() { abort(); }

View File

@ -231,12 +231,12 @@ uptr internal_execve(const char *filename, char *const argv[],
}
# if 0
tid_t GetTid() {
ThreadID GetTid() {
DEFINE__REAL(int, _lwp_self);
return _REAL(_lwp_self);
}
int TgKill(pid_t pid, tid_t tid, int sig) {
int TgKill(pid_t pid, ThreadID tid, int sig) {
DEFINE__REAL(int, _lwp_kill, int a, int b);
(void)pid;
return _REAL(_lwp_kill, tid, sig);

View File

@ -209,7 +209,7 @@ typedef long ssize;
typedef sptr ssize;
#endif
typedef u64 tid_t;
typedef u64 ThreadID;
// ----------- ATTENTION -------------
// This header should NOT include any other headers to avoid portability issues.

View File

@ -638,7 +638,7 @@ bool DirExists(const char *path) {
}
# if !SANITIZER_NETBSD
tid_t GetTid() {
ThreadID GetTid() {
# if SANITIZER_FREEBSD
long Tid;
thr_self(&Tid);
@ -652,7 +652,7 @@ tid_t GetTid() {
# endif
}
int TgKill(pid_t pid, tid_t tid, int sig) {
int TgKill(pid_t pid, ThreadID tid, int sig) {
# if SANITIZER_LINUX
return internal_syscall(SYSCALL(tgkill), pid, tid, sig);
# elif SANITIZER_FREEBSD
@ -1089,7 +1089,7 @@ ThreadLister::ThreadLister(pid_t pid) : buffer_(4096) {
}
ThreadLister::Result ThreadLister::ListThreads(
InternalMmapVector<tid_t> *threads) {
InternalMmapVector<ThreadID> *threads) {
int descriptor = internal_open(task_path_.data(), O_RDONLY | O_DIRECTORY);
if (internal_iserror(descriptor)) {
Report("Can't open %s for reading.\n", task_path_.data());
@ -1144,7 +1144,7 @@ ThreadLister::Result ThreadLister::ListThreads(
}
}
const char *ThreadLister::LoadStatus(tid_t tid) {
const char *ThreadLister::LoadStatus(ThreadID tid) {
status_path_.clear();
status_path_.AppendF("%s/%llu/status", task_path_.data(), tid);
auto cleanup = at_scope_exit([&] {
@ -1157,7 +1157,7 @@ const char *ThreadLister::LoadStatus(tid_t tid) {
return buffer_.data();
}
bool ThreadLister::IsAlive(tid_t tid) {
bool ThreadLister::IsAlive(ThreadID tid) {
// /proc/%d/task/%d/status uses same call to detect alive threads as
// proc_task_readdir. See task_state implementation in Linux.
static const char kPrefix[] = "\nPPid:";

View File

@ -108,11 +108,11 @@ class ThreadLister {
Incomplete,
Ok,
};
Result ListThreads(InternalMmapVector<tid_t> *threads);
const char *LoadStatus(tid_t tid);
Result ListThreads(InternalMmapVector<ThreadID> *threads);
const char *LoadStatus(ThreadID tid);
private:
bool IsAlive(tid_t tid);
bool IsAlive(ThreadID tid);
InternalScopedString task_path_;
InternalScopedString status_path_;

View File

@ -394,8 +394,8 @@ bool DirExists(const char *path) {
return S_ISDIR(st.st_mode);
}
tid_t GetTid() {
tid_t tid;
ThreadID GetTid() {
ThreadID tid;
pthread_threadid_np(nullptr, &tid);
return tid;
}

View File

@ -229,12 +229,12 @@ uptr internal_execve(const char *filename, char *const argv[],
return _sys_execve(filename, argv, envp);
}
tid_t GetTid() {
ThreadID GetTid() {
DEFINE__REAL(int, _lwp_self);
return _REAL(_lwp_self);
}
int TgKill(pid_t pid, tid_t tid, int sig) {
int TgKill(pid_t pid, ThreadID tid, int sig) {
DEFINE__REAL(int, _lwp_kill, int a, int b);
(void)pid;
return _REAL(_lwp_kill, tid, sig);

View File

@ -38,7 +38,7 @@ class SuspendedThreadsList {
}
virtual uptr ThreadCount() const { UNIMPLEMENTED(); }
virtual tid_t GetThreadID(uptr index) const { UNIMPLEMENTED(); }
virtual ThreadID GetThreadID(uptr index) const { UNIMPLEMENTED(); }
protected:
~SuspendedThreadsList() {}

View File

@ -94,17 +94,17 @@ class SuspendedThreadsListLinux final : public SuspendedThreadsList {
public:
SuspendedThreadsListLinux() { thread_ids_.reserve(1024); }
tid_t GetThreadID(uptr index) const override;
ThreadID GetThreadID(uptr index) const override;
uptr ThreadCount() const override;
bool ContainsTid(tid_t thread_id) const;
void Append(tid_t tid);
bool ContainsTid(ThreadID thread_id) const;
void Append(ThreadID tid);
PtraceRegistersStatus GetRegistersAndSP(uptr index,
InternalMmapVector<uptr> *buffer,
uptr *sp) const override;
private:
InternalMmapVector<tid_t> thread_ids_;
InternalMmapVector<ThreadID> thread_ids_;
};
// Structure for passing arguments into the tracer thread.
@ -137,10 +137,10 @@ class ThreadSuspender {
private:
SuspendedThreadsListLinux suspended_threads_list_;
pid_t pid_;
bool SuspendThread(tid_t thread_id);
bool SuspendThread(ThreadID thread_id);
};
bool ThreadSuspender::SuspendThread(tid_t tid) {
bool ThreadSuspender::SuspendThread(ThreadID tid) {
int pterrno;
if (internal_iserror(internal_ptrace(PTRACE_ATTACH, tid, nullptr, nullptr),
&pterrno)) {
@ -210,7 +210,7 @@ void ThreadSuspender::KillAllThreads() {
bool ThreadSuspender::SuspendAllThreads() {
ThreadLister thread_lister(pid_);
bool retry = true;
InternalMmapVector<tid_t> threads;
InternalMmapVector<ThreadID> threads;
threads.reserve(128);
for (int i = 0; i < 30 && retry; ++i) {
retry = false;
@ -226,7 +226,7 @@ bool ThreadSuspender::SuspendAllThreads() {
case ThreadLister::Ok:
break;
}
for (tid_t tid : threads) {
for (ThreadID tid : threads) {
// Are we already attached to this thread?
// Currently this check takes linear time, however the number of threads
// is usually small.
@ -546,7 +546,7 @@ static constexpr uptr kExtraRegs[] = {0};
#error "Unsupported architecture"
#endif // SANITIZER_ANDROID && defined(__arm__)
tid_t SuspendedThreadsListLinux::GetThreadID(uptr index) const {
ThreadID SuspendedThreadsListLinux::GetThreadID(uptr index) const {
CHECK_LT(index, thread_ids_.size());
return thread_ids_[index];
}
@ -555,14 +555,14 @@ uptr SuspendedThreadsListLinux::ThreadCount() const {
return thread_ids_.size();
}
bool SuspendedThreadsListLinux::ContainsTid(tid_t thread_id) const {
bool SuspendedThreadsListLinux::ContainsTid(ThreadID thread_id) const {
for (uptr i = 0; i < thread_ids_.size(); i++) {
if (thread_ids_[i] == thread_id) return true;
}
return false;
}
void SuspendedThreadsListLinux::Append(tid_t tid) {
void SuspendedThreadsListLinux::Append(ThreadID tid) {
thread_ids_.push_back(tid);
}

View File

@ -23,7 +23,7 @@
namespace __sanitizer {
typedef struct {
tid_t tid;
ThreadID tid;
thread_t thread;
} SuspendedThreadInfo;
@ -31,7 +31,7 @@ class SuspendedThreadsListMac final : public SuspendedThreadsList {
public:
SuspendedThreadsListMac() = default;
tid_t GetThreadID(uptr index) const override;
ThreadID GetThreadID(uptr index) const override;
thread_t GetThread(uptr index) const;
uptr ThreadCount() const override;
bool ContainsThread(thread_t thread) const;
@ -111,7 +111,7 @@ typedef x86_thread_state32_t regs_struct;
#error "Unsupported architecture"
#endif
tid_t SuspendedThreadsListMac::GetThreadID(uptr index) const {
ThreadID SuspendedThreadsListMac::GetThreadID(uptr index) const {
CHECK_LT(index, threads_.size());
return threads_[index].tid;
}

View File

@ -52,17 +52,17 @@ class SuspendedThreadsListNetBSD final : public SuspendedThreadsList {
public:
SuspendedThreadsListNetBSD() { thread_ids_.reserve(1024); }
tid_t GetThreadID(uptr index) const;
ThreadID GetThreadID(uptr index) const;
uptr ThreadCount() const;
bool ContainsTid(tid_t thread_id) const;
void Append(tid_t tid);
bool ContainsTid(ThreadID thread_id) const;
void Append(ThreadID tid);
PtraceRegistersStatus GetRegistersAndSP(uptr index,
InternalMmapVector<uptr> *buffer,
uptr *sp) const;
private:
InternalMmapVector<tid_t> thread_ids_;
InternalMmapVector<ThreadID> thread_ids_;
};
struct TracerThreadArgument {
@ -313,7 +313,7 @@ void StopTheWorld(StopTheWorldCallback callback, void *argument) {
}
}
tid_t SuspendedThreadsListNetBSD::GetThreadID(uptr index) const {
ThreadID SuspendedThreadsListNetBSD::GetThreadID(uptr index) const {
CHECK_LT(index, thread_ids_.size());
return thread_ids_[index];
}
@ -322,7 +322,7 @@ uptr SuspendedThreadsListNetBSD::ThreadCount() const {
return thread_ids_.size();
}
bool SuspendedThreadsListNetBSD::ContainsTid(tid_t thread_id) const {
bool SuspendedThreadsListNetBSD::ContainsTid(ThreadID thread_id) const {
for (uptr i = 0; i < thread_ids_.size(); i++) {
if (thread_ids_[i] == thread_id)
return true;
@ -330,7 +330,7 @@ bool SuspendedThreadsListNetBSD::ContainsTid(tid_t thread_id) const {
return false;
}
void SuspendedThreadsListNetBSD::Append(tid_t tid) {
void SuspendedThreadsListNetBSD::Append(ThreadID tid) {
thread_ids_.push_back(tid);
}

View File

@ -38,7 +38,7 @@ struct SuspendedThreadsListWindows final : public SuspendedThreadsList {
InternalMmapVector<uptr> *buffer,
uptr *sp) const override;
tid_t GetThreadID(uptr index) const override;
ThreadID GetThreadID(uptr index) const override;
uptr ThreadCount() const override;
};
@ -68,7 +68,7 @@ PtraceRegistersStatus SuspendedThreadsListWindows::GetRegistersAndSP(
return REGISTERS_AVAILABLE;
}
tid_t SuspendedThreadsListWindows::GetThreadID(uptr index) const {
ThreadID SuspendedThreadsListWindows::GetThreadID(uptr index) const {
CHECK_LT(index, threadIds.size());
return threadIds[index];
}

View File

@ -80,7 +80,7 @@ void ThreadContextBase::SetFinished() {
OnFinished();
}
void ThreadContextBase::SetStarted(tid_t _os_id, ThreadType _thread_type,
void ThreadContextBase::SetStarted(ThreadID _os_id, ThreadType _thread_type,
void *arg) {
status = ThreadStatusRunning;
os_id = _os_id;
@ -228,7 +228,8 @@ static bool FindThreadContextByOsIdCallback(ThreadContextBase *tctx,
tctx->status != ThreadStatusDead);
}
ThreadContextBase *ThreadRegistry::FindThreadContextByOsIDLocked(tid_t os_id) {
ThreadContextBase *ThreadRegistry::FindThreadContextByOsIDLocked(
ThreadID os_id) {
return FindThreadContextLocked(FindThreadContextByOsIdCallback,
(void *)os_id);
}
@ -322,8 +323,8 @@ ThreadStatus ThreadRegistry::FinishThread(u32 tid) {
return prev_status;
}
void ThreadRegistry::StartThread(u32 tid, tid_t os_id, ThreadType thread_type,
void *arg) {
void ThreadRegistry::StartThread(u32 tid, ThreadID os_id,
ThreadType thread_type, void *arg) {
ThreadRegistryLock l(this);
running_threads_++;
ThreadContextBase *tctx = threads_[tid];

View File

@ -43,7 +43,7 @@ class ThreadContextBase {
const u32 tid; // Thread ID. Main thread should have tid = 0.
u64 unique_id; // Unique thread ID.
u32 reuse_count; // Number of times this tid was reused.
tid_t os_id; // PID (used for reporting).
ThreadID os_id; // PID (used for reporting).
uptr user_id; // Some opaque user thread id (e.g. pthread_t).
char name[64]; // As annotated by user.
@ -62,7 +62,7 @@ class ThreadContextBase {
void SetDead();
void SetJoined(void *arg);
void SetFinished();
void SetStarted(tid_t _os_id, ThreadType _thread_type, void *arg);
void SetStarted(ThreadID _os_id, ThreadType _thread_type, void *arg);
void SetCreated(uptr _user_id, u64 _unique_id, bool _detached,
u32 _parent_tid, u32 _stack_tid, void *arg);
void Reset();
@ -126,7 +126,7 @@ class SANITIZER_MUTEX ThreadRegistry {
// is found.
ThreadContextBase *FindThreadContextLocked(FindThreadCallback cb,
void *arg);
ThreadContextBase *FindThreadContextByOsIDLocked(tid_t os_id);
ThreadContextBase *FindThreadContextByOsIDLocked(ThreadID os_id);
void SetThreadName(u32 tid, const char *name);
void SetThreadNameByUserId(uptr user_id, const char *name);
@ -134,7 +134,7 @@ class SANITIZER_MUTEX ThreadRegistry {
void JoinThread(u32 tid, void *arg);
// Finishes thread and returns previous status.
ThreadStatus FinishThread(u32 tid);
void StartThread(u32 tid, tid_t os_id, ThreadType thread_type, void *arg);
void StartThread(u32 tid, ThreadID os_id, ThreadType thread_type, void *arg);
u32 ConsumeThreadUserId(uptr user_id);
void SetThreadUserId(u32 tid, uptr user_id);

View File

@ -108,9 +108,7 @@ int internal_dlinfo(void *handle, int request, void *p) {
// In contrast to POSIX, on Windows GetCurrentThreadId()
// returns a system-unique identifier.
tid_t GetTid() {
return GetCurrentThreadId();
}
ThreadID GetTid() { return GetCurrentThreadId(); }
uptr GetThreadSelf() {
return GetTid();

View File

@ -43,7 +43,7 @@ struct TidReporterArgument {
pthread_cond_destroy(&tid_reported_cond);
}
tid_t reported_tid;
ThreadID reported_tid;
// For signaling to spawned threads that they should terminate.
pthread_cond_t terminate_thread_cond;
pthread_mutex_t terminate_thread_mutex;
@ -62,7 +62,7 @@ class ThreadListerTest : public ::testing::Test {
protected:
virtual void SetUp() {
pthread_t pthread_id;
tid_t tid;
ThreadID tid;
for (uptr i = 0; i < kThreadCount; i++) {
SpawnTidReporter(&pthread_id, &tid);
pthread_ids_.push_back(pthread_id);
@ -79,12 +79,12 @@ class ThreadListerTest : public ::testing::Test {
pthread_join(pthread_ids_[i], NULL);
}
void SpawnTidReporter(pthread_t *pthread_id, tid_t *tid);
void SpawnTidReporter(pthread_t *pthread_id, ThreadID *tid);
static const uptr kThreadCount = 20;
std::vector<pthread_t> pthread_ids_;
std::vector<tid_t> tids_;
std::vector<ThreadID> tids_;
TidReporterArgument thread_arg;
};
@ -105,42 +105,43 @@ void *TidReporterThread(void *argument) {
return NULL;
}
void ThreadListerTest::SpawnTidReporter(pthread_t *pthread_id, tid_t *tid) {
void ThreadListerTest::SpawnTidReporter(pthread_t *pthread_id, ThreadID *tid) {
pthread_mutex_lock(&thread_arg.tid_reported_mutex);
thread_arg.reported_tid = -1;
ASSERT_EQ(0,
pthread_create(pthread_id, NULL, TidReporterThread, &thread_arg));
while (thread_arg.reported_tid == (tid_t)(-1))
while (thread_arg.reported_tid == (ThreadID)(-1))
pthread_cond_wait(&thread_arg.tid_reported_cond,
&thread_arg.tid_reported_mutex);
pthread_mutex_unlock(&thread_arg.tid_reported_mutex);
*tid = thread_arg.reported_tid;
}
static std::vector<tid_t> ReadTidsToVector(ThreadLister *thread_lister) {
std::vector<tid_t> listed_tids;
InternalMmapVector<tid_t> threads(128);
static std::vector<ThreadID> ReadTidsToVector(ThreadLister *thread_lister) {
std::vector<ThreadID> listed_tids;
InternalMmapVector<ThreadID> threads(128);
EXPECT_TRUE(thread_lister->ListThreads(&threads));
return std::vector<tid_t>(threads.begin(), threads.end());
return std::vector<ThreadID>(threads.begin(), threads.end());
}
static bool Includes(std::vector<tid_t> first, std::vector<tid_t> second) {
static bool Includes(std::vector<ThreadID> first,
std::vector<ThreadID> second) {
std::sort(first.begin(), first.end());
std::sort(second.begin(), second.end());
return std::includes(first.begin(), first.end(), second.begin(),
second.end());
}
static bool HasElement(const std::vector<tid_t> &vector, tid_t element) {
static bool HasElement(const std::vector<ThreadID> &vector, ThreadID element) {
return std::find(vector.begin(), vector.end(), element) != vector.end();
}
// ThreadLister's output should include the current thread's TID and the TID of
// every thread we spawned.
TEST_F(ThreadListerTest, ThreadListerSeesAllSpawnedThreads) {
tid_t self_tid = GetTid();
ThreadID self_tid = GetTid();
ThreadLister thread_lister(getpid());
std::vector<tid_t> listed_tids = ReadTidsToVector(&thread_lister);
std::vector<ThreadID> listed_tids = ReadTidsToVector(&thread_lister);
ASSERT_TRUE(HasElement(listed_tids, self_tid));
ASSERT_TRUE(Includes(listed_tids, tids_));
@ -154,7 +155,7 @@ TEST_F(ThreadListerTest, DoNotForgetThreads) {
// Run the loop body twice, because ThreadLister might behave differently if
// called on a freshly created object.
for (uptr i = 0; i < 2; i++) {
std::vector<tid_t> listed_tids = ReadTidsToVector(&thread_lister);
std::vector<ThreadID> listed_tids = ReadTidsToVector(&thread_lister);
ASSERT_TRUE(Includes(listed_tids, tids_));
}
}
@ -163,10 +164,10 @@ TEST_F(ThreadListerTest, DoNotForgetThreads) {
// relisting should cause ThreadLister to recognize their existence.
TEST_F(ThreadListerTest, NewThreads) {
ThreadLister thread_lister(getpid());
std::vector<tid_t> threads_before_extra = ReadTidsToVector(&thread_lister);
std::vector<ThreadID> threads_before_extra = ReadTidsToVector(&thread_lister);
pthread_t extra_pthread_id;
tid_t extra_tid;
ThreadID extra_tid;
SpawnTidReporter(&extra_pthread_id, &extra_tid);
// Register the new thread so it gets terminated in TearDown().
pthread_ids_.push_back(extra_pthread_id);
@ -176,7 +177,7 @@ TEST_F(ThreadListerTest, NewThreads) {
// so better check for that.
ASSERT_FALSE(HasElement(threads_before_extra, extra_tid));
std::vector<tid_t> threads_after_extra = ReadTidsToVector(&thread_lister);
std::vector<ThreadID> threads_after_extra = ReadTidsToVector(&thread_lister);
ASSERT_TRUE(HasElement(threads_after_extra, extra_tid));
}

View File

@ -165,7 +165,7 @@ int __tsan_get_report_mutex(void *report, uptr idx, uptr *mutex_id, void **addr,
}
SANITIZER_INTERFACE_ATTRIBUTE
int __tsan_get_report_thread(void *report, uptr idx, int *tid, tid_t *os_id,
int __tsan_get_report_thread(void *report, uptr idx, int *tid, ThreadID *os_id,
int *running, const char **name, int *parent_tid,
void **trace, uptr trace_size) {
const ReportDesc *rep = (ReportDesc *)report;
@ -242,7 +242,7 @@ const char *__tsan_locate_address(uptr addr, char *name, uptr name_size,
SANITIZER_INTERFACE_ATTRIBUTE
int __tsan_get_alloc_stack(uptr addr, uptr *trace, uptr size, int *thread_id,
tid_t *os_id) {
ThreadID *os_id) {
MBlock *b = 0;
Allocator *a = allocator();
if (a->PointerIsMine((void *)addr)) {

View File

@ -2888,12 +2888,12 @@ TSAN_INTERCEPTOR(void, _lwp_exit) {
#endif
#if SANITIZER_FREEBSD
TSAN_INTERCEPTOR(void, thr_exit, tid_t *state) {
TSAN_INTERCEPTOR(void, thr_exit, ThreadID *state) {
SCOPED_TSAN_INTERCEPTOR(thr_exit, state);
DestroyThreadState();
REAL(thr_exit(state));
}
#define TSAN_MAYBE_INTERCEPT_THR_EXIT TSAN_INTERCEPT(thr_exit)
# define TSAN_MAYBE_INTERCEPT_THR_EXIT TSAN_INTERCEPT(thr_exit)
#else
#define TSAN_MAYBE_INTERCEPT_THR_EXIT
#endif

View File

@ -16,7 +16,7 @@
#define TSAN_INTERFACE_H
#include <sanitizer_common/sanitizer_internal_defs.h>
using __sanitizer::tid_t;
using __sanitizer::ThreadID;
using __sanitizer::uptr;
// This header should NOT include any other headers.
@ -175,7 +175,7 @@ int __tsan_get_report_mutex(void *report, uptr idx, uptr *mutex_id, void **addr,
// Returns information about threads included in the report.
SANITIZER_INTERFACE_ATTRIBUTE
int __tsan_get_report_thread(void *report, uptr idx, int *tid, tid_t *os_id,
int __tsan_get_report_thread(void *report, uptr idx, int *tid, ThreadID *os_id,
int *running, const char **name, int *parent_tid,
void **trace, uptr trace_size);
@ -192,7 +192,7 @@ const char *__tsan_locate_address(uptr addr, char *name, uptr name_size,
// Returns the allocation stack for a heap pointer.
SANITIZER_INTERFACE_ATTRIBUTE
int __tsan_get_alloc_stack(uptr addr, uptr *trace, uptr size, int *thread_id,
tid_t *os_id);
ThreadID *os_id);
#endif // SANITIZER_GO

View File

@ -84,7 +84,7 @@ struct ReportLocation {
struct ReportThread {
Tid id;
tid_t os_id;
ThreadID os_id;
bool running;
ThreadType thread_type;
char *name;

View File

@ -559,7 +559,7 @@ void ThreadIgnoreSyncBegin(ThreadState *thr, uptr pc);
void ThreadIgnoreSyncEnd(ThreadState *thr);
Tid ThreadCreate(ThreadState *thr, uptr pc, uptr uid, bool detached);
void ThreadStart(ThreadState *thr, Tid tid, tid_t os_id,
void ThreadStart(ThreadState *thr, Tid tid, ThreadID os_id,
ThreadType thread_type);
void ThreadFinish(ThreadState *thr);
Tid ThreadConsumeTid(ThreadState *thr, uptr pc, uptr uid);

View File

@ -149,7 +149,7 @@ struct OnStartedArgs {
uptr tls_size;
};
void ThreadStart(ThreadState *thr, Tid tid, tid_t os_id,
void ThreadStart(ThreadState *thr, Tid tid, ThreadID os_id,
ThreadType thread_type) {
ctx->thread_registry.StartThread(tid, os_id, thread_type, thr);
if (!thr->ignore_sync) {

View File

@ -32,7 +32,7 @@ template <size_t Version = 5> class FDRController {
uint64_t LastFunctionEntryTSC = 0;
uint64_t LatestTSC = 0;
uint16_t LatestCPU = 0;
tid_t TId = 0;
ThreadID TId = 0;
pid_t PId = 0;
bool First = true;
@ -84,7 +84,7 @@ template <size_t Version = 5> class FDRController {
// buffer, associated with a particular thread, with a new CPU. For the
// data, we have 15 bytes to squeeze as much information as we can. At
// this point we only write down the following bytes:
// - Thread ID (tid_t, cast to 4 bytes type due to Darwin being 8
// - Thread ID (ThreadID, cast to 4 bytes type due to Darwin being 8
// bytes)
createMetadataRecord<MetadataRecord::RecordKinds::NewBuffer>(
static_cast<int32_t>(TId)),

View File

@ -28,7 +28,7 @@ namespace {
SpinMutex GlobalMutex;
struct ThreadTrie {
tid_t TId;
ThreadID TId;
alignas(FunctionCallTrie) std::byte TrieStorage[sizeof(FunctionCallTrie)];
};
@ -61,7 +61,7 @@ struct ThreadData {
FunctionCallTrie::Allocators::Buffers Buffers;
FunctionCallTrie::Allocators Allocators;
FunctionCallTrie FCT;
tid_t TId;
ThreadID TId;
};
using ThreadDataArray = Array<ThreadData>;
@ -105,7 +105,7 @@ static atomic_uint8_t CollectorInitialized{0};
void post(BufferQueue *Q, FunctionCallTrie &&T,
FunctionCallTrie::Allocators &&A,
FunctionCallTrie::Allocators::Buffers &&B,
tid_t TId) XRAY_NEVER_INSTRUMENT {
ThreadID TId) XRAY_NEVER_INSTRUMENT {
DCHECK_NE(Q, nullptr);
// Bail out early if the collector has not been initialized.

View File

@ -38,7 +38,7 @@ namespace profileCollectorService {
///
void post(BufferQueue *Q, FunctionCallTrie &&T,
FunctionCallTrie::Allocators &&A,
FunctionCallTrie::Allocators::Buffers &&B, tid_t TId);
FunctionCallTrie::Allocators::Buffers &&B, ThreadID TId);
/// The serialize will process all FunctionCallTrie instances in memory, and
/// turn those into specifically formatted blocks, each describing the