From e48460762273586744a79d146c2916bcfca7e9e4 Mon Sep 17 00:00:00 2001 From: Christopher Ferris Date: Fri, 23 May 2014 14:46:36 -0700 Subject: [PATCH] Only copy mcontext data from sigcontext. The ucontext_t data structure could be bigger than the kernel data structure. Since the unwinder only cares about the mcontext data, only copy that out of the structure. The mcontext data is the same size in the kernel and in the ucontext_t structure. Bug: 15189014 Change-Id: I5978169c4425b8212e11db85a57eb319cd0e264b --- libbacktrace/BacktraceThread.cpp | 8 +++++++- libbacktrace/BacktraceThread.h | 6 ++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/libbacktrace/BacktraceThread.cpp b/libbacktrace/BacktraceThread.cpp index 018d51f04..b47cd2ad2 100644 --- a/libbacktrace/BacktraceThread.cpp +++ b/libbacktrace/BacktraceThread.cpp @@ -117,6 +117,12 @@ void ThreadEntry::Wake() { futex(&futex_, FUTEX_WAKE, INT_MAX, NULL, NULL, 0); } +void ThreadEntry::CopyUcontextFromSigcontext(void* sigcontext) { + ucontext_t* ucontext = reinterpret_cast(sigcontext); + // The only thing the unwinder cares about is the mcontext data. + memcpy(&ucontext_.uc_mcontext, &ucontext->uc_mcontext, sizeof(ucontext->uc_mcontext)); +} + //------------------------------------------------------------------------- // BacktraceThread functions. //------------------------------------------------------------------------- @@ -129,7 +135,7 @@ static void SignalHandler(int, siginfo_t*, void* sigcontext) { return; } - entry->CopyUcontext(reinterpret_cast(sigcontext)); + entry->CopyUcontextFromSigcontext(sigcontext); // Indicate the ucontext is now valid. entry->Wake(); diff --git a/libbacktrace/BacktraceThread.h b/libbacktrace/BacktraceThread.h index a75a807be..ff3e9f3f4 100644 --- a/libbacktrace/BacktraceThread.h +++ b/libbacktrace/BacktraceThread.h @@ -40,14 +40,12 @@ public: static void Remove(ThreadEntry* entry); - inline void CopyUcontext(ucontext_t* ucontext) { - memcpy(&ucontext_, ucontext, sizeof(ucontext_)); - } - void Wake(); void Wait(int); + void CopyUcontextFromSigcontext(void*); + inline void Lock() { pthread_mutex_lock(&mutex_); // Reset the futex value in case of multiple unwinds of the same thread.