From b8909530ab35bca0d795ea264d72d2640d88de46 Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Thu, 23 Aug 2018 16:48:53 -0400 Subject: [PATCH] Bug 1485716 - part 2 - add aarch64 windows support to the stack walking code; r=aklotz This code is untested and has been cargo-culted a little bit from the existing x86 code, but should work OK; all the code in Windows is compiled with frame pointers, we're compiled with frame pointers after the previous patch, and so the frame pointer unwinding path makes the most sense. --- mozglue/misc/StackWalk.cpp | 12 +++++++++--- mozglue/misc/StackWalk.h | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/mozglue/misc/StackWalk.cpp b/mozglue/misc/StackWalk.cpp index 58cd5fc65dd0..a3c226daafcc 100644 --- a/mozglue/misc/StackWalk.cpp +++ b/mozglue/misc/StackWalk.cpp @@ -207,7 +207,7 @@ WalkStackMain64(struct WalkStackData* aData) context = aData->context; } -#if defined(_M_IX86) || defined(_M_IA64) +#if defined(_M_IX86) || defined(_M_IA64) || defined(_M_ARM64) // Setup initial stack frame to walk from. STACKFRAME64 frame64; memset(&frame64, 0, sizeof(frame64)); @@ -219,6 +219,10 @@ WalkStackMain64(struct WalkStackData* aData) frame64.AddrPC.Offset = context->StIIP; frame64.AddrStack.Offset = context->SP; frame64.AddrFrame.Offset = context->RsBSP; +#elif defined _M_ARM64 + frame64.AddrPC.Offset = context->Pc; + frame64.AddrStack.Offset = context->Sp; + frame64.AddrFrame.Offset = context->Fp; #endif frame64.AddrPC.Mode = AddrModeFlat; frame64.AddrStack.Mode = AddrModeFlat; @@ -226,7 +230,7 @@ WalkStackMain64(struct WalkStackData* aData) frame64.AddrReturn.Mode = AddrModeFlat; #endif -#ifdef _WIN64 +#ifdef _M_AMD64 // If there are any active suppressions, then at least one thread (we don't // know which) is holding a lock that can deadlock RtlVirtualUnwind. Since // that thread may be the one that we're trying to unwind, we can't proceed. @@ -254,7 +258,7 @@ WalkStackMain64(struct WalkStackData* aData) DWORD64 addr; DWORD64 spaddr; -#if defined(_M_IX86) || defined(_M_IA64) +#if defined(_M_IX86) || defined(_M_IA64) || defined(_M_ARM64) // 32-bit frame unwinding. // Debug routines are not threadsafe, so grab the lock. EnterCriticalSection(&gDbgHelpCS); @@ -263,6 +267,8 @@ WalkStackMain64(struct WalkStackData* aData) IMAGE_FILE_MACHINE_IA64, #elif defined _M_IX86 IMAGE_FILE_MACHINE_I386, +#elif defined _M_ARM64 + IMAGE_FILE_MACHINE_ARM64, #endif aData->process, aData->thread, diff --git a/mozglue/misc/StackWalk.h b/mozglue/misc/StackWalk.h index 5ae6a0371d69..eea01be4582f 100644 --- a/mozglue/misc/StackWalk.h +++ b/mozglue/misc/StackWalk.h @@ -47,7 +47,8 @@ MozStackWalk(MozWalkStackCallback aCallback, uint32_t aSkipFrames, uint32_t aMaxFrames, void* aClosure); #if defined(_WIN32) && \ - (defined(_M_IX86) || defined(_M_AMD64) || defined(_M_IA64)) + (defined(_M_IX86) || defined(_M_AMD64) || \ + defined(_M_IA64) || defined(_M_ARM64)) #include