Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: base/debug/stack_trace.cc

Issue 2692123005: Fix stack walking to notice if the frame is obviously not valid. (Closed)
Patch Set: Comments from wez. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/debug/stack_trace.h" 5 #include "base/debug/stack_trace.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <sstream> 10 #include <sstream>
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // With the stack growing downwards, older stack frame must be 104 // With the stack growing downwards, older stack frame must be
105 // at a greater address that the current one. 105 // at a greater address that the current one.
106 if (fp <= prev_fp) return false; 106 if (fp <= prev_fp) return false;
107 107
108 // Assume huge stack frames are bogus. 108 // Assume huge stack frames are bogus.
109 if (fp - prev_fp > 100000) return false; 109 if (fp - prev_fp > 100000) return false;
110 110
111 // Check alignment. 111 // Check alignment.
112 if (fp & (sizeof(uintptr_t) - 1)) return false; 112 if (fp & (sizeof(uintptr_t) - 1)) return false;
113 113
114 // A PC that is too small means we've gone off the end of the stack.
115 const uintptr_t kMinimumReasonablePC = 32768;
116 if (GetStackFramePC(fp) < kMinimumReasonablePC)
117 return false;
118
114 if (stack_end) { 119 if (stack_end) {
115 // Both fp[0] and fp[1] must be within the stack. 120 // Both fp[0] and fp[1] must be within the stack.
116 if (fp > stack_end - 2 * sizeof(uintptr_t)) return false; 121 if (fp > stack_end - 2 * sizeof(uintptr_t)) return false;
117
118 // Additional check to filter out false positives.
119 if (GetStackFramePC(fp) < 32768) return false;
120 } 122 }
121 123
122 return true; 124 return true;
123 }; 125 };
124 126
125 // ScanStackForNextFrame() scans the stack for a valid frame to allow unwinding 127 // ScanStackForNextFrame() scans the stack for a valid frame to allow unwinding
126 // past system libraries. Only supported on Linux where system libraries are 128 // past system libraries. Only supported on Linux where system libraries are
127 // usually in the middle of the trace: 129 // usually in the middle of the trace:
128 // 130 //
129 // TraceStackFramePointers 131 // TraceStackFramePointers
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 ScopedStackFrameLinker::~ScopedStackFrameLinker() { 266 ScopedStackFrameLinker::~ScopedStackFrameLinker() {
265 void* previous_parent_fp = LinkStackFrames(fp_, original_parent_fp_); 267 void* previous_parent_fp = LinkStackFrames(fp_, original_parent_fp_);
266 CHECK_EQ(parent_fp_, previous_parent_fp) 268 CHECK_EQ(parent_fp_, previous_parent_fp)
267 << "Stack frame's parent pointer has changed!"; 269 << "Stack frame's parent pointer has changed!";
268 } 270 }
269 271
270 #endif // HAVE_TRACE_STACK_FRAME_POINTERS 272 #endif // HAVE_TRACE_STACK_FRAME_POINTERS
271 273
272 } // namespace debug 274 } // namespace debug
273 } // namespace base 275 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698