Commit cb895545 authored by Kenny Yu's avatar Kenny Yu Committed by Facebook GitHub Bot

ensure next stack frame address is valid when walking async stacks

Summary:
We have cases where the C++ -> Lua calls are not properly following the calling convention and the pointer to the previous normal stack frame is not correctly pushed after the lua call. This results in segfaults when we try to walk the normal stack.

Stack frame addresses for the normal stack frames should always be increasing. A simple fix is check whether the next stack frame address <= starting stack frame address. If it is, this indicates the end fo the stack (nullptr) or likely stack corruption, as in the case above.

This means that we might miss out on the stack frames right before the stack frame that breaks the calling convention, but we should correctly get the rest of the async stack trace before this frame, and the stack frames after this frame.

Reviewed By: yfeldblum

Differential Revision: D30907903

fbshipit-source-id: 7d78b53570fd24dbb23b4fc49afa995d44c9e549
parent e6c19c13
......@@ -177,7 +177,13 @@ size_t walkNormalStack(
StackFrame* normalStackFrame,
StackFrame* normalStackFrameStop) {
size_t numFrames = 0;
while (numFrames < maxAddresses && normalStackFrame != nullptr) {
// Stack frame addresses should increase as we traverse the stack.
// If it doesn't, it means we have stack corruption, or an unusual calling
// convention. In this case, stop walking the stack early to avoid incorrect
// stack walking.
auto* normalStackFrameStart = normalStackFrame;
while (numFrames < maxAddresses && normalStackFrame != nullptr &&
normalStackFrame >= normalStackFrameStart) {
auto* normalStackFrameNext = normalStackFrame->parentFrame;
if (normalStackFrameStop != nullptr &&
normalStackFrameNext == normalStackFrameStop) {
......
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