From fc18ed52838bea9502125dda304c6d7cf004b839 Mon Sep 17 00:00:00 2001 From: David Major Date: Tue, 18 Apr 2017 18:52:06 -0400 Subject: [PATCH] Bug 1354292: Let the stack walker unwind leaf functions without a function entry. r=njn --- mozglue/misc/StackWalk.cpp | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/mozglue/misc/StackWalk.cpp b/mozglue/misc/StackWalk.cpp index 2a9fcb1e7c6d..c06ffb85adb7 100644 --- a/mozglue/misc/StackWalk.cpp +++ b/mozglue/misc/StackWalk.cpp @@ -357,6 +357,10 @@ WalkStackMain64(struct WalkStackData* aData) }); #endif +#ifdef _M_AMD64 + bool firstFrame = true; +#endif + // Skip our own stack walking frames. int skip = (aData->walkCallingThread ? 3 : 0) + aData->skipFrames; @@ -416,26 +420,29 @@ WalkStackMain64(struct WalkStackData* aData) PRUNTIME_FUNCTION runtimeFunction = RtlLookupFunctionEntry(context.Rip, &imageBase, NULL); - if (!runtimeFunction) { - // Alas, this is probably a JIT frame, for which we don't generate unwind - // info and so we have to give up. + if (runtimeFunction) { + PVOID dummyHandlerData; + ULONG64 dummyEstablisherFrame; + RtlVirtualUnwind(UNW_FLAG_NHANDLER, + imageBase, + context.Rip, + runtimeFunction, + &context, + &dummyHandlerData, + &dummyEstablisherFrame, + nullptr); + } else if (firstFrame) { + // Leaf functions can be unwound by hand. + context.Rip = *reinterpret_cast(context.Rsp); + context.Rsp += sizeof(void*); + } else { + // Something went wrong. break; } - PVOID dummyHandlerData; - ULONG64 dummyEstablisherFrame; - RtlVirtualUnwind(UNW_FLAG_NHANDLER, - imageBase, - context.Rip, - runtimeFunction, - &context, - &dummyHandlerData, - &dummyEstablisherFrame, - nullptr); - addr = context.Rip; spaddr = context.Rsp; - + firstFrame = false; #else #error "unknown platform" #endif