Commit 6260b4a0 authored by Vlad Tsyrklevich's avatar Vlad Tsyrklevich Committed by Commit Bot

GWP-ASan: Report a different TID on macOS

The TID returned by PlatformThread::CurrentId() uses
`pthread_mach_thread_np(pthread_self())` which does not match the one
used by crashpad (and hence reported server-side.) Record a matching
TID instead.

Bug: 934888
Change-Id: I9606827874c6072fc8ba1dc9a1ed6b67e27a0898
Reviewed-on: https://chromium-review.googlesource.com/c/1484351
Auto-Submit: Vlad Tsyrklevich <vtsyrklevich@chromium.org>
Reviewed-by: default avatarVitaly Buka <vitalybuka@chromium.org>
Reviewed-by: default avatarMark Mentovai <mark@chromium.org>
Commit-Queue: Vlad Tsyrklevich <vtsyrklevich@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635667}
parent 5d1750a5
......@@ -20,9 +20,29 @@
#include "components/gwp_asan/common/crash_key_name.h"
#include "components/gwp_asan/common/pack_stack_trace.h"
#if defined(OS_MACOSX)
#include <pthread.h>
#endif
namespace gwp_asan {
namespace internal {
namespace {
// Report a tid that matches what crashpad collects which may differ from what
// base::PlatformThread::CurrentId() returns.
uint64_t ReportTid() {
#if !defined(OS_MACOSX)
return base::PlatformThread::CurrentId();
#else
uint64_t tid = base::kInvalidThreadId;
pthread_threadid_np(nullptr, &tid);
return tid;
#endif
}
} // namespace
// TODO: Delete out-of-line constexpr defininitons once C++17 is in use.
constexpr size_t GuardedPageAllocator::kGpaAllocAlignment;
......@@ -182,7 +202,7 @@ void GuardedPageAllocator::RecordAllocationInSlot(size_t slot,
slots_[slot].alloc.trace_len = Pack(reinterpret_cast<uintptr_t*>(trace), len,
slots_[slot].alloc.packed_trace,
sizeof(slots_[slot].alloc.packed_trace));
slots_[slot].alloc.tid = base::PlatformThread::CurrentId();
slots_[slot].alloc.tid = ReportTid();
slots_[slot].alloc.trace_collected = true;
slots_[slot].dealloc.tid = base::kInvalidThreadId;
......@@ -199,7 +219,7 @@ void GuardedPageAllocator::RecordDeallocationInSlot(size_t slot) {
Pack(reinterpret_cast<uintptr_t*>(trace), len,
slots_[slot].dealloc.packed_trace,
sizeof(slots_[slot].dealloc.packed_trace));
slots_[slot].dealloc.tid = base::PlatformThread::CurrentId();
slots_[slot].dealloc.tid = ReportTid();
slots_[slot].dealloc.trace_collected = true;
}
......
......@@ -67,7 +67,7 @@ class AllocatorState {
struct AllocationInfo {
// (De)allocation thread id or base::kInvalidThreadId if no (de)allocation
// occurred.
base::PlatformThreadId tid = base::kInvalidThreadId;
uint64_t tid = base::kInvalidThreadId;
// Packed stack trace.
uint8_t packed_trace[kMaxPackedTraceLength];
// Length used to encode the packed stack trace.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment